iPXE
Data Structures | Macros | Functions | Variables
ifmgmt.c File Reference

Network interface management. More...

#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <ipxe/console.h>
#include <ipxe/netdevice.h>
#include <ipxe/device.h>
#include <ipxe/job.h>
#include <ipxe/monojob.h>
#include <ipxe/timer.h>
#include <ipxe/errortab.h>
#include <usr/ifmgmt.h>

Go to the source code of this file.

Data Structures

struct  ifpoller
 Network device poller. More...
 

Macros

#define LINK_WAIT_TIMEOUT   ( 15 * TICKS_PER_SEC )
 Default time to wait for link-up. More...
 
#define EADDRNOTAVAIL_CONFIG   __einfo_error ( EINFO_EADDRNOTAVAIL_CONFIG )
 Default unsuccessful configuration status code. More...
 
#define EINFO_EADDRNOTAVAIL_CONFIG
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
int ifopen (struct net_device *netdev)
 Open network device. More...
 
void ifclose (struct net_device *netdev)
 Close network device. More...
 
static void ifstat_errors (struct net_device_stats *stats, const char *prefix)
 Print network device error breakdown. More...
 
void ifstat (struct net_device *netdev)
 Print status of network device. More...
 
static int ifpoller_progress (struct ifpoller *ifpoller, struct job_progress *progress __unused)
 Report network device poller progress. More...
 
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. More...
 
static int iflinkwait_progress (struct ifpoller *ifpoller)
 Check link-up progress. More...
 
int iflinkwait (struct net_device *netdev, unsigned long timeout, int verbose)
 Wait for link-up, with status indication. More...
 
static int ifconf_progress (struct ifpoller *ifpoller)
 Check configuration progress. More...
 
int ifconf (struct net_device *netdev, struct net_device_configurator *configurator, unsigned long timeout)
 Perform network device configuration. More...
 

Variables

struct errortab ifmgmt_errors [] __errortab
 Human-readable error message. More...
 
static struct interface_operation ifpoller_job_op []
 Network device poller operations. More...
 
static struct interface_descriptor ifpoller_job_desc
 Network device poller descriptor. More...
 

Detailed Description

Network interface management.

Definition in file ifmgmt.c.

Macro Definition Documentation

◆ LINK_WAIT_TIMEOUT

#define LINK_WAIT_TIMEOUT   ( 15 * TICKS_PER_SEC )

Default time to wait for link-up.

Definition at line 46 of file ifmgmt.c.

◆ EADDRNOTAVAIL_CONFIG

#define EADDRNOTAVAIL_CONFIG   __einfo_error ( EINFO_EADDRNOTAVAIL_CONFIG )

Default unsuccessful configuration status code.

Definition at line 49 of file ifmgmt.c.

◆ EINFO_EADDRNOTAVAIL_CONFIG

#define EINFO_EADDRNOTAVAIL_CONFIG
Value:
"No configuration methods succeeded" )
#define EINFO_EADDRNOTAVAIL
Definition: errno.h:309
#define __einfo_uniqify(einfo_base, uniq, desc)
Declare disambiguated error.
Definition: errno.h:180

Definition at line 50 of file ifmgmt.c.

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:362
int netdev_open(struct net_device *netdev)
Open network device.
Definition: netdevice.c:861

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

Referenced by iflinkwait(), ifopen_payload(), loopback_test(), 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:895

References netdev, and netdev_close().

Referenced by close_other_netdevs(), and ifclose_payload().

◆ ifstat_errors()

static void ifstat_errors ( struct net_device_stats stats,
const char *  prefix 
)
static

Print network device error breakdown.

Parameters
statsNetwork device statistics
prefixMessage prefix

Definition at line 92 of file ifmgmt.c.

93  {
94  unsigned int i;
95 
96  for ( i = 0 ; i < ( sizeof ( stats->errors ) /
97  sizeof ( stats->errors[0] ) ) ; i++ ) {
98  if ( stats->errors[i].count )
99  printf ( " [%s: %d x \"%s\"]\n", prefix,
100  stats->errors[i].count,
101  strerror ( stats->errors[i].rc ) );
102  }
103 }
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
char prefix[4]
Definition: vmconsole.c:53
unsigned int count
Error count.
Definition: netdevice.h:284
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
struct net_device_error errors[NETDEV_MAX_UNIQUE_ERRORS]
Error breakdowns.
Definition: netdevice.h:297
int rc
Error status code.
Definition: netdevice.h:282

