iPXE
|
Network device configuration settings. More...
#include <string.h>
#include <errno.h>
#include <byteswap.h>
#include <ipxe/dhcp.h>
#include <ipxe/dhcpopts.h>
#include <ipxe/settings.h>
#include <ipxe/device.h>
#include <ipxe/netdevice.h>
#include <ipxe/init.h>
Go to the source code of this file.
Data Structures | |
struct | netdev_setting_operation |
A network device setting operation. More... | |
Functions | |
FILE_LICENCE (GPL2_OR_LATER_OR_UBDL) | |
struct setting mac_setting | __setting (SETTING_NETDEV, mac) |
Network device predefined settings. | |
struct setting hwaddr_setting | __setting (SETTING_NETDEV, hwaddr) |
struct setting bustype_setting | __setting (SETTING_NETDEV, bustype) |
struct setting busloc_setting | __setting (SETTING_NETDEV, busloc) |
struct setting busid_setting | __setting (SETTING_NETDEV, busid) |
struct setting chip_setting | __setting (SETTING_NETDEV, chip) |
struct setting ifname_setting | __setting (SETTING_NETDEV, ifname) |
struct setting mtu_setting | __setting (SETTING_NETDEV, mtu) |
static int | netdev_store_mac (struct net_device *netdev, const void *data, size_t len) |
Store link-layer address setting. | |
static int | netdev_fetch_mac (struct net_device *netdev, void *data, size_t len) |
Fetch link-layer address setting. | |
static int | netdev_fetch_hwaddr (struct net_device *netdev, void *data, size_t len) |
Fetch hardware address setting. | |
static int | netdev_fetch_bustype (struct net_device *netdev, void *data, size_t len) |
Fetch bus type setting. | |
static int | netdev_fetch_busloc (struct net_device *netdev, void *data, size_t len) |
Fetch bus location setting. | |
static int | netdev_fetch_busid (struct net_device *netdev, void *data, size_t len) |
Fetch bus ID setting. | |
static int | netdev_fetch_chip (struct net_device *netdev, void *data, size_t len) |
Fetch chip setting. | |
static int | netdev_fetch_ifname (struct net_device *netdev, void *data, size_t len) |
Fetch ifname setting. | |
static int | netdev_store (struct settings *settings, const struct setting *setting, const void *data, size_t len) |
Store value of network device setting. | |
static int | netdev_fetch (struct settings *settings, struct setting *setting, void *data, size_t len) |
Fetch value of network device setting. | |
static void | netdev_clear (struct settings *settings) |
Clear network device settings. | |
static struct settings * | netdev_redirect (struct settings *settings) |
Redirect "netX" settings block. | |
static void | netdev_redirect_settings_init (void) |
Initialise "netX" settings. | |
struct init_fn netdev_redirect_settings_init_fn | __init_fn (INIT_LATE) |
"netX" settings initialiser | |
static int | apply_netdev_settings (void) |
Apply network device settings. | |
Variables | |
static struct netdev_setting_operation | netdev_setting_operations [] |
Network device settings. | |
struct settings_operations | netdev_settings_operations |
Network device configuration settings operations. | |
static struct settings_operations | netdev_redirect_settings_operations |
"netX" settings operations | |
static struct settings | netdev_redirect_settings |
"netX" settings | |
struct settings_applicator netdev_applicator | __settings_applicator |
Network device settings applicator. |
Network device configuration settings.
Definition in file netdev_settings.c.
FILE_LICENCE | ( | GPL2_OR_LATER_OR_UBDL | ) |
struct setting mac_setting __setting | ( | SETTING_NETDEV | , |
mac | |||
) | [read] |
Network device predefined settings.
struct setting hwaddr_setting __setting | ( | SETTING_NETDEV | , |
hwaddr | |||
) | [read] |
struct setting bustype_setting __setting | ( | SETTING_NETDEV | , |
bustype | |||
) | [read] |
struct setting busloc_setting __setting | ( | SETTING_NETDEV | , |
busloc | |||
) | [read] |
struct setting busid_setting __setting | ( | SETTING_NETDEV | , |
busid | |||
) | [read] |
struct setting chip_setting __setting | ( | SETTING_NETDEV | , |
chip | |||
) | [read] |
struct setting ifname_setting __setting | ( | SETTING_NETDEV | , |
ifname | |||
) | [read] |
struct setting mtu_setting __setting | ( | SETTING_NETDEV | , |
mtu | |||
) | [read] |
static int netdev_store_mac | ( | struct net_device * | netdev, |
const void * | data, | ||
size_t | len | ||
) | [static] |
Store link-layer address setting.
netdev | Network device |
data | Setting data, or NULL to clear setting |
len | Length of setting data |
rc | Return status code |
Definition at line 93 of file netdev_settings.c.
References EINVAL, net_device::hw_addr, ll_protocol::init_addr, net_device::ll_addr, ll_protocol::ll_addr_len, net_device::ll_protocol, and memcpy().
{ struct ll_protocol *ll_protocol = netdev->ll_protocol; /* Record new MAC address */ if ( data ) { if ( len != netdev->ll_protocol->ll_addr_len ) return -EINVAL; memcpy ( netdev->ll_addr, data, len ); } else { /* Reset MAC address if clearing setting */ ll_protocol->init_addr ( netdev->hw_addr, netdev->ll_addr ); } return 0; }
static int netdev_fetch_mac | ( | struct net_device * | netdev, |
void * | data, | ||
size_t | len | ||
) | [static] |
Fetch link-layer address setting.
netdev | Network device |
data | Buffer to fill with setting data |
len | Length of buffer |
len | Length of setting data, or negative error |
Definition at line 118 of file netdev_settings.c.
References net_device::ll_addr, ll_protocol::ll_addr_len, net_device::ll_protocol, max_len, and memcpy().
static int netdev_fetch_hwaddr | ( | struct net_device * | netdev, |
void * | data, | ||
size_t | len | ||
) | [static] |
Fetch hardware address setting.
netdev | Network device |
data | Buffer to fill with setting data |
len | Length of buffer |
len | Length of setting data, or negative error |
Definition at line 136 of file netdev_settings.c.
References net_device::hw_addr, ll_protocol::hw_addr_len, net_device::ll_protocol, max_len, and memcpy().
static int netdev_fetch_bustype | ( | struct net_device * | netdev, |
void * | data, | ||
size_t | len | ||
) | [static] |
Fetch bus type setting.
netdev | Network device |
data | Buffer to fill with setting data |
len | Length of buffer |
len | Length of setting data, or negative error |
Definition at line 154 of file netdev_settings.c.
References assert, device_description::bus_type, BUS_TYPE_EFI, BUS_TYPE_EISA, BUS_TYPE_HV, BUS_TYPE_ISA, BUS_TYPE_ISAPNP, BUS_TYPE_MCA, BUS_TYPE_PCI, BUS_TYPE_TAP, BUS_TYPE_USB, BUS_TYPE_XEN, device::desc, net_device::dev, ENOENT, strlen(), and strncpy().
{ static const char *bustypes[] = { [BUS_TYPE_PCI] = "PCI", [BUS_TYPE_ISAPNP] = "ISAPNP", [BUS_TYPE_EISA] = "EISA", [BUS_TYPE_MCA] = "MCA", [BUS_TYPE_ISA] = "ISA", [BUS_TYPE_TAP] = "TAP", [BUS_TYPE_EFI] = "EFI", [BUS_TYPE_XEN] = "XEN", [BUS_TYPE_HV] = "HV", [BUS_TYPE_USB] = "USB", }; struct device_description *desc = &netdev->dev->desc; const char *bustype; assert ( desc->bus_type < ( sizeof ( bustypes ) / sizeof ( bustypes[0] ) ) ); bustype = bustypes[desc->bus_type]; if ( ! bustype ) return -ENOENT; strncpy ( data, bustype, len ); return strlen ( bustype ); }
static int netdev_fetch_busloc | ( | struct net_device * | netdev, |
void * | data, | ||
size_t | len | ||
) | [static] |
Fetch bus location setting.
netdev | Network device |
data | Buffer to fill with setting data |
len | Length of buffer |
len | Length of setting data, or negative error |
Definition at line 188 of file netdev_settings.c.
References cpu_to_be32, device::desc, net_device::dev, device_description::location, and memcpy().
static int netdev_fetch_busid | ( | struct net_device * | netdev, |
void * | data, | ||
size_t | len | ||
) | [static] |
Fetch bus ID setting.
netdev | Network device |
data | Buffer to fill with setting data |
len | Length of buffer |
len | Length of setting data, or negative error |
Definition at line 208 of file netdev_settings.c.
References device_description::bus_type, device::desc, net_device::dev, device_description::device, dhcp_netdev_desc::device, htons, memcpy(), dhcp_netdev_desc::type, device_description::vendor, and dhcp_netdev_desc::vendor.
{ struct device_description *desc = &netdev->dev->desc; struct dhcp_netdev_desc dhcp_desc; dhcp_desc.type = desc->bus_type; dhcp_desc.vendor = htons ( desc->vendor ); dhcp_desc.device = htons ( desc->device ); if ( len > sizeof ( dhcp_desc ) ) len = sizeof ( dhcp_desc ); memcpy ( data, &dhcp_desc, len ); return sizeof ( dhcp_desc ); }
static int netdev_fetch_chip | ( | struct net_device * | netdev, |
void * | data, | ||
size_t | len | ||
) | [static] |
Fetch chip setting.
netdev | Network device |
data | Buffer to fill with setting data |
len | Length of buffer |
len | Length of setting data, or negative error |
Definition at line 230 of file netdev_settings.c.
References net_device::dev, device::driver_name, strlen(), and strncpy().
static int netdev_fetch_ifname | ( | struct net_device * | netdev, |
void * | data, | ||
size_t | len | ||
) | [static] |
Fetch ifname setting.
netdev | Network device |
data | Buffer to fill with setting data |
len | Length of buffer |
len | Length of setting data, or negative error |
Definition at line 246 of file netdev_settings.c.
References net_device::name, strlen(), and strncpy().
static int netdev_store | ( | struct settings * | settings, |
const struct setting * | setting, | ||
const void * | data, | ||
size_t | len | ||
) | [static] |
Store value of network device setting.
settings | Settings block |
setting | Setting to store |
data | Setting data, or NULL to clear setting |
len | Length of setting data |
rc | Return status code |
Definition at line 297 of file netdev_settings.c.
References container_of, ENOTSUP, generic_settings_store(), netdev, netdev_setting_operations, op, netdev_setting_operation::setting, setting_cmp(), and netdev_setting_operation::store.
{ struct net_device *netdev = container_of ( settings, struct net_device, settings.settings ); struct netdev_setting_operation *op; unsigned int i; /* Handle network device-specific settings */ for ( i = 0 ; i < ( sizeof ( netdev_setting_operations ) / sizeof ( netdev_setting_operations[0] ) ) ; i++ ) { op = &netdev_setting_operations[i]; if ( setting_cmp ( setting, op->setting ) == 0 ) { if ( op->store ) { return op->store ( netdev, data, len ); } else { return -ENOTSUP; } } } return generic_settings_store ( settings, setting, data, len ); }
static int netdev_fetch | ( | struct settings * | settings, |
struct setting * | setting, | ||
void * | data, | ||
size_t | len | ||
) | [static] |
Fetch value of network device setting.
settings | Settings block |
setting | Setting to fetch |
data | Buffer to fill with setting data |
len | Length of buffer |
len | Length of setting data, or negative error |
Definition at line 330 of file netdev_settings.c.
References container_of, netdev_setting_operation::fetch, generic_settings_fetch(), netdev, netdev_setting_operations, op, netdev_setting_operation::setting, and setting_cmp().
{ struct net_device *netdev = container_of ( settings, struct net_device, settings.settings ); struct netdev_setting_operation *op; unsigned int i; /* Handle network device-specific settings */ for ( i = 0 ; i < ( sizeof ( netdev_setting_operations ) / sizeof ( netdev_setting_operations[0] ) ) ; i++ ) { op = &netdev_setting_operations[i]; if ( setting_cmp ( setting, op->setting ) == 0 ) return op->fetch ( netdev, data, len ); } return generic_settings_fetch ( settings, setting, data, len ); }
static void netdev_clear | ( | struct settings * | settings | ) | [static] |
Clear network device settings.
settings | Settings block |
Definition at line 353 of file netdev_settings.c.
References generic_settings_clear().
{ generic_settings_clear ( settings ); }
static struct settings* netdev_redirect | ( | struct settings * | settings | ) | [static, read] |
Redirect "netX" settings block.
settings | Settings block |
settings | Underlying settings block |
Definition at line 370 of file netdev_settings.c.
References last_opened_netdev(), netdev, netdev_settings(), and net_device::settings.
{ struct net_device *netdev; /* Redirect to most recently opened network device */ netdev = last_opened_netdev(); if ( netdev ) { return netdev_settings ( netdev ); } else { return settings; } }
static void netdev_redirect_settings_init | ( | void | ) | [static] |
Initialise "netX" settings.
Definition at line 396 of file netdev_settings.c.
References DBG, NULL, rc, register_settings(), and strerror().
{ int rc; if ( ( rc = register_settings ( &netdev_redirect_settings, NULL, "netX" ) ) != 0 ) { DBG ( "Could not register netX settings: %s\n", strerror ( rc ) ); return; } }
"netX" settings initialiser
static int apply_netdev_settings | ( | void | ) | [static] |
Apply network device settings.
rc | Return status code |
Definition at line 417 of file netdev_settings.c.
References DBGC, fetch_uintz_setting(), for_each_netdev, ll_protocol::ll_header_len, net_device::ll_protocol, net_device::max_pkt_len, mtu, net_device::mtu, net_device::name, netdev, netdev_close(), netdev_is_open(), netdev_open(), netdev_settings(), rc, and strerror().
{ struct net_device *netdev; struct settings *settings; struct ll_protocol *ll_protocol; size_t max_mtu; size_t old_mtu; size_t mtu; int rc; /* Process settings for each network device */ for_each_netdev ( netdev ) { /* Get network device settings */ settings = netdev_settings ( netdev ); /* Get MTU */ mtu = fetch_uintz_setting ( settings, &mtu_setting ); /* Do nothing unless MTU is specified */ if ( ! mtu ) continue; /* Limit MTU to maximum supported by hardware */ ll_protocol = netdev->ll_protocol; max_mtu = ( netdev->max_pkt_len - ll_protocol->ll_header_len ); if ( mtu > max_mtu ) { DBGC ( netdev, "NETDEV %s cannot support MTU %zd (max " "%zd)\n", netdev->name, mtu, max_mtu ); mtu = max_mtu; } /* Update maximum packet length */ old_mtu = netdev->mtu; netdev->mtu = mtu; if ( mtu != old_mtu ) { DBGC ( netdev, "NETDEV %s MTU is %zd\n", netdev->name, mtu ); } /* Close and reopen network device if MTU has increased */ if ( netdev_is_open ( netdev ) && ( mtu > old_mtu ) ) { netdev_close ( netdev ); if ( ( rc = netdev_open ( netdev ) ) != 0 ) { DBGC ( netdev, "NETDEV %s could not reopen: " "%s\n", netdev->name, strerror ( rc ) ); return rc; } } } return 0; }
struct netdev_setting_operation netdev_setting_operations[] [static] |
{ { &mac_setting, netdev_store_mac, netdev_fetch_mac }, { &hwaddr_setting, NULL, netdev_fetch_hwaddr }, { &bustype_setting, NULL, netdev_fetch_bustype }, { &busloc_setting, NULL, netdev_fetch_busloc }, { &busid_setting, NULL, netdev_fetch_busid }, { &chip_setting, NULL, netdev_fetch_chip }, { &ifname_setting, NULL, netdev_fetch_ifname }, }
Network device settings.
Definition at line 278 of file netdev_settings.c.
Referenced by netdev_fetch(), and netdev_store().
{ .store = netdev_store, .fetch = netdev_fetch, .clear = netdev_clear, }
Network device configuration settings operations.
Definition at line 358 of file netdev_settings.c.
Referenced by netdev_settings_init().
struct settings_operations netdev_redirect_settings_operations [static] |
{ .redirect = netdev_redirect, }
"netX" settings operations
Definition at line 383 of file netdev_settings.c.
struct settings netdev_redirect_settings [static] |
{ .refcnt = NULL, .siblings = LIST_HEAD_INIT ( netdev_redirect_settings.siblings ), .children = LIST_HEAD_INIT ( netdev_redirect_settings.children ), .op = &netdev_redirect_settings_operations, }
"netX" settings
Definition at line 388 of file netdev_settings.c.
struct settings_applicator netdev_applicator __settings_applicator |
{ .apply = apply_netdev_settings, }
Network device settings applicator.
Definition at line 471 of file netdev_settings.c.