Update netlink attribute parsing to use the appropriate policy array size. This patch also initialize all netlink attributes before parsing them.
Signed-off-by: Alin Gabriel Serdean <aserd...@cloudbasesolutions.com> --- datapath-windows/ovsext/Vport.c | 109 ++++++++++++++-------------------------- 1 file changed, 39 insertions(+), 70 deletions(-) diff --git a/datapath-windows/ovsext/Vport.c b/datapath-windows/ovsext/Vport.c index 4315464..0b72aed 100644 --- a/datapath-windows/ovsext/Vport.c +++ b/datapath-windows/ovsext/Vport.c @@ -97,6 +97,20 @@ static VOID OvsTunnelVportPendingRemove(PVOID context, UINT32 *replyLen); +static const NL_POLICY ovsVportPolicy[__OVS_VPORT_ATTR_MAX] = { + [OVS_VPORT_ATTR_PORT_NO] = { .type = NL_A_U32, .optional = TRUE }, + [OVS_VPORT_ATTR_TYPE] = { .type = NL_A_U32, .optional = TRUE }, + [OVS_VPORT_ATTR_NAME] = { .type = NL_A_STRING, .maxLen = IFNAMSIZ, + .optional = TRUE }, + [OVS_VPORT_ATTR_UPCALL_PID] = { .type = NL_A_UNSPEC, + .optional = TRUE }, + [OVS_VPORT_ATTR_STATS] = { .type = NL_A_UNSPEC, + .minLen = sizeof(OVS_VPORT_FULL_STATS), + .maxLen = sizeof(OVS_VPORT_FULL_STATS), + .optional = TRUE }, + [OVS_VPORT_ATTR_OPTIONS] = { .type = NL_A_NESTED, .optional = TRUE }, +}; + /* * Functions implemented in relaton to NDIS port manipulation. */ @@ -271,7 +285,7 @@ HvDeletePort(POVS_SWITCH_CONTEXT switchContext, * counterpart was deleted. If the datapath port counterpart is present, * we only mark the vport for deletion, so that a netlink command vport * delete will delete the vport. - */ + */ if (vport) { OvsRemoveAndDeleteVport(NULL, switchContext, vport, TRUE, FALSE); } else { @@ -1619,7 +1633,7 @@ OvsGetNetdevCmdHandler(POVS_USER_PARAMS_CONTEXT usrParamsCtx, .minLen = 2, .maxLen = IFNAMSIZ }, }; - PNL_ATTR netdevAttrs[ARRAY_SIZE(ovsNetdevPolicy)]; + PNL_ATTR netdevAttrs[ARRAY_SIZE(ovsNetdevPolicy)] = { NULL }; /* input buffer has been validated while validating transaction dev op. */ ASSERT(usrParamsCtx->inputBuffer != NULL && @@ -1630,9 +1644,9 @@ OvsGetNetdevCmdHandler(POVS_USER_PARAMS_CONTEXT usrParamsCtx, } if (!NlAttrParse((PNL_MSG_HDR)msgIn, - NLMSG_HDRLEN + GENL_HDRLEN + OVS_HDRLEN, - NlMsgAttrsLen((PNL_MSG_HDR)msgIn), - ovsNetdevPolicy, netdevAttrs, ARRAY_SIZE(netdevAttrs))) { + NLMSG_HDRLEN + GENL_HDRLEN + OVS_HDRLEN, + NlMsgAttrsLen((PNL_MSG_HDR)msgIn), ovsNetdevPolicy, + netdevAttrs, ARRAY_SIZE(ovsNetdevPolicy))) { return STATUS_INVALID_PARAMETER; } @@ -1957,22 +1971,15 @@ OvsGetVport(POVS_USER_PARAMS_CONTEXT usrParamsCtx, UINT32 portNameLen = 0; UINT32 portNumber = OVS_DPPORT_NUMBER_INVALID; - static const NL_POLICY ovsVportPolicy[] = { - [OVS_VPORT_ATTR_PORT_NO] = { .type = NL_A_U32, .optional = TRUE }, - [OVS_VPORT_ATTR_NAME] = { .type = NL_A_STRING, - .minLen = 2, - .maxLen = IFNAMSIZ, - .optional = TRUE}, - }; - PNL_ATTR vportAttrs[ARRAY_SIZE(ovsVportPolicy)]; + PNL_ATTR vportAttrs[ARRAY_SIZE(ovsVportPolicy)] = { NULL }; /* input buffer has been validated while validating write dev op. */ ASSERT(usrParamsCtx->inputBuffer != NULL); if (!NlAttrParse((PNL_MSG_HDR)msgIn, - NLMSG_HDRLEN + GENL_HDRLEN + OVS_HDRLEN, - NlMsgAttrsLen((PNL_MSG_HDR)msgIn), - ovsVportPolicy, vportAttrs, ARRAY_SIZE(vportAttrs))) { + NLMSG_HDRLEN + GENL_HDRLEN + OVS_HDRLEN, + NlMsgAttrsLen((PNL_MSG_HDR)msgIn), ovsVportPolicy, + vportAttrs, ARRAY_SIZE(ovsVportPolicy))) { return STATUS_INVALID_PARAMETER; } @@ -2092,17 +2099,7 @@ OvsNewVportCmdHandler(POVS_USER_PARAMS_CONTEXT usrParamsCtx, BOOLEAN vportAllocated = FALSE, vportInitialized = FALSE; BOOLEAN addInternalPortAsNetdev = FALSE; - static const NL_POLICY ovsVportPolicy[] = { - [OVS_VPORT_ATTR_PORT_NO] = { .type = NL_A_U32, .optional = TRUE }, - [OVS_VPORT_ATTR_TYPE] = { .type = NL_A_U32, .optional = FALSE }, - [OVS_VPORT_ATTR_NAME] = { .type = NL_A_STRING, .maxLen = IFNAMSIZ, - .optional = FALSE}, - [OVS_VPORT_ATTR_UPCALL_PID] = { .type = NL_A_UNSPEC, - .optional = FALSE }, - [OVS_VPORT_ATTR_OPTIONS] = { .type = NL_A_NESTED, .optional = TRUE }, - }; - - PNL_ATTR vportAttrs[ARRAY_SIZE(ovsVportPolicy)]; + PNL_ATTR vportAttrs[ARRAY_SIZE(ovsVportPolicy)] = { NULL }; /* input buffer has been validated while validating write dev op. */ ASSERT(usrParamsCtx->inputBuffer != NULL); @@ -2111,9 +2108,9 @@ OvsNewVportCmdHandler(POVS_USER_PARAMS_CONTEXT usrParamsCtx, ASSERT(msgOut != NULL && usrParamsCtx->outputLength >= sizeof *msgOut); if (!NlAttrParse((PNL_MSG_HDR)msgIn, - NLMSG_HDRLEN + GENL_HDRLEN + OVS_HDRLEN, - NlMsgAttrsLen((PNL_MSG_HDR)msgIn), - ovsVportPolicy, vportAttrs, ARRAY_SIZE(vportAttrs))) { + NLMSG_HDRLEN + GENL_HDRLEN + OVS_HDRLEN, + NlMsgAttrsLen((PNL_MSG_HDR)msgIn), ovsVportPolicy, + vportAttrs, ARRAY_SIZE(ovsVportPolicy))) { return STATUS_INVALID_PARAMETER; } @@ -2307,27 +2304,14 @@ OvsSetVportCmdHandler(POVS_USER_PARAMS_CONTEXT usrParamsCtx, POVS_VPORT_ENTRY vport = NULL; NL_ERROR nlError = NL_ERROR_SUCCESS; - static const NL_POLICY ovsVportPolicy[] = { - [OVS_VPORT_ATTR_PORT_NO] = { .type = NL_A_U32, .optional = TRUE }, - [OVS_VPORT_ATTR_TYPE] = { .type = NL_A_U32, .optional = TRUE }, - [OVS_VPORT_ATTR_NAME] = { .type = NL_A_STRING, .maxLen = IFNAMSIZ, - .optional = TRUE }, - [OVS_VPORT_ATTR_UPCALL_PID] = { .type = NL_A_UNSPEC, - .optional = TRUE }, - [OVS_VPORT_ATTR_STATS] = { .type = NL_A_UNSPEC, - .minLen = sizeof(OVS_VPORT_FULL_STATS), - .maxLen = sizeof(OVS_VPORT_FULL_STATS), - .optional = TRUE }, - [OVS_VPORT_ATTR_OPTIONS] = { .type = NL_A_NESTED, .optional = TRUE }, - }; - PNL_ATTR vportAttrs[ARRAY_SIZE(ovsVportPolicy)]; + PNL_ATTR vportAttrs[ARRAY_SIZE(ovsVportPolicy)] = { NULL }; ASSERT(usrParamsCtx->inputBuffer != NULL); if (!NlAttrParse((PNL_MSG_HDR)msgIn, - NLMSG_HDRLEN + GENL_HDRLEN + OVS_HDRLEN, - NlMsgAttrsLen((PNL_MSG_HDR)msgIn), - ovsVportPolicy, vportAttrs, ARRAY_SIZE(vportAttrs))) { + NLMSG_HDRLEN + GENL_HDRLEN + OVS_HDRLEN, + NlMsgAttrsLen((PNL_MSG_HDR)msgIn), ovsVportPolicy, + vportAttrs, ARRAY_SIZE(ovsVportPolicy))) { return STATUS_INVALID_PARAMETER; } @@ -2417,19 +2401,14 @@ OvsDeleteVportCmdHandler(POVS_USER_PARAMS_CONTEXT usrParamsCtx, PSTR portName = NULL; UINT32 portNameLen = 0; - static const NL_POLICY ovsVportPolicy[] = { - [OVS_VPORT_ATTR_PORT_NO] = { .type = NL_A_U32, .optional = TRUE }, - [OVS_VPORT_ATTR_NAME] = { .type = NL_A_STRING, .maxLen = IFNAMSIZ, - .optional = TRUE }, - }; - PNL_ATTR vportAttrs[ARRAY_SIZE(ovsVportPolicy)]; + PNL_ATTR vportAttrs[ARRAY_SIZE(ovsVportPolicy)] = { NULL }; ASSERT(usrParamsCtx->inputBuffer != NULL); if (!NlAttrParse((PNL_MSG_HDR)msgIn, - NLMSG_HDRLEN + GENL_HDRLEN + OVS_HDRLEN, - NlMsgAttrsLen((PNL_MSG_HDR)msgIn), - ovsVportPolicy, vportAttrs, ARRAY_SIZE(vportAttrs))) { + NLMSG_HDRLEN + GENL_HDRLEN + OVS_HDRLEN, + NlMsgAttrsLen((PNL_MSG_HDR)msgIn), ovsVportPolicy, + vportAttrs, ARRAY_SIZE(ovsVportPolicy))) { return STATUS_INVALID_PARAMETER; } @@ -2558,17 +2537,7 @@ OvsTunnelVportPendingInit(PVOID context, break; } - static const NL_POLICY ovsVportPolicy[] = { - [OVS_VPORT_ATTR_PORT_NO] = { .type = NL_A_U32, .optional = TRUE }, - [OVS_VPORT_ATTR_TYPE] = { .type = NL_A_U32, .optional = FALSE }, - [OVS_VPORT_ATTR_NAME] = { .type = NL_A_STRING, .maxLen = IFNAMSIZ, - .optional = FALSE }, - [OVS_VPORT_ATTR_UPCALL_PID] = { .type = NL_A_UNSPEC, - .optional = FALSE }, - [OVS_VPORT_ATTR_OPTIONS] = { .type = NL_A_NESTED, .optional = TRUE }, - }; - - PNL_ATTR vportAttrs[ARRAY_SIZE(ovsVportPolicy)]; + PNL_ATTR vportAttrs[ARRAY_SIZE(ovsVportPolicy)] = { NULL }; /* input buffer has been validated while validating write dev op. */ ASSERT(msgIn != NULL); @@ -2577,9 +2546,9 @@ OvsTunnelVportPendingInit(PVOID context, ASSERT(msgOut != NULL && tunnelContext->outputLength >= sizeof *msgOut); if (!NlAttrParse((PNL_MSG_HDR)msgIn, - NLMSG_HDRLEN + GENL_HDRLEN + OVS_HDRLEN, - NlMsgAttrsLen((PNL_MSG_HDR)msgIn), - ovsVportPolicy, vportAttrs, ARRAY_SIZE(vportAttrs))) { + NLMSG_HDRLEN + GENL_HDRLEN + OVS_HDRLEN, + NlMsgAttrsLen((PNL_MSG_HDR)msgIn), ovsVportPolicy, + vportAttrs, ARRAY_SIZE(ovsVportPolicy))) { nlError = NL_ERROR_INVAL; break; } -- 1.9.5.msysgit.0 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev