mirror of
https://dev.iopsys.eu/bbf/bbfdm.git
synced 2026-03-02 23:53:49 +01:00
DHCPv{4,6}.Server.Pool.: Fix add/delete method
This commit is contained in:
parent
8a369fda5d
commit
8573e54f95
3 changed files with 34 additions and 3 deletions
|
|
@ -425,6 +425,31 @@ static struct uci_section *get_dhcp_classifier(char *classifier_name, char *netw
|
|||
return NULL;
|
||||
}
|
||||
|
||||
char *get_dhcp_server_pool_last_instance(char *package, char *section, char *dmmap_package, char *opt_inst)
|
||||
{
|
||||
struct uci_section *s = NULL, *dmmap_section = NULL;
|
||||
char *instance = NULL, *last_inst = NULL, *ignore = NULL;
|
||||
|
||||
uci_foreach_sections(package, section, s) {
|
||||
|
||||
// skip the section if option ignore = '1'
|
||||
dmuci_get_value_by_section_string(s, "ignore", &ignore);
|
||||
if (ignore && strcmp(ignore, "1") == 0)
|
||||
continue;
|
||||
|
||||
get_dmmap_section_of_config_section(dmmap_package, section, section_name(s), &dmmap_section);
|
||||
if (dmmap_section == NULL) {
|
||||
dmuci_add_section_bbfdm(dmmap_package, section, &dmmap_section);
|
||||
dmuci_set_value_by_section(dmmap_section, "section_name", section_name(s));
|
||||
}
|
||||
instance = update_instance(last_inst, 2, dmmap_section, opt_inst);
|
||||
if(last_inst)
|
||||
dmfree(last_inst);
|
||||
last_inst = dmstrdup(instance);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
/*************************************************************
|
||||
* ADD & DEL OBJ
|
||||
**************************************************************/
|
||||
|
|
@ -433,7 +458,7 @@ static int addObjDHCPv4ServerPool(char *refparam, struct dmctx *ctx, void *data,
|
|||
struct uci_section *s = NULL, *dmmap_dhcp = NULL;
|
||||
char dhcp_sname[32] = {0};
|
||||
|
||||
char *instance = get_last_instance_bbfdm("dmmap_dhcp", "dhcp", "dhcp_instance");
|
||||
char *instance = get_dhcp_server_pool_last_instance("dhcp", "dhcp", "dmmap_dhcp", "dhcp_instance");
|
||||
snprintf(dhcp_sname, sizeof(dhcp_sname), "dhcp_%d", instance ? atoi(instance) + 1 : 1);
|
||||
|
||||
dmuci_add_section("dhcp", "dhcp", &s);
|
||||
|
|
@ -441,6 +466,7 @@ static int addObjDHCPv4ServerPool(char *refparam, struct dmctx *ctx, void *data,
|
|||
dmuci_set_value_by_section(s, "start", "100");
|
||||
dmuci_set_value_by_section(s, "leasetime", "12h");
|
||||
dmuci_set_value_by_section(s, "limit", "150");
|
||||
dmuci_set_value_by_section(s, "ignore", "0");
|
||||
|
||||
dmuci_add_section_bbfdm("dmmap_dhcp", "dhcp", &dmmap_dhcp);
|
||||
dmuci_set_value_by_section(dmmap_dhcp, "section_name", dhcp_sname);
|
||||
|
|
|
|||
|
|
@ -40,5 +40,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 *s_data, char *dmmap_name, char *proto, int action);
|
||||
char *get_dhcp_server_pool_last_instance(char *package, char *section, char *dmmap_package, char *opt_inst);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -347,17 +347,21 @@ static int delObjDHCPv6Client(char *refparam, struct dmctx *ctx, void *data, cha
|
|||
static int addObjDHCPv6ServerPool(char *refparam, struct dmctx *ctx, void *data, char **instance)
|
||||
{
|
||||
struct uci_section *s = NULL, *dmmap_dhcp = NULL;
|
||||
char dhcpv6_sname[32] = {0};
|
||||
|
||||
char *inst_para = get_last_instance_bbfdm("dmmap_dhcpv6", "dhcp", "dhcpv6_serv_pool_instance");
|
||||
char *inst_para = get_dhcp_server_pool_last_instance("dhcp", "dhcp", "dmmap_dhcpv6", "dhcpv6_serv_pool_instance");
|
||||
snprintf(dhcpv6_sname, sizeof(dhcpv6_sname), "dhcpv6_%d", inst_para ? atoi(inst_para) + 1 : 1);
|
||||
|
||||
dmuci_add_section("dhcp", "dhcp", &s);
|
||||
dmuci_rename_section_by_section(s, dhcpv6_sname);
|
||||
dmuci_set_value_by_section(s, "dhcpv6", "server");
|
||||
dmuci_set_value_by_section(s, "start", "100");
|
||||
dmuci_set_value_by_section(s, "leasetime", "12h");
|
||||
dmuci_set_value_by_section(s, "limit", "150");
|
||||
dmuci_set_value_by_section(s, "ignore", "0");
|
||||
|
||||
dmuci_add_section_bbfdm("dmmap_dhcpv6", "dhcp", &dmmap_dhcp);
|
||||
dmuci_set_value_by_section(dmmap_dhcp, "section_name", section_name(s));
|
||||
dmuci_set_value_by_section(dmmap_dhcp, "section_name", dhcpv6_sname);
|
||||
*instance = update_instance(inst_para, 2, dmmap_dhcp, "dhcpv6_serv_pool_instance");
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue