iPXE
Data Structures | Functions | Variables
netdev_settings.c File Reference

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)
 
const struct setting mac_setting __setting (SETTING_NETDEV, mac)
 Network device predefined settings. More...
 
const struct setting hwaddr_setting __setting (SETTING_NETDEV, hwaddr)
 
const struct setting bustype_setting __setting (SETTING_NETDEV, bustype)
 
const struct setting busloc_setting __setting (SETTING_NETDEV, busloc)
 
const struct setting busid_setting __setting (SETTING_NETDEV, busid)
 
const struct setting linktype_setting __setting (SETTING_NETDEV, linktype)
 
const struct setting chip_setting __setting (SETTING_NETDEV, chip)
 
const struct setting ifname_setting __setting (SETTING_NETDEV, ifname)
 
const 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. More...
 
static int netdev_fetch_mac (struct net_device *netdev, void *data, size_t len)
 Fetch link-layer address setting. More...
 
static int netdev_fetch_hwaddr (struct net_device *netdev, void *data, size_t len)
 Fetch hardware address setting. More...
 
static int netdev_fetch_bustype (struct net_device *netdev, void *data, size_t len)
 Fetch bus type setting. More...
 
static int netdev_fetch_busloc (struct net_device *netdev, void *data, size_t len)
 Fetch bus location setting. More...
 
static int netdev_fetch_busid (struct net_device *netdev, void *data, size_t len)
 Fetch bus ID setting. More...
 
static int netdev_fetch_linktype (struct net_device *netdev, void *data, size_t len)
 Fetch link layer type setting. More...
 
static int netdev_fetch_chip (struct net_device *netdev, void *data, size_t len)
 Fetch chip setting. More...
 
static int netdev_fetch_ifname (struct net_device *netdev, void *data, size_t len)
 Fetch ifname setting. More...
 
static int netdev_store (struct settings *settings, const struct setting *setting, const void *data, size_t len)
 Store value of network device setting. More...
 
static int netdev_fetch (struct settings *settings, struct setting *setting, void *data, size_t len)
 Fetch value of network device setting. More...
 
static void netdev_clear (struct settings *settings)
 Clear network device settings. More...
 
static struct settingsnetdev_redirect (struct settings *settings)
 Redirect "netX" settings block. More...
 
static void netdev_redirect_settings_init (void)
 Initialise "netX" settings. More...
 
struct init_fn netdev_redirect_settings_init_fn __init_fn (INIT_LATE)
 "netX" settings initialiser More...
 
static int apply_netdev_settings (void)
 Apply network device settings. More...
 

Variables

static struct netdev_setting_operation netdev_setting_operations []
 Network device settings. More...
 
struct settings_operations netdev_settings_operations
 Network device configuration settings operations. More...
 
static struct settings_operations netdev_redirect_settings_operations
 "netX" settings operations More...
 
static struct settings netdev_redirect_settings
 "netX" settings More...
 
struct settings_applicator netdev_applicator __settings_applicator
 Network device settings applicator. More...
 

Detailed Description

Network device configuration settings.

Definition in file netdev_settings.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ __setting() [1/9]

const struct setting mac_setting __setting ( SETTING_NETDEV  ,
mac   
)

Network device predefined settings.

◆ __setting() [2/9]

const struct setting hwaddr_setting __setting ( SETTING_NETDEV  ,
hwaddr   
)

◆ __setting() [3/9]

const struct setting bustype_setting __setting ( SETTING_NETDEV  ,
bustype   
)

◆ __setting() [4/9]

const struct setting busloc_setting __setting ( SETTING_NETDEV  ,
busloc   
)

◆ __setting() [5/9]

const struct setting busid_setting __setting ( SETTING_NETDEV  ,
busid   
)

◆ __setting() [6/9]

const struct setting linktype_setting __setting ( SETTING_NETDEV  ,
linktype   
)

◆ __setting() [7/9]

const struct setting chip_setting __setting ( SETTING_NETDEV  ,
chip   
)

◆ __setting() [8/9]

const struct setting ifname_setting __setting ( SETTING_NETDEV  ,
ifname   
)

◆ __setting() [9/9]

const struct setting mtu_setting __setting ( SETTING_NETDEV  ,
mtu   
)

◆ netdev_store_mac()

