Skip to content

Commit b86fca8

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

File tree

4 files changed

+37
-49
lines changed

4 files changed

+37
-49
lines changed

include/net/ip_tunnels.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,9 @@ void ip_tunnel_setup(struct net_device *dev, unsigned int net_id);
305305
bool ip_tunnel_netlink_encap_parms(struct nlattr *data[],
306306
struct ip_tunnel_encap *encap);
307307

308+
void ip_tunnel_netlink_parms(struct nlattr *data[],
309+
struct ip_tunnel_parm *parms);
310+
308311
extern const struct header_ops ip_tunnel_header_ops;
309312
__be16 ip_tunnel_parse_protocol(const struct sk_buff *skb);
310313

net/ipv4/ip_tunnel_core.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,3 +1114,35 @@ bool ip_tunnel_netlink_encap_parms(struct nlattr *data[],
11141114
return ret;
11151115
}
11161116
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: 1 addition & 23 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;

net/ipv6/sit.c

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,32 +1503,7 @@ 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]);

0 commit comments

Comments
 (0)