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

xfrm: simplify xfrm_address_t use

In many places, the a6 field is typecasted to struct in6_addr. As the
fields are in union anyway, just add in6_addr type to the union and
get rid of the typecasting.

Modifying the uapi header is okay, the union has still the same size.

Signed-off-by: Jiri Benc <jbenc@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Jiri Benc and committed by
David S. Miller
15e318bd 8f55db48

+13 -13
+3 -3
include/net/xfrm.h
··· 1025 1025 case AF_INET: 1026 1026 return addr->a4 == 0; 1027 1027 case AF_INET6: 1028 - return ipv6_addr_any((struct in6_addr *)&addr->a6); 1028 + return ipv6_addr_any(&addr->in6); 1029 1029 } 1030 1030 return 0; 1031 1031 } ··· 1238 1238 memcpy(&daddr->a4, &fl->u.ip4.daddr, sizeof(daddr->a4)); 1239 1239 break; 1240 1240 case AF_INET6: 1241 - *(struct in6_addr *)saddr->a6 = fl->u.ip6.saddr; 1242 - *(struct in6_addr *)daddr->a6 = fl->u.ip6.daddr; 1241 + saddr->in6 = fl->u.ip6.saddr; 1242 + daddr->in6 = fl->u.ip6.daddr; 1243 1243 break; 1244 1244 } 1245 1245 }
+2
include/uapi/linux/xfrm.h
··· 1 1 #ifndef _LINUX_XFRM_H 2 2 #define _LINUX_XFRM_H 3 3 4 + #include <linux/in6.h> 4 5 #include <linux/types.h> 5 6 6 7 /* All of the structures in this file may not change size as they are ··· 14 13 typedef union { 15 14 __be32 a4; 16 15 __be32 a6[4]; 16 + struct in6_addr in6; 17 17 } xfrm_address_t; 18 18 19 19 /* Ident of a specific xfrm_state. It is used on input to lookup
+2 -2
net/ipv6/xfrm6_mode_beet.c
··· 95 95 96 96 ip6h = ipv6_hdr(skb); 97 97 ip6h->payload_len = htons(skb->len - size); 98 - ip6h->daddr = *(struct in6_addr *)&x->sel.daddr.a6; 99 - ip6h->saddr = *(struct in6_addr *)&x->sel.saddr.a6; 98 + ip6h->daddr = x->sel.daddr.in6; 99 + ip6h->saddr = x->sel.saddr.in6; 100 100 err = 0; 101 101 out: 102 102 return err;
+1 -3
net/ipv6/xfrm6_policy.c
··· 61 61 return -EHOSTUNREACH; 62 62 63 63 dev = ip6_dst_idev(dst)->dev; 64 - ipv6_dev_get_saddr(dev_net(dev), dev, 65 - (struct in6_addr *)&daddr->a6, 0, 66 - (struct in6_addr *)&saddr->a6); 64 + ipv6_dev_get_saddr(dev_net(dev), dev, &daddr->in6, 0, &saddr->in6); 67 65 dst_release(dst); 68 66 return 0; 69 67 }
+1 -1
net/key/af_key.c
··· 709 709 sin6->sin6_family = AF_INET6; 710 710 sin6->sin6_port = port; 711 711 sin6->sin6_flowinfo = 0; 712 - sin6->sin6_addr = *(struct in6_addr *)xaddr->a6; 712 + sin6->sin6_addr = xaddr->in6; 713 713 sin6->sin6_scope_id = 0; 714 714 return 128; 715 715 }
+4 -4
net/xfrm/xfrm_state.c
··· 1043 1043 break; 1044 1044 1045 1045 case AF_INET6: 1046 - *(struct in6_addr *)x->sel.daddr.a6 = *(struct in6_addr *)daddr; 1047 - *(struct in6_addr *)x->sel.saddr.a6 = *(struct in6_addr *)saddr; 1046 + x->sel.daddr.in6 = daddr->in6; 1047 + x->sel.saddr.in6 = saddr->in6; 1048 1048 x->sel.prefixlen_d = 128; 1049 1049 x->sel.prefixlen_s = 128; 1050 - *(struct in6_addr *)x->props.saddr.a6 = *(struct in6_addr *)saddr; 1051 - *(struct in6_addr *)x->id.daddr.a6 = *(struct in6_addr *)daddr; 1050 + x->props.saddr.in6 = saddr->in6; 1051 + x->id.daddr.in6 = daddr->in6; 1052 1052 break; 1053 1053 } 1054 1054