net: advertise netns_immutable property via netlink
authorNicolas Dichtel <nicolas.dichtel@6wind.com>
Fri, 28 Feb 2025 10:20:57 +0000 (11:20 +0100)
committerPaolo Abeni <pabeni@redhat.com>
Tue, 4 Mar 2025 11:44:48 +0000 (12:44 +0100)
Since commit 05c1280a2bcf ("netdev_features: convert NETIF_F_NETNS_LOCAL to
dev->netns_local"), there is no way to see if the netns_immutable property
s set on a device. Let's add a netlink attribute to advertise it.

Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Reviewed-by: Alexander Lobakin <aleksander.lobakin@intel.com>
Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Documentation/netlink/specs/rt_link.yaml
include/uapi/linux/if_link.h
net/core/rtnetlink.c

index 8b5c0f067328553dde5e29a8aaa25c8e6aed3b42..31238455f8e9d29531884cad4951391fa47ccfaf 100644 (file)
@@ -1160,6 +1160,9 @@ attribute-sets:
         name: max-pacing-offload-horizon
         type: uint
         doc: EDT offload horizon supported by the device (in nsec).
+      -
+        name: netns-immutable
+        type: u8
   -
     name: af-spec-attrs
     attributes:
index 3b586fb0bc4cddf6655d48ba7b31ab1c200532d6..318386cc5b0d19ed6a37734feffb450353dd9440 100644 (file)
@@ -378,6 +378,7 @@ enum {
        IFLA_GRO_IPV4_MAX_SIZE,
        IFLA_DPLL_PIN,
        IFLA_MAX_PACING_OFFLOAD_HORIZON,
+       IFLA_NETNS_IMMUTABLE,
        __IFLA_MAX
 };
 
index b52e610e157e9d5a5a1d7413ef77dccb2d0e2440..8b6bf5e9bb3422df0b025507e396730f27a182b2 100644 (file)
@@ -1292,6 +1292,7 @@ static noinline size_t if_nlmsg_size(const struct net_device *dev,
               + nla_total_size(4) /* IFLA_TSO_MAX_SEGS */
               + nla_total_size(1) /* IFLA_OPERSTATE */
               + nla_total_size(1) /* IFLA_LINKMODE */
+              + nla_total_size(1) /* IFLA_NETNS_IMMUTABLE */
               + nla_total_size(4) /* IFLA_CARRIER_CHANGES */
               + nla_total_size(4) /* IFLA_LINK_NETNSID */
               + nla_total_size(4) /* IFLA_GROUP */
@@ -2046,6 +2047,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb,
                       netif_running(dev) ? READ_ONCE(dev->operstate) :
                                            IF_OPER_DOWN) ||
            nla_put_u8(skb, IFLA_LINKMODE, READ_ONCE(dev->link_mode)) ||
+           nla_put_u8(skb, IFLA_NETNS_IMMUTABLE, dev->netns_immutable) ||
            nla_put_u32(skb, IFLA_MTU, READ_ONCE(dev->mtu)) ||
            nla_put_u32(skb, IFLA_MIN_MTU, READ_ONCE(dev->min_mtu)) ||
            nla_put_u32(skb, IFLA_MAX_MTU, READ_ONCE(dev->max_mtu)) ||
@@ -2234,6 +2236,7 @@ static const struct nla_policy ifla_policy[IFLA_MAX+1] = {
        [IFLA_ALLMULTI]         = { .type = NLA_REJECT },
        [IFLA_GSO_IPV4_MAX_SIZE]        = NLA_POLICY_MIN(NLA_U32, MAX_TCP_HEADER + 1),
        [IFLA_GRO_IPV4_MAX_SIZE]        = { .type = NLA_U32 },
+       [IFLA_NETNS_IMMUTABLE]  = { .type = NLA_REJECT },
 };
 
 static const struct nla_policy ifla_info_policy[IFLA_INFO_MAX+1] = {