static int netdev_store_mac ( struct net_device netdev,
const void *  data,
size_t  len 
)
static

Store link-layer address setting.

Parameters
netdevNetwork device
dataSetting data, or NULL to clear setting
lenLength of setting data
Return values
rcReturn status code

Definition at line 98 of file netdev_settings.c.

99  {
101 
102  /* Record new MAC address */
103  if ( data ) {
104  if ( len != netdev->ll_protocol->ll_addr_len )
105  return -EINVAL;
106  memcpy ( netdev->ll_addr, data, len );
107  } else {
108  /* Reset MAC address if clearing setting */
110  }
111 
112  return 0;
113 }
#define EINVAL
Invalid argument.
Definition: errno.h:428
uint8_t ll_addr_len
Link-layer address length.
Definition: netdevice.h:198
void(* init_addr)(const void *hw_addr, void *ll_addr)
Initialise link-layer address.
Definition: netdevice.h:150
A link-layer protocol.
Definition: netdevice.h:114
void * memcpy(void *dest, const void *src, size_t len) __nonnull
static struct net_device * netdev
Definition: gdbudp.c:52
uint32_t len
Length.
Definition: ena.h:14
uint8_t data[48]
Additional event data.
Definition: ena.h:22
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:387
uint8_t hw_addr[MAX_HW_ADDR_LEN]
Hardware address.
Definition: netdevice.h:381
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition: netdevice.h:372

References data, EINVAL, net_device::hw_addr, ll_protocol::init_addr, len, net_device::ll_addr, ll_protocol::ll_addr_len, net_device::ll_protocol, memcpy(), and netdev.

◆ netdev_fetch_mac()

static int netdev_fetch_mac ( struct net_device netdev,
void *  data,
size_t  len 
)
static

Fetch link-layer address setting.

Parameters
netdevNetwork device
dataBuffer to fill with setting data
lenLength of buffer
Return values
lenLength of setting data, or negative error

Definition at line 123 of file netdev_settings.c.

124  {
126 
127  if ( len > max_len )
128  len = max_len;
129  memcpy ( data, netdev->ll_addr, len );
130  return max_len;
131 }
uint8_t ll_addr_len
Link-layer address length.
Definition: netdevice.h:198
uint16_t max_len
Maximum length (in bytes)
Definition: ntlm.h:18
void * memcpy(void *dest, const void *src, size_t len) __nonnull
static struct net_device * netdev
Definition: gdbudp.c:52
uint32_t len
Length.
Definition: ena.h:14
uint8_t data[48]
Additional event data.
Definition: ena.h:22
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:387
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition: netdevice.h:372

References data, len, net_device::ll_addr, ll_protocol::ll_addr_len, net_device::ll_protocol, max_len, memcpy(), and netdev.

◆ netdev_fetch_hwaddr()

static int netdev_fetch_hwaddr ( struct net_device netdev,
void *  data,
size_t  len 
)
static

Fetch hardware address setting.

Parameters
netdevNetwork device
dataBuffer to fill with setting data
lenLength of buffer
Return values
lenLength of setting data, or negative error

Definition at line 141 of file netdev_settings.c.

142  {
144 
145  if ( len > max_len )
146  len = max_len;
147  memcpy ( data, netdev->hw_addr, len );
148  return max_len;
149 }
uint16_t max_len
Maximum length (in bytes)
Definition: ntlm.h:18
void * memcpy(void *dest, const void *src, size_t len) __nonnull
uint8_t hw_addr_len
Hardware address length.
Definition: netdevice.h:196
static struct net_device * netdev
Definition: gdbudp.c:52
uint32_t len
Length.
Definition: ena.h:14
uint8_t data[48]
Additional event data.
Definition: ena.h:22
uint8_t hw_addr[MAX_HW_ADDR_LEN]
Hardware address.
Definition: netdevice.h:381
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition: netdevice.h:372

References data, net_device::hw_addr, ll_protocol::hw_addr_len, len, net_device::ll_protocol, max_len, memcpy(), and netdev.

◆ netdev_fetch_bustype()

static int netdev_fetch_bustype ( struct net_device netdev,
void *  data,
size_t  len 
)
static

Fetch bus type setting.

