]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
netfilter: nf_tables: Store user-defined hook ifname
authorPhil Sutter <phil@nwl.cc>
Thu, 9 Jan 2025 17:31:33 +0000 (18:31 +0100)
committerPablo Neira Ayuso <pablo@netfilter.org>
Sun, 19 Jan 2025 15:41:53 +0000 (16:41 +0100)
Prepare for hooks with NULL ops.dev pointer (due to non-existent device)
and store the interface name and length as specified by the user upon
creation. No functional change intended.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
include/net/netfilter/nf_tables.h
net/netfilter/nf_tables_api.c

index f6958118986ac49edf71d7a1ed6bee3dfb44447b..bd93d085b6fb49e1fc271b7f5f4cafaaa7ece976 100644 (file)
@@ -1201,6 +1201,8 @@ struct nft_hook {
        struct list_head        list;
        struct nf_hook_ops      ops;
        struct rcu_head         rcu;
+       char                    ifname[IFNAMSIZ];
+       u8                      ifnamelen;
 };
 
 /**
index e41c77e5eefdcdcbbece19f8dba314d329ab39dc..95d8d33589b1d90956d1a629fac529eb65fe8b33 100644 (file)
@@ -2276,7 +2276,6 @@ static struct nft_hook *nft_netdev_hook_alloc(struct net *net,
                                              const struct nlattr *attr)
 {
        struct net_device *dev;
-       char ifname[IFNAMSIZ];
        struct nft_hook *hook;
        int err;
 
@@ -2286,12 +2285,17 @@ static struct nft_hook *nft_netdev_hook_alloc(struct net *net,
                goto err_hook_alloc;
        }
 
-       nla_strscpy(ifname, attr, IFNAMSIZ);
+       err = nla_strscpy(hook->ifname, attr, IFNAMSIZ);
+       if (err < 0)
+               goto err_hook_dev;
+
+       hook->ifnamelen = nla_len(attr);
+
        /* nf_tables_netdev_event() is called under rtnl_mutex, this is
         * indirectly serializing all the other holders of the commit_mutex with
         * the rtnl_mutex.
         */
-       dev = __dev_get_by_name(net, ifname);
+       dev = __dev_get_by_name(net, hook->ifname);
        if (!dev) {
                err = -ENOENT;
                goto err_hook_dev;