Selaa lähdekoodia

[netdevice] Pass both link-layer addresses in net_tx() and net_rx()

FCoE requires the use of fabric-provided MAC addresses, which breaks
the assumption that the net device's MAC address is implicitly the
source address for net_tx() and the (unicast) destination address for
net_rx().

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 14 vuotta sitten
vanhempi
commit
88dd921e24

+ 3
- 2
src/include/ipxe/eapol.h Näytä tiedosto

@@ -90,7 +90,8 @@ struct eapol_handler
90 90
 	 *
91 91
 	 * @v iob	I/O buffer containing packet payload
92 92
 	 * @v netdev	Network device from which packet was received
93
-	 * @v ll_source	Source link-layer address from which packet was received
93
+	 * @V ll_dest	Destination link-layer address
94
+	 * @v ll_source	Source link-layer address
94 95
 	 * @ret rc	Return status code
95 96
 	 *
96 97
 	 * The I/O buffer will have the EAPOL header pulled off it, so
@@ -99,7 +100,7 @@ struct eapol_handler
99 100
 	 * This function takes ownership of the I/O buffer passed to it.
100 101
 	 */
101 102
 	int ( * rx ) ( struct io_buffer *iob, struct net_device *netdev,
102
-		       const void *ll_source );
103
+		       const void *ll_dest, const void *ll_source );
103 104
 };
104 105
 
105 106
 #define EAPOL_HANDLERS	__table ( struct eapol_handler, "eapol_handlers" )

+ 6
- 3
src/include/ipxe/netdevice.h Näytä tiedosto

@@ -57,12 +57,13 @@ struct net_protocol {
57 57
 	 *
58 58
 	 * @v iobuf	I/O buffer
59 59
 	 * @v netdev	Network device
60
+	 * @v ll_dest	Link-layer destination address
60 61
 	 * @v ll_source	Link-layer source address
61 62
 	 *
62 63
 	 * This method takes ownership of the I/O buffer.
63 64
 	 */
64 65
 	int ( * rx ) ( struct io_buffer *iobuf, struct net_device *netdev,
65
-		       const void *ll_source );
66
+		       const void *ll_dest, const void *ll_source );
66 67
 	/**
67 68
 	 * Transcribe network-layer address
68 69
 	 *
@@ -534,9 +535,11 @@ extern struct net_device * find_netdev_by_location ( unsigned int bus_type,
534 535
 						     unsigned int location );
535 536
 extern struct net_device * last_opened_netdev ( void );
536 537
 extern int net_tx ( struct io_buffer *iobuf, struct net_device *netdev,
537
-		    struct net_protocol *net_protocol, const void *ll_dest );
538
+		    struct net_protocol *net_protocol, const void *ll_dest,
539
+		    const void *ll_source );
538 540
 extern int net_rx ( struct io_buffer *iobuf, struct net_device *netdev,
539
-		    uint16_t net_proto, const void *ll_source );
541
+		    uint16_t net_proto, const void *ll_dest,
542
+		    const void *ll_source );
540 543
 
541 544
 /**
542 545
  * Complete network transmission

+ 3
- 1
src/net/80211/wpa.c Näytä tiedosto

@@ -455,7 +455,7 @@ static int wpa_send_eapol ( struct io_buffer *iob, struct wpa_common_ctx *ctx,
455 455
 			   pkt->mic );
456 456
 
457 457
 	return net_tx ( iob, ctx->dev->netdev, &eapol_protocol,
458
-			ctx->dev->bssid );
458
+			ctx->dev->bssid, ctx->dev->netdev->ll_addr );
459 459
 }
460 460
 
461 461
 
@@ -757,9 +757,11 @@ static int wpa_handle_1_of_2 ( struct wpa_common_ctx *ctx,
757 757
  *
758 758
  * @v iob	I/O buffer
759 759
  * @v netdev	Network device
760
+ * @v ll_dest	Link-layer destination address
760 761
  * @v ll_source	Source link-layer address
761 762
  */
762 763
 static int eapol_key_rx ( struct io_buffer *iob, struct net_device *netdev,
764
+			  const void *ll_dest __unused,
763 765
 			  const void *ll_source )
