소스 검색

[netdevice] Add the concept of an "Ethernet-compatible" MAC address

The iBFT is Ethernet-centric in providing only six bytes for a MAC
address.  This is most probably an indirect consequence of a similar
design flaw in the Windows NDIS stack.  (The WinOF IPoIB stack
performs all sorts of contortions in order to pretend to the NDIS
layer that it is dealing with six-byte MAC addresses.)

There is no sensible way in which to extend the iBFT without breaking
compatibility with programs that expect to parse it.  Add the notion
of an "Ethernet-compatible" MAC address to our link layer abstraction,
so that link layers can provide their own workarounds for this
limitation.
tags/v1.0.0-rc1
Michael Brown 15 년 전
부모
커밋
1b1e63d54d
5개의 변경된 파일84개의 추가작업 그리고 6개의 파일을 삭제
  1. 57
    0
      src/drivers/net/ipoib.c
  2. 1
    0
      src/include/gpxe/ethernet.h
  3. 13
    6
      src/include/gpxe/netdevice.h
  4. 1
    0
      src/net/80211/net80211.c
  5. 12
    0
      src/net/ethernet.c

+ 57
- 0
src/drivers/net/ipoib.c 파일 보기

@@ -296,6 +296,62 @@ static int ipoib_mc_hash ( unsigned int af __unused,
296 296
 	return -ENOTSUP;
297 297
 }
298 298
 
299
+/**
300
+ * Generate Mellanox Ethernet-compatible compressed link-layer address
301
+ *
302
+ * @v ll_addr		Link-layer address
303
+ * @v eth_addr		Ethernet-compatible address to fill in
304
+ */
305
+static int ipoib_mlx_eth_addr ( const struct ib_gid_half *guid,
306
+				uint8_t *eth_addr ) {
307
+	eth_addr[0] = ( ( guid->u.bytes[3] == 2 ) ? 0x00 : 0x02 );
308
+	eth_addr[1] = guid->u.bytes[1];
309
+	eth_addr[2] = guid->u.bytes[2];
310
+	eth_addr[3] = guid->u.bytes[5];
311
+	eth_addr[4] = guid->u.bytes[6];
312
+	eth_addr[5] = guid->u.bytes[7];
313
+	return 0;
314
+}
315
+
316
+/** An IPoIB Ethernet-compatible compressed link-layer address generator */
317
+struct ipoib_eth_addr_handler {
318
+	/** GUID byte 1 */
319
+	uint8_t byte1;
320
+	/** GUID byte 2 */
321
+	uint8_t byte2;
322
+	/** Handler */
323
+	int ( * eth_addr ) ( const struct ib_gid_half *guid,
324
+			     uint8_t *eth_addr );
325
+};
326
+
327
+/** IPoIB Ethernet-compatible compressed link-layer address generators */
328
+static struct ipoib_eth_addr_handler ipoib_eth_addr_handlers[] = {
329
+	{ 0x02, 0xc9, ipoib_mlx_eth_addr },
330
+};
331
+
332
+/**
333
+ * Generate Ethernet-compatible compressed link-layer address
334
+ *
335
+ * @v ll_addr		Link-layer address
336
+ * @v eth_addr		Ethernet-compatible address to fill in
337
+ */
338
+static int ipoib_eth_addr ( const void *ll_addr, void *eth_addr ) {
339
+	const struct ipoib_mac *ipoib_addr = ll_addr;
340
+	const struct ib_gid_half *guid = &ipoib_addr->gid.u.half[1];
341
+	struct ipoib_eth_addr_handler *handler;
342
+	unsigned int i;
343
+
344
+	for ( i = 0 ; i < ( sizeof ( ipoib_eth_addr_handlers ) /
345
+			    sizeof ( ipoib_eth_addr_handlers[0] ) ) ; i++ ) {
346
+		handler = &ipoib_eth_addr_handlers[i];
347
+		if ( ( handler->byte1 == guid->u.bytes[1] ) &&
348
+		     ( handler->byte2 == guid->u.bytes[2] ) ) {
349
+			return handler->eth_addr ( guid, eth_addr );
350
+		}
351
+	}
352
+	return -ENOTSUP;
353
+}
354
+
299 355
 /** IPoIB protocol */
