Browse Source

[netdevice] Make all net_driver methods optional

Most network upper-layer drivers do not implement all three methods
(probe, notify, and remove).  Save code by making all methods
optional.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 11 years ago
parent
commit
5c11ff6304

+ 0
- 22
src/arch/i386/core/cachedhcp.c View File

159
 	return 0;
159
 	return 0;
160
 }
160
 }
161
 
161
 
162
-/**
163
- * Handle network device link state change
164
- *
165
- * @v netdev		Network device
166
- */
167
-static void cachedhcp_notify ( struct net_device *netdev __unused ) {
168
-
169
-	/* Nothing to do */
170
-}
171
-
172
-/**
173
- * Handle network device removal
174
- *
175
- * @v netdev		Network device
176
- */
177
-static void cachedhcp_remove ( struct net_device *netdev __unused ) {
178
-
179
-	/* Nothing to do */
180
-}
181
-
182
 /** Cached DHCP packet network device driver */
162
 /** Cached DHCP packet network device driver */
183
 struct net_driver cachedhcp_driver __net_driver = {
163
 struct net_driver cachedhcp_driver __net_driver = {
184
 	.name = "cachedhcp",
164
 	.name = "cachedhcp",
185
 	.probe = cachedhcp_probe,
165
 	.probe = cachedhcp_probe,
186
-	.notify = cachedhcp_notify,
187
-	.remove = cachedhcp_remove,
188
 };
166
 };

+ 0
- 10
src/arch/i386/interface/vmware/guestinfo.c View File

243
 	return rc;
243
 	return rc;
244
 }
244
 }
245
 
245
 
246
-/**
247
- * Handle network device or link state change
248
- *
249
- * @v netdev		Network device
250
- */
251
-static void guestinfo_net_notify ( struct net_device *netdev __unused ) {
252
-	/* Nothing to do */
253
-}
254
-
255
 /**
246
 /**
256
  * Remove per-netdevice GuestInfo settings
247
  * Remove per-netdevice GuestInfo settings
257
  *
248
  *
276
 struct net_driver guestinfo_net_driver __net_driver = {
267
 struct net_driver guestinfo_net_driver __net_driver = {
277
 	.name = "GuestInfo",
268
 	.name = "GuestInfo",
278
 	.probe = guestinfo_net_probe,
269
 	.probe = guestinfo_net_probe,
279
-	.notify = guestinfo_net_notify,
280
 	.remove = guestinfo_net_remove,
270
 	.remove = guestinfo_net_remove,
281
 };
271
 };

+ 0
- 11
src/net/ipv6.c View File

943
 	return 0;
943
 	return 0;
944
 }
944
 }
945
 
945
 
946
-/**
947
- * Handle IPv6 network device or link state change
948
- *
949
- * @v netdev		Network device
950
- */
951
-static void ipv6_notify ( struct net_device *netdev __unused ) {
952
-
953
-	/* Nothing to do */
954
-}
955
-
956
 /**
946
 /**
957
  * Destroy IPv6 network device
947
  * Destroy IPv6 network device
958
  *
948
  *
973
 struct net_driver ipv6_driver __net_driver = {
963
 struct net_driver ipv6_driver __net_driver = {
974
 	.name = "IPv6",
964
 	.name = "IPv6",
975
 	.probe = ipv6_probe,
965
 	.probe = ipv6_probe,
976
-	.notify = ipv6_notify,
977
 	.remove = ipv6_remove,
966
 	.remove = ipv6_remove,
978
 };
967
 };
979
 
968
 

+ 0
- 11
src/net/neighbour.c View File

375
 	return 0;
375
 	return 0;
376
 }
376
 }
377
 
377
 
378
-/**
379
- * Update neighbour cache on network device creation
380
- *
381
- * @v netdev		Network device
382
- */
383
-static int neighbour_probe ( struct net_device *netdev __unused ) {
384
-	/* Nothing to do */
385
-	return 0;
386
-}
387
-
388
 /**
378
 /**
389
  * Update neighbour cache on network device state change or removal
379
  * Update neighbour cache on network device state change or removal
390
  *
380
  *
404
 /** Neighbour driver (for net device notifications) */
394
 /** Neighbour driver (for net device notifications) */
