Skip to content

Commit

Permalink
datapath-windows: Transactional error support in Flow commands.
Browse files Browse the repository at this point in the history
In this patch we added the code to handle transactional errors
in flow commands.

Signed-off-by: Ankur Sharma <ankursharma@vmware.com>
Acked-by: Nithin Raju <nithin@vmware.com
Signed-off-by: Ben Pfaff <blp@nicira.com>
  • Loading branch information
ankursh authored and blp committed Oct 13, 2014
1 parent d752e05 commit 1cf7853
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 20 deletions.
66 changes: 47 additions & 19 deletions datapath-windows/ovsext/Flow.c
Expand Up @@ -261,6 +261,7 @@ OvsFlowNlCmdHandler(POVS_USER_PARAMS_CONTEXT usrParamsCtx,
OvsFlowPut mappedFlow;
OvsFlowStats stats;
struct ovs_flow_stats replyStats;
NL_ERROR nlError = NL_ERROR_SUCCESS;

NL_BUFFER nlBuf;

Expand All @@ -270,13 +271,19 @@ OvsFlowNlCmdHandler(POVS_USER_PARAMS_CONTEXT usrParamsCtx,

*replyLen = 0;

if (!(usrParamsCtx->outputBuffer)) {
/* No output buffer */
rc = STATUS_INVALID_BUFFER_SIZE;
goto done;
}

/* Get all the top level Flow attributes */
if ((NlAttrParse(nlMsgHdr, attrOffset, NlMsgAttrsLen(nlMsgHdr),
nlFlowPolicy, nlAttrs, ARRAY_SIZE(nlAttrs)))
!= TRUE) {
OVS_LOG_ERROR("Attr Parsing failed for msg: %p",
nlMsgHdr);
rc = STATUS_UNSUCCESSFUL;
rc = STATUS_INVALID_PARAMETER;
goto done;
}

Expand All @@ -287,7 +294,7 @@ OvsFlowNlCmdHandler(POVS_USER_PARAMS_CONTEXT usrParamsCtx,
goto done;
}

if ((_MapNlToFlowPut(msgIn, nlAttrs[OVS_FLOW_ATTR_KEY],
if ((rc = _MapNlToFlowPut(msgIn, nlAttrs[OVS_FLOW_ATTR_KEY],
nlAttrs[OVS_FLOW_ATTR_ACTIONS], nlAttrs[OVS_FLOW_ATTR_CLEAR],
&mappedFlow))
!= STATUS_SUCCESS) {
Expand All @@ -302,12 +309,6 @@ OvsFlowNlCmdHandler(POVS_USER_PARAMS_CONTEXT usrParamsCtx,
goto done;
}

if (!(usrParamsCtx->outputBuffer)) {
/* No output buffer */
OVS_LOG_ERROR("outputBuffer NULL.");
goto done;
}

replyStats.n_packets = stats.packetCount;
replyStats.n_bytes = stats.byteCount;

Expand All @@ -326,14 +327,23 @@ OvsFlowNlCmdHandler(POVS_USER_PARAMS_CONTEXT usrParamsCtx,
if (!NlMsgPutTailUnspec(&nlBuf, OVS_FLOW_ATTR_STATS,
(PCHAR)(&replyStats), sizeof(replyStats))) {
OVS_LOG_ERROR("Adding OVS_FLOW_ATTR_STATS attribute failed.");
rc = STATUS_UNSUCCESSFUL;
rc = STATUS_INVALID_BUFFER_SIZE;
goto done;
}

msgOut->nlMsg.nlmsgLen = NLMSG_ALIGN(NlBufSize(&nlBuf));
*replyLen = msgOut->nlMsg.nlmsgLen;

done:

if ((nlError != NL_ERROR_SUCCESS) &&
(usrParamsCtx->outputBuffer)) {
POVS_MESSAGE_ERROR msgError = (POVS_MESSAGE_ERROR)
usrParamsCtx->outputBuffer;
BuildErrorMsg(msgIn, msgError, nlError);
*replyLen = msgError->nlMsg.nlmsgLen;
}

return rc;
}

Expand All @@ -348,14 +358,32 @@ OvsFlowNlGetCmdHandler(POVS_USER_PARAMS_CONTEXT usrParamsCtx,
UINT32 *replyLen)
{
NTSTATUS rc = STATUS_SUCCESS;
NL_ERROR nlError = NL_ERROR_SUCCESS;
POVS_MESSAGE msgIn = (POVS_MESSAGE)usrParamsCtx->inputBuffer;

*replyLen = 0;

if (!(usrParamsCtx->outputBuffer)) {
/* No output buffer */
rc = STATUS_INVALID_BUFFER_SIZE;
goto done;
}

if (usrParamsCtx->devOp == OVS_TRANSACTION_DEV_OP) {
rc = _FlowNlGetCmdHandler(usrParamsCtx, replyLen);
} else {
rc = _FlowNlDumpCmdHandler(usrParamsCtx, replyLen);
}

if ((nlError != NL_ERROR_SUCCESS) &&
(usrParamsCtx->outputBuffer)) {
POVS_MESSAGE_ERROR msgError = (POVS_MESSAGE_ERROR)
usrParamsCtx->outputBuffer;
BuildErrorMsg(msgIn, msgError, nlError);
*replyLen = msgError->nlMsg.nlmsgLen;
}

done:
return rc;
}

Expand Down Expand Up @@ -410,7 +438,7 @@ _FlowNlGetCmdHandler(POVS_USER_PARAMS_CONTEXT usrParamsCtx,
!= TRUE) {
OVS_LOG_ERROR("Attr Parsing failed for msg: %p",
nlMsgHdr);
rc = STATUS_UNSUCCESSFUL;
rc = STATUS_INVALID_PARAMETER;
goto done;
}

Expand All @@ -424,7 +452,7 @@ _FlowNlGetCmdHandler(POVS_USER_PARAMS_CONTEXT usrParamsCtx,
!= TRUE) {
OVS_LOG_ERROR("Key Attr Parsing failed for msg: %p",
nlMsgHdr);
rc = STATUS_UNSUCCESSFUL;
rc = STATUS_INVALID_PARAMETER;
goto done;
}

Expand All @@ -441,7 +469,7 @@ _FlowNlGetCmdHandler(POVS_USER_PARAMS_CONTEXT usrParamsCtx,
!= TRUE) {
OVS_LOG_ERROR("Tunnel key Attr Parsing failed for msg: %p",
nlMsgHdr);
rc = STATUS_UNSUCCESSFUL;
rc = STATUS_INVALID_PARAMETER;
goto done;
}
}
Expand Down Expand Up @@ -657,19 +685,19 @@ _MapFlowStatsToNlStats(PNL_BUFFER nlBuf, OvsFlowStats *flowStats)
replyStats.n_bytes = flowStats->byteCount;

if (!NlMsgPutTailU64(nlBuf, OVS_FLOW_ATTR_USED, flowStats->used)) {
rc = STATUS_UNSUCCESSFUL;
rc = STATUS_INVALID_BUFFER_SIZE;
goto done;
}

if (!NlMsgPutTailUnspec(nlBuf, OVS_FLOW_ATTR_STATS,
(PCHAR)(&replyStats),
sizeof(struct ovs_flow_stats))) {
rc = STATUS_UNSUCCESSFUL;
rc = STATUS_INVALID_BUFFER_SIZE;
goto done;
}

if (!NlMsgPutTailU8(nlBuf, OVS_FLOW_ATTR_TCP_FLAGS, flowStats->tcpFlags)) {
rc = STATUS_UNSUCCESSFUL;
rc = STATUS_INVALID_BUFFER_SIZE;
goto done;
}

Expand All @@ -693,13 +721,13 @@ _MapFlowActionToNlAction(PNL_BUFFER nlBuf, uint32_t actionsLen,
offset = NlMsgStartNested(nlBuf, OVS_FLOW_ATTR_ACTIONS);
if (!offset) {
/* Starting the nested attribute failed. */
rc = STATUS_UNSUCCESSFUL;
rc = STATUS_INVALID_BUFFER_SIZE;
goto error_nested_start;
}

if (!NlBufCopyAtTail(nlBuf, (PCHAR)actions, actionsLen)) {
/* Adding a nested attribute failed. */
rc = STATUS_UNSUCCESSFUL;
rc = STATUS_INVALID_BUFFER_SIZE;
goto done;
}

Expand Down Expand Up @@ -1118,7 +1146,7 @@ _MapNlToFlowPut(POVS_MESSAGE msgIn, PNL_ATTR keyAttr,
!= TRUE) {
OVS_LOG_ERROR("Key Attr Parsing failed for msg: %p",
nlMsgHdr);
rc = STATUS_UNSUCCESSFUL;
rc = STATUS_INVALID_PARAMETER;
goto done;
}

Expand All @@ -1137,7 +1165,7 @@ _MapNlToFlowPut(POVS_MESSAGE msgIn, PNL_ATTR keyAttr,
!= TRUE) {
OVS_LOG_ERROR("Tunnel key Attr Parsing failed for msg: %p",
nlMsgHdr);
rc = STATUS_UNSUCCESSFUL;
rc = STATUS_INVALID_PARAMETER;
goto done;
}
}
Expand Down
2 changes: 1 addition & 1 deletion datapath-windows/ovsext/Netlink/NetlinkError.h
Expand Up @@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http :/*www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand Down

0 comments on commit 1cf7853

Please sign in to comment.