Browse Source

[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 16 years ago
parent
commit
3a505dfc35
5 changed files with 56 additions and 64 deletions
  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 View File

153
  * Add IPoIB link-layer header
153
  * Add IPoIB link-layer header
154
  *
154
  *
155
  * @v iobuf		I/O buffer
155
  * @v iobuf		I/O buffer
156
- * @v netdev		Network device
157
- * @v net_protocol	Network-layer protocol
158
  * @v ll_dest		Link-layer destination address
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
 	struct ipoib_hdr *ipoib_hdr =
163
 	struct ipoib_hdr *ipoib_hdr =
165
 		iob_push ( iobuf, sizeof ( *ipoib_hdr ) );
164
 		iob_push ( iobuf, sizeof ( *ipoib_hdr ) );
166
 
165
 
167
 	/* Build IPoIB header */
166
 	/* Build IPoIB header */
168
 	memcpy ( &ipoib_hdr->pseudo.peer, ll_dest,
167
 	memcpy ( &ipoib_hdr->pseudo.peer, ll_dest,
169
 		 sizeof ( ipoib_hdr->pseudo.peer ) );
168
 		 sizeof ( ipoib_hdr->pseudo.peer ) );
170
-	ipoib_hdr->real.proto = net_protocol->net_proto;
169
+	ipoib_hdr->real.proto = net_proto;
171
 	ipoib_hdr->real.reserved = 0;
170
 	ipoib_hdr->real.reserved = 0;
172
 
171
 
173
 	return 0;
172
 	return 0;
177
  * Remove IPoIB link-layer header
176
  * Remove IPoIB link-layer header
178
  *
177
  *
179
  * @v iobuf		I/O buffer
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
  * @ret rc		Return status code
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
 	struct ipoib_hdr *ipoib_hdr = iobuf->data;
186
 	struct ipoib_hdr *ipoib_hdr = iobuf->data;
189
 
187
 
190
 	/* Sanity check */
188
 	/* Sanity check */
198
 	iob_pull ( iobuf, sizeof ( *ipoib_hdr ) );
196
 	iob_pull ( iobuf, sizeof ( *ipoib_hdr ) );
199
 
197
 
200
 	/* Fill in required fields */
198
 	/* Fill in required fields */
201
-	*net_proto = ipoib_hdr->real.proto;
199
+	*ll_dest = &ipoib_broadcast; /* Doesn't really exist in packet */
202
 	*ll_source = &ipoib_hdr->pseudo.peer;
200
 	*ll_source = &ipoib_hdr->pseudo.peer;
201
+	*net_proto = ipoib_hdr->real.proto;
203
 
202
 
204
 	return 0;
203
 	return 0;
205
 }
204
 }

+ 11
- 21
src/include/gpxe/netdevice.h View File

79
 	 * Add link-layer header
79
 	 * Add link-layer header
80
 	 *
80
 	 *
81
 	 * @v iobuf		I/O buffer
81
 	 * @v iobuf		I/O buffer
82
-	 * @v netdev		Network device
83
-	 * @v net_protocol	Network-layer protocol
84
 	 * @v ll_dest		Link-layer destination address
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
 	 * @ret rc		Return status code
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
 	 * Remove link-layer header
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
 	 * Transcribe link-layer address
101
 	 * Transcribe link-layer address
112
 	 *
102
 	 *

+ 10
- 9
src/interface/pxe/pxe_undi.c View File

199
 	struct DataBlk *datablk;
199
 	struct DataBlk *datablk;
200
 	struct io_buffer *iobuf;
200
 	struct io_buffer *iobuf;
201
 	struct net_protocol *net_protocol;
201
 	struct net_protocol *net_protocol;
202
+	struct ll_protocol *ll_protocol = pxe_netdev->ll_protocol;
202
 	char destaddr[MAX_LL_ADDR_LEN];
203
 	char destaddr[MAX_LL_ADDR_LEN];
203
 	const void *ll_dest;
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
 	size_t len;
206
 	size_t len;
206
 	unsigned int i;
207
 	unsigned int i;
207
 	int rc;
208
 	int rc;
259
 			copy_from_real ( destaddr,
260
 			copy_from_real ( destaddr,
260
 					 undi_transmit->DestAddr.segment,
261
 					 undi_transmit->DestAddr.segment,
261
 					 undi_transmit->DestAddr.offset,
262
 					 undi_transmit->DestAddr.offset,
262
-					 pxe_netdev->ll_protocol->ll_addr_len );
263
+					 ll_protocol->ll_addr_len );
263
 			ll_dest = destaddr;
264
 			ll_dest = destaddr;
264
 		} else {
265
 		} else {
265
 			DBG ( " BCAST" );
266
 			DBG ( " BCAST" );
266
-			ll_dest = pxe_netdev->ll_protocol->ll_broadcast;
267
+			ll_dest = ll_protocol->ll_broadcast;
267
 		}
268
 		}
268
 
269
 
269
 		/* Add link-layer header */
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
 			free_iob ( iobuf );
274
 			free_iob ( iobuf );
