Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <liujian56@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Liu Jian and committed by
David S. Miller
b86fca80 537dd2d9

+37 -49
+3
include/net/ip_tunnels.h
··· 305 305 bool ip_tunnel_netlink_encap_parms(struct nlattr *data[], 306 306 struct ip_tunnel_encap *encap); 307 307 308 + void ip_tunnel_netlink_parms(struct nlattr *data[], 309 + struct ip_tunnel_parm *parms); 310 + 308 311 extern const struct header_ops ip_tunnel_header_ops; 309 312 __be16 ip_tunnel_parse_protocol(const struct sk_buff *skb); 310 313
+32
net/ipv4/ip_tunnel_core.c
··· 1114 1114 return ret; 1115 1115 } 1116 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);
+1 -23
net/ipv4/ipip.c
··· 417 417 if (!data) 418 418 return; 419 419 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); 443 421 444 422 if (data[IFLA_IPTUN_COLLECT_METADATA]) 445 423 *collect_md = true;
+1 -26
net/ipv6/sit.c
··· 1503 1503 if (!data) 1504 1504 return; 1505 1505 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); 1532 1507 1533 1508 if (data[IFLA_IPTUN_FWMARK]) 1534 1509 *fwmark = nla_get_u32(data[IFLA_IPTUN_FWMARK]);