Przeglądaj źródła

[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 10 lat temu
rodzic
commit
5c11ff6304

+ 0
- 22
src/arch/i386/core/cachedhcp.c Wyświetl plik

@@ -159,30 +159,8 @@ static int cachedhcp_probe ( struct net_device *netdev ) {
159 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 162
 /** Cached DHCP packet network device driver */
183 163
 struct net_driver cachedhcp_driver __net_driver = {
184 164
 	.name = "cachedhcp",
185 165
 	.probe = cachedhcp_probe,
186
-	.notify = cachedhcp_notify,
187
-	.remove = cachedhcp_remove,
188 166
 };

+ 0
- 10
src/arch/i386/interface/vmware/guestinfo.c Wyświetl plik

@@ -243,15 +243,6 @@ static int guestinfo_net_probe ( struct net_device *netdev ) {
243 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 247
  * Remove per-netdevice GuestInfo settings
257 248
  *
@@ -276,6 +267,5 @@ static void guestinfo_net_remove ( struct net_device *netdev ) {
276 267
 struct net_driver guestinfo_net_driver __net_driver = {
277 268
 	.name = "GuestInfo",
278 269
 	.probe = guestinfo_net_probe,
279
-	.notify = guestinfo_net_notify,
280 270
 	.remove = guestinfo_net_remove,
281 271
 };

+ 0
- 11
src/net/ipv6.c Wyświetl plik

@@ -943,16 +943,6 @@ static int ipv6_probe ( struct net_device *netdev ) {
943 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 947
  * Destroy IPv6 network device
958 948
  *
@@ -973,7 +963,6 @@ static void ipv6_remove ( struct net_device *netdev ) {
973 963
 struct net_driver ipv6_driver __net_driver = {
974 964
 	.name = "IPv6",
975 965
 	.probe = ipv6_probe,
976
-	.notify = ipv6_notify,
977 966
 	.remove = ipv6_remove,
978 967
 };
979 968
 

+ 0
- 11
src/net/neighbour.c Wyświetl plik

@@ -375,16 +375,6 @@ int neighbour_define ( struct net_device *netdev,
375 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 379
  * Update neighbour cache on network device state change or removal
390 380
  *
@@ -404,7 +394,6 @@ static void neighbour_flush ( struct net_device *netdev ) {
404 394
 /** Neighbour driver (for net device notifications) */
405 395
 struct net_driver neighbour_net_driver __net_driver = {
406 396
 	.name = "Neighbour",
407
-	.probe = neighbour_probe,
408 397
 	.notify = neighbour_flush,
409 398
 	.remove = neighbour_flush,
410 399
 };

+ 13
- 7
src/net/netdevice.c Wyświetl plik

@@ -90,8 +90,10 @@ static int netdev_has_ll_addr ( struct net_device *netdev ) {
90 90
 static void netdev_notify ( struct net_device *netdev ) {
91 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,7 +537,7 @@ int register_netdev ( struct net_device *netdev ) {
535 537
 
536 538
 	/* Probe device */
537 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 541
 			DBGC ( netdev, "NETDEV %s could not add %s device: "
540 542
 			       "%s\n", netdev->name, driver->name,
541 543
 			       strerror ( rc ) );
@@ -546,8 +548,10 @@ int register_netdev ( struct net_device *netdev ) {
546 548
 	return 0;
547 549
 
548 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 555
 	clear_settings ( netdev_settings ( netdev ) );
552 556
 	unregister_settings ( netdev_settings ( netdev ) );
553 557
  err_register_settings:
@@ -629,8 +633,10 @@ void unregister_netdev ( struct net_device *netdev ) {
629 633
 	netdev_close ( netdev );
630 634
 
631 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 641
 	/* Unregister per-netdev configuration settings */
636 642
 	clear_settings ( netdev_settings ( netdev ) );

+ 0
- 11
src/net/vlan.c Wyświetl plik

@@ -439,16 +439,6 @@ int vlan_destroy ( struct net_device *netdev ) {
439 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 443
  * Handle trunk network device link state change
454 444
  *
@@ -505,7 +495,6 @@ static void vlan_remove ( struct net_device *trunk ) {
505 495
 /** VLAN driver */
506 496
 struct net_driver vlan_driver __net_driver = {
507 497
 	.name = "VLAN",
508
-	.probe = vlan_probe,
509 498
 	.notify = vlan_notify,
510 499
 	.remove = vlan_remove,
511 500
 };

Ładowanie…
Anuluj
Zapisz