Parameters
netdevNetwork device
dataBuffer to fill with setting data
lenLength of buffer
Return values
lenLength of setting data, or negative error

Definition at line 159 of file netdev_settings.c.

160  {
161  static const char *bustypes[] = {
162  [BUS_TYPE_PCI] = "PCI",
163  [BUS_TYPE_ISAPNP] = "ISAPNP",
164  [BUS_TYPE_EISA] = "EISA",
165  [BUS_TYPE_MCA] = "MCA",
166  [BUS_TYPE_ISA] = "ISA",
167  [BUS_TYPE_TAP] = "TAP",
168  [BUS_TYPE_EFI] = "EFI",
169  [BUS_TYPE_XEN] = "XEN",
170  [BUS_TYPE_HV] = "HV",
171  [BUS_TYPE_USB] = "USB",
172  };
173  struct device_description *desc = &netdev->dev->desc;
174  const char *bustype;
175 
176  assert ( desc->bus_type < ( sizeof ( bustypes ) /
177  sizeof ( bustypes[0] ) ) );
178  bustype = bustypes[desc->bus_type];
179  if ( ! bustype )
180  return -ENOENT;
181  strncpy ( data, bustype, len );
182  return strlen ( bustype );
183 }
uint64_t desc
Microcode descriptor list physical address.
Definition: ucode.h:12
#define ENOENT
No such file or directory.
Definition: errno.h:514
A hardware device description.
Definition: device.h:19
#define BUS_TYPE_MCA
MCA bus type.
Definition: device.h:52
char * strncpy(char *dest, const char *src, size_t max)
Copy string.
Definition: string.c:347
#define BUS_TYPE_ISA
ISA bus type.
Definition: device.h:55
#define BUS_TYPE_PCI
PCI bus type.
Definition: device.h:43
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static struct net_device * netdev
Definition: gdbudp.c:52
#define BUS_TYPE_EISA
EISA bus type.
Definition: device.h:49
size_t strlen(const char *src)
Get length of string.
Definition: string.c:243
#define BUS_TYPE_EFI
EFI bus type.
Definition: device.h:61
struct device * dev
Underlying hardware device.
Definition: netdevice.h:364
#define BUS_TYPE_TAP
TAP bus type.
Definition: device.h:58
uint32_t len
Length.
Definition: ena.h:14
uint8_t data[48]
Additional event data.
Definition: ena.h:22
struct device_description desc
Device description.
Definition: device.h:79
#define BUS_TYPE_XEN
Xen bus type.
Definition: device.h:64
#define BUS_TYPE_USB
USB bus type.
Definition: device.h:70
#define BUS_TYPE_HV
Hyper-V bus type.
Definition: device.h:67
#define BUS_TYPE_ISAPNP
ISAPnP bus type.
Definition: device.h:46

References assert(), 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, data, desc, device::desc, net_device::dev, ENOENT, len, netdev, strlen(), and strncpy().

◆ netdev_fetch_busloc()

static int netdev_fetch_busloc ( struct net_device netdev,
void *  data,
size_t  len 
)
static

Fetch bus location setting.

Parameters
netdevNetwork device
dataBuffer to fill with setting data
lenLength of buffer
Return values
lenLength of setting data, or negative error

Definition at line 193 of file netdev_settings.c.

194  {
195  struct device_description *desc = &netdev->dev->desc;
196  uint32_t busloc;
197 
198  busloc = cpu_to_be32 ( desc->location );
199  if ( len > sizeof ( busloc ) )
200  len = sizeof ( busloc );
201  memcpy ( data, &busloc, len );
202  return sizeof ( busloc );
203 }
uint64_t desc
Microcode descriptor list physical address.
Definition: ucode.h:12
A hardware device description.
Definition: device.h:19
void * memcpy(void *dest, const void *src, size_t len) __nonnull
static struct net_device * netdev
Definition: gdbudp.c:52
unsigned int uint32_t
Definition: stdint.h:12
struct device * dev
Underlying hardware device.
Definition: netdevice.h:364
#define cpu_to_be32(value)
Definition: byteswap.h:110
uint32_t len
Length.
Definition: ena.h:14
uint8_t data[48]
Additional event data.
Definition: ena.h:22
struct device_description desc
Device description.
Definition: device.h:79

