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

vxlan: Move address helpers to private headers

Move the helpers out of the core C file to the private header so that
they could be used by the upcoming MDB code.

While at it, constify the second argument of vxlan_nla_get_addr().

Signed-off-by: Ido Schimmel <idosch@nvidia.com>
Reviewed-by: Nikolay Aleksandrov <razor@blackwall.org>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Ido Schimmel and committed by
David S. Miller
f307c8bf da654c80

+45 -47
-47
drivers/net/vxlan/vxlan_core.c
··· 71 71 ip_tunnel_collect_metadata(); 72 72 } 73 73 74 - #if IS_ENABLED(CONFIG_IPV6) 75 - static int vxlan_nla_get_addr(union vxlan_addr *ip, struct nlattr *nla) 76 - { 77 - if (nla_len(nla) >= sizeof(struct in6_addr)) { 78 - ip->sin6.sin6_addr = nla_get_in6_addr(nla); 79 - ip->sa.sa_family = AF_INET6; 80 - return 0; 81 - } else if (nla_len(nla) >= sizeof(__be32)) { 82 - ip->sin.sin_addr.s_addr = nla_get_in_addr(nla); 83 - ip->sa.sa_family = AF_INET; 84 - return 0; 85 - } else { 86 - return -EAFNOSUPPORT; 87 - } 88 - } 89 - 90 - static int vxlan_nla_put_addr(struct sk_buff *skb, int attr, 91 - const union vxlan_addr *ip) 92 - { 93 - if (ip->sa.sa_family == AF_INET6) 94 - return nla_put_in6_addr(skb, attr, &ip->sin6.sin6_addr); 95 - else 96 - return nla_put_in_addr(skb, attr, ip->sin.sin_addr.s_addr); 97 - } 98 - 99 - #else /* !CONFIG_IPV6 */ 100 - 101 - static int vxlan_nla_get_addr(union vxlan_addr *ip, struct nlattr *nla) 102 - { 103 - if (nla_len(nla) >= sizeof(struct in6_addr)) { 104 - return -EAFNOSUPPORT; 105 - } else if (nla_len(nla) >= sizeof(__be32)) { 106 - ip->sin.sin_addr.s_addr = nla_get_in_addr(nla); 107 - ip->sa.sa_family = AF_INET; 108 - return 0; 109 - } else { 110 - return -EAFNOSUPPORT; 111 - } 112 - } 113 - 114 - static int vxlan_nla_put_addr(struct sk_buff *skb, int attr, 115 - const union vxlan_addr *ip) 116 - { 117 - return nla_put_in_addr(skb, attr, ip->sin.sin_addr.s_addr); 118 - } 119 - #endif 120 - 121 74 /* Find VXLAN socket based on network namespace, address family, UDP port, 122 75 * enabled unshareable flags and socket device binding (see l3mdev with 123 76 * non-default VRF).
+45
drivers/net/vxlan/vxlan_private.h
··· 85 85 return a->sin.sin_addr.s_addr == b->sin.sin_addr.s_addr; 86 86 } 87 87 88 + static inline int vxlan_nla_get_addr(union vxlan_addr *ip, 89 + const struct nlattr *nla) 90 + { 91 + if (nla_len(nla) >= sizeof(struct in6_addr)) { 92 + ip->sin6.sin6_addr = nla_get_in6_addr(nla); 93 + ip->sa.sa_family = AF_INET6; 94 + return 0; 95 + } else if (nla_len(nla) >= sizeof(__be32)) { 96 + ip->sin.sin_addr.s_addr = nla_get_in_addr(nla); 97 + ip->sa.sa_family = AF_INET; 98 + return 0; 99 + } else { 100 + return -EAFNOSUPPORT; 101 + } 102 + } 103 + 104 + static inline int vxlan_nla_put_addr(struct sk_buff *skb, int attr, 105 + const union vxlan_addr *ip) 106 + { 107 + if (ip->sa.sa_family == AF_INET6) 108 + return nla_put_in6_addr(skb, attr, &ip->sin6.sin6_addr); 109 + else 110 + return nla_put_in_addr(skb, attr, ip->sin.sin_addr.s_addr); 111 + } 112 + 88 113 #else /* !CONFIG_IPV6 */ 89 114 90 115 static inline 91 116 bool vxlan_addr_equal(const union vxlan_addr *a, const union vxlan_addr *b) 92 117 { 93 118 return a->sin.sin_addr.s_addr == b->sin.sin_addr.s_addr; 119 + } 120 + 121 + static inline int vxlan_nla_get_addr(union vxlan_addr *ip, 122 + const struct nlattr *nla) 123 + { 124 + if (nla_len(nla) >= sizeof(struct in6_addr)) { 125 + return -EAFNOSUPPORT; 126 + } else if (nla_len(nla) >= sizeof(__be32)) { 127 + ip->sin.sin_addr.s_addr = nla_get_in_addr(nla); 128 + ip->sa.sa_family = AF_INET; 129 + return 0; 130 + } else { 131 + return -EAFNOSUPPORT; 132 + } 133 + } 134 + 135 + static inline int vxlan_nla_put_addr(struct sk_buff *skb, int attr, 136 + const union vxlan_addr *ip) 137 + { 138 + return nla_put_in_addr(skb, attr, ip->sin.sin_addr.s_addr); 94 139 } 95 140 96 141 #endif