Skip to content

Commit 537dd2d

Browse files
liujian56davem330
authored andcommitted
net: Add helper function to parse netlink msg of ip_tunnel_encap
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 <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 42e8e6d commit 537dd2d

File tree

5 files changed

+44
-107
lines changed

5 files changed

+44
-107
lines changed

include/net/ip_tunnels.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,9 @@ int ip_tunnel_newlink(struct net_device *dev, struct nlattr *tb[],
302302
struct ip_tunnel_parm *p, __u32 fwmark);
303303
void ip_tunnel_setup(struct net_device *dev, unsigned int net_id);
304304

305+
bool ip_tunnel_netlink_encap_parms(struct nlattr *data[],
306+
struct ip_tunnel_encap *encap);
307+
305308
extern const struct header_ops ip_tunnel_header_ops;
306309
__be16 ip_tunnel_parse_protocol(const struct sk_buff *skb);
307310

net/ipv4/ip_tunnel_core.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,3 +1079,38 @@ EXPORT_SYMBOL(ip_tunnel_parse_protocol);
10791079

10801080
const struct header_ops ip_tunnel_header_ops = { .parse_protocol = ip_tunnel_parse_protocol };
10811081
EXPORT_SYMBOL(ip_tunnel_header_ops);
1082+
1083+
/* This function returns true when ENCAP attributes are present in the nl msg */
1084+
bool ip_tunnel_netlink_encap_parms(struct nlattr *data[],
1085+
struct ip_tunnel_encap *encap)
1086+
{
1087+
bool ret = false;
1088+
1089+
memset(encap, 0, sizeof(*encap));
1090+
1091+
if (!data)
1092+
return ret;
1093+
1094+
if (data[IFLA_IPTUN_ENCAP_TYPE]) {
1095+
ret = true;
1096+
encap->type = nla_get_u16(data[IFLA_IPTUN_ENCAP_TYPE]);
1097+
}
1098+
1099+
if (data[IFLA_IPTUN_ENCAP_FLAGS]) {
1100+
ret = true;
1101+
encap->flags = nla_get_u16(data[IFLA_IPTUN_ENCAP_FLAGS]);
1102+
}
1103+
1104+
if (data[IFLA_IPTUN_ENCAP_SPORT]) {
1105+
ret = true;
1106+
encap->sport = nla_get_be16(data[IFLA_IPTUN_ENCAP_SPORT]);
1107+
}
1108+
1109+
if (data[IFLA_IPTUN_ENCAP_DPORT]) {
1110+
ret = true;
1111+
encap->dport = nla_get_be16(data[IFLA_IPTUN_ENCAP_DPORT]);
1112+
}
1113+
1114+
return ret;
1115+
}
1116+
EXPORT_SYMBOL_GPL(ip_tunnel_netlink_encap_parms);

net/ipv4/ipip.c

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -448,40 +448,6 @@ static void ipip_netlink_parms(struct nlattr *data[],
448448
*fwmark = nla_get_u32(data[IFLA_IPTUN_FWMARK]);
449449
}
450450