300 356
 struct ll_protocol ipoib_protocol __ll_protocol = {
301 357
 	.name		= "IPoIB",
@@ -308,6 +364,7 @@ struct ll_protocol ipoib_protocol __ll_protocol = {
308 364
 	.init_addr	= ipoib_init_addr,
309 365
 	.ntoa		= ipoib_ntoa,
310 366
 	.mc_hash	= ipoib_mc_hash,
367
+	.eth_addr	= ipoib_eth_addr,
311 368
 };
312 369
 
313 370
 /**

+ 1
- 0
src/include/gpxe/ethernet.h 파일 보기

@@ -15,6 +15,7 @@ extern void eth_init_addr ( const void *hw_addr, void *ll_addr );
15 15
 extern const char * eth_ntoa ( const void *ll_addr );
16 16
 extern int eth_mc_hash ( unsigned int af, const void *net_addr,
17 17
 			 void *ll_addr );
18
+extern int eth_eth_addr ( const void *ll_addr, void *eth_addr );
18 19
 extern struct net_device * alloc_etherdev ( size_t priv_size );
19 20
 
20 21
 #endif /* _GPXE_ETHERNET_H */

+ 13
- 6
src/include/gpxe/netdevice.h 파일 보기

@@ -128,8 +128,8 @@ struct ll_protocol {
128 128
 	/**
129 129
 	 * Transcribe link-layer address
130 130
 	 *
131
-	 * @v ll_addr	Link-layer address
132
-	 * @ret string	Human-readable transcription of address
131
+	 * @v ll_addr		Link-layer address
132
+	 * @ret string		Human-readable transcription of address
133 133
 	 *
134 134
 	 * This method should convert the link-layer address into a
135 135
 	 * human-readable format.
@@ -141,13 +141,20 @@ struct ll_protocol {
141 141
 	/**
142 142
 	 * Hash multicast address
143 143
 	 *
144
-	 * @v af	Address family
145
-	 * @v net_addr	Network-layer address
146
-	 * @v ll_addr	Link-layer address to fill in
147
-	 * @ret rc	Return status code
144
+	 * @v af		Address family
145
+	 * @v net_addr		Network-layer address
146
+	 * @v ll_addr		Link-layer address to fill in
147
+	 * @ret rc		Return status code
148 148
 	 */
149 149
 	int ( * mc_hash ) ( unsigned int af, const void *net_addr,
150 150
 			    void *ll_addr );
151
+	/**
152
+	 * Generate Ethernet-compatible compressed link-layer address
153
+	 *
154
+	 * @v ll_addr		Link-layer address
155
+	 * @v eth_addr		Ethernet-compatible address to fill in
156
+	 */
157
+	int ( * eth_addr ) ( const void *ll_addr, void *eth_addr );
151 158
 	/** Link-layer protocol
152 159
 	 *
153 160
 	 * This is an ARPHRD_XXX constant, in network byte order.

+ 1
- 0
src/net/80211/net80211.c 파일 보기

@@ -586,6 +586,7 @@ static struct ll_protocol net80211_ll_protocol __ll_protocol = {
586 586
 	.init_addr = eth_init_addr,
587 587
 	.ntoa = eth_ntoa,
588 588
 	.mc_hash = eth_mc_hash,
589
+	.eth_addr = eth_eth_addr,
589 590
 	.ll_proto = htons ( ARPHRD_ETHER ),	/* "encapsulated Ethernet" */
590 591
 	.hw_addr_len = ETH_ALEN,
591 592
 	.ll_addr_len = ETH_ALEN,

+ 12
- 0
src/net/ethernet.c 파일 보기

@@ -148,6 +148,17 @@ int eth_mc_hash ( unsigned int af, const void *net_addr, void *ll_addr ) {
148 148
 	}
149 149
 }
150 150
 
151
+/**
152
+ * Generate Ethernet-compatible compressed link-layer address
153
+ *
154
+ * @v ll_addr		Link-layer address
155
+ * @v eth_addr		Ethernet-compatible address to fill in
156
+ */
157
+int eth_eth_addr ( const void *ll_addr, void *eth_addr ) {
158
+	memcpy ( eth_addr, ll_addr, ETH_ALEN );
159
+	return 0;
160
+}
161
+
151 162
 /** Ethernet protocol */
152 163
 struct ll_protocol ethernet_protocol __ll_protocol = {
153 164
 	.name		= "Ethernet",
@@ -160,6 +171,7 @@ struct ll_protocol ethernet_protocol __ll_protocol = {
160 171
 	.init_addr	= eth_init_addr,
161 172
 	.ntoa		= eth_ntoa,
162 173
 	.mc_hash	= eth_mc_hash,
174
+	.eth_addr	= eth_eth_addr,
163 175
 };
164 176
 
165 177
 /**

Loading…
취소
저장