Browse Source

[neighbour] Add nstat() function to print out neighbour table

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 11 years ago
parent
commit
37ccbd301d
4 changed files with 115 additions and 41 deletions
  1. 44
    0
      src/include/ipxe/neighbour.h
  2. 14
    0
      src/include/usr/neighmgmt.h
  3. 1
    41
      src/net/neighbour.c
  4. 56
    0
      src/usr/neighmgmt.c

+ 44
- 0
src/include/ipxe/neighbour.h View File

@@ -9,7 +9,11 @@
9 9
 
10 10
 FILE_LICENCE ( GPL2_OR_LATER );
11 11
 
12
+#include <stdint.h>
13
+#include <ipxe/refcnt.h>
14
+#include <ipxe/list.h>
12 15
 #include <ipxe/netdevice.h>
16
+#include <ipxe/retry.h>
13 17
 
14 18
 /** A neighbour discovery protocol */
15 19
 struct neighbour_discovery {
@@ -29,6 +33,46 @@ struct neighbour_discovery {
29 33
 			       const void *net_dest, const void *net_source );
30 34
 };
31 35
 
36
+/** A neighbour cache entry */
37
+struct neighbour {
38
+	/** Reference count */
39
+	struct refcnt refcnt;
40
+	/** List of neighbour cache entries */
41
+	struct list_head list;
42
+
43
+	/** Network device */
44
+	struct net_device *netdev;
45
+	/** Network-layer protocol */
46
+	struct net_protocol *net_protocol;
47
+	/** Network-layer destination address */
48
+	uint8_t net_dest[MAX_NET_ADDR_LEN];
49
+	/** Link-layer destination address */
50
+	uint8_t ll_dest[MAX_LL_ADDR_LEN];
51
+
52
+	/** Neighbour discovery protocol (if any) */
53
+	struct neighbour_discovery *discovery;
54
+	/** Network-layer source address (if any) */
55
+	uint8_t net_source[MAX_NET_ADDR_LEN];
56
+	/** Retransmission timer */
57
+	struct retry_timer timer;
58
+
59
+	/** Pending I/O buffers */
60
+	struct list_head tx_queue;
61
+};
62
+
63
+/**
64
+ * Test if neighbour cache entry has a valid link-layer address
65
+ *
66
+ * @v neighbour		Neighbour cache entry
67
+ * @ret has_ll_dest	Neighbour cache entry has a valid link-layer address
68
+ */
69
+static inline __attribute__ (( always_inline )) int
70
+neighbour_has_ll_dest ( struct neighbour *neighbour ) {
71
+	return ( ! timer_running ( &neighbour->timer ) );
72
+}
73
+
74
+extern struct list_head neighbours;
75
+
32 76
 extern int neighbour_tx ( struct io_buffer *iobuf, struct net_device *netdev,
33 77
 			  struct net_protocol *net_protocol,
34 78
 			  const void *net_dest,

+ 14
- 0
src/include/usr/neighmgmt.h View File

@@ -0,0 +1,14 @@
1
+#ifndef _USR_NEIGHMGMT_H
2
+#define _USR_NEIGHMGMT_H
3
+
4
+/** @file
5
+ *
6
+ * Neighbour management
7
+ *
8
+ */
9
+
10
+FILE_LICENCE ( GPL2_OR_LATER );
11
+
12
+extern void nstat ( void );
13
+
14
+#endif /* _USR_NEIGHMGMT_H */

+ 1
- 41
src/net/neighbour.c View File

@@ -23,8 +23,6 @@ FILE_LICENCE ( GPL2_OR_LATER );
23 23
 #include <stdlib.h>
24 24
 #include <string.h>
25 25
 #include <errno.h>
26
-#include <ipxe/refcnt.h>
27
-#include <ipxe/list.h>
28 26
 #include <ipxe/iobuf.h>
29 27
 #include <ipxe/retry.h>
30 28
 #include <ipxe/timer.h>
@@ -40,33 +38,6 @@ FILE_LICENCE ( GPL2_OR_LATER );
40 38
  *
41 39
  */
42 40
 
43
-/** A neighbour cache entry */
44
-struct neighbour {
45
-	/** Reference count */
46
-	struct refcnt refcnt;
47
-	/** List of neighbour cache entries */
48
-	struct list_head list;
49
-
50
-	/** Network device */
51
-	struct net_device *netdev;
52
-	/** Network-layer protocol */
53
-	struct net_protocol *net_protocol;
54
-	/** Network-layer destination address */
55
-	uint8_t net_dest[MAX_NET_ADDR_LEN];
56
-	/** Link-layer destination address */
57
-	uint8_t ll_dest[MAX_LL_ADDR_LEN];
58
-
59
-	/** Neighbour discovery protocol (if any) */
60
-	struct neighbour_discovery *discovery;
61
-	/** Network-layer source address (if any) */
62
-	uint8_t net_source[MAX_NET_ADDR_LEN];
63
-	/** Retransmission timer */
64
-	struct retry_timer timer;
65
-
66
-	/** Pending I/O buffers */
67
-	struct list_head tx_queue;
68
-};
69
-
70 41
 /** Neighbour discovery minimum timeout */
71 42
 #define NEIGHBOUR_MIN_TIMEOUT ( TICKS_PER_SEC / 8 )
72 43
 
@@ -74,7 +45,7 @@ struct neighbour {
74 45
 #define NEIGHBOUR_MAX_TIMEOUT ( TICKS_PER_SEC * 3 )
75 46
 
76 47
 /** The neighbour cache */
77
-static LIST_HEAD ( neighbours );
48
+struct list_head neighbours = LIST_HEAD_INIT ( neighbours );
78 49
 
79 50
 static void neighbour_expired ( struct retry_timer *timer, int over );
80 51
 
@@ -97,17 +68,6 @@ static void neighbour_free ( struct refcnt *refcnt ) {
97 68
 	free ( neighbour );
98 69
 }
99 70
 
100
-/**
101
- * Test if neighbour cache entry has a valid link-layer address
102
- *
103
- * @v neighbour		Neighbour cache entry
104
- * @ret has_ll_dest	Neighbour cache entry has a valid link-layer address
105
- */
106
-static inline __attribute__ (( always_inline )) int
107
-neighbour_has_ll_dest ( struct neighbour *neighbour ) {
108
-	return ( ! timer_running ( &neighbour->timer ) );
109
-}
110
-
111 71
 /**
112 72
  * Create neighbour cache entry
113 73
  *

+ 56
- 0
src/usr/neighmgmt.c View File

@@ -0,0 +1,56 @@
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/neighbour.h>
24
+#include <usr/neighmgmt.h>
25
+
26
+/** @file
27
+ *
28
+ * Neighbour management
29
+ *
30
+ */
31
+
32
+/**
33
+ * Print neighbour table
34
+ *
35
+ */
36
+void nstat ( void ) {
37
+	struct neighbour *neighbour;
38
+	struct net_device *netdev;
39
+	struct ll_protocol *ll_protocol;
40
+	struct net_protocol *net_protocol;
41
+
42
+	list_for_each_entry ( neighbour, &neighbours, list ) {
43
+		netdev = neighbour->netdev;
44
+		ll_protocol = netdev->ll_protocol;
45
+		net_protocol = neighbour->net_protocol;
46
+		printf ( "%s %s %s is %s %s", netdev->name, net_protocol->name,
47
+			 net_protocol->ntoa ( neighbour->net_dest ),
48
+			 ll_protocol->name,
49
+			 ( neighbour_has_ll_dest ( neighbour ) ?
50
+			   ll_protocol->ntoa ( neighbour->ll_dest ) :
51
+			   "(incomplete)" ) );
52
+		if ( neighbour->discovery )
53
+			printf ( " (%s)", neighbour->discovery->name );
54
+		printf ( "\n" );
55
+	}
56
+}

Loading…
Cancel
Save