diff options
author | Michael Brown <mcb30@etherboot.org> | 2008-03-20 21:06:03 +0000 |
---|---|---|
committer | Michael Brown <mcb30@etherboot.org> | 2008-03-20 21:06:53 +0000 |
commit | acfa14423ef2c974e9d8ff3d0aa48fe0ea2fb8c7 (patch) | |
tree | 1541c01facb5ed9d291aa773f12b7a8664077206 /src/net/netdev_settings.c | |
parent | 260b93bb72ab31881669cb3e393816a6156c92b7 (diff) | |
download | ipxe-acfa14423ef2c974e9d8ff3d0aa48fe0ea2fb8c7.tar.gz |
[Settings] Add per-netdevice settings block
Add a configuration settings block for each net device. This will
provide the parent scope for settings applicable only to that network
device (e.g. non-volatile options stored on the NIC, options obtained via
DHCP, etc.).
Expose the MAC address as a setting.
Diffstat (limited to 'src/net/netdev_settings.c')
-rw-r--r-- | src/net/netdev_settings.c | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/src/net/netdev_settings.c b/src/net/netdev_settings.c new file mode 100644 index 000000000..9baad888b --- /dev/null +++ b/src/net/netdev_settings.c @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2008 Michael Brown <mbrown@fensystems.co.uk>. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include <string.h> +#include <errno.h> +#include <gpxe/dhcp.h> +#include <gpxe/settings.h> +#include <gpxe/netdevice.h> + +/** @file + * + * Network device configuration settings + * + */ + +/** + * Store value of network device setting + * + * @v settings Settings block + * @v tag Setting tag number + * @v data Setting data, or NULL to clear setting + * @v len Length of setting data + * @ret rc Return status code + */ +static int netdev_store ( struct settings *settings, unsigned int tag, + const void *data, size_t len ) { + struct net_device *netdev = + container_of ( settings, struct net_device, settings ); + + switch ( tag ) { + case DHCP_EB_MAC: + if ( len != netdev->ll_protocol->ll_addr_len ) + return -EINVAL; + memcpy ( netdev->ll_addr, data, len ); + return 0; + default : + return simple_settings_store ( settings, tag, data, len ); + } +} + +/** + * Fetch value of network device setting + * + * @v settings Settings block + * @v tag Setting tag number + * @v data Setting data, or NULL to clear setting + * @v len Length of setting data + * @ret rc Return status code + */ +static int netdev_fetch ( struct settings *settings, unsigned int tag, + void *data, size_t len ) { + struct net_device *netdev = + container_of ( settings, struct net_device, settings ); + + switch ( tag ) { + case DHCP_EB_MAC: + if ( len > netdev->ll_protocol->ll_addr_len ) + len = netdev->ll_protocol->ll_addr_len; + memcpy ( data, netdev->ll_addr, len ); + return netdev->ll_protocol->ll_addr_len; + default : + return simple_settings_fetch ( settings, tag, data, len ); + } +} + +/** Network device configuration settings operations */ +struct settings_operations netdev_settings_operations = { + .store = netdev_store, + .fetch = netdev_fetch, +}; + +/** Network device named settings */ +struct named_setting netdev_named_settings[] __named_setting = { + { + .name = "mac", + .description = "MAC address", + .tag = DHCP_EB_MAC, + .type = &setting_type_hex, + }, +}; |