fib rule selftest
Subsystems (4)
v4 cover fib rule selftest
From: Roopa Prabhu <[email protected]>
This series adds a new test to test fib rules.
ip route get is used to test fib rule matches.
This series also extends ip route get to match on
sport and dport to test recent support of sport
and dport fib rule match.
v2 - address ido's commemt to make sport dport ip route get to work correctly for input route get. I don't support ip route get on ip-proto match yet. ip route get creates a udp packet and i have left it at that. We could extend ip route get to support a few ip proto matches in followup patches.
v3 - Support ip_proto (only tcp and udp) match in getroute. dropped printing of new match attrs in ip route get, because ipv6 does not print it. And ipv6 currrently shares the dump api with ipv6 notify and its better to not add them to the notify api. dropped it to keep the api consistent between ipv4 and ipv6 (though uid is already printed in the ipv4 case). If we need it, both ipv4 and ipv6 can be enhanced to provide a separate get api. Moved skb creation for ipv4 to a separate func.
v4 - drop separate skb for netlink and fix concerns around rcu and netlink
reply (as pointed out by DaveM). I now try to reset the skb after the route lookup and before the netlink send (testing shows this is ok. More eyes and any feedback here will be helpful)
Roopa Prabhu (3):
ipv4: support sport, dport and ip_proto in RTM_GETROUTE
ipv6: support sport, dport and ip_proto in RTM_GETROUTE
selftests: net: initial fib rule tests
include/uapi/linux/rtnetlink.h | 2 + net/ipv4/route.c | 152 ++++++++++++----- net/ipv6/route.c | 25 +++ tools/testing/selftests/net/Makefile | 2 +- tools/testing/selftests/net/fib_rule_tests.sh | 224 ++++++++++++++++++++++++++ 5 files changed, 366 insertions(+), 39 deletions(-) create mode 100644 tools/testing/selftests/net/fib_rule_tests.sh
Signature · 1 line
2.1.4
PATCH v4 1/3 ipv4: support sport, dport and ip_proto in RTM_GETROUTE
From: Roopa Prabhu <[email protected]>
This is a followup to fib rules sport, dport and ipproto match support. Only supports tcp, udp and icmp for ipproto. Used by fib rule self tests.
--- include/net/ip.h | 3 + include/uapi/linux/rtnetlink.h | 3 + net/ipv4/Makefile | 2 +- net/ipv4/fib_frontend.c | 4 ++ net/ipv4/netlink.c | 23 +++++++ net/ipv4/route.c | 146 ++++++++++++++++++++++++++++++----------- 6 files changed, 141 insertions(+), 40 deletions(-) create mode 100644 net/ipv4/netlink.c
include/net/ip.h +3 -0
@@ -664,4 +664,7 @@ extern int sysctl_icmp_msgs_burst;int ip_misc_proc_init (void );#endif +int rtm_getroute_parse_ip_proto (struct nlattr *attr,u8 *ip_proto, +struct netlink_ext_ack *extack); +#endif /* _IP_H */
include/uapi/linux/rtnetlink.h +3 -0
@@ -327,6 +327,9 @@ enum rtattr_type_t {RTA_PAD ,RTA_UID ,RTA_TTL_PROPAGATE , +RTA_IP_PROTO , +RTA_SPORT , +RTA_DPORT , __RTA_MAX };
net/ipv4/Makefile +1 -1
@@ -14,7 +14,7 @@ obj-y := route.o inetpeer.o protocol.o \ udp_offload.o arp.o icmp.o devinet.o af_inet.o igmp.o \ fib_frontend.o fib_semantics.o fib_trie.o fib_notifier.o \ inet_fragment.o ping.o ip_tunnel_core.o gre_offload.o \ - metrics.o + metrics.o netlink.o obj-$(CONFIG_NET_IP_TUNNEL) += ip_tunnel.o obj-$(CONFIG_SYSCTL) += sysctl_net_ipv4.o
net/ipv4/fib_frontend.c +4 -0
@@ -649,6 +649,10 @@ const struct nla_policy rtm_ipv4_policy[RTA_MAX + 1] = { [RTA_ENCAP] = { .type = NLA_NESTED }, [RTA_UID] = { .type = NLA_U32 }, [RTA_MARK] = { .type = NLA_U32 }, + [RTA_TABLE] = { .type = NLA_U32 }, + [RTA_IP_PROTO] = { .type = NLA_U8 }, + [RTA_SPORT] = { .type = NLA_U16 }, + [RTA_DPORT] = { .type = NLA_U16 }, }; static int rtm_to_fib_config(struct net *net, struct sk_buff *skb,
net/ipv4/netlink.c new file +23 -0
@@ -0,0 +1,23 @@ +#include <linux/netlink.h> +#include <linux/rtnetlink.h> +#include <linux/types.h> +#include <net/net_namespace.h> +#include <net/netlink.h> +#include <net/ip.h> + +int rtm_getroute_parse_ip_proto (struct nlattr *attr,u8 *ip_proto, +struct netlink_ext_ack *extack) +{ + *ip_proto =nla_get_u8 (attr); + +switch (*ip_proto) { +case IPPROTO_TCP : +case IPPROTO_UDP : +case IPPROTO_ICMP : +return 0 ; +default : +NL_SET_ERR_MSG (extack,"Unsupported ip proto" ); +return -EOPNOTSUPP ; + } +} +EXPORT_SYMBOL_GPL (rtm_getroute_parse_ip_proto);
net/ipv4/route.c +107 -39
239 lines not on this page · raw message
Signature · 1 line
2.1.4
Re: [PATCH net-next v4 1/3] ipv4: support sport, dport and ip_proto in RTM_GETROUTE
Quoted 3 lines · Roopa Prabhu
From: Roopa Prabhu <[email protected]>
...
net/ipv4/fib_frontend.c const struct nla_policy rtm_ipv4_policy[RTA_MAX + 1] = { · line 656
Quoted 13 lines
net/ipv4/fib_frontend.c +4
-0@@ -649,6 +649,10 @@ const struct nla_policy rtm_ipv4_policy[RTA_MAX + 1] = { [RTA_ENCAP] = { .type = NLA_NESTED }, [RTA_UID] = { .type = NLA_U32 }, [RTA_MARK] = { .type = NLA_U32 }, + [RTA_TABLE] = { .type = NLA_U32 }, + [RTA_IP_PROTO] = { .type = NLA_U8 }, + [RTA_SPORT] = { .type = NLA_U16 }, + [RTA_DPORT] = { .type = NLA_U16 }, };
Hi Roopa
RTA_TABLE addition looks like a bug fix for net tree ?
This should be sent as an independent patch IMO.
Thanks.
Re: [PATCH net-next v4 1/3] ipv4: support sport, dport and ip_proto in RTM_GETROUTE
Quoted 25 lines · Eric Dumazet
Quoted 3 lines · Roopa Prabhu
From: Roopa Prabhu <[email protected]>
...
net/ipv4/fib_frontend.c const struct nla_policy rtm_ipv4_policy[RTA_MAX + 1] = { · line 656
Quoted 13 lines
net/ipv4/fib_frontend.c +4
-0@@ -649,6 +649,10 @@ const struct nla_policy rtm_ipv4_policy[RTA_MAX + 1] = { [RTA_ENCAP] = { .type = NLA_NESTED }, [RTA_UID] = { .type = NLA_U32 }, [RTA_MARK] = { .type = NLA_U32 }, + [RTA_TABLE] = { .type = NLA_U32 }, + [RTA_IP_PROTO] = { .type = NLA_U8 }, + [RTA_SPORT] = { .type = NLA_U16 }, + [RTA_DPORT] = { .type = NLA_U16 }, };Hi Roopa
Quoted 5 lines
RTA_TABLEaddition looks like a bug fix for net tree ?This should be sent as an independent patch IMO.
Thanks.
sure, I can do that. thanks.
PATCH v4 2/3 ipv6: support sport, dport and ip_proto in RTM_GETROUTE
In reply to Roopa PrabhuFrom: Roopa Prabhu <[email protected]>
This is a followup to fib6 rules sport, dport and ipproto match support. Only supports tcp, udp and icmp for ipproto. Used by fib rule self tests.
--- net/ipv6/route.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
net/ipv6/route.c +17 -0
@@ -63,6 +63,7 @@#include <net/lwtunnel.h> #include <net/ip_tunnels.h> #include <net/l3mdev.h> +#include <net/ip.h> #include <trace/events/fib6.h> #include <linux/uaccess.h>
@@ -4083,6 +4084,9 @@ static const struct nla_policy rtm_ipv6_policy[RTA_MAX+1] = { [RTA_UID] = { .type = NLA_U32 }, [RTA_MARK] = { .type = NLA_U32 }, [RTA_TABLE] = { .type = NLA_U32 }, + [RTA_IP_PROTO] = { .type = NLA_U8 }, + [RTA_SPORT] = { .type = NLA_U16 }, + [RTA_DPORT] = { .type = NLA_U16 }, }; static int rtm_to_fib6_config(struct sk_buff *skb, struct nlmsghdr *nlh,
@@ -4794,6 +4798,19 @@ static int inet6_rtm_getroute(struct sk_buff *in_skb, struct nlmsghdr *nlh,else fl6.flowi6_uid = iif ?INVALID_UID :current_uid (); +if (tb[RTA_SPORT ]) + fl6.fl6_sport =nla_get_be16 (tb[RTA_SPORT ]); + +if (tb[RTA_DPORT ]) + fl6.fl6_dport =nla_get_be16 (tb[RTA_DPORT ]); + +if (tb[RTA_IP_PROTO ]) { + err =rtm_getroute_parse_ip_proto (tb[RTA_IP_PROTO ], + &fl6.flowi6_proto, extack); +if (err) + goto errout; + } +if (iif) {struct net_device *dev;int flags =0 ;
Signature · 1 line
2.1.4
PATCH v4 3/3 selftests: net: initial fib rule tests
In reply to Roopa PrabhuFrom: Roopa Prabhu <[email protected]>
This adds a first set of tests for fib rule match/action for ipv4 and ipv6. Initial tests only cover action lookup table. can be extended to cover other actions in the future. Uses ip route get to validate the rule lookup.
--- tools/testing/selftests/net/Makefile | 2 +- tools/testing/selftests/net/fib_rule_tests.sh | 248 ++++++++++++++++++++++++++ 2 files changed, 249 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/net/fib_rule_tests.sh
tools/testing/selftests/net/Makefile +1 -1
@@ -6,7 +6,7 @@ CFLAGS += -I../../../../usr/include/ TEST_PROGS := run_netsocktests run_afpackettests test_bpf.sh netdevice.sh rtnetlink.sh TEST_PROGS += fib_tests.sh fib-onlink-tests.sh pmtu.sh udpgso.sh -TEST_PROGS += udpgso_bench.sh +TEST_PROGS += udpgso_bench.sh fib_rule_tests.sh TEST_PROGS_EXTENDED := in_netns.sh TEST_GEN_FILES = socket TEST_GEN_FILES += psock_fanout psock_tpacket msg_zerocopy
tools/testing/selftests/net/fib_rule_tests.sh new file +248 -0
248 lines not on this page · raw message
Signature · 1 line
2.1.4