Skip to content

Commit c77bbc6

Browse files
dsaherndavem330
authored andcommitted
net: rules: Move l3mdev attribute validation to a helper
Move the check on FRA_L3MDEV attribute to helper to improve the readability of fib_nl2rule. Update the extack messages to be clear when the configuration option is disabled versus an invalid value has been passed. Signed-off-by: David Ahern <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 5144678 commit c77bbc6

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

net/core/fib_rules.c

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,27 @@ static struct fib_rule *rule_find(struct fib_rules_ops *ops,
454454
return NULL;
455455
}
456456

457+
#ifdef CONFIG_NET_L3_MASTER_DEV
458+
static int fib_nl2rule_l3mdev(struct nlattr *nla, struct fib_rule *nlrule,
459+
struct netlink_ext_ack *extack)
460+
{
461+
nlrule->l3mdev = nla_get_u8(nla);
462+
if (nlrule->l3mdev != 1) {
463+
NL_SET_ERR_MSG(extack, "Invalid l3mdev attribute");
464+
return -1;
465+
}
466+
467+
return 0;
468+
}
469+
#else
470+
static int fib_nl2rule_l3mdev(struct nlattr *nla, struct fib_rule *nlrule,
471+
struct netlink_ext_ack *extack)
472+
{
473+
NL_SET_ERR_MSG(extack, "l3mdev support is not enabled in kernel");
474+
return -1;
475+
}
476+
#endif
477+
457478
static int fib_nl2rule(struct sk_buff *skb, struct nlmsghdr *nlh,
458479
struct netlink_ext_ack *extack,
459480
struct fib_rules_ops *ops,
@@ -536,16 +557,9 @@ static int fib_nl2rule(struct sk_buff *skb, struct nlmsghdr *nlh,
536557
nlrule->tun_id = nla_get_be64(tb[FRA_TUN_ID]);
537558

538559
err = -EINVAL;
539-
if (tb[FRA_L3MDEV]) {
540-
#ifdef CONFIG_NET_L3_MASTER_DEV
541-
nlrule->l3mdev = nla_get_u8(tb[FRA_L3MDEV]);
542-
if (nlrule->l3mdev != 1)
543-
#endif
544-
{
545-
NL_SET_ERR_MSG(extack, "Invalid l3mdev");
546-
goto errout_free;
547-
}
548-
}
560+
if (tb[FRA_L3MDEV] &&
561+
fib_nl2rule_l3mdev(tb[FRA_L3MDEV], nlrule, extack) < 0)
562+
goto errout_free;
549563

550564
nlrule->action = frh->action;
551565
nlrule->flags = frh->flags;

0 commit comments

Comments
 (0)