764 766
 {
765 767
 	struct net80211_device *dev = net80211_get ( netdev );

+ 6
- 3
src/net/aoe.c Näytä tiedosto

@@ -249,13 +249,14 @@ static void aoecmd_close ( struct aoe_command *aoecmd, int rc ) {
249 249
  */
250 250
 static int aoecmd_tx ( struct aoe_command *aoecmd ) {
251 251
 	struct aoe_device *aoedev = aoecmd->aoedev;
252
+	struct net_device *netdev = aoedev->netdev;
252 253
 	struct io_buffer *iobuf;
253 254
 	struct aoehdr *aoehdr;
254 255
 	size_t cmd_len;
255 256
 	int rc;
256 257
 
257 258
 	/* Sanity check */
258
-	assert ( aoedev->netdev != NULL );
259
+	assert ( netdev != NULL );
259 260
 
260 261
 	/* If we are transmitting anything that requires a response,
261 262
          * start the retransmission timer.  Do this before attempting
@@ -281,8 +282,8 @@ static int aoecmd_tx ( struct aoe_command *aoecmd ) {
281 282
 	aoecmd->type->cmd ( aoecmd, iobuf->data, iob_len ( iobuf ) );
282 283
 
283 284
 	/* Send packet */
284
-	if ( ( rc = net_tx ( iobuf, aoedev->netdev, &aoe_protocol,
285
-			     aoedev->target ) ) != 0 ) {
285
+	if ( ( rc = net_tx ( iobuf, netdev, &aoe_protocol, aoedev->target,
286
+			     netdev->ll_addr ) ) != 0 ) {
286 287
 		DBGC ( aoedev, "AoE %s/%08x could not transmit: %s\n",
287 288
 		       aoedev_name ( aoedev ), aoecmd->tag,
288 289
 		       strerror ( rc ) );
@@ -903,12 +904,14 @@ static int aoedev_open ( struct interface *parent, struct net_device *netdev,
903 904
  *
904 905
  * @v iobuf		I/O buffer
905 906
  * @v netdev		Network device
907
+ * @v ll_dest		Link-layer destination address
906 908
  * @v ll_source		Link-layer source address
907 909
  * @ret rc		Return status code
908 910
  *
909 911
  */
910 912
 static int aoe_rx ( struct io_buffer *iobuf,
911 913
 		    struct net_device *netdev __unused,
914
+		    const void *ll_dest __unused,
912 915
 		    const void *ll_source ) {
913 916
 	struct aoehdr *aoehdr = iobuf->data;
914 917
 	struct aoe_command *aoecmd;

+ 4
- 3
src/net/arp.c Näytä tiedosto

@@ -155,8 +155,8 @@ int arp_resolve ( struct net_device *netdev, struct net_protocol *net_protocol,
155 155
 		 dest_net_addr, net_protocol->net_addr_len );
156 156
 
157 157
 	/* Transmit ARP request */
158
-	if ( ( rc = net_tx ( iobuf, netdev, &arp_protocol, 
159
-			     netdev->ll_broadcast ) ) != 0 )
158
+	if ( ( rc = net_tx ( iobuf, netdev, &arp_protocol,
159
+			     netdev->ll_broadcast, netdev->ll_addr ) ) != 0 )
160 160
 		return rc;
161 161
 
162 162
 	return -ENOENT;
@@ -195,6 +195,7 @@ static struct arp_net_protocol * arp_find_protocol ( uint16_t net_proto ) {
195 195
  * details.
196 196
  */
197 197
 static int arp_rx ( struct io_buffer *iobuf, struct net_device *netdev,
198
+		    const void *ll_dest __unused,
198 199
 		    const void *ll_source __unused ) {
199 200
 	struct arphdr *arphdr = iobuf->data;
200 201
 	struct arp_net_protocol *arp_net_protocol;
@@ -261,7 +262,7 @@ static int arp_rx ( struct io_buffer *iobuf, struct net_device *netdev,
261 262
 
262 263
 	/* Send reply */
263 264
 	net_tx ( iob_disown ( iobuf ), netdev, &arp_protocol,
264
-		 arp_target_ha ( arphdr ) );
265
+		 arp_target_ha ( arphdr ), netdev->ll_addr );
265 266
 
266 267
  done:
267 268
 	free_iob ( iobuf );

+ 3
- 3
src/net/eapol.c Näytä tiedosto

@@ -36,13 +36,13 @@ FILE_LICENCE ( GPL2_OR_LATER );
36 36
  *
37 37
  * @v iob	I/O buffer
38 38
  * @v netdev	Network device
39
+ * @v ll_dest	Link-layer destination address
39 40
  * @v ll_source	Link-layer source address
40 41
  *
41 42
  * This function takes ownership of the I/O buffer passed to it.
42 43
  */
43 44
 static int eapol_rx ( struct io_buffer *iob, struct net_device *netdev,
44
-		      const void *ll_source )
45
-{
45
+		      const void *ll_dest, const void *ll_source ) {
46 46
 	struct eapol_frame *eapol = iob->data;
47 47
 	struct eapol_handler *handler;
48 48
 
@@ -54,7 +54,7 @@ static int eapol_rx ( struct io_buffer *iob, struct net_device *netdev,
54 54
 	for_each_table_entry ( handler, EAPOL_HANDLERS ) {
55 55
 		if ( handler->type == eapol->type ) {
56 56
 			iob_pull ( iob, EAPOL_HDR_LEN );
57
-			return handler->rx ( iob, netdev, ll_source );
57
+			return handler->rx ( iob, netdev, ll_dest, ll_source );
58 58
 		}
59 59
 	}
60 60
 

+ 5
- 2
src/net/eth_slow.c Näytä tiedosto

@@ -174,7 +174,8 @@ static int eth_slow_lacp_rx ( struct io_buffer *iobuf,
174 174
 
175 175
 	/* Send response */
176 176
 	eth_slow_lacp_dump ( iobuf, netdev, "TX" );
177
-	return net_tx ( iobuf, netdev, &eth_slow_protocol, eth_slow_address );
177
+	return net_tx ( iobuf, netdev, &eth_slow_protocol, eth_slow_address,
178
+			netdev->ll_addr );
178 179
 }
179 180
 
180 181
 /**
@@ -218,7 +219,7 @@ static int eth_slow_marker_rx ( struct io_buffer *iobuf,
218 219
 		marker->marker.tlv.type = ETH_SLOW_TLV_MARKER_RESPONSE;
219 220
 		eth_slow_marker_dump ( iobuf, netdev, "TX" );
220 221
 		return net_tx ( iobuf, netdev, &eth_slow_protocol,
221
-				eth_slow_address );
222
+				eth_slow_address, netdev->ll_addr );
222 223
 	} else {
223 224
 		/* Discard all other marker packets */
224 225
 		free_iob ( iobuf );
@@ -231,11 +232,13 @@ static int eth_slow_marker_rx ( struct io_buffer *iobuf,
231 232
  *
232 233
  * @v iobuf		I/O buffer
233 234
  * @v netdev		Network device
235
+ * @v ll_dest		Link-layer destination address
234 236
  * @v ll_source		Link-layer source address
235 237
  * @ret rc		Return status code
236 238
  */
237 239
 static int eth_slow_rx ( struct io_buffer *iobuf,
238 240
 			 struct net_device *netdev,
241
+			 const void *ll_dest __unused,
239 242
 			 const void *ll_source __unused ) {
240 243
 	union eth_slow_packet *eth_slow = iobuf->data;
241 244
 

+ 4
- 4
src/net/fcoe.c Näytä tiedosto

@@ -129,7 +129,7 @@ static int fcoe_deliver ( struct fcoe_port *fcoe,
129 129
 
130 130
 	/* Transmit packet */
131 131
 	if ( ( rc = net_tx ( iob_disown ( iobuf ), fcoe->netdev, &fcoe_protocol,
132
-			     fcoe->fcf_ll_addr ) ) != 0 ) {
132
+			     fcoe->fcf_ll_addr, fcoe->netdev->ll_addr )) != 0){
133 133
 		DBGC ( fcoe, "FCoE %s could not transmit: %s\n",
134 134
 		       fcoe->netdev->name, strerror ( rc ) );
135 135
 		goto done;
@@ -164,12 +164,12 @@ static struct io_buffer * fcoe_alloc_iob ( struct fcoe_port *fcoe __unused,
164 164
  *
165 165
  * @v iobuf		I/O buffer
166 166
  * @v netdev		Network device
167
+ * @v ll_dest		Link-layer destination address
167 168
  * @v ll_source		Link-layer source address
168 169
  * @ret rc		Return status code
169 170
  */
170
-static int fcoe_rx ( struct io_buffer *iobuf,
171
-		     struct net_device *netdev,
172
-		     const void *ll_source ) {
171
+static int fcoe_rx ( struct io_buffer *iobuf, struct net_device *netdev,
172
+		     const void *ll_dest __unused, const void *ll_source ) {
173 173
 	struct fcoe_header *fcoehdr;
174 174
 	struct fcoe_footer *fcoeftr;
175 175
 	struct fcoe_port *fcoe;

+ 6
- 2
src/net/ipv4.c Näytä tiedosto

@@ -355,7 +355,8 @@ static int ipv4_tx ( struct io_buffer *iobuf,
355 355
 	      ntohs ( iphdr->ident ), ntohs ( iphdr->chksum ) );
356 356
 
357 357
 	/* Hand off to link layer */
358
-	if ( ( rc = net_tx ( iobuf, netdev, &ipv4_protocol, ll_dest ) ) != 0 ) {
358
+	if ( ( rc = net_tx ( iobuf, netdev, &ipv4_protocol, ll_dest,
359
+			     netdev->ll_addr ) ) != 0 ) {
359 360
 		DBG ( "IPv4 could not transmit packet via %s: %s\n",
360 361
 		      netdev->name, strerror ( rc ) );
361 362
 		return rc;
@@ -373,12 +374,15 @@ static int ipv4_tx ( struct io_buffer *iobuf,
373 374
  *
374 375
  * @v iobuf	I/O buffer
375 376
  * @v netdev	Network device
377
+ * @v ll_dest	Link-layer destination address
376 378
  * @v ll_source	Link-layer destination source
377 379
  *
378 380
  * This function expects an IP4 network datagram. It processes the headers 
379 381
  * and sends it to the transport layer.
380 382
  */
381
-static int ipv4_rx ( struct io_buffer *iobuf, struct net_device *netdev __unused,
383
+static int ipv4_rx ( struct io_buffer *iobuf,
384
+		     struct net_device *netdev __unused,
385
+		     const void *ll_dest __unused,
382 386
 		     const void *ll_source __unused ) {
383 387
 	struct iphdr *iphdr = iobuf->data;
384 388
 	size_t hdrlen;

+ 4
- 1
src/net/ipv6.c Näytä tiedosto

@@ -242,7 +242,8 @@ static int ipv6_tx ( struct io_buffer *iobuf,
242 242
 	}
243 243
 
244 244
 	/* Transmit packet */
245
-	return net_tx ( iobuf, netdev, &ipv6_protocol, ll_dest );
245
+	return net_tx ( iobuf, netdev, &ipv6_protocol, ll_dest,
246
+			netdev->ll_addr );
246 247
 
247 248
   err:
248 249
 	free_iob ( iobuf );
@@ -285,12 +286,14 @@ static int ipv6_process_nxt_hdr ( struct io_buffer *iobuf, uint8_t nxt_hdr,
285 286
  *
286 287
  * @v iobuf		I/O buffer
287 288
  * @v netdev		Network device
289
+ * @v ll_dest		Link-layer destination address
288 290
  * @v ll_source		Link-layer source address
289 291
  *
290 292
  * This function processes a IPv6 packet
291 293
  */
292 294
 static int ipv6_rx ( struct io_buffer *iobuf,
293 295
 		     __unused struct net_device *netdev,
296
+		     __unused const void *ll_dest,
294 297
 		     __unused const void *ll_source ) {
295 298
 
296 299
 	struct ip6_header *ip6hdr = iobuf->data;

+ 10
- 5
src/net/netdevice.c Näytä tiedosto

@@ -607,6 +607,7 @@ struct net_device * last_opened_netdev ( void ) {
607 607
  * @v netdev		Network device
608 608
  * @v net_protocol	Network-layer protocol
609 609
  * @v ll_dest		Destination link-layer address
610
+ * @v ll_source		Source link-layer address
610 611
  * @ret rc		Return status code
611 612
  *
612 613
  * Prepends link-layer headers to the I/O buffer and transmits the
@@ -614,7 +615,8 @@ struct net_device * last_opened_netdev ( void ) {
614 615
  * ownership of the I/O buffer.
615 616
  */
616 617
 int net_tx ( struct io_buffer *iobuf, struct net_device *netdev,
617
-	     struct net_protocol *net_protocol, const void *ll_dest ) {
618
+	     struct net_protocol *net_protocol, const void *ll_dest,
619
+	     const void *ll_source ) {
618 620
 	struct ll_protocol *ll_protocol = netdev->ll_protocol;
619 621
 	int rc;
620 622
 
@@ -626,7 +628,7 @@ int net_tx ( struct io_buffer *iobuf, struct net_device *netdev,
626 628
 	netdev_poll ( netdev );
627 629
 
628 630
 	/* Add link-layer header */
629
-	if ( ( rc = ll_protocol->push ( netdev, iobuf, ll_dest, netdev->ll_addr,
631
+	if ( ( rc = ll_protocol->push ( netdev, iobuf, ll_dest, ll_source,
630 632
 					net_protocol->net_proto ) ) != 0 ) {
631 633
 		free_iob ( iobuf );
632 634
 		return rc;
@@ -642,17 +644,19 @@ int net_tx ( struct io_buffer *iobuf, struct net_device *netdev,
642 644
  * @v iobuf		I/O buffer
643 645
  * @v netdev		Network device
644 646
  * @v net_proto		Network-layer protocol, in network-byte order
647
+ * @v ll_dest		Destination link-layer address
645 648
  * @v ll_source		Source link-layer address
646 649
  * @ret rc		Return status code
647 650
  */
648 651
 int net_rx ( struct io_buffer *iobuf, struct net_device *netdev,
649
-	     uint16_t net_proto, const void *ll_source ) {
652
+	     uint16_t net_proto, const void *ll_dest, const void *ll_source ) {
650 653
 	struct net_protocol *net_protocol;
651 654
 
652 655
 	/* Hand off to network-layer protocol, if any */
653 656
 	for_each_table_entry ( net_protocol, NET_PROTOCOLS ) {
654 657
 		if ( net_protocol->net_proto == net_proto )
655
-			return net_protocol->rx ( iobuf, netdev, ll_source );
658
+			return net_protocol->rx ( iobuf, netdev, ll_dest,
659
+						  ll_source );
656 660
 	}
657 661
 
658 662
 	DBGC ( netdev, "NETDEV %p unknown network protocol %04x\n",
@@ -707,7 +711,8 @@ static void net_step ( struct process *process __unused ) {
707 711
 
708 712
 			/* Hand packet to network layer */
709 713
 			if ( ( rc = net_rx ( iob_disown ( iobuf ), netdev,
710
-					     net_proto, ll_source ) ) != 0 ) {
714
+					     net_proto, ll_dest,
715
+					     ll_source ) ) != 0 ) {
711 716
 				/* Record error for diagnosis */
712 717
 				netdev_rx_err ( netdev, NULL, rc );
713 718
 			}

+ 2
- 0
src/net/rarp.c Näytä tiedosto

@@ -36,6 +36,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
36 36
  *
37 37
  * @v iobuf		I/O buffer
38 38
  * @v netdev		Network device
39
+ * @v ll_dest		Link-layer destination address
39 40
  * @v ll_source		Link-layer source address
40 41
  * @ret rc		Return status code
41 42
  *
@@ -43,6 +44,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
43 44
  */
44 45
 static int rarp_rx ( struct io_buffer *iobuf,
45 46
 		     struct net_device *netdev __unused,
47
+		     const void *ll_dest __unused,
46 48
 		     const void *ll_source __unused ) {
47 49
 	free_iob ( iobuf );
48 50
 	return 0;

+ 4
- 2
src/usr/lotest.c Näytä tiedosto

@@ -45,11 +45,13 @@ FILE_LICENCE ( GPL2_OR_LATER );
45 45
  *
46 46
  * @v iobuf		I/O buffer
47 47
  * @v netdev		Network device
48
+ * @v ll_dest		Link-layer destination address
48 49
  * @v ll_source		Link-layer source address
49 50
  * @ret rc		Return status code
50 51
  */
51 52
 static int lotest_rx ( struct io_buffer *iobuf,
52 53
 		       struct net_device *netdev __unused,
54
+		       const void *ll_dest __unused,
53 55
 		       const void *ll_source __unused ) {
54 56
 	free_iob ( iobuf );
55 57
 	return -ENOTSUP;
@@ -138,8 +140,8 @@ int loopback_test ( struct net_device *sender, struct net_device *receiver,
138 140
 
139 141
 		/* Transmit packet */
140 142
 		if ( ( rc = net_tx ( iob_disown ( iobuf ), sender,
141
-				     &lotest_protocol,
142
-				     receiver->ll_addr ) ) != 0 ) {
143
+				     &lotest_protocol, receiver->ll_addr,
144
+				     sender->ll_addr ) ) != 0 ) {
143 145
 			printf ( "\nFailed to transmit packet: %s",
144 146
 				 strerror ( rc ) );
145 147
 			goto done;

Loading…
Peruuta
Tallenna