Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ipv6: Use container_of macro instead of magic number to get ipv6 header.

In ipv6_recv_error(), addr_offset points to daddr field of the ip header.
To get ipv6 header, use container_of() macro instead of substracting magic
number (24).

Signed-off-by: YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

YOSHIFUJI Hideaki / 吉藤英明 and committed by
David S. Miller
6c40d100 29166107

+4 -5
+4 -5
net/ipv6/datagram.c
··· 356 356 sin->sin6_port = serr->port; 357 357 sin->sin6_scope_id = 0; 358 358 if (skb->protocol == htons(ETH_P_IPV6)) { 359 - sin->sin6_addr = 360 - *(struct in6_addr *)(nh + serr->addr_offset); 359 + const struct ipv6hdr *ip6h = container_of((struct in6_addr *)(nh + serr->addr_offset), 360 + struct ipv6hdr, daddr); 361 + sin->sin6_addr = ip6h->daddr; 361 362 if (np->sndflow) 362 - sin->sin6_flowinfo = 363 - (*(__be32 *)(nh + serr->addr_offset - 24) & 364 - IPV6_FLOWINFO_MASK); 363 + sin->sin6_flowinfo = *(__be32 *)ip6h & IPV6_FLOWINFO_MASK; 365 364 if (ipv6_addr_type(&sin->sin6_addr) & IPV6_ADDR_LINKLOCAL) 366 365 sin->sin6_scope_id = IP6CB(skb)->iif; 367 366 } else {