451-
/* This function returns true when ENCAP attributes are present in the nl msg */
452-
static bool ipip_netlink_encap_parms(struct nlattr *data[],
453-
struct ip_tunnel_encap *ipencap)
454-
{
455-
bool ret = false;
456-
457-
memset(ipencap, 0, sizeof(*ipencap));
458-
459-
if (!data)
460-
return ret;
461-
462-
if (data[IFLA_IPTUN_ENCAP_TYPE]) {
463-
ret = true;
464-
ipencap->type = nla_get_u16(data[IFLA_IPTUN_ENCAP_TYPE]);
465-
}
466-
467-
if (data[IFLA_IPTUN_ENCAP_FLAGS]) {
468-
ret = true;
469-
ipencap->flags = nla_get_u16(data[IFLA_IPTUN_ENCAP_FLAGS]);
470-
}
471-
472-
if (data[IFLA_IPTUN_ENCAP_SPORT]) {
473-
ret = true;
474-
ipencap->sport = nla_get_be16(data[IFLA_IPTUN_ENCAP_SPORT]);
475-
}
476-
477-
if (data[IFLA_IPTUN_ENCAP_DPORT]) {
478-
ret = true;
479-
ipencap->dport = nla_get_be16(data[IFLA_IPTUN_ENCAP_DPORT]);
480-
}
481-
482-
return ret;
483-
}
484-
485451
static int ipip_newlink(struct net *src_net, struct net_device *dev,
486452
struct nlattr *tb[], struct nlattr *data[],
487453
struct netlink_ext_ack *extack)
@@ -491,7 +457,7 @@ static int ipip_newlink(struct net *src_net, struct net_device *dev,
491457
struct ip_tunnel_encap ipencap;
492458
__u32 fwmark = 0;
493459

494-
if (ipip_netlink_encap_parms(data, &ipencap)) {
460+
if (ip_tunnel_netlink_encap_parms(data, &ipencap)) {
495461
int err = ip_tunnel_encap_setup(t, &ipencap);
496462

497463
if (err < 0)
@@ -512,7 +478,7 @@ static int ipip_changelink(struct net_device *dev, struct nlattr *tb[],
512478
bool collect_md;
513479
__u32 fwmark = t->fwmark;
514480

515-
if (ipip_netlink_encap_parms(data, &ipencap)) {
481+
if (ip_tunnel_netlink_encap_parms(data, &ipencap)) {
516482
int err = ip_tunnel_encap_setup(t, &ipencap);
517483

518484
if (err < 0)

net/ipv6/ip6_tunnel.c

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1988,39 +1988,6 @@ static void ip6_tnl_netlink_parms(struct nlattr *data[],
19881988
parms->fwmark = nla_get_u32(data[IFLA_IPTUN_FWMARK]);
19891989
}
19901990

1991-
static bool ip6_tnl_netlink_encap_parms(struct nlattr *data[],
1992-
struct ip_tunnel_encap *ipencap)
1993-
{
1994-
bool ret = false;
1995-
1996-
memset(ipencap, 0, sizeof(*ipencap));
1997-
1998-
if (!data)
1999-
return ret;
2000-
2001-
if (data[IFLA_IPTUN_ENCAP_TYPE]) {
2002-
ret = true;
2003-
ipencap->type = nla_get_u16(data[IFLA_IPTUN_ENCAP_TYPE]);
2004-
}
2005-
2006-
if (data[IFLA_IPTUN_ENCAP_FLAGS]) {
2007-
ret = true;
2008-
ipencap->flags = nla_get_u16(data[IFLA_IPTUN_ENCAP_FLAGS]);
2009-
}
2010-
2011-
if (data[IFLA_IPTUN_ENCAP_SPORT]) {
2012-
ret = true;
2013-
ipencap->sport = nla_get_be16(data[IFLA_IPTUN_ENCAP_SPORT]);
2014-
}
2015-
2016-
if (data[IFLA_IPTUN_ENCAP_DPORT]) {
2017-
ret = true;
2018-
ipencap->dport = nla_get_be16(data[IFLA_IPTUN_ENCAP_DPORT]);
2019-
}
2020-
2021-
return ret;
2022-
}
2023-
20241991
static int ip6_tnl_newlink(struct net *src_net, struct net_device *dev,
20251992
struct nlattr *tb[], struct nlattr *data[],
20261993
struct netlink_ext_ack *extack)
@@ -2033,7 +2000,7 @@ static int ip6_tnl_newlink(struct net *src_net, struct net_device *dev,
20332000

20342001
nt = netdev_priv(dev);
20352002

2036-
if (ip6_tnl_netlink_encap_parms(data, &ipencap)) {
2003+
if (ip_tunnel_netlink_encap_parms(data, &ipencap)) {
20372004
err = ip6_tnl_encap_setup(nt, &ipencap);
20382005
if (err < 0)
20392006
return err;
@@ -2070,7 +2037,7 @@ static int ip6_tnl_changelink(struct net_device *dev, struct nlattr *tb[],
20702037
if (dev == ip6n->fb_tnl_dev)
20712038
return -EINVAL;
20722039

2073-
if (ip6_tnl_netlink_encap_parms(data, &ipencap)) {
2040+
if (ip_tunnel_netlink_encap_parms(data, &ipencap)) {
20742041
int err = ip6_tnl_encap_setup(t, &ipencap);
20752042

20762043
if (err < 0)

net/ipv6/sit.c

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,40 +1534,6 @@ static void ipip6_netlink_parms(struct nlattr *data[],
15341534
*fwmark = nla_get_u32(data[IFLA_IPTUN_FWMARK]);
15351535
}
15361536

1537-
/* This function returns true when ENCAP attributes are present in the nl msg */
1538-
static bool ipip6_netlink_encap_parms(struct nlattr *data[],
1539-
struct ip_tunnel_encap *ipencap)
1540-
{
1541-
bool ret = false;
1542-
1543-
memset(ipencap, 0, sizeof(*ipencap));
1544-
1545-
if (!data)
1546-
return ret;
1547-
1548-
if (data[IFLA_IPTUN_ENCAP_TYPE]) {
1549-
ret = true;
1550-
ipencap->type = nla_get_u16(data[IFLA_IPTUN_ENCAP_TYPE]);
1551-
}
1552-
1553-
if (data[IFLA_IPTUN_ENCAP_FLAGS]) {
1554-
ret = true;
1555-
ipencap->flags = nla_get_u16(data[IFLA_IPTUN_ENCAP_FLAGS]);
1556-
}
1557-
1558-
if (data[IFLA_IPTUN_ENCAP_SPORT]) {
1559-
ret = true;
1560-
ipencap->sport = nla_get_be16(data[IFLA_IPTUN_ENCAP_SPORT]);
1561-
}
1562-
1563-
if (data[IFLA_IPTUN_ENCAP_DPORT]) {
1564-
ret = true;
1565-
ipencap->dport = nla_get_be16(data[IFLA_IPTUN_ENCAP_DPORT]);
1566-
}
1567-
1568-
return ret;
1569-
}
1570-
15711537
#ifdef CONFIG_IPV6_SIT_6RD
15721538
/* This function returns true when 6RD attributes are present in the nl msg */
15731539
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,
16191585

16201586
nt = netdev_priv(dev);
16211587

1622-
if (ipip6_netlink_encap_parms(data, &ipencap)) {
1588+
if (ip_tunnel_netlink_encap_parms(data, &ipencap)) {
16231589
err = ip_tunnel_encap_setup(nt, &ipencap);
16241590
if (err < 0)
16251591
return err;
@@ -1671,7 +1637,7 @@ static int ipip6_changelink(struct net_device *dev, struct nlattr *tb[],
16711637
if (dev == sitn->fb_tunnel_dev)
16721638
return -EINVAL;
16731639

1674-
if (ipip6_netlink_encap_parms(data, &ipencap)) {
1640+
if (ip_tunnel_netlink_encap_parms(data, &ipencap)) {
16751641
err = ip_tunnel_encap_setup(t, &ipencap);
16761642
if (err < 0)
16771643
return err;

0 commit comments

Comments
 (0)