Skip to content

Commit 1bff1a0

Browse files
dsaherndavem330
authored andcommitted
ipv4: Add function to send route updates
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. Signed-off-by: David Ahern <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 19a3b7e commit 1bff1a0

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

include/net/ip_fib.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ struct fib_info {
150150
#define fib_advmss fib_metrics->metrics[RTAX_ADVMSS-1]
151151
int fib_nhs;
152152
bool fib_nh_is_v6;
153+
bool nh_updated;
153154
struct rcu_head rcu;
154155
struct fib_nh fib_nh[0];
155156
#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,
231232
int __net_init fib4_notifier_init(struct net *net);
232233
void __net_exit fib4_notifier_exit(struct net *net);
233234

235+
void fib_info_notify_update(struct net *net, struct nl_info *info);
234236
void fib_notify(struct net *net, struct notifier_block *nb);
235237

236238
struct fib_table {

net/ipv4/fib_trie.c

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1943,6 +1943,78 @@ int fib_table_flush(struct net *net, struct fib_table *tb, bool flush_all)
19431943
return found;
19441944
}
19451945

1946+
/* derived from fib_trie_free */
1947+
static void __fib_info_notify_update(struct net *net, struct fib_table *tb,
1948+
struct nl_info *info)
1949+
{
1950+
struct trie *t = (struct trie *)tb->tb_data;
1951+
struct key_vector *pn = t->kv;
1952+
unsigned long cindex = 1;
1953+
struct fib_alias *fa;
1954+
1955+
for (;;) {
1956+
struct key_vector *n;
1957+
1958+
if (!(cindex--)) {
1959+
t_key pkey = pn->key;
1960+
1961+
if (IS_TRIE(pn))
1962+
break;
1963+
1964+
n = pn;
1965+
pn = node_parent(pn);
1966+
cindex = get_index(pkey, pn);
1967+
continue;
1968+
}
1969+
1970+
/* grab the next available node */
1971+
n = get_child(pn, cindex);
1972+
if (!n)
1973+
continue;
1974+
1975+
if (IS_TNODE(n)) {
1976+
/* record pn and cindex for leaf walking */
1977+
pn = n;
1978+
cindex = 1ul << n->bits;
1979+
1980+
continue;
1981+
}
1982+
1983+
hlist_for_each_entry(fa, &n->leaf, fa_list) {
1984+
struct fib_info *fi = fa->fa_info;
1985+
1986+
if (!fi || !fi->nh_updated || fa->tb_id != tb->tb_id)
1987+
continue;
1988+
1989+
rtmsg_fib(RTM_NEWROUTE, htonl(n->key), fa,
1990+
KEYLENGTH - fa->fa_slen, tb->tb_id,
1991+
info, NLM_F_REPLACE);
1992+
1993+
/* call_fib_entry_notifiers will be removed when
1994+
* in-kernel notifier is implemented and supported
1995+
* for nexthop objects
1996+
*/
1997+
call_fib_entry_notifiers(net, FIB_EVENT_ENTRY_REPLACE,
1998+
n->key,
1999+
KEYLENGTH - fa->fa_slen, fa,
2000+
NULL);
2001+
}
2002+
}
2003+
}
2004+
2005+
void fib_info_notify_update(struct net *net, struct nl_info *info)
2006+
{
2007+
unsigned int h;
2008+
2009+
for (h = 0; h < FIB_TABLE_HASHSZ; h++) {
2010+
struct hlist_head *head = &net->ipv4.fib_table_hash[h];
2011+
struct fib_table *tb;
2012+
2013+
hlist_for_each_entry_rcu(tb, head, tb_hlist)
2014+
__fib_info_notify_update(net, tb, info);
2015+
}
2016+
}
2017+
19462018
static void fib_leaf_notify(struct net *net, struct key_vector *l,
19472019
struct fib_table *tb, struct notifier_block *nb)
19482020
{

0 commit comments

Comments
 (0)