Procházet zdrojové kódy

Add route() function to display routing table.

tags/v0.9.3
Michael Brown před 18 roky
rodič
revize
d9ba8f790b
6 změnil soubory, kde provedl 85 přidání a 33 odebrání
  1. 21
    0
      src/include/gpxe/ip.h
  2. 12
    0
      src/include/usr/route.h
  3. 6
    29
      src/net/ipv4.c
  4. 2
    4
      src/tests/dhcptest.c
  5. 3
    0
      src/usr/autoboot.c
  6. 41
    0
      src/usr/route.c

+ 21
- 0
src/include/gpxe/ip.h Zobrazit soubor

@@ -9,6 +9,7 @@
9 9
 
10 10
 #include <ip.h>
11 11
 #include <gpxe/retry.h>
12
+#include <gpxe/hotplug.h>
12 13
 
13 14
 /* IP constants */
14 15
 
@@ -36,6 +37,24 @@ struct ipv4_pseudo_header {
36 37
 	uint16_t len;
37 38
 };
38 39
 
40
+/** An IPv4 address/routing table entry */
41
+struct ipv4_miniroute {
42
+	/** List of miniroutes */
43
+	struct list_head list;
44
+
45
+	/** Network device */
46
+	struct net_device *netdev;
47
+	/** Reference to network device */
48
+	struct reference netdev_ref;
49
+
50
+	/** IPv4 address */
51
+	struct in_addr address;
52
+	/** Subnet mask */
53
+	struct in_addr netmask;
54
+	/** Gateway address */
55
+	struct in_addr gateway;
56
+};
57
+
39 58
 /* Fragment reassembly buffer */
