From: Kuniyuki Iwashima <kuniyu@google.com>
To: g.goller@proxmox.com
Cc: corbet@lwn.net, davem@davemloft.net, dsahern@kernel.org,
edumazet@google.com, horms@kernel.org, kuba@kernel.org,
linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org, netdev@vger.kernel.org,
nicolas.dichtel@6wind.com, pabeni@redhat.com, shuah@kernel.org,
kuniyu@google.com
Subject: Re: [PATCH net-next v4] ipv6: add `force_forwarding` sysctl to enable per-interface forwarding
Date: Fri, 4 Jul 2025 08:00:02 +0000 [thread overview]
Message-ID: <20250704080101.1659504-1-kuniyu@google.com> (raw)
In-Reply-To: <20250703160154.560239-1-g.goller@proxmox.com>
From: Gabriel Goller <g.goller@proxmox.com>
Date: Thu, 3 Jul 2025 18:01:53 +0200
> diff --git a/Documentation/networking/ip-sysctl.rst b/Documentation/networking/ip-sysctl.rst
> index 0f1251cce314..ec7fa1e890f1 100644
> --- a/Documentation/networking/ip-sysctl.rst
> +++ b/Documentation/networking/ip-sysctl.rst
> @@ -2292,6 +2292,11 @@ conf/all/forwarding - BOOLEAN
> proxy_ndp - BOOLEAN
> Do proxy ndp.
>
> +force_forwarding - BOOLEAN
> + Enable forwarding on this interface only -- regardless of the setting on
> + ``conf/all/forwarding``. When setting ``conf.all.forwarding`` to 0,
> + the ``force_forwarding`` flag will be reset on all interfaces.
Please update conf/all/forwarding too as it will be stale after
this patch.
> +
> fwmark_reflect - BOOLEAN
> Controls the fwmark of kernel-generated IPv6 reply packets that are not
> associated with a socket for example, TCP RSTs or ICMPv6 echo replies).
> diff --git a/include/linux/ipv6.h b/include/linux/ipv6.h
> index 5aeeed22f35b..5380107e466c 100644
> --- a/include/linux/ipv6.h
> +++ b/include/linux/ipv6.h
> @@ -19,6 +19,7 @@ struct ipv6_devconf {
> __s32 forwarding;
> __s32 disable_policy;
> __s32 proxy_ndp;
> + __s32 force_forwarding;
nit: place force_forwarding just after forwarding.
> __cacheline_group_end(ipv6_devconf_read_txrx);
>
> __s32 accept_ra;
> @@ -857,6 +859,15 @@ static void addrconf_forward_change(struct net *net, __s32 newf)
> idev = __in6_dev_get_rtnl_net(dev);
> if (idev) {
> int changed = (!idev->cnf.forwarding) ^ (!newf);
> + /*
> + * With the introduction of force_forwarding, we need to be backwards
> + * compatible, so that means we need to set the force_forwarding flag
Strictly backward compatibility is not related I think because
the per iface conf is disabled by default, and this is a new
behaviour. Maybe simply say
/* Disabling all.forwarding sets 0 to force_forwarding for all interfaces */
> + * on every interface to 0 if net.ipv6.conf.all.forwarding is set to 0.
> + * This allows the global forwarding flag to disable forwarding for
> + * all interfaces.
> + */
> + if (newf == 0)
> + WRITE_ONCE(idev->cnf.force_forwarding, newf);
>
> WRITE_ONCE(idev->cnf.forwarding, newf);
> if (changed)
> @@ -5719,6 +5730,7 @@ static void ipv6_store_devconf(const struct ipv6_devconf *cnf,
> array[DEVCONF_ACCEPT_UNTRACKED_NA] =
> READ_ONCE(cnf->accept_untracked_na);
> array[DEVCONF_ACCEPT_RA_MIN_LFT] = READ_ONCE(cnf->accept_ra_min_lft);
> + array[DEVCONF_FORCE_FORWARDING] = READ_ONCE(cnf->force_forwarding);
> }
>
[...]
> static inline size_t inet6_ifla6_size(void)
> @@ -6747,6 +6759,78 @@ static int addrconf_sysctl_disable_policy(const struct ctl_table *ctl, int write
> return ret;
> }
>
> +static void addrconf_force_forward_change(struct net *net, __s32 newf)
> +{
> + ASSERT_RTNL();
__in6_dev_get_rtnl_net() has the same check so this is not needed.
> + struct net_device *dev;
> + struct inet6_dev *idev;
> +
> + for_each_netdev(net, dev) {
> + idev = __in6_dev_get_rtnl_net(dev);
> + if (idev) {
> + int changed = (!idev->cnf.force_forwarding) ^ (!newf);
> +
> + WRITE_ONCE(idev->cnf.force_forwarding, newf);
> + if (changed) {
> + inet6_netconf_notify_devconf(dev_net(dev), RTM_NEWNETCONF,
> + NETCONFA_FORCE_FORWARDING,
> + dev->ifindex, &idev->cnf);
> + }
> + }
> + }
> +}
> +
> +static int addrconf_sysctl_force_forwarding(const struct ctl_table *ctl, int write,
> + void *buffer, size_t *lenp, loff_t *ppos)
> +{
> + struct inet6_dev *idev = ctl->extra1;
> + struct net *net = ctl->extra2;
> + int *valp = ctl->data;
> + loff_t pos = *ppos;
nit: Please keep the reverse xmas tree order.
https://www.kernel.org/doc/html/latest/process/maintainer-netdev.html#local-variable-ordering-reverse-xmas-tree-rcs
> + int new_val = *valp;
> + int old_val = *valp;
> + int ret;
> +
> + struct ctl_table tmp_ctl = *ctl;
same here.
> +
> + tmp_ctl.extra1 = SYSCTL_ZERO;
> + tmp_ctl.extra2 = SYSCTL_ONE;
As you are copying *ctl, please specify this in addrconf_sysctl[].
> + tmp_ctl.data = &new_val;
> +
> + ret = proc_douintvec_minmax(&tmp_ctl, write, buffer, lenp, ppos);
> +
> + if (write && old_val != new_val) {
> + if (!rtnl_net_trylock(net))
> + return restart_syscall();
> +
> + if (valp == &net->ipv6.devconf_dflt->force_forwarding) {
> + inet6_netconf_notify_devconf(net, RTM_NEWNETCONF,
> + NETCONFA_FORCE_FORWARDING,
> + NETCONFA_IFINDEX_DEFAULT,
> + net->ipv6.devconf_dflt);
> + } else if (valp == &net->ipv6.devconf_all->force_forwarding) {
> + inet6_netconf_notify_devconf(net, RTM_NEWNETCONF,
> + NETCONFA_FORCE_FORWARDING,
> + NETCONFA_IFINDEX_ALL,
> + net->ipv6.devconf_all);
> +
> + addrconf_force_forward_change(net, new_val);
> + } else {
> + inet6_netconf_notify_devconf(net, RTM_NEWNETCONF,
> + NETCONFA_FORCE_FORWARDING,
> + idev->dev->ifindex,
> + &idev->cnf);
> + }
> + rtnl_net_unlock(net);
> + }
> +
> + if (write)
> + WRITE_ONCE(*valp, new_val);
> + if (ret)
> + *ppos = pos;
> + return ret;
> +}
> +
> static int minus_one = -1;
> static const int two_five_five = 255;
> static u32 ioam6_if_id_max = U16_MAX;
> @@ -7217,6 +7301,13 @@ static const struct ctl_table addrconf_sysctl[] = {
> .extra1 = SYSCTL_ZERO,
> .extra2 = SYSCTL_TWO,
> },
> + {
> + .procname = "force_forwarding",
> + .data = &ipv6_devconf.force_forwarding,
> + .maxlen = sizeof(int),
> + .mode = 0644,
> + .proc_handler = addrconf_sysctl_force_forwarding,
Here for extra{1,2}.
> + },
> };
>
> static int __addrconf_sysctl_register(struct net *net, char *dev_name,
> diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
> index 7bd29a9ff0db..440b9efced72 100644
> --- a/net/ipv6/ip6_output.c
> +++ b/net/ipv6/ip6_output.c
> @@ -509,7 +509,8 @@ int ip6_forward(struct sk_buff *skb)
> u32 mtu;
>
> idev = __in6_dev_get_safely(dev_get_by_index_rcu(net, IP6CB(skb)->iif));
> - if (READ_ONCE(net->ipv6.devconf_all->forwarding) == 0)
> + if (idev && !READ_ONCE(idev->cnf.force_forwarding) &&
> + !READ_ONCE(net->ipv6.devconf_all->forwarding))
Now this ignores devconf_all when !idev whose dev was not
found or has not had a valid mtu.
if (!READ_ONCE(net->ipv6.devconf_all->forwarding) &&
(!idev || !READ_ONCE(idev->cnf.force_forwarding)))
next prev parent reply other threads:[~2025-07-04 8:01 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-03 16:01 [PATCH net-next v4] ipv6: add `force_forwarding` sysctl to enable per-interface forwarding Gabriel Goller
2025-07-04 8:00 ` Kuniyuki Iwashima [this message]
2025-07-04 9:37 ` Gabriel Goller
2025-07-04 18:08 ` Kuniyuki Iwashima
2025-07-04 8:07 ` Nicolas Dichtel
2025-07-04 9:41 ` Gabriel Goller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250704080101.1659504-1-kuniyu@google.com \
--to=kuniyu@google.com \
--cc=corbet@lwn.net \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=g.goller@proxmox.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=nicolas.dichtel@6wind.com \
--cc=pabeni@redhat.com \
--cc=shuah@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox