]> git.baikalelectronics.ru Git - kernel.git/commitdiff
net: Add helper function to parse netlink msg of ip_tunnel_parm
authorLiu Jian <liujian56@huawei.com>
Thu, 29 Sep 2022 13:52:03 +0000 (21:52 +0800)
committerDavid S. Miller <davem@davemloft.net>
Mon, 3 Oct 2022 06:59:06 +0000 (07:59 +0100)
Add ip_tunnel_netlink_parms to parse netlink msg of ip_tunnel_parm.
Reduces duplicate code, no actual functional changes.

Signed-off-by: Liu Jian <liujian56@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/ip_tunnels.h
net/ipv4/ip_tunnel_core.c
net/ipv4/ipip.c
net/ipv6/sit.c

index 51da2957cf48faa50511518a713b2b73e895665e..fca3576798166416982ee6a9100b003810c49830 100644 (file)
@@ -305,6 +305,9 @@ void ip_tunnel_setup(struct net_device *dev, unsigned int net_id);
 bool ip_tunnel_netlink_encap_parms(struct nlattr *data[],
                                   struct ip_tunnel_encap *encap);
 
+void ip_tunnel_netlink_parms(struct nlattr *data[],
+                            struct ip_tunnel_parm *parms);
+
 extern const struct header_ops ip_tunnel_header_ops;
 __be16 ip_tunnel_parse_protocol(const struct sk_buff *skb);
 
index 6d08f7e3919151823504230b786d5dc177a4b3db..92c02c886fe735ba0dd784181fe297acf8a98faa 100644 (file)
@@ -1114,3 +1114,35 @@ bool ip_tunnel_netlink_encap_parms(struct nlattr *data[],
        return ret;
 }
 EXPORT_SYMBOL_GPL(ip_tunnel_netlink_encap_parms);
+
+void ip_tunnel_netlink_parms(struct nlattr *data[],
+                            struct ip_tunnel_parm *parms)
+{
+       if (data[IFLA_IPTUN_LINK])
+               parms->link = nla_get_u32(data[IFLA_IPTUN_LINK]);
+
+       if (data[IFLA_IPTUN_LOCAL])
+               parms->iph.saddr = nla_get_be32(data[IFLA_IPTUN_LOCAL]);
+
+       if (data[IFLA_IPTUN_REMOTE])
+               parms->iph.daddr = nla_get_be32(data[IFLA_IPTUN_REMOTE]);
+
+       if (data[IFLA_IPTUN_TTL]) {
+               parms->iph.ttl = nla_get_u8(data[IFLA_IPTUN_TTL]);
+               if (parms->iph.ttl)
+                       parms->iph.frag_off = htons(IP_DF);
+       }
+
+       if (data[IFLA_IPTUN_TOS])
+               parms->iph.tos = nla_get_u8(data[IFLA_IPTUN_TOS]);
+
+       if (!data[IFLA_IPTUN_PMTUDISC] || nla_get_u8(data[IFLA_IPTUN_PMTUDISC]))
+               parms->iph.frag_off = htons(IP_DF);
+
+       if (data[IFLA_IPTUN_FLAGS])
+               parms->i_flags = nla_get_be16(data[IFLA_IPTUN_FLAGS]);
+
+       if (data[IFLA_IPTUN_PROTO])
+               parms->iph.protocol = nla_get_u8(data[IFLA_IPTUN_PROTO]);
+}
+EXPORT_SYMBOL_GPL(ip_tunnel_netlink_parms);
index 7c64ca06adf38caf5929fccc3719c36784bd3f28..180f9daf5bec577b8f6062185ea13f7af9e5fe33 100644 (file)
@@ -417,29 +417,7 @@ static void ipip_netlink_parms(struct nlattr *data[],
        if (!data)
                return;
 
-       if (data[IFLA_IPTUN_LINK])
-               parms->link = nla_get_u32(data[IFLA_IPTUN_LINK]);
-
-       if (data[IFLA_IPTUN_LOCAL])
-               parms->iph.saddr = nla_get_in_addr(data[IFLA_IPTUN_LOCAL]);
-
-       if (data[IFLA_IPTUN_REMOTE])
-               parms->iph.daddr = nla_get_in_addr(data[IFLA_IPTUN_REMOTE]);
-
-       if (data[IFLA_IPTUN_TTL]) {
-               parms->iph.ttl = nla_get_u8(data[IFLA_IPTUN_TTL]);
-               if (parms->iph.ttl)
-                       parms->iph.frag_off = htons(IP_DF);
-       }
-
-       if (data[IFLA_IPTUN_TOS])
-               parms->iph.tos = nla_get_u8(data[IFLA_IPTUN_TOS]);
-
-       if (data[IFLA_IPTUN_PROTO])
-               parms->iph.protocol = nla_get_u8(data[IFLA_IPTUN_PROTO]);
-
-       if (!data[IFLA_IPTUN_PMTUDISC] || nla_get_u8(data[IFLA_IPTUN_PMTUDISC]))
-               parms->iph.frag_off = htons(IP_DF);
+       ip_tunnel_netlink_parms(data, parms);
 
        if (data[IFLA_IPTUN_COLLECT_METADATA])
                *collect_md = true;
index a8a258f672fa03890ab55fa84ed2d52fe5c135ed..d27683e3fc971ec8f9c6ece5f92c5927f5feb789 100644 (file)
@@ -1503,32 +1503,7 @@ static void ipip6_netlink_parms(struct nlattr *data[],
        if (!data)
                return;
 
-       if (data[IFLA_IPTUN_LINK])
-               parms->link = nla_get_u32(data[IFLA_IPTUN_LINK]);
-
-       if (data[IFLA_IPTUN_LOCAL])
-               parms->iph.saddr = nla_get_be32(data[IFLA_IPTUN_LOCAL]);
-
-       if (data[IFLA_IPTUN_REMOTE])
-               parms->iph.daddr = nla_get_be32(data[IFLA_IPTUN_REMOTE]);
-
-       if (data[IFLA_IPTUN_TTL]) {
-               parms->iph.ttl = nla_get_u8(data[IFLA_IPTUN_TTL]);
-               if (parms->iph.ttl)
-                       parms->iph.frag_off = htons(IP_DF);
-       }
-
-       if (data[IFLA_IPTUN_TOS])
-               parms->iph.tos = nla_get_u8(data[IFLA_IPTUN_TOS]);
-
-       if (!data[IFLA_IPTUN_PMTUDISC] || nla_get_u8(data[IFLA_IPTUN_PMTUDISC]))
-               parms->iph.frag_off = htons(IP_DF);
-
-       if (data[IFLA_IPTUN_FLAGS])
-               parms->i_flags = nla_get_be16(data[IFLA_IPTUN_FLAGS]);
-
-       if (data[IFLA_IPTUN_PROTO])
-               parms->iph.protocol = nla_get_u8(data[IFLA_IPTUN_PROTO]);
+       ip_tunnel_netlink_parms(data, parms);
 
        if (data[IFLA_IPTUN_FWMARK])
                *fwmark = nla_get_u32(data[IFLA_IPTUN_FWMARK]);