Skip to content

Commit 493ced1

Browse files
dsaherndavem330
authored andcommitted
ipv4: Allow routes to use nexthop objects
Add support for RTA_NH_ID attribute to allow a user to specify a nexthop id to use with a route. fc_nh_id is added to fib_config to hold the value passed in the RTA_NH_ID attribute. If a nexthop id is given, the gateway, device, encap and multipath attributes can not be set. Update fib_nh_match to check ids on a route delete. Signed-off-by: David Ahern <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 2d44234 commit 493ced1

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

include/net/ip_fib.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ struct fib_config {
4040
u32 fc_flags;
4141
u32 fc_priority;
4242
__be32 fc_prefsrc;
43+
u32 fc_nh_id;
4344
struct nlattr *fc_mx;
4445
struct rtnexthop *fc_mp;
4546
int fc_mx_len;

net/ipv4/fib_frontend.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,7 @@ const struct nla_policy rtm_ipv4_policy[RTA_MAX + 1] = {
671671
[RTA_IP_PROTO] = { .type = NLA_U8 },
672672
[RTA_SPORT] = { .type = NLA_U16 },
673673
[RTA_DPORT] = { .type = NLA_U16 },
674+
[RTA_NH_ID] = { .type = NLA_U32 },
674675
};
675676

676677
int fib_gw_from_via(struct fib_config *cfg, struct nlattr *nla,
@@ -808,6 +809,18 @@ static int rtm_to_fib_config(struct net *net, struct sk_buff *skb,
808809
if (err < 0)
809810
goto errout;
810811
break;
812+
case RTA_NH_ID:
813+
cfg->fc_nh_id = nla_get_u32(attr);
814+
break;
815+
}
816+
}
817+
818+
if (cfg->fc_nh_id) {
819+
if (cfg->fc_oif || cfg->fc_gw_family ||
820+
cfg->fc_encap || cfg->fc_mp) {
821+
NL_SET_ERR_MSG(extack,
822+
"Nexthop specification and nexthop id are mutually exclusive");
823+
return -EINVAL;
811824
}
812825
}
813826

@@ -834,6 +847,12 @@ static int inet_rtm_delroute(struct sk_buff *skb, struct nlmsghdr *nlh,
834847
if (err < 0)
835848
goto errout;
836849

850+
if (cfg.fc_nh_id && !nexthop_find_by_id(net, cfg.fc_nh_id)) {
851+
NL_SET_ERR_MSG(extack, "Nexthop id does not exist");
852+
err = -EINVAL;
853+
goto errout;
854+
}
855+
837856
tb = fib_get_table(net, cfg.fc_table);
838857
if (!tb) {
839858
NL_SET_ERR_MSG(extack, "FIB table does not exist");

net/ipv4/fib_semantics.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,12 @@ int fib_nh_match(struct fib_config *cfg, struct fib_info *fi,
789789
if (cfg->fc_priority && cfg->fc_priority != fi->fib_priority)
790790
return 1;
791791

792+
if (cfg->fc_nh_id) {
793+
if (fi->nh && cfg->fc_nh_id == fi->nh->id)
794+
return 0;
795+
return 1;
796+
}
797+
792798
if (cfg->fc_oif || cfg->fc_gw_family) {
793799
struct fib_nh *nh = fib_info_nh(fi, 0);
794800

@@ -1302,6 +1308,15 @@ struct fib_info *fib_create_info(struct fib_config *cfg,
13021308
goto err_inval;
13031309
}
13041310

1311+
if (cfg->fc_nh_id) {
1312+
nh = nexthop_find_by_id(net, cfg->fc_nh_id);
1313+
if (!nh) {
1314+
NL_SET_ERR_MSG(extack, "Nexthop id does not exist");
1315+
goto err_inval;
1316+
}
1317+
nhs = 0;
1318+
}
1319+
13051320
#ifdef CONFIG_IP_ROUTE_MULTIPATH
13061321
if (cfg->fc_mp) {
13071322
nhs = fib_count_nexthops(cfg->fc_mp, cfg->fc_mp_len, extack);

0 commit comments

Comments
 (0)