Skip to content

Commit

Permalink
datapath-windows: Using windows kernel netlink parsing APIs.
Browse files Browse the repository at this point in the history
In this patch we incorporate the usage of netlink message
and the parsing APIs that were added in previous commit.

Signed-off-by: Ankur Sharma <[email protected]>
Reported-at: openvswitch/ovs-issues#18
Acked-by: Nithin Raju <[email protected]>
Signed-off-by: Ben Pfaff <[email protected]>
  • Loading branch information
ankursh authored and blp committed Aug 22, 2014
1 parent 344b47e commit d838e57
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 49 deletions.
5 changes: 4 additions & 1 deletion datapath-windows/automake.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ EXTRA_DIST += \
datapath-windows/Package/package.VcxProj.user \
datapath-windows/include/OvsDpInterfaceExt.h \
datapath-windows/include/OvsNetlink.h \
datapath-windows/include/OvsPub.h \
datapath-windows/include/OvsPub.h\
datapath-windows/ovsext/Netlink.c \
datapath-windows/ovsext/Netlink.h \
datapath-windows/ovsext/NetlinkProto.h \
datapath-windows/misc/install.cmd \
datapath-windows/misc/uninstall.cmd \
datapath-windows/ovsext.sln \
Expand Down
13 changes: 4 additions & 9 deletions datapath-windows/include/OvsPub.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@
#ifndef __OVS_PUB_H_
#define __OVS_PUB_H_ 1

/* Needed by netlink-protocol.h */
#define BUILD_ASSERT(EXPR) \
typedef char AssertOnCompileFailed[(EXPR) ? 1: -1]
#define BUILD_ASSERT_DECL(EXPR) BUILD_ASSERT(EXPR)

#include "OvsNetlink.h"
#include "../ovsext/Netlink.h"

#define OVS_DRIVER_MAJOR_VER 1
#define OVS_DRIVER_MINOR_VER 0
Expand Down Expand Up @@ -369,7 +364,7 @@ typedef struct OvsFlowInfo {
OvsFlowKey key;
struct OvsFlowStats stats;
uint32_t actionsLen;
struct nlattr actions[0];
NL_ATTR actions[0];
} OvsFlowInfo;

enum GetFlags {
Expand Down Expand Up @@ -425,7 +420,7 @@ typedef struct OvsFlowPut {
uint32_t actionsLen;
OvsFlowKey key;
uint32_t flags;
struct nlattr actions[0]; /* Variable length indicated by actionsLen. */
NL_ATTR actions[0]; /* Variable length indicated by actionsLen. */
} OvsFlowPut;

#define OVS_MIN_PACKET_SIZE 60
Expand All @@ -452,7 +447,7 @@ typedef struct OvsPacketExecute {
/* Variable size blob with packet data first, followed by action
* attrs. */
char packetBuf[0];
struct nlattr actions[0];
NL_ATTR actions[0];
};
} OvsPacketExecute;

