Browse Source

Add route() function to display routing table.

tags/v0.9.3
Michael Brown 17 years ago
parent
commit
d9ba8f790b
6 changed files with 85 additions and 33 deletions
  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 View File

9
 
9
 
10
 #include <ip.h>
10
 #include <ip.h>
11
 #include <gpxe/retry.h>
11
 #include <gpxe/retry.h>
12
+#include <gpxe/hotplug.h>
12
 
13
 
13
 /* IP constants */
14
 /* IP constants */
14
 
15
 
36
 	uint16_t len;
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
 /* Fragment reassembly buffer */
58
 /* Fragment reassembly buffer */
40
 struct frag_buffer {
59
 struct frag_buffer {
41
 	/* Identification number */
60
 	/* Identification number */
57
 struct net_protocol;
76
 struct net_protocol;
58
 struct tcpip_protocol;
77
 struct tcpip_protocol;
59
 
78
 
79
+extern struct list_head ipv4_miniroutes;
80
+
60
 extern struct net_protocol ipv4_protocol;
81
 extern struct net_protocol ipv4_protocol;
61
 
82
 
62
 extern int add_ipv4_address ( struct net_device *netdev,
83
 extern int add_ipv4_address ( struct net_device *netdev,

+ 12
- 0
src/include/usr/route.h View File

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 View File

17
  *
17
  *
18
  * IPv4 protocol
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
 /* Unique IP datagram identification number */
22
 /* Unique IP datagram identification number */
29
 
24
 
30
 struct net_protocol ipv4_protocol;
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
 /** List of IPv4 miniroutes */
27
 /** List of IPv4 miniroutes */
51
-static LIST_HEAD ( miniroutes );
28
+struct list_head ipv4_miniroutes = LIST_HEAD_INIT ( ipv4_miniroutes );
52
 
29
 
53
 /** List of fragment reassembly buffers */
30
 /** List of fragment reassembly buffers */
54
 static LIST_HEAD ( frag_buffers );
31
 static LIST_HEAD ( frag_buffers );
90
 		 * to start of list.
67
 		 * to start of list.
91
 		 */
68
 		 */
92
 		if ( gateway.s_addr != INADDR_NONE ) {
69
 		if ( gateway.s_addr != INADDR_NONE ) {
93
-			list_add_tail ( &miniroute->list, &miniroutes );
70
+			list_add_tail ( &miniroute->list, &ipv4_miniroutes );
94
 		} else {
71
 		} else {
95
-			list_add ( &miniroute->list, &miniroutes );
72
+			list_add ( &miniroute->list, &ipv4_miniroutes );
96
 		}
73
 		}
97
 
74
 
98
 		/* Record reference to net_device */
75
 		/* Record reference to net_device */
166
 void del_ipv4_address ( struct net_device *netdev ) {
143
 void del_ipv4_address ( struct net_device *netdev ) {
167
 	struct ipv4_miniroute *miniroute;
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
 		if ( miniroute->netdev == netdev ) {
147
 		if ( miniroute->netdev == netdev ) {
171
 			del_ipv4_miniroute ( miniroute );
148
 			del_ipv4_miniroute ( miniroute );
172
 			break;
149
 			break;
186
 	int local;
163
 	int local;
187
 	int has_gw;
164
 	int has_gw;
188
 
165
 
189
-	list_for_each_entry ( miniroute, &miniroutes, list ) {
166
+	list_for_each_entry ( miniroute, &ipv4_miniroutes, list ) {
190
 		local = ( ( ( dest->s_addr ^ miniroute->address.s_addr )
167
 		local = ( ( ( dest->s_addr ^ miniroute->address.s_addr )
191
 			    & miniroute->netmask.s_addr ) == 0 );
168
 			    & miniroute->netmask.s_addr ) == 0 );
192
 		has_gw = ( miniroute->gateway.s_addr != INADDR_NONE );
169
 		has_gw = ( miniroute->gateway.s_addr != INADDR_NONE );
547
 	const struct in_addr *address = net_addr;
524
 	const struct in_addr *address = net_addr;
548
 	struct ipv4_miniroute *miniroute;
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
 		if ( ( miniroute->netdev == netdev ) &&
528
 		if ( ( miniroute->netdev == netdev ) &&
552
 		     ( miniroute->address.s_addr == address->s_addr ) ) {
529
 		     ( miniroute->address.s_addr == address->s_addr ) ) {
553
 			/* Found matching address */
530
 			/* Found matching address */

+ 2
- 4
src/tests/dhcptest.c View File

236
 	find_global_dhcp_ipv4_option ( DHCP_SUBNET_MASK, &netmask );
236
 	find_global_dhcp_ipv4_option ( DHCP_SUBNET_MASK, &netmask );
237
 	find_global_dhcp_ipv4_option ( DHCP_ROUTERS, &gateway );
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
 	dhcp_snprintf ( filename, sizeof ( filename ),
239
 	dhcp_snprintf ( filename, sizeof ( filename ),
244
 			find_global_dhcp_option ( DHCP_BOOTFILE_NAME ) );
240
 			find_global_dhcp_option ( DHCP_BOOTFILE_NAME ) );
245
 	
241
 	
251
 				       gateway ) ) != 0 )
247
 				       gateway ) ) != 0 )
252
 		goto out_no_del_ipv4;
248
 		goto out_no_del_ipv4;
253
 
249
 
250
+	route();
251
+
254
 	/* Test boot */
252
 	/* Test boot */
255
 	if ( ( rc = test_dhcp_boot ( netdev, filename ) ) != 0 ) {
253
 	if ( ( rc = test_dhcp_boot ( netdev, filename ) ) != 0 ) {
256
 		printf ( "Boot failed\n" );
254
 		printf ( "Boot failed\n" );

+ 3
- 0
src/usr/autoboot.c View File

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

+ 41
- 0
src/usr/route.c View File

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
+}

Loading…
Cancel
Save