[libvirt] [PATCHv3 2/4] util: allow specifying both src and dst pid in virNetlinkCommand

Laine Stump laine at laine.org
Fri May 4 18:51:14 UTC 2012


Until now, virNetlinkCommand has assumed that the nl_pid in the source
address of outgoing netlink messages should always be the return value
of getpid(). In most cases it actually doesn't matter, but in the case
of communication with lldpad, lldpad saves this info and later uses it
to send netlink messages back to libvirt. A recent patch to fix Bug
816465 changed the order of the universe such that the netlink event
service socket is no longer bound with nl_pid == getpid(), so lldpad
could no longer send unsolicited messages to libvirtd. Adding src_pid
as an argument to virNetlinkCommand() is the first step in notifying
lldpad of the proper address of the netlink event service socket.
---
 src/util/virnetdev.c             |    4 ++--
 src/util/virnetdevmacvlan.c      |    6 +++---
 src/util/virnetdevvportprofile.c |    4 ++--
 src/util/virnetlink.c            |   13 +++++++------
 src/util/virnetlink.h            |    2 +-
 5 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
index 460aa83..72af3cd 100644
--- a/src/util/virnetdev.c
+++ b/src/util/virnetdev.c
@@ -1288,7 +1288,7 @@ virNetDevLinkDump(const char *ifname, int ifindex,
         }
     }
 
-    if (virNetlinkCommand(nl_msg, recvbuf, &recvbuflen, pid) < 0)
+    if (virNetlinkCommand(nl_msg, recvbuf, &recvbuflen, 0, pid) < 0)
         goto cleanup;
 
     if (recvbuflen < NLMSG_LENGTH(0) || *recvbuf == NULL)
@@ -1416,7 +1416,7 @@ virNetDevSetVfConfig(const char *ifname, int ifindex, int vf,
         }
     }
 
-    if (virNetlinkCommand(nl_msg, &recvbuf, &recvbuflen, pid) < 0)
+    if (virNetlinkCommand(nl_msg, &recvbuf, &recvbuflen, 0, pid) < 0)
         goto cleanup;
 
     if (recvbuflen < NLMSG_LENGTH(0) || recvbuf == NULL)
diff --git a/src/util/virnetdevmacvlan.c b/src/util/virnetdevmacvlan.c
index 401ee74..d168d42 100644
--- a/src/util/virnetdevmacvlan.c
+++ b/src/util/virnetdevmacvlan.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2011 Red Hat, Inc.
+ * Copyright (C) 2010-2012 Red Hat, Inc.
  * Copyright (C) 2010-2012 IBM Corporation
  *
  * This library is free software; you can redistribute it and/or
@@ -154,7 +154,7 @@ virNetDevMacVLanCreate(const char *ifname,
 
     nla_nest_end(nl_msg, linkinfo);
 
-    if (virNetlinkCommand(nl_msg, &recvbuf, &recvbuflen, 0) < 0) {
+    if (virNetlinkCommand(nl_msg, &recvbuf, &recvbuflen, 0, 0) < 0) {
         goto cleanup;
     }
 
@@ -242,7 +242,7 @@ int virNetDevMacVLanDelete(const char *ifname)
     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, &recvbuf, &recvbuflen, 0, 0) < 0) {
         goto cleanup;
     }
 
diff --git a/src/util/virnetdevvportprofile.c b/src/util/virnetdevvportprofile.c
index 5b562be..def5c62 100644
--- a/src/util/virnetdevvportprofile.c
+++ b/src/util/virnetdevvportprofile.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009-2011 Red Hat, Inc.
+ * Copyright (C) 2009-2012 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -395,7 +395,7 @@ virNetDevVPortProfileOpSetLink(const char *ifname, int ifindex,
             goto cleanup;
     }
 
-    if (virNetlinkCommand(nl_msg, &recvbuf, &recvbuflen, pid) < 0)
+    if (virNetlinkCommand(nl_msg, &recvbuf, &recvbuflen, 0, pid) < 0)
         goto cleanup;
 
     if (recvbuflen < NLMSG_LENGTH(0) || recvbuf == NULL)
diff --git a/src/util/virnetlink.c b/src/util/virnetlink.c
index 1b64033..df0f57a 100644
--- a/src/util/virnetlink.c
+++ b/src/util/virnetlink.c
@@ -168,12 +168,12 @@ virNetlinkShutdown(void)
  */
 int virNetlinkCommand(struct nl_msg *nl_msg,
                       unsigned char **respbuf, unsigned int *respbuflen,
-                      int nl_pid)
+                      uint32_t src_pid, uint32_t dst_pid)
 {
     int rc = 0;
     struct sockaddr_nl nladdr = {
             .nl_family = AF_NETLINK,
-            .nl_pid    = nl_pid,
+            .nl_pid    = dst_pid,
             .nl_groups = 0,
     };
     ssize_t nbytes;
@@ -201,7 +201,7 @@ int virNetlinkCommand(struct nl_msg *nl_msg,
 
     nlmsg_set_dst(nl_msg, &nladdr);
 
-    nlmsg->nlmsg_pid = getpid();
+    nlmsg->nlmsg_pid = src_pid ? src_pid : getpid();
 
     nbytes = nl_send_auto_complete(nlhandle, nl_msg);
     if (nbytes < 0) {
@@ -612,9 +612,10 @@ virNetlinkShutdown(void)
 }
 
 int virNetlinkCommand(struct nl_msg *nl_msg ATTRIBUTE_UNUSED,
-           unsigned char **respbuf ATTRIBUTE_UNUSED,
-           unsigned int *respbuflen ATTRIBUTE_UNUSED,
-           int nl_pid ATTRIBUTE_UNUSED)
+                      unsigned char **respbuf ATTRIBUTE_UNUSED,
+                      unsigned int *respbuflen ATTRIBUTE_UNUSED,
+                      uint32_t src_pid ATTRIBUTE_UNUSED,
+                      uint32_t dst_pid ATTRIBUTE_UNUSED)
 {
     netlinkError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported));
     return -1;
diff --git a/src/util/virnetlink.h b/src/util/virnetlink.h
index 93df59a..c57be82 100644
--- a/src/util/virnetlink.h
+++ b/src/util/virnetlink.h
@@ -40,7 +40,7 @@ void virNetlinkShutdown(void);
 
 int virNetlinkCommand(struct nl_msg *nl_msg,
                       unsigned char **respbuf, unsigned int *respbuflen,
-                      int nl_pid);
+                      uint32_t src_port, uint32_t dst_port);
 
 typedef void (*virNetlinkEventHandleCallback)(unsigned char *msg, int length, struct sockaddr_nl *peer, bool *handled, void *opaque);
 
-- 
1.7.10




More information about the libvir-list mailing list