References cpu_to_be32, data, desc, device::desc, net_device::dev, len, memcpy(), and netdev.

◆ netdev_fetch_busid()

static int netdev_fetch_busid ( struct net_device netdev,
void *  data,
size_t  len 
)
static

Fetch bus ID setting.

Parameters
netdevNetwork device
dataBuffer to fill with setting data
lenLength of buffer
Return values
lenLength of setting data, or negative error

Definition at line 213 of file netdev_settings.c.

214  {
215  struct device_description *desc = &netdev->dev->desc;
216  struct dhcp_netdev_desc dhcp_desc;
217 
218  dhcp_desc.type = desc->bus_type;
219  dhcp_desc.vendor = htons ( desc->vendor );
220  dhcp_desc.device = htons ( desc->device );
221  if ( len > sizeof ( dhcp_desc ) )
222  len = sizeof ( dhcp_desc );
223  memcpy ( data, &dhcp_desc, len );
224  return sizeof ( dhcp_desc );
225 }
uint8_t type
Bus type ID.
Definition: dhcp.h:448
uint64_t desc
Microcode descriptor list physical address.
Definition: ucode.h:12
A hardware device description.
Definition: device.h:19
void * memcpy(void *dest, const void *src, size_t len) __nonnull
static struct net_device * netdev
Definition: gdbudp.c:52
Network device descriptor.
Definition: dhcp.h:446
struct device * dev
Underlying hardware device.
Definition: netdevice.h:364
uint32_t len
Length.
Definition: ena.h:14
uint8_t data[48]
Additional event data.
Definition: ena.h:22
struct device_description desc
Device description.
Definition: device.h:79
#define htons(value)
Definition: byteswap.h:135

References data, desc, device::desc, net_device::dev, dhcp_netdev_desc::device, htons, len, memcpy(), netdev, dhcp_netdev_desc::type, and dhcp_netdev_desc::vendor.

◆ netdev_fetch_linktype()

static int netdev_fetch_linktype ( struct net_device netdev,
void *  data,
size_t  len 
)
static

Fetch link layer type setting.

Parameters
netdevNetwork device
dataBuffer to fill with setting data
lenLength of buffer
Return values
lenLength of setting data, or negative error

Definition at line 235 of file netdev_settings.c.

236  {
237  const char *linktype = netdev->ll_protocol->name;
238 
239  strncpy ( data, linktype, len );
240  return strlen ( linktype );
241 }
const char * name
Protocol name.
Definition: netdevice.h:116
char * strncpy(char *dest, const char *src, size_t max)
Copy string.
Definition: string.c:347
static struct net_device * netdev
Definition: gdbudp.c:52
size_t strlen(const char *src)
Get length of string.
Definition: string.c:243
uint32_t len
Length.
Definition: ena.h:14
uint8_t data[48]
Additional event data.
Definition: ena.h:22
linktype
Definition: 3c90x.h:240
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition: netdevice.h:372

References data, len, net_device::ll_protocol, ll_protocol::name, netdev, strlen(), and strncpy().

◆ netdev_fetch_chip()

static int netdev_fetch_chip ( struct net_device netdev,
void *  data,
size_t  len 
)
static

Fetch chip setting.

Parameters
netdevNetwork device
dataBuffer to fill with setting data
lenLength of buffer
Return values
lenLength of setting data, or negative error

Definition at line 251 of file netdev_settings.c.

252  {
253  const char *chip = netdev->dev->driver_name;
254 
255  strncpy ( data, chip, len );
256  return strlen ( chip );
257 }
char * strncpy(char *dest, const char *src, size_t max)
Copy string.
Definition: string.c:347
static struct net_device * netdev
Definition: gdbudp.c:52
const char * driver_name
Driver name.
Definition: device.h:77
size_t strlen(const char *src)
Get length of string.
Definition: string.c:243
struct device * dev
Underlying hardware device.
Definition: netdevice.h:364
uint32_t len
Length.
Definition: ena.h:14
uint8_t data[48]
Additional event data.
Definition: ena.h:22

References data, net_device::dev, device::driver_name, len, netdev, strlen(), and strncpy().

◆ netdev_fetch_ifname()

static int netdev_fetch_ifname ( struct net_device netdev,
void *  data,
size_t  len 
)
static

Fetch ifname setting.

