{"id":817948,"url":"http://patchwork.ozlabs.org/api/patches/817948/?format=json","web_url":"http://patchwork.ozlabs.org/project/netdev/patch/20170924172212.10096-4-jiri@resnulli.us/","project":{"id":7,"url":"http://patchwork.ozlabs.org/api/projects/7/?format=json","name":"Linux network development","link_name":"netdev","list_id":"netdev.vger.kernel.org","list_email":"netdev@vger.kernel.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20170924172212.10096-4-jiri@resnulli.us>","list_archive_url":null,"date":"2017-09-24T17:22:03","name":"[net-next,v2,03/12] ipmr: Add FIB notification access functions","commit_ref":null,"pull_url":null,"state":"changes-requested","archived":true,"hash":"c57f01fa931078945b9c2994f2a3658fd1bbc914","submitter":{"id":15321,"url":"http://patchwork.ozlabs.org/api/people/15321/?format=json","name":"Jiri Pirko","email":"jiri@resnulli.us"},"delegate":{"id":34,"url":"http://patchwork.ozlabs.org/api/users/34/?format=json","username":"davem","first_name":"David","last_name":"Miller","email":"davem@davemloft.net"},"mbox":"http://patchwork.ozlabs.org/project/netdev/patch/20170924172212.10096-4-jiri@resnulli.us/mbox/","series":[{"id":4828,"url":"http://patchwork.ozlabs.org/api/series/4828/?format=json","web_url":"http://patchwork.ozlabs.org/project/netdev/list/?series=4828","date":"2017-09-24T17:22:00","name":"mlxsw: Add support for offloading IPv4 multicast routes","version":2,"mbox":"http://patchwork.ozlabs.org/series/4828/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/817948/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/817948/checks/","tags":{},"related":[],"headers":{"Return-Path":"<netdev-owner@vger.kernel.org>","X-Original-To":"patchwork-incoming@ozlabs.org","Delivered-To":"patchwork-incoming@ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=vger.kernel.org\n\t(client-ip=209.132.180.67; helo=vger.kernel.org;\n\tenvelope-from=netdev-owner@vger.kernel.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (2048-bit key;\n\tunprotected) header.d=resnulli-us.20150623.gappssmtp.com\n\theader.i=@resnulli-us.20150623.gappssmtp.com\n\theader.b=\"BRw6TN7w\"; dkim-atps=neutral"],"Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3y0YvT0nQBz9sRm\n\tfor <patchwork-incoming@ozlabs.org>;\n\tMon, 25 Sep 2017 03:23:01 +1000 (AEST)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1752748AbdIXRWU (ORCPT <rfc822;patchwork-incoming@ozlabs.org>);\n\tSun, 24 Sep 2017 13:22:20 -0400","from mail-wm0-f67.google.com ([74.125.82.67]:35732 \"EHLO\n\tmail-wm0-f67.google.com\" rhost-flags-OK-OK-OK-OK) by vger.kernel.org\n\twith ESMTP id S1752741AbdIXRWS (ORCPT\n\t<rfc822;netdev@vger.kernel.org>); Sun, 24 Sep 2017 13:22:18 -0400","by mail-wm0-f67.google.com with SMTP id e64so5328698wmi.2\n\tfor <netdev@vger.kernel.org>; Sun, 24 Sep 2017 10:22:17 -0700 (PDT)","from localhost (ip-89-177-136-69.net.upcbroadband.cz.\n\t[89.177.136.69]) by smtp.gmail.com with ESMTPSA id\n\tt15sm2194406wrb.41.2017.09.24.10.22.16\n\t(version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256);\n\tSun, 24 Sep 2017 10:22:16 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=resnulli-us.20150623.gappssmtp.com; s=20150623;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references;\n\tbh=Veyr7AKRYvcRfGINQZcddodcbUJ4IUb/LIm2s6HTIYE=;\n\tb=BRw6TN7w5FEEhk2K+cwfhZNZbOhLf98PyU2fuaNg+KLUr3kIFfUuqH+u/dcDYV0JKN\n\tSfyHnpBEZ71DGLSnYcBR9AB9GLQsTF1QdblClNCIlHYMFLnclIXeqPOI9y6WafYzyWy7\n\txaMR3WYpqcShemfBYxLSN+UNzardahEziT2VuUMqazNZqu5Ghn4CyBvdENvmIulQ6JAm\n\tNmVg7TPkvBVMFJS55TPGiGCK6WH2W5PTpw14aqe1RdY/43EG+2dOJCtDkhZWUF+KBlfn\n\tDhmtNkbSX56HfA3N6rBL2U5pkLu7/vqu6fpRRLgssZec1TxdKK4ZhlhPRFGiQQSRMFe4\n\tqA2A==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references;\n\tbh=Veyr7AKRYvcRfGINQZcddodcbUJ4IUb/LIm2s6HTIYE=;\n\tb=HZ88nNF4xMu82IV8Y/hbX9wDcORQmXONM8PRg9Nsp/axWa+mKIcwXr5VkToac9ltg3\n\tGskP8Xj/vS2kz04h7bQz3bQZ+Du2Jf/99XFR8ULg3RD8WlI6o3qVc1URjhodnxUOBOLf\n\t9MDovYNc7jLtqZu0RY4JtLUVuQfTci4KBqT+ZbPMRIlvdfDM3We+11fIB/8uxPELSEms\n\tDRHWX9bnNO+j1MXDZgmAc1AXKFHVzOnF5oaHbeLYdge45OPZk3AzkhFyZv9nBvDIQm9m\n\tHFPkjWiKEPPyAzgT0GVpjvwnCg27S02MVWqdM3+dDPFUFVE32mw12a/ZpfsrKCDOW24V\n\tirbw==","X-Gm-Message-State":"AHPjjUicSMdNARDZFZJfNZF6aSUOZO3LkSg5lQyjLJr1ymiDqakEsk8k\n\tPzW2+GI42T+IsfIDxKzBzgtpp0zl","X-Google-Smtp-Source":"AOwi7QDiS0IYkWL0Lr3V1+N4uk4Vyt7d4Z3kFO4lcxdsA8/iKZ76xWgcbbbftGfDBl+ik230B+3d+Q==","X-Received":"by 10.28.208.72 with SMTP id h69mr8994439wmg.134.1506273736826; \n\tSun, 24 Sep 2017 10:22:16 -0700 (PDT)","From":"Jiri Pirko <jiri@resnulli.us>","To":"netdev@vger.kernel.org","Cc":"davem@davemloft.net, yotamg@mellanox.com, idosch@mellanox.com,\n\tmlxsw@mellanox.com, nikolay@cumulusnetworks.com, andrew@lunn.ch","Subject":"[patch net-next v2 03/12] ipmr: Add FIB notification access\n\tfunctions","Date":"Sun, 24 Sep 2017 19:22:03 +0200","Message-Id":"<20170924172212.10096-4-jiri@resnulli.us>","X-Mailer":"git-send-email 2.9.5","In-Reply-To":"<20170924172212.10096-1-jiri@resnulli.us>","References":"<20170924172212.10096-1-jiri@resnulli.us>","Sender":"netdev-owner@vger.kernel.org","Precedence":"bulk","List-ID":"<netdev.vger.kernel.org>","X-Mailing-List":"netdev@vger.kernel.org"},"content":"From: Yotam Gigi <yotamg@mellanox.com>\n\nMake the ipmr module register as a FIB notifier. To do that, implement both\nthe ipmr_seq_read and ipmr_dump ops.\n\nThe ipmr_seq_read op returns a sequence counter that is incremented on\nevery notification related operation done by the ipmr. To implement that,\nadd a sequence counter in the netns_ipv4 struct and increment it whenever a\nnew MFC route or VIF are added or deleted. The sequence operations are\nprotected by the RTNL lock.\n\nThe ipmr_dump iterates the list of MFC routes and the list of VIF entries\nand sends notifications about them. The entries dump is done under RCU\nwhere the VIF dump uses the mrt_lock too, as the vif->dev field can change\nunder RCU.\n\nSigned-off-by: Yotam Gigi <yotamg@mellanox.com>\nReviewed-by: Ido Schimmel <idosch@mellanox.com>\nSigned-off-by: Jiri Pirko <jiri@mellanox.com>\n---\nv1->v2:\n - Take the mrt_lock when dumping VIF entries.\n---\n include/linux/mroute.h   |  15 ++++++\n include/net/netns/ipv4.h |   3 ++\n net/ipv4/ipmr.c          | 137 ++++++++++++++++++++++++++++++++++++++++++++++-\n 3 files changed, 153 insertions(+), 2 deletions(-)","diff":"diff --git a/include/linux/mroute.h b/include/linux/mroute.h\nindex 10028f2..54c5cb8 100644\n--- a/include/linux/mroute.h\n+++ b/include/linux/mroute.h\n@@ -5,6 +5,7 @@\n #include <linux/pim.h>\n #include <linux/rhashtable.h>\n #include <net/sock.h>\n+#include <net/fib_notifier.h>\n #include <uapi/linux/mroute.h>\n \n #ifdef CONFIG_IP_MROUTE\n@@ -58,6 +59,14 @@ struct vif_device {\n \tint\t\tlink;\t\t\t/* Physical interface index\t*/\n };\n \n+struct vif_entry_notifier_info {\n+\tstruct fib_notifier_info info;\n+\tstruct net_device *dev;\n+\tvifi_t vif_index;\n+\tunsigned short vif_flags;\n+\tu32 tb_id;\n+};\n+\n #define VIFF_STATIC 0x8000\n \n #define VIF_EXISTS(_mrt, _idx) ((_mrt)->vif_table[_idx].dev != NULL)\n@@ -146,6 +155,12 @@ struct mfc_cache {\n \tstruct rcu_head\trcu;\n };\n \n+struct mfc_entry_notifier_info {\n+\tstruct fib_notifier_info info;\n+\tstruct mfc_cache *mfc;\n+\tu32 tb_id;\n+};\n+\n struct rtmsg;\n int ipmr_get_route(struct net *net, struct sk_buff *skb,\n \t\t   __be32 saddr, __be32 daddr,\ndiff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h\nindex 8387f09..abc84d9 100644\n--- a/include/net/netns/ipv4.h\n+++ b/include/net/netns/ipv4.h\n@@ -163,6 +163,9 @@ struct netns_ipv4 {\n \tstruct fib_notifier_ops\t*notifier_ops;\n \tunsigned int\tfib_seq;\t/* protected by rtnl_mutex */\n \n+\tstruct fib_notifier_ops\t*ipmr_notifier_ops;\n+\tunsigned int\tipmr_seq;\t/* protected by rtnl_mutex */\n+\n \tatomic_t\trt_genid;\n };\n #endif\ndiff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c\nindex 86dc5f9..49879c3 100644\n--- a/net/ipv4/ipmr.c\n+++ b/net/ipv4/ipmr.c\n@@ -264,6 +264,16 @@ static void __net_exit ipmr_rules_exit(struct net *net)\n \tfib_rules_unregister(net->ipv4.mr_rules_ops);\n \trtnl_unlock();\n }\n+\n+static int ipmr_rules_dump(struct net *net, struct notifier_block *nb)\n+{\n+\treturn fib_rules_dump(net, nb, RTNL_FAMILY_IPMR);\n+}\n+\n+static unsigned int ipmr_rules_seq_read(struct net *net)\n+{\n+\treturn fib_rules_seq_read(net, RTNL_FAMILY_IPMR);\n+}\n #else\n #define ipmr_for_each_table(mrt, net) \\\n \tfor (mrt = net->ipv4.mrt; mrt; mrt = NULL)\n@@ -298,6 +308,16 @@ static void __net_exit ipmr_rules_exit(struct net *net)\n \tnet->ipv4.mrt = NULL;\n \trtnl_unlock();\n }\n+\n+static int ipmr_rules_dump(struct net *net, struct notifier_block *nb)\n+{\n+\treturn 0;\n+}\n+\n+static unsigned int ipmr_rules_seq_read(struct net *net)\n+{\n+\treturn 0;\n+}\n #endif\n \n static inline int ipmr_hash_cmp(struct rhashtable_compare_arg *arg,\n@@ -587,6 +607,43 @@ static struct net_device *ipmr_reg_vif(struct net *net, struct mr_table *mrt)\n }\n #endif\n \n+static int call_ipmr_vif_entry_notifier(struct notifier_block *nb,\n+\t\t\t\t\tstruct net *net,\n+\t\t\t\t\tenum fib_event_type event_type,\n+\t\t\t\t\tstruct vif_device *vif,\n+\t\t\t\t\tvifi_t vif_index, u32 tb_id)\n+{\n+\tstruct vif_entry_notifier_info info = {\n+\t\t.info = {\n+\t\t\t.family = RTNL_FAMILY_IPMR,\n+\t\t\t.net = net,\n+\t\t},\n+\t\t.dev = vif->dev,\n+\t\t.vif_index = vif_index,\n+\t\t.vif_flags = vif->flags,\n+\t\t.tb_id = tb_id,\n+\t};\n+\n+\treturn call_fib_notifier(nb, net, event_type, &info.info);\n+}\n+\n+static int call_ipmr_mfc_entry_notifier(struct notifier_block *nb,\n+\t\t\t\t\tstruct net *net,\n+\t\t\t\t\tenum fib_event_type event_type,\n+\t\t\t\t\tstruct mfc_cache *mfc, u32 tb_id)\n+{\n+\tstruct mfc_entry_notifier_info info = {\n+\t\t.info = {\n+\t\t\t.family = RTNL_FAMILY_IPMR,\n+\t\t\t.net = net,\n+\t\t},\n+\t\t.mfc = mfc,\n+\t\t.tb_id = tb_id\n+\t};\n+\n+\treturn call_fib_notifier(nb, net, event_type, &info.info);\n+}\n+\n /**\n  *\tvif_delete - Delete a VIF entry\n  *\t@notify: Set to 1, if the caller is a notifier_call\n@@ -3050,14 +3107,87 @@ static const struct net_protocol pim_protocol = {\n };\n #endif\n \n+static unsigned int ipmr_seq_read(struct net *net)\n+{\n+\tASSERT_RTNL();\n+\n+\treturn net->ipv4.ipmr_seq + ipmr_rules_seq_read(net);\n+}\n+\n+static int ipmr_dump(struct net *net, struct notifier_block *nb)\n+{\n+\tstruct mr_table *mrt;\n+\tint err;\n+\n+\terr = ipmr_rules_dump(net, nb);\n+\tif (err)\n+\t\treturn err;\n+\n+\tipmr_for_each_table(mrt, net) {\n+\t\tstruct vif_device *v = &mrt->vif_table[0];\n+\t\tstruct mfc_cache *mfc;\n+\t\tint vifi;\n+\n+\t\t/* Notifiy on table VIF entries */\n+\t\tread_lock(&mrt_lock);\n+\t\tfor (vifi = 0; vifi < mrt->maxvif; vifi++, v++) {\n+\t\t\tif (!v->dev)\n+\t\t\t\tcontinue;\n+\n+\t\t\tcall_ipmr_vif_entry_notifier(nb, net, FIB_EVENT_VIF_ADD,\n+\t\t\t\t\t\t     v, vifi, mrt->id);\n+\t\t}\n+\t\tread_unlock(&mrt_lock);\n+\n+\t\t/* Notify on table MFC entries */\n+\t\tlist_for_each_entry_rcu(mfc, &mrt->mfc_cache_list, list)\n+\t\t\tcall_ipmr_mfc_entry_notifier(nb, net,\n+\t\t\t\t\t\t     FIB_EVENT_ENTRY_ADD, mfc,\n+\t\t\t\t\t\t     mrt->id);\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static const struct fib_notifier_ops ipmr_notifier_ops_template = {\n+\t.family\t\t= RTNL_FAMILY_IPMR,\n+\t.fib_seq_read\t= ipmr_seq_read,\n+\t.fib_dump\t= ipmr_dump,\n+\t.owner\t\t= THIS_MODULE,\n+};\n+\n+int __net_init ipmr_notifier_init(struct net *net)\n+{\n+\tstruct fib_notifier_ops *ops;\n+\n+\tnet->ipv4.ipmr_seq = 0;\n+\n+\tops = fib_notifier_ops_register(&ipmr_notifier_ops_template, net);\n+\tif (IS_ERR(ops))\n+\t\treturn PTR_ERR(ops);\n+\tnet->ipv4.ipmr_notifier_ops = ops;\n+\n+\treturn 0;\n+}\n+\n+static void __net_exit ipmr_notifier_exit(struct net *net)\n+{\n+\tfib_notifier_ops_unregister(net->ipv4.ipmr_notifier_ops);\n+\tnet->ipv4.ipmr_notifier_ops = NULL;\n+}\n+\n /* Setup for IP multicast routing */\n static int __net_init ipmr_net_init(struct net *net)\n {\n \tint err;\n \n+\terr = ipmr_notifier_init(net);\n+\tif (err)\n+\t\tgoto ipmr_notifier_fail;\n+\n \terr = ipmr_rules_init(net);\n \tif (err < 0)\n-\t\tgoto fail;\n+\t\tgoto ipmr_rules_fail;\n \n #ifdef CONFIG_PROC_FS\n \terr = -ENOMEM;\n@@ -3074,7 +3204,9 @@ static int __net_init ipmr_net_init(struct net *net)\n proc_vif_fail:\n \tipmr_rules_exit(net);\n #endif\n-fail:\n+ipmr_rules_fail:\n+\tipmr_notifier_exit(net);\n+ipmr_notifier_fail:\n \treturn err;\n }\n \n@@ -3084,6 +3216,7 @@ static void __net_exit ipmr_net_exit(struct net *net)\n \tremove_proc_entry(\"ip_mr_cache\", net->proc_net);\n \tremove_proc_entry(\"ip_mr_vif\", net->proc_net);\n #endif\n+\tipmr_notifier_exit(net);\n \tipmr_rules_exit(net);\n }\n \n","prefixes":["net-next","v2","03/12"]}