net: Export functions for nexthop code
Subsystems (3)
David Ahern
maintainerv2 cover net: Export functions for nexthop code
From: David Ahern <[email protected]>
This set exports ipv4 and ipv6 fib functions for use by the nexthop code. It also adds new ones to send route notifications if a nexthop configuration changes.
v2
- repost of patches dropped at the end of the last dev window added patch 8 which exports nh_update_mtu since it is inline with the other patches
David Ahern (8):
ipv6: Add delete route hook to stubs
ipv6: Add hook to bump sernum for a route to stubs
ipv6: export function to send route updates
ipv4: Add function to send route updates
ipv4: export fib_check_nh
ipv4: export fib_flush
ipv4: export fib_info_update_nh_saddr
ipv4: Rename and export nh_update_mtu
include/net/ip6_fib.h | 7 +++++ include/net/ip_fib.h | 9 +++++- include/net/ipv6_stubs.h | 5 ++++ net/ipv4/fib_frontend.c | 2 +- net/ipv4/fib_semantics.c | 27 +++++++++--------- net/ipv4/fib_trie.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++ net/ipv6/addrconf_core.c | 6 ++++ net/ipv6/af_inet6.c | 3 ++ net/ipv6/ip6_fib.c | 16 ++++++++--- net/ipv6/route.c | 32 +++++++++++++++++++++ 10 files changed, 159 insertions(+), 20 deletions(-)
Signature · 1 line
2.11.0
David Ahern
maintainerPATCH v2 1/8 ipv6: Add delete route hook to stubs
From: David Ahern <[email protected]>
Add ip6_del_rt to the IPv6 stub. The hook is needed by the nexthop code to remove entries linked to a nexthop that is getting deleted.
--- include/net/ipv6_stubs.h | 1 + net/ipv6/addrconf_core.c | 6 ++++++ net/ipv6/af_inet6.c | 1 + 3 files changed, 8 insertions(+)
include/net/ipv6_stubs.h +1 -0
@@ -45,6 +45,7 @@ struct ipv6_stub { struct fib6_config *cfg, gfp_t gfp_flags, struct netlink_ext_ack *extack);void (*fib6_nh_release)(struct fib6_nh *fib6_nh); +int (*ip6_del_rt)(struct net *net,struct fib6_info *rt);void (*udpv6_encap_enable)(void ); void (*ndisc_send_na)(struct net_device *dev, const struct in6_addr *daddr, const struct in6_addr *solicited_addr,
net/ipv6/addrconf_core.c +6 -0
@@ -182,6 +182,11 @@ static int eafnosupport_fib6_nh_init(struct net *net, struct fib6_nh *fib6_nh,return -EAFNOSUPPORT ; } +static int eafnosupport_ip6_del_rt (struct net *net,struct fib6_info *rt) +{ +return -EAFNOSUPPORT ; +} +const struct ipv6_stub *ipv6_stub__read_mostly = &(struct ipv6_stub ) { .ipv6_dst_lookup = eafnosupport_ipv6_dst_lookup, .ipv6_route_input = eafnosupport_ipv6_route_input,
@@ -191,6 +196,7 @@ const struct ipv6_stub *ipv6_stub __read_mostly = &(struct ipv6_stub) { .fib6_select_path = eafnosupport_fib6_select_path, .ip6_mtu_from_fib6 = eafnosupport_ip6_mtu_from_fib6, .fib6_nh_init = eafnosupport_fib6_nh_init, + .ip6_del_rt = eafnosupport_ip6_del_rt, };EXPORT_SYMBOL_GPL (ipv6_stub);
net/ipv6/af_inet6.c +1 -0
@@ -926,6 +926,7 @@ static const struct ipv6_stub ipv6_stub_impl = { .ip6_mtu_from_fib6 = ip6_mtu_from_fib6, .fib6_nh_init = fib6_nh_init, .fib6_nh_release = fib6_nh_release, + .ip6_del_rt = ip6_del_rt, .udpv6_encap_enable = udpv6_encap_enable, .ndisc_send_na = ndisc_send_na, .nd_tbl = &nd_tbl,
Signature · 1 line
2.11.0
David Ahern
maintainerPATCH v2 2/8 ipv6: Add hook to bump sernum for a route to stubs
In reply to David AhernFrom: David Ahern <[email protected]>
Add hook to ipv6 stub to bump the sernum up to the root node for a route. This is needed by the nexthop code when a nexthop config changes.
--- include/net/ip6_fib.h | 1 + include/net/ipv6_stubs.h | 1 + net/ipv6/af_inet6.c | 1 + net/ipv6/ip6_fib.c | 8 ++++++++ 4 files changed, 11 insertions(+)
include/net/ip6_fib.h +1 -0
@@ -485,6 +485,7 @@ int fib6_tables_dump(struct net *net, struct notifier_block *nb);void fib6_update_sernum (struct net *net,struct fib6_info *rt);void fib6_update_sernum_upto_root (struct net *net,struct fib6_info *rt); +void fib6_update_sernum_stub (struct net *net,struct fib6_info *f6i);void fib6_metric_set (struct fib6_info *f6i,int metric,u32 val);static inline bool fib6_metric_locked (struct fib6_info *f6i,int metric)
include/net/ipv6_stubs.h +1 -0
@@ -45,6 +45,7 @@ struct ipv6_stub { struct fib6_config *cfg, gfp_t gfp_flags, struct netlink_ext_ack *extack);void (*fib6_nh_release)(struct fib6_nh *fib6_nh); +void (*fib6_update_sernum)(struct net *net,struct fib6_info *rt);int (*ip6_del_rt)(struct net *net,struct fib6_info *rt);void (*udpv6_encap_enable)(void ); void (*ndisc_send_na)(struct net_device *dev, const struct in6_addr *daddr,
net/ipv6/af_inet6.c +1 -0
@@ -926,6 +926,7 @@ static const struct ipv6_stub ipv6_stub_impl = { .ip6_mtu_from_fib6 = ip6_mtu_from_fib6, .fib6_nh_init = fib6_nh_init, .fib6_nh_release = fib6_nh_release, + .fib6_update_sernum = fib6_update_sernum_stub, .ip6_del_rt = ip6_del_rt, .udpv6_encap_enable = udpv6_encap_enable, .ndisc_send_na = ndisc_send_na,
net/ipv6/ip6_fib.c +8 -0
@@ -1222,6 +1222,14 @@ void fib6_update_sernum_upto_root(struct net *net, struct fib6_info *rt)__fib6_update_sernum_upto_root (rt,fib6_new_sernum (net)); } +/* allow ipv4 to update sernum via ipv6_stub */ +void fib6_update_sernum_stub (struct net *net,struct fib6_info *f6i) +{ +spin_lock_bh (&f6i->fib6_table->tb6_lock); +fib6_update_sernum_upto_root (net, f6i); +spin_unlock_bh (&f6i->fib6_table->tb6_lock); +} +/* * Add routing information to the routing tree. * <destination addr>/<source addr>
Signature · 1 line
2.11.0
David Ahern
maintainerPATCH v2 3/8 ipv6: export function to send route updates
In reply to David AhernFrom: David Ahern <[email protected]>
Add fib6_rt_update to send RTM_NEWROUTE with NLM_F_REPLACE set. This helper will be used by the nexthop code to notify userspace of routes that are impacted when a nexthop config is updated via replace.
This notification is needed for legacy apps that do not understand the new nexthop object. Apps that are nexthop aware can use the RTA_NH_ID attribute in the route notification to just ignore it.
In the future this should be wrapped in a sysctl to allow OS'es that are fully updated to avoid the notificaton storm.
--- include/net/ip6_fib.h | 6 ++++++ include/net/ipv6_stubs.h | 3 +++ net/ipv6/af_inet6.c | 1 + net/ipv6/ip6_fib.c | 8 ++++---- net/ipv6/route.c | 32 ++++++++++++++++++++++++++++++++ 5 files changed, 46 insertions(+), 4 deletions(-)
include/net/ip6_fib.h +6 -0
@@ -452,6 +452,12 @@ int fib6_nh_init(struct net *net, struct fib6_nh *fib6_nh, struct netlink_ext_ack *extack);void fib6_nh_release (struct fib6_nh *fib6_nh); +int call_fib6_entry_notifiers (struct net *net, +enum fib_event_type event_type, +struct fib6_info *rt, +struct netlink_ext_ack *extack); +void fib6_rt_update (struct net *net,struct fib6_info *rt, +struct nl_info *info);void inet6_rt_notify (int event,struct fib6_info *rt,struct nl_info *info,unsigned int flags);
include/net/ipv6_stubs.h +3 -0
@@ -47,6 +47,9 @@ struct ipv6_stub {void (*fib6_nh_release)(struct fib6_nh *fib6_nh);void (*fib6_update_sernum)(struct net *net,struct fib6_info *rt);int (*ip6_del_rt)(struct net *net,struct fib6_info *rt); +void (*fib6_rt_update)(struct net *net,struct fib6_info *rt, +struct nl_info *info); +void (*udpv6_encap_enable)(void ); void (*ndisc_send_na)(struct net_device *dev, const struct in6_addr *daddr, const struct in6_addr *solicited_addr,
net/ipv6/af_inet6.c +1 -0
@@ -927,6 +927,7 @@ static const struct ipv6_stub ipv6_stub_impl = { .fib6_nh_init = fib6_nh_init, .fib6_nh_release = fib6_nh_release, .fib6_update_sernum = fib6_update_sernum_stub, + .fib6_rt_update = fib6_rt_update, .ip6_del_rt = ip6_del_rt, .udpv6_encap_enable = udpv6_encap_enable, .ndisc_send_na = ndisc_send_na,
net/ipv6/ip6_fib.c +4 -4
@@ -393,10 +393,10 @@ static int call_fib6_entry_notifier(struct notifier_block *nb, struct net *net,return call_fib6_notifier (nb, net, event_type, &info.info); } -static int call_fib6_entry_notifiers (struct net *net, -enum fib_event_type event_type, -struct fib6_info *rt, -struct netlink_ext_ack *extack) +int call_fib6_entry_notifiers (struct net *net, +enum fib_event_type event_type, +struct fib6_info *rt, +struct netlink_ext_ack *extack) {struct fib6_entry_notifier_info info = { .info.extack = extack,
net/ipv6/route.c +32 -0
@@ -5123,6 +5123,38 @@ void inet6_rt_notify(int event, struct fib6_info *rt, struct nl_info *info,rtnl_set_sk_err (net,RTNLGRP_IPV6_ROUTE , err); } +void fib6_rt_update (struct net *net,struct fib6_info *rt, +struct nl_info *info) +{ +u32 seq = info->nlh ? info->nlh->nlmsg_seq :0 ; +struct sk_buff *skb; +int err = -ENOBUFS ; + +/* call_fib6_entry_notifiers will be removed when in-kernel notifier +* is implemented and supported for nexthop objects +*/ +call_fib6_entry_notifiers (net,FIB_EVENT_ENTRY_REPLACE , rt,NULL ); + + skb =nlmsg_new (rt6_nlmsg_size (rt),gfp_any ()); +if (!skb) + goto errout; + + err =rt6_fill_node (net, skb, rt,NULL ,NULL ,NULL ,0 , +RTM_NEWROUTE , info->portid, seq,NLM_F_REPLACE ); +if (err <0 ) { +/* -EMSGSIZE implies BUG in rt6_nlmsg_size() */ +WARN_ON (err == -EMSGSIZE ); +kfree_skb (skb); + goto errout; + } +rtnl_notify (skb, net, info->portid,RTNLGRP_IPV6_ROUTE , + info->nlh,gfp_any ()); +return ; +errout: +if (err <0 ) +rtnl_set_sk_err (net,RTNLGRP_IPV6_ROUTE , err); +} +static int ip6_route_dev_notify (struct notifier_block *this,unsigned long event,void *ptr) {
Signature · 1 line
2.11.0
David Ahern
maintainerPATCH v2 4/8 ipv4: Add function to send route updates
In reply to David AhernFrom: David Ahern <[email protected]>
Add fib_info_notify_update to walk the fib and send RTM_NEWROUTE notifications with NLM_F_REPLACE set for entries linked to a fib_info that have nh_updated flag set. This helper will be used by the nexthop code to notify userspace of routes that are impacted when a nexthop config is updated via replace. The new function and its helper are similar to how fib_flush and fib_table_flush work for address delete and link down events.
This notification is needed for legacy apps that do not understand the new nexthop object. Apps that are nexthop aware can use the RTA_NH_ID attribute in the route notification to just ignore it.
In the future this should be wrapped in a sysctl to allow OS'es that are fully updated to avoid the notificaton storm.
--- include/net/ip_fib.h | 2 ++ net/ipv4/fib_trie.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+)
include/net/ip_fib.h +2 -0
@@ -150,6 +150,7 @@ struct fib_info {#define fib_advmss fib_metrics->metrics[RTAX_ADVMSS-1]int fib_nhs;bool fib_nh_is_v6; +bool nh_updated;struct rcu_head rcu;struct fib_nh fib_nh[0 ];#define fib_dev fib_nh[0].fib_nh_dev
@@ -231,6 +232,7 @@ int call_fib4_notifiers(struct net *net, enum fib_event_type event_type,int __net_init fib4_notifier_init (struct net *net); void __net_exit fib4_notifier_exit(struct net *net); +void fib_info_notify_update (struct net *net,struct nl_info *info);void fib_notify (struct net *net,struct notifier_block *nb);struct fib_table {
net/ipv4/fib_trie.c +72 -0
78 lines not on this page · raw message
Signature · 1 line
2.11.0
David Ahern
maintainerPATCH v2 5/8 ipv4: export fib_check_nh
In reply to David AhernFrom: 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 | 12 ++++++------ 2 files changed, 8 insertions(+), 6 deletions(-)
include/net/ip_fib.h +2 -0
@@ -436,6 +436,8 @@ void fib_sync_mtu(struct net_device *dev, u32 orig_mtu);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);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);
net/ipv4/fib_semantics.c +6 -6
@@ -1092,15 +1092,13 @@ static int fib_check_nh_nongw(struct net *net, struct fib_nh *nh,return err; } -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) { -struct net *net = cfg->fc_nlinfo.nl_net; -u32 table = cfg->fc_table;int err;if (nh->fib_nh_gw_family ==AF_INET ) - err =fib_check_nh_v4_gw (net, nh, table, cfg->fc_scope, extack); + err =fib_check_nh_v4_gw (net, nh, table, scope, extack);else if (nh->fib_nh_gw_family ==AF_INET6 ) err =fib_check_nh_v6_gw (net, nh, table, extack);else
@@ -1377,7 +1375,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->fib_nh_flags &RTNH_F_LINKDOWN )
Signature · 1 line
2.11.0
David Ahern
maintainerPATCH v2 6/8 ipv4: export fib_flush
In reply to David AhernFrom: David Ahern <[email protected]>
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 | 1 + net/ipv4/fib_frontend.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)
include/net/ip_fib.h +1 -0
@@ -473,6 +473,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;
Signature · 1 line
2.11.0
David Ahern
maintainerPATCH v2 7/8 ipv4: export fib_info_update_nh_saddr
In reply to David AhernFrom: 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 | 3 ++- net/ipv4/fib_semantics.c | 11 +++++------ 2 files changed, 7 insertions(+), 7 deletions(-)
include/net/ip_fib.h +2 -1
@@ -201,7 +201,8 @@ static inline struct fib_nh_common *fib_info_nhc(struct fib_info *fi, int nhsel)#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);__be32 fib_result_prefsrc (struct net *net,struct fib_result *res);#define FIB_RES_NHC (res) ((res).nhc)
net/ipv4/fib_semantics.c +5 -6
@@ -1189,11 +1189,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->fib_nh_dev, - nh->fib_nh_gw4, - nh->nh_parent->fib_scope); + nh->nh_saddr =inet_select_addr (nh->fib_nh_dev, nh->fib_nh_gw4, scope); nh->nh_saddr_genid =atomic_read (&net->ipv4.dev_addr_genid);return nh->nh_saddr;
@@ -1211,7 +1210,7 @@ __be32 fib_result_prefsrc(struct net *net, struct fib_result *res)if (nh->nh_saddr_genid ==atomic_read (&net->ipv4.dev_addr_genid))return nh->nh_saddr; -return fib_info_update_nh_saddr (net, nh); +return fib_info_update_nh_saddr (net, nh, res->fi->fib_scope); }static bool fib_valid_prefsrc (struct fib_config *cfg,__be32 fib_prefsrc)
@@ -1393,7 +1392,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);if (nexthop_nh->fib_nh_gw_family ==AF_INET6 ) fi->fib_nh_is_v6 = true; }endfor_nexthops (fi)
Signature · 1 line
2.11.0
David Ahern
maintainerPATCH v2 8/8 ipv4: Rename and export nh_update_mtu
In reply to David AhernFrom: David Ahern <[email protected]>
Rename nh_update_mtu to fib_nhc_update_mtu and export for use by the nexthop code.
--- include/net/ip_fib.h | 1 + net/ipv4/fib_semantics.c | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-)
include/net/ip_fib.h +1 -0
@@ -432,6 +432,7 @@ int fib_sync_down_dev(struct net_device *dev, unsigned long event, bool force);int fib_sync_down_addr (struct net_device *dev,__be32 local);int fib_sync_up (struct net_device *dev,unsigned char nh_flags);void fib_sync_mtu (struct net_device *dev,u32 orig_mtu); +void fib_nhc_update_mtu (struct fib_nh_common *nhc,u32 new,u32 orig);#ifdef CONFIG_IP_ROUTE_MULTIPATH int fib_multipath_hash(const struct net *net, const struct flowi4 *fl4,
net/ipv4/fib_semantics.c +2 -2
@@ -1712,7 +1712,7 @@ static int call_fib_nh_notifiers(struct fib_nh *nh,* - if the new MTU is greater than the PMTU, don't make any change * - otherwise, unlock and set PMTU */ -static void nh_update_mtu (struct fib_nh_common *nhc,u32 new,u32 orig) +void fib_nhc_update_mtu (struct fib_nh_common *nhc,u32 new,u32 orig) {struct fnhe_hash_bucket *bucket;int i;
@@ -1748,7 +1748,7 @@ void fib_sync_mtu(struct net_device *dev, u32 orig_mtu)hlist_for_each_entry (nh, head, nh_hash) {if (nh->fib_nh_dev == dev) -nh_update_mtu (&nh->nh_common, dev->mtu, orig_mtu); +fib_nhc_update_mtu (&nh->nh_common, dev->mtu, orig_mtu); } }
Signature · 1 line
2.11.0
David Miller
maintainerFrom: David Ahern <[email protected]>
Date: Wed, 22 May 2019 12:04:38 -0700
Quoted 10 lines
From: David Ahern <[email protected]>
This set exports ipv4 and ipv6 fib functions for use by the nexthop code. It also adds new ones to send route notifications if a nexthop configuration changes.
v2
- repost of patches dropped at the end of the last dev window added patch 8 which exportsnh_update_mtusince it is inline with the other patches
Series applied, thanks David.