Parameters
netdevNetwork device
dataBuffer to fill with setting data
lenLength of buffer
Return values
lenLength of setting data, or negative error

Definition at line 267 of file netdev_settings.c.

268  {
269  const char *ifname = netdev->name;
270 
271  strncpy ( data, ifname, len );
272  return strlen ( ifname );
273 }
char * strncpy(char *dest, const char *src, size_t max)
Copy string.
Definition: string.c:347
static struct net_device * netdev
Definition: gdbudp.c:52
size_t strlen(const char *src)
Get length of string.
Definition: string.c:243
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:362
uint32_t len
Length.
Definition: ena.h:14
uint8_t data[48]
Additional event data.
Definition: ena.h:22

References data, len, net_device::name, netdev, strlen(), and strncpy().

◆ netdev_store()

static int netdev_store ( struct settings settings,
const struct setting setting,
const void *  data,
size_t  len 
)
static

Store value of network device setting.

Parameters
settingsSettings block
settingSetting to store
dataSetting data, or NULL to clear setting
lenLength of setting data
Return values
rcReturn status code

Definition at line 319 of file netdev_settings.c.

321  {
322  struct net_device *netdev = container_of ( settings, struct net_device,
323  settings.settings );
325  unsigned int i;
326 
327  /* Handle network device-specific settings */
328  for ( i = 0 ; i < ( sizeof ( netdev_setting_operations ) /
329  sizeof ( netdev_setting_operations[0] ) ) ; i++ ) {
331  if ( setting_cmp ( setting, op->setting ) == 0 ) {
332  if ( op->store ) {
333  return op->store ( netdev, data, len );
334  } else {
335  return -ENOTSUP;
336  }
337  }
338  }
339 
341 }
static struct netdev_setting_operation netdev_setting_operations[]
Network device settings.
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
static struct net_device * netdev
Definition: gdbudp.c:52
A network device setting operation.
A network device.
Definition: netdevice.h:352
A settings block.
Definition: settings.h:132
A setting.
Definition: settings.h:23
static uint16_t struct vmbus_xfer_pages_operations * op
Definition: netvsc.h:327
uint32_t len
Length.
Definition: ena.h:14
int generic_settings_store(struct settings *settings, const struct setting *setting, const void *data, size_t len)
Store value of generic setting.
Definition: settings.c:126
uint8_t data[48]
Additional event data.
Definition: ena.h:22
int setting_cmp(const struct setting *a, const struct setting *b)
Compare two settings.
Definition: settings.c:1120

References container_of, data, ENOTSUP, generic_settings_store(), len, netdev, netdev_setting_operations, op, and setting_cmp().

◆ netdev_fetch()

static int netdev_fetch ( struct settings settings,
struct setting setting,
void *  data,
size_t  len 
)
static

Fetch value of network device setting.

Parameters
settingsSettings block
settingSetting to fetch
dataBuffer to fill with setting data
lenLength of buffer
Return values
lenLength of setting data, or negative error

Definition at line 352 of file netdev_settings.c.

353  {
354  struct net_device *netdev = container_of ( settings, struct net_device,
355  settings.settings );
357  unsigned int i;
358 
359  /* Handle network device-specific settings */
360  for ( i = 0 ; i < ( sizeof ( netdev_setting_operations ) /
361  sizeof ( netdev_setting_operations[0] ) ) ; i++ ) {
363  if ( setting_cmp ( setting, op->setting ) == 0 )
364  return op->fetch ( netdev, data, len );
365  }
366 
368 }
static struct netdev_setting_operation netdev_setting_operations[]
Network device settings.
int generic_settings_fetch(struct settings *settings, struct setting *setting, void *data, size_t len)
Fetch value of generic setting.
Definition: settings.c:178
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
static struct net_device * netdev
Definition: gdbudp.c:52
A network device setting operation.
A network device.
Definition: netdevice.h:352
A settings block.
Definition: settings.h:132
A setting.
Definition: settings.h:23
static uint16_t struct vmbus_xfer_pages_operations * op
Definition: netvsc.h:327
uint32_t len
Length.
Definition: ena.h:14
uint8_t data[48]
Additional event data.
Definition: ena.h:22
int setting_cmp(const struct setting *a, const struct setting *b)
Compare two settings.
Definition: settings.c:1120

