lib-interface: Add parsing for interface 'options'
authorVinit Agnihotri <vagnihotri@ddn.com>
Tue, 5 Mar 2024 10:15:11 +0000 (02:15 -0800)
committerMartin Schwenke <martins@samba.org>
Tue, 16 Apr 2024 23:51:45 +0000 (23:51 +0000)
Signed-off-by: Vinit Agnihotri <vagnihotri@ddn.com>
Reviewed-by: Martin Schwenke <mschwenke@ddn.com>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
source3/lib/interface.c
source3/lib/interface.h

index c586e97e741b896a654f9047c0ad2c1a3e596463..b8450316b6730db65ddf61bd6edcf09ed8181cbf 100644 (file)
@@ -338,6 +338,7 @@ static void add_interface(const struct iface_struct *ifs)
        iface->linkspeed = ifs->linkspeed;
        iface->capability = ifs->capability;
        iface->if_index = ifs->if_index;
+       iface->options = ifs->options;
 
        DLIST_ADD(local_interfaces, iface);
 
@@ -353,8 +354,11 @@ static void add_interface(const struct iface_struct *ifs)
 }
 
 
-static void parse_extra_info(char *key, uint64_t *speed, uint32_t *cap,
-                            uint32_t *if_index)
+static void parse_extra_info(char *key,
+                            uint64_t *speed,
+                            uint32_t *cap,
+                            uint32_t *if_index,
+                            uint32_t *options)
 {
        while (key != NULL && *key != '\0') {
                char *next_key;
@@ -397,6 +401,15 @@ static void parse_extra_info(char *key, uint64_t *speed, uint32_t *cap,
                                if (error != 0) {
                                        DBG_DEBUG("Invalid key value (%s)\n", val);
                                }
+                       } else if (strequal_m(key, "options")) {
+                               if (strequal_m(val, "dynamic")) {
+                                       *options |= IFACE_DYNAMIC_OPTION;
+                               } else if (strequal_m(val, "nodynamic")) {
+                                       *options &= ~IFACE_DYNAMIC_OPTION;
+                               } else {
+                                       DBG_WARNING("Options unknown: "
+                                                   "'%s'\n", val);
+                               }
                        } else {
                                DBG_DEBUG("Key unknown: '%s'\n", key);
                        }
@@ -455,6 +468,8 @@ static void interpret_interface(char *token)
        bool speed_set = false;
        bool cap_set = false;
        bool if_index_set = false;
+       uint32_t options = IFACE_NONE_OPTION;
+       bool options_set = false;
 
        /*
         * extract speed / capability information if present
@@ -462,7 +477,7 @@ static void interpret_interface(char *token)
        p = strchr_m(token, ';');
        if (p != NULL) {
                *p++ = 0;
-               parse_extra_info(p, &speed, &cap, &if_index);
+               parse_extra_info(p, &speed, &cap, &if_index, &options);
                if (speed != 0) {
                        speed_set = true;
                }
@@ -472,6 +487,9 @@ static void interpret_interface(char *token)
                if (if_index != 0) {
                        if_index_set = true;
                }
+               if (options != IFACE_NONE_OPTION) {
+                       options_set = true;
+               }
        }
 
        /* first check if it is an interface name */
@@ -486,6 +504,9 @@ static void interpret_interface(char *token)
                        if (if_index_set) {
                                probed_ifaces[i].if_index = if_index;
                        }
+                       if (options_set) {
+                                probed_ifaces[i].options = options;
+                       }
                        add_interface(&probed_ifaces[i]);
                        added = true;
                }
@@ -515,6 +536,9 @@ static void interpret_interface(char *token)
                                if (if_index_set) {
                                        probed_ifaces[i].if_index = if_index;
                                }
+                               if (options_set) {
+                                       probed_ifaces[i].options = options;
+                               }
                                add_interface(&probed_ifaces[i]);
                                return;
                        }
@@ -595,6 +619,9 @@ static void interpret_interface(char *token)
                                if (if_index_set) {
                                        probed_ifaces[i].if_index = if_index;
                                }
+                               if (options_set) {
+                                       probed_ifaces[i].options = options;
+                               }
                                add_interface(&probed_ifaces[i]);
                                probed_ifaces[i].netmask = saved_mask;
                                return;
@@ -626,6 +653,7 @@ static void interpret_interface(char *token)
                ifs.linkspeed = 1000 * 1000 * 1000;
        }
        ifs.capability = cap;
+       ifs.options = options;
        add_interface(&ifs);
 }
 
index 1a575c5f22b1224113d37b01dc496f9c27a9d353..d93e9094a33e3119e6c4df8f89538567539d614f 100644 (file)
@@ -24,6 +24,9 @@
 
 #include <system/network.h>
 
+#define IFACE_NONE_OPTION      0x00000000U
+#define IFACE_DYNAMIC_OPTION   0x00000001U
+
 bool ismyaddr(const struct sockaddr *ip);
 bool ismyip_v4(struct in_addr ip);
 bool is_local_net(const struct sockaddr *from);