References net_device_error::count, net_device_stats::errors, prefix, printf(), net_device_error::rc, and strerror().

Referenced by ifstat().

◆ 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) [%s]\n"
112  " [Link:%s%s, TX:%d TXE:%d RX:%d RXE:%d]\n",
116  ( netdev_is_open ( netdev ) ? "open" : "closed" ),
117  ( netdev_link_ok ( netdev ) ? "up" : "down" ),
118  ( netdev_link_blocked ( netdev ) ? " (blocked)" : "" ),
121  if ( ! netdev_link_ok ( netdev ) ) {
122  printf ( " [Link status: %s]\n",
123  strerror ( netdev->link_rc ) );
124  }
125  ifstat_errors ( &netdev->tx_stats, "TXE" );
126  ifstat_errors ( &netdev->rx_stats, "RXE" );
127 }
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:647
static const char * netdev_addr(struct net_device *netdev)
Get printable network device link-layer address.
Definition: netdevice.h:538
struct net_device_stats tx_stats
TX statistics.
Definition: netdevice.h:423
const char * name
Protocol name.
Definition: netdevice.h:116
static int netdev_is_open(struct net_device *netdev)
Check whether or not network device is open.
Definition: netdevice.h:658
int link_rc
Link status code.
Definition: netdevice.h:401
static int netdev_link_ok(struct net_device *netdev)
Check link state of network device.
Definition: netdevice.h:636
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:425
unsigned int bad
Count of error completions.
Definition: netdevice.h:295
struct device * dev
Underlying hardware device.
Definition: netdevice.h:364
unsigned int good
Count of successful completions.
Definition: netdevice.h:293
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:362
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition: netdevice.h:372

References net_device_stats::bad, net_device::dev, device::driver_name, net_device_stats::good, ifstat_errors(), net_device::link_rc, net_device::ll_protocol, device::name, ll_protocol::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().

◆ ifpoller_progress()

static int ifpoller_progress ( struct ifpoller ifpoller,
struct job_progress *progress  __unused 
)
static

Report network device poller progress.

Parameters
ifpollerNetwork device poller
progressProgress report to fill in
Return values
ongoing_rcOngoing job status code (if known)

Definition at line 153 of file ifmgmt.c.

154  {
155 
156  /* Hand off to current progress checker */
157  return ifpoller->progress ( ifpoller );
158 }
int(* progress)(struct ifpoller *ifpoller)
Check progress.
Definition: ifmgmt.c:143
Network device poller.
Definition: ifmgmt.c:130

References ifpoller::progress.

◆ ifpoller_wait()

