* @ifindex: The interface index; may be < 0 if ifname is given
* @nlattr: pointer to a pointer of netlink attributes that will contain
* the results
- * @recvbuf: Pointer to the buffer holding the returned netlink response
- * message; free it, once not needed anymore
* @src_pid: pid used for nl_pid of the local end of the netlink message
* (0 == "use getpid()")
* @dst_pid: pid of destination nl_pid if the kernel
int
virNetDevLinkDump(const char *ifname, int ifindex,
struct nlattr **tb,
- unsigned char **recvbuf,
uint32_t src_pid, uint32_t dst_pid)
{
int rc = -1;
- struct nlmsghdr *resp;
+ struct nlmsghdr *resp = NULL;
struct nlmsgerr *err;
struct ifinfomsg ifinfo = {
.ifi_family = AF_UNSPEC,
unsigned int recvbuflen;
struct nl_msg *nl_msg;
- *recvbuf = NULL;
-
if (ifname && ifindex <= 0 && virNetDevGetIndex(ifname, &ifindex) < 0)
return -1;
}
# endif
- if (virNetlinkCommand(nl_msg, recvbuf, &recvbuflen,
+ if (virNetlinkCommand(nl_msg, &resp, &recvbuflen,
src_pid, dst_pid, NETLINK_ROUTE, 0) < 0)
goto cleanup;
- if (recvbuflen < NLMSG_LENGTH(0) || *recvbuf == NULL)
+ if (recvbuflen < NLMSG_LENGTH(0) || resp == NULL)
goto malformed_resp;
- resp = (struct nlmsghdr *)*recvbuf;
-
switch (resp->nlmsg_type) {
case NLMSG_ERROR:
err = (struct nlmsgerr *)NLMSG_DATA(resp);
}
rc = 0;
cleanup:
- if (rc < 0)
- VIR_FREE(*recvbuf);
nlmsg_free(nl_msg);
+ VIR_FREE(resp);
return rc;
malformed_resp:
int vlanid, uint32_t (*getPidFunc)(void))
{
int rc = -1;
- struct nlmsghdr *resp;
+ struct nlmsghdr *resp = NULL;
struct nlmsgerr *err;
- unsigned char *recvbuf = NULL;
unsigned int recvbuflen = 0;
uint32_t pid = 0;
struct nl_msg *nl_msg;
}
}
- if (virNetlinkCommand(nl_msg, &recvbuf, &recvbuflen, 0, pid,
+ if (virNetlinkCommand(nl_msg, &resp, &recvbuflen, 0, pid,
NETLINK_ROUTE, 0) < 0)
goto cleanup;
- if (recvbuflen < NLMSG_LENGTH(0) || recvbuf == NULL)
+ if (recvbuflen < NLMSG_LENGTH(0) || resp == NULL)
goto malformed_resp;
- resp = (struct nlmsghdr *)recvbuf;
-
switch (resp->nlmsg_type) {
case NLMSG_ERROR:
err = (struct nlmsgerr *)NLMSG_DATA(resp);
rc = 0;
cleanup:
nlmsg_free(nl_msg);
- VIR_FREE(recvbuf);
+ VIR_FREE(resp);
return rc;
malformed_resp:
int *vlanid)
{
int rc = -1;
- unsigned char *recvbuf = NULL;
struct nlattr *tb[IFLA_MAX + 1] = {NULL, };
int ifindex = -1;
- rc = virNetDevLinkDump(ifname, ifindex, tb, &recvbuf, 0, 0);
+ rc = virNetDevLinkDump(ifname, ifindex, tb, 0, 0);
if (rc < 0)
return rc;
rc = virNetDevParseVfConfig(tb, vf, mac, vlanid);
- VIR_FREE(recvbuf);
-
return rc;
}
virNetDevLinkDump(const char *ifname ATTRIBUTE_UNUSED,
int ifindex ATTRIBUTE_UNUSED,
struct nlattr **tb ATTRIBUTE_UNUSED,
- unsigned char **recvbuf ATTRIBUTE_UNUSED,
uint32_t src_pid ATTRIBUTE_UNUSED,
uint32_t dst_pid ATTRIBUTE_UNUSED)
{
int virNetDevLinkDump(const char *ifname, int ifindex,
struct nlattr **tb,
- unsigned char **recvbuf,
uint32_t src_pid, uint32_t dst_pid)
ATTRIBUTE_RETURN_CHECK;
int *retry)
{
int rc = -1;
- struct nlmsghdr *resp;
+ struct nlmsghdr *resp = NULL;
struct nlmsgerr *err;
struct ifinfomsg ifinfo = { .ifi_family = AF_UNSPEC };
int ifindex;
- unsigned char *recvbuf = NULL;
unsigned int recvbuflen;
struct nl_msg *nl_msg;
struct nlattr *linkinfo, *info_data;
nla_nest_end(nl_msg, linkinfo);
- if (virNetlinkCommand(nl_msg, &recvbuf, &recvbuflen, 0, 0,
+ if (virNetlinkCommand(nl_msg, &resp, &recvbuflen, 0, 0,
NETLINK_ROUTE, 0) < 0) {
goto cleanup;
}
- if (recvbuflen < NLMSG_LENGTH(0) || recvbuf == NULL)
+ if (recvbuflen < NLMSG_LENGTH(0) || resp == NULL)
goto malformed_resp;
- resp = (struct nlmsghdr *)recvbuf;
-
switch (resp->nlmsg_type) {
case NLMSG_ERROR:
err = (struct nlmsgerr *)NLMSG_DATA(resp);
rc = 0;
cleanup:
nlmsg_free(nl_msg);
- VIR_FREE(recvbuf);
+ VIR_FREE(resp);
return rc;
malformed_resp:
int virNetDevMacVLanDelete(const char *ifname)
{
int rc = -1;
- struct nlmsghdr *resp;
+ struct nlmsghdr *resp = NULL;
struct nlmsgerr *err;
struct ifinfomsg ifinfo = { .ifi_family = AF_UNSPEC };
- unsigned char *recvbuf = NULL;
unsigned int recvbuflen;
struct nl_msg *nl_msg;
if (nla_put(nl_msg, IFLA_IFNAME, strlen(ifname)+1, ifname) < 0)
goto buffer_too_small;
- if (virNetlinkCommand(nl_msg, &recvbuf, &recvbuflen, 0, 0,
+ if (virNetlinkCommand(nl_msg, &resp, &recvbuflen, 0, 0,
NETLINK_ROUTE, 0) < 0) {
goto cleanup;
}
- if (recvbuflen < NLMSG_LENGTH(0) || recvbuf == NULL)
+ if (recvbuflen < NLMSG_LENGTH(0) || resp == NULL)
goto malformed_resp;
- resp = (struct nlmsghdr *)recvbuf;
-
switch (resp->nlmsg_type) {
case NLMSG_ERROR:
err = (struct nlmsgerr *)NLMSG_DATA(resp);
rc = 0;
cleanup:
nlmsg_free(nl_msg);
- VIR_FREE(recvbuf);
+ VIR_FREE(resp);
return rc;
malformed_resp:
/**
* virNetDevMacVLanVPortProfileCallback:
*
- * @msg: The buffer containing the received netlink message
+ * @hdr: The buffer containing the received netlink header + payload
* @length: The length of the received netlink message.
* @peer: The netling sockaddr containing the peer information
* @handled: Contains information if the message has been replied to yet
*/
static void
-virNetDevMacVLanVPortProfileCallback(unsigned char *msg,
- int length,
+virNetDevMacVLanVPortProfileCallback(struct nlmsghdr *hdr,
+ unsigned int length,
struct sockaddr_nl *peer,
bool *handled,
void *opaque)
*tb_vfinfo[IFLA_VF_MAX + 1], *tb_vfinfo_list;
struct ifinfomsg ifinfo;
- struct nlmsghdr *hdr;
void *data;
int rem;
char *ifname;
pid_t virip_pid = 0;
char macaddr[VIR_MAC_STRING_BUFLEN];
- hdr = (struct nlmsghdr *) msg;
data = nlmsg_data(hdr);
/* Quickly decide if we want this or not */
uint8_t op)
{
int rc = -1;
- struct nlmsghdr *resp;
+ struct nlmsghdr *resp = NULL;
struct nlmsgerr *err;
struct ifinfomsg ifinfo = {
.ifi_family = AF_UNSPEC,
.ifi_index = ifindex,
};
- unsigned char *recvbuf = NULL;
unsigned int recvbuflen = 0;
int src_pid = 0;
uint32_t dst_pid = 0;
goto cleanup;
}
- if (virNetlinkCommand(nl_msg, &recvbuf, &recvbuflen,
+ if (virNetlinkCommand(nl_msg, &resp, &recvbuflen,
src_pid, dst_pid, NETLINK_ROUTE, 0) < 0)
goto cleanup;
- if (recvbuflen < NLMSG_LENGTH(0) || recvbuf == NULL)
+ if (recvbuflen < NLMSG_LENGTH(0) || resp == NULL)
goto malformed_resp;
- resp = (struct nlmsghdr *)recvbuf;
-
switch (resp->nlmsg_type) {
case NLMSG_ERROR:
err = (struct nlmsgerr *)NLMSG_DATA(resp);
rc = 0;
cleanup:
nlmsg_free(nl_msg);
- VIR_FREE(recvbuf);
+ VIR_FREE(resp);
return rc;
malformed_resp:
{
int rc;
struct nlattr *tb[IFLA_MAX + 1] = { NULL, };
- unsigned char *recvbuf = NULL;
bool end = false;
unsigned int i = 0;
return -1;
while (!end && i <= nthParent) {
- rc = virNetDevLinkDump(ifname, ifindex, tb, &recvbuf, 0, 0);
+ rc = virNetDevLinkDump(ifname, ifindex, tb, 0, 0);
if (rc < 0)
break;
IFNAMSIZ)) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("buffer for root interface name is too small"));
- VIR_FREE(recvbuf);
return -1;
}
*parent_ifindex = ifindex;
} else
end = true;
- VIR_FREE(recvbuf);
-
i++;
}
int rc;
int src_pid = 0;
uint32_t dst_pid = 0;
- unsigned char *recvbuf = NULL;
struct nlattr *tb[IFLA_MAX + 1] = { NULL , };
int repeats = STATUS_POLL_TIMEOUT_USEC / STATUS_POLL_INTERVL_USEC;
uint16_t status = 0;
}
while (--repeats >= 0) {
- rc = virNetDevLinkDump(NULL, ifindex, tb, &recvbuf, src_pid, dst_pid);
+ rc = virNetDevLinkDump(NULL, ifindex, tb, src_pid, dst_pid);
if (rc < 0)
goto cleanup;
}
usleep(STATUS_POLL_INTERVL_USEC);
-
- VIR_FREE(recvbuf);
}
if (status == PORT_PROFILE_RESPONSE_INPROGRESS) {
}
cleanup:
- VIR_FREE(recvbuf);
return rc;
}
* buffer will be returned.
*/
int virNetlinkCommand(struct nl_msg *nl_msg,
- unsigned char **respbuf, unsigned int *respbuflen,
+ struct nlmsghdr **resp, unsigned int *respbuflen,
uint32_t src_pid, uint32_t dst_pid,
unsigned int protocol, unsigned int groups)
{
goto error;
}
- *respbuflen = nl_recv(nlhandle, &nladdr, respbuf, NULL);
+ *respbuflen = nl_recv(nlhandle, &nladdr,
+ (unsigned char **)resp, NULL);
if (*respbuflen <= 0) {
virReportSystemError(errno,
"%s", _("nl_recv failed"));
}
error:
if (rc == -1) {
- VIR_FREE(*respbuf);
- *respbuf = NULL;
+ VIR_FREE(*resp);
+ *resp = NULL;
*respbuflen = 0;
}
void *opaque)
{
virNetlinkEventSrvPrivatePtr srv = opaque;
- unsigned char *msg;
+ struct nlmsghdr *msg;
struct sockaddr_nl peer;
struct ucred *creds = NULL;
int i, length;
bool handled = false;
- length = nl_recv(srv->netlinknh, &peer, &msg, &creds);
+ length = nl_recv(srv->netlinknh, &peer,
+ (unsigned char **)&msg, &creds);
if (length == 0)
return;
struct nl_msg;
struct sockaddr_nl;
struct nlattr;
+struct nlmsghdr;
# endif /* __linux__ */
void virNetlinkShutdown(void);
int virNetlinkCommand(struct nl_msg *nl_msg,
- unsigned char **respbuf, unsigned int *respbuflen,
+ struct nlmsghdr **resp, unsigned int *respbuflen,
uint32_t src_pid, uint32_t dst_pid,
unsigned int protocol, unsigned int groups);
-typedef void (*virNetlinkEventHandleCallback)(unsigned char *msg, int length, struct sockaddr_nl *peer, bool *handled, void *opaque);
+typedef void (*virNetlinkEventHandleCallback)(struct nlmsghdr *,
+ unsigned int length,
+ struct sockaddr_nl *peer,
+ bool *handled,
+ void *opaque);
typedef void (*virNetlinkEventRemoveCallback)(int watch, const virMacAddrPtr macaddr, void *opaque);