]> git.proxmox.com Git - mirror_lxc.git/commitdiff
tree_wide: switch to netns_getifaddrs()
authorChristian Brauner <christian.brauner@ubuntu.com>
Sun, 23 Sep 2018 13:40:20 +0000 (15:40 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Sun, 23 Sep 2018 19:19:35 +0000 (21:19 +0200)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/confile.c
src/lxc/lxccontainer.c
src/lxc/network.c
src/lxc/tools/lxc_device.c

index 43b68bdd4112e6dccbdb85c8f645b80f113961d6..c55ea787297d0babaab4667d6a1cdde73179f0c7 100644 (file)
@@ -48,6 +48,7 @@
 #include "config.h"
 #include "confile.h"
 #include "confile_utils.h"
+#include <../include/netns_ifaddrs.h>
 #include "log.h"
 #include "lxcseccomp.h"
 #include "network.h"
 #include "storage.h"
 #include "utils.h"
 
-#if HAVE_IFADDRS_H
-#include <ifaddrs.h>
-#else
-#include <../include/ifaddrs.h>
-#endif
-
 #if HAVE_SYS_PERSONALITY_H
 #include <sys/personality.h>
 #endif
@@ -324,14 +319,14 @@ static int set_config_net_flags(const char *key, const char *value,
 static int create_matched_ifnames(const char *value, struct lxc_conf *lxc_conf,
                                  struct lxc_netdev *netdev)
 {
-       struct ifaddrs *ifaddr, *ifa;
+       struct netns_ifaddrs *ifaddr, *ifa;
        int n;
        int ret = 0;
        const char *type_key = "lxc.net.type";
        const char *link_key = "lxc.net.link";
        const char *tmpvalue = "phys";
 
-       if (getifaddrs(&ifaddr) == -1) {
+       if (netns_getifaddrs(&ifaddr, -1, &(bool){false}) < 0) {
                SYSERROR("Get network interfaces failed");
                return -1;
        }
@@ -359,7 +354,7 @@ static int create_matched_ifnames(const char *value, struct lxc_conf *lxc_conf,
                }
        }
 
-       freeifaddrs(ifaddr);
+       netns_freeifaddrs(ifaddr);
        ifaddr = NULL;
 
        return ret;
index a6a7df21275536c18b97cd9dda63faf9108cd000..412fe0456c5920701fed8a90b4e2cd3eb081e36f 100644 (file)
@@ -53,6 +53,7 @@
 #include "confile_utils.h"
 #include "criu.h"
 #include "error.h"
+#include <../include/netns_ifaddrs.h>
 #include "initutils.h"
 #include "log.h"
 #include "lxc.h"
 #include <sys/mkdev.h>
 #endif
 
-#if HAVE_IFADDRS_H
-#include <ifaddrs.h>
-#else
-#include <../include/ifaddrs.h>
-#endif
-
 #if IS_BIONIC
 #include <../include/lxcmntent.h>
 #else
@@ -2327,7 +2322,7 @@ static char **do_lxcapi_get_interfaces(struct lxc_container *c)
 
        if (pid == 0) { /* child */
                int ret = 1, nbytes;
-               struct ifaddrs *interfaceArray = NULL, *tempIfAddr = NULL;
+               struct netns_ifaddrs *interfaceArray = NULL, *tempIfAddr = NULL;
 
                /* close the read-end of the pipe */
                close(pipefd[0]);
@@ -2338,7 +2333,7 @@ static char **do_lxcapi_get_interfaces(struct lxc_container *c)
                }
 
                /* Grab the list of interfaces */
-               if (getifaddrs(&interfaceArray)) {
+               if (netns_getifaddrs(&interfaceArray, -1, &(bool){false})) {
                        SYSERROR("Failed to get interfaces list");
                        goto out;
                }
@@ -2357,7 +2352,7 @@ static char **do_lxcapi_get_interfaces(struct lxc_container *c)
 
        out:
                if (interfaceArray)
-                       freeifaddrs(interfaceArray);
+                       netns_freeifaddrs(interfaceArray);
 
                /* close the write-end of the pipe, thus sending EOF to the reader */
                close(pipefd[1]);
@@ -2429,7 +2424,7 @@ static char **do_lxcapi_get_ips(struct lxc_container *c, const char *interface,
                int ret = 1;
                char *address = NULL;
                void *tempAddrPtr = NULL;
-               struct ifaddrs *interfaceArray = NULL, *tempIfAddr = NULL;
+               struct netns_ifaddrs *interfaceArray = NULL, *tempIfAddr = NULL;
 
                /* close the read-end of the pipe */
                close(pipefd[0]);
@@ -2440,7 +2435,7 @@ static char **do_lxcapi_get_ips(struct lxc_container *c, const char *interface,
                }
 
                /* Grab the list of interfaces */
-               if (getifaddrs(&interfaceArray)) {
+               if (netns_getifaddrs(&interfaceArray, -1, &(bool){false})) {
                        SYSERROR("Failed to get interfaces list");
                        goto out;
                }
@@ -2496,7 +2491,7 @@ static char **do_lxcapi_get_ips(struct lxc_container *c, const char *interface,
 
        out:
                if (interfaceArray)
-                       freeifaddrs(interfaceArray);
+                       netns_freeifaddrs(interfaceArray);
 
                /* close the write-end of the pipe, thus sending EOF to the reader */
                close(pipefd[1]);
index 8bfe6a1a2f4c223acd572fe2a1b008f02bf8fc7f..62fdd9097320ad48b9f54df75d76f4dca286877c 100644 (file)
@@ -48,6 +48,7 @@
 #include "af_unix.h"
 #include "conf.h"
 #include "config.h"
+#include <../include/netns_ifaddrs.h>
 #include "file_utils.h"
 #include "log.h"
 #include "macro.h"
 #include "nl.h"
 #include "utils.h"
 
-#if HAVE_IFADDRS_H
-#include <ifaddrs.h>
-#else
-#include <../include/ifaddrs.h>
-#endif
-
 #ifndef HAVE_STRLCPY
 #include "include/strlcpy.h"
 #endif
@@ -1950,7 +1945,7 @@ static const char padchar[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
 char *lxc_mkifname(char *template)
 {
        int ret;
-       struct ifaddrs *ifa, *ifaddr;
+       struct netns_ifaddrs *ifa, *ifaddr;
        char name[IFNAMSIZ];
        bool exists = false;
        size_t i = 0;
@@ -1967,7 +1962,7 @@ char *lxc_mkifname(char *template)
                return NULL;
 
        /* Get all the network interfaces. */
-       ret = getifaddrs(&ifaddr);
+       ret = netns_getifaddrs(&ifaddr, -1, &(bool){false});
        if (ret < 0) {
                SYSERROR("Failed to get network interfaces");
                return NULL;
@@ -2001,7 +1996,7 @@ char *lxc_mkifname(char *template)
                        break;
        }
 
-       freeifaddrs(ifaddr);
+       netns_freeifaddrs(ifaddr);
        (void)strlcpy(template, name, strlen(template) + 1);
 
        return template;
index e2f576d7141425414a43d8443e7d44134bcc5aa5..1d0c4041508af45e2ceffbac02f4dc1a4fdb3e6c 100644 (file)
 #include <lxc/lxccontainer.h>
 
 #include "arguments.h"
+#include "../../include/netns_ifaddrs.h"
 #include "log.h"
 #include "utils.h"
 
-#if HAVE_IFADDRS_H
-#include <ifaddrs.h>
-#else
-#include "../include/ifaddrs.h"
-#endif
-
 lxc_log_define(lxc_device, lxc);
 
 static bool is_interface(const char *dev_name, pid_t pid);
@@ -73,7 +68,7 @@ static bool is_interface(const char *dev_name, pid_t pid)
        }
 
        if (p == 0) {
-               struct ifaddrs *interfaceArray = NULL, *tempIfAddr = NULL;
+               struct netns_ifaddrs *interfaceArray = NULL, *tempIfAddr = NULL;
 
                if (!switch_to_ns(pid, "net")) {
                        ERROR("Failed to enter netns of container");
@@ -81,7 +76,7 @@ static bool is_interface(const char *dev_name, pid_t pid)
                }
 
                /* Grab the list of interfaces */
-               if (getifaddrs(&interfaceArray)) {
+               if (netns_getifaddrs(&interfaceArray, -1, &(bool){false})) {
                        ERROR("Failed to get interfaces list");
                        _exit(-1);
                }