From patchwork Thu Aug 3 11:28:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 797151 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) 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="mS7wlO+4"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3xNSVs4qrPz9s75 for ; Thu, 3 Aug 2017 21:28:53 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752153AbdHCL2w (ORCPT ); Thu, 3 Aug 2017 07:28:52 -0400 Received: from mail-wr0-f194.google.com ([209.85.128.194]:38337 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752106AbdHCL2q (ORCPT ); Thu, 3 Aug 2017 07:28:46 -0400 Received: by mail-wr0-f194.google.com with SMTP id g32so799114wrd.5 for ; Thu, 03 Aug 2017 04:28:45 -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=PcjfY/2qzJJ/7OibGNHE9wPurJ8aQP7K+SVNNpnrtKQ=; b=mS7wlO+4fDgA7LkEjbG6GbowIHvYDY/GSJceW4aVbcQ/2Mv77wqvCwPke+9ZJjPBRb Vvn4uLgawKL+gm1FVNSnfxn2wgAEFdorMw+GotjyCBIDaBl2bb3feQ1xUMTGg+Q/iXIx ni5lrMltDwys/khqVBH1yiDK/MqEB37GnC3d4EVqdgHAlj7pAilSc/3BK5+1GABrBomY iXV+yMCv2RVwXEdjqFfXzujhHbt8qfdG1LtYhnjhayiQ2vy+9iRXhjxBCQYV6S7JJpcj HBKc9Qc7Io3xFvc3FdoK+xeVjNcsLO+C8evEzPBwN/XxOrIO3adJPkFvVw+doglCiNgm ngQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=PcjfY/2qzJJ/7OibGNHE9wPurJ8aQP7K+SVNNpnrtKQ=; b=S5ajH0md5LhOFNbBAr/Vp/iCwTHfzBGxwZuxu6DCVP2bi5bpFdbVK70GSK0/XquDmI 5wyCjnS6Kiijy4/7DkwEHVqitI94Z215fnoc9LdPrbiqrB5sFFAN8NOp93a3YA/eRQwM KsDR2xihHcFSK6uc6HRKFYXfx4SpyOufNvfu6cfQDxOm3+V+FC1qXqwZRfsMOBjDPG3h yI1xBOtQAdwr4h4NJRK+wg/dWA8CZ2UmjBlWMoy6n/70J/Z6RIIbKWOgjiescsfEOJW0 YT83oLN/JzXxOOT5mEX8SBstqvGBoupiRw1p9RY9FIozOat8CSxHU8jy525DevyVaOoS 2o6A== X-Gm-Message-State: AIVw113kVnkB8j7V1/YzN7+xZKbje65aCIfdfKa9eHQZYBbWz3ktUitB TnxPeErGYSgPEKNIt2I= X-Received: by 10.223.136.178 with SMTP id f47mr1246764wrf.250.1501759724615; Thu, 03 Aug 2017 04:28:44 -0700 (PDT) Received: from localhost (static-cl188134168102.unet.cz. [188.134.168.102]) by smtp.gmail.com with ESMTPSA id p68sm1749787wmf.0.2017.08.03.04.28.43 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 03 Aug 2017 04:28:44 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: davem@davemloft.net, idosch@mellanox.com, mlxsw@mellanox.com, dsahern@gmail.com, roopa@cumulusnetworks.com, nikolay@cumulusnetworks.com, kafai@fb.com, hannes@stressinduktion.org, yoshfuji@linux-ipv6.org, edumazet@google.com, yanhaishuang@cmss.chinamobile.com Subject: [patch net-next 06/21] ipv6: fib: Add FIB notifiers callbacks Date: Thu, 3 Aug 2017 13:28:16 +0200 Message-Id: <20170803112831.1831-7-jiri@resnulli.us> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170803112831.1831-1-jiri@resnulli.us> References: <20170803112831.1831-1-jiri@resnulli.us> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Ido Schimmel We're about to add IPv6 FIB offload support, so implement the necessary callbacks in IPv6 code, which will later allow us to add routes and rules notifications. Signed-off-by: Ido Schimmel Signed-off-by: Jiri Pirko --- include/net/ip6_fib.h | 11 ++++++++++ include/net/netns/ipv6.h | 1 + net/ipv6/Makefile | 2 +- net/ipv6/fib6_notifier.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++ net/ipv6/ip6_fib.c | 7 ++++++ 5 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 net/ipv6/fib6_notifier.c diff --git a/include/net/ip6_fib.h b/include/net/ip6_fib.h index 6000b0d..be8ddf3 100644 --- a/include/net/ip6_fib.h +++ b/include/net/ip6_fib.h @@ -16,10 +16,12 @@ #include #include #include +#include #include #include #include #include +#include #ifdef CONFIG_IPV6_MULTIPLE_TABLES #define FIB6_TABLE_HASHSZ 256 @@ -292,6 +294,15 @@ int fib6_init(void); int ipv6_route_open(struct inode *inode, struct file *file); +int call_fib6_notifier(struct notifier_block *nb, struct net *net, + enum fib_event_type event_type, + struct fib_notifier_info *info); +int call_fib6_notifiers(struct net *net, enum fib_event_type event_type, + struct fib_notifier_info *info); + +int __net_init fib6_notifier_init(struct net *net); +void __net_exit fib6_notifier_exit(struct net *net); + #ifdef CONFIG_IPV6_MULTIPLE_TABLES int fib6_rules_init(void); void fib6_rules_cleanup(void); diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h index de7745e..abdf3b4 100644 --- a/include/net/netns/ipv6.h +++ b/include/net/netns/ipv6.h @@ -86,6 +86,7 @@ struct netns_ipv6 { atomic_t dev_addr_genid; atomic_t fib6_sernum; struct seg6_pernet_data *seg6_data; + struct fib_notifier_ops *notifier_ops; }; #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6) diff --git a/net/ipv6/Makefile b/net/ipv6/Makefile index 217e9ff..f8b24c2 100644 --- a/net/ipv6/Makefile +++ b/net/ipv6/Makefile @@ -9,7 +9,7 @@ ipv6-objs := af_inet6.o anycast.o ip6_output.o ip6_input.o addrconf.o \ route.o ip6_fib.o ipv6_sockglue.o ndisc.o udp.o udplite.o \ raw.o icmp.o mcast.o reassembly.o tcp_ipv6.o ping.o \ exthdrs.o datagram.o ip6_flowlabel.o inet6_connection_sock.o \ - udp_offload.o seg6.o + udp_offload.o seg6.o fib6_notifier.o ipv6-offload := ip6_offload.o tcpv6_offload.o exthdrs_offload.o diff --git a/net/ipv6/fib6_notifier.c b/net/ipv6/fib6_notifier.c new file mode 100644 index 0000000..c2bb1ab --- /dev/null +++ b/net/ipv6/fib6_notifier.c @@ -0,0 +1,55 @@ +#include +#include +#include +#include +#include +#include +#include + +int call_fib6_notifier(struct notifier_block *nb, struct net *net, + enum fib_event_type event_type, + struct fib_notifier_info *info) +{ + info->family = AF_INET6; + return call_fib_notifier(nb, net, event_type, info); +} + +int call_fib6_notifiers(struct net *net, enum fib_event_type event_type, + struct fib_notifier_info *info) +{ + info->family = AF_INET6; + return call_fib_notifiers(net, event_type, info); +} + +static unsigned int fib6_seq_read(struct net *net) +{ + return 0; +} + +static int fib6_dump(struct net *net, struct notifier_block *nb) +{ + return 0; +} + +static const struct fib_notifier_ops fib6_notifier_ops_template = { + .family = AF_INET6, + .fib_seq_read = fib6_seq_read, + .fib_dump = fib6_dump, +}; + +int __net_init fib6_notifier_init(struct net *net) +{ + struct fib_notifier_ops *ops; + + ops = fib_notifier_ops_register(&fib6_notifier_ops_template, net); + if (IS_ERR(ops)) + return PTR_ERR(ops); + net->ipv6.notifier_ops = ops; + + return 0; +} + +void __net_exit fib6_notifier_exit(struct net *net) +{ + fib_notifier_ops_unregister(net->ipv6.notifier_ops); +} diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c index ebb299c..f93976e 100644 --- a/net/ipv6/ip6_fib.c +++ b/net/ipv6/ip6_fib.c @@ -1839,6 +1839,11 @@ static void fib6_gc_timer_cb(unsigned long arg) static int __net_init fib6_net_init(struct net *net) { size_t size = sizeof(struct hlist_head) * FIB6_TABLE_HASHSZ; + int err; + + err = fib6_notifier_init(net); + if (err) + return err; spin_lock_init(&net->ipv6.fib6_gc_lock); rwlock_init(&net->ipv6.fib6_walker_lock); @@ -1891,6 +1896,7 @@ static int __net_init fib6_net_init(struct net *net) out_rt6_stats: kfree(net->ipv6.rt6_stats); out_timer: + fib6_notifier_exit(net); return -ENOMEM; } @@ -1907,6 +1913,7 @@ static void fib6_net_exit(struct net *net) kfree(net->ipv6.fib6_main_tbl); kfree(net->ipv6.fib_table_hash); kfree(net->ipv6.rt6_stats); + fib6_notifier_exit(net); } static struct pernet_operations fib6_net_ops = {