Skip to content

Commit 84e54fe

Browse files
williamtudavem330
authored andcommitted
gre: introduce native tunnel support for ERSPAN
The patch adds ERSPAN type II tunnel support. The implementation is based on the draft at [1]. One of the purposes is for Linux box to be able to receive ERSPAN monitoring traffic sent from the Cisco switch, by creating a ERSPAN tunnel device. In addition, the patch also adds ERSPAN TX, so Linux virtual switch can redirect monitored traffic to the ERSPAN tunnel device. The traffic will be encapsulated into ERSPAN and sent out. The implementation reuses tunnel key as ERSPAN session ID, and field 'erspan' as ERSPAN Index fields: ./ip link add dev ers11 type erspan seq key 100 erspan 123 \ local 172.16.1.200 remote 172.16.1.100 To use the above device as ERSPAN receiver, configure Nexus 5000 switch as below: monitor session 100 type erspan-source erspan-id 123 vrf default destination ip 172.16.1.200 source interface Ethernet1/11 both source interface Ethernet1/12 both no shut monitor erspan origin ip-address 172.16.1.100 global [1] https://tools.ietf.org/html/draft-foschiano-erspan-01 [2] iproute2 patch: http://marc.info/?l=linux-netdev&m=150306086924951&w=2 [3] test script: http://marc.info/?l=linux-netdev&m=150231021807304&w=2 Signed-off-by: William Tu <[email protected]> Signed-off-by: Meenakshi Vohra <[email protected]> Cc: Alexey Kuznetsov <[email protected]> Cc: Hideaki YOSHIFUJI <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent ab2fb7e commit 84e54fe

File tree

5 files changed

+335
-0
lines changed

5 files changed

+335
-0
lines changed

include/net/erspan.h

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#ifndef __LINUX_ERSPAN_H
2+
#define __LINUX_ERSPAN_H
3+
4+
/*
5+
* GRE header for ERSPAN encapsulation (8 octets [34:41]) -- 8 bytes
6+
* 0 1 2 3
7+
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
8+
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
9+
* |0|0|0|1|0|00000|000000000|00000| Protocol Type for ERSPAN |
10+
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
11+
* | Sequence Number (increments per packet per session) |
12+
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
13+
*
14+
* Note that in the above GRE header [RFC1701] out of the C, R, K, S,
15+
* s, Recur, Flags, Version fields only S (bit 03) is set to 1. The
16+
* other fields are set to zero, so only a sequence number follows.
17+
*
18+
* ERSPAN Type II header (8 octets [42:49])
19+
* 0 1 2 3
20+
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
21+
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
22+
* | Ver | VLAN | COS | En|T| Session ID |
23+
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
24+
* | Reserved | Index |
25+
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
26+
*
27+
* GRE proto ERSPAN type II = 0x88BE, type III = 0x22EB
28+
*/
29+
30+
#define ERSPAN_VERSION 0x1
31+
32+
#define VER_MASK 0xf000
33+
#define VLAN_MASK 0x0fff
34+
#define COS_MASK 0xe000
35+
#define EN_MASK 0x1800
36+
#define T_MASK 0x0400
37+
#define ID_MASK 0x03ff
38+
#define INDEX_MASK 0xfffff
39+
40+
enum erspan_encap_type {
41+
ERSPAN_ENCAP_NOVLAN = 0x0, /* originally without VLAN tag */
42+
ERSPAN_ENCAP_ISL = 0x1, /* originally ISL encapsulated */
43+
ERSPAN_ENCAP_8021Q = 0x2, /* originally 802.1Q encapsulated */
44+
ERSPAN_ENCAP_INFRAME = 0x3, /* VLAN tag perserved in frame */
45+
};
46+
47+
struct erspan_metadata {
48+
__be32 index; /* type II */
49+
};
50+
51+
struct erspanhdr {
52+
__be16 ver_vlan;
53+
#define VER_OFFSET 12
54+
__be16 session_id;
55+
#define COS_OFFSET 13
56+
#define EN_OFFSET 11
57+
#define T_OFFSET 10
58+
struct erspan_metadata md;
59+
};
60+
61+
#endif

include/net/ip_tunnels.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ struct ip_tunnel {
115115
u32 o_seqno; /* The last output seqno */
116116
int tun_hlen; /* Precalculated header length */
117117

118+
/* This field used only by ERSPAN */
119+
u32 index; /* ERSPAN type II index */
120+
118121
struct dst_cache dst_cache;
119122

120123
struct ip_tunnel_parm parms;

include/uapi/linux/if_ether.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
#define ETH_P_ATALK 0x809B /* Appletalk DDP */
6767
#define ETH_P_AARP 0x80F3 /* Appletalk AARP */
6868
#define ETH_P_8021Q 0x8100 /* 802.1Q VLAN Extended Header */
69+
#define ETH_P_ERSPAN 0x88BE /* ERSPAN type II */
6970
#define ETH_P_IPX 0x8137 /* IPX over DIX */
7071
#define ETH_P_IPV6 0x86DD /* IPv6 over bluebook */
7172
#define ETH_P_PAUSE 0x8808 /* IEEE Pause frames. See 802.3 31B */

include/uapi/linux/if_tunnel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ enum {
134134
IFLA_GRE_COLLECT_METADATA,
135135
IFLA_GRE_IGNORE_DF,
136136
IFLA_GRE_FWMARK,
137+
IFLA_GRE_ERSPAN_INDEX,
137138
__IFLA_GRE_MAX,
138139
};
139140

0 commit comments

Comments
 (0)