mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
netlink: Minor changes for macros NETLINK_MSG_[NEST_START|NEST_END|PUT]
Move macros NETLINK_MSG_[NEST_START|NEST_END|PUT] from .h into .c; within these macros, replace 'goto' with reporting error and returning; simplify virNetlinkDumpLink and virNetlinkDelLink by using NETLINK_MSG_PUT. Signed-off-by: Shi Lei <shi_lei@massclouds.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
8133400234
commit
121fdeacdf
@ -44,6 +44,35 @@ VIR_LOG_INIT("util.netlink");
|
|||||||
|
|
||||||
# include <linux/veth.h>
|
# include <linux/veth.h>
|
||||||
|
|
||||||
|
# define NETLINK_MSG_NEST_START(msg, container, attrtype) \
|
||||||
|
do { \
|
||||||
|
container = nla_nest_start(msg, attrtype); \
|
||||||
|
if (!container) { \
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", \
|
||||||
|
_("allocated netlink buffer is too small")); \
|
||||||
|
return -1; \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
# define NETLINK_MSG_NEST_END(msg, container) \
|
||||||
|
do { nla_nest_end(msg, container); } while (0)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* we need to use an intermediary pointer to @data as compilers may sometimes
|
||||||
|
* complain about @data not being a pointer type:
|
||||||
|
* error: the address of 'foo' will always evaluate as 'true' [-Werror=address]
|
||||||
|
*/
|
||||||
|
# define NETLINK_MSG_PUT(msg, attrtype, datalen, data) \
|
||||||
|
do { \
|
||||||
|
const void *dataptr = data; \
|
||||||
|
if (dataptr && nla_put(msg, attrtype, datalen, dataptr) < 0) { \
|
||||||
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", \
|
||||||
|
_("allocated netlink buffer is too small")); \
|
||||||
|
return -1; \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
|
||||||
/* State for a single netlink event handle */
|
/* State for a single netlink event handle */
|
||||||
struct virNetlinkEventHandle {
|
struct virNetlinkEventHandle {
|
||||||
int watch;
|
int watch;
|
||||||
@ -406,10 +435,8 @@ virNetlinkDumpLink(const char *ifname, int ifindex,
|
|||||||
if (nlmsg_append(nl_msg, &ifinfo, sizeof(ifinfo), NLMSG_ALIGNTO) < 0)
|
if (nlmsg_append(nl_msg, &ifinfo, sizeof(ifinfo), NLMSG_ALIGNTO) < 0)
|
||||||
goto buffer_too_small;
|
goto buffer_too_small;
|
||||||
|
|
||||||
if (ifname) {
|
if (ifname)
|
||||||
if (nla_put(nl_msg, IFLA_IFNAME, strlen(ifname)+1, ifname) < 0)
|
NETLINK_MSG_PUT(nl_msg, IFLA_IFNAME, (strlen(ifname) + 1), ifname);
|
||||||
goto buffer_too_small;
|
|
||||||
}
|
|
||||||
|
|
||||||
# ifdef RTEXT_FILTER_VF
|
# ifdef RTEXT_FILTER_VF
|
||||||
/* if this filter exists in the kernel's netlink implementation,
|
/* if this filter exists in the kernel's netlink implementation,
|
||||||
@ -419,10 +446,8 @@ virNetlinkDumpLink(const char *ifname, int ifindex,
|
|||||||
{
|
{
|
||||||
uint32_t ifla_ext_mask = RTEXT_FILTER_VF;
|
uint32_t ifla_ext_mask = RTEXT_FILTER_VF;
|
||||||
|
|
||||||
if (nla_put(nl_msg, IFLA_EXT_MASK,
|
NETLINK_MSG_PUT(nl_msg, IFLA_EXT_MASK,
|
||||||
sizeof(ifla_ext_mask), &ifla_ext_mask) < 0) {
|
sizeof(ifla_ext_mask), &ifla_ext_mask);
|
||||||
goto buffer_too_small;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
@ -636,8 +661,7 @@ virNetlinkDelLink(const char *ifname, virNetlinkDelLinkFallback fallback)
|
|||||||
if (nlmsg_append(nl_msg, &ifinfo, sizeof(ifinfo), NLMSG_ALIGNTO) < 0)
|
if (nlmsg_append(nl_msg, &ifinfo, sizeof(ifinfo), NLMSG_ALIGNTO) < 0)
|
||||||
goto buffer_too_small;
|
goto buffer_too_small;
|
||||||
|
|
||||||
if (nla_put(nl_msg, IFLA_IFNAME, strlen(ifname)+1, ifname) < 0)
|
NETLINK_MSG_PUT(nl_msg, IFLA_IFNAME, (strlen(ifname) + 1), ifname);
|
||||||
goto buffer_too_small;
|
|
||||||
|
|
||||||
if (virNetlinkCommand(nl_msg, &resp, &recvbuflen, 0, 0,
|
if (virNetlinkCommand(nl_msg, &resp, &recvbuflen, 0, 0,
|
||||||
NETLINK_ROUTE, 0) < 0) {
|
NETLINK_ROUTE, 0) < 0) {
|
||||||
|
@ -38,29 +38,6 @@ struct nlmsghdr;
|
|||||||
|
|
||||||
#endif /* WITH_LIBNL */
|
#endif /* WITH_LIBNL */
|
||||||
|
|
||||||
#define NETLINK_MSG_NEST_START(msg, container, attrtype) \
|
|
||||||
do { \
|
|
||||||
container = nla_nest_start(msg, attrtype); \
|
|
||||||
if (!container) \
|
|
||||||
goto buffer_too_small; \
|
|
||||||
} while(0)
|
|
||||||
|
|
||||||
#define NETLINK_MSG_NEST_END(msg, container) \
|
|
||||||
do { nla_nest_end(msg, container); } while(0)
|
|
||||||
|
|
||||||
/*
|
|
||||||
* we need to use an intermediary pointer to @data as compilers may sometimes
|
|
||||||
* complain about @data not being a pointer type:
|
|
||||||
* error: the address of 'foo' will always evaluate as 'true' [-Werror=address]
|
|
||||||
*/
|
|
||||||
#define NETLINK_MSG_PUT(msg, attrtype, datalen, data) \
|
|
||||||
do { \
|
|
||||||
const void *dataptr = data; \
|
|
||||||
if (dataptr && nla_put(msg, attrtype, datalen, dataptr) < 0) \
|
|
||||||
goto buffer_too_small; \
|
|
||||||
} while(0)
|
|
||||||
|
|
||||||
|
|
||||||
int virNetlinkStartup(void);
|
int virNetlinkStartup(void);
|
||||||
void virNetlinkShutdown(void);
|
void virNetlinkShutdown(void);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user