diff mbox series

[net-next,v2,2/2] net: Add helper function to parse netlink msg of ip_tunnel_parm

Message ID 20220928033917.281937-3-liujian56@huawei.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series Add helper functions to parse netlink msg of ip_tunnel | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 182 this patch: 182
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/build_clang success Errors and warnings before: 11 this patch: 11
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 195 this patch: 195
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 107 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Liu Jian Sept. 28, 2022, 3:39 a.m. UTC
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>
---
v1->v2: Move the implementation of the helper function to ip_tunnel_core.c
 include/net/ip_tunnels.h  |  3 +++
 net/ipv4/ip_tunnel_core.c | 32 ++++++++++++++++++++++++++++++++
 net/ipv4/ipip.c           | 24 +-----------------------
 net/ipv6/sit.c            | 27 +--------------------------
 4 files changed, 37 insertions(+), 49 deletions(-)

Comments

Paolo Abeni Sept. 29, 2022, 1:16 p.m. UTC | #1
On Wed, 2022-09-28 at 11:39 +0800, Liu Jian wrote:
> 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>
> ---
> v1->v2: Move the implementation of the helper function to ip_tunnel_core.c
>  include/net/ip_tunnels.h  |  3 +++
>  net/ipv4/ip_tunnel_core.c | 32 ++++++++++++++++++++++++++++++++
>  net/ipv4/ipip.c           | 24 +-----------------------
>  net/ipv6/sit.c            | 27 +--------------------------
>  4 files changed, 37 insertions(+), 49 deletions(-)
> 
> diff --git a/include/net/ip_tunnels.h b/include/net/ip_tunnels.h
> index 51da2957cf48..fca357679816 100644
> --- a/include/net/ip_tunnels.h
> +++ b/include/net/ip_tunnels.h
> @@ -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);
>  
> diff --git a/net/ipv4/ip_tunnel_core.c b/net/ipv4/ip_tunnel_core.c
> index 526e6a52a973..1e1217e87885 100644
> --- a/net/ipv4/ip_tunnel_core.c
> +++ b/net/ipv4/ip_tunnel_core.c
> @@ -1114,3 +1114,35 @@ bool ip_tunnel_netlink_encap_parms(struct nlattr *data[],
>  	return ret;
>  }
>  EXPORT_SYMBOL(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(ip_tunnel_netlink_parms);

The same here, I think it should be EXPORT_SYMBOL_GPL()

Thanks,

Paolo
Liu Jian Sept. 29, 2022, 1:38 p.m. UTC | #2
> -----Original Message-----
> From: Paolo Abeni [mailto:pabeni@redhat.com]
> Sent: Thursday, September 29, 2022 9:17 PM
> To: liujian (CE) <liujian56@huawei.com>; davem@davemloft.net;
> yoshfuji@linux-ipv6.org; dsahern@kernel.org; edumazet@google.com;
> kuba@kernel.org; netdev@vger.kernel.org
> Subject: Re: [PATCH net-next v2 2/2] net: Add helper function to parse
> netlink msg of ip_tunnel_parm
> 
> On Wed, 2022-09-28 at 11:39 +0800, Liu Jian wrote:
> > 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>
> > ---
> > v1->v2: Move the implementation of the helper function to
> > v1->ip_tunnel_core.c
> >  include/net/ip_tunnels.h  |  3 +++
> >  net/ipv4/ip_tunnel_core.c | 32 ++++++++++++++++++++++++++++++++
> >  net/ipv4/ipip.c           | 24 +-----------------------
> >  net/ipv6/sit.c            | 27 +--------------------------
> >  4 files changed, 37 insertions(+), 49 deletions(-)
> >
> > diff --git a/include/net/ip_tunnels.h b/include/net/ip_tunnels.h index
> > 51da2957cf48..fca357679816 100644
> > --- a/include/net/ip_tunnels.h
> > +++ b/include/net/ip_tunnels.h
> > @@ -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);
> >
> > diff --git a/net/ipv4/ip_tunnel_core.c b/net/ipv4/ip_tunnel_core.c
> > index 526e6a52a973..1e1217e87885 100644
> > --- a/net/ipv4/ip_tunnel_core.c
> > +++ b/net/ipv4/ip_tunnel_core.c
> > @@ -1114,3 +1114,35 @@ bool ip_tunnel_netlink_encap_parms(struct
> nlattr *data[],
> >  	return ret;
> >  }
> >  EXPORT_SYMBOL(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(ip_tunnel_netlink_parms);
> 
> The same here, I think it should be EXPORT_SYMBOL_GPL()
OK, thanks for your review, I will send v3 for this.
> 
> Thanks,
> 
> Paolo
>
diff mbox series

Patch

diff --git a/include/net/ip_tunnels.h b/include/net/ip_tunnels.h
index 51da2957cf48..fca357679816 100644
--- a/include/net/ip_tunnels.h
+++ b/include/net/ip_tunnels.h
@@ -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);
 
diff --git a/net/ipv4/ip_tunnel_core.c b/net/ipv4/ip_tunnel_core.c
index 526e6a52a973..1e1217e87885 100644
--- a/net/ipv4/ip_tunnel_core.c
+++ b/net/ipv4/ip_tunnel_core.c
@@ -1114,3 +1114,35 @@  bool ip_tunnel_netlink_encap_parms(struct nlattr *data[],
 	return ret;
 }
 EXPORT_SYMBOL(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(ip_tunnel_netlink_parms);
diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
index 7c64ca06adf3..180f9daf5bec 100644
--- a/net/ipv4/ipip.c
+++ b/net/ipv4/ipip.c
@@ -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;
diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
index a8a258f672fa..d27683e3fc97 100644
--- a/net/ipv6/sit.c
+++ b/net/ipv6/sit.c
@@ -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]);