Commit f35b794b authored by David Ahern's avatar David Ahern Committed by David S. Miller

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: default avatarDavid Ahern <dsahern@gmail.com>
Reviewed-by: default avatarIdo Schimmel <idosch@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 1550c171
...@@ -32,10 +32,11 @@ struct fib_config { ...@@ -32,10 +32,11 @@ struct fib_config {
u8 fc_protocol; u8 fc_protocol;
u8 fc_scope; u8 fc_scope;
u8 fc_type; u8 fc_type;
/* 3 bytes unused */ u8 fc_gw_family;
/* 2 bytes unused */
u32 fc_table; u32 fc_table;
__be32 fc_dst; __be32 fc_dst;
__be32 fc_gw; __be32 fc_gw4;
int fc_oif; int fc_oif;
u32 fc_flags; u32 fc_flags;
u32 fc_priority; u32 fc_priority;
......
...@@ -558,7 +558,8 @@ static int rtentry_to_fib_config(struct net *net, int cmd, struct rtentry *rt, ...@@ -558,7 +558,8 @@ static int rtentry_to_fib_config(struct net *net, int cmd, struct rtentry *rt,
if (rt->rt_gateway.sa_family == AF_INET && addr) { if (rt->rt_gateway.sa_family == AF_INET && addr) {
unsigned int addr_type; unsigned int addr_type;
cfg->fc_gw = addr; cfg->fc_gw4 = addr;
cfg->fc_gw_family = AF_INET;
addr_type = inet_addr_type_table(net, addr, cfg->fc_table); addr_type = inet_addr_type_table(net, addr, cfg->fc_table);
if (rt->rt_flags & RTF_GATEWAY && if (rt->rt_flags & RTF_GATEWAY &&
addr_type == RTN_UNICAST) addr_type == RTN_UNICAST)
...@@ -568,7 +569,7 @@ static int rtentry_to_fib_config(struct net *net, int cmd, struct rtentry *rt, ...@@ -568,7 +569,7 @@ static int rtentry_to_fib_config(struct net *net, int cmd, struct rtentry *rt,
if (cmd == SIOCDELRT) if (cmd == SIOCDELRT)
return 0; return 0;
if (rt->rt_flags & RTF_GATEWAY && !cfg->fc_gw) if (rt->rt_flags & RTF_GATEWAY && !cfg->fc_gw_family)
return -EINVAL; return -EINVAL;
if (cfg->fc_scope == RT_SCOPE_NOWHERE) if (cfg->fc_scope == RT_SCOPE_NOWHERE)
...@@ -708,7 +709,8 @@ static int rtm_to_fib_config(struct net *net, struct sk_buff *skb, ...@@ -708,7 +709,8 @@ static int rtm_to_fib_config(struct net *net, struct sk_buff *skb,
cfg->fc_oif = nla_get_u32(attr); cfg->fc_oif = nla_get_u32(attr);
break; break;
case RTA_GATEWAY: case RTA_GATEWAY:
cfg->fc_gw = nla_get_be32(attr); cfg->fc_gw_family = AF_INET;
cfg->fc_gw4 = nla_get_be32(attr);
break; break;
case RTA_VIA: case RTA_VIA:
NL_SET_ERR_MSG(extack, "IPv4 does not support RTA_VIA attribute"); NL_SET_ERR_MSG(extack, "IPv4 does not support RTA_VIA attribute");
......
...@@ -511,8 +511,8 @@ int fib_nh_init(struct net *net, struct fib_nh *nh, ...@@ -511,8 +511,8 @@ int fib_nh_init(struct net *net, struct fib_nh *nh,
goto init_failure; goto init_failure;
nh->fib_nh_oif = cfg->fc_oif; nh->fib_nh_oif = cfg->fc_oif;
if (cfg->fc_gw) { if (cfg->fc_gw_family == AF_INET) {
nh->fib_nh_gw4 = cfg->fc_gw; nh->fib_nh_gw4 = cfg->fc_gw4;
nh->fib_nh_gw_family = AF_INET; nh->fib_nh_gw_family = AF_INET;
} }
nh->fib_nh_flags = cfg->fc_flags; nh->fib_nh_flags = cfg->fc_flags;
...@@ -589,8 +589,10 @@ static int fib_get_nhs(struct fib_info *fi, struct rtnexthop *rtnh, ...@@ -589,8 +589,10 @@ static int fib_get_nhs(struct fib_info *fi, struct rtnexthop *rtnh,
struct nlattr *nla, *attrs = rtnh_attrs(rtnh); struct nlattr *nla, *attrs = rtnh_attrs(rtnh);
nla = nla_find(attrs, attrlen, RTA_GATEWAY); nla = nla_find(attrs, attrlen, RTA_GATEWAY);
if (nla) if (nla) {
fib_cfg.fc_gw = nla_get_in_addr(nla); fib_cfg.fc_gw_family = AF_INET;
fib_cfg.fc_gw4 = nla_get_in_addr(nla);
}
nla = nla_find(attrs, attrlen, RTA_FLOW); nla = nla_find(attrs, attrlen, RTA_FLOW);
if (nla) if (nla)
...@@ -616,11 +618,15 @@ static int fib_get_nhs(struct fib_info *fi, struct rtnexthop *rtnh, ...@@ -616,11 +618,15 @@ static int fib_get_nhs(struct fib_info *fi, struct rtnexthop *rtnh,
"Nexthop device index does not match RTA_OIF"); "Nexthop device index does not match RTA_OIF");
goto errout; goto errout;
} }
if (cfg->fc_gw && fi->fib_nh->fib_nh_gw4 != cfg->fc_gw) { if (cfg->fc_gw_family) {
if (cfg->fc_gw_family != fi->fib_nh->fib_nh_gw_family ||
(cfg->fc_gw_family == AF_INET &&
fi->fib_nh->fib_nh_gw4 != cfg->fc_gw4)) {
NL_SET_ERR_MSG(extack, NL_SET_ERR_MSG(extack,
"Nexthop gateway does not match RTA_GATEWAY"); "Nexthop gateway does not match RTA_GATEWAY");
goto errout; goto errout;
} }
}
#ifdef CONFIG_IP_ROUTE_CLASSID #ifdef CONFIG_IP_ROUTE_CLASSID
if (cfg->fc_flow && fi->fib_nh->nh_tclassid != cfg->fc_flow) { if (cfg->fc_flow && fi->fib_nh->nh_tclassid != cfg->fc_flow) {
NL_SET_ERR_MSG(extack, NL_SET_ERR_MSG(extack,
...@@ -719,7 +725,7 @@ int fib_nh_match(struct fib_config *cfg, struct fib_info *fi, ...@@ -719,7 +725,7 @@ int fib_nh_match(struct fib_config *cfg, struct fib_info *fi,
if (cfg->fc_priority && cfg->fc_priority != fi->fib_priority) if (cfg->fc_priority && cfg->fc_priority != fi->fib_priority)
return 1; return 1;
if (cfg->fc_oif || cfg->fc_gw) { if (cfg->fc_oif || cfg->fc_gw_family) {
if (cfg->fc_encap) { if (cfg->fc_encap) {
if (fib_encap_match(cfg->fc_encap_type, cfg->fc_encap, if (fib_encap_match(cfg->fc_encap_type, cfg->fc_encap,
fi->fib_nh, cfg, extack)) fi->fib_nh, cfg, extack))
...@@ -730,10 +736,16 @@ int fib_nh_match(struct fib_config *cfg, struct fib_info *fi, ...@@ -730,10 +736,16 @@ int fib_nh_match(struct fib_config *cfg, struct fib_info *fi,
cfg->fc_flow != fi->fib_nh->nh_tclassid) cfg->fc_flow != fi->fib_nh->nh_tclassid)
return 1; return 1;
#endif #endif
if ((!cfg->fc_oif || cfg->fc_oif == fi->fib_nh->fib_nh_oif) && if ((cfg->fc_oif && cfg->fc_oif != fi->fib_nh->fib_nh_oif) ||
(!cfg->fc_gw || cfg->fc_gw == fi->fib_nh->fib_nh_gw4)) (cfg->fc_gw_family &&
return 0; cfg->fc_gw_family != fi->fib_nh->fib_nh_gw_family))
return 1; return 1;
if (cfg->fc_gw_family == AF_INET &&
cfg->fc_gw4 != fi->fib_nh->fib_nh_gw4)
return 1;
return 0;
} }
#ifdef CONFIG_IP_ROUTE_MULTIPATH #ifdef CONFIG_IP_ROUTE_MULTIPATH
...@@ -1204,7 +1216,7 @@ struct fib_info *fib_create_info(struct fib_config *cfg, ...@@ -1204,7 +1216,7 @@ struct fib_info *fib_create_info(struct fib_config *cfg,
goto failure; goto failure;
if (fib_props[cfg->fc_type].error) { if (fib_props[cfg->fc_type].error) {
if (cfg->fc_gw || cfg->fc_oif || cfg->fc_mp) { if (cfg->fc_gw_family || cfg->fc_oif || cfg->fc_mp) {
NL_SET_ERR_MSG(extack, NL_SET_ERR_MSG(extack,
"Gateway, device and multipath can not be specified for this route type"); "Gateway, device and multipath can not be specified for this route type");
goto err_inval; goto err_inval;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment