mbox series

[net-next,0/3] net: Allow changing IPv4 address protocol

Message ID cover.1679399108.git.petrm@nvidia.com (mailing list archive)
Headers show
Series net: Allow changing IPv4 address protocol | expand

Message

Petr Machata March 21, 2023, 11:51 a.m. UTC
IPv4 and IPv6 addresses can be assigned a protocol value that indicates the
provenance of the IP address. The attribute is modeled after ip route
protocols, and essentially allows the administrator or userspace stack to
tag addresses in some way that makes sense to the actor in question.

When IP address protocol field was added in commit 47f0bd503210 ("net: Add
new protocol attribute to IP addresses"), the semantics included the
ability to change the protocol for IPv6 addresses, but not for IPv4
addresses. It seems this was not deliberate, but rather by accident.

One particular use case is tagging the addresses differently depending on
whether the routing stack should advertise them or not. Without support for
protocol replacement, this can not be done.

In this patchset, extend IPv4 to allow changing the protocol defined at an
address (in patch #1). Then in patches #2 and #3 add selftest coverage for
ip address protocols.

Currently the kernel simply ignores the new value. Thus allowing the
replacement changes the observable behavior. However, since IPv6 already
behaves like this anyway, and since the feature as such is relatively new,
it seems like the change is safe to make.

An example session with the feature in action:

	bash-5.2# ip address add dev d 192.0.2.1/28 proto 0xab
	bash-5.2# ip address show dev d
	4: d: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN group default qlen 1000
	    link/ether 06:29:74:fd:1f:eb brd ff:ff:ff:ff:ff:ff
	    inet 192.0.2.1/28 scope global proto 0xab d
	       valid_lft forever preferred_lft forever

	bash-5.2# ip address replace dev d 192.0.2.1/28 proto 0x11
	bash-5.2# ip address show dev d
	4: d: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN group default qlen 1000
	    link/ether 06:29:74:fd:1f:eb brd ff:ff:ff:ff:ff:ff
	    inet 192.0.2.1/28 scope global proto 0x11 d
	       valid_lft forever preferred_lft forever

Petr Machata (3):
  net: ipv4: Allow changing IPv4 address protocol
  selftests: rtnetlink: Make the set of tests to run configurable
  selftests: rtnetlink: Add an address proto test

 net/ipv4/devinet.c                       |   3 +
 tools/testing/selftests/net/rtnetlink.sh | 181 +++++++++++++++++------
 2 files changed, 142 insertions(+), 42 deletions(-)

Comments

patchwork-bot+netdevbpf@kernel.org March 23, 2023, 8:40 a.m. UTC | #1
Hello:

This series was applied to netdev/net-next.git (main)
by David S. Miller <davem@davemloft.net>:

On Tue, 21 Mar 2023 12:51:58 +0100 you wrote:
> IPv4 and IPv6 addresses can be assigned a protocol value that indicates the
> provenance of the IP address. The attribute is modeled after ip route
> protocols, and essentially allows the administrator or userspace stack to
> tag addresses in some way that makes sense to the actor in question.
> 
> When IP address protocol field was added in commit 47f0bd503210 ("net: Add
> new protocol attribute to IP addresses"), the semantics included the
> ability to change the protocol for IPv6 addresses, but not for IPv4
> addresses. It seems this was not deliberate, but rather by accident.
> 
> [...]

Here is the summary with links:
  - [net-next,1/3] net: ipv4: Allow changing IPv4 address protocol
    https://git.kernel.org/netdev/net-next/c/5c4a9aa856c7
  - [net-next,2/3] selftests: rtnetlink: Make the set of tests to run configurable
    https://git.kernel.org/netdev/net-next/c/ecb3c1e675c7
  - [net-next,3/3] selftests: rtnetlink: Add an address proto test
    https://git.kernel.org/netdev/net-next/c/6a414fd77f61

You are awesome, thank you!