mirror of
https://dev.iopsys.eu/bbf/bbfdm.git
synced 2026-02-21 03:42:31 +01:00
Add support for Device.RouterAdvertisement.InterfaceSetting.{i}.Option.{i}. object
This commit is contained in:
parent
9efd1e0582
commit
0650586286
2 changed files with 257 additions and 2 deletions
|
|
@ -11,6 +11,12 @@
|
|||
#include "dhcpv4.h"
|
||||
#include "routeradvertisement.h"
|
||||
|
||||
struct radv_option_args {
|
||||
struct uci_section *config_sect;
|
||||
struct uci_section *dmmap_sect;
|
||||
char *option_value;
|
||||
};
|
||||
|
||||
/*************************************************************
|
||||
* ENTRY METHOD
|
||||
**************************************************************/
|
||||
|
|
@ -39,6 +45,49 @@ static int browseRouterAdvertisementInterfaceSettingInst(struct dmctx *dmctx, DM
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int browseRouterAdvertisementInterfaceSettingOptionInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
|
||||
{
|
||||
struct uci_section *dhcp_s = (struct uci_section *)prev_data;
|
||||
struct uci_section *dhcp_dmmap_s = NULL;
|
||||
struct radv_option_args radv_option_args = {0};
|
||||
struct browse_args browse_args = {0};
|
||||
struct uci_list *dns_list = NULL;
|
||||
char *inst = NULL, *max_inst = NULL, *option_value = NULL;
|
||||
|
||||
dmuci_get_value_by_section_list(dhcp_s, "dns", &dns_list);
|
||||
|
||||
if (dns_list != NULL) {
|
||||
struct uci_element *e = NULL;
|
||||
|
||||
uci_foreach_element(dns_list, e) {
|
||||
if ((dhcp_dmmap_s = get_dup_section_in_dmmap_eq("dmmap_radv", "radv_option", section_name(dhcp_s), "option_value", e->name)) == NULL) {
|
||||
dmuci_add_section_bbfdm("dmmap_radv", "radv_option", &dhcp_dmmap_s);
|
||||
dmuci_set_value_by_section_bbfdm(dhcp_dmmap_s, "option_value", e->name);
|
||||
dmuci_set_value_by_section_bbfdm(dhcp_dmmap_s, "section_name", section_name(dhcp_s));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uci_path_foreach_option_eq(bbfdm, "dmmap_radv", "radv_option", "section_name", section_name(dhcp_s), dhcp_dmmap_s) {
|
||||
dmuci_get_value_by_section_string(dhcp_dmmap_s, "option_value", &option_value);
|
||||
|
||||
radv_option_args.config_sect = dhcp_s;
|
||||
radv_option_args.dmmap_sect = dhcp_dmmap_s;
|
||||
radv_option_args.option_value = option_value;
|
||||
|
||||
browse_args.option = "section_name";
|
||||
browse_args.value = section_name(dhcp_s);
|
||||
|
||||
inst = handle_update_instance(2, dmctx, &max_inst, update_instance_alias, 5,
|
||||
dhcp_dmmap_s, "radv_option_instance", "radv_option_alias",
|
||||
check_browse_section, (void *)&browse_args);
|
||||
|
||||
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&radv_option_args, inst) == DM_STOP)
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*************************************************************
|
||||
* ADD & DEL OBJ
|
||||
**************************************************************/
|
||||
|
|
@ -85,6 +134,47 @@ static int delObjRouterAdvertisementInterfaceSetting(char *refparam, struct dmct
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int addObjRouterAdvertisementInterfaceSettingOption(char *refparam, struct dmctx *ctx, void *data, char **instance)
|
||||
{
|
||||
struct uci_section *dmmap_sect = NULL;
|
||||
struct browse_args browse_args = {0};
|
||||
|
||||
char *inst_para = get_last_instance_lev2_bbfdm_dmmap_opt("dmmap_radv", "radv_option", "radv_option_instance", "section_name", section_name((struct uci_section *)data));
|
||||
|
||||
dmuci_add_section_bbfdm("dmmap_radv", "radv_option", &dmmap_sect);
|
||||
dmuci_set_value_by_section_bbfdm(dmmap_sect, "section_name", section_name((struct uci_section *)data));
|
||||
dmuci_set_value_by_section_bbfdm(dmmap_sect, "option_tag", "25");
|
||||
|
||||
browse_args.option = "section_name";
|
||||
browse_args.value = section_name((struct uci_section *)data);
|
||||
|
||||
*instance = update_instance(inst_para, 5, dmmap_sect, "radv_option_instance", NULL, check_browse_section, (void *)&browse_args);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int delObjRouterAdvertisementInterfaceSettingOption(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
|
||||
{
|
||||
struct uci_section *s = NULL, *stmp = NULL;
|
||||
char *dns_list = NULL;
|
||||
|
||||
switch (del_action) {
|
||||
case DEL_INST:
|
||||
dmuci_get_value_by_section_string(((struct radv_option_args *)data)->config_sect, "dns", &dns_list);
|
||||
if (elt_exits_in_str_list(dns_list, ((struct radv_option_args *)data)->option_value))
|
||||
dmuci_del_list_value_by_section(((struct radv_option_args *)data)->config_sect, "dns", ((struct radv_option_args *)data)->option_value);
|
||||
|
||||
dmuci_delete_by_section_unnamed_bbfdm(((struct radv_option_args *)data)->dmmap_sect, NULL, NULL);
|
||||
break;
|
||||
case DEL_ALL:
|
||||
dmuci_set_value_by_section((struct uci_section *)data, "dns", "");
|
||||
uci_path_foreach_sections_safe(bbfdm, "dmmap_radv", "radv_option", stmp, s) {
|
||||
dmuci_delete_by_section_unnamed_bbfdm(s, NULL, NULL);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*************************************************************
|
||||
* GET & SET PARAM
|
||||
**************************************************************/
|
||||
|
|
@ -504,13 +594,159 @@ static int set_RouterAdvertisementInterfaceSetting_AdvCurHopLimit(char *refparam
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int get_RouterAdvertisementInterfaceSetting_OptionNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
struct uci_list *dns_list = NULL;
|
||||
int length = 0;
|
||||
|
||||
dmuci_get_value_by_section_list((struct uci_section *)data, "dns", &dns_list);
|
||||
if (dns_list != NULL) {
|
||||
struct uci_element *e = NULL;
|
||||
|
||||
uci_foreach_element(dns_list, e) {
|
||||
length++;
|
||||
}
|
||||
}
|
||||
|
||||
dmasprintf(value, "%d", length);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int get_RouterAdvertisementInterfaceSettingOption_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
struct radv_option_args *radv_option_s = (struct radv_option_args *)data;
|
||||
char *dns_list = NULL;
|
||||
|
||||
dmuci_get_value_by_section_string(radv_option_s->config_sect, "dns", &dns_list);
|
||||
*value = (elt_exits_in_str_list(dns_list, radv_option_s->option_value)) ? "1" : "0";
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int set_RouterAdvertisementInterfaceSettingOption_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
|
||||
{
|
||||
struct radv_option_args *radv_option_s = (struct radv_option_args *)data;
|
||||
char *dns_list = NULL;
|
||||
bool b;
|
||||
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
if (dm_validate_boolean(value))
|
||||
return FAULT_9007;
|
||||
break;
|
||||
case VALUESET:
|
||||
string_to_bool(value, &b);
|
||||
dmuci_get_value_by_section_string(radv_option_s->config_sect, "dns", &dns_list);
|
||||
if (b) {
|
||||
if (!elt_exits_in_str_list(dns_list, radv_option_s->option_value))
|
||||
dmuci_add_list_value_by_section(radv_option_s->config_sect, "dns", radv_option_s->option_value);
|
||||
} else {
|
||||
if (elt_exits_in_str_list(dns_list, radv_option_s->option_value))
|
||||
dmuci_del_list_value_by_section(radv_option_s->config_sect, "dns", radv_option_s->option_value);
|
||||
}
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int get_RouterAdvertisementInterfaceSettingOption_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
dmuci_get_value_by_section_string(((struct radv_option_args *)data)->dmmap_sect, "radv_option_alias", value);
|
||||
if ((*value)[0] == '\0')
|
||||
dmasprintf(value, "cpe-%s", instance);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int set_RouterAdvertisementInterfaceSettingOption_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
|
||||
{
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
if (dm_validate_string(value, -1, 64, NULL, NULL))
|
||||
return FAULT_9007;
|
||||
break;
|
||||
case VALUESET:
|
||||
dmuci_set_value_by_section_bbfdm(((struct radv_option_args *)data)->dmmap_sect, "radv_option_alias", value);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int get_RouterAdvertisementInterfaceSettingOption_Tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
*value = "25";
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int set_RouterAdvertisementInterfaceSettingOption_Tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
|
||||
{
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
if (dm_validate_unsignedInt(value, RANGE_ARGS{{"0","65535"}}, 1))
|
||||
return FAULT_9007;
|
||||
break;
|
||||
case VALUESET:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int get_RouterAdvertisementInterfaceSettingOption_Value(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
const char *option_value = ((struct radv_option_args *)data)->option_value;
|
||||
char hex[65535] = {0};
|
||||
|
||||
if (option_value && *option_value)
|
||||
convert_string_to_hex(option_value, hex);
|
||||
|
||||
*value = (*hex) ? dmstrdup(hex) : "";
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int set_RouterAdvertisementInterfaceSettingOption_Value(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
|
||||
{
|
||||
struct radv_option_args *radv_option_s = (struct radv_option_args *)data;
|
||||
struct uci_list *dns_list = NULL;
|
||||
char res[256] = {0};
|
||||
bool option_enabled = false;
|
||||
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
if (dm_validate_hexBinary(value, RANGE_ARGS{{"0","65535"}}, 1))
|
||||
return FAULT_9007;
|
||||
break;
|
||||
case VALUESET:
|
||||
dmuci_get_value_by_section_list(radv_option_s->config_sect, "dns", &dns_list);
|
||||
|
||||
if (dns_list != NULL) {
|
||||
struct uci_element *e = NULL;
|
||||
|
||||
uci_foreach_element(dns_list, e) {
|
||||
if (strcmp(e->name, radv_option_s->option_value) == 0) {
|
||||
option_enabled = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
convert_hex_to_string(value, res);
|
||||
|
||||
if (option_enabled) {
|
||||
dmuci_del_list_value_by_section(radv_option_s->config_sect, "dns", radv_option_s->option_value);
|
||||
dmuci_add_list_value_by_section(radv_option_s->config_sect, "dns", res);
|
||||
}
|
||||
|
||||
dmuci_set_value_by_section_bbfdm(radv_option_s->dmmap_sect, "option_value", res);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**********************************************************************************************************************************
|
||||
* OBJ & PARAM DEFINITION
|
||||
***********************************************************************************************************************************/
|
||||
/* *** Device.RouterAdvertisement. *** */
|
||||
DMOBJ tRouterAdvertisementObj[] = {
|
||||
/* OBJ, permission, addobj, delobj, checkdep, browseinstobj, nextdynamicobj, dynamicleaf, nextobj, leaf, linker, bbfdm_type, uniqueKeys*/
|
||||
{"InterfaceSetting", &DMWRITE, addObjRouterAdvertisementInterfaceSetting, delObjRouterAdvertisementInterfaceSetting, NULL, browseRouterAdvertisementInterfaceSettingInst, NULL, NULL, NULL, tRouterAdvertisementInterfaceSettingParams, NULL, BBFDM_BOTH, LIST_KEY{"Alias", "Interface", NULL}},
|
||||
{"InterfaceSetting", &DMWRITE, addObjRouterAdvertisementInterfaceSetting, delObjRouterAdvertisementInterfaceSetting, NULL, browseRouterAdvertisementInterfaceSettingInst, NULL, NULL, tRouterAdvertisementInterfaceSettingObj, tRouterAdvertisementInterfaceSettingParams, NULL, BBFDM_BOTH, LIST_KEY{"Alias", "Interface", NULL}},
|
||||
{0}
|
||||
};
|
||||
|
||||
|
|
@ -522,6 +758,12 @@ DMLEAF tRouterAdvertisementParams[] = {
|
|||
};
|
||||
|
||||
/* *** Device.RouterAdvertisement.InterfaceSetting.{i}. *** */
|
||||
DMOBJ tRouterAdvertisementInterfaceSettingObj[] = {
|
||||
/* OBJ, permission, addobj, delobj, checkdep, browseinstobj, nextdynamicobj, dynamicleaf, nextobj, leaf, linker, bbfdm_type, uniqueKeys*/
|
||||
{"Option", &DMWRITE, addObjRouterAdvertisementInterfaceSettingOption, delObjRouterAdvertisementInterfaceSettingOption, NULL, browseRouterAdvertisementInterfaceSettingOptionInst, NULL, NULL, NULL, tRouterAdvertisementInterfaceSettingOptionParams, NULL, BBFDM_BOTH, LIST_KEY{"Alias", "Tag", NULL}},
|
||||
{0}
|
||||
};
|
||||
|
||||
DMLEAF tRouterAdvertisementInterfaceSettingParams[] = {
|
||||
/* PARAM, permission, type, getvalue, setvalue, bbfdm_type*/
|
||||
{"Enable", &DMWRITE, DMT_BOOL, get_RouterAdvertisementInterfaceSetting_Enable, set_RouterAdvertisementInterfaceSetting_Enable, BBFDM_BOTH},
|
||||
|
|
@ -542,6 +784,17 @@ DMLEAF tRouterAdvertisementInterfaceSettingParams[] = {
|
|||
{"AdvReachableTime", &DMWRITE, DMT_UNINT, get_RouterAdvertisementInterfaceSetting_AdvReachableTime, set_RouterAdvertisementInterfaceSetting_AdvReachableTime, BBFDM_BOTH},
|
||||
{"AdvRetransTimer", &DMWRITE, DMT_UNINT, get_RouterAdvertisementInterfaceSetting_AdvRetransTimer, set_RouterAdvertisementInterfaceSetting_AdvRetransTimer, BBFDM_BOTH},
|
||||
{"AdvCurHopLimit", &DMWRITE, DMT_UNINT, get_RouterAdvertisementInterfaceSetting_AdvCurHopLimit, set_RouterAdvertisementInterfaceSetting_AdvCurHopLimit, BBFDM_BOTH},
|
||||
//{"OptionNumberOfEntries", &DMREAD, DMT_UNINT, get_RouterAdvertisementInterfaceSetting_OptionNumberOfEntries, NULL, BBFDM_BOTH},
|
||||
{"OptionNumberOfEntries", &DMREAD, DMT_UNINT, get_RouterAdvertisementInterfaceSetting_OptionNumberOfEntries, NULL, BBFDM_BOTH},
|
||||
{0}
|
||||
};
|
||||
|
||||
/* *** Device.RouterAdvertisement.InterfaceSetting.{i}.Option.{i}. *** */
|
||||
DMLEAF tRouterAdvertisementInterfaceSettingOptionParams[] = {
|
||||
/* PARAM, permission, type, getvalue, setvalue, bbfdm_type*/
|
||||
{"Enable", &DMWRITE, DMT_BOOL, get_RouterAdvertisementInterfaceSettingOption_Enable, set_RouterAdvertisementInterfaceSettingOption_Enable, BBFDM_BOTH},
|
||||
{"Alias", &DMWRITE, DMT_STRING, get_RouterAdvertisementInterfaceSettingOption_Alias, set_RouterAdvertisementInterfaceSettingOption_Alias, BBFDM_BOTH},
|
||||
{"Tag", &DMWRITE, DMT_UNINT, get_RouterAdvertisementInterfaceSettingOption_Tag, set_RouterAdvertisementInterfaceSettingOption_Tag, BBFDM_BOTH},
|
||||
{"Value", &DMWRITE, DMT_HEXBIN, get_RouterAdvertisementInterfaceSettingOption_Value, set_RouterAdvertisementInterfaceSettingOption_Value, BBFDM_BOTH},
|
||||
{0}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,9 @@
|
|||
|
||||
extern DMOBJ tRouterAdvertisementObj[];
|
||||
extern DMLEAF tRouterAdvertisementParams[];
|
||||
extern DMOBJ tRouterAdvertisementInterfaceSettingObj[];
|
||||
extern DMLEAF tRouterAdvertisementInterfaceSettingParams[];
|
||||
extern DMLEAF tRouterAdvertisementInterfaceSettingOptionParams[];
|
||||
|
||||
#endif //__ROUTERADVERTISEMENT_H
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue