*
* @ifname: The name of the interface; only use if ifindex < 0
* @ifindex: The interface index; may be < 0 if ifname is given
- * @nltarget_kernel: whether to send the message to the kernel or another
- * process
* @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
- * @getPidFunc: Pointer to a function that will be invoked if the kernel
- * is not the target of the netlink message but it is to be
- * sent to another process.
+ * @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
+ * is not the target of the netlink message but it is to be
+ * sent to another process (0 if sending to the kernel)
*
* Get information about an interface given its name or index.
*
*/
int
virNetDevLinkDump(const char *ifname, int ifindex,
- bool nltarget_kernel, struct nlattr **tb,
+ struct nlattr **tb,
unsigned char **recvbuf,
- uint32_t (*getPidFunc)(void))
+ uint32_t src_pid, uint32_t dst_pid)
{
int rc = -1;
struct nlmsghdr *resp;
.ifi_index = ifindex
};
unsigned int recvbuflen;
- uint32_t pid = 0;
struct nl_msg *nl_msg;
*recvbuf = NULL;
goto buffer_too_small;
}
- if (!nltarget_kernel) {
- pid = getPidFunc();
- if (pid == 0) {
- goto cleanup;
- }
- }
-
- if (virNetlinkCommand(nl_msg, recvbuf, &recvbuflen, 0, pid) < 0)
+ if (virNetlinkCommand(nl_msg, recvbuf, &recvbuflen, src_pid, dst_pid) < 0)
goto cleanup;
if (recvbuflen < NLMSG_LENGTH(0) || *recvbuf == NULL)
struct nlattr *tb[IFLA_MAX + 1] = {NULL, };
int ifindex = -1;
- rc = virNetDevLinkDump(ifname, ifindex, true, tb, &recvbuf, NULL);
+ rc = virNetDevLinkDump(ifname, ifindex, tb, &recvbuf, 0, 0);
if (rc < 0)
return rc;
int
virNetDevLinkDump(const char *ifname ATTRIBUTE_UNUSED,
int ifindex ATTRIBUTE_UNUSED,
- bool nltarget_kernel ATTRIBUTE_UNUSED,
struct nlattr **tb ATTRIBUTE_UNUSED,
unsigned char **recvbuf ATTRIBUTE_UNUSED,
- uint32_t (*getPidFunc)(void) ATTRIBUTE_UNUSED)
+ uint32_t src_pid ATTRIBUTE_UNUSED,
+ uint32_t dst_pid ATTRIBUTE_UNUSED)
{
virReportSystemError(ENOSYS, "%s",
_("Unable to dump link info on this platform"));
};
unsigned char *recvbuf = NULL;
unsigned int recvbuflen = 0;
- uint32_t pid = 0;
+ int src_pid = 0;
+ uint32_t dst_pid = 0;
struct nl_msg *nl_msg;
struct nlattr *vfports = NULL, *vfport;
}
if (!nltarget_kernel) {
- pid = virNetDevVPortProfileGetLldpadPid();
- if (pid == 0)
+ if ((src_pid = virNetlinkEventServiceLocalPid()) < 0)
+ goto cleanup;
+ if ((dst_pid = virNetDevVPortProfileGetLldpadPid()) == 0)
goto cleanup;
}
- if (virNetlinkCommand(nl_msg, &recvbuf, &recvbuflen, 0, pid) < 0)
+ if (virNetlinkCommand(nl_msg, &recvbuf, &recvbuflen, src_pid, dst_pid) < 0)
goto cleanup;
if (recvbuflen < NLMSG_LENGTH(0) || recvbuf == NULL)
return -1;
while (!end && i <= nthParent) {
- rc = virNetDevLinkDump(ifname, ifindex, true, tb, &recvbuf, NULL);
+ rc = virNetDevLinkDump(ifname, ifindex, tb, &recvbuf, 0, 0);
if (rc < 0)
break;
bool setlink_only)
{
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;
if (setlink_only) /*for re-associations on existing links*/
return 0;
+ if (!nltarget_kernel &&
+ (((src_pid = virNetlinkEventServiceLocalPid()) < 0) ||
+ ((dst_pid = virNetDevVPortProfileGetLldpadPid()) == 0))) {
+ rc = -1;
+ goto cleanup;
+ }
+
while (--repeats >= 0) {
- rc = virNetDevLinkDump(NULL, ifindex, nltarget_kernel, tb,
- &recvbuf, virNetDevVPortProfileGetLldpadPid);
+ rc = virNetDevLinkDump(NULL, ifindex, tb, &recvbuf, src_pid, dst_pid);
if (rc < 0)
goto cleanup;