mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 20:45:18 +00:00
netlink: Introduce macro NETLINK_MSG_APPEND to wrap nlmsg_append
Introduce a macro NETLINK_MSG_APPEND to wrap nlmsg_append and simplify code. Remove those labels 'buffer_too_small', since they are now useless. Signed-off-by: Shi Lei <shi_lei@massclouds.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
121fdeacdf
commit
871eba4d99
@ -72,6 +72,15 @@ do { \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
# define NETLINK_MSG_APPEND(msg, datalen, dataptr) \
|
||||
do { \
|
||||
if (nlmsg_append(msg, dataptr, datalen, NLMSG_ALIGNTO) < 0) { \
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", \
|
||||
_("allocated netlink buffer is too small")); \
|
||||
return -1; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
|
||||
/* State for a single netlink event handle */
|
||||
struct virNetlinkEventHandle {
|
||||
@ -432,8 +441,7 @@ virNetlinkDumpLink(const char *ifname, int ifindex,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (nlmsg_append(nl_msg, &ifinfo, sizeof(ifinfo), NLMSG_ALIGNTO) < 0)
|
||||
goto buffer_too_small;
|
||||
NETLINK_MSG_APPEND(nl_msg, sizeof(ifinfo), &ifinfo);
|
||||
|
||||
if (ifname)
|
||||
NETLINK_MSG_PUT(nl_msg, IFLA_IFNAME, (strlen(ifname) + 1), ifname);
|
||||
@ -491,11 +499,6 @@ virNetlinkDumpLink(const char *ifname, int ifindex,
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("malformed netlink response message"));
|
||||
return rc;
|
||||
|
||||
buffer_too_small:
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("allocated netlink buffer is too small"));
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
@ -545,8 +548,7 @@ virNetlinkNewLink(const char *ifname,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (nlmsg_append(nl_msg, &ifinfo, sizeof(ifinfo), NLMSG_ALIGNTO) < 0)
|
||||
goto buffer_too_small;
|
||||
NETLINK_MSG_APPEND(nl_msg, sizeof(ifinfo), &ifinfo);
|
||||
|
||||
NETLINK_MSG_PUT(nl_msg, IFLA_IFNAME, (strlen(ifname) + 1), ifname);
|
||||
|
||||
@ -620,11 +622,6 @@ virNetlinkNewLink(const char *ifname,
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("malformed netlink response message"));
|
||||
return -1;
|
||||
|
||||
buffer_too_small:
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("allocated netlink buffer is too small"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@ -658,8 +655,7 @@ virNetlinkDelLink(const char *ifname, virNetlinkDelLinkFallback fallback)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (nlmsg_append(nl_msg, &ifinfo, sizeof(ifinfo), NLMSG_ALIGNTO) < 0)
|
||||
goto buffer_too_small;
|
||||
NETLINK_MSG_APPEND(nl_msg, sizeof(ifinfo), &ifinfo);
|
||||
|
||||
NETLINK_MSG_PUT(nl_msg, IFLA_IFNAME, (strlen(ifname) + 1), ifname);
|
||||
|
||||
@ -701,11 +697,6 @@ virNetlinkDelLink(const char *ifname, virNetlinkDelLinkFallback fallback)
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("malformed netlink response message"));
|
||||
return -1;
|
||||
|
||||
buffer_too_small:
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("allocated netlink buffer is too small"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -740,9 +731,7 @@ virNetlinkGetNeighbor(void **nlData, uint32_t src_pid, uint32_t dst_pid)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (nlmsg_append(nl_msg, &ndinfo, sizeof(ndinfo), NLMSG_ALIGNTO) < 0)
|
||||
goto buffer_too_small;
|
||||
|
||||
NETLINK_MSG_APPEND(nl_msg, sizeof(ndinfo), &ndinfo);
|
||||
|
||||
if (virNetlinkCommand(nl_msg, &resp, &recvbuflen,
|
||||
src_pid, dst_pid, NETLINK_ROUTE, 0) < 0)
|
||||
@ -778,11 +767,6 @@ virNetlinkGetNeighbor(void **nlData, uint32_t src_pid, uint32_t dst_pid)
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("malformed netlink response message"));
|
||||
return -1;
|
||||
|
||||
buffer_too_small:
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("allocated netlink buffer is too small"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
|
Loading…
x
Reference in New Issue
Block a user