This patch replaces virNetDevPutExtraHeader with nlmsg_append directly. Signed-off-by: Shi Lei <shi_...@massclouds.com> --- src/util/virnetdev.c | 44 ++++++++++++-------------------------------- 1 file changed, 12 insertions(+), 32 deletions(-)
diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index 892a147..a7bc8e0 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -3155,28 +3155,6 @@ virNetDevGetEthtoolFeatures(virBitmapPtr bitmap, # if HAVE_DECL_DEVLINK_CMD_ESWITCH_GET -/** - * virNetDevPutExtraHeader - * reserve and prepare room for an extra header - * This function sets to zero the room that is required to put the extra - * header after the initial Netlink header. This function also increases - * the nlmsg_len field. - * - * @nlh: pointer to Netlink header - * @size: size of the extra header that we want to put - * - * Returns pointer to the start of the extended header - */ -static void * -virNetDevPutExtraHeader(struct nlmsghdr *nlh, - size_t size) -{ - char *ptr = (char *)nlh + nlh->nlmsg_len; - size_t len = NLMSG_ALIGN(size); - nlh->nlmsg_len += len; - return ptr; -} - /** * virNetDevGetFamilyId: @@ -3191,7 +3169,11 @@ virNetDevGetFamilyId(const char *family_name) { struct nl_msg *nl_msg = NULL; struct nlmsghdr *resp = NULL; - struct genlmsghdr* gmsgh = NULL; + struct genlmsghdr gmsgh = { + .cmd = CTRL_CMD_GETFAMILY, + .version = DEVLINK_GENL_VERSION, + .reserved = 0, + }; struct nlattr *tb[CTRL_ATTR_MAX + 1] = {NULL, }; unsigned int recvbuflen; uint32_t family_id = 0; @@ -3202,12 +3184,9 @@ virNetDevGetFamilyId(const char *family_name) goto cleanup; } - if (!(gmsgh = virNetDevPutExtraHeader(nlmsg_hdr(nl_msg), sizeof(struct genlmsghdr)))) + if (nlmsg_append(nl_msg, &gmsgh, sizeof(gmsgh), NLMSG_ALIGNTO) < 0) goto cleanup; - gmsgh->cmd = CTRL_CMD_GETFAMILY; - gmsgh->version = DEVLINK_GENL_VERSION; - if (nla_put_string(nl_msg, CTRL_ATTR_FAMILY_NAME, family_name) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("allocated netlink buffer is too small")); @@ -3254,7 +3233,11 @@ virNetDevSwitchdevFeature(const char *ifname, unsigned int recvbuflen; struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {NULL, }; virPCIDevicePtr pci_device_ptr = NULL; - struct genlmsghdr* gmsgh = NULL; + struct genlmsghdr gmsgh = { + .cmd = DEVLINK_CMD_ESWITCH_GET, + .version = DEVLINK_GENL_VERSION, + .reserved = 0, + }; const char *pci_name; char *pfname = NULL; int is_vf = -1; @@ -3284,12 +3267,9 @@ virNetDevSwitchdevFeature(const char *ifname, goto cleanup; } - if (!(gmsgh = virNetDevPutExtraHeader(nlmsg_hdr(nl_msg), sizeof(struct genlmsghdr)))) + if (nlmsg_append(nl_msg, &gmsgh, sizeof(gmsgh), NLMSG_ALIGNTO) < 0) goto cleanup; - gmsgh->cmd = DEVLINK_CMD_ESWITCH_GET; - gmsgh->version = DEVLINK_GENL_VERSION; - pci_name = virPCIDeviceGetName(pci_device_ptr); if (nla_put(nl_msg, DEVLINK_ATTR_BUS_NAME, strlen("pci")+1, "pci") < 0 || -- 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list