Skip to content

Commit 3735264

Browse files
committed
Merge branch 'ip_tunnel-netlink-parms'
Liu Jian says: ==================== Add helper functions to parse netlink msg of ip_tunnel v1->v2: Move the implementation of the helper function to ip_tunnel_core.c v2->v3: Change EXPORT_SYMBOL to EXPORT_SYMBOL_GPL ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 42e8e6d + b86fca8 commit 3735264

File tree

5 files changed

+81
-156
lines changed

5 files changed

+81
-156
lines changed

include/net/ip_tunnels.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,12 @@ 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+
308+
void ip_tunnel_netlink_parms(struct nlattr *data[],
309+
struct ip_tunnel_parm *parms);
310+
305311
extern const struct header_ops ip_tunnel_header_ops;
306312
__be16 ip_tunnel_parse_protocol(const struct sk_buff *skb);
307313

net/ipv4/ip_tunnel_core.c

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,3 +1079,70 @@ 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);
1117+
1118+
void ip_tunnel_netlink_parms(struct nlattr *data[],
1119+
struct ip_tunnel_parm *parms)
1120+
{
1121+
if (data[IFLA_IPTUN_LINK])
1122+
parms->link = nla_get_u32(data[IFLA_IPTUN_LINK]);
1123+
1124+
if (data[IFLA_IPTUN_LOCAL])
1125+
parms->iph.saddr = nla_get_be32(data[IFLA_IPTUN_LOCAL]);
1126+
1127+
if (data[IFLA_IPTUN_REMOTE])
1128+
parms->iph.daddr = nla_get_be32(data[IFLA_IPTUN_REMOTE]);
1129+
1130+
if (data[IFLA_IPTUN_TTL]) {
1131+
parms->iph.ttl = nla_get_u8(data[IFLA_IPTUN_TTL]);
1132+
if (parms->iph.ttl)
1133+
parms->iph.frag_off = htons(IP_DF);
1134+
}
1135+
1136+
if (data[IFLA_IPTUN_TOS])
1137+
parms->iph.tos = nla_get_u8(data[IFLA_IPTUN_TOS]);
1138+
1139+
if (!data[IFLA_IPTUN_PMTUDISC] || nla_get_u8(data[IFLA_IPTUN_PMTUDISC]))
1140+
parms->iph.frag_off = htons(IP_DF);
1141+
1142+
if (data[IFLA_IPTUN_FLAGS])
1143+
parms->i_flags = nla_get_be16(data[IFLA_IPTUN_FLAGS]);
1144+
1145+
if (data[IFLA_IPTUN_PROTO])
1146+
parms->iph.protocol = nla_get_u8(data[IFLA_IPTUN_PROTO]);
1147+
}
1148+
EXPORT_SYMBOL_GPL(ip_tunnel_netlink_parms);

net/ipv4/ipip.c

