Skip to content

Commit f307c8b

Browse files
idoschdavem330
authored andcommitted
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 <[email protected]> Reviewed-by: Nikolay Aleksandrov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent da654c8 commit f307c8b

File tree

2 files changed

+45
-47
lines changed

2 files changed

+45
-47
lines changed

drivers/net/vxlan/vxlan_core.c

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -71,53 +71,6 @@ static inline bool vxlan_collect_metadata(struct vxlan_sock *vs)
7171
ip_tunnel_collect_metadata();
7272
}
7373

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-
12174
/* Find VXLAN socket based on network namespace, address family, UDP port,
12275
* enabled unshareable flags and socket device binding (see l3mdev with
12376
* non-default VRF).

drivers/net/vxlan/vxlan_private.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,31 @@ bool vxlan_addr_equal(const union vxlan_addr *a, const union vxlan_addr *b)
8585
return a->sin.sin_addr.s_addr == b->sin.sin_addr.s_addr;
8686
}
8787

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+
88113
#else /* !CONFIG_IPV6 */
89114

90115
static inline
@@ -93,6 +118,26 @@ bool vxlan_addr_equal(const union vxlan_addr *a, const union vxlan_addr *b)
93118
return a->sin.sin_addr.s_addr == b->sin.sin_addr.s_addr;
94119
}
95120

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);
139+
}
140+
96141
#endif
97142

98143
static inline struct vxlan_vni_node *

0 commit comments

Comments
 (0)