]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
nexthop: Move nlmsg_parse() in rtm_to_nh_config() to rtm_new_nexthop().
authorKuniyuki Iwashima <kuniyu@amazon.com>
Wed, 19 Mar 2025 23:06:46 +0000 (16:06 -0700)
committerJakub Kicinski <kuba@kernel.org>
Tue, 25 Mar 2025 14:31:58 +0000 (07:31 -0700)
We will split rtm_to_nh_config() into non-RTNL and RTNL parts,
and then the latter also needs tb.

As a prep, let's move nlmsg_parse() to rtm_new_nexthop().

Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Reviewed-by: David Ahern <dsahern@kernel.org>
Reviewed-by: Eric Dumazet <edumazet@google.com>
Link: https://patch.msgid.link/20250319230743.65267-2-kuniyu@amazon.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/ipv4/nexthop.c

index 01df7dd795f01fe560c9f7d3bda2d9517b8368c9..487933ecdb686f7a0078e0a2ed81a152216b2463 100644 (file)
@@ -3016,19 +3016,13 @@ static int rtm_to_nh_config_grp_res(struct nlattr *res, struct nh_config *cfg,
 }
 
 static int rtm_to_nh_config(struct net *net, struct sk_buff *skb,
-                           struct nlmsghdr *nlh, struct nh_config *cfg,
+                           struct nlmsghdr *nlh, struct nlattr **tb,
+                           struct nh_config *cfg,
                            struct netlink_ext_ack *extack)
 {
        struct nhmsg *nhm = nlmsg_data(nlh);
-       struct nlattr *tb[ARRAY_SIZE(rtm_nh_policy_new)];
        int err;
 
-       err = nlmsg_parse(nlh, sizeof(*nhm), tb,
-                         ARRAY_SIZE(rtm_nh_policy_new) - 1,
-                         rtm_nh_policy_new, extack);
-       if (err < 0)
-               return err;
-
        err = -EINVAL;
        if (nhm->resvd || nhm->nh_scope) {
                NL_SET_ERR_MSG(extack, "Invalid values in ancillary header");
@@ -3093,7 +3087,8 @@ static int rtm_to_nh_config(struct net *net, struct sk_buff *skb,
                        NL_SET_ERR_MSG(extack, "Invalid group type");
                        goto out;
                }
-               err = nh_check_attr_group(net, tb, ARRAY_SIZE(tb),
+
+               err = nh_check_attr_group(net, tb, ARRAY_SIZE(rtm_nh_policy_new),
                                          cfg->nh_grp_type, extack);
                if (err)
                        goto out;
@@ -3211,18 +3206,26 @@ out:
 static int rtm_new_nexthop(struct sk_buff *skb, struct nlmsghdr *nlh,
                           struct netlink_ext_ack *extack)
 {
+       struct nlattr *tb[ARRAY_SIZE(rtm_nh_policy_new)];
        struct net *net = sock_net(skb->sk);
        struct nh_config cfg;
        struct nexthop *nh;
        int err;
 
-       err = rtm_to_nh_config(net, skb, nlh, &cfg, extack);
-       if (!err) {
-               nh = nexthop_add(net, &cfg, extack);
-               if (IS_ERR(nh))
-                       err = PTR_ERR(nh);
-       }
+       err = nlmsg_parse(nlh, sizeof(struct nhmsg), tb,
+                         ARRAY_SIZE(rtm_nh_policy_new) - 1,
+                         rtm_nh_policy_new, extack);
+       if (err < 0)
+               goto out;
 
+       err = rtm_to_nh_config(net, skb, nlh, tb, &cfg, extack);
+       if (err)
+               goto out;
+
+       nh = nexthop_add(net, &cfg, extack);
+       if (IS_ERR(nh))
+               err = PTR_ERR(nh);
+out:
        return err;
 }