Skip to content

Commit dd693f9

Browse files
Jiri BencPravin B Shelar
authored andcommitted
datapath: Use netlink ipv4 API to handle the ipv4 addr attributes.
upstream: ("netlink: implement nla_put_in_addr and nla_put_in6_addr") upstream: ("netlink: implement nla_get_in_addr and nla_get_in6_addr") IP addresses are often stored in netlink attributes. Add generic functions to do that. Signed-off-by: Jiri Benc <jbenc@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net> Acked-by: Pravin B Shelar <pshelar@nicira.com>
1 parent c465f75 commit dd693f9

3 files changed

Lines changed: 33 additions & 4 deletions

File tree

acinclude.m4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ AC_DEFUN([OVS_CHECK_LINUX_COMPAT], [
422422
OVS_GREP_IFELSE([$KSRC/include/net/netlink.h], [nla_put_be16])
423423
OVS_GREP_IFELSE([$KSRC/include/net/netlink.h], [nla_put_be32])
424424
OVS_GREP_IFELSE([$KSRC/include/net/netlink.h], [nla_put_be64])
425+
OVS_GREP_IFELSE([$KSRC/include/net/netlink.h], [nla_put_in_addr])
425426
OVS_GREP_IFELSE([$KSRC/include/net/netlink.h], [nla_find_nested])
426427
OVS_GREP_IFELSE([$KSRC/include/net/netlink.h], [nla_is_last])
427428

datapath/flow_netlink.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -535,11 +535,11 @@ static int ipv4_tun_from_nlattr(const struct nlattr *attr,
535535
break;
536536
case OVS_TUNNEL_KEY_ATTR_IPV4_SRC:
537537
SW_FLOW_KEY_PUT(match, tun_key.ipv4_src,
538-
nla_get_be32(a), is_mask);
538+
nla_get_in_addr(a), is_mask);
539539
break;
540540
case OVS_TUNNEL_KEY_ATTR_IPV4_DST:
541541
SW_FLOW_KEY_PUT(match, tun_key.ipv4_dst,
542-
nla_get_be32(a), is_mask);
542+
nla_get_in_addr(a), is_mask);
543543
break;
544544
case OVS_TUNNEL_KEY_ATTR_TOS:
545545
SW_FLOW_KEY_PUT(match, tun_key.ipv4_tos,
@@ -648,10 +648,10 @@ static int __ipv4_tun_to_nlattr(struct sk_buff *skb,
648648
nla_put_be64(skb, OVS_TUNNEL_KEY_ATTR_ID, output->tun_id))
649649
return -EMSGSIZE;
650650
if (output->ipv4_src &&
651-
nla_put_be32(skb, OVS_TUNNEL_KEY_ATTR_IPV4_SRC, output->ipv4_src))
651+
nla_put_in_addr(skb, OVS_TUNNEL_KEY_ATTR_IPV4_SRC, output->ipv4_src))
652652
return -EMSGSIZE;
653653
if (output->ipv4_dst &&
654-
nla_put_be32(skb, OVS_TUNNEL_KEY_ATTR_IPV4_DST, output->ipv4_dst))
654+
nla_put_in_addr(skb, OVS_TUNNEL_KEY_ATTR_IPV4_DST, output->ipv4_dst))
655655
return -EMSGSIZE;
656656
if (output->ipv4_tos &&
657657
nla_put_u8(skb, OVS_TUNNEL_KEY_ATTR_TOS, output->ipv4_tos))

datapath/linux/compat/include/net/netlink.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <linux/version.h>
55
#include_next <net/netlink.h>
6+
#include_next <linux/in6.h>
67

78
#ifndef HAVE_NLA_GET_BE16
89
/**
@@ -70,4 +71,31 @@ static inline bool nla_is_last(const struct nlattr *nla, int rem)
7071
}
7172
#endif
7273

74+
#ifndef HAVE_NLA_PUT_IN_ADDR
75+
static inline int nla_put_in_addr(struct sk_buff *skb, int attrtype,
76+
__be32 addr)
77+
{
78+
return nla_put_be32(skb, attrtype, addr);
79+
}
80+
81+
static inline int nla_put_in6_addr(struct sk_buff *skb, int attrtype,
82+
const struct in6_addr *addr)
83+
{
84+
return nla_put(skb, attrtype, sizeof(*addr), addr);
85+
}
86+
87+
static inline __be32 nla_get_in_addr(const struct nlattr *nla)
88+
{
89+
return *(__be32 *) nla_data(nla);
90+
}
91+
92+
static inline struct in6_addr nla_get_in6_addr(const struct nlattr *nla)
93+
{
94+
struct in6_addr tmp;
95+
96+
nla_memcpy(&tmp, nla, sizeof(tmp));
97+
return tmp;
98+
}
99+
#endif
100+
73101
#endif /* net/netlink.h */

0 commit comments

Comments
 (0)