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.
int ifconf (struct net_device *netdev, struct net_device_configurator *configurator)
 Perform network device configuration.
void ifclose (struct net_device *netdev)
 Close network device.
void ifstat (struct net_device *netdev)
 Print status of network device.
int iflinkwait (struct net_device *netdev, unsigned long timeout)
 Wait for link-up, with status indication.

Detailed Description

Network interface management.

Definition in file ifmgmt.h.


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;
}
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 );
}
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 );
}
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" );
}
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 );
}