[ovs-dev] [PATCH 1/1] datapath: Add pre_tunnel option to tunneling code

Kyle Mestery kmestery at cisco.com
Fri Dec 7 21:47:13 UTC 2012


Add support to the tunneling code for a "pre_tunnel"
function. This allows the tunneling code to perform
operations on the packet before the outer IP header is
added.

A tunneling protocol such as LISP may require this, as it needs
to remove the MAC header before applying the LISP header.

Signed-off-by: Kyle Mestery <kmestery at cisco.com>
---
 datapath/tunnel.c       | 5 +++++
 datapath/tunnel.h       | 7 +++++++
 datapath/vport-capwap.c | 1 +
 datapath/vport-gre.c    | 2 ++
 datapath/vport-vxlan.c  | 1 +
 5 files changed, 16 insertions(+)

diff --git a/datapath/tunnel.c b/datapath/tunnel.c
index 1db60d2..ea6f7a9 100644
--- a/datapath/tunnel.c
+++ b/datapath/tunnel.c
@@ -988,6 +988,11 @@ int ovs_tnl_send(struct vport *vport, struct sk_buff *skb)
 		if (unlikely(vlan_deaccel_tag(skb)))
 			goto next;
 
+		/* Pre tunnel header work done by tunneling layer. */
+		if (tnl_vport->tnl_ops->pre_tunnel)
+			skb = tnl_vport->tnl_ops->pre_tunnel(vport, mutable,
+							     skb);
+
 		skb_push(skb, tunnel_hlen);
 		skb_reset_network_header(skb);
 		skb_set_transport_header(skb, sizeof(struct iphdr));
diff --git a/datapath/tunnel.h b/datapath/tunnel.h
index b7de7a9..12e7f19 100644
--- a/datapath/tunnel.h
+++ b/datapath/tunnel.h
@@ -135,6 +135,13 @@ struct tnl_ops {
 	int (*hdr_len)(const struct tnl_mutable_config *,
 		       const struct ovs_key_ipv4_tunnel *);
 	/*
+	 * Some tunnels may need to perform actions on the packet before
+	 * appending the outer IP header of the tunneled packet.
+	 */
+	struct sk_buff *(*pre_tunnel)(const struct vport *,
+				      const struct tnl_mutable_config *,
+				      struct sk_buff *);
+	/*
 	 * Returns a linked list of SKBs with tunnel headers (multiple
 	 * packets may be generated in the event of fragmentation).  Space
 	 * will have already been allocated at the start of the packet equal
diff --git a/datapath/vport-capwap.c b/datapath/vport-capwap.c
index 5f31732..7f304e0 100644
--- a/datapath/vport-capwap.c
+++ b/datapath/vport-capwap.c
@@ -355,6 +355,7 @@ static const struct tnl_ops capwap_tnl_ops = {
 	.tunnel_type	= TNL_T_PROTO_CAPWAP,
 	.ipproto	= IPPROTO_UDP,
 	.hdr_len	= capwap_hdr_len,
+	.pre_tunnel	= NULL,
 	.build_header	= capwap_build_header,
 };
 
diff --git a/datapath/vport-gre.c b/datapath/vport-gre.c
index 3c13499..3d95584 100644
--- a/datapath/vport-gre.c
+++ b/datapath/vport-gre.c
@@ -423,6 +423,7 @@ static const struct tnl_ops gre_tnl_ops = {
 	.tunnel_type	= TNL_T_PROTO_GRE,
 	.ipproto	= IPPROTO_GRE,
 	.hdr_len	= gre_hdr_len,
+	.pre_tunnel	= NULL,
 	.build_header	= gre_build_header,
 };
 
@@ -440,6 +441,7 @@ static const struct tnl_ops gre64_tnl_ops = {
 	.tunnel_type	= TNL_T_PROTO_GRE64,
 	.ipproto	= IPPROTO_GRE,
 	.hdr_len	= gre_hdr_len,
+	.pre_tunnel	= NULL,
 	.build_header	= gre_build_header,
 };
 
diff --git a/datapath/vport-vxlan.c b/datapath/vport-vxlan.c
index 137e5d8..4be7825 100644
--- a/datapath/vport-vxlan.c
+++ b/datapath/vport-vxlan.c
@@ -329,6 +329,7 @@ static const struct tnl_ops ovs_vxlan_tnl_ops = {
 	.tunnel_type	= TNL_T_PROTO_VXLAN,
 	.ipproto	= IPPROTO_UDP,
 	.hdr_len	= vxlan_hdr_len,
+	.pre_tunnel	= NULL,
 	.build_header	= vxlan_build_header,
 };
 
-- 
1.7.11.7




More information about the dev mailing list