iPXE
Data Structures | Defines | 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...

Defines

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

Functions

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

Variables

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

Detailed Description

Network interface management.

Definition in file ifmgmt.c.


Define Documentation

#define LINK_WAIT_TIMEOUT   ( 15 * TICKS_PER_SEC )

Default time to wait for link-up.

Definition at line 46 of file ifmgmt.c.

Referenced by ifconf().

Default unsuccessful configuration status code.

Definition at line 49 of file ifmgmt.c.

Referenced by ifconf_progress().

Value:
__einfo_uniqify ( EINFO_EADDRNOTAVAIL, 0x01,                    \
                          "No configuration methods succeeded" )

Definition at line 50 of file ifmgmt.c.


Function Documentation

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

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

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

                                         {
        int rc;

        if ( ( rc = netdev_open ( netdev ) ) != 0 ) {
                printf ( "Could not open %s: %s\n",
                         netdev->name, strerror ( rc ) );
                return rc;
        }

        return 0;
}
void ifclose ( struct net_device netdev)

Close network device.

Parameters:
netdevNetwork device

Definition at line 82 of file ifmgmt.c.

References netdev_close().

Referenced by close_all_netdevs(), and ifclose_payload().

                                           {
        netdev_close ( netdev );
}
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.

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

Referenced by ifstat().

                                                 {
        unsigned int i;

        for ( i = 0 ; i < ( sizeof ( stats->errors ) /
                            sizeof ( stats->errors[0] ) ) ; i++ ) {
                if ( stats->errors[i].count )
                        printf ( "  [%s: %d x \"%s\"]\n", prefix,
                                 stats->errors[i].count,
                                 strerror ( stats->errors[i].rc ) );
        }
}
void ifstat ( struct net_device netdev)

Print status of network device.

Parameters:
netdevNetwork device

Definition at line 110 of file ifmgmt.c.

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

                                          {
        printf ( "%s: %s using %s on %s (%s)\n"
                 "  [Link:%s%s, TX:%d TXE:%d RX:%d RXE:%d]\n",
                 netdev->name, netdev_addr ( netdev ),
                 netdev->dev->driver_name, netdev->dev->name,
                 ( netdev_is_open ( netdev ) ? "open" : "closed" ),
                 ( netdev_link_ok ( netdev ) ? "up" : "down" ),
                 ( netdev_link_blocked ( netdev ) ? " (blocked)" : "" ),
                 netdev->tx_stats.good, netdev->tx_stats.bad,
                 netdev->rx_stats.good, netdev->rx_stats.bad );
        if ( ! netdev_link_ok ( netdev ) ) {
                printf ( "  [Link status: %s]\n",
                         strerror ( netdev->link_rc ) );
        }
        ifstat_errors ( &netdev->tx_stats, "TXE" );
        ifstat_errors ( &netdev->rx_stats, "RXE" );
}
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 152 of file ifmgmt.c.

References ifpoller::progress.

                                                                        {

        /* Hand off to current progress checker */
        return ifpoller->progress ( ifpoller );
}
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 177 of file ifmgmt.c.

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

Referenced by ifconf(), and iflinkwait().

                                                                              {
        static struct ifpoller ifpoller = {
                .job = INTF_INIT ( ifpoller_job_desc ),
        };

        ifpoller.netdev = netdev;
        ifpoller.configurator = configurator;
        ifpoller.progress = progress;
        intf_plug_plug ( &monojob, &ifpoller.job );
        return monojob_wait ( "", timeout );
}
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 198 of file ifmgmt.c.

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

Referenced by iflinkwait().

                                                             {
        struct net_device *netdev = ifpoller->netdev;
        int ongoing_rc = netdev->link_rc;

        /* Terminate successfully if link is up */
        if ( ongoing_rc == 0 )
                intf_close ( &ifpoller->job, 0 );

        /* Otherwise, report link status as ongoing job status */
        return ongoing_rc;
}
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.

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

Referenced by ifconf(), and loopback_test().

                                                                    {
        int rc;

        /* Ensure device is open */
        if ( ( rc = ifopen ( netdev ) ) != 0 )
                return rc;

        /* Return immediately if link is already up */
        netdev_poll ( netdev );
        if ( netdev_link_ok ( netdev ) )
                return 0;

        /* Wait for link-up */
        printf ( "Waiting for link-up on %s", netdev->name );
        return ifpoller_wait ( netdev, NULL, timeout, iflinkwait_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 239 of file ifmgmt.c.

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

Referenced by ifconf().

                                                         {
        struct net_device *netdev = ifpoller->netdev;
        struct net_device_configurator *configurator = ifpoller->configurator;
        struct net_device_configuration *config;
        int rc;

        /* Do nothing unless configuration has completed */
        if ( netdev_configuration_in_progress ( netdev ) )
                return 0;

        /* Terminate with appropriate overall return status code */
        if ( configurator ) {
                config = netdev_configuration ( netdev, configurator );
                rc = config->rc;
        } else {
                rc = ( netdev_configuration_ok ( netdev ) ?
                       0 : -EADDRNOTAVAIL_CONFIG );
        }
        intf_close ( &ifpoller->job, rc );

        return rc;
}
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.

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

Referenced by ifconf_payload(), and netboot().

                                                            {
        int rc;

        /* Ensure device is open and link is up */
        if ( ( rc = iflinkwait ( netdev, LINK_WAIT_TIMEOUT ) ) != 0 )
                return rc;

        /* Start configuration */
        if ( configurator ) {
                if ( ( rc = netdev_configure ( netdev, configurator ) ) != 0 ) {
                        printf ( "Could not configure %s via %s: %s\n",
                                 netdev->name, configurator->name,
                                 strerror ( rc ) );
                        return rc;
                }
        } else {
                if ( ( rc = netdev_configure_all ( netdev ) ) != 0 ) {
                        printf ( "Could not configure %s: %s\n",
                                 netdev->name, strerror ( rc ) );
                        return rc;
                }
        }

        /* Wait for configuration to complete */
        printf ( "Configuring %s%s%s(%s %s)",
                 ( configurator ? "[" : "" ),
                 ( configurator ? configurator->name : "" ),
                 ( configurator ? "] " : "" ),
                 netdev->name, netdev->ll_protocol->ntoa ( netdev->ll_addr ) );
        return ifpoller_wait ( netdev, configurator, 0, ifconf_progress );
}

Variable Documentation

struct errortab ifmgmt_errors [] __errortab
Initial value:

Human-readable error message.

Definition at line 55 of file ifmgmt.c.

Initial value:

Network device poller operations.

Definition at line 160 of file ifmgmt.c.

Initial value:

Network device poller descriptor.

Definition at line 165 of file ifmgmt.c.