Quellcode durchsuchen

[ipv4] Abstract out protocol-specific portions of "route" command

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown vor 11 Jahren
Ursprung
Commit
43307b4e39
4 geänderte Dateien mit 115 neuen und 14 gelöschten Zeilen
  1. 24
    0
      src/config/config_route.c
  2. 22
    1
      src/include/usr/route.h
  3. 11
    13
      src/usr/route.c
  4. 58
    0
      src/usr/route_ipv4.c

+ 24
- 0
src/config/config_route.c Datei anzeigen

@@ -0,0 +1,24 @@
1
+/*
2
+ * This program is free software; you can redistribute it and/or
3
+ * modify it under the terms of the GNU General Public License as
4
+ * published by the Free Software Foundation; either version 2, or (at
5
+ * your option) any later version.
6
+ */
7
+
8
+FILE_LICENCE ( GPL2_OR_LATER );
9
+
10
+#include <config/general.h>
11
+
12
+/** @file
13
+ *
14
+ * Routing management configuration options
15
+ *
16
+ */
17
+
18
+/*
19
+ * Drag in routing management for relevant protocols
20
+ *
21
+ */
22
+#ifdef NET_PROTO_IPV4
23
+REQUIRE_OBJECT ( route_ipv4 );
24
+#endif

+ 22
- 1
src/include/usr/route.h Datei anzeigen

@@ -3,12 +3,33 @@
3 3
 
4 4
 /** @file
5 5
  *
6
- * Routing table management
6
+ * Routing management
7 7
  *
8 8
  */
9 9
 
10 10
 FILE_LICENCE ( GPL2_OR_LATER );
11 11
 
12
+#include <ipxe/tables.h>
13
+
14
+/** A routing family */
15
+struct routing_family {
16
+	/**
17
+	 * Print routes for a network device
18
+	 *
19
+	 * @v netdev		Network device
20
+	 */
21
+	void ( * print ) ( struct net_device *netdev );
22
+};
23
+
24
+/** Routing family table */
25
+#define ROUTING_FAMILIES __table ( struct routing_family, "routing_families" )
26
+
27
+/** Declare a routing family */
28
+#define __routing_family( order ) __table_entry ( ROUTING_FAMILIES, order )
29
+
30
+#define ROUTING_IPV4 01
31
+#define ROUTING_IPV6 02
32
+
12 33
 extern void route ( void );
13 34
 
14 35
 #endif /* _USR_ROUTE_H */

+ 11
- 13
src/usr/route.c Datei anzeigen

@@ -19,28 +19,26 @@
19 19
 
20 20
 FILE_LICENCE ( GPL2_OR_LATER );
21 21
 
22
-#include <stdio.h>
23 22
 #include <ipxe/netdevice.h>
24
-#include <ipxe/ip.h>
25 23
 #include <usr/route.h>
26 24
 
27 25
 /** @file
28 26
  *
29
- * Routing table management
27
+ * Routing management
30 28
  *
31 29
  */
32 30
 
31
+/**
32
+ * Print routing table
33
+ *
34
+ */
33 35
 void route ( void ) {
34
-	struct ipv4_miniroute *miniroute;
36
+	struct net_device *netdev;
37
+	struct routing_family *family;
35 38
 
36
-	list_for_each_entry ( miniroute, &ipv4_miniroutes, list ) {
37
-		printf ( "%s: %s/", miniroute->netdev->name,
38
-			 inet_ntoa ( miniroute->address ) );
39
-		printf ( "%s", inet_ntoa ( miniroute->netmask ) );
40
-		if ( miniroute->gateway.s_addr )
41
-			printf ( " gw %s", inet_ntoa ( miniroute->gateway ) );
42
-		if ( ! netdev_is_open ( miniroute->netdev ) )
43
-			printf ( " (inaccessible)" );
44
-		printf ( "\n" );
39
+	for_each_netdev ( netdev ) {
40
+		for_each_table_entry ( family, ROUTING_FAMILIES ) {
41
+			family->print ( netdev );
42
+		}
45 43
 	}
46 44
 }

+ 58
- 0
src/usr/route_ipv4.c Datei anzeigen

@@ -0,0 +1,58 @@
1
+/*
2
+ * Copyright (C) 2013 Michael Brown <mbrown@fensystems.co.uk>.
3
+ *
4
+ * This program is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as
6
+ * published by the Free Software Foundation; either version 2 of the
7
+ * License, or any later version.
8
+ *
9
+ * This program is distributed in the hope that it will be useful, but
10
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
+ * General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU General Public License
15
+ * along with this program; if not, write to the Free Software
16
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17
+ * 02110-1301, USA.
18
+ */
19
+
20
+FILE_LICENCE ( GPL2_OR_LATER );
21
+
22
+#include <stdio.h>
23
+#include <ipxe/netdevice.h>
24
+#include <ipxe/ip.h>
25
+#include <usr/route.h>
26
+
27
+/** @file
28
+ *
29
+ * IPv4 routing management
30
+ *
31
+ */
32
+
33
+/**
34
+ * Print IPv4 routing table
35
+ *
36
+ * @v netdev		Network device
37
+ */
38
+static void route_ipv4_print ( struct net_device *netdev ) {
39
+	struct ipv4_miniroute *miniroute;
40
+
41
+	list_for_each_entry ( miniroute, &ipv4_miniroutes, list ) {
42
+		if ( miniroute->netdev != netdev )
43
+			continue;
44
+		printf ( "%s: %s/", netdev->name,
45
+			 inet_ntoa ( miniroute->address ) );
46
+		printf ( "%s", inet_ntoa ( miniroute->netmask ) );
47
+		if ( miniroute->gateway.s_addr )
48
+			printf ( " gw %s", inet_ntoa ( miniroute->gateway ) );
49
+		if ( ! netdev_is_open ( miniroute->netdev ) )
50
+			printf ( " (inaccessible)" );
51
+		printf ( "\n" );
52
+	}
53
+}
54
+
55
+/** IPv4 routing family */
56
+struct routing_family ipv4_routing_family __routing_family ( ROUTING_IPV4 ) = {
57
+	.print = route_ipv4_print,
58
+};

Laden…
Abbrechen
Speichern