From patchwork Wed Sep 16 10:50:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sorin Vinturis X-Patchwork-Id: 518329 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 57C5614010F for ; Wed, 16 Sep 2015 20:51:12 +1000 (AEST) Received: from archives.nicira.com (localhost [127.0.0.1]) by archives.nicira.com (Postfix) with ESMTP id 2E36C10B17; Wed, 16 Sep 2015 03:51:11 -0700 (PDT) X-Original-To: dev@openvswitch.org Delivered-To: dev@openvswitch.org Received: from mx1e3.cudamail.com (mx1.cudamail.com [69.90.118.67]) by archives.nicira.com (Postfix) with ESMTPS id BCC4D10B16 for ; Wed, 16 Sep 2015 03:51:09 -0700 (PDT) Received: from bar2.cudamail.com (localhost [127.0.0.1]) by mx1e3.cudamail.com (Postfix) with ESMTPS id 2D7BF42025A for ; Wed, 16 Sep 2015 04:51:09 -0600 (MDT) X-ASG-Debug-ID: 1442400667-03dc537fe0dcb50001-byXFYA Received: from mx1-pf2.cudamail.com ([192.168.24.2]) by bar2.cudamail.com with ESMTP id QrREpzcecCTPD9Wu (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 16 Sep 2015 04:51:07 -0600 (MDT) X-Barracuda-Envelope-From: svinturis@cloudbasesolutions.com X-Barracuda-RBL-Trusted-Forwarder: 192.168.24.2 Received: from unknown (HELO cbssmtp1.cloudbase.local) (91.232.152.5) by mx1-pf2.cudamail.com with SMTP; 16 Sep 2015 10:51:06 -0000 Received-SPF: pass (mx1-pf2.cudamail.com: SPF record at cloudbasesolutions.com designates 91.232.152.5 as permitted sender) X-Barracuda-Apparent-Source-IP: 91.232.152.5 X-Barracuda-RBL-IP: 91.232.152.5 Received: from localhost (localhost [127.0.0.1]) by cbssmtp1.cloudbase.local (Postfix) with ESMTP id DC5A2428E3 for ; Wed, 16 Sep 2015 13:51:04 +0300 (EEST) X-Virus-Scanned: amavisd-new at cloudbasesolutions.com Received: from cbssmtp1.cloudbase.local ([127.0.0.1]) by localhost (cbssmtp1.cloudbase.local [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id r1x8C1dghnfv for ; Wed, 16 Sep 2015 13:50:44 +0300 (EEST) Received: from CBSEX1.cloudbase.local (unknown [10.77.78.3]) by cbssmtp1.cloudbase.local (Postfix) with ESMTP id 55DD6428BF for ; Wed, 16 Sep 2015 13:50:44 +0300 (EEST) Received: from CBSEX1.cloudbase.local ([10.77.78.3]) by CBSEX1.cloudbase.local ([10.77.78.3]) with mapi id 14.03.0224.002; Wed, 16 Sep 2015 12:50:44 +0200 X-CudaMail-Envelope-Sender: svinturis@cloudbasesolutions.com From: Sorin Vinturis To: "dev@openvswitch.org" X-CudaMail-MID: CM-E2-915007570 X-CudaMail-DTE: 091615 X-CudaMail-Originating-IP: 91.232.152.5 Thread-Topic: [PATCH v2] datapath-windows: Removed hardcoded names for internal/external vports X-ASG-Orig-Subj: [##CM-E2-915007570##][PATCH v2] datapath-windows: Removed hardcoded names for internal/external vports Thread-Index: AQHQ8G2JpQ584VegokCb6oLekfII4Q== Date: Wed, 16 Sep 2015 10:50:43 +0000 Message-ID: <1441151929-15054-1-git-send-email-svinturis@cloudbasesolutions.com> Accept-Language: en-US, it-IT Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.77.78.1] MIME-Version: 1.0 X-GBUdb-Analysis: 0, 91.232.152.5, Ugly c=0.297854 p=-0.444444 Source Normal X-MessageSniffer-Rules: 0-0-0-17269-c X-Barracuda-Connect: UNKNOWN[192.168.24.2] X-Barracuda-Start-Time: 1442400667 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://web.cudamail.com:443/cgi-mod/mark.cgi X-Virus-Scanned: by bsmtpd at cudamail.com X-Barracuda-BRTS-Status: 1 X-Barracuda-Spam-Score: 0.10 X-Barracuda-Spam-Status: No, SCORE=0.10 using per-user scores of TAG_LEVEL=3.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=3.0 tests=RDNS_NONE X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.22595 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 0.10 RDNS_NONE Delivered to trusted network by a host with no rDNS Subject: [ovs-dev] [PATCH v2] datapath-windows: Removed hardcoded names for internal/external vports 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: , Errors-To: dev-bounces@openvswitch.org Sender: "dev" The internal/external vports will have the actual OS-based names, which represent the NIC interface alias that is displayed by running 'Get-NetAdapter' Hyper-V PS command. Signed-off-by: Sorin Vinturis --- datapath-windows/ovsext/Vport.c | 89 ++++++++++++++++++++--------------------- datapath-windows/ovsext/Vport.h | 5 --- 2 files changed, 43 insertions(+), 51 deletions(-) diff --git a/datapath-windows/ovsext/Vport.c b/datapath-windows/ovsext/Vport.c index ea10692..74d7e07 100644 --- a/datapath-windows/ovsext/Vport.c +++ b/datapath-windows/ovsext/Vport.c @@ -95,7 +95,7 @@ static VOID OvsTunnelVportPendingInit(PVOID context, static VOID OvsTunnelVportPendingRemove(PVOID context, NTSTATUS status, UINT32 *replyLen); - +static VOID AssignNicNameSpecial(POVS_VPORT_ENTRY vport); /* * Functions implemented in relaton to NDIS port manipulation. @@ -191,10 +191,8 @@ HvUpdatePort(POVS_SWITCH_CONTEXT switchContext, portParam->PortId, 0); /* * Update properties only for NETDEV ports for supprting PS script - * We don't allow changing the names of the internal or external ports */ - if (vport == NULL || (( vport->portType != NdisSwitchPortTypeSynthetic) && - ( vport->portType != NdisSwitchPortTypeEmulated))) { + if (vport == NULL) { goto update_port_done; } @@ -436,6 +434,10 @@ HvUpdateNic(POVS_SWITCH_CONTEXT switchContext, } switch (nicParam->NicType) { case NdisSwitchNicTypeExternal: + RtlCopyMemory(&vport->netCfgInstanceId, &nicParam->NetCfgInstanceId, + sizeof(GUID)); + AssignNicNameSpecial(vport); + break; case NdisSwitchNicTypeInternal: RtlCopyMemory(&vport->netCfgInstanceId, &nicParam->NetCfgInstanceId, sizeof (GUID)); @@ -890,6 +892,10 @@ OvsInitPhysNicVport(POVS_VPORT_ENTRY physExtVport, &virtExtVport->portFriendlyName, sizeof(NDIS_SWITCH_PORT_FRIENDLYNAME)); + RtlCopyMemory(&physExtVport->netCfgInstanceId, + &virtExtVport->netCfgInstanceId, + sizeof(physExtVport->netCfgInstanceId)); + physExtVport->ovsState = OVS_STATE_PORT_CREATED; } @@ -968,36 +974,47 @@ OvsInitBridgeInternalVport(POVS_VPORT_ENTRY vport) /* * -------------------------------------------------------------------------- - * For external vports 'portFriendlyName' provided by Hyper-V is over-written - * by synthetic names. + * For external vport 'portFriendlyName' parameter, provided by Hyper-V, is + * overwritten with the interface alias name. * -------------------------------------------------------------------------- */ static VOID AssignNicNameSpecial(POVS_VPORT_ENTRY vport) { - size_t len; + NTSTATUS status = STATUS_SUCCESS; + WCHAR interfaceName[IF_MAX_STRING_SIZE] = { 0 }; + NET_LUID interfaceLuid = { 0 }; + size_t len = 0; - if (vport->portType == NdisSwitchPortTypeExternal) { - if (vport->nicIndex == 0) { - ASSERT(vport->nicIndex == 0); - RtlStringCbPrintfW(vport->portFriendlyName.String, - IF_MAX_STRING_SIZE, - L"%s.virtualAdapter", OVS_DPPORT_EXTERNAL_NAME_W); + ASSERT(vport->portType == NdisSwitchPortTypeExternal || + vport->portType == NdisSwitchPortTypeInternal); + + status = ConvertInterfaceGuidToLuid(&vport->netCfgInstanceId, + &interfaceLuid); + if (status == STATUS_SUCCESS) { + status = ConvertInterfaceLuidToAlias(&interfaceLuid, interfaceName, + IF_MAX_STRING_SIZE + 1); + if (status == STATUS_SUCCESS) { + if (vport->portType == NdisSwitchPortTypeExternal && + vport->nicIndex == 0) { + RtlStringCbPrintfW(vport->portFriendlyName.String, IF_MAX_STRING_SIZE, + L"%s.virtualAdapter", interfaceName); + } else { + RtlStringCbPrintfW(vport->portFriendlyName.String, + IF_MAX_STRING_SIZE, L"%s", interfaceName); + } + + RtlStringCbLengthW(vport->portFriendlyName.String, IF_MAX_STRING_SIZE, + &len); + vport->portFriendlyName.Length = (USHORT)len; } else { - RtlStringCbPrintfW(vport->portFriendlyName.String, - IF_MAX_STRING_SIZE, - L"%s.%lu", OVS_DPPORT_EXTERNAL_NAME_W, - (UINT32)vport->nicIndex); + OVS_LOG_INFO("Fail to convert interface LUID to alias, status: %x", + status); } } else { - RtlStringCbPrintfW(vport->portFriendlyName.String, - IF_MAX_STRING_SIZE, - L"%s", OVS_DPPORT_INTERNAL_NAME_W); + OVS_LOG_INFO("Fail to convert interface GUID to LUID, status: %x", + status); } - - RtlStringCbLengthW(vport->portFriendlyName.String, IF_MAX_STRING_SIZE, - &len); - vport->portFriendlyName.Length = (USHORT)len; } @@ -1038,8 +1055,6 @@ InitHvVportCommon(POVS_SWITCH_CONTEXT switchContext, case NdisSwitchPortTypeInternal: ASSERT(vport->isBridgeInternal == FALSE); - /* Overwrite the 'portFriendlyName' of the internal vport. */ - AssignNicNameSpecial(vport); switchContext->internalPortId = vport->portId; switchContext->internalVport = vport; break; @@ -2093,9 +2108,7 @@ OvsNewVportCmdHandler(POVS_USER_PARAMS_CONTEXT usrParamsCtx, PCHAR portName; ULONG portNameLen; UINT32 portType; - BOOLEAN isBridgeInternal = FALSE; BOOLEAN vportAllocated = FALSE, vportInitialized = FALSE; - BOOLEAN addInternalPortAsNetdev = FALSE; static const NL_POLICY ovsVportPolicy[] = { [OVS_VPORT_ATTR_PORT_NO] = { .type = NL_A_U32, .optional = TRUE }, @@ -2138,24 +2151,12 @@ OvsNewVportCmdHandler(POVS_USER_PARAMS_CONTEXT usrParamsCtx, goto Cleanup; } - if (portName && portType == OVS_VPORT_TYPE_NETDEV && - !strcmp(OVS_DPPORT_INTERNAL_NAME_A, portName)) { - addInternalPortAsNetdev = TRUE; - } - - if (portName && portType == OVS_VPORT_TYPE_INTERNAL && - strcmp(OVS_DPPORT_INTERNAL_NAME_A, portName)) { - isBridgeInternal = TRUE; - } - - if (portType == OVS_VPORT_TYPE_INTERNAL && !isBridgeInternal) { - vport = gOvsSwitchContext->internalVport; - } else if (portType == OVS_VPORT_TYPE_NETDEV) { + if (portType == OVS_VPORT_TYPE_NETDEV) { /* External ports can also be looked up like VIF ports. */ vport = OvsFindVportByHvNameA(gOvsSwitchContext, portName); } else { ASSERT(OvsIsTunnelVportType(portType) || - (portType == OVS_VPORT_TYPE_INTERNAL && isBridgeInternal)); + portType == OVS_VPORT_TYPE_INTERNAL); vport = (POVS_VPORT_ENTRY)OvsAllocateVport(); if (vport == NULL) { @@ -2221,10 +2222,6 @@ OvsNewVportCmdHandler(POVS_USER_PARAMS_CONTEXT usrParamsCtx, goto Cleanup; } - /* Initialize the vport with OVS specific properties. */ - if (addInternalPortAsNetdev != TRUE) { - vport->ovsType = portType; - } if (vportAttrs[OVS_VPORT_ATTR_PORT_NO] != NULL) { /* * XXX: when we implement the limit for ovs port number to be diff --git a/datapath-windows/ovsext/Vport.h b/datapath-windows/ovsext/Vport.h index ba21c62..ead55a9 100644 --- a/datapath-windows/ovsext/Vport.h +++ b/datapath-windows/ovsext/Vport.h @@ -34,11 +34,6 @@ */ #define OVS_DPPORT_NUMBER_LOCAL 0 -#define OVS_DPPORT_INTERNAL_NAME_A "internal" -#define OVS_DPPORT_INTERNAL_NAME_W L"internal" -#define OVS_DPPORT_EXTERNAL_NAME_A "external" -#define OVS_DPPORT_EXTERNAL_NAME_W L"external" - /* * A Vport, or Virtual Port, is a port on the OVS. It can be one of the * following types. Some of the Vports are "real" ports on the hyper-v switch,