Skip to content

Commit 9727c1b

Browse files
christophefontainetmonjalo
authored andcommitted
net: fix IPv6 link local compliance with RFC 4291
As specified in RFC 4291 section 2.5.1, link local addresses must be generated based on a modified EUI-64 interface identifier: > Modified EUI-64 format interface identifiers are formed by inverting > the "u" bit (universal/local bit in IEEE EUI-64 terminology) when > forming the interface identifier from IEEE EUI-64 identifiers. This translates to 'mac->addr_bytes[0] ^= 0x02'. Fixes: 3d6d85f ("net: add utilities for well known IPv6 address types") Cc: [email protected] Signed-off-by: Christophe Fontaine <[email protected]> Signed-off-by: Robin Jarry <[email protected]>
1 parent e0b87fa commit 9727c1b

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

app/test/test_net_ip6.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ test_ipv6_llocal_from_ethernet(void)
160160
{
161161
const struct rte_ether_addr local_mac = {{0x04, 0x7b, 0xcb, 0x5c, 0x08, 0x44}};
162162
const struct rte_ipv6_addr local_ip =
163-
RTE_IPV6(0xfe80, 0, 0, 0, 0x047b, 0xcbff, 0xfe5c, 0x0844);
163+
RTE_IPV6(0xfe80, 0, 0, 0, 0x067b, 0xcbff, 0xfe5c, 0x0844);
164164
struct rte_ipv6_addr ip;
165165

166166
rte_ipv6_llocal_from_ethernet(&ip, &local_mac);

lib/net/rte_ip6.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ rte_ipv6_mc_scope(const struct rte_ipv6_addr *ip)
393393

394394
/*
395395
* Generate a link-local IPv6 address from an Ethernet address as specified in
396-
* RFC 2464, section 5.
396+
* RFC 4291, section 2.5.1.
397397
*
398398
* @param[out] ip
399399
* The link-local IPv6 address to generate.
@@ -406,7 +406,12 @@ rte_ipv6_llocal_from_ethernet(struct rte_ipv6_addr *ip, const struct rte_ether_a
406406
ip->a[0] = 0xfe;
407407
ip->a[1] = 0x80;
408408
memset(&ip->a[2], 0, 6);
409-
ip->a[8] = mac->addr_bytes[0];
409+
/*
410+
* The "u" bit (universal/local bit in IEEE EUI-64 terminology)
411+
* must be inverted for IPv6 link local address.
412+
* 0 means local scope, 1 means universal scope.
413+
*/
414+
ip->a[8] = mac->addr_bytes[0] ^ RTE_ETHER_LOCAL_ADMIN_ADDR;
410415
ip->a[9] = mac->addr_bytes[1];
411416
ip->a[10] = mac->addr_bytes[2];
412417
ip->a[11] = 0xff;

0 commit comments

Comments
 (0)