diff options
author | Nithin Raju <nithin@vmware.com> | 2014-12-03 07:56:00 -0800 |
---|---|---|
committer | Ben Pfaff <blp@nicira.com> | 2014-12-05 10:30:20 -0800 |
commit | fa8266a805b46891854d1fd48827514c7a1f0b55 (patch) | |
tree | b4ffc673a7f648e08fd2358df86b013b77324a80 /datapath-windows/ovsext/Netlink | |
parent | 3100516ad790b20e449b67a848e071dc5bd3f8d3 (diff) | |
download | openvswitch-fa8266a805b46891854d1fd48827514c7a1f0b55.tar.gz |
datapath-windows: Move Build*Msg() to Netlink.c
Moving the functions that build netlink messages to Netlink.c from
Vport.c
Signed-off-by: Nithin Raju <nithin@vmware.com>
Acked-by: Eitan Eliahu <eliahue@vmware.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
Diffstat (limited to 'datapath-windows/ovsext/Netlink')
-rw-r--r-- | datapath-windows/ovsext/Netlink/Netlink.c | 37 | ||||
-rw-r--r-- | datapath-windows/ovsext/Netlink/Netlink.h | 13 |
2 files changed, 50 insertions, 0 deletions
diff --git a/datapath-windows/ovsext/Netlink/Netlink.c b/datapath-windows/ovsext/Netlink/Netlink.c index ae10a870d..7633f2ff1 100644 --- a/datapath-windows/ovsext/Netlink/Netlink.c +++ b/datapath-windows/ovsext/Netlink/Netlink.c @@ -102,6 +102,43 @@ NlFillNlHdr(PNL_BUFFER nlBuf, UINT16 nlmsgType, return writeOk ? STATUS_SUCCESS : STATUS_INVALID_BUFFER_SIZE; } +static VOID +BuildMsgOut(POVS_MESSAGE msgIn, POVS_MESSAGE msgOut, UINT16 type, + UINT32 length, UINT16 flags) +{ + msgOut->nlMsg.nlmsgType = type; + msgOut->nlMsg.nlmsgFlags = flags; + msgOut->nlMsg.nlmsgSeq = msgIn->nlMsg.nlmsgSeq; + msgOut->nlMsg.nlmsgPid = msgIn->nlMsg.nlmsgPid; + msgOut->nlMsg.nlmsgLen = length; + + msgOut->genlMsg.cmd = msgIn->genlMsg.cmd; + msgOut->genlMsg.version = msgIn->genlMsg.version; + msgOut->genlMsg.reserved = 0; +} + +/* + * XXX: should move out these functions to a Netlink.c or to a OvsMessage.c + * or even make them inlined functions in Datapath.h. Can be done after the + * first sprint once we have more code to refactor. + */ +VOID +BuildReplyMsgFromMsgIn(POVS_MESSAGE msgIn, POVS_MESSAGE msgOut, UINT16 flags) +{ + BuildMsgOut(msgIn, msgOut, msgIn->nlMsg.nlmsgType, sizeof(OVS_MESSAGE), + flags); +} + +VOID +BuildErrorMsg(POVS_MESSAGE msgIn, POVS_MESSAGE_ERROR msgOut, UINT errorCode) +{ + BuildMsgOut(msgIn, (POVS_MESSAGE)msgOut, NLMSG_ERROR, + sizeof(OVS_MESSAGE_ERROR), 0); + + msgOut->errorMsg.error = errorCode; + msgOut->errorMsg.nlMsg = msgIn->nlMsg; +} + /* * --------------------------------------------------------------------------- * Adds Netlink Header to the NL_BUF. diff --git a/datapath-windows/ovsext/Netlink/Netlink.h b/datapath-windows/ovsext/Netlink/Netlink.h index 438d8571a..18e40b133 100644 --- a/datapath-windows/ovsext/Netlink/Netlink.h +++ b/datapath-windows/ovsext/Netlink/Netlink.h @@ -32,6 +32,14 @@ typedef struct _OVS_MESSAGE { /* Variable length nl_attrs follow. */ } OVS_MESSAGE, *POVS_MESSAGE; +/* + * Structure of an error message sent as a reply from kernel. + */ +typedef struct _OVS_MESSAGE_ERROR { + NL_MSG_HDR nlMsg; + NL_MSG_ERR errorMsg; +} OVS_MESSAGE_ERROR, *POVS_MESSAGE_ERROR; + /* Netlink attribute types. */ typedef enum { @@ -86,6 +94,11 @@ NTSTATUS NlFillNlHdr(PNL_BUFFER nlBuf, UINT16 nlmsgType, UINT16 nlmsgFlags, UINT32 nlmsgSeq, UINT32 nlmsgPid); +VOID BuildReplyMsgFromMsgIn(POVS_MESSAGE msgIn, POVS_MESSAGE msgOut, + UINT16 flags); +VOID BuildErrorMsg(POVS_MESSAGE msgIn, POVS_MESSAGE_ERROR msgOut, + UINT errorCode); + /* Netlink message accessing the payload */ PVOID NlMsgAt(const PNL_MSG_HDR nlh, UINT32 offset); UINT32 NlMsgSize(const PNL_MSG_HDR nlh); |