]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
ipv4: Add function to send route updates
authorDavid Ahern <dsahern@gmail.com>
Wed, 22 May 2019 19:04:42 +0000 (12:04 -0700)
committerDavid S. Miller <davem@davemloft.net>
Thu, 23 May 2019 00:48:44 +0000 (17:48 -0700)
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 <dsahern@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/ip_fib.h
net/ipv4/fib_trie.c

index d0e28f4ab0994ae55ca0b1778a29fda0aa2789e8..ec6496c08f48237d0a4dd09eedf356be63315ebb 100644 (file)
@@ -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 {
index 334f723bdf802d2b169fc99631e7af2be7e90fb5..ea7df7ebf597b82a1043b3231bd70cd8670e9e03 100644 (file)
@@ -1943,6 +1943,78 @@ int fib_table_flush(struct net *net, struct fib_table *tb, bool flush_all)
        return found;
 }
 
+/* derived from fib_trie_free */
+static void __fib_info_notify_update(struct net *net, struct fib_table *tb,
+                                    struct nl_info *info)
+{
+       struct trie *t = (struct trie *)tb->tb_data;
+       struct key_vector *pn = t->kv;
+       unsigned long cindex = 1;
+       struct fib_alias *fa;
+
+       for (;;) {
+               struct key_vector *n;
+
+               if (!(cindex--)) {
+                       t_key pkey = pn->key;
+
+                       if (IS_TRIE(pn))
+                               break;
+
+                       n = pn;
+                       pn = node_parent(pn);
+                       cindex = get_index(pkey, pn);
+                       continue;
+               }
+
+               /* grab the next available node */
+               n = get_child(pn, cindex);
+               if (!n)
+                       continue;
+
+               if (IS_TNODE(n)) {
+                       /* record pn and cindex for leaf walking */
+                       pn = n;
+                       cindex = 1ul << n->bits;
+
+                       continue;
+               }
+
+               hlist_for_each_entry(fa, &n->leaf, fa_list) {
+                       struct fib_info *fi = fa->fa_info;
+
+                       if (!fi || !fi->nh_updated || fa->tb_id != tb->tb_id)
+                               continue;
+
+                       rtmsg_fib(RTM_NEWROUTE, htonl(n->key), fa,
+                                 KEYLENGTH - fa->fa_slen, tb->tb_id,
+                                 info, NLM_F_REPLACE);
+
+                       /* call_fib_entry_notifiers will be removed when
+                        * in-kernel notifier is implemented and supported
+                        * for nexthop objects
+                        */
+                       call_fib_entry_notifiers(net, FIB_EVENT_ENTRY_REPLACE,
+                                                n->key,
+                                                KEYLENGTH - fa->fa_slen, fa,
+                                                NULL);
+               }
+       }
+}
+
+void fib_info_notify_update(struct net *net, struct nl_info *info)
+{
+       unsigned int h;
+
+       for (h = 0; h < FIB_TABLE_HASHSZ; h++) {
+               struct hlist_head *head = &net->ipv4.fib_table_hash[h];
+               struct fib_table *tb;
+
+               hlist_for_each_entry_rcu(tb, head, tb_hlist)
+                       __fib_info_notify_update(net, tb, info);
+       }
+}
+
 static void fib_leaf_notify(struct net *net, struct key_vector *l,
                            struct fib_table *tb, struct notifier_block *nb)
 {