]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
network: improve network logging
authorChristian Brauner <christian.brauner@ubuntu.com>
Sun, 18 Jun 2017 09:31:39 +0000 (11:31 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Sun, 18 Jun 2017 09:55:34 +0000 (11:55 +0200)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/confile.c
src/lxc/confile_utils.c
src/lxc/confile_utils.h

index 8f99b886f7fc96d1bf28d7c99f82f7338c4c4a51..66fb1d1861611e23f035a1f9de3df5365e73bdec 100644 (file)
@@ -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,
index 9bc61628419ceadf8ef6fe65d63ecd25df295d1f..eb6b4717da32ee55d1a0c29a15da54ac8ed9a34e 100644 (file)
@@ -22,6 +22,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <arpa/inet.h>
 
 #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;
+}
index f50dc336543a32bbac9933b8ffb42ca3ce182a41..284ecc574bed5de9e48c1afdcc1c64c930b6c511 100644 (file)
 
 #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 */