]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
confile_utils: lxc_config_net_is_hwaddr()
authorChristian Brauner <christian.brauner@ubuntu.com>
Mon, 4 Mar 2019 19:26:33 +0000 (20:26 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Mon, 4 Mar 2019 19:42:11 +0000 (20:42 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/confile.c
src/lxc/confile_utils.c
src/lxc/confile_utils.h
src/tests/lxc-test-utils.c

index 120e9cddf8aac0379935af4797d91ab14f6c872c..2c420cf8b5980470b15be2f8aefea41dd1ae22e6 100644 (file)
@@ -3014,7 +3014,7 @@ bool network_new_hwaddrs(struct lxc_conf *conf)
                else
                        lend++;
 
-               if (!lxc_config_net_hwaddr(lstart)) {
+               if (!lxc_config_net_is_hwaddr(lstart)) {
                        lstart = lend;
                        continue;
                }
index 04926854d1134c11168e8dab2a2f694e030c17fb..fd6c28a0b9fbe56bae79d4885a45193feb9ca9b4 100644 (file)
@@ -548,6 +548,27 @@ int network_ifname(char *valuep, const char *value, size_t size)
        return 0;
 }
 
+bool lxc_config_net_is_hwaddr(const char *line)
+{
+       unsigned index;
+       char tmp[7];
+
+       if (strncmp(line, "lxc.net", 7) != 0)
+               return false;
+
+       if (strncmp(line, "lxc.net.hwaddr", 14) == 0)
+               return true;
+
+       if (strncmp(line, "lxc.network.hwaddr", 18) == 0)
+               return true;
+
+       if (sscanf(line, "lxc.net.%u.%6s", &index, tmp) == 2 ||
+           sscanf(line, "lxc.network.%u.%6s", &index, tmp) == 2)
+               return strncmp(tmp, "hwaddr", 6) == 0;
+
+       return false;
+}
+
 void rand_complete_hwaddr(char *hwaddr)
 {
        const char hex[] = "0123456789abcdef";
@@ -580,27 +601,6 @@ void rand_complete_hwaddr(char *hwaddr)
        }
 }
 
-bool lxc_config_net_hwaddr(const char *line)
-{
-       unsigned index;
-       char tmp[7];
-
-       if (strncmp(line, "lxc.net", 7) != 0)
-               return false;
-
-       if (strncmp(line, "lxc.net.hwaddr", 14) == 0)
-               return true;
-
-       if (strncmp(line, "lxc.network.hwaddr", 18) == 0)
-               return true;
-
-       if (sscanf(line, "lxc.net.%u.%6s", &index, tmp) == 2 ||
-           sscanf(line, "lxc.network.%u.%6s", &index, tmp) == 2)
-               return strncmp(tmp, "hwaddr", 6) == 0;
-
-       return false;
-}
-
 /*
  * If we find a lxc.net.[i].hwaddr or lxc.network.hwaddr in the original config
  * file, we expand it in the unexpanded_config, so that after a save_config we
@@ -617,7 +617,7 @@ void update_hwaddr(const char *line)
        if (line[0] == '#')
                return;
 
-       if (!lxc_config_net_hwaddr(line))
+       if (!lxc_config_net_is_hwaddr(line))
                return;
 
        /* Let config_net_hwaddr raise the error. */
index e381cbe6480229560cf9f024931e0e262342b5be..2c3948b8fbab07defddc26cabfdb49458b6ae4b0 100644 (file)
@@ -66,7 +66,7 @@ extern int set_config_path_item(char **conf_item, const char *value);
 extern int config_ip_prefix(struct in_addr *addr);
 extern int network_ifname(char *valuep, const char *value, size_t size);
 extern void rand_complete_hwaddr(char *hwaddr);
-extern bool lxc_config_net_hwaddr(const char *line);
+extern bool lxc_config_net_is_hwaddr(const char *line);
 extern void update_hwaddr(const char *line);
 extern bool new_hwaddr(char *hwaddr);
 extern int lxc_get_conf_str(char *retv, int inlen, const char *value);
index 4f7950ce8446b02577f7c94cc735cb675a667f3c..841198d9ef6c5ee0c4737f18c938c4b72a4a4615 100644 (file)
@@ -518,18 +518,18 @@ void test_parse_byte_size_string(void)
        }
 }
 
-void test_lxc_config_net_hwaddr(void)
+void test_lxc_config_net_is_hwaddr(void)
 {
-       if (!lxc_config_net_hwaddr("lxc.net.0.hwaddr = 00:16:3e:04:65:b8\n"))
+       if (!lxc_config_net_is_hwaddr("lxc.net.0.hwaddr = 00:16:3e:04:65:b8\n"))
                exit(EXIT_FAILURE);
 
-       if (lxc_config_net_hwaddr("lxc.net"))
+       if (lxc_config_net_is_hwaddr("lxc.net"))
                exit(EXIT_FAILURE);
 
-       if (lxc_config_net_hwaddr("lxc.net."))
+       if (lxc_config_net_is_hwaddr("lxc.net."))
                exit(EXIT_FAILURE);
 
-       if (lxc_config_net_hwaddr("lxc.net.0."))
+       if (lxc_config_net_is_hwaddr("lxc.net.0."))
                exit(EXIT_FAILURE);
 }
 
@@ -604,7 +604,7 @@ int main(int argc, char *argv[])
        test_lxc_safe_int();
        test_lxc_safe_long();
        test_parse_byte_size_string();
-       test_lxc_config_net_hwaddr();
+       test_lxc_config_net_is_hwaddr();
        test_task_blocks_signal();
 
        exit(EXIT_SUCCESS);