Skip to content

Commit 1550c17

Browse files
dsaherndavem330
authored andcommitted
ipv4: Prepare rtable for IPv6 gateway
To allow the gateway to be either an IPv4 or IPv6 address, remove rt_uses_gateway from rtable and replace with rt_gw_family. If rt_gw_family is set it implies rt_uses_gateway. Rename rt_gateway to rt_gw4 to represent the IPv4 version. Signed-off-by: David Ahern <[email protected]> Reviewed-by: Ido Schimmel <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent bdf0046 commit 1550c17

File tree

13 files changed

+57
-45
lines changed

13 files changed

+57
-45
lines changed

drivers/infiniband/core/addr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ static bool has_gateway(const struct dst_entry *dst, sa_family_t family)
351351

352352
if (family == AF_INET) {
353353
rt = container_of(dst, struct rtable, dst);
354-
return rt->rt_uses_gateway;
354+
return rt->rt_gw_family == AF_INET;
355355
}
356356

357357
rt6 = container_of(dst, struct rt6_info, dst);

drivers/infiniband/hw/nes/nes_cm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1407,7 +1407,7 @@ static int nes_addr_resolve_neigh(struct nes_vnic *nesvnic, u32 dst_ip, int arpi
14071407
if (neigh->nud_state & NUD_VALID) {
14081408
nes_debug(NES_DBG_CM, "Neighbor MAC address for 0x%08X"
14091409
" is %pM, Gateway is 0x%08X \n", dst_ip,
1410-
neigh->ha, ntohl(rt->rt_gateway));
1410+
neigh->ha, ntohl(rt->rt_gw4));
14111411

14121412
if (arpindex >= 0) {
14131413
if (ether_addr_equal(nesadapter->arp_table[arpindex].mac_addr, neigh->ha)) {

drivers/net/appletalk/ipddp.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,15 @@ static struct net_device * __init ipddp_init(void)
116116
*/
117117
static netdev_tx_t ipddp_xmit(struct sk_buff *skb, struct net_device *dev)
118118
{
119-
__be32 paddr = skb_rtable(skb)->rt_gateway;
119+
struct rtable *rtable = skb_rtable(skb);
120+
__be32 paddr = 0;
120121
struct ddpehdr *ddp;
121122
struct ipddp_route *rt;
122123
struct atalk_addr *our_addr;
123124

125+
if (rtable->rt_gw_family == AF_INET)
126+
paddr = rtable->rt_gw4;
127+
124128
spin_lock(&ipddp_route_lock);
125129

126130
/*

drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ static int mlx5e_route_lookup_ipv4(struct mlx5e_priv *priv,
7070
if (ret)
7171
return ret;
7272

73-
if (mlx5_lag_is_multipath(mdev) && !rt->rt_gateway)
73+
if (mlx5_lag_is_multipath(mdev) && rt->rt_gw_family != AF_INET)
7474
return -ENETUNREACH;
7575
#else
7676
return -EOPNOTSUPP;

drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,8 @@ mlxsw_sp_span_gretap4_route(const struct net_device *to_dev,
316316

317317
dev = rt->dst.dev;
318318
*saddrp = fl4.saddr;
319-
*daddrp = rt->rt_gateway;
319+
if (rt->rt_gw_family == AF_INET)
320+
*daddrp = rt->rt_gw4;
320321

321322
out:
322323
ip_rt_put(rt);

include/net/route.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ struct rtable {
5555
unsigned int rt_flags;
5656
__u16 rt_type;
5757
__u8 rt_is_input;
58-
__u8 rt_uses_gateway;
58+
u8 rt_gw_family;
5959

6060
int rt_iif;
6161

6262
/* Info on neighbour */
63-
__be32 rt_gateway;
63+
__be32 rt_gw4;
6464

6565
/* Miscellaneous cached information */
6666
u32 rt_mtu_locked:1,
@@ -82,8 +82,8 @@ static inline bool rt_is_output_route(const struct rtable *rt)
8282

8383
static inline __be32 rt_nexthop(const struct rtable *rt, __be32 daddr)
8484
{
85-
if (rt->rt_gateway)
86-
return rt->rt_gateway;
85+
if (rt->rt_gw_family == AF_INET)
86+
return rt->rt_gw4;
8787
return daddr;
8888
}
8989

net/atm/clip.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,8 @@ static netdev_tx_t clip_start_xmit(struct sk_buff *skb,
345345
return NETDEV_TX_OK;
346346
}
347347
rt = (struct rtable *) dst;
348-
if (rt->rt_gateway)
349-
daddr = &rt->rt_gateway;
348+
if (rt->rt_gw_family == AF_INET)
349+
daddr = &rt->rt_gw4;
350350
else
351351
daddr = &ip_hdr(skb)->daddr;
352352
n = dst_neigh_lookup(dst, daddr);

net/ipv4/inet_connection_sock.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ struct dst_entry *inet_csk_route_req(const struct sock *sk,
564564
rt = ip_route_output_flow(net, fl4, sk);
565565
if (IS_ERR(rt))
566566
goto no_route;
567-
if (opt && opt->opt.is_strictroute && rt->rt_uses_gateway)
567+
if (opt && opt->opt.is_strictroute && rt->rt_gw_family)
568568
goto route_err;
569569
rcu_read_unlock();
570570
return &rt->dst;
@@ -602,7 +602,7 @@ struct dst_entry *inet_csk_route_child_sock(const struct sock *sk,
602602
rt = ip_route_output_flow(net, fl4, sk);
603603
if (IS_ERR(rt))
604604
goto no_route;
605-
if (opt && opt->opt.is_strictroute && rt->rt_uses_gateway)
605+
if (opt && opt->opt.is_strictroute && rt->rt_gw_family)
606606
goto route_err;
607607
return &rt->dst;
608608

net/ipv4/ip_forward.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ int ip_forward(struct sk_buff *skb)
123123

124124
rt = skb_rtable(skb);
125125

126-
if (opt->is_strictroute && rt->rt_uses_gateway)
126+
if (opt->is_strictroute && rt->rt_gw_family)
127127
goto sr_failed;
128128

129129
IPCB(skb)->flags |= IPSKB_FORWARDED;

net/ipv4/ip_output.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ int __ip_queue_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl,
472472
skb_dst_set_noref(skb, &rt->dst);
473473

474474
packet_routed:
475-
if (inet_opt && inet_opt->opt.is_strictroute && rt->rt_uses_gateway)
475+
if (inet_opt && inet_opt->opt.is_strictroute && rt->rt_gw_family)
476476
goto no_route;
477477

478478
/* OK, we know where to send it, allocate and build IP header. */

net/ipv4/route.c

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -434,14 +434,13 @@ static struct neighbour *ipv4_neigh_lookup(const struct dst_entry *dst,
434434
struct sk_buff *skb,
435435
const void *daddr)
436436
{
437+
const struct rtable *rt = container_of(dst, struct rtable, dst);
437438
struct net_device *dev = dst->dev;
438439
const __be32 *pkey = daddr;
439-
const struct rtable *rt;
440440
struct neighbour *n;
441441

442-
rt = (const struct rtable *) dst;
443-
if (rt->rt_gateway)
444-
pkey = (const __be32 *) &rt->rt_gateway;
442+
if (rt->rt_gw_family == AF_INET)
443+
pkey = (const __be32 *) &rt->rt_gw4;
445444
else if (skb)
446445
pkey = &ip_hdr(skb)->daddr;
447446

@@ -453,13 +452,12 @@ static struct neighbour *ipv4_neigh_lookup(const struct dst_entry *dst,
453452

454453
static void ipv4_confirm_neigh(const struct dst_entry *dst, const void *daddr)
455454
{
455+
const struct rtable *rt = container_of(dst, struct rtable, dst);
456456
struct net_device *dev = dst->dev;
457457
const __be32 *pkey = daddr;
458-
const struct rtable *rt;
459458

460-
rt = (const struct rtable *)dst;
461-
if (rt->rt_gateway)
462-
pkey = (const __be32 *)&rt->rt_gateway;
459+
if (rt->rt_gw_family == AF_INET)
460+
pkey = (const __be32 *)&rt->rt_gw4;
463461
else if (!daddr ||
464462
(rt->rt_flags &
465463
(RTCF_MULTICAST | RTCF_BROADCAST | RTCF_LOCAL)))
@@ -629,8 +627,8 @@ static void fill_route_from_fnhe(struct rtable *rt, struct fib_nh_exception *fnh
629627

630628
if (fnhe->fnhe_gw) {
631629
rt->rt_flags |= RTCF_REDIRECTED;
632-
rt->rt_gateway = fnhe->fnhe_gw;
633-
rt->rt_uses_gateway = 1;
630+
rt->rt_gw_family = AF_INET;
631+
rt->rt_gw4 = fnhe->fnhe_gw;
634632
}
635633
}
636634

@@ -747,7 +745,7 @@ static void __ip_do_redirect(struct rtable *rt, struct sk_buff *skb, struct flow
747745
return;
748746
}
749747

750-
if (rt->rt_gateway != old_gw)
748+
if (rt->rt_gw_family != AF_INET || rt->rt_gw4 != old_gw)
751749
return;
752750

753751
in_dev = __in_dev_get_rcu(dev);
@@ -1282,7 +1280,7 @@ static unsigned int ipv4_mtu(const struct dst_entry *dst)
12821280
mtu = READ_ONCE(dst->dev->mtu);
12831281

12841282
if (unlikely(ip_mtu_locked(dst))) {
1285-
if (rt->rt_uses_gateway && mtu > 576)
1283+
if (rt->rt_gw_family && mtu > 576)
12861284
mtu = 576;
12871285
}
12881286

@@ -1410,8 +1408,10 @@ static bool rt_bind_exception(struct rtable *rt, struct fib_nh_exception *fnhe,
14101408
orig = NULL;
14111409
}
14121410
fill_route_from_fnhe(rt, fnhe);
1413-
if (!rt->rt_gateway)
1414-
rt->rt_gateway = daddr;
1411+
if (!rt->rt_gw4) {
1412+
rt->rt_gw4 = daddr;
1413+
rt->rt_gw_family = AF_INET;
1414+
}
14151415

14161416
if (do_cache) {
14171417
dst_hold(&rt->dst);
@@ -1538,8 +1538,8 @@ static void rt_set_nexthop(struct rtable *rt, __be32 daddr,
15381538
struct fib_nh *nh = container_of(nhc, struct fib_nh, nh_common);
15391539

15401540
if (nh->fib_nh_gw4 && nh->fib_nh_scope == RT_SCOPE_LINK) {
1541-
rt->rt_gateway = nh->fib_nh_gw4;
1542-
rt->rt_uses_gateway = 1;
1541+
rt->rt_gw4 = nh->fib_nh_gw4;
1542+
rt->rt_gw_family = AF_INET;
15431543
}
15441544
ip_dst_init_metrics(&rt->dst, fi->fib_metrics);
15451545

@@ -1557,8 +1557,10 @@ static void rt_set_nexthop(struct rtable *rt, __be32 daddr,
15571557
* However, if we are unsuccessful at storing this
15581558
* route into the cache we really need to set it.
15591559
*/
1560-
if (!rt->rt_gateway)
1561-
rt->rt_gateway = daddr;
1560+
if (!rt->rt_gw4) {
1561+
rt->rt_gw_family = AF_INET;
1562+
rt->rt_gw4 = daddr;
1563+
}
15621564
rt_add_uncached_list(rt);
15631565
}
15641566
} else
@@ -1591,8 +1593,8 @@ struct rtable *rt_dst_alloc(struct net_device *dev,
15911593
rt->rt_iif = 0;
15921594
rt->rt_pmtu = 0;
15931595
rt->rt_mtu_locked = 0;
1594-
rt->rt_gateway = 0;
1595-
rt->rt_uses_gateway = 0;
1596+
rt->rt_gw_family = 0;
1597+
rt->rt_gw4 = 0;
15961598
INIT_LIST_HEAD(&rt->rt_uncached);
15971599

15981600
rt->dst.output = ip_output;
@@ -2595,8 +2597,9 @@ struct dst_entry *ipv4_blackhole_route(struct net *net, struct dst_entry *dst_or
25952597
rt->rt_genid = rt_genid_ipv4(net);
25962598
rt->rt_flags = ort->rt_flags;
25972599
rt->rt_type = ort->rt_type;
2598-
rt->rt_gateway = ort->rt_gateway;
2599-
rt->rt_uses_gateway = ort->rt_uses_gateway;
2600+
rt->rt_gw_family = ort->rt_gw_family;
2601+
if (rt->rt_gw_family == AF_INET)
2602+
rt->rt_gw4 = ort->rt_gw4;
26002603

26012604
INIT_LIST_HEAD(&rt->rt_uncached);
26022605
}
@@ -2675,8 +2678,8 @@ static int rt_fill_info(struct net *net, __be32 dst, __be32 src,
26752678
if (nla_put_in_addr(skb, RTA_PREFSRC, fl4->saddr))
26762679
goto nla_put_failure;
26772680
}
2678-
if (rt->rt_uses_gateway &&
2679-
nla_put_in_addr(skb, RTA_GATEWAY, rt->rt_gateway))
2681+
if (rt->rt_gw_family == AF_INET &&
2682+
nla_put_in_addr(skb, RTA_GATEWAY, rt->rt_gw4))
26802683
goto nla_put_failure;
26812684

26822685
expires = rt->dst.expires;

net/ipv4/xfrm4_policy.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,9 @@ static int xfrm4_fill_dst(struct xfrm_dst *xdst, struct net_device *dev,
9797
xdst->u.rt.rt_flags = rt->rt_flags & (RTCF_BROADCAST | RTCF_MULTICAST |
9898
RTCF_LOCAL);
9999
xdst->u.rt.rt_type = rt->rt_type;
100-
xdst->u.rt.rt_gateway = rt->rt_gateway;
101-
xdst->u.rt.rt_uses_gateway = rt->rt_uses_gateway;
100+
xdst->u.rt.rt_gw_family = rt->rt_gw_family;
101+
if (rt->rt_gw_family == AF_INET)
102+
xdst->u.rt.rt_gw4 = rt->rt_gw4;
102103
xdst->u.rt.rt_pmtu = rt->rt_pmtu;
103104
xdst->u.rt.rt_mtu_locked = rt->rt_mtu_locked;
104105
INIT_LIST_HEAD(&xdst->u.rt.rt_uncached);

net/mpls/mpls_iptunnel.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,13 @@ static int mpls_xmit(struct sk_buff *skb)
137137

138138
mpls_stats_inc_outucastpkts(out_dev, skb);
139139

140-
if (rt)
141-
err = neigh_xmit(NEIGH_ARP_TABLE, out_dev, &rt->rt_gateway,
142-
skb);
143-
else if (rt6) {
140+
if (rt) {
141+
if (rt->rt_gw_family == AF_INET)
142+
err = neigh_xmit(NEIGH_ARP_TABLE, out_dev, &rt->rt_gw4,
143+
skb);
144+
else
145+
err = -EAFNOSUPPORT;
146+
} else if (rt6) {
144147
if (ipv6_addr_v4mapped(&rt6->rt6i_gateway)) {
145148
/* 6PE (RFC 4798) */
146149
err = neigh_xmit(NEIGH_ARP_TABLE, out_dev, &rt6->rt6i_gateway.s6_addr32[3],

0 commit comments

Comments
 (0)