]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: rename netlink.[ch] to virnetlink.[ch]
authorD. Herrendoerfer <d.herrendoerfer@herrendoerfer.name>
Fri, 3 Feb 2012 14:13:19 +0000 (15:13 +0100)
committerLaine Stump <laine@laine.org>
Fri, 3 Feb 2012 20:27:40 +0000 (15:27 -0500)
Rename the src/util/netlink files to src/util/virnetlink to
better fit the naming scheme. Also rename nlComm to virNetlinkCommand.

Signed-off-by: D. Herrendoerfer <d.herrendoerfer@herrendoerfer.name>
po/POTFILES.in
src/Makefile.am
src/libvirt_private.syms
src/util/netlink.c [deleted file]
src/util/netlink.h [deleted file]
src/util/virnetdevmacvlan.c
src/util/virnetdevvportprofile.c
src/util/virnetlink.c [new file with mode: 0644]
src/util/virnetlink.h [new file with mode: 0644]

index cbe62dd0705b9c49cea04cfb1741fc22634dafe1..5a7ecae7578ac26785922ed8933c247dc9faf2f9 100644 (file)
@@ -116,7 +116,6 @@ src/util/hostusb.c
 src/util/iohelper.c
 src/util/iptables.c
 src/util/json.c
-src/util/netlink.c
 src/util/pci.c
 src/util/processinfo.c
 src/util/sexpr.c
@@ -132,6 +131,7 @@ src/util/virnetdevbridge.c
 src/util/virnetdevmacvlan.c
 src/util/virnetdevtap.c
 src/util/virnetdevvportprofile.c
+src/util/virnetlink.c
 src/util/virnodesuspend.c
 src/util/virpidfile.c
 src/util/virsocketaddr.c
index ac6c957f51e857adfbde347d369ca554bc9cd008..a3dd847ed02967e8df5adc595bca036c33fa66be 100644 (file)
@@ -67,7 +67,6 @@ UTIL_SOURCES =                                                        \
                util/json.c util/json.h                         \
                util/logging.c util/logging.h                   \
                util/memory.c util/memory.h                     \
-               util/netlink.c util/netlink.h                   \
                util/pci.c util/pci.h                           \
                util/processinfo.c util/processinfo.h           \
                util/hostusb.c util/hostusb.h                   \
@@ -101,6 +100,7 @@ UTIL_SOURCES =                                                      \
                util/virnetdevtap.h util/virnetdevtap.c         \
                util/virnetdevveth.h util/virnetdevveth.c \
                util/virnetdevvportprofile.h util/virnetdevvportprofile.c \
+               util/virnetlink.c util/virnetlink.h             \
                util/virrandom.h util/virrandom.c               \
                util/virsocketaddr.h util/virsocketaddr.c \
                util/virtime.h util/virtime.c
index e300f06f1e4dcd8548f10eeb7d302840fbff212f..d6ad36cf402d65e7739de0bd9a9ff47d35703245 100644 (file)
@@ -734,10 +734,6 @@ virResizeN;
 virShrinkN;
 
 
-#netlink.h
-nlComm;
-
-
 # netdev_bandwidth_conf.h
 virNetDevBandwidthFormat;
 virNetDevBandwidthParse;
@@ -1260,6 +1256,10 @@ virNetDevVPortProfileOpTypeFromString;
 virNetDevVPortProfileOpTypeToString;
 
 
+#virnetlink.h
+virNetlinkCommand;
+
+
 # virnetmessage.h
 virNetMessageClear;
 virNetMessageDecodeNumFDs;
