[net-next 2/2] Add support for SRv6 End.DT4 action

From: Carmine Scarpitta
Date: Wed Feb 12 2020 - 20:24:52 EST


SRv6 End.DT4 is defined in the SRv6 Network Programming doc within IETF [1].

End.DT4 is used to implement IPv4 L3VPN use-cases in multi-tenants
environments. It decapsulates the received packets and does IPv4 routing
lookup in the routing table of the tenant.

At JANOG44, LINE corporation presented their multi-tenant DC architecture
using SRv6 [2]. In the slides, they reported that the linux kernel is
missing the support of SRv6 End.DT4 action.

This patch adds support to SRv6 End.DT4 action.

The iproute2 part required for this action was already implemented along
with the other supported SRv6 actions [3].

[1] https://tools.ietf.org/html/draft-ietf-spring-srv6-network-programming-08
[2] https://speakerdeck.com/line_developers/line-data-center-networking-with-srv6
[3] https://patchwork.ozlabs.org/patch/799837/

Signed-off-by: Carmine Scarpitta <carmine.scarpitta@xxxxxxxxxxx>
Acked-by: Ahmed Abdelsalam <ahmed.abdelsalam@xxxxxxx>
Acked-by: Andrea Mayer <andrea.mayer@xxxxxxxxxxx>
Acked-by: Paolo Lungaroni <paolo.lungaroni@xxxxxxx>
---
net/ipv6/seg6_local.c | 49 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 49 insertions(+)

diff --git a/net/ipv6/seg6_local.c b/net/ipv6/seg6_local.c
index 7cbc19731997..d54a921ea96d 100644
--- a/net/ipv6/seg6_local.c
+++ b/net/ipv6/seg6_local.c
@@ -151,6 +151,26 @@ static void advance_nextseg(struct ipv6_sr_hdr *srh, struct in6_addr *daddr)
*daddr = *addr;
}

+static int seg6_lookup_nexthop_v4(struct sk_buff *skb, u32 tbl_id)
+{
+ struct net *net = dev_net(skb->dev);
+ struct fib_result res;
+ struct iphdr *iph;
+ u8 tos;
+
+ iph = ip_hdr(skb);
+ tos = iph->tos & IPTOS_RT_MASK;
+
+ res.table = fib_get_table(net, tbl_id);
+ if (!res.table)
+ return -ENOENT;
+
+ skb_dst_drop(skb);
+
+ return ip_route_input_rcu(skb, iph->daddr, iph->saddr,
+ tos, skb->dev, &res, true);
+}
+
static int
seg6_lookup_any_nexthop(struct sk_buff *skb, struct in6_addr *nhaddr,
u32 tbl_id, bool local_delivery)
@@ -401,6 +421,30 @@ static int input_action_end_dx4(struct sk_buff *skb,
return -EINVAL;
}

+static int input_action_end_dt4(struct sk_buff *skb,
+ struct seg6_local_lwt *slwt)
+{
+ int err;
+
+ if (!decap_and_validate(skb, IPPROTO_IPIP))
+ goto drop;
+
+ if (!pskb_may_pull(skb, sizeof(struct iphdr)))
+ goto drop;
+
+ skb_set_transport_header(skb, sizeof(struct iphdr));
+
+ err = seg6_lookup_nexthop_v4(skb, slwt->table);
+ if (err)
+ goto drop;
+
+ return dst_input(skb);
+
+drop:
+ kfree_skb(skb);
+ return -EINVAL;
+}
+
static int input_action_end_dt6(struct sk_buff *skb,
struct seg6_local_lwt *slwt)
{
@@ -589,6 +633,11 @@ static struct seg6_action_desc seg6_action_table[] = {
.attrs = (1 << SEG6_LOCAL_NH4),
.input = input_action_end_dx4,
},
+ {
+ .action = SEG6_LOCAL_ACTION_END_DT4,
+ .attrs = (1 << SEG6_LOCAL_TABLE),
+ .input = input_action_end_dt4,
+ },
{
.action = SEG6_LOCAL_ACTION_END_DT6,
.attrs = (1 << SEG6_LOCAL_TABLE),
--
2.17.1