summaryrefslogtreecommitdiff
path: root/datapath-windows/ovsext/Netlink
diff options
context:
space:
mode:
authorAnkur Sharma <ankursharma@vmware.com>2014-10-03 15:53:41 -0700
committerBen Pfaff <blp@nicira.com>2014-10-06 15:26:31 -0700
commite6ac5e9ea90efd0edb6ae0b0e6f70bf59795f42b (patch)
tree0e066aed388d51657b32f6a4103b920a9e67e59b /datapath-windows/ovsext/Netlink
parent1786535e7ef76d3bd3de5b15b8f22083eb5beb7e (diff)
downloadopenvswitch-e6ac5e9ea90efd0edb6ae0b0e6f70bf59795f42b.tar.gz
datapath-windows: Netlink additional APIs.
In this patch we have added following new APIs. NlMsgAlignSize => Aligns the size of netlink message. NlMsgSetSize => Sets the value of nlmsgLen. Signed-off-by: Ankur Sharma <ankursharma@vmware.com> Acked-by: Nithin Raju <nithin@vmware.com> Acked-by: Alin Gabriel Serdean <aserdean@cloudbasesolutions.com> Signed-off-by: Ben Pfaff <blp@nicira.com>
Diffstat (limited to 'datapath-windows/ovsext/Netlink')
-rw-r--r--datapath-windows/ovsext/Netlink/Netlink.c66
-rw-r--r--datapath-windows/ovsext/Netlink/Netlink.h5
2 files changed, 63 insertions, 8 deletions
diff --git a/datapath-windows/ovsext/Netlink/Netlink.c b/datapath-windows/ovsext/Netlink/Netlink.c
index 0c4f84742..7ec651f08 100644
--- a/datapath-windows/ovsext/Netlink/Netlink.c
+++ b/datapath-windows/ovsext/Netlink/Netlink.c
@@ -34,7 +34,9 @@
/*
* ---------------------------------------------------------------------------
- * Prepare netlink message headers. Attributes should be added by caller.
+ * Prepare netlink message headers. This API adds
+ * NL_MSG_HDR + GENL_HDR + OVS_HDR to the tail of input NLBuf.
+ * Attributes should be added by caller.
* ---------------------------------------------------------------------------
*/
NTSTATUS
@@ -44,16 +46,18 @@ NlFillOvsMsg(PNL_BUFFER nlBuf, UINT16 nlmsgType,
UINT8 genlVer, UINT32 dpNo)
{
BOOLEAN writeOk;
- PNL_MSG_HDR nlMsg;
OVS_MESSAGE msgOut;
UINT32 offset = NlBufSize(nlBuf);
+ /* To keep compiler happy for release build. */
+ UNREFERENCED_PARAMETER(offset);
ASSERT(NlBufAt(nlBuf, offset, sizeof(struct _OVS_MESSAGE)) != 0);
msgOut.nlMsg.nlmsgType = nlmsgType;
msgOut.nlMsg.nlmsgFlags = nlmsgFlags;
msgOut.nlMsg.nlmsgSeq = nlmsgSeq;
msgOut.nlMsg.nlmsgPid = nlmsgPid;
+ msgOut.nlMsg.nlmsgLen = sizeof(struct _OVS_MESSAGE);
msgOut.genlMsg.cmd = genlCmd;
msgOut.genlMsg.version = genlVer;
@@ -64,14 +68,37 @@ NlFillOvsMsg(PNL_BUFFER nlBuf, UINT16 nlmsgType,
writeOk = NlMsgPutTail(nlBuf, (PCHAR)(&msgOut),
sizeof (struct _OVS_MESSAGE));
- if (!writeOk) {
- goto done;
- }
+ return writeOk ? STATUS_SUCCESS : STATUS_INVALID_BUFFER_SIZE;
+}
- nlMsg = (PNL_MSG_HDR)NlBufAt(nlBuf, offset, sizeof(struct _NL_MSG_HDR));
- nlMsg->nlmsgLen = sizeof(struct _OVS_MESSAGE);
+/*
+ * ---------------------------------------------------------------------------
+ * Prepare NL_MSG_HDR only. This API appends a NL_MSG_HDR to the tail of
+ * input NlBuf.
+ * ---------------------------------------------------------------------------
+ */
+NTSTATUS
+NlFillNlHdr(PNL_BUFFER nlBuf, UINT16 nlmsgType,
+ UINT16 nlmsgFlags, UINT32 nlmsgSeq,
+ UINT32 nlmsgPid)
+{
+ BOOLEAN writeOk;
+ NL_MSG_HDR msgOut;
+ UINT32 offset = NlBufSize(nlBuf);
+
+ /* To keep compiler happy for release build. */
+ UNREFERENCED_PARAMETER(offset);
+ ASSERT(NlBufAt(nlBuf, offset, sizeof(struct _NL_MSG_HDR)) != 0);
+
+ msgOut.nlmsgType = nlmsgType;
+ msgOut.nlmsgFlags = nlmsgFlags;
+ msgOut.nlmsgSeq = nlmsgSeq;
+ msgOut.nlmsgPid = nlmsgPid;
+ msgOut.nlmsgLen = sizeof(struct _NL_MSG_HDR);
+
+ writeOk = NlMsgPutTail(nlBuf, (PCHAR)(&msgOut),
+ sizeof(struct _NL_MSG_HDR));
-done:
return writeOk ? STATUS_SUCCESS : STATUS_INVALID_BUFFER_SIZE;
}
@@ -554,6 +581,29 @@ NlMsgSize(const PNL_MSG_HDR nlh)
/*
* ---------------------------------------------------------------------------
+ * Aligns the size of Netlink message.
+ * ---------------------------------------------------------------------------
+ */
+VOID
+NlMsgAlignSize(const PNL_MSG_HDR nlh)
+{
+ nlh->nlmsgLen = NLMSG_ALIGN(nlh->nlmsgLen);
+ return;
+}
+
+/*
+ * ---------------------------------------------------------------------------
+ * Sets the size of Netlink message.
+ * ---------------------------------------------------------------------------
+ */
+VOID
+NlMsgSetSize(const PNL_MSG_HDR nlh, UINT32 msgLen)
+{
+ nlh->nlmsgLen = msgLen;
+}
+
+/*
+ * ---------------------------------------------------------------------------
* Returns pointer to nlmsg payload.
* ---------------------------------------------------------------------------
*/
diff --git a/datapath-windows/ovsext/Netlink/Netlink.h b/datapath-windows/ovsext/Netlink/Netlink.h
index 26772b7a0..cd5564700 100644
--- a/datapath-windows/ovsext/Netlink/Netlink.h
+++ b/datapath-windows/ovsext/Netlink/Netlink.h
@@ -82,10 +82,15 @@ NTSTATUS NlFillOvsMsg(PNL_BUFFER nlBuf,
UINT16 nlmsgType, UINT16 nlmsgFlags,
UINT32 nlmsgSeq, UINT32 nlmsgPid,
UINT8 genlCmd, UINT8 genlVer, UINT32 dpNo);
+NTSTATUS NlFillNlHdr(PNL_BUFFER nlBuf,
+ UINT16 nlmsgType, UINT16 nlmsgFlags,
+ UINT32 nlmsgSeq, UINT32 nlmsgPid);
/* Netlink message accessing the payload */
PVOID NlMsgAt(const PNL_MSG_HDR nlh, UINT32 offset);
UINT32 NlMsgSize(const PNL_MSG_HDR nlh);
+VOID NlMsgAlignSize(const PNL_MSG_HDR nlh);
+VOID NlMsgSetSize(const PNL_MSG_HDR nlh, UINT32 msgLen);
PCHAR NlHdrPayload(const PNL_MSG_HDR nlh);
UINT32 NlHdrPayloadLen(const PNL_MSG_HDR nlh);
PNL_ATTR NlMsgAttrs(const PNL_MSG_HDR nlh);