Skip to content

Commit f35b794

Browse files
dsaherndavem330
authored andcommitted
ipv4: Prepare fib_config for IPv6 gateway
Similar to rtable, fib_config needs to allow the gateway to be either an IPv4 or an IPv6 address. To that end, rename fc_gw to fc_gw4 to mean an IPv4 address and add fc_gw_family. Checks on 'is a gateway set' are changed to see if fc_gw_family is set. In the process prepare the code for a fc_gw_family == AF_INET6. Signed-off-by: David Ahern <[email protected]> Reviewed-by: Ido Schimmel <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 1550c17 commit f35b794

File tree

3 files changed

+34
-19
lines changed

3 files changed

+34
-19
lines changed

include/net/ip_fib.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ struct fib_config {
3232
u8 fc_protocol;
3333
u8 fc_scope;
3434
u8 fc_type;
35-
/* 3 bytes unused */
35+
u8 fc_gw_family;
36+
/* 2 bytes unused */
3637
u32 fc_table;
3738
__be32 fc_dst;
38-
__be32 fc_gw;
39+
__be32 fc_gw4;
3940
int fc_oif;
4041
u32 fc_flags;
4142
u32 fc_priority;

net/ipv4/fib_frontend.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,8 @@ static int rtentry_to_fib_config(struct net *net, int cmd, struct rtentry *rt,
558558
if (rt->rt_gateway.sa_family == AF_INET && addr) {
559559
unsigned int addr_type;
560560

561-
cfg->fc_gw = addr;
561+
cfg->fc_gw4 = addr;
562+
cfg->fc_gw_family = AF_INET;
562563
addr_type = inet_addr_type_table(net, addr, cfg->fc_table);
563564
if (rt->rt_flags & RTF_GATEWAY &&
564565
addr_type == RTN_UNICAST)
@@ -568,7 +569,7 @@ static int rtentry_to_fib_config(struct net *net, int cmd, struct rtentry *rt,
568569
if (cmd == SIOCDELRT)
569570
return 0;
570571

571-
if (rt->rt_flags & RTF_GATEWAY && !cfg->fc_gw)
572+
if (rt->rt_flags & RTF_GATEWAY && !cfg->fc_gw_family)
572573
return -EINVAL;
573574

574575
if (cfg->fc_scope == RT_SCOPE_NOWHERE)
@@ -708,7 +709,8 @@ static int rtm_to_fib_config(struct net *net, struct sk_buff *skb,
708709
cfg->fc_oif = nla_get_u32(attr);
709710
break;
710711
case RTA_GATEWAY:
711-
cfg->fc_gw = nla_get_be32(attr);
712+
cfg->fc_gw_family = AF_INET;
713+
cfg->fc_gw4 = nla_get_be32(attr);
712714
break;
713715
case RTA_VIA:
714716
NL_SET_ERR_MSG(extack, "IPv4 does not support RTA_VIA attribute");

net/ipv4/fib_semantics.c

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -511,8 +511,8 @@ int fib_nh_init(struct net *net, struct fib_nh *nh,
511511
goto init_failure;
512512

513513
nh->fib_nh_oif = cfg->fc_oif;
514-
if (cfg->fc_gw) {
515-
nh->fib_nh_gw4 = cfg->fc_gw;
514+
if (cfg->fc_gw_family == AF_INET) {
515+
nh->fib_nh_gw4 = cfg->fc_gw4;
516516
nh->fib_nh_gw_family = AF_INET;
517517
}
518518
nh->fib_nh_flags = cfg->fc_flags;
@@ -589,8 +589,10 @@ static int fib_get_nhs(struct fib_info *fi, struct rtnexthop *rtnh,
589589
struct nlattr *nla, *attrs = rtnh_attrs(rtnh);
590590

591591
nla = nla_find(attrs, attrlen, RTA_GATEWAY);
592-
if (nla)
593-
fib_cfg.fc_gw = nla_get_in_addr(nla);
592+
if (nla) {
593+
fib_cfg.fc_gw_family = AF_INET;
594+
fib_cfg.fc_gw4 = nla_get_in_addr(nla);
595+
}
594596

595597
nla = nla_find(attrs, attrlen, RTA_FLOW);
596598
if (nla)
@@ -616,10 +618,14 @@ static int fib_get_nhs(struct fib_info *fi, struct rtnexthop *rtnh,
616618
"Nexthop device index does not match RTA_OIF");
617619
goto errout;
618620
}
619-
if (cfg->fc_gw && fi->fib_nh->fib_nh_gw4 != cfg->fc_gw) {
620-
NL_SET_ERR_MSG(extack,
621-
"Nexthop gateway does not match RTA_GATEWAY");
622-
goto errout;
621+
if (cfg->fc_gw_family) {
622+
if (cfg->fc_gw_family != fi->fib_nh->fib_nh_gw_family ||
623+
(cfg->fc_gw_family == AF_INET &&
624+
fi->fib_nh->fib_nh_gw4 != cfg->fc_gw4)) {
625+
NL_SET_ERR_MSG(extack,
626+
"Nexthop gateway does not match RTA_GATEWAY");
627+
goto errout;
628+
}
623629
}
624630
#ifdef CONFIG_IP_ROUTE_CLASSID
625631
if (cfg->fc_flow && fi->fib_nh->nh_tclassid != cfg->fc_flow) {
@@ -719,7 +725,7 @@ int fib_nh_match(struct fib_config *cfg, struct fib_info *fi,
719725
if (cfg->fc_priority && cfg->fc_priority != fi->fib_priority)
720726
return 1;
721727

722-
if (cfg->fc_oif || cfg->fc_gw) {
728+
if (cfg->fc_oif || cfg->fc_gw_family) {
723729
if (cfg->fc_encap) {
724730
if (fib_encap_match(cfg->fc_encap_type, cfg->fc_encap,
725731
fi->fib_nh, cfg, extack))
@@ -730,10 +736,16 @@ int fib_nh_match(struct fib_config *cfg, struct fib_info *fi,
730736
cfg->fc_flow != fi->fib_nh->nh_tclassid)
731737
return 1;
732738
#endif
733-
if ((!cfg->fc_oif || cfg->fc_oif == fi->fib_nh->fib_nh_oif) &&
734-
(!cfg->fc_gw || cfg->fc_gw == fi->fib_nh->fib_nh_gw4))
735-
return 0;
736-
return 1;
739+
if ((cfg->fc_oif && cfg->fc_oif != fi->fib_nh->fib_nh_oif) ||
740+
(cfg->fc_gw_family &&
741+
cfg->fc_gw_family != fi->fib_nh->fib_nh_gw_family))
742+
return 1;
743+
744+
if (cfg->fc_gw_family == AF_INET &&
745+
cfg->fc_gw4 != fi->fib_nh->fib_nh_gw4)
746+
return 1;
747+
748+
return 0;
737749
}
738750

739751
#ifdef CONFIG_IP_ROUTE_MULTIPATH
@@ -1204,7 +1216,7 @@ struct fib_info *fib_create_info(struct fib_config *cfg,
12041216
goto failure;
12051217

12061218
if (fib_props[cfg->fc_type].error) {
1207-
if (cfg->fc_gw || cfg->fc_oif || cfg->fc_mp) {
1219+
if (cfg->fc_gw_family || cfg->fc_oif || cfg->fc_mp) {
12081220
NL_SET_ERR_MSG(extack,
12091221
"Gateway, device and multipath can not be specified for this route type");
12101222
goto err_inval;

0 commit comments

Comments
 (0)