tree_wide: switch to netns_getifaddrs()

parent c504d32f
...@@ -48,6 +48,7 @@ ...@@ -48,6 +48,7 @@
#include "config.h" #include "config.h"
#include "confile.h" #include "confile.h"
#include "confile_utils.h" #include "confile_utils.h"
#include <../include/netns_ifaddrs.h>
#include "log.h" #include "log.h"
#include "lxcseccomp.h" #include "lxcseccomp.h"
#include "network.h" #include "network.h"
...@@ -55,12 +56,6 @@ ...@@ -55,12 +56,6 @@
#include "storage.h" #include "storage.h"
#include "utils.h" #include "utils.h"
#if HAVE_IFADDRS_H
#include <ifaddrs.h>
#else
#include <../include/ifaddrs.h>
#endif
#if HAVE_SYS_PERSONALITY_H #if HAVE_SYS_PERSONALITY_H
#include <sys/personality.h> #include <sys/personality.h>
#endif #endif
...@@ -314,14 +309,14 @@ static int set_config_net_flags(const char *key, const char *value, ...@@ -314,14 +309,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, static int create_matched_ifnames(const char *value, struct lxc_conf *lxc_conf,
struct lxc_netdev *netdev) struct lxc_netdev *netdev)
{ {
struct ifaddrs *ifaddr, *ifa; struct netns_ifaddrs *ifaddr, *ifa;
int n; int n;
int ret = 0; int ret = 0;
const char *type_key = "lxc.net.type"; const char *type_key = "lxc.net.type";
const char *link_key = "lxc.net.link"; const char *link_key = "lxc.net.link";
const char *tmpvalue = "phys"; const char *tmpvalue = "phys";
if (getifaddrs(&ifaddr) == -1) { if (netns_getifaddrs(&ifaddr, -1, &(bool){false}) < 0) {
SYSERROR("Get network interfaces failed"); SYSERROR("Get network interfaces failed");
return -1; return -1;
} }
...@@ -349,7 +344,7 @@ static int create_matched_ifnames(const char *value, struct lxc_conf *lxc_conf, ...@@ -349,7 +344,7 @@ static int create_matched_ifnames(const char *value, struct lxc_conf *lxc_conf,
} }
} }
freeifaddrs(ifaddr); netns_freeifaddrs(ifaddr);
ifaddr = NULL; ifaddr = NULL;
return ret; return ret;
......
...@@ -50,6 +50,7 @@ ...@@ -50,6 +50,7 @@
#include "confile_utils.h" #include "confile_utils.h"
#include "criu.h" #include "criu.h"
#include "error.h" #include "error.h"
#include <../include/netns_ifaddrs.h>
#include "initutils.h" #include "initutils.h"
#include "log.h" #include "log.h"
#include "lxc.h" #include "lxc.h"
...@@ -75,12 +76,6 @@ ...@@ -75,12 +76,6 @@
#include <sys/mkdev.h> #include <sys/mkdev.h>
#endif #endif
#if HAVE_IFADDRS_H
#include <ifaddrs.h>
#else
#include <../include/ifaddrs.h>
#endif
#if IS_BIONIC #if IS_BIONIC
#include <../include/lxcmntent.h> #include <../include/lxcmntent.h>
#else #else
...@@ -2305,7 +2300,7 @@ static char **do_lxcapi_get_interfaces(struct lxc_container *c) ...@@ -2305,7 +2300,7 @@ static char **do_lxcapi_get_interfaces(struct lxc_container *c)
if (pid == 0) { /* child */ if (pid == 0) { /* child */
int ret = 1, nbytes; 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 the read-end of the pipe */
close(pipefd[0]); close(pipefd[0]);
...@@ -2316,7 +2311,7 @@ static char **do_lxcapi_get_interfaces(struct lxc_container *c) ...@@ -2316,7 +2311,7 @@ static char **do_lxcapi_get_interfaces(struct lxc_container *c)
} }
/* Grab the list of interfaces */ /* Grab the list of interfaces */
if (getifaddrs(&interfaceArray)) { if (netns_getifaddrs(&interfaceArray, -1, &(bool){false})) {
SYSERROR("Failed to get interfaces list"); SYSERROR("Failed to get interfaces list");
goto out; goto out;
} }
...@@ -2335,7 +2330,7 @@ static char **do_lxcapi_get_interfaces(struct lxc_container *c) ...@@ -2335,7 +2330,7 @@ static char **do_lxcapi_get_interfaces(struct lxc_container *c)
out: out:
if (interfaceArray) if (interfaceArray)
freeifaddrs(interfaceArray); netns_freeifaddrs(interfaceArray);
/* close the write-end of the pipe, thus sending EOF to the reader */ /* close the write-end of the pipe, thus sending EOF to the reader */
close(pipefd[1]); close(pipefd[1]);
...@@ -2407,7 +2402,7 @@ static char **do_lxcapi_get_ips(struct lxc_container *c, const char *interface, ...@@ -2407,7 +2402,7 @@ static char **do_lxcapi_get_ips(struct lxc_container *c, const char *interface,
int ret = 1; int ret = 1;
char *address = NULL; char *address = NULL;
void *tempAddrPtr = 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 the read-end of the pipe */
close(pipefd[0]); close(pipefd[0]);
...@@ -2418,7 +2413,7 @@ static char **do_lxcapi_get_ips(struct lxc_container *c, const char *interface, ...@@ -2418,7 +2413,7 @@ static char **do_lxcapi_get_ips(struct lxc_container *c, const char *interface,
} }
/* Grab the list of interfaces */ /* Grab the list of interfaces */
if (getifaddrs(&interfaceArray)) { if (netns_getifaddrs(&interfaceArray, -1, &(bool){false})) {
SYSERROR("Failed to get interfaces list"); SYSERROR("Failed to get interfaces list");
goto out; goto out;
} }
...@@ -2474,7 +2469,7 @@ static char **do_lxcapi_get_ips(struct lxc_container *c, const char *interface, ...@@ -2474,7 +2469,7 @@ static char **do_lxcapi_get_ips(struct lxc_container *c, const char *interface,
out: out:
if (interfaceArray) if (interfaceArray)
freeifaddrs(interfaceArray); netns_freeifaddrs(interfaceArray);
/* close the write-end of the pipe, thus sending EOF to the reader */ /* close the write-end of the pipe, thus sending EOF to the reader */
close(pipefd[1]); close(pipefd[1]);
......
...@@ -48,6 +48,7 @@ ...@@ -48,6 +48,7 @@
#include "af_unix.h" #include "af_unix.h"
#include "conf.h" #include "conf.h"
#include "config.h" #include "config.h"
#include <../include/netns_ifaddrs.h>
#include "file_utils.h" #include "file_utils.h"
#include "log.h" #include "log.h"
#include "macro.h" #include "macro.h"
...@@ -55,12 +56,6 @@ ...@@ -55,12 +56,6 @@
#include "nl.h" #include "nl.h"
#include "utils.h" #include "utils.h"
#if HAVE_IFADDRS_H
#include <ifaddrs.h>
#else
#include <../include/ifaddrs.h>
#endif
#ifndef HAVE_STRLCPY #ifndef HAVE_STRLCPY
#include "include/strlcpy.h" #include "include/strlcpy.h"
#endif #endif
...@@ -1950,7 +1945,7 @@ static const char padchar[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; ...@@ -1950,7 +1945,7 @@ static const char padchar[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char *lxc_mkifname(char *template) char *lxc_mkifname(char *template)
{ {
int ret; int ret;
struct ifaddrs *ifa, *ifaddr; struct netns_ifaddrs *ifa, *ifaddr;
char name[IFNAMSIZ]; char name[IFNAMSIZ];
bool exists = false; bool exists = false;
size_t i = 0; size_t i = 0;
...@@ -1967,7 +1962,7 @@ char *lxc_mkifname(char *template) ...@@ -1967,7 +1962,7 @@ char *lxc_mkifname(char *template)
return NULL; return NULL;
/* Get all the network interfaces. */ /* Get all the network interfaces. */
ret = getifaddrs(&ifaddr); ret = netns_getifaddrs(&ifaddr, -1, &(bool){false});
if (ret < 0) { if (ret < 0) {
SYSERROR("Failed to get network interfaces"); SYSERROR("Failed to get network interfaces");
return NULL; return NULL;
...@@ -2001,7 +1996,7 @@ char *lxc_mkifname(char *template) ...@@ -2001,7 +1996,7 @@ char *lxc_mkifname(char *template)
break; break;
} }
freeifaddrs(ifaddr); netns_freeifaddrs(ifaddr);
(void)strlcpy(template, name, strlen(template) + 1); (void)strlcpy(template, name, strlen(template) + 1);
return template; return template;
......
...@@ -30,15 +30,10 @@ ...@@ -30,15 +30,10 @@
#include <lxc/lxccontainer.h> #include <lxc/lxccontainer.h>
#include "arguments.h" #include "arguments.h"
#include "../../include/netns_ifaddrs.h"
#include "log.h" #include "log.h"
#include "utils.h" #include "utils.h"
#if HAVE_IFADDRS_H
#include <ifaddrs.h>
#else
#include "../include/ifaddrs.h"
#endif
lxc_log_define(lxc_device, lxc); lxc_log_define(lxc_device, lxc);
static bool is_interface(const char *dev_name, pid_t pid); 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) ...@@ -73,7 +68,7 @@ static bool is_interface(const char *dev_name, pid_t pid)
} }
if (p == 0) { if (p == 0) {
struct ifaddrs *interfaceArray = NULL, *tempIfAddr = NULL; struct netns_ifaddrs *interfaceArray = NULL, *tempIfAddr = NULL;
if (!switch_to_ns(pid, "net")) { if (!switch_to_ns(pid, "net")) {
ERROR("Failed to enter netns of container"); ERROR("Failed to enter netns of container");
...@@ -81,7 +76,7 @@ static bool is_interface(const char *dev_name, pid_t pid) ...@@ -81,7 +76,7 @@ static bool is_interface(const char *dev_name, pid_t pid)
} }
/* Grab the list of interfaces */ /* Grab the list of interfaces */
if (getifaddrs(&interfaceArray)) { if (netns_getifaddrs(&interfaceArray, -1, &(bool){false})) {
ERROR("Failed to get interfaces list"); ERROR("Failed to get interfaces list");
_exit(-1); _exit(-1);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment