summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/include/gpxe/netdevice.h12
-rw-r--r--src/net/ipv4.c4
-rw-r--r--src/net/netdevice.c32
-rw-r--r--src/tests/aoeboot.c2
-rw-r--r--src/tests/dhcptest.c2
-rw-r--r--src/usr/autoboot.c2
6 files changed, 39 insertions, 15 deletions
diff --git a/src/include/gpxe/netdevice.h b/src/include/gpxe/netdevice.h
index bc0827284..90d03fcf1 100644
--- a/src/include/gpxe/netdevice.h
+++ b/src/include/gpxe/netdevice.h
@@ -138,7 +138,8 @@ struct ll_protocol {
struct net_device {
/** List of network devices */
struct list_head list;
-
+ /** Name of this network device */
+ char name[8];
/** List of persistent reference holders */
struct list_head references;
@@ -224,14 +225,12 @@ struct net_device {
#define __net_protocol __table ( net_protocols, 01 )
/**
- * Get network device name
+ * Get printable network device hardware address
*
* @v netdev Network device
- * @ret name Network device name
- *
- * The name will be the device's link-layer address.
+ * @ret name Hardware address
*/
-static inline const char * netdev_name ( struct net_device *netdev ) {
+static inline const char * netdev_hwaddr ( struct net_device *netdev ) {
return netdev->ll_protocol->ntoa ( netdev->ll_addr );
}
@@ -247,6 +246,7 @@ extern int netdev_open ( struct net_device *netdev );
extern void netdev_close ( struct net_device *netdev );
extern void unregister_netdev ( struct net_device *netdev );
extern void free_netdev ( struct net_device *netdev );
+struct net_device * find_netdev ( const char *name );
extern struct net_device * next_netdev ( void );
extern int net_tx ( struct pk_buff *pkb, struct net_device *netdev,
struct net_protocol *net_protocol, const void *ll_dest );
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
diff --git a/src/tests/aoeboot.c b/src/tests/aoeboot.c
index e585731ac..9d3013b24 100644
--- a/src/tests/aoeboot.c
+++ b/src/tests/aoeboot.c
@@ -36,7 +36,7 @@ int test_aoeboot ( struct net_device *netdev, const char *aoename,
int rc;
printf ( "Attempting to boot from AoE device %s via %s\n",
- aoename, netdev_name ( netdev ) );
+ aoename, netdev->name );
if ( ( rc = aoe_parse ( aoename, &test_aoedev.aoe ) ) != 0 ) {
printf ( "Invalid AoE device name \"%s\"\n", aoename );
diff --git a/src/tests/dhcptest.c b/src/tests/dhcptest.c
index 19949ab0e..d6b199270 100644
--- a/src/tests/dhcptest.c
+++ b/src/tests/dhcptest.c
@@ -224,7 +224,7 @@ int test_dhcp ( struct net_device *netdev ) {
goto out_no_del_ipv4;
/* Issue DHCP request */
- printf ( "DHCP (%s)...", netdev_name ( netdev ) );
+ printf ( "DHCP (%s)...", netdev->name );
memset ( &dhcp, 0, sizeof ( dhcp ) );
dhcp.netdev = netdev;
if ( ( rc = async_wait ( start_dhcp ( &dhcp ) ) ) != 0 ) {
diff --git a/src/usr/autoboot.c b/src/usr/autoboot.c
index e67722981..0fa4e8e4f 100644
--- a/src/usr/autoboot.c
+++ b/src/usr/autoboot.c
@@ -41,7 +41,7 @@ void autoboot ( void ) {
}
if ( ( rc = netdev_open ( netdev ) ) != 0 ) {
- printf ( "Could not open %s: %s\n", netdev_name ( netdev ),
+ printf ( "Could not open %s: %s\n", netdev->name,
strerror ( rc ) );
return;
}