Lines changed: 3 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -417,29 +417,7 @@ static void ipip_netlink_parms(struct nlattr *data[],
417417
if (!data)
418418
return;
419419

420-
if (data[IFLA_IPTUN_LINK])
421-
parms->link = nla_get_u32(data[IFLA_IPTUN_LINK]);
422-
423-
if (data[IFLA_IPTUN_LOCAL])
424-
parms->iph.saddr = nla_get_in_addr(data[IFLA_IPTUN_LOCAL]);
425-
426-
if (data[IFLA_IPTUN_REMOTE])
427-
parms->iph.daddr = nla_get_in_addr(data[IFLA_IPTUN_REMOTE]);
428-
429-
if (data[IFLA_IPTUN_TTL]) {
430-
parms->iph.ttl = nla_get_u8(data[IFLA_IPTUN_TTL]);
431-
if (parms->iph.ttl)
432-
parms->iph.frag_off = htons(IP_DF);
433-
}
434-
435-
if (data[IFLA_IPTUN_TOS])
436-
parms->iph.tos = nla_get_u8(data[IFLA_IPTUN_TOS]);
437-
438-
if (data[IFLA_IPTUN_PROTO])
439-
parms->iph.protocol = nla_get_u8(data[IFLA_IPTUN_PROTO]);
440-
441-
if (!data[IFLA_IPTUN_PMTUDISC] || nla_get_u8(data[IFLA_IPTUN_PMTUDISC]))
442-
parms->iph.frag_off = htons(IP_DF);
420+
ip_tunnel_netlink_parms(data, parms);
443421

444422
if (data[IFLA_IPTUN_COLLECT_METADATA])
445423
*collect_md = true;
@@ -448,40 +426,6 @@ static void ipip_netlink_parms(struct nlattr *data[],
448426
*fwmark = nla_get_u32(data[IFLA_IPTUN_FWMARK]);
449427
}
450428

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-
485429
static int ipip_newlink(struct net *src_net, struct net_device *dev,
486430
struct nlattr *tb[], struct nlattr *data[],
487431
struct netlink_ext_ack *extack)
@@ -491,7 +435,7 @@ static int ipip_newlink(struct net *src_net, struct net_device *dev,
491435
struct ip_tunnel_encap ipencap;
492436
__u32 fwmark = 0;
493437

494-
if (ipip_netlink_encap_parms(data, &ipencap)) {
438+
if (ip_tunnel_netlink_encap_parms(data, &ipencap)) {
495439
int err = ip_tunnel_encap_setup(t, &ipencap);
496440

497441
if (err < 0)
@@ -512,7 +456,7 @@ static int ipip_changelink(struct net_device *dev, struct nlattr *tb[],
512456
bool collect_md;
513457
__u32 fwmark = t->fwmark;
514458

515-
if (ipip_netlink_encap_parms(data, &ipencap)) {
459+
if (ip_tunnel_netlink_encap_parms(data, &ipencap)) {
516460
int err = ip_tunnel_encap_setup(t, &ipencap);
517461

518462
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: 3 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,71 +1503,12 @@ static void ipip6_netlink_parms(struct nlattr *data[],
15031503
if (!data)
15041504
return;
15051505

1506-
if (data[IFLA_IPTUN_LINK])
1507-
parms->link = nla_get_u32(data[IFLA_IPTUN_LINK]);
1508-
1509-
if (data[IFLA_IPTUN_LOCAL])
1510-
parms->iph.saddr = nla_get_be32(data[IFLA_IPTUN_LOCAL]);
1511-
1512-
if (data[IFLA_IPTUN_REMOTE])
1513-
parms->iph.daddr = nla_get_be32(data[IFLA_IPTUN_REMOTE]);
1514-
1515-
if (data[IFLA_IPTUN_TTL]) {
1516-
parms->iph.ttl = nla_get_u8(data[IFLA_IPTUN_TTL]);
1517-
if (parms->iph.ttl)
1518-
parms->iph.frag_off = htons(IP_DF);
1519-
}
1520-
1521-
if (data[IFLA_IPTUN_TOS])
1522-
parms->iph.tos = nla_get_u8(data[IFLA_IPTUN_TOS]);
1523-
1524-
if (!data[IFLA_IPTUN_PMTUDISC] || nla_get_u8(data[IFLA_IPTUN_PMTUDISC]))
1525-
parms->iph.frag_off = htons(IP_DF);
1526-
1527-
if (data[IFLA_IPTUN_FLAGS])
1528-
parms->i_flags = nla_get_be16(data[IFLA_IPTUN_FLAGS]);
1529-
1530-
if (data[IFLA_IPTUN_PROTO])
1531-
parms->iph.protocol = nla_get_u8(data[IFLA_IPTUN_PROTO]);
1506+
ip_tunnel_netlink_parms(data, parms);
15321507

15331508
if (data[IFLA_IPTUN_FWMARK])
15341509
*fwmark = nla_get_u32(data[IFLA_IPTUN_FWMARK]);
15351510
}
15361511

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-
15711512
#ifdef CONFIG_IPV6_SIT_6RD
15721513
/* This function returns true when 6RD attributes are present in the nl msg */
15731514
static bool ipip6_netlink_6rd_parms(struct nlattr *data[],
@@ -1619,7 +1560,7 @@ static int ipip6_newlink(struct net *src_net, struct net_device *dev,
16191560

16201561
nt = netdev_priv(dev);
16211562

1622-
if (ipip6_netlink_encap_parms(data, &ipencap)) {
1563+
if (ip_tunnel_netlink_encap_parms(data, &ipencap)) {
16231564
err = ip_tunnel_encap_setup(nt, &ipencap);
16241565
if (err < 0)
16251566
return err;
@@ -1671,7 +1612,7 @@ static int ipip6_changelink(struct net_device *dev, struct nlattr *tb[],
16711612
if (dev == sitn->fb_tunnel_dev)
16721613
return -EINVAL;
16731614

1674-
if (ipip6_netlink_encap_parms(data, &ipencap)) {
1615+
if (ip_tunnel_netlink_encap_parms(data, &ipencap)) {
16751616
err = ip_tunnel_encap_setup(t, &ipencap);
16761617
if (err < 0)
16771618
return err;

0 commit comments

Comments
 (0)