Browse Source

[linux] Give tap devices a name and bus type

Give tap devices a meaningful name, and avoid segmentation faults when
attempting to retrieve ${net0/bustype} by assigning a new bus type for
tap devices.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 10 years ago
parent
commit
ae0124cd40
3 changed files with 8 additions and 1 deletions
  1. 3
    0
      src/drivers/linux/tap.c
  2. 3
    0
      src/include/ipxe/device.h
  3. 2
    1
      src/net/netdev_settings.c

+ 3
- 0
src/drivers/linux/tap.c View File

@@ -216,6 +216,9 @@ static int tap_probe(struct linux_device *device, struct linux_device_request *r
216 216
 	}
217 217
 
218 218
 	nic->interface = if_setting->value;
219
+	snprintf ( device->dev.name, sizeof ( device->dev.name ), "%s",
220
+		   nic->interface );
221
+	device->dev.desc.bus_type = BUS_TYPE_TAP;
219 222
 	if_setting->applied = 1;
220 223
 
221 224
 	/* Apply rest of the settings */

+ 3
- 0
src/include/ipxe/device.h View File

@@ -54,6 +54,9 @@ struct device_description {
54 54
 /** ISA bus type */
55 55
 #define BUS_TYPE_ISA 5
56 56
 
57
+/** TAP bus type */
58
+#define BUS_TYPE_TAP 6
59
+
57 60
 /** A hardware device */
58 61
 struct device {
59 62
 	/** Name */

+ 2
- 1
src/net/netdev_settings.c View File

@@ -120,6 +120,7 @@ static int netdev_fetch_bustype ( struct net_device *netdev, void *data,
120 120
 		[BUS_TYPE_EISA] = "EISA",
121 121
 		[BUS_TYPE_MCA] = "MCA",
122 122
 		[BUS_TYPE_ISA] = "ISA",
123
+		[BUS_TYPE_TAP] = "TAP",
123 124
 	};
124 125
 	struct device_description *desc = &netdev->dev->desc;
125 126
 	const char *bustype;
@@ -127,7 +128,7 @@ static int netdev_fetch_bustype ( struct net_device *netdev, void *data,
127 128
 	assert ( desc->bus_type < ( sizeof ( bustypes ) /
128 129
 				    sizeof ( bustypes[0] ) ) );
129 130
 	bustype = bustypes[desc->bus_type];
130
-	assert ( bustypes != NULL );
131
+	assert ( bustype != NULL );
131 132
 	strncpy ( data, bustype, len );
132 133
 	return strlen ( bustype );
133 134
 }

Loading…
Cancel
Save