Selaa lähdekoodia

Add "name" field to network device, to facilitate netdev commands.

tags/v0.9.3
Michael Brown 17 vuotta sitten
vanhempi
commit
98b6154c3e
6 muutettua tiedostoa jossa 39 lisäystä ja 15 poistoa
  1. 6
    6
      src/include/gpxe/netdevice.h
  2. 2
    2
      src/net/ipv4.c
  3. 28
    4
      src/net/netdevice.c
  4. 1
    1
      src/tests/aoeboot.c
  5. 1
    1
      src/tests/dhcptest.c
  6. 1
    1
      src/usr/autoboot.c

+ 6
- 6
src/include/gpxe/netdevice.h Näytä tiedosto

@@ -138,7 +138,8 @@ struct ll_protocol {
138 138
 struct net_device {
139 139
 	/** List of network devices */
140 140
 	struct list_head list;
141
-
141
+	/** Name of this network device */
142
+	char name[8];
142 143
 	/** List of persistent reference holders */
143 144
 	struct list_head references;
144 145
 
@@ -224,14 +225,12 @@ struct net_device {
224 225
 #define __net_protocol __table ( net_protocols, 01 )
225 226
 
226 227
 /**
227
- * Get network device name
228
+ * Get printable network device hardware address
228 229
  *
229 230
  * @v netdev		Network device
230
- * @ret name		Network device name
231
- *
232
- * The name will be the device's link-layer address.
231
+ * @ret name		Hardware address
233 232
  */
234
-static inline const char * netdev_name ( struct net_device *netdev ) {
233
+static inline const char * netdev_hwaddr ( struct net_device *netdev ) {
235 234
 	return netdev->ll_protocol->ntoa ( netdev->ll_addr );
236 235
 }
237 236
 
@@ -247,6 +246,7 @@ extern int netdev_open ( struct net_device *netdev );
247 246
 extern void netdev_close ( struct net_device *netdev );
248 247
 extern void unregister_netdev ( struct net_device *netdev );
249 248
 extern void free_netdev ( struct net_device *netdev );
249
+struct net_device * find_netdev ( const char *name );
250 250
 extern struct net_device * next_netdev ( void );
251 251
 extern int net_tx ( struct pk_buff *pkb, struct net_device *netdev,
252 252
 		    struct net_protocol *net_protocol, const void *ll_dest );

+ 2
- 2
src/net/ipv4.c Näytä tiedosto

@@ -79,7 +79,7 @@ static struct ipv4_miniroute * add_ipv4_miniroute ( struct net_device *netdev,
79 79
 		DBG ( "/%s ", inet_ntoa ( netmask ) );
80 80
 		if ( gateway.s_addr != INADDR_NONE )
81 81
 			DBG ( "gw %s ", inet_ntoa ( gateway ) );
82
-		DBG ( "via %s\n", netdev_name ( netdev ) );
82
+		DBG ( "via %s\n", netdev->name );
83 83
 
84 84
 		/* Record routing information */
85 85
 		miniroute->netdev = netdev;
@@ -115,7 +115,7 @@ static void del_ipv4_miniroute ( struct ipv4_miniroute *miniroute ) {
115 115
 	DBG ( "/%s ", inet_ntoa ( miniroute->netmask ) );
116 116
 	if ( miniroute->gateway.s_addr != INADDR_NONE )
117 117
 		DBG ( "gw %s ", inet_ntoa ( miniroute->gateway ) );
118
-	DBG ( "via %s\n", netdev_name ( miniroute->netdev ) );
118
+	DBG ( "via %s\n", miniroute->netdev->name );
119 119
 
120 120
 	ref_del ( &miniroute->netdev_ref );
121 121
 	list_del ( &miniroute->list );

+ 28
- 4
src/net/netdevice.c Näytä tiedosto

@@ -21,6 +21,7 @@
21 21
 #include <byteswap.h>
22 22
 #include <string.h>
23 23
 #include <errno.h>
24
+#include <vsprintf.h>
24 25
 #include <gpxe/if_ether.h>
25 26
 #include <gpxe/pkbuff.h>
26 27
 #include <gpxe/tables.h>
@@ -187,14 +188,20 @@ struct net_device * alloc_netdev ( size_t priv_size ) {
187 188
  * @v netdev		Network device
188 189
  * @ret rc		Return status code
189 190
  *
190
- * Adds the network device to the list of network devices.
191
+ * Gives the network device a name and adds it to the list of network
192
+ * devices.
191 193
  */
192 194
 int register_netdev ( struct net_device *netdev ) {
193
-	
195
+	static unsigned int ifindex = 0;
196
+
197
+	/* Create device name */
198
+	snprintf ( netdev->name, sizeof ( netdev->name ), "net%d",
199
+		   ifindex++ );
200
+
194 201
 	/* Add to device list */
195 202
 	list_add_tail ( &netdev->list, &net_devices );
196
-	DBGC ( netdev, "NETDEV %p registered as %s\n",
197
-	       netdev, netdev_name ( netdev ) );
203
+	DBGC ( netdev, "NETDEV %p registered as %s (%s)\n",
204
+	       netdev, netdev->name, netdev_hwaddr ( netdev ) );
198 205
 
199 206
 	return 0;
200 207
 }
@@ -285,6 +292,23 @@ void free_netdev ( struct net_device *netdev ) {
285 292
 	free ( netdev );
286 293
 }
287 294
 
295
+/**
296
+ * Get network device by name
297
+ *
298
+ * @v name		Network device name
299
+ * @ret netdev		Network device, or NULL
300
+ */
301
+struct net_device * find_netdev ( const char *name ) {
302
+	struct net_device *netdev;
303
+
304
+	list_for_each_entry ( netdev, &net_devices, list ) {
305
+		if ( strcmp ( netdev->name, name ) == 0 )
306
+			return netdev;
307
+	}
308
+
309
+	return NULL;
310
+}
311
+
288 312
 /**
289 313
  * Iterate through network devices
290 314
  *

+ 1
- 1
src/tests/aoeboot.c Näytä tiedosto

@@ -36,7 +36,7 @@ int test_aoeboot ( struct net_device *netdev, const char *aoename,
36 36
 	int rc;
37 37
 
38 38
 	printf ( "Attempting to boot from AoE device %s via %s\n",
39
-		 aoename, netdev_name ( netdev ) );
39
+		 aoename, netdev->name );
40 40
 
41 41
 	if ( ( rc = aoe_parse ( aoename, &test_aoedev.aoe ) ) != 0 ) {
42 42
 		printf ( "Invalid AoE device name \"%s\"\n", aoename );

+ 1
- 1
src/tests/dhcptest.c Näytä tiedosto

@@ -224,7 +224,7 @@ int test_dhcp ( struct net_device *netdev ) {
224 224
 		goto out_no_del_ipv4;
225 225
 
226 226
 	/* Issue DHCP request */
227
-	printf ( "DHCP (%s)...", netdev_name ( netdev ) );
227
+	printf ( "DHCP (%s)...", netdev->name );
228 228
 	memset ( &dhcp, 0, sizeof ( dhcp ) );
229 229
 	dhcp.netdev = netdev;
230 230
 	if ( ( rc = async_wait ( start_dhcp ( &dhcp ) ) ) != 0 ) {

+ 1
- 1
src/usr/autoboot.c Näytä tiedosto

@@ -41,7 +41,7 @@ void autoboot ( void ) {
41 41
 	}
42 42
 
43 43
 	if ( ( rc = netdev_open ( netdev ) ) != 0 ) {
44
-		printf ( "Could not open %s: %s\n", netdev_name ( netdev ),
44
+		printf ( "Could not open %s: %s\n", netdev->name,
45 45
 			 strerror ( rc ) );
46 46
 		return;
47 47
 	}

Loading…
Peruuta
Tallenna