diff mbox series

[ovs-dev,v3] datapath-windows: Append tunnel info to upcall for correct template

Message ID A1225F80-A517-4AF0-AB4A-93341EE046C3@vmware.com
State Accepted
Headers show
Series [ovs-dev,v3] datapath-windows: Append tunnel info to upcall for correct template | expand

Commit Message

Li,Rongqing via dev Feb. 4, 2020, 5:03 a.m. UTC
Formerly, there is no tunnel information appended in the upcall’s 
packet data, which is expected by IPFIX in userspace to calculate 
the template for exporting the sampled flow record of on egress 
tunnel port. 
To fix this, during performing OvsOutputUserspaceAction(), we 
would check whether it is initiated by the sampling on egress 
tunnel which would be indicated by the attribute as 
OVS_USERSPACE_ATTR_EGRESS_TUN_PORT in the nested attribute
list. If so, we would append the tunKey in OvsForwardingContext 
indexed by OVS_PACKET_ATTR_EGRESS_TUN_KEY to the upcall. 
Besides, at this point, the source transport port and  source ip 
address are not available in the structure, so we have to fill it in the 
way how the packet would be capsulated during performing 
OvsEncapGeneve(), which is following the 
OvsOutputUserspaceAction() unfortunately.
I have tested the IPFIX functionality with the change, we could see the 
template is correct and the expected tunnel information could be 
packed in the IPFIX packet finally. The traffic for test is generated by 
PING utility.

From d727d051c9a44a4a93e5ee5f3da3ca9b125aad29 Mon Sep 17 00:00:00 2001
From: Amber Hu <qhu@vmware.com>
Date: Thu, 30 Jan 2020 18:01:32 -0800
Subject: [PATCH v3] datapath-windows: Append tunnel info to upcall for correct
 template

Signed-off-by: Amber Hu <qhu@vmware.com>
---
 datapath-windows/ovsext/Actions.c | 24 +++++++++++++++++++++---
 datapath-windows/ovsext/Flow.c    | 12 ++++++++++++
 datapath-windows/ovsext/Tunnel.c  |  2 +-
 datapath-windows/ovsext/User.c    | 12 +++++++++---
 datapath-windows/ovsext/User.h    |  1 +
 5 files changed, 44 insertions(+), 7 deletions(-)

Comments

Alin Serdean Feb. 4, 2020, 6:40 p.m. UTC | #1
> -----Original Message-----
> From: Amber Hu <qhu@vmware.com>
> Sent: Tuesday, February 4, 2020 7:03 AM
> To: Alin Serdean <aserdean@cloudbasesolutions.com>; dev@openvswitch.org
> Cc: Qiong Wang <wqiong@vmware.com>; Wenyu Zhang
> <wenyuz@vmware.com>; Jinjun Gao <jinjung@vmware.com>
> Subject: [patch v3] datapath-windows: Append tunnel info to upcall for correct
> template
> 
> Formerly, there is no tunnel information appended in the upcall’s packet data,
> which is expected by IPFIX in userspace to calculate the template for exporting
> the sampled flow record of on egress tunnel port.
> To fix this, during performing OvsOutputUserspaceAction(), we would check
> whether it is initiated by the sampling on egress tunnel which would be indicated
> by the attribute as OVS_USERSPACE_ATTR_EGRESS_TUN_PORT in the nested
> attribute list. If so, we would append the tunKey in OvsForwardingContext
> indexed by OVS_PACKET_ATTR_EGRESS_TUN_KEY to the upcall.
> Besides, at this point, the source transport port and  source ip address are not
> available in the structure, so we have to fill it in the way how the packet would
> be capsulated during performing OvsEncapGeneve(), which is following the
> OvsOutputUserspaceAction() unfortunately.
> I have tested the IPFIX functionality with the change, we could see the template
> is correct and the expected tunnel information could be packed in the IPFIX
> packet finally. The traffic for test is generated by PING utility.
> 
> From d727d051c9a44a4a93e5ee5f3da3ca9b125aad29 Mon Sep 17 00:00:00
> 2001
> From: Amber Hu <qhu@vmware.com>
> Date: Thu, 30 Jan 2020 18:01:32 -0800
> Subject: [PATCH v3] datapath-windows: Append tunnel info to upcall for correct
> template
> 

Thank you for addressing the comments!

Acked-by: Alin Gabriel Serdean <aserdean@ovn.org>
Alin Serdean Feb. 10, 2020, 11:27 a.m. UTC | #2
Thank you for the patch, applied on master!

