]> git.ipfire.org Git - thirdparty/iproute2.git/commit
ip: Support IP address protocol
authorPetr Machata <petrm@nvidia.com>
Mon, 27 Mar 2023 16:12:05 +0000 (18:12 +0200)
committerDavid Ahern <dsahern@kernel.org>
Thu, 30 Mar 2023 15:53:13 +0000 (09:53 -0600)
commitbdb8d8549ed97a02935c8fb00ece05030f2f91ad
treead8bb1c9e04005977052dbb60906962569bfd3e2
parente8a3fb470b4e96aa35a2731c7cc175b946c0a62d
ip: Support IP address protocol

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.
Support for this feature was merged with commit 47f0bd503210 ("net: Add new
protocol attribute to IP addresses"), for kernel 5.18.

In this patch, add support for setting the protocol attribute at IP address
addition, replacement, and listing requests.

An example session with the feature in action:

# ip address add dev d 192.0.2.1/28 proto 0xab
# ip address show dev d
26: 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

# ip address replace dev d 192.0.2.1/28 proto 0x11
# ip address show dev d
26: 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

A JSON dump. The protocol value is always provided as a string, even in
numeric mode, to provide a consistent interface.

# ip -j address show dev d | jq
[
  {
    "ifindex": 26,
    "ifname": "d",
    "flags": [
      "BROADCAST",
      "NOARP"
    ],
    "mtu": 1500,
    "qdisc": "noop",
    "operstate": "DOWN",
    "group": "default",
    "txqlen": 1000,
    "link_type": "ether",
    "address": "06:29:74:fd:1f:eb",
    "broadcast": "ff:ff:ff:ff:ff:ff",
    "addr_info": [
      {
        "family": "inet",
        "local": "192.0.2.1",
        "prefixlen": 28,
        "scope": "global",
        "protocol": "0x11",
        "label": "d",
        "valid_life_time": 4294967295,
        "preferred_life_time": 4294967295
      }
    ]
  }
]

Signed-off-by: Petr Machata <petrm@nvidia.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
include/rt_names.h
ip/ip_common.h
ip/ipaddress.c
lib/rt_names.c