summaryrefslogtreecommitdiff
path: root/datapath-windows/ovsext/Vport.c
diff options
context:
space:
mode:
authorNithin Raju <nithin@vmware.com>2014-10-12 20:56:14 -0700
committerBen Pfaff <blp@nicira.com>2014-10-13 14:01:21 -0700
commit8d9f1e0c0150b0cfa71275e93e2b663129703985 (patch)
treecdd8300f6a01ad26cddf0622b11a12f579843243 /datapath-windows/ovsext/Vport.c
parent9189184d09bfb742149b878d6b9e0194979b3dbb (diff)
downloadopenvswitch-8d9f1e0c0150b0cfa71275e93e2b663129703985.tar.gz
datapath-windows: Add netlink command: vport new
Does the following: a. before creating the vport, makes sure there is no existing vport with the same ovs (datapath) port name. If this is not so, it means that the specified port already exists: it returns NL_ERROR_EXIST. b. looks up the vport: o) if the vport type is "internal", then the internal vport of the hyper-v switch is yielded. o) if the vport type is "netdev" and the vport ovs (datapath) name is "external", then the external vport is yielded. The switch can have only one "external" vport. The method of looking up the "external" port can be changed later, if a better method is found. o) if the vport type is "netdev" but the name is not "external", then a VM VNic is assumed, so the vport is looked up by hyper-v switch port friendly name. o) if none of the above, a tunneling vport type is expected, which in our case, at the moment, can only be the one vxlan vport. Only one vxlan vport is allowed, and it's saved in switchContext->vxlanVport. The tunneling vport is the only kind which is created in the netlink command vport new, because it does not have a hyper-v switch port counterpart. c. if the vport could not be found (non-tunneling vports), then the NL_ERROR_INVAL is returned to the userspace. d. if the vport was found, but it has a valid ovs (datapath) port number, it means that this port was already created by a netlink command vport new. Therefore, NL_ERROR_EXIST is returned to the userspace. e. if the netlink command vport new specified an ovs (datapath) port number, then it means that the userspace is trying to re-create a vport: that specified port number will be used. Otherwise, a new ovs (datapath) port number is computed and assigned to the vport. f. the ovsName field of the vport is set to the name given by the OVS_VPORT_ATTR_NAME netlink attribute. The ovsNameLen is no longer stored in the OVS_VPORT_ENTRY struct, because ovsName is null-terminated. g. the "portOptions" are set to the vport, if the attribute OVS_VPORT_ATTR_OPTIONS was given. Otherwise, it is set to NULL. portOptions is a PNL_ATTR, which is yet to be implemented. The only option available for now would be vxlan udp destination port, but we have a constant value there, so this option is not yet needed. h. the upcall pid is set to the vport. i. if the vport type is vxlan, then the vport pointer is also saved to switchContext->vxlanVport. j. Now that the ovs (datapath) port number and the ovs name were set, the vport can be added to the hash array of vports, hashed on ovs name and to the hash array of vports hashed by ovs (datapath) port number. k. the reply is yielded to the userspace. Signed-off-by: Samuel Ghinet <sghinet@cloudbasesolutions.com> Acked-by: Nithin Raju <nithin@vmware.com> Acked-by: Ankur Sharma <ankursharma@vmware.com> Acked-by: Eitan Eliahu <eliahue@vmware.com> Acked-by: Alin Gabriel Serdean <aserdean@cloudbasesolutions.com> Tested-by: Alin Gabriel Serdean <aserdean@cloudbasesolutions.com> Signed-off-by: Ben Pfaff <blp@nicira.com>
Diffstat (limited to 'datapath-windows/ovsext/Vport.c')
-rw-r--r--datapath-windows/ovsext/Vport.c69
1 files changed, 22 insertions, 47 deletions
diff --git a/datapath-windows/ovsext/Vport.c b/datapath-windows/ovsext/Vport.c
index f2dbbc97c..00a9145fa 100644
--- a/datapath-windows/ovsext/Vport.c
+++ b/datapath-windows/ovsext/Vport.c
@@ -50,7 +50,6 @@
extern POVS_SWITCH_CONTEXT gOvsSwitchContext;
extern PNDIS_SPIN_LOCK gOvsCtrlLock;
-static POVS_VPORT_ENTRY OvsAllocateVport(VOID);
static VOID OvsInitVportWithPortParam(POVS_VPORT_ENTRY vport,
PNDIS_SWITCH_PORT_PARAMETERS portParam);
static VOID OvsInitVportWithNicParam(POVS_SWITCH_CONTEXT switchContext,
@@ -59,10 +58,6 @@ static VOID OvsInitPhysNicVport(POVS_VPORT_ENTRY vport, POVS_VPORT_ENTRY
virtVport, UINT32 nicIndex);
static VOID OvsInitPhysNicVport(POVS_VPORT_ENTRY vport, POVS_VPORT_ENTRY
virtVport, UINT32 nicIndex);
-static NDIS_STATUS OvsInitVportCommon(POVS_SWITCH_CONTEXT switchContext,
- POVS_VPORT_ENTRY vport);
-static VOID OvsRemoveAndDeleteVport(POVS_SWITCH_CONTEXT switchContext,
- POVS_VPORT_ENTRY vport);
static __inline VOID OvsWaitActivate(POVS_SWITCH_CONTEXT switchContext,
ULONG sleepMicroSec);
static NTSTATUS OvsGetExtInfoIoctl(POVS_VPORT_GET vportGet,
@@ -89,15 +84,17 @@ HvCreatePort(POVS_SWITCH_CONTEXT switchContext,
NdisAcquireRWLockWrite(switchContext->dispatchLock, &lockState, 0);
vport = OvsFindVportByPortIdAndNicIndex(switchContext,
portParam->PortId, 0);
- if (vport != NULL) {
+ if (vport != NULL && !vport->hvDeleted) {
status = STATUS_DATA_NOT_ACCEPTED;
goto create_port_done;
+ } else if (!vport) {
+ vport = (POVS_VPORT_ENTRY)OvsAllocateVport();
+ if (vport == NULL) {
+ status = NDIS_STATUS_RESOURCES;
+ goto create_port_done;
+ }
}
- vport = (POVS_VPORT_ENTRY)OvsAllocateVport();
- if (vport == NULL) {
- status = NDIS_STATUS_RESOURCES;
- goto create_port_done;
- }
+
OvsInitVportWithPortParam(vport, portParam);
OvsInitVportCommon(switchContext, vport);
@@ -474,20 +471,23 @@ OvsFindVportByPortNo(POVS_SWITCH_CONTEXT switchContext,
POVS_VPORT_ENTRY
OvsFindVportByOvsName(POVS_SWITCH_CONTEXT switchContext,
- CHAR *name,
- UINT32 length)
+ PSTR name)
{
POVS_VPORT_ENTRY vport;
PLIST_ENTRY head, link;
- UINT32 hash = OvsJhashBytes((const VOID *)name, length, OVS_HASH_BASIS);
+ UINT32 hash;
+ SIZE_T length = strlen(name) + 1;
+
+ hash = OvsJhashBytes((const VOID *)name, length, OVS_HASH_BASIS);
head = &(switchContext->ovsPortNameHashArray[hash & OVS_VPORT_MASK]);
+
LIST_FORALL(head, link) {
vport = CONTAINING_RECORD(link, OVS_VPORT_ENTRY, ovsNameLink);
- if (vport->ovsNameLen == length &&
- RtlEqualMemory(name, vport->ovsName, length)) {
+ if (!strcmp(name, vport->ovsName)) {
return vport;
}
}
+
return NULL;
}
@@ -561,7 +561,7 @@ OvsFindVportByPortIdAndNicIndex(POVS_SWITCH_CONTEXT switchContext,
}
}
-static POVS_VPORT_ENTRY
+POVS_VPORT_ENTRY
OvsAllocateVport(VOID)
{
POVS_VPORT_ENTRY vport;
@@ -571,6 +571,7 @@ OvsAllocateVport(VOID)
}
RtlZeroMemory(vport, sizeof (OVS_VPORT_ENTRY));
vport->ovsState = OVS_STATE_UNKNOWN;
+ vport->hvDeleted = FALSE;
vport->portNo = OVS_DPPORT_NUMBER_INVALID;
InitializeListHead(&vport->ovsNameLink);
@@ -692,7 +693,8 @@ OvsInitPhysNicVport(POVS_VPORT_ENTRY vport,
vport->ovsState = OVS_STATE_PORT_CREATED;
}
-static NDIS_STATUS
+
+NDIS_STATUS
OvsInitVportCommon(POVS_SWITCH_CONTEXT switchContext,
POVS_VPORT_ENTRY vport)
{
@@ -739,8 +741,7 @@ OvsInitVportCommon(POVS_SWITCH_CONTEXT switchContext,
return NDIS_STATUS_SUCCESS;
}
-
-static VOID
+VOID
OvsRemoveAndDeleteVport(POVS_SWITCH_CONTEXT switchContext,
POVS_VPORT_ENTRY vport)
{
@@ -917,32 +918,6 @@ OvsClearAllSwitchVports(POVS_SWITCH_CONTEXT switchContext)
}
}
-NTSTATUS
-OvsInitTunnelVport(POVS_VPORT_ENTRY vport,
- POVS_VPORT_ADD_REQUEST addReq)
-{
- size_t len;
- NTSTATUS status = STATUS_SUCCESS;
-
- vport->ovsType = addReq->type;
- vport->ovsState = OVS_STATE_PORT_CREATED;
- RtlCopyMemory(vport->ovsName, addReq->name, OVS_MAX_PORT_NAME_LENGTH);
- vport->ovsName[OVS_MAX_PORT_NAME_LENGTH - 1] = 0;
- StringCbLengthA(vport->ovsName, OVS_MAX_PORT_NAME_LENGTH - 1, &len);
- vport->ovsNameLen = (UINT32)len;
- switch (addReq->type) {
- case OVS_VPORT_TYPE_GRE:
- break;
- case OVS_VPORT_TYPE_GRE64:
- break;
- case OVS_VPORT_TYPE_VXLAN:
- status = OvsInitVxlanTunnel(vport, addReq);
- break;
- default:
- ASSERT(0);
- }
- return status;
-}
NTSTATUS
OvsConvertIfCountedStrToAnsiStr(PIF_COUNTED_STRING wStr,
@@ -983,7 +958,7 @@ OvsConvertIfCountedStrToAnsiStr(PIF_COUNTED_STRING wStr,
* XXX: Get rid of USE_NEW_VPORT_ADD_WORKFLOW while checking in the code for
* new vport add workflow, or set USE_NEW_VPORT_ADD_WORKFLOW to 1.
*/
-#define USE_NEW_VPORT_ADD_WORKFLOW 0
+#define USE_NEW_VPORT_ADD_WORKFLOW 1
NTSTATUS
OvsGetExtInfoIoctl(POVS_VPORT_GET vportGet,
POVS_VPORT_EXT_INFO extInfo)