Browse Source

[netdevice] Add method for generating EUI-64 address from link-layer address

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 10 years ago
parent
commit
0b65c8cad6

+ 1
- 0
src/drivers/net/ipoib.c View File

@@ -265,6 +265,7 @@ struct ll_protocol ipoib_protocol __ll_protocol = {
265 265
 	.ntoa		= eth_ntoa,
266 266
 	.mc_hash	= eth_mc_hash,
267 267
 	.eth_addr	= eth_eth_addr,
268
+	.eui64		= eth_eui64,
268 269
 	.flags		= LL_NAME_ONLY,
269 270
 };
270 271
 

+ 1
- 0
src/include/ipxe/ethernet.h View File

@@ -91,6 +91,7 @@ extern const char * eth_ntoa ( const void *ll_addr );
91 91
 extern int eth_mc_hash ( unsigned int af, const void *net_addr,
92 92
 			 void *ll_addr );
93 93
 extern int eth_eth_addr ( const void *ll_addr, void *eth_addr );
94
+extern int eth_eui64 ( const void *ll_addr, void *eui64 );
94 95
 extern struct net_device * alloc_etherdev ( size_t priv_size );
95 96
 
96 97
 #endif /* _IPXE_ETHERNET_H */

+ 9
- 0
src/include/ipxe/netdevice.h View File

@@ -175,8 +175,17 @@ struct ll_protocol {
175 175
 	 *
176 176
 	 * @v ll_addr		Link-layer address
177 177
 	 * @v eth_addr		Ethernet-compatible address to fill in
178
+	 * @ret rc		Return status code
178 179
 	 */
179 180
 	int ( * eth_addr ) ( const void *ll_addr, void *eth_addr );
181
+	/**
182
+	 * Generate EUI-64 address
183
+	 *
184
+	 * @v ll_addr		Link-layer address
185
+	 * @v eui64		EUI-64 address to fill in
186
+	 * @ret rc		Return status code
187
+	 */
188
+	int ( * eui64 ) ( const void *ll_addr, void *eui64 );
180 189
 	/** Link-layer protocol
181 190
 	 *
182 191
 	 * This is an ARPHRD_XXX constant, in network byte order.

+ 1
- 0
src/net/80211/net80211.c View File

@@ -599,6 +599,7 @@ static struct ll_protocol net80211_ll_protocol __ll_protocol = {
599 599
 	.ntoa = eth_ntoa,
600 600
 	.mc_hash = eth_mc_hash,
601 601
 	.eth_addr = eth_eth_addr,
602
+	.eui64 = eth_eui64,
602 603
 	.ll_proto = htons ( ARPHRD_ETHER ),	/* "encapsulated Ethernet" */
603 604
 	.hw_addr_len = ETH_ALEN,
604 605
 	.ll_addr_len = ETH_ALEN,

+ 16
- 0
src/net/ethernet.c View File

@@ -165,6 +165,21 @@ int eth_eth_addr ( const void *ll_addr, void *eth_addr ) {
165 165
 	return 0;
166 166
 }
167 167
 
168
+/**
169
+ * Generate EUI-64 address
170
+ *
171
+ * @v ll_addr		Link-layer address
172
+ * @v eui64		EUI-64 address to fill in
173
+ * @ret rc		Return status code
174
+ */
175
+int eth_eui64 ( const void *ll_addr, void *eui64 ) {
176
+
177
+	memcpy ( ( eui64 + 0 ), ( ll_addr + 0 ), 3 );
178
+	memcpy ( ( eui64 + 5 ), ( ll_addr + 3 ), 3 );
179
+	*( ( uint16_t * ) ( eui64 + 3 ) ) = htons ( 0xfffe );
180
+	return 0;
181
+}
182
+
168 183
 /** Ethernet protocol */
169 184
 struct ll_protocol ethernet_protocol __ll_protocol = {
170 185
 	.name		= "Ethernet",
@@ -178,6 +193,7 @@ struct ll_protocol ethernet_protocol __ll_protocol = {
178 193
 	.ntoa		= eth_ntoa,
179 194
 	.mc_hash	= eth_mc_hash,
180 195
 	.eth_addr	= eth_eth_addr,
196
+	.eui64		= eth_eui64,
181 197
 };
182 198
 
183 199
 /**

Loading…
Cancel
Save