summaryrefslogtreecommitdiffstats
path: root/src/net
diff options
context:
space:
mode:
authorMichael Brown2007-01-10 00:48:18 +0100
committerMichael Brown2007-01-10 00:48:18 +0100
commit98b6154c3ea76121e942cb14765f05ecd7d7911c (patch)
tree155cba92d021ae1471001b0e9d128c412dff2795 /src/net
parentAdd RX quotas to the net device poll() method. This avoids the problem (diff)
downloadipxe-98b6154c3ea76121e942cb14765f05ecd7d7911c.tar.gz
ipxe-98b6154c3ea76121e942cb14765f05ecd7d7911c.tar.xz
ipxe-98b6154c3ea76121e942cb14765f05ecd7d7911c.zip
Add "name" field to network device, to facilitate netdev commands.
Diffstat (limited to 'src/net')
-rw-r--r--src/net/ipv4.c4
-rw-r--r--src/net/netdevice.c32
2 files changed, 30 insertions, 6 deletions
diff --git a/src/net/ipv4.c b/src/net/ipv4.c
index 228a5a537..e663ec32b 100644
--- a/src/net/ipv4.c
+++ b/src/net/ipv4.c
@@ -79,7 +79,7 @@ static struct ipv4_miniroute * add_ipv4_miniroute ( struct net_device *netdev,
DBG ( "/%s ", inet_ntoa ( netmask ) );
if ( gateway.s_addr != INADDR_NONE )
DBG ( "gw %s ", inet_ntoa ( gateway ) );
- DBG ( "via %s\n", netdev_name ( netdev ) );
+ DBG ( "via %s\n", netdev->name );
/* Record routing information */
miniroute->netdev = netdev;
@@ -115,7 +115,7 @@ static void del_ipv4_miniroute ( struct ipv4_miniroute *miniroute ) {
DBG ( "/%s ", inet_ntoa ( miniroute->netmask ) );
if ( miniroute->gateway.s_addr != INADDR_NONE )
DBG ( "gw %s ", inet_ntoa ( miniroute->gateway ) );
- DBG ( "via %s\n", netdev_name ( miniroute->netdev ) );
+ DBG ( "via %s\n", miniroute->netdev->name );
ref_del ( &miniroute->netdev_ref );
list_del ( &miniroute->list );
diff --git a/src/net/netdevice.c b/src/net/netdevice.c
index 40f836d45..f3b76a764 100644
--- a/src/net/netdevice.c
+++ b/src/net/netdevice.c
@@ -21,6 +21,7 @@
#include <byteswap.h>
#include <string.h>
#include <errno.h>
+#include <vsprintf.h>
#include <gpxe/if_ether.h>
#include <gpxe/pkbuff.h>
#include <gpxe/tables.h>
@@ -187,14 +188,20 @@ struct net_device * alloc_netdev ( size_t priv_size ) {
* @v netdev Network device
* @ret rc Return status code
*
- * Adds the network device to the list of network devices.
+ * Gives the network device a name and adds it to the list of network
+ * devices.
*/
int register_netdev ( struct net_device *netdev ) {
-
+ static unsigned int ifindex = 0;
+
+ /* Create device name */
+ snprintf ( netdev->name, sizeof ( netdev->name ), "net%d",
+ ifindex++ );
+
/* Add to device list */
list_add_tail ( &netdev->list, &net_devices );
- DBGC ( netdev, "NETDEV %p registered as %s\n",
- netdev, netdev_name ( netdev ) );
+ DBGC ( netdev, "NETDEV %p registered as %s (%s)\n",
+ netdev, netdev->name, netdev_hwaddr ( netdev ) );
return 0;
}
@@ -286,6 +293,23 @@ void free_netdev ( struct net_device *netdev ) {
}
/**
+ * Get network device by name
+ *
+ * @v name Network device name
+ * @ret netdev Network device, or NULL
+ */
+struct net_device * find_netdev ( const char *name ) {
+ struct net_device *netdev;
+
+ list_for_each_entry ( netdev, &net_devices, list ) {
+ if ( strcmp ( netdev->name, name ) == 0 )
+ return netdev;
+ }
+
+ return NULL;
+}
+
+/**
* Iterate through network devices
*
* @ret netdev Network device, or NULL