> -----Original Message-----
> From: Alin Serdean
> Sent: Tuesday, February 4, 2020 8:41 PM
> To: Amber Hu <qhu@vmware.com>; dev@openvswitch.org
> Cc: Qiong Wang <wqiong@vmware.com>; Wenyu Zhang
> <wenyuz@vmware.com>; Jinjun Gao <jinjung@vmware.com>
> Subject: RE: [patch v3] datapath-windows: Append tunnel info to upcall for
> correct template
> 
> > -----Original Message-----
> > From: Amber Hu <qhu@vmware.com>
> > Sent: Tuesday, February 4, 2020 7:03 AM
> > To: Alin Serdean <aserdean@cloudbasesolutions.com>;
> > dev@openvswitch.org
> > Cc: Qiong Wang <wqiong@vmware.com>; Wenyu Zhang
> <wenyuz@vmware.com>;
> > Jinjun Gao <jinjung@vmware.com>
> > Subject: [patch v3] datapath-windows: Append tunnel info to upcall for
> > correct template
> >
diff mbox series

Patch

diff --git a/datapath-windows/ovsext/Actions.c b/datapath-windows/ovsext/Actions.c
index 5c9b5c3..4a11cea 100644
--- a/datapath-windows/ovsext/Actions.c
+++ b/datapath-windows/ovsext/Actions.c
@@ -1815,10 +1815,12 @@  OvsOutputUserspaceAction(OvsForwardingContext *ovsFwdCtx,
 {
     NTSTATUS status = NDIS_STATUS_SUCCESS;
     PNL_ATTR userdataAttr;
-    PNL_ATTR queueAttr;
+    PNL_ATTR egrTunAttr = NULL;
     POVS_PACKET_QUEUE_ELEM elem;
     POVS_PACKET_HDR_INFO layers = &ovsFwdCtx->layers;
     BOOLEAN isRecv = FALSE;
+    OVS_FWD_INFO fwdInfo;
+    OvsIPv4TunnelKey tunKey;
 
     POVS_VPORT_ENTRY vport = OvsFindVportByPortNo(ovsFwdCtx->switchContext,
                                                   ovsFwdCtx->srcVportNo);
@@ -1830,13 +1832,29 @@  OvsOutputUserspaceAction(OvsForwardingContext *ovsFwdCtx,
         }
     }
 
-    queueAttr = NlAttrFindNested(attr, OVS_USERSPACE_ATTR_PID);
     userdataAttr = NlAttrFindNested(attr, OVS_USERSPACE_ATTR_USERDATA);
+    /* Indicate the packet is from egress-tunnel direction */
+    egrTunAttr = NlAttrFindNested(attr, OVS_USERSPACE_ATTR_EGRESS_TUN_PORT);
+
+    /* Fill tunnel key to export to usersspace to calculate the template id */
+    if (egrTunAttr) {
+        RtlZeroMemory(&tunKey,  sizeof tunKey);
+        RtlCopyMemory(&tunKey, &ovsFwdCtx->tunKey, sizeof tunKey);
+        if (!tunKey.src) {
+            status = OvsLookupIPFwdInfo(tunKey.src, tunKey.dst, &fwdInfo);
+            if (status == NDIS_STATUS_SUCCESS && tunKey.dst == fwdInfo.dstIpAddr) {
+                tunKey.src = fwdInfo.srcIpAddr;
+            }
+        }
+        tunKey.flow_hash = tunKey.flow_hash ? tunKey.flow_hash : MAXINT16;
+    }
 
     elem = OvsCreateQueueNlPacket(NlAttrData(userdataAttr),
                                   NlAttrGetSize(userdataAttr),
                                   OVS_PACKET_CMD_ACTION,
-                                  vport, key, ovsFwdCtx->curNbl,
+                                  vport, key,
+                                  egrTunAttr ? &(tunKey) : NULL,
+                                  ovsFwdCtx->curNbl,
                                   NET_BUFFER_LIST_FIRST_NB(ovsFwdCtx->curNbl),
                                   isRecv,
                                   layers);
diff --git a/datapath-windows/ovsext/Flow.c b/datapath-windows/ovsext/Flow.c
index fdb1010..ac0582c 100644
--- a/datapath-windows/ovsext/Flow.c
+++ b/datapath-windows/ovsext/Flow.c
@@ -1094,6 +1094,18 @@  MapFlowTunKeyToNlKey(PNL_BUFFER nlBuf,
         goto done;
     }
 
+    if (!NlMsgPutTailU16(nlBuf, OVS_TUNNEL_KEY_ATTR_TP_SRC,
+                         tunKey->flow_hash)) {
+        rc = STATUS_UNSUCCESSFUL;
+        goto done;
+    }
+
+    if (!NlMsgPutTailU16(nlBuf, OVS_TUNNEL_KEY_ATTR_TP_DST,
+                         tunKey->dst_port)) {
+        rc = STATUS_UNSUCCESSFUL;
+        goto done;
+    }
+
 done:
     NlMsgEndNested(nlBuf, offset);
 error_nested_start:
diff --git a/datapath-windows/ovsext/Tunnel.c b/datapath-windows/ovsext/Tunnel.c
index ad2c254..5d1be80 100644
--- a/datapath-windows/ovsext/Tunnel.c
+++ b/datapath-windows/ovsext/Tunnel.c
@@ -308,7 +308,7 @@  OvsInjectPacketThroughActions(PNET_BUFFER_LIST pNbl,
 
             datapath->misses++;
             elem = OvsCreateQueueNlPacket(NULL, 0, OVS_PACKET_CMD_MISS,
-                                          vport, &key, pNbl, curNb,
+                                          vport, &key, NULL, pNbl, curNb,
                                           TRUE, &layers);
             if (elem) {
                 /* Complete the packet since it was copied to user buffer. */
diff --git a/datapath-windows/ovsext/User.c b/datapath-windows/ovsext/User.c
index ed1fcbe..ee0e38d 100644
--- a/datapath-windows/ovsext/User.c
+++ b/datapath-windows/ovsext/User.c
@@ -830,7 +830,7 @@  OvsCreateAndAddPackets(PVOID userData,
     nb = NET_BUFFER_LIST_FIRST_NB(nbl);
     while (nb) {
         elem = OvsCreateQueueNlPacket(userData, userDataLen,
-                                    cmd, vport, key, nbl, nb,
+                                    cmd, vport, key, NULL, nbl, nb,
                                     isRecv, hdrInfo);
         if (elem) {
             InsertTailList(list, &elem->link);
@@ -1013,6 +1013,7 @@  OvsCreateQueueNlPacket(PVOID userData,
                        UINT32 cmd,
                        POVS_VPORT_ENTRY vport,
                        OvsFlowKey *key,
+                       OvsIPv4TunnelKey *tunnelKey,
                        PNET_BUFFER_LIST nbl,
                        PNET_BUFFER nb,
                        BOOLEAN isRecv,
@@ -1025,7 +1026,6 @@  OvsCreateQueueNlPacket(PVOID userData,
     NDIS_TCP_IP_CHECKSUM_NET_BUFFER_LIST_INFO csumInfo;
     PNDIS_NET_BUFFER_LIST_8021Q_INFO vlanInfo = NULL;
     PVOID vlanTag;
-    OvsIPv4TunnelKey *tunnelKey = (OvsIPv4TunnelKey *)&key->tunKey;
     UINT32 pid;
     UINT32 nlMsgSize;
     NL_BUFFER nlBuf;
@@ -1127,7 +1127,13 @@  OvsCreateQueueNlPacket(PVOID userData,
         }
     }
 
-    /* XXX must send OVS_PACKET_ATTR_EGRESS_TUN_KEY if set by vswtchd */
+    /* Set OVS_PACKET_ATTR_EGRESS_TUN_KEY attribute */
+    if (tunnelKey) {
+        if (MapFlowTunKeyToNlKey(&nlBuf, tunnelKey,
+                                 OVS_PACKET_ATTR_EGRESS_TUN_KEY) != STATUS_SUCCESS) {
+            goto fail;
+        }
+    }
     if (userData){
         if (!NlMsgPutTailUnspec(&nlBuf, OVS_PACKET_ATTR_USERDATA,
                                 userData, (UINT16)userDataLen)) {
diff --git a/datapath-windows/ovsext/User.h b/datapath-windows/ovsext/User.h
index 3a42888..ccca0ba 100644
--- a/datapath-windows/ovsext/User.h
+++ b/datapath-windows/ovsext/User.h
@@ -75,6 +75,7 @@  POVS_PACKET_QUEUE_ELEM OvsCreateQueueNlPacket(PVOID userData,
                                               UINT32 cmd, 
                                               POVS_VPORT_ENTRY vport,
                                               OvsFlowKey *key,
+                                              OvsIPv4TunnelKey *tunnelKey,
                                               PNET_BUFFER_LIST nbl,
                                               PNET_BUFFER nb,
                                               BOOLEAN isRecv,