References container_of, data, generic_settings_fetch(), len, netdev, netdev_setting_operations, op, and setting_cmp().

◆ netdev_clear()

static void netdev_clear ( struct settings settings)
static

Clear network device settings.

Parameters
settingsSettings block

Definition at line 375 of file netdev_settings.c.

375  {
377 }
void generic_settings_clear(struct settings *settings)
Clear generic settings block.
Definition: settings.c:207
A settings block.
Definition: settings.h:132

References generic_settings_clear().

◆ netdev_redirect()

static struct settings* netdev_redirect ( struct settings settings)
static

Redirect "netX" settings block.

Parameters
settingsSettings block
Return values
settingsUnderlying settings block

Definition at line 392 of file netdev_settings.c.

392  {
393  struct net_device *netdev;
394 
395  /* Redirect to "netX" network device */
397  if ( netdev ) {
398  return netdev_settings ( netdev );
399  } else {
400  return settings;
401  }
402 }
static struct settings * netdev_settings(struct net_device *netdev)
Get per-netdevice configuration settings block.
Definition: netdevice.h:583
static struct net_device * netdev
Definition: gdbudp.c:52
A network device.
Definition: netdevice.h:352
A settings block.
Definition: settings.h:132
const char * name
Name.
Definition: settings.h:136
struct net_device * find_netdev(const char *name)
Get network device by name.
Definition: netdevice.c:988
struct generic_settings settings
Configuration settings applicable to this device.
Definition: netdevice.h:428

References find_netdev(), settings::name, netdev, netdev_settings(), and net_device::settings.

◆ netdev_redirect_settings_init()

static void netdev_redirect_settings_init ( void  )
static

Initialise "netX" settings.

Definition at line 418 of file netdev_settings.c.

418  {
419  int rc;
420 
422  "netX" ) ) != 0 ) {
423  DBG ( "Could not register netX settings: %s\n",
424  strerror ( rc ) );
425  return;
426  }
427 }
static struct settings netdev_redirect_settings
"netX" settings
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
int register_settings(struct settings *settings, struct settings *parent, const char *name)
Register settings block.
Definition: settings.c:475
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References DBG, netdev_redirect_settings, NULL, rc, register_settings(), and strerror().

◆ __init_fn()

struct init_fn netdev_redirect_settings_init_fn __init_fn ( INIT_LATE  )

"netX" settings initialiser

◆ apply_netdev_settings()

static int apply_netdev_settings ( void  )
static

Apply network device settings.

Return values
rcReturn status code

Definition at line 439 of file netdev_settings.c.