405
 struct net_driver neighbour_net_driver __net_driver = {
395
 struct net_driver neighbour_net_driver __net_driver = {
406
 	.name = "Neighbour",
396
 	.name = "Neighbour",
407
-	.probe = neighbour_probe,
408
 	.notify = neighbour_flush,
397
 	.notify = neighbour_flush,
409
 	.remove = neighbour_flush,
398
 	.remove = neighbour_flush,
410
 };
399
 };

+ 13
- 7
src/net/netdevice.c View File

90
 static void netdev_notify ( struct net_device *netdev ) {
90
 static void netdev_notify ( struct net_device *netdev ) {
91
 	struct net_driver *driver;
91
 	struct net_driver *driver;
92
 
92
 
93
-	for_each_table_entry ( driver, NET_DRIVERS )
94
-		driver->notify ( netdev );
93
+	for_each_table_entry ( driver, NET_DRIVERS ) {
94
+		if ( driver->notify )
95
+			driver->notify ( netdev );
96
+	}
95
 }
97
 }
96
 
98
 
97
 /**
99
 /**
535
 
537
 
536
 	/* Probe device */
538
 	/* Probe device */
537
 	for_each_table_entry ( driver, NET_DRIVERS ) {
539
 	for_each_table_entry ( driver, NET_DRIVERS ) {
538
-		if ( ( rc = driver->probe ( netdev ) ) != 0 ) {
540
+		if ( driver->probe && ( rc = driver->probe ( netdev ) ) != 0 ) {
539
 			DBGC ( netdev, "NETDEV %s could not add %s device: "
541
 			DBGC ( netdev, "NETDEV %s could not add %s device: "
540
 			       "%s\n", netdev->name, driver->name,
542
 			       "%s\n", netdev->name, driver->name,
541
 			       strerror ( rc ) );
543
 			       strerror ( rc ) );
546
 	return 0;
548
 	return 0;
547
 
549
 
548
  err_probe:
550
  err_probe:
549
-	for_each_table_entry_continue_reverse ( driver, NET_DRIVERS )
550
-		driver->remove ( netdev );
551
+	for_each_table_entry_continue_reverse ( driver, NET_DRIVERS ) {
552
+		if ( driver->remove )
553
+			driver->remove ( netdev );
554
+	}
551
 	clear_settings ( netdev_settings ( netdev ) );
555
 	clear_settings ( netdev_settings ( netdev ) );
552
 	unregister_settings ( netdev_settings ( netdev ) );
556
 	unregister_settings ( netdev_settings ( netdev ) );
553
  err_register_settings:
557
  err_register_settings:
629
 	netdev_close ( netdev );
633
 	netdev_close ( netdev );
630
 
634
 
631
 	/* Remove device */
635
 	/* Remove device */
632
-	for_each_table_entry_reverse ( driver, NET_DRIVERS )
633
-		driver->remove ( netdev );
636
+	for_each_table_entry_reverse ( driver, NET_DRIVERS ) {
637
+		if ( driver->remove )
638
+			driver->remove ( netdev );
639
+	}
634
 
640
 
635
 	/* Unregister per-netdev configuration settings */
641
 	/* Unregister per-netdev configuration settings */
636
 	clear_settings ( netdev_settings ( netdev ) );
642
 	clear_settings ( netdev_settings ( netdev ) );

+ 0
- 11
src/net/vlan.c View File

439
 	return 0;
439
 	return 0;
440
 }
440
 }
441
 
441
 
442
-/**
443
- * Do nothing
444
- *
445
- * @v trunk		Trunk network device
446
- * @ret rc		Return status code
447
- */
448
-static int vlan_probe ( struct net_device *trunk __unused ) {
449
-	return 0;
450
-}
451
-
452
 /**
442
 /**
453
  * Handle trunk network device link state change
443
  * Handle trunk network device link state change
454
  *
444
  *
505
 /** VLAN driver */
495
 /** VLAN driver */
506
 struct net_driver vlan_driver __net_driver = {
496
 struct net_driver vlan_driver __net_driver = {
507
 	.name = "VLAN",
497
 	.name = "VLAN",
508
-	.probe = vlan_probe,
509
 	.notify = vlan_notify,
498
 	.notify = vlan_notify,
510
 	.remove = vlan_remove,
499
 	.remove = vlan_remove,
511
 };
500
 };

Loading…
Cancel
Save