iPXE
Functions
ifmgmt.h File Reference

Network interface management. More...

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
int ifopen (struct net_device *netdev)
 Open network device. More...
 
int ifconf (struct net_device *netdev, struct net_device_configurator *configurator)
 Perform network device configuration. More...
 
void ifclose (struct net_device *netdev)
 Close network device. More...
 
void ifstat (struct net_device *netdev)
 Print status of network device. More...
 
int iflinkwait (struct net_device *netdev, unsigned long timeout)
 Wait for link-up, with status indication. More...
 

Detailed Description

Network interface management.

Definition in file ifmgmt.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ ifopen()

int ifopen ( struct net_device netdev)

Open network device.

Parameters
netdevNetwork device
Return values
rcReturn status code

Definition at line 65 of file ifmgmt.c.

65  {
66  int rc;
67 
68  if ( ( rc = netdev_open ( netdev ) ) != 0 ) {
69  printf ( "Could not open %s: %s\n",
70  netdev->name, strerror ( rc ) );
71  return rc;
72  }
73 
74  return 0;
75 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
static struct net_device * netdev
Definition: gdbudp.c:52
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:358
int netdev_open(struct net_device *netdev)
Open network device.
Definition: netdevice.c:767

References net_device::name, netdev, netdev_open(), printf(), rc, and strerror().

Referenced by iflinkwait(), ifopen_payload(), loopback_test(), and netboot().

◆ ifconf()

int ifconf ( struct net_device netdev,
struct net_device_configurator configurator 
)

Perform network device configuration.

Parameters
netdevNetwork device
configuratorNetwork device configurator, or NULL to use all
Return values
rcReturn status code

Definition at line 269 of file ifmgmt.c.

270  {
271  int rc;
272 
273  /* Ensure device is open and link is up */
274  if ( ( rc = iflinkwait ( netdev, LINK_WAIT_TIMEOUT ) ) != 0 )
275  return rc;
276 
277  /* Start configuration */
278  if ( configurator ) {
279  if ( ( rc = netdev_configure ( netdev, configurator ) ) != 0 ) {
280  printf ( "Could not configure %s via %s: %s\n",
281  netdev->name, configurator->name,
282  strerror ( rc ) );
283  return rc;
284  }
285  } else {
286  if ( ( rc = netdev_configure_all ( netdev ) ) != 0 ) {
287  printf ( "Could not configure %s: %s\n",
288  netdev->name, strerror ( rc ) );
289  return rc;
290  }
291  }
292 
293  /* Wait for configuration to complete */
294  printf ( "Configuring %s%s%s(%s %s)",
295  ( configurator ? "[" : "" ),
296  ( configurator ? configurator->name : "" ),
297  ( configurator ? "] " : "" ),
299  return ifpoller_wait ( netdev, configurator, 0, ifconf_progress );
300 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const char * name
Name.
Definition: netdevice.h:311
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
int netdev_configure(struct net_device *netdev, struct net_device_configurator *configurator)
Start network device configuration.
Definition: netdevice.c:1219
int netdev_configure_all(struct net_device *netdev)
Start network device configuration via all supported configurators.
Definition: netdevice.c:1259
#define LINK_WAIT_TIMEOUT
Default time to wait for link-up.
Definition: ifmgmt.c:46
static struct net_device * netdev
Definition: gdbudp.c:52
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:358
static int ifconf_progress(struct ifpoller *ifpoller)
Check configuration progress.
Definition: ifmgmt.c:239
int iflinkwait(struct net_device *netdev, unsigned long timeout)
Wait for link-up, with status indication.
Definition: ifmgmt.c:216
const char *(* ntoa)(const void *ll_addr)
Transcribe link-layer address.
Definition: netdevice.h:163
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:381
static int ifpoller_wait(struct net_device *netdev, struct net_device_configurator *configurator, unsigned long timeout, int(*progress)(struct ifpoller *ifpoller))
Poll network device until completion.
Definition: ifmgmt.c:177
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition: netdevice.h:366

References net_device_configuration::configurator, ifconf_progress(), iflinkwait(), ifpoller_wait(), LINK_WAIT_TIMEOUT, net_device::ll_addr, net_device::ll_protocol, net_device_configurator::name, net_device::name, netdev, netdev_configure(), netdev_configure_all(), ll_protocol::ntoa, printf(), rc, and strerror().

Referenced by ifconf_payload(), and netboot().

◆ ifclose()

void ifclose ( struct net_device netdev)

Close network device.

Parameters
netdevNetwork device

Definition at line 82 of file ifmgmt.c.

82  {
83  netdev_close ( netdev );
84 }
static struct net_device * netdev
Definition: gdbudp.c:52
void netdev_close(struct net_device *netdev)
Close network device.
Definition: netdevice.c:801

References netdev, and netdev_close().

Referenced by close_all_netdevs(), and ifclose_payload().

◆ ifstat()

void ifstat ( struct net_device netdev)

Print status of network device.

Parameters
netdevNetwork device

Definition at line 110 of file ifmgmt.c.

110  {
111  printf ( "%s: %s using %s on %s (%s)\n"
112  " [Link:%s%s, TX:%d TXE:%d RX:%d RXE:%d]\n",
115  ( netdev_is_open ( netdev ) ? "open" : "closed" ),
116  ( netdev_link_ok ( netdev ) ? "up" : "down" ),
117  ( netdev_link_blocked ( netdev ) ? " (blocked)" : "" ),
120  if ( ! netdev_link_ok ( netdev ) ) {
121  printf ( " [Link status: %s]\n",
122  strerror ( netdev->link_rc ) );
123  }
124  ifstat_errors ( &netdev->tx_stats, "TXE" );
125  ifstat_errors ( &netdev->rx_stats, "RXE" );
126 }
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
static void ifstat_errors(struct net_device_stats *stats, const char *prefix)
Print network device error breakdown.
Definition: ifmgmt.c:92
char name[40]
Name.
Definition: device.h:75
static int netdev_link_blocked(struct net_device *netdev)
Check link block state of network device.
Definition: netdevice.h:641
static const char * netdev_addr(struct net_device *netdev)
Get printable network device link-layer address.
Definition: netdevice.h:521
struct net_device_stats tx_stats
TX statistics.
Definition: netdevice.h:417
static int netdev_is_open(struct net_device *netdev)
Check whether or not network device is open.
Definition: netdevice.h:652
int link_rc
Link status code.
Definition: netdevice.h:395
static int netdev_link_ok(struct net_device *netdev)
Check link state of network device.
Definition: netdevice.h:630
static struct net_device * netdev
Definition: gdbudp.c:52
const char * driver_name
Driver name.
Definition: device.h:77
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
struct net_device_stats rx_stats
RX statistics.
Definition: netdevice.h:419
unsigned int bad
Count of error completions.
Definition: netdevice.h:291
struct device * dev
Underlying hardware device.
Definition: netdevice.h:360
unsigned int good
Count of successful completions.
Definition: netdevice.h:289
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:358

References net_device_stats::bad, net_device::dev, device::driver_name, net_device_stats::good, ifstat_errors(), net_device::link_rc, device::name, net_device::name, netdev, netdev_addr(), netdev_is_open(), netdev_link_blocked(), netdev_link_ok(), printf(), net_device::rx_stats, strerror(), and net_device::tx_stats.

Referenced by ifstat_payload(), iwstat(), loopback_test(), and netboot().

◆ iflinkwait()

int iflinkwait ( struct net_device netdev,
unsigned long  timeout 
)

Wait for link-up, with status indication.

Parameters
netdevNetwork device
timeoutTimeout period, in ticks

Definition at line 216 of file ifmgmt.c.

216  {
217  int rc;
218 
219  /* Ensure device is open */
220  if ( ( rc = ifopen ( netdev ) ) != 0 )
221  return rc;
222 
223  /* Return immediately if link is already up */
224  netdev_poll ( netdev );
225  if ( netdev_link_ok ( netdev ) )
226  return 0;
227 
228  /* Wait for link-up */
229  printf ( "Waiting for link-up on %s", netdev->name );
231 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
static int netdev_link_ok(struct net_device *netdev)
Check link state of network device.
Definition: netdevice.h:630
static struct net_device * netdev
Definition: gdbudp.c:52
void netdev_poll(struct net_device *netdev)
Poll for completed and received packets on network device.
Definition: netdevice.c:523
int ifopen(struct net_device *netdev)
Open network device.
Definition: ifmgmt.c:65
static int iflinkwait_progress(struct ifpoller *ifpoller)
Check link-up progress.
Definition: ifmgmt.c:198
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:358
void timeout(int)
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
static int ifpoller_wait(struct net_device *netdev, struct net_device_configurator *configurator, unsigned long timeout, int(*progress)(struct ifpoller *ifpoller))
Poll network device until completion.
Definition: ifmgmt.c:177

References iflinkwait_progress(), ifopen(), ifpoller_wait(), net_device::name, netdev, netdev_link_ok(), netdev_poll(), NULL, printf(), rc, and timeout().

Referenced by ifconf(), and loopback_test().