diff --git a/src/util/netlink.c b/src/util/netlink.c
deleted file mode 100644 (file)
index 0672184..0000000
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- * Copyright (C) 2010-2011 Red Hat, Inc.
- * Copyright (C) 2010 IBM Corporation
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
- *
- * Authors:
- *     Stefan Berger <stefanb@us.ibm.com>
- *
- * Notes:
- * netlink: http://lovezutto.googlepages.com/netlink.pdf
- *          iproute2 package
- *
- */
-
-#include <config.h>
-
-#include <errno.h>
-#include <unistd.h>
-#include <sys/types.h>
-
-#include "netlink.h"
-#include "memory.h"
-#include "virterror_internal.h"
-
-#define VIR_FROM_THIS VIR_FROM_NET
-
-#define netlinkError(code, ...)                                           \
-        virReportErrorHelper(VIR_FROM_NET, code, __FILE__,                 \
-                             __FUNCTION__, __LINE__, __VA_ARGS__)
-
-#define NETLINK_ACK_TIMEOUT_S  2
-
-/**
- * nlComm:
- * @nlmsg: pointer to netlink message
- * @respbuf: pointer to pointer where response buffer will be allocated
- * @respbuflen: pointer to integer holding the size of the response buffer
- *      on return of the function.
- * @nl_pid: the pid of the process to talk to, i.e., pid = 0 for kernel
- *
- * Send the given message to the netlink layer and receive response.
- * Returns 0 on success, -1 on error. In case of error, no response
- * buffer will be returned.
- */
-#if defined(__linux__) && defined(HAVE_LIBNL)
-int nlComm(struct nl_msg *nl_msg,
-           unsigned char **respbuf, unsigned int *respbuflen,
-           int nl_pid)
-{
-    int rc = 0;
-    struct sockaddr_nl nladdr = {
-            .nl_family = AF_NETLINK,
-            .nl_pid    = nl_pid,
-            .nl_groups = 0,
-    };
-    ssize_t nbytes;
-    struct timeval tv = {
-        .tv_sec = NETLINK_ACK_TIMEOUT_S,
-    };
-    fd_set readfds;
-    int fd;
-    int n;
-    struct nlmsghdr *nlmsg = nlmsg_hdr(nl_msg);
-    struct nl_handle *nlhandle = nl_handle_alloc();
-
-    if (!nlhandle) {
-        virReportSystemError(errno,
-                             "%s", _("cannot allocate nlhandle for netlink"));
-        return -1;
-    }
-
-    if (nl_connect(nlhandle, NETLINK_ROUTE) < 0) {
-        virReportSystemError(errno,
-                             "%s", _("cannot connect to netlink socket"));
-        rc = -1;
-        goto err_exit;
-    }
-
-    nlmsg_set_dst(nl_msg, &nladdr);
-
-    nlmsg->nlmsg_pid = getpid();
-
-    nbytes = nl_send_auto_complete(nlhandle, nl_msg);
-    if (nbytes < 0) {
-        virReportSystemError(errno,
-                             "%s", _("cannot send to netlink socket"));
-        rc = -1;
-        goto err_exit;
-    }
-
-    fd = nl_socket_get_fd(nlhandle);
-
-    FD_ZERO(&readfds);
-    FD_SET(fd, &readfds);
-
-    n = select(fd + 1, &readfds, NULL, NULL, &tv);
-    if (n <= 0) {
-        if (n < 0)
-            virReportSystemError(errno, "%s",
-                                 _("error in select call"));
-        if (n == 0)
-            virReportSystemError(ETIMEDOUT, "%s",
-                                 _("no valid netlink response was received"));
-        rc = -1;
-        goto err_exit;
-    }
-
-    *respbuflen = nl_recv(nlhandle, &nladdr, respbuf, NULL);
-    if (*respbuflen <= 0) {
-        virReportSystemError(errno,
-                             "%s", _("nl_recv failed"));
-        rc = -1;
-    }
-err_exit:
-    if (rc == -1) {
-        VIR_FREE(*respbuf);
-        *respbuf = NULL;
-        *respbuflen = 0;
-    }
-
-    nl_handle_destroy(nlhandle);
-    return rc;
-}
-
-#else
-
-int nlComm(struct nl_msg *nl_msg ATTRIBUTE_UNUSED,
-           unsigned char **respbuf ATTRIBUTE_UNUSED,
-           unsigned int *respbuflen ATTRIBUTE_UNUSED,
-           int nl_pid ATTRIBUTE_UNUSED)
-{
-    netlinkError(VIR_ERR_INTERNAL_ERROR, "%s",
-# if defined(__linux__) && !defined(HAVE_LIBNL)
-                 _("nlComm is not supported since libnl was not available"));
-# else
-                 _("nlComm is not supported on non-linux platforms"));
-# endif
-    return -1;
-}
-
-#endif /* __linux__ */
diff --git a/src/util/netlink.h b/src/util/netlink.h
deleted file mode 100644 (file)
index 6e915ff..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (C) 2010-2011 Red Hat, Inc.
- * Copyright (C) 2010 IBM Corporation
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
- */
-
-#ifndef __VIR_NETLINK_H__
-# define __VIR_NETLINK_H__
-
-# include "config.h"
-
-# if defined(__linux__) && defined(HAVE_LIBNL)
-
-#  include <netlink/msg.h>
-
-# else
-
-struct nl_msg;
-
-# endif /* __linux__ */
-
-int nlComm(struct nl_msg *nl_msg,
-           unsigned char **respbuf, unsigned int *respbuflen,
-           int nl_pid);
-
-#endif /* __VIR_NETLINK_H__ */
index 1d64b73f3e3c356c60f3e8e949336330b654358a..25d0846c11cdd09d3f8a9133100d9210bda614ad 100644 (file)
@@ -66,7 +66,7 @@ VIR_ENUM_IMPL(virNetDevMacVLanMode, VIR_NETDEV_MACVLAN_MODE_LAST,
 # include "logging.h"
 # include "uuid.h"
 # include "virfile.h"
-# include "netlink.h"
+# include "virnetlink.h"
 # include "virnetdev.h"
 
 # define MACVTAP_NAME_PREFIX   "macvtap"
@@ -153,7 +153,7 @@ virNetDevMacVLanCreate(const char *ifname,
 
     nla_nest_end(nl_msg, linkinfo);
 
-    if (nlComm(nl_msg, &recvbuf, &recvbuflen, 0) < 0) {
+    if (virNetlinkCommand(nl_msg, &recvbuf, &recvbuflen, 0) < 0) {
         rc = -1;
         goto cleanup;
     }
@@ -249,7 +249,7 @@ int virNetDevMacVLanDelete(const char *ifname)
     if (nla_put(nl_msg, IFLA_IFNAME, strlen(ifname)+1, ifname) < 0)
         goto buffer_too_small;
 
-    if (nlComm(nl_msg, &recvbuf, &recvbuflen, 0) < 0) {
+    if (virNetlinkCommand(nl_msg, &recvbuf, &recvbuflen, 0) < 0) {
         rc = -1;
         goto cleanup;
     }
index 46f2a248dde21a8853e84aabdf5653a8b8085dde..faadc3a2147a253ec2792f612df2c4bd82a4335d 100644 (file)
@@ -55,7 +55,7 @@ VIR_ENUM_IMPL(virNetDevVPortProfileOp, VIR_NETDEV_VPORT_PROFILE_OP_LAST,
 # include <linux/if.h>
 # include <linux/if_tun.h>
 
-# include "netlink.h"
+# include "virnetlink.h"
 # include "virfile.h"
 # include "memory.h"
 # include "logging.h"
@@ -224,7 +224,7 @@ virNetDevVPortProfileLinkDump(const char *ifname, int ifindex, bool nltarget_ker
         }
     }
 
-    if (nlComm(nl_msg, recvbuf, &recvbuflen, pid) < 0) {
+    if (virNetlinkCommand(nl_msg, recvbuf, &recvbuflen, pid) < 0) {
         rc = -1;
         goto cleanup;
     }
@@ -517,7 +517,7 @@ virNetDevVPortProfileOpSetLink(const char *ifname, int ifindex,
             goto err_exit;
     }
 
-    if (nlComm(nl_msg, &recvbuf, &recvbuflen, pid) < 0)
+    if (virNetlinkCommand(nl_msg, &recvbuf, &recvbuflen, pid) < 0)
         goto err_exit;
 
     if (recvbuflen < NLMSG_LENGTH(0) || recvbuf == NULL)
diff --git a/src/util/virnetlink.c b/src/util/virnetlink.c
new file mode 100644 (file)
index 0000000..d03d171
--- /dev/null
@@ -0,0 +1,157 @@
+/*
+ * Copyright (C) 2010-2011 Red Hat, Inc.
+ * Copyright (C) 2010-2012 IBM Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
+ *
+ * Authors:
+ *     Stefan Berger <stefanb@us.ibm.com>
+ *     Dirk Herrendoerfer <herrend[at]de[dot]ibm[dot]com>
+ *
+ * Notes:
+ * netlink: http://lovezutto.googlepages.com/netlink.pdf
+ *          iproute2 package
+ *
+ * 2012/02: Renamed from netlink.[ch] to virnetlink.[ch]
+ *
+ */
+
+#include <config.h>
+
+#include <errno.h>
+#include <unistd.h>
+#include <sys/types.h>
+
+#include "virnetlink.h"
+#include "memory.h"
+#include "virterror_internal.h"
+
+#define VIR_FROM_THIS VIR_FROM_NET
+
+#define netlinkError(code, ...)                                           \
+        virReportErrorHelper(VIR_FROM_NET, code, __FILE__,                 \
+                             __FUNCTION__, __LINE__, __VA_ARGS__)
+
+#define NETLINK_ACK_TIMEOUT_S  2
+
+/**
+ * virNetlinkCommand:
+ * @nlmsg: pointer to netlink message
+ * @respbuf: pointer to pointer where response buffer will be allocated
+ * @respbuflen: pointer to integer holding the size of the response buffer
+ *      on return of the function.
+ * @nl_pid: the pid of the process to talk to, i.e., pid = 0 for kernel
+ *
+ * Send the given message to the netlink layer and receive response.
+ * Returns 0 on success, -1 on error. In case of error, no response
+ * buffer will be returned.
+ */
+#if defined(__linux__) && defined(HAVE_LIBNL)
+int virNetlinkCommand(struct nl_msg *nl_msg,
+                      unsigned char **respbuf, unsigned int *respbuflen,
+                      int nl_pid)
+{
+    int rc = 0;
+    struct sockaddr_nl nladdr = {
+            .nl_family = AF_NETLINK,
+            .nl_pid    = nl_pid,
+            .nl_groups = 0,
+    };
+    ssize_t nbytes;
+    struct timeval tv = {
+        .tv_sec = NETLINK_ACK_TIMEOUT_S,
+    };
+    fd_set readfds;
+    int fd;
+    int n;
+    struct nlmsghdr *nlmsg = nlmsg_hdr(nl_msg);
+    struct nl_handle *nlhandle = nl_handle_alloc();
+
+    if (!nlhandle) {
+        virReportSystemError(errno,
+                             "%s", _("cannot allocate nlhandle for netlink"));
+        return -1;
+    }
+
+    if (nl_connect(nlhandle, NETLINK_ROUTE) < 0) {
+        virReportSystemError(errno,
+                             "%s", _("cannot connect to netlink socket"));
+        rc = -1;
+        goto err_exit;
+    }
+
+    nlmsg_set_dst(nl_msg, &nladdr);
+
+    nlmsg->nlmsg_pid = getpid();
+
+    nbytes = nl_send_auto_complete(nlhandle, nl_msg);
+    if (nbytes < 0) {
+        virReportSystemError(errno,
+                             "%s", _("cannot send to netlink socket"));
+        rc = -1;
+        goto err_exit;
+    }
+
+    fd = nl_socket_get_fd(nlhandle);
+
+    FD_ZERO(&readfds);
+    FD_SET(fd, &readfds);
+
+    n = select(fd + 1, &readfds, NULL, NULL, &tv);
+    if (n <= 0) {
+        if (n < 0)
+            virReportSystemError(errno, "%s",
+                                 _("error in select call"));
+        if (n == 0)
+            virReportSystemError(ETIMEDOUT, "%s",
+                                 _("no valid netlink response was received"));
+        rc = -1;
+        goto err_exit;
+    }
+
+    *respbuflen = nl_recv(nlhandle, &nladdr, respbuf, NULL);
+    if (*respbuflen <= 0) {
+        virReportSystemError(errno,
+                             "%s", _("nl_recv failed"));
+        rc = -1;
+    }
+err_exit:
+    if (rc == -1) {
+        VIR_FREE(*respbuf);
+        *respbuf = NULL;
+        *respbuflen = 0;
+    }
+
+    nl_handle_destroy(nlhandle);
+    return rc;
+}
+
+#else
+
+int virNetlinkCommand(struct nl_msg *nl_msg ATTRIBUTE_UNUSED,
+           unsigned char **respbuf ATTRIBUTE_UNUSED,
+           unsigned int *respbuflen ATTRIBUTE_UNUSED,
+           int nl_pid ATTRIBUTE_UNUSED)
+{
+    netlinkError(VIR_ERR_INTERNAL_ERROR, "%s",
+# if defined(__linux__) && !defined(HAVE_LIBNL)
+                 _("virNetlinkCommand is not supported since libnl was not available"));
+# else
+                 _("virNetlinkCommand is not supported on non-linux platforms"));
+# endif
+    return -1;
+}
+
+#endif /* __linux__ */
diff --git a/src/util/virnetlink.h b/src/util/virnetlink.h
new file mode 100644 (file)
index 0000000..a70abb6
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2010-2011 Red Hat, Inc.
+ * Copyright (C) 2010-2012 IBM Corporation
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
+ */
+
+#ifndef __VIR_NETLINK_H__
+# define __VIR_NETLINK_H__
+
+# include "config.h"
+
+# if defined(__linux__) && defined(HAVE_LIBNL)
+
+#  include <netlink/msg.h>
+
+# else
+
+struct nl_msg;
+
+# endif /* __linux__ */
+
+int virNetlinkCommand(struct nl_msg *nl_msg,
+                      unsigned char **respbuf, unsigned int *respbuflen,
+                      int nl_pid);
+
+#endif /* __VIR_NETLINK_H__ */