#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <console.h>
#include <gpxe/netdevice.h>
#include <gpxe/device.h>
#include <gpxe/process.h>
#include <gpxe/keys.h>
#include <usr/ifmgmt.h>
Go to the source code of this file.
Functions | |
| FILE_LICENCE (GPL2_OR_LATER) | |
| 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. | |
| int | iflinkwait (struct net_device *netdev, unsigned int max_wait_ms) |
| Wait for link-up, with status indication. | |
Definition in file ifmgmt.c.
| FILE_LICENCE | ( | GPL2_OR_LATER | ) |
| int ifopen | ( | struct net_device * | netdev | ) |
Open network device.
| netdev | Network device |
| rc | Return status code |
Definition at line 44 of file ifmgmt.c.
References net_device::name, netdev_open(), printf(), and strerror().
Referenced by dhcp(), ifopen_payload(), and netboot().
00044 { 00045 int rc; 00046 00047 if ( ( rc = netdev_open ( netdev ) ) != 0 ) { 00048 printf ( "Could not open %s: %s\n", 00049 netdev->name, strerror ( rc ) ); 00050 return rc; 00051 } 00052 00053 return 0; 00054 }
| void ifclose | ( | struct net_device * | netdev | ) |
Close network device.
| netdev | Network device |
Definition at line 61 of file ifmgmt.c.
References netdev_close().
Referenced by close_all_netdevs(), and ifclose_payload().
00061 { 00062 netdev_close ( netdev ); 00063 }
| static void ifstat_errors | ( | struct net_device_stats * | stats, | |
| const char * | prefix | |||
| ) | [static] |
Print network device error breakdown.
| stats | Network device statistics | |
| prefix | Message prefix |
Definition at line 71 of file ifmgmt.c.
References net_device_error::count, net_device_stats::errors, printf(), net_device_error::rc, and strerror().
Referenced by ifstat().
00072 { 00073 unsigned int i; 00074 00075 for ( i = 0 ; i < ( sizeof ( stats->errors ) / 00076 sizeof ( stats->errors[0] ) ) ; i++ ) { 00077 if ( stats->errors[i].count ) 00078 printf ( " [%s: %d x \"%s\"]\n", prefix, 00079 stats->errors[i].count, 00080 strerror ( stats->errors[i].rc ) ); 00081 } 00082 }
| void ifstat | ( | struct net_device * | netdev | ) |
Print status of network device.
| netdev | Network device |
Definition at line 89 of file ifmgmt.c.
References net_device_stats::bad, net_device::dev, net_device_stats::good, ifstat_errors(), net_device::link_rc, device::name, net_device::name, netdev_addr(), netdev_is_open(), netdev_link_ok(), printf(), net_device::rx_stats, strerror(), and net_device::tx_stats.
Referenced by ifstat_payload(), iwstat(), and netboot().
00089 { 00090 printf ( "%s: %s on %s (%s)\n" 00091 " [Link:%s, TX:%d TXE:%d RX:%d RXE:%d]\n", 00092 netdev->name, netdev_addr ( netdev ), netdev->dev->name, 00093 ( netdev_is_open ( netdev ) ? "open" : "closed" ), 00094 ( netdev_link_ok ( netdev ) ? "up" : "down" ), 00095 netdev->tx_stats.good, netdev->tx_stats.bad, 00096 netdev->rx_stats.good, netdev->rx_stats.bad ); 00097 if ( ! netdev_link_ok ( netdev ) ) { 00098 printf ( " [Link status: %s]\n", 00099 strerror ( netdev->link_rc ) ); 00100 } 00101 ifstat_errors ( &netdev->tx_stats, "TXE" ); 00102 ifstat_errors ( &netdev->rx_stats, "RXE" ); 00103 }
| int iflinkwait | ( | struct net_device * | netdev, | |
| unsigned int | max_wait_ms | |||
| ) |
Wait for link-up, with status indication.
| netdev | Network device | |
| max_wait_ms | Maximum time to wait, in ms |
Definition at line 111 of file ifmgmt.c.
References CTRL_C, ECANCELED, getchar(), iskey(), net_device::link_rc, mdelay(), net_device::name, netdev_link_ok(), printf(), step(), and strerror().
Referenced by dhcp().
00111 { 00112 int key; 00113 int rc; 00114 00115 if ( netdev_link_ok ( netdev ) ) 00116 return 0; 00117 00118 printf ( "Waiting for link-up on %s...", netdev->name ); 00119 00120 while ( 1 ) { 00121 if ( netdev_link_ok ( netdev ) ) { 00122 rc = 0; 00123 break; 00124 } 00125 if ( max_wait_ms-- == 0 ) { 00126 rc = netdev->link_rc; 00127 break; 00128 } 00129 step(); 00130 if ( iskey() ) { 00131 key = getchar(); 00132 if ( key == CTRL_C ) { 00133 rc = -ECANCELED; 00134 break; 00135 } 00136 } 00137 mdelay ( 1 ); 00138 } 00139 00140 if ( rc == 0 ) { 00141 printf ( " ok\n" ); 00142 } else { 00143 printf ( " failed: %s\n", strerror ( rc ) ); 00144 } 00145 00146 return rc; 00147 }
1.5.7.1