From: David Ahern <dsahern@kernel.org>
To: davem@davemloft.net, netdev@vger.kernel.org
Cc: idosch@mellanox.com, jiri@mellanox.com, David Ahern <dsahern@gmail.com>
Subject: [PATCH v2 net-next 06/18] ipv4: Add support to rtable for ipv6 gateway
Date: Fri, 5 Apr 2019 16:30:29 -0700 [thread overview]
Message-ID: <20190405233041.30775-7-dsahern@kernel.org> (raw)
In-Reply-To: <20190405233041.30775-1-dsahern@kernel.org>
From: David Ahern <dsahern@gmail.com>
Add support for an IPv6 gateway to rtable. Since a gateway is either
IPv4 or IPv6, make it a union with rt_gw4 where rt_gw_family decides
which address is in use.
When dumping the route data, encode an ipv6 nexthop using RTA_VIA.
Signed-off-by: David Ahern <dsahern@gmail.com>
Reviewed-by: Ido Schimmel <idosch@mellanox.com>
---
.../net/ethernet/mellanox/mlxsw/spectrum_span.c | 3 +++
include/net/route.h | 5 +++-
net/ipv4/route.c | 31 ++++++++++++++++++----
net/ipv4/xfrm4_policy.c | 2 ++
net/mpls/mpls_iptunnel.c | 5 ++--
5 files changed, 38 insertions(+), 8 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c
index 133a497e3457..560a60e522f9 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c
@@ -318,6 +318,9 @@ mlxsw_sp_span_gretap4_route(const struct net_device *to_dev,
*saddrp = fl4.saddr;
if (rt->rt_gw_family == AF_INET)
*daddrp = rt->rt_gw4;
+ /* can not offload if route has an IPv6 gateway */
+ else if (rt->rt_gw_family == AF_INET6)
+ dev = NULL;
out:
ip_rt_put(rt);
diff --git a/include/net/route.h b/include/net/route.h
index 96912b099c08..5d28a2509b58 100644
--- a/include/net/route.h
+++ b/include/net/route.h
@@ -60,7 +60,10 @@ struct rtable {
int rt_iif;
/* Info on neighbour */
- __be32 rt_gw4;
+ union {
+ __be32 rt_gw4;
+ struct in6_addr rt_gw6;
+ };
/* Miscellaneous cached information */
u32 rt_mtu_locked:1,
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index b77b4950d0c7..6e58acf0a87b 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -1535,14 +1535,20 @@ static void rt_set_nexthop(struct rtable *rt, __be32 daddr,
if (fi) {
struct fib_nh_common *nhc = FIB_RES_NHC(*res);
- struct fib_nh *nh = container_of(nhc, struct fib_nh, nh_common);
+ struct fib_nh *nh;
- if (nh->fib_nh_gw4 && nh->fib_nh_scope == RT_SCOPE_LINK) {
- rt->rt_gw4 = nh->fib_nh_gw4;
- rt->rt_gw_family = AF_INET;
+ if (nhc->nhc_gw_family && nhc->nhc_scope == RT_SCOPE_LINK) {
+ rt->rt_gw_family = nhc->nhc_gw_family;
+ /* only INET and INET6 are supported */
+ if (likely(nhc->nhc_gw_family == AF_INET))
+ rt->rt_gw4 = nhc->nhc_gw.ipv4;
+ else
+ rt->rt_gw6 = nhc->nhc_gw.ipv6;
}
+
ip_dst_init_metrics(&rt->dst, fi->fib_metrics);
+ nh = container_of(nhc, struct fib_nh, nh_common);
#ifdef CONFIG_IP_ROUTE_CLASSID
rt->dst.tclassid = nh->nh_tclassid;
#endif
@@ -2600,6 +2606,8 @@ struct dst_entry *ipv4_blackhole_route(struct net *net, struct dst_entry *dst_or
rt->rt_gw_family = ort->rt_gw_family;
if (rt->rt_gw_family == AF_INET)
rt->rt_gw4 = ort->rt_gw4;
+ else if (rt->rt_gw_family == AF_INET6)
+ rt->rt_gw6 = ort->rt_gw6;
INIT_LIST_HEAD(&rt->rt_uncached);
}
@@ -2679,8 +2687,21 @@ static int rt_fill_info(struct net *net, __be32 dst, __be32 src,
goto nla_put_failure;
}
if (rt->rt_gw_family == AF_INET &&
- nla_put_in_addr(skb, RTA_GATEWAY, rt->rt_gw4))
+ nla_put_in_addr(skb, RTA_GATEWAY, rt->rt_gw4)) {
goto nla_put_failure;
+ } else if (rt->rt_gw_family == AF_INET6) {
+ int alen = sizeof(struct in6_addr);
+ struct nlattr *nla;
+ struct rtvia *via;
+
+ nla = nla_reserve(skb, RTA_VIA, alen + 2);
+ if (!nla)
+ goto nla_put_failure;
+
+ via = nla_data(nla);
+ via->rtvia_family = AF_INET6;
+ memcpy(via->rtvia_addr, &rt->rt_gw6, alen);
+ }
expires = rt->dst.expires;
if (expires) {
diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
index ee53a91526e5..72d19b1838ed 100644
--- a/net/ipv4/xfrm4_policy.c
+++ b/net/ipv4/xfrm4_policy.c
@@ -100,6 +100,8 @@ static int xfrm4_fill_dst(struct xfrm_dst *xdst, struct net_device *dev,
xdst->u.rt.rt_gw_family = rt->rt_gw_family;
if (rt->rt_gw_family == AF_INET)
xdst->u.rt.rt_gw4 = rt->rt_gw4;
+ else if (rt->rt_gw_family == AF_INET6)
+ xdst->u.rt.rt_gw6 = rt->rt_gw6;
xdst->u.rt.rt_pmtu = rt->rt_pmtu;
xdst->u.rt.rt_mtu_locked = rt->rt_mtu_locked;
INIT_LIST_HEAD(&xdst->u.rt.rt_uncached);
diff --git a/net/mpls/mpls_iptunnel.c b/net/mpls/mpls_iptunnel.c
index 1f61b4e53686..2619c2fbea93 100644
--- a/net/mpls/mpls_iptunnel.c
+++ b/net/mpls/mpls_iptunnel.c
@@ -141,8 +141,9 @@ static int mpls_xmit(struct sk_buff *skb)
if (rt->rt_gw_family == AF_INET)
err = neigh_xmit(NEIGH_ARP_TABLE, out_dev, &rt->rt_gw4,
skb);
- else
- err = -EAFNOSUPPORT;
+ else if (rt->rt_gw_family == AF_INET6)
+ err = neigh_xmit(NEIGH_ND_TABLE, out_dev, &rt->rt_gw6,
+ skb);
} else if (rt6) {
if (ipv6_addr_v4mapped(&rt6->rt6i_gateway)) {
/* 6PE (RFC 4798) */
--
2.11.0
next prev parent reply other threads:[~2019-04-05 23:30 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-05 23:30 [PATCH v2 net-next 00/18] ipv4: Enable support for IPv6 gateway with IPv4 routes David Ahern
2019-04-05 23:30 ` [PATCH v2 net-next 01/18] ipv6: Add fib6_nh_init and release to stubs David Ahern
2019-04-05 23:30 ` [PATCH v2 net-next 02/18] ipv6: Add neighbor helpers that use the ipv6 stub David Ahern
2019-04-05 23:30 ` [PATCH v2 net-next 03/18] net: Replace nhc_has_gw with nhc_gw_family David Ahern
2019-04-05 23:30 ` [PATCH v2 net-next 04/18] ipv4: Prepare rtable for IPv6 gateway David Ahern
2019-04-05 23:30 ` [PATCH v2 net-next 05/18] ipv4: Prepare fib_config " David Ahern
2019-04-05 23:30 ` David Ahern [this message]
2019-04-05 23:30 ` [PATCH v2 net-next 07/18] ipv4: Add support to " David Ahern
2019-04-05 23:30 ` [PATCH v2 net-next 08/18] ipv4: Refactor fib_check_nh David Ahern
2019-04-10 0:08 ` Govindarajulu Varadarajan
2019-04-10 0:43 ` David Ahern
2019-04-10 2:13 ` David Ahern
2019-04-10 5:31 ` Govindarajulu Varadarajan
2019-04-10 15:44 ` David Ahern
2019-04-05 23:30 ` [PATCH v2 net-next 09/18] ipv4: Add fib_check_nh_v6_gw David Ahern
2019-04-05 23:30 ` [PATCH v2 net-next 10/18] neighbor: Add skip_cache argument to neigh_output David Ahern
2019-04-05 23:30 ` [PATCH v2 net-next 11/18] ipv4: Add helpers for neigh lookup for nexthop David Ahern
2019-04-05 23:30 ` [PATCH v2 net-next 12/18] bpf: Handle ipv6 gateway in bpf_ipv4_fib_lookup David Ahern
2019-04-05 23:30 ` [PATCH v2 net-next 13/18] ipv4: Handle ipv6 gateway in ipv4_confirm_neigh David Ahern
2019-04-05 23:30 ` [PATCH v2 net-next 14/18] ipv4: Handle ipv6 gateway in fib_detect_death David Ahern
2019-04-05 23:30 ` [PATCH v2 net-next 15/18] ipv4: Handle ipv6 gateway in fib_good_nh David Ahern
2019-04-05 23:30 ` [PATCH v2 net-next 16/18] ipv4: Flag fib_info with a fib_nh using IPv6 gateway David Ahern
2019-04-05 23:30 ` [PATCH v2 net-next 17/18] ipv4: Allow ipv6 gateway with ipv4 routes David Ahern
2019-04-05 23:30 ` [PATCH v2 net-next 18/18] selftests: fib_tests: Add tests for ipv6 gateway with ipv4 route David Ahern
2019-04-08 22:24 ` [PATCH v2 net-next 00/18] ipv4: Enable support for IPv6 gateway with IPv4 routes David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190405233041.30775-7-dsahern@kernel.org \
--to=dsahern@kernel.org \
--cc=davem@davemloft.net \
--cc=dsahern@gmail.com \
--cc=idosch@mellanox.com \
--cc=jiri@mellanox.com \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).