439  {
440  struct net_device *netdev;
441  struct settings *settings;
442  struct ll_protocol *ll_protocol;
443  size_t max_mtu;
444  size_t old_mtu;
445  size_t mtu;
446  int rc;
447 
448  /* Process settings for each network device */
449  for_each_netdev ( netdev ) {
450 
451  /* Get network device settings */
453 
454  /* Get MTU */
455  mtu = fetch_uintz_setting ( settings, &mtu_setting );
456 
457  /* Do nothing unless MTU is specified */
458  if ( ! mtu )
459  continue;
460 
461  /* Limit MTU to maximum supported by hardware */
463  max_mtu = ( netdev->max_pkt_len - ll_protocol->ll_header_len );
464  if ( mtu > max_mtu ) {
465  DBGC ( netdev, "NETDEV %s cannot support MTU %zd (max "
466  "%zd)\n", netdev->name, mtu, max_mtu );
467  mtu = max_mtu;
468  }
469 
470  /* Update maximum packet length */
471  old_mtu = netdev->mtu;
472  netdev->mtu = mtu;
473  if ( mtu != old_mtu ) {
474  DBGC ( netdev, "NETDEV %s MTU is %zd\n",
475  netdev->name, mtu );
476  }
477 
478  /* Close and reopen network device if MTU has increased */
479  if ( netdev_is_open ( netdev ) && ( mtu > old_mtu ) ) {
480  netdev_close ( netdev );
481  if ( ( rc = netdev_open ( netdev ) ) != 0 ) {
482  DBGC ( netdev, "NETDEV %s could not reopen: "
483  "%s\n", netdev->name, strerror ( rc ) );
484  return rc;
485  }
486  }
487  }
488 
489  return 0;
490 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
uint8_t ll_header_len
Link-layer header length.
Definition: netdevice.h:200
size_t mtu
Maximum transmission unit length.
Definition: netdevice.h:415
#define DBGC(...)
Definition: compiler.h:505
static struct settings * netdev_settings(struct net_device *netdev)
Get per-netdevice configuration settings block.
Definition: netdevice.h:583
A link-layer protocol.
Definition: netdevice.h:114
static int netdev_is_open(struct net_device *netdev)
Check whether or not network device is open.
Definition: netdevice.h:658
static struct net_device * netdev
Definition: gdbudp.c:52
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
#define for_each_netdev(netdev)
Iterate over all network devices.
Definition: netdevice.h:543
A network device.
Definition: netdevice.h:352
A settings block.
Definition: settings.h:132
unsigned long fetch_uintz_setting(struct settings *settings, const struct setting *setting)
Fetch value of unsigned integer setting, or zero.
Definition: settings.c:1068
void netdev_close(struct net_device *netdev)
Close network device.
Definition: netdevice.c:895
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:362
uint32_t mtu
Maximum MTU.
Definition: ena.h:28
size_t max_pkt_len
Maximum packet length.
Definition: netdevice.h:409
int netdev_open(struct net_device *netdev)
Open network device.
Definition: netdevice.c:861
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition: netdevice.h:372

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().

Variable Documentation

◆ netdev_setting_operations

struct netdev_setting_operation netdev_setting_operations[]
static
Initial value:
= {
{ &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 },
{ &linktype_setting, NULL, netdev_fetch_linktype },
{ &chip_setting, NULL, netdev_fetch_chip },
{ &ifname_setting, NULL, netdev_fetch_ifname },
}
static int netdev_fetch_mac(struct net_device *netdev, void *data, size_t len)
Fetch link-layer address setting.
static int netdev_fetch_chip(struct net_device *netdev, void *data, size_t len)
Fetch chip setting.
static int netdev_fetch_busid(struct net_device *netdev, void *data, size_t len)
Fetch bus ID setting.
static int netdev_fetch_linktype(struct net_device *netdev, void *data, size_t len)
Fetch link layer type 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_ifname(struct net_device *netdev, void *data, size_t len)
Fetch ifname setting.
static int netdev_store_mac(struct net_device *netdev, const void *data, size_t len)
Store link-layer address setting.
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
static int netdev_fetch_busloc(struct net_device *netdev, void *data, size_t len)
Fetch bus location setting.

Network device settings.

Definition at line 299 of file netdev_settings.c.

Referenced by netdev_fetch(), and netdev_store().

◆ netdev_settings_operations

struct settings_operations netdev_settings_operations
Initial value:
= {
.store = netdev_store,
.fetch = netdev_fetch,
.clear = netdev_clear,
}
static void netdev_clear(struct settings *settings)
Clear network device settings.
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.

Network device configuration settings operations.

Definition at line 380 of file netdev_settings.c.

Referenced by netdev_settings_init().

◆ netdev_redirect_settings_operations

struct settings_operations netdev_redirect_settings_operations
static
Initial value:
= {
.redirect = netdev_redirect,
}
static struct settings * netdev_redirect(struct settings *settings)
Redirect "netX" settings block.

"netX" settings operations

Definition at line 405 of file netdev_settings.c.

◆ netdev_redirect_settings

struct settings netdev_redirect_settings
static
Initial value:
= {
.refcnt = NULL,
}
static struct settings netdev_redirect_settings
"netX" settings
static struct settings_operations netdev_redirect_settings_operations
"netX" settings operations
struct list_head siblings
Sibling settings blocks.
Definition: settings.h:140
struct list_head children
Child settings blocks.
Definition: settings.h:142
#define LIST_HEAD_INIT(list)
Initialise a static list head.
Definition: list.h:30
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

"netX" settings

Definition at line 410 of file netdev_settings.c.

Referenced by netdev_redirect_settings_init().

◆ __settings_applicator

struct settings_applicator netdev_applicator __settings_applicator
Initial value:
= {
}
static int apply_netdev_settings(void)
Apply network device settings.

Network device settings applicator.

Definition at line 493 of file netdev_settings.c.