diff --git a/src/lxc/confile.c b/src/lxc/confile.c index 8f99b886f..66fb1d186 100644 --- a/src/lxc/confile.c +++ b/src/lxc/confile.c @@ -685,8 +685,6 @@ static int set_config_network(const char *key, const char *value, return clr_config_network(key, lxc_conf, data); } -static int macvlan_mode(int *valuep, const char *value); - static int set_config_network_type(const char *key, const char *value, struct lxc_conf *lxc_conf, void *data) { @@ -728,7 +726,8 @@ static int set_config_network_type(const char *key, const char *value, netdev->type = LXC_NET_VETH; } else if (!strcmp(value, "macvlan")) { netdev->type = LXC_NET_MACVLAN; - macvlan_mode(&netdev->priv.macvlan_attr.mode, "private"); + lxc_macvlan_mode_to_flag(&netdev->priv.macvlan_attr.mode, + "private"); } else if (!strcmp(value, "vlan")) { netdev->type = LXC_NET_VLAN; } else if (!strcmp(value, "phys")) { @@ -854,47 +853,6 @@ static int network_ifname(char **valuep, const char *value) return set_config_string_item_max(valuep, value, IFNAMSIZ); } -#ifndef MACVLAN_MODE_PRIVATE -#define MACVLAN_MODE_PRIVATE 1 -#endif - -#ifndef MACVLAN_MODE_VEPA -#define MACVLAN_MODE_VEPA 2 -#endif - -#ifndef MACVLAN_MODE_BRIDGE -#define MACVLAN_MODE_BRIDGE 4 -#endif - -#ifndef MACVLAN_MODE_PASSTHRU -#define MACVLAN_MODE_PASSTHRU 8 -#endif - -static int macvlan_mode(int *valuep, const char *value) -{ - struct mc_mode { - char *name; - int mode; - } m[] = { - { "private", MACVLAN_MODE_PRIVATE }, - { "vepa", MACVLAN_MODE_VEPA }, - { "bridge", MACVLAN_MODE_BRIDGE }, - { "passthru", MACVLAN_MODE_PASSTHRU }, - }; - - size_t i; - - for (i = 0; i < sizeof(m) / sizeof(m[0]); i++) { - if (strcmp(m[i].name, value)) - continue; - - *valuep = m[i].mode; - return 0; - } - - return -1; -} - static int rand_complete_hwaddr(char *hwaddr) { const char hex[] = "0123456789abcdef"; @@ -1099,7 +1057,7 @@ static int set_config_network_macvlan_mode(const char *key, const char *value, if (!netdev) return -1; - return macvlan_mode(&netdev->priv.macvlan_attr.mode, value); + return lxc_macvlan_mode_to_flag(&netdev->priv.macvlan_attr.mode, value); } static int set_config_network_hwaddr(const char *key, const char *value, diff --git a/src/lxc/confile_utils.c b/src/lxc/confile_utils.c index 9bc616284..eb6b4717d 100644 --- a/src/lxc/confile_utils.c +++ b/src/lxc/confile_utils.c @@ -22,6 +22,7 @@ #include #include #include +#include #include "conf.h" #include "confile.h" @@ -242,18 +243,35 @@ void lxc_log_configured_netdevs(const struct lxc_conf *conf) } lxc_list_for_each(it, &conf->network) { + struct lxc_list *cur, *next; + struct lxc_inetdev *inet4dev; + struct lxc_inet6dev *inet6dev; + char bufinet4[INET_ADDRSTRLEN], bufinet6[INET6_ADDRSTRLEN]; + netdev = it->elem; TRACE("index: %zd", netdev->idx); switch (netdev->type) { case LXC_NET_VETH: TRACE("type: veth"); + if (netdev->priv.veth_attr.pair) + TRACE("veth pair: %s", + netdev->priv.veth_attr.pair); break; case LXC_NET_MACVLAN: TRACE("type: macvlan"); + if (netdev->priv.macvlan_attr.mode > 0) { + char *macvlan_mode; + macvlan_mode = lxc_macvlan_flag_to_mode( + netdev->priv.macvlan_attr.mode); + TRACE("macvlan mode: %s", + macvlan_mode ? macvlan_mode + : "(invalid mode)"); + } break; case LXC_NET_VLAN: TRACE("type: vlan"); + TRACE("vlan id: %d", netdev->priv.vlan_attr.vid); break; case LXC_NET_PHYS: TRACE("type: phys"); @@ -269,19 +287,52 @@ void lxc_log_configured_netdevs(const struct lxc_conf *conf) return; } - TRACE("flags: %s", netdev->flags == IFF_UP ? "up" : "none"); - if (netdev->link) - TRACE("link: %s", netdev->link); - if (netdev->name) - TRACE("name: %s", netdev->name); - if (netdev->hwaddr) - TRACE("hwaddr: %s", netdev->hwaddr); - if (netdev->mtu) - TRACE("mtu: %s", netdev->mtu); - if (netdev->upscript) - TRACE("upscript: %s", netdev->upscript); - if (netdev->downscript) - TRACE("downscript: %s", netdev->downscript); + if (netdev->type != LXC_NET_EMPTY) { + TRACE("flags: %s", + netdev->flags == IFF_UP ? "up" : "none"); + if (netdev->link) + TRACE("link: %s", netdev->link); + if (netdev->name) + TRACE("name: %s", netdev->name); + if (netdev->hwaddr) + TRACE("hwaddr: %s", netdev->hwaddr); + if (netdev->mtu) + TRACE("mtu: %s", netdev->mtu); + if (netdev->upscript) + TRACE("upscript: %s", netdev->upscript); + if (netdev->downscript) + TRACE("downscript: %s", netdev->downscript); + + TRACE("ipv4 gateway auto: %s", + netdev->ipv4_gateway_auto ? "true" : "false"); + + if (netdev->ipv4_gateway) { + inet_ntop(AF_INET, netdev->ipv4_gateway, + bufinet4, sizeof(bufinet4)); + TRACE("ipv4 gateway: %s", bufinet4); + } + + lxc_list_for_each_safe(cur, &netdev->ipv4, next) { + inet4dev = cur->elem; + inet_ntop(AF_INET, &inet4dev->addr, bufinet4, + sizeof(bufinet4)); + TRACE("ipv4 addr: %s", bufinet4); + } + + TRACE("ipv6 gateway auto: %s", + netdev->ipv6_gateway_auto ? "true" : "false"); + if (netdev->ipv6_gateway) { + inet_ntop(AF_INET6, netdev->ipv6_gateway, + bufinet6, sizeof(bufinet6)); + TRACE("ipv6 gateway: %s", bufinet6); + } + lxc_list_for_each_safe(cur, &netdev->ipv6, next) { + inet6dev = cur->elem; + inet_ntop(AF_INET6, &inet6dev->addr, bufinet6, + sizeof(bufinet6)); + TRACE("ipv6 addr: %s", bufinet6); + } + } } } @@ -354,3 +405,42 @@ void lxc_free_networks(struct lxc_list *networks) /* prevent segfaults */ lxc_list_init(networks); } + +static struct macvlan_mode { + char *name; + int mode; +} macvlan_mode[] = { + { "private", MACVLAN_MODE_PRIVATE }, + { "vepa", MACVLAN_MODE_VEPA }, + { "bridge", MACVLAN_MODE_BRIDGE }, + { "passthru", MACVLAN_MODE_PASSTHRU }, +}; + +int lxc_macvlan_mode_to_flag(int *mode, const char *value) +{ + size_t i; + + for (i = 0; i < sizeof(macvlan_mode) / sizeof(macvlan_mode[0]); i++) { + if (strcmp(macvlan_mode[i].name, value)) + continue; + + *mode = macvlan_mode[i].mode; + return 0; + } + + return -1; +} + +char *lxc_macvlan_flag_to_mode(int mode) +{ + size_t i; + + for (i = 0; i < sizeof(macvlan_mode) / sizeof(macvlan_mode[0]); i++) { + if (macvlan_mode[i].mode == mode) + continue; + + return macvlan_mode[i].name; + } + + return NULL; +} diff --git a/src/lxc/confile_utils.h b/src/lxc/confile_utils.h index f50dc3365..284ecc574 100644 --- a/src/lxc/confile_utils.h +++ b/src/lxc/confile_utils.h @@ -24,6 +24,22 @@ #include "conf.h" +#ifndef MACVLAN_MODE_PRIVATE +#define MACVLAN_MODE_PRIVATE 1 +#endif + +#ifndef MACVLAN_MODE_VEPA +#define MACVLAN_MODE_VEPA 2 +#endif + +#ifndef MACVLAN_MODE_BRIDGE +#define MACVLAN_MODE_BRIDGE 4 +#endif + +#ifndef MACVLAN_MODE_PASSTHRU +#define MACVLAN_MODE_PASSTHRU 8 +#endif + extern int parse_idmaps(const char *idmap, char *type, unsigned long *nsid, unsigned long *hostid, unsigned long *range); @@ -35,5 +51,7 @@ lxc_get_netdev_by_idx(struct lxc_conf *conf, unsigned int idx, bool allocate); extern void lxc_log_configured_netdevs(const struct lxc_conf *conf); extern bool lxc_remove_nic_by_idx(struct lxc_conf *conf, unsigned int idx); extern void lxc_free_networks(struct lxc_list *networks); +extern int lxc_macvlan_mode_to_flag(int *mode, const char *value); +extern char *lxc_macvlan_flag_to_mode(int mode); #endif /* __LXC_CONFILE_UTILS_H */