From patchwork Wed Sep 23 16:15:30 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nithin Raju X-Patchwork-Id: 521760 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from archives.nicira.com (li376-54.members.linode.com [96.126.127.54]) by ozlabs.org (Postfix) with ESMTP id 0D47E1401AF for ; Thu, 24 Sep 2015 02:15:51 +1000 (AEST) Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id DF9A422C396; Wed, 23 Sep 2015 09:15:40 -0700 (PDT) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx3v1.cudamail.com (mx3.cudamail.com [64.34.241.5]) by archives.nicira.com (Postfix) with ESMTPS id 8DE3310B6C for ; Wed, 23 Sep 2015 09:15:38 -0700 (PDT) Received: from bar4.cudamail.com (bar2 [192.168.15.2]) by mx3v1.cudamail.com (Postfix) with ESMTP id 189446188CA for ; Wed, 23 Sep 2015 10:15:38 -0600 (MDT) X-ASG-Debug-ID: 1443024937-03dc216fbc1b430001-byXFYA Received: from mx3-pf3.cudamail.com ([192.168.14.3]) by bar4.cudamail.com with ESMTP id sYXe5kPgMgHOlNX0 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 23 Sep 2015 10:15:37 -0600 (MDT) X-Barracuda-Envelope-From: nithin@vmware.com X-Barracuda-RBL-Trusted-Forwarder: 192.168.14.3 Received: from unknown (HELO smtp-outbound-1.vmware.com) (208.91.2.12) by mx3-pf3.cudamail.com with ESMTPS (DHE-RSA-AES256-SHA encrypted); 23 Sep 2015 16:15:35 -0000 Received-SPF: pass (mx3-pf3.cudamail.com: SPF record at _spf.vmware.com designates 208.91.2.12 as permitted sender) X-Barracuda-Apparent-Source-IP: 208.91.2.12 X-Barracuda-RBL-IP: 208.91.2.12 Received: from sc9-mailhost1.vmware.com (sc9-mailhost1.vmware.com [10.113.161.71]) by smtp-outbound-1.vmware.com (Postfix) with ESMTP id C1DF328719 for ; Wed, 23 Sep 2015 09:18:02 -0700 (PDT) Received: from pa-dbc1122.eng.vmware.com (unknown [10.162.210.22]) by sc9-mailhost1.vmware.com (Postfix) with ESMTP id 3E5B418614; Wed, 23 Sep 2015 09:15:34 -0700 (PDT) X-CudaMail-Envelope-Sender: nithin@vmware.com From: Nithin Raju To: dev@openvswitch.org X-CudaMail-Whitelist-To: dev@openvswitch.org X-CudaMail-MID: CM-V3-922031548 X-CudaMail-DTE: 092315 X-CudaMail-Originating-IP: 208.91.2.12 Date: Wed, 23 Sep 2015 09:15:30 -0700 X-ASG-Orig-Subj: [##CM-V3-922031548##][PATCH 1/4 v2] datapath-windows: move packet read code to User.c Message-Id: <1443024933-47622-1-git-send-email-nithin@vmware.com> X-Mailer: git-send-email 1.8.5.6 X-Barracuda-Connect: UNKNOWN[192.168.14.3] X-Barracuda-Start-Time: 1443024937 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://web.cudamail.com:443/cgi-mod/mark.cgi X-ASG-Whitelist: Header =?UTF-8?B?eFwtY3VkYW1haWxcLXdoaXRlbGlzdFwtdG8=?= X-Virus-Scanned: by bsmtpd at cudamail.com X-Barracuda-BRTS-Status: 1 X-ASG-Whitelist: EmailCat (corporate) Subject: [ovs-dev] [PATCH 1/4 v2] datapath-windows: move packet read code to User.c X-BeenThere: dev@openvswitch.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dev-bounces@openvswitch.org Sender: "dev" Simple code motion. Signed-off-by: Nithin Raju Acked-by: Sairam Venugopal Acked-by: Alin Gabriel Serdean --- v2: addressed Alin's review comments --- datapath-windows/ovsext/Datapath.c | 115 ++----------------------------------- datapath-windows/ovsext/User.c | 108 ++++++++++++++++++++++++++++++++++ datapath-windows/ovsext/User.h | 7 +++ 3 files changed, 119 insertions(+), 111 deletions(-) diff --git a/datapath-windows/ovsext/Datapath.c b/datapath-windows/ovsext/Datapath.c index b7bbf80..1e16604 100644 --- a/datapath-windows/ovsext/Datapath.c +++ b/datapath-windows/ovsext/Datapath.c @@ -89,11 +89,8 @@ typedef struct _NETLINK_FAMILY { /* Handlers for the various netlink commands. */ static NetlinkCmdHandler OvsPendEventCmdHandler, - OvsPendPacketCmdHandler, OvsSubscribeEventCmdHandler, - OvsSubscribePacketCmdHandler, OvsReadEventCmdHandler, - OvsReadPacketCmdHandler, OvsNewDpCmdHandler, OvsGetDpCmdHandler, OvsSetDpCmdHandler; @@ -102,7 +99,10 @@ NetlinkCmdHandler OvsGetNetdevCmdHandler, OvsGetVportCmdHandler, OvsSetVportCmdHandler, OvsNewVportCmdHandler, - OvsDeleteVportCmdHandler; + OvsDeleteVportCmdHandler, + OvsPendPacketCmdHandler, + OvsSubscribePacketCmdHandler, + OvsReadPacketCmdHandler; static NTSTATUS HandleGetDpTransaction(POVS_USER_PARAMS_CONTEXT usrParamsCtx, UINT32 *replyLen); @@ -1593,110 +1593,3 @@ cleanup: return status; } -/* - * -------------------------------------------------------------------------- - * Handler for reading missed pacckets from the driver event queue. This - * handler is executed when user modes issues a socket receive on a socket - * -------------------------------------------------------------------------- - */ -static NTSTATUS -OvsReadPacketCmdHandler(POVS_USER_PARAMS_CONTEXT usrParamsCtx, - UINT32 *replyLen) -{ -#ifdef DBG - POVS_MESSAGE msgOut = (POVS_MESSAGE)usrParamsCtx->outputBuffer; -#endif - POVS_OPEN_INSTANCE instance = - (POVS_OPEN_INSTANCE)usrParamsCtx->ovsInstance; - NTSTATUS status; - - ASSERT(usrParamsCtx->devOp == OVS_READ_DEV_OP); - - /* Should never read events with a dump socket */ - ASSERT(instance->dumpState.ovsMsg == NULL); - - /* Must have an packet queue */ - ASSERT(instance->packetQueue != NULL); - - /* Output buffer has been validated while validating read dev op. */ - ASSERT(msgOut != NULL && usrParamsCtx->outputLength >= sizeof *msgOut); - - /* Read a packet from the instance queue */ - status = OvsReadDpIoctl(instance->fileObject, usrParamsCtx->outputBuffer, - usrParamsCtx->outputLength, replyLen); - return status; -} - -/* - * -------------------------------------------------------------------------- - * Handler for the subscription for a packet queue - * -------------------------------------------------------------------------- - */ -static NTSTATUS -OvsSubscribePacketCmdHandler(POVS_USER_PARAMS_CONTEXT usrParamsCtx, - UINT32 *replyLen) -{ - NDIS_STATUS status; - BOOLEAN rc; - UINT8 join; - UINT32 pid; - const NL_POLICY policy[] = { - [OVS_NL_ATTR_PACKET_PID] = {.type = NL_A_U32 }, - [OVS_NL_ATTR_PACKET_SUBSCRIBE] = {.type = NL_A_U8 } - }; - PNL_ATTR attrs[ARRAY_SIZE(policy)]; - - UNREFERENCED_PARAMETER(replyLen); - - POVS_OPEN_INSTANCE instance = - (POVS_OPEN_INSTANCE)usrParamsCtx->ovsInstance; - POVS_MESSAGE msgIn = (POVS_MESSAGE)usrParamsCtx->inputBuffer; - - rc = NlAttrParse(&msgIn->nlMsg, sizeof (*msgIn), - NlMsgAttrsLen((PNL_MSG_HDR)msgIn), policy, ARRAY_SIZE(policy), - attrs, ARRAY_SIZE(attrs)); - if (!rc) { - status = STATUS_INVALID_PARAMETER; - goto done; - } - - join = NlAttrGetU8(attrs[OVS_NL_ATTR_PACKET_PID]); - pid = NlAttrGetU32(attrs[OVS_NL_ATTR_PACKET_PID]); - - /* The socket subscribed with must be the same socket we perform receive*/ - ASSERT(pid == instance->pid); - - status = OvsSubscribeDpIoctl(instance, pid, join); - - /* - * XXX Need to add this instance to a global data structure - * which hold all packet based instances. The data structure (hash) - * should be searched through the pid field of the instance for - * placing the missed packet into the correct queue - */ -done: - return status; -} - -/* - * -------------------------------------------------------------------------- - * Handler for queueing an IRP used for missed packet notification. The IRP is - * completed when a packet received and mismatched. STATUS_PENDING is returned - * on success. User mode keep a pending IRP at all times. - * -------------------------------------------------------------------------- - */ -static NTSTATUS -OvsPendPacketCmdHandler(POVS_USER_PARAMS_CONTEXT usrParamsCtx, - UINT32 *replyLen) -{ - UNREFERENCED_PARAMETER(replyLen); - - POVS_OPEN_INSTANCE instance = - (POVS_OPEN_INSTANCE)usrParamsCtx->ovsInstance; - - /* - * XXX access to packet queue must be through acquiring a lock as user mode - * could unsubscribe and the instnace will be freed. - */ - return OvsWaitDpIoctl(usrParamsCtx->irp, instance->fileObject); -} diff --git a/datapath-windows/ovsext/User.c b/datapath-windows/ovsext/User.c index 8045e9a..0bbf690 100644 --- a/datapath-windows/ovsext/User.c +++ b/datapath-windows/ovsext/User.c @@ -1156,3 +1156,111 @@ fail: OvsFreeMemoryWithTag(elem, OVS_USER_POOL_TAG); return NULL; } + +/* + * -------------------------------------------------------------------------- + * Handler for the subscription for a packet queue + * -------------------------------------------------------------------------- + */ +NTSTATUS +OvsSubscribePacketCmdHandler(POVS_USER_PARAMS_CONTEXT usrParamsCtx, + UINT32 *replyLen) +{ + NDIS_STATUS status; + BOOLEAN rc; + UINT8 join; + UINT32 pid; + const NL_POLICY policy[] = { + [OVS_NL_ATTR_PACKET_PID] = {.type = NL_A_U32 }, + [OVS_NL_ATTR_PACKET_SUBSCRIBE] = {.type = NL_A_U8 } + }; + PNL_ATTR attrs[ARRAY_SIZE(policy)]; + + UNREFERENCED_PARAMETER(replyLen); + + POVS_OPEN_INSTANCE instance = + (POVS_OPEN_INSTANCE)usrParamsCtx->ovsInstance; + POVS_MESSAGE msgIn = (POVS_MESSAGE)usrParamsCtx->inputBuffer; + + rc = NlAttrParse(&msgIn->nlMsg, sizeof (*msgIn), + NlMsgAttrsLen((PNL_MSG_HDR)msgIn), policy, ARRAY_SIZE(policy), + attrs, ARRAY_SIZE(attrs)); + if (!rc) { + status = STATUS_INVALID_PARAMETER; + goto done; + } + + join = NlAttrGetU8(attrs[OVS_NL_ATTR_PACKET_PID]); + pid = NlAttrGetU32(attrs[OVS_NL_ATTR_PACKET_PID]); + + /* The socket subscribed with must be the same socket we perform receive*/ + ASSERT(pid == instance->pid); + + status = OvsSubscribeDpIoctl(instance, pid, join); + + /* + * XXX Need to add this instance to a global data structure + * which hold all packet based instances. The data structure (hash) + * should be searched through the pid field of the instance for + * placing the missed packet into the correct queue + */ +done: + return status; +} + +/* + * -------------------------------------------------------------------------- + * Handler for queueing an IRP used for missed packet notification. The IRP is + * completed when a packet received and mismatched. STATUS_PENDING is returned + * on success. User mode keep a pending IRP at all times. + * -------------------------------------------------------------------------- + */ +NTSTATUS +OvsPendPacketCmdHandler(POVS_USER_PARAMS_CONTEXT usrParamsCtx, + UINT32 *replyLen) +{ + UNREFERENCED_PARAMETER(replyLen); + + POVS_OPEN_INSTANCE instance = + (POVS_OPEN_INSTANCE)usrParamsCtx->ovsInstance; + + /* + * XXX access to packet queue must be through acquiring a lock as user mode + * could unsubscribe and the instnace will be freed. + */ + return OvsWaitDpIoctl(usrParamsCtx->irp, instance->fileObject); +} + +/* + * -------------------------------------------------------------------------- + * Handler for reading missed pacckets from the driver event queue. This + * handler is executed when user modes issues a socket receive on a socket + * -------------------------------------------------------------------------- + */ +NTSTATUS +OvsReadPacketCmdHandler(POVS_USER_PARAMS_CONTEXT usrParamsCtx, + UINT32 *replyLen) +{ +#ifdef DBG + POVS_MESSAGE msgOut = (POVS_MESSAGE)usrParamsCtx->outputBuffer; +#endif + POVS_OPEN_INSTANCE instance = + (POVS_OPEN_INSTANCE)usrParamsCtx->ovsInstance; + NTSTATUS status; + + ASSERT(usrParamsCtx->devOp == OVS_READ_DEV_OP); + + /* Should never read events with a dump socket */ + ASSERT(instance->dumpState.ovsMsg == NULL); + + /* Must have an packet queue */ + ASSERT(instance->packetQueue != NULL); + + /* Output buffer has been validated while validating read dev op. */ + ASSERT(msgOut != NULL && usrParamsCtx->outputLength >= sizeof *msgOut); + + /* Read a packet from the instance queue */ + status = OvsReadDpIoctl(instance->fileObject, usrParamsCtx->outputBuffer, + usrParamsCtx->outputLength, replyLen); + return status; +} \ No newline at end of file diff --git a/datapath-windows/ovsext/User.h b/datapath-windows/ovsext/User.h index 139b0ca..8b80ded 100644 --- a/datapath-windows/ovsext/User.h +++ b/datapath-windows/ovsext/User.h @@ -118,4 +118,11 @@ OvsAddPidInstance(POVS_SWITCH_CONTEXT switchContext, UINT32 pid, VOID OvsDelPidInstance(POVS_SWITCH_CONTEXT switchContext, UINT32 pid); +NTSTATUS OvsReadPacketCmdHandler(POVS_USER_PARAMS_CONTEXT usrParamsCtx, + UINT32 *replyLen); +NTSTATUS OvsSubscribePacketCmdHandler(POVS_USER_PARAMS_CONTEXT usrParamsCtx, + UINT32 *replyLen); +NTSTATUS OvsPendPacketCmdHandler(POVS_USER_PARAMS_CONTEXT usrParamsCtx, + UINT32 *replyLen); + #endif /* __USER_H_ */