* [PATCH net-next 0/2] Add helper functions to parse netlink msg of ip_tunnel
@ 2022-09-26 13:19 Liu Jian
2022-09-26 13:19 ` [PATCH net-next 1/2] net: Add helper function to parse netlink msg of ip_tunnel_encap Liu Jian
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Liu Jian @ 2022-09-26 13:19 UTC (permalink / raw)
To: davem, yoshfuji, dsahern, edumazet, kuba, pabeni, netdev; +Cc: liujian56
Add helper functions to parse netlinkmsg of ip_tunnel
Liu Jian (2):
net: Add helper function to parse netlink msg of ip_tunnel_encap
net: Add helper function to parse netlink msg of ip_tunnel_parm
include/net/ip_tunnels.h | 66 ++++++++++++++++++++++++++++++++++++++++
net/ipv4/ipip.c | 62 ++-----------------------------------
net/ipv6/ip6_tunnel.c | 37 ++--------------------
net/ipv6/sit.c | 65 ++-------------------------------------
4 files changed, 74 insertions(+), 156 deletions(-)
--
2.17.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH net-next 1/2] net: Add helper function to parse netlink msg of ip_tunnel_encap
2022-09-26 13:19 [PATCH net-next 0/2] Add helper functions to parse netlink msg of ip_tunnel Liu Jian
@ 2022-09-26 13:19 ` Liu Jian
2022-09-26 13:19 ` [PATCH net-next 2/2] net: Add helper function to parse netlink msg of ip_tunnel_parm Liu Jian
2022-09-27 14:58 ` [PATCH net-next 0/2] Add helper functions to parse netlink msg of ip_tunnel Jakub Kicinski
2 siblings, 0 replies; 5+ messages in thread
From: Liu Jian @ 2022-09-26 13:19 UTC (permalink / raw)
To: davem, yoshfuji, dsahern, edumazet, kuba, pabeni, netdev; +Cc: liujian56
Add ip_tunnel_netlink_encap_parms to parse netlink msg of ip_tunnel_encap.
Reduces duplicate code, no actual functional changes.
Signed-off-by: Liu Jian <liujian56@huawei.com>
---
include/net/ip_tunnels.h | 34 ++++++++++++++++++++++++++++++++++
net/ipv4/ipip.c | 38 ++------------------------------------
net/ipv6/ip6_tunnel.c | 37 ++-----------------------------------
net/ipv6/sit.c | 38 ++------------------------------------
4 files changed, 40 insertions(+), 107 deletions(-)
diff --git a/include/net/ip_tunnels.h b/include/net/ip_tunnels.h
index ced80e2f8b58..e8bb8944ce3f 100644
--- a/include/net/ip_tunnels.h
+++ b/include/net/ip_tunnels.h
@@ -302,6 +302,40 @@ int ip_tunnel_newlink(struct net_device *dev, struct nlattr *tb[],
struct ip_tunnel_parm *p, __u32 fwmark);
void ip_tunnel_setup(struct net_device *dev, unsigned int net_id);
+/* This function returns true when ENCAP attributes are present in the nl msg */
+static inline bool ip_tunnel_netlink_encap_parms(struct nlattr *data[],
+ struct ip_tunnel_encap *encap)
+{
+ bool ret = false;
+
+ memset(encap, 0, sizeof(*encap));
+
+ if (!data)
+ return ret;
+
+ if (data[IFLA_IPTUN_ENCAP_TYPE]) {
+ ret = true;
+ encap->type = nla_get_u16(data[IFLA_IPTUN_ENCAP_TYPE]);
+ }
+
+ if (data[IFLA_IPTUN_ENCAP_FLAGS]) {
+ ret = true;
+ encap->flags = nla_get_u16(data[IFLA_IPTUN_ENCAP_FLAGS]);
+ }
+
+ if (data[IFLA_IPTUN_ENCAP_SPORT]) {
+ ret = true;
+ encap->sport = nla_get_be16(data[IFLA_IPTUN_ENCAP_SPORT]);
+ }
+
+ if (data[IFLA_IPTUN_ENCAP_DPORT]) {
+ ret = true;
+ encap->dport = nla_get_be16(data[IFLA_IPTUN_ENCAP_DPORT]);
+ }
+
+ return ret;
+}
+
extern const struct header_ops ip_tunnel_header_ops;
__be16 ip_tunnel_parse_protocol(const struct sk_buff *skb);
diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
index 123ea63a04cb..7c64ca06adf3 100644
--- a/net/ipv4/ipip.c
+++ b/net/ipv4/ipip.c
@@ -448,40 +448,6 @@ static void ipip_netlink_parms(struct nlattr *data[],
*fwmark = nla_get_u32(data[IFLA_IPTUN_FWMARK]);
}
-/* This function returns true when ENCAP attributes are present in the nl msg */
-static bool ipip_netlink_encap_parms(struct nlattr *data[],
- struct ip_tunnel_encap *ipencap)
-{
- bool ret = false;
-
- memset(ipencap, 0, sizeof(*ipencap));
-
- if (!data)
- return ret;
-
- if (data[IFLA_IPTUN_ENCAP_TYPE]) {
- ret = true;
- ipencap->type = nla_get_u16(data[IFLA_IPTUN_ENCAP_TYPE]);
- }
-
- if (data[IFLA_IPTUN_ENCAP_FLAGS]) {
- ret = true;
- ipencap->flags = nla_get_u16(data[IFLA_IPTUN_ENCAP_FLAGS]);
- }
-
- if (data[IFLA_IPTUN_ENCAP_SPORT]) {
- ret = true;
- ipencap->sport = nla_get_be16(data[IFLA_IPTUN_ENCAP_SPORT]);
- }
-
- if (data[IFLA_IPTUN_ENCAP_DPORT]) {
- ret = true;
- ipencap->dport = nla_get_be16(data[IFLA_IPTUN_ENCAP_DPORT]);
- }
-
- return ret;
-}
-
static int ipip_newlink(struct net *src_net, struct net_device *dev,
struct nlattr *tb[], struct nlattr *data[],
struct netlink_ext_ack *extack)
@@ -491,7 +457,7 @@ static int ipip_newlink(struct net *src_net, struct net_device *dev,
struct ip_tunnel_encap ipencap;
__u32 fwmark = 0;
- if (ipip_netlink_encap_parms(data, &ipencap)) {
+ if (ip_tunnel_netlink_encap_parms(data, &ipencap)) {
int err = ip_tunnel_encap_setup(t, &ipencap);
if (err < 0)
@@ -512,7 +478,7 @@ static int ipip_changelink(struct net_device *dev, struct nlattr *tb[],
bool collect_md;
__u32 fwmark = t->fwmark;
- if (ipip_netlink_encap_parms(data, &ipencap)) {
+ if (ip_tunnel_netlink_encap_parms(data, &ipencap)) {
int err = ip_tunnel_encap_setup(t, &ipencap);
if (err < 0)
diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
index 9e97f3b4c7e8..cc5d5e75b658 100644
--- a/net/ipv6/ip6_tunnel.c
+++ b/net/ipv6/ip6_tunnel.c
@@ -1988,39 +1988,6 @@ static void ip6_tnl_netlink_parms(struct nlattr *data[],
parms->fwmark = nla_get_u32(data[IFLA_IPTUN_FWMARK]);
}
-static bool ip6_tnl_netlink_encap_parms(struct nlattr *data[],
- struct ip_tunnel_encap *ipencap)
-{
- bool ret = false;
-
- memset(ipencap, 0, sizeof(*ipencap));
-
- if (!data)
- return ret;
-
- if (data[IFLA_IPTUN_ENCAP_TYPE]) {
- ret = true;
- ipencap->type = nla_get_u16(data[IFLA_IPTUN_ENCAP_TYPE]);
- }
-
- if (data[IFLA_IPTUN_ENCAP_FLAGS]) {
- ret = true;
- ipencap->flags = nla_get_u16(data[IFLA_IPTUN_ENCAP_FLAGS]);
- }
-
- if (data[IFLA_IPTUN_ENCAP_SPORT]) {
- ret = true;
- ipencap->sport = nla_get_be16(data[IFLA_IPTUN_ENCAP_SPORT]);
- }
-
- if (data[IFLA_IPTUN_ENCAP_DPORT]) {
- ret = true;
- ipencap->dport = nla_get_be16(data[IFLA_IPTUN_ENCAP_DPORT]);
- }
-
- return ret;
-}
-
static int ip6_tnl_newlink(struct net *src_net, struct net_device *dev,
struct nlattr *tb[], struct nlattr *data[],
struct netlink_ext_ack *extack)
@@ -2033,7 +2000,7 @@ static int ip6_tnl_newlink(struct net *src_net, struct net_device *dev,
nt = netdev_priv(dev);
- if (ip6_tnl_netlink_encap_parms(data, &ipencap)) {
+ if (ip_tunnel_netlink_encap_parms(data, &ipencap)) {
err = ip6_tnl_encap_setup(nt, &ipencap);
if (err < 0)
return err;
@@ -2070,7 +2037,7 @@ static int ip6_tnl_changelink(struct net_device *dev, struct nlattr *tb[],
if (dev == ip6n->fb_tnl_dev)
return -EINVAL;
- if (ip6_tnl_netlink_encap_parms(data, &ipencap)) {
+ if (ip_tunnel_netlink_encap_parms(data, &ipencap)) {
int err = ip6_tnl_encap_setup(t, &ipencap);
if (err < 0)
diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
index 98f1cf40746f..a8a258f672fa 100644
--- a/net/ipv6/sit.c
+++ b/net/ipv6/sit.c
@@ -1534,40 +1534,6 @@ static void ipip6_netlink_parms(struct nlattr *data[],
*fwmark = nla_get_u32(data[IFLA_IPTUN_FWMARK]);
}
-/* This function returns true when ENCAP attributes are present in the nl msg */
-static bool ipip6_netlink_encap_parms(struct nlattr *data[],
- struct ip_tunnel_encap *ipencap)
-{
- bool ret = false;
-
- memset(ipencap, 0, sizeof(*ipencap));
-
- if (!data)
- return ret;
-
- if (data[IFLA_IPTUN_ENCAP_TYPE]) {
- ret = true;
- ipencap->type = nla_get_u16(data[IFLA_IPTUN_ENCAP_TYPE]);
- }
-
- if (data[IFLA_IPTUN_ENCAP_FLAGS]) {
- ret = true;
- ipencap->flags = nla_get_u16(data[IFLA_IPTUN_ENCAP_FLAGS]);
- }
-
- if (data[IFLA_IPTUN_ENCAP_SPORT]) {
- ret = true;
- ipencap->sport = nla_get_be16(data[IFLA_IPTUN_ENCAP_SPORT]);
- }
-
- if (data[IFLA_IPTUN_ENCAP_DPORT]) {
- ret = true;
- ipencap->dport = nla_get_be16(data[IFLA_IPTUN_ENCAP_DPORT]);
- }
-
- return ret;
-}
-
#ifdef CONFIG_IPV6_SIT_6RD
/* This function returns true when 6RD attributes are present in the nl msg */
static bool ipip6_netlink_6rd_parms(struct nlattr *data[],
@@ -1619,7 +1585,7 @@ static int ipip6_newlink(struct net *src_net, struct net_device *dev,
nt = netdev_priv(dev);
- if (ipip6_netlink_encap_parms(data, &ipencap)) {
+ if (ip_tunnel_netlink_encap_parms(data, &ipencap)) {
err = ip_tunnel_encap_setup(nt, &ipencap);
if (err < 0)
return err;
@@ -1671,7 +1637,7 @@ static int ipip6_changelink(struct net_device *dev, struct nlattr *tb[],
if (dev == sitn->fb_tunnel_dev)
return -EINVAL;
- if (ipip6_netlink_encap_parms(data, &ipencap)) {
+ if (ip_tunnel_netlink_encap_parms(data, &ipencap)) {
err = ip_tunnel_encap_setup(t, &ipencap);
if (err < 0)
return err;
--
2.17.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH net-next 2/2] net: Add helper function to parse netlink msg of ip_tunnel_parm
2022-09-26 13:19 [PATCH net-next 0/2] Add helper functions to parse netlink msg of ip_tunnel Liu Jian
2022-09-26 13:19 ` [PATCH net-next 1/2] net: Add helper function to parse netlink msg of ip_tunnel_encap Liu Jian
@ 2022-09-26 13:19 ` Liu Jian
2022-09-27 14:58 ` [PATCH net-next 0/2] Add helper functions to parse netlink msg of ip_tunnel Jakub Kicinski
2 siblings, 0 replies; 5+ messages in thread
From: Liu Jian @ 2022-09-26 13:19 UTC (permalink / raw)
To: davem, yoshfuji, dsahern, edumazet, kuba, pabeni, netdev; +Cc: liujian56
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>
---
include/net/ip_tunnels.h | 32 ++++++++++++++++++++++++++++++++
net/ipv4/ipip.c | 24 +-----------------------
net/ipv6/sit.c | 27 +--------------------------
3 files changed, 34 insertions(+), 49 deletions(-)
diff --git a/include/net/ip_tunnels.h b/include/net/ip_tunnels.h
index e8bb8944ce3f..ea047de92e83 100644
--- a/include/net/ip_tunnels.h
+++ b/include/net/ip_tunnels.h
@@ -17,6 +17,7 @@
#include <net/rtnetlink.h>
#include <net/lwtunnel.h>
#include <net/dst_cache.h>
+#include <net/ip.h>
#if IS_ENABLED(CONFIG_IPV6)
#include <net/ipv6.h>
@@ -336,6 +337,37 @@ static inline bool ip_tunnel_netlink_encap_parms(struct nlattr *data[],
return ret;
}
+static inline 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]);
+}
+
extern const struct header_ops ip_tunnel_header_ops;
__be16 ip_tunnel_parse_protocol(const struct sk_buff *skb);
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]);
--
2.17.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH net-next 0/2] Add helper functions to parse netlink msg of ip_tunnel
2022-09-26 13:19 [PATCH net-next 0/2] Add helper functions to parse netlink msg of ip_tunnel Liu Jian
2022-09-26 13:19 ` [PATCH net-next 1/2] net: Add helper function to parse netlink msg of ip_tunnel_encap Liu Jian
2022-09-26 13:19 ` [PATCH net-next 2/2] net: Add helper function to parse netlink msg of ip_tunnel_parm Liu Jian
@ 2022-09-27 14:58 ` Jakub Kicinski
2022-09-28 3:34 ` liujian (CE)
2 siblings, 1 reply; 5+ messages in thread
From: Jakub Kicinski @ 2022-09-27 14:58 UTC (permalink / raw)
To: Liu Jian; +Cc: davem, yoshfuji, dsahern, edumazet, pabeni, netdev
On Mon, 26 Sep 2022 21:19:42 +0800 Liu Jian wrote:
> Add helper functions to parse netlinkmsg of ip_tunnel
>
> Liu Jian (2):
> net: Add helper function to parse netlink msg of ip_tunnel_encap
> net: Add helper function to parse netlink msg of ip_tunnel_parm
>
> include/net/ip_tunnels.h | 66 ++++++++++++++++++++++++++++++++++++++++
> net/ipv4/ipip.c | 62 ++-----------------------------------
> net/ipv6/ip6_tunnel.c | 37 ++--------------------
> net/ipv6/sit.c | 65 ++-------------------------------------
Do they need to be in a header file? Could you put them in
net/ipv4/ip_tunnel.c or net/ipv4/ip_tunnel_core.c instead?
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: [PATCH net-next 0/2] Add helper functions to parse netlink msg of ip_tunnel
2022-09-27 14:58 ` [PATCH net-next 0/2] Add helper functions to parse netlink msg of ip_tunnel Jakub Kicinski
@ 2022-09-28 3:34 ` liujian (CE)
0 siblings, 0 replies; 5+ messages in thread
From: liujian (CE) @ 2022-09-28 3:34 UTC (permalink / raw)
To: Jakub Kicinski; +Cc: davem, yoshfuji, dsahern, edumazet, pabeni, netdev
> -----Original Message-----
> From: Jakub Kicinski [mailto:kuba@kernel.org]
> Sent: Tuesday, September 27, 2022 10:59 PM
> To: liujian (CE) <liujian56@huawei.com>
> Cc: davem@davemloft.net; yoshfuji@linux-ipv6.org; dsahern@kernel.org;
> edumazet@google.com; pabeni@redhat.com; netdev@vger.kernel.org
> Subject: Re: [PATCH net-next 0/2] Add helper functions to parse netlink msg
> of ip_tunnel
>
> On Mon, 26 Sep 2022 21:19:42 +0800 Liu Jian wrote:
> > Add helper functions to parse netlinkmsg of ip_tunnel
> >
> > Liu Jian (2):
> > net: Add helper function to parse netlink msg of ip_tunnel_encap
> > net: Add helper function to parse netlink msg of ip_tunnel_parm
> >
> > include/net/ip_tunnels.h | 66
> ++++++++++++++++++++++++++++++++++++++++
> > net/ipv4/ipip.c | 62 ++-----------------------------------
> > net/ipv6/ip6_tunnel.c | 37 ++--------------------
> > net/ipv6/sit.c | 65 ++-------------------------------------
>
> Do they need to be in a header file? Could you put them in
> net/ipv4/ip_tunnel.c or net/ipv4/ip_tunnel_core.c instead?
The v2 version has been sent. Thanks for your review.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-09-28 3:34 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-26 13:19 [PATCH net-next 0/2] Add helper functions to parse netlink msg of ip_tunnel Liu Jian
2022-09-26 13:19 ` [PATCH net-next 1/2] net: Add helper function to parse netlink msg of ip_tunnel_encap Liu Jian
2022-09-26 13:19 ` [PATCH net-next 2/2] net: Add helper function to parse netlink msg of ip_tunnel_parm Liu Jian
2022-09-27 14:58 ` [PATCH net-next 0/2] Add helper functions to parse netlink msg of ip_tunnel Jakub Kicinski
2022-09-28 3:34 ` liujian (CE)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).