Ver código fonte

Added the concept of a network interface (a network-layer concept) as

separate from a network device (a link-layer concept).
tags/v0.9.3
Michael Brown 18 anos atrás
pai
commit
3ca7dbe7ca
1 arquivos alterados com 104 adições e 23 exclusões
  1. 104
    23
      src/include/gpxe/netdevice.h

+ 104
- 23
src/include/gpxe/netdevice.h Ver arquivo

@@ -3,43 +3,31 @@
3 3
 
4 4
 /** @file
5 5
  *
6
- * Net device interface
6
+ * Network device and network interface
7 7
  *
8 8
  */
9 9
 
10 10
 #include <stdint.h>
11 11
 #include <gpxe/llh.h>
12
+#include <gpxe/list.h>
12 13
 
13 14
 struct net_device;
15
+struct net_interface;
14 16
 struct pk_buff;
15 17
 
16 18
 /**
17 19
  * A network device
18 20
  *
21
+ * This structure represents a piece of networking hardware.  It has
22
+ * properties such as a link-layer address and methods for
23
+ * transmitting and receiving raw packets.  It does not know anything
24
+ * about network-layer protocols (e.g. IP) or their addresses; these
25
+ * are handled by struct @c net_interface instead.
26
+ *
19 27
  * Note that this structure must represent a generic network device,
20 28
  * not just an Ethernet device.
21 29
  */
22 30
 struct net_device {
23
-	/** Build media-specific link-layer header
24
-	 *
25
-	 * @v netdev	Network device
26
-	 * @v pkb	Packet buffer
27
-	 * @ret rc	Return status code
28
-	 *
29
-	 * This method should convert the packet buffer's generic
30
-	 * link-layer header (a struct gpxehdr) into a media-specific
31
-	 * link-layer header (e.g. a struct ethhdr).  The generic
32
-	 * header should be removed from the buffer (via pkb_pull())
33
-	 * and the media-specific header should be prepended (via
34
-	 * pkb_push()) in its place.
35
-	 *
36
-	 * If a link-layer header cannot be constructed (e.g. because
37
-	 * of a missing ARP cache entry), then this method should
38
-	 * replace the contents of the packet buffer with an
39
-	 * appropriate ARP request or equivalent, and return -ENOENT.
40
-	 */
41
-	int ( * make_media_header ) ( struct net_device *netdev,
42
-				      struct pk_buff *pkb );
43 31
 	/** Transmit packet
44 32
 	 *
45 33
 	 * @v netdev	Network device
@@ -72,7 +60,27 @@ struct net_device {
72 60
 	 */
73 61
 	int ( * poll ) ( struct net_device *netdev, int retrieve,
74 62
 			 struct pk_buff *pkb );
75
-	/** Parse link-layer header
63
+	/** Build media-specific link-layer header
64
+	 *
65
+	 * @v netdev	Network device
66
+	 * @v pkb	Packet buffer
67
+	 * @ret rc	Return status code
68
+	 *
69
+	 * This method should convert the packet buffer's generic
70
+	 * link-layer header (a struct gpxehdr) into a media-specific
71
+	 * link-layer header (e.g. a struct ethhdr).  The generic
72
+	 * header should be removed from the buffer (via pkb_pull())
73
+	 * and the media-specific header should be prepended (via
74
+	 * pkb_push()) in its place.
75
+	 *
76
+	 * If a link-layer header cannot be constructed (e.g. because
77
+	 * of a missing ARP cache entry), then this method should
78
+	 * return an error (after transmitting an ARP request, if
79
+	 * applicable).
80
+	 */
81
+	int ( * make_media_header ) ( struct net_device *netdev,
82
+				      struct pk_buff *pkb );
83
+	/** Build media-independent link-layer header
76 84
 	 *
77 85
 	 * @v netdev	Network device
78 86
 	 * @v pkb	Packet buffer
@@ -91,7 +99,7 @@ struct net_device {
91 99
 					struct pk_buff *pkb );
92 100
 	/** Link-layer protocol
93 101
 	 *
94
-	 * This is an ARPHRD_XXX constant, in network-byte order.
102
+	 * This is an ARPHRD_XXX constant, in network byte order.
95 103
 	 */
96 104
 	uint16_t ll_proto;
97 105
 	/** Link-layer address length */
@@ -101,10 +109,83 @@ struct net_device {
101 109
 	 * For Ethernet, this is the MAC address.
102 110
 	 */
103 111
 	uint8_t ll_addr[MAX_LLH_ADDR_LEN];
112
+	/** List of network interfaces */
113
+	struct list_head interfaces;
104 114
 	/** Driver private data */
105 115
 	void *priv;
106 116
 };
107 117
 
118
+/**
119
+ * A network interface
120
+ *
121
+ * This structure represents a particular network layer protocol's
122
+ * interface to a piece of network hardware (a struct @c net_device).
123
+ *
124
+ */
125
+struct net_interface {
126
+	/** Underlying net device */
127
+	struct net_device *netdev;
128
+	/** Linked list of interfaces for this device */
129
+	struct list_head list;
130
+	/** Network-layer protocol
131
+	 *
132
+	 * This is an ETH_P_XXX constant, in network byte order.
133
+	 */
134
+	uint16_t net_proto;
135
+	/** Network-layer address length */
136
+	uint8_t net_addr_len;
137
+	/** Network-layer address */
138
+	uint8_t net_addr[MAX_NET_ADDR_LEN];
139
+	/** Packet processor
140
+	 *
141
+	 * @v netif	Network interface
142
+	 * @v pkb	Packet buffer
143
+	 * @ret rc	Return status code
144
+	 *
145
+	 * This method is called for packets arriving on the
146
+	 * associated network device that match this interface's
147
+	 * network-layer protocol.
148
+	 *
149
+	 * When this method is called, the link-layer header will
150
+	 * already have been stripped from the packet.
151
+	 */
152
+	int ( * process ) ( struct net_interface *netif,
153
+			    struct pk_buff *pkb );
154
+	/** Add media-independent link-layer header
155
+	 *
156
+	 * @v netif	Network interface
157
+	 * @v pkb	Packet buffer
158
+	 * @ret rc	Return status code
159
+	 *
160
+	 * This method should prepend a generic link-layer header (a
161
+	 * struct @c gpxehdr) to the packet buffer using pkb_push().
162
+	 */
163
+	int ( * add_generic_header ) ( struct net_interface *netif,
164
+				       struct pk_buff *pkb );
165
+};
166
+
167
+/**
168
+ * Find interface for a specific protocol
169
+ *
170
+ * @v netdev	Network device
171
+ * @v net_proto	Network-layer protocol, in network byte order
172
+ * @ret netif	Network interface, or NULL if none found
173
+ *
174
+ */
175
+static inline struct net_interface *
176
+netdev_find_netif ( const struct net_device *netdev, uint16_t net_proto ) {
177
+	struct net_interface *netif;
178
+
179
+	list_for_each_entry ( netif, &netdev->interfaces, list ) {
180
+		if ( netif->net_proto == net_proto )
181
+			return netif;
182
+	}
183
+	return NULL;
184
+}
185
+
186
+extern int netdev_send ( struct net_device *netdev, struct pk_buff *pkb );
187
+extern int netif_send ( struct net_interface *netif, struct pk_buff *pkb );
188
+
108 189
 extern struct net_device static_single_netdev;
109 190
 
110 191
 /* Must be a macro because priv_data[] is of variable size */

Carregando…
Cancelar
Salvar