net: Improve route scalability via support for nexthop objects
Subsystems (9)
[email protected]
maintainerRFC PATCH 2/18 net: ipv4: export fib_good_nh and fib_flush
In reply to [email protected]From: David Ahern <[email protected]>
Export fib_good_nh for use by the nexthop code when selecting a path within a multipath nexthop.
As nexthops are deleted, fib entries referencing it are marked dead. Export fib_flush so those entries can be removed in a timely manner.
--- include/net/ip_fib.h | 2 ++ net/ipv4/fib_frontend.c | 2 +- net/ipv4/fib_semantics.c | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-)
include/net/ip_fib.h +2 -0
@@ -399,6 +399,7 @@ int fib_sync_up(struct net_device *dev, unsigned int nh_flags);int fib_multipath_hash (const struct net *net,const struct flowi4 *fl4,const struct sk_buff *skb,struct flow_keys *flkeys);#endif +bool fib_good_nh (const struct fib_nh *nh);void fib_select_multipath (struct fib_result *res,int hash);void fib_select_path (struct net *net,struct fib_result *res,struct flowi4 *fl4,const struct sk_buff *skb);
@@ -423,6 +424,7 @@ static inline void fib_combine_itag(u32 *itag, const struct fib_result *res)#endif } +void fib_flush (struct net *net);void free_fib_info (struct fib_info *fi);static inline void fib_info_hold (struct fib_info *fi)
net/ipv4/fib_frontend.c +1 -1
@@ -192,7 +192,7 @@ int fib_unmerge(struct net *net)return 0 ; } -static void fib_flush (struct net *net) +void fib_flush (struct net *net) {int flushed =0 ;unsigned int h;
net/ipv4/fib_semantics.c +1 -1
@@ -1682,7 +1682,7 @@ int fib_sync_up(struct net_device *dev, unsigned int nh_flags) }#ifdef CONFIG_IP_ROUTE_MULTIPATH -static bool fib_good_nh (const struct fib_nh *nh) +bool fib_good_nh (const struct fib_nh *nh) {int state =NUD_REACHABLE ;
Signature · 1 line
2.11.0
[email protected]
maintainerRFC PATCH 3/18 net/ipv4: export fib_info_update_nh_saddr
In reply to [email protected]From: David Ahern <[email protected]>
Add scope as input argument versus relying on fib_info reference in fib_nh and export fib_info_update_nh_saddr.
--- include/net/ip_fib.h | 5 +++-- net/ipv4/fib_semantics.c | 9 ++++----- 2 files changed, 7 insertions(+), 7 deletions(-)
include/net/ip_fib.h +3 -2
@@ -173,13 +173,14 @@ struct fib_result_nl {#define FIB_TABLE_HASHSZ 2#endif -__be32 fib_info_update_nh_saddr (struct net *net,struct fib_nh *nh); +__be32 fib_info_update_nh_saddr (struct net *net,struct fib_nh *nh, +unsigned char scope);#define FIB_RES_SADDR (net, res) \ ((FIB_RES_NH(res).nh_saddr_genid == \ atomic_read(&(net)->ipv4.dev_addr_genid)) ? \ FIB_RES_NH(res).nh_saddr : \ - fib_info_update_nh_saddr((net), &FIB_RES_NH(res))) + fib_info_update_nh_saddr((net), &FIB_RES_NH(res), (res).fi->fib_scope))#define FIB_RES_GW (res) (FIB_RES_NH(res).nh_gw)#define FIB_RES_DEV (res) (FIB_RES_NH(res).nh_dev)#define FIB_RES_OIF (res) (FIB_RES_NH(res).nh_oif)
net/ipv4/fib_semantics.c +4 -5
@@ -984,11 +984,10 @@ static void fib_info_hash_move(struct hlist_head *new_info_hash,fib_info_hash_free (old_laddrhash, bytes); } -__be32 fib_info_update_nh_saddr (struct net *net,struct fib_nh *nh) +__be32 fib_info_update_nh_saddr (struct net *net,struct fib_nh *nh, +unsigned char scope) { - nh->nh_saddr =inet_select_addr (nh->nh_dev, - nh->nh_gw, - nh->nh_parent->fib_scope); + nh->nh_saddr =inet_select_addr (nh->nh_dev, nh->nh_gw, scope); nh->nh_saddr_genid =atomic_read (&net->ipv4.dev_addr_genid);return nh->nh_saddr;
@@ -1238,7 +1237,7 @@ struct fib_info *fib_create_info(struct fib_config *cfg, }change_nexthops (fi) { -fib_info_update_nh_saddr (net, nexthop_nh); +fib_info_update_nh_saddr (net, nexthop_nh, fi->fib_scope); }endfor_nexthops (fi)fib_rebalance (fi);
Signature · 1 line
2.11.0
[email protected]
maintainerRFC PATCH 9/18 net/ipv6: Create init and release helpers for fib6_nh
In reply to [email protected]From: David Ahern <[email protected]>
Refactor initialization and cleanup of fib6_nh to helpers similar to what was done for IPv4. Add fib6_nh_init to the ipv6 stubs for use by core code when ipv6 is built as a module.
The replace helper is small enough, so make an inline rather than requiring it to go through ipv6 stubs.
--- include/net/addrconf.h | 5 + include/net/ip6_fib.h | 11 +++ net/ipv6/addrconf_core.c | 9 ++ net/ipv6/af_inet6.c | 1 + net/ipv6/ip6_fib.c | 5 +- net/ipv6/route.c | 239 +++++++++++++++++++++++++---------------------- 6 files changed, 153 insertions(+), 117 deletions(-)
include/net/addrconf.h +5 -0
@@ -2,6 +2,8 @@#ifndef _ADDRCONF_H#define _ADDRCONF_H +#include <net/ip6_fib.h> +#define MAX_RTR_SOLICITATIONS -1/* unlimited */ #define RTR_SOLICITATION_INTERVAL (4*HZ)#define RTR_SOLICITATION_MAX_INTERVAL (3600*HZ)/* 1 hour */
@@ -253,6 +255,9 @@ struct ipv6_stub {u32 (*ip6_mtu_from_fib6)(struct fib6_info *f6i,struct in6_addr *daddr,struct in6_addr *saddr); +int (*fib6_nh_init)(struct net *net,struct fib6_nh *fib6_nh, +struct fib6_config *cfg, +struct netlink_ext_ack *extack);void (*udpv6_encap_enable)(void ); void (*ndisc_send_na)(struct net_device *dev, const struct in6_addr *daddr, const struct in6_addr *solicited_addr,
include/net/ip6_fib.h +11 -0
@@ -22,6 +22,7 @@#include <net/netlink.h> #include <net/inetpeer.h> #include <net/fib_notifier.h> +#include <net/lwtunnel.h> #ifdef CONFIG_IPV6_MULTIPLE_TABLES #define FIB6_TABLE_HASHSZ 256
@@ -413,6 +414,16 @@ int fib6_add(struct fib6_node *root, struct fib6_info *rt, struct nl_info *info, struct netlink_ext_ack *extack);int fib6_del (struct fib6_info *rt,struct nl_info *info); +int fib6_nh_init (struct net *net,struct fib6_nh *fib6_nh, +struct fib6_config *cfg,struct netlink_ext_ack *extack); +static inline void fib6_nh_release (struct fib6_nh *fib6_nh) +{ +if (fib6_nh->nh_dev) +dev_put (fib6_nh->nh_dev); + +lwtstate_put (fib6_nh->nh_lwtstate); +} +static inline struct net_device *fib6_info_nh_dev (const struct fib6_info *f6i) {return f6i->fib6_nh.nh_dev;
net/ipv6/addrconf_core.c +9 -0
@@ -168,6 +168,14 @@ eafnosupport_ip6_mtu_from_fib6(struct fib6_info *f6i, struct in6_addr *daddr,return 0 ; } +static int eafnosupport_fib6_nh_init (struct net *net,struct fib6_nh *fib6_nh, +struct fib6_config *cfg, +struct netlink_ext_ack *extack) +{ +NL_SET_ERR_MSG (extack,"IPv6 support not enabled in kernel" ); +return -EAFNOSUPPORT ; +} +const struct ipv6_stub *ipv6_stub__read_mostly = &(struct ipv6_stub ) { .ipv6_dst_lookup = eafnosupport_ipv6_dst_lookup, .fib6_get_table = eafnosupport_fib6_get_table,
@@ -175,6 +183,7 @@ const struct ipv6_stub *ipv6_stub __read_mostly = &(struct ipv6_stub) { .fib6_lookup = eafnosupport_fib6_lookup, .fib6_multipath_select = eafnosupport_fib6_multipath_select, .ip6_mtu_from_fib6 = eafnosupport_ip6_mtu_from_fib6, + .fib6_nh_init = eafnosupport_fib6_nh_init, };EXPORT_SYMBOL_GPL (ipv6_stub);
net/ipv6/af_inet6.c +1 -0
@@ -895,6 +895,7 @@ static const struct ipv6_stub ipv6_stub_impl = { .fib6_lookup = fib6_lookup, .fib6_multipath_select = fib6_multipath_select, .ip6_mtu_from_fib6 = ip6_mtu_from_fib6, + .fib6_nh_init = fib6_nh_init, .udpv6_encap_enable = udpv6_encap_enable, .ndisc_send_na = ndisc_send_na, .nd_tbl = &nd_tbl,
net/ipv6/ip6_fib.c +1 -4
@@ -198,10 +198,7 @@ void fib6_info_destroy_rcu(struct rcu_head *head) } } -lwtstate_put (f6i->fib6_nh.nh_lwtstate); - -if (f6i->fib6_nh.nh_dev) -dev_put (f6i->fib6_nh.nh_dev); +fib6_nh_release (&f6i->fib6_nh); m = f6i->fib6_metrics;if (m != &dst_default_metrics &&refcount_dec_and_test (&m->refcnt))
net/ipv6/route.c +126 -113
291 lines not on this page · raw message
Signature · 1 line
2.11.0
[email protected]
maintainerRFC PATCH 11/18 net: Initial nexthop code
In reply to [email protected]From: David Ahern <[email protected]>
Initial import of nexthop code.
- Add new RTM commands for nexthop objects.
- Add new uapi attributes for creating nexthops. Attributes are similar to the current nexthop attributes for routes.
- Add basic helpers for ipv4 and ipv6 references to nexthop data
Similar to routes nexthops are configured per namespace, so add netns_nexthop struct and add it to struct net.
--- include/net/net_namespace.h | 2 + include/net/netns/nexthop.h | 18 + include/net/nexthop.h | 121 +++++ include/uapi/linux/nexthop.h | 56 +++ include/uapi/linux/rtnetlink.h | 7 + net/ipv4/Makefile | 2 +- net/ipv4/nexthop.c | 1080 ++++++++++++++++++++++++++++++++++++++++ security/selinux/nlmsgtab.c | 5 +- 8 files changed, 1289 insertions(+), 2 deletions(-) create mode 100644 include/net/netns/nexthop.h create mode 100644 include/net/nexthop.h create mode 100644 include/uapi/linux/nexthop.h create mode 100644 net/ipv4/nexthop.c
include/net/net_namespace.h +2 -0
@@ -19,6 +19,7 @@#include <net/netns/packet.h> #include <net/netns/ipv4.h> #include <net/netns/ipv6.h> +#include <net/netns/nexthop.h> #include <net/netns/ieee802154_6lowpan.h> #include <net/netns/sctp.h> #include <net/netns/dccp.h>
@@ -105,6 +106,7 @@ struct net {struct netns_mib mib;struct netns_packet packet;struct netns_unix unx; +struct netns_nexthop nexthop;struct netns_ipv4 ipv4;#if IS_ENABLED (CONFIG_IPV6 )struct netns_ipv6 ipv6;
include/net/netns/nexthop.h new file +18 -0
@@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* nexthops in net namespaces +*/ + +#ifndef __NETNS_NEXTHOP_H__ +#define __NETNS_NEXTHOP_H__ + +#include <linux/rbtree.h> + +struct netns_nexthop { +struct rb_root root;/* tree of nexthops by id */ +struct hlist_head *devhash;/* nexthops by device */ + +unsigned int seq;/* protected by rtnl_mutex */ +u32 last_id_allocated; +}; +#endif
include/net/nexthop.h new file +121 -0
121 lines not on this page · raw message
include/uapi/linux/nexthop.h new file +56 -0
56 lines not on this page · raw message
include/uapi/linux/rtnetlink.h +7 -0
@@ -157,6 +157,13 @@ enum { RTM_GETCHAIN,#define RTM_GETCHAIN RTM_GETCHAIN + RTM_NEWNEXTHOP = 104, +#define RTM_NEWNEXTHOP RTM_NEWNEXTHOP + RTM_DELNEXTHOP, +#define RTM_DELNEXTHOP RTM_DELNEXTHOP + RTM_GETNEXTHOP, +#define RTM_GETNEXTHOP RTM_GETNEXTHOP + __RTM_MAX,#define RTM_MAX (((__RTM_MAX + 3) & ~3) - 1) };
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 netlink.o + metrics.o netlink.o nexthop.o obj-$(CONFIG_BPFILTER) += bpfilter/
net/ipv4/nexthop.c new file +1080 -0
1,080 lines not on this page · raw message
security/selinux/nlmsgtab.c +4 -1
@@ -80,6 +80,9 @@ static const struct nlmsg_perm nlmsg_route_perms[] = { RTM_NEWSTATS, NETLINK_ROUTE_SOCKET__NLMSG_READ }, { RTM_GETSTATS, NETLINK_ROUTE_SOCKET__NLMSG_READ }, { RTM_NEWCACHEREPORT, NETLINK_ROUTE_SOCKET__NLMSG_READ }, + { RTM_NEWNEXTHOP, NETLINK_ROUTE_SOCKET__NLMSG_WRITE }, + { RTM_DELNEXTHOP, NETLINK_ROUTE_SOCKET__NLMSG_WRITE }, + { RTM_GETNEXTHOP, NETLINK_ROUTE_SOCKET__NLMSG_READ }, }; static const struct nlmsg_perm nlmsg_tcpdiag_perms[] =
@@ -159,7 +162,7 @@ int selinux_nlmsg_lookup(u16 sclass, u16 nlmsg_type, u32 *perm)switch (sclass) {case SECCLASS_NETLINK_ROUTE_SOCKET :/* RTM_MAX always point to RTM_SETxxxx, ie RTM_NEWxxx + 3 */ -BUILD_BUG_ON (RTM_MAX != (RTM_NEWCHAIN +3 )); +BUILD_BUG_ON (RTM_MAX != (RTM_NEWNEXTHOP +3 )); err =nlmsg_perm (nlmsg_type, perm, nlmsg_route_perms,sizeof (nlmsg_route_perms));break ;
Signature · 1 line
2.11.0
[email protected]
maintainerRFC PATCH 4/18 net/ipv4: export fib_check_nh
In reply to [email protected]From: David Ahern <[email protected]>
Change fib_check_nh to take net, table and scope as input arguments over struct fib_config and export for use by nexthop code.
--- include/net/ip_fib.h | 2 ++ net/ipv4/fib_semantics.c | 18 +++++++++--------- 2 files changed, 11 insertions(+), 9 deletions(-)
include/net/ip_fib.h +2 -0
@@ -400,6 +400,8 @@ int fib_sync_up(struct net_device *dev, unsigned int nh_flags);int fib_multipath_hash (const struct net *net,const struct flowi4 *fl4,const struct sk_buff *skb,struct flow_keys *flkeys);#endif +int fib_check_nh (struct net *net,struct fib_nh *nh,u32 table,u8 scope, +struct netlink_ext_ack *extack);bool fib_good_nh (const struct fib_nh *nh);void fib_select_multipath (struct fib_result *res,int hash); void fib_select_path(struct net *net, struct fib_result *res,
net/ipv4/fib_semantics.c +9 -9
@@ -777,21 +777,19 @@ bool fib_metrics_match(struct fib_config *cfg, struct fib_info *fi)* | * |-> {local prefix} (terminal node) */ -static int fib_check_nh (struct fib_config *cfg,struct fib_nh *nh, -struct netlink_ext_ack *extack) +int fib_check_nh (struct net *net,struct fib_nh *nh,u32 table,u8 scope, +struct netlink_ext_ack *extack) {int err =0 ; -struct net *net;struct net_device *dev; - net = cfg->fc_nlinfo.nl_net;if (nh->nh_gw) {struct fib_result res;if (nh->nh_flags &RTNH_F_ONLINK ) {unsigned int addr_type; -if (cfg->fc_scope >=RT_SCOPE_LINK ) { +if (scope >=RT_SCOPE_LINK ) {NL_SET_ERR_MSG (extack,"Nexthop has invalid scope" );return -EINVAL ;
@@ -822,7 +820,7 @@ static int fib_check_nh(struct fib_config *cfg, struct fib_nh *nh,struct fib_table *tbl =NULL ;struct flowi4 fl4 = { .daddr = nh->nh_gw, - .flowi4_scope = cfg->fc_scope +1 , + .flowi4_scope = scope +1 , .flowi4_oif = nh->nh_oif, .flowi4_iif =LOOPBACK_IFINDEX , };
@@ -831,8 +829,8 @@ static int fib_check_nh(struct fib_config *cfg, struct fib_nh *nh,if (fl4.flowi4_scope <RT_SCOPE_LINK ) fl4.flowi4_scope =RT_SCOPE_LINK ; -if (cfg->fc_table) - tbl =fib_get_table (net, cfg->fc_table); +if (table) + tbl =fib_get_table (net, table);if (tbl) err = fib_table_lookup(tbl, &fl4, &res,
@@ -1221,7 +1219,9 @@ struct fib_info *fib_create_info(struct fib_config *cfg,int linkdown =0 ;change_nexthops (fi) { - err =fib_check_nh (cfg, nexthop_nh, extack); + err =fib_check_nh (cfg->fc_nlinfo.nl_net, nexthop_nh, + cfg->fc_table, cfg->fc_scope, + extack);if (err !=0 ) goto failure;if (nexthop_nh->nh_flags &RTNH_F_LINKDOWN )
Signature · 1 line
2.11.0
[email protected]
maintainerRFC PATCH 5/18 net/ipv4: Define fib_get_nhs when CONFIG_IP_ROUTE_MULTIPATH is disabled
In reply to [email protected]From: David Ahern <[email protected]>
Define fib_get_nhs to return EINVAL when CONFIG_IP_ROUTE_MULTIPATH is not enabled and remove the ifdef check for CONFIG_IP_ROUTE_MULTIPATH.
--- net/ipv4/fib_semantics.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
net/ipv4/fib_semantics.c +9 -6
@@ -603,6 +603,15 @@ static void fib_rebalance(struct fib_info *fi) }#else /* CONFIG_IP_ROUTE_MULTIPATH */ +static int fib_get_nhs (struct fib_info *fi,struct rtnexthop *rtnh, +int remaining,struct fib_config *cfg, +struct netlink_ext_ack *extack) +{ +NL_SET_ERR_MSG (extack,"Multipath support not enabled in kernel" ); + +return -EINVAL ; +} +#define fib_rebalance (fi) do { } while (0)#endif /* CONFIG_IP_ROUTE_MULTIPATH */
@@ -1112,7 +1121,6 @@ struct fib_info *fib_create_info(struct fib_config *cfg, goto failure;if (cfg->fc_mp) { -#ifdef CONFIG_IP_ROUTE_MULTIPATH err =fib_get_nhs (fi, cfg->fc_mp, cfg->fc_mp_len, cfg, extack);if (err !=0 ) goto failure;
@@ -1133,11 +1141,6 @@ struct fib_info *fib_create_info(struct fib_config *cfg, goto err_inval; }#endif -#else -NL_SET_ERR_MSG (extack, -"Multipath support not enabled in kernel" ); - goto err_inval; -#endif }else {struct fib_nh *nh = fi->fib_nh;
Signature · 1 line
2.11.0
[email protected]
maintainerRFC PATCH 6/18 net/ipv4: Create init and release helpers for fib_nh
In reply to [email protected]From: David Ahern <[email protected]>
Consolidate the fib_nh initialization which is duplicated between fib_create_info for single path and fib_get_nhs for multipath.
Move the fib_nh cleanup code from free_fib_info_rcu into a new helper, fib_nh_release. Move classid accounting into fib_nh_release which is called per fib_nh to make accounting symmetrical with fib_nh_init.
Export both new helpers to allow for use with nexthop objects.
--- include/net/ip_fib.h | 5 ++ net/ipv4/fib_semantics.c | 185 +++++++++++++++++++++++++---------------------- 2 files changed, 104 insertions(+), 86 deletions(-)
include/net/ip_fib.h +5 -0
@@ -400,6 +400,11 @@ int fib_sync_up(struct net_device *dev, unsigned int nh_flags);int fib_multipath_hash (const struct net *net,const struct flowi4 *fl4,const struct sk_buff *skb,struct flow_keys *flkeys);#endif + +int fib_nh_init (struct net *net,struct fib_nh *fib_nh, +struct fib_config *cfg,int nh_weight, +struct netlink_ext_ack *extack); +void fib_nh_release (struct net *net,struct fib_nh *fib_nh);int fib_check_nh (struct net *net,struct fib_nh *nh,u32 table,u8 scope,struct netlink_ext_ack *extack);bool fib_good_nh (const struct fib_nh *nh);
net/ipv4/fib_semantics.c +99 -86
247 lines not on this page · raw message
Signature · 1 line
2.11.0
[email protected]
maintainerRFC PATCH 8/18 net/ipv4: Move device validation to helper
In reply to [email protected]From: David Ahern <[email protected]>
Move the device matching check in __fib_validate_source to a helper. Code move only; no functional change intended.
--- net/ipv4/fib_frontend.c | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-)
net/ipv4/fib_frontend.c +27 -17
@@ -315,6 +315,32 @@ __be32 fib_compute_spec_dst(struct sk_buff *skb)return inet_select_addr (dev,ip_hdr (skb)->saddr, scope); } +static bool fib_info_nh_uses_dev (struct fib_info *fi, +const struct net_device *dev) +{ +bool dev_match = false; +int ret; + +#ifdef CONFIG_IP_ROUTE_MULTIPATH +for (ret =0 ; ret < fi->fib_nhs; ret++) { +struct fib_nh *nh = &fi->fib_nh[ret]; + +if (nh->nh_dev == dev) { + dev_match = true; +break ; + }else if (l3mdev_master_ifindex_rcu (nh->nh_dev) == dev->ifindex) { + dev_match = true; +break ; + } + } +#else +if (FIB_RES_DEV (res) == dev) + dev_match = true; +#endif + +return dev_match; +} +/* Given (packet source, input interface) and optional (dst, oif, tos): * - (main) check, that source is valid i.e. not broadcast or our local * address.
@@ -361,24 +387,8 @@ static int __fib_validate_source(struct sk_buff *skb, __be32 src, __be32 dst, (res.type != RTN_LOCAL || !IN_DEV_ACCEPT_LOCAL(idev))) goto e_inval;fib_combine_itag (itag, &res); - dev_match = false; - -#ifdef CONFIG_IP_ROUTE_MULTIPATH -for (ret =0 ; ret < res.fi->fib_nhs; ret++) { -struct fib_nh *nh = &res.fi->fib_nh[ret]; -if (nh->nh_dev == dev) { - dev_match = true; -break ; - }else if (l3mdev_master_ifindex_rcu (nh->nh_dev) == dev->ifindex) { - dev_match = true; -break ; - } - } -#else -if (FIB_RES_DEV (res) == dev) - dev_match = true; -#endif + dev_match =fib_info_nh_uses_dev (res.fi, dev);if (dev_match) { ret =FIB_RES_NH (res)->nh_scope >=RT_SCOPE_HOST ;return ret;
Signature · 1 line
2.11.0
[email protected]
maintainerRFC PATCH 10/18 net/ipv6: Make fib6_nh optional at the end of fib6_info
In reply to [email protected]From: David Ahern <[email protected]>
Move fib6_nh to the end of fib6_info and make an array of size 0. Pass a flag to fib6_info_alloc indicating if the allocation needs to add space for a fib6_nh.
The current code path always has a fib6_nh allocated; with nexthop objects they will not.
--- include/net/ip6_fib.h | 8 +-- include/net/ip6_route.h | 10 ++- include/trace/events/fib6.h | 15 ++-- net/core/filter.c | 6 +- net/ipv6/addrconf.c | 2 +- net/ipv6/ip6_fib.c | 15 ++-- net/ipv6/ndisc.c | 13 ++-- net/ipv6/route.c | 165 ++++++++++++++++++++++---------------------- 8 files changed, 124 insertions(+), 110 deletions(-)
include/net/ip6_fib.h +4 -4
@@ -170,8 +170,8 @@ struct fib6_info { dst_host:1 , unused:3; -struct fib6_nh fib6_nh;struct rcu_head rcu; +struct fib6_nh fib6_nh[0 ]; };struct rt6_info {
@@ -274,7 +274,7 @@ static inline void ip6_rt_put(struct rt6_info *rt)dst_release (&rt->dst); } -struct fib6_info *fib6_info_alloc (gfp_t gfp_flags); +struct fib6_info *fib6_info_alloc (gfp_t gfp_flags,bool with_fib6_nh);void fib6_info_destroy_rcu (struct rcu_head *head);static inline void fib6_info_hold (struct fib6_info *f6i)
@@ -426,13 +426,13 @@ static inline void fib6_nh_release(struct fib6_nh *fib6_nh)static inline struct net_device *fib6_info_nh_dev (const struct fib6_info *f6i) { -return f6i->fib6_nh.nh_dev; +return f6i->fib6_nh->nh_dev; }static inline struct lwtunnel_state *fib6_info_nh_lwt (const struct fib6_info *f6i) { -return f6i->fib6_nh.nh_lwtstate; +return f6i->fib6_nh->nh_lwtstate; } void inet6_rt_notify(int event, struct fib6_info *rt, struct nl_info *info,
include/net/ip6_route.h +7 -3
@@ -274,9 +274,13 @@ static inline struct in6_addr *rt6_nexthop(struct rt6_info *rt,static inline bool rt6_duplicate_nexthop (struct fib6_info *a,struct fib6_info *b) { -return a->fib6_nh.nh_dev == b->fib6_nh.nh_dev && -ipv6_addr_equal (&a->fib6_nh.nh_gw, &b->fib6_nh.nh_gw) && - !lwtunnel_cmp_encap (a->fib6_nh.nh_lwtstate, b->fib6_nh.nh_lwtstate); +// TO-DO: +//if (a->nh || b->nh) +// return nexthop_cmp(a->nh, b->nh); + +return a->fib6_nh->nh_dev == b->fib6_nh->nh_dev && +ipv6_addr_equal (&a->fib6_nh->nh_gw, &b->fib6_nh->nh_gw) && + !lwtunnel_cmp_encap (a->fib6_nh->nh_lwtstate, b->fib6_nh->nh_lwtstate); }static inline unsigned int ip6_dst_mtu_forward (const struct dst_entry *dst)
include/trace/events/fib6.h +8 -7
@@ -12,7 +12,7 @@ TRACE_EVENT(fib6_table_lookup, - TP_PROTO(const struct net *net, const struct fib6_info *f6i, + TP_PROTO(const struct net *net, struct fib6_info *f6i, struct fib6_table *table, const struct flowi6 *flp), TP_ARGS(net, f6i, table, flp),
@@ -36,6 +36,7 @@ TRACE_EVENT(fib6_table_lookup, ),TP_fast_assign ( + struct fib6_nh *fib6_nh = f6i->fib6_nh;struct in6_addr *in6; __entry->tb_id = table->tb6_id;
@@ -62,20 +63,20 @@ TRACE_EVENT(fib6_table_lookup, __entry->dport =0 ; } -if (f6i->fib6_nh.nh_dev) { -__assign_str (name, f6i->fib6_nh.nh_dev); +if (fib6_nh && fib6_nh->nh_dev) { +__assign_str (name, fib6_nh->nh_dev); }else {__assign_str (name,"-" ); } -if (f6i == net->ipv6.fib6_null_entry) { + +if (!fib6_nh) {struct in6_addr in6_zero = {}; in6 = (struct in6_addr *)__entry->gw; *in6 = in6_zero; - - }else if (f6i) { + }else { in6 = (struct in6_addr *)__entry->gw; - *in6 = f6i->fib6_nh.nh_gw; + *in6 = fib6_nh->nh_gw; } ),
net/core/filter.c +3 -3
@@ -4428,13 +4428,13 @@ static int bpf_ipv6_fib_lookup(struct net *net, struct bpf_fib_lookup *params,return BPF_FIB_LKUP_RET_FRAG_NEEDED ; } -if (f6i->fib6_nh.nh_lwtstate) +if (f6i->fib6_nh->nh_lwtstate)return BPF_FIB_LKUP_RET_UNSUPP_LWT ;if (f6i->fib6_flags &RTF_GATEWAY ) - *dst = f6i->fib6_nh.nh_gw; + *dst = f6i->fib6_nh->nh_gw; - dev = f6i->fib6_nh.nh_dev; + dev = f6i->fib6_nh->nh_dev; params->rt_metric = f6i->fib6_metric;/* xdp and cls_bpf programs are run in RCU-bh so rcu_read_lock_bh is
net/ipv6/addrconf.c +1 -1
@@ -2366,7 +2366,7 @@ static struct fib6_info *addrconf_get_prefix_route(const struct in6_addr *pfx, goto out;for_each_fib6_node_rt_rcu (fn) { -if (rt->fib6_nh.nh_dev->ifindex != dev->ifindex) +if (rt->fib6_nh->nh_dev->ifindex != dev->ifindex)continue ;if ((rt->fib6_flags & flags) != flags)continue ;
net/ipv6/ip6_fib.c +10 -5
@@ -145,11 +145,15 @@ static __be32 addr_bit_set(const void *token, int fn_bit) addr[fn_bit >>5 ]; } -struct fib6_info *fib6_info_alloc (gfp_t gfp_flags) +struct fib6_info *fib6_info_alloc (gfp_t gfp_flags,bool with_fib6_nh) {struct fib6_info *f6i; +size_t sz =sizeof (*f6i); - f6i =kzalloc (sizeof (*f6i), gfp_flags); +if (with_fib6_nh) + sz +=sizeof (struct fib6_nh ); + + f6i =kzalloc (sz, gfp_flags);if (!f6i)return NULL ;
@@ -198,7 +202,7 @@ void fib6_info_destroy_rcu(struct rcu_head *head) } } -fib6_nh_release (&f6i->fib6_nh); +fib6_nh_release (f6i->fib6_nh); m = f6i->fib6_metrics;if (m != &dst_default_metrics &&refcount_dec_and_test (&m->refcnt))
@@ -2247,6 +2251,7 @@ void fib6_gc_cleanup(void)static int ipv6_route_seq_show (struct seq_file *seq,void *v) {struct fib6_info *rt = v; +struct fib6_nh *fib6_nh = rt->fib6_nh;struct ipv6_route_iter *iter = seq->private;const struct net_device *dev;
@@ -2258,11 +2263,11 @@ static int ipv6_route_seq_show(struct seq_file *seq, void *v)seq_puts (seq,"00000000000000000000000000000000 00 " );#endif if (rt->fib6_flags &RTF_GATEWAY ) -seq_printf (seq,"%pi6" , &rt->fib6_nh.nh_gw); +seq_printf (seq,"%pi6" , &fib6_nh->nh_gw);else seq_puts (seq,"00000000000000000000000000000000" ); - dev = rt->fib6_nh.nh_dev; + dev = fib6_nh->nh_dev;seq_printf (seq," %08x %08x %08x %08x %8s\n" , rt->fib6_metric,atomic_read (&rt->fib6_ref),0 , rt->fib6_flags, dev ? dev->name :"" );
net/ipv6/ndisc.c +7 -6
@@ -1156,6 +1156,7 @@ static void ndisc_router_discovery(struct sk_buff *skb)struct neighbour *neigh =NULL ;struct inet6_dev *in6_dev;struct fib6_info *rt =NULL ; +struct fib6_nh *fib6_nh;struct net *net;int lifetime;struct ndisc_options ndopts;
@@ -1276,9 +1277,9 @@ static void ndisc_router_discovery(struct sk_buff *skb) rt =rt6_get_dflt_router (net, &ipv6_hdr (skb)->saddr, skb->dev);if (rt) { - neigh =ip6_neigh_lookup (&rt->fib6_nh.nh_gw, - rt->fib6_nh.nh_dev,NULL , - &ipv6_hdr (skb)->saddr); + fib6_nh = rt->fib6_nh; + neigh =ip6_neigh_lookup (&fib6_nh->nh_gw, fib6_nh->nh_dev,NULL , + &ipv6_hdr (skb)->saddr);if (!neigh) { ND_PRINTK(0, err, "RA: %s got default router without neighbour\n",
@@ -1306,9 +1307,9 @@ static void ndisc_router_discovery(struct sk_buff *skb)return ; } - neigh =ip6_neigh_lookup (&rt->fib6_nh.nh_gw, - rt->fib6_nh.nh_dev,NULL , - &ipv6_hdr (skb)->saddr); + fib6_nh = rt->fib6_nh; + neigh =ip6_neigh_lookup (&fib6_nh->nh_gw, fib6_nh->nh_dev,NULL , + &ipv6_hdr (skb)->saddr);if (!neigh) { ND_PRINTK(0, err, "RA: %s got default router without neighbour\n",
net/ipv6/route.c +84 -81
503 lines not on this page · raw message
Signature · 1 line
2.11.0
[email protected]
maintainerRFC PATCH 12/18 net/ipv4: Add nexthop helpers for ipv4 integration
In reply to [email protected]From: David Ahern <[email protected]>
Add nexthop reference to fib_info along with a list_head for tracking the association of nexthop back to the fib_info.
Add helpers to take a fib_info and return a fib_nh, a nexthop device and nexthop gateway.
Add helper to validate a nexthop works with a fib_info.
--- include/net/ip_fib.h | 4 ++++ include/net/nexthop.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++ net/ipv4/nexthop.c | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+)
include/net/ip_fib.h +4 -0
@@ -103,9 +103,12 @@ struct fib_nh {* This structure contains data shared by many of routes. */ +struct nexthop ; +struct fib_info {struct hlist_node fib_hash;struct hlist_node fib_lhash; +struct list_head nh_list;struct net *fib_net;int fib_treeref;refcount_t fib_clntref;
@@ -122,6 +125,7 @@ struct fib_info {#define fib_window fib_metrics->metrics[RTAX_WINDOW-1]#define fib_rtt fib_metrics->metrics[RTAX_RTT-1]#define fib_advmss fib_metrics->metrics[RTAX_ADVMSS-1] +struct nexthop *nh;int fib_nhs;struct rcu_head rcu;struct fib_nh fib_nh[0 ];
include/net/nexthop.h +46 -0
50 lines not on this page · raw message
net/ipv4/nexthop.c +39 -0
@@ -315,6 +315,21 @@ static void nexthop_notify(int event, struct nexthop *nh, struct nl_info *info)rtnl_set_sk_err (info->nl_net,RTNLGRP_IPV4_ROUTE , err); } +static void __remove_nexthop_fib (struct net *net,struct nexthop *nh) +{ +struct fib_info *fi; +bool do_flush; + + do_flush = false; +list_for_each_entry (fi, &nh->fi_list, nh_list) { + fi->fib_flags |=RTNH_F_DEAD ; + do_flush = true; + } + +if (do_flush) +fib_flush (net); +} +/* called on insert failure too */ static void __remove_nexthop (struct net *net,struct nexthop *nh,bool skip_fib,struct nl_info *nlinfo)
@@ -326,6 +341,8 @@ static void __remove_nexthop(struct net *net, struct nexthop *nh, dev =nh_info_dev (nhi);if (dev)hlist_del (&nhi->dev_hash); +if (!skip_fib) +__remove_nexthop_fib (net, nh); } static void remove_nexthop(struct net *net, struct nexthop *nh,
@@ -461,6 +478,28 @@ static void flush_all_nexthops(struct net *net) } } +/* invoked by fib add code to verify nexthop by id is ok with +* config for prefix; parts of fib_check_nh not done when nexthop +* is created +*/ +int fib_check_nexthop (struct fib_info *fi,struct fib_config *cfg, +struct netlink_ext_ack *extack) +{ +struct nexthop *nh = fi->nh; +struct nh_info *nhi; + + nhi =rtnl_dereference (nh->nh_info); +if (nhi->family !=AF_UNSPEC ) { +if (nh->nh_flags &RTNH_F_ONLINK && + cfg->fc_scope >=RT_SCOPE_LINK ) { +NL_SET_ERR_MSG (extack,"Scope mismatch with nexthop" ); +return -EINVAL ; + } + } + +return 0 ; +} +static int nh_check_attr (struct nhmsg *nhm,struct nlattr *tb[],struct net *net,struct netlink_ext_ack *extack) {
Signature · 1 line
2.11.0
[email protected]
maintainerRFC PATCH 16/18 net/ipv6: Allow routes to use nexthop objects
In reply to [email protected]From: David Ahern <[email protected]>
Allow users to specify a nexthop id to use with a route.
--- include/net/ip6_fib.h | 4 +++ include/net/nexthop.h | 3 ++ net/ipv4/nexthop.c | 5 +++ net/ipv6/addrconf.c | 3 ++ net/ipv6/ip6_fib.c | 17 ++++++++--- net/ipv6/ndisc.c | 2 ++ net/ipv6/route.c | 85 +++++++++++++++++++++++++++++++++++++++++---------- 7 files changed, 98 insertions(+), 21 deletions(-)
include/net/ip6_fib.h +4 -0
@@ -52,6 +52,7 @@ struct fib6_config {u16 fc_type;/* only 8 bits are used */ u16 fc_delete_all_nh : 1, __unused : 15; +u32 fc_nh_id;struct in6_addr fc_dst;struct in6_addr fc_src;
@@ -139,6 +140,8 @@ struct fib6_info {struct fib6_info __rcu *fib6_next;struct fib6_node __rcu *fib6_node; +struct list_head nh_list; +/* Multipath routes: * siblings is a list of fib6_info that have the the same metric/weight, * destination, but not the same gateway. nsiblings is just a cache
@@ -171,6 +174,7 @@ struct fib6_info { unused:3 ;struct rcu_head rcu; +struct nexthop *nh;struct fib6_nh fib6_nh[0 ]; };
include/net/nexthop.h +3 -0
@@ -175,6 +175,9 @@ static inline struct fib6_nh *nexthop_fib6_nh(struct nexthop *nh)static inline struct fib6_nh *fib6_info_nh (struct fib6_info *f6i) { +if (f6i->nh) +return nexthop_fib6_nh (f6i->nh); +return f6i->fib6_nh; }
net/ipv4/nexthop.c +5 -0
@@ -317,6 +317,7 @@ static void nexthop_notify(int event, struct nexthop *nh, struct nl_info *info)static void __remove_nexthop_fib (struct net *net,struct nexthop *nh) { +struct fib6_info *f6i, *tmp;struct fib_info *fi;bool do_flush;
@@ -328,6 +329,10 @@ static void __remove_nexthop_fib(struct net *net, struct nexthop *nh)if (do_flush)fib_flush (net); + +list_for_each_entry_safe (f6i, tmp, &nh->f6i_list, nh_list) { +ip6_del_rt (net, f6i); + } }/* called on insert failure too */
net/ipv6/addrconf.c +3 -0
@@ -2366,6 +2366,9 @@ static struct fib6_info *addrconf_get_prefix_route(const struct in6_addr *pfx, goto out;for_each_fib6_node_rt_rcu (fn) { +/* prefix routes do not use nexthop objects */ +if (rt->nh) +continue ;if (rt->fib6_nh->nh_dev->ifindex != dev->ifindex)continue ;if ((rt->fib6_flags & flags) != flags)
net/ipv6/ip6_fib.c +12 -5
@@ -202,7 +202,10 @@ void fib6_info_destroy_rcu(struct rcu_head *head) } } -fib6_nh_release (f6i->fib6_nh); +if (f6i->nh) +nexthop_put (f6i->nh); +else +fib6_nh_release (f6i->fib6_nh); m = f6i->fib6_metrics;if (m != &dst_default_metrics &&refcount_dec_and_test (&m->refcnt))
@@ -1302,6 +1305,8 @@ int fib6_add(struct fib6_node *root, struct fib6_info *rt,if (!err) {__fib6_update_sernum_upto_root (rt, sernum);fib6_start_gc (info->nl_net, rt); +if (rt->nh) +list_add (&rt->nh_list, &rt->nh->f6i_list); } out:
@@ -1776,6 +1781,9 @@ static void fib6_del_route(struct fib6_table *table, struct fib6_node *fn,fib6_purge_rt (rt, fn, net); +if (rt->nh) +list_del (&rt->nh_list); +call_fib6_entry_notifiers (net,FIB_EVENT_ENTRY_DEL , rt,NULL );if (!info->skip_notify)inet6_rt_notify (RTM_DELROUTE , rt, info,0 );
@@ -2251,7 +2259,6 @@ void fib6_gc_cleanup(void)static int ipv6_route_seq_show (struct seq_file *seq,void *v) {struct fib6_info *rt = v; -struct fib6_nh *fib6_nh = rt->fib6_nh;struct ipv6_route_iter *iter = seq->private;const struct net_device *dev;
@@ -2262,12 +2269,12 @@ static int ipv6_route_seq_show(struct seq_file *seq, void *v)#else seq_puts (seq,"00000000000000000000000000000000 00 " );#endif -if (rt->fib6_flags &RTF_GATEWAY ) -seq_printf (seq,"%pi6" , &fib6_nh->nh_gw); +if (!rt->nh && rt->fib6_flags &RTF_GATEWAY ) +seq_printf (seq,"%pi6" , &rt->fib6_nh->nh_gw);else seq_puts (seq,"00000000000000000000000000000000" ); - dev = fib6_nh->nh_dev; + dev = rt->nh ?NULL : rt->fib6_nh->nh_dev;seq_printf (seq," %08x %08x %08x %08x %8s\n" , rt->fib6_metric,atomic_read (&rt->fib6_ref),0 , rt->fib6_flags, dev ? dev->name :"" );
net/ipv6/ndisc.c +2 -0
@@ -1277,6 +1277,7 @@ static void ndisc_router_discovery(struct sk_buff *skb) rt =rt6_get_dflt_router (net, &ipv6_hdr (skb)->saddr, skb->dev);if (rt) { +/* routes added from RAs do not use nexthop objects */ fib6_nh = rt->fib6_nh; neigh =ip6_neigh_lookup (&fib6_nh->nh_gw, fib6_nh->nh_dev,NULL , &ipv6_hdr (skb)->saddr);
@@ -1307,6 +1308,7 @@ static void ndisc_router_discovery(struct sk_buff *skb)return ; } +/* routes added from RAs do not use nexthop objects */ fib6_nh = rt->fib6_nh; neigh =ip6_neigh_lookup (&fib6_nh->nh_gw, fib6_nh->nh_dev,NULL , &ipv6_hdr (skb)->saddr);
net/ipv6/route.c +69 -16
210 lines not on this page · raw message
Signature · 1 line
2.11.0
[email protected]
maintainerRFC PATCH 17/18 net: Add support for nexthop groups
In reply to [email protected]From: David Ahern <[email protected]>
Allow the creation of nexthop groups which reference other nexthop objects to create multipath routes.
TO-DO: Add mpath support to IPv6
--- include/net/nexthop.h | 77 +++++-- net/ipv4/fib_semantics.c | 5 +- net/ipv4/nexthop.c | 511 ++++++++++++++++++++++++++++++++++++++++++----- net/ipv4/route.c | 16 +- 4 files changed, 540 insertions(+), 69 deletions(-)
include/net/nexthop.h +60 -17
@@ -28,6 +28,23 @@struct nexthop ; +struct nh_grp_entry { +struct nexthop *nh; +u32 weight; +atomic_t upper_bound; + +struct list_head nh_list; +struct nexthop *nh_parent;/* nexthop of group with this entry */ +}; + +struct nh_group { +u16 num_nh_set; +u16 num_nh; +u8 mpath:1 , + unused:7 ; +struct nh_grp_entry nh_entries[0 ]; +}; +struct nh_info {struct hlist_node dev_hash;struct net *net;
@@ -47,6 +64,7 @@ struct nh_info {struct nexthop {struct rb_node rb_node; +struct list_head grp_list;/* nh group entries using this nh */ struct list_head fi_list;/* v4 entries using nh */ struct list_head f6i_list;/* v6 entries using nh */
@@ -54,12 +72,15 @@ struct nexthop {u8 protocol;u8 nh_flags; + u8 is_group:1, + unused:7;refcount_t refcnt;struct rcu_head rcu;union {struct nh_info __rcu *nh_info; +struct nh_group __rcu *nh_grp; }; };
@@ -81,6 +102,9 @@ struct nh_config {struct in6_addr ipv6; } gw; +struct nlattr *nh_grp; +u16 nh_grp_type; +u32 nlflags;struct nl_info nlinfo; };
@@ -88,42 +112,61 @@ struct nh_config {void nexthop_get (struct nexthop *nh);void nexthop_put (struct nexthop *nh); +static inline bool nexthop_cmp (struct nexthop *nh1,struct nexthop *nh2) +{ +return nh1 == nh2; +} +/* caller is holding rtnl; no reference taken to nexthop */ struct nexthop *nexthop_find_by_id (struct net *net,u32 id); -static inline bool nexthop_cmp (struct nexthop *nh1,struct nexthop *nh2) +/* called with rcu lock */ +static inline bool nexthop_is_multipath (const struct nexthop *nh) { -return nh1 == nh2; +if (nh->is_group) { +struct nh_group *nh_grp; + + nh_grp =rcu_dereference (nh->nh_grp); +return !!nh_grp->mpath; + } +return false; } +struct nexthop *nexthop_mpath_select (struct nexthop *nh,int nhsel); + +/* called with rcu lock */ static inline int nexthop_num_path (struct nexthop *nh) { +if (nexthop_is_multipath (nh)) { +struct nh_group *nh_grp; + + nh_grp =rcu_dereference (nh->nh_grp); +return nh_grp->num_nh_set; + } +return 1 ; } -/* called with rcu lock */ +void nexthop_select_path (struct net *net,struct fib_result *res,int hash); +static inline bool nexthop_has_gw (struct nexthop *nh) { -struct nh_info *nhi; - - nhi =rcu_dereference (nh->nh_info); -return !!nhi->has_gw; +return !!nh->nh_info->has_gw; } -/* called with rcu lock */ static inline bool nexthop_is_blackhole (struct nexthop *nh) { -struct nh_info *nhi; - - nhi =rcu_dereference (nh->nh_info); -return !!nhi->reject_nh; +return !nexthop_is_multipath (nh) && !!nh->nh_info->reject_nh; }static inline struct fib_nh *nexthop_fib_nh (struct nexthop *nh,int nhsel) {struct nh_info *nhi; - nhi =rcu_dereference (nh->nh_info); +if (nexthop_is_multipath (nh)) + nh =nexthop_mpath_select (nh, nhsel); + + nhi = nh->nh_info;if (nhi->family ==AF_INET || nhi->family ==AF_UNSPEC )/* dev only re-uses IPv4 struct */ return &nhi->fib_nh;
@@ -164,11 +207,11 @@ static inline __be32 fib_info_nh_gw(struct fib_info *fi)*/ static inline struct fib6_nh *nexthop_fib6_nh (struct nexthop *nh) { -struct nh_info *nhi; +if (nexthop_is_multipath (nh)) + nh =nexthop_mpath_select (nh,0 ); - nhi =rcu_dereference (nh->nh_info); -if (nhi->family ==AF_INET6 ) -return &nhi->fib6_nh; +if (nh->nh_info->family ==AF_INET6 ) +return &nh->nh_info->fib6_nh;return NULL ; }
net/ipv4/fib_semantics.c +4 -1
@@ -1821,7 +1821,10 @@ void fib_select_path(struct net *net, struct fib_result *res, goto check_saddr;#ifdef CONFIG_IP_ROUTE_MULTIPATH -if (res->fi->fib_nhs >1 ) { +if (res->fi->nh &&nexthop_is_multipath (res->fi->nh)) { + h =fib_multipath_hash (net, fl4, skb,NULL ); +nexthop_select_path (net, res, h); + }else if (res->fi->fib_nhs >1 ) { h =fib_multipath_hash (net, fl4, skb,NULL );fib_select_multipath (res, h); }
net/ipv4/nexthop.c +464 -47
670 lines not on this page · raw message
net/ipv4/route.c +12 -4
@@ -112,6 +112,7 @@#include <net/secure_seq.h> #include <net/ip_tunnels.h> #include <net/l3mdev.h> +#include <net/nexthop.h> #include "fib_lookup.h"
@@ -1887,10 +1888,17 @@ static int ip_mkroute_input(struct sk_buff *skb, struct flow_keys *hkeys) {#ifdef CONFIG_IP_ROUTE_MULTIPATH -if (res->fi && res->fi->fib_nhs >1 ) { -int h =fib_multipath_hash (res->fi->fib_net,NULL , skb, hkeys); - -fib_select_multipath (res, h); +if (res->fi) { +struct net *net = res->fi->fib_net; +int h; + +if (res->fi->nh &&nexthop_is_multipath (res->fi->nh)) { + h =fib_multipath_hash (net,NULL , skb, hkeys); +nexthop_select_path (net, res, h); + }else if (res->fi->fib_nhs >1 ) { + h =fib_multipath_hash (net,NULL , skb, hkeys); +fib_select_multipath (res, h); + } }#endif
Signature · 1 line
2.11.0
[email protected]
maintainerRFC PATCH 18/18 net/ipv4: Optimization for fib_info lookup
In reply to [email protected]From: David Ahern <[email protected]>
Be optimistic about re-using a fib_info when nexthop id is given and the route does not use metrics. Avoids a memory allocation which in most cases is expected to be freed anyways.
--- net/ipv4/fib_semantics.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+)
net/ipv4/fib_semantics.c +48 -0
@@ -316,6 +316,19 @@ static inline unsigned int fib_devindex_hashfn(unsigned int val) (val >> (DEVINDEX_HASHBITS * 2))) & mask; } +static inline unsigned int fib_info_hashfn_cfg (const struct fib_config *cfg) +{ +unsigned int mask = (fib_info_hash_size -1 ); +unsigned int val =0 ; + + val ^= (cfg->fc_protocol <<8 ) | cfg->fc_scope; + val ^= (__force u32 )cfg->fc_prefsrc; + val ^= cfg->fc_priority; + val ^=fib_devindex_hashfn (cfg->fc_nh_id); + +return (val ^ (val >>7 ) ^ (val >>12 )) & mask; +} +static inline unsigned int fib_info_hashfn (const struct fib_info *fi) {unsigned int mask = (fib_info_hash_size -1 );
@@ -334,6 +347,35 @@ static inline unsigned int fib_info_hashfn(const struct fib_info *fi)return (val ^ (val >>7 ) ^ (val >>12 )) & mask; } +/* no metrics, only nexthop id */ +static struct fib_info *fib_find_info_nh (struct net *net, +const struct fib_config *cfg) +{ +struct hlist_head *head; +struct fib_info *fi; +unsigned int hash; + + hash =fib_info_hashfn_cfg (cfg); + head = &fib_info_hash[hash]; + +hlist_for_each_entry (fi, head, fib_hash) { +if (!net_eq (fi->fib_net, net)) +continue ; +if (!fi->nh || fi->nh->id != cfg->fc_nh_id) +continue ; +if (cfg->fc_protocol == fi->fib_protocol && + cfg->fc_scope == fi->fib_scope && + cfg->fc_prefsrc == fi->fib_prefsrc && + cfg->fc_priority == fi->fib_priority && + cfg->fc_type == fi->fib_type && + cfg->fc_table == fi->fib_tb_id && + !((cfg->fc_flags ^ fi->fib_flags) & ~RTNH_COMPARE_MASK )) +return fi; + } + +return NULL ; +} +static struct fib_info *fib_find_info (const struct fib_info *nfi) {struct hlist_head *head;
@@ -1154,6 +1196,12 @@ struct fib_info *fib_create_info(struct fib_config *cfg, goto err_inval; } +if (!cfg->fc_mx) { + fi =fib_find_info_nh (net, cfg); +if (fi) +return fi; + } + nh =nexthop_find_by_id (net, cfg->fc_nh_id);if (!nh) { NL_SET_ERR_MSG(extack,
Signature · 1 line
2.11.0
[email protected]
maintainercover net: Improve route scalability via support for nexthop objects
From: David Ahern <[email protected]>
As mentioned at netconf in Seoul, we would like to introduce nexthops as independent objects from the routes to better align with both routing daemons and hardware and to improve route insertion times into the kernel.
This series adds nexthop objects with their own lifecycle. The model retains a lot of the established semantics from routes and re-uses some of the data structures like fib_nh and fib6_nh to more easily align with the existing code. One difference with nexthop objects is the behavior better aligns with the target user - routing daemons and switch ASICs. Specifically, with the exception of the blackhole nexthop, all nexthops must reference a netdevice (or have a gateway that resolves to a device) and the device must be admin up with carrier.
Prefixes are then installed pointing to the nexthop by id:
{ prefix } --> { nexthop } --> { gateway, device }
The nexthop object contains the gateway and device reference.
Benchmarks
The following data shows the route insert time for 720,022 routes (a full IPv4 internet feed from August 28th). "current" means the current code where a route insert specifies the device and gateway inline with the prefix; the "nexthop" columns mean use of the nexthop objects.
1-hop 1-hop | 2-hops 2-hops
current nexthop | current nexthop
--------------------------|-------------------------
real 0m21.872s 0m12.982s | 0m28.723s 0m12.406s
user 0m2.929s 0m1.816s | 0m3.966s 0m1.935s
sys 0m13.469s 0m6.010s | 0m18.992s 0m5.913sWith nexthop objects the time to insert the routes is reduced by more than 30% with the kernel time cut in half. The current model has a route insertion rate of about 32,000 prefixes / second and with nexthop objects that increases to a little over 55,000 prefixes/second.
For routes with multiple nexthops the install time is cut by more than half with system time reduce by a factor of 3. Further, with nexthop objects insert times for multipath routes drops down to the same as single path routes since the multipath spec is given once (ie., with the current model, the time to insert routes increases with the number of paths in the route compared to nexthop objects where the number of paths is handled once and the prefixes referencing it are installed in constant time.
The difference between real and system times shows there is room for improvement with the trie implementation. As an example, increasing the sync_pages from 128 to 1024 delays the call to synchronize_rcu increasing the insert rate to more than 78,000 prefixes/sec!
Some key features:
1. Allows atomic replace of any nexthop object - a nexthop or a group. This allows existing route entries to have their nexthop updated without the overhead of removing and re-inserting (or replacing) them. Instead, one update of the nexthop object implicitly updates all routes referencing it.
One limitation with the atomic replace is that a nexthop group can only be replaced with a new group spec and similarly a nexthop can only be replaced by a nexthop spec. Specifically, a nexthop id can not move between a single nexthop and a group nexthop.
2. Blackhole nexthop: a nexthop object can be designated a blackhole which means any lookups that resolve to it, packets are dropped as if the lookup failed with the result RTN_BLACKHOLE. Blackhole nexthops can not be used with nexthop groups. Combined with atomic replace this allows routes to be installed pointing to a blackhole nexthop and then switched to an actual gateway with a single nexthop replace command (or vice versa, a gateway nexthop is flipped to a blackhole).
3. Nexthop groups for multipath routes. A nexthop group is a nexthop that references other nexthops. A multipath group can not be used as a nexthop in another nexthop group (ie., groups can not be nested).
4. Multipath routes for IPv6 with device only nexthops. There is a demonstrated need for this feature and the existing route semantics do not allow it. This series provides a means for that end - create a nexthop that has a device only specification.
5. Admin and carrier up are required. If the device goes down (admin or carrier) the nexthop is removed in which case routes referencing the nexthop are evicted and any nexthop groups referencing it are adjusted.
6. Follow on patches will allow IPv6 nexthops with IPv4 routes for users wanting support of RFC 5549.
7. Future extensions: active / backup nexthop. The nexthop groups are structured to allow a new group type to be added. One example is a group where a nexthop has a preferred device and gateway, but should the device go down or the gateway not resolve, the backup nexthop is used.
Additional Benefits
- smaller route notifications - messages contain a single nexthop id versus the detailed nexthop specification. This is especially noticeable as the number of paths increases. Smaller messages have a reduced load on userspace as well.
- smaller memory footprint for IPv6 routes.
Examples
1. Single path
$ ip nexthop add id 1 via 10.99.1.2 dev veth1
$ ip route add 10.1.1.0/24 nhid 1 $ ip next ls
id 1 via 10.99.1.2 src 10.99.1.1 dev veth1 scope link $ ip ro ls
10.1.1.0/24 nhid 1 scope link
...2. ECMP
$ ip nexthop add id 2 via 10.99.3.2 dev veth3
$ ip nexthop add id 1001 group 1/2
--> creates a nexthop group with 2 component nexthops:
id 1 and id 2 both the same weight$ ip route add 10.1.2.0/24 nhid 1001
$ ip next ls
id 1 via 10.99.1.2 src 10.99.1.1 dev veth1 scope link
id 2 via 10.99.3.2 src 10.99.3.1 dev veth3 scope link
id 1001 group 1/2 $ ip ro ls
10.1.1.0/24 nhid 1 scope link
10.1.2.0/24 nhid 1001 scope link
...3. Weighted multipath
$ ip nexthop add id 1002 group 1,10/2,20
--> creates a nexthop group with 2 component nexthops:
id 1 with a weight of 10 and id 2 with a weight of 20$ ip route add 10.1.3.0/24 nhid 1002
$ ip next ls
id 1 via 10.99.1.2 src 10.99.1.1 dev veth1 scope link
id 2 via 10.99.3.2 src 10.99.3.1 dev veth3 scope link
id 1001 group 1/2
id 1002 group 1,10/2,20 $ ip ro ls
10.1.1.0/24 nhid 1 scope link
10.1.2.0/24 nhid 1001 scope link
10.1.3.0/24 nhid 1002 scope link
...Open Items
There is long to-do list before this is ready (e.g., IPv6 multipath, lwt encap, and updating mlxsw). The point of this RFC is to get comments on the API and overall idea. Specifically, any interested parties should think about the API, the objects, the workflow, how it fits and possibility for future extensions.
David Ahern (18):
net: Rename net/nexthop.h net/rtnh.h
net: ipv4: export fib_good_nh and fib_flush net/ipv4: export fib_info_update_nh_saddr
net/ipv4: export fib_check_nh
net/ipv4: Define fib_get_nhs when CONFIG_IP_ROUTE_MULTIPATH is
disabled
net/ipv4: Create init and release helpers for fib_nh
net: ipv4: Add fib_nh to fib_result
net/ipv4: Move device validation to helper
net/ipv6: Create init and release helpers for fib6_nh net/ipv6: Make fib6_nh optional at the end of fib6_info
net: Initial nexthop code
net/ipv4: Add nexthop helpers for ipv4 integration net/ipv4: Convert existing use of fib_info to new helpers net/ipv4: Allow routes to use nexthop objects net/ipv6: Use helpers to access fib6_nh data net/ipv6: Allow routes to use nexthop objects
net: Add support for nexthop groups
net/ipv4: Optimization for fib_info lookup
.../net/ethernet/mellanox/mlxsw/spectrum_router.c | 4 +- drivers/net/ethernet/rocker/rocker_ofdpa.c | 20 +- include/net/addrconf.h | 5 + include/net/ip6_fib.h | 22 +- include/net/ip6_route.h | 12 +- include/net/ip_fib.h | 39 +- include/net/net_namespace.h | 2 + include/net/netns/nexthop.h | 18 + include/net/nexthop.h | 253 +++- include/net/rtnh.h | 34 + include/trace/events/fib6.h | 15 +- include/uapi/linux/nexthop.h | 56 + include/uapi/linux/rtnetlink.h | 8 + net/core/filter.c | 13 +- net/core/lwtunnel.c | 2 +- net/decnet/dn_fib.c | 2 +- net/ipv4/Makefile | 2 +- net/ipv4/fib_frontend.c | 60 +- net/ipv4/fib_rules.c | 3 +- net/ipv4/fib_semantics.c | 433 ++++-- net/ipv4/fib_trie.c | 54 +- net/ipv4/ipmr.c | 2 +- net/ipv4/nexthop.c | 1541 ++++++++++++++++++++ net/ipv4/route.c | 34 +- net/ipv6/addrconf.c | 5 +- net/ipv6/addrconf_core.c | 9 + net/ipv6/af_inet6.c | 1 + net/ipv6/ip6_fib.c | 27 +- net/ipv6/ndisc.c | 15 +- net/ipv6/route.c | 474 +++--- net/mpls/af_mpls.c | 2 +- security/selinux/nlmsgtab.c | 5 +- 32 files changed, 2690 insertions(+), 482 deletions(-) create mode 100644 include/net/netns/nexthop.h create mode 100644 include/net/rtnh.h create mode 100644 include/uapi/linux/nexthop.h create mode 100644 net/ipv4/nexthop.c
Signature · 1 line
2.11.0
[email protected]
maintainerRFC PATCH 1/18 net: Rename net/nexthop.h net/rtnh.h
From: David Ahern <[email protected]>
The header contains rtnh_ macros so rename the file accordingly. Allows next patch to use the nexthop.h name.
---
include/net/{nexthop.h => rtnh.h} | 4 ++--
net/core/lwtunnel.c | 2 +-
net/decnet/dn_fib.c | 2 +-
net/ipv4/fib_semantics.c | 2 +-
net/ipv4/ipmr.c | 2 +-
net/ipv6/route.c | 2 +-
net/mpls/af_mpls.c | 2 +-
7 files changed, 8 insertions(+), 8 deletions(-)
rename include/net/{nexthop.h => rtnh.h} (94%)include/net/rtnh.h renamed from include/net/nexthop.h +2 -2
@@ -1,6 +1,6 @@/* SPDX-License-Identifier: GPL-2.0 */ -#ifndef __NET_NEXTHOP_H -#define __NET_NEXTHOP_H +#ifndef __NET_RTNH_H +#define __NET_RTNH_H#include <linux/rtnetlink.h> #include <net/netlink.h>
net/core/lwtunnel.c +1 -1
@@ -26,7 +26,7 @@#include <net/lwtunnel.h> #include <net/rtnetlink.h> #include <net/ip6_fib.h> -#include <net/nexthop.h> +#include <net/rtnh.h> #ifdef CONFIG_MODULES
net/decnet/dn_fib.c +1 -1
@@ -42,7 +42,7 @@#include <net/dn_fib.h> #include <net/dn_neigh.h> #include <net/dn_dev.h> -#include <net/nexthop.h> +#include <net/rtnh.h> #define RT_MIN_TABLE 1
net/ipv4/fib_semantics.c +1 -1
@@ -42,7 +42,7 @@#include <net/sock.h> #include <net/ip_fib.h> #include <net/netlink.h> -#include <net/nexthop.h> +#include <net/rtnh.h> #include <net/lwtunnel.h> #include <net/fib_notifier.h>
net/ipv4/ipmr.c +1 -1
@@ -66,7 +66,7 @@#include <net/netlink.h> #include <net/fib_rules.h> #include <linux/netconf.h> -#include <net/nexthop.h> +#include <net/rtnh.h> #include <net/switchdev.h> struct ipmr_rule {
net/ipv6/route.c +1 -1
@@ -59,7 +59,7 @@#include <net/xfrm.h> #include <net/netevent.h> #include <net/netlink.h> -#include <net/nexthop.h> +#include <net/rtnh.h> #include <net/lwtunnel.h> #include <net/ip_tunnels.h> #include <net/l3mdev.h>
net/mpls/af_mpls.c +1 -1
@@ -23,7 +23,7 @@#include <net/ipv6.h> #endif #include <net/addrconf.h> -#include <net/nexthop.h> +#include <net/rtnh.h> #include "internal.h" /* max memory we will use for mpls_route */
Signature · 1 line
2.11.0
[email protected]
maintainerRFC PATCH 7/18 net: ipv4: Add fib_nh to fib_result
In reply to [email protected]From: David Ahern <[email protected]>
Add nexthop selection to fib_result and update FIB_RES macros to use it. Right now, fib_nh in fib_result will point to a nexthop within a fib_info. Later, fib_nh can point to data with a nexthop.
--- include/net/ip_fib.h | 21 +++++++++------------ net/core/filter.c | 2 +- net/ipv4/fib_frontend.c | 4 ++-- net/ipv4/fib_semantics.c | 4 ++-- net/ipv4/fib_trie.c | 4 ++-- net/ipv4/route.c | 18 +++++++++--------- 6 files changed, 25 insertions(+), 28 deletions(-)
include/net/ip_fib.h +9 -12
@@ -141,6 +141,7 @@ struct fib_result {unsigned char type;unsigned char scope;u32 tclassid; +struct fib_nh *nh;struct fib_info *fi;struct fib_table *table;struct hlist_head *fa_head;
@@ -161,11 +162,7 @@ struct fib_result_nl {int err; }; -#ifdef CONFIG_IP_ROUTE_MULTIPATH -#define FIB_RES_NH (res) ((res).fi->fib_nh[(res).nh_sel]) -#else /* CONFIG_IP_ROUTE_MULTIPATH */ -#define FIB_RES_NH (res) ((res).fi->fib_nh[0]) -#endif /* CONFIG_IP_ROUTE_MULTIPATH */ +#define FIB_RES_NH (res) ((res).nh)#ifdef CONFIG_IP_MULTIPLE_TABLES #define FIB_TABLE_HASHSZ 256
@@ -177,13 +174,13 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh, unsigned char scope);#define FIB_RES_SADDR (net, res) \ - ((FIB_RES_NH(res).nh_saddr_genid == \ + ((FIB_RES_NH(res)->nh_saddr_genid == \ atomic_read(&(net)->ipv4.dev_addr_genid)) ? \ - FIB_RES_NH(res).nh_saddr : \ - fib_info_update_nh_saddr((net), &FIB_RES_NH(res), (res).fi->fib_scope)) -#define FIB_RES_GW (res) (FIB_RES_NH(res).nh_gw) -#define FIB_RES_DEV (res) (FIB_RES_NH(res).nh_dev) -#define FIB_RES_OIF (res) (FIB_RES_NH(res).nh_oif) + FIB_RES_NH(res)->nh_saddr : \ + fib_info_update_nh_saddr((net), FIB_RES_NH(res), (res).fi->fib_scope)) +#define FIB_RES_GW (res) (FIB_RES_NH(res)->nh_gw) +#define FIB_RES_DEV (res) (FIB_RES_NH(res)->nh_dev) +#define FIB_RES_OIF (res) (FIB_RES_NH(res)->nh_oif)#define FIB_RES_PREFSRC (net, res) ((res).fi->fib_prefsrc ? : \ FIB_RES_SADDR(net, res))
@@ -422,7 +419,7 @@ static inline void fib_combine_itag(u32 *itag, const struct fib_result *res)#ifdef CONFIG_IP_MULTIPLE_TABLES u32 rtag;#endif - *itag =FIB_RES_NH (*res).nh_tclassid<<16 ; + *itag =FIB_RES_NH (*res)->nh_tclassid <<16 ;#ifdef CONFIG_IP_MULTIPLE_TABLES rtag = res->tclassid;if (*itag ==0 )
net/core/filter.c +1 -1
@@ -4311,7 +4311,7 @@ static int bpf_ipv4_fib_lookup(struct net *net, struct bpf_fib_lookup *params,return BPF_FIB_LKUP_RET_FRAG_NEEDED ; } - nh = &res.fi->fib_nh[res.nh_sel]; + nh = res.nh;/* do not handle lwt encaps right now */ if (nh->nh_lwtstate)
net/ipv4/fib_frontend.c +2 -2
@@ -380,7 +380,7 @@ static int __fib_validate_source(struct sk_buff *skb, __be32 src, __be32 dst, dev_match = true;#endif if (dev_match) { - ret =FIB_RES_NH (res).nh_scope >=RT_SCOPE_HOST ; + ret =FIB_RES_NH (res)->nh_scope >=RT_SCOPE_HOST ;return ret; }if (no_addr)
@@ -392,7 +392,7 @@ static int __fib_validate_source(struct sk_buff *skb, __be32 src, __be32 dst, ret =0 ;if (fib_lookup (net, &fl4, &res,FIB_LOOKUP_IGNORE_LINKSTATE ) ==0 ) {if (res.type ==RTN_UNICAST ) - ret =FIB_RES_NH (res).nh_scope >=RT_SCOPE_HOST ; + ret =FIB_RES_NH (res)->nh_scope >=RT_SCOPE_HOST ; }return ret;
net/ipv4/fib_semantics.c +2 -2
@@ -1728,7 +1728,7 @@ void fib_select_multipath(struct fib_result *res, int hash)if (!fib_good_nh (nh))continue ;if (!first) { - res->nh_sel = nhsel; + res->nh = &fi->fib_nh[nhsel]; first = true; } }
@@ -1736,7 +1736,7 @@ void fib_select_multipath(struct fib_result *res, int hash)if (hash >atomic_read (&nh->nh_upper_bound))continue ; - res->nh_sel = nhsel; + res->nh = &fi->fib_nh[nhsel];return ; }endfor_nexthops (fi); }
net/ipv4/fib_trie.c +2 -2
@@ -1468,7 +1468,7 @@ int fib_table_lookup(struct fib_table *tb, const struct flowi4 *flp,if (fi->fib_flags &RTNH_F_DEAD )continue ;for (nhsel =0 ; nhsel < fi->fib_nhs; nhsel++) { -const struct fib_nh *nh = &fi->fib_nh[nhsel]; +struct fib_nh *nh = &fi->fib_nh[nhsel];struct in_device *in_dev =__in_dev_get_rcu (nh->nh_dev);if (nh->nh_flags &RTNH_F_DEAD )
@@ -1489,7 +1489,7 @@ int fib_table_lookup(struct fib_table *tb, const struct flowi4 *flp, res->prefix =htonl (n->key); res->prefixlen =KEYLENGTH - fa->fa_slen; - res->nh_sel = nhsel; + res->nh = nh; res->type = fa->fa_type; res->scope = fi->fib_scope; res->fi = fi;
net/ipv4/route.c +9 -9
@@ -776,7 +776,7 @@ static void __ip_do_redirect(struct rtable *rt, struct sk_buff *skb, struct flowneigh_event_send (n,NULL ); }else {if (fib_lookup (net, fl4, &res,0 ) ==0 ) { -struct fib_nh *nh = &FIB_RES_NH (res); +struct fib_nh *nh =FIB_RES_NH (res); update_or_create_fnhe(nh, fl4->daddr, new_gw, 0, false,
@@ -1021,7 +1021,7 @@ static void __ip_rt_update_pmtu(struct rtable *rt, struct flowi4 *fl4, u32 mtu)rcu_read_lock ();if (fib_lookup (dev_net (dst->dev), fl4, &res,0 ) ==0 ) { -struct fib_nh *nh = &FIB_RES_NH (res); +struct fib_nh *nh =FIB_RES_NH (res);update_or_create_fnhe (nh, fl4->daddr,0 , mtu, lock, jiffies + ip_rt_mtu_expires);
@@ -1350,7 +1350,7 @@ static struct fib_nh_exception *find_exception(struct fib_nh *nh, __be32 daddr)u32 ip_mtu_from_fib_result (struct fib_result *res,__be32 daddr) {struct fib_info *fi = res->fi; -struct fib_nh *nh = &fi->fib_nh[res->nh_sel]; +struct fib_nh *nh = res->nh;struct net_device *dev = nh->nh_dev;u32 mtu =0 ;
@@ -1527,7 +1527,7 @@ static void rt_set_nexthop(struct rtable *rt, __be32 daddr,bool cached = false;if (fi) { -struct fib_nh *nh = &FIB_RES_NH (*res); +struct fib_nh *nh =FIB_RES_NH (*res);if (nh->nh_gw && nh->nh_scope ==RT_SCOPE_LINK ) { rt->rt_gateway = nh->nh_gw;
@@ -1744,12 +1744,12 @@ static int __mkroute_input(struct sk_buff *skb, } } - fnhe =find_exception (&FIB_RES_NH (*res), daddr); + fnhe =find_exception (FIB_RES_NH (*res), daddr);if (do_cache) {if (fnhe) rth =rcu_dereference (fnhe->fnhe_rth_input);else - rth =rcu_dereference (FIB_RES_NH (*res).nh_rth_input); + rth =rcu_dereference (FIB_RES_NH (*res)->nh_rth_input);if (rt_cache_valid (rth)) {skb_dst_set_noref (skb, &rth->dst); goto out;
@@ -2039,7 +2039,7 @@ out: return err; do_cache = false;if (res->fi) {if (!itag) { - rth =rcu_dereference (FIB_RES_NH (*res).nh_rth_input); + rth =rcu_dereference (FIB_RES_NH (*res)->nh_rth_input);if (rt_cache_valid (rth)) {skb_dst_set_noref (skb, &rth->dst); err =0 ;
@@ -2069,7 +2069,7 @@ out: return err; }if (do_cache) { -struct fib_nh *nh = &FIB_RES_NH (*res); +struct fib_nh *nh =FIB_RES_NH (*res); rth->dst.lwtstate =lwtstate_get (nh->nh_lwtstate);if (lwtunnel_input_redirect (rth->dst.lwtstate)) {
@@ -2249,7 +2249,7 @@ static struct rtable *__mkroute_output(const struct fib_result *res, do_cache &= fi !=NULL ;if (fi) {struct rtable __rcu **prth; -struct fib_nh *nh = &FIB_RES_NH (*res); +struct fib_nh *nh =FIB_RES_NH (*res); fnhe =find_exception (nh, fl4->daddr);if (!do_cache)
Signature · 1 line
2.11.0
[email protected]
maintainerRFC PATCH 13/18 net/ipv4: Convert existing use of fib_info to new helpers
In reply to [email protected]From: David Ahern <[email protected]>
Remove direct accesses to fi->fib_nh in favor of the helpers added in the previous patch.
--- .../net/ethernet/mellanox/mlxsw/spectrum_router.c | 4 +++- drivers/net/ethernet/rocker/rocker_ofdpa.c | 20 ++++++++++++++------ include/net/ip_fib.h | 1 - net/ipv4/fib_frontend.c | 3 ++- net/ipv4/fib_rules.c | 3 ++- net/ipv4/fib_semantics.c | 12 ++++++++---- net/ipv4/fib_trie.c | 19 +++++++++++-------- 7 files changed, 40 insertions(+), 22 deletions(-)
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +3 -1
@@ -28,6 +28,7 @@#include <net/ipv6.h> #include <net/fib_notifier.h> #include <net/switchdev.h> +#include <net/nexthop.h> #include "spectrum.h" #include "core.h"
@@ -4121,12 +4122,13 @@ mlxsw_sp_fib4_entry_type_set(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_fib_entry *fib_entry) {union mlxsw_sp_l3addr dip = { .addr4 =htonl (fen_info->dst) }; -struct net_device *dev = fen_info->fi->fib_dev;struct mlxsw_sp_ipip_entry *ipip_entry;struct fib_info *fi = fen_info->fi; +struct net_device *dev;switch (fen_info->type) {case RTN_LOCAL : + dev =fib_info_nh_dev (fi); ipip_entry =mlxsw_sp_ipip_entry_find_by_decap (mlxsw_sp, dev,MLXSW_SP_L3_PROTO_IPV4 , dip);if (ipip_entry && ipip_entry->ol_dev->flags &IFF_UP ) {
drivers/net/ethernet/rocker/rocker_ofdpa.c +14 -6
@@ -23,6 +23,7 @@#include <net/switchdev.h> #include <net/ip_fib.h> #include <net/arp.h> +#include <net/nexthop.h> #include "rocker.h" #include "rocker_tlv.h"
@@ -2286,8 +2287,8 @@ static int ofdpa_port_fib_ipv4(struct ofdpa_port *ofdpa_port, __be32 dst,/* XXX support ECMP */ - nh = fi->fib_nh; - nh_on_port = (fi->fib_dev == ofdpa_port->dev); + nh =fib_info_nh (fi,0 ); + nh_on_port = (nh->nh_dev == ofdpa_port->dev); has_gw = !!nh->nh_gw;if (has_gw && nh_on_port) {
@@ -2747,11 +2748,13 @@ static int ofdpa_fib4_add(struct rocker *rocker, {struct ofdpa *ofdpa = rocker->wpriv;struct ofdpa_port *ofdpa_port; +struct net_device *dev;int err;if (ofdpa->fib_aborted)return 0 ; - ofdpa_port =ofdpa_port_dev_lower_find (fen_info->fi->fib_dev, rocker); + dev =fib_info_nh_dev (fen_info->fi); + ofdpa_port =ofdpa_port_dev_lower_find (dev, rocker);if (!ofdpa_port)return 0 ; err = ofdpa_port_fib_ipv4(ofdpa_port, htonl(fen_info->dst),
@@ -2768,10 +2771,12 @@ static int ofdpa_fib4_del(struct rocker *rocker, {struct ofdpa *ofdpa = rocker->wpriv;struct ofdpa_port *ofdpa_port; +struct net_device *dev;if (ofdpa->fib_aborted)return 0 ; - ofdpa_port =ofdpa_port_dev_lower_find (fen_info->fi->fib_dev, rocker); + dev =fib_info_nh_dev (fen_info->fi); + ofdpa_port =ofdpa_port_dev_lower_find (dev, rocker);if (!ofdpa_port)return 0 ; fen_info->fi->fib_nh->nh_flags &= ~RTNH_F_OFFLOAD ;
@@ -2794,11 +2799,14 @@ static void ofdpa_fib4_abort(struct rocker *rocker)spin_lock_irqsave (&ofdpa->flow_tbl_lock, flags);hash_for_each_safe (ofdpa->flow_tbl, bkt, tmp, flow_entry, entry) { +struct net_device *dev; +if (flow_entry->key.tbl_id !=ROCKER_OF_DPA_TABLE_ID_UNICAST_ROUTING )continue ; - ofdpa_port =ofdpa_port_dev_lower_find (flow_entry->fi->fib_dev, - rocker); + + dev =fib_info_nh_dev (flow_entry->fi); + ofdpa_port =ofdpa_port_dev_lower_find (dev, rocker);if (!ofdpa_port)continue ; flow_entry->fi->fib_nh->nh_flags &= ~RTNH_F_OFFLOAD ;
include/net/ip_fib.h +0 -1
@@ -129,7 +129,6 @@ struct fib_info {int fib_nhs;struct rcu_head rcu;struct fib_nh fib_nh[0 ]; -#define fib_dev fib_nh[0].nh_dev };
net/ipv4/fib_frontend.c +2 -1
@@ -35,6 +35,7 @@#include <linux/init.h> #include <linux/list.h> #include <linux/slab.h> +#include <net/nexthop.h> #include <net/ip.h> #include <net/protocol.h>
@@ -234,7 +235,7 @@ static inline unsigned int __inet_dev_addr_type(struct net *net,if (table) { ret =RTN_UNICAST ;if (!fib_table_lookup (table, &fl4, &res,FIB_LOOKUP_NOREF )) { -if (!dev || dev == res.fi->fib_dev) +if (!dev || dev ==fib_info_nh_dev (res.fi)) ret = res.type; } }
net/ipv4/fib_rules.c +2 -1
@@ -32,6 +32,7 @@#include <net/tcp.h> #include <net/ip_fib.h> #include <net/fib_rules.h> +#include <net/nexthop.h> struct fib4_rule {struct fib_rule common;
@@ -146,7 +147,7 @@ static bool fib4_rule_suppress(struct fib_rule *rule, struct fib_lookup_arg *argstruct net_device *dev =NULL ;if (result->fi) - dev = result->fi->fib_dev; + dev =fib_info_nh_dev (result->fi);/* do not accept result if the route does * not meet the required prefix length
net/ipv4/fib_semantics.c +8 -4
@@ -45,6 +45,7 @@#include <net/rtnh.h> #include <net/lwtunnel.h> #include <net/fib_notifier.h> +#include <net/nexthop.h> #include "fib_lookup.h"
@@ -447,10 +448,11 @@ static int fib_detect_death(struct fib_info *fi, int order, struct fib_info **last_resort, int *last_idx, int dflt) { + struct fib_nh *fnh = fib_info_nh(fi, 0);struct neighbour *n;int state =NUD_NONE ; - n =neigh_lookup (&arp_tbl, &fi->fib_nh[0 ].nh_gw, fi->fib_dev); + n =neigh_lookup (&arp_tbl, &fnh->nh_gw, fnh->nh_dev);if (n) { state = n->nud_state;neigh_release (n);
@@ -713,7 +715,7 @@ int fib_nh_match(struct fib_config *cfg, struct fib_info *fi,if (cfg->fc_oif || cfg->fc_gw) {if (cfg->fc_encap) {if (fib_encap_match (cfg->fc_encap_type, cfg->fc_encap, - fi->fib_nh, cfg, extack)) +fib_info_nh (fi,0 ), cfg, extack))return 1 ; }#ifdef CONFIG_IP_ROUTE_CLASSID
@@ -1571,6 +1573,7 @@ static void fib_select_default(const struct flowi4 *flp, struct fib_result *res)hlist_for_each_entry_rcu (fa, fa_head, fa_list) {struct fib_info *next_fi = fa->fa_info; +struct fib_nh *fnh;if (fa->fa_slen != slen)continue ;
@@ -1592,8 +1595,9 @@ static void fib_select_default(const struct flowi4 *flp, struct fib_result *res)if (next_fi->fib_scope != res->scope || fa->fa_type !=RTN_UNICAST )continue ; -if (!next_fi->fib_nh[0 ].nh_gw || - next_fi->fib_nh[0 ].nh_scope !=RT_SCOPE_LINK ) + + fnh =fib_info_nh (next_fi,0 ); +if (!fnh->nh_gw || fnh->nh_scope !=RT_SCOPE_LINK )continue ;fib_alias_accessed (fa);
net/ipv4/fib_trie.c +11 -8
@@ -83,6 +83,7 @@#include <net/sock.h> #include <net/ip_fib.h> #include <net/fib_notifier.h> +#include <net/nexthop.h> #include <trace/events/fib.h> #include "fib_lookup.h"
@@ -2621,13 +2622,13 @@ static void fib_route_seq_stop(struct seq_file *seq, void *v)rcu_read_unlock (); } -static unsigned int fib_flag_trans (int type,__be32 mask,const struct fib_info *fi) +static unsigned int fib_flag_trans (int type,__be32 mask,struct fib_info *fi) {unsigned int flags =0 ;if (type ==RTN_UNREACHABLE || type ==RTN_PROHIBIT ) flags =RTF_REJECT ; -if (fi && fi->fib_nh->nh_gw) +if (fi &&fib_info_nh_gw (fi)) flags |=RTF_GATEWAY ;if (mask ==htonl (0xFFFFFFFF )) flags |=RTF_HOST ;
@@ -2659,7 +2660,7 @@ static int fib_route_seq_show(struct seq_file *seq, void *v) prefix =htonl (l->key);hlist_for_each_entry_rcu (fa, &l->leaf, fa_list) { -const struct fib_info *fi = fa->fa_info; +struct fib_info *fi = fa->fa_info;__be32 mask =inet_make_mask (KEYLENGTH - fa->fa_slen);unsigned int flags =fib_flag_trans (fa->fa_type, mask, fi);
@@ -2672,26 +2673,28 @@ static int fib_route_seq_show(struct seq_file *seq, void *v)seq_setwidth (seq,127 ); -if (fi) +if (fi) { +struct net_device *dev =fib_info_nh_dev (fi); +seq_printf (seq,"%s\t%08X\t%08X\t%04X\t%d\t%u\t" "%d\t%08X\t%d\t%u\t%u" , - fi->fib_dev ? fi->fib_dev->name :"*" , + dev ? dev->name :"*" , prefix, - fi->fib_nh->nh_gw, flags,0 ,0 , +fib_info_nh_gw (fi), flags,0 ,0 , fi->fib_priority, mask, (fi->fib_advmss ? fi->fib_advmss +40 :0 ), fi->fib_window, fi->fib_rtt >>3 ); -else + }else {seq_printf (seq,"*\t%08X\t%08X\t%04X\t%d\t%u\t" "%d\t%08X\t%d\t%u\t%u" , prefix,0 , flags,0 ,0 ,0 , mask,0 ,0 ,0 ); - + }seq_pad (seq,'\n' ); }
Signature · 1 line
2.11.0
[email protected]
maintainerRFC PATCH 15/18 net/ipv6: Use helpers to access fib6_nh data
In reply to [email protected]From: David Ahern <[email protected]>
Similar to ipv4, add helpers for accessing fib6_nh data and convert existing users.
--- include/net/ip6_fib.h | 11 ---------- include/net/ip6_route.h | 2 ++ include/net/nexthop.h | 40 +++++++++++++++++++++++++++++++++++ include/trace/events/fib6.h | 2 +- net/core/filter.c | 11 +++++++--- net/ipv6/route.c | 51 ++++++++++++++++++++++++++------------------- 6 files changed, 81 insertions(+), 36 deletions(-)
include/net/ip6_fib.h +0 -11
@@ -424,17 +424,6 @@ static inline void fib6_nh_release(struct fib6_nh *fib6_nh)lwtstate_put (fib6_nh->nh_lwtstate); } -static inline struct net_device *fib6_info_nh_dev (const struct fib6_info *f6i) -{ -return f6i->fib6_nh->nh_dev; -} - -static inline -struct lwtunnel_state *fib6_info_nh_lwt (const struct fib6_info *f6i) -{ -return f6i->fib6_nh->nh_lwtstate; -} -void inet6_rt_notify (int event,struct fib6_info *rt,struct nl_info *info,unsigned int flags);
include/net/ip6_route.h +2 -0
@@ -2,6 +2,8 @@ #ifndef _NET_IP6_ROUTE_H #define _NET_IP6_ROUTE_H +#include <net/nexthop.h> + struct route_info { __u8 type; __u8 length;
include/net/nexthop.h +40 -0
@@ -160,6 +160,46 @@ static inline __be32 fib_info_nh_gw(struct fib_info *fi)return fib_nh ? fib_nh->nh_gw :0 ; } +/* IPv6 variants +*/ +static inline struct fib6_nh *nexthop_fib6_nh (struct nexthop *nh) +{ +struct nh_info *nhi; + + nhi =rcu_dereference (nh->nh_info); +if (nhi->family ==AF_INET6 ) +return &nhi->fib6_nh; + +return NULL ; +} + +static inline struct fib6_nh *fib6_info_nh (struct fib6_info *f6i) +{ +return f6i->fib6_nh; +} + +static inline struct net_device *fib6_info_nh_dev (struct fib6_info *f6i) +{ +struct fib6_nh *fib6_nh =fib6_info_nh (f6i); + +return fib6_nh ? fib6_nh->nh_dev :NULL ; +} + +static inline struct in6_addr *fib6_info_nh_gw (struct fib6_info *f6i) +{ +struct fib6_nh *fib6_nh =fib6_info_nh (f6i); + +return fib6_nh ? &fib6_nh->nh_gw :NULL ; +} + +static inline +struct lwtunnel_state *fib6_info_nh_lwt (struct fib6_info *f6i) +{ +struct fib6_nh *fib6_nh =fib6_info_nh (f6i); + +return fib6_nh ? fib6_nh->nh_lwtstate :NULL ; +} +int fib_check_nexthop (struct fib_info *fi,struct fib_config *cfg,struct netlink_ext_ack *extack);
include/trace/events/fib6.h +1 -1
@@ -36,7 +36,7 @@ TRACE_EVENT(fib6_table_lookup, ),TP_fast_assign ( - struct fib6_nh *fib6_nh = f6i->fib6_nh; + struct fib6_nh *fib6_nh = fib6_info_nh(f6i);struct in6_addr *in6; __entry->tb_id = table->tb6_id;
net/core/filter.c +8 -3
@@ -4340,6 +4340,7 @@ static int bpf_ipv6_fib_lookup(struct net *net, struct bpf_fib_lookup *params, {struct in6_addr *src = (struct in6_addr *) params->ipv6_src;struct in6_addr *dst = (struct in6_addr *) params->ipv6_dst; +struct fib6_nh *fib6_nh;struct neighbour *neigh;struct net_device *dev;struct inet6_dev *idev;
@@ -4428,13 +4429,17 @@ static int bpf_ipv6_fib_lookup(struct net *net, struct bpf_fib_lookup *params,return BPF_FIB_LKUP_RET_FRAG_NEEDED ; } -if (f6i->fib6_nh->nh_lwtstate) + fib6_nh =fib6_info_nh (f6i); +if (!fib6_nh) +return BPF_FIB_LKUP_RET_NOT_FWDED ; + +if (fib6_nh->nh_lwtstate)return BPF_FIB_LKUP_RET_UNSUPP_LWT ;if (f6i->fib6_flags &RTF_GATEWAY ) - *dst = f6i->fib6_nh->nh_gw; + *dst = fib6_nh->nh_gw; - dev = f6i->fib6_nh->nh_dev; + dev = fib6_nh->nh_dev; params->rt_metric = f6i->fib6_metric;/* xdp and cls_bpf programs are run in RCU-bh so rcu_read_lock_bh is
net/ipv6/route.c +30 -21
171 lines not on this page · raw message
Signature · 1 line
2.11.0
[email protected]
maintainerPATCH 1/1 ip: Add support for nexthop objects
In reply to [email protected]From: David Ahern <[email protected]>
--- include/uapi/linux/nexthop.h | 56 ++++ include/uapi/linux/rtnetlink.h | 8 + ip/Makefile | 3 +- ip/ip.c | 3 +- ip/ip_common.h | 7 +- ip/ipmonitor.c | 6 + ip/ipnexthop.c | 652 +++++++++++++++++++++++++++++++++++++++++ ip/iproute.c | 19 +- 8 files changed, 747 insertions(+), 7 deletions(-) create mode 100644 include/uapi/linux/nexthop.h create mode 100644 ip/ipnexthop.c
include/uapi/linux/nexthop.h new file +56 -0
@@ -0,0 +1,56 @@ +#ifndef __LINUX_NEXTHOP_H +#define __LINUX_NEXTHOP_H + +#include <linux/types.h> + +struct nhmsg { +unsigned char nh_family; +unsigned char nh_scope;/* one of RT_SCOPE */ +unsigned char nh_protocol;/* Routing protocol that installed nh */ +unsigned char resvd; +unsigned int nh_flags;/* RTNH_F flags */ +}; + +struct nexthop_grp { +__u32 id; +__u32 weight; +}; + +enum { +NEXTHOP_GRP_TYPE_MPATH ,/* default type if not specified */ + __NEXTHOP_GRP_TYPE_MAX, +}; + +#define NEXTHOP_GRP_TYPE_MAX (__NEXTHOP_GRP_TYPE_MAX - 1) + + +/* NHA_ID 32-bit id for nexthop. id must be greater than 0. +* id == 0 means assign an unused id. +*/ +enum { +NHA_UNSPEC , +NHA_ID ,/* u32 */ +NHA_GROUP ,/* array of nexthop_grp */ +NHA_GROUP_TYPE ,/* u16 one of NEXTHOP_GRP_TYPE; +* default is NEXTHOP_GRP_TYPE_MPATH */ + +/* if NHA_GROUP attribute is added, no other attributes can be set */ + +NHA_BLACKHOLE ,/* flag; nexthop used to blackhole packets */ +NHA_OIF ,/* u32 */ +NHA_FLOW ,/* u32 */ + +NHA_TABLE_ID ,/* u32 - table id to validate gateway */ +NHA_GATEWAY ,/* be32 (IPv4) or in6_addr (IPv6) gw address */ + +/* Dump control attributes */ +NHA_GROUPS ,/* flag; only return nexthop groups in dump */ +NHA_MASTER ,/* u32; only return nexthops with given master dev */ + +NHA_SADDR ,/* return only: IPv4 or IPv6 source address */ + + __NHA_MAX, +}; + +#define NHA_MAX (__NHA_MAX - 1) +#endif
include/uapi/linux/rtnetlink.h +8 -0
@@ -157,6 +157,13 @@ enum { RTM_GETCHAIN,#define RTM_GETCHAIN RTM_GETCHAIN + RTM_NEWNEXTHOP = 104, +#define RTM_NEWNEXTHOP RTM_NEWNEXTHOP + RTM_DELNEXTHOP, +#define RTM_DELNEXTHOP RTM_DELNEXTHOP + RTM_GETNEXTHOP, +#define RTM_GETNEXTHOP RTM_GETNEXTHOP + __RTM_MAX,#define RTM_MAX (((__RTM_MAX + 3) & ~3) - 1) };
@@ -342,6 +349,7 @@ enum rtattr_type_t {RTA_IP_PROTO ,RTA_SPORT ,RTA_DPORT , +RTA_NH_ID , __RTA_MAX };
ip/Makefile +2 -1
@@ -10,7 +10,8 @@ IPOBJ=ip.o ipaddress.o ipaddrlabel.o iproute.o iprule.o ipnetns.o \ link_iptnl.o link_gre6.o iplink_bond.o iplink_bond_slave.o iplink_hsr.o \ iplink_bridge.o iplink_bridge_slave.o ipfou.o iplink_ipvlan.o \ iplink_geneve.o iplink_vrf.o iproute_lwtunnel.o ipmacsec.o ipila.o \ - ipvrf.o iplink_xstats.o ipseg6.o iplink_netdevsim.o iplink_rmnet.o + ipvrf.o iplink_xstats.o ipseg6.o iplink_netdevsim.o iplink_rmnet.o \ + ipnexthop.o RTMONOBJ=rtmon.o
ip/ip.c +2 -1
@@ -51,7 +51,7 @@ static void usage(void)"where OBJECT := { link | address | addrlabel | route | rule | neigh | ntable |\n" " tunnel | tuntap | maddress | mroute | mrule | monitor | xfrm |\n" " netns | l2tp | fou | macsec | tcp_metrics | token | netconf | ila |\n" -" vrf | sr }\n" +" vrf | sr | nexthop }\n" " OPTIONS := { -V[ersion] | -s[tatistics] | -d[etails] | -r[esolve] |\n" " -h[uman-readable] | -iec | -j[son] | -p[retty] |\n" " -f[amily] { inet | inet6 | ipx | dnet | mpls | bridge | link } |\n"
@@ -101,6 +101,7 @@ static const struct cmd { { "netconf", do_ipnetconf }, { "vrf", do_ipvrf}, { "sr", do_seg6 }, + { "nexthop", do_ipnh }, { "help", do_help }, { 0 } };
ip/ip_common.h +6 -1
@@ -56,6 +56,8 @@ int print_rule(const struct sockaddr_nl *who,int print_netconf (const struct sockaddr_nl *who,struct rtnl_ctrl_data *ctrl,struct nlmsghdr *n,void *arg); +int print_nexthop (const struct sockaddr_nl *who, +struct nlmsghdr *n,void *arg);void netns_map_init (void );void netns_nsid_socket_init (void ); int print_nsid(const struct sockaddr_nl *who,
@@ -90,6 +92,7 @@ int do_ipvrf(int argc, char **argv);void vrf_reset (void );int netns_identify_pid (const char *pidstr,char *name,int len);int do_seg6 (int argc,char **argv); +int do_ipnh (int argc,char **argv);int iplink_get (unsigned int flags,char *name,__u32 filt_mask);int iplink_ifla_xstats (int argc,char **argv);
@@ -165,5 +168,7 @@ int name_is_vrf(const char *name);#endif void print_num (FILE *fp,unsigned int width,uint64_t count); - +void print_rta_flow (FILE *fp,const struct rtattr *rta); +void print_rt_flags (FILE *fp,unsigned int flags); +void print_rta_if (FILE *fp,const struct rtattr *rta,const char *prefix);#endif /* _IP_COMMON_H_ */
ip/ipmonitor.c +6 -0
@@ -84,6 +84,12 @@ static int accept_msg(const struct sockaddr_nl *who, } } +case RTM_NEWNEXTHOP : +case RTM_DELNEXTHOP : +print_headers (fp,"[NEXTHOP]" , ctrl); +print_nexthop (who, n, arg); +return 0 ; +case RTM_NEWLINK :case RTM_DELLINK :ll_remember_index (who, n,NULL );
ip/ipnexthop.c new file +652 -0
652 lines not on this page · raw message
ip/iproute.c +15 -4
@@ -349,7 +349,7 @@ static void print_rtax_features(FILE *fp, unsigned int features) "features", "0x%x ", of); } -static void print_rt_flags (FILE *fp,unsigned int flags) +void print_rt_flags (FILE *fp,unsigned int flags) {open_json_array (PRINT_JSON ,is_json_context () ?"flags" :"" );
@@ -394,8 +394,8 @@ static void print_rt_pref(FILE *fp, unsigned int pref) } } -static void print_rta_if (FILE *fp,const struct rtattr *rta, -const char *prefix) +void print_rta_if (FILE *fp,const struct rtattr *rta, +const char *prefix) {const char *ifname =ll_index_to_name (rta_getattr_u32 (rta));
@@ -492,7 +492,7 @@ static void print_rta_cacheinfo(FILE *fp, const struct rta_cacheinfo *ci) } } -static void print_rta_flow (FILE *fp,const struct rtattr *rta) +void print_rta_flow (FILE *fp,const struct rtattr *rta) {__u32 to =rta_getattr_u32 (rta);__u32 from = to >>16 ;
@@ -823,6 +823,10 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) rtnl_dsfield_n2a(r->rtm_tos, b1, sizeof(b1))); } +if (tb[RTA_NH_ID ]) +print_uint (PRINT_ANY ,"nhid" ,"nhid %u " , +rta_getattr_u32 (tb[RTA_NH_ID ])); +if (tb[RTA_GATEWAY ] && filter.rvia.bitlen != host_len)print_rta_gateway (fp, r, tb[RTA_GATEWAY ]);
@@ -1351,6 +1355,13 @@ static int iproute_modify(int cmd, unsigned int flags, int argc, char **argv) }else if (strcmp (*argv,"nexthop" ) ==0 ) { nhs_ok =1 ;break ; + }else if (!strcmp (*argv,"nhid" )) { +__u32 id; + +NEXT_ARG (); +if (get_u32 (&id, *argv,0 )) +invarg ("\"id\" value is invalid\n" , *argv); +addattr32 (&req.n,sizeof (req),RTA_NH_ID , id); }else if (matches (*argv,"protocol" ) ==0 ) {__u32 prot;
Signature · 1 line
2.11.0
[email protected]
maintainerRFC PATCH 14/18 net/ipv4: Allow routes to use nexthop objects
In reply to [email protected]From: David Ahern <[email protected]>
Add new RTA attribute to allow a user to specify a nexthop id to use with a route instead of the current nexthop specification.
--- include/net/ip_fib.h | 1 + include/uapi/linux/rtnetlink.h | 1 + net/ipv4/fib_frontend.c | 7 +++ net/ipv4/fib_semantics.c | 139 ++++++++++++++++++++++++++++++----------- net/ipv4/fib_trie.c | 33 +++++++--- 5 files changed, 136 insertions(+), 45 deletions(-)
include/net/ip_fib.h +1 -0
@@ -40,6 +40,7 @@ struct fib_config {u32 fc_flags;u32 fc_priority;__be32 fc_prefsrc; +u32 fc_nh_id;struct nlattr *fc_mx;struct rtnexthop *fc_mp;int fc_mx_len;
include/uapi/linux/rtnetlink.h +1 -0
@@ -349,6 +349,7 @@ enum rtattr_type_t {RTA_IP_PROTO ,RTA_SPORT ,RTA_DPORT , +RTA_NH_ID , __RTA_MAX };
net/ipv4/fib_frontend.c +7 -0
@@ -322,6 +322,9 @@ static bool fib_info_nh_uses_dev(struct fib_info *fi,bool dev_match = false;int ret; +if (fi->nh) +return nexthop_uses_dev (fi->nh, dev); +#ifdef CONFIG_IP_ROUTE_MULTIPATH for (ret =0 ; ret < fi->fib_nhs; ret++) {struct fib_nh *nh = &fi->fib_nh[ret];
@@ -663,6 +666,7 @@ const struct nla_policy rtm_ipv4_policy[RTA_MAX + 1] = { [RTA_IP_PROTO] = { .type = NLA_U8 }, [RTA_SPORT] = { .type = NLA_U16 }, [RTA_DPORT] = { .type = NLA_U16 }, + [RTA_NH_ID] = { .type = NLA_U32 }, }; static int rtm_to_fib_config(struct net *net, struct sk_buff *skb,
@@ -746,6 +750,9 @@ static int rtm_to_fib_config(struct net *net, struct sk_buff *skb,if (err <0 ) goto errout;break ; +case RTA_NH_ID : + cfg->fc_nh_id =nla_get_u32 (attr); +break ; } }
net/ipv4/fib_semantics.c +103 -36
284 lines not on this page · raw message
net/ipv4/fib_trie.c +24 -9
@@ -1445,7 +1445,7 @@ int fib_table_lookup(struct fib_table *tb, const struct flowi4 *flp,/* Step 3: Process the leaf, if that fails fall back to backtracing */ hlist_for_each_entry_rcu (fa, &n->leaf, fa_list) {struct fib_info *fi = fa->fa_info; -int nhsel, err; +int nhsel, err, nhmax;if ((BITS_PER_LONG >KEYLENGTH ) || (fa->fa_slen <KEYLENGTH )) {if (index >= (1ul << fa->fa_slen))
@@ -1460,6 +1460,7 @@ int fib_table_lookup(struct fib_table *tb, const struct flowi4 *flp,fib_alias_accessed (fa); err = fib_props[fa->fa_type].error;if (unlikely (err <0 )) { +out_reject:#ifdef CONFIG_IP_FIB_TRIE_STATS this_cpu_inc (stats->semantic_match_passed);#endif
@@ -1468,17 +1469,31 @@ int fib_table_lookup(struct fib_table *tb, const struct flowi4 *flp, }if (fi->fib_flags &RTNH_F_DEAD )continue ; -for (nhsel =0 ; nhsel < fi->fib_nhs; nhsel++) { -struct fib_nh *nh = &fi->fib_nh[nhsel]; -struct in_device *in_dev =__in_dev_get_rcu (nh->nh_dev); + +if (fi->nh) { +if (nexthop_is_blackhole (fi->nh)) { + err = fib_props[RTN_BLACKHOLE ].error; + goto out_reject; + } + nhmax =nexthop_num_path (fi->nh); + }else { + nhmax = fi->fib_nhs; + } +for (nhsel =0 ; nhsel < nhmax; nhsel++) { +struct fib_nh *nh =fib_info_nh (fi, nhsel); +struct in_device *in_dev;if (nh->nh_flags &RTNH_F_DEAD )continue ; -if (in_dev && -IN_DEV_IGNORE_ROUTES_WITH_LINKDOWN (in_dev) && - nh->nh_flags &RTNH_F_LINKDOWN && - !(fib_flags &FIB_LOOKUP_IGNORE_LINKSTATE )) -continue ; + +if (!fi->nh) { + in_dev =__in_dev_get_rcu (nh->nh_dev); +if (in_dev && +IN_DEV_IGNORE_ROUTES_WITH_LINKDOWN (in_dev) && + nh->nh_flags &RTNH_F_LINKDOWN && + !(fib_flags &FIB_LOOKUP_IGNORE_LINKSTATE )) +continue ; + }if (!(flp->flowi4_flags &FLOWI_FLAG_SKIP_NH_OIF )) {if (flp->flowi4_oif && flp->flowi4_oif != nh->nh_oif)
Signature · 1 line
2.11.0
Re: [PATCH iproute2-next] ip: Add support for nexthop objects
In reply to [email protected]Quoted 24 lines · On Fri, 31 Aug 2018 17:49:54 -0700 [email protected] wrote:
From: David Ahern <[email protected]>
Signed-off-by David Ahern <[email protected]>--- include/uapi/linux/nexthop.h | 56 ++++ include/uapi/linux/rtnetlink.h | 8 + ip/Makefile | 3 +- ip/ip.c | 3 +- ip/ip_common.h | 7 +- ip/ipmonitor.c | 6 + ip/ipnexthop.c | 652 +++++++++++++++++++++++++++++++++++++++++ ip/iproute.c | 19 +- 8 files changed, 747 insertions(+), 7 deletions(-) create mode 100644 include/uapi/linux/nexthop.h create mode 100644 ip/ipnexthop.cinclude/uapi/linux/nexthop.h new file +2
-0@@ -0,0 +1,56 @@ +#ifndef __LINUX_NEXTHOP_H +#define __LINUX_NEXTHOP_H
include/uapi/linux/nexthop.h line 12
Quoted 10 lines
include/uapi/linux/nexthop.h new file +10
-0+ +#include <linux/types.h> + +struct nhmsg { +unsigned char nh_family; +unsigned char nh_scope;/* one of RT_SCOPE */ +unsigned char nh_protocol;/* Routing protocol that installed nh */ +unsigned char resvd; +unsigned int nh_flags;/* RTNH_F flags */ +};
Why not use __u8 and __u32 for these?
Quoted 6 lines
include/uapi/linux/nexthop.h new file +6
-0+struct nexthop_grp { +__u32 id; +__u32 weight; +}; + +enum {
include/uapi/linux/nexthop.h line 29
Quoted 10 lines
include/uapi/linux/nexthop.h new file +10
-0+NEXTHOP_GRP_TYPE_MPATH ,/* default type if not specified */ + __NEXTHOP_GRP_TYPE_MAX, +}; + +#define NEXTHOP_GRP_TYPE_MAX (__NEXTHOP_GRP_TYPE_MAX - 1) + + +/* NHA_ID 32-bit id for nexthop. id must be greater than 0. +* id == 0 means assign an unused id. +*/
Don't use dave's preferred comment style in this file. The reset of the file uses standard comments.
...
Quoted 60 lines
ip/ip_common.h +6
-1@@ -56,6 +56,8 @@ int print_rule(const struct sockaddr_nl *who,int print_netconf (const struct sockaddr_nl *who,struct rtnl_ctrl_data *ctrl,struct nlmsghdr *n,void *arg); +int print_nexthop (const struct sockaddr_nl *who, +struct nlmsghdr *n,void *arg);void netns_map_init (void );void netns_nsid_socket_init (void ); int print_nsid(const struct sockaddr_nl *who,@@ -90,6 +92,7 @@ int do_ipvrf(int argc, char **argv);void vrf_reset (void );int netns_identify_pid (const char *pidstr,char *name,int len);int do_seg6 (int argc,char **argv); +int do_ipnh (int argc,char **argv);int iplink_get (unsigned int flags,char *name,__u32 filt_mask);int iplink_ifla_xstats (int argc,char **argv);@@ -165,5 +168,7 @@ int name_is_vrf(const char *name);#endif void print_num (FILE *fp,unsigned int width,uint64_t count); - +void print_rta_flow (FILE *fp,const struct rtattr *rta); +void print_rt_flags (FILE *fp,unsigned int flags); +void print_rta_if (FILE *fp,const struct rtattr *rta,const char *prefix);#endif /* _IP_COMMON_H_ */ ip/ipmonitor.c +6
-0@@ -84,6 +84,12 @@ static int accept_msg(const struct sockaddr_nl *who, } } +case RTM_NEWNEXTHOP : +case RTM_DELNEXTHOP : +print_headers (fp,"[NEXTHOP]" , ctrl); +print_nexthop (who, n, arg); +return 0 ; +case RTM_NEWLINK :case RTM_DELLINK :ll_remember_index (who, n,NULL );ip/ipnexthop.c new file +6
-0@@ -0,0 +1,652 @@ +/* +* ip nexthop +* +* Copyright (C) 2017 Cumulus Networks +* Copyright (c) 2017 David Ahern <[email protected]> +*
ip/ipnexthop.c line 16
Quoted 10 lines
ip/ipnexthop.c new file +10
-0+* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/
Please use SPDX and not GPL boilerplate in new files.
ip/ipnexthop.c line 27
Quoted 10 lines
ip/ipnexthop.c new file +10
-0+#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <netinet/ip.h> +#include <errno.h> +#include <linux/nexthop.h> +#include <libmnl/libmnl.h>
Is this code really using libmnl?
Quoted 194 lines
ip/ipnexthop.c new file +194
-0+#include <rt_names.h> + +#include "utils.h" +#include "ip_common.h" + +static struct +{ +unsigned int flushed; +unsigned int groups; +char *flushb; +int flushp; +int flushe; +} filter; + +enum { +IPNH_LIST , +IPNH_FLUSH , +}; + +#define RTM_NHA (h) ((struct rtattr *)(((char *)(h)) + \ + NLMSG_ALIGN(sizeof(struct nhmsg)))) + +static void usage (void ) __attribute__((noreturn)); + +static void usage (void ) +{ +fprintf (stderr,"Usage: ip nexthop { list | flush } SELECTOR\n" ); +fprintf (stderr," ip nexthop get [ id ID ]\n" ); +fprintf (stderr," ip nexthop { add | del | change | replace } NH\n" ); +fprintf (stderr,"SELECTOR := [ id ID ] [ dev DEV ] [ table TABLE ] [ vrf NAME ]\n" ); +fprintf (stderr,"NH := [ encap ENCAPTYPE ENCAPHDR ] [ via [ FAMILY ] ADDRESS ]\n" ); +fprintf (stderr," [ id ID ] [ dev STRING ] [ weight NUMBER ]\n" ); +fprintf (stderr," [ table TABLE ] [ vrf VRF ] NHFLAGS\n" ); +fprintf (stderr,"NHFLAGS := [ onlink | pervasive ]\n" ); +fprintf (stderr,"ENCAPTYPE := [ mpls | ip | ip6 ]\n" ); +fprintf (stderr,"ENCAPHDR := [ MPLSLABEL ]\n" ); +exit (-1 ); +} + +static int delete_nexthop (__u32 id) +{ +struct { +struct nlmsghdr n; +struct nhmsg nhm; +char buf[64 ]; + } req = { + .n.nlmsg_len =NLMSG_LENGTH (sizeof (struct nhmsg )), + .n.nlmsg_flags =NLM_F_REQUEST , + .n.nlmsg_type =RTM_DELNEXTHOP , + .nhm.nh_family =AF_UNSPEC , + }; + + req.n.nlmsg_seq = ++rth.seq; + +addattr32 (&req.n,sizeof (req),NHA_ID , id); + +if (rtnl_talk (&rth, &req.n,NULL ) <0 ) +return -1 ; + + filter.flushed++; +return 0 ; +} + +struct nh_entry { +__u32 id; +unsigned int group; +struct nh_entry *next; +}; + +struct nh_entry *first, *last; + +static int flush_nexthop (const struct sockaddr_nl *who, +struct nlmsghdr *nlh,void *arg) +{ +struct nhmsg *nhm =NLMSG_DATA (nlh); +struct rtattr *tb[NHA_MAX +1 ]; +struct nh_entry *nh; +__u32 id =0 ; +int len; + + len = nlh->nlmsg_len -NLMSG_SPACE (sizeof (*nhm)); +if (len <0 ) { +fprintf (stderr,"BUG: wrong nlmsg len %d\n" , len); +return -1 ; + } + +parse_rtattr (tb,NHA_MAX ,RTM_NHA (nhm), len); +if (tb[NHA_ID ]) + id =rta_getattr_u32 (tb[NHA_ID ]); + +if (!id) +return 0 ; + + nh =malloc (sizeof (*nh)); +if (!nh) +return -1 ; + + nh->id = id; + nh->group = tb[NHA_GROUP ] !=NULL ; + nh->next =NULL ; +if (!first) + first = nh; +else + last->next = nh; + + last = nh; +return 0 ; +} + +static int ipnh_flush (void *req,__u32 len,unsigned int all) +{ +struct nh_entry *nh; + +if (send (rth.fd, req, len,0 ) <0 ) { +perror ("Cannot send dump request" ); +return -2 ; + } + +if (rtnl_dump_filter (&rth, flush_nexthop, stdout) <0 ) { +fprintf (stderr,"Dump terminated\n" ); +return -2 ; + } + +/* if deleting all, then remove groups first */ +if (all) { + nh = first; +while (nh) { +if (nh->group) +delete_nexthop (nh->id); + nh = nh->next; + } + } + + nh = first; +while (nh) { +if (!all || !nh->group) +delete_nexthop (nh->id); + nh = nh->next; + } + +if (!filter.flushed) +printf ("Nothing to flush\n" ); +else +printf ("Flushed %d nexthops\n" , filter.flushed); + +return 0 ; +} + +static char *nh_group_type_to_str (__u16 group_type,char *buf,size_t len) +{ +static const char *typestr[NEXTHOP_GRP_TYPE_MAX +1 ] = { +"multipath" ,/* NEXTHOP_GRP_TYPE_MPATH */ + }; + +if (group_type <ARRAY_SIZE (typestr)) +snprintf (buf, len-1 ,"%s" , typestr[group_type]); +else +snprintf (buf, len-1 ,"<%u>" , group_type); + + buf[len-1 ] ='\0' ; + +return buf; +} + +static void print_nh_group (FILE *fp,const struct rtattr *grps_attr, +const struct rtattr *gtype) +{ +struct nexthop_grp *nhg =RTA_DATA (grps_attr); +int num =RTA_PAYLOAD (grps_attr) /sizeof (*nhg); +__u16 group_type =NEXTHOP_GRP_TYPE_MPATH ; +int i; + +SPRINT_BUF (b1); + +if (!num || num *sizeof (*nhg) !=RTA_PAYLOAD (grps_attr)) { +fprintf (fp,"<invalid nexthop group>" ); +return ; + } + +if (gtype) + group_type =rta_getattr_u16 (gtype); + +if (is_json_context ()) { +open_json_array (PRINT_JSON ,"group" ); +for (i =0 ; i < num; ++i) { +open_json_object (NULL ); +print_uint (PRINT_ANY ,"id" ,"id %u " , nhg[i].id); +print_uint (PRINT_ANY ,"weight" ,"weight %u " , nhg[i].weight); +close_json_object (); + } +close_json_array (PRINT_JSON ,NULL ); +print_string (PRINT_ANY ,"type" ,"type %s " , +nh_group_type_to_str (group_type, b1,sizeof (b1))); + }else {
ip/ipnexthop.c line 231
Quoted 10 lines
ip/ipnexthop.c new file +10
-0+fprintf (fp,"group " ); +for (i =0 ; i < num; ++i) { +if (i) +fprintf (fp,"/" ); +fprintf (fp,"%u" , nhg[i].id); +if (num >1 && nhg[i].weight >1 ) +fprintf (fp,",%u" , nhg[i].weight); + } + } +}
I think this could be done by using json_print cleverly rather than having to use is_json_contex(). That would avoid repeating code.
You are only decoding group type in the json version, why not both?
Re: [PATCH RFC net-next 18/18] net/ipv4: Optimization for fib_info lookup
In reply to [email protected]net/ipv4/fib_semantics.c static inline unsigned int fib_devindex_hashfn(unsigned int val) · line 324
Quoted 6 lines · On Fri, 31 Aug 2018 17:49:53 -0700 [email protected] wrote:
net/ipv4/fib_semantics.c +6
-0+static inline unsigned int fib_info_hashfn_cfg (const struct fib_config *cfg) +{ +unsigned int mask = (fib_info_hash_size -1 ); +unsigned int val =0 ; + + val ^= (cfg->fc_protocol <<8 ) | cfg->fc_scope;
Why do assignment to 0 than do initial xor?
Why not instead just do assignment in the first statement which would be clearer.
David Miller
maintainerFrom: [email protected]
Date: Fri, 31 Aug 2018 17:49:35 -0700
Quoted 11 lines
Examples
1. Single path$ ip nexthop add id 1 via 10.99.1.2 dev veth1 $ ip route add 10.1.1.0/24 nhid 1$ ip next ls id 1 via 10.99.1.2 src 10.99.1.1 dev veth1 scope link$ ip ro ls 10.1.1.0/24 nhid 1 scope link ...
First of all, this whole idea is awesome! But, you knew that already. :)
However, I worry what happesn in a mixed environment where we have routing daemons and tools inserting nexthop based routes, and some doing things the old way using and expecting inline nexthop information in the routes.
That mixed environment situation has to function correctly. Older apps have to see the per-route nexthop info in the format and layout they expect (gw/dev pairs). They cannot be expected to just studdenly understand the nexthop ID etc.
Otherwise the concept and ideas are fine, so as long as you can resolve the mixed environment situation I fully support this work and look forward to it being in a state where I can integrate it :-)
Re: [PATCH RFC net-next 18/18] net/ipv4: Optimization for fib_info lookup
In reply to Stephen HemmingerQuoted 13 lines · Stephen Hemminger
net/ipv4/fib_semantics.c static inline unsigned int fib_devindex_hashfn(unsigned int val) · line 324
Quoted 6 lines · On Fri, 31 Aug 2018 17:49:53 -0700 [email protected] wrote:
net/ipv4/fib_semantics.c +6
-0+static inline unsigned int fib_info_hashfn_cfg (const struct fib_config *cfg) +{ +unsigned int mask = (fib_info_hash_size -1 ); +unsigned int val =0 ; + + val ^= (cfg->fc_protocol <<8 ) | cfg->fc_scope;Why do assignment to 0 than do initial xor?
Why not instead just do assignment in the first statement which would be clearer.
Side effect of copy-paste-adjust of the original. Will fix for the next rfc (really need to not have 2 versions of the hashfn; need to think through it).
Re: [PATCH iproute2-next] ip: Add support for nexthop objects
In reply to Stephen HemmingerQuoted 12 lines · Stephen Hemminger
Quoted 12 lines
include/uapi/linux/nexthop.h new file +6
-0@@ -0,0 +1,56 @@ +#ifndef __LINUX_NEXTHOP_H +#define __LINUX_NEXTHOP_H + +#include <linux/types.h> + +struct nhmsg {
Quoted 8 lines
include/uapi/linux/nexthop.h line 12
Quoted 6 lines
include/uapi/linux/nexthop.h new file +6
-0+unsigned char nh_family; +unsigned char nh_scope;/* one of RT_SCOPE */ +unsigned char nh_protocol;/* Routing protocol that installed nh */ +unsigned char resvd; +unsigned int nh_flags;/* RTNH_F flags */ +};Why not use
__u8and__u32for these?
I want consistency with rtmsg on which nhmsg is based and has many parallels.
Quoted 12 lines
Quoted 12 lines
include/uapi/linux/nexthop.h new file +11
-0+struct nexthop_grp { +__u32 id; +__u32 weight; +}; + +enum { +NEXTHOP_GRP_TYPE_MPATH ,/* default type if not specified */ + __NEXTHOP_GRP_TYPE_MAX, +}; + +#define NEXTHOP_GRP_TYPE_MAX (__NEXTHOP_GRP_TYPE_MAX - 1)
Quoted 8 lines
include/uapi/linux/nexthop.h line 29
Quoted 5 lines
include/uapi/linux/nexthop.h new file +5
-0+ + +/* NHA_ID 32-bit id for nexthop. id must be greater than 0. +* id == 0 means assign an unused id. +*/ Don't use dave's preferred comment style in this file. The reset of the file uses standard comments.
The file will eventually come from the kernel via header sync, so I have to stick to whatever style is appropriate for the uapi files.
Quoted 17 lines
Quoted 17 lines
ip/ipnexthop.c new file +11
-0@@ -0,0 +1,652 @@ +/* +* ip nexthop +* +* Copyright (C) 2017 Cumulus Networks +* Copyright (c) 2017 David Ahern <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +*
Quoted 8 lines
ip/ipnexthop.c line 16
Quoted 6 lines
ip/ipnexthop.c new file +5
-0+* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ Please use SPDX and not GPL boilerplate in new files.
yes, the file pre-dates SPDX. Need to do the same with the kernel side files.
Quoted 13 lines
ip/ipnexthop.c line 27
Quoted 11 lines
ip/ipnexthop.c new file +10
-0+#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <string.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <netinet/ip.h> +#include <errno.h> +#include <linux/nexthop.h> +#include <libmnl/libmnl.h> Is this code really using libmnl?
no. need to fix. The iproute2 patch was only added for the RFC so people could try out the UAPI which is the point of the RFC.
Quoted 34 lines
Quoted 20 lines
ip/ipnexthop.c new file +20
-0+if (!num || num *sizeof (*nhg) !=RTA_PAYLOAD (grps_attr)) { +fprintf (fp,"<invalid nexthop group>" ); +return ; + } + +if (gtype) + group_type =rta_getattr_u16 (gtype); + +if (is_json_context ()) { +open_json_array (PRINT_JSON ,"group" ); +for (i =0 ; i < num; ++i) { +open_json_object (NULL ); +print_uint (PRINT_ANY ,"id" ,"id %u " , nhg[i].id); +print_uint (PRINT_ANY ,"weight" ,"weight %u " , nhg[i].weight); +close_json_object (); + } +close_json_array (PRINT_JSON ,NULL ); +print_string (PRINT_ANY ,"type" ,"type %s " , +nh_group_type_to_str (group_type, b1,sizeof (b1))); + }else {ip/ipnexthop.c line 231
Quoted 10 lines
ip/ipnexthop.c new file +10
-0+fprintf (fp,"group " ); +for (i =0 ; i < num; ++i) { +if (i) +fprintf (fp,"/" ); +fprintf (fp,"%u" , nhg[i].id); +if (num >1 && nhg[i].weight >1 ) +fprintf (fp,",%u" , nhg[i].weight); + } + } +}I think this could be done by using
json_printcleverly rather than having to useis_json_contex(). That would avoid repeating code.
Quoted 1 line
You are only decoding group type in the json version, why not both?
oversight. group type was a recent change.
Quoted 8 lines · David Miller
From: [email protected]
Date: Fri, 31 Aug 2018 17:49:35 -0700Quoted 5 lines
Examples
1. Single path$ ip nexthop add id 1 via 10.99.1.2 dev veth1 $ ip route add 10.1.1.0/24 nhid 1
Quoted 8 lines
Quoted 6 lines
$ ip next ls id 1 via 10.99.1.2 src 10.99.1.1 dev veth1 scope link$ ip ro ls 10.1.1.0/24 nhid 1 scope link ...First of all, this whole idea is awesome! But, you knew that already. :)
:-)
Quoted 5 lines
However, I worry what happesn in a mixed environment where we have routing daemons and tools inserting nexthop based routes, and some doing things the old way using and expecting inline nexthop information in the routes.
Quoted 9 lines
That mixed environment situation has to function correctly. Older apps have to see the per-route nexthop info in the format and layout they expect (gw/dev pairs). They cannot be expected to just studdenly understand the nexthop ID etc.
Otherwise the concept and ideas are fine, so as long as you can resolve the mixed environment situation I fully support this work and look forward to it being in a state where I can integrate it :-)
RTA_NH_ID is on par with other new attributes (RTA_ENCAP for example) -- userspace apps get a route attribute and have no idea what it means until support is added (e.g., it took more than 2 years for libnl to get support for RTA_ENCAP). I take your comment to mean you prefer this new attribute to be treated differently -- assume apps are clueless unless they indicate otherwise. Given the number of ioctl based apps that might be the better option for this case.
I can add an attribute for apps to specify 'hey, I understand nexthops' on dump and get requests (per-app flag), and then I can add a sysctl that controls whether the nexthop spec is included. The sysctl would be for notifications and a global option for dumps/gets. Users who know their OS is safe for the short form can set it and get the benefit of smaller messages. While the biggest win here is pushing routes to the kernel faster, there is also a gain with less data from the kernel in route dumps and notifications, especially with multipath environments.
Hello!
Quoted 12 lines · David Ahern
Quoted 11 lines · David Miller
From: [email protected]
Date: Fri, 31 Aug 2018 17:49:35 -0700Quoted 8 lines
Examples
1. Single path$ ip nexthop add id 1 via 10.99.1.2 dev veth1 $ ip route add 10.1.1.0/24 nhid 1$ ip next ls id 1 via 10.99.1.2 src 10.99.1.1 dev veth1 scope link
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
$ ip ro ls 10.1.1.0/24 nhid 1 scope link ...First of all, this whole idea is awesome! But, you knew that already. :)
:-)
Joining the wow's. This seems that it may save valuable kernel table synchronization time in BIRD.
Quoted 22 lines
Quoted 4 lines
However, I worry what happesn in a mixed environment where we have routing daemons and tools inserting nexthop based routes, and some doing things the old way using and expecting inline nexthop information in the routes.
Quoted 9 lines
That mixed environment situation has to function correctly. Older apps have to see the per-route nexthop info in the format and layout they expect (gw/dev pairs). They cannot be expected to just studdenly understand the nexthop ID etc.
Otherwise the concept and ideas are fine, so as long as you can resolve the mixed environment situation I fully support this work and look forward to it being in a state where I can integrate it :-)
RTA_NH_IDis on par with other new attriwo parallel commands doing butes (RTA_ENCAPfor example) -- userspace apps get a route attribute and have no idea what it means
until support is added (e.g., it took more than 2 years for libnl to get
support forRTA_ENCAP). I take your comment to mean you prefer this new
attribute to be treated differently -- assume apps are clueless unless
they indicate otherwise. Given the number of ioctl based apps that might
be the better option for this case.
Quoted 8 lines
I can add an attribute for apps to specify 'hey, I understand nexthops' on dump and get requests (per-app flag), and then I can add a sysctl that controls whether the nexthop spec is included. The sysctl would be for notifications and a global option for dumps/gets. Users who know their OS is safe for the short form can set it and get the benefit of smaller messages. While the biggest win here is pushing routes to the kernel faster, there is also a gain with less data from the kernel in route dumps and notifications, especially with multipath environments.
Personally, I use mixed environments where iproute2 version doesn't match kernel version most of the time and I'd like to use both new iproute2 and old BIRD or whatever at the same machine. For myself, not knowing exactly how to implement it, the best way how to interact with the nexthop layer, would be a flag set while opening the netlink socket, or maybe another RTMGRP_* like RTMGRP_IPV4_NEXTHOP and RTMGRP_IPV6_NEXTHOP. Who asks for these, they will get nexthop-ed notifications; who asks for RTMGRP_IPV[46]_ROUTE, gets them the old way. Anyway, I may live quite well with a system-wide knob in sysctl setting this.
I'd also like to have documented that the multipath is forbidden to be recursive and only one level of depth is allowed. It seems OK for me on first sight how it works, just please write it down for future generations for them to say "it is OK to fail badly when kernel sends us a recursive nexthop group definition"
At last, what I consider important, is a namespace separation by nh_protocol. Let's suppose that there is a routing daemon maintaining some routes and also an operator who has her own routes. Then the operator does a stupid typo while running ip nexthop replace and instead of replacing her own nexthop, she replaces the routing daemon's nexthop.
I suggest that the key in the nexthop table should include nh_protocol together with nh_id to split these records. It also seems that there is only one nexthop table; is this OK wrt. multiple VRF's and so? There is also the nh_table parameter in struct nh_config which only validates the gateway in a given table. If I look correctly, this nexthop may be then used anywhere which is insane from my point of view.
BTW, let's consider this:
# ip nexthop add id 1 via 10.99.0.1 dev veth1 # ip nexthop add id 2 via 10.99.0.2 dev veth1 # ip nexthop add id 3 via 10.99.0.3 dev veth1
and then both commands at the same time:
# ip nexthop replace id 1 group 2/3 # ip nexthop replace id 2 group 1/3
Is this synchronized and one of these commands fails? (I'm not familiar with the code such deeply, sorry if I'm asking for something obvious.)
Thank you for considering my objections and sorry for reviving such an old thread.
Maria
BIRD developer
Quoted 57 lines · Jan Maria Matejka
Hello!
Quoted 12 lines · David Ahern
Quoted 11 lines · David Miller
From: [email protected]
Date: Fri, 31 Aug 2018 17:49:35 -0700Quoted 8 lines
Examples
1. Single path$ ip nexthop add id 1 via 10.99.1.2 dev veth1 $ ip route add 10.1.1.0/24 nhid 1$ ip next ls id 1 via 10.99.1.2 src 10.99.1.1 dev veth1 scope linkQuoted 7 lines
Quoted 5 lines
Quoted 3 lines
$ ip ro ls 10.1.1.0/24 nhid 1 scope link ...First of all, this whole idea is awesome! But, you knew that already. :)
:-)
Joining the wow's. This seems that it may save valuable kernel table synchronization time in BIRD.
Quoted 22 lines
Quoted 4 lines
However, I worry what happesn in a mixed environment where we have routing daemons and tools inserting nexthop based routes, and some doing things the old way using and expecting inline nexthop information in the routes.
Quoted 9 lines
That mixed environment situation has to function correctly. Older apps have to see the per-route nexthop info in the format and layout they expect (gw/dev pairs). They cannot be expected to just studdenly understand the nexthop ID etc.
Otherwise the concept and ideas are fine, so as long as you can resolve the mixed environment situation I fully support this work and look forward to it being in a state where I can integrate it :-)
RTA_NH_IDis on par with other new attriwo parallel commands doing butes (RTA_ENCAPfor example) -- userspace apps get a route attribute and have no idea what it means
until support is added (e.g., it took more than 2 years for libnl to get
support forRTA_ENCAP). I take your comment to mean you prefer this new
attribute to be treated differently -- assume apps are clueless unless
they indicate otherwise. Given the number of ioctl based apps that might
be the better option for this case.Quoted 8 lines
I can add an attribute for apps to specify 'hey, I understand nexthops' on dump and get requests (per-app flag), and then I can add a sysctl that controls whether the nexthop spec is included. The sysctl would be for notifications and a global option for dumps/gets. Users who know their OS is safe for the short form can set it and get the benefit of smaller messages. While the biggest win here is pushing routes to the kernel faster, there is also a gain with less data from the kernel in route dumps and notifications, especially with multipath environments.
Quoted 3 lines
Personally, I use mixed environments where iproute2 version doesn't match kernel version most of the time and I'd like to use both new iproute2 and old BIRD or whatever at the same machine. For myself, not knowing exactly
That is a requirement for any solution but with limits. There is always the problem of an older app running on a new kernel and not understanding some whiz bang feature that another app configured. An example of that today is lwt encaps.
Quoted 6 lines
how to implement it, the best way how to interact with the nexthop layer, would be a flag set while opening the netlink socket, or maybe another RTMGRP_* like
RTMGRP_IPV4_NEXTHOPandRTMGRP_IPV6_NEXTHOP. Who asks for these, they will get nexthop-ed notifications; who asks for RTMGRP_IPV[46]_ROUTE, gets them the old way. Anyway, I may live quite well with a system-wide knob in sysctl setting this.
Notifications (e.g, the RTMGRP's) do not allow per-app customizations - an app registers for the event and gets the message however it is created by the code implementing the NEW or DEL message.
Yes, I do plan a separate NEXTHOP RTMGRP.
Dave's comment is really about RTM_NEWROUTE and RTM_DELROUTE messages. The most efficient implementation is to add only the NHID to the message and skip the rest of the nexthop specs (dev, gw, encap, ...). That means all apps listening for the notifications understand the abbreviated NHID reference. A sysctl allows an admin to say 'yes, all apps are converted and understand this nexthop thingy so use the most efficient message'. Without it, route notifications can add the new NHID attribute but still need to add the full nexthop spec.
An app requesting a dump of all entries in the FIB is a different matter. In this case the requesting app can take the nexthop efficiencies while processing the initial configuration without affecting any other processes.
Quoted 6 lines
I'd also like to have documented that the multipath is forbidden to be recursive and only one level of depth is allowed. It seems OK for me on first sight how it works, just please write it down for future generations for them to say "it is OK to fail badly when kernel sends us a recursive nexthop group definition"
That is documented, but apps should be robust and never fail badly when the kernel sends something unknown. That is the basic backwards/forwards compatibility thing. If you do not understand an attribute in a message handle it gracefully.
Quoted 9 lines
At last, what I consider important, is a namespace separation by
nh_protocol. Let's suppose that there is a routing daemon maintaining some routes and also an operator who has her own routes. Then the operator does a stupid typo while running ip nexthop replace and instead of replacing her own nexthop, she replaces the routing daemon's nexthop.I suggest that the key in the nexthop table should include
nh_protocoltogether withnh_idto split these records. It also seems that there is
That creates a difference between routes and nexthops. With FIB entries the protocol is not used for route adds / replace. Same problem but now two different responses from the kernel. Consistency is important.
Quoted 4 lines
only one nexthop table; is this OK wrt. multiple VRF's and so? There is also the
nh_tableparameter in structnh_configwhich only validates the gateway in a given table. If I look correctly, this nexthop may be then used anywhere which is insane from my point of view.
Yes, it should be fine. e.g., consider VRF route leaking.
Quoted 10 lines
BTW, let's consider this:
# ip nexthop add id 1 via 10.99.0.1 dev veth1 # ip nexthop add id 2 via 10.99.0.2 dev veth1 # ip nexthop add id 3 via 10.99.0.3 dev veth1and then both commands at the same time:
# ip nexthop replace id 1 group 2/3
you can not replace a non-group with a group or vice versa. You need to choose a different id.
Quoted 1 line
# ip nexthop replace id 2 group 1/3
same problem here, but also remember these are successive operations - only one change is allowed at a time due to the rtnl lock.
Quoted 9 lines
Is this synchronized and one of these commands fails? (I'm not familiar with the code such deeply, sorry if I'm asking for something obvious.)
Thank you for considering my objections and sorry for reviving such an old thread.
Maria
BIRD developer
If you have time to add support to BIRD a second implementation helps ensure we have the right API.