From patchwork Tue Sep 6 12:01:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 666499 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3sT4vn28KVz9s9c for ; Tue, 6 Sep 2016 22:01:57 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=resnulli-us.20150623.gappssmtp.com header.i=@resnulli-us.20150623.gappssmtp.com header.b=1nw4hE2V; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755852AbcIFMBw (ORCPT ); Tue, 6 Sep 2016 08:01:52 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:34864 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754722AbcIFMBt (ORCPT ); Tue, 6 Sep 2016 08:01:49 -0400 Received: by mail-wm0-f66.google.com with SMTP id a6so6889976wmc.2 for ; Tue, 06 Sep 2016 05:01:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=pcs7/sn9DMmlTVpBuzKsvPPlbCVQU2XSIXA9pwNtkso=; b=1nw4hE2VzKBYryHCA+mw1yhrD9a+ix3WpMrT4tgiDYAEjR99ZtjoGzLFeiMDmR7kLk /0q4fJ41P7AqK/1A10SEVHu9xU9DFUdFm46VyRMCC7mocRbx4v4rScATCs2KTYZ8d7UA Q9TgtRnbEmQk/OPWROkn0FPyUEbKH0AcufYuifbJRLPOG3pvgD8A60UHyJNerdOF3Uwj wpdGB5yzG2j5kU61x4Je98OMbxeIxUSAIfW81ZJLMr77UR4qDmAY/fanFk4b6DVLaS8I Him08E5CgCyZYu8KEABcm2sfRwuMrHGDeHcSzzYGt80VjtsRnAnJnudtgNcW4OChfcVC 9zoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=pcs7/sn9DMmlTVpBuzKsvPPlbCVQU2XSIXA9pwNtkso=; b=GD5NGn6BIiHj6o0jgHl2wjLcnr6xpyNI6mYdYlddI3DgWJgfl15ec5TJNiQ/t5IY/q 4en7nn5gW7RIlWM4SFiehfyC9I1XBJ04SQuFuzIoXg9CSMyrO5eXbV1rBL0HcwFYva14 /Fn8lMAjy1HSSFz7olEOcju/m5pXhAh6PP93XOUb2g1VF/cI+vIikr/0P2OHqHr1GFo3 aLfgEfRcE1UzQwuaf1JIBopfm18+GxFAmXzsg7q5GnUBipy/0XihgayS1knrVp/bdH4r ulkLOVQKgqA/LYJjwCPvgRxw+5Nh56j+7hp0ciNc9cBIJ0NecN2HYLyOb1fGZmK903B3 QpXw== X-Gm-Message-State: AE9vXwOCAiHZ68QZ1ojNqKEpWCDJEZ8fYNyeweWwseo3Cav7T7CrZbR7LPeVtejJRV69mA== X-Received: by 10.28.69.14 with SMTP id s14mr6037139wma.104.1473163308078; Tue, 06 Sep 2016 05:01:48 -0700 (PDT) Received: from localhost (ip-37-188-231-153.eurotel.cz. [37.188.231.153]) by smtp.gmail.com with ESMTPSA id 142sm26164651wmh.12.2016.09.06.05.01.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Sep 2016 05:01:47 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, idosch@mellanox.com, eladr@mellanox.com, yotamg@mellanox.com, nogahf@mellanox.com, ogerlitz@mellanox.com, roopa@cumulusnetworks.com, nikolay@cumulusnetworks.com, linville@tuxdriver.com, tgraf@suug.ch, gospo@cumulusnetworks.com, sfeldma@gmail.com, ast@plumgrid.com, edumazet@google.com, hannes@stressinduktion.org, f.fainelli@gmail.com, dsa@cumulusnetworks.com, jhs@mojatatu.com, vivien.didelot@savoirfairelinux.com, john.fastabend@intel.com, andrew@lunn.ch, ivecera@redhat.com Subject: [patch net-next RFC 1/2] fib: introduce fib notification infrastructure Date: Tue, 6 Sep 2016 14:01:39 +0200 Message-Id: <1473163300-2045-2-git-send-email-jiri@resnulli.us> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1473163300-2045-1-git-send-email-jiri@resnulli.us> References: <1473163300-2045-1-git-send-email-jiri@resnulli.us> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Jiri Pirko This allows to pass information about added/deleted fib entries to whoever is interested. This is done in a very similar way as devinet notifies address additions/removals. Signed-off-by: Jiri Pirko --- include/net/ip_fib.h | 19 +++++++++++++++++++ net/ipv4/fib_trie.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h index 4079fc1..9ad7ba9 100644 --- a/include/net/ip_fib.h +++ b/include/net/ip_fib.h @@ -22,6 +22,7 @@ #include #include #include +#include struct fib_config { u8 fc_dst_len; @@ -184,6 +185,24 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh); #define FIB_RES_PREFSRC(net, res) ((res).fi->fib_prefsrc ? : \ FIB_RES_SADDR(net, res)) +struct fib_notifier_info { + u32 dst; + int dst_len; + struct fib_info *fi; + u8 tos; + u8 type; + u32 tb_id; + u32 nlflags; +}; + +enum fib_event_type { + FIB_EVENT_TYPE_ADD, + FIB_EVENT_TYPE_DEL, +}; + +int register_fib_notifier(struct notifier_block *nb); +int unregister_fib_notifier(struct notifier_block *nb); + struct fib_table { struct hlist_node tb_hlist; u32 tb_id; diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c index e2ffc2a..19ec471 100644 --- a/net/ipv4/fib_trie.c +++ b/net/ipv4/fib_trie.c @@ -73,6 +73,7 @@ #include #include #include +#include #include #include #include @@ -84,6 +85,36 @@ #include #include "fib_lookup.h" +static BLOCKING_NOTIFIER_HEAD(fib_chain); + +int register_fib_notifier(struct notifier_block *nb) +{ + return blocking_notifier_chain_register(&fib_chain, nb); +} +EXPORT_SYMBOL(register_fib_notifier); + +int unregister_fib_notifier(struct notifier_block *nb) +{ + return blocking_notifier_chain_unregister(&fib_chain, nb); +} +EXPORT_SYMBOL(unregister_fib_notifier); + +static int call_fib_notifiers(enum fib_event_type event_type, u32 dst, + int dst_len, struct fib_info *fi, + u8 tos, u8 type, u32 tb_id, u32 nlflags) +{ + struct fib_notifier_info info = { + .dst = dst, + .dst_len = dst_len, + .fi = fi, + .tos = tos, + .type = type, + .tb_id = tb_id, + .nlflags = nlflags, + }; + return blocking_notifier_call_chain(&fib_chain, event_type, &info); +} + #define MAX_STAT_DEPTH 32 #define KEYLENGTH (8*sizeof(t_key)) @@ -1190,6 +1221,10 @@ int fib_table_insert(struct fib_table *tb, struct fib_config *cfg) fib_release_info(fi_drop); if (state & FA_S_ACCESSED) rt_cache_flush(cfg->fc_nlinfo.nl_net); + + call_fib_notifiers(FIB_EVENT_TYPE_ADD, key, plen, fi, + new_fa->fa_tos, cfg->fc_type, + tb->tb_id, cfg->fc_nlflags); rtmsg_fib(RTM_NEWROUTE, htonl(key), new_fa, plen, tb->tb_id, &cfg->fc_nlinfo, NLM_F_REPLACE); @@ -1241,6 +1276,8 @@ int fib_table_insert(struct fib_table *tb, struct fib_config *cfg) tb->tb_num_default++; rt_cache_flush(cfg->fc_nlinfo.nl_net); + call_fib_notifiers(FIB_EVENT_TYPE_ADD, key, plen, fi, tos, + cfg->fc_type, tb->tb_id, cfg->fc_nlflags); rtmsg_fib(RTM_NEWROUTE, htonl(key), new_fa, plen, new_fa->tb_id, &cfg->fc_nlinfo, nlflags); succeeded: @@ -1542,6 +1579,8 @@ int fib_table_delete(struct fib_table *tb, struct fib_config *cfg) switchdev_fib_ipv4_del(key, plen, fa_to_delete->fa_info, tos, cfg->fc_type, tb->tb_id); + call_fib_notifiers(FIB_EVENT_TYPE_DEL, key, plen, fa_to_delete->fa_info, + tos, cfg->fc_type, tb->tb_id, 0); rtmsg_fib(RTM_DELROUTE, htonl(key), fa_to_delete, plen, tb->tb_id, &cfg->fc_nlinfo, 0); @@ -1857,6 +1896,10 @@ int fib_table_flush(struct fib_table *tb) switchdev_fib_ipv4_del(n->key, KEYLENGTH - fa->fa_slen, fi, fa->fa_tos, fa->fa_type, tb->tb_id); + call_fib_notifiers(FIB_EVENT_TYPE_DEL, n->key, + KEYLENGTH - fa->fa_slen, + fi, fa->fa_tos, fa->fa_type, + tb->tb_id, 0); hlist_del_rcu(&fa->fa_list); fib_release_info(fa->fa_info); alias_free_mem_rcu(fa);