Expand Down
8 changes: 4 additions & 4 deletions datapath-windows/ovsext/Datapath.c
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ OvsDeviceControl(PDEVICE_OBJECT deviceObject,
PIO_STACK_LOCATION irpSp;
NTSTATUS status = STATUS_SUCCESS;
PFILE_OBJECT fileObject;
PVOID inputBuffer;
PVOID inputBuffer = NULL;
PVOID outputBuffer = NULL;
UINT32 inputBufferLen, outputBufferLen;
UINT32 code, replyLen = 0;
Expand Down Expand Up @@ -645,7 +645,7 @@ OvsDeviceControl(PDEVICE_OBJECT deviceObject,
}

ASSERT(ovsMsg);
switch (ovsMsg->nlMsg.nlmsg_type) {
switch (ovsMsg->nlMsg.nlmsgType) {
case OVS_WIN_NL_CTRL_FAMILY_ID:
nlFamilyOps = &nlControlFamilyOps;
break;
Expand Down Expand Up @@ -801,8 +801,8 @@ OvsGetPidCmdHandler(PIRP irp,
POVS_OPEN_INSTANCE instance = (POVS_OPEN_INSTANCE)fileObject->FsContext;

RtlZeroMemory(msgOut, sizeof *msgOut);
msgOut->nlMsg.nlmsg_seq = msgIn->nlMsg.nlmsg_seq;
msgOut->nlMsg.nlmsg_pid = instance->pid;
msgOut->nlMsg.nlmsgSeq = msgIn->nlMsg.nlmsgSeq;
msgOut->nlMsg.nlmsgPid = instance->pid;
*replyLen = sizeof *msgOut;
/* XXX: We might need to return the DP index as well. */
} else {
Expand Down
4 changes: 2 additions & 2 deletions datapath-windows/ovsext/Datapath.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ NTSTATUS OvsCompleteIrpRequest(PIRP irp, ULONG_PTR infoPtr, NTSTATUS status);
* Structure of any message passed between userspace and kernel.
*/
typedef struct _OVS_MESSAGE {
struct nlmsghdr nlMsg;
struct genlmsghdr genlMsg;
NL_MSG_HDR nlMsg;
GENL_MSG_HDR genlMsg;
struct ovs_header ovsHdr;
/* Variable length nl_attrs follow. */
} OVS_MESSAGE, *POVS_MESSAGE;
Expand Down
58 changes: 29 additions & 29 deletions datapath-windows/ovsext/OvsActions.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include "OvsChecksum.h"
#include "OvsPacketIO.h"


#ifdef OVS_DBG_MOD
#undef OVS_DBG_MOD
#endif
Expand Down Expand Up @@ -1030,35 +1029,35 @@ OvsPopVlanInPktBuf(OvsForwardingContext *ovsFwdCtx)
* --------------------------------------------------------------------------
*/
static __inline NDIS_STATUS
OvsTunnelAttrToIPv4TunnelKey(struct nlattr *attr,
OvsTunnelAttrToIPv4TunnelKey(PNL_ATTR attr,
OvsIPv4TunnelKey *tunKey)
{
struct nlattr *a;
PNL_ATTR a;
INT rem;

tunKey->attr[0] = 0;
tunKey->attr[1] = 0;
tunKey->attr[2] = 0;
ASSERT(nl_attr_type(attr) == OVS_KEY_ATTR_TUNNEL);
ASSERT(NlAttrType(attr) == OVS_KEY_ATTR_TUNNEL);

NL_ATTR_FOR_EACH_UNSAFE (a, rem, nl_attr_data(attr),
nl_attr_get_size(attr)) {
switch (nl_attr_type(a)) {
NL_ATTR_FOR_EACH_UNSAFE (a, rem, NlAttrData(attr),
NlAttrGetSize(attr)) {
switch (NlAttrType(a)) {
case OVS_TUNNEL_KEY_ATTR_ID:
tunKey->tunnelId = nl_attr_get_be64(a);
tunKey->tunnelId = NlAttrGetBe64(a);
tunKey->flags |= OVS_TNL_F_KEY;
break;
case OVS_TUNNEL_KEY_ATTR_IPV4_SRC:
tunKey->src = nl_attr_get_be32(a);
tunKey->src = NlAttrGetBe32(a);
break;
case OVS_TUNNEL_KEY_ATTR_IPV4_DST:
tunKey->dst = nl_attr_get_be32(a);
tunKey->dst = NlAttrGetBe32(a);
break;
case OVS_TUNNEL_KEY_ATTR_TOS:
tunKey->tos = nl_attr_get_u8(a);
tunKey->tos = NlAttrGetU8(a);
break;
case OVS_TUNNEL_KEY_ATTR_TTL:
tunKey->ttl = nl_attr_get_u8(a);
tunKey->ttl = NlAttrGetU8(a);
break;
case OVS_TUNNEL_KEY_ATTR_DONT_FRAGMENT:
tunKey->flags |= OVS_TNL_F_DONT_FRAGMENT;
Expand Down Expand Up @@ -1283,27 +1282,27 @@ static __inline NDIS_STATUS
OvsExecuteSetAction(OvsForwardingContext *ovsFwdCtx,
OvsFlowKey *key,
UINT64 *hash,
const struct nlattr *a)
const PNL_ATTR a)
{
enum ovs_key_attr type = nl_attr_type(a);
enum ovs_key_attr type = NlAttrType(a);
NDIS_STATUS status = NDIS_STATUS_SUCCESS;

switch (type) {
case OVS_KEY_ATTR_ETHERNET:
status = OvsUpdateEthHeader(ovsFwdCtx,
nl_attr_get_unspec(a, sizeof(struct ovs_key_ethernet)));
NlAttrGetUnspec(a, sizeof(struct ovs_key_ethernet)));
break;

case OVS_KEY_ATTR_IPV4:
status = OvsUpdateIPv4Header(ovsFwdCtx,
nl_attr_get_unspec(a, sizeof(struct ovs_key_ipv4)));
NlAttrGetUnspec(a, sizeof(struct ovs_key_ipv4)));
break;

case OVS_KEY_ATTR_TUNNEL:
{
OvsIPv4TunnelKey tunKey;

status = OvsTunnelAttrToIPv4TunnelKey((struct nlattr *)a, &tunKey);
status = OvsTunnelAttrToIPv4TunnelKey((PNL_ATTR)a, &tunKey);
ASSERT(status == NDIS_STATUS_SUCCESS);
tunKey.flow_hash = (uint16)(hash ? *hash : OvsHashFlow(key));
RtlCopyMemory(&ovsFwdCtx->tunKey, &tunKey, sizeof ovsFwdCtx->tunKey);
Expand Down Expand Up @@ -1357,10 +1356,10 @@ OvsActionsExecute(POVS_SWITCH_CONTEXT switchContext,
OvsFlowKey *key,
UINT64 *hash,
OVS_PACKET_HDR_INFO *layers,
const struct nlattr *actions,
const PNL_ATTR actions,
INT actionsLen)
{
const struct nlattr *a;
PNL_ATTR a;
INT rem;
UINT32 dstPortID;
OvsForwardingContext ovsFwdCtx;
Expand All @@ -1385,9 +1384,9 @@ OvsActionsExecute(POVS_SWITCH_CONTEXT switchContext,
}

NL_ATTR_FOR_EACH_UNSAFE (a, rem, actions, actionsLen) {
switch(nl_attr_type(a)) {
switch(NlAttrType(a)) {
case OVS_ACTION_ATTR_OUTPUT:
dstPortID = nl_attr_get_u32(a);
dstPortID = NlAttrGetU32(a);
status = OvsAddPorts(&ovsFwdCtx, key, dstPortID,
TRUE, TRUE);
if (status != NDIS_STATUS_SUCCESS) {
Expand Down Expand Up @@ -1424,7 +1423,7 @@ OvsActionsExecute(POVS_SWITCH_CONTEXT switchContext,
} else {
vlanTagValue = 0;
vlanTag = (PNDIS_NET_BUFFER_LIST_8021Q_INFO)(PVOID *)&vlanTagValue;
vlan = (struct ovs_action_push_vlan *)nl_attr_get(a);
vlan = (struct ovs_action_push_vlan *)NlAttrGet((const PNL_ATTR)a);
vlanTag->TagHeader.VlanId = ntohs(vlan->vlan_tci) & 0xfff;
vlanTag->TagHeader.UserPriority = ntohs(vlan->vlan_tci) >> 13;

Expand Down Expand Up @@ -1465,19 +1464,19 @@ OvsActionsExecute(POVS_SWITCH_CONTEXT switchContext,

case OVS_ACTION_ATTR_USERSPACE:
{
const struct nlattr *userdata_attr;
const struct nlattr *queue_attr;
PNL_ATTR userdataAttr;
PNL_ATTR queueAttr;
POVS_PACKET_QUEUE_ELEM elem;
UINT32 queueId = OVS_DEFAULT_PACKET_QUEUE;
//XXX confusing that portNo is actually portId for external port.
BOOLEAN isRecv = (portNo == switchContext->externalPortId)
|| OvsIsTunnelVportNo(portNo);

queue_attr = nl_attr_find_nested(a, OVS_USERSPACE_ATTR_PID);
userdata_attr = nl_attr_find_nested(a, OVS_USERSPACE_ATTR_USERDATA);
queueAttr = NlAttrFindNested(a, OVS_USERSPACE_ATTR_PID);
userdataAttr = NlAttrFindNested(a, OVS_USERSPACE_ATTR_USERDATA);

elem = OvsCreateQueuePacket(queueId, (PVOID)userdata_attr,
userdata_attr->nla_len,
elem = OvsCreateQueuePacket(queueId, (PVOID)userdataAttr,
userdataAttr->nlaLen,
OVS_PACKET_CMD_ACTION,
portNo, (OvsIPv4TunnelKey *)&key->tunKey,
ovsFwdCtx.curNbl,
Expand Down Expand Up @@ -1510,7 +1509,8 @@ OvsActionsExecute(POVS_SWITCH_CONTEXT switchContext,
}

status = OvsExecuteSetAction(&ovsFwdCtx, key, hash,
nl_attr_get(a));
(const PNL_ATTR)NlAttrGet
((const PNL_ATTR)a));
if (status != NDIS_STATUS_SUCCESS) {
dropReason = L"OVS-set action failed";
goto dropit;
Expand Down
1 change: 1 addition & 0 deletions datapath-windows/ovsext/OvsDebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#define OVS_DBG_IPHELPER BIT32(18)
#define OVS_DBG_BUFMGMT BIT32(19)
#define OVS_DBG_OTHERS BIT32(21)
#define OVS_DBG_NETLINK BIT32(22)

#define OVS_DBG_RESERVED BIT32(31)
//Please add above OVS_DBG_RESERVED.
Expand Down
2 changes: 1 addition & 1 deletion datapath-windows/ovsext/OvsFlow.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ typedef struct _OvsFlow {
UINT64 byteCount;
UINT32 userActionsLen; // used for flow query
UINT32 actionBufferLen; // used for flow reuse
struct nlattr actions[1];
NL_ATTR actions[1];
} OvsFlow;


Expand Down
2 changes: 1 addition & 1 deletion datapath-windows/ovsext/OvsPacketIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ NDIS_STATUS OvsActionsExecute(POVS_SWITCH_CONTEXT switchContext,
PNET_BUFFER_LIST curNbl, UINT32 srcVportNo,
ULONG sendFlags, OvsFlowKey *key, UINT64 *hash,
OVS_PACKET_HDR_INFO *layers,
const struct nlattr *actions, int actionsLen);
const PNL_ATTR actions, int actionsLen);

VOID OvsLookupFlowOutput(POVS_SWITCH_CONTEXT switchContext,
VOID *compList, PNET_BUFFER_LIST curNbl);
Expand Down
4 changes: 2 additions & 2 deletions datapath-windows/ovsext/OvsUser.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ OvsExecuteDpIoctl(PVOID inputBuffer,
OvsPacketExecute *execute;
LOCK_STATE_EX lockState;
PNET_BUFFER_LIST pNbl;
struct nlattr *actions;
PNL_ATTR actions;
PNDIS_SWITCH_FORWARDING_DETAIL_NET_BUFFER_LIST_INFO fwdDetail;
OvsFlowKey key;
OVS_PACKET_HDR_INFO layers;
Expand Down Expand Up @@ -338,7 +338,7 @@ OvsExecuteDpIoctl(PVOID inputBuffer,
status = STATUS_INFO_LENGTH_MISMATCH;
goto unlock;
}
actions = (struct nlattr *)((PCHAR)&execute->actions + execute->packetLen);
actions = (PNL_ATTR)((PCHAR)&execute->actions + execute->packetLen);

/*
* Allocate the NBL, copy the data from the userspace buffer. Allocate
Expand Down
3 changes: 3 additions & 0 deletions datapath-windows/ovsext/ovsext.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
<ClInclude Include="OvsBufferMgmt.h" />
<ClInclude Include="OvsChecksum.h" />
<ClInclude Include="Datapath.h" />
<ClInclude Include="Netlink.h" />
<ClInclude Include="NetlinkProto.h" />
<ClInclude Include="OvsDebug.h" />
<ClInclude Include="OvsEth.h" />
<ClInclude Include="OvsEvent.h" />
Expand Down Expand Up @@ -125,6 +127,7 @@
</ClCompile>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="Netlink.c" />
<ClCompile Include="Datapath.c" />
<ClCompile Include="OvsDriver.c" />
<ClCompile Include="OvsJhash.c" />
Expand Down
2 changes: 2 additions & 0 deletions datapath-windows/ovsext/precomp.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include "OvsTypes.h"
#include "..\include\OvsPub.h"
#include "OvsUtil.h"
#include "Netlink.h"
#include "NetlinkProto.h"
/*
* Include openvswitch.h from userspace. Changing the location the file from
* include/linux is pending discussion.
Expand Down

0 comments on commit d838e57

Please sign in to comment.