Commit 38ee7f2d authored by David Lebrun's avatar David Lebrun Committed by David S. Miller

ipv6: sr: add support for encapsulation of L2 frames

This patch implements the L2 frame encapsulation mechanism, referred to
as T.Encaps.L2 in the SRv6 specifications [1].

A new type of SRv6 tunnel mode is added (SEG6_IPTUN_MODE_L2ENCAP). It only
accepts packets with an existing MAC header (i.e., it will not work for
locally generated packets). The resulting packet looks like IPv6 -> SRH ->
Ethernet -> original L3 payload. The next header field of the SRH is set to
NEXTHDR_NONE.

[1] https://tools.ietf.org/html/draft-filsfils-spring-srv6-network-programming-01Signed-off-by: default avatarDavid Lebrun <david.lebrun@uclouvain.be>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 32d99d0b
...@@ -33,16 +33,26 @@ struct seg6_iptunnel_encap { ...@@ -33,16 +33,26 @@ struct seg6_iptunnel_encap {
enum { enum {
SEG6_IPTUN_MODE_INLINE, SEG6_IPTUN_MODE_INLINE,
SEG6_IPTUN_MODE_ENCAP, SEG6_IPTUN_MODE_ENCAP,
SEG6_IPTUN_MODE_L2ENCAP,
}; };
#ifdef __KERNEL__ #ifdef __KERNEL__
static inline size_t seg6_lwt_headroom(struct seg6_iptunnel_encap *tuninfo) static inline size_t seg6_lwt_headroom(struct seg6_iptunnel_encap *tuninfo)
{ {
int encap = (tuninfo->mode == SEG6_IPTUN_MODE_ENCAP); int head = 0;
return ((tuninfo->srh->hdrlen + 1) << 3) + switch (tuninfo->mode) {
(encap * sizeof(struct ipv6hdr)); case SEG6_IPTUN_MODE_INLINE:
break;
case SEG6_IPTUN_MODE_ENCAP:
head = sizeof(struct ipv6hdr);
break;
case SEG6_IPTUN_MODE_L2ENCAP:
return 0;
}
return ((tuninfo->srh->hdrlen + 1) << 3) + head;
} }
#endif #endif
......
...@@ -238,6 +238,22 @@ static int seg6_do_srh(struct sk_buff *skb) ...@@ -238,6 +238,22 @@ static int seg6_do_srh(struct sk_buff *skb)
if (err) if (err)
return err; return err;
skb->protocol = htons(ETH_P_IPV6);
break;
case SEG6_IPTUN_MODE_L2ENCAP:
if (!skb_mac_header_was_set(skb))
return -EINVAL;
if (pskb_expand_head(skb, skb->mac_len, 0, GFP_ATOMIC) < 0)
return -ENOMEM;
skb_mac_header_rebuild(skb);
skb_push(skb, skb->mac_len);
err = seg6_do_srh_encap(skb, tinfo->srh, NEXTHDR_NONE);
if (err)
return err;
skb->protocol = htons(ETH_P_IPV6); skb->protocol = htons(ETH_P_IPV6);
break; break;
} }
...@@ -386,6 +402,8 @@ static int seg6_build_state(struct nlattr *nla, ...@@ -386,6 +402,8 @@ static int seg6_build_state(struct nlattr *nla,
break; break;
case SEG6_IPTUN_MODE_ENCAP: case SEG6_IPTUN_MODE_ENCAP:
break; break;
case SEG6_IPTUN_MODE_L2ENCAP:
break;
default: default:
return -EINVAL; return -EINVAL;
} }
...@@ -409,8 +427,11 @@ static int seg6_build_state(struct nlattr *nla, ...@@ -409,8 +427,11 @@ static int seg6_build_state(struct nlattr *nla,
memcpy(&slwt->tuninfo, tuninfo, tuninfo_len); memcpy(&slwt->tuninfo, tuninfo, tuninfo_len);
newts->type = LWTUNNEL_ENCAP_SEG6; newts->type = LWTUNNEL_ENCAP_SEG6;
newts->flags |= LWTUNNEL_STATE_OUTPUT_REDIRECT | newts->flags |= LWTUNNEL_STATE_INPUT_REDIRECT;
LWTUNNEL_STATE_INPUT_REDIRECT;
if (tuninfo->mode != SEG6_IPTUN_MODE_L2ENCAP)
newts->flags |= LWTUNNEL_STATE_OUTPUT_REDIRECT;
newts->headroom = seg6_lwt_headroom(tuninfo); newts->headroom = seg6_lwt_headroom(tuninfo);
*ts = newts; *ts = newts;
......
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