LowerLayers: fix empty linker

This commit is contained in:
Amin Ben Ramdhane 2022-01-24 20:16:31 +01:00
parent 5abdb50dd9
commit b265b8ca8b
4 changed files with 32 additions and 0 deletions

View file

@ -365,6 +365,8 @@ static int get_linker_link(char *refparam, struct dmctx *dmctx, void *data, char
static int get_linker_vlan_term(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker)
{
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "name", linker);
if ((*linker)[0] == '\0')
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->dmmap_section, "default_linker", linker);
return 0;
}
@ -442,6 +444,7 @@ static int addObjEthernetVLANTermination(char *refparam, struct dmctx *ctx, void
// Add device section in dmmap_network file
dmuci_add_section_bbfdm("dmmap_network", "device", &dmmap_network);
dmuci_set_value_by_section(dmmap_network, "section_name", device_name);
dmuci_set_value_by_section(dmmap_network, "default_linker", device_name);
dmuci_set_value_by_section(dmmap_network, "is_vlan_ter", "1");
dmuci_set_value_by_section(dmmap_network, "vlan_term_instance", *instance);
return 0;
@ -1349,6 +1352,7 @@ static int set_EthernetVLANTermination_LowerLayers(char *refparam, struct dmctx
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "name", "");
} else if (strncmp(value, eth_link, strlen(eth_link)) == 0) {
char new_name[16] = {0}, *type;
char *iface_name = NULL;
// Get type option from device section
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "type", &type);
@ -1400,6 +1404,14 @@ static int set_EthernetVLANTermination_LowerLayers(char *refparam, struct dmctx
}
}
// Update interface->device option linked to this VLANTermination if exists
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->dmmap_section, "iface_name", &iface_name);
if (iface_name && *iface_name != 0) {
struct uci_section *s = get_origin_section_from_config("network", "interface", iface_name);
dmuci_set_value_by_section(s, "device", new_name);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->dmmap_section, "iface_name", "");
}
// Set ifname and name options of device section
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "ifname", vlan_linker);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "name", new_name);

View file

@ -1327,6 +1327,14 @@ static int set_IPInterface_LowerLayers(char *refparam, struct dmctx *ctx, void *
if (strncmp(value, eth_vlan_term, strlen(eth_vlan_term)) == 0) {
struct uci_section *s = NULL, *stmp = NULL;
// Check linker value
struct uci_section *vlan_ter_s = get_dup_section_in_config_opt("network", "device", "name", linker_buf);
if (vlan_ter_s == NULL) {
vlan_ter_s = get_dup_section_in_dmmap_opt("dmmap_network", "device", "default_linker", linker_buf);
dmuci_set_value_by_section_bbfdm(vlan_ter_s, "iface_name", section_name((struct uci_section *)data));
return 0;
}
// Remove the device section corresponding to this interface if exists
char *device = get_device(section_name((struct uci_section *)data));
uci_foreach_option_eq_safe("network", "device", "name", device, stmp, s) {

View file

@ -293,6 +293,17 @@ struct uci_section *get_dup_section_in_dmmap(char *dmmap_package, char *section_
return NULL;
}
struct uci_section *get_dup_section_in_config_opt(char *package, char *section_type, char *opt_name, char *opt_value)
{
struct uci_section *s;
uci_foreach_option_eq(package, section_type, opt_name, opt_value, s) {
return s;
}
return NULL;
}
struct uci_section *get_dup_section_in_dmmap_opt(char *dmmap_package, char *section_type, char *opt_name, char *opt_value)
{
struct uci_section *s;

View file

@ -246,6 +246,7 @@ void add_elt_to_str_list(char **str_list, char *elt);
void remove_elt_from_str_list(char **str_list, char *ifname);
struct uci_section *get_origin_section_from_config(char *package, char *section_type, char *orig_section_name);
struct uci_section *get_dup_section_in_dmmap(char *dmmap_package, char *section_type, char *orig_section_name);
struct uci_section *get_dup_section_in_config_opt(char *package, char *section_type, char *opt_name, char *opt_value);
struct uci_section *get_dup_section_in_dmmap_opt(char *dmmap_package, char *section_type, char *opt_name, char *opt_value);
struct uci_section *get_dup_section_in_dmmap_eq(char *dmmap_package, char* section_type, char*sect_name, char *opt_name, char* opt_value);
bool elt_exists_in_array(char **str_array, char *str, int length);