DHCPv4: update implementation

- Don't create a network interface when adding a new 'DHCPv4.Client.' instance, therefore the network interface will only be managed with 'Device.IP.Interface.' object
This commit is contained in:
Amin Ben Ramdhane 2022-02-02 22:24:20 +01:00
parent 25fee5c7dc
commit 52e6a80306
6 changed files with 935 additions and 638 deletions

View file

@ -363,7 +363,7 @@ int adm_entry_get_linker_param(struct dmctx *ctx, char *param, char *linker, cha
struct dmctx dmctx = {0};
*value = "";
if (!param || !linker)
if (!param || !linker || *linker == 0)
return 0;
dm_ctx_init_sub(&dmctx, ctx->instance_mode);

File diff suppressed because it is too large Load diff

View file

@ -39,7 +39,6 @@ extern DMLEAF tDHCPv4RelayForwardingParams[];
int set_section_order(char *package, char *dmpackage, char* sect_type, struct uci_section *dmmap_sect, struct uci_section *conf, int set_force, char* order);
int get_value_in_mac_format(struct uci_section *s, char *option_name, bool type, char **value);
int set_DHCP_Interface(struct dmctx *ctx, char *value, struct uci_section *config_s, struct uci_section *dmmap_s, char *dmmap_name, char *proto, int action);
bool tag_option_exists(char *dmmap_package, char *section, char *opt_check, char *value_check, char *tag_name, char *tag_value);
char *generate_tag_option(char *dmmap_package, char *section, char *opt_check, char *value_check, char *tag_name);

View file

@ -368,6 +368,29 @@ static int delete_ip_intertace_instance(struct uci_section *s)
dmuci_get_value_by_section_string(int_ss, "proto", &proto);
if (strcmp(proto, "dhcp") == 0) {
struct uci_section *dhcpv4_client_s = get_dup_section_in_dmmap_opt("dmmap_dhcp_client", "interface", "iface_name", section_name(int_ss));
if (dhcpv4_client_s) {
char *dhcp_client_key = NULL;
dmuci_get_value_by_section_string(dhcpv4_client_s, "dhcp_client_key", &dhcp_client_key);
/* Remove "DHCPv4.Client.{i}.ReqOption." sections related to this "IP.Interface." object */
uci_path_foreach_option_eq_safe(bbfdm, "dmmap_dhcp_client", "req_option", "dhcp_client_key", dhcp_client_key, stmp, ss) {
dmuci_delete_by_section(ss, NULL, NULL);
}
/* Remove "DHCPv4.Client.{i}.SentOption." sections related to this "IP.Interface." object */
uci_path_foreach_option_eq_safe(bbfdm, "dmmap_dhcp_client", "send_option", "dhcp_client_key", dhcp_client_key, stmp, ss) {
dmuci_delete_by_section(ss, NULL, NULL);
}
/* Remove "DHCPv4.Client." section related to this "IP.Interface." object */
dmuci_delete_by_section(dhcpv4_client_s, NULL, NULL);
}
}
if (strcmp(proto, "dhcpv6") == 0) {
struct uci_section *dhcpv6_client_s = get_dup_section_in_dmmap_opt("dmmap_dhcpv6", "interface", "iface_name", section_name(int_ss));
@ -524,17 +547,6 @@ static int browseIPInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void
strchr(device, '@'))
continue;
// skip dhcpv4 sections added by controller
if (strcmp(proto, "dhcp") == 0) {
struct uci_section *dmmap_section = NULL;
char *dhcpv4_user_s = NULL;
get_dmmap_section_of_config_section("dmmap_dhcp_client", "interface", section_name(p->config_section), &dmmap_section);
dmuci_get_value_by_section_string(dmmap_section, "added_by_controller", &dhcpv4_user_s);
if (dhcpv4_user_s && strcmp(dhcpv4_user_s, "1") == 0)
continue;
}
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "ip_int_instance", "ip_int_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, inst) == DM_STOP)

View file

@ -328,6 +328,21 @@ struct uci_section *get_dup_section_in_dmmap_eq(char *dmmap_package, char* secti
return NULL;
}
struct uci_section *get_section_in_dmmap_with_options_eq(char *dmmap_package, char *section_type, char *opt1_name, char *opt1_value, char *opt2_name, char *opt2_value)
{
struct uci_section *s = NULL;
uci_path_foreach_option_eq(bbfdm, dmmap_package, section_type, opt1_name, opt1_value, s) {
char *value = NULL;
dmuci_get_value_by_section_string(s, opt2_name, &value);
if (opt2_value && value && strcmp(value, opt2_value) == 0)
return s;
}
return NULL;
}
void synchronize_specific_config_sections_with_dmmap(char *package, char *section_type, char *dmmap_package, struct list_head *dup_list)
{
struct uci_section *s, *stmp, *dmmap_sect;

View file

@ -249,6 +249,7 @@ struct uci_section *get_dup_section_in_dmmap(char *dmmap_package, char *section_
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);
struct uci_section *get_section_in_dmmap_with_options_eq(char *dmmap_package, char *section_type, char *opt1_name, char *opt1_value, char *opt2_name, char *opt2_value);
bool elt_exists_in_array(char **str_array, char *str, int length);
int get_shift_utc_time(int shift_time, char *utc_time, int size);
int get_shift_time_time(int shift_time, char *local_time, int size);