274
 			undi_transmit->Status = PXENV_STATUS ( rc );
275
 			undi_transmit->Status = PXENV_STATUS ( rc );
275
 			return PXENV_EXIT_FAILURE;
276
 			return PXENV_EXIT_FAILURE;
545
 	struct io_buffer *iobuf;
546
 	struct io_buffer *iobuf;
546
 	size_t len;
547
 	size_t len;
547
 	struct ll_protocol *ll_protocol;
548
 	struct ll_protocol *ll_protocol;
549
+	const void *ll_dest;
548
 	const void *ll_source;
550
 	const void *ll_source;
549
 	uint16_t net_proto;
551
 	uint16_t net_proto;
550
 	size_t ll_hlen;
552
 	size_t ll_hlen;
625
 
627
 
626
 		/* Strip link-layer header */
628
 		/* Strip link-layer header */
627
 		ll_protocol = pxe_netdev->ll_protocol;
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
 			/* Assume unknown net_proto and no ll_source */
632
 			/* Assume unknown net_proto and no ll_source */
632
 			net_proto = 0;
633
 			net_proto = 0;
633
 			ll_source = NULL;
634
 			ll_source = NULL;

+ 14
- 14
src/net/ethernet.c View File

42
  * Add Ethernet link-layer header
42
  * Add Ethernet link-layer header
43
  *
43
  *
44
  * @v iobuf		I/O buffer
44
  * @v iobuf		I/O buffer
45
- * @v netdev		Network device
46
- * @v net_protocol	Network-layer protocol
47
  * @v ll_dest		Link-layer destination address
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
 	struct ethhdr *ethhdr = iob_push ( iobuf, sizeof ( *ethhdr ) );
52
 	struct ethhdr *ethhdr = iob_push ( iobuf, sizeof ( *ethhdr ) );
53
 
53
 
54
 	/* Build Ethernet header */
54
 	/* Build Ethernet header */
55
 	memcpy ( ethhdr->h_dest, ll_dest, ETH_ALEN );
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
 	return 0;
59
 	return 0;
60
 }
60
 }
63
  * Remove Ethernet link-layer header
63
  * Remove Ethernet link-layer header
64
  *
64
  *
65
  * @v iobuf		I/O buffer
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
  * @ret rc		Return status code
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
 	struct ethhdr *ethhdr = iobuf->data;
73
 	struct ethhdr *ethhdr = iobuf->data;
75
 
74
 
76
 	/* Sanity check */
75
 	/* Sanity check */
84
 	iob_pull ( iobuf, sizeof ( *ethhdr ) );
83
 	iob_pull ( iobuf, sizeof ( *ethhdr ) );
85
 
84
 
86
 	/* Fill in required fields */
85
 	/* Fill in required fields */
87
-	*net_proto = ethhdr->h_protocol;
86
+	*ll_dest = ethhdr->h_dest;
88
 	*ll_source = ethhdr->h_source;
87
 	*ll_source = ethhdr->h_source;
88
+	*net_proto = ethhdr->h_protocol;
89
 
89
 
90
 	return 0;
90
 	return 0;
91
 }
91
 }

+ 8
- 6
src/net/netdevice.c View File

439
  */
439
  */
440
 int net_tx ( struct io_buffer *iobuf, struct net_device *netdev,
440
 int net_tx ( struct io_buffer *iobuf, struct net_device *netdev,
441
 	     struct net_protocol *net_protocol, const void *ll_dest ) {
441
 	     struct net_protocol *net_protocol, const void *ll_dest ) {
442
+	struct ll_protocol *ll_protocol = netdev->ll_protocol;
442
 	int rc;
443
 	int rc;
443
 
444
 
444
 	/* Force a poll on the netdevice to (potentially) clear any
445
 	/* Force a poll on the netdevice to (potentially) clear any
449
 	netdev_poll ( netdev );
450
 	netdev_poll ( netdev );
450
 
451
 
451
 	/* Add link-layer header */
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
 		free_iob ( iobuf );
455
 		free_iob ( iobuf );
455
 		return rc;
456
 		return rc;
456
 	}
457
 	}
495
 	struct net_device *netdev;
496
 	struct net_device *netdev;
496
 	struct io_buffer *iobuf;
497
 	struct io_buffer *iobuf;
497
 	struct ll_protocol *ll_protocol;
498
 	struct ll_protocol *ll_protocol;
498
-	uint16_t net_proto;
499
+	const void *ll_dest;
499
 	const void *ll_source;
500
 	const void *ll_source;
501
+	uint16_t net_proto;
500
 	int rc;
502
 	int rc;
501
 
503
 
502
 	/* Poll and process each network device */
504
 	/* Poll and process each network device */
519
 
521
 
520
 			/* Remove link-layer header */
522
 			/* Remove link-layer header */
521
 			ll_protocol = netdev->ll_protocol;
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
 				free_iob ( iobuf );
527
 				free_iob ( iobuf );
526
 				continue;
528
 				continue;
527
 			}
529
 			}

Loading…
Cancel
Save