static int ifpoller_wait ( struct net_device netdev,
struct net_device_configurator configurator,
unsigned long  timeout,
int(*)(struct ifpoller *ifpoller progress 
)
static

Poll network device until completion.

Parameters
netdevNetwork device
configuratorNetwork device configurator (if applicable)
timeoutTimeout period, in ticks
progressMethod to check progress
Return values
rcReturn status code

Definition at line 178 of file ifmgmt.c.

181  {
182  static struct ifpoller ifpoller = {
184  };
185 
190  return monojob_wait ( "", timeout );
191 }
int monojob_wait(const char *string, unsigned long timeout)
Wait for single foreground job to complete.
Definition: monojob.c:81
struct net_device * netdev
Network device.
Definition: ifmgmt.c:134
#define INTF_INIT(descriptor)
Initialise a static object interface.
Definition: interface.h:217
void intf_plug_plug(struct interface *a, struct interface *b)
Plug two object interfaces together.
Definition: interface.c:107
int(* progress)(struct ifpoller *ifpoller)
Check progress.
Definition: ifmgmt.c:143
struct interface job
Job control interface.
Definition: ifmgmt.c:132
static struct net_device * netdev
Definition: gdbudp.c:52
struct interface monojob
Definition: monojob.c:56
Network device poller.
Definition: ifmgmt.c:130
struct net_device_configurator * configurator
Network device configurator (if applicable)
Definition: ifmgmt.c:136
static struct interface_descriptor ifpoller_job_desc
Network device poller descriptor.
Definition: ifmgmt.c:166
void timeout(int)

References ifpoller::configurator, ifpoller_job_desc, INTF_INIT, intf_plug_plug(), ifpoller::job, monojob, monojob_wait(), netdev, ifpoller::netdev, ifpoller::progress, and timeout().

Referenced by ifconf(), and iflinkwait().

◆ iflinkwait_progress()

static int iflinkwait_progress ( struct ifpoller ifpoller)
static

Check link-up progress.

Parameters
ifpollerNetwork device poller
Return values
ongoing_rcOngoing job status code (if known)

Definition at line 199 of file ifmgmt.c.

199  {
200  struct net_device *netdev = ifpoller->netdev;
201  int ongoing_rc = netdev->link_rc;
202 
203  /* Terminate successfully if link is up */
204  if ( ongoing_rc == 0 )
205  intf_close ( &ifpoller->job, 0 );
206 
207  /* Otherwise, report link status as ongoing job status */
208  return ongoing_rc;
209 }
void intf_close(struct interface *intf, int rc)
Close an object interface.
Definition: interface.c:249
struct net_device * netdev
Network device.
Definition: ifmgmt.c:134
struct interface job
Job control interface.
Definition: ifmgmt.c:132
int link_rc
Link status code.
Definition: netdevice.h:401
static struct net_device * netdev
Definition: gdbudp.c:52
A network device.
Definition: netdevice.h:352
Network device poller.
Definition: ifmgmt.c:130

References intf_close(), ifpoller::job, net_device::link_rc, netdev, and ifpoller::netdev.

Referenced by iflinkwait().

◆ iflinkwait()

int iflinkwait ( struct net_device netdev,
unsigned long  timeout,
int  verbose 
)

Wait for link-up, with status indication.

Parameters
netdevNetwork device
timeoutTimeout period, in ticks
verboseAlways display progress message
Return values
rcReturn status code

Definition at line 219 of file ifmgmt.c.

220  {
221  int rc;
222 
223  /* Ensure device is open */
224  if ( ( rc = ifopen ( netdev ) ) != 0 )
225  return rc;
226 
227  /* Return immediately if link is already up, unless being verbose */
228  netdev_poll ( netdev );
229  if ( netdev_link_ok ( netdev ) && ( ! verbose ) )
230  return 0;
231 
232  /* Wait for link-up */
233  printf ( "Waiting for link-up on %s", netdev->name );
235 }
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:636
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:612
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:199
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:362
void timeout(int)
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
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:178

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

Referenced by ifconf(), iflinkwait_payload(), and loopback_test().

◆ ifconf_progress()

static int ifconf_progress ( struct ifpoller ifpoller)
static

Check configuration progress.

Parameters
ifpollerNetwork device poller
Return values
ongoing_rcOngoing job status code (if known)

Definition at line 243 of file ifmgmt.c.

243  {
244  struct net_device *netdev = ifpoller->netdev;
245  struct net_device_configurator *configurator = ifpoller->configurator;
246  struct net_device_configuration *config;
247  int rc;
248 
249  /* Do nothing unless configuration has completed */
251  return 0;
252 
253  /* Terminate with appropriate overall return status code */
254  if ( configurator ) {
256  rc = config->rc;
257  } else {
259  0 : -EADDRNOTAVAIL_CONFIG );
260  }
261  intf_close ( &ifpoller->job, rc );
262 
263  return rc;
264 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void intf_close(struct interface *intf, int rc)
Close an object interface.
Definition: interface.c:249
int netdev_configuration_in_progress(struct net_device *netdev)
Check if network device configuration is in progress.
Definition: netdevice.c:1379
struct net_device * netdev
Network device.
Definition: ifmgmt.c:134
#define EADDRNOTAVAIL_CONFIG
Default unsuccessful configuration status code.
Definition: ifmgmt.c:49
struct interface job
Job control interface.
Definition: ifmgmt.c:132
static struct net_device * netdev
Definition: gdbudp.c:52
A network device.
Definition: netdevice.h:352
Network device poller.
Definition: ifmgmt.c:130
int rc
Configuration status.
Definition: netdevice.h:307
A network device configurator.
Definition: netdevice.h:313
struct net_device_configurator * configurator
Network device configurator (if applicable)
Definition: ifmgmt.c:136
struct net_device_configurator * configurator
Network device configurator.
Definition: netdevice.h:305
A network device configuration.
Definition: netdevice.h:301
int netdev_configuration_ok(struct net_device *netdev)
Check if network device has at least one successful configuration.
Definition: netdevice.c:1391
static struct net_device_configuration * netdev_configuration(struct net_device *netdev, struct net_device_configurator *configurator)
Get network device configuration.
Definition: netdevice.h:608

References ifpoller::configurator, net_device_configuration::configurator, EADDRNOTAVAIL_CONFIG, intf_close(), ifpoller::job, netdev, ifpoller::netdev, netdev_configuration(), netdev_configuration_in_progress(), netdev_configuration_ok(), net_device_configuration::rc, and rc.

Referenced by ifconf().

◆ ifconf()

int ifconf ( struct net_device netdev,
struct net_device_configurator configurator,
unsigned long  timeout 
)

Perform network device configuration.

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

Definition at line 274 of file ifmgmt.c.

276  {
277  int rc;
278 
279  /* Ensure device is open and link is up */
280  if ( ( rc = iflinkwait ( netdev, LINK_WAIT_TIMEOUT, 0 ) ) != 0 )
281  return rc;
282 
283  /* Start configuration */
284  if ( configurator ) {
285  if ( ( rc = netdev_configure ( netdev, configurator ) ) != 0 ) {
286  printf ( "Could not configure %s via %s: %s\n",
288  strerror ( rc ) );
289  return rc;
290  }
291  } else {
292  if ( ( rc = netdev_configure_all ( netdev ) ) != 0 ) {
293  printf ( "Could not configure %s: %s\n",
294  netdev->name, strerror ( rc ) );
295  return rc;
296  }
297  }
298 
299  /* Wait for configuration to complete */
300  printf ( "Configuring %s%s%s(%s %s)",
301  ( configurator ? "[" : "" ),
302  ( configurator ? configurator->name : "" ),
303  ( configurator ? "] " : "" ),
306 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
const char * name
Name.
Definition: netdevice.h:315
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:1295
int iflinkwait(struct net_device *netdev, unsigned long timeout, int verbose)
Wait for link-up, with status indication.
Definition: ifmgmt.c:219
int netdev_configure_all(struct net_device *netdev)
Start network device configuration via all supported configurators.
Definition: netdevice.c:1335
#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:362
static int ifconf_progress(struct ifpoller *ifpoller)
Check configuration progress.
Definition: ifmgmt.c:243
const char *(* ntoa)(const void *ll_addr)
Transcribe link-layer address.
Definition: netdevice.h:163
struct net_device_configurator * configurator
Network device configurator.
Definition: netdevice.h:305
void timeout(int)
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:387
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:178
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition: netdevice.h:372

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, strerror(), and timeout().

Referenced by ifconf_payload(), and netboot().

Variable Documentation

◆ __errortab

struct errortab ifmgmt_errors [] __errortab
Initial value:
= {
}
#define __einfo_errortab(einfo)
Definition: errortab.h:23
#define EINFO_EADDRNOTAVAIL_CONFIG
Definition: ifmgmt.c:50

Human-readable error message.

Definition at line 55 of file ifmgmt.c.

◆ ifpoller_job_op

struct interface_operation ifpoller_job_op[]
static
Initial value:
= {
}
Job progress.
Definition: job.h:15
#define INTF_OP(op_type, object_type, op_func)
Define an object interface operation.
Definition: interface.h:32
Network device poller.
Definition: ifmgmt.c:130
static int ifpoller_progress(struct ifpoller *ifpoller, struct job_progress *progress __unused)
Report network device poller progress.
Definition: ifmgmt.c:153

Network device poller operations.

Definition at line 161 of file ifmgmt.c.

◆ ifpoller_job_desc

struct interface_descriptor ifpoller_job_desc
static
Initial value:
=
struct interface job
Job control interface.
Definition: netdevice.h:309
Network device poller.
Definition: ifmgmt.c:130
#define INTF_DESC(object_type, intf, operations)
Define an object interface descriptor.
Definition: interface.h:80
static struct interface_operation ifpoller_job_op[]
Network device poller operations.
Definition: ifmgmt.c:161

Network device poller descriptor.

Definition at line 166 of file ifmgmt.c.

Referenced by ifpoller_wait().