From patchwork Fri Jun 25 07:04:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antony Antony X-Patchwork-Id: 467780 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D2DC9C2B9F4 for ; Fri, 25 Jun 2021 07:04:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B54B2613FD for ; Fri, 25 Jun 2021 07:04:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229774AbhFYHGu (ORCPT ); Fri, 25 Jun 2021 03:06:50 -0400 Received: from mailout2.secunet.com ([62.96.220.49]:60016 "EHLO mailout2.secunet.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229437AbhFYHGt (ORCPT ); Fri, 25 Jun 2021 03:06:49 -0400 Received: from cas-essen-01.secunet.de (unknown [10.53.40.201]) by mailout2.secunet.com (Postfix) with ESMTP id 3704E800056; Fri, 25 Jun 2021 09:04:28 +0200 (CEST) Received: from mbx-essen-01.secunet.de (10.53.40.197) by cas-essen-01.secunet.de (10.53.40.201) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Fri, 25 Jun 2021 09:04:28 +0200 Received: from moon.secunet.de (172.18.26.121) by mbx-essen-01.secunet.de (10.53.40.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Fri, 25 Jun 2021 09:04:27 +0200 Date: Fri, 25 Jun 2021 09:04:10 +0200 From: Antony Antony To: "David S. Miller" , Jakub Kicinski , Hideaki YOSHIFUJI , David Ahern CC: , Christian Perle , Antony Antony Subject: [PATCH net-next] ipv6: Add sysctl for RA default route table number Message-ID: <32de887afdc7d6851e7c53d27a21f1389bb0bd0f.1624604535.git.antony.antony@secunet.com> Reply-To: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Organization: secunet User-Agent: Mutt/1.10.1 (2018-07-13) X-ClientProxiedBy: cas-essen-01.secunet.de (10.53.40.201) To mbx-essen-01.secunet.de (10.53.40.197) X-EXCLAIMER-MD-CONFIG: 2c86f778-e09b-4440-8b15-867914633a10 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Christian Perle Default routes learned from router advertisements(RA) are always placed in main routing table. For policy based routing setups one may want a different table for default routes. This commit adds a sysctl to make table number for RA default routes configurable. examples: sysctl net.ipv6.route.defrtr_table sysctl -w net.ipv6.route.defrtr_table=42 ip -6 route show table 42 Signed-off-by: Christian Perle Signed-off-by: Antony Antony --- include/net/netns/ipv6.h | 1 + net/ipv6/route.c | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h index bde0b7adb4a3..0eb599ee621a 100644 --- a/include/net/netns/ipv6.h +++ b/include/net/netns/ipv6.h @@ -53,6 +53,7 @@ struct netns_sysctl_ipv6 { int seg6_flowlabel; bool skip_notify_on_dev_down; u8 fib_notify_on_flag_change; + u32 ip6_rt_defrtr_table; }; struct netns_ipv6 { diff --git a/net/ipv6/route.c b/net/ipv6/route.c index 7b756a7dc036..5c561f5b7618 100644 --- a/net/ipv6/route.c +++ b/net/ipv6/route.c @@ -4336,7 +4336,7 @@ struct fib6_info *rt6_get_dflt_router(struct net *net, const struct in6_addr *addr, struct net_device *dev) { - u32 tb_id = l3mdev_fib_table(dev) ? : RT6_TABLE_DFLT; + u32 tb_id = l3mdev_fib_table(dev) ? : net->ipv6.sysctl.ip6_rt_defrtr_table; struct fib6_info *rt; struct fib6_table *table; @@ -4371,7 +4371,7 @@ struct fib6_info *rt6_add_dflt_router(struct net *net, u32 defrtr_usr_metric) { struct fib6_config cfg = { - .fc_table = l3mdev_fib_table(dev) ? : RT6_TABLE_DFLT, + .fc_table = l3mdev_fib_table(dev) ? : net->ipv6.sysctl.ip6_rt_defrtr_table, .fc_metric = defrtr_usr_metric, .fc_ifindex = dev->ifindex, .fc_flags = RTF_GATEWAY | RTF_ADDRCONF | RTF_DEFAULT | @@ -6391,6 +6391,13 @@ static struct ctl_table ipv6_route_table_template[] = { .extra1 = SYSCTL_ZERO, .extra2 = SYSCTL_ONE, }, + { + .procname = "defrtr_table", + .data = &init_net.ipv6.sysctl.ip6_rt_defrtr_table, + .maxlen = sizeof(u32), + .mode = 0644, + .proc_handler = proc_dointvec, + }, { } }; @@ -6415,6 +6422,7 @@ struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net) table[8].data = &net->ipv6.sysctl.ip6_rt_min_advmss; table[9].data = &net->ipv6.sysctl.ip6_rt_gc_min_interval; table[10].data = &net->ipv6.sysctl.skip_notify_on_dev_down; + table[11].data = &net->ipv6.sysctl.ip6_rt_defrtr_table; /* Don't export sysctls to unprivileged users */ if (net->user_ns != &init_user_ns) @@ -6486,6 +6494,7 @@ static int __net_init ip6_route_net_init(struct net *net) net->ipv6.sysctl.ip6_rt_mtu_expires = 10*60*HZ; net->ipv6.sysctl.ip6_rt_min_advmss = IPV6_MIN_MTU - 20 - 40; net->ipv6.sysctl.skip_notify_on_dev_down = 0; + net->ipv6.sysctl.ip6_rt_defrtr_table = RT6_TABLE_DFLT; net->ipv6.ip6_rt_gc_expire = 30*HZ;