40 59
 struct frag_buffer {
41 60
 	/* Identification number */
@@ -57,6 +76,8 @@ struct net_device;
57 76
 struct net_protocol;
58 77
 struct tcpip_protocol;
59 78
 
79
+extern struct list_head ipv4_miniroutes;
80
+
60 81
 extern struct net_protocol ipv4_protocol;
61 82
 
62 83
 extern int add_ipv4_address ( struct net_device *netdev,

+ 12
- 0
src/include/usr/route.h Zobrazit soubor

@@ -0,0 +1,12 @@
1
+#ifndef _USR_ROUTE_H
2
+#define _USR_ROUTE_H
3
+
4
+/** @file
5
+ *
6
+ * Routing table management
7
+ *
8
+ */
9
+
10
+extern void route ( void );
11
+
12
+#endif /* _USR_ROUTE_H */

+ 6
- 29
src/net/ipv4.c Zobrazit soubor

@@ -17,11 +17,6 @@
17 17
  *
18 18
  * IPv4 protocol
19 19
  *
20
- * The gPXE IP stack is currently implemented on top of the uIP
21
- * protocol stack.  This file provides wrappers around uIP so that
22
- * higher-level protocol implementations do not need to talk directly
23
- * to uIP (which has a somewhat baroque API).
24
- *
25 20
  */
26 21
 
27 22
 /* Unique IP datagram identification number */
@@ -29,26 +24,8 @@ static uint16_t next_ident = 0;
29 24
 
30 25
 struct net_protocol ipv4_protocol;
31 26
 
32
-/** An IPv4 address/routing table entry */
33
-struct ipv4_miniroute {
34
-	/** List of miniroutes */
35
-	struct list_head list;
36
-
37
-	/** Network device */
38
-	struct net_device *netdev;
39
-	/** Reference to network device */
40
-	struct reference netdev_ref;
41
-
42
-	/** IPv4 address */
43
-	struct in_addr address;
44
-	/** Subnet mask */
45
-	struct in_addr netmask;
46
-	/** Gateway address */
47
-	struct in_addr gateway;
48
-};
49
-
50 27
 /** List of IPv4 miniroutes */
51
-static LIST_HEAD ( miniroutes );
28
+struct list_head ipv4_miniroutes = LIST_HEAD_INIT ( ipv4_miniroutes );
52 29
 
53 30
 /** List of fragment reassembly buffers */
54 31
 static LIST_HEAD ( frag_buffers );
@@ -90,9 +67,9 @@ static struct ipv4_miniroute * add_ipv4_miniroute ( struct net_device *netdev,
90 67
 		 * to start of list.
91 68
 		 */
92 69
 		if ( gateway.s_addr != INADDR_NONE ) {
93
-			list_add_tail ( &miniroute->list, &miniroutes );
70
+			list_add_tail ( &miniroute->list, &ipv4_miniroutes );
94 71
 		} else {
95
-			list_add ( &miniroute->list, &miniroutes );
72
+			list_add ( &miniroute->list, &ipv4_miniroutes );
96 73
 		}
97 74
 
98 75
 		/* Record reference to net_device */
@@ -166,7 +143,7 @@ int add_ipv4_address ( struct net_device *netdev, struct in_addr address,
166 143
 void del_ipv4_address ( struct net_device *netdev ) {
167 144
 	struct ipv4_miniroute *miniroute;
168 145
 
169
-	list_for_each_entry ( miniroute, &miniroutes, list ) {
146
+	list_for_each_entry ( miniroute, &ipv4_miniroutes, list ) {
170 147
 		if ( miniroute->netdev == netdev ) {
171 148
 			del_ipv4_miniroute ( miniroute );
172 149
 			break;
@@ -186,7 +163,7 @@ static struct ipv4_miniroute * ipv4_route ( struct in_addr *dest ) {
186 163
 	int local;
187 164
 	int has_gw;
188 165
 
189
-	list_for_each_entry ( miniroute, &miniroutes, list ) {
166
+	list_for_each_entry ( miniroute, &ipv4_miniroutes, list ) {
190 167
 		local = ( ( ( dest->s_addr ^ miniroute->address.s_addr )
191 168
 			    & miniroute->netmask.s_addr ) == 0 );
192 169
 		has_gw = ( miniroute->gateway.s_addr != INADDR_NONE );
@@ -547,7 +524,7 @@ static int ipv4_arp_check ( struct net_device *netdev, const void *net_addr ) {
547 524
 	const struct in_addr *address = net_addr;
548 525
 	struct ipv4_miniroute *miniroute;
549 526
 
550
-	list_for_each_entry ( miniroute, &miniroutes, list ) {
527
+	list_for_each_entry ( miniroute, &ipv4_miniroutes, list ) {
551 528
 		if ( ( miniroute->netdev == netdev ) &&
552 529
 		     ( miniroute->address.s_addr == address->s_addr ) ) {
553 530
 			/* Found matching address */

+ 2
- 4
src/tests/dhcptest.c Zobrazit soubor

@@ -236,10 +236,6 @@ int test_dhcp ( struct net_device *netdev ) {
236 236
 	find_global_dhcp_ipv4_option ( DHCP_SUBNET_MASK, &netmask );
237 237
 	find_global_dhcp_ipv4_option ( DHCP_ROUTERS, &gateway );
238 238
 
239
-	printf ( "IP %s", inet_ntoa ( address ) );
240
-	printf ( " netmask %s", inet_ntoa ( netmask ) );
241
-	printf ( " gateway %s\n", inet_ntoa ( gateway ) );
242
-
243 239
 	dhcp_snprintf ( filename, sizeof ( filename ),
244 240
 			find_global_dhcp_option ( DHCP_BOOTFILE_NAME ) );
245 241
 	
@@ -251,6 +247,8 @@ int test_dhcp ( struct net_device *netdev ) {
251 247
 				       gateway ) ) != 0 )
252 248
 		goto out_no_del_ipv4;
253 249
 
250
+	route();
251
+
254 252
 	/* Test boot */
255 253
 	if ( ( rc = test_dhcp_boot ( netdev, filename ) ) != 0 ) {
256 254
 		printf ( "Boot failed\n" );

+ 3
- 0
src/usr/autoboot.c Zobrazit soubor

@@ -21,6 +21,7 @@
21 21
 #include <vsprintf.h>
22 22
 #include <gpxe/netdevice.h>
23 23
 #include <usr/ifmgmt.h>
24
+#include <usr/route.h>
24 25
 #include <usr/autoboot.h>
25 26
 
26 27
 /** @file
@@ -81,6 +82,8 @@ void netboot ( struct net_device *netdev ) {
81 82
 	ifstat ( netdev );
82 83
 
83 84
 	test_dhcp ( netdev );
85
+
86
+	route();
84 87
 }
85 88
 
86 89
 /**

+ 41
- 0
src/usr/route.c Zobrazit soubor

@@ -0,0 +1,41 @@
1
+/*
2
+ * Copyright (C) 2007 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., 675 Mass Ave, Cambridge, MA 02139, USA.
17
+ */
18
+
19
+#include <vsprintf.h>
20
+#include <gpxe/netdevice.h>
21
+#include <gpxe/ip.h>
22
+#include <usr/route.h>
23
+
24
+/** @file
25
+ *
26
+ * Routing table management
27
+ *
28
+ */
29
+
30
+void route ( void ) {
31
+	struct ipv4_miniroute *miniroute;
32
+
33
+	list_for_each_entry ( miniroute, &ipv4_miniroutes, list ) {
34
+		printf ( "%s: %s/", miniroute->netdev->name,
35
+			 inet_ntoa ( miniroute->address ) );
36
+		printf ( "%s", inet_ntoa ( miniroute->netmask ) );
37
+		if ( miniroute->gateway.s_addr != INADDR_NONE )
38
+			printf ( " gw %s", inet_ntoa ( miniroute->gateway ) );
39
+		printf ( "\n" );
40
+	}
41
+}

Načítá se…
Zrušit
Uložit