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 <ankursha...@vmware.com> Acked-by: Nithin Raju <nit...@vmware.com> --- datapath-windows/ovsext/Netlink/Netlink.c | 66 +++++++++++++++++++++++++++---- datapath-windows/ovsext/Netlink/Netlink.h | 5 +++ 2 files changed, 63 insertions(+), 8 deletions(-) diff --git a/datapath-windows/ovsext/Netlink/Netlink.c b/datapath-windows/ovsext/Netlink/Netlink.c index 0c4f847..7ec651f 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 26772b7..cd55647 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); -- 1.9.1 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev