ソースを参照

[netdevice] Change link-layer push() and pull() methods to take raw types

EFI requires us to be able to specify the source address for
individual transmitted packets, and to be able to extract the
destination address on received packets.

Take advantage of this to rationalise the push() and pull() methods so
that push() takes a (dest,source,proto) tuple and pull() returns a
(dest,source,proto) tuple.
tags/v0.9.6
Michael Brown 15年前
コミット
3a505dfc35
5個のファイルの変更56行の追加64行の削除
  1. 13
    14
      src/drivers/net/ipoib.c
  2. 11
    21
      src/include/gpxe/netdevice.h
  3. 10
    9
      src/interface/pxe/pxe_undi.c
  4. 14
    14
      src/net/ethernet.c
  5. 8
    6
      src/net/netdevice.c

+ 13
- 14
src/drivers/net/ipoib.c ファイルの表示

@@ -153,21 +153,20 @@ static struct ipoib_mac ipoib_broadcast = {
153 153
  * Add IPoIB link-layer header
154 154
  *
155 155
  * @v iobuf		I/O buffer
156
- * @v netdev		Network device
157
- * @v net_protocol	Network-layer protocol
158 156
  * @v ll_dest		Link-layer destination address
157
+ * @v ll_source		Source link-layer address
158
+ * @v net_proto		Network-layer protocol, in network-byte order
159
+ * @ret rc		Return status code
159 160
  */
160
-static int ipoib_push ( struct io_buffer *iobuf,
161
-			struct net_device *netdev __unused,
162
-			struct net_protocol *net_protocol,
163
-			const void *ll_dest ) {
161
+static int ipoib_push ( struct io_buffer *iobuf, const void *ll_dest,
162
+			const void *ll_source __unused, uint16_t net_proto ) {
164 163
 	struct ipoib_hdr *ipoib_hdr =
165 164
 		iob_push ( iobuf, sizeof ( *ipoib_hdr ) );
166 165
 
167 166
 	/* Build IPoIB header */
168 167
 	memcpy ( &ipoib_hdr->pseudo.peer, ll_dest,
169 168
 		 sizeof ( ipoib_hdr->pseudo.peer ) );
170
-	ipoib_hdr->real.proto = net_protocol->net_proto;
169
+	ipoib_hdr->real.proto = net_proto;
171 170
 	ipoib_hdr->real.reserved = 0;
172 171
 
173 172
 	return 0;
@@ -177,14 +176,13 @@ static int ipoib_push ( struct io_buffer *iobuf,
177 176
  * Remove IPoIB link-layer header
178 177
  *
179 178
  * @v iobuf		I/O buffer
180
- * @v netdev		Network device
181
- * @v net_proto		Network-layer protocol, in network-byte order
182
- * @v ll_source		Source link-layer address
179
+ * @ret ll_dest		Link-layer destination address
180
+ * @ret ll_source	Source link-layer address
181
+ * @ret net_proto	Network-layer protocol, in network-byte order
183 182
  * @ret rc		Return status code
184 183
  */
185
-static int ipoib_pull ( struct io_buffer *iobuf,
186
-			struct net_device *netdev __unused,
187
-			uint16_t *net_proto, const void **ll_source ) {
184
+static int ipoib_pull ( struct io_buffer *iobuf, const void **ll_dest,
185
+			const void **ll_source, uint16_t *net_proto ) {
188 186
 	struct ipoib_hdr *ipoib_hdr = iobuf->data;
189 187
 
190 188
 	/* Sanity check */
@@ -198,8 +196,9 @@ static int ipoib_pull ( struct io_buffer *iobuf,
198 196
 	iob_pull ( iobuf, sizeof ( *ipoib_hdr ) );
199 197
 
200 198
 	/* Fill in required fields */
201
-	*net_proto = ipoib_hdr->real.proto;
199
+	*ll_dest = &ipoib_broadcast; /* Doesn't really exist in packet */
202 200
 	*ll_source = &ipoib_hdr->pseudo.peer;
201
+	*net_proto = ipoib_hdr->real.proto;
203 202
 
204 203
 	return 0;
205 204
 }

+ 11
- 21
src/include/gpxe/netdevice.h ファイルの表示

@@ -79,34 +79,24 @@ struct ll_protocol {
79 79
 	 * Add link-layer header
80 80
 	 *
81 81
 	 * @v iobuf		I/O buffer
82
-	 * @v netdev		Network device
83
-	 * @v net_protocol	Network-layer protocol
84 82
 	 * @v ll_dest		Link-layer destination address
83
+	 * @v ll_source		Source link-layer address
84
+	 * @v net_proto		Network-layer protocol, in network-byte order
85 85
 	 * @ret rc		Return status code
86
-	 *
87
-	 * This method should prepend in the link-layer header
88
-	 * (e.g. the Ethernet DIX header).
89 86
 	 */
90
-	int ( * push ) ( struct io_buffer *iobuf, struct net_device *netdev,
91
-			 struct net_protocol *net_protocol,
92
-			 const void *ll_dest );
87
+	int ( * push ) ( struct io_buffer *iobuf, const void *ll_dest,
88
+			 const void *ll_source, uint16_t net_proto );
93 89
 	/**
94 90
 	 * Remove link-layer header
95 91
 	 *
96
-	 * @v iobuf	I/O buffer
97
-	 * @v netdev	Network device
98
-	 * @v net_proto	Network-layer protocol, in network-byte order
99
-	 * @v ll_source	Source link-layer address
100
-	 * @ret rc	Return status code
101
-	 *
102
-	 * This method should strip off the link-layer header
103
-	 * (e.g. the Ethernet DIX header) and return the protocol and
104
-	 * source link-layer address.  The method must not alter the
105
-	 * packet content, and may return the link-layer address as a
106
-	 * pointer to data within the packet.
92
+	 * @v iobuf		I/O buffer
93
+	 * @ret ll_dest		Link-layer destination address
94
+	 * @ret ll_source	Source link-layer address
95
+	 * @ret net_proto	Network-layer protocol, in network-byte order
96
+	 * @ret rc		Return status code
107 97
 	 */
108
-	int ( * pull ) ( struct io_buffer *iobuf, struct net_device *netdev,
109
-			 uint16_t *net_proto, const void **ll_source );
98
+	int ( * pull ) ( struct io_buffer *iobuf, const void **ll_dest,
99
+			 const void **ll_source, uint16_t *net_proto );
110 100
 	/**
111 101
 	 * Transcribe link-layer address
112 102
 	 *

+ 10
- 9
src/interface/pxe/pxe_undi.c ファイルの表示

@@ -199,9 +199,10 @@ PXENV_EXIT_t pxenv_undi_transmit ( struct s_PXENV_UNDI_TRANSMIT
199 199
 	struct DataBlk *datablk;
200 200
 	struct io_buffer *iobuf;
201 201
 	struct net_protocol *net_protocol;
202
+	struct ll_protocol *ll_protocol = pxe_netdev->ll_protocol;
202 203
 	char destaddr[MAX_LL_ADDR_LEN];
203 204
 	const void *ll_dest;
204
-	size_t ll_hlen = pxe_netdev->ll_protocol->ll_header_len;
205
+	size_t ll_hlen = ll_protocol->ll_header_len;
205 206
 	size_t len;
206 207
 	unsigned int i;
207 208
 	int rc;
@@ -259,17 +260,17 @@ PXENV_EXIT_t pxenv_undi_transmit ( struct s_PXENV_UNDI_TRANSMIT
259 260
 			copy_from_real ( destaddr,
260 261
 					 undi_transmit->DestAddr.segment,
261 262
 					 undi_transmit->DestAddr.offset,
262
-					 pxe_netdev->ll_protocol->ll_addr_len );
263
+					 ll_protocol->ll_addr_len );
263 264
 			ll_dest = destaddr;
264 265
 		} else {
265 266
 			DBG ( " BCAST" );
266
-			ll_dest = pxe_netdev->ll_protocol->ll_broadcast;
267
+			ll_dest = ll_protocol->ll_broadcast;
267 268
 		}
268 269
 
269 270
 		/* Add link-layer header */
270
-		if ( ( rc = pxe_netdev->ll_protocol->push ( iobuf, pxe_netdev,
271
-							    net_protocol,
272
-							    ll_dest )) != 0 ){
271
+		if ( ( rc = ll_protocol->push ( iobuf, ll_dest,
272
+						pxe_netdev->ll_addr,
273
+						net_protocol->net_proto ))!=0){
273 274
 			free_iob ( iobuf );
274 275
 			undi_transmit->Status = PXENV_STATUS ( rc );
275 276
 			return PXENV_EXIT_FAILURE;
@@ -545,6 +546,7 @@ PXENV_EXIT_t pxenv_undi_isr ( struct s_PXENV_UNDI_ISR *undi_isr ) {
545 546
 	struct io_buffer *iobuf;
546 547
 	size_t len;
547 548
 	struct ll_protocol *ll_protocol;
549
+	const void *ll_dest;
548 550
 	const void *ll_source;
549 551
 	uint16_t net_proto;
550 552
 	size_t ll_hlen;
@@ -625,9 +627,8 @@ PXENV_EXIT_t pxenv_undi_isr ( struct s_PXENV_UNDI_ISR *undi_isr ) {
625 627
 
626 628
 		/* Strip link-layer header */
627 629
 		ll_protocol = pxe_netdev->ll_protocol;
628
-		if ( ( rc = ll_protocol->pull ( iobuf, pxe_netdev,
629
-						&net_proto,
630
-						&ll_source ) ) != 0 ) {
630
+		if ( ( rc = ll_protocol->pull ( iobuf, &ll_dest, &ll_source,
631
+						&net_proto ) ) != 0 ) {
631 632
 			/* Assume unknown net_proto and no ll_source */
632 633
 			net_proto = 0;
633 634
 			ll_source = NULL;

+ 14
- 14
src/net/ethernet.c ファイルの表示

@@ -42,19 +42,19 @@ static uint8_t eth_broadcast[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
42 42
  * Add Ethernet link-layer header
43 43
  *
44 44
  * @v iobuf		I/O buffer
45
- * @v netdev		Network device
46
- * @v net_protocol	Network-layer protocol
47 45
  * @v ll_dest		Link-layer destination address
46
+ * @v ll_source		Source link-layer address
47
+ * @v net_proto		Network-layer protocol, in network-byte order
48
+ * @ret rc		Return status code
48 49
  */
49
-static int eth_push ( struct io_buffer *iobuf, struct net_device *netdev,
50
-		      struct net_protocol *net_protocol,
51
-		      const void *ll_dest ) {
50
+static int eth_push ( struct io_buffer *iobuf, const void *ll_dest,
51
+		      const void *ll_source, uint16_t net_proto ) {
52 52
 	struct ethhdr *ethhdr = iob_push ( iobuf, sizeof ( *ethhdr ) );
53 53
 
54 54
 	/* Build Ethernet header */
55 55
 	memcpy ( ethhdr->h_dest, ll_dest, ETH_ALEN );
56
-	memcpy ( ethhdr->h_source, netdev->ll_addr, ETH_ALEN );
57
-	ethhdr->h_protocol = net_protocol->net_proto;
56
+	memcpy ( ethhdr->h_source, ll_source, ETH_ALEN );
57
+	ethhdr->h_protocol = net_proto;
58 58
 
59 59
 	return 0;
60 60
 }
@@ -63,14 +63,13 @@ static int eth_push ( struct io_buffer *iobuf, struct net_device *netdev,
63 63
  * Remove Ethernet link-layer header
64 64
  *
65 65
  * @v iobuf		I/O buffer
66
- * @v netdev		Network device
67
- * @v net_proto		Network-layer protocol, in network-byte order
68
- * @v ll_source		Source link-layer address
66
+ * @ret ll_dest		Link-layer destination address
67
+ * @ret ll_source	Source link-layer address
68
+ * @ret net_proto	Network-layer protocol, in network-byte order
69 69
  * @ret rc		Return status code
70 70
  */
71
-static int eth_pull ( struct io_buffer *iobuf,
72
-		      struct net_device *netdev __unused,
73
-		      uint16_t *net_proto, const void **ll_source ) {
71
+static int eth_pull ( struct io_buffer *iobuf, const void **ll_dest,
72
+		      const void **ll_source, uint16_t *net_proto ) {
74 73
 	struct ethhdr *ethhdr = iobuf->data;
75 74
 
76 75
 	/* Sanity check */
@@ -84,8 +83,9 @@ static int eth_pull ( struct io_buffer *iobuf,
84 83
 	iob_pull ( iobuf, sizeof ( *ethhdr ) );
85 84
 
86 85
 	/* Fill in required fields */
87
-	*net_proto = ethhdr->h_protocol;
86
+	*ll_dest = ethhdr->h_dest;
88 87
 	*ll_source = ethhdr->h_source;
88
+	*net_proto = ethhdr->h_protocol;
89 89
 
90 90
 	return 0;
91 91
 }

+ 8
- 6
src/net/netdevice.c ファイルの表示

@@ -439,6 +439,7 @@ struct net_device * find_netdev_by_location ( unsigned int bus_type,
439 439
  */
440 440
 int net_tx ( struct io_buffer *iobuf, struct net_device *netdev,
441 441
 	     struct net_protocol *net_protocol, const void *ll_dest ) {
442
+	struct ll_protocol *ll_protocol = netdev->ll_protocol;
442 443
 	int rc;
443 444
 
444 445
 	/* Force a poll on the netdevice to (potentially) clear any
@@ -449,8 +450,8 @@ int net_tx ( struct io_buffer *iobuf, struct net_device *netdev,
449 450
 	netdev_poll ( netdev );
450 451
 
451 452
 	/* Add link-layer header */
452
-	if ( ( rc = netdev->ll_protocol->push ( iobuf, netdev, net_protocol,
453
-						ll_dest ) ) != 0 ) {
453
+	if ( ( rc = ll_protocol->push ( iobuf, ll_dest, netdev->ll_addr,
454
+					net_protocol->net_proto ) ) != 0 ) {
454 455
 		free_iob ( iobuf );
455 456
 		return rc;
456 457
 	}
@@ -495,8 +496,9 @@ static void net_step ( struct process *process __unused ) {
495 496
 	struct net_device *netdev;
496 497
 	struct io_buffer *iobuf;
497 498
 	struct ll_protocol *ll_protocol;
498
-	uint16_t net_proto;
499
+	const void *ll_dest;
499 500
 	const void *ll_source;
501
+	uint16_t net_proto;
500 502
 	int rc;
501 503
 
502 504
 	/* Poll and process each network device */
@@ -519,9 +521,9 @@ static void net_step ( struct process *process __unused ) {
519 521
 
520 522
 			/* Remove link-layer header */
521 523
 			ll_protocol = netdev->ll_protocol;
522
-			if ( ( rc = ll_protocol->pull ( iobuf, netdev,
523
-							&net_proto,
524
-							&ll_source ) ) != 0 ) {
524
+			if ( ( rc = ll_protocol->pull ( iobuf, &ll_dest,
525
+							&ll_source,
526
+							&net_proto ) ) != 0 ) {
525 527
 				free_iob ( iobuf );
526 528
 				continue;
527 529
 			}

読み込み中…
キャンセル
保存