Ticket refs #5773: improve and simplify handle instance in browser and add functions

This commit is contained in:
Amin Ben Ramdhane 2021-09-09 16:56:02 +00:00
parent 0e101a4c48
commit 42bc8e95a7
70 changed files with 3316 additions and 4883 deletions

View file

@ -201,6 +201,27 @@ Each leaf in the **DMLEAF** table can be a **Parameter**, **Command** or **Event
| `bbfdm_type` | The bbfdm type of the event. It should be **BBFDM_USP** as long as events are only defined in USP protocol. |
### Browse definition
The browse function allow to go over all instances of the current object and link them to the data model tree.
In this function, there are two functions that need to be defined:
- function to retrieve the instances: it can be
* `handle_instance` function: allow to retrieve/attribute the instances number/alias from uci config sections depending of the request and the instance mode.
* `handle_instance_without_section` function: allow to attribute the instances number/alias with constant values.
- function to link the instances: we need to call `DM_LINK_INST_OBJ()` function for each instance in order to link the instance to the data model tree. we also need to specify the `data`of this instance level. This `data` could be use later in the sub object and parameters functions (Get/Set/Add/Delete/Operate/Event).
> Note1: the browse function is only developed for multi-instances objects.
> Note2: you can read the next section `BBF API` below to find the definition of the functions used in the browse.
> Note3: you can use [bbf_test plugin](./test/bbf_test/bbf_test.c) as a reference in order to develop any new object/leaf/browse.
## BBF API
`libbbf_api` is a library which contains the source code of all API functions (UCI, Ubus, JSON, CLI and memory management). these API are used for GET/SET/ADD/Delete/Operate calls which can be called in internal or external packages.
@ -264,6 +285,42 @@ int dmubus_call_set(char *obj, char *method, struct ubus_arg u_args[], int u_arg
- **u_args: ubus** arguments
- **u_args_size:** number of ubus arguments
#### 6. handle_instance: allow to retrieve/attribute the instances from uci config sections
```bash
char *handle_instance(struct dmctx *dmctx, DMNODE *parent_node, struct uci_section *s, char *inst_opt, char *alias_opt);
```
**Argument:**
- **dmctx:** the current dmctx struct passed when calling this object
- **parent_node:** the current node struct passed when calling this object
- **s:** the uci section used to get the instance
- **inst_opt:** the option name of the instance number used for this object
- **alias_opt:** the option name of the instance alias used for this object
#### 7. handle_instance_without_section: allow to attribute instances with constant values
```bash
char *handle_instance_without_section(struct dmctx *dmctx, DMNODE *parent_node, int inst_nbr);
```
**Argument:** the current dmctx struct passed when calling this object
- **dmctx:** the current dmctx struct passed when calling this object
- **parent_node:** the current node struct passed when calling this object
- **inst_nbr:** the instance to attribute for this object
#### 8. DM_LINK_INST_OBJ: link the instance to the data model tree
```bash
int DM_LINK_INST_OBJ(struct dmctx *dmctx, DMNODE *parent_node, void *data, char *instance)
```
**Argument:**
- **dmctx:** the current dmctx struct passed when calling this object
- **parent_node:** the current node struct passed when calling this object
- **data:** the data transmitted for the next sub object and parameters that can be uci section, json object, or any type of data
- **instance:** the current instance used for this object
> Note1: For other funtions, please refer to dmuci, dmubus, dmjson, dmcommon and dmmem (.c and .h) files in the [link](https://dev.iopsys.eu/iopsys/bbf/-/tree/devel/libbbf_api)
@ -281,6 +338,25 @@ dmastrcat(s, b, m)
dmfree(x)
```
> Note3: There are several APIs that have been deprecated and replaced with new ones. the table below summarizes them
| Deprecated API | New API |
| -------------------------------------- | -------------------------------------------------- |
| handle_update_instance | handle_instance or handle_instance_without_section |
| update_instance_alias | handle_instance |
| update_instance_without_section | handle_instance_without_section |
| update_instance | Not Used |
| get_last_instance_bbfdm | Not Used |
| get_last_instance | find_max_instance |
| get_last_instance_lev2_bbfdm_dmmap_opt | Not Used |
| get_last_instance_lev2_bbfdm | Not Used |
| is_section_unnamed | Not Used |
| delete_sections_save_next_sections | Not Used |
| update_dmmap_sections | Not Used |
| check_browse_section | Not Used |
| dmuci_delete_by_section_unnamed | dmuci_delete_by_section |
| dmuci_delete_by_section_unnamed_bbfdm | dmuci_delete_by_section |
## BBFDM Vendor
`bbfdm` library can be used to **Extend** the Data Model with new objects/parameters, to **Overwrite** existing objects/parameters with new ones and **Exclude** some objects/parameters from Data Model tree.
@ -607,6 +683,10 @@ The application should bring its JSON file under **'/etc/bbfdm/json/'** path wit
> Note2: JSON File is not allowed to overwrite objects/parameters
> Note3: Set, Add, Delete methods are only allowed for uci mapping. therefore for ubus mapping, only Get method is authorized
> Note4: Each object definition in JSON file must begin with "Device." and should have the full parent path if it is under another object
- For more examples on JSON files, you can see these links: [X_IOPSYS_EU_MCPD](https://dev.iopsys.eu/feed/broadcom/-/blob/devel/mcpd/files/etc/bbfdm/json/X_IOPSYS_EU_MCPD.json), [UserInterface](/test/files/etc/bbfdm/json/UserInterface.json), [X_IOPSYS_EU_Dropbear](/test/files/etc/bbfdm/json/X_IOPSYS_EU_Dropbear.json)
## BBFDM Tools

View file

@ -46,11 +46,6 @@ void bbf_uci_revert_bbfdm(void)
dmuci_exit_bbfdm();
}
void del_list_parameter(struct dm_parameter *dm_parameter)
{
api_del_list_parameter(dm_parameter);
}
void del_list_fault_param(struct param_fault *param_fault)
{
bbf_api_del_list_fault_param(param_fault);

View file

@ -19,7 +19,6 @@ void bbf_uci_commit_bbfdm(void);
void bbf_uci_revert_bbfdm(void);
int set_bbfdatamodel_type(int bbf_type);
int get_bbfdatamodel_type(void);
void del_list_parameter(struct dm_parameter *dm_parameter);
void del_list_fault_param(struct param_fault *param_fault);
void bbf_set_end_session_flag (struct dmctx *ctx, unsigned int flag);

View file

@ -177,7 +177,7 @@ static int browse_obj(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data,
//UCI: arg1=type :: arg2=uci_file :: arg3=uci_section_type :: arg4=uci_dmmap_file :: arg5="" :: arg6=""
char buf_instance[64], buf_alias[64], *prefix_obj = NULL, *object = NULL;
char *inst = NULL, *max_inst = NULL;
char *inst = NULL;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
@ -194,8 +194,7 @@ static int browse_obj(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data,
synchronize_specific_config_sections_with_dmmap(arg2, arg3, arg4, &dup_list);
list_for_each_entry(p, &dup_list, list) {
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
p->dmmap_section, buf_instance, buf_alias);
inst = handle_instance(dmctx, parent_node, p->dmmap_section, buf_instance, buf_alias);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, inst) == DM_STOP)
break;
@ -207,7 +206,6 @@ static int browse_obj(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data,
//UBUS: arg1=type :: arg2=ubus_object :: arg3=ubus_method :: arg4=ubus_args1 :: arg5=ubus_args2 :: arg6=ubus_key
json_object *res = NULL, *dyn_obj = NULL, *arrobj = NULL;
char *max_inst = NULL;
if (arg2 && arg3 && arg4 && arg5)
dmubus_call(arg2, arg3, UBUS_ARGS{{arg4, arg5, String}}, 1, &res);
@ -217,7 +215,7 @@ static int browse_obj(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data,
int id = 0, j = 0;
dmjson_foreach_obj_in_array(res, arrobj, dyn_obj, j, 1, arg6) {
char *inst = handle_update_instance(1, dmctx, &max_inst, update_instance_without_section, 1, ++id);
char *inst = handle_instance_without_section(dmctx, parent_node, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)dyn_obj, inst) == DM_STOP)
break;
}
@ -256,12 +254,11 @@ static int add_obj(char *refparam, struct dmctx *ctx, void *data, char **instanc
if(arg2 && arg3 && arg4) {
struct uci_section *section = NULL, *dmmap = NULL;
char *inst = get_last_instance_bbfdm(arg4, arg3, buf_instance);
dmuci_add_section(arg2, arg3, &section);
dmuci_add_section_bbfdm(arg4, arg3, &dmmap);
dmuci_set_value_by_section(dmmap, "section_name", section_name(section));
*instance = update_instance(inst, 2, dmmap, buf_instance);
dmuci_set_value_by_section(dmmap, buf_instance, *instance);
}
}
return 0;
@ -287,32 +284,21 @@ static int delete_obj(char *refparam, struct dmctx *ctx, void *data, char *insta
if (arg1 && strcmp(arg1, "uci") == 0) {
if(arg2 && arg3 && arg4) {
struct uci_section *s = NULL, *ss = NULL, *dmmap_section= NULL;
int found = 0;
struct uci_section *s = NULL, *stmp = NULL, *dmmap_section= NULL;
switch (del_action) {
case DEL_INST:
get_dmmap_section_of_config_section(arg4, arg3, section_name((struct uci_section *)data), &dmmap_section);
if (dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section((struct uci_section *)data, NULL, NULL);
break;
case DEL_ALL:
uci_foreach_sections(arg2, arg3, s) {
if (found != 0) {
get_dmmap_section_of_config_section(arg4, arg3, section_name(ss), &dmmap_section);
if (dmmap_section != NULL)
uci_foreach_sections_safe(arg2, arg3, stmp, s) {
get_dmmap_section_of_config_section(arg4, arg3, section_name(s), &dmmap_section);
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
ss = s;
found++;
}
if (ss != NULL) {
get_dmmap_section_of_config_section(arg4, arg3, section_name(ss), &dmmap_section);
if(dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
dmuci_delete_by_section(s, NULL, NULL);
}
break;
}

View file

@ -16,51 +16,40 @@
**************************************************************/
int browseVoiceServiceSIPProviderInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *inst_last = NULL;
char *inst = NULL;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("asterisk", "sip_service_provider", "dmmap_asterisk", &dup_list);
list_for_each_entry(p, &dup_list, list) {
inst = handle_update_instance(2, dmctx, &inst_last, update_instance_alias, 3,
p->dmmap_section, "clientinstance", "clientalias");
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "clientinstance", "clientalias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, inst) == DM_STOP)
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p, inst) == DM_STOP)
break;
}
free_dmmap_config_dup_list(&dup_list);
return 0;
}
int delObjVoiceServiceSIPProvider(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
struct uci_section *s = NULL, *ss = NULL, *dmmap_section = NULL;
int found = 0;
struct uci_section *s = NULL, *stmp = NULL;
switch (del_action) {
case DEL_INST:
get_dmmap_section_of_config_section("dmmap_asterisk", "sip_service_provider", section_name((struct uci_section *)data), &dmmap_section);
if (dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section((struct uci_section *)data, NULL, NULL);
dmuci_delete_by_section(((struct dmmap_dup *)data)->config_section, NULL, NULL);
dmuci_delete_by_section(((struct dmmap_dup *)data)->dmmap_section, NULL, NULL);
break;
case DEL_ALL:
uci_foreach_sections("asterisk", "sip_service_provider", s) {
if (found != 0) {
get_dmmap_section_of_config_section("dmmap_asterisk", "sip_service_provider", section_name(ss), &dmmap_section);
if (dmmap_section != NULL)
uci_foreach_sections_safe("asterisk", "sip_service_provider", stmp, s) {
struct uci_section *dmmap_section = NULL;
get_dmmap_section_of_config_section("dmmap_asterisk", "sip_service_provider", section_name(s), &dmmap_section);
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
ss = s;
found++;
}
if (ss != NULL) {
get_dmmap_section_of_config_section("dmmap_asterisk", "sip_service_provider", section_name(ss), &dmmap_section);
if (dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
dmuci_delete_by_section(s, NULL, NULL);
}
break;
}
@ -73,7 +62,7 @@ int delObjVoiceServiceSIPProvider(char *refparam, struct dmctx *ctx, void *data,
static int browseServicesVoiceServiceCallLogInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct call_log_entry *entry = NULL;
char inst[16];
char *inst = NULL;
int i = 0;
init_call_log();
@ -82,7 +71,9 @@ static int browseServicesVoiceServiceCallLogInst(struct dmctx *dmctx, DMNODE *pa
list_for_each_entry(entry, &call_log_list, list) {
i++;
snprintf(inst, sizeof(inst), "%d", i);
inst = handle_instance_without_section(dmctx, parent_node, i);
if (DM_LINK_INST_OBJ(dmctx, parent_node, entry, inst) == DM_STOP)
break;
@ -102,7 +93,7 @@ static int browseServicesVoiceServiceVoIPProfileInst(struct dmctx *dmctx, DMNODE
/*#Device.Services.VoiceService.{i}.CodecProfile.{i}.!UCI:asterisk/codec_profile/dmmap_asterisk*/
static int browseServicesVoiceServiceCodecProfileInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *inst_last = NULL;
char *inst = NULL;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
int i, j;
@ -146,16 +137,24 @@ static int browseServicesVoiceServiceCodecProfileInst(struct dmctx *dmctx, DMNOD
synchronize_specific_config_sections_with_dmmap("asterisk", "codec_profile", "dmmap_asterisk", &dup_list);
list_for_each_entry(p, &dup_list, list) {
inst = handle_update_instance(2, dmctx, &inst_last, update_instance_alias, 3,
p->dmmap_section, "codecprofileinstance", "codecprofilealias");
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "codecprofileinstance", "codecprofilealias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, inst) == DM_STOP)
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p, inst) == DM_STOP)
break;
}
free_dmmap_config_dup_list(&dup_list);
return 0;
}
static int browseVoiceServiceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct uci_section *s = is_dmmap_section_exist("dmmap_asterisk", "voice_service");
if (!s) dmuci_add_section_bbfdm("dmmap_asterisk", "voice_service", &s);
handle_instance(dmctx, parent_node, s, "vsinstance", "vsalias");
DM_LINK_INST_OBJ(dmctx, parent_node, s, "1");
return 0;
}
/*************************************************************
* ADD & DEL OBJ
**************************************************************/
@ -163,12 +162,11 @@ static int addObjServicesVoiceServiceVoIPProfile(char *refparam, struct dmctx *c
{
struct uci_section *dmmap = NULL, *s = NULL;
char *inst = get_last_instance_bbfdm("dmmap_asterisk", "sip_service_provider", "clientinstance");
dmuci_add_section("asterisk", "sip_service_provider", &s);
dmuci_add_section_bbfdm("dmmap_asterisk", "sip_service_provider", &dmmap);
dmuci_set_value_by_section(dmmap, "section_name", section_name(s));
*instance = update_instance(inst, 2, dmmap, "clientinstance");
dmuci_set_value_by_section(dmmap, "clientinstance", *instance);
return 0;
}
@ -181,67 +179,41 @@ static int addObjServicesVoiceServiceCodecProfile(char *refparam, struct dmctx *
{
struct uci_section *dmmap = NULL, *s = NULL;
char *inst = get_last_instance_bbfdm("dmmap_asterisk", "codec_profile", "codecprofileinstance");
dmuci_add_section("asterisk", "codec_profile", &s);
dmuci_add_section_bbfdm("dmmap_asterisk", "codec_profile", &dmmap);
dmuci_set_value_by_section(dmmap, "section_name", section_name(s));
*instance = update_instance(inst, 2, dmmap, "codecprofileinstance");
dmuci_set_value_by_section(dmmap, "codecprofileinstance", *instance);
return 0;
}
static int delObjServicesVoiceServiceCodecProfile(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
struct uci_section *s = NULL, *ss = NULL, *dmmap_section = NULL;
int found = 0;
struct uci_section *s = NULL, *stmp = NULL;
switch (del_action) {
case DEL_INST:
get_dmmap_section_of_config_section("dmmap_asterisk", "codec_profile", section_name((struct uci_section *)data), &dmmap_section);
if (dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section((struct uci_section *)data, NULL, NULL);
dmuci_delete_by_section(((struct dmmap_dup *)data)->config_section, NULL, NULL);
dmuci_delete_by_section(((struct dmmap_dup *)data)->dmmap_section, NULL, NULL);
break;
case DEL_ALL:
uci_foreach_sections("asterisk", "codec_profile", s) {
if (found != 0) {
get_dmmap_section_of_config_section("dmmap_asterisk", "codec_profile", section_name(ss), &dmmap_section);
if (dmmap_section != NULL)
uci_foreach_sections_safe("asterisk", "codec_profile", stmp, s) {
struct uci_section *dmmap_section = NULL;
get_dmmap_section_of_config_section("dmmap_asterisk", "codec_profile", section_name(s), &dmmap_section);
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
ss = s;
found++;
}
if (ss != NULL) {
get_dmmap_section_of_config_section("dmmap_asterisk", "codec_profile", section_name(ss), &dmmap_section);
if (dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
dmuci_delete_by_section(s, NULL, NULL);
}
break;
}
return 0;
}
static int browseVoiceServiceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct uci_section *s = NULL;
char *vs = NULL, *vs_last = NULL;
update_section_list(DMMAP,"voice_service", NULL, 1, NULL, NULL, NULL, NULL, NULL);
uci_path_foreach_sections(bbfdm, "dmmap", "voice_service", s) {
vs = handle_update_instance(1, dmctx, &vs_last, update_instance_alias, 3,
s, "vsinstance", "vsalias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)s, vs) == DM_STOP)
break;
}
return 0;
}
int get_service_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
/*************************************************************
* GET & SET PARAM
**************************************************************/
static int get_service_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string((struct uci_section *)data, "vsalias", value);
if ((*value)[0] == '\0')

View file

@ -18,7 +18,7 @@
***************************************************************************/
static int get_voice_service_line_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker)
{
*linker = data ? section_name((struct uci_section *)data) : "";
*linker = data ? section_name(((struct dmmap_dup *)data)->config_section) : "";
return 0;
}
@ -28,17 +28,16 @@ static int get_voice_service_line_linker(char *refparam, struct dmctx *dmctx, vo
/*#Device.Services.VoiceService.{i}.CallControl.Line.{i}.!UCI:asterisk/tel_line/dmmap_asterisk*/
static int browseServicesVoiceServiceCallControlLineInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *inst_last = NULL;
char *inst = NULL;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("asterisk", "tel_line", "dmmap_asterisk", &dup_list);
list_for_each_entry(p, &dup_list, list) {
inst = handle_update_instance(2, dmctx, &inst_last, update_instance_alias, 3,
p->dmmap_section, "lineinstance", "linealias");
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "lineinstance", "linealias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, inst) == DM_STOP)
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p, inst) == DM_STOP)
break;
}
free_dmmap_config_dup_list(&dup_list);
@ -60,17 +59,16 @@ static int browseServicesVoiceServiceCallControlOutgoingMapInst(struct dmctx *dm
/*#Device.Services.VoiceService.{i}.CallControl.NumberingPlan.{i}.!UCI:asterisk/tel_advanced/dmmap_asterisk*/
static int browseServicesVoiceServiceCallControlNumberingPlanInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *max_inst = NULL;
char *inst = NULL;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("asterisk", "tel_advanced", "dmmap_asterisk", &dup_list);
list_for_each_entry(p, &dup_list, list) {
inst = handle_update_instance(2, dmctx, &max_inst, update_instance_alias, 3,
p->dmmap_section, "numberingplaninstance", "numberingplanalias");
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "numberingplaninstance", "numberingplanalias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, inst) == DM_STOP)
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p, inst) == DM_STOP)
break;
}
free_dmmap_config_dup_list(&dup_list);
@ -80,17 +78,16 @@ static int browseServicesVoiceServiceCallControlNumberingPlanInst(struct dmctx *
/*#Device.Services.VoiceService.{i}.CallControl.CallingFeatures.Set.{i}.!UCI:asterisk/advanced_features/dmmap_asterisk*/
static int browseServicesVoiceServiceCallControlCallingFeaturesSetInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *max_inst = NULL;
char *inst = NULL;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("asterisk", "advanced_features", "dmmap_asterisk", &dup_list);
list_for_each_entry(p, &dup_list, list) {
inst = handle_update_instance(2, dmctx, &max_inst, update_instance_alias, 3,
p->dmmap_section, "setinstance", "setalias");
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "setinstance", "setalias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, inst) == DM_STOP)
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p, inst) == DM_STOP)
break;
}
free_dmmap_config_dup_list(&dup_list);
@ -100,17 +97,16 @@ static int browseServicesVoiceServiceCallControlCallingFeaturesSetInst(struct dm
/*#Device.Services.VoiceService.{i}.CallControl.CallingFeatures.Set.{i}.SCREJ.{i}.!UCI:asterisk/call_filter_rule_incoming/dmmap_asterisk*/
static int browseServicesVoiceServiceCallControlCallingFeaturesSetSCREJInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *inst_last = NULL;
char *inst = NULL;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("asterisk", "call_filter_rule_incoming", "dmmap_asterisk", &dup_list);
list_for_each_entry(p, &dup_list, list) {
inst = handle_update_instance(3, dmctx, &inst_last, update_instance_alias, 3,
p->dmmap_section, "screjinstance", "screjalias");
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "screjinstance", "screjalias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, inst) == DM_STOP)
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p, inst) == DM_STOP)
break;
}
free_dmmap_config_dup_list(&dup_list);
@ -188,43 +184,31 @@ static int addObjServicesVoiceServiceCallControlCallingFeaturesSetSCREJ(char *re
{
struct uci_section *dmmap = NULL, *s = NULL;
char *inst = get_last_instance_bbfdm("dmmap_asterisk", "call_filter_rule_incoming", "screjinstance");
dmuci_add_section("asterisk", "call_filter_rule_incoming", &s);
dmuci_add_section_bbfdm("dmmap_asterisk", "call_filter_rule_incoming", &dmmap);
dmuci_set_value_by_section(dmmap, "section_name", section_name(s));
*instance = update_instance(inst, 2, dmmap, "screjinstance");
dmuci_set_value_by_section(dmmap, "screjinstance", *instance);
return 0;
}
static int delObjServicesVoiceServiceCallControlCallingFeaturesSetSCREJ(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
struct uci_section *s = NULL, *ss = NULL, *dmmap_section = NULL;
int found = 0;
struct uci_section *s = NULL, *stmp = NULL;
switch (del_action) {
case DEL_INST:
get_dmmap_section_of_config_section("dmmap_asterisk", "call_filter_rule_incoming", section_name((struct uci_section *)data), &dmmap_section);
if (dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section((struct uci_section *)data, NULL, NULL);
dmuci_delete_by_section(((struct dmmap_dup *)data)->config_section, NULL, NULL);
dmuci_delete_by_section(((struct dmmap_dup *)data)->dmmap_section, NULL, NULL);
break;
case DEL_ALL:
uci_foreach_sections("asterisk", "call_filter_rule_incoming", s) {
if (found != 0) {
get_dmmap_section_of_config_section("dmmap_asterisk", "call_filter_rule_incoming", section_name(ss), &dmmap_section);
if (dmmap_section != NULL)
uci_foreach_sections_safe("asterisk", "call_filter_rule_incoming", stmp, s) {
struct uci_section *dmmap_section = NULL;
get_dmmap_section_of_config_section("dmmap_asterisk", "call_filter_rule_incoming", section_name(s), &dmmap_section);
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
ss = s;
found++;
}
if (ss != NULL) {
get_dmmap_section_of_config_section("dmmap_asterisk", "call_filter_rule_incoming", section_name(ss), &dmmap_section);
if (dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
dmuci_delete_by_section(s, NULL, NULL);
}
break;
}
@ -268,7 +252,7 @@ static int get_ServicesVoiceServiceCallControlLine_DirectoryNumber(char *refpara
{
char *sip_account = NULL;
dmuci_get_value_by_section_string((struct uci_section *)data, "sip_account", &sip_account);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "sip_account", &sip_account);
dmuci_get_option_value_string("asterisk", sip_account, "directory_number", value);
return 0;
}
@ -283,7 +267,7 @@ static int set_ServicesVoiceServiceCallControlLine_DirectoryNumber(char *refpara
return FAULT_9007;
break;
case VALUESET:
dmuci_get_value_by_section_string((struct uci_section *)data, "sip_account", &sip_account);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "sip_account", &sip_account);
dmuci_set_value("asterisk", sip_account, "directory_number", value);
break;
}
@ -295,7 +279,7 @@ static int get_ServicesVoiceServiceCallControlLine_Provider(char *refparam, stru
{
char *linker = NULL;
dmuci_get_value_by_section_string((struct uci_section *)data, "sip_account", &linker);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "sip_account", &linker);
adm_entry_get_linker_param(ctx, "Device.Services.VoiceService.", linker, value);
if (*value == NULL)
*value = "";
@ -318,7 +302,7 @@ static int set_ServicesVoiceServiceCallControlLine_Provider(char *refparam, stru
char *linker = NULL;
adm_entry_get_linker_value(ctx, value, &linker);
if (linker && *linker) {
dmuci_set_value_by_section((struct uci_section *)data, "sip_account", linker);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "sip_account", linker);
dmfree(linker);
}
}
@ -330,7 +314,7 @@ static int set_ServicesVoiceServiceCallControlLine_Provider(char *refparam, stru
/*#Device.Services.VoiceService.{i}.CallControl.Line.{i}.Enable!UCI:asterisk/tel_line,@i-1/enabled*/
static int get_ServicesVoiceServiceCallControlLine_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "enabled", "1");
*value = dmuci_get_value_by_section_fallback_def(((struct dmmap_dup *)data)->config_section, "enabled", "1");
return 0;
}
@ -345,7 +329,7 @@ static int set_ServicesVoiceServiceCallControlLine_Enable(char *refparam, struct
break;
case VALUESET:
string_to_bool(value, &b);
dmuci_set_value_by_section((struct uci_section *)data, "enabled", b ? "1" : "0");
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "enabled", b ? "1" : "0");
break;
}
return 0;
@ -356,7 +340,7 @@ static int get_ServicesVoiceServiceCallControlIncomingMap_Line(char *refparam, s
{
char *tmp = NULL;
dmuci_get_value_by_section_string((struct uci_section *)data, "call_lines", &tmp);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "call_lines", &tmp);
if (tmp && *tmp) {
char *token = NULL, *saveptr = NULL, *p, buf[512] = { 0, 0 }, linker[16] = {0};
@ -414,7 +398,7 @@ static int set_ServicesVoiceServiceCallControlIncomingMap_Line(char *refparam, s
dmstrappendend(p);
if (buf[0] != '\0')
dmuci_set_value_by_section((struct uci_section *)data, "call_lines", buf);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "call_lines", buf);
break;
}
return 0;
@ -423,7 +407,7 @@ static int set_ServicesVoiceServiceCallControlIncomingMap_Line(char *refparam, s
/*#Device.Services.VoiceService.{i}.CallControl.OutgoingMap.{i}.CLIPNoScreeningNumber!UCI:asterisk/sip_service_provider,@i-1/displayname*/
static int get_ServicesVoiceServiceCallControlOutgoingMap_CLIPNoScreeningNumber(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string((struct uci_section *)data, "displayname", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "displayname", value);
return 0;
}
@ -435,7 +419,7 @@ static int set_ServicesVoiceServiceCallControlOutgoingMap_CLIPNoScreeningNumber(
return FAULT_9007;
break;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "displayname", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "displayname", value);
break;
}
return 0;
@ -513,7 +497,7 @@ static int set_ServicesVoiceServiceCallControlCallingFeaturesSet_CallForwardUnco
/*#Device.Services.VoiceService.{i}.CallControl.CallingFeatures.Set.SCREJ.{i}.CallingNumber!UCI:asterisk/call_filter_rule_incoming,@i-1/extension*/
static int get_ServicesVoiceServiceCallControlCallingFeaturesSetSCREJ_CallingNumber(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string((struct uci_section *)data, "extension", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "extension", value);
return 0;
}
@ -526,9 +510,9 @@ static int set_ServicesVoiceServiceCallControlCallingFeaturesSetSCREJ_CallingNum
break;
case VALUESET:
dmuci_set_value(TR104_UCI_PACKAGE, "call_filter0", "block_incoming", "1");
dmuci_set_value_by_section((struct uci_section *)data, "owner", "call_filter0");
dmuci_set_value_by_section((struct uci_section *)data, "enabled", "1");
dmuci_set_value_by_section((struct uci_section *)data, "extension", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "owner", "call_filter0");
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "enabled", "1");
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "extension", value);
break;
}
return 0;
@ -608,4 +592,3 @@ DMLEAF tServicesVoiceServiceCallControlCallingFeaturesSetSCREJParams[] = {
{"CallingNumber", &DMWRITE, DMT_STRING, get_ServicesVoiceServiceCallControlCallingFeaturesSetSCREJ_CallingNumber, set_ServicesVoiceServiceCallControlCallingFeaturesSetSCREJ_CallingNumber, BBFDM_BOTH},
{0}
};

View file

@ -23,6 +23,5 @@ extern DMOBJ tServicesVoiceServiceCallControlCallingFeaturesSetObj[];
extern DMLEAF tServicesVoiceServiceCallControlCallingFeaturesSetParams[];
extern DMLEAF tServicesVoiceServiceCallControlCallingFeaturesSetSCREJParams[];
#endif //__SERVICESVOICESERVICECALLCONTROL_H

View file

@ -26,13 +26,13 @@ static int get_voice_service_capabilities_codec_linker(char *refparam, struct dm
static int browseServicesVoiceServiceCapabilitiesCodecInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
int i;
char inst[16];
char *inst = NULL;
if (codecs_num <= 0)
init_supported_codecs();
for (i = 0; i < codecs_num; i++) {
snprintf(inst, sizeof(inst), "%d", i + 1);
inst = handle_instance_without_section(dmctx, parent_node, i+1);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&supported_codecs[i], inst) == DM_STOP)
break;
}

View file

@ -20,6 +20,5 @@ extern DMLEAF tServicesVoiceServiceCapabilitiesSIPClientParams[];
extern DMLEAF tServicesVoiceServiceCapabilitiesPOTSParams[];
extern DMLEAF tServicesVoiceServiceCapabilitiesCodecParams[];
#endif //__SERVICESVOICESERVICECAPABILITIES_H

View file

@ -20,7 +20,7 @@ static int get_ServicesVoiceServiceCodecProfile_Codec(char *refparam, struct dmc
{
char *linker;
dmuci_get_value_by_section_string((struct uci_section *)data, "name", &linker);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "name", &linker);
adm_entry_get_linker_param(ctx, "Device.Services.VoiceService.", linker, value);
if (*value == NULL)
*value = "";
@ -30,7 +30,7 @@ static int get_ServicesVoiceServiceCodecProfile_Codec(char *refparam, struct dmc
/*#Device.Services.VoiceService.{i}.CodecProfile.{i}.PacketizationPeriod!UCI:asterisk/codec_profile,@i-1/ptime*/
static int get_ServicesVoiceServiceCodecProfile_PacketizationPeriod(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string((struct uci_section *)data, "ptime", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "ptime", value);
return 0;
}
@ -42,7 +42,7 @@ static int set_ServicesVoiceServiceCodecProfile_PacketizationPeriod(char *refpar
return FAULT_9007;
break;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "ptime", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "ptime", value);
break;
}
return 0;

View file

@ -15,6 +15,5 @@
extern DMLEAF tServicesVoiceServiceCodecProfileParams[];
#endif //__SERVICESVOICESERVICECODECPROFILE_H

View file

@ -17,14 +17,14 @@
static int browseServicesVoiceServiceDECTBaseInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
json_object *res = NULL, *obj = NULL, *arrobj = NULL;
char *inst = NULL, *max_inst = NULL;
char *inst = NULL;
int id = 0, i = 0;
dmubus_call("dect", "status", UBUS_ARGS{}, 0, &res);
if (res) {
dmjson_foreach_obj_in_array(res, arrobj, obj, i, 1, "base") {
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_without_section, 1, ++id);
inst = handle_instance_without_section(dmctx, parent_node, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)obj, inst) == DM_STOP)
break;
@ -37,14 +37,14 @@ static int browseServicesVoiceServiceDECTBaseInst(struct dmctx *dmctx, DMNODE *p
static int browseServicesVoiceServiceDECTPortableInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
json_object *res = NULL, *obj = NULL, *arrobj = NULL;
char *inst = NULL, *max_inst = NULL;
char *inst = NULL;
int id = 0, i = 0;
dmubus_call("dect", "status", UBUS_ARGS{}, 0, &res);
if (res) {
dmjson_foreach_obj_in_array(res, arrobj, obj, i, 1, "handsets") {
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_without_section, 1, ++id);
inst = handle_instance_without_section(dmctx, parent_node, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)obj, inst) == DM_STOP)
break;

View file

@ -17,7 +17,7 @@
/*#Device.Services.VoiceService.{i}.POTS.FXS.{i}.!UCI:asterisk/tel_line/dmmap_asterisk*/
static int browseServicesVoiceServicePOTSFXSInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *inst_last = NULL;
char *inst = NULL;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
@ -28,10 +28,9 @@ static int browseServicesVoiceServicePOTSFXSInst(struct dmctx *dmctx, DMNODE *pa
dmuci_get_value_by_section_string(p->config_section, "name", &line_name);
if (line_name && (*line_name == '\0' || strcasestr(line_name, "DECT") == NULL)) {
inst = handle_update_instance(2, dmctx, &inst_last, update_instance_alias, 3,
p->dmmap_section, "fxsinstance", "fxsalias");
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "fxsinstance", "fxsalias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, inst) == DM_STOP)
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p, inst) == DM_STOP)
break;
}
if (line_name && *line_name)
@ -74,7 +73,7 @@ static int get_ServicesVoiceServicePOTSFXS_Status(char *refparam, struct dmctx *
/*#Device.Services.VoiceService.{i}.POTS.FXS.{i}.Name!UCI:asterisk/tel_line,@i-1/name*/
static int get_ServicesVoiceServicePOTSFXS_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string((struct uci_section *)data, "name", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "name", value);
return 0;
}
@ -88,7 +87,7 @@ static int get_ServicesVoiceServicePOTSFXS_DialType(char *refparam, struct dmctx
static int get_ServicesVoiceServicePOTSFXS_ClipGeneration(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *clir;
dmuci_get_value_by_section_string((struct uci_section *)data, "clir", &clir);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "clir", &clir);
*value = *clir == '1' ? "0" : "1";
return 0;
}
@ -104,7 +103,7 @@ static int set_ServicesVoiceServicePOTSFXS_ClipGeneration(char *refparam, struct
break;
case VALUESET:
string_to_bool(value, &b);
dmuci_set_value_by_section((struct uci_section *)data, "clir", !b ? "1" : "0");
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "clir", !b ? "1" : "0");
break;
}
return 0;
@ -125,7 +124,7 @@ static int get_ServicesVoiceServicePOTSFXS_TerminalType(char *refparam, struct d
/*#Device.Services.VoiceService.{i}.POTS.FXS.{i}.VoiceProcessing.TransmitGain!UCI:asterisk/tel_line,@i-1/txgain*/
static int get_ServicesVoiceServicePOTSFXSVoiceProcessing_TransmitGain(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "txgain", "0");
*value = dmuci_get_value_by_section_fallback_def(((struct dmmap_dup *)data)->config_section, "txgain", "0");
return 0;
}
@ -137,7 +136,7 @@ static int set_ServicesVoiceServicePOTSFXSVoiceProcessing_TransmitGain(char *ref
return FAULT_9007;
break;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "txgain", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "txgain", value);
break;
}
return 0;
@ -146,7 +145,7 @@ static int set_ServicesVoiceServicePOTSFXSVoiceProcessing_TransmitGain(char *ref
/*#Device.Services.VoiceService.{i}.POTS.FXS.{i}.VoiceProcessing.ReceiveGain!UCI:asterisk/tel_line,@i-1/rxgain*/
static int get_ServicesVoiceServicePOTSFXSVoiceProcessing_ReceiveGain(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "rxgain", "0");
*value = dmuci_get_value_by_section_fallback_def(((struct dmmap_dup *)data)->config_section, "rxgain", "0");
return 0;
}
@ -158,7 +157,7 @@ static int set_ServicesVoiceServicePOTSFXSVoiceProcessing_ReceiveGain(char *refp
return FAULT_9007;
break;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "rxgain", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "rxgain", value);
break;
}
return 0;
@ -167,7 +166,7 @@ static int set_ServicesVoiceServicePOTSFXSVoiceProcessing_ReceiveGain(char *refp
/*#Device.Services.VoiceService.{i}.POTS.FXS.{i}.VoiceProcessing.EchoCancellationEnable!UCI:asterisk/tel_line,@i-1/echo_cancel*/
static int get_ServicesVoiceServicePOTSFXSVoiceProcessing_EchoCancellationEnable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "echo_cancel", "1");
*value = dmuci_get_value_by_section_fallback_def(((struct dmmap_dup *)data)->config_section, "echo_cancel", "1");
return 0;
}
@ -182,7 +181,7 @@ static int set_ServicesVoiceServicePOTSFXSVoiceProcessing_EchoCancellationEnable
break;
case VALUESET:
string_to_bool(value, &b);
dmuci_set_value_by_section((struct uci_section *)data, "echo_cancel", b ? "1" : "0");
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "echo_cancel", b ? "1" : "0");
break;
}
return 0;
@ -230,4 +229,3 @@ DMLEAF tServicesVoiceServicePOTSFXSVoiceProcessingParams[] = {
{"EchoCancellationEnable", &DMWRITE, DMT_BOOL, get_ServicesVoiceServicePOTSFXSVoiceProcessing_EchoCancellationEnable, set_ServicesVoiceServicePOTSFXSVoiceProcessing_EchoCancellationEnable, BBFDM_BOTH},
{0}
};

View file

@ -19,6 +19,5 @@ extern DMOBJ tServicesVoiceServicePOTSFXSObj[];
extern DMLEAF tServicesVoiceServicePOTSFXSParams[];
extern DMLEAF tServicesVoiceServicePOTSFXSVoiceProcessingParams[];
#endif //__SERVICESVOICESERVICEPOTS_H

View file

@ -15,6 +15,5 @@
extern DMLEAF tServicesVoiceServiceReservedPortsParams[];
#endif //__SERVICESVOICESERVICERESERVEDPORTS_H

View file

@ -18,7 +18,7 @@
***************************************************************************/
static int get_voice_service_sip_client_linker(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker)
{
*linker = data ? section_name((struct uci_section *)data) : "";
*linker = data ? section_name(((struct dmmap_dup *)data)->config_section) : "";
return 0;
}
@ -39,21 +39,19 @@ static int browseServicesVoiceServiceSIPClientContactInst(struct dmctx *dmctx, D
return 0;
}
/*#Device.Services.VoiceService.{i}.SIP.Network.{i}.!UCI:asterisk/sip_service_provider/dmmap_asterisk*/
static int browseServicesVoiceServiceSIPNetworkInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *inst_last = NULL;
char *inst = NULL;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("asterisk", "sip_service_provider", "dmmap_asterisk", &dup_list);
list_for_each_entry(p, &dup_list, list) {
inst = handle_update_instance(2, dmctx, &inst_last, update_instance_alias, 3,
p->dmmap_section, "networkinstance", "networkalias");
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "networkinstance", "networkalias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, inst) == DM_STOP)
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p, inst) == DM_STOP)
break;
}
free_dmmap_config_dup_list(&dup_list);
@ -76,12 +74,10 @@ static int addObjServicesVoiceServiceSIPClient(char *refparam, struct dmctx *ctx
char new_sec_name[16], value[32];
struct uci_section *dmmap = NULL;
char *inst = get_last_instance_bbfdm("dmmap_asterisk", "sip_service_provider", "clientinstance");
snprintf(new_sec_name, sizeof(new_sec_name), "sip%d", (inst) ? atoi(inst) : 0);
dmuci_set_value(TR104_UCI_PACKAGE, new_sec_name, "", "sip_service_provider");
snprintf(new_sec_name, sizeof(new_sec_name), "sip%s", *instance);
snprintf(value, sizeof(value), "account %s", *instance);
// Set default options
snprintf(value, sizeof(value), "account %d", (inst) ? atoi(inst) + 1 : 1);
dmuci_set_value(TR104_UCI_PACKAGE, new_sec_name, "", "sip_service_provider");
dmuci_set_value(TR104_UCI_PACKAGE, new_sec_name, "name", value);
dmuci_set_value(TR104_UCI_PACKAGE, new_sec_name, "enabled", "0");
dmuci_set_value(TR104_UCI_PACKAGE, new_sec_name, "codec0", "alaw");
@ -105,8 +101,7 @@ static int addObjServicesVoiceServiceSIPClient(char *refparam, struct dmctx *ctx
dmuci_add_section_bbfdm("dmmap_asterisk", "sip_service_provider", &dmmap);
dmuci_set_value_by_section(dmmap, "section_name", new_sec_name);
*instance = update_instance(inst, 2, dmmap, "clientinstance");
dmuci_set_value_by_section(dmmap, "clientinstance", *instance);
return 0;
}
@ -173,7 +168,7 @@ static int delObjServicesVoiceServiceSIPNetworkFQDNServer(char *refparam, struct
/*#Device.Services.VoiceService.{i}.SIP.Client.{i}.Enable!UCI:asterisk/sip_service_provider,@i-1/enabled*/
static int get_ServicesVoiceServiceSIPClient_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "enabled", "1");
*value = dmuci_get_value_by_section_fallback_def(((struct dmmap_dup *)data)->config_section, "enabled", "1");
return 0;
}
@ -188,7 +183,7 @@ static int set_ServicesVoiceServiceSIPClient_Enable(char *refparam, struct dmctx
break;
case VALUESET:
string_to_bool(value, &b);
dmuci_set_value_by_section((struct uci_section *)data, "enabled", b ? "1" : "0");
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "enabled", b ? "1" : "0");
break;
}
return 0;
@ -196,7 +191,7 @@ static int set_ServicesVoiceServiceSIPClient_Enable(char *refparam, struct dmctx
static int get_ServicesVoiceServiceSIPClient_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *section = (struct uci_section *)data;
struct uci_section *section = ((struct dmmap_dup *)data)->config_section;
char *enabled = NULL;
dmuci_get_value_by_section_string(section, "enabled", &enabled);
@ -249,7 +244,7 @@ static int get_ServicesVoiceServiceSIPClient_Origin(char *refparam, struct dmctx
/*#Device.Services.VoiceService.{i}.SIP.Client.{i}.AuthUserName!UCI:asterisk/sip_service_provider,@i-1/authuser*/
static int get_ServicesVoiceServiceSIPClient_AuthUserName(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string((struct uci_section *)data, "authuser", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "authuser", value);
return 0;
}
@ -261,7 +256,7 @@ static int set_ServicesVoiceServiceSIPClient_AuthUserName(char *refparam, struct
return FAULT_9007;
break;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "authuser", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "authuser", value);
break;
}
return 0;
@ -275,7 +270,7 @@ static int set_ServicesVoiceServiceSIPClient_AuthPassword(char *refparam, struct
return FAULT_9007;
break;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "secret", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "secret", value);
break;
}
return 0;
@ -287,11 +282,11 @@ static int get_ServicesVoiceServiceSIPClient_RegisterURI(char *refparam, struct
char *value_user = NULL;
char *value_address = NULL;
dmuci_get_value_by_section_string((struct uci_section *)data, "user", &value_user);
dmuci_get_value_by_section_string((struct uci_section *)data, "domain", &value_address);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "user", &value_user);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "domain", &value_address);
if (!(value_address && *value_address)) {
dmuci_get_value_by_section_string((struct uci_section *)data, "outbound_proxy", &value_address);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "outbound_proxy", &value_address);
}
dmasprintf(value, "%s@%s", value_user, value_address);
@ -315,8 +310,8 @@ static int set_ServicesVoiceServiceSIPClient_RegisterURI(char *refparam, struct
value_user = dmstrdup(value);
if (value_user) {
value_user[value_domain - value - 1] = '\0';
dmuci_set_value_by_section((struct uci_section *)data, "user", value_user);
dmuci_set_value_by_section((struct uci_section *)data, "domain", value_domain);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "user", value_user);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "domain", value_domain);
}
}
break;
@ -354,7 +349,7 @@ static int set_ServicesVoiceServiceSIPClientContact_Port(char *refparam, struct
/*#Device.Services.VoiceService.{i}.SIP.Client.{i}.Contact.ExpireTime!UCI:asterisk/sip_advanced,sip_options/defaultexpiry*/
static int get_ServicesVoiceServiceSIPClientContact_ExpireTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *section = (struct uci_section *)data;
struct uci_section *section = ((struct dmmap_dup *)data)->config_section;
json_object *res = NULL, *sip = NULL, *client = NULL;
*value = "0001-01-01T00:00:00Z";
@ -409,7 +404,7 @@ static int get_ServicesVoiceServiceSIPClientContact_ExpireTime(char *refparam, s
static int get_ServicesVoiceServiceSIPClientContact_UserAgent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *section = (struct uci_section *)data;
struct uci_section *section = ((struct dmmap_dup *)data)->config_section;
json_object *res = NULL, *sip = NULL, *client = NULL;
if (!section) {
@ -435,7 +430,7 @@ static int get_ServicesVoiceServiceSIPClientContact_UserAgent(char *refparam, st
/*#Device.Services.VoiceService.{i}.SIP.Network.{i}.Enable!UCI:asterisk/sip_service_provider,@i-1/enabled*/
static int get_ServicesVoiceServiceSIPNetwork_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "enabled", "1");
*value = dmuci_get_value_by_section_fallback_def(((struct dmmap_dup *)data)->config_section, "enabled", "1");
return 0;
}
@ -450,7 +445,7 @@ static int set_ServicesVoiceServiceSIPNetwork_Enable(char *refparam, struct dmct
break;
case VALUESET:
string_to_bool(value, &b);
dmuci_set_value_by_section((struct uci_section *)data, "enabled", b ? "1" : "0");
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "enabled", b ? "1" : "0");
break;
}
return 0;
@ -542,7 +537,7 @@ static int set_server_port(struct uci_section *section, char *option, char *valu
/*#Device.Services.VoiceService.{i}.SIP.Network.{i}.ProxyServer!UCI:asterisk/sip_service_provider,@i-1/host*/
static int get_ServicesVoiceServiceSIPNetwork_ProxyServer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string((struct uci_section *)data, "host", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "host", value);
return 0;
}
@ -554,7 +549,7 @@ static int set_ServicesVoiceServiceSIPNetwork_ProxyServer(char *refparam, struct
return FAULT_9007;
break;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "host", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "host", value);
break;
}
return 0;
@ -563,7 +558,7 @@ static int set_ServicesVoiceServiceSIPNetwork_ProxyServer(char *refparam, struct
/*#Device.Services.VoiceService.{i}.SIP.Network.{i}.ProxyServerPort!UCI:asterisk/sip_service_provider,@i-1/port*/
static int get_ServicesVoiceServiceSIPNetwork_ProxyServerPort(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "port", DEFAULT_SIP_PORT_STR);
*value = dmuci_get_value_by_section_fallback_def(((struct dmmap_dup *)data)->config_section, "port", DEFAULT_SIP_PORT_STR);
return 0;
}
@ -575,7 +570,7 @@ static int set_ServicesVoiceServiceSIPNetwork_ProxyServerPort(char *refparam, st
return FAULT_9007;
break;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "port", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "port", value);
break;
}
return 0;
@ -585,7 +580,7 @@ static int set_ServicesVoiceServiceSIPNetwork_ProxyServerPort(char *refparam, st
/*#Device.Services.VoiceService.{i}.SIP.Network.{i}.UserAgentTransport!UCI:asterisk/sip_service_provider,@i-1/transport*/
static int get_ServicesVoiceServiceSIPNetwork_Transport(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string((struct uci_section *)data, "transport", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "transport", value);
if (*value && **value) {
// Convert to uppercase
for (char *ch = *value; *ch != '\0'; ch++)
@ -606,7 +601,7 @@ static int set_ServicesVoiceServiceSIPNetwork_Transport(char *refparam, struct d
case VALUESET:
for (char *ch = value; *ch != '\0'; ch++)
*ch = tolower(*ch);
dmuci_set_value_by_section((struct uci_section *)data, "transport", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "transport", value);
break;
}
return 0;
@ -615,7 +610,7 @@ static int set_ServicesVoiceServiceSIPNetwork_Transport(char *refparam, struct d
/*#Device.Services.VoiceService.{i}.SIP.Network.{i}.RegistrarServer!UCI:asterisk/sip_service_provider,@i-1/host*/
static int get_ServicesVoiceServiceSIPNetwork_RegistrarServer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string((struct uci_section *)data, "host", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "host", value);
return 0;
}
@ -627,7 +622,7 @@ static int set_ServicesVoiceServiceSIPNetwork_RegistrarServer(char *refparam, st
return FAULT_9007;
break;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "host", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "host", value);
break;
}
return 0;
@ -636,7 +631,7 @@ static int set_ServicesVoiceServiceSIPNetwork_RegistrarServer(char *refparam, st
/*#Device.Services.VoiceService.{i}.SIP.Network.{i}.RegistrarServerPort!UCI:asterisk/sip_service_provider,@i-1/port*/
static int get_ServicesVoiceServiceSIPNetwork_RegistrarServerPort(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "port", DEFAULT_SIP_PORT_STR);
*value = dmuci_get_value_by_section_fallback_def(((struct dmmap_dup *)data)->config_section, "port", DEFAULT_SIP_PORT_STR);
return 0;
}
@ -648,7 +643,7 @@ static int set_ServicesVoiceServiceSIPNetwork_RegistrarServerPort(char *refparam
return FAULT_9007;
break;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "port", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "port", value);
break;
}
return 0;
@ -657,7 +652,7 @@ static int set_ServicesVoiceServiceSIPNetwork_RegistrarServerPort(char *refparam
/*#Device.Services.VoiceService.{i}.SIP.Network.{i}.RegistrarServerTransport!UCI:asterisk/sip_service_provider,@i-1/transport*/
static int get_ServicesVoiceServiceSIPNetwork_RegistrarServerTransport(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string((struct uci_section *)data, "transport", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "transport", value);
if (*value && **value) {
for (char *ch = *value; *ch != '\0'; ch++)
*ch = toupper(*ch);
@ -677,7 +672,7 @@ static int set_ServicesVoiceServiceSIPNetwork_RegistrarServerTransport(char *ref
case VALUESET:
for (char *ch = value; *ch != '\0'; ch++)
*ch = tolower(*ch);
dmuci_set_value_by_section((struct uci_section *)data, "transport", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "transport", value);
break;
}
return 0;
@ -686,7 +681,7 @@ static int set_ServicesVoiceServiceSIPNetwork_RegistrarServerTransport(char *ref
/*#Device.Services.VoiceService.{i}.SIP.Network.{i}.UserAgentDomain!UCI:asterisk/sip_service_provider,@i-1/domain*/
static int get_ServicesVoiceServiceSIPNetwork_UserAgentDomain(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string((struct uci_section *)data, "domain", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "domain", value);
return 0;
}
@ -698,7 +693,7 @@ static int set_ServicesVoiceServiceSIPNetwork_UserAgentDomain(char *refparam, st
return FAULT_9007;
break;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "domain", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "domain", value);
break;
}
return 0;
@ -707,7 +702,7 @@ static int set_ServicesVoiceServiceSIPNetwork_UserAgentDomain(char *refparam, st
/*#Device.Services.VoiceService.{i}.SIP.Network.{i}.OutboundProxy!UCI:asterisk/sip_service_provider,@i-1/outbound_proxy*/
static int get_ServicesVoiceServiceSIPNetwork_OutboundProxy(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string((struct uci_section *)data, "outbound_proxy", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "outbound_proxy", value);
return 0;
}
@ -719,7 +714,7 @@ static int set_ServicesVoiceServiceSIPNetwork_OutboundProxy(char *refparam, stru
return FAULT_9007;
break;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "outbound_proxy", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "outbound_proxy", value);
break;
}
return 0;
@ -728,7 +723,7 @@ static int set_ServicesVoiceServiceSIPNetwork_OutboundProxy(char *refparam, stru
/*#Device.Services.VoiceService.{i}.SIP.Network.{i}.OutboundProxyPort!UCI:asterisk/sip_service_provider,@i-1/outbound_proxy_port*/
static int get_ServicesVoiceServiceSIPNetwork_OutboundProxyPort(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "outbound_proxy_port", DEFAULT_SIP_PORT_STR);
*value = dmuci_get_value_by_section_fallback_def(((struct dmmap_dup *)data)->config_section, "outbound_proxy_port", DEFAULT_SIP_PORT_STR);
return 0;
}
@ -740,7 +735,7 @@ static int set_ServicesVoiceServiceSIPNetwork_OutboundProxyPort(char *refparam,
return FAULT_9007;
break;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "outbound_proxy_port", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "outbound_proxy_port", value);
break;
}
return 0;
@ -857,7 +852,7 @@ static int get_ServicesVoiceServiceSIPNetwork_CodecList(char *refparam, struct d
char *tmp = NULL;
*value = "";
dmuci_get_value_by_section_string((struct uci_section *)data, "codecs", &tmp);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "codecs", &tmp);
if (tmp && *tmp) {
char buf[256] = "";
char *token, *saveptr;
@ -906,7 +901,7 @@ static int set_ServicesVoiceServiceSIPNetwork_CodecList(char *refparam, struct d
case VALUESET:
if (value) {
// Empty the existing code list first
dmuci_set_value_by_section((struct uci_section *)data, "codecs", "");
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "codecs", "");
if (*value) {
codec_list = dmstrdup(value);
@ -914,7 +909,7 @@ static int set_ServicesVoiceServiceSIPNetwork_CodecList(char *refparam, struct d
token = strtok_r(NULL, ", ", &saveptr)) {
uci_name = (char *)get_codec_uci_name(token);
if (uci_name) {
dmuci_add_list_value_by_section((struct uci_section *)data, "codecs", uci_name);
dmuci_add_list_value_by_section(((struct dmmap_dup *)data)->config_section, "codecs", uci_name);
}
}
}
@ -961,7 +956,7 @@ static int get_ServicesVoiceServiceSIPNetworkFQDNServer_Origin(char *refparam, s
/*#Device.Services.VoiceService.{i}.SIP.Network.{i}.FQDNServer.Domain!UCI:asterisk/sip_service_provider,@i-1/domain*/
static int get_ServicesVoiceServiceSIPNetworkFQDNServer_Domain(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return get_server_address(data, "domain", value);
return get_server_address(((struct dmmap_dup *)data)->config_section, "domain", value);
}
static int set_ServicesVoiceServiceSIPNetworkFQDNServer_Domain(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
@ -972,7 +967,7 @@ static int set_ServicesVoiceServiceSIPNetworkFQDNServer_Domain(char *refparam, s
return FAULT_9007;
break;
case VALUESET:
set_server_address(data, "domain", value);
set_server_address(((struct dmmap_dup *)data)->config_section, "domain", value);
break;
}
return 0;
@ -981,7 +976,7 @@ static int set_ServicesVoiceServiceSIPNetworkFQDNServer_Domain(char *refparam, s
/*#Device.Services.VoiceService.{i}.SIP.Network.{i}.FQDNServer.Port!UCI:asterisk/sip_service_provider,@i-1/domain*/
static int get_ServicesVoiceServiceSIPNetworkFQDNServer_Port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return get_server_port(data, "domain", value);
return get_server_port(((struct dmmap_dup *)data)->config_section, "domain", value);
}
static int set_ServicesVoiceServiceSIPNetworkFQDNServer_Port(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
@ -992,7 +987,7 @@ static int set_ServicesVoiceServiceSIPNetworkFQDNServer_Port(char *refparam, str
return FAULT_9007;
break;
case VALUESET:
set_server_port(data, "domain", value);
set_server_port(((struct dmmap_dup *)data)->config_section, "domain", value);
break;
}
return 0;

View file

@ -21,6 +21,5 @@ extern DMOBJ tServicesVoiceServiceSIPNetworkObj[];
extern DMLEAF tServicesVoiceServiceSIPNetworkParams[];
extern DMLEAF tServicesVoiceServiceSIPNetworkFQDNServerParams[];
#endif //__SERVICESVOICESERVICESIP_H

View file

@ -216,7 +216,7 @@ static int set_ServicesVoiceServiceVoIPProfileRTPRTCP_TxRepeatInterval(char *ref
/*#Device.Services.VoiceService.{i}.VoIPProfile.{i}.RTP.SRTP.Enable!UCI:asterisk/sip_service_provider,@i-1/encryption*/
static int get_ServicesVoiceServiceVoIPProfileRTPSRTP_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "encryption", "1");
*value = dmuci_get_value_by_section_fallback_def(((struct dmmap_dup *)data)->config_section, "encryption", "1");
return 0;
}
@ -231,7 +231,7 @@ static int set_ServicesVoiceServiceVoIPProfileRTPSRTP_Enable(char *refparam, str
break;
case VALUESET:
string_to_bool(value, &b);
dmuci_set_value_by_section((struct uci_section *)data, "encryption", b ? "1" : "0");
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "encryption", b ? "1" : "0");
break;
}
return 0;

View file

@ -20,6 +20,5 @@ extern DMLEAF tServicesVoiceServiceVoIPProfileRTPParams[];
extern DMLEAF tServicesVoiceServiceVoIPProfileRTPRTCPParams[];
extern DMLEAF tServicesVoiceServiceVoIPProfileRTPSRTPParams[];
#endif //__SERVICESVOICESERVICEVOIPPROFILE_H

View file

@ -1577,13 +1577,10 @@ static int get_IPDiagnosticsServerSelectionDiagnostics_MaximumResponseTime(char
static int browseIPDiagnosticsTraceRouteRouteHopsInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct uci_section *s = NULL;
char *inst = NULL, *max_inst = NULL;
char *inst = NULL;
uci_path_foreach_sections(bbfdm, DMMAP_DIAGNOSTIGS, "RouteHops", s) {
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
s, "routehop_instance", "routehop_alias");
inst = handle_instance(dmctx, parent_node, s, "routehop_instance", "routehop_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)s, inst) == DM_STOP)
break;
}
@ -1593,13 +1590,10 @@ static int browseIPDiagnosticsTraceRouteRouteHopsInst(struct dmctx *dmctx, DMNOD
static int browseIPDiagnosticsDownloadDiagnosticsPerConnectionResultInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct uci_section *s = NULL;
char *inst = NULL, *max_inst = NULL;
char *inst = NULL;
uci_path_foreach_sections(bbfdm, DMMAP_DIAGNOSTIGS, "DownloadPerConnection", s) {
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
s, "perconnection_instance", "perconnection_alias");
inst = handle_instance(dmctx, parent_node, s, "perconnection_instance", "perconnection_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)s, inst) == DM_STOP)
break;
}
@ -1609,13 +1603,10 @@ static int browseIPDiagnosticsDownloadDiagnosticsPerConnectionResultInst(struct
static int browseIPDiagnosticsUploadDiagnosticsPerConnectionResultInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct uci_section *s = NULL;
char *inst = NULL, *max_inst = NULL;
char *inst = NULL;
uci_path_foreach_sections(bbfdm, DMMAP_DIAGNOSTIGS, "UploadPerConnection", s) {
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
s, "perconnection_instance", "perconnection_alias");
inst = handle_instance(dmctx, parent_node, s, "perconnection_instance", "perconnection_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)s, inst) == DM_STOP)
break;
}

View file

@ -14,7 +14,7 @@
struct atm_args
{
struct uci_section *atm_sec;
struct dmmap_dup *sections;
char *device;
};
@ -30,9 +30,9 @@ static int get_atm_linker(char *refparam, struct dmctx *dmctx, void *data, char
/**************************************************************************
* INIT
***************************************************************************/
static inline int init_atm_link(struct atm_args *args, struct uci_section *s, char *device)
static inline int init_atm_link(struct atm_args *args, struct dmmap_dup *s, char *device)
{
args->atm_sec = s;
args->sections = s;
args->device = device;
return 0;
}
@ -63,16 +63,106 @@ void remove_device_from_interface(struct uci_section *interface_s, char *device)
dmuci_set_value_by_section(interface_s, "device", new_device);
}
/**************************************************************************
* SET & GET DSL LINK PARAMETERS
***************************************************************************/
/*************************************************************
* ENTRY METHOD
*************************************************************/
/*#Device.ATM.Link.{i}.!UCI:dsl/atm-device/dmmap_dsl*/
static int browseAtmLinkInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *device;
struct atm_args curr_atm_args = {0};
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("dsl", "atm-device", "dmmap_dsl", &dup_list);
list_for_each_entry(p, &dup_list, list) {
dmuci_get_value_by_section_string(p->config_section, "device", &device);
init_atm_link(&curr_atm_args, p, device);
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "atmlinkinstance", "atmlinkalias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_atm_args, inst) == DM_STOP)
break;
}
free_dmmap_config_dup_list(&dup_list);
return 0;
}
/*************************************************************
* ADD & DEL OBJ
**************************************************************/
static int add_atm_link(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
struct uci_section *dmmap_atm = NULL;
char atm_device[16];
snprintf(atm_device, sizeof(atm_device), "atm%s", *instance);
dmuci_set_value("dsl", atm_device, "", "atm-device");
dmuci_set_value("dsl", atm_device, "name", "ATM");
dmuci_set_value("dsl", atm_device, "enabled", "0");
dmuci_set_value("dsl", atm_device, "vpi", "8");
dmuci_set_value("dsl", atm_device, "vci", "35");
dmuci_set_value("dsl", atm_device, "device", atm_device);
dmuci_add_section_bbfdm("dmmap_dsl", "atm-device", &dmmap_atm);
dmuci_set_value_by_section(dmmap_atm, "section_name", atm_device);
dmuci_set_value_by_section(dmmap_atm, "atmlinkinstance", *instance);
return 0;
}
static int delete_atm_link(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
struct uci_section *s = NULL, *stmp = NULL;
switch (del_action) {
case DEL_INST:
uci_foreach_option_cont("network", "interface", "device", ((struct atm_args *)data)->device, s) {
if (stmp != NULL && ((struct atm_args *)data)->device != NULL)
remove_device_from_interface(stmp, ((struct atm_args *)data)->device);
stmp = s;
}
if (stmp != NULL && ((struct atm_args *)data)->device != NULL)
remove_device_from_interface(stmp, ((struct atm_args *)data)->device);
dmuci_delete_by_section((((struct atm_args *)data)->sections)->dmmap_section, NULL, NULL);
dmuci_delete_by_section((((struct atm_args *)data)->sections)->config_section, NULL, NULL);
break;
case DEL_ALL:
uci_foreach_sections_safe("dsl", "atm-device", stmp, s) {
struct uci_section *ns = NULL, *nss = NULL, *dmmap_section = NULL;
char *device = NULL;
dmuci_get_value_by_section_string(s, "device", &device);
uci_foreach_option_cont("network", "interface", "device", device, ns) {
if (nss != NULL && device != NULL)
remove_device_from_interface(nss, device);
nss = ns;
}
if (nss != NULL && device != NULL)
remove_device_from_interface(nss, device);
get_dmmap_section_of_config_section("dmmap_dsl", "atm-device", section_name(s), &dmmap_section);
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(s, NULL, NULL);
}
break;
}
return 0;
}
/*************************************************************
* GET & SET PARAM
**************************************************************/
/*#Device.ATM.Link.{i}.DestinationAddress!UCI:dsl/atm-device,@i-1/vpi&UCI:dsl/atm-device,@i-1/vci*/
static int get_atm_destination_address(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *vpi, *vci;
dmuci_get_value_by_section_string(((struct atm_args *)data)->atm_sec, "vpi", &vpi);
dmuci_get_value_by_section_string(((struct atm_args *)data)->atm_sec, "vci", &vci);
dmuci_get_value_by_section_string((((struct atm_args *)data)->sections)->config_section, "vpi", &vpi);
dmuci_get_value_by_section_string((((struct atm_args *)data)->sections)->config_section, "vci", &vci);
dmasprintf(value, "%s/%s", vpi, vci); // MEM WILL BE FREED IN DMMEMCLEAN
return 0;
}
@ -91,8 +181,8 @@ static int set_atm_destination_address(char *refparam, struct dmctx *ctx, void *
if (vpi)
vci = strtok_r(NULL, "/", &spch);
if (vpi && vci) {
dmuci_set_value_by_section(((struct atm_args *)data)->atm_sec, "vpi", vpi);
dmuci_set_value_by_section(((struct atm_args *)data)->atm_sec, "vci", vci);
dmuci_set_value_by_section((((struct atm_args *)data)->sections)->config_section, "vpi", vpi);
dmuci_set_value_by_section((((struct atm_args *)data)->sections)->config_section, "vci", vci);
}
return 0;
}
@ -102,7 +192,7 @@ static int set_atm_destination_address(char *refparam, struct dmctx *ctx, void *
/*#Device.ATM.Link.{i}.Name!UCI:dsl/atm-device,@i-1/name*/
static int get_atm_link_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string(((struct atm_args *)data)->atm_sec, "name", value);
dmuci_get_value_by_section_string((((struct atm_args *)data)->sections)->config_section, "name", value);
return 0;
}
@ -111,7 +201,7 @@ static int get_atm_encapsulation(char *refparam, struct dmctx *ctx, void *data,
{
char *encapsulation;
dmuci_get_value_by_section_string(((struct atm_args *)data)->atm_sec, "encapsulation", &encapsulation);
dmuci_get_value_by_section_string((((struct atm_args *)data)->sections)->config_section, "encapsulation", &encapsulation);
*value = (strcmp(encapsulation, "vcmux") == 0) ? "VCMUX" : "LLC";
return 0;
@ -125,7 +215,7 @@ static int set_atm_encapsulation(char *refparam, struct dmctx *ctx, void *data,
return FAULT_9007;
return 0;
case VALUESET:
dmuci_set_value_by_section(((struct atm_args *)data)->atm_sec, "encapsulation", (strcmp(value, "LLC") == 0) ? "llc" : "vcmux");
dmuci_set_value_by_section((((struct atm_args *)data)->sections)->config_section, "encapsulation", (strcmp(value, "LLC") == 0) ? "llc" : "vcmux");
return 0;
}
return 0;
@ -136,7 +226,7 @@ static int get_atm_link_type(char *refparam, struct dmctx *ctx, void *data, char
{
char *link_type;
dmuci_get_value_by_section_string(((struct atm_args *)data)->atm_sec, "link_type", &link_type);
dmuci_get_value_by_section_string((((struct atm_args *)data)->sections)->config_section, "link_type", &link_type);
if (strcmp(link_type, "eoa") == 0)
*value = "EoA";
else if (strcmp(link_type, "ipoa") == 0)
@ -159,15 +249,15 @@ static int set_atm_link_type(char *refparam, struct dmctx *ctx, void *data, char
return 0;
case VALUESET:
if (strcmp(value, "EoA") == 0)
dmuci_set_value_by_section(((struct atm_args *)data)->atm_sec, "link_type", "eoa");
dmuci_set_value_by_section((((struct atm_args *)data)->sections)->config_section, "link_type", "eoa");
else if (strcmp(value, "IPoA") == 0)
dmuci_set_value_by_section(((struct atm_args *)data)->atm_sec, "link_type", "ipoa");
dmuci_set_value_by_section((((struct atm_args *)data)->sections)->config_section, "link_type", "ipoa");
else if (strcmp(value, "PPPoA") == 0)
dmuci_set_value_by_section(((struct atm_args *)data)->atm_sec, "link_type", "pppoa");
dmuci_set_value_by_section((((struct atm_args *)data)->sections)->config_section, "link_type", "pppoa");
else if (strcmp(value, "CIP") == 0)
dmuci_set_value_by_section(((struct atm_args *)data)->atm_sec, "link_type", "cip");
dmuci_set_value_by_section((((struct atm_args *)data)->sections)->config_section, "link_type", "cip");
else
dmuci_set_value_by_section(((struct atm_args *)data)->atm_sec, "link_type", "");
dmuci_set_value_by_section((((struct atm_args *)data)->sections)->config_section, "link_type", "");
return 0;
}
return 0;
@ -176,34 +266,31 @@ static int set_atm_link_type(char *refparam, struct dmctx *ctx, void *data, char
static int get_atm_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *linker = NULL;
struct uci_section *dmmap_section = NULL;
char atm_file[128];
get_dmmap_section_of_config_section("dmmap_dsl", "atm-device", section_name(((struct atm_args *)data)->atm_sec), &dmmap_section);
dmuci_get_value_by_section_string(dmmap_section, "atm_ll_link", &linker);
dmuci_get_value_by_section_string((((struct atm_args *)data)->sections)->dmmap_section, "atm_ll_link", &linker);
if (linker != NULL)
adm_entry_get_linker_param(ctx, "Device.DSL.Channel.", linker, value);
if (*value != NULL && (*value)[0] != '\0')
return 0;
char *atm_file = NULL;
dmasprintf(&atm_file, "/sys/class/net/atm%d", atoi(instance) - 1);
snprintf(atm_file, sizeof(atm_file), "/sys/class/net/atm%d", atoi(instance) - 1);
if (folder_exists(atm_file)) {
*value = "Device.DSL.Channel.1";
dmuci_set_value_by_section(dmmap_section, "atm_ll_link", "dsl_channel_1");
dmuci_set_value_by_section((((struct atm_args *)data)->sections)->dmmap_section, "atm_ll_link", "dsl_channel_1");
}
return 0;
}
static int set_atm_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *dmmap_section = NULL;
switch (action) {
case VALUECHECK:
if (strncmp(value, "Device.DSL.Channel.1", strlen("Device.DSL.Channel.1")) != 0)
return FAULT_9007;
break;
case VALUESET:
get_dmmap_section_of_config_section("dmmap_dsl", "atm-device", section_name(((struct atm_args *)data)->atm_sec), &dmmap_section);
dmuci_set_value_by_section(dmmap_section, "atm_ll_link", "dsl_channel_1");
dmuci_set_value_by_section((((struct atm_args *)data)->sections)->dmmap_section, "atm_ll_link", "dsl_channel_1");
break;
}
return 0;
@ -251,7 +338,7 @@ static int get_atm_stats_pack_sent(char *refparam, struct dmctx *ctx, void *data
/*#Device.ATM.Link.{i}.Enable!UCI:dsl/atm-device,@i-1/enabled*/
static int get_atm_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmuci_get_value_by_section_fallback_def(((struct atm_args *)data)->atm_sec, "enabled", "1");
*value = dmuci_get_value_by_section_fallback_def((((struct atm_args *)data)->sections)->config_section, "enabled", "1");
return 0;
}
@ -266,7 +353,7 @@ static int set_atm_enable(char *refparam, struct dmctx *ctx, void *data, char *i
return 0;
case VALUESET:
string_to_bool(value, &b);
dmuci_set_value_by_section(((struct atm_args *)data)->atm_sec, "enabled", b ? "1" : "0");
dmuci_set_value_by_section((((struct atm_args *)data)->sections)->config_section, "enabled", b ? "1" : "0");
return 0;
}
return 0;
@ -278,83 +365,10 @@ static int get_atm_status(char *refparam, struct dmctx *ctx, void *data, char *i
return get_net_device_status(((struct atm_args *)data)->device, value);
}
/*************************************************************
* ADD OBJ
*************************************************************/
static int add_atm_link(char *refparam, struct dmctx *ctx, void *data, char **instancepara)
{
struct uci_section *dmmap_atm = NULL;
char atm_device[16];
char *instance = get_last_instance_bbfdm("dmmap_dsl", "atm-device", "atmlinkinstance");
snprintf(atm_device, sizeof(atm_device), "atm%d", instance ? atoi(instance) : 0);
dmuci_set_value("dsl", atm_device, "", "atm-device");
dmuci_set_value("dsl", atm_device, "name", "ATM");
dmuci_set_value("dsl", atm_device, "enabled", "0");
dmuci_set_value("dsl", atm_device, "vpi", "8");
dmuci_set_value("dsl", atm_device, "vci", "35");
dmuci_set_value("dsl", atm_device, "device", atm_device);
dmuci_add_section_bbfdm("dmmap_dsl", "atm-device", &dmmap_atm);
dmuci_set_value_by_section(dmmap_atm, "section_name", atm_device);
*instancepara = update_instance(instance, 2, dmmap_atm, "atmlinkinstance");
return 0;
}
static int delete_atm_link(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
struct uci_section *s = NULL, *stmp = NULL, *dmmap_section = NULL;
switch (del_action) {
case DEL_INST:
uci_foreach_option_cont("network", "interface", "device", ((struct atm_args *)data)->device, s) {
if (stmp != NULL && ((struct atm_args *)data)->device != NULL)
remove_device_from_interface(stmp, ((struct atm_args *)data)->device);
stmp = s;
}
if (stmp != NULL && ((struct atm_args *)data)->device != NULL)
remove_device_from_interface(stmp, ((struct atm_args *)data)->device);
get_dmmap_section_of_config_section("dmmap_dsl", "atm-device", section_name(((struct atm_args *)data)->atm_sec), &dmmap_section);
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(((struct atm_args *)data)->atm_sec, NULL, NULL);
break;
case DEL_ALL:
uci_foreach_sections_safe("dsl", "atm-device", stmp, s) {
struct uci_section *ns = NULL, *nss = NULL;
char *device = NULL;
dmuci_get_value_by_section_string(s, "device", &device);
uci_foreach_option_cont("network", "interface", "device", device, ns) {
if (nss != NULL && device != NULL)
remove_device_from_interface(nss, device);
nss = ns;
}
if (nss != NULL && device != NULL)
remove_device_from_interface(nss, device);
get_dmmap_section_of_config_section("dmmap_dsl", "atm-device", section_name(s), &dmmap_section);
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(s, NULL, NULL);
}
break;
}
return 0;
}
/*************************************************************
* SET AND GET ALIAS
*************************************************************/
/*#Device.ATM.Link.{i}.Alias!UCI:dmmap_dsl/atm-device,@i-1/atmlinkalias*/
static int get_atm_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *dmmap_section = NULL;
get_dmmap_section_of_config_section("dmmap_dsl", "atm-device", section_name(((struct atm_args *)data)->atm_sec), &dmmap_section);
dmuci_get_value_by_section_string(dmmap_section, "atmlinkalias", value);
dmuci_get_value_by_section_string((((struct atm_args *)data)->sections)->dmmap_section, "atmlinkalias", value);
if ((*value)[0] == '\0')
dmasprintf(value, "cpe-%s", instance);
return 0;
@ -362,48 +376,21 @@ static int get_atm_alias(char *refparam, struct dmctx *ctx, void *data, char *in
static int set_atm_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *dmmap_section = NULL;
switch (action) {
case VALUECHECK:
if (dm_validate_string(value, -1, 64, NULL, NULL))
return FAULT_9007;
return 0;
case VALUESET:
get_dmmap_section_of_config_section("dmmap_dsl", "atm-device", section_name(((struct atm_args *)data)->atm_sec), &dmmap_section);
dmuci_set_value_by_section(dmmap_section, "atmlinkalias", value);
dmuci_set_value_by_section((((struct atm_args *)data)->sections)->dmmap_section, "atmlinkalias", value);
return 0;
}
return 0;
}
/*************************************************************
* ENTRY METHOD
*************************************************************/
/*#Device.ATM.Link.{i}.!UCI:dsl/atm-device/dmmap_dsl*/
static int browseAtmLinkInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *max_inst = NULL, *device;
struct atm_args curr_atm_args = {0};
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("dsl", "atm-device", "dmmap_dsl", &dup_list);
list_for_each_entry(p, &dup_list, list) {
dmuci_get_value_by_section_string(p->config_section, "device", &device);
init_atm_link(&curr_atm_args, p->config_section, device);
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
p->dmmap_section, "atmlinkinstance", "atmlinkalias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_atm_args, inst) == DM_STOP)
break;
}
free_dmmap_config_dup_list(&dup_list);
return 0;
}
/**********************************************************************************************************************************
* OBJ & LEAF DEFINITION
***********************************************************************************************************************************/
/*** ATM. ***/
DMOBJ tATMObj[] = {
/* OBJ, permission, addobj, delobj, checkdep, browseinstobj, nextdynamicobj, dynamicleaf, nextobj, leaf, linker, bbfdm_type, uniqueKeys*/

View file

@ -398,15 +398,31 @@ static bool is_bridge_section_exist(char *device)
return false;
}
static int get_last_instance_bridge(char *package, char *section, char *opt_inst)
{
struct uci_section *s;
int inst = 0;
uci_path_foreach_sections(bbfdm, package, section, s) {
char *opt_val = NULL;
dmuci_get_value_by_section_string(s, opt_inst, &opt_val);
if (opt_val && *opt_val != '\0' && atoi(opt_val) > inst)
inst = atoi(opt_val);
}
return inst;
}
static char *create_dmmap_bridge_section(char *port)
{
struct uci_section *dmmap_br_sec = NULL;
char bridge_name[64] = {0};
char *current_inst = NULL;
char *last_inst_dmmap = get_last_instance_bbfdm("dmmap_bridge", "device", "bridge_instance");
dmasprintf(&current_inst, "%d", last_inst_dmmap ? atoi(last_inst_dmmap)+1 : 1);
snprintf(bridge_name, sizeof(bridge_name), "bridge_%d", last_inst_dmmap ? atoi(last_inst_dmmap)+1 : 1);
int last_inst_dmmap = get_last_instance_bridge("dmmap_bridge", "device", "bridge_instance");
dmasprintf(&current_inst, "%d", (last_inst_dmmap == 0) ? 1 : last_inst_dmmap+1);
snprintf(bridge_name, sizeof(bridge_name), "bridge_%d", (last_inst_dmmap == 0) ? 1 : last_inst_dmmap+1);
dmuci_add_section_bbfdm("dmmap_bridge", "device", &dmmap_br_sec);
dmuci_set_value_by_section(dmmap_br_sec, "section_name", bridge_name);
@ -424,7 +440,6 @@ static void dmmap_synchronizeBridgingProviderBridge(struct dmctx *dmctx, DMNODE
struct uci_section *dmmap_pr_br_sec = NULL;
struct uci_list *ports_list = NULL;
struct uci_element *e = NULL;
char *last_inst_dmmap = NULL;
char current_inst[16] = {0};
if (strncmp(section_name(s), "pr_br_", 6) != 0)
@ -433,9 +448,9 @@ static void dmmap_synchronizeBridgingProviderBridge(struct dmctx *dmctx, DMNODE
if ((dmmap_pr_br_sec = get_dup_section_in_dmmap("dmmap_provider_bridge", "provider_bridge", section_name(s))) != NULL)
continue;
last_inst_dmmap = get_last_instance_bbfdm("dmmap_provider_bridge", "provider_bridge", "provider_bridge_instance");
int last_inst_dmmap = get_last_instance_bridge("dmmap_provider_bridge", "provider_bridge", "provider_bridge_instance");
dmuci_add_section_bbfdm("dmmap_provider_bridge", "provider_bridge", &dmmap_pr_br_sec);
snprintf(current_inst, sizeof(current_inst), "%d", last_inst_dmmap ? atoi(last_inst_dmmap)+1 : 1);
snprintf(current_inst, sizeof(current_inst), "%d", (last_inst_dmmap == 0) ? 1 : last_inst_dmmap+1);
dmuci_set_value_by_section(dmmap_pr_br_sec, "provider_bridge_instance", current_inst);
dmuci_set_value_by_section(dmmap_pr_br_sec, "section_name", section_name(s));
dmuci_set_value_by_section(dmmap_pr_br_sec, "enable", "1");
@ -1481,8 +1496,7 @@ static int addObjBridgingBridge(char *refparam, struct dmctx *ctx, void *data, c
struct uci_section *s = NULL, *dmmap_bridge = NULL;
char device_name[32];
char *last_inst = get_last_instance_bbfdm("dmmap_bridge", "device", "bridge_instance");
snprintf(device_name, sizeof(device_name), "br_%d", last_inst ? atoi(last_inst)+1 : 1);
snprintf(device_name, sizeof(device_name), "br_%s", *instance);
// Add device bridge section
dmuci_add_section("network", "device", &s);
@ -1493,7 +1507,7 @@ static int addObjBridgingBridge(char *refparam, struct dmctx *ctx, void *data, c
dmuci_add_section_bbfdm("dmmap_bridge", "device", &dmmap_bridge);
dmuci_set_value_by_section(dmmap_bridge, "section_name", section_name(s));
dmuci_set_value_by_section(dmmap_bridge, "added_by_user", "1");
*instance = update_instance(last_inst, 2, dmmap_bridge, "bridge_instance");
dmuci_set_value_by_section(dmmap_bridge, "bridge_instance", *instance);
return 0;
}
@ -1761,13 +1775,11 @@ static int addObjBridgingProviderBridge(char *refparam, struct dmctx *ctx, void
{
struct uci_section *pr_br_sec = NULL;
char *last_instance = get_last_instance_bbfdm("dmmap_provider_bridge", "provider_bridge", "provider_bridge_instance");
// Add dmmap section
dmuci_add_section_bbfdm("dmmap_provider_bridge", "provider_bridge", &pr_br_sec);
dmuci_set_value_by_section(pr_br_sec, "enable", "1");
dmuci_set_value_by_section(pr_br_sec, "type", "S-VLAN");
*instance = update_instance(last_instance, 2, pr_br_sec, "provider_bridge_instance");
dmuci_set_value_by_section(pr_br_sec, "provider_bridge_instance", *instance);
return 0;
}
@ -3098,15 +3110,13 @@ static int browseBridgingBridgeInst(struct dmctx *dmctx, DMNODE *parent_node, vo
struct bridge_args curr_bridging_args = {0};
struct dmmap_dup *p = NULL;
struct uci_list *ports_list = NULL;
char *inst = NULL, *max_inst = NULL;
char *sec_name = NULL;
char *inst = NULL, *sec_name = NULL;
LIST_HEAD(dup_list);
synchronize_bridge_config_sections_with_dmmap_bridge_eq("network", "device", "dmmap_bridge", "type", "bridge", &dup_list);
list_for_each_entry(p, &dup_list, list) {
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
p->dmmap_section, "bridge_instance", "bridge_alias");
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "bridge_instance", "bridge_alias");
dmuci_get_value_by_section_list(p->dmmap_section, "ports", &ports_list);
dmuci_get_value_by_section_string(p->dmmap_section, "section_name", &sec_name);
@ -3124,13 +3134,12 @@ static int browseBridgingProviderBridgeInst(struct dmctx *dmctx, DMNODE *parent_
{
struct provider_bridge_args curr_bridging_args = {0};
struct uci_section *s = NULL;
char *inst = NULL, *max_inst = NULL;
char *inst = NULL;
dmmap_synchronizeBridgingProviderBridge(dmctx, parent_node, prev_data, prev_instance);
uci_path_foreach_sections(bbfdm, "dmmap_provider_bridge", "provider_bridge", s) {
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
s, "provider_bridge_instance", "provider_bridge_alias");
inst = handle_instance(dmctx, parent_node, s, "provider_bridge_instance", "provider_bridge_alias");
init_provider_bridge_args(&curr_bridging_args, s, inst);
@ -3144,9 +3153,8 @@ static int browseBridgingBridgePortInst(struct dmctx *dmctx, DMNODE *parent_node
{
struct bridge_port_args curr_bridge_port_args = {0};
struct bridge_args *br_args = (struct bridge_args *)prev_data;
struct browse_args browse_args = {0};
struct uci_section *dmmap_s = NULL, *br_port_s = NULL;
char *inst = NULL, *max_inst = NULL, *port_device = NULL;
char *inst = NULL, *port_device = NULL;
dmmap_synchronizeBridgingBridgePort(dmctx, parent_node, prev_data, prev_instance);
uci_path_foreach_option_eq(bbfdm, "dmmap_bridge_port", "bridge_port", "br_inst", br_args->br_inst, dmmap_s) {
@ -3159,12 +3167,7 @@ static int browseBridgingBridgePortInst(struct dmctx *dmctx, DMNODE *parent_node
init_bridge_port_args(&curr_bridge_port_args, br_port_s, dmmap_s, br_args->bridge_sec, br_args->br_inst, port_device);
browse_args.option = "br_inst";
browse_args.value = br_args->br_inst;
inst = handle_update_instance(2, dmctx, &max_inst, update_instance_alias, 5,
dmmap_s, "bridge_port_instance", "bridge_port_alias",
check_browse_section, (void *)&browse_args);
inst = handle_instance(dmctx, parent_node, dmmap_s, "bridge_port_instance", "bridge_port_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_bridge_port_args, inst) == DM_STOP)
break;
@ -3176,21 +3179,15 @@ static int browseBridgingBridgeVLANInst(struct dmctx *dmctx, DMNODE *parent_node
{
struct bridge_vlan_args curr_bridge_vlan_args = {0};
struct bridge_args *br_args = (struct bridge_args *)prev_data;
struct browse_args browse_args = {0};
struct uci_section *s = NULL;
char *inst = NULL, *max_inst = NULL;
char *inst = NULL;
dmmap_synchronizeBridgingBridgeVLAN(dmctx, parent_node, prev_data, prev_instance);
uci_path_foreach_option_eq(bbfdm, "dmmap_bridge_vlan", "bridge_vlan", "br_inst", br_args->br_inst, s) {
init_bridge_vlan_args(&curr_bridge_vlan_args, s, br_args->bridge_sec, br_args->br_inst);
browse_args.option = "br_inst";
browse_args.value = br_args->br_inst;
inst = handle_update_instance(2, dmctx, &max_inst, update_instance_alias, 5,
s, "bridge_vlan_instance", "bridge_vlan_alias",
check_browse_section, (void *)&browse_args);
inst = handle_instance(dmctx, parent_node, s, "bridge_vlan_instance", "bridge_vlan_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_bridge_vlan_args, inst) == DM_STOP)
break;
@ -3202,9 +3199,8 @@ static int browseBridgingBridgeVLANPortInst(struct dmctx *dmctx, DMNODE *parent_
{
struct bridge_vlanport_args curr_bridge_vlanport_args = {0};
struct bridge_args *br_args = (struct bridge_args *)prev_data;
struct browse_args browse_args = {0};
struct uci_section *s = NULL, *device_s = NULL;
char *inst = NULL, *max_inst = NULL;
char *inst = NULL;
dmmap_synchronizeBridgingBridgeVLANPort(dmctx, parent_node, prev_data, prev_instance);
uci_path_foreach_option_eq(bbfdm, "dmmap_bridge_vlanport", "bridge_vlanport", "br_inst", br_args->br_inst, s) {
@ -3213,12 +3209,7 @@ static int browseBridgingBridgeVLANPortInst(struct dmctx *dmctx, DMNODE *parent_
init_bridge_vlanport_args(&curr_bridge_vlanport_args, device_s, s, br_args->bridge_sec, br_args->br_inst);
browse_args.option = "br_inst";
browse_args.value = br_args->br_inst;
inst = handle_update_instance(2, dmctx, &max_inst, update_instance_alias, 5,
s, "bridge_vlanport_instance", "bridge_vlanport_alias",
check_browse_section, (void *)&browse_args);
inst = handle_instance(dmctx, parent_node, s, "bridge_vlanport_instance", "bridge_vlanport_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_bridge_vlanport_args, inst) == DM_STOP)
break;

View file

@ -50,12 +50,7 @@
**************************************************************/
static int get_Device_InterfaceStackNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s = NULL;
int cnt = 0;
uci_path_foreach_sections(bbfdm, "dmmap_interface_stack", "interface_stack", s) {
cnt++;
}
int cnt = get_number_of_entries(ctx, data, instance, browseInterfaceStackInst);
dmasprintf(value, "%d", cnt);
return 0;
}
@ -96,11 +91,8 @@ DMOBJ tDeviceObj[] = {
{"ManagementServer", &DMREAD, NULL, NULL, "file:/etc/config/cwmp", NULL, NULL, NULL, NULL, tManagementServerParams, NULL, BBFDM_BOTH},
{"Time", &DMREAD, NULL, NULL, "file:/etc/config/system", NULL, NULL, NULL, NULL, tTimeParams, NULL, BBFDM_BOTH},
{"UPnP", &DMREAD, NULL, NULL, "file:/etc/config/upnpd", NULL, NULL, NULL, tUPnPObj, NULL, NULL, BBFDM_BOTH},
#ifdef BBF_TR104
{"Services", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tServicesObj, NULL, NULL, BBFDM_BOTH},
#endif
{"Bridging", &DMREAD, NULL, NULL, "file:/etc/config/network", NULL, NULL, NULL, tBridgingObj, tBridgingParams, NULL, BBFDM_BOTH},
{"WiFi", &DMREAD, NULL, NULL, "file:/etc/config/wireless", NULL, NULL, NULL, tWiFiObj, tWiFiParams, NULL, BBFDM_BOTH},
{"Bridging", &DMREAD, NULL, NULL, "file:/etc/config/network", NULL, NULL, NULL, tBridgingObj, tBridgingParams, NULL, BBFDM_BOTH},
{"IP", &DMREAD, NULL, NULL, "file:/etc/config/network", NULL, NULL, NULL, tIPObj, tIPParams, NULL, BBFDM_BOTH},
{"Ethernet", &DMREAD, NULL, NULL, "file:/etc/config/network", NULL, NULL, NULL, tEthernetObj, tEthernetParams, NULL, BBFDM_BOTH},
{"DSL", &DMREAD, NULL, NULL, "file:/etc/config/dsl", NULL, NULL, NULL, tDSLObj, tDSLParams, NULL, BBFDM_BOTH},
@ -125,6 +117,9 @@ DMOBJ tDeviceObj[] = {
{"LANConfigSecurity", &DMREAD, NULL, NULL, "file:/etc/config/users", NULL, NULL, NULL, NULL, tLANConfigSecurityParams, NULL, BBFDM_BOTH},
{"Security", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tSecurityObj, tSecurityParams, NULL, BBFDM_BOTH},
{"RouterAdvertisement", &DMREAD, NULL, NULL, "file:/etc/config/dhcp", NULL, NULL, NULL, tRouterAdvertisementObj, tRouterAdvertisementParams, NULL, BBFDM_BOTH},
#ifdef BBF_TR104
{"Services", &DMREAD, NULL, NULL, NULL, NULL, NULL, NULL, tServicesObj, NULL, NULL, BBFDM_BOTH},
#endif
{0}
};

View file

@ -7,6 +7,7 @@
*
* Author: Imen Bhiri <imen.bhiri@pivasoftware.com>
* Author: Feten Besbes <feten.besbes@pivasoftware.com>
* Author: Amin Ben Ramdhane <amin.benramdhane@pivasoftware.com>
*/
#include "dmdiagnostics.h"
@ -36,6 +37,162 @@ static int get_device_fwimage_linker(char *refparam, struct dmctx *dmctx, void *
return 0;
}
/*************************************************************
* COMMON FUNCTIONS
**************************************************************/
static bool check_file_dir(char *name)
{
DIR *dir = NULL;
struct dirent *d_file = NULL;
if ((dir = opendir (DEFAULT_CONFIG_DIR)) != NULL) {
while ((d_file = readdir (dir)) != NULL) {
if (strcmp(name, d_file->d_name) == 0) {
closedir(dir);
return true;
}
}
closedir(dir);
}
return false;
}
static int get_number_of_cpus(void)
{
char val[16];
dm_read_sysfs_file("/sys/devices/system/cpu/present", val, sizeof(val));
char *max = strchr(val, '-');
return max ? atoi(max+1)+1 : 0;
}
static int dmmap_synchronizeVcfInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct uci_section *s = NULL, *stmp = NULL;
DIR *dir;
struct dirent *d_file;
sysfs_foreach_file(DEFAULT_CONFIG_DIR, dir, d_file) {
if(d_file->d_name[0] == '.')
continue;
if (!is_dmmap_section_exist_eq("dmmap", "vcf", "name", d_file->d_name)) {
dmuci_add_section_bbfdm("dmmap", "vcf", &s);
dmuci_set_value_by_section(s, "name", d_file->d_name);
dmuci_set_value_by_section(s, "backup_restore", "1");
}
}
if (dir)
closedir (dir);
uci_path_foreach_sections_safe(bbfdm, "dmmap", "vcf", stmp, s) {
char *name;
dmuci_get_value_by_section_string(s, "name", &name);
if (check_file_dir(name) == 0)
dmuci_delete_by_section_bbfdm(s, NULL, NULL);
}
return 0;
}
/*************************************************************
* ENTRY METHOD
**************************************************************/
static int browseVcfInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct uci_section *s = NULL;
char *inst = NULL;
dmmap_synchronizeVcfInst(dmctx, parent_node, prev_data, prev_instance);
uci_path_foreach_sections(bbfdm, "dmmap", "vcf", s) {
inst = handle_instance(dmctx, parent_node, s, "vcf_instance", "vcf_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)s, inst) == DM_STOP)
break;
}
return 0;
}
static int browseVlfInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct dmmap_dup *p = NULL;
char *inst = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("system", "system", "dmmap", &dup_list);
list_for_each_entry(p, &dup_list, list) {
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "vlf_instance", "vlf_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p, inst) == DM_STOP)
break;
}
free_dmmap_config_dup_list(&dup_list);
return 0;
}
static int browseDeviceInfoProcessorInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL;
int i;
for (i = 0; i < get_number_of_cpus(); i++) {
inst = handle_instance_without_section(dmctx, parent_node, i+1);
if (DM_LINK_INST_OBJ(dmctx, parent_node, NULL, inst) == DM_STOP)
break;
}
return 0;
}
static int browseDeviceInfoSupportedDataModelInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL;
int i;
for (i = 0; i < ARRAY_SIZE(Data_Models); i++) {
inst = handle_instance_without_section(dmctx, parent_node, i+1);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&Data_Models[i], inst) == DM_STOP)
break;
}
return 0;
}
static int browseDeviceInfoFirmwareImageInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
json_object *res = NULL, *bank_obj = NULL, *arrobj = NULL;
char *inst = NULL;
int id = 0, i = 0;
dmubus_call("fwbank", "dump", UBUS_ARGS{}, 0, &res);
dmjson_foreach_obj_in_array(res, arrobj, bank_obj, i, 1, "bank") {
inst = handle_instance_without_section(dmctx, parent_node, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)bank_obj, inst) == DM_STOP)
break;
}
return 0;
}
/*#Device.DeviceInfo.ProcessStatus.Process.{i}.!UBUS:router.system/processes//processes*/
static int browseProcessEntriesInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
json_object *res = NULL, *processes = NULL, *arrobj = NULL;
char *inst = NULL;
int id = 0, i = 0;
dmubus_call("router.system", "processes", UBUS_ARGS{}, 0, &res);
dmjson_foreach_obj_in_array(res, arrobj, processes, i, 1, "processes") {
inst = handle_instance_without_section(dmctx, parent_node, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)processes, inst) == DM_STOP)
break;
}
return 0;
}
/*************************************************************
* GET & SET PARAM
**************************************************************/
/*#Device.DeviceInfo.Manufacturer!UCI:cwmp/cpe,cpe/manufacturer*/
static int get_device_manufacturer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
@ -238,31 +395,24 @@ static int set_device_provisioningcode(char *refparam, struct dmctx *ctx, void *
return 0;
}
static int get_number_of_cpus(void)
{
char val[16];
dm_read_sysfs_file("/sys/devices/system/cpu/present", val, sizeof(val));
char *max = strchr(val, '-');
return max ? atoi(max+1)+1 : 0;
}
static int get_DeviceInfo_ProcessorNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmasprintf(value, "%d", get_number_of_cpus());
int cnt = get_number_of_entries(ctx, data, instance, browseDeviceInfoProcessorInst);
dmasprintf(value, "%d", cnt);
return 0;
}
static int get_DeviceInfo_VendorLogFileNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *dm_sec = NULL;
unsigned int num = 0;
int cnt = get_number_of_entries(ctx, data, instance, browseVlfInst);
dmasprintf(value, "%d", cnt);
return 0;
}
uci_path_foreach_sections(bbfdm, "dmmap", "vlf", dm_sec) {
num++;
}
dmasprintf(value, "%d", num);
static int get_DeviceInfo_VendorConfigFileNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
int cnt = get_number_of_entries(ctx, data, instance, browseVcfInst);
dmasprintf(value, "%d", cnt);
return 0;
}
@ -274,14 +424,8 @@ static int get_DeviceInfo_SupportedDataModelNumberOfEntries(char *refparam, stru
static int get_DeviceInfo_FirmwareImageNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res = NULL, *banks = NULL;
size_t nbre_banks = 0;
dmubus_call("fwbank", "dump", UBUS_ARGS{}, 0, &res);
DM_ASSERT(res, *value = "0");
json_object_object_get_ex(res, "bank", &banks);
nbre_banks = (banks) ? json_object_array_length(banks) : 0;
dmasprintf(value, "%d", nbre_banks);
int cnt = get_number_of_entries(ctx, data, instance, browseDeviceInfoFirmwareImageInst);
dmasprintf(value, "%d", cnt);
return 0;
}
@ -356,26 +500,9 @@ static int set_vcf_alias(char *refparam, struct dmctx *ctx, void *data, char *in
return 0;
}
static int check_file_dir(char *name)
{
DIR *dir = NULL;
struct dirent *d_file = NULL;
if ((dir = opendir (DEFAULT_CONFIG_DIR)) != NULL) {
while ((d_file = readdir (dir)) != NULL) {
if (strcmp(name, d_file->d_name) == 0) {
closedir(dir);
return 1;
}
}
closedir(dir);
}
return 0;
}
static int get_vlf_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string((struct uci_section *)data, "vlf_alias", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->dmmap_section, "vlf_alias", value);
if ((*value)[0] == '\0')
dmasprintf(value, "cpe-%s", instance);
return 0;
@ -389,7 +516,7 @@ static int set_vlf_alias(char *refparam, struct dmctx *ctx, void *data, char *in
return FAULT_9007;
return 0;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "vlf_alias", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->dmmap_section, "vlf_alias", value);
return 0;
}
return 0;
@ -397,7 +524,7 @@ static int set_vlf_alias(char *refparam, struct dmctx *ctx, void *data, char *in
static int get_vlf_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string((struct uci_section *)data, "log_file", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "log_file", value);
return 0;
}
@ -405,7 +532,7 @@ static int get_vlf_max_size (char *refparam, struct dmctx *ctx, void *data, char
{
int size = 0;
dmuci_get_value_by_section_string((struct uci_section *)data, "log_size", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "log_size", value);
// Value defined in system is in KiB in datamodel this is in bytes, convert the value in bytes
size = (*value && **value) ? atoi(*value) * 1000 : 0;
@ -420,93 +547,6 @@ static int get_vlf_persistent(char *refparam, struct dmctx *ctx, void *data, cha
return 0;
}
static int browseVcfInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *max_inst = NULL, *name;
struct uci_section *s = NULL, *del_sec = NULL;
DIR *dir = NULL;
struct dirent *d_file = NULL;
if ((dir = opendir (DEFAULT_CONFIG_DIR)) != NULL) {
while ((d_file = readdir (dir)) != NULL) {
if(d_file->d_name[0] == '.')
continue;
update_section_list(DMMAP,"vcf", "name", 1, d_file->d_name, NULL, NULL, "backup_restore", "1");
}
closedir (dir);
}
uci_path_foreach_sections(bbfdm, DMMAP, "vcf", s) {
dmuci_get_value_by_section_string(s, "name", &name);
if(del_sec) {
dmuci_delete_by_section_bbfdm(del_sec, NULL, NULL);
del_sec = NULL;
}
if (check_file_dir(name) == 0) {
del_sec = s;
continue;
}
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
s, "vcf_instance", "vcf_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)s, inst) == DM_STOP)
break;
}
if(del_sec)
dmuci_delete_by_section_bbfdm(del_sec, NULL, NULL);
return 0;
}
static int browseVlfInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct uci_section *sys_log_sec = NULL, *dm_sec = NULL;
char *log_file = NULL,*log_size = NULL;
char *inst = NULL, *max_inst = NULL;
int i = 1;
uci_foreach_sections("system", "system", sys_log_sec) {
if (!sys_log_sec)
break;
dmuci_get_value_by_section_string(sys_log_sec, "log_file", &log_file);
dmuci_get_value_by_section_string(sys_log_sec, "log_size", &log_size);
uci_path_foreach_sections(bbfdm, "dmmap", "vlf", dm_sec) {
if (dm_sec)
break;
}
if (!dm_sec) {
update_section_list(DMMAP,"vlf", NULL, i++, NULL, "log_file", log_file, "log_size", log_size);
} else {
dmuci_set_value_by_section_bbfdm(dm_sec, "log_file", log_file);
dmuci_set_value_by_section_bbfdm(dm_sec, "log_size", log_size);
}
}
uci_path_foreach_sections(bbfdm, "dmmap", "vlf", dm_sec) {
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
dm_sec, "vlf_instance", "vlf_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)dm_sec, inst) == DM_STOP){
break;
}
}
return 0;
}
static int browseDeviceInfoProcessorInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *max_inst = NULL;
int i;
for (i = 0; i < get_number_of_cpus(); i++) {
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_without_section, 1, i+1);
if (DM_LINK_INST_OBJ(dmctx, parent_node, NULL, inst) == DM_STOP)
break;
}
return 0;
}
static int get_DeviceInfoProcessor_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s = NULL;
@ -559,34 +599,6 @@ static int get_DeviceInfoProcessor_Architecture(char *refparam, struct dmctx *ct
return 0;
}
static int browseDeviceInfoSupportedDataModelInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *max_inst = NULL;
int i;
for (i = 0; i < ARRAY_SIZE(Data_Models); i++) {
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_without_section, 1, i+1);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&Data_Models[i], inst) == DM_STOP)
break;
}
return 0;
}
static int browseDeviceInfoFirmwareImageInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
json_object *res = NULL, *bank_obj = NULL, *arrobj = NULL;
char *inst = NULL, *max_inst = NULL;
int id = 0, i = 0;
dmubus_call("fwbank", "dump", UBUS_ARGS{}, 0, &res);
dmjson_foreach_obj_in_array(res, arrobj, bank_obj, i, 1, "bank") {
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_without_section, 1, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)bank_obj, inst) == DM_STOP)
break;
}
return 0;
}
static int get_DeviceInfoSupportedDataModel_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s = NULL;
@ -743,22 +755,6 @@ static int get_process_number_of_entries(char* refparam, struct dmctx *ctx, void
return 0;
}
/*#Device.DeviceInfo.ProcessStatus.Process.{i}.!UBUS:router.system/processes//processes*/
static int browseProcessEntriesInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
json_object *res = NULL, *processes = NULL, *arrobj = NULL;
char *inst = NULL, *max_inst = NULL;
int id = 0, i = 0;
dmubus_call("router.system", "processes", UBUS_ARGS{}, 0, &res);
dmjson_foreach_obj_in_array(res, arrobj, processes, i, 1, "processes") {
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_without_section, 1, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)processes, inst) == DM_STOP)
break;
}
return 0;
}
/*#Device.DeviceInfo.ProcessStatus.Process.{i}.PID!UBUS:router.system/processes//processes[@i-1].pid*/
static int get_process_pid(char* refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
@ -1018,6 +1014,7 @@ DMLEAF tDeviceInfoParams[] = {
{"UpTime", &DMREAD, DMT_UNINT, get_device_info_uptime, NULL, BBFDM_BOTH},
{"ProcessorNumberOfEntries", &DMREAD, DMT_UNINT, get_DeviceInfo_ProcessorNumberOfEntries, NULL, BBFDM_BOTH},
{"VendorLogFileNumberOfEntries", &DMREAD, DMT_UNINT, get_DeviceInfo_VendorLogFileNumberOfEntries, NULL, BBFDM_BOTH},
{"VendorConfigFileNumberOfEntries", &DMREAD, DMT_UNINT, get_DeviceInfo_VendorConfigFileNumberOfEntries, NULL, BBFDM_BOTH},
{"SupportedDataModelNumberOfEntries", &DMREAD, DMT_UNINT, get_DeviceInfo_SupportedDataModelNumberOfEntries, NULL, BBFDM_CWMP},
{"FirmwareImageNumberOfEntries", &DMREAD, DMT_UNINT, get_DeviceInfo_FirmwareImageNumberOfEntries, NULL, BBFDM_BOTH},
{0}
@ -1111,4 +1108,3 @@ DMLEAF tDeviceInfoFirmwareImageParams[] = {
{"Activate()", &DMASYNC, DMT_COMMAND, get_operate_args_DeviceInfoFirmwareImage_Activate, operate_DeviceInfoFirmwareImage_Activate, BBFDM_USP},
{0}
};

File diff suppressed because it is too large Load diff

View file

@ -40,7 +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 *config_s, struct uci_section *dmmap_s, char *dmmap_name, char *proto, int action);
char *get_dhcp_server_pool_last_instance(char *package, char *section, char *dmmap_package, char *opt_inst);
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

@ -16,14 +16,13 @@
struct dhcpv6_client_args
{
struct uci_section *dhcp_client_conf;
struct uci_section *dhcp_client_dm;
struct dmmap_dup *dhcp_client_sections;
char *ip;
};
struct dhcpv6_args
{
struct uci_section *dhcp_sec;
struct dmmap_dup *dhcp_sections;
char *interface;
};
@ -67,6 +66,9 @@ static int get_value_in_date_time_format(json_object *json_obj, char *option_nam
return 0;
}
/*************************************************************
* INIT
**************************************************************/
static inline int init_dhcpv6_client_args(struct clientv6_args *args, json_object *client, json_object *client_param, int i)
{
args->client = client;
@ -75,18 +77,21 @@ static inline int init_dhcpv6_client_args(struct clientv6_args *args, json_objec
return 0;
}
static inline int init_dhcpv6_args(struct dhcpv6_args *args, struct uci_section *s, char *interface)
static inline int init_dhcpv6_args(struct dhcpv6_args *args, struct dmmap_dup *s, char *interface)
{
args->dhcp_sections = s;
args->interface = interface;
args->dhcp_sec = s;
return 0;
}
/*************************************************************
* ENTRY METHOD
**************************************************************/
/*#Device.DHCPv6.Client.{i}.!UCI:network/interface/dmmap_dhcpv6*/
static int browseDHCPv6ClientInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct dhcpv6_client_args dhcpv6_client_arg = {0};
char *inst = NULL, *max_inst = NULL;
char *inst = NULL;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
@ -105,12 +110,10 @@ static int browseDHCPv6ClientInst(struct dmctx *dmctx, DMNODE *parent_node, void
}
}
dhcpv6_client_arg.dhcp_client_conf = p->config_section;
dhcpv6_client_arg.dhcp_client_dm = p->dmmap_section;
dhcpv6_client_arg.dhcp_client_sections = p;
dhcpv6_client_arg.ip = dmstrdup(ipv6addr ? ipv6addr : "");
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
p->dmmap_section, "bbf_dhcpv6client_instance", "bbf_dhcpv6client_alias");
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "bbf_dhcpv6client_instance", "bbf_dhcpv6client_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&dhcpv6_client_arg, inst) == DM_STOP)
break;
@ -122,7 +125,7 @@ static int browseDHCPv6ClientInst(struct dmctx *dmctx, DMNODE *parent_node, void
/*#Device.DHCPv6.Server.Pool.{i}.!UCI:dhcp/dhcp/dmmap_dhcpv6*/
static int browseDHCPv6ServerPoolInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *ignore = NULL, *interface, *inst = NULL, *max_inst = NULL, *v;
char *ignore = NULL, *interface, *inst = NULL, *v;
struct dhcpv6_args curr_dhcp6_args = {0};
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
@ -136,10 +139,9 @@ static int browseDHCPv6ServerPoolInst(struct dmctx *dmctx, DMNODE *parent_node,
continue;
dmuci_get_value_by_section_string(p->config_section, "interface", &interface);
init_dhcpv6_args(&curr_dhcp6_args, p->config_section, interface);
init_dhcpv6_args(&curr_dhcp6_args, p, interface);
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
p->dmmap_section, "dhcpv6_serv_pool_instance", "dhcpv6_serv_pool_alias");
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "dhcpv6_serv_pool_instance", "dhcpv6_serv_pool_alias");
dmuci_get_value_by_section_string(p->dmmap_section, "order", &v);
if (v == NULL || strlen(v) == 0)
@ -155,13 +157,13 @@ static int browseDHCPv6ServerPoolInst(struct dmctx *dmctx, DMNODE *parent_node,
static int browseDHCPv6ServerPoolClientInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct dhcpv6_args *dhcp_arg= (struct dhcpv6_args*)prev_data;
struct dhcpv6_args *dhcp_arg= (struct dhcpv6_args *)prev_data;
json_object *res = NULL, *res1 = NULL, *jobj = NULL, *dev_obj = NULL, *net_obj = NULL;
struct clientv6_args curr_dhcp_client_args = {0};
int i = 0;
char *inst = NULL, *max_inst = NULL, *device;
char *inst = NULL, *device;
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(dhcp_arg->dhcp_sec), String}}, 1, &res1);
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(dhcp_arg->dhcp_sections->config_section), String}}, 1, &res1);
if (!res1) return 0;
device = dmjson_get_value(res1, 1, "device");
dmubus_call("dhcp", "ipv6leases", UBUS_ARGS{}, 0, &res);
@ -176,7 +178,7 @@ static int browseDHCPv6ServerPoolClientInst(struct dmctx *dmctx, DMNODE *parent_
if (!jobj) break;
init_dhcpv6_client_args(&curr_dhcp_client_args, jobj, NULL, i);
i++;
inst = handle_update_instance(2, dmctx, &max_inst, update_instance_without_section, 1, i);
inst = handle_instance_without_section(dmctx, parent_node, i);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_dhcp_client_args, inst) == DM_STOP)
break;
}
@ -189,12 +191,11 @@ static int browseDHCPv6ServerPoolOptionInst(struct dmctx *dmctx, DMNODE *parent_
struct uci_list *dhcp_options_list = NULL;
struct uci_element *e = NULL;
struct uci_section *dmmap_sect = NULL;
struct browse_args browse_args = {0};
char **dhcpv6_option = NULL, *inst = NULL, *max_inst = NULL, *dhcpv6_tag, *dhcpv6_value;
char **dhcpv6_option = NULL, *inst = NULL, *dhcpv6_tag, *dhcpv6_value;
size_t length = 0;
struct dhcpv6_client_option_args dhcpv6_client_opt_args = {0};
dmuci_get_value_by_section_list(curr_dhcp_args->dhcp_sec, "dhcp_option", &dhcp_options_list);
dmuci_get_value_by_section_list(curr_dhcp_args->dhcp_sections->config_section, "dhcp_option", &dhcp_options_list);
if (dhcp_options_list != NULL) {
uci_foreach_element(dhcp_options_list, e) {
@ -203,30 +204,25 @@ static int browseDHCPv6ServerPoolOptionInst(struct dmctx *dmctx, DMNODE *parent_
if (!dhcpv6_option)
continue;
if ((dmmap_sect = get_dup_section_in_dmmap_eq("dmmap_dhcpv6", "servpool_option", section_name(curr_dhcp_args->dhcp_sec), "option_tag", dhcpv6_option[0])) == NULL) {
if ((dmmap_sect = get_dup_section_in_dmmap_eq("dmmap_dhcpv6", "servpool_option", section_name(curr_dhcp_args->dhcp_sections->config_section), "option_tag", dhcpv6_option[0])) == NULL) {
dmuci_add_section_bbfdm("dmmap_dhcpv6", "servpool_option", &dmmap_sect);
dmuci_set_value_by_section_bbfdm(dmmap_sect, "option_tag", dhcpv6_option[0]);
dmuci_set_value_by_section_bbfdm(dmmap_sect, "section_name", section_name(curr_dhcp_args->dhcp_sec));
dmuci_set_value_by_section_bbfdm(dmmap_sect, "section_name", section_name(curr_dhcp_args->dhcp_sections->config_section));
dmuci_set_value_by_section_bbfdm(dmmap_sect, "option_value", length > 1 ? dhcpv6_option[1] : "");
}
}
}
uci_path_foreach_option_eq(bbfdm, "dmmap_dhcpv6", "servpool_option", "section_name", section_name(curr_dhcp_args->dhcp_sec), dmmap_sect) {
uci_path_foreach_option_eq(bbfdm, "dmmap_dhcpv6", "servpool_option", "section_name", section_name(curr_dhcp_args->dhcp_sections->config_section), dmmap_sect) {
dmuci_get_value_by_section_string(dmmap_sect, "option_tag", &dhcpv6_tag);
dmuci_get_value_by_section_string(dmmap_sect, "option_value", &dhcpv6_value);
dhcpv6_client_opt_args.client_sect = curr_dhcp_args->dhcp_sec;
dhcpv6_client_opt_args.client_sect = curr_dhcp_args->dhcp_sections->config_section;
dhcpv6_client_opt_args.dmmap_sect = dmmap_sect;
dhcpv6_client_opt_args.option_tag = dhcpv6_tag;
dhcpv6_client_opt_args.value = dhcpv6_value;
browse_args.option = "section_name";
browse_args.value = section_name(curr_dhcp_args->dhcp_sec);
inst = handle_update_instance(2, dmctx, &max_inst, update_instance_alias, 5,
dmmap_sect, "bbf_dhcpv6_servpool_option_instance", "bbf_dhcpv6_servpool_option_alias",
check_browse_section, (void *)&browse_args);
inst = handle_instance(dmctx, parent_node, dmmap_sect, "bbf_dhcpv6_servpool_option_instance", "bbf_dhcpv6_servpool_option_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&dhcpv6_client_opt_args, inst) == DM_STOP)
break;
@ -239,7 +235,7 @@ static int browseDHCPv6ServerPoolClientIPv6AddressInst(struct dmctx *dmctx, DMNO
struct clientv6_args *dhcpv6_serv_pool_client = (struct clientv6_args *)prev_data;
json_object *address_obj= NULL;
struct clientv6_args curr_dhcv6_address_args = {0};
char *inst = NULL, *max_inst = NULL;
char *inst = NULL;
int i = 0;
while (1) {
@ -248,7 +244,7 @@ static int browseDHCPv6ServerPoolClientIPv6AddressInst(struct dmctx *dmctx, DMNO
break;
init_dhcpv6_client_args(&curr_dhcv6_address_args, dhcpv6_serv_pool_client->client, address_obj, i);
i++;
inst = handle_update_instance(3, dmctx, &max_inst, update_instance_without_section, 1, i);
inst = handle_instance_without_section(dmctx, parent_node, i);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_dhcv6_address_args, inst) == DM_STOP)
break;
}
@ -261,7 +257,7 @@ static int browseDHCPv6ServerPoolClientIPv6PrefixInst(struct dmctx *dmctx, DMNOD
struct clientv6_args *dhcpv6_serv_pool_client = (struct clientv6_args *)prev_data;
json_object *address_obj = NULL;
struct clientv6_args curr_dhcv6_address_args = {0};
char *inst = NULL, *max_inst = NULL;
char *inst = NULL;
int i = 0;
while (1) {
@ -270,7 +266,7 @@ static int browseDHCPv6ServerPoolClientIPv6PrefixInst(struct dmctx *dmctx, DMNOD
break;
init_dhcpv6_client_args(&curr_dhcv6_address_args, dhcpv6_serv_pool_client->client, address_obj, i);
i++;
inst = handle_update_instance(3, dmctx, &max_inst, update_instance_without_section, 1, i);
inst = handle_instance_without_section(dmctx, parent_node, i);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_dhcv6_address_args, inst) == DM_STOP)
break;
}
@ -278,13 +274,15 @@ static int browseDHCPv6ServerPoolClientIPv6PrefixInst(struct dmctx *dmctx, DMNOD
return 0;
}
/*************************************************************
* ADD & DEL OBJ
**************************************************************/
static int addObjDHCPv6Client(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
struct uci_section *s = NULL, *dmmap_sect = NULL;
char dhcpv6_s[32];
char *last_inst = get_last_instance_bbfdm("dmmap_dhcpv6", "interface", "bbf_dhcpv6client_instance");
snprintf(dhcpv6_s, sizeof(dhcpv6_s), "dhcpv6_intf_%d", last_inst ? atoi(last_inst) + 1 : 1);
snprintf(dhcpv6_s, sizeof(dhcpv6_s), "dhcpv6_intf_%s", *instance);
dmuci_add_section("network", "interface", &s);
dmuci_rename_section_by_section(s, dhcpv6_s);
@ -296,7 +294,7 @@ static int addObjDHCPv6Client(char *refparam, struct dmctx *ctx, void *data, cha
dmuci_add_section_bbfdm("dmmap_dhcpv6", "interface", &dmmap_sect);
dmuci_set_value_by_section(dmmap_sect, "section_name", dhcpv6_s);
dmuci_set_value_by_section(dmmap_sect, "added_by_controller", "1");
*instance = update_instance(last_inst, 2, dmmap_sect, "bbf_dhcpv6client_instance");
dmuci_set_value_by_section(dmmap_sect, "bbf_dhcpv6client_instance", *instance);
return 0;
}
@ -307,14 +305,14 @@ static int delObjDHCPv6Client(char *refparam, struct dmctx *ctx, void *data, cha
switch (del_action) {
case DEL_INST:
dmuci_get_value_by_section_string(((struct dhcpv6_client_args*)data)->dhcp_client_dm, "added_by_controller", &added_by_controller);
dmuci_get_value_by_section_string((((struct dhcpv6_client_args *)data)->dhcp_client_sections)->config_section, "added_by_controller", &added_by_controller);
if (added_by_controller && strcmp(added_by_controller, "1") == 0) {
dmuci_delete_by_section(((struct dhcpv6_client_args*)data)->dhcp_client_conf, NULL, NULL);
dmuci_delete_by_section((((struct dhcpv6_client_args *)data)->dhcp_client_sections)->config_section, NULL, NULL);
} else {
dmuci_set_value_by_section(((struct dhcpv6_client_args*)data)->dhcp_client_conf, "proto", "none");
dmuci_set_value_by_section((((struct dhcpv6_client_args *)data)->dhcp_client_sections)->config_section, "proto", "none");
}
dmuci_delete_by_section(((struct dhcpv6_client_args*)data)->dhcp_client_dm, NULL, NULL);
dmuci_delete_by_section((((struct dhcpv6_client_args *)data)->dhcp_client_sections)->dmmap_section, NULL, NULL);
break;
case DEL_ALL:
uci_foreach_option_eq_safe("network", "interface", "proto", "dhcpv6", s_tmp, s) {
@ -341,8 +339,7 @@ static int addObjDHCPv6ServerPool(char *refparam, struct dmctx *ctx, void *data,
struct uci_section *s = NULL, *dmmap_dhcp = NULL;
char dhcpv6_sname[32] = {0};
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);
snprintf(dhcpv6_sname, sizeof(dhcpv6_sname), "dhcpv6_%s", *instance);
dmuci_add_section("dhcp", "dhcp", &s);
dmuci_rename_section_by_section(s, dhcpv6_sname);
@ -351,48 +348,31 @@ static int addObjDHCPv6ServerPool(char *refparam, struct dmctx *ctx, void *data,
dmuci_add_section_bbfdm("dmmap_dhcpv6", "dhcp", &dmmap_dhcp);
dmuci_set_value_by_section(dmmap_dhcp, "section_name", dhcpv6_sname);
*instance = update_instance(inst_para, 2, dmmap_dhcp, "dhcpv6_serv_pool_instance");
dmuci_set_value_by_section(dmmap_dhcp, "dhcpv6_serv_pool_instance", *instance);
return 0;
}
static int delObjDHCPv6ServerPool(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
int found = 0;
struct uci_section *s = NULL, *ss = NULL, *dmmap_section = NULL;
char *dhcpv6 = NULL;
struct uci_section *s = NULL, *stmp = NULL;
switch (del_action) {
case DEL_INST:
if(is_section_unnamed(section_name(((struct dhcpv6_args *)data)->dhcp_sec))){
LIST_HEAD(dup_list);
delete_sections_save_next_sections("dmmap_dhcpv6", "dhcp", "dhcpv6_serv_pool_instance", section_name(((struct dhcpv6_args *)data)->dhcp_sec), atoi(instance), &dup_list);
update_dmmap_sections(&dup_list, "dhcpv6_serv_pool_instance", "dmmap_dhcpv6", "dhcp");
dmuci_delete_by_section_unnamed(((struct dhcpv6_args *)data)->dhcp_sec, NULL, NULL);
} else {
get_dmmap_section_of_config_section("dmmap_dhcpv6", "dhcp", section_name(((struct dhcpv6_args *)data)->dhcp_sec), &dmmap_section);
if(dmmap_section) dmuci_delete_by_section_unnamed_bbfdm(dmmap_section, NULL, NULL);
dmuci_delete_by_section(((struct dhcpv6_args *)data)->dhcp_sec, NULL, NULL);
}
dmuci_delete_by_section((((struct dhcpv6_args *)data)->dhcp_sections)->config_section, NULL, NULL);
dmuci_delete_by_section((((struct dhcpv6_args *)data)->dhcp_sections)->dmmap_section, NULL, NULL);
break;
case DEL_ALL:
uci_foreach_sections("dhcp", "dhcp", s) {
if (found != 0){
dmuci_get_value_by_section_string(ss, "dhcpv6", &dhcpv6);
if(strcmp(dhcpv6, "server") == 0){
uci_foreach_sections_safe("dhcp", "dhcp", stmp, s) {
char *dhcpv6 = NULL;
dmuci_get_value_by_section_string(s, "dhcpv6", &dhcpv6);
if (strcmp(dhcpv6, "server") == 0) {
struct uci_section *dmmap_section = NULL;
get_dmmap_section_of_config_section("dmmap_dhcpv6", "dhcp", section_name(s), &dmmap_section);
if (dmmap_section) dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
}
ss = s;
found++;
}
if (ss != NULL){
dmuci_get_value_by_section_string(ss, "dhcpv6", &dhcpv6);
if(strcmp(dhcpv6, "server") == 0){
get_dmmap_section_of_config_section("dmmap_dhcpv6", "dhcp", section_name(ss), &dmmap_section);
if(dmmap_section) dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(s, NULL, NULL);
}
}
break;
@ -402,21 +382,14 @@ static int delObjDHCPv6ServerPool(char *refparam, struct dmctx *ctx, void *data,
static int addObjDHCPv6ServerPoolOption(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
struct dhcpv6_args *dhcpv6_arg = (struct dhcpv6_args*)data;
struct dhcpv6_args *dhcpv6_arg = (struct dhcpv6_args *)data;
struct uci_section *dmmap_sect;
struct browse_args browse_args = {0};
char *inst_para = get_last_instance_lev2_bbfdm_dmmap_opt("dmmap_dhcpv6", "servpool_option", "bbf_dhcpv6_servpool_option_instance", "section_name", section_name(dhcpv6_arg->dhcp_sec));
dmuci_add_section_bbfdm("dmmap_dhcpv6", "servpool_option", &dmmap_sect);
dmuci_set_value_by_section_bbfdm(dmmap_sect, "section_name", section_name(dhcpv6_arg->dhcp_sec));
char *option_tag = generate_tag_option("dmmap_dhcpv6", "servpool_option", "section_name", section_name(dhcpv6_arg->dhcp_sec), "option_tag");
dmuci_set_value_by_section_bbfdm(dmmap_sect, "section_name", section_name(dhcpv6_arg->dhcp_sections->config_section));
char *option_tag = generate_tag_option("dmmap_dhcpv6", "servpool_option", "section_name", section_name(dhcpv6_arg->dhcp_sections->config_section), "option_tag");
dmuci_set_value_by_section_bbfdm(dmmap_sect, "option_tag", option_tag);
browse_args.option = "section_name";
browse_args.value = section_name(dhcpv6_arg->dhcp_sec);
*instance = update_instance(inst_para, 5, dmmap_sect, "bbf_dhcpv6_servpool_option_instance", NULL, check_browse_section, (void *)&browse_args);
dmuci_set_value_by_section_bbfdm(dmmap_sect, "bbf_dhcpv6_servpool_option_instance", *instance);
return 0;
}
@ -435,26 +408,24 @@ static int delObjDHCPv6ServerPoolOption(char *refparam, struct dmctx *ctx, void
dmuci_del_list_value_by_section(((struct dhcpv6_client_option_args *)data)->client_sect, "dhcp_option", tag_value);
}
dmuci_delete_by_section_unnamed_bbfdm(((struct dhcpv6_client_option_args *)data)->dmmap_sect, NULL, NULL);
dmuci_delete_by_section(((struct dhcpv6_client_option_args *)data)->dmmap_sect, NULL, NULL);
break;
case DEL_ALL:
dmuci_set_value_by_section(((struct dhcpv6_args *)data)->dhcp_sec, "dhcp_option", "");
dmuci_set_value_by_section((((struct dhcpv6_args *)data)->dhcp_sections)->config_section, "dhcp_option", "");
uci_path_foreach_sections_safe(bbfdm, "dmmap_dhcpv6", "servpool_option", stmp, s) {
dmuci_delete_by_section_unnamed_bbfdm(s, NULL, NULL);
dmuci_delete_by_section(s, NULL, NULL);
}
break;
}
return 0;
}
/*************************************************************
* GET & SET PARAM
**************************************************************/
static int get_DHCPv6_ClientNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s = NULL;
int cnt = 0;
uci_path_foreach_sections(bbfdm, "dmmap_dhcpv6", "interface", s) {
cnt++;
}
int cnt = get_number_of_entries(ctx, data, instance, browseDHCPv6ClientInst);
dmasprintf(value, "%d", cnt);
return 0;
}
@ -463,7 +434,7 @@ static int get_DHCPv6_ClientNumberOfEntries(char *refparam, struct dmctx *ctx, v
static int get_DHCPv6Client_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *disabled = NULL;
dmuci_get_value_by_section_string(((struct dhcpv6_client_args *)data)->dhcp_client_conf, "disabled", &disabled);
dmuci_get_value_by_section_string((((struct dhcpv6_client_args *)data)->dhcp_client_sections)->config_section, "disabled", &disabled);
*value = (disabled[0] == '1') ? "0" : "1";
return 0;
}
@ -479,7 +450,7 @@ static int set_DHCPv6Client_Enable(char *refparam, struct dmctx *ctx, void *data
return 0;
case VALUESET:
string_to_bool(value, &b);
dmuci_set_value_by_section(((struct dhcpv6_client_args *)data)->dhcp_client_conf, "disabled", b ? "0" : "1");
dmuci_set_value_by_section((((struct dhcpv6_client_args *)data)->dhcp_client_sections)->config_section, "disabled", b ? "0" : "1");
return 0;
}
return 0;
@ -487,7 +458,7 @@ static int set_DHCPv6Client_Enable(char *refparam, struct dmctx *ctx, void *data
static int get_DHCPv6Client_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string(((struct dhcpv6_client_args *)data)->dhcp_client_dm, "bbf_dhcpv6client_alias", value);
dmuci_get_value_by_section_string((((struct dhcpv6_client_args *)data)->dhcp_client_sections)->dmmap_section, "bbf_dhcpv6client_alias", value);
if ((*value)[0] == '\0')
dmasprintf(value, "cpe-%s", instance);
return 0;
@ -501,7 +472,7 @@ static int set_DHCPv6Client_Alias(char *refparam, struct dmctx *ctx, void *data,
return FAULT_9007;
break;
case VALUESET:
dmuci_set_value_by_section(((struct dhcpv6_client_args *)data)->dhcp_client_dm, "bbf_dhcpv6client_alias", value);
dmuci_set_value_by_section((((struct dhcpv6_client_args *)data)->dhcp_client_sections)->dmmap_section, "bbf_dhcpv6client_alias", value);
break;
}
return 0;
@ -509,7 +480,7 @@ static int set_DHCPv6Client_Alias(char *refparam, struct dmctx *ctx, void *data,
static int get_DHCPv6Client_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *dhcpv6_s = ((struct dhcpv6_client_args *)data)->dhcp_client_conf;
struct uci_section *dhcpv6_s = (((struct dhcpv6_client_args *)data)->dhcp_client_sections)->config_section;
char *device = NULL;
dmuci_get_value_by_section_string(dhcpv6_s, "device", &device);
@ -524,14 +495,14 @@ static int get_DHCPv6Client_Interface(char *refparam, struct dmctx *ctx, void *d
static int set_DHCPv6Client_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
return set_DHCP_Interface(ctx, value, ((struct dhcpv6_client_args *)data)->dhcp_client_conf, ((struct dhcpv6_client_args *)data)->dhcp_client_dm, "dmmap_dhcpv6", "dhcpv6", action);
return set_DHCP_Interface(ctx, value, (((struct dhcpv6_client_args *)data)->dhcp_client_sections)->config_section, (((struct dhcpv6_client_args *)data)->dhcp_client_sections)->dmmap_section, "dmmap_dhcpv6", "dhcpv6", action);
}
/*#Device.DHCPv6.Client.{i}.Status!UCI:network/interface,@i-1/disabled*/
static int get_DHCPv6Client_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *disabled = NULL;
dmuci_get_value_by_section_string(((struct dhcpv6_client_args *)data)->dhcp_client_conf, "disabled", &disabled);
dmuci_get_value_by_section_string((((struct dhcpv6_client_args *)data)->dhcp_client_sections)->config_section, "disabled", &disabled);
*value = (disabled[0] == '1') ? "Disabled" : "Enabled";
return 0;
}
@ -539,7 +510,7 @@ static int get_DHCPv6Client_Status(char *refparam, struct dmctx *ctx, void *data
/*#Device.DHCPv6.Client.{i}.DUID!UBUS:network.interface/status/interface,@Name/data.passthru*/
static int get_DHCPv6Client_DUID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *dhcpv6_s = ((struct dhcpv6_client_args *)data)->dhcp_client_conf;
struct uci_section *dhcpv6_s = (((struct dhcpv6_client_args *)data)->dhcp_client_sections)->config_section;
json_object *res = NULL;
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", dhcpv6_s ? section_name(dhcpv6_s) : "", String}}, 1, &res);
@ -552,7 +523,7 @@ static int get_DHCPv6Client_RequestAddresses(char *refparam, struct dmctx *ctx,
{
char *reqaddress = NULL;
dmuci_get_value_by_section_string(((struct dhcpv6_client_args *)data)->dhcp_client_conf, "reqaddress", &reqaddress);
dmuci_get_value_by_section_string((((struct dhcpv6_client_args *)data)->dhcp_client_sections)->config_section, "reqaddress", &reqaddress);
*value = (reqaddress && strcmp(reqaddress, "none") == 0) ? "0" : "1";
return 0;
}
@ -568,7 +539,7 @@ static int set_DHCPv6Client_RequestAddresses(char *refparam, struct dmctx *ctx,
return 0;
case VALUESET:
string_to_bool(value, &b);
dmuci_set_value_by_section(((struct dhcpv6_client_args *)data)->dhcp_client_conf, "reqaddress", b ? "force" : "none");
dmuci_set_value_by_section((((struct dhcpv6_client_args *)data)->dhcp_client_sections)->config_section, "reqaddress", b ? "force" : "none");
break;
}
return 0;
@ -579,7 +550,7 @@ static int get_DHCPv6Client_RequestPrefixes(char *refparam, struct dmctx *ctx, v
{
char *reqprefix = NULL;
dmuci_get_value_by_section_string(((struct dhcpv6_client_args *)data)->dhcp_client_conf, "reqprefix", &reqprefix);
dmuci_get_value_by_section_string((((struct dhcpv6_client_args *)data)->dhcp_client_sections)->config_section, "reqprefix", &reqprefix);
*value = (reqprefix && strcmp(reqprefix, "auto") == 0) ? "1" : "0";
return 0;
}
@ -595,7 +566,7 @@ static int set_DHCPv6Client_RequestPrefixes(char *refparam, struct dmctx *ctx, v
return 0;
case VALUESET:
string_to_bool(value, &b);
dmuci_set_value_by_section(((struct dhcpv6_client_args *)data)->dhcp_client_conf, "reqprefix", b ? "auto" : "no");
dmuci_set_value_by_section((((struct dhcpv6_client_args *)data)->dhcp_client_sections)->config_section, "reqprefix", b ? "auto" : "no");
return 0;
}
return 0;
@ -609,7 +580,7 @@ static int get_DHCPv6Client_Renew(char *refparam, struct dmctx *ctx, void *data,
static int set_DHCPv6Client_Renew(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *dhcpv6_s = ((struct dhcpv6_client_args *)data)->dhcp_client_conf;
struct uci_section *dhcpv6_s = (((struct dhcpv6_client_args *)data)->dhcp_client_sections)->config_section;
bool b;
switch (action) {
@ -629,7 +600,7 @@ static int set_DHCPv6Client_Renew(char *refparam, struct dmctx *ctx, void *data,
/*#Device.DHCPv6.Client.{i}.RequestedOptions!UCI:network/interface,@i-1/reqopts*/
static int get_DHCPv6Client_RequestedOptions(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string(((struct dhcpv6_client_args *)data)->dhcp_client_conf, "reqopts", value);
dmuci_get_value_by_section_string((((struct dhcpv6_client_args *)data)->dhcp_client_sections)->config_section, "reqopts", value);
return 0;
}
@ -641,7 +612,7 @@ static int set_DHCPv6Client_RequestedOptions(char *refparam, struct dmctx *ctx,
return FAULT_9007;
break;
case VALUESET:
dmuci_set_value_by_section(((struct dhcpv6_client_args *)data)->dhcp_client_conf, "reqopts", value);
dmuci_set_value_by_section((((struct dhcpv6_client_args *)data)->dhcp_client_sections)->config_section, "reqopts", value);
break;
}
return 0;
@ -676,27 +647,15 @@ static int set_DHCPv6Server_Enable(char *refparam, struct dmctx *ctx, void *data
static int get_DHCPv6Server_PoolNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s = NULL;
char *ignore = NULL;
int i = 0;
uci_foreach_sections("dhcp", "dhcp", s) {
// skip the section if option ignore = '1'
dmuci_get_value_by_section_string(s, "ignore", &ignore);
if (ignore && strcmp(ignore, "1") == 0)
continue;
i++;
}
dmasprintf(value, "%d", i);
int cnt = get_number_of_entries(ctx, data, instance, browseDHCPv6ServerPoolInst);
dmasprintf(value, "%d", cnt);
return 0;
}
/*#Device.DHCPv6.Server.Pool.{i}.Enable!UCI:dhcp/dhcp,@i-1/dhcpv6*/
static int get_DHCPv6ServerPool_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string(((struct dhcpv6_args *)data)->dhcp_sec, "dhcpv6", value);
dmuci_get_value_by_section_string((((struct dhcpv6_args *)data)->dhcp_sections)->config_section, "dhcpv6", value);
*value = (*value && strcmp(*value, "disabled") == 0) ? "0" : "1";
return 0;
}
@ -712,7 +671,7 @@ static int set_DHCPv6ServerPool_Enable(char *refparam, struct dmctx *ctx, void *
return 0;
case VALUESET:
string_to_bool(value, &b);
dmuci_set_value_by_section(((struct dhcpv6_args *)data)->dhcp_sec, "dhcpv6", b ? "server" : "disabled");
dmuci_set_value_by_section((((struct dhcpv6_args *)data)->dhcp_sections)->config_section, "dhcpv6", b ? "server" : "disabled");
return 0;
}
return 0;
@ -721,7 +680,7 @@ static int set_DHCPv6ServerPool_Enable(char *refparam, struct dmctx *ctx, void *
/*#Device.DHCPv6.Server.Pool.{i}.Status!UCI:dhcp/dhcp,@i-1/dhcpv6*/
static int get_DHCPv6ServerPool_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string(((struct dhcpv6_args *)data)->dhcp_sec, "dhcpv6", value);
dmuci_get_value_by_section_string((((struct dhcpv6_args *)data)->dhcp_sections)->config_section, "dhcpv6", value);
*value = (*value && strcmp(*value, "disabled") == 0) ? "Disabled" : "Enabled";
return 0;
}
@ -729,10 +688,7 @@ static int get_DHCPv6ServerPool_Status(char *refparam, struct dmctx *ctx, void *
/*#Device.DHCPv6.Server.Pool.{i}.Alias!UCI:dmmap_dhcpv6/dhcp,@i-1/dhcpv6_serv_pool_alias*/
static int get_DHCPv6ServerPool_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *dmmap_sect = NULL;
get_dmmap_section_of_config_section("dmmap_dhcpv6", "dhcp", section_name(((struct dhcpv6_args *)data)->dhcp_sec), &dmmap_sect);
dmuci_get_value_by_section_string(dmmap_sect, "dhcpv6_serv_pool_alias", value);
dmuci_get_value_by_section_string((((struct dhcpv6_args *)data)->dhcp_sections)->dmmap_section, "dhcpv6_serv_pool_alias", value);
if ((*value)[0] == '\0')
dmasprintf(value, "cpe-%s", instance);
return 0;
@ -740,16 +696,13 @@ static int get_DHCPv6ServerPool_Alias(char *refparam, struct dmctx *ctx, void *d
static int set_DHCPv6ServerPool_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *dmmap_sect = NULL;
switch (action) {
case VALUECHECK:
if (dm_validate_string(value, -1, 64, NULL, NULL))
return FAULT_9007;
return 0;
case VALUESET:
get_dmmap_section_of_config_section("dmmap_dhcpv6", "dhcp", section_name(((struct dhcpv6_args *)data)->dhcp_sec), &dmmap_sect);
dmuci_set_value_by_section_bbfdm(dmmap_sect, "dhcpv6_serv_pool_alias", value);
dmuci_set_value_by_section_bbfdm((((struct dhcpv6_args *)data)->dhcp_sections)->dmmap_section, "dhcpv6_serv_pool_alias", value);
return 0;
}
return 0;
@ -757,26 +710,19 @@ static int set_DHCPv6ServerPool_Alias(char *refparam, struct dmctx *ctx, void *d
static int get_DHCPv6ServerPool_Order(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *dmmap_sect = NULL;
get_dmmap_section_of_config_section("dmmap_dhcpv6", "dhcp", section_name(((struct dhcpv6_args *)data)->dhcp_sec), &dmmap_sect);
dmuci_get_value_by_section_string(dmmap_sect, "order", value);
dmuci_get_value_by_section_string((((struct dhcpv6_args *)data)->dhcp_sections)->dmmap_section, "order", value);
return 0;
}
static int set_DHCPv6ServerPool_Order(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *dmmap_sect = NULL;
switch (action) {
case VALUECHECK:
if (dm_validate_unsignedInt(value, RANGE_ARGS{{"1",NULL}}, 1))
return FAULT_9007;
break;
case VALUESET:
get_dmmap_section_of_config_section("dmmap_dhcpv6", "dhcp", section_name(((struct dhcpv6_args *)data)->dhcp_sec), &dmmap_sect);
if (dmmap_sect)
set_section_order("dhcp", "dmmap_dhcpv6", "dhcp", dmmap_sect, ((struct dhcpv6_args *)data)->dhcp_sec, 1, value);
set_section_order("dhcp", "dmmap_dhcpv6", "dhcp", (((struct dhcpv6_args *)data)->dhcp_sections)->dmmap_section, (((struct dhcpv6_args *)data)->dhcp_sections)->config_section, 1, value);
break;
}
return 0;
@ -805,7 +751,7 @@ static int set_DHCPv6ServerPool_Interface(char *refparam, struct dmctx *ctx, voi
case VALUESET:
adm_entry_get_linker_value(ctx, value, &linker);
if (linker && *linker) {
dmuci_set_value_by_section(((struct dhcpv6_args *)data)->dhcp_sec, "interface", linker);
dmuci_set_value_by_section((((struct dhcpv6_args *)data)->dhcp_sections)->config_section, "interface", linker);
dmfree(linker);
}
break;
@ -941,42 +887,15 @@ static int set_DHCPv6ServerPool_SourceAddressMask(char *refparam, struct dmctx *
static int get_DHCPv6ServerPool_ClientNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res = NULL, *res1 = NULL, *jobj = NULL, *dev_obj = NULL, *next_obj = NULL;
char *device;
int i = 0;
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct dhcpv6_args *)data)->dhcp_sec), String}}, 1, &res1);
DM_ASSERT(res1, *value = "0");
device = dmjson_get_value(res1, 1, "device");
dmubus_call("dhcp", "ipv6leases", UBUS_ARGS{}, 0, &res);
DM_ASSERT(res, *value = "0");
dev_obj = dmjson_get_obj(res, 1, "device");
DM_ASSERT(dev_obj, *value = "0");
next_obj = dmjson_get_obj(dev_obj, 1, device);
DM_ASSERT(next_obj, *value = "0");
while (1) {
jobj = dmjson_select_obj_in_array_idx(next_obj, i, 1, "leases");
if (jobj == NULL)
break;
i++;
}
dmasprintf(value, "%d", i);
int cnt = get_number_of_entries(ctx, data, instance, browseDHCPv6ServerPoolClientInst);
dmasprintf(value, "%d", cnt);
return 0;
}
static int get_DHCPv6ServerPool_OptionNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_list *dhcp_options_list = NULL;
struct uci_element *e = NULL;
int i = 0;
dmuci_get_value_by_section_list(((struct dhcpv6_args *)data)->dhcp_sec, "dhcp_option", &dhcp_options_list);
if (dhcp_options_list != NULL) {
uci_foreach_element(dhcp_options_list, e) {
i++;
}
}
dmasprintf(value, "%d", i);
int cnt = get_number_of_entries(ctx, data, instance, browseDHCPv6ServerPoolOptionInst);
dmasprintf(value, "%d", cnt);
return 0;
}
@ -1023,31 +942,15 @@ static int set_DHCPv6ServerPoolClient_Alias(char *refparam, struct dmctx *ctx, v
static int get_DHCPv6ServerPoolClient_IPv6AddressNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *address_obj = NULL;
int i = 0;
while (1) {
address_obj = dmjson_select_obj_in_array_idx(((struct clientv6_args *)data)->client, i, 1, "ipv6-addr");
if (address_obj == NULL)
break;
i++;
}
dmasprintf(value, "%d", i);
int cnt = get_number_of_entries(ctx, data, instance, browseDHCPv6ServerPoolClientIPv6AddressInst);
dmasprintf(value, "%d", cnt);
return 0;
}
static int get_DHCPv6ServerPoolClient_IPv6PrefixNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *address_obj = NULL;
int i= 0;
while (1) {
address_obj = dmjson_select_obj_in_array_idx(((struct clientv6_args *)data)->client, i, 1, "ipv6-prefix");
if (address_obj == NULL)
break;
i++;
}
dmasprintf(value, "%d", i);
int cnt = get_number_of_entries(ctx, data, instance, browseDHCPv6ServerPoolClientIPv6PrefixInst);
dmasprintf(value, "%d", cnt);
return 0;
}
@ -1305,7 +1208,7 @@ static int set_DHCPv6ServerPoolOption_Value(char *refparam, struct dmctx *ctx, v
*************************************************************/
static int operate_DHCPv6Client_Renew(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *dhcpv6_s = ((struct dhcpv6_client_args *)data)->dhcp_client_conf;
struct uci_section *dhcpv6_s = (((struct dhcpv6_client_args *)data)->dhcp_client_sections)->config_section;
dmubus_call_set("network.interface", "renew", UBUS_ARGS{{"interface", section_name(dhcpv6_s), String}}, 1);

View file

@ -109,13 +109,12 @@ static int dmmap_synchronizeDNSClientRelayServer(struct dmctx *dmctx, DMNODE *pa
static int browseDNSServerInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct uci_section *s = NULL;
char *inst = NULL, *max_inst = NULL;
char *inst = NULL;
dmmap_synchronizeDNSClientRelayServer(dmctx, NULL, NULL, NULL);
dmmap_synchronizeDNSClientRelayServer(dmctx, parent_node, prev_data, prev_instance);
uci_path_foreach_sections(bbfdm, "dmmap_dns", "dns_server", s) {
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
s, "dns_server_instance", "dns_server_alias");
inst = handle_instance(dmctx, parent_node, s, "dns_server_instance", "dns_server_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)s, inst) == DM_STOP)
break;
@ -126,12 +125,11 @@ static int browseDNSServerInst(struct dmctx *dmctx, DMNODE *parent_node, void *p
static int browseResultInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct uci_section *s = NULL;
char *inst = NULL, *max_inst = NULL;
char *inst = NULL;
uci_path_foreach_sections(bbfdm, DMMAP_DIAGNOSTIGS, "NSLookupResult", s) {
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
s, "nslookup_res_instance", "nslookup_res_alias");
inst = handle_instance(dmctx, parent_node, s, "nslookup_res_instance", "nslookup_res_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)s, inst) == DM_STOP)
break;
@ -146,15 +144,13 @@ static int add_dns_server(char *refparam, struct dmctx *ctx, void *data, char **
{
struct uci_section *s = NULL;
char *inst = get_last_instance_bbfdm("dmmap_dns", "dns_server", "dns_server_instance");
dmuci_add_list_value("network", "lan", "dns", "0.0.0.0");
dmuci_add_section_bbfdm("dmmap_dns", "dns_server", &s);
dmuci_set_value_by_section(s, "ip", "0.0.0.0");
dmuci_set_value_by_section(s, "interface", "lan");
dmuci_set_value_by_section(s, "enable", "1");
*instance = update_instance(inst, 2, s, "dns_server_instance");
dmuci_set_value_by_section(s, "dns_server_instance", *instance);
return 0;
}
@ -218,13 +214,7 @@ static int get_client_status(char *refparam, struct dmctx *ctx, void *data, char
static int get_client_server_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s = NULL;
int cnt = 0;
dmmap_synchronizeDNSClientRelayServer(ctx, NULL, NULL, NULL);
uci_path_foreach_sections(bbfdm, "dmmap_dns", "dns_server", s) {
cnt++;
}
int cnt = get_number_of_entries(ctx, data, instance, browseDNSServerInst);
dmasprintf(value, "%d", cnt);
return 0;
}
@ -302,13 +292,7 @@ static int get_relay_status(char *refparam, struct dmctx *ctx, void *data, char
static int get_relay_forward_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s = NULL;
int cnt = 0;
dmmap_synchronizeDNSClientRelayServer(ctx, NULL, NULL, NULL);
uci_path_foreach_sections(bbfdm, "dmmap_dns", "dns_server", s) {
cnt++;
}
int cnt = get_number_of_entries(ctx, data, instance, browseDNSServerInst);
dmasprintf(value, "%d", cnt);
return 0;
}
@ -389,13 +373,8 @@ static int get_nslookupdiagnostics_success_count(char *refparam, struct dmctx *c
static int get_nslookupdiagnostics_result_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s = NULL;
int cnt = 0;
uci_path_foreach_sections(bbfdm, DMMAP_DIAGNOSTIGS, "NSLookupResult", s) {
cnt++;
}
dmasprintf(value, "%d", cnt); // MEM WILL BE FREED IN DMMEMCLEAN
int cnt = get_number_of_entries(ctx, data, instance, browseResultInst);
dmasprintf(value, "%d", cnt);
return 0;
}

View file

@ -105,7 +105,7 @@ static int browseDSLLineInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
json_object *res = NULL, *line_obj = NULL;
struct dsl_line_args cur_dsl_line_args = {0};
struct uci_section *s = NULL;
char *inst = NULL, *max_inst = NULL;
char *inst = NULL;
int entries = 0;
dmubus_call("dsl", "status", UBUS_ARGS{}, 0, &res);
@ -117,8 +117,7 @@ static int browseDSLLineInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
s = update_create_dmmap_dsl_line(cur_dsl_line_args.id);
init_dsl_line(&cur_dsl_line_args, s);
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
s, "dsl_line_instance", "dsl_line_alias");
inst = handle_instance(dmctx, parent_node, s, "dsl_line_instance", "dsl_line_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&cur_dsl_line_args, inst) == DM_STOP)
break;
@ -134,7 +133,7 @@ static int browseDSLChannelInst(struct dmctx *dmctx, DMNODE *parent_node, void *
json_object *res = NULL, *line_obj = NULL, *channel_obj = NULL;
struct dsl_channel_args cur_dsl_channel_args = {0};
struct uci_section *s = NULL;
char *inst = NULL, *max_inst = NULL;
char *inst = NULL;
int entries_line = 0, entries_channel = 0;
dmubus_call("dsl", "status", UBUS_ARGS{}, 0, &res);
@ -148,8 +147,7 @@ static int browseDSLChannelInst(struct dmctx *dmctx, DMNODE *parent_node, void *
s = update_create_dmmap_dsl_channel(cur_dsl_channel_args.id);
init_dsl_channel(&cur_dsl_channel_args, s);
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
s, "dsl_channel_instance", "dsl_channel_alias");
inst = handle_instance(dmctx, parent_node, s, "dsl_channel_instance", "dsl_channel_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&cur_dsl_channel_args, inst) == DM_STOP)
break;
@ -241,24 +239,14 @@ int get_line_linkstatus(char *method, char *id, char **value)
***************************************************************************/
static int get_DSL_LineNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s = NULL;
int cnt = 0;
uci_path_foreach_sections(bbfdm, "dmmap", "dsl_line", s) {
cnt++;
}
int cnt = get_number_of_entries(ctx, data, instance, browseDSLLineInst);
dmasprintf(value, "%d", cnt);
return 0;
}
static int get_DSL_ChannelNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s = NULL;
int cnt = 0;
uci_path_foreach_sections(bbfdm, "dmmap", "dsl_channel", s) {
cnt++;
}
int cnt = get_number_of_entries(ctx, data, instance, browseDSLChannelInst);
dmasprintf(value, "%d", cnt);
return 0;
}
@ -1458,6 +1446,9 @@ static int get_DSLChannelStatsQuarterHour_XTUCCRCErrors(char *refparam, struct d
return 0;
}
/**********************************************************************************************************************************
* OBJ & LEAF DEFINITION
***********************************************************************************************************************************/
/* *** Device.DSL. *** */
DMOBJ tDSLObj[] = {
/* OBJ, permission, addobj, delobj, checkdep, browseinstobj, nextdynamicobj, dynamicleaf, nextobj, leaf, linker, bbfdm_type, uniqueKeys*/

View file

@ -22,11 +22,10 @@ static int get_linker_dynamicdns_server(char *refparam, struct dmctx *dmctx, voi
if (data) {
dmuci_get_value_by_section_string((struct uci_section *)data, "service_name", &service_name);
dmasprintf(linker, "%s", service_name);
return 0;
} else {
*linker = "";
return 0;
}
return 0;
}
/*************************************************************
@ -35,17 +34,16 @@ static int get_linker_dynamicdns_server(char *refparam, struct dmctx *dmctx, voi
/*#Device.DynamicDNS.Client.{i}.!UCI:ddns/service/dmmap_ddns*/
static int browseDynamicDNSClientInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *max_inst = NULL;
char *inst = NULL;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("ddns", "service", "dmmap_ddns", &dup_list);
list_for_each_entry(p, &dup_list, list) {
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
p->dmmap_section, "clientinstance", "clientalias");
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "clientinstance", "clientalias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, inst) == DM_STOP)
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p, inst) == DM_STOP)
break;
}
free_dmmap_config_dup_list(&dup_list);
@ -127,14 +125,13 @@ static int dmmap_synchronizeDynamicDNSServer(struct dmctx *dmctx, DMNODE *parent
/*#Device.DynamicDNS.Server.{i}.!UCI:ddns/service/dmmap_ddns*/
static int browseDynamicDNSServerInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *max_inst = NULL;
char *inst = NULL;
struct uci_section *s = NULL;
dmmap_synchronizeDynamicDNSServer(dmctx, NULL, NULL, NULL);
uci_path_foreach_sections(bbfdm, "dmmap_ddns", "ddns_server", s) {
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
s, "serverinstance", "serveralias");
inst = handle_instance(dmctx, parent_node, s, "serverinstance", "serveralias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)s, inst) == DM_STOP)
break;
@ -156,8 +153,7 @@ static int addObjDynamicDNSClient(char *refparam, struct dmctx *ctx, void *data,
struct uci_section *dmmap = NULL, *s = NULL;
char s_name[32];
char *last_inst = get_last_instance_bbfdm("dmmap_ddns", "service", "clientinstance");
snprintf(s_name, sizeof(s_name), "Ddns_%s", last_inst ? last_inst : "1");
snprintf(s_name, sizeof(s_name), "Ddns_%s", *instance);
dmuci_add_section("ddns", "service", &s);
dmuci_rename_section_by_section(s, s_name);
@ -174,38 +170,27 @@ static int addObjDynamicDNSClient(char *refparam, struct dmctx *ctx, void *data,
dmuci_add_section_bbfdm("dmmap_ddns", "service", &dmmap);
dmuci_set_value_by_section(dmmap, "section_name", section_name(s));
*instance = update_instance(last_inst, 2, dmmap, "clientinstance");
dmuci_set_value_by_section(dmmap, "clientinstance", *instance);
return 0;
}
static int delObjDynamicDNSClient(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
struct uci_section *s = NULL, *ss = NULL, *dmmap_section = NULL;
int found = 0;
struct uci_section *s = NULL, *stmp = NULL;
switch (del_action) {
case DEL_INST:
get_dmmap_section_of_config_section("dmmap_ddns", "service", section_name((struct uci_section *)data), &dmmap_section);
if(dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section((struct uci_section *)data, NULL, NULL);
dmuci_delete_by_section(((struct dmmap_dup *)data)->config_section, NULL, NULL);
dmuci_delete_by_section(((struct dmmap_dup *)data)->dmmap_section, NULL, NULL);
break;
case DEL_ALL:
uci_foreach_sections("ddns", "service", s) {
if (found != 0){
get_dmmap_section_of_config_section("dmmap_ddns", "service", section_name(ss), &dmmap_section);
if(dmmap_section != NULL)
uci_foreach_sections_safe("ddns", "service", stmp, s) {
struct uci_section *dmmap_section = NULL;
get_dmmap_section_of_config_section("dmmap_ddns", "service", section_name(s), &dmmap_section);
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
ss = s;
found++;
}
if (ss != NULL) {
get_dmmap_section_of_config_section("dmmap_ddns", "service", section_name(ss), &dmmap_section);
if(dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
dmuci_delete_by_section(s, NULL, NULL);
}
break;
}
@ -217,8 +202,7 @@ static int addObjDynamicDNSServer(char *refparam, struct dmctx *ctx, void *data,
struct uci_section *dmmap = NULL, *s = NULL;
char s_name[16];
char *last_inst = get_last_instance_bbfdm("dmmap_ddns", "ddns_server", "serverinstance");
snprintf(s_name, sizeof(s_name), "server_%s", last_inst ? last_inst : "1");
snprintf(s_name, sizeof(s_name), "server_%s", *instance);
dmuci_add_section("ddns", "service", &s);
dmuci_rename_section_by_section(s, s_name);
@ -236,14 +220,13 @@ static int addObjDynamicDNSServer(char *refparam, struct dmctx *ctx, void *data,
dmuci_add_section_bbfdm("dmmap_ddns", "ddns_server", &dmmap);
dmuci_set_value_by_section(dmmap, "section_name", section_name(s));
*instance = update_instance(last_inst, 2, dmmap, "serverinstance");
dmuci_set_value_by_section(dmmap, "serverinstance", *instance);
return 0;
}
static int delObjDynamicDNSServer(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
struct uci_section *s = NULL, *ss = NULL, *stmp = NULL, *dmmap_section= NULL;
int found = 0;
struct uci_section *s = NULL, *stmp = NULL;
char *service_name;
switch (del_action) {
@ -255,21 +238,13 @@ static int delObjDynamicDNSServer(char *refparam, struct dmctx *ctx, void *data,
dmuci_delete_by_section((struct uci_section *)data, NULL, NULL);
break;
case DEL_ALL:
uci_foreach_sections("ddns", "service", s) {
if (found != 0){
get_dmmap_section_of_config_section("dmmap_ddns", "ddns_server", section_name(ss), &dmmap_section);
if(dmmap_section != NULL)
uci_foreach_sections_safe("ddns", "service", stmp, s) {
struct uci_section *dmmap_section = NULL;
get_dmmap_section_of_config_section("dmmap_ddns", "ddns_server", section_name(s), &dmmap_section);
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
ss = s;
found++;
}
if (ss != NULL) {
get_dmmap_section_of_config_section("dmmap_ddns", "ddns_server", section_name(ss), &dmmap_section);
if(dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
dmuci_delete_by_section(s, NULL, NULL);
}
break;
}
@ -281,25 +256,14 @@ static int delObjDynamicDNSServer(char *refparam, struct dmctx *ctx, void *data,
*************************************************************/
static int get_DynamicDNS_ClientNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s = NULL;
int cnt = 0;
uci_foreach_sections("ddns", "service", s) {
cnt++;
}
int cnt = get_number_of_entries(ctx, data, instance, browseDynamicDNSClientInst);
dmasprintf(value, "%d", cnt);
return 0;
}
static int get_DynamicDNS_ServerNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s = NULL;
int cnt = 0;
dmmap_synchronizeDynamicDNSServer(ctx, NULL, NULL, NULL);
uci_path_foreach_sections(bbfdm, "dmmap_ddns", "ddns_server", s) {
cnt++;
}
int cnt = get_number_of_entries(ctx, data, instance, browseDynamicDNSServerInst);
dmasprintf(value, "%d", cnt);
return 0;
}
@ -338,7 +302,7 @@ static int get_DynamicDNS_SupportedServices(char *refparam, struct dmctx *ctx, v
/*#Device.DynamicDNS.Client.{i}.Enable!UCI:ddns/service,@i-1/enabled*/
static int get_DynamicDNSClient_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "enabled", "0");
*value = dmuci_get_value_by_section_fallback_def(((struct dmmap_dup *)data)->config_section, "enabled", "0");
return 0;
}
@ -353,7 +317,7 @@ static int set_DynamicDNSClient_Enable(char *refparam, struct dmctx *ctx, void *
break;
case VALUESET:
string_to_bool(value, &b);
dmuci_set_value_by_section((struct uci_section *)data, "enabled", b ? "1" : "0");
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "enabled", b ? "1" : "0");
break;
}
return 0;
@ -364,7 +328,7 @@ static int get_DynamicDNSClient_Status(char *refparam, struct dmctx *ctx, void *
{
char status[32] = {0}, *enable, *logdir = NULL;
dmuci_get_value_by_section_string((struct uci_section *)data, "enabled", &enable);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "enabled", &enable);
if (*enable == '\0' || strcmp(enable, "0") == 0) {
strcpy(status, "Disabled");
} else {
@ -373,7 +337,7 @@ static int get_DynamicDNSClient_Status(char *refparam, struct dmctx *ctx, void *
dmuci_get_option_value_string("ddns", "global", "ddns_logdir", &logdir);
if (*logdir == '\0')
logdir = "/var/log/ddns";
snprintf(path, sizeof(path), "%s/%s.log", logdir, section_name((struct uci_section *)data));
snprintf(path, sizeof(path), "%s/%s.log", logdir, section_name(((struct dmmap_dup *)data)->config_section));
FILE *fp = fopen(path, "r");
if (fp != NULL) {
char buf[512] = {0};
@ -400,10 +364,7 @@ static int get_DynamicDNSClient_Status(char *refparam, struct dmctx *ctx, void *
/*#Device.DynamicDNS.Client.{i}.Alias!UCI:dmmap_ddns/service,@i-1/clientalias*/
static int get_DynamicDNSClient_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *dmmap_section = NULL;
get_dmmap_section_of_config_section("dmmap_ddns", "service", section_name((struct uci_section *)data), &dmmap_section);
dmuci_get_value_by_section_string(dmmap_section, "clientalias", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->dmmap_section, "clientalias", value);
if ((*value)[0] == '\0')
dmasprintf(value, "cpe-%s", instance);
return 0;
@ -411,16 +372,13 @@ static int get_DynamicDNSClient_Alias(char *refparam, struct dmctx *ctx, void *d
static int set_DynamicDNSClient_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *dmmap_section = NULL;
switch (action) {
case VALUECHECK:
if (dm_validate_string(value, -1, 64, NULL, NULL))
return FAULT_9007;
break;
case VALUESET:
get_dmmap_section_of_config_section("dmmap_ddns", "service", section_name((struct uci_section *)data), &dmmap_section);
dmuci_set_value_by_section(dmmap_section, "clientalias", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->dmmap_section, "clientalias", value);
break;
}
return 0;
@ -428,39 +386,39 @@ static int set_DynamicDNSClient_Alias(char *refparam, struct dmctx *ctx, void *d
static int get_DynamicDNSClient_LastError(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char status[64] = {0}, *enable = NULL;
char last_err[64] = {0}, *enable = NULL;
dmuci_get_value_by_section_string((struct uci_section *)data, "enabled", &enable);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "enabled", &enable);
if (enable && (*enable == '\0' || strcmp(enable, "0") == 0)) {
strcpy(status, "NO_ERROR");
strcpy(last_err, "NO_ERROR");
} else {
char path[128] = {0}, *logdir = NULL;
dmuci_get_option_value_string("ddns", "global", "ddns_logdir", &logdir);
snprintf(path, sizeof(path), "%s/%s.log", (logdir && *logdir) ? logdir : "/var/log/ddns", section_name((struct uci_section *)data));
snprintf(path, sizeof(path), "%s/%s.log", (logdir && *logdir) ? logdir : "/var/log/ddns", section_name(((struct dmmap_dup *)data)->config_section));
FILE *fp = fopen(path, "r");
if (fp != NULL) {
char buf[512] = {0};
strcpy(status, "NO_ERROR");
strcpy(last_err, "NO_ERROR");
while (fgets(buf, 512, fp) != NULL) {
if (strstr(buf, "ERROR") && strstr(buf, "Please check your configuration"))
strcpy(status, "MISCONFIGURATION_ERROR");
strcpy(last_err, "MISCONFIGURATION_ERROR");
else if (strstr(buf, "NO valid IP found"))
strcpy(status, "DNS_ERROR");
strcpy(last_err, "DNS_ERROR");
else if (strstr(buf, "Authentication Failed"))
strcpy(status, "AUTHENTICATION_ERROR");
strcpy(last_err, "AUTHENTICATION_ERROR");
else if (strstr(buf, "Transfer failed") || (strstr(buf, "WARN") && strstr(buf, "failed")))
strcpy(status, "CONNECTION_ERROR");
strcpy(last_err, "CONNECTION_ERROR");
else if (strstr(buf, "Registered IP") || strstr(buf, "Update successful"))
strcpy(status, "NO_ERROR");
strcpy(last_err, "NO_ERROR");
}
fclose(fp);
} else
strcpy(status, "MISCONFIGURATION_ERROR");
strcpy(last_err, "MISCONFIGURATION_ERROR");
}
*value = dmstrdup(status);
*value = dmstrdup(last_err);
return 0;
}
@ -468,7 +426,7 @@ static int get_DynamicDNSClient_LastError(char *refparam, struct dmctx *ctx, voi
static int get_DynamicDNSClient_Server(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *service_name;
dmuci_get_value_by_section_string((struct uci_section *)data, "service_name", &service_name);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "service_name", &service_name);
adm_entry_get_linker_param(ctx, "Device.DynamicDNS.Server.", service_name, value);
if (*value == NULL)
*value = "";
@ -487,7 +445,7 @@ static int set_DynamicDNSClient_Server(char *refparam, struct dmctx *ctx, void *
case VALUESET:
adm_entry_get_linker_value(ctx, value, &linker);
if (linker && *linker) {
dmuci_set_value_by_section((struct uci_section *)data, "service_name", linker);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "service_name", linker);
dmfree(linker);
}
break;
@ -499,7 +457,7 @@ static int set_DynamicDNSClient_Server(char *refparam, struct dmctx *ctx, void *
static int get_DynamicDNSClient_Interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *interface;
dmuci_get_value_by_section_string((struct uci_section *)data, "interface", &interface);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "interface", &interface);
adm_entry_get_linker_param(ctx, "Device.IP.Interface.", interface, value);
if (*value == NULL)
*value = "";
@ -518,7 +476,7 @@ static int set_DynamicDNSClient_Interface(char *refparam, struct dmctx *ctx, voi
case VALUESET:
adm_entry_get_linker_value(ctx, value, &linker);
if (linker && *linker) {
dmuci_set_value_by_section((struct uci_section *)data, "interface", linker);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "interface", linker);
dmfree(linker);
}
break;
@ -529,7 +487,7 @@ static int set_DynamicDNSClient_Interface(char *refparam, struct dmctx *ctx, voi
/*#Device.DynamicDNS.Client.{i}.Username!UCI:ddns/service,@i-1/username*/
static int get_DynamicDNSClient_Username(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string((struct uci_section *)data, "username", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "username", value);
return 0;
}
@ -541,7 +499,7 @@ static int set_DynamicDNSClient_Username(char *refparam, struct dmctx *ctx, void
return FAULT_9007;
break;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "username", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "username", value);
break;
}
return 0;
@ -562,7 +520,7 @@ static int set_DynamicDNSClient_Password(char *refparam, struct dmctx *ctx, void
return FAULT_9007;
break;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "password", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "password", value);
break;
}
return 0;
@ -577,7 +535,7 @@ static int get_DynamicDNSClient_HostnameNumberOfEntries(char *refparam, struct d
/*#Device.DynamicDNS.Client.{i}.Hostname.{i}.Enable!UCI:ddns/service,@i-1/enabled*/
static int get_DynamicDNSClientHostname_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "enabled", "0");
*value = dmuci_get_value_by_section_fallback_def(((struct dmmap_dup *)data)->config_section, "enabled", "0");
return 0;
}
@ -592,7 +550,7 @@ static int set_DynamicDNSClientHostname_Enable(char *refparam, struct dmctx *ctx
break;
case VALUESET:
string_to_bool(value, &b);
dmuci_set_value_by_section((struct uci_section *)data, "enabled", b ? "1" : "0");
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "enabled", b ? "1" : "0");
break;
}
return 0;
@ -603,14 +561,14 @@ static int get_DynamicDNSClientHostname_Status(char *refparam, struct dmctx *ctx
{
char status[32] = {0}, *enable = NULL;
dmuci_get_value_by_section_string((struct uci_section *)data, "enabled", &enable);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "enabled", &enable);
if (enable && (*enable == '\0' || strcmp(enable, "0") == 0)) {
strcpy(status, "Disabled");
} else {
char path[128] = {0}, *logdir = NULL;
dmuci_get_option_value_string("ddns", "global", "ddns_logdir", &logdir);
snprintf(path, sizeof(path), "%s/%s.log", (logdir && *logdir) ? logdir : "/var/log/ddns", section_name((struct uci_section *)data));
snprintf(path, sizeof(path), "%s/%s.log", (logdir && *logdir) ? logdir : "/var/log/ddns", section_name(((struct dmmap_dup *)data)->config_section));
FILE *fp = fopen(path, "r");
if (fp != NULL) {
char buf[512] = {0};
@ -635,7 +593,7 @@ static int get_DynamicDNSClientHostname_Status(char *refparam, struct dmctx *ctx
/*#Device.DynamicDNS.Client.{i}.Hostname.{i}.Name!UCI:ddns/service,@i-1/domain*/
static int get_DynamicDNSClientHostname_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string((struct uci_section *)data, "domain", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "domain", value);
return 0;
}
@ -647,8 +605,8 @@ static int set_DynamicDNSClientHostname_Name(char *refparam, struct dmctx *ctx,
return FAULT_9007;
break;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "domain", value);
dmuci_set_value_by_section((struct uci_section *)data, "lookup_host", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "domain", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "lookup_host", value);
break;
}
return 0;
@ -666,7 +624,7 @@ static int get_DynamicDNSClientHostname_LastUpdate(char *refparam, struct dmctx
dmuci_get_option_value_string("ddns", "global", "ddns_rundir", &rundir);
if (*rundir == '\0')
rundir = "/var/run/ddns";
snprintf(path, sizeof(path), "%s/%s.update", rundir, section_name((struct uci_section *)data));
snprintf(path, sizeof(path), "%s/%s.update", rundir, section_name(((struct dmmap_dup *)data)->config_section));
fp = fopen(path, "r");
if (fp != NULL) {
@ -1057,6 +1015,9 @@ static int set_DynamicDNSServer_MaxRetries(char *refparam, struct dmctx *ctx, vo
return 0;
}
/**********************************************************************************************************************************
* OBJ & PARAM DEFINITION
***********************************************************************************************************************************/
/* *** Device.DynamicDNS. *** */
DMOBJ tDynamicDNSObj[] = {
/* OBJ, permission, addobj, delobj, checkdep, browseinstobj, nextdynamicobj, dynamicleaf, nextobj, leaf, linker, bbfdm_type, uniqueKeys*/

View file

@ -15,29 +15,29 @@
struct eth_port_args
{
struct uci_section *eth_port_sec;
struct dmmap_dup *sections;
char *ifname;
};
struct eth_rmon_args
{
struct uci_section *eth_rmon_sec;
struct dmmap_dup *sections;
json_object *eth_rmon_obj;
};
/*************************************************************
* INIT
**************************************************************/
static inline int init_eth_port(struct eth_port_args *args, struct uci_section *s, char *ifname)
static inline int init_eth_port(struct eth_port_args *args, struct dmmap_dup *s, char *ifname)
{
args->eth_port_sec = s;
args->sections = s;
args->ifname = ifname;
return 0;
}
static inline int init_eth_rmon(struct eth_rmon_args *args, struct uci_section *s, json_object *obj)
static inline int init_eth_rmon(struct eth_rmon_args *args, struct dmmap_dup *s, json_object *obj)
{
args->eth_rmon_sec = s;
args->sections = s;
args->eth_rmon_obj = obj;
return 0;
}
@ -223,35 +223,13 @@ static int dmmap_synchronizeEthernetLink(struct dmctx *dmctx, DMNODE *parent_nod
return 0;
}
static char *get_vlan_last_instance_bbfdm(char *package, char *section, char *opt_inst)
{
struct uci_section *s = NULL, *confsect;
char *inst = NULL, *last_inst = NULL, *type, *sect_name, *name;
uci_path_foreach_sections(bbfdm, package, section, s) {
dmuci_get_value_by_section_string(s, "section_name", &sect_name);
get_config_section_of_dmmap_section("network", "device", sect_name, &confsect);
dmuci_get_value_by_section_string(confsect, "type", &type);
dmuci_get_value_by_section_string(confsect, "name", &name);
if (strcmp(type, "bridge") == 0 || strcmp(type, "untagged") == 0) {
dmuci_set_value_by_section(s, "vlan_term_instance", "");
continue;
}
inst = update_instance(last_inst, 2, s, opt_inst);
if(last_inst)
dmfree(last_inst);
last_inst = dmstrdup(inst);
}
return inst;
}
/*************************************************************
* ENTRY METHOD
**************************************************************/
/*#Device.Ethernet.Interface.{i}.!UCI:ports/ethport/dmmap_ports*/
static int browseEthernetInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *max_inst = NULL, *ifname;
char *inst = NULL, *ifname;
struct eth_port_args curr_eth_port_args = {0};
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
@ -261,10 +239,9 @@ static int browseEthernetInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node,
dmuci_get_value_by_section_string(p->config_section, "ifname", &ifname);
init_eth_port(&curr_eth_port_args, p->config_section, ifname);
init_eth_port(&curr_eth_port_args, p, ifname);
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
p->dmmap_section, "eth_port_instance", "eth_port_alias");
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "eth_port_instance", "eth_port_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_eth_port_args, inst) == DM_STOP)
break;
@ -276,13 +253,12 @@ static int browseEthernetInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node,
static int browseEthernetLinkInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct uci_section *s = NULL;
char *inst = NULL, *max_inst = NULL;
char *inst = NULL;
dmmap_synchronizeEthernetLink(dmctx, NULL, NULL, NULL);
uci_path_foreach_sections(bbfdm, DMMAP, "link", s) {
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
s, "link_instance", "link_alias");
inst = handle_instance(dmctx, parent_node, s, "link_instance", "link_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)s, inst) == DM_STOP)
break;
@ -293,7 +269,7 @@ static int browseEthernetLinkInst(struct dmctx *dmctx, DMNODE *parent_node, void
/*#Device.Ethernet.VLANTermination.{i}.!UCI:network/device/dmmap_network*/
static int browseEthernetVLANTerminationInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *type, *name, *inst = NULL, *max_inst = NULL;
char *type, *name, *inst = NULL;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
@ -305,10 +281,9 @@ static int browseEthernetVLANTerminationInst(struct dmctx *dmctx, DMNODE *parent
if (strcmp(type, "bridge") == 0 || strcmp(type, "untagged") == 0)
continue;
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
p->dmmap_section, "vlan_term_instance", "vlan_term_alias");
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "vlan_term_instance", "vlan_term_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, inst) == DM_STOP)
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p, inst) == DM_STOP)
break;
}
free_dmmap_config_dup_list(&dup_list);
@ -317,7 +292,7 @@ static int browseEthernetVLANTerminationInst(struct dmctx *dmctx, DMNODE *parent
static int browseEthernetRMONStatsInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *max_inst = NULL, *ifname;
char *inst = NULL, *ifname;
struct eth_rmon_args curr_eth_rmon_args = {0};
struct dmmap_dup *p = NULL;
json_object *res = NULL;
@ -331,10 +306,9 @@ static int browseEthernetRMONStatsInst(struct dmctx *dmctx, DMNODE *parent_node,
dmubus_call("ethernet", "rmonstats", UBUS_ARGS{{"ifname", ifname, String}}, 1, &res);
if (!res) continue;
init_eth_rmon(&curr_eth_rmon_args, p->config_section, res);
init_eth_rmon(&curr_eth_rmon_args, p, res);
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
p->dmmap_section, "eth_rmon_instance", "eth_rmon_alias");
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "eth_rmon_instance", "eth_rmon_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_eth_rmon_args, inst) == DM_STOP)
break;
@ -365,7 +339,7 @@ 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 uci_section *)data, "name", linker);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "name", linker);
return 0;
}
@ -377,8 +351,7 @@ static int addObjEthernetLink(char *refparam, struct dmctx *ctx, void *data, cha
struct uci_section *s = NULL, *dmmap_link = NULL;
char interface_name[32];
char *inst = get_last_instance_bbfdm(DMMAP, "link", "link_instance");
snprintf(interface_name, sizeof(interface_name), "link_%d", inst ? atoi(inst)+1 : 1);
snprintf(interface_name, sizeof(interface_name), "link_%s", *instance);
/* Add device section */
dmuci_add_section("network", "interface", &s);
@ -387,7 +360,7 @@ static int addObjEthernetLink(char *refparam, struct dmctx *ctx, void *data, cha
/* Add link section in dmmap file */
dmuci_add_section_bbfdm(DMMAP, "link", &dmmap_link);
dmuci_set_value_by_section(dmmap_link, "section_name", interface_name);
*instance = update_instance(inst, 2, dmmap_link, "link_instance");
dmuci_set_value_by_section(dmmap_link, "link_instance", *instance);
return 0;
}
@ -438,8 +411,7 @@ static int addObjEthernetVLANTermination(char *refparam, struct dmctx *ctx, void
struct uci_section *s = NULL, *dmmap_network = NULL;
char device_name[32];
char *inst = get_vlan_last_instance_bbfdm("dmmap_network", "device", "vlan_term_instance");
snprintf(device_name, sizeof(device_name), "vlan_ter_%d", inst ? atoi(inst)+1 : 1);
snprintf(device_name, sizeof(device_name), "vlan_ter_%s", *instance);
// Add device section
dmuci_add_section("network", "device", &s);
@ -449,26 +421,27 @@ 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);
*instance = update_instance(inst, 2, dmmap_network, "vlan_term_instance");
dmuci_set_value_by_section(dmmap_network, "vlan_term_instance", *instance);
return 0;
}
static int delObjEthernetVLANTermination(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
struct uci_section *dmmap_section = NULL, *s_dev = NULL, *sdevtmp = NULL;
struct uci_section *s_dev = NULL, *sdevtmp = NULL;
char *name, *type;
switch (del_action) {
case DEL_INST:
// Remove device section
dmuci_delete_by_section((struct uci_section *)data, NULL, NULL);
dmuci_delete_by_section(((struct dmmap_dup *)data)->config_section, NULL, NULL);
// Remove device section in dmmap_network file
get_dmmap_section_of_config_section("dmmap_network", "device", section_name((struct uci_section *)data), &dmmap_section);
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(((struct dmmap_dup *)data)->dmmap_section, NULL, NULL);
break;
case DEL_ALL:
uci_foreach_sections_safe("network", "device", sdevtmp, s_dev) {
struct uci_section *dmmap_section = NULL;
dmuci_get_value_by_section_string(s_dev, "type", &type);
dmuci_get_value_by_section_string(s_dev, "name", &name);
if (strcmp(type, "bridge") == 0 || strcmp(type, "untagged") == 0)
@ -492,25 +465,14 @@ static int delObjEthernetVLANTermination(char *refparam, struct dmctx *ctx, void
/*#Device.Ethernet.InterfaceNumberOfEntries!UCI:ports/ethport/*/
static int get_Ethernet_InterfaceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s = NULL;
int cnt = 0;
uci_foreach_sections("ports", "ethport", s) {
cnt++;
}
int cnt = get_number_of_entries(ctx, data, instance, browseEthernetInterfaceInst);
dmasprintf(value, "%d", cnt);
return 0;
}
static int get_Ethernet_LinkNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s = NULL;
int cnt = 0;
dmmap_synchronizeEthernetLink(ctx, NULL, NULL, NULL);
uci_path_foreach_sections(bbfdm, DMMAP, "link", s) {
cnt++;
}
int cnt = get_number_of_entries(ctx, data, instance, browseEthernetLinkInst);
dmasprintf(value, "%d", cnt);
return 0;
}
@ -518,34 +480,14 @@ static int get_Ethernet_LinkNumberOfEntries(char *refparam, struct dmctx *ctx, v
/*#Device.Ethernet.VLANTerminationNumberOfEntries!UCI:network/device/*/
static int get_Ethernet_VLANTerminationNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s = NULL;
char *type, *name;
int cnt = 0;
uci_foreach_sections("network", "device", s) {
dmuci_get_value_by_section_string(s, "type", &type);
dmuci_get_value_by_section_string(s, "name", &name);
if (strcmp(type, "bridge") == 0 || strcmp(type, "untagged") == 0)
continue;
cnt++;
}
int cnt = get_number_of_entries(ctx, data, instance, browseEthernetVLANTerminationInst);
dmasprintf(value, "%d", cnt);
return 0;
}
static int get_Ethernet_RMONStatsNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s = NULL;
json_object *res = NULL;
char *ifname;
int cnt = 0;
uci_foreach_sections("ports", "ethport", s) {
dmuci_get_value_by_section_string(s, "ifname", &ifname);
dmubus_call("ethernet", "rmonstats", UBUS_ARGS{{"ifname", ifname, String}}, 1, &res);
if (!res) continue;
cnt++;
}
int cnt = get_number_of_entries(ctx, data, instance, browseEthernetRMONStatsInst);
dmasprintf(value, "%d", cnt);
return 0;
}
@ -553,7 +495,7 @@ static int get_Ethernet_RMONStatsNumberOfEntries(char *refparam, struct dmctx *c
/*#Device.Ethernet.Interface.{i}.Enable!UCI:ports/ethport,@i-1/enabled*/
static int get_EthernetInterface_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmuci_get_value_by_section_fallback_def(((struct eth_port_args *)data)->eth_port_sec, "enabled", "1");
*value = dmuci_get_value_by_section_fallback_def((((struct eth_port_args *)data)->sections)->config_section, "enabled", "1");
return 0;
}
@ -568,7 +510,7 @@ static int set_EthernetInterface_Enable(char *refparam, struct dmctx *ctx, void
return 0;
case VALUESET:
string_to_bool(value, &b);
dmuci_set_value_by_section(((struct eth_port_args *)data)->eth_port_sec, "enabled", b ? "1" : "0");
dmuci_set_value_by_section((((struct eth_port_args *)data)->sections)->config_section, "enabled", b ? "1" : "0");
return 0;
}
return 0;
@ -583,29 +525,23 @@ static int get_EthernetInterface_Status(char *refparam, struct dmctx *ctx, void
/*#Device.Ethernet.Interface.{i}.Alias!UCI:dmmap_ports/ethport,@i-1/eth_port_alias*/
static int get_EthernetInterface_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *dmmap_section = NULL;
get_dmmap_section_of_config_section("dmmap_ports", "ethport", section_name(((struct eth_port_args *)data)->eth_port_sec), &dmmap_section);
dmuci_get_value_by_section_string(dmmap_section, "eth_port_alias", value);
dmuci_get_value_by_section_string((((struct eth_port_args *)data)->sections)->dmmap_section, "eth_port_alias", value);
if ((*value)[0] == '\0') {
dmuci_get_value_by_section_string(((struct eth_port_args *)data)->eth_port_sec, "name", value);
dmuci_set_value_by_section(dmmap_section, "eth_port_alias", *value);
dmuci_get_value_by_section_string((((struct eth_port_args *)data)->sections)->config_section, "name", value);
dmuci_set_value_by_section((((struct eth_port_args *)data)->sections)->dmmap_section, "eth_port_alias", *value);
}
return 0;
}
static int set_EthernetInterface_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *dmmap_section = NULL;
switch (action) {
case VALUECHECK:
if (dm_validate_string(value, -1, 64, NULL, NULL))
return FAULT_9007;
return 0;
case VALUESET:
get_dmmap_section_of_config_section("dmmap_ports", "ethport", section_name(((struct eth_port_args *)data)->eth_port_sec), &dmmap_section);
dmuci_set_value_by_section(dmmap_section, "eth_port_alias", value);
dmuci_set_value_by_section((((struct eth_port_args *)data)->sections)->dmmap_section, "eth_port_alias", value);
return 0;
}
return 0;
@ -614,7 +550,7 @@ static int set_EthernetInterface_Alias(char *refparam, struct dmctx *ctx, void *
/*#Device.Ethernet.Interface.{i}.Name!UCI:ports/ethport,@i-1/ifname*/
static int get_EthernetInterface_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string(((struct eth_port_args *)data)->eth_port_sec, "ifname", value);
dmuci_get_value_by_section_string((((struct eth_port_args *)data)->sections)->config_section, "ifname", value);
return 0;
}
@ -666,7 +602,7 @@ static int set_EthernetInterface_LowerLayers(char *refparam, struct dmctx *ctx,
/*#Device.Ethernet.Interface.{i}.Upstream!UCI:ports/ethport,@i-1/uplink*/
static int get_EthernetInterface_Upstream(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmuci_get_value_by_section_fallback_def(((struct eth_port_args *)data)->eth_port_sec, "uplink", "0");
*value = dmuci_get_value_by_section_fallback_def((((struct eth_port_args *)data)->sections)->config_section, "uplink", "0");
return 0;
}
@ -681,10 +617,10 @@ static int get_EthernetInterface_MaxBitRate(char *refparam, struct dmctx *ctx, v
{
char *autoneg = NULL;
dmuci_get_value_by_section_string(((struct eth_port_args *)data)->eth_port_sec, "autoneg", &autoneg);
dmuci_get_value_by_section_string((((struct eth_port_args *)data)->sections)->config_section, "autoneg", &autoneg);
if (autoneg && strcmp(autoneg, "0") == 0)
dmuci_get_value_by_section_string(((struct eth_port_args *)data)->eth_port_sec, "speed", value);
dmuci_get_value_by_section_string((((struct eth_port_args *)data)->sections)->config_section, "speed", value);
else
*value = "-1";
@ -700,10 +636,10 @@ static int set_EthernetInterface_MaxBitRate(char *refparam, struct dmctx *ctx, v
return 0;
case VALUESET:
if (strcmp(value, "-1") == 0)
dmuci_set_value_by_section(((struct eth_port_args *)data)->eth_port_sec, "autoneg", "1");
dmuci_set_value_by_section((((struct eth_port_args *)data)->sections)->config_section, "autoneg", "1");
else {
dmuci_set_value_by_section(((struct eth_port_args *)data)->eth_port_sec, "autoneg", "0");
dmuci_set_value_by_section(((struct eth_port_args *)data)->eth_port_sec, "speed", value);
dmuci_set_value_by_section((((struct eth_port_args *)data)->sections)->config_section, "autoneg", "0");
dmuci_set_value_by_section((((struct eth_port_args *)data)->sections)->config_section, "speed", value);
}
return 0;
}
@ -729,12 +665,12 @@ static int get_EthernetInterface_DuplexMode(char *refparam, struct dmctx *ctx, v
{
char *autoneg = NULL;
dmuci_get_value_by_section_string(((struct eth_port_args *)data)->eth_port_sec, "autoneg", &autoneg);
dmuci_get_value_by_section_string((((struct eth_port_args *)data)->sections)->config_section, "autoneg", &autoneg);
if (autoneg && strcmp(autoneg, "0") == 0) {
char *duplex = NULL;
dmuci_get_value_by_section_string(((struct eth_port_args *)data)->eth_port_sec, "duplex", &duplex);
dmuci_get_value_by_section_string((((struct eth_port_args *)data)->sections)->config_section, "duplex", &duplex);
*value = (duplex && strcmp(duplex, "full") == 0) ? "Full" : "Half";
} else {
*value = "Auto";
@ -751,10 +687,10 @@ static int set_EthernetInterface_DuplexMode(char *refparam, struct dmctx *ctx, v
return 0;
case VALUESET:
if (strcmp(value, "Auto") == 0)
dmuci_set_value_by_section(((struct eth_port_args *)data)->eth_port_sec, "autoneg", "1");
dmuci_set_value_by_section((((struct eth_port_args *)data)->sections)->config_section, "autoneg", "1");
else {
dmuci_set_value_by_section(((struct eth_port_args *)data)->eth_port_sec, "autoneg", "0");
dmuci_set_value_by_section(((struct eth_port_args *)data)->eth_port_sec, "duplex", (*value == 'F') ? "full" : "half");
dmuci_set_value_by_section((((struct eth_port_args *)data)->sections)->config_section, "autoneg", "0");
dmuci_set_value_by_section((((struct eth_port_args *)data)->sections)->config_section, "duplex", (*value == 'F') ? "full" : "half");
}
return 0;
}
@ -770,7 +706,7 @@ static int get_EthernetInterface_EEECapability(char *refparam, struct dmctx *ctx
/*#Device.Ethernet.Interface.{i}.EEEEnable!UCI:ports/ethport,@i-1/eee*/
static int get_EthernetInterface_EEEEnable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmuci_get_value_by_section_fallback_def(((struct eth_port_args *)data)->eth_port_sec, "eee", "1");
*value = dmuci_get_value_by_section_fallback_def((((struct eth_port_args *)data)->sections)->config_section, "eee", "1");
return 0;
}
@ -785,7 +721,7 @@ static int set_EthernetInterface_EEEEnable(char *refparam, struct dmctx *ctx, vo
break;
case VALUESET:
string_to_bool(value, &b);
dmuci_set_value_by_section(((struct eth_port_args *)data)->eth_port_sec, "eee", b ? "1" : "0");
dmuci_set_value_by_section((((struct eth_port_args *)data)->sections)->config_section, "eee", b ? "1" : "0");
break;
}
return 0;
@ -1202,10 +1138,7 @@ static int get_EthernetVLANTermination_Status(char *refparam, struct dmctx *ctx,
/*#Device.Ethernet.VLANTermination.{i}.Alias!UCI:dmmap_network/device,@i-1/vlan_term_alias*/
static int get_EthernetVLANTermination_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *dmmap_section = NULL;
get_dmmap_section_of_config_section("dmmap_network", "device", section_name((struct uci_section *)data), &dmmap_section);
dmuci_get_value_by_section_string(dmmap_section, "vlan_term_alias", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->dmmap_section, "vlan_term_alias", value);
if ((*value)[0] == '\0')
dmasprintf(value, "cpe-%s", instance);
return 0;
@ -1213,16 +1146,13 @@ static int get_EthernetVLANTermination_Alias(char *refparam, struct dmctx *ctx,
static int set_EthernetVLANTermination_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *dmmap_section = NULL;
switch (action) {
case VALUECHECK:
if (dm_validate_string(value, -1, 64, NULL, NULL))
return FAULT_9007;
return 0;
case VALUESET:
get_dmmap_section_of_config_section("dmmap_network", "device", section_name((struct uci_section *)data), &dmmap_section);
dmuci_set_value_by_section(dmmap_section, "vlan_term_alias", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->dmmap_section, "vlan_term_alias", value);
return 0;
}
return 0;
@ -1230,7 +1160,7 @@ static int set_EthernetVLANTermination_Alias(char *refparam, struct dmctx *ctx,
static int get_EthernetVLANTermination_Name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmstrdup(section_name((struct uci_section *)data));
*value = dmstrdup(section_name(((struct dmmap_dup *)data)->config_section));
return 0;
}
@ -1242,7 +1172,7 @@ static int get_EthernetVLANTermination_LastChange(char *refparam, struct dmctx *
char *devname;
*value = "0";
dmuci_get_value_by_section_string((struct uci_section *)data, "name", &devname);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "name", &devname);
uci_foreach_option_eq("network", "interface", "device", devname, s) {
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(s), String}}, 1, &res);
DM_ASSERT(res, *value = "0");
@ -1258,14 +1188,14 @@ static int get_EthernetVLANTermination_LowerLayers(char *refparam, struct dmctx
{
char *name, *type, *inner_vid, *dev_name;
dmuci_get_value_by_section_string((struct uci_section *)data, "name", &name);
dmuci_get_value_by_section_string((struct uci_section *)data, "type", &type);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "name", &name);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "type", &type);
char *vid = strchr(name, '.');
if (vid) *vid = '\0';
if (strncmp(type, "8021ad", 6) == 0) {
// 8021ad device, will have a vlan termination object as its lowerlayer
dmuci_get_value_by_section_string((struct uci_section *)data, "inner_vid", &inner_vid);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "inner_vid", &inner_vid);
dmasprintf(&dev_name, "%s.%s", name, inner_vid);
adm_entry_get_linker_param(ctx, "Device.Ethernet.VLANTermination.", dev_name, value);
} else {
@ -1295,7 +1225,7 @@ static int set_EthernetVLANTermination_LowerLayers(char *refparam, struct dmctx
char new_name[16] = {0}, *type;
// Get type option from device section
dmuci_get_value_by_section_string((struct uci_section *)data, "type", &type);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "type", &type);
if ((strcmp(type, "macvlan") == 0)) {
/* type == macvlan */
@ -1324,8 +1254,8 @@ static int set_EthernetVLANTermination_LowerLayers(char *refparam, struct dmctx
struct uci_section *s = NULL;
char *vid, *old_name;
dmuci_get_value_by_section_string((struct uci_section *)data, "name", &old_name);
dmuci_get_value_by_section_string((struct uci_section *)data, "vid", &vid);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "name", &old_name);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "vid", &vid);
if (*vid != '\0')
snprintf(new_name, sizeof(new_name), "%s.%s", vlan_linker, vid);
else
@ -1343,14 +1273,14 @@ static int set_EthernetVLANTermination_LowerLayers(char *refparam, struct dmctx
}
// Set ifname and name options of device section
dmuci_set_value_by_section((struct uci_section *)data, "ifname", vlan_linker);
dmuci_set_value_by_section((struct uci_section *)data, "name", new_name);
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);
} else if (strncmp(value, "Device.Ethernet.VLANTermination.", 32) == 0) {
struct uci_section *ss = NULL;
char *dev_name, *inner_vid, *vid, new_name[16] = {0};
dmuci_get_value_by_section_string((struct uci_section *)data, "vid", &vid);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "vid", &vid);
uci_foreach_option_eq("network", "device", "name", vlan_linker, ss) {
dmuci_get_value_by_section_string(ss, "vid", &inner_vid);
@ -1361,9 +1291,9 @@ static int set_EthernetVLANTermination_LowerLayers(char *refparam, struct dmctx
if (ethernet_name_exists_in_devices(new_name))
return -1;
dmuci_set_value_by_section((struct uci_section *)data, "ifname", dev_name);
dmuci_set_value_by_section((struct uci_section *)data, "name", new_name);
dmuci_set_value_by_section((struct uci_section *)data, "inner_vid", inner_vid);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "ifname", dev_name);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "name", new_name);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "inner_vid", inner_vid);
}
break;
}
@ -1373,7 +1303,7 @@ static int set_EthernetVLANTermination_LowerLayers(char *refparam, struct dmctx
/*#Device.Ethernet.VLANTermination.{i}.VLANID!UCI:network/device,@i-1/vid*/
static int get_EthernetVLANTermination_VLANID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "vid", "1");
*value = dmuci_get_value_by_section_fallback_def(((struct dmmap_dup *)data)->config_section, "vid", "1");
return 0;
}
@ -1390,18 +1320,18 @@ static int set_EthernetVLANTermination_VLANID(char *refparam, struct dmctx *ctx,
return 0;
case VALUESET:
// Get type option from device section
dmuci_get_value_by_section_string((struct uci_section *)data, "type", &type);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "type", &type);
if (strcmp(type, "macvlan") != 0) {
/* only when type != macvlan */
dmuci_get_value_by_section_string((struct uci_section *)data, "ifname", &ifname);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "ifname", &ifname);
if (*ifname != '\0') {
if (strcmp(type, "8021ad") == 0) {
dmuci_get_value_by_section_string((struct uci_section *)data, "inner_vid", &inner_vid);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "inner_vid", &inner_vid);
dmasprintf(&name, "%s.%s.%s", ifname, inner_vid, value);
} else {
dmuci_get_value_by_section_string((struct uci_section *)data, "vid", &old_vid);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "vid", &old_vid);
dmasprintf(&old_name, "%s.%s.", ifname, old_vid);
dmasprintf(&name, "%s.%s", ifname, value);
}
@ -1410,7 +1340,7 @@ static int set_EthernetVLANTermination_VLANID(char *refparam, struct dmctx *ctx,
return -1;
// set ifname option of the corresponding interface section
dmuci_get_value_by_section_string((struct uci_section *)data, "name", &curr_ifname);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "name", &curr_ifname);
uci_foreach_option_eq("network", "interface", "device", curr_ifname, s) {
dmuci_set_value_by_section(s, "device", name);
}
@ -1440,13 +1370,13 @@ static int set_EthernetVLANTermination_VLANID(char *refparam, struct dmctx *ctx,
}
// set name option of the device section
dmuci_set_value_by_section((struct uci_section *)data, "name", name);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "name", name);
dmfree(name);
}
}
// set vid option of the device section
dmuci_set_value_by_section((struct uci_section *)data, "vid", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "vid", value);
return 0;
}
return 0;
@ -1455,7 +1385,7 @@ static int set_EthernetVLANTermination_VLANID(char *refparam, struct dmctx *ctx,
/*#Device.Ethernet.VLANTermination.{i}.TPID!UCI:network/device,@i-1/type*/
static int get_EthernetVLANTermination_TPID(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string((struct uci_section *)data, "type", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "type", value);
if (strcmp(*value, "8021q") == 0)
*value = "33024";
else if (strcmp(*value, "8021ad") == 0)
@ -1474,9 +1404,9 @@ static int set_EthernetVLANTermination_TPID(char *refparam, struct dmctx *ctx, v
return 0;
case VALUESET:
if (strcmp(value, "33024") == 0)
dmuci_set_value_by_section((struct uci_section *)data, "type", "8021q");
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "type", "8021q");
else if (strcmp(value, "34984") == 0)
dmuci_set_value_by_section((struct uci_section *)data, "type", "8021ad");
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "type", "8021ad");
return 0;
}
return 0;
@ -1485,61 +1415,61 @@ static int set_EthernetVLANTermination_TPID(char *refparam, struct dmctx *ctx, v
/*#Device.Ethernet.VLANTermination.{i}.Stats.BytesSent!SYSFS:/sys/class/net/@Name/statistics/tx_bytes*/
static int get_EthernetVLANTerminationStats_BytesSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return eth_iface_sysfs(data, "statistics/tx_bytes", value);
return eth_iface_sysfs(((struct dmmap_dup *)data)->config_section, "statistics/tx_bytes", value);
}
/*#Device.Ethernet.VLANTermination.{i}.Stats.BytesReceived!SYSFS:/sys/class/net/@Name/statistics/rx_bytes*/
static int get_EthernetVLANTerminationStats_BytesReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return eth_iface_sysfs(data, "statistics/rx_bytes", value);
return eth_iface_sysfs(((struct dmmap_dup *)data)->config_section, "statistics/rx_bytes", value);
}
/*#Device.Ethernet.VLANTermination.{i}.Stats.PacketsSent!SYSFS:/sys/class/net/@Name/statistics/tx_packets*/
static int get_EthernetVLANTerminationStats_PacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return eth_iface_sysfs(data, "statistics/tx_packets", value);
return eth_iface_sysfs(((struct dmmap_dup *)data)->config_section, "statistics/tx_packets", value);
}
/*#Device.Ethernet.VLANTermination.{i}.Stats.PacketsReceived!SYSFS:/sys/class/net/@Name/statistics/rx_packets*/
static int get_EthernetVLANTerminationStats_PacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return eth_iface_sysfs(data, "statistics/rx_packets", value);
return eth_iface_sysfs(((struct dmmap_dup *)data)->config_section, "statistics/rx_packets", value);
}
/*#Device.Ethernet.VLANTermination.{i}.Stats.ErrorsSent!SYSFS:/sys/class/net/@Name/statistics/tx_errors*/
static int get_EthernetVLANTerminationStats_ErrorsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return eth_iface_sysfs(data, "statistics/tx_errors", value);
return eth_iface_sysfs(((struct dmmap_dup *)data)->config_section, "statistics/tx_errors", value);
}
/*#Device.Ethernet.VLANTermination.{i}.Stats.ErrorsReceived!SYSFS:/sys/class/net/@Name/statistics/rx_errors*/
static int get_EthernetVLANTerminationStats_ErrorsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return eth_iface_sysfs(data, "statistics/rx_errors", value);
return eth_iface_sysfs(((struct dmmap_dup *)data)->config_section, "statistics/rx_errors", value);
}
/*#Device.Ethernet.VLANTermination.{i}.Stats.DiscardPacketsSent!SYSFS:/sys/class/net/@Name/statistics/tx_dropped*/
static int get_EthernetVLANTerminationStats_DiscardPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return eth_iface_sysfs(data, "statistics/tx_dropped", value);
return eth_iface_sysfs(((struct dmmap_dup *)data)->config_section, "statistics/tx_dropped", value);
}
/*#Device.Ethernet.VLANTermination.{i}.Stats.DiscardPacketsReceived!SYSFS:/sys/class/net/@Name/statistics/rx_dropped*/
static int get_EthernetVLANTerminationStats_DiscardPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return eth_iface_sysfs(data, "statistics/rx_dropped", value);
return eth_iface_sysfs(((struct dmmap_dup *)data)->config_section, "statistics/rx_dropped", value);
}
/*#Device.Ethernet.VLANTermination.{i}.Stats.MulticastPacketsReceived!SYSFS:/sys/class/net/@Name/statistics/multicast*/
static int get_EthernetVLANTerminationStats_MulticastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return eth_iface_sysfs(data, "statistics/multicast", value);
return eth_iface_sysfs(((struct dmmap_dup *)data)->config_section, "statistics/multicast", value);
}
/*#Device.Ethernet.RMONStats.{i}.Enable!UCI:ports/ethport,@i-1/rmon*/
static int get_EthernetRMONStats_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmuci_get_value_by_section_fallback_def(((struct eth_rmon_args *)data)->eth_rmon_sec, "rmon", "1");
*value = dmuci_get_value_by_section_fallback_def((((struct eth_rmon_args *)data)->sections)->config_section, "rmon", "1");
return 0;
}
@ -1554,7 +1484,7 @@ static int set_EthernetRMONStats_Enable(char *refparam, struct dmctx *ctx, void
break;
case VALUESET:
string_to_bool(value, &b);
dmuci_set_value_by_section(((struct eth_rmon_args *)data)->eth_rmon_sec, "rmon", b ? "1" : "0");
dmuci_set_value_by_section((((struct eth_rmon_args *)data)->sections)->config_section, "rmon", b ? "1" : "0");
break;
}
return 0;
@ -1570,10 +1500,7 @@ static int get_EthernetRMONStats_Status(char *refparam, struct dmctx *ctx, void
/*#Device.Ethernet.RMONStats.{i}.Alias!UCI:dmmap_eth_rmon/ethport,@i-1/eth_rmon_alias*/
static int get_EthernetRMONStats_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *dmmap_section = NULL;
get_dmmap_section_of_config_section("dmmap_eth_rmon", "ethport", section_name(((struct eth_rmon_args *)data)->eth_rmon_sec), &dmmap_section);
dmuci_get_value_by_section_string(dmmap_section, "eth_rmon_alias", value);
dmuci_get_value_by_section_string((((struct eth_rmon_args *)data)->sections)->dmmap_section, "eth_rmon_alias", value);
if ((*value)[0] == '\0')
dmasprintf(value, "cpe-%s", instance);
return 0;
@ -1581,16 +1508,13 @@ static int get_EthernetRMONStats_Alias(char *refparam, struct dmctx *ctx, void *
static int set_EthernetRMONStats_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *dmmap_section = NULL;
switch (action) {
case VALUECHECK:
if (dm_validate_string(value, -1, 64, NULL, NULL))
return FAULT_9007;
break;
case VALUESET:
get_dmmap_section_of_config_section("dmmap_eth_rmon", "ethport", section_name(((struct eth_rmon_args *)data)->eth_rmon_sec), &dmmap_section);
dmuci_set_value_by_section(dmmap_section, "eth_rmon_alias", value);
dmuci_set_value_by_section((((struct eth_rmon_args *)data)->sections)->dmmap_section, "eth_rmon_alias", value);
break;
}
return 0;
@ -1607,7 +1531,7 @@ static int get_EthernetRMONStats_Interface(char *refparam, struct dmctx *ctx, vo
{
char *linker;
dmuci_get_value_by_section_string(((struct eth_rmon_args *)data)->eth_rmon_sec, "ifname", &linker);
dmuci_get_value_by_section_string((((struct eth_rmon_args *)data)->sections)->config_section, "ifname", &linker);
adm_entry_get_linker_param(ctx, "Device.Ethernet.Interface.", linker, value);
if (*value == NULL)
*value = "";

View file

@ -68,7 +68,7 @@ static int browseFASTLineInst(struct dmctx *dmctx, DMNODE *parent_node, void *pr
json_object *res = NULL, *line_obj = NULL;
struct fast_line_args cur_fast_line_args = {0};
struct uci_section *s = NULL;
char *inst = NULL, *max_inst = NULL;
char *inst = NULL;
int entries = 0;
dmubus_call("fast", "status", UBUS_ARGS{}, 0, &res);
@ -80,8 +80,7 @@ static int browseFASTLineInst(struct dmctx *dmctx, DMNODE *parent_node, void *pr
s = update_create_dmmap_fast_line(cur_fast_line_args.id);
init_fast_line(&cur_fast_line_args, s);
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
s, "fast_line_instance", "fast_line_alias");
inst = handle_instance(dmctx, parent_node, s, "fast_line_instance", "fast_line_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&cur_fast_line_args, inst) == DM_STOP)
break;
@ -136,12 +135,7 @@ static char *get_fast_value_array_without_argument(char *command1, char *id, cha
***************************************************************************/
static int get_FAST_LineNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s = NULL;
int cnt = 0;
uci_path_foreach_sections(bbfdm, "dmmap", "fast_line", s) {
cnt++;
}
int cnt = get_number_of_entries(ctx, data, instance, browseFASTLineInst);
dmasprintf(value, "%d", cnt);
return 0;
}
@ -901,6 +895,9 @@ static int get_FASTLineStatsQuarterHour_SuccessTIGA(char *refparam, struct dmctx
return 0;
}
/**********************************************************************************************************************************
* OBJ & LEAF DEFINITION
***********************************************************************************************************************************/
/* *** Device.FAST. *** */
DMOBJ tFASTObj[] = {
/* OBJ, permission, addobj, delobj, checkdep, browseinstobj, nextdynamicobj, dynamicleaf, nextobj, leaf, linker, bbfdm_type, uniqueKeys*/

View file

@ -6,33 +6,29 @@
* as published by the Free Software Foundation
*
* Author: Omar Kallel <omar.kallel@pivasoftware.com>
* Author: Amin Ben Ramdhane <amin.benramdhane@pivasoftware.com>
*/
#include "dmentry.h"
#include "firewall.h"
/***************************** Browse Functions ***********************************/
/*************************************************************
* ENTRY METHOD
**************************************************************/
static int browseLevelInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *max_inst = NULL;
struct uci_section *s = is_dmmap_section_exist("dmmap_firewall", "level");
if (!s) dmuci_add_section_bbfdm("dmmap_firewall", "level", &s);
handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
s, "firewall_level_instance", "firewall_level_alias");
handle_instance(dmctx, parent_node, s, "firewall_level_instance", "firewall_level_alias");
DM_LINK_INST_OBJ(dmctx, parent_node, s, "1");
return 0;
}
static int browseChainInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *max_inst = NULL;
struct uci_section *s = is_dmmap_section_exist("dmmap_firewall", "chain");
if (!s) dmuci_add_section_bbfdm("dmmap_firewall", "chain", &s);
handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
s, "firewall_chain_instance", "firewall_chain_alias");
handle_instance(dmctx, parent_node, s, "firewall_chain_instance", "firewall_chain_alias");
DM_LINK_INST_OBJ(dmctx, parent_node, s, "1");
return 0;
}
@ -40,23 +36,25 @@ static int browseChainInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_
/*#Device.Firewall.Chain.{i}.Rule.{i}.!UCI:firewall/rule/dmmap_firewall*/
static int browseRuleInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *max_inst = NULL;
char *inst = NULL;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("firewall", "rule", "dmmap_firewall", &dup_list);
list_for_each_entry(p, &dup_list, list) {
inst = handle_update_instance(2, dmctx, &max_inst, update_instance_alias, 3,
p->dmmap_section, "firewall_chain_rule_instance", "firewall_chain_rule_alias");
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "firewall_chain_rule_instance", "firewall_chain_rule_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, inst) == DM_STOP)
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p, inst) == DM_STOP)
break;
}
free_dmmap_config_dup_list(&dup_list);
return 0;
}
/*************************************************************
* ADD & DEL OBJ
**************************************************************/
static int add_firewall_rule(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
struct uci_section *s = NULL, *dmmap_firewall_rule = NULL;
@ -66,8 +64,7 @@ static int add_firewall_rule(char *refparam, struct dmctx *ctx, void *data, char
strftime(creation_date, sizeof(creation_date), "%Y-%m-%dT%H:%M:%SZ", gmtime(&now));
char *last_inst = get_last_instance_bbfdm("dmmap_firewall", "rule", "firewall_chain_rule_instance");
snprintf(s_name, sizeof(s_name), "rule_%s", last_inst ? last_inst : "1");
snprintf(s_name, sizeof(s_name), "rule_%s", *instance);
dmuci_add_section("firewall", "rule", &s);
dmuci_rename_section_by_section(s, s_name);
@ -77,51 +74,36 @@ static int add_firewall_rule(char *refparam, struct dmctx *ctx, void *data, char
dmuci_add_section_bbfdm("dmmap_firewall", "rule", &dmmap_firewall_rule);
dmuci_set_value_by_section(dmmap_firewall_rule, "section_name", s_name);
dmuci_set_value_by_section(dmmap_firewall_rule, "creation_date", creation_date);
*instance = update_instance(last_inst, 2, dmmap_firewall_rule, "firewall_chain_rule_instance");
dmuci_set_value_by_section(dmmap_firewall_rule, "firewall_chain_rule_instance", *instance);
return 0;
}
static int delete_firewall_rule(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
struct uci_section *s = NULL, *ss = NULL, *dmmap_section = NULL;
int found = 0;
struct uci_section *s = NULL, *stmp = NULL;
switch (del_action) {
case DEL_INST:
if (is_section_unnamed(section_name((struct uci_section *)data))) {
LIST_HEAD(dup_list);
delete_sections_save_next_sections("dmmap_firewall", "rule", "firewall_chain_rule_instance", section_name((struct uci_section *)data), atoi(instance), &dup_list);
update_dmmap_sections(&dup_list, "firewall_chain_rule_instance", "dmmap_firewall", "rule");
dmuci_delete_by_section_unnamed((struct uci_section *)data, NULL, NULL);
} else {
get_dmmap_section_of_config_section("dmmap_firewall", "rule", section_name((struct uci_section *)data), &dmmap_section);
if (dmmap_section)
dmuci_delete_by_section_unnamed_bbfdm(dmmap_section, NULL, NULL);
dmuci_delete_by_section((struct uci_section *)data, NULL, NULL);
}
dmuci_delete_by_section(((struct dmmap_dup *)data)->config_section, NULL, NULL);
dmuci_delete_by_section(((struct dmmap_dup *)data)->dmmap_section, NULL, NULL);
break;
case DEL_ALL:
uci_foreach_sections("firewall", "rule", s) {
if (found != 0) {
get_dmmap_section_of_config_section("dmmap_firewall", "rule", section_name(ss), &dmmap_section);
if (dmmap_section)
uci_foreach_sections_safe("firewall", "rule", stmp, s) {
struct uci_section *dmmap_section = NULL;
get_dmmap_section_of_config_section("dmmap_firewall", "rule", section_name(s), &dmmap_section);
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
ss = s;
found++;
}
if (ss != NULL) {
get_dmmap_section_of_config_section("dmmap_firewall", "rule", section_name(ss), &dmmap_section);
if (dmmap_section)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
dmuci_delete_by_section(s, NULL, NULL);
}
break;
}
return 0;
}
/***************************************** Set/Get Parameter functions ***********************/
/*************************************************************
* GET & SET PARAM
**************************************************************/
static int get_firewall_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *path = "/etc/rc.d/*firewall";
@ -243,12 +225,7 @@ static int get_chain_creator(char *refparam, struct dmctx *ctx, void *data, char
/*#Device.Firewall.Chain.{i}.RuleNumberOfEntries!UCI:firewall/rule/*/
static int get_chain_rule_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s = NULL;
int cnt = 0;
uci_foreach_sections("firewall", "rule", s) {
cnt++;
}
int cnt = get_number_of_entries(ctx, data, instance, browseRuleInst);
dmasprintf(value, "%d", cnt);
return 0;
}
@ -257,7 +234,7 @@ static int get_chain_rule_number_of_entries(char *refparam, struct dmctx *ctx, v
static int get_rule_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *v;
dmuci_get_value_by_section_string((struct uci_section *)data, "enabled", &v);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "enabled", &v);
*value = (*v == 'n' || *v == '0' ) ? "0" : "1";
return 0;
}
@ -266,26 +243,21 @@ static int get_rule_enable(char *refparam, struct dmctx *ctx, void *data, char *
static int get_rule_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *v;
dmuci_get_value_by_section_string((struct uci_section *)data, "enabled", &v);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "enabled", &v);
*value = (*v == 'n' || *v == '0') ? "Disabled" : "Enabled";
return 0;
}
static int get_rule_order(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *dms = NULL;
get_dmmap_section_of_config_section("dmmap_firewall", "rule", section_name((struct uci_section *)data), &dms);
dmuci_get_value_by_section_string(dms, "firewall_chain_rule_instance", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->dmmap_section, "firewall_chain_rule_instance", value);
return 0;
}
/*#Device.Firewall.Chain.{i}.Rule.{i}.Alias!UCI:dmmap_firewall/rule,@i-1/firewall_chain_rule_alias*/
static int get_rule_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *dmmap_section = NULL;
get_dmmap_section_of_config_section("dmmap_firewall", "rule", section_name((struct uci_section *)data), &dmmap_section);
dmuci_get_value_by_section_string(dmmap_section, "firewall_chain_rule_alias", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->dmmap_section, "firewall_chain_rule_alias", value);
if ((*value)[0] == '\0')
dmasprintf(value, "cpe-%s", instance);
return 0;
@ -294,7 +266,7 @@ static int get_rule_alias(char *refparam, struct dmctx *ctx, void *data, char *i
/*#Device.Firewall.Chain.{i}.Rule.{i}.Description!UCI:firewall/rule,@i-1/name*/
static int get_rule_description(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string((struct uci_section *)data, "name", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "name", value);
return 0;
}
@ -303,7 +275,7 @@ static int get_rule_target(char *refparam, struct dmctx *ctx, void *data, char *
{
char *v;
dmuci_get_value_by_section_string((struct uci_section *)data, "target", &v);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "target", &v);
if (strcasecmp(v, "Accept") == 0)
*value = "Accept";
else if (strcasecmp(v, "Reject") == 0)
@ -321,17 +293,14 @@ static int get_rule_target(char *refparam, struct dmctx *ctx, void *data, char *
static int get_rule_log(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *v;
dmuci_get_value_by_section_string((struct uci_section *)data, "log", &v);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "log", &v);
*value = (*v == '1' ) ? "1" : "0";
return 0;
}
static int get_FirewallChainRule_CreationDate(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *dmmap_section = NULL;
get_dmmap_section_of_config_section("dmmap_firewall", "rule", section_name((struct uci_section *)data), &dmmap_section);
*value = dmuci_get_value_by_section_fallback_def(dmmap_section, "creation_date", "0001-01-01T00:00:00Z");
*value = dmuci_get_value_by_section_fallback_def(((struct dmmap_dup *)data)->dmmap_section, "creation_date", "0001-01-01T00:00:00Z");
return 0;
}
@ -340,7 +309,7 @@ static int get_FirewallChainRule_ExpiryDate(char *refparam, struct dmctx *ctx, v
{
char *expiry_date = NULL;
dmuci_get_value_by_section_string((struct uci_section *)data, "expiry", &expiry_date);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "expiry", &expiry_date);
if (expiry_date && *expiry_date != '\0' && atoi(expiry_date) > 0) {
char expiry[sizeof "AAAA-MM-JJTHH:MM:SSZ"];
time_t time_value = atoi(expiry_date);
@ -366,7 +335,7 @@ static int set_FirewallChainRule_ExpiryDate(char *refparam, struct dmctx *ctx, v
case VALUESET:
strptime(value, "%Y-%m-%dT%H:%M:%SZ", &tm);
snprintf(expiry_date, sizeof(expiry_date), "%ld", timegm(&tm));
dmuci_set_value_by_section((struct uci_section *)data, "expiry", expiry_date);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "expiry", expiry_date);
break;
}
return 0;
@ -377,15 +346,12 @@ static int get_rule_source_interface(char *refparam, struct dmctx *ctx, void *da
char *ifaceobj = NULL, *src = NULL, src_iface[256] = {0};
struct uci_list *net_list = NULL;
dmuci_get_value_by_section_string((struct uci_section *)data, "src", &src);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "src", &src);
if (src == NULL || *src == '\0')
return 0;
if (strcmp(src, "*") == 0) {
struct uci_section *dmmap_section = NULL;
get_dmmap_section_of_config_section("dmmap_firewall", "rule", section_name((struct uci_section *)data), &dmmap_section);
dmuci_get_value_by_section_string(dmmap_section, "src", &src);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->dmmap_section, "src", &src);
} else {
struct uci_section *s = NULL;
char *zone_name = NULL;
@ -425,7 +391,7 @@ static int get_rule_source_interface(char *refparam, struct dmctx *ctx, void *da
static int get_rule_source_all_interfaces(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *v;
dmuci_get_value_by_section_string((struct uci_section *)data, "src", &v);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "src", &v);
*value = (*v == '*') ? "1" : "0";
return 0;
}
@ -435,15 +401,12 @@ static int get_rule_dest_interface(char *refparam, struct dmctx *ctx, void *data
char *ifaceobj = NULL, *dest = NULL, dst_iface[256] = {0};
struct uci_list *net_list = NULL;
dmuci_get_value_by_section_string((struct uci_section *)data, "dest", &dest);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "dest", &dest);
if (dest == NULL || *dest == '\0')
return 0;
if (strcmp(dest, "*") == 0) {
struct uci_section *dmmap_section = NULL;
get_dmmap_section_of_config_section("dmmap_firewall", "rule", section_name((struct uci_section *)data), &dmmap_section);
dmuci_get_value_by_section_string(dmmap_section, "dest", &dest);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->dmmap_section, "dest", &dest);
} else {
struct uci_section *s = NULL;
char *zone_name = NULL;
@ -483,7 +446,7 @@ static int get_rule_dest_interface(char *refparam, struct dmctx *ctx, void *data
static int get_rule_dest_all_interfaces(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *v;
dmuci_get_value_by_section_string((struct uci_section *)data, "dest", &v);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "dest", &v);
*value = (*v == '*') ? "1" : "0";
return 0;
}
@ -493,7 +456,7 @@ static int get_rule_i_p_version(char *refparam, struct dmctx *ctx, void *data, c
{
char *ipversion;
dmuci_get_value_by_section_string((struct uci_section *)data, "family", &ipversion);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "family", &ipversion);
if (strcasecmp(ipversion, "ipv4") == 0) {
*value = "4";
} else if (strcasecmp(ipversion, "ipv6") == 0) {
@ -509,7 +472,7 @@ static int get_rule_dest_ip(char *refparam, struct dmctx *ctx, void *data, char
{
char buf[64], *pch, *destip;
dmuci_get_value_by_section_string((struct uci_section *)data, "dest_ip", &destip);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "dest_ip", &destip);
DM_STRNCPY(buf, destip, sizeof(buf));
pch = strchr(buf, '/');
if (pch) *pch = '\0';
@ -522,7 +485,7 @@ static int get_rule_dest_mask(char *refparam, struct dmctx *ctx, void *data, cha
{
char *pch, *destip;
dmuci_get_value_by_section_string((struct uci_section *)data, "dest_ip", &destip);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "dest_ip", &destip);
if (*destip == '\0')
return 0;
@ -532,7 +495,7 @@ static int get_rule_dest_mask(char *refparam, struct dmctx *ctx, void *data, cha
} else {
char *family;
dmuci_get_value_by_section_string((struct uci_section *)data, "family", &family);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "family", &family);
dmasprintf(value, "%s/%s", destip, strcmp(family, "ipv6") == 0 ? "128" : "32");
}
return 0;
@ -543,7 +506,7 @@ static int get_rule_source_ip(char *refparam, struct dmctx *ctx, void *data, cha
{
char buf[64], *pch, *srcip;
dmuci_get_value_by_section_string((struct uci_section *)data, "src_ip", &srcip);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "src_ip", &srcip);
DM_STRNCPY(buf, srcip, sizeof(buf));
pch = strchr(buf, '/');
if (pch)
@ -557,7 +520,7 @@ static int get_rule_source_mask(char *refparam, struct dmctx *ctx, void *data, c
{
char *pch, *srcip;
dmuci_get_value_by_section_string((struct uci_section *)data, "src_ip", &srcip);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "src_ip", &srcip);
if (*srcip == '\0')
return 0;
@ -567,7 +530,7 @@ static int get_rule_source_mask(char *refparam, struct dmctx *ctx, void *data, c
} else {
char *family;
dmuci_get_value_by_section_string((struct uci_section *)data, "family", &family);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "family", &family);
dmasprintf(value, "%s/%s", srcip, strcmp(family, "ipv6") == 0 ? "128" : "32");
}
return 0;
@ -579,7 +542,7 @@ static int get_rule_protocol(char *refparam, struct dmctx *ctx, void *data, char
FILE *fp;
char *v, buf[256], protocol[32], protocol_nbr[16];
dmuci_get_value_by_section_string((struct uci_section *)data, "proto", &v);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "proto", &v);
*value = "-1";
if (*v == '\0' || *v == '0') {
return 0;
@ -608,7 +571,7 @@ static int get_rule_dest_port(char *refparam, struct dmctx *ctx, void *data, cha
{
char *tmp,*v;
dmuci_get_value_by_section_string((struct uci_section *)data, "dest_port", &v);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "dest_port", &v);
v = dmstrdup(v);
tmp = strchr(v, ':');
if (tmp == NULL)
@ -628,7 +591,7 @@ static int get_rule_dest_port_range_max(char *refparam, struct dmctx *ctx, void
{
char *tmp, *v;
dmuci_get_value_by_section_string((struct uci_section *)data, "dest_port", &v);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "dest_port", &v);
tmp = strchr(v, ':');
if (tmp == NULL)
tmp = strchr(v, '-');
@ -641,7 +604,7 @@ static int get_rule_source_port(char *refparam, struct dmctx *ctx, void *data, c
{
char *tmp, *v;
dmuci_get_value_by_section_string((struct uci_section *)data, "src_port", &v);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "src_port", &v);
v = dmstrdup(v);
tmp = strchr(v, ':');
if (tmp == NULL)
@ -661,7 +624,7 @@ static int get_rule_source_port_range_max(char *refparam, struct dmctx *ctx, voi
{
char *tmp, *v;
dmuci_get_value_by_section_string((struct uci_section *)data, "src_port", &v);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "src_port", &v);
tmp = strchr(v, ':');
if (tmp == NULL)
tmp = strchr(v, '-');
@ -867,7 +830,7 @@ static int set_rule_enable(char *refparam, struct dmctx *ctx, void *data, char *
break;
case VALUESET:
string_to_bool(value, &b);
dmuci_set_value_by_section((struct uci_section *)data, "enabled", b ? "" : "0");
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "enabled", b ? "" : "0");
break;
}
return 0;
@ -888,16 +851,13 @@ static int set_rule_order(char *refparam, struct dmctx *ctx, void *data, char *i
static int set_rule_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *dmmap_section = NULL;
switch (action) {
case VALUECHECK:
if (dm_validate_string(value, -1, 64, NULL, NULL))
return FAULT_9007;
break;
case VALUESET:
get_dmmap_section_of_config_section("dmmap_firewall", "rule", section_name((struct uci_section *)data), &dmmap_section);
dmuci_set_value_by_section(dmmap_section, "firewall_chain_rule_alias", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->dmmap_section, "firewall_chain_rule_alias", value);
return 0;
}
return 0;
@ -911,7 +871,7 @@ static int set_rule_description(char *refparam, struct dmctx *ctx, void *data, c
return FAULT_9007;
break;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "name", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "name", value);
break;
}
return 0;
@ -926,13 +886,13 @@ static int set_rule_target(char *refparam, struct dmctx *ctx, void *data, char *
break;
case VALUESET:
if (strcasecmp(value, "Accept") == 0)
dmuci_set_value_by_section((struct uci_section *)data, "target", "ACCEPT");
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "target", "ACCEPT");
else if (strcasecmp(value, "Reject") == 0)
dmuci_set_value_by_section((struct uci_section *)data, "target", "REJECT");
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "target", "REJECT");
else if (strcasecmp(value, "Drop") == 0)
dmuci_set_value_by_section((struct uci_section *)data, "target", "DROP");
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "target", "DROP");
else if (strcasecmp(value, "Return") == 0)
dmuci_set_value_by_section((struct uci_section *)data, "target", "MARK");
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "target", "MARK");
break;
}
return 0;
@ -949,7 +909,7 @@ static int set_rule_log(char *refparam, struct dmctx *ctx, void *data, char *ins
break;
case VALUESET:
string_to_bool(value, &b);
dmuci_set_value_by_section((struct uci_section *)data, "log", b ? "1" : "");
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "log", b ? "1" : "");
break;
}
return 0;
@ -957,7 +917,6 @@ static int set_rule_log(char *refparam, struct dmctx *ctx, void *data, char *ins
static int set_rule_interface(struct dmctx *ctx, void *data, char *type, char *value, int action)
{
struct uci_section *dmmap_section = NULL;
char *iface = NULL, *option = NULL;
switch (action) {
@ -974,11 +933,10 @@ static int set_rule_interface(struct dmctx *ctx, void *data, char *type, char *v
break;
case VALUESET:
get_dmmap_section_of_config_section("dmmap_firewall", "rule", section_name((struct uci_section *)data), &dmmap_section);
dmuci_get_value_by_section_string((struct uci_section *)data, type, &option);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, type, &option);
if (*value == '\0') {
dmuci_set_value_by_section((option && strcmp(option, "*") == 0) ? dmmap_section : (struct uci_section *)data, type, "");
dmuci_set_value_by_section((option && strcmp(option, "*") == 0) ? ((struct dmmap_dup *)data)->dmmap_section : ((struct dmmap_dup *)data)->config_section, type, "");
} else {
adm_entry_get_linker_value(ctx, value, &iface);
if (iface && iface[0] != '\0') {
@ -991,7 +949,7 @@ static int set_rule_interface(struct dmctx *ctx, void *data, char *type, char *v
char *zone_name;
dmuci_get_value_by_section_string(s, "name", &zone_name);
dmuci_set_value_by_section((option && strcmp(option, "*") == 0) ? dmmap_section : (struct uci_section *)data, type, zone_name);
dmuci_set_value_by_section((option && strcmp(option, "*") == 0) ? ((struct dmmap_dup *)data)->dmmap_section : ((struct dmmap_dup *)data)->config_section, type, zone_name);
break;
}
}
@ -1010,7 +968,6 @@ static int set_rule_source_interface(char *refparam, struct dmctx *ctx, void *da
static int set_rule_source_all_interfaces(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *dmmap_section = NULL;
char *src;
bool b;
@ -1020,23 +977,22 @@ static int set_rule_source_all_interfaces(char *refparam, struct dmctx *ctx, voi
return FAULT_9007;
break;
case VALUESET:
get_dmmap_section_of_config_section("dmmap_firewall", "rule", section_name((struct uci_section *)data), &dmmap_section);
string_to_bool(value, &b);
if (b) {
// Get the current 'src' option
dmuci_get_value_by_section_string((struct uci_section *)data, "src", &src);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "src", &src);
// Save 'src' option in the associated dmmap rule section
dmuci_set_value_by_section(dmmap_section, "src", src);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->dmmap_section, "src", src);
// Set the current 'src' option
dmuci_set_value_by_section((struct uci_section *)data, "src", "*");
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "src", "*");
} else {
// Get 'src' option from the associated dmmap rule section
dmuci_get_value_by_section_string(dmmap_section, "src", &src);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->dmmap_section, "src", &src);
// Set the current 'src' option
dmuci_set_value_by_section((struct uci_section *)data, "src", src);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "src", src);
}
break;
}
@ -1050,7 +1006,6 @@ static int set_rule_dest_interface(char *refparam, struct dmctx *ctx, void *data
static int set_rule_dest_all_interfaces(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *dmmap_section = NULL;
char *dest;
bool b;
@ -1060,23 +1015,22 @@ static int set_rule_dest_all_interfaces(char *refparam, struct dmctx *ctx, void
return FAULT_9007;
break;
case VALUESET:
get_dmmap_section_of_config_section("dmmap_firewall", "rule", section_name((struct uci_section *)data), &dmmap_section);
string_to_bool(value, &b);
if (b) {
// Get the current 'dest' option
dmuci_get_value_by_section_string((struct uci_section *)data, "dest", &dest);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "dest", &dest);
// Save 'dest' option in the associated dmmap rule section
dmuci_set_value_by_section(dmmap_section, "dest", dest);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->dmmap_section, "dest", dest);
// Set the current 'dest' option
dmuci_set_value_by_section((struct uci_section *)data, "dest", "*");
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "dest", "*");
} else {
// Get 'dest' option from the associated dmmap rule section
dmuci_get_value_by_section_string(dmmap_section, "dest", &dest);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->dmmap_section, "dest", &dest);
// Set the current 'dest' option
dmuci_set_value_by_section((struct uci_section *)data, "dest", dest);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "dest", dest);
}
break;
}
@ -1092,11 +1046,11 @@ static int set_rule_i_p_version(char *refparam, struct dmctx *ctx, void *data, c
break;
case VALUESET:
if (strcmp(value, "4") == 0)
dmuci_set_value_by_section((struct uci_section *)data, "family", "ipv4");
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "family", "ipv4");
else if (strcmp(value, "6") == 0)
dmuci_set_value_by_section((struct uci_section *)data, "family", "ipv6");
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "family", "ipv6");
else if (strcmp(value, "-1") == 0)
dmuci_set_value_by_section((struct uci_section *)data, "family", "");
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "family", "");
break;
}
return 0;
@ -1112,14 +1066,14 @@ static int set_rule_dest_ip(char *refparam, struct dmctx *ctx, void *data, char
return FAULT_9007;
break;
case VALUESET:
dmuci_get_value_by_section_string((struct uci_section *)data, "dest_ip", &destip);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "dest_ip", &destip);
DM_STRNCPY(buf, destip, sizeof(buf));
pch = strchr(buf, '/');
if (pch)
snprintf(new, sizeof(new), "%s%s", value, pch);
else
DM_STRNCPY(new, value, sizeof(new));
dmuci_set_value_by_section((struct uci_section *)data, "dest_ip", new);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "dest_ip", new);
break;
}
return 0;
@ -1135,7 +1089,7 @@ static int set_rule_dest_mask(char *refparam, struct dmctx *ctx, void *data, cha
return FAULT_9007;
break;
case VALUESET:
dmuci_get_value_by_section_string((struct uci_section *)data, "dest_ip", &destip);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "dest_ip", &destip);
pch = strchr(destip, '/');
if (pch)
*pch = '\0';
@ -1143,7 +1097,7 @@ static int set_rule_dest_mask(char *refparam, struct dmctx *ctx, void *data, cha
pch = strchr(value, '/');
snprintf(new, sizeof(new), "%s%s", destip, pch);
dmuci_set_value_by_section((struct uci_section *)data, "dest_ip", new);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "dest_ip", new);
break;
}
return 0;
@ -1159,14 +1113,14 @@ static int set_rule_source_ip(char *refparam, struct dmctx *ctx, void *data, cha
return FAULT_9007;
break;
case VALUESET:
dmuci_get_value_by_section_string((struct uci_section *)data, "src_ip", &srcip);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "src_ip", &srcip);
DM_STRNCPY(buf, srcip, sizeof(buf));
pch = strchr(buf, '/');
if (pch)
snprintf(new, sizeof(new), "%s%s", value, pch);
else
DM_STRNCPY(new, value, sizeof(new));
dmuci_set_value_by_section((struct uci_section *)data, "src_ip", new);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "src_ip", new);
break;
}
return 0;
@ -1182,7 +1136,7 @@ static int set_rule_source_mask(char *refparam, struct dmctx *ctx, void *data, c
return FAULT_9007;
break;
case VALUESET:
dmuci_get_value_by_section_string((struct uci_section *)data, "src_ip", &srcip);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "src_ip", &srcip);
pch = strchr(srcip, '/');
if (pch)
*pch = '\0';
@ -1190,7 +1144,7 @@ static int set_rule_source_mask(char *refparam, struct dmctx *ctx, void *data, c
pch = strchr(value, '/');
snprintf(new, sizeof(new), "%s%s", srcip, pch);
dmuci_set_value_by_section((struct uci_section *)data, "src_ip", new);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "src_ip", new);
break;
}
return 0;
@ -1204,7 +1158,7 @@ static int set_rule_protocol(char *refparam, struct dmctx *ctx, void *data, char
return FAULT_9007;
break;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "proto", (*value == '-') ? "" : value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "proto", (*value == '-') ? "" : value);
break;
}
return 0;
@ -1222,7 +1176,7 @@ static int set_rule_dest_port(char *refparam, struct dmctx *ctx, void *data, cha
case VALUESET:
if (*value == '-')
value = "";
dmuci_get_value_by_section_string((struct uci_section *)data, "dest_port", &v);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "dest_port", &v);
tmp = strchr(v, ':');
if (tmp == NULL)
tmp = strchr(v, '-');
@ -1230,7 +1184,7 @@ static int set_rule_dest_port(char *refparam, struct dmctx *ctx, void *data, cha
snprintf(buffer, sizeof(buffer), "%s", value);
else
snprintf(buffer, sizeof(buffer), "%s%s", value, tmp);
dmuci_set_value_by_section((struct uci_section *)data, "dest_port", buffer);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "dest_port", buffer);
break;
}
return 0;
@ -1246,7 +1200,7 @@ static int set_rule_dest_port_range_max(char *refparam, struct dmctx *ctx, void
return FAULT_9007;
break;
case VALUESET:
dmuci_get_value_by_section_string((struct uci_section *)data, "dest_port", &v);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "dest_port", &v);
buf = dmstrdup(v);
v = buf;
tmp = strchr(buf, ':');
@ -1259,7 +1213,7 @@ static int set_rule_dest_port_range_max(char *refparam, struct dmctx *ctx, void
else
snprintf(buffer, sizeof(buffer), "%s:%s", v, value);
dmfree(buf);
dmuci_set_value_by_section((struct uci_section *)data, "dest_port", buffer);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "dest_port", buffer);
break;
}
return 0;
@ -1277,7 +1231,7 @@ static int set_rule_source_port(char *refparam, struct dmctx *ctx, void *data, c
case VALUESET:
if (*value == '-')
value = "";
dmuci_get_value_by_section_string((struct uci_section *)data, "src_port", &v);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "src_port", &v);
tmp = strchr(v, ':');
if (tmp == NULL)
tmp = strchr(v, '-');
@ -1285,7 +1239,7 @@ static int set_rule_source_port(char *refparam, struct dmctx *ctx, void *data, c
snprintf(buffer, sizeof(buffer), "%s", value);
else
snprintf(buffer, sizeof(buffer), "%s%s", value, tmp);
dmuci_set_value_by_section((struct uci_section *)data, "src_port", buffer);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "src_port", buffer);
break;
}
return 0;
@ -1301,7 +1255,7 @@ static int set_rule_source_port_range_max(char *refparam, struct dmctx *ctx, voi
return FAULT_9007;
break;
case VALUESET:
dmuci_get_value_by_section_string((struct uci_section *)data, "src_port", &v);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "src_port", &v);
buf = dmstrdup(v);
v = buf;
tmp = strchr(buf, ':');
@ -1314,12 +1268,15 @@ static int set_rule_source_port_range_max(char *refparam, struct dmctx *ctx, voi
else
snprintf(buffer, sizeof(buffer), "%s:%s", v, value);
dmfree(buf);
dmuci_set_value_by_section((struct uci_section *)data, "src_port", buffer);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "src_port", buffer);
break;
}
return 0;
}
/**********************************************************************************************************************************
* OBJ & PARAM DEFINITION
***********************************************************************************************************************************/
/* *** Device.Firewall. *** */
DMOBJ tFirewallObj[] = {
/* OBJ, permission, addobj, delobj, checkdep, browseinstobj, nextdynamicobj, dynamicleaf, nextobj, leaf, linker, bbfdm_type, uniqueKeys*/

View file

@ -10,21 +10,19 @@
#include "gre.h"
/*************************************************************
* ENTRY METHOD
*************************************************************/
static int browseGRETunnelInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *max_inst = NULL;
char *inst = NULL;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap_eq("network", "interface", "dmmap_network", "proto", "gre", &dup_list);
list_for_each_entry(p, &dup_list, list) {
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
p->dmmap_section, "gretunnel_instance", "gretunnel_alias");
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "gretunnel_instance", "gretunnel_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p, inst) == DM_STOP)
break;
@ -33,7 +31,7 @@ static int browseGRETunnelInst(struct dmctx *dmctx, DMNODE *parent_node, void *p
return 0;
}
struct uci_section *has_tunnel_interface_route(char *interface)
static struct uci_section *has_tunnel_interface_route(char *interface)
{
struct uci_section *s = NULL;
@ -45,10 +43,9 @@ struct uci_section *has_tunnel_interface_route(char *interface)
static int browseGRETunnelInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *max_inst = NULL, *device = NULL;
char *inst = NULL, *device = NULL;
struct dmmap_dup *p = NULL, *dm = (struct dmmap_dup *)prev_data;
struct uci_section *s = NULL;
struct browse_args browse_args = {0};
LIST_HEAD(dup_list);
dmasprintf(&device, "@%s", section_name(dm->config_section));
@ -57,12 +54,7 @@ static int browseGRETunnelInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node
if ((s = has_tunnel_interface_route(section_name(p->config_section))) == NULL)
continue;
browse_args.option = "section_name";
browse_args.value = section_name(dm->config_section);
inst = handle_update_instance(2, dmctx, &max_inst, update_instance_alias, 5,
p->dmmap_section, "greiface_instance", "greiface_alias",
check_browse_section, (void *)&browse_args);
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "greiface_instance", "greiface_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p, inst) == DM_STOP)
break;
@ -74,69 +66,49 @@ static int browseGRETunnelInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node
/*************************************************************
* ADD & DEL OBJ
*************************************************************/
static int addObjGRETunnel(char *refparam, struct dmctx *ctx, void *data, char **instancepara)
static int addObjGRETunnel(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
struct uci_section *gre_sec = NULL, *dmmap_sec = NULL;
char *instance = get_last_instance_lev2_bbfdm("network", "interface", "dmmap_network", "gretunnel_instance", "proto", "gre");
dmuci_add_section("network", "interface", &gre_sec);
dmuci_set_value_by_section(gre_sec, "proto", "gre");
dmuci_add_section_bbfdm("dmmap_network", "interface", &dmmap_sec);
dmuci_set_value_by_section(dmmap_sec, "section_name", section_name(gre_sec));
*instancepara = update_instance(instance, 2, dmmap_sec, "gretunnel_instance");
dmuci_set_value_by_section(dmmap_sec, "gretunnel_instance", *instance);
return 0;
}
static int delObjGRETunnel(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
struct uci_section *s = NULL, *ss = NULL, *dmmap_section = NULL;
int found = 0;
struct uci_section *s = NULL, *stmp = NULL;
switch (del_action) {
case DEL_INST:
get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct dmmap_dup *)data)->config_section), &dmmap_section);
if (dmmap_section != NULL) {
dmuci_set_value_by_section(dmmap_section, "gretunnel_instance", "");
dmuci_set_value_by_section(dmmap_section, "gretunnel_alias", "");
}
dmuci_set_value_by_section(((struct dmmap_dup *)data)->dmmap_section, "gretunnel_instance", "");
dmuci_set_value_by_section(((struct dmmap_dup *)data)->dmmap_section, "gretunnel_alias", "");
dmuci_delete_by_section(((struct dmmap_dup *)data)->config_section, NULL, NULL);
break;
case DEL_ALL:
uci_foreach_option_eq("network", "interface", "proto", "gre", s) {
if (found != 0) {
get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(ss), &dmmap_section);
if (dmmap_section != NULL) {
uci_foreach_option_eq_safe("network", "interface", "proto", "gre", stmp, s) {
struct uci_section *dmmap_section = NULL;
get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(s), &dmmap_section);
dmuci_set_value_by_section(dmmap_section, "gretunnel_instance", "");
dmuci_set_value_by_section(dmmap_section, "gretunnel_alias", "");
}
dmuci_delete_by_section(ss, NULL, NULL);
}
ss = s;
found++;
}
if (ss != NULL){
get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(ss), &dmmap_section);
if (dmmap_section != NULL) {
dmuci_set_value_by_section(dmmap_section, "gretunnel_instance", "");
dmuci_set_value_by_section(dmmap_section, "gretunnel_alias", "");
}
dmuci_delete_by_section(ss, NULL, NULL);
dmuci_delete_by_section(s, NULL, NULL);
}
break;
}
return 0;
}
static int addObjGRETunnelInterface(char *refparam, struct dmctx *ctx, void *data, char **instancepara)
static int addObjGRETunnelInterface(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
struct uci_section *greiface_sec = NULL, *dmmap_sec = NULL, *route_sec = NULL;
struct browse_args browse_args = {0};
char device_buf[32];
char *instance = get_last_instance_lev2_bbfdm_dmmap_opt("dmmap_network", "interface", "greiface_instance", "gre_tunnel_sect", section_name(((struct dmmap_dup *)data)->config_section));
dmuci_add_section("network", "interface", &greiface_sec);
snprintf(device_buf, sizeof(device_buf), "@%s", section_name(((struct dmmap_dup *)data)->config_section));
dmuci_set_value_by_section(greiface_sec, "device", device_buf);
@ -144,35 +116,30 @@ static int addObjGRETunnelInterface(char *refparam, struct dmctx *ctx, void *dat
dmuci_add_section("network", "route", &route_sec);
dmuci_set_value_by_section(route_sec, "interface", section_name(greiface_sec));
browse_args.option = "gre_tunnel_sect";
browse_args.value = section_name(((struct dmmap_dup *)data)->config_section);
dmuci_add_section_bbfdm("dmmap_network", "interface", &dmmap_sec);
dmuci_set_value_by_section(dmmap_sec, "section_name", section_name(greiface_sec));
dmuci_set_value_by_section(dmmap_sec, "gre_tunnel_sect", section_name(((struct dmmap_dup *)data)->config_section));
*instancepara = update_instance(instance, 5, dmmap_sec, "greiface_instance", NULL, check_browse_section, (void *)&browse_args);
dmuci_set_value_by_section(dmmap_sec, "greiface_instance", *instance);
return 0;
}
static int delObjGRETunnelInterface(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
struct uci_section *s = NULL, *stmp = NULL, *dmmap_section = NULL;
struct uci_section *s = NULL, *stmp = NULL;
switch (del_action) {
case DEL_INST:
get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct dmmap_dup *)data)->config_section), &dmmap_section);
if (dmmap_section != NULL) {
dmuci_set_value_by_section(dmmap_section, "greiface_instance", "");
dmuci_set_value_by_section(dmmap_section, "greiface_alias", "");
}
dmuci_set_value_by_section(((struct dmmap_dup *)data)->dmmap_section, "greiface_instance", "");
dmuci_set_value_by_section(((struct dmmap_dup *)data)->dmmap_section, "greiface_alias", "");
if ((s = has_tunnel_interface_route(section_name(((struct dmmap_dup *)data)->config_section))) != NULL)
dmuci_delete_by_section(s, NULL, NULL);
dmuci_delete_by_section(((struct dmmap_dup *)data)->config_section, NULL, NULL);
break;
case DEL_ALL:
uci_foreach_sections_safe("network", "interface", stmp, s) {
struct uci_section *ss = NULL;
struct uci_section *ss = NULL, *dmmap_section = NULL;
char device_buf[32] = {0};
char *device = NULL;
@ -183,10 +150,8 @@ static int delObjGRETunnelInterface(char *refparam, struct dmctx *ctx, void *dat
continue;
get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(s), &dmmap_section);
if (dmmap_section != NULL) {
dmuci_set_value_by_section(dmmap_section, "greiface_instance", "");
dmuci_set_value_by_section(dmmap_section, "greiface_alias", "");
}
if ((ss = has_tunnel_interface_route(section_name(s))) != NULL)
dmuci_delete_by_section(ss, NULL, NULL);
@ -219,22 +184,15 @@ static char *get_gre_tunnel_interface_statistics(char *interface, char *key)
static int get_GRE_TunnelNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s= NULL;
int i= 0;
uci_foreach_option_eq("network", "interface", "proto", "gre", s) {
i++;
}
dmasprintf(value, "%d", i);
int cnt = get_number_of_entries(ctx, data, instance, browseGRETunnelInst);
dmasprintf(value, "%d", cnt);
return 0;
}
/*#Device.GRE.Tunnel.{i}.Alias!UCI:dmmap_network/interface,@i-1/gretunnel_alias*/
static int get_GRETunnel_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *dmmap_section = NULL;
get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct dmmap_dup *)data)->config_section), &dmmap_section);
dmuci_get_value_by_section_string(dmmap_section, "gretunnel_alias", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->dmmap_section, "gretunnel_alias", value);
if ((*value)[0] == '\0')
dmasprintf(value, "cpe-%s", instance);
return 0;
@ -242,16 +200,13 @@ static int get_GRETunnel_Alias(char *refparam, struct dmctx *ctx, void *data, ch
static int set_GRETunnel_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *dmmap_section = NULL;
switch (action) {
case VALUECHECK:
if (dm_validate_string(value, -1, 64, NULL, NULL))
return FAULT_9007;
break;
case VALUESET:
get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct dmmap_dup *)data)->config_section), &dmmap_section);
dmuci_set_value_by_section(dmmap_section, "gretunnel_alias", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->dmmap_section, "gretunnel_alias", value);
break;
}
return 0;
@ -285,15 +240,8 @@ static int get_GRETunnel_ConnectedRemoteEndpoint(char *refparam, struct dmctx *c
static int get_GRETunnel_InterfaceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s = NULL;
char device_buf[32] = {0};
int i = 0;
snprintf(device_buf, sizeof(device_buf), "@%s", section_name(((struct dmmap_dup *)data)->config_section));
uci_foreach_option_eq("network", "interface", "device", device_buf, s) {
i++;
}
dmasprintf(value, "%d", i);
int cnt = get_number_of_entries(ctx, data, instance, browseGRETunnelInterfaceInst);
dmasprintf(value, "%d", cnt);
return 0;
}
@ -336,10 +284,7 @@ static int get_GRETunnelStats_ErrorsReceived(char *refparam, struct dmctx *ctx,
/*#Device.GRE.Tunnel.{i}.Interface.{i}.Alias!UCI:dmmap_network/interface,@i-1/greiface_alias*/
static int get_GRETunnelInterface_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *dmmap_section = NULL;
get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct dmmap_dup *)data)->config_section), &dmmap_section);
dmuci_get_value_by_section_string(dmmap_section, "greiface_alias", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->dmmap_section, "greiface_alias", value);
if ((*value)[0] == '\0')
dmasprintf(value, "cpe-%s", instance);
return 0;
@ -347,16 +292,13 @@ static int get_GRETunnelInterface_Alias(char *refparam, struct dmctx *ctx, void
static int set_GRETunnelInterface_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *dmmap_section = NULL;
switch (action) {
case VALUECHECK:
if (dm_validate_string(value, -1, 64, NULL, NULL))
return FAULT_9007;
break;
case VALUESET:
get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct dmmap_dup *)data)->config_section), &dmmap_section);
dmuci_set_value_by_section(dmmap_section, "greiface_alias", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->dmmap_section, "greiface_alias", value);
break;
}
return 0;
@ -404,6 +346,9 @@ static int get_GRETunnelInterfaceStats_ErrorsReceived(char *refparam, struct dmc
return 0;
}
/**********************************************************************************************************************************
* OBJ & PARAM DEFINITION
***********************************************************************************************************************************/
/* *** Device.GRE. *** */
DMOBJ tGREObj[] = {
/* OBJ, permission, addobj, delobj, checkdep, browseinstobj, nextdynamicobj, dynamicleaf, nextobj, leaf, linker, bbfdm_type, uniqueKeys*/

View file

@ -18,12 +18,12 @@
static int browseHostsHostInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
json_object *res = NULL, *host_obj = NULL, *arrobj = NULL;
char *inst = NULL, *max_inst = NULL;
char *inst = NULL;
int id = 0, i = 0;
dmubus_call("topology", "hosts", UBUS_ARGS{}, 0, &res);
dmjson_foreach_obj_in_array(res, arrobj, host_obj, i, 1, "hosts") {
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_without_section, 1, ++id);
inst = handle_instance_without_section(dmctx, parent_node, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)host_obj, inst) == DM_STOP)
break;
}
@ -34,11 +34,11 @@ static int browseHostsHostInst(struct dmctx *dmctx, DMNODE *parent_node, void *p
static int browseHostsHostIPv4AddressInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
json_object *ip_arr = NULL, *host_obj = (json_object *)prev_data;
char *inst = NULL, *max_inst = NULL, *ipv4addr = NULL;
char *inst = NULL, *ipv4addr = NULL;
int id = 0, i = 0;
dmjson_foreach_value_in_array(host_obj, ip_arr, ipv4addr, i, 1, "ipv4addr") {
inst = handle_update_instance(2, dmctx, &max_inst, update_instance_without_section, 1, ++id);
inst = handle_instance_without_section(dmctx, parent_node, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)ipv4addr, inst) == DM_STOP)
break;
}
@ -49,11 +49,11 @@ static int browseHostsHostIPv4AddressInst(struct dmctx *dmctx, DMNODE *parent_no
static int browseHostsHostIPv6AddressInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
json_object *ip_arr = NULL, *host_obj = (json_object *)prev_data;
char *inst = NULL, *max_inst = NULL, *ipv6addr = NULL;
char *inst = NULL, *ipv6addr = NULL;
int id = 0, i = 0;
dmjson_foreach_value_in_array(host_obj, ip_arr, ipv6addr, i, 1, "ipv6addr") {
inst = handle_update_instance(2, dmctx, &max_inst, update_instance_without_section, 1, ++id);
inst = handle_instance_without_section(dmctx, parent_node, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)ipv6addr, inst) == DM_STOP)
break;
}
@ -75,14 +75,8 @@ static int get_linker_host(char *refparam, struct dmctx *dmctx, void *data, char
/*#Device.Hosts.HostNumberOfEntries!UBUS:topology/hosts//hosts*/
static int get_Hosts_HostNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res = NULL, *hosts = NULL;
size_t nbre_hosts = 0;
dmubus_call("topology", "hosts", UBUS_ARGS{}, 0, &res);
DM_ASSERT(res, *value = "0");
json_object_object_get_ex(res, "hosts", &hosts);
nbre_hosts = (hosts) ? json_object_array_length(hosts) : 0;
dmasprintf(value, "%d", nbre_hosts);
int cnt = get_number_of_entries(ctx, data, instance, browseHostsHostInst);
dmasprintf(value, "%d", cnt);
return 0;
}
@ -171,24 +165,16 @@ static int get_HostsHost_ActiveLastChange(char *refparam, struct dmctx *ctx, voi
/*#Device.Hosts.Host.{i}.IPv4AddressNumberOfEntries!UBUS:topology/hosts//hosts[@i-1].ipv4addr*/
static int get_HostsHost_IPv4AddressNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *ipv4addr = NULL;
size_t nbre_addr = 0;
json_object_object_get_ex((json_object *)data, "ipv4addr", &ipv4addr);
nbre_addr = (ipv4addr) ? json_object_array_length(ipv4addr) : 0;
dmasprintf(value, "%d", nbre_addr);
int cnt = get_number_of_entries(ctx, data, instance, browseHostsHostIPv4AddressInst);
dmasprintf(value, "%d", cnt);
return 0;
}
/*#Device.Hosts.Host.{i}.IPv6AddressNumberOfEntries!UBUS:topology/hosts//hosts[@i-1].ipv6addr*/
static int get_HostsHost_IPv6AddressNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *ipv6addr = NULL;
size_t nbre_addr = 0;
json_object_object_get_ex((json_object *)data, "ipv6addr", &ipv6addr);
nbre_addr = (ipv6addr) ? json_object_array_length(ipv6addr) : 0;
dmasprintf(value, "%d", nbre_addr);
int cnt = get_number_of_entries(ctx, data, instance, browseHostsHostIPv6AddressInst);
dmasprintf(value, "%d", cnt);
return 0;
}
@ -234,6 +220,9 @@ static int get_HostsHostWANStats_PacketsReceived(char *refparam, struct dmctx *c
return 0;
}
/**********************************************************************************************************************************
* OBJ & LEAF DEFINITION
***********************************************************************************************************************************/
/* *** Device.Hosts. *** */
DMOBJ tHostsObj[] = {
/* OBJ, permission, addobj, delobj, checkdep, browseinstobj, nextdynamicobj, dynamicleaf, nextobj, leaf, linker, bbfdm_type, uniqueKeys*/

View file

@ -19,13 +19,12 @@
static int browseIEEE1905ALInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
json_object *res = NULL, *interface_obj = NULL, *arrobj = NULL;
char *inst = NULL, *max_inst = NULL;
char *inst = NULL;
int id = 0, i = 0;
dmubus_call("ieee1905", "info", UBUS_ARGS{}, 0, &res);
dmjson_foreach_obj_in_array(res, arrobj, interface_obj, i, 1, "interface") {
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_without_section, 1, ++id);
inst = handle_instance_without_section(dmctx, parent_node, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)interface_obj, inst) == DM_STOP)
break;
}
@ -36,12 +35,11 @@ static int browseIEEE1905ALInterfaceInst(struct dmctx *dmctx, DMNODE *parent_nod
static int browseIEEE1905ALInterfaceVendorPropertiesInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
json_object *arrobj = NULL, *propertie_obj = NULL, *interface = (json_object *)prev_data;
char *inst = NULL, *max_inst = NULL;
char *inst = NULL;
int id = 0, i = 0;
dmjson_foreach_obj_in_array(interface, arrobj, propertie_obj, i, 1, "properties") {
inst = handle_update_instance(2, dmctx, &max_inst, update_instance_without_section, 1, ++id);
inst = handle_instance_without_section(dmctx, parent_node, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)propertie_obj, inst) == DM_STOP)
break;
}
@ -52,12 +50,11 @@ static int browseIEEE1905ALInterfaceVendorPropertiesInst(struct dmctx *dmctx, DM
static int browseIEEE1905ALInterfaceLinkInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
json_object *arrobj = NULL, *link_obj = NULL, *interface = (json_object *)prev_data;
char *inst = NULL, *max_inst = NULL;
char *inst = NULL;
int id = 0, i = 0;
dmjson_foreach_obj_in_array(interface, arrobj, link_obj, i, 1, "links") {
inst = handle_update_instance(2, dmctx, &max_inst, update_instance_without_section, 1, ++id);
inst = handle_instance_without_section(dmctx, parent_node, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)link_obj, inst) == DM_STOP)
break;
}
@ -67,17 +64,16 @@ static int browseIEEE1905ALInterfaceLinkInst(struct dmctx *dmctx, DMNODE *parent
/*#Device.IEEE1905.AL.ForwardingTable.ForwardingRule.{i}.!UCI:ieee1905/forwarding_rule/dmmap_forwarding_rule*/
static int browseIEEE1905ALForwardingTableForwardingRuleInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *max_inst = NULL;
char *inst = NULL;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("ieee1905", "forwarding_rule", "dmmap_forwarding_rule", &dup_list);
list_for_each_entry(p, &dup_list, list) {
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
p->dmmap_section, "forwardingruleinstance", "forwardingrulealias");
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "forwardingruleinstance", "forwardingrulealias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, inst) == DM_STOP)
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p, inst) == DM_STOP)
break;
}
free_dmmap_config_dup_list(&dup_list);
@ -96,13 +92,12 @@ static int browseIEEE1905ALNetworkTopologyChangeLogInst(struct dmctx *dmctx, DMN
static int browseIEEE1905ALNetworkTopologyIEEE1905DeviceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
json_object *res = NULL, *device_obj = NULL, *arrobj = NULL;
char *inst = NULL, *max_inst = NULL;
char *inst = NULL;
int id = 0, i = 0;
dmubus_call("ieee1905", "info", UBUS_ARGS{}, 0, &res);
dmjson_foreach_obj_in_array(res, arrobj, device_obj, i, 2, "topology", "device") {
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_without_section, 1, ++id);
inst = handle_instance_without_section(dmctx, parent_node, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)device_obj, inst) == DM_STOP)
break;
}
@ -113,12 +108,11 @@ static int browseIEEE1905ALNetworkTopologyIEEE1905DeviceInst(struct dmctx *dmctx
static int browseIEEE1905ALNetworkTopologyIEEE1905DeviceIPv4AddressInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
json_object *arrobj = NULL, *ipv4_address = NULL, *device = (json_object *)prev_data;
char *inst = NULL, *max_inst = NULL;
char *inst = NULL;
int id = 0, i = 0;
dmjson_foreach_obj_in_array(device, arrobj, ipv4_address, i, 1, "ipv4_address") {
inst = handle_update_instance(2, dmctx, &max_inst, update_instance_without_section, 1, ++id);
inst = handle_instance_without_section(dmctx, parent_node, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)ipv4_address, inst) == DM_STOP)
break;
}
@ -129,12 +123,11 @@ static int browseIEEE1905ALNetworkTopologyIEEE1905DeviceIPv4AddressInst(struct d
static int browseIEEE1905ALNetworkTopologyIEEE1905DeviceIPv6AddressInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
json_object *arrobj = NULL, *ipv6_address = NULL, *device = (json_object *)prev_data;
char *inst = NULL, *max_inst = NULL;
char *inst = NULL;
int id = 0, i = 0;
dmjson_foreach_obj_in_array(device, arrobj, ipv6_address, i, 1, "ipv6_address") {
inst = handle_update_instance(2, dmctx, &max_inst, update_instance_without_section, 1, ++id);
inst = handle_instance_without_section(dmctx, parent_node, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)ipv6_address, inst) == DM_STOP)
break;
}
@ -145,12 +138,11 @@ static int browseIEEE1905ALNetworkTopologyIEEE1905DeviceIPv6AddressInst(struct d
static int browseIEEE1905ALNetworkTopologyIEEE1905DeviceVendorPropertiesInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
json_object *arrobj = NULL, *vendor_properties = NULL, *device = (json_object *)prev_data;
char *inst = NULL, *max_inst = NULL;
char *inst = NULL;
int id = 0, i = 0;
dmjson_foreach_obj_in_array(device, arrobj, vendor_properties, i, 1, "vendor_properties") {
inst = handle_update_instance(2, dmctx, &max_inst, update_instance_without_section, 1, ++id);
inst = handle_instance_without_section(dmctx, parent_node, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)vendor_properties, inst) == DM_STOP)
break;
}
@ -161,12 +153,11 @@ static int browseIEEE1905ALNetworkTopologyIEEE1905DeviceVendorPropertiesInst(str
static int browseIEEE1905ALNetworkTopologyIEEE1905DeviceInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
json_object *arrobj = NULL, *interface = NULL, *device = (json_object *)prev_data;
char *inst = NULL, *max_inst = NULL;
char *inst = NULL;
int id = 0, i = 0;
dmjson_foreach_obj_in_array(device, arrobj, interface, i, 1, "interface") {
inst = handle_update_instance(2, dmctx, &max_inst, update_instance_without_section, 1, ++id);
inst = handle_instance_without_section(dmctx, parent_node, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)interface, inst) == DM_STOP)
break;
}
@ -177,12 +168,11 @@ static int browseIEEE1905ALNetworkTopologyIEEE1905DeviceInterfaceInst(struct dmc
static int browseIEEE1905ALNetworkTopologyIEEE1905DeviceNonIEEE1905NeighborInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
json_object *arrobj = NULL, *non1905_neighbor = NULL, *device = (json_object *)prev_data;
char *inst = NULL, *max_inst = NULL;
char *inst = NULL;
int id = 0, i = 0;
dmjson_foreach_obj_in_array(device, arrobj, non1905_neighbor, i, 1, "non1905_neighbors") {
inst = handle_update_instance(2, dmctx, &max_inst, update_instance_without_section, 1, ++id);
inst = handle_instance_without_section(dmctx, parent_node, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)non1905_neighbor, inst) == DM_STOP)
break;
}
@ -201,12 +191,11 @@ static int browseIEEE1905ALNetworkTopologyIEEE1905DeviceL2NeighborInst(struct dm
static int browseIEEE1905ALNetworkTopologyIEEE1905DeviceIEEE1905NeighborInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
json_object *arrobj = NULL, *ieee1905_neighbors = NULL, *device = (json_object *)prev_data;
char *inst = NULL, *max_inst = NULL;
char *inst = NULL;
int id = 0, i = 0;
dmjson_foreach_obj_in_array(device, arrobj, ieee1905_neighbors, i, 1, "ieee1905_neighbors") {
inst = handle_update_instance(2, dmctx, &max_inst, update_instance_without_section, 1, ++id);
inst = handle_instance_without_section(dmctx, parent_node, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)ieee1905_neighbors, inst) == DM_STOP)
break;
}
@ -217,12 +206,11 @@ static int browseIEEE1905ALNetworkTopologyIEEE1905DeviceIEEE1905NeighborInst(str
static int browseIEEE1905ALNetworkTopologyIEEE1905DeviceBridgingTupleInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
json_object *arrobj = NULL, *bridge_tuple = NULL, *device = (json_object *)prev_data;
char *inst = NULL, *max_inst = NULL;
char *inst = NULL;
int id = 0, i = 0;
dmjson_foreach_obj_in_array(device, arrobj, bridge_tuple, i, 1, "bridge_tuples") {
inst = handle_update_instance(2, dmctx, &max_inst, update_instance_without_section, 1, ++id);
inst = handle_instance_without_section(dmctx, parent_node, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)bridge_tuple, inst) == DM_STOP)
break;
}
@ -233,12 +221,11 @@ static int browseIEEE1905ALNetworkTopologyIEEE1905DeviceBridgingTupleInst(struct
static int browseIEEE1905ALNetworkTopologyIEEE1905DeviceIEEE1905NeighborMetricInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
json_object *arrobj = NULL, *metric = NULL, *ieee1905_neighbors = (json_object *)prev_data;
char *inst = NULL, *max_inst = NULL;
char *inst = NULL;
int id = 0, i = 0;
dmjson_foreach_obj_in_array(ieee1905_neighbors, arrobj, metric, i, 1, "metric") {
inst = handle_update_instance(3, dmctx, &max_inst, update_instance_without_section, 1, ++id);
inst = handle_instance_without_section(dmctx, parent_node, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)metric, inst) == DM_STOP)
break;
}
@ -253,43 +240,31 @@ static int addObjIEEE1905ALForwardingTableForwardingRule(char *refparam, struct
{
struct uci_section *dmmap = NULL, *s = NULL;
char *inst = get_last_instance_bbfdm("dmmap_forwarding_rule", "forwarding_rule", "forwardingruleinstance");
dmuci_add_section("ieee1905", "forwarding_rule", &s);
dmuci_add_section_bbfdm("dmmap_forwarding_rule", "forwarding_rule", &dmmap);
dmuci_set_value_by_section(dmmap, "section_name", section_name(s));
*instance = update_instance(inst, 2, dmmap, "forwardingruleinstance");
dmuci_set_value_by_section(dmmap, "forwardingruleinstance", *instance);
return 0;
}
static int delObjIEEE1905ALForwardingTableForwardingRule(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
struct uci_section *s = NULL, *ss = NULL, *dmmap_section = NULL;
int found = 0;
struct uci_section *s = NULL, *stmp = NULL;
switch (del_action) {
case DEL_INST:
get_dmmap_section_of_config_section("dmmap_forwarding_rule", "forwarding_rule", section_name((struct uci_section *)data), &dmmap_section);
if (dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section((struct uci_section *)data, NULL, NULL);
dmuci_delete_by_section(((struct dmmap_dup *)data)->config_section, NULL, NULL);
dmuci_delete_by_section(((struct dmmap_dup *)data)->dmmap_section, NULL, NULL);
break;
case DEL_ALL:
uci_foreach_sections("ieee1905", "forwarding_rule", s) {
if (found != 0) {
get_dmmap_section_of_config_section("dmmap_forwarding_rule", "forwarding_rule", section_name(ss), &dmmap_section);
if (dmmap_section != NULL)
uci_foreach_sections_safe("ieee1905", "forwarding_rule", stmp, s) {
struct uci_section *dmmap_section = NULL;
get_dmmap_section_of_config_section("dmmap_forwarding_rule", "forwarding_rule", section_name(s), &dmmap_section);
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
ss = s;
found++;
}
if (ss != NULL) {
get_dmmap_section_of_config_section("dmmap_forwarding_rule", "forwarding_rule", section_name(ss), &dmmap_section);
if (dmmap_section != NULL)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
dmuci_delete_by_section(s, NULL, NULL);
}
break;
}
@ -697,7 +672,7 @@ static int get_IEEE1905ALForwardingTable_ForwardingRuleNumberOfEntries(char *ref
/*#Device.IEEE1905.AL.ForwardingTable.ForwardingRule.{i}.InterfaceList!UCI:dmmap_forwarding_rule/forwarding_rule,@i-1/interface_list*/
static int get_IEEE1905ALForwardingTableForwardingRule_InterfaceList(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string((struct uci_section *)data, "interface_list", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "interface_list", value);
return 0;
}
@ -709,7 +684,7 @@ static int set_IEEE1905ALForwardingTableForwardingRule_InterfaceList(char *refpa
return FAULT_9007;
break;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "interface_list", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "interface_list", value);
break;
}
return 0;
@ -718,7 +693,7 @@ static int set_IEEE1905ALForwardingTableForwardingRule_InterfaceList(char *refpa
/*#Device.IEEE1905.AL.ForwardingTable.ForwardingRule.{i}.MACDestinationAddress!UCI:dmmap_forwarding_rule/forwarding_rule,@i-1/mac_destination_addr*/
static int get_IEEE1905ALForwardingTableForwardingRule_MACDestinationAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string((struct uci_section *)data, "mac_destination_addr", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "mac_destination_addr", value);
return 0;
}
@ -730,7 +705,7 @@ static int set_IEEE1905ALForwardingTableForwardingRule_MACDestinationAddress(cha
return FAULT_9007;
break;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "mac_destination_addr", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "mac_destination_addr", value);
break;
}
return 0;
@ -739,7 +714,7 @@ static int set_IEEE1905ALForwardingTableForwardingRule_MACDestinationAddress(cha
/*#Device.IEEE1905.AL.ForwardingTable.ForwardingRule.{i}.MACDestinationAddressFlag!UCI:dmmap_forwarding_rule/forwarding_rule,@i-1/mac_destination_addr_flag*/
static int get_IEEE1905ALForwardingTableForwardingRule_MACDestinationAddressFlag(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string((struct uci_section *)data, "mac_destination_addr_flag", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "mac_destination_addr_flag", value);
return 0;
}
@ -754,7 +729,7 @@ static int set_IEEE1905ALForwardingTableForwardingRule_MACDestinationAddressFlag
break;
case VALUESET:
string_to_bool(value, &b);
dmuci_set_value_by_section((struct uci_section *)data, "mac_destination_addr_flag", b ? "1" : "0");
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "mac_destination_addr_flag", b ? "1" : "0");
break;
}
return 0;
@ -763,7 +738,7 @@ static int set_IEEE1905ALForwardingTableForwardingRule_MACDestinationAddressFlag
/*#Device.IEEE1905.AL.ForwardingTable.ForwardingRule.{i}.MACSourceAddress!UCI:dmmap_forwarding_rule/forwarding_rule,@i-1/mac_source_addr*/
static int get_IEEE1905ALForwardingTableForwardingRule_MACSourceAddress(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string((struct uci_section *)data, "mac_source_addr", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "mac_source_addr", value);
return 0;
}
@ -775,7 +750,7 @@ static int set_IEEE1905ALForwardingTableForwardingRule_MACSourceAddress(char *re
return FAULT_9007;
break;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "mac_source_addr", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "mac_source_addr", value);
break;
}
return 0;
@ -784,7 +759,7 @@ static int set_IEEE1905ALForwardingTableForwardingRule_MACSourceAddress(char *re
/*#Device.IEEE1905.AL.ForwardingTable.ForwardingRule.{i}.MACSourceAddressFlag!UCI:dmmap_forwarding_rule/forwarding_rule,@i-1/mac_source_addr_flag*/
static int get_IEEE1905ALForwardingTableForwardingRule_MACSourceAddressFlag(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string((struct uci_section *)data, "mac_source_addr_flag", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "mac_source_addr_flag", value);
return 0;
}
@ -799,7 +774,7 @@ static int set_IEEE1905ALForwardingTableForwardingRule_MACSourceAddressFlag(char
break;
case VALUESET:
string_to_bool(value, &b);
dmuci_set_value_by_section((struct uci_section *)data, "mac_source_addr_flag", b ? "1" : "0");
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "mac_source_addr_flag", b ? "1" : "0");
break;
}
return 0;
@ -808,7 +783,7 @@ static int set_IEEE1905ALForwardingTableForwardingRule_MACSourceAddressFlag(char
/*#Device.IEEE1905.AL.ForwardingTable.ForwardingRule.{i}.EtherType!UCI:dmmap_forwarding_rule/forwarding_rule,@i-1/ether_type*/
static int get_IEEE1905ALForwardingTableForwardingRule_EtherType(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "ether_type", "0");
*value = dmuci_get_value_by_section_fallback_def(((struct dmmap_dup *)data)->config_section, "ether_type", "0");
return 0;
}
@ -820,7 +795,7 @@ static int set_IEEE1905ALForwardingTableForwardingRule_EtherType(char *refparam,
return FAULT_9007;
break;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "ether_type", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "ether_type", value);
break;
}
return 0;
@ -829,7 +804,7 @@ static int set_IEEE1905ALForwardingTableForwardingRule_EtherType(char *refparam,
/*#Device.IEEE1905.AL.ForwardingTable.ForwardingRule.{i}.EtherTypeFlag!UCI:dmmap_forwarding_rule/forwarding_rule,@i-1/ether_type_flag*/
static int get_IEEE1905ALForwardingTableForwardingRule_EtherTypeFlag(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string((struct uci_section *)data, "ether_type_flag", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "ether_type_flag", value);
return 0;
}
@ -844,7 +819,7 @@ static int set_IEEE1905ALForwardingTableForwardingRule_EtherTypeFlag(char *refpa
break;
case VALUESET:
string_to_bool(value, &b);
dmuci_set_value_by_section((struct uci_section *)data, "ether_type_flag", b ? "1" : "0");
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "ether_type_flag", b ? "1" : "0");
break;
}
return 0;
@ -853,7 +828,7 @@ static int set_IEEE1905ALForwardingTableForwardingRule_EtherTypeFlag(char *refpa
/*#Device.IEEE1905.AL.ForwardingTable.ForwardingRule.{i}.Vid!UCI:dmmap_forwarding_rule/forwarding_rule,@i-1/vid*/
static int get_IEEE1905ALForwardingTableForwardingRule_Vid(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "vid", "0");
*value = dmuci_get_value_by_section_fallback_def(((struct dmmap_dup *)data)->config_section, "vid", "0");
return 0;
}
@ -865,7 +840,7 @@ static int set_IEEE1905ALForwardingTableForwardingRule_Vid(char *refparam, struc
return FAULT_9007;
break;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "vid", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "vid", value);
break;
}
return 0;
@ -874,7 +849,7 @@ static int set_IEEE1905ALForwardingTableForwardingRule_Vid(char *refparam, struc
/*#Device.IEEE1905.AL.ForwardingTable.ForwardingRule.{i}.VidFlag!UCI:dmmap_forwarding_rule/forwarding_rule,@i-1/vid_flag*/
static int get_IEEE1905ALForwardingTableForwardingRule_VidFlag(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string((struct uci_section *)data, "vid_flag", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "vid_flag", value);
return 0;
}
@ -889,7 +864,7 @@ static int set_IEEE1905ALForwardingTableForwardingRule_VidFlag(char *refparam, s
break;
case VALUESET:
string_to_bool(value, &b);
dmuci_set_value_by_section((struct uci_section *)data, "vid_flag", b ? "1" : "0");
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "vid_flag", b ? "1" : "0");
break;
}
return 0;
@ -898,7 +873,7 @@ static int set_IEEE1905ALForwardingTableForwardingRule_VidFlag(char *refparam, s
/*#Device.IEEE1905.AL.ForwardingTable.ForwardingRule.{i}.PCP!UCI:dmmap_forwarding_rule/forwarding_rule,@i-1/pcp*/
static int get_IEEE1905ALForwardingTableForwardingRule_PCP(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "pcp", "0");
*value = dmuci_get_value_by_section_fallback_def(((struct dmmap_dup *)data)->config_section, "pcp", "0");
return 0;
}
@ -910,7 +885,7 @@ static int set_IEEE1905ALForwardingTableForwardingRule_PCP(char *refparam, struc
return FAULT_9007;
break;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "pcp", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "pcp", value);
break;
}
return 0;
@ -919,7 +894,7 @@ static int set_IEEE1905ALForwardingTableForwardingRule_PCP(char *refparam, struc
/*#Device.IEEE1905.AL.ForwardingTable.ForwardingRule.{i}.PCPFlag!UCI:dmmap_forwarding_rule/forwarding_rule,@i-1/pcp_flag*/
static int get_IEEE1905ALForwardingTableForwardingRule_PCPFlag(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string((struct uci_section *)data, "pcp_flag", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "pcp_flag", value);
return 0;
}
@ -934,7 +909,7 @@ static int set_IEEE1905ALForwardingTableForwardingRule_PCPFlag(char *refparam, s
break;
case VALUESET:
string_to_bool(value, &b);
dmuci_set_value_by_section((struct uci_section *)data, "pcp_flag", b ? "1" : "0");
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "pcp_flag", b ? "1" : "0");
break;
}
return 0;

View file

@ -88,7 +88,7 @@ static struct uci_section *create_dmmap_interface_stack_section(char *curr_inst)
return s;
}
static int create_and_link_interface_stack_instance(struct dmctx *dmctx, DMNODE *parent_node, char *higherlayer, char *lowerlayer, char *higheralias, char *loweralias, char *max_inst, int *instance)
static int create_and_link_interface_stack_instance(struct dmctx *dmctx, DMNODE *parent_node, char *higherlayer, char *lowerlayer, char *higheralias, char *loweralias, int *instance)
{
struct interfacestack_data intf_stack_data = {0};
char buf_instance[16] = {0};
@ -104,8 +104,7 @@ static int create_and_link_interface_stack_instance(struct dmctx *dmctx, DMNODE
struct uci_section *dmmap_s = create_dmmap_interface_stack_section(buf_instance);
// link instance to interface stack data
char *inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
dmmap_s, "interface_stack_instance", "interface_stack_alias");
char *inst = handle_instance(dmctx, parent_node, dmmap_s, "interface_stack_instance", "interface_stack_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&intf_stack_data, inst) == DM_STOP)
return -1;
@ -117,7 +116,6 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
{
struct uci_section *s = NULL;
char *layer_inst = "", *loweralias = "", *higheralias = "";
char *max_inst = NULL;
char buf_lowerlayer[128] = {0};
char buf_higherlayer[128] = {0};
char buf_higheralias[64] = {0};
@ -197,7 +195,7 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
snprintf(buf_loweralias, sizeof(buf_loweralias), "%s%s", *loweralias ? loweralias : *layer_inst ? "cpe-" : "", (*loweralias == '\0' && *layer_inst) ? layer_inst : "");
}
if (create_and_link_interface_stack_instance(dmctx, parent_node, buf_higherlayer, buf_lowerlayer, buf_higheralias, buf_loweralias, max_inst, &instance))
if (create_and_link_interface_stack_instance(dmctx, parent_node, buf_higherlayer, buf_lowerlayer, buf_higheralias, buf_loweralias, &instance))
goto end;
}
@ -249,7 +247,7 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
snprintf(buf_lowerlayer, sizeof(buf_lowerlayer), "%s", value);
snprintf(buf_loweralias, sizeof(buf_loweralias), "%s%s", *loweralias ? loweralias : *layer_inst ? "cpe-" : "", (*loweralias == '\0' && *layer_inst) ? layer_inst : "");
if (create_and_link_interface_stack_instance(dmctx, parent_node, buf_higherlayer, buf_lowerlayer, buf_higheralias, buf_loweralias, max_inst, &instance))
if (create_and_link_interface_stack_instance(dmctx, parent_node, buf_higherlayer, buf_lowerlayer, buf_higheralias, buf_loweralias, &instance))
goto end;
}
@ -286,7 +284,7 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
snprintf(buf_lowerlayer, sizeof(buf_lowerlayer), "%s", value);
snprintf(buf_loweralias, sizeof(buf_loweralias), "%s%s", *loweralias ? loweralias : *layer_inst ? "cpe-" : "", (*loweralias == '\0' && *layer_inst) ? layer_inst : "");
if (create_and_link_interface_stack_instance(dmctx, parent_node, buf_higherlayer, buf_lowerlayer, buf_higheralias, buf_loweralias, max_inst, &instance))
if (create_and_link_interface_stack_instance(dmctx, parent_node, buf_higherlayer, buf_lowerlayer, buf_higheralias, buf_loweralias, &instance))
goto end;
}
@ -360,7 +358,7 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
snprintf(buf_lowerlayer, sizeof(buf_lowerlayer), "%s", value);
snprintf(buf_loweralias, sizeof(buf_loweralias), "%s%s", *loweralias ? loweralias : *layer_inst ? "cpe-" : "", (*loweralias == '\0' && *layer_inst) ? layer_inst : "");
if (create_and_link_interface_stack_instance(dmctx, parent_node, buf_higherlayer, buf_lowerlayer, buf_higheralias, buf_loweralias, max_inst, &instance))
if (create_and_link_interface_stack_instance(dmctx, parent_node, buf_higherlayer, buf_lowerlayer, buf_higheralias, buf_loweralias, &instance))
goto end;
}
@ -420,7 +418,7 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
snprintf(buf_loweralias, sizeof(buf_loweralias), "%s%s", *loweralias ? loweralias : *bridge_port_inst ? "cpe-" : "", (*loweralias == '\0' && *bridge_port_inst) ? bridge_port_inst : "");
if (create_and_link_interface_stack_instance(dmctx, parent_node, mg_value, vb, buf_mngr, buf_loweralias, max_inst, &instance))
if (create_and_link_interface_stack_instance(dmctx, parent_node, mg_value, vb, buf_mngr, buf_loweralias, &instance))
goto end;
snprintf(buf_higheralias, sizeof(buf_higheralias), "%s%s", *loweralias ? loweralias : *bridge_port_inst ? "cpe-" : "", (*loweralias == '\0' && *bridge_port_inst) ? bridge_port_inst : "");
@ -513,7 +511,7 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
snprintf(buf_loweralias, sizeof(buf_loweralias), "%s%s", *loweralias ? loweralias : *bridge_port_inst ? "cpe-" : "", (*loweralias == '\0' && *bridge_port_inst) ? bridge_port_inst : "");
if (create_and_link_interface_stack_instance(dmctx, parent_node, vb, value, buf_higheralias, buf_loweralias, max_inst, &instance))
if (create_and_link_interface_stack_instance(dmctx, parent_node, vb, value, buf_higheralias, buf_loweralias, &instance))
goto end;
// The lower layer is Device.WiFi.Radio.{i}.
@ -545,7 +543,7 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
snprintf(buf_loweralias, sizeof(buf_loweralias), "%s%s", *loweralias ? loweralias : *bridge_port_inst ? "cpe-" : "", (*loweralias == '\0' && *bridge_port_inst) ? bridge_port_inst : "");
if (create_and_link_interface_stack_instance(dmctx, parent_node, value, vb, buf_higheralias, buf_loweralias, max_inst, &instance))
if (create_and_link_interface_stack_instance(dmctx, parent_node, value, vb, buf_higheralias, buf_loweralias, &instance))
goto end;
}
@ -567,7 +565,7 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
snprintf(buf_loweralias, sizeof(buf_loweralias), "%s%s", *loweralias ? loweralias : *bridge_port_inst ? "cpe-" : "", (*loweralias == '\0' && *bridge_port_inst) ? bridge_port_inst : "");
if (create_and_link_interface_stack_instance(dmctx, parent_node, value, vb, buf_higheralias, buf_loweralias, max_inst, &instance))
if (create_and_link_interface_stack_instance(dmctx, parent_node, value, vb, buf_higheralias, buf_loweralias, &instance))
goto end;
}
@ -589,7 +587,7 @@ int browseInterfaceStackInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
snprintf(buf_loweralias, sizeof(buf_loweralias), "%s%s", *loweralias ? loweralias : *bridge_port_inst ? "cpe-" : "", (*loweralias == '\0' && *bridge_port_inst) ? bridge_port_inst : "");
if (create_and_link_interface_stack_instance(dmctx, parent_node, vb, value, buf_higheralias, buf_loweralias, max_inst, &instance))
if (create_and_link_interface_stack_instance(dmctx, parent_node, vb, value, buf_higheralias, buf_loweralias, &instance))
goto end;
}
}
@ -654,6 +652,9 @@ static int get_InterfaceStack_LowerAlias(char *refparam, struct dmctx *ctx, void
return 0;
}
/**********************************************************************************************************************************
* OBJ & PARAM DEFINITION
***********************************************************************************************************************************/
/* *** Device.InterfaceStack.{i}. *** */
DMLEAF tInterfaceStackParams[] = {
/* PARAM, permission, type, getvalue, setvalue, bbfdm_type*/

View file

@ -330,56 +330,6 @@ static void synchronize_intf_ipv6_prefix_sections_with_dmmap(void)
}
}
static char *get_ip_interface_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, *proto, *device;
uci_foreach_sections(package, section, s) {
dmuci_get_value_by_section_string(s, "proto", &proto);
dmuci_get_value_by_section_string(s, "device", &device);
if (strcmp(section_name(s), "loopback") == 0 ||
*proto == '\0' ||
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(s), &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;
}
// skip dhcpv6 sections added by controller
if (strcmp(proto, "dhcpv6") == 0) {
struct uci_section *dmmap_section = NULL;
char *dhcpv6_user_s = NULL;
get_dmmap_section_of_config_section("dmmap_dhcpv6", "interface", section_name(s), &dmmap_section);
dmuci_get_value_by_section_string(dmmap_section, "added_by_controller", &dhcpv6_user_s);
if (dhcpv6_user_s && strcmp(dhcpv6_user_s, "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;
}
static int delete_ip_intertace_instance(struct uci_section *s)
{
struct uci_section *int_ss = NULL, *int_stmp = NULL;
@ -573,7 +523,7 @@ static int delObjIPInterfaceIPv6(void *data, unsigned char del_action, char *dmm
/*#Device.IP.Interface.{i}.!UCI:network/interface/dmmap_network*/
static int browseIPInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *max_inst = NULL;
char *inst = NULL;
char *proto, *device;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
@ -611,8 +561,7 @@ static int browseIPInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void
continue;
}
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
p->dmmap_section, "ip_int_instance", "ip_int_alias");
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)
break;
@ -624,10 +573,9 @@ static int browseIPInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void
static int browseIPInterfaceIPv4AddressInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct uci_section *parent_sec = (struct uci_section *)prev_data, *intf_s = NULL, *dmmap_s = NULL;
char *inst = NULL, *max_inst = NULL, *ipaddr, *added_by_controller = NULL, *device, buf[32] = {0};
char *inst = NULL, *ipaddr, *added_by_controller = NULL, *device, buf[32] = {0};
json_object *res = NULL, *ipv4_obj = NULL;
struct intf_ip_args curr_intf_ip_args = {0};
struct browse_args browse_args = {0};
snprintf(buf, sizeof(buf), "@%s", section_name(parent_sec));
@ -655,12 +603,7 @@ static int browseIPInterfaceIPv4AddressInst(struct dmctx *dmctx, DMNODE *parent_
init_interface_ip_args(&curr_intf_ip_args, intf_s, dmmap_s, res);
browse_args.option = "parent_section";
browse_args.value = section_name(parent_sec);
inst = handle_update_instance(2, dmctx, &max_inst, update_instance_alias, 5,
dmmap_s, "ipv4_instance", "ipv4_alias",
check_browse_section, (void *)&browse_args);
inst = handle_instance(dmctx, parent_node, dmmap_s, "ipv4_instance", "ipv4_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_intf_ip_args, inst) == DM_STOP)
break;
@ -671,10 +614,9 @@ static int browseIPInterfaceIPv4AddressInst(struct dmctx *dmctx, DMNODE *parent_
static int browseIPInterfaceIPv6AddressInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct uci_section *parent_sec = (struct uci_section *)prev_data, *intf_s = NULL, *dmmap_s = NULL;
char *inst = NULL, *max_inst = NULL, *device, *ip6addr, buf[32] = {0};
char *inst = NULL, *device, *ip6addr, buf[32] = {0};
json_object *res = NULL, *ipv6_obj = NULL, *arrobj = NULL;
struct intf_ip_args curr_intf_ip_args = {0};
struct browse_args browse_args = {0};
int i = 0;
snprintf(buf, sizeof(buf), "@%s", section_name(parent_sec));
@ -702,12 +644,7 @@ static int browseIPInterfaceIPv6AddressInst(struct dmctx *dmctx, DMNODE *parent_
init_interface_ip_args(&curr_intf_ip_args, intf_s, dmmap_s, ipv6_obj);
browse_args.option = "parent_section";
browse_args.value = section_name(parent_sec);
inst = handle_update_instance(2, dmctx, &max_inst, update_instance_alias, 5,
dmmap_s, "ipv6_instance", "ipv6_alias",
check_browse_section, (void *)&browse_args);
inst = handle_instance(dmctx, parent_node, dmmap_s, "ipv6_instance", "ipv6_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_intf_ip_args, inst) == DM_STOP)
goto end;
@ -719,12 +656,7 @@ static int browseIPInterfaceIPv6AddressInst(struct dmctx *dmctx, DMNODE *parent_
init_interface_ip_args(&curr_intf_ip_args, intf_s, dmmap_s, NULL);
browse_args.option = "parent_section";
browse_args.value = section_name(parent_sec);
inst = handle_update_instance(2, dmctx, &max_inst, update_instance_alias, 5,
dmmap_s, "ipv6_instance", "ipv6_alias",
check_browse_section, (void *)&browse_args);
inst = handle_instance(dmctx, parent_node, dmmap_s, "ipv6_instance", "ipv6_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_intf_ip_args, inst) == DM_STOP)
goto end;
@ -741,12 +673,7 @@ static int browseIPInterfaceIPv6AddressInst(struct dmctx *dmctx, DMNODE *parent_
init_interface_ip_args(&curr_intf_ip_args, intf_s, dmmap_s, ipv6_obj);
browse_args.option = "parent_section";
browse_args.value = section_name(parent_sec);
inst = handle_update_instance(2, dmctx, &max_inst, update_instance_alias, 5,
dmmap_s, "ipv6_instance", "ipv6_alias",
check_browse_section, (void *)&browse_args);
inst = handle_instance(dmctx, parent_node, dmmap_s, "ipv6_instance", "ipv6_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_intf_ip_args, inst) == DM_STOP)
goto end;
@ -766,12 +693,7 @@ static int browseIPInterfaceIPv6AddressInst(struct dmctx *dmctx, DMNODE *parent_
init_interface_ip_args(&curr_intf_ip_args, NULL, dmmap_s, NULL);
browse_args.option = "parent_section";
browse_args.value = section_name(parent_sec);
inst = handle_update_instance(2, dmctx, &max_inst, update_instance_alias, 5,
dmmap_s, "ipv6_instance", "ipv6_alias",
check_browse_section, (void *)&browse_args);
inst = handle_instance(dmctx, parent_node, dmmap_s, "ipv6_instance", "ipv6_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_intf_ip_args, inst) == DM_STOP)
goto end;
@ -786,10 +708,9 @@ end:
static int browseIPInterfaceIPv6PrefixInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct uci_section *parent_sec = (struct uci_section *)prev_data, *intf_s = NULL, *dmmap_s = NULL;
char *inst = NULL, *max_inst = NULL, *device, *ip6prefix, buf[32] = {0}, ipv6_prefix[256] = {0};
char *inst = NULL, *device, *ip6prefix, buf[32] = {0}, ipv6_prefix[256] = {0};
json_object *res = NULL, *ipv6_prefix_obj = NULL, *arrobj = NULL;
struct intf_ip_args curr_intf_ip_args = {0};
struct browse_args browse_args = {0};
int i = 0;
snprintf(buf, sizeof(buf), "@%s", section_name(parent_sec));
@ -819,12 +740,7 @@ static int browseIPInterfaceIPv6PrefixInst(struct dmctx *dmctx, DMNODE *parent_n
init_interface_ip_args(&curr_intf_ip_args, intf_s, dmmap_s, ipv6_prefix_obj);
browse_args.option = "parent_section";
browse_args.value = section_name(parent_sec);
inst = handle_update_instance(2, dmctx, &max_inst, update_instance_alias, 5,
dmmap_s, "ipv6_prefix_instance", "ipv6_prefix_alias",
check_browse_section, (void *)&browse_args);
inst = handle_instance(dmctx, parent_node, dmmap_s, "ipv6_prefix_instance", "ipv6_prefix_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_intf_ip_args, inst) == DM_STOP)
goto end;
@ -836,12 +752,7 @@ static int browseIPInterfaceIPv6PrefixInst(struct dmctx *dmctx, DMNODE *parent_n
init_interface_ip_args(&curr_intf_ip_args, intf_s, dmmap_s, NULL);
browse_args.option = "parent_section";
browse_args.value = section_name(parent_sec);
inst = handle_update_instance(2, dmctx, &max_inst, update_instance_alias, 5,
dmmap_s, "ipv6_prefix_instance", "ipv6_prefix_alias",
check_browse_section, (void *)&browse_args);
inst = handle_instance(dmctx, parent_node, dmmap_s, "ipv6_prefix_instance", "ipv6_prefix_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_intf_ip_args, inst) == DM_STOP)
goto end;
@ -860,12 +771,7 @@ static int browseIPInterfaceIPv6PrefixInst(struct dmctx *dmctx, DMNODE *parent_n
init_interface_ip_args(&curr_intf_ip_args, intf_s, dmmap_s, ipv6_prefix_obj);
browse_args.option = "parent_section";
browse_args.value = section_name(parent_sec);
inst = handle_update_instance(2, dmctx, &max_inst, update_instance_alias, 5,
dmmap_s, "ipv6_prefix_instance", "ipv6_prefix_alias",
check_browse_section, (void *)&browse_args);
inst = handle_instance(dmctx, parent_node, dmmap_s, "ipv6_prefix_instance", "ipv6_prefix_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_intf_ip_args, inst) == DM_STOP)
goto end;
@ -884,8 +790,7 @@ static int addObjIPInterface(char *refparam, struct dmctx *ctx, void *data, char
struct uci_section *dmmap_ip_interface;
char ip_name[32] = {0};
char *last_inst = get_ip_interface_last_instance("network", "interface", "dmmap_network", "ip_int_instance");
snprintf(ip_name, sizeof(ip_name), "ip_interface_%d", last_inst ? atoi(last_inst) + 1 : 1);
snprintf(ip_name, sizeof(ip_name), "ip_interface_%s", *instance);
dmuci_set_value("network", ip_name, "", "interface");
dmuci_set_value("network", ip_name, "proto", "none");
@ -893,7 +798,7 @@ static int addObjIPInterface(char *refparam, struct dmctx *ctx, void *data, char
dmuci_add_section_bbfdm("dmmap_network", "interface", &dmmap_ip_interface);
dmuci_set_value_by_section(dmmap_ip_interface, "section_name", ip_name);
*instance = update_instance(last_inst, 2, dmmap_ip_interface, "ip_int_instance");
dmuci_set_value_by_section(dmmap_ip_interface, "ip_int_instance", *instance);
return 0;
}
@ -927,17 +832,14 @@ static int addObjIPInterfaceIPv4Address(char *refparam, struct dmctx *ctx, void
{
char *ip_inst = NULL, ipv4_name[64] = {0};
struct uci_section *dmmap_ip_interface = NULL, *dmmap_ip_interface_ipv4 = NULL;
struct browse_args browse_args = {0};
get_dmmap_section_of_config_section("dmmap_network", "interface", section_name((struct uci_section *)data), &dmmap_ip_interface);
dmuci_get_value_by_section_string(dmmap_ip_interface, "ip_int_instance", &ip_inst);
char *last_inst = get_last_instance_lev2_bbfdm_dmmap_opt("dmmap_network_ipv4", "intf_ipv4", "ipv4_instance", "parent_section", section_name((struct uci_section *)data));
if (last_inst) {
if (!strcmp(*instance, "1")) {
char device_buf[32] = {0};
snprintf(ipv4_name, sizeof(ipv4_name), "ip_interface_%s_ipv4_%d", ip_inst, atoi(last_inst) + 1);
snprintf(ipv4_name, sizeof(ipv4_name), "ip_interface_%s_ipv4_%s", ip_inst, *instance);
snprintf(device_buf, sizeof(device_buf), "@%s", section_name((struct uci_section *)data));
dmuci_set_value("network", ipv4_name, "", "interface");
@ -950,15 +852,11 @@ static int addObjIPInterfaceIPv4Address(char *refparam, struct dmctx *ctx, void
dmuci_set_value_by_section((struct uci_section *)data, "proto", strcmp(proto, "dhcp") == 0 ? proto : "static");
}
browse_args.option = "parent_section";
browse_args.value = section_name((struct uci_section *)data);
dmuci_add_section_bbfdm("dmmap_network_ipv4", "intf_ipv4", &dmmap_ip_interface_ipv4);
dmuci_set_value_by_section(dmmap_ip_interface_ipv4, "parent_section", section_name((struct uci_section *)data));
dmuci_set_value_by_section(dmmap_ip_interface_ipv4, "section_name", last_inst ? ipv4_name : section_name((struct uci_section *)data));
dmuci_set_value_by_section(dmmap_ip_interface_ipv4, "section_name", !strcmp(*instance, "1") ? ipv4_name : section_name((struct uci_section *)data));
dmuci_set_value_by_section(dmmap_ip_interface_ipv4, "added_by_controller", "1");
*instance = update_instance(last_inst, 5, dmmap_ip_interface_ipv4, "ipv4_instance", NULL, check_browse_section, (void *)&browse_args);
dmuci_set_value_by_section(dmmap_ip_interface_ipv4, "ipv4_instance", *instance);
return 0;
}
@ -1018,13 +916,11 @@ static int addObjIPInterfaceIPv6Address(char *refparam, struct dmctx *ctx, void
{
char *ip_inst = NULL, ipv6_name[64] = {0}, device_buf[32] = {0};
struct uci_section *dmmap_ip_interface = NULL, *dmmap_ip_interface_ipv6 = NULL;
struct browse_args browse_args = {0};
get_dmmap_section_of_config_section("dmmap_network", "interface", section_name((struct uci_section *)data), &dmmap_ip_interface);
dmuci_get_value_by_section_string(dmmap_ip_interface, "ip_int_instance", &ip_inst);
char *last_inst = get_last_instance_lev2_bbfdm_dmmap_opt("dmmap_network_ipv6", "intf_ipv6", "ipv6_instance", "parent_section", section_name((struct uci_section *)data));
snprintf(ipv6_name, sizeof(ipv6_name), "ip_interface_%s_ipv6_%d", ip_inst, last_inst ? atoi(last_inst) + 1 : 1);
snprintf(ipv6_name, sizeof(ipv6_name), "ip_interface_%s_ipv6_%s", ip_inst, *instance);
snprintf(device_buf, sizeof(device_buf), "@%s", section_name((struct uci_section *)data));
dmuci_set_value("network", ipv6_name, "", "interface");
@ -1032,15 +928,11 @@ static int addObjIPInterfaceIPv6Address(char *refparam, struct dmctx *ctx, void
dmuci_set_value("network", ipv6_name, "proto", "static");
dmuci_set_value("network", ipv6_name, "ip6addr", "::");
browse_args.option = "parent_section";
browse_args.value = section_name((struct uci_section *)data);
dmuci_add_section_bbfdm("dmmap_network_ipv6", "intf_ipv6", &dmmap_ip_interface_ipv6);
dmuci_set_value_by_section(dmmap_ip_interface_ipv6, "parent_section", section_name((struct uci_section *)data));
dmuci_set_value_by_section(dmmap_ip_interface_ipv6, "section_name", ipv6_name);
dmuci_set_value_by_section(dmmap_ip_interface_ipv6, "address", "::");
*instance = update_instance(last_inst, 5, dmmap_ip_interface_ipv6, "ipv6_instance", NULL, check_browse_section, (void *)&browse_args);
dmuci_set_value_by_section(dmmap_ip_interface_ipv6, "ipv6_instance", *instance);
return 0;
}
@ -1053,13 +945,11 @@ static int addObjIPInterfaceIPv6Prefix(char *refparam, struct dmctx *ctx, void *
{
char *ip_inst = NULL, ipv6_prefix_name[64] = {0}, device_buf[32] = {0};
struct uci_section *dmmap_ip_interface = NULL, *dmmap_ip_interface_ipv6_prefix = NULL;
struct browse_args browse_args = {0};
get_dmmap_section_of_config_section("dmmap_network", "interface", section_name((struct uci_section *)data), &dmmap_ip_interface);
dmuci_get_value_by_section_string(dmmap_ip_interface, "ip_int_instance", &ip_inst);
char *last_inst = get_last_instance_lev2_bbfdm_dmmap_opt("dmmap_network_ipv6_prefix", "intf_ipv6_prefix", "ipv6_prefix_instance", "parent_section", section_name((struct uci_section *)data));
snprintf(ipv6_prefix_name, sizeof(ipv6_prefix_name), "ip_interface_%s_ipv6_prefix_%d", ip_inst, last_inst ? atoi(last_inst) + 1 : 1);
snprintf(ipv6_prefix_name, sizeof(ipv6_prefix_name), "ip_interface_%s_ipv6_prefix_%s", ip_inst, *instance);
snprintf(device_buf, sizeof(device_buf), "@%s", section_name((struct uci_section *)data));
dmuci_set_value("network", ipv6_prefix_name, "", "interface");
@ -1067,15 +957,11 @@ static int addObjIPInterfaceIPv6Prefix(char *refparam, struct dmctx *ctx, void *
dmuci_set_value("network", ipv6_prefix_name, "proto", "static");
dmuci_set_value("network", ipv6_prefix_name, "ip6prefix", "::/64");
browse_args.option = "parent_section";
browse_args.value = section_name((struct uci_section *)data);
dmuci_add_section_bbfdm("dmmap_network_ipv6_prefix", "intf_ipv6_prefix", &dmmap_ip_interface_ipv6_prefix);
dmuci_set_value_by_section(dmmap_ip_interface_ipv6_prefix, "parent_section", section_name((struct uci_section *)data));
dmuci_set_value_by_section(dmmap_ip_interface_ipv6_prefix, "section_name", ipv6_prefix_name);
dmuci_set_value_by_section(dmmap_ip_interface_ipv6_prefix, "address", "::/64");
*instance = update_instance(last_inst, 5, dmmap_ip_interface_ipv6_prefix, "ipv6_prefix_instance", NULL, check_browse_section, (void *)&browse_args);
dmuci_set_value_by_section(dmmap_ip_interface_ipv6_prefix, "ipv6_prefix_instance", *instance);
return 0;
}
@ -1213,21 +1099,7 @@ static int set_IP_ULAPrefix(char *refparam, struct dmctx *ctx, void *data, char
static int get_IP_InterfaceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s = NULL;
int cnt = 0;
char *proto, *device;
uci_foreach_sections("network", "interface", s) {
dmuci_get_value_by_section_string(s, "proto", &proto);
dmuci_get_value_by_section_string(s, "device", &device);
if (strcmp(section_name(s), "loopback") == 0 ||
*proto == '\0' ||
strchr(device, '@'))
continue;
cnt++;
}
int cnt = get_number_of_entries(ctx, data, instance, browseIPInterfaceInst);
dmasprintf(value, "%d", cnt);
return 0;
}
@ -1660,50 +1532,21 @@ static int set_IPInterface_Loopback(char *refparam, struct dmctx *ctx, void *dat
static int get_IPInterface_IPv4AddressNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s = NULL;
int cnt = 0;
uci_path_foreach_option_eq(bbfdm, "dmmap_network_ipv4", "intf_ipv4", "parent_section", section_name((struct uci_section *)data), s) {
cnt++;
}
int cnt = get_number_of_entries(ctx, data, instance, browseIPInterfaceIPv4AddressInst);
dmasprintf(value, "%d", cnt);
return 0;
}
static int get_IPInterface_IPv6AddressNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s = NULL;
int cnt = 0;
synchronize_intf_ipv6_sections_with_dmmap();
uci_path_foreach_option_eq(bbfdm, "dmmap_network_ipv6", "intf_ipv6", "parent_section", section_name((struct uci_section *)data), s) {
cnt++;
}
int cnt = get_number_of_entries(ctx, data, instance, browseIPInterfaceIPv6AddressInst);
dmasprintf(value, "%d", cnt);
return 0;
}
static int get_IPInterface_IPv6PrefixNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s = NULL;
int cnt = 0;
synchronize_intf_ipv6_prefix_sections_with_dmmap();
uci_path_foreach_option_eq(bbfdm, "dmmap_network_ipv6_prefix", "intf_ipv6_prefix", "parent_section", section_name((struct uci_section *)data), s) {
cnt++;
}
dmasprintf(value, "%d", cnt);
return 0;
}
static int get_IPInterface_TWAMPReflectorNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s = NULL;
int cnt = 0;
uci_foreach_option_eq("twamp", "twamp_reflector", "interface", section_name((struct uci_section *)data), s) {
cnt++;
}
int cnt = get_number_of_entries(ctx, data, instance, browseIPInterfaceIPv6PrefixInst);
dmasprintf(value, "%d", cnt);
return 0;
}
@ -2434,7 +2277,6 @@ DMLEAF tIPInterfaceParams[] = {
{"IPv6AddressNumberOfEntries", &DMREAD, DMT_UNINT, get_IPInterface_IPv6AddressNumberOfEntries, NULL, BBFDM_BOTH},
{"IPv6PrefixNumberOfEntries", &DMREAD, DMT_UNINT, get_IPInterface_IPv6PrefixNumberOfEntries, NULL, BBFDM_BOTH},
//{"AutoIPEnable", &DMWRITE, DMT_BOOL, get_IPInterface_AutoIPEnable, set_IPInterface_AutoIPEnable, BBFDM_BOTH},
{"TWAMPReflectorNumberOfEntries", &DMREAD, DMT_UNINT, get_IPInterface_TWAMPReflectorNumberOfEntries, NULL, BBFDM_BOTH},
{"Reset()", &DMSYNC, DMT_COMMAND, NULL, operate_IPInterface_Reset, BBFDM_USP},
{0}
};

View file

@ -1,3 +1,13 @@
/*
* Copyright (C) 2021 iopsys Software Solutions AB
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 2.1
* as published by the Free Software Foundation
*
* Author: Amin Ben Ramdhane <amin.benramdhane@pivasoftware.com>
*/
#include "lanconfigsecurity.h"
/*#Device.LANConfigSecurity.ConfigPassword!UCI:users/user,user/password*/
@ -21,6 +31,9 @@ static int set_LANConfigSecurity_ConfigPassword(char *refparam, struct dmctx *ct
return 0;
}
/**********************************************************************************************************************************
* OBJ & PARAM DEFINITION
***********************************************************************************************************************************/
DMLEAF tLANConfigSecurityParams[] = {
{"ConfigPassword", &DMWRITE, DMT_STRING, get_LANConfigSecurity_ConfigPassword, set_LANConfigSecurity_ConfigPassword, BBFDM_BOTH},
{0}

View file

@ -1,3 +1,13 @@
/*
* Copyright (C) 2021 iopsys Software Solutions AB
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 2.1
* as published by the Free Software Foundation
*
* Author: Amin Ben Ramdhane <amin.benramdhane@pivasoftware.com>
*/
#ifndef __LANCONFIGSECURITY_H
#define __LANCONFIGSECURITY_H

View file

@ -580,6 +580,9 @@ static int get_management_server_supported_conn_req_methods(char *refparam, stru
return 0;
}
/**********************************************************************************************************************************
* OBJ & PARAM DEFINITION
***********************************************************************************************************************************/
/*** ManagementServer. ***/
DMLEAF tManagementServerParams[] = {
/* PARAM, permission, type, getvalue, setvalue, bbfdm_type*/

View file

@ -13,6 +13,49 @@
#include "dmentry.h"
#include "nat.h"
/*************************************************************
* ENTRY METHOD
**************************************************************/
/*#Device.NAT.InterfaceSetting.{i}.!UCI:firewall/zone/dmmap_firewall*/
static int browseInterfaceSettingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("firewall", "zone", "dmmap_firewall", &dup_list);
list_for_each_entry(p, &dup_list, list) {
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "interface_setting_instance", "interface_setting_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p, inst) == DM_STOP)
break;
}
free_dmmap_config_dup_list(&dup_list);
return 0;
}
/*#Device.NAT.PortMapping.{i}.!UCI:firewall/redirect/dmmap_firewall*/
static int browsePortMappingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *target;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("firewall", "redirect", "dmmap_firewall", &dup_list);
list_for_each_entry(p, &dup_list, list) {
dmuci_get_value_by_section_string(p->config_section, "target", &target);
if (*target != '\0' && strcmp(target, "DNAT") != 0)
continue;
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "port_mapping_instance", "port_mapping_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p, inst) == DM_STOP)
break;
}
free_dmmap_config_dup_list(&dup_list);
return 0;
}
/*************************************************************
* ADD DEL OBJ
@ -22,8 +65,7 @@ static int add_NAT_InterfaceSetting(char *refparam, struct dmctx *ctx, void *dat
struct uci_section *s = NULL, *dmmap_firewall = NULL;
char name[32];
char *inst = get_last_instance_bbfdm("dmmap_firewall", "zone", "interface_setting_instance");
snprintf(name, sizeof(name), "iface_set_%d", inst ? (atoi(inst)+1) : 1);
snprintf(name, sizeof(name), "iface_set_%s", *instance);
dmuci_add_section("firewall", "zone", &s);
dmuci_set_value_by_section(s, "input", "REJECT");
@ -33,41 +75,29 @@ static int add_NAT_InterfaceSetting(char *refparam, struct dmctx *ctx, void *dat
dmuci_add_section_bbfdm("dmmap_firewall", "zone", &dmmap_firewall);
dmuci_set_value_by_section(dmmap_firewall, "section_name", section_name(s));
*instance = update_instance(inst, 2, dmmap_firewall, "interface_setting_instance");
dmuci_set_value_by_section(dmmap_firewall, "interface_setting_instance", *instance);
return 0;
}
static int delete_NAT_InterfaceSetting(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
int found = 0;
struct uci_section *s = NULL, *ss = NULL, *dmmap_firewall = NULL;
struct uci_section *s = NULL, *stmp = NULL;
switch (del_action) {
case DEL_INST:
get_dmmap_section_of_config_section("dmmap_firewall", "zone", section_name((struct uci_section *)data), &dmmap_firewall);
if (dmmap_firewall)
dmuci_delete_by_section(dmmap_firewall, NULL, NULL);
dmuci_delete_by_section((struct uci_section *)data, NULL, NULL);
dmuci_delete_by_section(((struct dmmap_dup *)data)->config_section, NULL, NULL);
dmuci_delete_by_section(((struct dmmap_dup *)data)->dmmap_section, NULL, NULL);
break;
case DEL_ALL:
uci_foreach_sections("firewall", "zone", s) {
if (found != 0) {
get_dmmap_section_of_config_section("dmmap_firewall", "zone", section_name(ss), &dmmap_firewall);
if (dmmap_firewall)
uci_foreach_sections_safe("firewall", "zone", stmp, s) {
struct uci_section *dmmap_firewall = NULL;
get_dmmap_section_of_config_section("dmmap_firewall", "zone", section_name(s), &dmmap_firewall);
dmuci_delete_by_section(dmmap_firewall, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
dmuci_delete_by_section(s, NULL, NULL);
}
ss = s;
found++;
}
if (ss != NULL) {
get_dmmap_section_of_config_section("dmmap_firewall", "zone", section_name(ss), &dmmap_firewall);
if(dmmap_firewall)
dmuci_delete_by_section(dmmap_firewall, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
return 0;
break;
}
return 0;
}
@ -77,8 +107,7 @@ static int add_NAT_PortMapping(char *refparam, struct dmctx *ctx, void *data, ch
struct uci_section *s = NULL, *dmmap_firewall = NULL;
char s_name[32];
char *inst = get_last_instance_bbfdm("dmmap_firewall", "redirect", "port_mapping_instance");
snprintf(s_name, sizeof(s_name), "port_map_%d", inst ? (atoi(inst)+1) : 1);
snprintf(s_name, sizeof(s_name), "port_map_%s", *instance);
dmuci_add_section("firewall", "redirect", &s);
dmuci_rename_section_by_section(s, s_name);
@ -87,39 +116,27 @@ static int add_NAT_PortMapping(char *refparam, struct dmctx *ctx, void *data, ch
dmuci_add_section_bbfdm("dmmap_firewall", "redirect", &dmmap_firewall);
dmuci_set_value_by_section(dmmap_firewall, "section_name", s_name);
*instance = update_instance(inst, 2, dmmap_firewall, "port_mapping_instance");
dmuci_set_value_by_section(dmmap_firewall, "port_mapping_instance", *instance);
return 0;
}
static int delete_NAT_PortMapping(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
int found = 0;
struct uci_section *s = NULL, *ss = NULL, *dmmap_firewall = NULL;
struct uci_section *s = NULL, *stmp = NULL;
switch (del_action) {
case DEL_INST:
get_dmmap_section_of_config_section("dmmap_firewall", "redirect", section_name((struct uci_section *)data), &dmmap_firewall);
if (dmmap_firewall)
dmuci_delete_by_section(dmmap_firewall, NULL, NULL);
dmuci_delete_by_section((struct uci_section *)data, NULL, NULL);
dmuci_delete_by_section(((struct dmmap_dup *)data)->config_section, NULL, NULL);
dmuci_delete_by_section(((struct dmmap_dup *)data)->dmmap_section, NULL, NULL);
break;
case DEL_ALL:
uci_foreach_sections("firewall", "redirect", s) {
if (found != 0) {
get_dmmap_section_of_config_section("dmmap_firewall", "redirect", section_name(ss), &dmmap_firewall);
if (dmmap_firewall)
uci_foreach_sections_safe("firewall", "redirect", stmp, s) {
struct uci_section *dmmap_firewall = NULL;
get_dmmap_section_of_config_section("dmmap_firewall", "redirect", section_name(s), &dmmap_firewall);
dmuci_delete_by_section(dmmap_firewall, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
ss = s;
found++;
}
if (ss != NULL) {
get_dmmap_section_of_config_section("dmmap_firewall", "redirect", section_name(ss), &dmmap_firewall);
if (dmmap_firewall)
dmuci_delete_by_section(dmmap_firewall, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
dmuci_delete_by_section(s, NULL, NULL);
}
return 0;
}
@ -132,12 +149,7 @@ static int delete_NAT_PortMapping(char *refparam, struct dmctx *ctx, void *data,
/*#Device.NAT.InterfaceSettingNumberOfEntries!UCI:firewall/zone/*/
static int get_nat_interface_setting_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s = NULL;
int cnt = 0;
uci_foreach_sections("firewall", "zone", s) {
cnt++;
}
int cnt = get_number_of_entries(ctx, data, instance, browseInterfaceSettingInst);
dmasprintf(value, "%d", cnt);
return 0;
}
@ -145,12 +157,7 @@ static int get_nat_interface_setting_number_of_entries(char *refparam, struct dm
/*#Device.NAT.PortMappingNumberOfEntries!UCI:firewall/redirect/*/
static int get_nat_port_mapping_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s = NULL;
int cnt = 0;
uci_foreach_sections("firewall", "redirect", s) {
cnt++;
}
int cnt = get_number_of_entries(ctx, data, instance, browsePortMappingInst);
dmasprintf(value, "%d", cnt);
return 0;
}
@ -159,7 +166,7 @@ static int get_nat_port_mapping_number_of_entries(char *refparam, struct dmctx *
static int get_nat_interface_setting_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *val;
dmuci_get_value_by_section_string((struct uci_section *)data, "masq", &val);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "masq", &val);
*value = (*val == '1') ? "1" : "0";
return 0;
}
@ -174,7 +181,7 @@ static int set_nat_interface_setting_enable(char *refparam, struct dmctx *ctx, v
return 0;
case VALUESET:
string_to_bool(value, &b);
dmuci_set_value_by_section((struct uci_section *)data, "masq", b ? "1" : "0");
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "masq", b ? "1" : "0");
return 0;
}
return 0;
@ -184,7 +191,7 @@ static int set_nat_interface_setting_enable(char *refparam, struct dmctx *ctx, v
static int get_nat_interface_setting_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *val;
dmuci_get_value_by_section_string((struct uci_section *)data, "masq", &val);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "masq", &val);
*value = (*val == '1') ? "Enabled" : "Disabled";
return 0;
}
@ -192,10 +199,7 @@ static int get_nat_interface_setting_status(char *refparam, struct dmctx *ctx, v
/*#Device.NAT.InterfaceSetting.{i}.Alias!UCI:dmmap_firewall/zone,@i-1/interface_setting_alias*/
static int get_nat_interface_setting_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *dmmap_section = NULL;
get_dmmap_section_of_config_section("dmmap_firewall", "zone", section_name((struct uci_section *)data), &dmmap_section);
dmuci_get_value_by_section_string(dmmap_section, "interface_setting_alias", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->dmmap_section, "interface_setting_alias", value);
if ((*value)[0] == '\0')
dmasprintf(value, "cpe-%s", instance);
return 0;
@ -203,16 +207,13 @@ static int get_nat_interface_setting_alias(char *refparam, struct dmctx *ctx, vo
static int set_nat_interface_setting_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *dmmap_section = NULL;
switch (action) {
case VALUECHECK:
if (dm_validate_string(value, -1, 64, NULL, NULL))
return FAULT_9007;
return 0;
case VALUESET:
get_dmmap_section_of_config_section("dmmap_firewall", "zone", section_name((struct uci_section *)data), &dmmap_section);
dmuci_set_value_by_section(dmmap_section, "interface_setting_alias", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->dmmap_section, "interface_setting_alias", value);
return 0;
}
return 0;
@ -225,7 +226,7 @@ static int get_nat_interface_setting_interface(char *refparam, struct dmctx *ctx
unsigned pos = 0;
buf[0] = 0;
dmuci_get_value_by_section_list((struct uci_section *)data, "network", &v);
dmuci_get_value_by_section_list(((struct dmmap_dup *)data)->config_section, "network", &v);
if (v) {
struct uci_element *e = NULL;
char *ifaceobj = NULL;
@ -256,11 +257,11 @@ static int set_nat_interface_setting_interface(char *refparam, struct dmctx *ctx
return 0;
case VALUESET:
DM_STRNCPY(buf, value, sizeof(buf));
dmuci_set_value_by_section((struct uci_section *)data, "network", "");
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "network", "");
for(pch = strtok_r(buf, ",", &pchr); pch != NULL; pch = strtok_r(NULL, ",", &pchr)) {
adm_entry_get_linker_value(ctx, pch, &iface);
if (iface && *iface) {
dmuci_add_list_value_by_section((struct uci_section *)data, "network", iface);
dmuci_add_list_value_by_section(((struct dmmap_dup *)data)->config_section, "network", iface);
dmfree(iface);
}
}
@ -273,7 +274,7 @@ static int set_nat_interface_setting_interface(char *refparam, struct dmctx *ctx
static int get_nat_port_mapping_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *val;
dmuci_get_value_by_section_string((struct uci_section *)data, "enabled", &val);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "enabled", &val);
*value = (*val == '0') ? "0" : "1";
return 0;
}
@ -289,7 +290,7 @@ static int set_nat_port_mapping_enable(char *refparam, struct dmctx *ctx, void *
return 0;
case VALUESET:
string_to_bool(value, &b);
dmuci_set_value_by_section((struct uci_section *)data, "enabled", b ? "1" : "0");
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "enabled", b ? "1" : "0");
return 0;
}
return 0;
@ -299,7 +300,7 @@ static int set_nat_port_mapping_enable(char *refparam, struct dmctx *ctx, void *
static int get_nat_port_mapping_status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *val;
dmuci_get_value_by_section_string((struct uci_section *)data, "enabled", &val);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "enabled", &val);
*value = (*val == '1') ? "Enabled" : "Disabled";
return 0;
}
@ -307,10 +308,7 @@ static int get_nat_port_mapping_status(char *refparam, struct dmctx *ctx, void *
/*#Device.NAT.PortMapping.{i}.Alias!UCI:dmmap_firewall/redirect,@i-1/port_mapping_alias*/
static int get_nat_port_mapping_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *dmmap_section = NULL;
get_dmmap_section_of_config_section("dmmap_firewall", "redirect", section_name((struct uci_section *)data), &dmmap_section);
dmuci_get_value_by_section_string(dmmap_section, "port_mapping_alias", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->dmmap_section, "port_mapping_alias", value);
if ((*value)[0] == '\0')
dmasprintf(value, "cpe-%s", instance);
return 0;
@ -318,16 +316,13 @@ static int get_nat_port_mapping_alias(char *refparam, struct dmctx *ctx, void *d
static int set_nat_port_mapping_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *dmmap_section = NULL;
switch (action) {
case VALUECHECK:
if (dm_validate_string(value, -1, 64, NULL, NULL))
return FAULT_9007;
return 0;
case VALUESET:
get_dmmap_section_of_config_section("dmmap_firewall", "redirect", section_name((struct uci_section *)data), &dmmap_section);
dmuci_set_value_by_section(dmmap_section, "port_mapping_alias", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->dmmap_section, "port_mapping_alias", value);
return 0;
}
return 0;
@ -340,12 +335,12 @@ static int get_nat_port_mapping_interface(char *refparam, struct dmctx *ctx, voi
char *zone_name = NULL, *name = NULL, *src_dip = NULL, buf[256];
unsigned pos = 0;
dmuci_get_value_by_section_string((struct uci_section *)data, "src_dip", &src_dip);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "src_dip", &src_dip);
if (src_dip && strcmp(src_dip, "*") == 0)
return 0;
buf[0] = 0;
dmuci_get_value_by_section_string((struct uci_section *)data, "src", &zone_name);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "src", &zone_name);
uci_foreach_sections("firewall", "zone", s) {
dmuci_get_value_by_section_string(s, "name", &name);
if (zone_name && name && strcmp(zone_name, name) == 0) {
@ -391,7 +386,7 @@ static int set_nat_port_mapping_interface(char *refparam, struct dmctx *ctx, voi
dmuci_get_value_by_section_string(s, "network", &network);
if (is_strword_in_optionvalue(network, iface)) {
dmuci_get_value_by_section_string(s, "name", &zone);
dmuci_set_value_by_section((struct uci_section *)data, "src", zone);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "src", zone);
break;
}
}
@ -406,7 +401,7 @@ static int get_nat_port_mapping_all_interface(char *refparam, struct dmctx *ctx,
{
char *src_dip = NULL;
dmuci_get_value_by_section_string((struct uci_section *)data, "src_dip", &src_dip);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "src_dip", &src_dip);
*value = (src_dip && *src_dip == '*') ? "1" : "0";
return 0;
}
@ -423,11 +418,11 @@ static int set_nat_port_mapping_all_interface(char *refparam, struct dmctx *ctx,
break;
case VALUESET:
string_to_bool(value, &b);
dmuci_set_value_by_section((struct uci_section *)data, "src_dip", b ? "*" : "");
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "src_dip", b ? "*" : "");
if (b) {
dmuci_get_value_by_section_string((struct uci_section *)data, "src", &src);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "src", &src);
if (src == NULL || *src == '\0')
dmuci_set_value_by_section((struct uci_section *)data, "src", "wan");
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "src", "wan");
}
break;
}
@ -439,7 +434,7 @@ static int get_nat_port_mapping_lease_duration(char *refparam, struct dmctx *ctx
{
char *expiry_date = NULL;
dmuci_get_value_by_section_string((struct uci_section *)data, "expiry", &expiry_date);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "expiry", &expiry_date);
if (expiry_date && *expiry_date != '\0' && atoi(expiry_date) > 0) {
dmasprintf(value, "%ld", atoi(expiry_date) - time(NULL));
} else {
@ -462,7 +457,7 @@ static int set_nat_port_mapping_lease_duration(char *refparam, struct dmctx *ctx
break;
snprintf(expiry_date, sizeof(expiry_date), "%ld", atoi(value) + time(NULL));
dmuci_set_value_by_section((struct uci_section *)data, "expiry", expiry_date);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "expiry", expiry_date);
break;
}
return 0;
@ -471,7 +466,7 @@ static int set_nat_port_mapping_lease_duration(char *refparam, struct dmctx *ctx
/*#Device.NAT.PortMapping.{i}.RemoteHost!UCI:firewall/redirect,@i-1/src_dip*/
static int get_nat_port_mapping_remote_host(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string((struct uci_section *)data, "src_ip", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "src_ip", value);
return 0;
}
@ -483,7 +478,7 @@ static int set_nat_port_mapping_remote_host(char *refparam, struct dmctx *ctx, v
return FAULT_9007;
return 0;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "src_ip", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "src_ip", value);
return 0;
}
return 0;
@ -493,7 +488,7 @@ static int set_nat_port_mapping_remote_host(char *refparam, struct dmctx *ctx, v
static int get_nat_port_mapping_external_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *src_dport = NULL;
dmuci_get_value_by_section_string((struct uci_section *)data, "src_dport", &src_dport);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "src_dport", &src_dport);
if (src_dport && *src_dport == '\0') {
*value = "0";
return 0;
@ -516,13 +511,13 @@ static int set_nat_port_mapping_external_port(char *refparam, struct dmctx *ctx,
return FAULT_9007;
return 0;
case VALUESET:
dmuci_get_value_by_section_string((struct uci_section *)data, "src_dport", &src_dport);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "src_dport", &src_dport);
src_dport = src_dport ? strchr(src_dport, ':') : NULL;
if (src_dport == NULL)
snprintf(buffer, sizeof(buffer), "%s", value);
else
snprintf(buffer, sizeof(buffer), "%s%s", value, src_dport);
dmuci_set_value_by_section((struct uci_section *)data, "src_dport", buffer);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "src_dport", buffer);
return 0;
}
return 0;
@ -532,7 +527,7 @@ static int set_nat_port_mapping_external_port(char *refparam, struct dmctx *ctx,
static int get_nat_port_mapping_external_port_end_range(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *src_dport = NULL;
dmuci_get_value_by_section_string((struct uci_section *)data, "src_dport", &src_dport);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "src_dport", &src_dport);
char *tmp = src_dport ? strchr(src_dport, ':') : NULL;
*value = tmp ? tmp + 1 : "0";
return 0;
@ -548,13 +543,13 @@ static int set_nat_port_mapping_external_port_end_range(char *refparam, struct d
return FAULT_9007;
return 0;
case VALUESET:
dmuci_get_value_by_section_string((struct uci_section *)data, "src_dport", &src_dport);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "src_dport", &src_dport);
tmp = src_dport ? strchr(src_dport, ':') : NULL;
if (tmp)
*tmp = '\0';
snprintf(buffer, sizeof(buffer), "%s:%s", src_dport, value);
dmuci_set_value_by_section((struct uci_section *)data, "src_dport", buffer);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "src_dport", buffer);
return 0;
}
return 0;
@ -563,7 +558,7 @@ static int set_nat_port_mapping_external_port_end_range(char *refparam, struct d
/*#Device.NAT.PortMapping.{i}.InternalPort!UCI:firewall/redirect,@i-1/dest_port*/
static int get_nat_port_mapping_internal_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "dest_port", "0");
*value = dmuci_get_value_by_section_fallback_def(((struct dmmap_dup *)data)->config_section, "dest_port", "0");
return 0;
}
@ -575,7 +570,7 @@ static int set_nat_port_mapping_internal_port(char *refparam, struct dmctx *ctx,
return FAULT_9007;
return 0;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "dest_port", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "dest_port", value);
return 0;
}
return 0;
@ -585,7 +580,7 @@ static int set_nat_port_mapping_internal_port(char *refparam, struct dmctx *ctx,
static int get_nat_port_mapping_protocol(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *proto = NULL;
dmuci_get_value_by_section_string((struct uci_section *)data, "proto", &proto);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "proto", &proto);
*value = (proto && strcmp(proto, "udp") == 0) ? "UDP" : "TCP";
return 0;
}
@ -598,7 +593,7 @@ static int set_nat_port_mapping_protocol(char *refparam, struct dmctx *ctx, void
return FAULT_9007;
return 0;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "proto", (strcmp("UDP", value) == 0) ? "udp" : "tcp");
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "proto", (strcmp("UDP", value) == 0) ? "udp" : "tcp");
return 0;
}
return 0;
@ -607,7 +602,7 @@ static int set_nat_port_mapping_protocol(char *refparam, struct dmctx *ctx, void
/*#Device.NAT.PortMapping.{i}.InternalClient!UCI:firewall/redirect,@i-1/dest_ip*/
static int get_nat_port_mapping_internal_client(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string((struct uci_section *)data, "dest_ip", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "dest_ip", value);
return 0;
}
@ -619,7 +614,7 @@ static int set_nat_port_mapping_internal_client(char *refparam, struct dmctx *ct
return FAULT_9007;
return 0;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "dest_ip", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "dest_ip", value);
return 0;
}
return 0;
@ -628,7 +623,7 @@ static int set_nat_port_mapping_internal_client(char *refparam, struct dmctx *ct
/*#Device.NAT.PortMapping.{i}.Description!UCI:firewall/redirect,@i-1/name*/
static int get_nat_port_mapping_description(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string((struct uci_section *)data, "name", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "name", value);
return 0;
}
@ -640,58 +635,15 @@ static int set_nat_port_mapping_description(char *refparam, struct dmctx *ctx, v
return FAULT_9007;
return 0;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "name", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "name", value);
return 0;
}
return 0;
}
/*************************************************************
* ENTRY METHOD
**************************************************************/
/*#Device.NAT.InterfaceSetting.{i}.!UCI:firewall/zone/dmmap_firewall*/
static int browseInterfaceSettingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *max_inst = NULL;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("firewall", "zone", "dmmap_firewall", &dup_list);
list_for_each_entry(p, &dup_list, list) {
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
p->dmmap_section, "interface_setting_instance", "interface_setting_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, inst) == DM_STOP)
break;
}
free_dmmap_config_dup_list(&dup_list);
return 0;
}
/*#Device.NAT.PortMapping.{i}.!UCI:firewall/redirect/dmmap_firewall*/
static int browsePortMappingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *max_inst = NULL, *target;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("firewall", "redirect", "dmmap_firewall", &dup_list);
list_for_each_entry(p, &dup_list, list) {
dmuci_get_value_by_section_string(p->config_section, "target", &target);
if (*target != '\0' && strcmp(target, "DNAT") != 0)
continue;
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
p->dmmap_section, "port_mapping_instance", "port_mapping_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, inst) == DM_STOP)
break;
}
free_dmmap_config_dup_list(&dup_list);
return 0;
}
/**********************************************************************************************************************************
* OBJ & PARAM DEFINITION
***********************************************************************************************************************************/
/* *** Device.NAT. *** */
DMOBJ tNATObj[] = {
/* OBJ, permission, addobj, delobj, checkdep, browseinstobj, nextdynamicobj, dynamicleaf, nextobj, leaf, linker, bbfdm_type, uniqueKeys*/

View file

@ -13,45 +13,81 @@
#include "ppp.h"
/*************************************************************
* GET SET ALIAS
* ENTRY METHOD
**************************************************************/
/*#Device.PPP.Interface.{i}.Alias!UCI:dmmap_network/interface,@i-1/ppp_int_alias*/
static int get_ppp_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
/*#Device.PPP.Interface.{i}.!UCI:network/interface/dmmap_network*/
static int browseInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct uci_section *dmmap_section = NULL;
char *inst = NULL, *proto;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
get_dmmap_section_of_config_section("dmmap_network", "interface", section_name((struct uci_section *)data), &dmmap_section);
dmuci_get_value_by_section_string(dmmap_section, "ppp_int_alias", value);
if ((*value)[0] == '\0')
dmasprintf(value, "cpe-%s", instance);
synchronize_specific_config_sections_with_dmmap("network", "interface", "dmmap_network", &dup_list);
list_for_each_entry(p, &dup_list, list) {
dmuci_get_value_by_section_string(p->config_section, "proto", &proto);
if (!strstr(proto, "ppp"))
continue;
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "ppp_int_instance", "ppp_int_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p, inst) == DM_STOP)
break;
}
free_dmmap_config_dup_list(&dup_list);
return 0;
}
static int set_ppp_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
/*************************************************************
* ADD DEL OBJ
**************************************************************/
static int add_ppp_interface(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
struct uci_section *dmmap_ppp = NULL;
char name[16] = {0};
snprintf(name, sizeof(name), "ppp_%s", *instance);
dmuci_set_value("network", name, "", "interface");
dmuci_set_value("network", name, "proto", "ppp");
dmuci_set_value("network", name, "disabled", "1");
dmuci_add_section_bbfdm("dmmap_network", "interface", &dmmap_ppp);
dmuci_set_value_by_section(dmmap_ppp, "section_name", name);
dmuci_set_value_by_section(dmmap_ppp, "ppp_int_instance", *instance);
return 0;
}
static int delete_ppp_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
struct uci_section *s = NULL, *stmp = NULL;
switch (del_action) {
case DEL_INST:
dmuci_delete_by_section(((struct dmmap_dup *)data)->config_section, NULL, NULL);
dmuci_delete_by_section(((struct dmmap_dup *)data)->dmmap_section, NULL, NULL);
break;
case DEL_ALL:
uci_foreach_option_cont_safe("network", "interface", "proto", "ppp", stmp, s) {
struct uci_section *dmmap_section = NULL;
switch (action) {
case VALUECHECK:
if (dm_validate_string(value, -1, 64, NULL, NULL))
return FAULT_9007;
return 0;
case VALUESET:
get_dmmap_section_of_config_section("dmmap_network", "interface", section_name((struct uci_section *)data), &dmmap_section);
dmuci_set_value_by_section(dmmap_section, "ppp_int_alias", value);
return 0;
get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(s), &dmmap_section);
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(s, NULL, NULL);
}
break;
}
return 0;
}
/**************************************************************************
* GET & SET PARAMETERS
***************************************************************************/
/*************************************************************
* GET & SET PARAM
**************************************************************/
/*#Device.PPP.Interface.{i}.Enable!UBUS:network.interface/status/interface,@Name/up*/
static int get_ppp_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct uci_section *)data)), String}}, 1, &res);
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct dmmap_dup *)data)->config_section), String}}, 1, &res);
DM_ASSERT(res, *value = "false");
*value = dmjson_get_value(res, 1, "up");
return 0;
@ -69,7 +105,7 @@ static int set_ppp_enable(char *refparam, struct dmctx *ctx, void *data, char *i
break;
case VALUESET:
string_to_bool(value, &b);
dmastrcat(&ubus_object, "network.interface.", section_name(((struct uci_section *)data)));
dmastrcat(&ubus_object, "network.interface.", section_name(((struct dmmap_dup *)data)->config_section));
dmubus_call_set(ubus_object, b ? "up" : "down", UBUS_ARGS{}, 0);
dmfree(ubus_object);
break;
@ -83,18 +119,41 @@ static int get_PPPInterface_Status(char *refparam, struct dmctx *ctx, void *data
json_object *res = NULL;
char *status;
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct uci_section *)data)), String}}, 1, &res);
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct dmmap_dup *)data)->config_section), String}}, 1, &res);
DM_ASSERT(res, *value = "Down");
status = dmjson_get_value(res, 1, "up");
*value = (strcmp(status, "true") == 0) ? "Up" : "Down";
return 0;
}
/*#Device.PPP.Interface.{i}.Alias!UCI:dmmap_network/interface,@i-1/ppp_int_alias*/
static int get_ppp_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->dmmap_section, "ppp_int_alias", value);
if ((*value)[0] == '\0')
dmasprintf(value, "cpe-%s", instance);
return 0;
}
static int set_ppp_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;
return 0;
case VALUESET:
dmuci_set_value_by_section(((struct dmmap_dup *)data)->dmmap_section, "ppp_int_alias", value);
return 0;
}
return 0;
}
/*#Device.PPP.Interface.{i}.LastChange!UBUS:network.interface/status/interface,@Name/uptime*/
static int get_PPPInterface_LastChange(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res;
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name((struct uci_section *)data), String}}, 1, &res);
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct dmmap_dup *)data)->config_section), String}}, 1, &res);
DM_ASSERT(res, *value = "0");
*value = dmjson_get_value(res, 1, "uptime");
return 0;
@ -119,7 +178,7 @@ static int set_PPPInterface_Reset(char *refparam, struct dmctx *ctx, void *data,
string_to_bool(value, &b);
if (b) {
char intf_obj[64] = {0};
snprintf(intf_obj, sizeof(intf_obj), "network.interface.%s", section_name(((struct uci_section *)data)));
snprintf(intf_obj, sizeof(intf_obj), "network.interface.%s", section_name(((struct dmmap_dup *)data)->config_section));
dmubus_call_set(intf_obj, "down", UBUS_ARGS{}, 0);
dmubus_call_set(intf_obj, "up", UBUS_ARGS{}, 0);
}
@ -130,7 +189,7 @@ static int set_PPPInterface_Reset(char *refparam, struct dmctx *ctx, void *data,
static int get_ppp_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmstrdup(section_name(((struct uci_section *)data)));
*value = dmstrdup(section_name(((struct dmmap_dup *)data)->config_section));
return 0;
}
@ -141,7 +200,7 @@ static int get_ppp_status(char *refparam, struct dmctx *ctx, void *data, char *i
json_object *res = NULL, *jobj = NULL;
bool bstatus = false, bpend = false;
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct uci_section *)data)), String}}, 1, &res);
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct dmmap_dup *)data)->config_section), String}}, 1, &res);
DM_ASSERT(res, *value = "Unconfigured");
jobj = dmjson_get_obj(res, 1, "up");
if (jobj) {
@ -167,7 +226,7 @@ static int get_PPPInterface_LastConnectionError(char *refparam, struct dmctx *ct
json_object *res = NULL;
char *status;
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name((struct uci_section *)data), String}}, 1, &res);
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct dmmap_dup *)data)->config_section), String}}, 1, &res);
DM_ASSERT(res, *value = "ERROR_NONE");
status = dmjson_get_value(res, 2, "data", "lastconnectionerror");
@ -207,7 +266,7 @@ static int get_PPPInterface_LastConnectionError(char *refparam, struct dmctx *ct
/*#Device.PPP.Interface.{i}.Username!UCI:network/interface,@i-1/username*/
static int get_ppp_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string(((struct uci_section *)data), "username", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "username", value);
return 0;
}
@ -219,7 +278,7 @@ static int set_ppp_username(char *refparam, struct dmctx *ctx, void *data, char
return FAULT_9007;
return 0;
case VALUESET:
dmuci_set_value_by_section(((struct uci_section *)data), "username", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "username", value);
return 0;
}
return 0;
@ -234,7 +293,7 @@ static int set_ppp_password(char *refparam, struct dmctx *ctx, void *data, char
return FAULT_9007;
return 0;
case VALUESET:
dmuci_set_value_by_section(((struct uci_section *)data), "password", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "password", value);
return 0;
}
return 0;
@ -243,7 +302,7 @@ static int set_ppp_password(char *refparam, struct dmctx *ctx, void *data, char
static int get_PPPInterface_MaxMRUSize(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *pppd_opt = NULL;
dmuci_get_value_by_section_string(((struct uci_section *)data), "pppd_options", &pppd_opt);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "pppd_options", &pppd_opt);
if (pppd_opt && *pppd_opt == '\0') {
*value = "1500";
return 0;
@ -255,7 +314,7 @@ static int get_PPPInterface_MaxMRUSize(char *refparam, struct dmctx *ctx, void *
if (0 == strcmp(token, "mru")) {
char mru_val[1024] = {0}, mru_str[1024] = {0};
DM_STRNCPY(mru_val, end, sizeof(mru_val));
sscanf(mru_val, "%s", mru_str);
sscanf(mru_val, "%1023s", mru_str);
if ('\0' != mru_str[0]) {
*value = dmstrdup(mru_str);
}
@ -273,36 +332,33 @@ static int get_PPPInterface_MaxMRUSize(char *refparam, struct dmctx *ctx, void *
static int configure_pppd_mru(char *pppd_opt, char *mru_str, void *data, char *value)
{
int found = 0;
char *token = NULL, *end = NULL;
char mru_val[1024] = {0}, mru_opt[1024] = {0};
char list_options[1024] = {0}, mru_opt[1024] = {0};
unsigned pos = 0;
bool found = false;
list_options[0] = 0;
token = strtok_r(pppd_opt, " ", &end);
while (NULL != token) {
if (0 == strcmp(token, "mru")) {
found = 1;
strcat(mru_val, token);
strcat(mru_val, " ");
strcat(mru_val, value);
found = true;
pos += snprintf(&list_options[pos], sizeof(list_options) - pos, "%s %s", token, value);
DM_STRNCPY(mru_opt, end, sizeof(mru_opt));
char *p, *q;
p = strtok_r(mru_opt, " ", &q);
if (p != NULL && q != NULL) {
strcat(mru_val, " ");
strcat(mru_val, q);
pos += snprintf(&list_options[pos], sizeof(list_options) - pos, " %s", q);
}
break;
}
strcat(mru_val, token);
strcat(mru_val, " ");
pos += snprintf(&list_options[pos], sizeof(list_options) - pos, "%s ", token);
token = strtok_r(NULL, " ", &end);
}
if (found == 0) {
strcat(mru_val, mru_str);
}
if (found == false)
snprintf(&list_options[pos], sizeof(list_options) - pos, "%s", mru_str);
dmuci_set_value_by_section(((struct uci_section *)data), "pppd_options", mru_val);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "pppd_options", list_options);
return 0;
}
@ -318,10 +374,10 @@ static int set_PPPInterface_MaxMRUSize(char *refparam, struct dmctx *ctx, void *
break;
case VALUESET:
snprintf(mru_str, sizeof(mru_str), "%s %s", "mru", value);
dmuci_get_value_by_section_string(((struct uci_section *)data), "pppd_options", &pppd_opt);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "pppd_options", &pppd_opt);
if (pppd_opt && *pppd_opt == '\0') {
dmuci_set_value_by_section(((struct uci_section *)data), "pppd_options", mru_str);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "pppd_options", mru_str);
} else {
// If mru is specified then we need to replace and keep the rest of the options intact.
configure_pppd_mru(pppd_opt, mru_str, data, value);
@ -336,7 +392,7 @@ static int get_PPPInterface_CurrentMRUSize(char *refparam, struct dmctx *ctx, vo
json_object *res = NULL;
char *status;
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct uci_section *)data)), String}}, 1, &res);
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct dmmap_dup *)data)->config_section), String}}, 1, &res);
DM_ASSERT(res, *value = "");
status = dmjson_get_value(res, 1, "up");
if (0 != strcmp(status, "true")) {
@ -345,7 +401,7 @@ static int get_PPPInterface_CurrentMRUSize(char *refparam, struct dmctx *ctx, vo
}
char intf[1024] = {0};
snprintf(intf, sizeof(intf), "%s-%s", "pppoe", section_name((struct uci_section *)data));
snprintf(intf, sizeof(intf), "%s-%s", "pppoe", section_name(((struct dmmap_dup *)data)->config_section));
get_net_device_sysfs(intf, "mtu", value);
return 0;
@ -356,7 +412,7 @@ static int get_PPPInterface_LCPEcho(char *refparam, struct dmctx *ctx, void *dat
char *lcp_echo = NULL, *token = NULL;
char echo_val[50] = {0};
dmuci_get_value_by_section_string(((struct uci_section *)data), "keepalive", &lcp_echo);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "keepalive", &lcp_echo);
if (lcp_echo && *lcp_echo == '\0') {
*value = "1";
return 0;
@ -375,7 +431,7 @@ static int get_PPPInterface_LCPEchoRetry(char *refparam, struct dmctx *ctx, void
{
char *lcp_retry = NULL, *token = NULL;
char lcp_interval[50] = {0};
dmuci_get_value_by_section_string(((struct uci_section *)data), "keepalive", &lcp_retry);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "keepalive", &lcp_retry);
if (lcp_retry && *lcp_retry == '\0') {
*value = "5";
} else {
@ -392,7 +448,8 @@ static int get_PPPInterface_LCPEchoRetry(char *refparam, struct dmctx *ctx, void
static int configure_supported_ncp_options(struct uci_section *ss, char *value, char *option)
{
char *proto, *pppd_opt = NULL;
char ipcp_opt[1024] = {0};
char list_options[1024] = {0};
unsigned pos = 0;
dmuci_get_value_by_section_string(ss, "proto", &proto);
if (0 == strcmp(proto, "pppoe")) {
@ -401,37 +458,39 @@ static int configure_supported_ncp_options(struct uci_section *ss, char *value,
if (pppd_opt && *pppd_opt != '\0') {
char *token = NULL, *end = NULL;
int found = 0;
bool found = false;
list_options[0] = 0;
token = strtok_r(pppd_opt, " ", &end);
while (NULL != token) {
char ncp_opt[1024] = {0};
DM_STRNCPY(ncp_opt, token, sizeof(ncp_opt));
if (0 == strncmp(ncp_opt, option, sizeof(ncp_opt))) {
found = 1;
found = true;
if (0 == strcmp(value, "1") && NULL != end) {
if ('\0' != ipcp_opt[0]) {
strcat(ipcp_opt, " ");
}
strcat(ipcp_opt, end);
if (pos != 0)
pos += snprintf(&list_options[pos], sizeof(list_options) - pos, "%c", ' ');
pos += snprintf(&list_options[pos], sizeof(list_options) - pos, "%s", end);
break;
}
} else {
if ('\0' != ipcp_opt[0]) {
strcat(ipcp_opt, " ");
}
strcat(ipcp_opt, token);
if (pos != 0)
pos += snprintf(&list_options[pos], sizeof(list_options) - pos, "%c", ' ');
pos += snprintf(&list_options[pos], sizeof(list_options) - pos, "%s", token);
}
token = strtok_r(NULL, " ", &end);
}
if ((0 == strcmp(value, "0")) && found == 0) {
if ('\0' != ipcp_opt[0]) {
strcat(ipcp_opt, " ");
}
strcat(ipcp_opt, option);
if ((0 == strcmp(value, "0")) && found == false) {
if (pos != 0)
pos += snprintf(&list_options[pos], sizeof(list_options) - pos, "%c", ' ');
pos += snprintf(&list_options[pos], sizeof(list_options) - pos, "%s", option);
}
dmuci_set_value_by_section(ss, "pppd_options", ipcp_opt);
dmuci_set_value_by_section(ss, "pppd_options", list_options);
} else {
if (0 == strcmp(value, "0")) {
dmuci_set_value_by_section(ss, "pppd_options", option);
@ -482,7 +541,7 @@ static int handle_supported_ncp_options(struct uci_section *s, char *instance, i
static int get_PPPInterface_IPCPEnable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
int ret = handle_supported_ncp_options((struct uci_section *)data, instance, IPCP);
int ret = handle_supported_ncp_options(((struct dmmap_dup *)data)->config_section, instance, IPCP);
*value = ret ? "0" : "1";
return 0;
}
@ -495,7 +554,7 @@ static int set_PPPInterface_IPCPEnable(char *refparam, struct dmctx *ctx, void *
return FAULT_9007;
break;
case VALUESET:
configure_supported_ncp_options((struct uci_section *)data, value, "noip");
configure_supported_ncp_options(((struct dmmap_dup *)data)->config_section, value, "noip");
break;
}
return 0;
@ -503,7 +562,7 @@ static int set_PPPInterface_IPCPEnable(char *refparam, struct dmctx *ctx, void *
static int get_PPPInterface_IPv6CPEnable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
int ret = handle_supported_ncp_options((struct uci_section *)data, instance, IPCPv6);
int ret = handle_supported_ncp_options(((struct dmmap_dup *)data)->config_section, instance, IPCPv6);
*value = ret ? "0" : "1";
return 0;
}
@ -516,7 +575,7 @@ static int set_PPPInterface_IPv6CPEnable(char *refparam, struct dmctx *ctx, void
return FAULT_9007;
break;
case VALUESET:
configure_supported_ncp_options((struct uci_section *)data, value, "noipv6");
configure_supported_ncp_options(((struct dmmap_dup *)data)->config_section, value, "noipv6");
break;
}
return 0;
@ -536,7 +595,7 @@ static int get_PPPInterfacePPPoE_SessionID(char *refparam, struct dmctx *ctx, vo
while (fgets(path, sizeof(path), fp) != NULL) {
i++;
if (2 == i) {
sscanf(path, "%s", session_id);
sscanf(path, "%19s", session_id);
int number = (int)strtol(session_id, NULL, 16);
memset(session_id, '\0', sizeof(session_id));
snprintf(session_id, sizeof(session_id), "%d", number);
@ -557,7 +616,7 @@ static int get_PPPInterfaceIPCP_LocalIPAddress(char *refparam, struct dmctx *ctx
{
json_object *res = NULL;
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name((struct uci_section *)data), String}}, 1, &res);
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct dmmap_dup *)data)->config_section), String}}, 1, &res);
DM_ASSERT(res, *value = "");
json_object *ipv4_obj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv4-address");
*value = dmjson_get_value(ipv4_obj, 1, "address");
@ -568,7 +627,7 @@ static int get_PPPInterfaceIPCP_RemoteIPAddress(char *refparam, struct dmctx *ct
{
json_object *res = NULL;
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name((struct uci_section *)data), String}}, 1, &res);
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct dmmap_dup *)data)->config_section), String}}, 1, &res);
DM_ASSERT(res, *value = "");
json_object *ipv4_obj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv4-address");
*value = dmjson_get_value(ipv4_obj, 1, "ptpaddress");
@ -583,7 +642,7 @@ static int get_PPPInterfaceIPCP_DNSServers(char *refparam, struct dmctx *ctx, vo
{
json_object *res = NULL;
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name((struct uci_section *)data), String}}, 1, &res);
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct dmmap_dup *)data)->config_section), String}}, 1, &res);
DM_ASSERT(res, *value = "");
*value = dmjson_get_value_array_all(res, ",", 1, "dns-server");
return 0;
@ -593,7 +652,7 @@ static int get_PPPInterfaceIPv6CP_LocalInterfaceIdentifier(char *refparam, struc
{
json_object *res = NULL;
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name((struct uci_section *)data), String}}, 1, &res);
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct dmmap_dup *)data)->config_section), String}}, 1, &res);
DM_ASSERT(res, *value = "");
json_object *ipv4_obj = dmjson_select_obj_in_array_idx(res, 0, 1, "ipv6-address");
*value = dmjson_get_value(ipv4_obj, 1, "address");
@ -604,7 +663,7 @@ static int get_PPPInterfaceIPv6CP_RemoteInterfaceIdentifier(char *refparam, stru
{
json_object *res = NULL;
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name((struct uci_section *)data), String}}, 1, &res);
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(((struct dmmap_dup *)data)->config_section), String}}, 1, &res);
DM_ASSERT(res, *value = "");
*value = dmjson_get_value(res, 2, "data", "llremote");
return 0;
@ -626,55 +685,55 @@ static int ppp_read_sysfs(struct uci_section *sect, const char *name, char **val
/*#Device.PPP.Interface.{i}.Stats.BytesReceived!SYSFS:/sys/class/net/@Name/statistics/rx_bytes*/
static int get_ppp_eth_bytes_received(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return ppp_read_sysfs(data, "statistics/rx_bytes", value);
return ppp_read_sysfs(((struct dmmap_dup *)data)->config_section, "statistics/rx_bytes", value);
}
/*#Device.PPP.Interface.{i}.Stats.BytesSent!SYSFS:/sys/class/net/@Name/statistics/tx_bytes*/
static int get_ppp_eth_bytes_sent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return ppp_read_sysfs(data, "statistics/tx_bytes", value);
return ppp_read_sysfs(((struct dmmap_dup *)data)->config_section, "statistics/tx_bytes", value);
}
/*#Device.PPP.Interface.{i}.Stats.PacketsReceived!SYSFS:/sys/class/net/@Name/statistics/rx_packets*/
static int get_ppp_eth_pack_received(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return ppp_read_sysfs(data, "statistics/rx_packets", value);
return ppp_read_sysfs(((struct dmmap_dup *)data)->config_section, "statistics/rx_packets", value);
}
/*#Device.PPP.Interface.{i}.Stats.PacketsSent!SYSFS:/sys/class/net/@Name/statistics/tx_packets*/
static int get_ppp_eth_pack_sent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return ppp_read_sysfs(data, "statistics/tx_packets", value);
return ppp_read_sysfs(((struct dmmap_dup *)data)->config_section, "statistics/tx_packets", value);
}
/*#Device.PPP.Interface.{i}.Stats.ErrorsSent!SYSFS:/sys/class/net/@Name/statistics/tx_errors*/
static int get_PPPInterfaceStats_ErrorsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return ppp_read_sysfs(data, "statistics/tx_errors", value);
return ppp_read_sysfs(((struct dmmap_dup *)data)->config_section, "statistics/tx_errors", value);
}
/*#Device.PPP.Interface.{i}.Stats.ErrorsReceived!SYSFS:/sys/class/net/@Name/statistics/rx_errors*/
static int get_PPPInterfaceStats_ErrorsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return ppp_read_sysfs(data, "statistics/rx_errors", value);
return ppp_read_sysfs(((struct dmmap_dup *)data)->config_section, "statistics/rx_errors", value);
}
/*#Device.PPP.Interface.{i}.Stats.DiscardPacketsSent!SYSFS:/sys/class/net/@Name/statistics/tx_dropped*/
static int get_PPPInterfaceStats_DiscardPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return ppp_read_sysfs(data, "statistics/tx_dropped", value);
return ppp_read_sysfs(((struct dmmap_dup *)data)->config_section, "statistics/tx_dropped", value);
}
/*#Device.PPP.Interface.{i}.Stats.DiscardPacketsReceived!SYSFS:/sys/class/net/@Name/statistics/rx_dropped*/
static int get_PPPInterfaceStats_DiscardPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return ppp_read_sysfs(data, "statistics/rx_dropped", value);
return ppp_read_sysfs(((struct dmmap_dup *)data)->config_section, "statistics/rx_dropped", value);
}
/*#Device.PPP.Interface.{i}.Stats.MulticastPacketsReceived!SYSFS:/sys/class/net/@Name/statistics/multicast*/
static int get_PPPInterfaceStats_MulticastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return ppp_read_sysfs(data, "statistics/multicast", value);
return ppp_read_sysfs(((struct dmmap_dup *)data)->config_section, "statistics/multicast", value);
}
static int get_ppp_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
@ -684,10 +743,10 @@ static int get_ppp_lower_layer(char *refparam, struct dmctx *ctx, void *data, ch
struct uci_section *ss = NULL;
char *dev = "0";
dmuci_get_value_by_section_string(((struct uci_section *)data), "device", &linker);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "device", &linker);
// Get wan interface
dev = get_device(section_name(((struct uci_section *)data)));
dev = get_device(section_name(((struct dmmap_dup *)data)->config_section));
// Check if interface name is same as dev value.
char *token, *end = linker;
@ -738,7 +797,7 @@ static int set_ppp_lower_layer(char *refparam, struct dmctx *ctx, void *data, ch
case VALUESET:
adm_entry_get_linker_value(ctx, value, &ppp_linker);
if (ppp_linker && *ppp_linker) {
dmuci_set_value_by_section(((struct uci_section *)data), "device", ppp_linker);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "device", ppp_linker);
dmfree(ppp_linker);
}
return 0;
@ -748,17 +807,8 @@ static int set_ppp_lower_layer(char *refparam, struct dmctx *ctx, void *data, ch
static int get_PPP_InterfaceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s = NULL;
char *proto;
int nbre = 0;
uci_foreach_sections("network", "interface", s) {
dmuci_get_value_by_section_string(s, "proto", &proto);
if (!strstr(proto, "ppp"))
continue;
nbre++;
}
dmasprintf(value, "%d", nbre);
int cnt = get_number_of_entries(ctx, data, instance, browseInterfaceInst);
dmasprintf(value, "%d", cnt);
return 0;
}
@ -772,9 +822,9 @@ static int get_PPP_SupportedNCPs(char *refparam, struct dmctx *ctx, void *data,
static int get_PPPInterfacePPPoE_ACName(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *proto;
dmuci_get_value_by_section_string(((struct uci_section *)data), "proto", &proto);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "proto", &proto);
if (strcmp(proto, "pppoe") == 0) {
dmuci_get_value_by_section_string(((struct uci_section *)data), "ac", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "ac", value);
return 0;
}
return 0;
@ -789,12 +839,12 @@ static int set_PPPInterfacePPPoE_ACName(char *refparam, struct dmctx *ctx, void
if (dm_validate_string(value, -1, 256, NULL, NULL))
return FAULT_9007;
dmuci_get_value_by_section_string(((struct uci_section *)data), "proto", &proto_intf);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "proto", &proto_intf);
if (strcmp(proto_intf, "pppoe") != 0)
return FAULT_9001;
break;
case VALUESET:
dmuci_set_value_by_section(((struct uci_section *)data), "ac", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "ac", value);
break;
}
return 0;
@ -804,9 +854,9 @@ static int set_PPPInterfacePPPoE_ACName(char *refparam, struct dmctx *ctx, void
static int get_PPPInterfacePPPoE_ServiceName(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *proto;
dmuci_get_value_by_section_string(((struct uci_section *)data), "proto", &proto);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "proto", &proto);
if (strcmp(proto, "pppoe") == 0) {
dmuci_get_value_by_section_string(((struct uci_section *)data), "service", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "service", value);
return 0;
}
return 0;
@ -821,12 +871,12 @@ static int set_PPPInterfacePPPoE_ServiceName(char *refparam, struct dmctx *ctx,
if (dm_validate_string(value, -1, 256, NULL, NULL))
return FAULT_9007;
dmuci_get_value_by_section_string(((struct uci_section *)data), "proto", &proto);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "proto", &proto);
if (strcmp(proto, "pppoe") != 0)
return FAULT_9001;
break;
case VALUESET:
dmuci_set_value_by_section(((struct uci_section *)data), "service", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "service", value);
break;
}
return 0;
@ -837,86 +887,7 @@ static int set_PPPInterfacePPPoE_ServiceName(char *refparam, struct dmctx *ctx,
***************************************************************************/
static int get_linker_ppp_interface(char *refparam, struct dmctx *dmctx, void *data, char *instance, char **linker)
{
*linker = data ? dmstrdup(section_name(((struct uci_section *)data))) : "";
return 0;
}
/*************************************************************
* ADD DEL OBJ
**************************************************************/
static int add_ppp_interface(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
struct uci_section *dmmap_ppp = NULL;
char name[16] = {0};
char *inst = get_last_instance_lev2_bbfdm("network", "interface", "dmmap_network", "ppp_int_instance", "proto", "ppp");
snprintf(name, sizeof(name), "ppp_%d", inst ? (atoi(inst)+1) : 1);
dmuci_set_value("network", name, "", "interface");
dmuci_set_value("network", name, "proto", "ppp");
dmuci_set_value("network", name, "disabled", "1");
dmuci_add_section_bbfdm("dmmap_network", "interface", &dmmap_ppp);
dmuci_set_value_by_section(dmmap_ppp, "section_name", name);
*instance = update_instance(inst, 2, dmmap_ppp, "ppp_int_instance");
return 0;
}
static int delete_ppp_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
int found = 0;
struct uci_section *ppp_s = NULL, *ss = NULL, *dmmap_section = NULL;
switch (del_action) {
case DEL_INST:
get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(((struct uci_section *)data)), &dmmap_section);
if (dmmap_section) dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(((struct uci_section *)data), NULL, NULL);
break;
case DEL_ALL:
uci_foreach_option_cont("network", "interface", "proto", "ppp", ppp_s) {
if (found != 0) {
get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(ss), &dmmap_section);
if (dmmap_section) dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
ss = ppp_s;
found++;
}
if (ss != NULL) {
get_dmmap_section_of_config_section("dmmap_network", "interface", section_name(ss), &dmmap_section);
if (dmmap_section) dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
break;
}
return 0;
}
/*************************************************************
* ENTRY METHOD
**************************************************************/
/*#Device.PPP.Interface.{i}.!UCI:network/interface/dmmap_network*/
static int browseInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *max_inst = NULL, *proto;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("network", "interface", "dmmap_network", &dup_list);
list_for_each_entry(p, &dup_list, list) {
dmuci_get_value_by_section_string(p->config_section, "proto", &proto);
if (!strstr(proto, "ppp"))
continue;
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
p->dmmap_section, "ppp_int_instance", "ppp_int_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, inst) == DM_STOP)
break;
}
free_dmmap_config_dup_list(&dup_list);
*linker = data ? dmstrdup(section_name(((struct dmmap_dup *)data)->config_section)) : "";
return 0;
}
@ -927,7 +898,7 @@ static int operate_PPPInterface_Reset(char *refparam, struct dmctx *ctx, void *d
{
char interface_obj[64] = {0};
snprintf(interface_obj, sizeof(interface_obj), "network.interface.%s", section_name(((struct uci_section *)data)));
snprintf(interface_obj, sizeof(interface_obj), "network.interface.%s", section_name(((struct dmmap_dup *)data)->config_section));
dmubus_call_set(interface_obj, "down", UBUS_ARGS{}, 0);
dmubus_call_set(interface_obj, "up", UBUS_ARGS{}, 0);

View file

@ -15,11 +15,10 @@
struct ptm_args
{
struct uci_section *ptm_sec;
struct dmmap_dup *sections;
char *device;
};
/**************************************************************************
* LINKER
***************************************************************************/
@ -32,20 +31,107 @@ static int get_ptm_linker(char *refparam, struct dmctx *dmctx, void *data, char
/**************************************************************************
* INIT
***************************************************************************/
static inline int init_ptm_link(struct ptm_args *args, struct uci_section *s, char *device)
static inline int init_ptm_link(struct ptm_args *args, struct dmmap_dup *s, char *device)
{
args->ptm_sec = s;
args->sections = s;
args->device = device;
return 0;
}
/**************************************************************************
* SET & GET DSL LINK PARAMETERS
***************************************************************************/
/*************************************************************
* ENTRY METHOD
*************************************************************/
/*#Device.PTM.Link.{i}.!UCI:dsl/ptm-device/dmmap_dsl*/
static int browsePtmLinkInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *device;
struct ptm_args curr_ptm_args = {0};
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("dsl", "ptm-device", "dmmap_dsl", &dup_list);
list_for_each_entry(p, &dup_list, list) {
dmuci_get_value_by_section_string(p->config_section, "device", &device);
init_ptm_link(&curr_ptm_args, p, device);
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "ptmlinkinstance", "ptmlinkalias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_ptm_args, inst) == DM_STOP)
break;
}
free_dmmap_config_dup_list(&dup_list);
return 0;
}
/*************************************************************
* ADD OBJ
*************************************************************/
static int add_ptm_link(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
struct uci_section *dmmap_ptm = NULL;
char ptm_device[16];
snprintf(ptm_device, sizeof(ptm_device), "ptm%s", *instance);
dmuci_set_value("dsl", ptm_device, "", "ptm-device");
dmuci_set_value("dsl", ptm_device, "name", "PTM");
dmuci_set_value("dsl", ptm_device, "device", ptm_device);
dmuci_set_value("dsl", ptm_device, "enabled", "0");
dmuci_add_section_bbfdm("dmmap_dsl", "ptm-device", &dmmap_ptm);
dmuci_set_value_by_section(dmmap_ptm, "section_name", ptm_device);
dmuci_set_value_by_section(dmmap_ptm, "ptmlinkinstance", *instance);
return 0;
}
static int delete_ptm_link(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
struct uci_section *s = NULL, *stmp = NULL;
switch (del_action) {
case DEL_INST:
uci_foreach_option_cont("network", "interface", "device", ((struct ptm_args *)data)->device, s) {
if (stmp && ((struct ptm_args *)data)->device != NULL)
remove_device_from_interface(stmp, ((struct ptm_args *)data)->device);
stmp = s;
}
if (stmp != NULL && ((struct ptm_args *)data)->device != NULL)
remove_device_from_interface(stmp, ((struct ptm_args *)data)->device);
dmuci_delete_by_section((((struct ptm_args *)data)->sections)->dmmap_section, NULL, NULL);
dmuci_delete_by_section((((struct ptm_args *)data)->sections)->config_section, NULL, NULL);
break;
case DEL_ALL:
uci_foreach_sections_safe("dsl", "ptm-device", stmp, s) {
struct uci_section *ns = NULL, *nss = NULL, *dmmap_section = NULL;
char *device = NULL;
dmuci_get_value_by_section_string(s, "device", &device);
uci_foreach_option_cont("network", "interface", "device", device, ns) {
if (nss != NULL && device != NULL)
remove_device_from_interface(nss, device);
nss = ns;
}
if (nss != NULL && device != NULL)
remove_device_from_interface(nss, device);
get_dmmap_section_of_config_section("dmmap_dsl", "ptm-device", section_name(s), &dmmap_section);
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(s, NULL, NULL);
}
break;
}
return 0;
}
/*************************************************************
* GET & SET PARAM
**************************************************************/
/*#Device.PTM.Link.{i}.Enable!UCI:dsl/ptm-device,@i-1/enabled*/
static int get_ptm_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmuci_get_value_by_section_fallback_def(((struct ptm_args *)data)->ptm_sec, "enabled", "1");
*value = dmuci_get_value_by_section_fallback_def((((struct ptm_args *)data)->sections)->config_section, "enabled", "1");
return 0;
}
@ -60,7 +146,7 @@ static int set_ptm_enable(char *refparam, struct dmctx *ctx, void *data, char *i
return 0;
case VALUESET:
string_to_bool(value, &b);
dmuci_set_value_by_section(((struct ptm_args *)data)->ptm_sec, "enabled", b ? "1" : "0");
dmuci_set_value_by_section((((struct ptm_args *)data)->sections)->config_section, "enabled", b ? "1" : "0");
return 0;
}
return 0;
@ -75,10 +161,7 @@ static int get_ptm_status(char *refparam, struct dmctx *ctx, void *data, char *i
/*#Device.PTM.Link.{i}.Alias!UCI:dmmap_dsl/ptm-device,@i-1/ptmlinkalias*/
static int get_ptm_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *dmmap_section = NULL;
get_dmmap_section_of_config_section("dmmap_dsl", "ptm-device", section_name(((struct ptm_args *)data)->ptm_sec), &dmmap_section);
dmuci_get_value_by_section_string(dmmap_section, "ptmlinkalias", value);
dmuci_get_value_by_section_string((((struct ptm_args *)data)->sections)->dmmap_section, "ptmlinkalias", value);
if ((*value)[0] == '\0')
dmasprintf(value, "cpe-%s", instance);
return 0;
@ -86,16 +169,13 @@ static int get_ptm_alias(char *refparam, struct dmctx *ctx, void *data, char *in
static int set_ptm_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *dmmap_section = NULL;
switch (action) {
case VALUECHECK:
if (dm_validate_string(value, -1, 64, NULL, NULL))
return FAULT_9007;
return 0;
case VALUESET:
get_dmmap_section_of_config_section("dmmap_dsl", "ptm-device", section_name(((struct ptm_args *)data)->ptm_sec), &dmmap_section);
dmuci_set_value_by_section(dmmap_section, "ptmlinkalias", value);
dmuci_set_value_by_section((((struct ptm_args *)data)->sections)->dmmap_section, "ptmlinkalias", value);
return 0;
}
return 0;
@ -104,17 +184,15 @@ static int set_ptm_alias(char *refparam, struct dmctx *ctx, void *data, char *in
/*#Device.PTM.Link.{i}.Name!UCI:dsl/ptm-device,@i-1/name*/
static int get_ptm_link_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string(((struct ptm_args *)data)->ptm_sec, "name", value);
dmuci_get_value_by_section_string((((struct ptm_args *)data)->sections)->config_section, "name", value);
return 0;
}
static int find_lower_layer_by_dmmap_link(struct dmctx *ctx, void *data, char* dm_object, char **value)
{
char *linker = NULL;
struct uci_section *dmmap_section = NULL;
get_dmmap_section_of_config_section("dmmap_dsl", "ptm-device", section_name(((struct ptm_args *)data)->ptm_sec), &dmmap_section);
dmuci_get_value_by_section_string(dmmap_section, "ptm_ll_link", &linker);
dmuci_get_value_by_section_string((((struct ptm_args *)data)->sections)->dmmap_section, "ptm_ll_link", &linker);
if (linker != NULL)
adm_entry_get_linker_param(ctx, dm_object, linker, value);
if (*value == NULL)
@ -125,13 +203,11 @@ static int find_lower_layer_by_dmmap_link(struct dmctx *ctx, void *data, char* d
static int get_ptm_dsl_channel(struct dmctx *ctx, void *data, char *instance, char **value)
{
char *ptm_file = NULL;
struct uci_section *dmmap_section = NULL;
dmasprintf(&ptm_file, "/sys/class/net/ptm%d", atoi(instance) - 1);
if (folder_exists(ptm_file)) {
*value = "Device.DSL.Channel.1";
get_dmmap_section_of_config_section("dmmap_dsl", "ptm-device", section_name(((struct ptm_args *)data)->ptm_sec), &dmmap_section);
dmuci_set_value_by_section(dmmap_section, "ptm_ll_link", "fast_line_1");
dmuci_set_value_by_section((((struct ptm_args *)data)->sections)->dmmap_section, "ptm_ll_link", "fast_line_1");
}
return 0;
@ -139,7 +215,6 @@ static int get_ptm_dsl_channel(struct dmctx *ctx, void *data, char *instance, ch
static int get_ptm_fast_line(struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *dmmap_section = NULL;
json_object *res = NULL, *line_obj = NULL;
dmubus_call("fast", "status", UBUS_ARGS{}, 0, &res);
@ -150,8 +225,7 @@ static int get_ptm_fast_line(struct dmctx *ctx, void *data, char *instance, char
return 0;
if ( strcmp(dmjson_get_value(line_obj, 1, "status"), "up") == 0) {
*value = "Device.FAST.Line.1";
get_dmmap_section_of_config_section("dmmap_dsl", "ptm-device", section_name(((struct ptm_args *)data)->ptm_sec), &dmmap_section);
dmuci_set_value_by_section(dmmap_section, "ptm_ll_link", "fast_line_1");
dmuci_set_value_by_section((((struct ptm_args *)data)->sections)->dmmap_section, "ptm_ll_link", "fast_line_1");
}
return 0;
}
@ -170,19 +244,16 @@ static int get_ptm_lower_layer(char *refparam, struct dmctx *ctx, void *data, ch
static int set_ptm_lower_layer(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *dmmap_section = NULL;
switch (action) {
case VALUECHECK:
if (strncmp(value, "Device.DSL.Channel.1", strlen("Device.DSL.Channel.1")) != 0 && strncmp(value, "Device.FAST.Line.1", strlen("Device.FAST.Line.1")) != 0)
return FAULT_9007;
break;
case VALUESET:
get_dmmap_section_of_config_section("dmmap_dsl", "ptm-device", section_name(((struct ptm_args *)data)->ptm_sec), &dmmap_section);
if (strcmp(value, "Device.DSL.Channel.1") == 0)
dmuci_set_value_by_section(dmmap_section, "ptm_ll_link", "dsl_channel_1");
dmuci_set_value_by_section((((struct ptm_args *)data)->sections)->dmmap_section, "ptm_ll_link", "dsl_channel_1");
else
dmuci_set_value_by_section(dmmap_section, "ptm_ll_link", "fast_line_1");
dmuci_set_value_by_section((((struct ptm_args *)data)->sections)->dmmap_section, "ptm_ll_link", "fast_line_1");
break;
}
return 0;
@ -223,97 +294,9 @@ static int get_ptm_stats_pack_sent(char *refparam, struct dmctx *ctx, void *data
return ubus_ptm_stats(value, "tx_packets", data);
}
/*************************************************************
* ADD OBJ
*************************************************************/
static int add_ptm_link(char *refparam, struct dmctx *ctx, void *data, char **instancepara)
{
struct uci_section *dmmap_ptm = NULL;
char ptm_device[16];
char *instance = get_last_instance_bbfdm("dmmap_dsl", "ptm-device", "ptmlinkinstance");
snprintf(ptm_device, sizeof(ptm_device), "ptm%d", instance ? atoi(instance) : 0);
dmuci_set_value("dsl", ptm_device, "", "ptm-device");
dmuci_set_value("dsl", ptm_device, "name", "PTM");
dmuci_set_value("dsl", ptm_device, "device", ptm_device);
dmuci_set_value("dsl", ptm_device, "enabled", "0");
dmuci_add_section_bbfdm("dmmap_dsl", "ptm-device", &dmmap_ptm);
dmuci_set_value_by_section(dmmap_ptm, "section_name", ptm_device);
*instancepara = update_instance(instance, 2, dmmap_ptm, "ptmlinkinstance");
return 0;
}
static int delete_ptm_link(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
struct uci_section *s = NULL, *stmp = NULL, *dmmap_section = NULL;
switch (del_action) {
case DEL_INST:
get_dmmap_section_of_config_section("dmmap_dsl", "ptm-device", section_name(((struct ptm_args *)data)->ptm_sec), &dmmap_section);
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(((struct ptm_args *)data)->ptm_sec, NULL, NULL);
uci_foreach_option_cont("network", "interface", "device", ((struct ptm_args *)data)->device, s) {
if (stmp && ((struct ptm_args *)data)->device != NULL)
remove_device_from_interface(stmp, ((struct ptm_args *)data)->device);
stmp = s;
}
if (stmp != NULL && ((struct ptm_args *)data)->device != NULL)
remove_device_from_interface(stmp, ((struct ptm_args *)data)->device);
break;
case DEL_ALL:
uci_foreach_sections_safe("dsl", "ptm-device", stmp, s) {
struct uci_section *ns = NULL, *nss = NULL;
char *device = NULL;
dmuci_get_value_by_section_string(s, "device", &device);
uci_foreach_option_cont("network", "interface", "device", device, ns) {
if (nss != NULL && device != NULL)
remove_device_from_interface(nss, device);
nss = ns;
}
if (nss != NULL && device != NULL)
remove_device_from_interface(nss, device);
get_dmmap_section_of_config_section("dmmap_dsl", "ptm-device", section_name(s), &dmmap_section);
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(s, NULL, NULL);
}
break;
}
return 0;
}
/*************************************************************
* ENTRY METHOD
*************************************************************/
/*#Device.PTM.Link.{i}.!UCI:dsl/ptm-device/dmmap_dsl*/
static int browsePtmLinkInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *max_inst = NULL, *device;
struct ptm_args curr_ptm_args = {0};
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("dsl", "ptm-device", "dmmap_dsl", &dup_list);
list_for_each_entry(p, &dup_list, list) {
dmuci_get_value_by_section_string(p->config_section, "device", &device);
init_ptm_link(&curr_ptm_args, p->config_section, device);
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
p->dmmap_section, "ptmlinkinstance", "ptmlinkalias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_ptm_args, inst) == DM_STOP)
break;
}
free_dmmap_config_dup_list(&dup_list);
return 0;
}
/**********************************************************************************************************************************
* OBJ & LEAF DEFINITION
***********************************************************************************************************************************/
/* *** Device.PTM. *** */
DMOBJ tPTMObj[] = {
/* OBJ, permission, addobj, delobj, checkdep, browseinstobj, nextdynamicobj, dynamicleaf, nextobj, leaf, linker, bbfdm_type, uniqueKeys*/

File diff suppressed because it is too large Load diff

View file

@ -50,7 +50,7 @@ static int radv_set_option_value(struct uci_section *s, char *option_list, const
/*#Device.RouterAdvertisement.InterfaceSetting.{i}.!UCI:dhcp/dhcp/dmmap_radv*/
static int browseRouterAdvertisementInterfaceSettingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *max_inst = NULL, *ignore = NULL;
char *inst = NULL, *ignore = NULL;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
@ -62,10 +62,9 @@ static int browseRouterAdvertisementInterfaceSettingInst(struct dmctx *dmctx, DM
if (ignore && strcmp(ignore, "1") == 0)
continue;
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
p->dmmap_section, "radv_intf_instance", "radv_intf_alias");
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "radv_intf_instance", "radv_intf_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, inst) == DM_STOP)
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p, inst) == DM_STOP)
break;
}
free_dmmap_config_dup_list(&dup_list);
@ -74,12 +73,11 @@ static int browseRouterAdvertisementInterfaceSettingInst(struct dmctx *dmctx, DM
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_s = ((struct dmmap_dup *)prev_data)->config_section;
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;
char *inst = NULL, *option_value = NULL;
dmuci_get_value_by_section_list(dhcp_s, "dns", &dns_list);
@ -102,12 +100,7 @@ static int browseRouterAdvertisementInterfaceSettingOptionInst(struct dmctx *dmc
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);
inst = handle_instance(dmctx, parent_node, dhcp_dmmap_s, "radv_option_instance", "radv_option_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&radv_option_args, inst) == DM_STOP)
break;
@ -123,8 +116,7 @@ static int addObjRouterAdvertisementInterfaceSetting(char *refparam, struct dmct
struct uci_section *dmmap = NULL, *s = NULL;
char ra_sname[32] = {0};
char *inst = get_dhcp_server_pool_last_instance("dhcp", "dhcp", "dmmap_radv", "radv_intf_instance");
snprintf(ra_sname, sizeof(ra_sname), "ra_%d", inst ? atoi(inst) + 1 : 1);
snprintf(ra_sname, sizeof(ra_sname), "ra_%s", *instance);
dmuci_add_section("dhcp", "dhcp", &s);
dmuci_rename_section_by_section(s, ra_sname);
@ -134,23 +126,23 @@ static int addObjRouterAdvertisementInterfaceSetting(char *refparam, struct dmct
dmuci_add_section_bbfdm("dmmap_radv", "dhcp", &dmmap);
dmuci_set_value_by_section(dmmap, "section_name", ra_sname);
*instance = update_instance(inst, 2, dmmap, "radv_intf_instance");
dmuci_set_value_by_section(dmmap, "radv_intf_instance", *instance);
return 0;
}
static int delObjRouterAdvertisementInterfaceSetting(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
struct uci_section *s = NULL, *stmp = NULL, *dmmap_section = NULL;
struct uci_section *s = NULL, *stmp = NULL;
switch (del_action) {
case DEL_INST:
get_dmmap_section_of_config_section("dmmap_radv", "dhcp", section_name((struct uci_section *)data), &dmmap_section);
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section((struct uci_section *)data, NULL, NULL);
dmuci_delete_by_section(((struct dmmap_dup *)data)->config_section, NULL, NULL);
dmuci_delete_by_section(((struct dmmap_dup *)data)->dmmap_section, NULL, NULL);
break;
case DEL_ALL:
uci_foreach_sections_safe("dhcp", "dhcp", stmp, s) {
struct uci_section *dmmap_section = NULL;
get_dmmap_section_of_config_section("dmmap_radv", "dhcp", section_name(s), &dmmap_section);
dmuci_delete_by_section(dmmap_section, NULL, NULL);
@ -164,18 +156,11 @@ static int delObjRouterAdvertisementInterfaceSetting(char *refparam, struct dmct
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, "section_name", section_name(((struct dmmap_dup *)data)->config_section));
dmuci_set_value_by_section_bbfdm(dmmap_sect, "option_tag", "23");
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);
dmuci_set_value_by_section_bbfdm(dmmap_sect, "radv_option_instance", *instance);
return 0;
}
@ -190,12 +175,12 @@ static int delObjRouterAdvertisementInterfaceSettingOption(char *refparam, struc
if (value_exists_in_uci_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);
dmuci_delete_by_section(((struct radv_option_args *)data)->dmmap_sect, NULL, NULL);
break;
case DEL_ALL:
dmuci_set_value_by_section((struct uci_section *)data, "dns", "");
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "dns", "");
uci_path_foreach_sections_safe(bbfdm, "dmmap_radv", "radv_option", stmp, s) {
dmuci_delete_by_section_unnamed_bbfdm(s, NULL, NULL);
dmuci_delete_by_section(s, NULL, NULL);
}
break;
}
@ -231,27 +216,15 @@ static int set_RouterAdvertisement_Enable(char *refparam, struct dmctx *ctx, voi
static int get_RouterAdvertisement_InterfaceSettingNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s = NULL;
char *ignore = NULL;
int i = 0;
uci_foreach_sections("dhcp", "dhcp", s) {
// skip the section if option ignore = '1'
dmuci_get_value_by_section_string(s, "ignore", &ignore);
if (ignore && strcmp(ignore, "1") == 0)
continue;
i++;
}
dmasprintf(value, "%d", i);
int cnt = get_number_of_entries(ctx, data, instance, browseRouterAdvertisementInterfaceSettingInst);
dmasprintf(value, "%d", cnt);
return 0;
}
/*#Device.RouterAdvertisement.InterfaceSetting.{i}.Enable!UCI:dhcp/dhcp,@i-1/ra*/
static int get_RouterAdvertisementInterfaceSetting_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string((struct uci_section *)data, "ra", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "ra", value);
*value = (*value && strcmp(*value, "disabled") == 0) ? "0" : "1";
return 0;
}
@ -267,7 +240,7 @@ static int set_RouterAdvertisementInterfaceSetting_Enable(char *refparam, struct
break;
case VALUESET:
string_to_bool(value, &b);
dmuci_set_value_by_section((struct uci_section *)data, "ra", b ? "server" : "disabled");
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "ra", b ? "server" : "disabled");
break;
}
return 0;
@ -276,17 +249,14 @@ static int set_RouterAdvertisementInterfaceSetting_Enable(char *refparam, struct
/*#Device.RouterAdvertisement.InterfaceSetting.{i}.Status!UCI:dhcp/dhcp,@i-1/ra*/
static int get_RouterAdvertisementInterfaceSetting_Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string((struct uci_section *)data, "ra", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "ra", value);
*value = (*value && strcmp(*value, "disabled") == 0) ? "Disabled" : "Enabled";
return 0;
}
static int get_RouterAdvertisementInterfaceSetting_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *dmmap_sect = NULL;
get_dmmap_section_of_config_section("dmmap_radv", "dhcp", section_name((struct uci_section *)data), &dmmap_sect);
dmuci_get_value_by_section_string(dmmap_sect, "radv_intf_alias", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->dmmap_section, "radv_intf_alias", value);
if ((*value)[0] == '\0')
dmasprintf(value, "cpe-%s", instance);
return 0;
@ -294,16 +264,13 @@ static int get_RouterAdvertisementInterfaceSetting_Alias(char *refparam, struct
static int set_RouterAdvertisementInterfaceSetting_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *dmmap_sect = NULL;
switch (action) {
case VALUECHECK:
if (dm_validate_string(value, -1, 64, NULL, NULL))
return FAULT_9007;
break;
case VALUESET:
get_dmmap_section_of_config_section("dmmap_radv", "dhcp", section_name((struct uci_section *)data), &dmmap_sect);
dmuci_set_value_by_section_bbfdm(dmmap_sect, "radv_intf_alias", value);
dmuci_set_value_by_section_bbfdm(((struct dmmap_dup *)data)->dmmap_section, "radv_intf_alias", value);
break;
}
return 0;
@ -314,7 +281,7 @@ static int get_RouterAdvertisementInterfaceSetting_Interface(char *refparam, str
{
char *linker = NULL;
dmuci_get_value_by_section_string((struct uci_section *)data, "interface", &linker);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "interface", &linker);
adm_entry_get_linker_param(ctx, "Device.IP.Interface.", linker, value);
if (*value == NULL)
*value = "";
@ -333,7 +300,7 @@ static int set_RouterAdvertisementInterfaceSetting_Interface(char *refparam, str
case VALUESET:
adm_entry_get_linker_value(ctx, value, &linker);
if (linker && *linker) {
dmuci_set_value_by_section((struct uci_section *)data, "interface", linker);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "interface", linker);
dmfree(linker);
}
break;
@ -345,12 +312,11 @@ static int get_RouterAdvertisementInterfaceSetting_Prefixes(char *refparam, stru
{
json_object *res = NULL, *ipv6_prefix_obj = NULL, *arrobj = NULL;
char *interface = NULL, *ip_inst = NULL, list_val[512];
struct uci_section *dmmap_section = NULL;
struct uci_section *dmmap_s = NULL;
int i = 0, pos = 0;
dmuci_get_value_by_section_string((struct uci_section *)data, "interface", &interface);
get_dmmap_section_of_config_section("dmmap_network", "interface", interface, &dmmap_section);
dmuci_get_value_by_section_string(dmmap_section, "ip_int_instance", &ip_inst);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "interface", &interface);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->dmmap_section, "ip_int_instance", &ip_inst);
list_val[0] = 0;
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", interface, String}}, 1, &res);
@ -361,10 +327,10 @@ static int get_RouterAdvertisementInterfaceSetting_Prefixes(char *refparam, stru
char *mask = dmjson_get_value(ipv6_prefix_obj, 1, "mask");
snprintf(ipv6_prefix, sizeof(ipv6_prefix), "%s/%s", address, mask);
uci_path_foreach_option_eq(bbfdm, "dmmap_network_ipv6_prefix", "intf_ipv6_prefix", "section_name", interface, dmmap_section) {
dmuci_get_value_by_section_string(dmmap_section, "address", &address);
uci_path_foreach_option_eq(bbfdm, "dmmap_network_ipv6_prefix", "intf_ipv6_prefix", "section_name", interface, dmmap_s) {
dmuci_get_value_by_section_string(dmmap_s, "address", &address);
if (address && strcmp(address, ipv6_prefix) == 0) {
dmuci_get_value_by_section_string(dmmap_section, "ipv6_prefix_instance", &ipv6_prefix_inst);
dmuci_get_value_by_section_string(dmmap_s, "ipv6_prefix_instance", &ipv6_prefix_inst);
break;
}
}
@ -384,7 +350,7 @@ static int get_RouterAdvertisementInterfaceSetting_Prefixes(char *refparam, stru
/*#Device.RouterAdvertisement.InterfaceSetting.{i}.MaxRtrAdvInterval!UCI:dhcp/dhcp,@i-1/ra_maxinterval*/
static int get_RouterAdvertisementInterfaceSetting_MaxRtrAdvInterval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "ra_maxinterval", "600");
*value = dmuci_get_value_by_section_fallback_def(((struct dmmap_dup *)data)->config_section, "ra_maxinterval", "600");
return 0;
}
@ -396,7 +362,7 @@ static int set_RouterAdvertisementInterfaceSetting_MaxRtrAdvInterval(char *refpa
return FAULT_9007;
break;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "ra_maxinterval", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "ra_maxinterval", value);
break;
}
return 0;
@ -405,7 +371,7 @@ static int set_RouterAdvertisementInterfaceSetting_MaxRtrAdvInterval(char *refpa
/*#Device.RouterAdvertisement.InterfaceSetting.{i}.MinRtrAdvInterval!UCI:dhcp/dhcp,@i-1/ra_mininterval*/
static int get_RouterAdvertisementInterfaceSetting_MinRtrAdvInterval(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "ra_mininterval", "200");
*value = dmuci_get_value_by_section_fallback_def(((struct dmmap_dup *)data)->config_section, "ra_mininterval", "200");
return 0;
}
@ -417,7 +383,7 @@ static int set_RouterAdvertisementInterfaceSetting_MinRtrAdvInterval(char *refpa
return FAULT_9007;
break;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "ra_mininterval", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "ra_mininterval", value);
break;
}
return 0;
@ -426,7 +392,7 @@ static int set_RouterAdvertisementInterfaceSetting_MinRtrAdvInterval(char *refpa
/*#Device.RouterAdvertisement.InterfaceSetting.{i}.AdvDefaultLifetime!UCI:dhcp/dhcp,@i-1/ra_lifetime*/
static int get_RouterAdvertisementInterfaceSetting_AdvDefaultLifetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "ra_lifetime", "1800");
*value = dmuci_get_value_by_section_fallback_def(((struct dmmap_dup *)data)->config_section, "ra_lifetime", "1800");
return 0;
}
@ -438,7 +404,7 @@ static int set_RouterAdvertisementInterfaceSetting_AdvDefaultLifetime(char *refp
return FAULT_9007;
break;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "ra_lifetime", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "ra_lifetime", value);
break;
}
return 0;
@ -447,7 +413,7 @@ static int set_RouterAdvertisementInterfaceSetting_AdvDefaultLifetime(char *refp
/*#Device.RouterAdvertisement.InterfaceSetting.{i}.AdvManagedFlag!UCI:dhcp/dhcp,@i-1/ra_flags*/
static int get_RouterAdvertisementInterfaceSetting_AdvManagedFlag(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return radv_get_option_value((struct uci_section *)data, "ra_flags", "managed-config", value);
return radv_get_option_value(((struct dmmap_dup *)data)->config_section, "ra_flags", "managed-config", value);
}
static int set_RouterAdvertisementInterfaceSetting_AdvManagedFlag(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
@ -461,7 +427,7 @@ static int set_RouterAdvertisementInterfaceSetting_AdvManagedFlag(char *refparam
break;
case VALUESET:
string_to_bool(value, &b);
return radv_set_option_value((struct uci_section *)data, "ra_flags", "managed-config", b);
return radv_set_option_value(((struct dmmap_dup *)data)->config_section, "ra_flags", "managed-config", b);
}
return 0;
}
@ -469,7 +435,7 @@ static int set_RouterAdvertisementInterfaceSetting_AdvManagedFlag(char *refparam
/*#Device.RouterAdvertisement.InterfaceSetting.{i}.AdvOtherConfigFlag!UCI:dhcp/dhcp,@i-1/ra_flags*/
static int get_RouterAdvertisementInterfaceSetting_AdvOtherConfigFlag(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return radv_get_option_value((struct uci_section *)data, "ra_flags", "other-config", value);
return radv_get_option_value(((struct dmmap_dup *)data)->config_section, "ra_flags", "other-config", value);
}
static int set_RouterAdvertisementInterfaceSetting_AdvOtherConfigFlag(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
@ -483,7 +449,7 @@ static int set_RouterAdvertisementInterfaceSetting_AdvOtherConfigFlag(char *refp
break;
case VALUESET:
string_to_bool(value, &b);
return radv_set_option_value((struct uci_section *)data, "ra_flags", "other-config", b);
return radv_set_option_value(((struct dmmap_dup *)data)->config_section, "ra_flags", "other-config", b);
}
return 0;
}
@ -491,7 +457,7 @@ static int set_RouterAdvertisementInterfaceSetting_AdvOtherConfigFlag(char *refp
/*#Device.RouterAdvertisement.InterfaceSetting.{i}.AdvMobileAgentFlag!UCI:dhcp/dhcp,@i-1/ra_flags*/
static int get_RouterAdvertisementInterfaceSetting_AdvMobileAgentFlag(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
return radv_get_option_value((struct uci_section *)data, "ra_flags", "home-agent", value);
return radv_get_option_value(((struct dmmap_dup *)data)->config_section, "ra_flags", "home-agent", value);
}
static int set_RouterAdvertisementInterfaceSetting_AdvMobileAgentFlag(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
@ -505,7 +471,7 @@ static int set_RouterAdvertisementInterfaceSetting_AdvMobileAgentFlag(char *refp
break;
case VALUESET:
string_to_bool(value, &b);
return radv_set_option_value((struct uci_section *)data, "ra_flags", "home-agent", b);
return radv_set_option_value(((struct dmmap_dup *)data)->config_section, "ra_flags", "home-agent", b);
}
return 0;
}
@ -515,7 +481,7 @@ static int get_RouterAdvertisementInterfaceSetting_AdvPreferredRouterFlag(char *
{
char *preferenece = NULL;
dmuci_get_value_by_section_string((struct uci_section *)data, "ra_preference", &preferenece);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "ra_preference", &preferenece);
*value = (preferenece && *preferenece == 'h') ? "High" : (preferenece && *preferenece == 'l') ? "Low" : "Medium";
return 0;
}
@ -528,7 +494,7 @@ static int set_RouterAdvertisementInterfaceSetting_AdvPreferredRouterFlag(char *
return FAULT_9007;
break;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "ra_preference", (*value == 'H') ? "high" : (*value == 'L') ? "low" : "medium");
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "ra_preference", (*value == 'H') ? "high" : (*value == 'L') ? "low" : "medium");
break;
}
return 0;
@ -537,7 +503,7 @@ static int set_RouterAdvertisementInterfaceSetting_AdvPreferredRouterFlag(char *
/*#Device.RouterAdvertisement.InterfaceSetting.{i}.AdvLinkMTU!UCI:dhcp/dhcp,@i-1/ra_mtu*/
static int get_RouterAdvertisementInterfaceSetting_AdvLinkMTU(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "ra_mtu", "0");
*value = dmuci_get_value_by_section_fallback_def(((struct dmmap_dup *)data)->config_section, "ra_mtu", "0");
return 0;
}
@ -549,7 +515,7 @@ static int set_RouterAdvertisementInterfaceSetting_AdvLinkMTU(char *refparam, st
return FAULT_9007;
break;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "ra_mtu", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "ra_mtu", value);
break;
}
return 0;
@ -558,7 +524,7 @@ static int set_RouterAdvertisementInterfaceSetting_AdvLinkMTU(char *refparam, st
/*#Device.RouterAdvertisement.InterfaceSetting.{i}.AdvReachableTime!UCI:dhcp/dhcp,@i-1/ra_reachabletime*/
static int get_RouterAdvertisementInterfaceSetting_AdvReachableTime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "ra_reachabletime", "0");
*value = dmuci_get_value_by_section_fallback_def(((struct dmmap_dup *)data)->config_section, "ra_reachabletime", "0");
return 0;
}
@ -570,7 +536,7 @@ static int set_RouterAdvertisementInterfaceSetting_AdvReachableTime(char *refpar
return FAULT_9007;
break;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "ra_reachabletime", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "ra_reachabletime", value);
break;
}
return 0;
@ -579,7 +545,7 @@ static int set_RouterAdvertisementInterfaceSetting_AdvReachableTime(char *refpar
/*#Device.RouterAdvertisement.InterfaceSetting.{i}.AdvRetransTimer!UCI:dhcp/dhcp,@i-1/ra_retranstime*/
static int get_RouterAdvertisementInterfaceSetting_AdvRetransTimer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "ra_retranstime", "0");
*value = dmuci_get_value_by_section_fallback_def(((struct dmmap_dup *)data)->config_section, "ra_retranstime", "0");
return 0;
}
@ -591,7 +557,7 @@ static int set_RouterAdvertisementInterfaceSetting_AdvRetransTimer(char *refpara
return FAULT_9007;
break;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "ra_retranstime", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "ra_retranstime", value);
break;
}
return 0;
@ -600,7 +566,7 @@ static int set_RouterAdvertisementInterfaceSetting_AdvRetransTimer(char *refpara
/*#Device.RouterAdvertisement.InterfaceSetting.{i}.AdvCurHopLimit!UCI:dhcp/dhcp,@i-1/ra_hoplimit*/
static int get_RouterAdvertisementInterfaceSetting_AdvCurHopLimit(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "ra_hoplimit", "0");
*value = dmuci_get_value_by_section_fallback_def(((struct dmmap_dup *)data)->config_section, "ra_hoplimit", "0");
return 0;
}
@ -612,7 +578,7 @@ static int set_RouterAdvertisementInterfaceSetting_AdvCurHopLimit(char *refparam
return FAULT_9007;
break;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "ra_hoplimit", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "ra_hoplimit", value);
break;
}
return 0;
@ -620,19 +586,8 @@ static int set_RouterAdvertisementInterfaceSetting_AdvCurHopLimit(char *refparam
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);
int cnt = get_number_of_entries(ctx, data, instance, browseRouterAdvertisementInterfaceSettingOptionInst);
dmasprintf(value, "%d", cnt);
return 0;
}
@ -795,4 +750,3 @@ DMLEAF tRouterAdvertisementInterfaceSettingOptionParams[] = {
{"Value", &DMWRITE, DMT_HEXBIN, get_RouterAdvertisementInterfaceSettingOption_Value, set_RouterAdvertisementInterfaceSettingOption_Value, BBFDM_BOTH},
{0}
};

View file

@ -190,78 +190,6 @@ static int parse_proc_route6_line(const char *line, char *ipstr, char *gwstr, ch
return 0;
}
static int get_forwarding_last_inst(bool ipv6)
{
char *rinst = NULL, *drinst = NULL, *dsinst = NULL, *tmp = NULL;
int r = 0, dr = 0, ds = 0;
struct uci_section *s = NULL;
uci_path_foreach_sections(bbfdm, "dmmap_route_forwarding", ipv6 ? "route6" : "route", s) {
dmuci_get_value_by_section_string(s, ipv6 ? "route6instance" : "routeinstance", &tmp);
if (tmp && tmp[0] == '\0')
break;
rinst = tmp;
}
uci_path_foreach_sections(bbfdm, "dmmap_route_forwarding", ipv6 ? "route6_disabled" : "route_disabled", s) {
dmuci_get_value_by_section_string(s, ipv6 ? "route6instance" : "routeinstance", &tmp);
if (tmp && tmp[0] == '\0')
break;
dsinst = tmp;
}
uci_path_foreach_sections(bbfdm, "dmmap_route_forwarding", ipv6 ? "route6_dynamic" : "route_dynamic", s) {
dmuci_get_value_by_section_string(s, ipv6 ? "route6instance" : "routeinstance", &tmp);
if (tmp && tmp[0] == '\0')
break;
drinst = tmp;
}
if (rinst) r = atoi(rinst);
if (dsinst) ds = atoi(dsinst);
if (drinst) dr = atoi(drinst);
return (r > ds && r > dr ? r : ds > dr ? ds : dr);
}
static char *forwarding_update_instance_alias_bbfdm(int action, char **last_inst, char **max_inst, void *argv[])
{
char *instance, *alias;
char buf[64] = {0};
struct uci_section *s = (struct uci_section *) argv[0];
char *inst_opt = (char *) argv[1];
char *alias_opt = (char *) argv[2];
bool *ipv4_forwarding = (bool *) argv[3];
bool *find_max = (bool *) argv[4];
dmuci_get_value_by_section_string(s, inst_opt, &instance);
if (instance[0] == '\0') {
if (*find_max) {
int m = get_forwarding_last_inst((*ipv4_forwarding) ? false : true);
snprintf(buf, sizeof(buf), "%d", m+1);
*find_max = false;
} else if (max_inst == NULL) {
snprintf(buf, sizeof(buf), "%d", 1);
} else {
snprintf(buf, sizeof(buf), "%d", atoi(*max_inst)+1);
}
instance = dmuci_set_value_by_section_bbfdm(s, inst_opt, buf);
}
*max_inst = instance;
*last_inst = instance;
if (action == INSTANCE_MODE_ALIAS) {
dmuci_get_value_by_section_string(s, alias_opt, &alias);
if (alias[0] == '\0') {
snprintf(buf, sizeof(buf), "cpe-%s", instance);
alias = dmuci_set_value_by_section_bbfdm(s, alias_opt, buf);
}
snprintf(buf, sizeof(buf), "[%s]", alias);
instance = dmstrdup(buf);
}
return instance;
}
static int dmmap_synchronizeRoutingRouterIPv4Forwarding(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct uci_section *s = NULL, *stmp = NULL;
@ -319,9 +247,7 @@ static int dmmap_synchronizeRoutingRouterIPv4Forwarding(struct dmctx *dmctx, DMN
break;
}
}
char instance[16];
snprintf(instance, sizeof(instance), "%d", get_forwarding_last_inst(false) + 1);
dmuci_add_section_bbfdm("dmmap_route_forwarding", "route_dynamic", &s);
dmuci_set_value_by_section_bbfdm(s, "target", proute.destination);
dmuci_set_value_by_section_bbfdm(s, "netmask", proute.mask);
@ -329,7 +255,6 @@ static int dmmap_synchronizeRoutingRouterIPv4Forwarding(struct dmctx *dmctx, DMN
dmuci_set_value_by_section_bbfdm(s, "gateway", proute.gateway);
dmuci_set_value_by_section_bbfdm(s, "device", proute.iface);
dmuci_set_value_by_section_bbfdm(s, "interface", iface);
dmuci_set_value_by_section_bbfdm(s, "routeinstance", instance);
}
fclose(fp);
}
@ -396,9 +321,7 @@ static int dmmap_synchronizeRoutingRouterIPv6Forwarding(struct dmctx *dmctx, DMN
break;
}
}
char instance[16];
snprintf(instance, sizeof(instance), "%d", get_forwarding_last_inst(true) + 1);
dmuci_add_section_bbfdm("dmmap_route_forwarding", "route6_dynamic", &s);
dmuci_set_value_by_section_bbfdm(s, "target", ipstr);
dmuci_set_value_by_section_bbfdm(s, "gateway", gwstr);
@ -406,12 +329,150 @@ static int dmmap_synchronizeRoutingRouterIPv6Forwarding(struct dmctx *dmctx, DMN
dmuci_set_value_by_section_bbfdm(s, "device", dev);
snprintf(buf, sizeof(buf), "%u", metric);
dmuci_set_value_by_section_bbfdm(s, "metric", buf);
dmuci_set_value_by_section_bbfdm(s, "route6instance", instance);
}
fclose(fp);
return 0;
}
/*************************************************************
* ENTRY METHOD
**************************************************************/
static int browseRouterInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct uci_section *s = is_dmmap_section_exist("dmmap_route_forwarding", "router");
if (!s) dmuci_add_section_bbfdm("dmmap_route_forwarding", "router", &s);
handle_instance(dmctx, parent_node, s, "router_instance", "router_alias");
DM_LINK_INST_OBJ(dmctx, parent_node, s, "1");
return 0;
}
/*#Device.Routing.Router.{i}.IPv4Forwarding.{i}.!UCI:network/route/dmmap_route_forwarding*/
static int browseIPv4ForwardingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL;
struct uci_section *s = NULL;
struct routingfwdargs curr_routefwdargs = {0};
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
// Enable Routes
synchronize_specific_config_sections_with_dmmap("network", "route", "dmmap_route_forwarding", &dup_list);
list_for_each_entry(p, &dup_list, list) {
init_args_ipv4forward(&curr_routefwdargs, p->config_section, "1", ROUTE_STATIC);
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "routeinstance", "routealias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_routefwdargs, inst) == DM_STOP)
goto end;
}
free_dmmap_config_dup_list(&dup_list);
// Disable Routes
synchronize_specific_config_sections_with_dmmap("network", "route_disabled", "dmmap_route_forwarding", &dup_list);
list_for_each_entry(p, &dup_list, list) {
init_args_ipv4forward(&curr_routefwdargs, p->config_section, "1", ROUTE_DISABLED);
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "routeinstance", "routealias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_routefwdargs, inst) == DM_STOP)
goto end;
}
free_dmmap_config_dup_list(&dup_list);
// Dynamic Routes
dmmap_synchronizeRoutingRouterIPv4Forwarding(dmctx, parent_node, prev_data, prev_instance);
uci_path_foreach_sections(bbfdm, "dmmap_route_forwarding", "route_dynamic", s) {
init_args_ipv4forward(&curr_routefwdargs, s, "0", ROUTE_DYNAMIC);
inst = handle_instance(dmctx, parent_node, s, "routeinstance", "routealias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_routefwdargs, inst) == DM_STOP)
goto end;
}
end:
return 0;
}
/*#Device.Routing.Router.{i}.IPv6Forwarding.{i}.!UCI:network/route6/dmmap_route_forwarding*/
static int browseIPv6ForwardingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL;
struct uci_section *s = NULL;
struct routingfwdargs curr_route6fwdargs = {0};
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
// Enable Routes
synchronize_specific_config_sections_with_dmmap("network", "route6", "dmmap_route_forwarding", &dup_list);
list_for_each_entry(p, &dup_list, list) {
init_args_ipv6forward(&curr_route6fwdargs, p->config_section, "1", ROUTE_STATIC);
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "route6instance", "route6alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_route6fwdargs, inst) == DM_STOP)
goto end;
}
free_dmmap_config_dup_list(&dup_list);
// Disable Routes
synchronize_specific_config_sections_with_dmmap("network", "route6_disabled", "dmmap_route_forwarding", &dup_list);
list_for_each_entry(p, &dup_list, list) {
init_args_ipv6forward(&curr_route6fwdargs, p->config_section, "1", ROUTE_DISABLED);
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "route6instance", "route6alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_route6fwdargs, inst) == DM_STOP)
goto end;
}
free_dmmap_config_dup_list(&dup_list);
// Dynamic Routes
dmmap_synchronizeRoutingRouterIPv6Forwarding(dmctx, parent_node, prev_data, prev_instance);
uci_path_foreach_sections(bbfdm, "dmmap_route_forwarding", "route6_dynamic", s) {
init_args_ipv6forward(&curr_route6fwdargs, s, "0", ROUTE_DYNAMIC);
inst = handle_instance(dmctx, parent_node, s, "route6instance", "route6alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_route6fwdargs, inst) == DM_STOP)
goto end;
}
end:
return 0;
}
static int browseRoutingRouteInformationInterfaceSettingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct uci_section *s = NULL;
char *inst = NULL;
int id = 0, i = 0;
uci_foreach_sections("network", "interface", s) {
char *proto = NULL, *ip6addr = NULL;
dmuci_get_value_by_section_string(s, "proto", &proto);
dmuci_get_value_by_section_string(s, "ip6addr", &ip6addr);
if ((proto && strcmp(proto, "dhcpv6") == 0) || (ip6addr && ip6addr[0] != '\0')) {
json_object *res = NULL, *route_obj = NULL, *arrobj = NULL;
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(s), String}}, 1, &res);
dmjson_foreach_obj_in_array(res, arrobj, route_obj, i, 1, "route") {
inst = handle_instance_without_section(dmctx, parent_node, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)route_obj, inst) == DM_STOP)
break;
}
}
}
return 0;
}
/*************************************************************
* GET & SET PARAM
**************************************************************/
@ -449,40 +510,16 @@ static int get_RoutingRouter_Status(char *refparam, struct dmctx *ctx, void *dat
/*#Device.Routing.Router.{i}.IPv4ForwardingNumberOfEntries!UCI:network/route/*/
static int get_RoutingRouter_IPv4ForwardingNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s = NULL;
int cnt = 0;
uci_foreach_sections("network", "route", s) {
cnt++;
}
uci_foreach_sections("network", "route_disabled", s) {
cnt++;
}
dmmap_synchronizeRoutingRouterIPv4Forwarding(ctx, NULL, NULL, NULL);
uci_path_foreach_sections(bbfdm, "dmmap_route_forwarding", "route_dynamic", s) {
cnt++;
}
dmasprintf(value, "%d", cnt); // MEM WILL BE FREED IN DMMEMCLEAN
int cnt = get_number_of_entries(ctx, data, instance, browseIPv4ForwardingInst);
dmasprintf(value, "%d", cnt);
return 0;
}
/*#Device.Routing.Router.{i}.IPv6ForwardingNumberOfEntries!UCI:network/route6/*/
static int get_RoutingRouter_IPv6ForwardingNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s = NULL;
int cnt = 0;
uci_foreach_sections("network", "route6", s) {
cnt++;
}
uci_foreach_sections("network", "route6_disabled", s) {
cnt++;
}
dmmap_synchronizeRoutingRouterIPv6Forwarding(ctx, NULL, NULL, NULL);
uci_path_foreach_sections(bbfdm, "dmmap_route_forwarding", "route6_dynamic", s) {
cnt++;
}
dmasprintf(value, "%d", cnt); // MEM WILL BE FREED IN DMMEMCLEAN
int cnt = get_number_of_entries(ctx, data, instance, browseIPv6ForwardingInst);
dmasprintf(value, "%d", cnt);
return 0;
}
@ -1063,21 +1100,19 @@ struct dm_permession_s DMRouting = {"1", &get_routing_perm};
/*************************************************************
* ADD DEL OBJ
**************************************************************/
static int add_ipv4forwarding(char *refparam, struct dmctx *ctx, void *data, char **instancepara)
static int add_ipv4forwarding(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
struct uci_section *s = NULL, *dmmap_route = NULL;
char instance[16], route_name[32];
char route_name[32];
int last_inst = get_forwarding_last_inst(false);
snprintf(instance, sizeof(instance), "%d", last_inst);
snprintf(route_name, sizeof(route_name), "route_%d", (last_inst == 0) ? 1 : last_inst + 1);
snprintf(route_name, sizeof(route_name), "route_%s", *instance);
dmuci_add_section("network", "route_disabled", &s);
dmuci_rename_section_by_section(s, route_name);
dmuci_add_section_bbfdm("dmmap_route_forwarding", "route_disabled", &dmmap_route);
dmuci_set_value_by_section(dmmap_route, "section_name", route_name);
*instancepara = update_instance(instance, 2, dmmap_route, "routeinstance");
dmuci_set_value_by_section(dmmap_route, "routeinstance", *instance);
return 0;
}
@ -1120,27 +1155,24 @@ static int delete_ipv4forwarding(char *refparam, struct dmctx *ctx, void *data,
// Remove config section
dmuci_delete_by_section(route_s, NULL, NULL);
}
break;
}
return 0;
}
static int add_ipv6Forwarding(char *refparam, struct dmctx *ctx, void *data, char **instancepara)
static int add_ipv6Forwarding(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
struct uci_section *s = NULL, *dmmap_route6 = NULL;
char instance[16], route6_name[32];
char route6_name[32];
int last_inst = get_forwarding_last_inst(true);
snprintf(instance, sizeof(instance), "%d", last_inst);
snprintf(route6_name, sizeof(route6_name), "route6_%d", (last_inst == 0) ? 1 : last_inst + 1);
snprintf(route6_name, sizeof(route6_name), "route6_%s", *instance);
dmuci_add_section("network", "route6_disabled", &s);
dmuci_rename_section_by_section(s, route6_name);
dmuci_add_section_bbfdm("dmmap_route_forwarding", "route6_disabled", &dmmap_route6);
dmuci_set_value_by_section(dmmap_route6, "section_name", route6_name);
*instancepara = update_instance(instance, 2, dmmap_route6, "route6instance");
dmuci_set_value_by_section(dmmap_route6, "route6instance", *instance);
return 0;
}
@ -1183,167 +1215,14 @@ static int delete_ipv6Forwarding(char *refparam, struct dmctx *ctx, void *data,
// Remove config section
dmuci_delete_by_section(route6_s, NULL, NULL);
}
break;
}
return 0;
}
/*************************************************************
* SUB ENTRIES
**************************************************************/
static int browseRouterInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct uci_section *s = NULL;
char *inst = NULL, *max_inst = NULL;
update_section_list(DMMAP,"router", NULL, 1, NULL, NULL, NULL, NULL, NULL);
uci_path_foreach_sections(bbfdm, "dmmap", "router", s) {
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
s, "router_instance", "router_alias");
DM_LINK_INST_OBJ(dmctx, parent_node, (void *)s, inst);
break;
}
return 0;
}
/*#Device.Routing.Router.{i}.IPv4Forwarding.{i}.!UCI:network/route/dmmap_route_forwarding*/
static int browseIPv4ForwardingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *max_inst = NULL;
struct uci_section *ss = NULL;
bool find_max = true, ipv4_forwarding = true;
struct routingfwdargs curr_routefwdargs = {0};
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
// Enable Routes
synchronize_specific_config_sections_with_dmmap("network", "route", "dmmap_route_forwarding", &dup_list);
list_for_each_entry(p, &dup_list, list) {
init_args_ipv4forward(&curr_routefwdargs, p->config_section, "1", ROUTE_STATIC);
inst = handle_update_instance(2, dmctx, &max_inst, forwarding_update_instance_alias_bbfdm, 5,
p->dmmap_section, "routeinstance", "routealias", &ipv4_forwarding, &find_max);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_routefwdargs, inst) == DM_STOP)
goto end;
}
free_dmmap_config_dup_list(&dup_list);
// Disable Routes
synchronize_specific_config_sections_with_dmmap("network", "route_disabled", "dmmap_route_forwarding", &dup_list);
list_for_each_entry(p, &dup_list, list) {
init_args_ipv4forward(&curr_routefwdargs, p->config_section, "1", ROUTE_DISABLED);
inst = handle_update_instance(2, dmctx, &max_inst, forwarding_update_instance_alias_bbfdm, 5,
p->dmmap_section, "routeinstance", "routealias", &ipv4_forwarding, &find_max);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_routefwdargs, inst) == DM_STOP)
goto end;
}
free_dmmap_config_dup_list(&dup_list);
// Dynamic Routes
dmmap_synchronizeRoutingRouterIPv4Forwarding(dmctx, NULL, NULL, NULL);
uci_path_foreach_sections(bbfdm, "dmmap_route_forwarding", "route_dynamic", ss) {
init_args_ipv4forward(&curr_routefwdargs, ss, "0", ROUTE_DYNAMIC);
inst = handle_update_instance(2, dmctx, &max_inst, forwarding_update_instance_alias_bbfdm, 5,
ss, "routeinstance", "routealias", &ipv4_forwarding, &find_max);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_routefwdargs, inst) == DM_STOP)
goto end;
}
end:
return 0;
}
/*#Device.Routing.Router.{i}.IPv6Forwarding.{i}.!UCI:network/route6/dmmap_route_forwarding*/
static int browseIPv6ForwardingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *max_inst = NULL;
struct uci_section *ss = NULL;
bool find_max = true, ipv4_forwarding = false;
struct routingfwdargs curr_route6fwdargs = {0};
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
// Enable Routes
synchronize_specific_config_sections_with_dmmap("network", "route6", "dmmap_route_forwarding", &dup_list);
list_for_each_entry(p, &dup_list, list) {
init_args_ipv6forward(&curr_route6fwdargs, p->config_section, "1", ROUTE_STATIC);
inst = handle_update_instance(2, dmctx, &max_inst, forwarding_update_instance_alias_bbfdm, 5,
p->dmmap_section, "route6instance", "route6alias", &ipv4_forwarding, &find_max);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_route6fwdargs, inst) == DM_STOP)
goto end;
}
free_dmmap_config_dup_list(&dup_list);
// Disable Routes
synchronize_specific_config_sections_with_dmmap("network", "route6_disabled", "dmmap_route_forwarding", &dup_list);
list_for_each_entry(p, &dup_list, list) {
init_args_ipv6forward(&curr_route6fwdargs, p->config_section, "1", ROUTE_DISABLED);
inst = handle_update_instance(2, dmctx, &max_inst, forwarding_update_instance_alias_bbfdm, 5,
p->dmmap_section, "route6instance", "route6alias", &ipv4_forwarding, &find_max);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_route6fwdargs, inst) == DM_STOP)
goto end;
}
free_dmmap_config_dup_list(&dup_list);
// Dynamic Routes
dmmap_synchronizeRoutingRouterIPv6Forwarding(dmctx, NULL, NULL, NULL);
uci_path_foreach_sections(bbfdm, "dmmap_route_forwarding", "route6_dynamic", ss) {
init_args_ipv6forward(&curr_route6fwdargs, ss, "0", ROUTE_DYNAMIC);
inst = handle_update_instance(2, dmctx, &max_inst, forwarding_update_instance_alias_bbfdm, 5,
ss, "route6instance", "route6alias", &ipv4_forwarding, &find_max);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_route6fwdargs, inst) == DM_STOP)
goto end;
}
end:
return 0;
}
static int browseRoutingRouteInformationInterfaceSettingInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct uci_section *s = NULL;
char *inst = NULL, *max_inst = NULL;
int id = 0, i = 0;
uci_foreach_sections("network", "interface", s) {
char *proto = NULL, *ip6addr = NULL;
dmuci_get_value_by_section_string(s, "proto", &proto);
dmuci_get_value_by_section_string(s, "ip6addr", &ip6addr);
if ((proto && strcmp(proto, "dhcpv6") == 0) || (ip6addr && ip6addr[0] != '\0')) {
json_object *res = NULL, *route_obj = NULL, *arrobj = NULL;
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(s), String}}, 1, &res);
dmjson_foreach_obj_in_array(res, arrobj, route_obj, i, 1, "route") {
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_without_section, 1, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)route_obj, inst) == DM_STOP)
break;
}
}
}
return 0;
}
/**********************************************************************************************************************************
* OBJ & PARAM DEFINITION
***********************************************************************************************************************************/
/* *** Device.Routing. *** */
DMOBJ tRoutingObj[] = {
/* OBJ, permission, addobj, delobj, checkdep, browseinstobj, nextdynamicobj, dynamicleaf, nextobj, leaf, linker, bbfdm_type, uniqueKeys*/

View file

@ -223,7 +223,7 @@ static void get_certificate_paths(void)
static int browseSecurityCertificateInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
#if defined(LOPENSSL) || defined(LMBEDTLS)
char *inst = NULL, *max_inst = NULL;
char *inst = NULL;
struct uci_section *dmmap_sect = NULL;
struct certificate_profile certificateprofile = {};
@ -248,8 +248,7 @@ static int browseSecurityCertificateInst(struct dmctx *dmctx, DMNODE *parent_nod
}
init_certificate(certifcates_paths[i], cert, dmmap_sect, &certificateprofile);
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
dmmap_sect, "security_certificate_instance", "security_certificate_alias");
inst = handle_instance(dmctx, parent_node, dmmap_sect, "security_certificate_instance", "security_certificate_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&certificateprofile, inst) == DM_STOP)
break;
@ -271,8 +270,7 @@ static int browseSecurityCertificateInst(struct dmctx *dmctx, DMNODE *parent_nod
}
init_certificate(certifcates_paths[i], cacert, dmmap_sect, &certificateprofile);
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
dmmap_sect, "security_certificate_instance", "security_certificate_alias");
inst = handle_instance(dmctx, parent_node, dmmap_sect, "security_certificate_instance", "security_certificate_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&certificateprofile, inst) == DM_STOP)
break;
@ -287,41 +285,8 @@ static int browseSecurityCertificateInst(struct dmctx *dmctx, DMNODE *parent_nod
**************************************************************/
static int get_Security_CertificateNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
int number = 0;
#if defined(LOPENSSL) || defined(LMBEDTLS)
get_certificate_paths();
int i;
for (i=0; i < MAX_CERT; i++) {
if(!strlen(certifcates_paths[i]))
break;
#ifdef LOPENSSL
FILE *fp = fopen(certifcates_paths[i], "r");
if (fp == NULL)
continue;
X509 *cert = PEM_read_X509(fp, NULL, NULL, NULL);
if (!cert) {
fclose(fp);
continue;
}
number++;
X509_free(cert);
cert = NULL;
fclose(fp);
fp = NULL;
#elif LMBEDTLS
mbedtls_x509_crt cacert;
mbedtls_x509_crt_init( &cacert );
int ret = mbedtls_x509_crt_parse_file( &cacert, certifcates_paths[i]);
if (ret < 0)
continue;
number++;
#endif
}
#endif
dmasprintf(value, "%d", number);
int cnt = get_number_of_entries(ctx, data, instance, browseSecurityCertificateInst);
dmasprintf(value, "%d", cnt);
return 0;
}
@ -441,6 +406,9 @@ static int get_SecurityCertificate_SignatureAlgorithm(char *refparam, struct dmc
return 0;
}
/**********************************************************************************************************************************
* OBJ & PARAM DEFINITION
***********************************************************************************************************************************/
/* *** Device.Security. *** */
DMOBJ tSecurityObj[] = {
/* OBJ, permission, addobj, delobj, checkdep, browseinstobj, nextdynamicobj, dynamicleaf, nextobj, leaf, linker, bbfdm_type, uniqueKeys*/

View file

@ -9,9 +9,11 @@
*
*/
#include "dmentry.h"
#include "times.h"
/*************************************************************
* GET & SET PARAM
**************************************************************/
static int get_time_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *path = "/etc/rc.d/*ntpd";
@ -207,6 +209,9 @@ static int set_time_ntpserver5(char *refparam, struct dmctx *ctx, void *data, ch
return set_time_ntpserver(refparam, ctx, action, value, 5);
}
/**********************************************************************************************************************************
* OBJ & LEAF DEFINITION
***********************************************************************************************************************************/
/* *** Device.Time. *** */
DMLEAF tTimeParams[] = {
/* PARAM, permission, type, getvalue, setvalue, bbfdm_type*/

View file

@ -100,7 +100,7 @@ static int browseUPnPDiscoveryRootDeviceInst(struct dmctx *dmctx, DMNODE *parent
{
json_object *res = NULL, *devices = NULL, *device = NULL;
struct upnpdiscovery upnp_dev = {};
char *descurl = NULL, *st = NULL, *usn = NULL, *is_root_device = NULL, *inst = NULL, *max_inst = NULL;
char *descurl = NULL, *st = NULL, *usn = NULL, *is_root_device = NULL, *inst = NULL;
char **stparams = NULL, **uuid, **urn;
size_t length;
struct uci_section* dmmap_sect = NULL;
@ -137,11 +137,10 @@ static int browseUPnPDiscoveryRootDeviceInst(struct dmctx *dmctx, DMNODE *parent
upnp_dev.dmmap_sect = dmmap_sect;
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
dmmap_sect, "upnp_root_device_instance", "upnp_root_device_alias");
inst = handle_instance_without_section(dmctx, parent_node, i+1);
if (DM_LINK_INST_OBJ(dmctx, parent_node, &upnp_dev, inst) == DM_STOP)
return 0;
break;
}
return 0;
}
@ -150,7 +149,7 @@ static int browseUPnPDiscoveryDeviceInst(struct dmctx *dmctx, DMNODE *parent_nod
{
json_object *res = NULL, *devices = NULL, *device = NULL;
struct upnpdiscovery upnp_dev = {};
char *dev_descurl = NULL, *dev_st = NULL, *dev_usn = NULL, *inst = NULL, *max_inst = NULL;
char *dev_descurl = NULL, *dev_st = NULL, *dev_usn = NULL, *inst = NULL;
char **stparams = NULL, **uuid = NULL, **urn = NULL;
size_t lengthuuid, lengthurn;
struct uci_section* dmmap_sect = NULL;
@ -183,11 +182,10 @@ static int browseUPnPDiscoveryDeviceInst(struct dmctx *dmctx, DMNODE *parent_nod
upnp_dev.dmmap_sect = dmmap_sect;
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
dmmap_sect, "upnp_evice_instance", "upnp_device_alias");
inst = handle_instance_without_section(dmctx, parent_node, i+1);
if (DM_LINK_INST_OBJ(dmctx, parent_node, &upnp_dev, inst) == DM_STOP)
return 0;
break;
}
return 0;
}
@ -196,7 +194,7 @@ static int browseUPnPDiscoveryServiceInst(struct dmctx *dmctx, DMNODE *parent_no
{
json_object *res = NULL, *services = NULL, *service = NULL;
struct upnpdiscovery upnp_dev = {};
char *srv_descurl = NULL, *srv_st = NULL, *srv_usn = NULL, *inst = NULL, *max_inst = NULL;
char *srv_descurl = NULL, *srv_st = NULL, *srv_usn = NULL, *inst = NULL;
char **stparams = NULL, **uuid = NULL, **urn = NULL;
size_t lengthuuid, lengthurn;
struct uci_section* dmmap_sect = NULL;
@ -229,11 +227,10 @@ static int browseUPnPDiscoveryServiceInst(struct dmctx *dmctx, DMNODE *parent_no
upnp_dev.dmmap_sect = dmmap_sect;
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
dmmap_sect, "upnp_service_instance", "upnp_service_alias");
inst = handle_instance_without_section(dmctx, parent_node, i+1);
if (DM_LINK_INST_OBJ(dmctx, parent_node, &upnp_dev, inst) == DM_STOP)
return 0;
break;
}
return 0;
}
@ -242,7 +239,7 @@ static int browseUPnPDescriptionDeviceDescriptionInst(struct dmctx *dmctx, DMNOD
{
json_object *res = NULL, *descriptions = NULL, *description = NULL;
struct upnp_description_file_info upnp_desc = {};
char *descurl = NULL, *inst = NULL, *max_inst = NULL;
char *descurl = NULL, *inst = NULL;
struct uci_section* dmmap_sect = NULL;
int i;
@ -263,11 +260,10 @@ static int browseUPnPDescriptionDeviceDescriptionInst(struct dmctx *dmctx, DMNOD
}
upnp_desc.dmmap_sect = dmmap_sect;
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
dmmap_sect, "upnp_service_instance", "upnp_service_alias");
inst = handle_instance_without_section(dmctx, parent_node, i+1);
if (DM_LINK_INST_OBJ(dmctx, parent_node, &upnp_desc, inst) == DM_STOP)
return 0;
break;
}
return 0;
}
@ -276,7 +272,7 @@ static int browseUPnPDescriptionDeviceInstanceInst(struct dmctx *dmctx, DMNODE *
{
json_object *res = NULL, *devices_instances = NULL, *device_inst = NULL;
struct upnp_device_inst upnp_dev_inst = {};
char *inst = NULL, *max_inst = NULL;
char *inst = NULL;
struct uci_section* dmmap_sect = NULL;
int i;
@ -308,11 +304,10 @@ static int browseUPnPDescriptionDeviceInstanceInst(struct dmctx *dmctx, DMNODE *
upnp_dev_inst.dmmap_sect = dmmap_sect;
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
dmmap_sect, "upnp_device_inst_instance", "upnp_device_inst_alias");
inst = handle_instance_without_section(dmctx, parent_node, i+1);
if (DM_LINK_INST_OBJ(dmctx, parent_node, &upnp_dev_inst, inst) == DM_STOP)
return 0;
break;
}
return 0;
}
@ -321,7 +316,7 @@ static int browseUPnPDescriptionServiceInstanceInst(struct dmctx *dmctx, DMNODE
{
json_object *res = NULL, *services_instances = NULL, *service_inst = NULL;
struct upnp_service_inst upnp_services_inst = {};
char *inst = NULL, *max_inst = NULL;
char *inst = NULL;
struct uci_section* dmmap_sect = NULL;
int i;
@ -347,11 +342,10 @@ static int browseUPnPDescriptionServiceInstanceInst(struct dmctx *dmctx, DMNODE
upnp_services_inst.dmmap_sect = dmmap_sect;
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
dmmap_sect, "upnp_service_inst_instance", "upnp_service_inst_alias");
inst = handle_instance_without_section(dmctx, parent_node, i+1);
if (DM_LINK_INST_OBJ(dmctx, parent_node, &upnp_services_inst, inst) == DM_STOP)
return 0;
break;
}
return 0;
}
@ -432,68 +426,22 @@ static int set_UPnPDevice_UPnPIGD(char *refparam, struct dmctx *ctx, void *data,
static int get_UPnPDiscovery_RootDeviceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
int nbre = 0;
char *is_root_device = NULL;
json_object *res = NULL, *devices = NULL, *device = NULL;
*value = "0";
dmubus_call("upnpc", "discovery", UBUS_ARGS{{}}, 0, &res);
if (res == NULL)
return 0;
json_object_object_get_ex(res, "devices", &devices);
if (devices == NULL)
return 0;
size_t nbre_devices = json_object_array_length(devices);
if (nbre_devices > 0) {
int i;
for (i = 0; i < nbre_devices; i++){
device = json_object_array_get_idx(devices, i);
is_root_device = dmjson_get_value(device, 1, "is_root_device");
if(strcmp(is_root_device, "0") == 0)
continue;
nbre ++;
}
}
dmasprintf(value, "%d", nbre);
int cnt = get_number_of_entries(ctx, data, instance, browseUPnPDiscoveryRootDeviceInst);
dmasprintf(value, "%d", cnt);
return 0;
}
static int get_UPnPDiscovery_DeviceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res = NULL, *devices;
*value = "0";
dmubus_call("upnpc", "discovery", UBUS_ARGS{{}}, 0, &res);
if (res == NULL)
return 0;
json_object_object_get_ex(res, "devices", &devices);
if (devices == NULL)
return 0;
size_t nbre_devices = json_object_array_length(devices);
dmasprintf(value, "%d", nbre_devices);
int cnt = get_number_of_entries(ctx, data, instance, browseUPnPDiscoveryDeviceInst);
dmasprintf(value, "%d", cnt);
return 0;
}
static int get_UPnPDiscovery_ServiceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res = NULL, *services;
*value = "0";
dmubus_call("upnpc", "discovery", UBUS_ARGS{{}}, 0, &res);
if (res == NULL)
return 0;
json_object_object_get_ex(res, "services", &services);
if (services == NULL)
return 0;
size_t nbre_services = json_object_array_length(services);
dmasprintf(value, "%d", nbre_services);
int cnt = get_number_of_entries(ctx, data, instance, browseUPnPDiscoveryServiceInst);
dmasprintf(value, "%d", cnt);
return 0;
}
@ -565,55 +513,22 @@ static int get_UPnPDiscoveryService_ParentDevice(char *refparam, struct dmctx *c
static int get_UPnPDescription_DeviceDescriptionNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res = NULL, *descriptions;
*value = "0";
dmubus_call("upnpc", "description", UBUS_ARGS{{}}, 0, &res);
if (res == NULL)
return 0;
json_object_object_get_ex(res, "descriptions", &descriptions);
if (descriptions == NULL)
return 0;
size_t nbre_descriptions = json_object_array_length(descriptions);
dmasprintf(value, "%d", nbre_descriptions);
int cnt = get_number_of_entries(ctx, data, instance, browseUPnPDescriptionDeviceDescriptionInst);
dmasprintf(value, "%d", cnt);
return 0;
}
static int get_UPnPDescription_DeviceInstanceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res = NULL, *devicesinstances;
*value = "0";
dmubus_call("upnpc", "description", UBUS_ARGS{{}}, 0, &res);
if (res == NULL)
return 0;
json_object_object_get_ex(res, "devicesinstances", &devicesinstances);
if (devicesinstances == NULL)
return 0;
size_t nbre_devinstances = json_object_array_length(devicesinstances);
dmasprintf(value, "%d", nbre_devinstances);
int cnt = get_number_of_entries(ctx, data, instance, browseUPnPDescriptionDeviceInstanceInst);
dmasprintf(value, "%d", cnt);
return 0;
}
static int get_UPnPDescription_ServiceInstanceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
json_object *res = NULL, *servicesinstances;
*value = "0";
dmubus_call("upnpc", "description", UBUS_ARGS{{}}, 0, &res);
if (res == NULL)
return 0;
json_object_object_get_ex(res, "servicesinstances", &servicesinstances);
if (servicesinstances == NULL)
return 0;
size_t nbre_servinstances = json_object_array_length(servicesinstances);
dmasprintf(value, "%d", nbre_servinstances);
int cnt = get_number_of_entries(ctx, data, instance, browseUPnPDescriptionServiceInstanceInst);
dmasprintf(value, "%d", cnt);
return 0;
}
@ -789,6 +704,9 @@ static int get_UPnPDescriptionServiceInstance_EventSubURL(char *refparam, struct
return 0;
}
/**********************************************************************************************************************************
* OBJ & LEAF DEFINITION
***********************************************************************************************************************************/
/* *** Device.UPnP. *** */
DMOBJ tUPnPObj[] = {
/* OBJ, permission, addobj, delobj, checkdep, browseinstobj, nextdynamicobj, dynamicleaf, nextobj, leaf, linker, bbfdm_type, uniqueKeys*/

View file

@ -115,25 +115,27 @@ static void writeFileContent(const char *filepath, const char *data)
}
}
/*************************************************************
* ENTRY METHOD
**************************************************************/
static int browseUSBInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
DIR *dir = NULL;
struct dirent *ent = NULL;
char *iface_path, *statistics_path, *max_inst = NULL, *inst = NULL;
char *inst = NULL;
size_t length;
char **foldersplit;
struct usb_interface iface= {};
struct usb_interface iface = {0};
LIST_HEAD(dup_list);
struct sysfs_dmsection *p = NULL;
synchronize_system_folders_with_dmmap_opt(SYSFS_USB_DEVICES_PATH, "dmmap_usb", "dmmap_interface", "usb_iface_link", "usb_iface_instance", &dup_list);
list_for_each_entry(p, &dup_list, list) {
char netfolderpath[256];
char port_link[128];
char iface_name[260];
port_link[0] = 0;
iface_name[0] = 0;
char statistics_path[652] = {0};
char iface_path[620] = {0};
char netfolderpath[256] = {0};
char iface_name[260] = {0};
char port_link[128] = {0};
snprintf(netfolderpath, sizeof(netfolderpath), "%s/%s/net", SYSFS_USB_DEVICES_PATH, p->sysfs_folder_name);
if (!folder_exists(netfolderpath))
@ -153,15 +155,14 @@ static int browseUSBInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void
if (dir)
closedir(dir);
dmasprintf(&iface_path, "%s/%s", netfolderpath, iface_name);
snprintf(iface_path, sizeof(iface_path), "%s/%s", netfolderpath, iface_name);
if (p->dmmap_section)
dmuci_set_value_by_section_bbfdm(p->dmmap_section, "usb_iface_path", iface_path);
dmasprintf(&statistics_path, "%s/statistics", iface_path);
snprintf(statistics_path, sizeof(statistics_path), "%s/statistics", iface_path);
init_usb_interface(p->dmmap_section, iface_name, iface_path, statistics_path, port_link, &iface);
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
p->dmmap_section, "usb_iface_instance", "usb_iface_alias");
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "usb_iface_instance", "usb_iface_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, &iface, inst) == DM_STOP)
break;
@ -172,7 +173,7 @@ static int browseUSBInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void
static int browseUSBPortInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *max_inst = NULL, *inst = NULL;
char *inst = NULL;
struct usb_port port = {0};
struct sysfs_dmsection *p = NULL;
LIST_HEAD(dup_list);
@ -183,20 +184,16 @@ static int browseUSBPortInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
regcomp(&regex2, "^[0-9][0-9]*-[0-9]*[0-9]\\.[0-9]*[0-9]$", 0);
synchronize_system_folders_with_dmmap_opt(SYSFS_USB_DEVICES_PATH, "dmmap_usb", "dmmap_port", "port_link", "usb_port_instance", &dup_list);
list_for_each_entry(p, &dup_list, list) {
if (regexec(&regex1, p->sysfs_folder_name, 0, NULL, 0) != 0 &&
regexec(&regex2, p->sysfs_folder_name, 0, NULL, 0) !=0 &&
strstr(p->sysfs_folder_name, "usb") != p->sysfs_folder_name) {
dmuci_delete_by_section_unnamed_bbfdm(p->dmmap_section, NULL, NULL);
strstr(p->sysfs_folder_name, "usb") != p->sysfs_folder_name)
continue;
}
init_usb_port(p->dmmap_section, p->sysfs_folder_name, p->sysfs_folder_path, &port);
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
p->dmmap_section, "usb_port_instance", "usb_port_alias");
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "usb_port_instance", "usb_port_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, &port, inst) == DM_STOP)
break;
@ -210,21 +207,21 @@ static int browseUSBPortInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre
static int browseUSBUSBHostsHostInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct sysfs_dmsection *p = NULL;
char *inst = NULL, *max_inst = NULL;
char *inst = NULL;
struct usb_port port = {0};
LIST_HEAD(dup_list);
synchronize_system_folders_with_dmmap_opt(SYSFS_USB_DEVICES_PATH, "dmmap_usb", "dmmap_host", "port_link", "usb_host_instance", &dup_list);
list_for_each_entry(p, &dup_list, list) {
if(!strstr(p->sysfs_folder_name, "usb"))
continue;
init_usb_port(p->dmmap_section, p->sysfs_folder_name, p->sysfs_folder_path, &port);
port.dmsect= p->dmmap_section;
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
p->dmmap_section, "usb_host_instance", "usb_host_alias");
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "usb_host_instance", "usb_host_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, &port, inst) == DM_STOP)
break;
@ -299,7 +296,7 @@ static int synchronize_usb_devices_with_dmmap_opt_recursively(char *sysfsrep, ch
uci_path_foreach_sections_safe(bbfdm, dmmap_package, dmmap_section, stmp, s) {
dmuci_get_value_by_section_string(s, opt_name, &v);
if (!folder_exists(v)) {
dmuci_delete_by_section_unnamed_bbfdm(s, NULL, NULL);
dmuci_delete_by_section(s, NULL, NULL);
}
}
}
@ -309,7 +306,7 @@ static int synchronize_usb_devices_with_dmmap_opt_recursively(char *sysfsrep, ch
static int browseUSBUSBHostsHostDeviceInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
struct sysfs_dmsection *p = NULL;
char *instance = NULL, *instnbr = NULL, *parent_host_instance = NULL;
char *inst = NULL, *parent_host_instance = NULL;
struct usb_port port= {};
struct usb_port *prev_port = (struct usb_port *)prev_data;
LIST_HEAD(dup_list);
@ -329,10 +326,9 @@ static int browseUSBUSBHostsHostDeviceInst(struct dmctx *dmctx, DMNODE *parent_n
port.dmsect = prev_port->dmsect;
instance = handle_update_instance(2, dmctx, &instnbr, update_instance_alias, 3,
p->dmmap_section, "usb_host_device_instance", "usb_host_device_alias");
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "usb_host_device_instance", "usb_host_device_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, &port, instance) == DM_STOP)
if (DM_LINK_INST_OBJ(dmctx, parent_node, &port, inst) == DM_STOP)
break;
}
free_dmmap_config_dup_list(&dup_list);
@ -344,7 +340,7 @@ static int browseUSBUSBHostsHostDeviceConfigurationInst(struct dmctx *dmctx, DMN
const struct usb_port *usb_dev = prev_data;
struct usb_port port = {};
struct uci_section *s = NULL;
char nbre[16], *max_inst = NULL;
char nbre[16];
__read_sysfs_usb_port(usb_dev, "bNumConfigurations", nbre, sizeof(nbre));
if(nbre[0] == '0')
@ -357,8 +353,7 @@ static int browseUSBUSBHostsHostDeviceConfigurationInst(struct dmctx *dmctx, DMN
init_usb_port(s, usb_dev->folder_name, usb_dev->folder_path, &port);
handle_update_instance(3, dmctx, &max_inst, update_instance_alias, 3,
s, "usb_device_conf_instance", "usb_device_conf_alias");
handle_instance(dmctx, parent_node, s, "usb_device_conf_instance", "usb_device_conf_alias");
DM_LINK_INST_OBJ(dmctx, parent_node, &port, "1");
return 0;
@ -370,7 +365,7 @@ static int browseUSBUSBHostsHostDeviceConfigurationInterfaceInst(struct dmctx *d
struct dirent *ent = NULL;
struct usb_port *usb_dev = (struct usb_port*)prev_data;
struct usb_port port = {0};
char *sysfs_rep_path, *inst = NULL, *max_inst = NULL;
char *sysfs_rep_path, *inst = NULL;
struct uci_section *dmmap_sect = NULL;
regex_t regex1 = {};
regex_t regex2 = {};
@ -392,8 +387,7 @@ static int browseUSBUSBHostsHostDeviceConfigurationInterfaceInst(struct dmctx *d
init_usb_port(dmmap_sect, ent->d_name, sysfs_rep_path, &port);
inst = handle_update_instance(4, dmctx, &max_inst, update_instance_alias, 3,
dmmap_sect, "usb_device_conf_iface_instance", "usb_device_conf_iface_alias");
inst = handle_instance(dmctx, parent_node, dmmap_sect, "usb_device_conf_iface_instance", "usb_device_conf_iface_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, &port, inst) == DM_STOP)
break;
@ -411,48 +405,15 @@ static int browseUSBUSBHostsHostDeviceConfigurationInterfaceInst(struct dmctx *d
**************************************************************/
static int get_USB_InterfaceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
DIR *dir = NULL;
struct dirent *ent = NULL;
int nbre = 0;
sysfs_foreach_file(SYSFS_USB_DEVICES_PATH, dir, ent) {
char netfolderpath[512] = {0};
if (*(ent->d_name) == '.')
continue;
snprintf(netfolderpath, sizeof(netfolderpath), "%s/%s/net", SYSFS_USB_DEVICES_PATH, ent->d_name);
if (folder_exists(netfolderpath))
nbre++;
}
closedir(dir);
dmasprintf(value, "%d", nbre);
int cnt = get_number_of_entries(ctx, data, instance, browseUSBInterfaceInst);
dmasprintf(value, "%d", cnt);
return 0;
}
static int get_USB_PortNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
DIR *dir = NULL;
struct dirent *ent = NULL;
int nbre = 0;
regex_t regex1 = {};
regex_t regex2 = {};
regcomp(&regex1, "^[0-9][0-9]*-[0-9]*[0-9]$", 0);
regcomp(&regex2, "^[0-9][0-9]*-[0-9]*[0-9]\\.[0-9]*[0-9]$", 0);
sysfs_foreach_file(SYSFS_USB_DEVICES_PATH, dir, ent) {
if(regexec(&regex1, ent->d_name, 0, NULL, 0) == 0 || regexec(&regex2, ent->d_name, 0, NULL, 0) ==0 || strstr(ent->d_name, "usb") == ent->d_name)
nbre++;
}
if (dir)
closedir(dir);
regfree(&regex1);
regfree(&regex2);
dmasprintf(value, "%d", nbre);
int cnt = get_number_of_entries(ctx, data, instance, browseUSBPortInst);
dmasprintf(value, "%d", cnt);
return 0;
}
@ -693,16 +654,8 @@ static int get_USBPort_Power(char *refparam, struct dmctx *ctx, void *data, char
static int get_USBUSBHosts_HostNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
DIR *dir = NULL;
struct dirent *ent = NULL;
int nbre= 0;
sysfs_foreach_file(SYSFS_USB_DEVICES_PATH, dir, ent) {
if(strstr(ent->d_name, "usb") == ent->d_name)
nbre++;
}
if (dir) closedir(dir);
dmasprintf(value, "%d", nbre);
int cnt = get_number_of_entries(ctx, data, instance, browseUSBUSBHostsHostInst);
dmasprintf(value, "%d", cnt);
return 0;
}
@ -835,58 +788,20 @@ static int get_USBUSBHostsHost_USBVersion(char *refparam, struct dmctx *ctx, voi
return 0;
}
static int get_number_devices(char *folderpath, int *nbre)
{
DIR *dir = NULL;
struct dirent *ent = NULL;
regex_t regex1 = {};
regex_t regex2 = {};
regcomp(&regex1, "^[0-9][0-9]*-[0-9]*[0-9]$", 0);
regcomp(&regex2, "^[0-9][0-9]*-[0-9]*[0-9]\\.[0-9]*[0-9]$", 0);
sysfs_foreach_file(folderpath, dir, ent) {
if (regexec(&regex1, ent->d_name, 0, NULL, 0) == 0 || regexec(&regex2, ent->d_name, 0, NULL, 0) == 0) {
char deviceClassFile[270];
char deviceClass[16];
snprintf(deviceClassFile, sizeof(deviceClassFile), "%s/%s/bDeviceClass", folderpath, ent->d_name);
dm_read_sysfs_file(deviceClassFile, deviceClass, sizeof(deviceClass));
if(strncmp(deviceClass, "09", 2) == 0){
char hubpath[260];
snprintf(hubpath, sizeof(hubpath), "%s/%s", folderpath, ent->d_name);
get_number_devices(hubpath, nbre);
}
(*nbre)++;
}
}
if (dir)
closedir(dir);
regfree(&regex1);
regfree(&regex2);
return 0;
}
static int get_USBUSBHostsHost_DeviceNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct usb_port* usb_host= (struct usb_port *) data;
int dev_nbre= 0;
get_number_devices(usb_host->folder_path, &dev_nbre);
dmasprintf(value, "%d", dev_nbre);
int cnt = get_number_of_entries(ctx, data, instance, browseUSBUSBHostsHostDeviceInst);
dmasprintf(value, "%d", cnt);
return 0;
}
static int get_USBUSBHostsHostDevice_DeviceNumber(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct usb_port *usbdev= (struct usb_port *)data;
struct usb_port *usbdev = (struct usb_port *)data;
size_t length;
char **filename= strsplit(usbdev->folder_name, "-", &length);
char **port= strsplit(filename[1], ".", &length);
char **filename = strsplit(usbdev->folder_name, "-", &length);
char **port = strsplit(filename[1], ".", &length);
dmasprintf(value ,"%s", port[0]);
return 0;
}
@ -1087,6 +1002,9 @@ static int get_linker_usb_host_device(char *refparam, struct dmctx *dmctx, void
}
}
/**********************************************************************************************************************************
* OBJ & PARAM DEFINITION
***********************************************************************************************************************************/
/* *** Device.USB. *** */
DMOBJ tUSBObj[] = {
/* OBJ, permission, addobj, delobj, checkdep, browseinstobj, nextdynamicobj, dynamicleaf, nextobj, leaf, linker, bbfdm_type, uniqueKeys*/

View file

@ -5,103 +5,85 @@
* it under the terms of the GNU Lesser General Public License version 2.1
* as published by the Free Software Foundation
*
*
* Author: Omar Kallel <omar.kallel@pivasoftware.com>
* Author: Amin Ben Ramdhane <amin.benramdhane@pivasoftware.com>
*/
#include "users.h"
/***************************** Browse Functions ***********************************/
/*************************************************************
* ENTRY METHOD
**************************************************************/
/*#Device.Users.User.{i}.!UCI:users/user/dmmap_users*/
static int browseUserInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *max_inst = NULL;
char *inst = NULL;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("users", "user", "dmmap_users", &dup_list);
list_for_each_entry(p, &dup_list, list) {
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
p->dmmap_section, "user_instance", "user_alias");
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "user_instance", "user_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, inst) == DM_STOP)
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p, inst) == DM_STOP)
break;
}
free_dmmap_config_dup_list(&dup_list);
return 0;
}
/*************************************************************
* ADD & DEL OBJ
**************************************************************/
static int add_users_user(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
struct uci_section *s = NULL, *dmmap_user = NULL;
char username[32];
char sec_name[32];
char *last_inst = get_last_instance_bbfdm("dmmap_users", "user", "user_instance");
snprintf(username, sizeof(username), "user_%d", last_inst ? atoi(last_inst) + 1 : 1);
snprintf(sec_name, sizeof(sec_name), "user_%s", *instance);
dmuci_add_section("users", "user", &s);
dmuci_rename_section_by_section(s, username);
dmuci_rename_section_by_section(s, sec_name);
dmuci_set_value_by_section(s, "enabled", "0");
dmuci_set_value_by_section(s, "remote_access", "0");
dmuci_add_section_bbfdm("dmmap_users", "user", &dmmap_user);
dmuci_set_value_by_section(dmmap_user, "section_name", username);
*instance = update_instance(last_inst, 2, dmmap_user, "user_instance");
dmuci_set_value_by_section(dmmap_user, "section_name", sec_name);
dmuci_set_value_by_section(dmmap_user, "user_instance", *instance);
return 0;
}
static int delete_users_user(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
struct uci_section *s = NULL, *ss = NULL, *dmmap_section = NULL;
int found = 0;
struct uci_section *s = NULL, *stmp = NULL;
switch (del_action) {
case DEL_INST:
if (is_section_unnamed(section_name((struct uci_section *)data))) {
LIST_HEAD(dup_list);
delete_sections_save_next_sections("dmmap_users", "user", "user_instance", section_name((struct uci_section *)data), atoi(instance), &dup_list);
update_dmmap_sections(&dup_list, "user_instance", "dmmap_users", "user");
dmuci_delete_by_section_unnamed((struct uci_section *)data, NULL, NULL);
} else {
get_dmmap_section_of_config_section("dmmap_users", "user", section_name((struct uci_section *)data), &dmmap_section);
if (dmmap_section)
dmuci_delete_by_section_unnamed_bbfdm(dmmap_section, NULL, NULL);
dmuci_delete_by_section((struct uci_section *)data, NULL, NULL);
}
dmuci_delete_by_section(((struct dmmap_dup *)data)->config_section, NULL, NULL);
dmuci_delete_by_section(((struct dmmap_dup *)data)->dmmap_section, NULL, NULL);
break;
case DEL_ALL:
uci_foreach_sections("users", "user", s) {
if (found != 0) {
get_dmmap_section_of_config_section("dmmap_users", "user", section_name(ss), &dmmap_section);
if (dmmap_section)
uci_foreach_sections_safe("users", "user", stmp, s) {
struct uci_section *dmmap_section = NULL;
get_dmmap_section_of_config_section("dmmap_users", "user", section_name(s), &dmmap_section);
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
ss = s;
found++;
}
if (ss != NULL) {
get_dmmap_section_of_config_section("dmmap_users", "user", section_name(ss), &dmmap_section);
if (dmmap_section)
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
dmuci_delete_by_section(s, NULL, NULL);
}
break;
}
return 0;
}
/***************************************** Set/Get Parameter functions ***********************/
/*************************************************************
* GET & SET PARAM
**************************************************************/
/*#Device.Users.UserNumberOfEntries!UCI:users/user/*/
static int get_users_user_number_of_entries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s = NULL;
int cnt = 0;
uci_foreach_sections("users", "user", s) {
cnt++;
}
int cnt = get_number_of_entries(ctx, data, instance, browseUserInst);
dmasprintf(value, "%d", cnt);
return 0;
}
@ -109,10 +91,7 @@ static int get_users_user_number_of_entries(char *refparam, struct dmctx *ctx, v
/*#Device.Users.User.{i}.Alias!UCI:dmmap_users/user,@i-1/user_alias*/
static int get_user_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *dmmap_section = NULL;
get_dmmap_section_of_config_section("dmmap_users", "user", section_name((struct uci_section *)data), &dmmap_section);
dmuci_get_value_by_section_string(dmmap_section, "user_alias", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->dmmap_section, "user_alias", value);
if ((*value)[0] == '\0')
dmasprintf(value, "cpe-%s", instance);
return 0;
@ -121,13 +100,13 @@ static int get_user_alias(char *refparam, struct dmctx *ctx, void *data, char *i
/*#Device.Users.User.{i}.Enable!UCI:users/user,@i-1/enabled*/
static int get_user_enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "enabled", "1");
*value = dmuci_get_value_by_section_fallback_def(((struct dmmap_dup *)data)->config_section, "enabled", "1");
return 0;
}
static int get_user_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmstrdup(section_name((struct uci_section *)data));
*value = dmstrdup(section_name(((struct dmmap_dup *)data)->config_section));
return 0;
}
@ -141,29 +120,26 @@ static int get_user_password(char *refparam, struct dmctx *ctx, void *data, char
/*#Device.Users.User.{i}.RemoteAccessCapable!UCI:users/user,@i-1/remote_access*/
static int get_user_remote_accessable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "remote_access", "1");
*value = dmuci_get_value_by_section_fallback_def(((struct dmmap_dup *)data)->config_section, "remote_access", "1");
return 0;
}
/*#Device.Users.User.{i}.Language!UCI:users/user,@i-1/language*/
static int get_user_language(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string((struct uci_section *)data, "language", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "language", value);
return 0;
}
static int set_user_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *dmmap_section = NULL;
switch (action) {
case VALUECHECK:
if (dm_validate_string(value, -1, 64, NULL, NULL))
return FAULT_9007;
break;
case VALUESET:
get_dmmap_section_of_config_section("dmmap_users", "user", section_name((struct uci_section *)data), &dmmap_section);
dmuci_set_value_by_section(dmmap_section, "user_alias", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->dmmap_section, "user_alias", value);
return 0;
}
return 0;
@ -179,7 +155,7 @@ static int set_user_enable(char *refparam, struct dmctx *ctx, void *data, char *
break;
case VALUESET:
string_to_bool(value, &b);
dmuci_set_value_by_section((struct uci_section *)data, "enabled", b ? "1" : "0");
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "enabled", b ? "1" : "0");
break;
}
return 0;
@ -187,8 +163,6 @@ static int set_user_enable(char *refparam, struct dmctx *ctx, void *data, char *
static int set_user_username(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *dmmap_section = NULL;
switch (action) {
case VALUECHECK:
if (dm_validate_string(value, -1, 64, NULL, NULL))
@ -200,11 +174,10 @@ static int set_user_username(char *refparam, struct dmctx *ctx, void *data, char
break;
case VALUESET:
// Update dmmap_users file
get_dmmap_section_of_config_section("dmmap_users", "user", section_name((struct uci_section *)data), &dmmap_section);
dmuci_set_value_by_section(dmmap_section, "section_name", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->dmmap_section, "section_name", value);
// Update users config
dmuci_rename_section_by_section((struct uci_section *)data, value);
dmuci_rename_section_by_section(((struct dmmap_dup *)data)->config_section, value);
break;
}
return 0;
@ -218,7 +191,7 @@ static int set_user_password(char *refparam, struct dmctx *ctx, void *data, char
return FAULT_9007;
break;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "password", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "password", value);
break;
}
return 0;
@ -234,7 +207,7 @@ static int set_user_remote_accessable(char *refparam, struct dmctx *ctx, void *d
break;
case VALUESET:
string_to_bool(value, &b);
dmuci_set_value_by_section((struct uci_section *)data, "remote_access", b ? "1" : "0");
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "remote_access", b ? "1" : "0");
break;
}
return 0;
@ -248,12 +221,15 @@ static int set_user_language(char *refparam, struct dmctx *ctx, void *data, char
return FAULT_9007;
break;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "language", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "language", value);
break;
}
return 0;
}
/**********************************************************************************************************************************
* OBJ & LEAF DEFINITION
***********************************************************************************************************************************/
/* *** Device.Users. *** */
DMOBJ tUsersObj[] = {
/* OBJ, permission, addobj, delobj, checkdep, browseinstobj, nextdynamicobj, dynamicleaf, nextobj, leaf, linker, bbfdm_type, uniqueKeys*/

File diff suppressed because it is too large Load diff

View file

@ -73,25 +73,25 @@ extern DMLEAF tWiFiDataElementsDisassociationEventDisassociationEventDataParams[
struct wifi_radio_args
{
struct uci_section *wifi_radio_sec;
struct dmmap_dup *sections;
};
struct wifi_ssid_args
{
struct uci_section *wifi_ssid_sec;
struct dmmap_dup *sections;
char *ifname;
char *linker;
};
struct wifi_enp_args
{
struct uci_section *wifi_enp_sec;
struct dmmap_dup *sections;
char *ifname;
};
struct wifi_acp_args
{
struct uci_section *wifi_acp_sec;
struct dmmap_dup *sections;
char *ifname;
};

View file

@ -14,7 +14,7 @@
static int get_EthernetVLANTermination_MACVLAN(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string((struct uci_section *)data, "type", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "type", value);
*value = (strcmp(*value, "macvlan") == 0) ? "1" : "0";
return 0;
}
@ -31,8 +31,8 @@ static int set_EthernetVLANTermination_MACVLAN(char *refparam, struct dmctx *ctx
break;
case VALUESET:
string_to_bool(value, &b);
dmuci_get_value_by_section_string((struct uci_section *)data, "ifname", &ifname);
dmuci_get_value_by_section_string((struct uci_section *)data, "name", &name);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "ifname", &ifname);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "name", &name);
struct uci_section *s = NULL, *dmmap_s = NULL;
if (b && *name != '\0') {
char *link_instance = NULL, new_name[16] = {0};
@ -104,10 +104,10 @@ static int set_EthernetVLANTermination_MACVLAN(char *refparam, struct dmctx *ctx
}
}
dmuci_set_value_by_section((struct uci_section *)data, "name", new_name);
dmuci_set_value_by_section((struct uci_section *)data, "type", "macvlan");
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "name", new_name);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "type", "macvlan");
} else {
dmuci_set_value_by_section((struct uci_section *)data, "type", b ? "macvlan" : "8021q");
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "type", b ? "macvlan" : "8021q");
}
break;
}

View file

@ -154,7 +154,7 @@ void synchronize_specific_config_sections_with_dmmap_mcast_iface(char *package,
uci_path_foreach_sections_safe(bbfdm, dmmap_package, dmmap_sec, stmp, s) {
dmuci_get_value_by_section_string(s, "section_name", &v);
if (get_origin_section_from_config(package, section_type, v) == NULL)
dmuci_delete_by_section_unnamed_bbfdm(s, NULL, NULL);
dmuci_delete_by_section(s, NULL, NULL);
}
}
@ -217,7 +217,7 @@ void synchronize_specific_config_sections_with_dmmap_mcast_filter(char *package,
uci_path_foreach_sections_safe(bbfdm, dmmap_package, dmmap_sec, stmp, s) {
dmuci_get_value_by_section_string(s, "section_name", &v);
if (get_origin_section_from_config(package, section_type, v) == NULL)
dmuci_delete_by_section_unnamed_bbfdm(s, NULL, NULL);
dmuci_delete_by_section(s, NULL, NULL);
}
}
@ -295,7 +295,7 @@ void del_dmmap_sec_with_opt_eq(char *dmmap_file, char *section, char *option, ch
uci_path_foreach_sections_safe(bbfdm, dmmap_file, section, stmp, d_sec) {
dmuci_get_value_by_section_string(d_sec, option, &opt_val);
if (strcmp(opt_val, value) == 0)
dmuci_delete_by_section_unnamed_bbfdm(d_sec, NULL, NULL);
dmuci_delete_by_section(d_sec, NULL, NULL);
}
}
@ -373,11 +373,9 @@ int del_proxy_obj(void *data, char *proto, unsigned char del_action)
static int add_igmp_proxy_obj(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
struct uci_section *dmmap = NULL, *s = NULL;
struct browse_args browse_args = {0};
char s_name[32];
char *inst = get_last_instance_lev2_bbfdm_dmmap_opt("dmmap_mcast", "proxy", "proxy_instance", "proto", "igmp");
snprintf(s_name, sizeof(s_name), "igmp_proxy_%d", inst ? atoi(inst)+1 : 1);
snprintf(s_name, sizeof(s_name), "igmp_proxy_%s", *instance);
dmuci_add_section("mcast", "proxy", &s);
dmuci_rename_section_by_section(s, s_name);
@ -387,14 +385,11 @@ static int add_igmp_proxy_obj(char *refparam, struct dmctx *ctx, void *data, cha
dmuci_set_value_by_section(s, "robustness", "2");
dmuci_set_value_by_section(s, "aggregation", "0");
browse_args.option = "proto";
browse_args.value = "igmp";
dmuci_add_section_bbfdm("dmmap_mcast", "proxy", &dmmap);
dmuci_set_value_by_section(dmmap, "section_name", s_name);
dmuci_set_value_by_section(dmmap, "proto", "igmp");
*instance = update_instance(inst, 5, dmmap, "proxy_instance", NULL, check_browse_section, (void *)&browse_args);
dmuci_set_value_by_section(dmmap, "proxy_instance", *instance);
return 0;
}
@ -405,20 +400,14 @@ static int del_igmp_proxy_obj(char *refparam, struct dmctx *ctx, void *data, cha
static int browse_igmp_proxy_inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *max_inst = NULL;
struct browse_args browse_args = {0};
char *inst = NULL;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap_cont("mcast", "proxy", "dmmap_mcast", "proto", "igmp", &dup_list);
list_for_each_entry(p, &dup_list, list) {
browse_args.option = "proto";
browse_args.value = "igmp";
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 5,
p->dmmap_section, "proxy_instance", "proxy_alias",
check_browse_section, (void *)&browse_args);
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "proxy_instance", "proxy_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, inst) == DM_STOP)
break;
@ -431,11 +420,9 @@ static int browse_igmp_proxy_inst(struct dmctx *dmctx, DMNODE *parent_node, void
static int add_igmp_snooping_obj(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
struct uci_section *dmmap = NULL, *s = NULL;
struct browse_args browse_args = {0};
char s_name[32];
char *inst = get_last_instance_lev2_bbfdm_dmmap_opt("dmmap_mcast", "snooping", "snooping_instance", "proto", "igmp");
snprintf(s_name, sizeof(s_name), "igmp_snoop_%d", inst ? atoi(inst)+1 : 1);
snprintf(s_name, sizeof(s_name), "igmp_snoop_%s", *instance);
dmuci_add_section("mcast", "snooping", &s);
dmuci_rename_section_by_section(s, s_name);
@ -445,14 +432,10 @@ static int add_igmp_snooping_obj(char *refparam, struct dmctx *ctx, void *data,
dmuci_set_value_by_section(s, "robustness", "2");
dmuci_set_value_by_section(s, "aggregation", "0");
browse_args.option = "proto";
browse_args.value = "igmp";
dmuci_add_section_bbfdm("dmmap_mcast", "snooping", &dmmap);
dmuci_set_value_by_section(dmmap, "section_name", s_name);
dmuci_set_value_by_section(dmmap, "proto", "igmp");
*instance = update_instance(inst, 5, dmmap, "snooping_instance", NULL, check_browse_section, (void *)&browse_args);
dmuci_set_value_by_section(dmmap, "snooping_instance", *instance);
return 0;
}
@ -504,20 +487,14 @@ static int del_igmp_snooping_obj(char *refparam, struct dmctx *ctx, void *data,
static int browse_igmp_snooping_inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *max_inst = NULL;
struct browse_args browse_args = {0};
char *inst = NULL;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap_cont("mcast", "snooping", "dmmap_mcast", "proto", "igmp", &dup_list);
list_for_each_entry(p, &dup_list, list) {
browse_args.option = "proto";
browse_args.value = "igmp";
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 5,
p->dmmap_section, "snooping_instance", "snooping_alias",
check_browse_section, (void *)&browse_args);
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "snooping_instance", "snooping_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, inst) == DM_STOP)
break;
@ -556,7 +533,7 @@ static int browse_igmp_cgrp_inst(struct dmctx *dmctx, DMNODE *parent_node, void
{
//perform ubus call to mcast stats and browse through each igmp group json object
json_object *res = NULL, *jobj = NULL, *arrobj = NULL, *group_obj = NULL;
char *inst = NULL, *max_inst = NULL;
char *inst = NULL;
dmubus_call("mcast", "stats", UBUS_ARGS{}, 0, &res);
if (res) {
@ -564,7 +541,7 @@ static int browse_igmp_cgrp_inst(struct dmctx *dmctx, DMNODE *parent_node, void
jobj = dmjson_select_obj_in_array_idx(res, 0, 1, "snooping");
dmjson_foreach_obj_in_array(jobj, arrobj, group_obj, i, 1, "groups") {
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_without_section, 1, ++id);
inst = handle_instance_without_section(dmctx, parent_node, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)group_obj, inst) == DM_STOP)
break;
}
@ -575,20 +552,11 @@ static int browse_igmp_cgrp_inst(struct dmctx *dmctx, DMNODE *parent_node, void
static int add_igmps_filter_obj(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
struct uci_section *dmmap_igmps_filter = NULL;
struct browse_args browse_args = {0};
char *last_inst = get_last_instance_lev2_bbfdm_dmmap_opt("dmmap_mcast", "snooping_filter", "filter_instance",
"section_name", section_name((struct uci_section *)data));
dmuci_add_section_bbfdm("dmmap_mcast", "snooping_filter", &dmmap_igmps_filter);
dmuci_set_value_by_section(dmmap_igmps_filter, "section_name", section_name((struct uci_section *)data));
dmuci_set_value_by_section(dmmap_igmps_filter, "enable", "0");
browse_args.option = "section_name";
browse_args.value = section_name((struct uci_section *)data);
*instance = update_instance(last_inst, 5, dmmap_igmps_filter, "filter_instance", NULL, check_browse_section, (void *)&browse_args);
dmuci_set_value_by_section(dmmap_igmps_filter, "filter_instance", *instance);
return 0;
}
@ -636,8 +604,7 @@ int del_mcasts_filter_obj(char *refparam, struct dmctx *ctx, void *data, char *i
int browse_filter_inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *section_type, char *option_name, char *option_value)
{
struct dmmap_dup *p = NULL;
struct browse_args browse_args = {0};
char *inst = NULL, *max_inst = NULL;
char *inst = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap_mcast_filter("mcast", section_type, prev_data, "dmmap_mcast", option_name, option_value, &dup_list);
@ -645,12 +612,7 @@ int browse_filter_inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data
if (!p->config_section)
break;
browse_args.option = "section_name";
browse_args.value = section_name((struct uci_section *)prev_data);
inst = handle_update_instance(2, dmctx, &max_inst, update_instance_alias, 5,
p->dmmap_section, "filter_instance", "filter_alias",
check_browse_section, (void *)&browse_args);
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "filter_instance", "filter_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, inst) == DM_STOP)
break;
@ -1039,23 +1001,13 @@ int set_mcast_snooping_interface(char *refparam, struct dmctx *ctx, void *data,
static int add_igmpp_interface_obj(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
// This section works but commented for now as it is tested not much yet.
struct uci_section *dmmap_igmpp_interface = NULL;
struct browse_args browse_args = {0};
char *last_inst = get_last_instance_lev2_bbfdm_dmmap_opt("dmmap_mcast", "proxy_interface", "iface_instance",
"section_name", section_name((struct uci_section *)data));
dmuci_add_section_bbfdm("dmmap_mcast", "proxy_interface", &dmmap_igmpp_interface);
dmuci_set_value_by_section(dmmap_igmpp_interface, "section_name",
section_name((struct uci_section *)data));
dmuci_set_value_by_section(dmmap_igmpp_interface, "section_name", section_name((struct uci_section *)data));
dmuci_set_value_by_section(dmmap_igmpp_interface, "upstream", "0");
dmuci_set_value_by_section(dmmap_igmpp_interface, "snooping_mode", "0");
browse_args.option = "section_name";
browse_args.value = section_name((struct uci_section *)data);
*instance = update_instance(last_inst, 5, dmmap_igmpp_interface, "iface_instance", NULL, check_browse_section, (void *)&browse_args);
dmuci_set_value_by_section(dmmap_igmpp_interface, "iface_instance", *instance);
return 0;
}
@ -1152,8 +1104,7 @@ static int del_igmpp_interface_obj(char *refparam, struct dmctx *ctx, void *data
int browse_proxy_interface_inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *proto)
{
struct dmmap_dup *p = NULL;
struct browse_args browse_args = {0};
char *inst = NULL, *max_inst = NULL;
char *inst = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap_mcast_iface("mcast", "proxy", prev_data, "dmmap_mcast", "proxy_interface", proto, &dup_list);
@ -1161,12 +1112,7 @@ int browse_proxy_interface_inst(struct dmctx *dmctx, DMNODE *parent_node, void *
if (!p->config_section)
break;
browse_args.option = "section_name";
browse_args.value = section_name((struct uci_section *)prev_data);
inst = handle_update_instance(2, dmctx, &max_inst, update_instance_alias, 5,
p->dmmap_section, "iface_instance", "iface_alias",
check_browse_section, (void *)&browse_args);
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "iface_instance", "iface_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, inst) == DM_STOP)
break;
@ -1184,21 +1130,11 @@ static int browse_igmpp_interface_inst(struct dmctx *dmctx, DMNODE *parent_node,
static int add_igmpp_filter_obj(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
struct uci_section *dmmap_igmpp_filter = NULL;
struct browse_args browse_args = {0};
char *last_inst = get_last_instance_lev2_bbfdm_dmmap_opt("dmmap_mcast", "proxy_filter", "filter_instance",
"section_name", section_name((struct uci_section *)data));
dmuci_add_section_bbfdm("dmmap_mcast", "proxy_filter", &dmmap_igmpp_filter);
dmuci_set_value_by_section(dmmap_igmpp_filter, "section_name",
section_name((struct uci_section *)data));
dmuci_set_value_by_section(dmmap_igmpp_filter, "section_name", section_name((struct uci_section *)data));
dmuci_set_value_by_section(dmmap_igmpp_filter, "enable", "0");
browse_args.option = "section_name";
browse_args.value = section_name((struct uci_section *)data);
*instance = update_instance(last_inst, 5, dmmap_igmpp_filter, "filter_instance", NULL, check_browse_section, (void *)&browse_args);
dmuci_set_value_by_section(dmmap_igmpp_filter, "filter_instance", *instance);
return 0;
}
@ -1368,10 +1304,10 @@ static int browse_igmp_cgrp_assoc_dev_inst(struct dmctx *dmctx, DMNODE *parent_n
int i = 0, id = 0;
json_object *arrobj = NULL, *client_jobj = NULL;
char *inst = NULL, *max_inst = NULL;
char *inst = NULL;
dmjson_foreach_obj_in_array((struct json_object *)prev_data, arrobj, client_jobj, i, 1, "clients") {
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_without_section, 1, ++id);
inst = handle_instance_without_section(dmctx, parent_node, ++id);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)client_jobj, inst) == DM_STOP)
break;
}

View file

@ -16,11 +16,9 @@
static int add_mld_proxy_obj(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
struct uci_section *dmmap = NULL, *s = NULL;
struct browse_args browse_args = {0};
char s_name[32];
char *inst = get_last_instance_lev2_bbfdm_dmmap_opt("dmmap_mcast", "proxy", "proxy_instance", "proto", "mld");
snprintf(s_name, sizeof(s_name), "mld_proxy_%d", inst ? atoi(inst)+1 : 1);
snprintf(s_name, sizeof(s_name), "mld_proxy_%s", *instance);
dmuci_add_section("mcast", "proxy", &s);
dmuci_rename_section_by_section(s, s_name);
@ -30,13 +28,10 @@ static int add_mld_proxy_obj(char *refparam, struct dmctx *ctx, void *data, char
dmuci_set_value_by_section(s, "robustness", "2");
dmuci_set_value_by_section(s, "aggregation", "0");
browse_args.option = "proto";
browse_args.value = "mld";
dmuci_add_section_bbfdm("dmmap_mcast", "proxy", &dmmap);
dmuci_set_value_by_section(dmmap, "section_name", s_name);
dmuci_set_value_by_section(dmmap, "proto", "mld");
*instance = update_instance(inst, 5, dmmap, "proxy_instance", NULL, check_browse_section, (void *)&browse_args);
dmuci_set_value_by_section(dmmap, "proxy_instance", *instance);
return 0;
}
@ -47,20 +42,14 @@ static int del_mld_proxy_obj(char *refparam, struct dmctx *ctx, void *data, char
static int browse_mld_proxy_inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *max_inst = NULL;
struct browse_args browse_args = {0};
char *inst = NULL;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap_cont("mcast", "proxy", "dmmap_mcast", "proto", "mld", &dup_list);
list_for_each_entry(p, &dup_list, list) {
browse_args.option = "proto";
browse_args.value = "mld";
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 5,
p->dmmap_section, "proxy_instance", "proxy_alias",
check_browse_section, (void *)&browse_args);
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "proxy_instance", "proxy_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, inst) == DM_STOP)
break;
@ -73,11 +62,9 @@ static int browse_mld_proxy_inst(struct dmctx *dmctx, DMNODE *parent_node, void
static int add_mld_snooping_obj(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
struct uci_section *dmmap = NULL, *s = NULL;
struct browse_args browse_args = {0};
char s_name[32];
char *inst = get_last_instance_lev2_bbfdm_dmmap_opt("dmmap_mcast", "snooping", "snooping_instance", "proto", "mld");
snprintf(s_name, sizeof(s_name), "mld_snoop_%d", inst ? atoi(inst)+1 : 1);
snprintf(s_name, sizeof(s_name), "mld_snoop_%s", *instance);
dmuci_add_section("mcast", "snooping", &s);
dmuci_rename_section_by_section(s, s_name);
@ -87,13 +74,10 @@ static int add_mld_snooping_obj(char *refparam, struct dmctx *ctx, void *data, c
dmuci_set_value_by_section(s, "robustness", "2");
dmuci_set_value_by_section(s, "aggregation", "0");
browse_args.option = "proto";
browse_args.value = "mld";
dmuci_add_section_bbfdm("dmmap_mcast", "snooping", &dmmap);
dmuci_set_value_by_section(dmmap, "section_name", s_name);
dmuci_set_value_by_section(dmmap, "proto", "mld");
*instance = update_instance(inst, 5, dmmap, "snooping_instance", NULL, check_browse_section, (void *)&browse_args);
dmuci_set_value_by_section(dmmap, "snooping_instance", *instance);
return 0;
}
@ -104,20 +88,14 @@ static int del_mld_snooping_obj(char *refparam, struct dmctx *ctx, void *data, c
static int browse_mld_snooping_inst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *max_inst = NULL;
struct browse_args browse_args = {0};
char *inst = NULL;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap_cont("mcast", "snooping", "dmmap_mcast", "proto", "mld", &dup_list);
list_for_each_entry(p, &dup_list, list) {
browse_args.option = "proto";
browse_args.value = "mld";
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 5,
p->dmmap_section, "snooping_instance", "snooping_alias",
check_browse_section, (void *)&browse_args);
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "snooping_instance", "snooping_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, inst) == DM_STOP)
break;
@ -169,20 +147,11 @@ static int browse_mldp_cgrp_inst(struct dmctx *dmctx, DMNODE *parent_node, void
static int add_mlds_filter_obj(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
struct uci_section *dmmap_mlds_filter = NULL;
struct browse_args browse_args = {0};
char *last_inst = get_last_instance_lev2_bbfdm_dmmap_opt("dmmap_mcast", "snooping_filter", "filter_instance",
"section_name", section_name((struct uci_section *)data));
dmuci_add_section_bbfdm("dmmap_mcast", "snooping_filter", &dmmap_mlds_filter);
dmuci_set_value_by_section(dmmap_mlds_filter, "section_name", section_name((struct uci_section *)data));
dmuci_set_value_by_section(dmmap_mlds_filter, "enable", "0");
browse_args.option = "section_name";
browse_args.value = section_name((struct uci_section *)data);
*instance = update_instance(last_inst, 5, dmmap_mlds_filter, "filter_instance", NULL, check_browse_section, (void *)&browse_args);
dmuci_set_value_by_section(dmmap_mlds_filter, "filter_instance", *instance);
return 0;
}
@ -216,22 +185,13 @@ static int set_mld_version(char *refparam, struct dmctx *ctx, void *data, char *
static int add_mldp_interface_obj(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
// This section works but commented for now as it is tested not much yet.
struct uci_section *dmmap_mldp_interface = NULL;
struct browse_args browse_args = {0};
char *last_inst = get_last_instance_lev2_bbfdm_dmmap_opt("dmmap_mcast", "proxy_interface", "iface_instance",
"section_name", section_name((struct uci_section *)data));
dmuci_add_section_bbfdm("dmmap_mcast", "proxy_interface", &dmmap_mldp_interface);
dmuci_set_value_by_section(dmmap_mldp_interface, "section_name", section_name((struct uci_section *)data));
dmuci_set_value_by_section(dmmap_mldp_interface, "upstream", "0");
dmuci_set_value_by_section(dmmap_mldp_interface, "snooping_mode", "0");
browse_args.option = "section_name";
browse_args.value = section_name((struct uci_section *)data);
*instance = update_instance(last_inst, 5, dmmap_mldp_interface, "iface_instance", NULL, check_browse_section, (void *)&browse_args);
dmuci_set_value_by_section(dmmap_mldp_interface, "iface_instance", *instance);
return 0;
}
@ -294,19 +254,11 @@ static int browse_mldp_interface_inst(struct dmctx *dmctx, DMNODE *parent_node,
static int add_mldp_filter_obj(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
struct uci_section *dmmap_mldp_filter = NULL;
struct browse_args browse_args = {0};
char *last_inst = get_last_instance_lev2_bbfdm_dmmap_opt("dmmap_mcast", "proxy_filter", "filter_instance", "section_name", section_name((struct uci_section *)data));
dmuci_add_section_bbfdm("dmmap_mcast", "proxy_filter", &dmmap_mldp_filter);
dmuci_set_value_by_section(dmmap_mldp_filter, "section_name", section_name((struct uci_section *)data));
dmuci_set_value_by_section(dmmap_mldp_filter, "enable", "0");
browse_args.option = "section_name";
browse_args.value = section_name((struct uci_section *)data);
*instance = update_instance(last_inst, 5, dmmap_mldp_filter, "filter_instance", NULL, check_browse_section, (void *)&browse_args);
dmuci_set_value_by_section(dmmap_mldp_filter, "filter_instance", *instance);
return 0;
}

View file

@ -34,13 +34,13 @@ static const struct fw_image fw_images[] = {
static int openwrt__browseDeviceInfoFirmwareImageInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *max_inst = NULL;
char *inst = NULL;
int i;
for (i = 0; i < ARRAY_SIZE(fw_images); i++) {
const struct fw_image *fw_img = &fw_images[i];
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_without_section, 1, i+1);
inst = handle_instance_without_section(dmctx, parent_node, i+1);
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)fw_img, inst) == DM_STOP)
break;
}

View file

@ -62,15 +62,14 @@ int command_exec_output_to_array(const char *cmd, char **output, int *length)
/*#Device.QoS.Classification.{i}.!UCI:qos/classify/dmmap_qos*/
static int openwrt__browseQoSClassificationInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *max_inst = NULL;
char *inst = NULL;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("qos", "classify", "dmmap_qos", &dup_list);
list_for_each_entry(p, &dup_list, list) {
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
p->dmmap_section, "classifinstance", "classifalias");
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "classifinstance", "classifalias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p, inst) == DM_STOP)
break;
@ -128,8 +127,7 @@ static int openwrt__browseQoSQueueStatsInst(struct dmctx *dmctx, DMNODE *parent_
if (lastinstancestore != NULL && max_inst != NULL)
max_inst = dmstrdup(lastinstancestore);
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
dmmap_sect, "queuestatsinstance", "queuestatsalias");
inst = handle_instance(dmctx, parent_node, dmmap_sect, "queuestatsinstance", "queuestatsalias");
lastinstancestore = dmstrdup(max_inst);
@ -155,39 +153,30 @@ static int openwrt__addObjQoSClassification(char *refparam, struct dmctx *ctx, v
struct uci_section *s, *dmmap_qclassify;
char qcomment[32];
char *last_inst = get_last_instance_bbfdm("dmmap_qos", "classify", "classifinstance");
snprintf(qcomment, sizeof(qcomment), "QoS classify %s", (last_inst) ? last_inst : "1");
snprintf(qcomment, sizeof(qcomment), "QoS classify %s", *instance);
dmuci_add_section("qos", "classify", &s);
dmuci_set_value_by_section(s, "comment", qcomment);
dmuci_add_section_bbfdm("dmmap_qos", "classify", &dmmap_qclassify);
dmuci_set_value_by_section(dmmap_qclassify, "section_name", section_name(s));
*instance = update_instance(last_inst, 2, dmmap_qclassify, "classifinstance");
dmuci_set_value_by_section(dmmap_qclassify, "classifinstance", *instance);
return 0;
}
static int openwrt__delObjQoSClassification(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
struct dmmap_dup *p = (struct dmmap_dup*)data;
struct uci_section *s = NULL, *stmp = NULL, *dmmap_section = NULL;
struct uci_section *s = NULL, *stmp = NULL;
switch (del_action) {
case DEL_INST:
if(is_section_unnamed(section_name(p->config_section))){
LIST_HEAD(dup_list);
delete_sections_save_next_sections("dmmap_qos", "classify", "classifinstance", section_name(p->config_section), atoi(instance), &dup_list);
update_dmmap_sections(&dup_list, "classifinstance", "dmmap_qos", "classify");
dmuci_delete_by_section_unnamed(p->config_section, NULL, NULL);
} else {
get_dmmap_section_of_config_section("dmmap_qos", "classify", section_name(p->config_section), &dmmap_section);
dmuci_delete_by_section_unnamed_bbfdm(dmmap_section, NULL, NULL);
dmuci_delete_by_section(p->config_section, NULL, NULL);
}
dmuci_delete_by_section(((struct dmmap_dup *)data)->dmmap_section, NULL, NULL);
dmuci_delete_by_section(((struct dmmap_dup *)data)->config_section, NULL, NULL);
break;
case DEL_ALL:
uci_foreach_sections_safe("qos", "classify", stmp, s) {
struct uci_section *dmmap_section = NULL;
get_dmmap_section_of_config_section("dmmap_qos", "classify", section_name(s), &dmmap_section);
dmuci_delete_by_section(dmmap_section, NULL, NULL);
@ -214,24 +203,15 @@ static int openwrt__delObjQoSQueueStats(char *refparam, struct dmctx *ctx, void
/*#Device.QoS.ClassificationNumberOfEntries!UCI:qos/classify/*/
static int openwrt__get_QClassificationNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *s = NULL;
static int nbre= 0;
uci_foreach_sections("qos", "classify", s) {
nbre++;
}
dmasprintf(value, "%d", nbre);
int cnt = get_number_of_entries(ctx, data, instance, openwrt__browseQoSClassificationInst);
dmasprintf(value, "%d", cnt);
return 0;
}
static int openwrt__get_QQueueStatsNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *questatsout[256];
static int length = 0;
command_exec_output_to_array("tc -s qdisc", questatsout, &length);
dmasprintf(value, "%d", length/3);
int cnt = get_number_of_entries(ctx, data, instance, openwrt__browseQoSQueueStatsInst);
dmasprintf(value, "%d", cnt);
return 0;
}

View file

@ -18,7 +18,7 @@ static int get_rule_icmp_type(char *refparam, struct dmctx *ctx, void *data, cha
char *ptr = NULL;
dmasprintf(value, "%s", "");
dmuci_get_value_by_section_list((struct uci_section *)data, "icmp_type", &v);
dmuci_get_value_by_section_list(((struct dmmap_dup *)data)->config_section, "icmp_type", &v);
if (v != NULL) {
uci_foreach_element(v, e) {
ptr = dmstrdup(*value);
@ -38,7 +38,7 @@ static int get_rule_icmp_type(char *refparam, struct dmctx *ctx, void *data, cha
static int get_rule_source_mac(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *v = NULL;
dmuci_get_value_by_section_string((struct uci_section *)data, "src_mac", &v);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "src_mac", &v);
*value = (v) ? v : "";
return 0;
}
@ -52,7 +52,7 @@ static int get_time_span_supported_days(char *refparam, struct dmctx *ctx, void
static int get_time_span_days(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *v;
dmuci_get_value_by_section_string((struct uci_section *)data, "weekdays", &v);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "weekdays", &v);
*value = (v) ? v : "";
return 0;
}
@ -60,7 +60,7 @@ static int get_time_span_days(char *refparam, struct dmctx *ctx, void *data, cha
static int get_time_span_start_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *v;
dmuci_get_value_by_section_string((struct uci_section *)data, "start_time", &v);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "start_time", &v);
*value = (v) ? v : "";
return 0;
}
@ -68,7 +68,7 @@ static int get_time_span_start_time(char *refparam, struct dmctx *ctx, void *dat
static int get_time_span_stop_time(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *v;
dmuci_get_value_by_section_string((struct uci_section *)data, "stop_time", &v);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "stop_time", &v);
*value = (v) ? v : "";
return 0;
}
@ -84,10 +84,10 @@ static int set_rule_icmp_type(char *refparam, struct dmctx *ctx, void *data, cha
//TODO
break;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "icmp_type", "");
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "icmp_type", "");
devices = strsplit(value, " ", &length);
for (i = 0; i < length; i++)
dmuci_add_list_value_by_section((struct uci_section *)data, "icmp_type", devices[i]);
dmuci_add_list_value_by_section(((struct dmmap_dup *)data)->config_section, "icmp_type", devices[i]);
break;
}
return 0;
@ -100,7 +100,7 @@ static int set_rule_source_mac(char *refparam, struct dmctx *ctx, void *data, ch
//TODO
break;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "src_mac", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "src_mac", value);
break;
}
return 0;
@ -125,7 +125,7 @@ static int set_time_span_days(char *refparam, struct dmctx *ctx, void *data, cha
//TODO
break;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "weekdays", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "weekdays", value);
break;
}
return 0;
@ -138,7 +138,7 @@ static int set_time_span_start_time(char *refparam, struct dmctx *ctx, void *dat
//TODO
break;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "start_time", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "start_time", value);
break;
}
return 0;
@ -151,7 +151,7 @@ static int set_time_span_stop_time(char *refparam, struct dmctx *ctx, void *data
//TODO
break;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "stop_time", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "stop_time", value);
break;
}
return 0;

View file

@ -16,17 +16,16 @@
**************************************************************/
int browse_dropbear_instance(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *max_inst = NULL;
char *inst = NULL;
struct dmmap_dup *p = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("dropbear", "dropbear", "dmmap_dropbear", &dup_list);
list_for_each_entry(p, &dup_list, list) {
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
p->dmmap_section, "dropbearinstance", "dropbearalias");
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "dropbearinstance", "dropbearalias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, inst) == DM_STOP)
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p, inst) == DM_STOP)
break;
}
return 0;
@ -35,12 +34,10 @@ int browse_dropbear_instance(struct dmctx *dmctx, DMNODE *parent_node, void *pre
/*************************************************************
* ADD & DEL OBJ
**************************************************************/
int add_dropbear_instance(char *refparam, struct dmctx *ctx, void *data, char **instancepara)
int add_dropbear_instance(char *refparam, struct dmctx *ctx, void *data, char **instance)
{
struct uci_section *dropbear_sec = NULL, *dmmap_sec = NULL;
char *instance = get_last_instance_bbfdm("dmmap_dropbear", "dropbear", "dropbearinstance");
dmuci_add_section("dropbear", "dropbear", &dropbear_sec);
dmuci_set_value_by_section(dropbear_sec, "verbose", "0");
dmuci_set_value_by_section(dropbear_sec, "Port", "22");
@ -51,42 +48,27 @@ int add_dropbear_instance(char *refparam, struct dmctx *ctx, void *data, char **
dmuci_add_section_bbfdm("dmmap_dropbear", "dropbear", &dmmap_sec);
dmuci_set_value_by_section(dmmap_sec, "section_name", section_name(dropbear_sec));
*instancepara = update_instance(instance, 2, dmmap_sec, "dropbearinstance");
dmuci_set_value_by_section(dmmap_sec, "dropbearinstance", *instance);
return 0;
}
int delete_dropbear_instance(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
struct uci_section *s = NULL, *ss = NULL, *dmmap_section;
int found = 0;
struct uci_section *s = NULL, *stmp = NULL;
switch (del_action) {
case DEL_INST:
if(is_section_unnamed(section_name((struct uci_section *)data))){
LIST_HEAD(dup_list);
delete_sections_save_next_sections("dmmap_dropbear", "dropbear", "dropbearinstance", section_name((struct uci_section *)data), atoi(instance), &dup_list);
update_dmmap_sections(&dup_list, "dropbearinstance", "dmmap_dropbear", "dropbear");
dmuci_delete_by_section_unnamed((struct uci_section *)data, NULL, NULL);
} else {
get_dmmap_section_of_config_section("dmmap_dropbear", "dropbear", section_name((struct uci_section *)data), &dmmap_section);
dmuci_delete_by_section_unnamed_bbfdm(dmmap_section, NULL, NULL);
dmuci_delete_by_section((struct uci_section *)data, NULL, NULL);
}
dmuci_delete_by_section(((struct dmmap_dup *)data)->config_section, NULL, NULL);
dmuci_delete_by_section(((struct dmmap_dup *)data)->dmmap_section, NULL, NULL);
break;
case DEL_ALL:
uci_foreach_sections("dropbear", "dropbear", s) {
if (found != 0) {
get_dmmap_section_of_config_section("dmmap_dropbear", "dropbear", section_name(ss), &dmmap_section);
if (dmmap_section) dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
}
ss = s;
found++;
}
if (ss != NULL) {
get_dmmap_section_of_config_section("dmmap_dropbear", "dropbear", section_name(ss), &dmmap_section);
if (dmmap_section) dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(ss, NULL, NULL);
uci_foreach_sections_safe("dropbear", "dropbear", stmp, s) {
struct uci_section *dmmap_section = NULL;
get_dmmap_section_of_config_section("dmmap_dropbear", "dropbear", section_name(s), &dmmap_section);
dmuci_delete_by_section(dmmap_section, NULL, NULL);
dmuci_delete_by_section(s, NULL, NULL);
}
return 0;
}
@ -98,10 +80,7 @@ int delete_dropbear_instance(char *refparam, struct dmctx *ctx, void *data, char
**************************************************************/
static int get_x_test_com_dropbear_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
struct uci_section *dmmap_section = NULL;
get_dmmap_section_of_config_section("dmmap_dropbear", "dropbear", section_name((struct uci_section *)data), &dmmap_section);
dmuci_get_value_by_section_string(dmmap_section, "dropbearalias", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->dmmap_section, "dropbearalias", value);
if ((*value)[0] == '\0')
dmasprintf(value, "cpe-%s", instance);
return 0;
@ -109,16 +88,13 @@ static int get_x_test_com_dropbear_alias(char *refparam, struct dmctx *ctx, void
static int set_x_test_com_dropbear_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
struct uci_section *dmmap_section = NULL;
switch (action) {
case VALUECHECK:
if (dm_validate_string(value, -1, 64, NULL, NULL))
return FAULT_9007;
return 0;
case VALUESET:
get_dmmap_section_of_config_section("dmmap_dropbear", "dropbear", section_name((struct uci_section *)data), &dmmap_section);
dmuci_set_value_by_section(dmmap_section, "dropbearalias", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->dmmap_section, "dropbearalias", value);
return 0;
}
return 0;
@ -126,7 +102,7 @@ static int set_x_test_com_dropbear_alias(char *refparam, struct dmctx *ctx, void
static int get_x_test_com_dropbear_password_auth(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *res = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "PasswordAuth", "1");
char *res = dmuci_get_value_by_section_fallback_def(((struct dmmap_dup *)data)->config_section, "PasswordAuth", "1");
*value = ((strcmp(res, "on") == 0) || *res == '1') ? "1" : "0";
return 0;
}
@ -142,7 +118,7 @@ static int set_x_test_com_dropbear_password_auth(char *refparam, struct dmctx *c
return 0;
case VALUESET:
string_to_bool(value, &b);
dmuci_set_value_by_section((struct uci_section *)data, "PasswordAuth", b ? "1" : "0");
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "PasswordAuth", b ? "1" : "0");
return 0;
}
return 0;
@ -150,7 +126,7 @@ static int set_x_test_com_dropbear_password_auth(char *refparam, struct dmctx *c
static int get_x_test_com_dropbear_root_password_auth(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
char *res = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "RootPasswordAuth", "1");
char *res = dmuci_get_value_by_section_fallback_def(((struct dmmap_dup *)data)->config_section, "RootPasswordAuth", "1");
*value = ((strcmp(res, "on") == 0) || *res == '1') ? "1" : "0";
return 0;
}
@ -166,7 +142,7 @@ static int set_x_test_com_dropbear_root_password_auth(char *refparam, struct dmc
return 0;
case VALUESET:
string_to_bool(value, &b);
dmuci_set_value_by_section((struct uci_section *)data, "RootPasswordAuth", b ? "1" : "0");
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "RootPasswordAuth", b ? "1" : "0");
return 0;
}
return 0;
@ -174,7 +150,7 @@ static int set_x_test_com_dropbear_root_password_auth(char *refparam, struct dmc
static int get_x_test_com_dropbear_port(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "Port", "22");
*value = dmuci_get_value_by_section_fallback_def(((struct dmmap_dup *)data)->config_section, "Port", "22");
return 0;
}
@ -185,7 +161,7 @@ static int set_x_test_com_dropbear_port(char *refparam, struct dmctx *ctx, void
case VALUECHECK:
return 0;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "Port", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "Port", value);
return 0;
}
return 0;
@ -193,7 +169,7 @@ static int set_x_test_com_dropbear_port(char *refparam, struct dmctx *ctx, void
static int get_x_test_com_dropbear_root_login(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string((struct uci_section *)data, "RootLogin", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "RootLogin", value);
if ((*value)[0] == '\0' || ((*value)[0] == 'o' && (*value)[1] == 'n') || (*value)[0] == '1' )
*value = "1";
else
@ -212,7 +188,7 @@ static int set_x_test_com_dropbear_root_login(char *refparam, struct dmctx *ctx,
return 0;
case VALUESET:
string_to_bool(value, &b);
dmuci_set_value_by_section((struct uci_section *)data, "RootLogin", b ? "1" : "0");
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "RootLogin", b ? "1" : "0");
return 0;
}
return 0;
@ -220,7 +196,7 @@ static int set_x_test_com_dropbear_root_login(char *refparam, struct dmctx *ctx,
static int get_x_test_com_dropbear_verbose(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "verbose", "0");
*value = dmuci_get_value_by_section_fallback_def(((struct dmmap_dup *)data)->config_section, "verbose", "0");
return 0;
}
@ -235,7 +211,7 @@ static int set_x_test_com_dropbear_verbose(char *refparam, struct dmctx *ctx, vo
return 0;
case VALUESET:
string_to_bool(value, &b);
dmuci_set_value_by_section((struct uci_section *)data, "verbose", b ? "1" : "0");
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "verbose", b ? "1" : "0");
return 0;
}
return 0;
@ -243,7 +219,7 @@ static int set_x_test_com_dropbear_verbose(char *refparam, struct dmctx *ctx, vo
static int get_x_test_com_dropbear_gateway_ports(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "GatewayPorts", "0");
*value = dmuci_get_value_by_section_fallback_def(((struct dmmap_dup *)data)->config_section, "GatewayPorts", "0");
return 0;
}
@ -258,7 +234,7 @@ static int set_x_test_com_dropbear_gateway_ports(char *refparam, struct dmctx *c
return 0;
case VALUESET:
string_to_bool(value, &b);
dmuci_set_value_by_section((struct uci_section *)data, "GatewayPorts", b ? "1" : "");
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "GatewayPorts", b ? "1" : "");
return 0;
}
return 0;
@ -266,7 +242,7 @@ static int set_x_test_com_dropbear_gateway_ports(char *refparam, struct dmctx *c
static int get_x_test_com_dropbear_interface(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string((struct uci_section *)data, "Interface", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "Interface", value);
return 0;
}
@ -276,7 +252,7 @@ static int set_x_test_com_dropbear_interface(char *refparam, struct dmctx *ctx,
case VALUECHECK:
return 0;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "Interface", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "Interface", value);
return 0;
}
return 0;
@ -284,7 +260,7 @@ static int set_x_test_com_dropbear_interface(char *refparam, struct dmctx *ctx,
static int get_x_test_com_dropbear_rsakeyfile(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string((struct uci_section *)data, "rsakeyfile", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "rsakeyfile", value);
return 0;
}
@ -294,7 +270,7 @@ static int set_x_test_com_dropbear_rsakeyfile(char *refparam, struct dmctx *ctx,
case VALUECHECK:
return 0;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "rsakeyfile", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "rsakeyfile", value);
return 0;
}
return 0;
@ -302,7 +278,7 @@ static int set_x_test_com_dropbear_rsakeyfile(char *refparam, struct dmctx *ctx,
static int get_x_test_com_dropbear_dsskeyfile(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string((struct uci_section *)data, "dsskeyfile", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "dsskeyfile", value);
return 0;
}
@ -312,7 +288,7 @@ static int set_x_test_com_dropbear_dsskeyfile(char *refparam, struct dmctx *ctx,
case VALUECHECK:
return 0;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "dsskeyfile", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "dsskeyfile", value);
return 0;
}
return 0;
@ -320,7 +296,7 @@ static int set_x_test_com_dropbear_dsskeyfile(char *refparam, struct dmctx *ctx,
static int get_x_test_com_dropbear_ssh_keepalive(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "SSHKeepAlive", "300");
*value = dmuci_get_value_by_section_fallback_def(((struct dmmap_dup *)data)->config_section, "SSHKeepAlive", "300");
return 0;
}
@ -330,7 +306,7 @@ static int set_x_test_com_dropbear_ssh_keepalive(char *refparam, struct dmctx *c
case VALUECHECK:
return 0;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "SSHKeepAlive", (strcmp(value, "300") == 0) ? "" : value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "SSHKeepAlive", (strcmp(value, "300") == 0) ? "" : value);
return 0;
}
@ -339,7 +315,7 @@ static int set_x_test_com_dropbear_ssh_keepalive(char *refparam, struct dmctx *c
static int get_x_test_com_dropbear_idle_timeout(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "IdleTimeout", "300");
*value = dmuci_get_value_by_section_fallback_def(((struct dmmap_dup *)data)->config_section, "IdleTimeout", "300");
return 0;
}
@ -349,7 +325,7 @@ static int set_x_test_com_dropbear_idle_timeout(char *refparam, struct dmctx *ct
case VALUECHECK:
return 0;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "IdleTimeout", (value[0] == '0') ? "" : value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "IdleTimeout", (value[0] == '0') ? "" : value);
return 0;
}
return 0;
@ -357,7 +333,7 @@ static int set_x_test_com_dropbear_idle_timeout(char *refparam, struct dmctx *ct
static int get_x_test_com_dropbear_banner_file(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string((struct uci_section *)data, "BannerFile", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "BannerFile", value);
return 0;
}
@ -368,7 +344,7 @@ static int set_x_test_com_dropbear_banner_file(char *refparam, struct dmctx *ctx
case VALUECHECK:
return 0;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "BannerFile", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "BannerFile", value);
return 0;
}
return 0;

View file

@ -256,6 +256,8 @@ static void dm_browse_entry(struct dmctx *dmctx, DMNODE *parent_node, DMOBJ *ent
node.parent = parent_node;
node.instance_level = parent_node->instance_level;
node.matched = parent_node->matched;
node.prev_data = data;
node.prev_instance = instance;
if (!bbfdatamodel_matches(entryobj->bbfdm_type))
return;
@ -344,11 +346,24 @@ int dm_link_inst_obj(struct dmctx *dmctx, DMNODE *parent_node, void *data, char
{
int err = 0;
char *parent_obj;
DMNODE node = {0};
if (parent_node->browse_type == BROWSE_FIND_MAX_INST) {
int curr_inst = (instance && *instance != '\0') ? atoi(instance) : 0;
if (curr_inst > parent_node->max_instance)
parent_node->max_instance = curr_inst;
return 0;
}
if (parent_node->browse_type == BROWSE_NUM_OF_ENTRIES) {
parent_node->num_of_entries++;
return 0;
}
DMOBJ *prevobj = parent_node->obj;
DMOBJ *nextobj = prevobj->nextobj;
DMLEAF *nextleaf = prevobj->leaf;
DMNODE node = {0};
node.obj = prevobj;
node.parent = parent_node;
node.instance_level = parent_node->instance_level + 1;
@ -533,14 +548,103 @@ static int rootcmp(char *inparam, char *rootobj)
{
char buf[32];
snprintf(buf, sizeof(buf), "%s.", rootobj);
int cmp = strcmp(inparam, buf);
return cmp;
return strcmp(inparam, buf);
}
/***************************
* update instance & alias
***************************/
char *handle_update_instance(int instance_ranck, struct dmctx *ctx, char **max_inst, char * (*up_instance)(int action, char **last_inst, char **max_inst, void *argv[]), int argc, ...)
int get_number_of_entries(struct dmctx *ctx, void *data, char *instance, int (*browseinstobj)(struct dmctx *ctx, struct dmnode *node, void *data, char *instance))
{
DMNODE node = {0};
node.browse_type = BROWSE_NUM_OF_ENTRIES;
(browseinstobj)(ctx, &node, data, instance);
return node.num_of_entries;
}
static int get_instance_mode(struct dmctx *dmctx, DMNODE *node)
{
unsigned char instancelevel = node->instance_level;
int inst_mode = INSTANCE_MODE_NUMBER;
if (dmctx->nbrof_instance <= instancelevel) {
if (dmctx->instance_mode == INSTANCE_MODE_ALIAS)
inst_mode = INSTANCE_MODE_ALIAS;
} else if (dmctx->alias_register & (1 << instancelevel)) {
inst_mode = INSTANCE_MODE_ALIAS;
}
return inst_mode;
}
static int find_max_instance(struct dmctx *ctx, DMNODE *node)
{
if (node->max_instance == 0) {
node->browse_type = BROWSE_FIND_MAX_INST;
node->obj->browseinstobj(ctx, node, node->prev_data, node->prev_instance);
node->browse_type = BROWSE_NORMAL;
}
return ++(node->max_instance);
}
char *handle_instance(struct dmctx *dmctx, DMNODE *parent_node, struct uci_section *s, char *inst_opt, char *alias_opt)
{
char buf[64] = {0};
char *instance = "";
dmuci_get_value_by_section_string(s, inst_opt, &instance);
switch(parent_node->browse_type) {
case BROWSE_NORMAL:
if (instance && *instance == '\0') {
int max_inst = find_max_instance(dmctx, parent_node);
snprintf(buf, sizeof(buf), "%d", max_inst);
instance = dmuci_set_value_by_section(s, inst_opt, buf);
}
int inst_mode = get_instance_mode(dmctx, parent_node);
if (inst_mode == INSTANCE_MODE_ALIAS) {
char *alias = "";
dmuci_get_value_by_section_string(s, alias_opt, &alias);
if (alias && alias[0] == '\0') {
snprintf(buf, sizeof(buf), "cpe-%s", instance);
alias = dmuci_set_value_by_section(s, alias_opt, buf);
}
snprintf(buf, sizeof(buf), "[%s]", alias);
instance = dmstrdup(buf);
}
break;
case BROWSE_FIND_MAX_INST:
case BROWSE_NUM_OF_ENTRIES:
break;
}
return instance;
}
char *handle_instance_without_section(struct dmctx *dmctx, DMNODE *parent_node, int inst_nbr)
{
char *instance = "";
switch(parent_node->browse_type) {
case BROWSE_NORMAL:
dmasprintf(&instance, "%d", inst_nbr);
int inst_mode = get_instance_mode(dmctx, parent_node);
if (inst_mode == INSTANCE_MODE_ALIAS)
dmasprintf(&instance, "[cpe-%d]", inst_nbr);
break;
case BROWSE_FIND_MAX_INST:
case BROWSE_NUM_OF_ENTRIES:
break;
}
return instance;
}
__attribute__ ((deprecated)) char *handle_update_instance(int instance_ranck, struct dmctx *ctx, char **max_inst, char * (*up_instance)(int action, char **last_inst, char **max_inst, void *argv[]), int argc, ...)
{
va_list arg;
char *instance, *last_inst = NULL;
@ -644,7 +748,7 @@ char *update_instance_alias(int action, char **last_inst, char **max_inst, void
return instance;
}
char *update_instance_without_section(int action, char **last_inst, char **max_inst, void *argv[])
__attribute__ ((deprecated)) char *update_instance_without_section(int action, char **last_inst, char **max_inst, void *argv[])
{
char *instance, buf[64] = {0};
int instnbr = (int)(long)argv[0];
@ -661,7 +765,7 @@ char *update_instance_without_section(int action, char **last_inst, char **max_i
return instance;
}
char *get_last_instance_bbfdm(char *package, char *section, char *opt_inst)
__attribute__ ((deprecated)) char *get_last_instance_bbfdm(char *package, char *section, char *opt_inst)
{
struct uci_section *s;
char *inst = NULL, *last_inst = NULL;
@ -676,7 +780,7 @@ char *get_last_instance_bbfdm(char *package, char *section, char *opt_inst)
return inst;
}
char *get_last_instance(char *package, char *section, char *opt_inst)
__attribute__ ((deprecated)) char *get_last_instance(char *package, char *section, char *opt_inst)
{
struct uci_section *s;
char *inst = NULL, *last_inst = NULL;
@ -696,7 +800,7 @@ char *get_last_instance(char *package, char *section, char *opt_inst)
return inst;
}
char *get_last_instance_lev2_bbfdm_dmmap_opt(char *dmmap_package, char *section, char *opt_inst, char *opt_check, char *value_check)
__attribute__ ((deprecated)) char *get_last_instance_lev2_bbfdm_dmmap_opt(char *dmmap_package, char *section, char *opt_inst, char *opt_check, char *value_check)
{
struct uci_section *s;
char *instance = NULL, *last_inst = NULL;
@ -714,7 +818,7 @@ char *get_last_instance_lev2_bbfdm_dmmap_opt(char *dmmap_package, char *section,
return instance;
}
char *get_last_instance_lev2_bbfdm(char *package, char *section, char* dmmap_package, char *opt_inst, char *opt_check, char *value_check)
__attribute__ ((deprecated)) char *get_last_instance_lev2_bbfdm(char *package, char *section, char* dmmap_package, char *opt_inst, char *opt_check, char *value_check)
{
struct uci_section *s = NULL, *dmmap_section = NULL;
char *instance = NULL, *last_inst = NULL;
@ -761,7 +865,7 @@ void add_list_parameter(struct dmctx *ctx, char *param_name, char *param_data, c
dm_parameter->additional_data = additional_data;
}
void api_del_list_parameter(struct dm_parameter *dm_parameter)
static void api_del_list_parameter(struct dm_parameter *dm_parameter)
{
list_del(&dm_parameter->list);
dmfree(dm_parameter->name);
@ -830,44 +934,6 @@ void free_all_list_fault_param(struct dmctx *ctx)
}
}
int update_param_instance_alias(struct dmctx *ctx, char *param, char **new_param)
{
char *pch, *spch, *p;
char buf[512];
int i = 0, j = 0;
char pat[2] = {0};
char *dup = dmstrdup(param);
*pat = '.';
p = buf;
for (pch = strtok_r(dup, pat, &spch); pch != NULL; pch = strtok_r(NULL, pat, &spch)) {
if (isdigit(pch[0])) {
dmstrappendchr(p, '.');
dmstrappendstr(p, pch);
i++;
} else if (pch[0]== '[') {
dmstrappendchr(p, '.');
dmstrappendstr(p, (ctx->inst_buf[i]) ? ctx->inst_buf[i] : "1");
i++;
} else {
if (j > 0) {
dmstrappendchr(p, '.');
dmstrappendstr(p, pch);
}
if (j == 0) {
dmstrappendstr(p, pch);
j++;
}
}
}
if (param[strlen(param) - 1] == '.')
dmstrappendchr(p, '.');
dmstrappendend(p);
*new_param = dmstrdup(buf);
dmfree(dup);
return 0;
}
int string_to_bool(char *v, bool *b)
{
if (v[0] == '1' && v[1] == '\0') {
@ -1348,12 +1414,12 @@ static int mobj_add_object(DMOBJECT_ARGS)
{
char *refparam = node->current_object;
char *perm = permission->val;
char *new_instance = NULL;
int fault = 0;
if (strcmp(refparam, dmctx->in_param) != 0)
return FAULT_9005;
dmctx->stop = 1;
if (node->is_instanceobj)
return FAULT_9005;
@ -1363,11 +1429,18 @@ static int mobj_add_object(DMOBJECT_ARGS)
if (perm[0] == '0' || addobj == NULL)
return FAULT_9005;
int fault = (addobj)(refparam, dmctx, data, &instance);
int max_inst = find_max_instance(dmctx, node);
fault = dmasprintf(&new_instance, "%d", max_inst);
if (fault)
return fault;
dmctx->addobj_instance = instance;
dmctx->stop = 1;
fault = (addobj)(refparam, dmctx, data, &new_instance);
if (fault)
return fault;
dmctx->addobj_instance = new_instance;
return 0;
}

View file

@ -38,6 +38,10 @@
#define FREE(x) do { if(x) {free(x); x = NULL;} } while (0)
#endif
#ifndef BBF_ATTR_UNUSED
#define BBF_ATTR_UNUSED(x) (void)(x)
#endif
#define DM_STRNCPY(DST, SRC, SIZE) \
do { \
strncpy(DST, SRC, SIZE - 1); \
@ -192,9 +196,14 @@ typedef struct dmnode {
DMOBJ *obj;
struct dmnode *parent;
char *current_object;
void *prev_data;
char *prev_instance;
unsigned char instance_level;
unsigned char matched;
unsigned char is_instanceobj;
unsigned char browse_type;
int max_instance;
int num_of_entries;
} DMNODE;
typedef struct dm_map_obj {
@ -257,6 +266,12 @@ enum del_action_enum {
DEL_ALL
};
enum browse_type_enum {
BROWSE_NORMAL,
BROWSE_FIND_MAX_INST,
BROWSE_NUM_OF_ENTRIES
};
enum {
CMD_GET_VALUE,
CMD_GET_NAME,
@ -416,12 +431,11 @@ enum {
__INDX_DYNAMIC_MAX
};
char *update_instance(char *max_inst, int argc, ...);
char *update_instance_alias(int action, char **last_inst, char **max_inst, void *argv[]);
char *update_instance_without_section(int action, char **last_inst, char **max_inst, void *argv[]);
int get_number_of_entries(struct dmctx *ctx, void *data, char *instance, int (*browseinstobj)(struct dmctx *ctx, struct dmnode *node, void *data, char *instance));
char *handle_instance(struct dmctx *dmctx, DMNODE *parent_node, struct uci_section *s, char *inst_opt, char *alias_opt);
char *handle_instance_without_section(struct dmctx *dmctx, DMNODE *parent_node, int inst_nbr);
int get_empty(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value);
void add_list_parameter(struct dmctx *ctx, char *param_name, char *param_data, char *param_type, char *additional_data);
void api_del_list_parameter(struct dm_parameter *dm_parameter);
void free_all_list_parameter(struct dmctx *ctx);
void free_all_set_list_tmp(struct dmctx *ctx);
void add_list_fault_param(struct dmctx *ctx, char *param, int fault);
@ -442,11 +456,6 @@ int dm_entry_list_operates(struct dmctx *ctx);
int dm_entry_operate(struct dmctx *dmctx);
int dm_entry_list_events(struct dmctx *dmctx);
int dm_browse_last_access_path(char *path, size_t len);
char *get_last_instance(char *package, char *section, char *opt_inst);
char *get_last_instance_bbfdm(char *package, char *section, char *opt_inst);
char *get_last_instance_lev2_bbfdm_dmmap_opt(char* dmmap_package, char *section, char *opt_inst, char *opt_check, char *value_check);
char *get_last_instance_lev2_bbfdm(char *package, char *section, char* dmmap_package, char *opt_inst, char *opt_check, char *value_check);
char *handle_update_instance(int instance_ranck, struct dmctx *ctx, char **max_inst, char * (*up_instance)(int action, char **last_inst, char **max_inst, void *argv[]), int argc, ...);
int dm_link_inst_obj(struct dmctx *dmctx, DMNODE *parent_node, void *data, char *instance);
void dm_exclude_obj(struct dmctx *dmctx, DMNODE *parent_node, DMOBJ *entryobj, char *data);
void dm_check_dynamic_obj(struct dmctx *dmctx, DMNODE *parent_node, DMOBJ *entryobj, char *full_obj, char *obj, DMOBJ **root_entry, int *obj_found);
@ -455,6 +464,15 @@ int get_obj_idx_dynamic_array(DMOBJ **entryobj);
int get_leaf_idx_dynamic_array(DMLEAF **entryleaf);
void free_dm_browse_node_dynamic_object_tree(DMNODE *parent_node, DMOBJ *entryobj);
char *update_instance_alias(int action, char **last_inst, char **max_inst, void *argv[]);
char *update_instance(char *max_inst, int argc, ...);
__attribute__ ((deprecated)) char *update_instance_without_section(int action, char **last_inst, char **max_inst, void *argv[]);
__attribute__ ((deprecated)) char *get_last_instance(char *package, char *section, char *opt_inst);
__attribute__ ((deprecated)) char *get_last_instance_bbfdm(char *package, char *section, char *opt_inst);
__attribute__ ((deprecated)) char *get_last_instance_lev2_bbfdm_dmmap_opt(char* dmmap_package, char *section, char *opt_inst, char *opt_check, char *value_check);
__attribute__ ((deprecated)) char *get_last_instance_lev2_bbfdm(char *package, char *section, char* dmmap_package, char *opt_inst, char *opt_check, char *value_check);
__attribute__ ((deprecated)) char *handle_update_instance(int instance_ranck, struct dmctx *ctx, char **max_inst, char * (*up_instance)(int action, char **last_inst, char **max_inst, void *argv[]), int argc, ...);
static inline int DM_LINK_INST_OBJ(struct dmctx *dmctx, DMNODE *parent_node, void *data, char *instance)
{
dmctx->faultcode = dm_link_inst_obj(dmctx, parent_node, data, instance);

View file

@ -217,48 +217,6 @@ int dmcmd_no_wait(char *cmd, int n, ...)
return 0;
}
void update_section_list(char *config, char *section, char *option, int number, char *filter, char *option1, char *val1, char *option2, char *val2)
{
struct uci_section *s = NULL;
int i = 0;
if (strcmp(config, DMMAP) == 0) {
if (option) {
uci_path_foreach_option_eq(bbfdm, config, section, option, filter, s) {
return;
}
} else {
uci_path_foreach_sections(bbfdm, config, section, s) {
return;
}
}
while (i < number) {
dmuci_add_section_bbfdm(config, section, &s);
dmuci_set_value_by_section_bbfdm(s, option, filter);
dmuci_set_value_by_section_bbfdm(s, option1, val1);
dmuci_set_value_by_section_bbfdm(s, option2, val2);
i++;
}
} else {
if (option) {
uci_foreach_option_eq(config, section, option, filter, s) {
return;
}
} else {
uci_foreach_sections(config, section, s) {
return;
}
}
while (i < number) {
dmuci_add_section(config, section, &s);
dmuci_set_value_by_section(s, option, filter);
dmuci_set_value_by_section(s, option1, val1);
dmuci_set_value_by_section(s, option2, val2);
i++;
}
}
}
void hex_to_ip(char *address, char *ret)
{
unsigned int ip[4] = {0};
@ -374,28 +332,28 @@ void synchronize_specific_config_sections_with_dmmap(char *package, char *sectio
uci_path_foreach_sections_safe(bbfdm, dmmap_package, section_type, stmp, s) {
dmuci_get_value_by_section_string(s, "section_name", &v);
if (get_origin_section_from_config(package, section_type, v) == NULL)
dmuci_delete_by_section_unnamed_bbfdm(s, NULL, NULL);
dmuci_delete_by_section(s, NULL, NULL);
}
}
void synchronize_specific_config_sections_with_dmmap_eq(char *package, char *section_type, char *dmmap_package,char* option_name, char* option_value, struct list_head *dup_list)
void synchronize_specific_config_sections_with_dmmap_eq(char *package, char *section_type, char *dmmap_package, char* option_name, char* option_value, struct list_head *dup_list)
{
struct uci_section *s, *stmp, *dmmap_sect;
struct uci_section *s, *stmp, *dmmap_sec;
char *v;
uci_foreach_option_eq(package, section_type, option_name, option_value, s) {
/*
* create/update corresponding dmmap section that have same config_section link and using param_value_array
*/
if ((dmmap_sect = get_dup_section_in_dmmap(dmmap_package, section_type, section_name(s))) == NULL) {
dmuci_add_section_bbfdm(dmmap_package, section_type, &dmmap_sect);
dmuci_set_value_by_section_bbfdm(dmmap_sect, "section_name", section_name(s));
if ((dmmap_sec = get_dup_section_in_dmmap(dmmap_package, section_type, section_name(s))) == NULL) {
dmuci_add_section_bbfdm(dmmap_package, section_type, &dmmap_sec);
dmuci_set_value_by_section_bbfdm(dmmap_sec, "section_name", section_name(s));
}
/*
* Add system and dmmap sections to the list
*/
add_dmmap_config_dup_list(dup_list, s, dmmap_sect);
add_dmmap_config_dup_list(dup_list, s, dmmap_sec);
}
/*
@ -408,7 +366,7 @@ void synchronize_specific_config_sections_with_dmmap_eq(char *package, char *sec
}
}
void synchronize_specific_config_sections_with_dmmap_cont(char *package, char *section_type, char *dmmap_package,char* option_name, char* option_value, struct list_head *dup_list)
void synchronize_specific_config_sections_with_dmmap_cont(char *package, char *section_type, char *dmmap_package, char* option_name, char* option_value, struct list_head *dup_list)
{
struct uci_section *uci_s, *stmp, *dmmap_sect;
char *v;
@ -451,12 +409,10 @@ void add_sysfs_section_list(struct list_head *dup_list, struct uci_section *dmma
int synchronize_system_folders_with_dmmap_opt(char *sysfsrep, char *dmmap_package, char *dmmap_section, char *opt_name, char* inst_opt, struct list_head *dup_list)
{
struct uci_section *s, *stmp, *dmmap_sect;
struct uci_section *s = NULL, *stmp = NULL, *dmmap_sect = NULL;
char sysfs_rep_path[512];
DIR *dir;
struct dirent *ent;
char *v, *sysfs_rep_path, *instance = NULL;
struct sysfs_dmsection *p, *tmp;
LIST_HEAD(dup_list_no_inst);
sysfs_foreach_file(sysfsrep, dir, ent) {
if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0)
@ -465,39 +421,29 @@ int synchronize_system_folders_with_dmmap_opt(char *sysfsrep, char *dmmap_packag
/*
* create/update corresponding dmmap section that have same config_section link and using param_value_array
*/
dmasprintf(&sysfs_rep_path, "%s/%s", sysfsrep, ent->d_name);
snprintf(sysfs_rep_path, sizeof(sysfs_rep_path), "%s/%s", sysfsrep, ent->d_name);
if ((dmmap_sect = get_dup_section_in_dmmap_opt(dmmap_package, dmmap_section, opt_name, sysfs_rep_path)) == NULL) {
dmuci_add_section_bbfdm(dmmap_package, dmmap_section, &dmmap_sect);
dmuci_set_value_by_section_bbfdm(dmmap_sect, opt_name, sysfs_rep_path);
}
dmuci_get_value_by_section_string(dmmap_sect, inst_opt, &instance);
/*
* Add system and dmmap sections to the list
*/
if (instance == NULL || *instance == '\0')
add_sysfs_section_list(&dup_list_no_inst, dmmap_sect, ent->d_name, sysfs_rep_path);
else
add_sysfs_section_list(dup_list, dmmap_sect, ent->d_name, sysfs_rep_path);
}
if (dir)
closedir(dir);
/*
* fusion two lists
*/
list_for_each_entry_safe(p, tmp, &dup_list_no_inst, list)
list_move_tail(&p->list, dup_list);
/*
* Delete unused dmmap sections
*/
uci_path_foreach_sections_safe(bbfdm, dmmap_package, dmmap_section, stmp, s) {
dmuci_get_value_by_section_string(s, opt_name, &v);
if (!folder_exists(v))
dmuci_delete_by_section_unnamed_bbfdm(s, NULL, NULL);
char *opt_val = NULL;
dmuci_get_value_by_section_string(s, opt_name, &opt_val);
if (!folder_exists(opt_val))
dmuci_delete_by_section(s, NULL, NULL);
}
return 0;
}
@ -568,7 +514,7 @@ char *check_create_dmmap_package(const char *dmmap_package)
return path;
}
int is_section_unnamed(char *section_name)
__attribute__ ((deprecated)) int is_section_unnamed(char *section_name)
{
int i;
@ -583,7 +529,7 @@ int is_section_unnamed(char *section_name)
return 1;
}
void add_dmmap_list_section(struct list_head *dup_list, char* section_name, char* instance)
static void add_dmmap_list_section(struct list_head *dup_list, char* section_name, char* instance)
{
struct dmmap_sect *dmsect;
@ -593,7 +539,7 @@ void add_dmmap_list_section(struct list_head *dup_list, char* section_name, char
dmasprintf(&dmsect->instance, "%s", instance);
}
void delete_sections_save_next_sections(char* dmmap_package, char *section_type, char *instancename, char *section_name, int instance, struct list_head *dup_list)
__attribute__ ((deprecated)) void delete_sections_save_next_sections(char* dmmap_package, char *section_type, char *instancename, char *section_name, int instance, struct list_head *dup_list)
{
struct uci_section *s, *stmp;
char *v = NULL, *lsectname = NULL, *tmp = NULL;
@ -625,7 +571,7 @@ void delete_sections_save_next_sections(char* dmmap_package, char *section_type,
}
}
void update_dmmap_sections(struct list_head *dup_list, char *instancename, char* dmmap_package, char *section_type)
__attribute__ ((deprecated)) void update_dmmap_sections(struct list_head *dup_list, char *instancename, char* dmmap_package, char *section_type)
{
struct uci_section *dm_sect = NULL;
struct dmmap_sect *p = NULL;

View file

@ -226,7 +226,6 @@ bool is_strword_in_optionvalue(char *optionvalue, char *str);
void remove_new_line(char *buf);
int dmcmd(char *cmd, int n, ...);
int dmcmd_no_wait(char *cmd, int n, ...);
void update_section_list(char *config, char *section, char *option, int number, char *filter, char *option1, char *val1, char *option2, char *val2);
void hex_to_ip(char *address, char *ret);
void add_dmmap_config_dup_list(struct list_head *dup_list, struct uci_section *config_section, struct uci_section *dmmap_section);
void free_dmmap_config_dup_list(struct list_head *dup_list);
@ -243,9 +242,9 @@ void get_config_section_of_dmmap_section(char* package, char* section_type, char
int adm_entry_get_linker_param(struct dmctx *ctx, char *param, char *linker, char **value);
int adm_entry_get_linker_value(struct dmctx *ctx, char *param, char **value);
char *check_create_dmmap_package(const char *dmmap_package);
int is_section_unnamed(char *section_name);
void delete_sections_save_next_sections(char* dmmap_package, char *section_type, char *instancename, char *section_name, int instance, struct list_head *dup_list);
void update_dmmap_sections(struct list_head *dup_list, char *instancename, char* dmmap_package, char *section_type);
__attribute__ ((deprecated)) int is_section_unnamed(char *section_name);
__attribute__ ((deprecated)) void delete_sections_save_next_sections(char* dmmap_package, char *section_type, char *instancename, char *section_name, int instance, struct list_head *dup_list);
__attribute__ ((deprecated)) void update_dmmap_sections(struct list_head *dup_list, char *instancename, char* dmmap_package, char *section_type);
unsigned char isdigit_str(char *str);
char *dm_strword(char *src, char *str);
char **strsplit(const char* str, const char* delim, size_t* numtokens);

View file

@ -106,6 +106,12 @@ struct package_change
section != NULL; \
section = dmuci_walk_section(package, stype, option, val, CMP_OPTION_CONTAINING, NULL, section, GET_NEXT_SECTION))
#define uci_foreach_option_cont_safe(package, stype, option, val, _tmp, section) \
for (section = dmuci_walk_section(package, stype, option, val, CMP_OPTION_CONTAINING, NULL, NULL, GET_FIRST_SECTION), \
_tmp = (section) ? dmuci_walk_section(package, stype, option, val, CMP_OPTION_CONTAINING, NULL, section, GET_NEXT_SECTION) : NULL; \
section != NULL; \
section = _tmp, _tmp = (section) ? dmuci_walk_section(package, stype, option, val, CMP_OPTION_CONTAINING, NULL, section, GET_NEXT_SECTION) : NULL)
#define uci_foreach_option_cont_word(package, stype, option, val, section) \
for (section = dmuci_walk_section(package, stype, option, val, CMP_OPTION_CONT_WORD, NULL, NULL, GET_FIRST_SECTION); \
section != NULL; \
@ -255,15 +261,6 @@ int dmuci_delete_by_section_##UCI_PATH(struct uci_section *s, char *option, char
uci_ctx = save_uci_ctx; \
return res; \
}\
int dmuci_delete_by_section_unnamed_##UCI_PATH(struct uci_section *s, char *option, char *value)\
{\
struct uci_context *save_uci_ctx; \
save_uci_ctx = uci_ctx; \
uci_ctx = uci_ctx_##UCI_PATH; \
int res = dmuci_delete_by_section_unnamed(s, option, value); \
uci_ctx = save_uci_ctx; \
return res; \
}\
struct uci_section *dmuci_walk_section_##UCI_PATH(char *package, char *stype, void *arg1, void *arg2, int cmp , int (*filter)(struct uci_section *s, void *value), struct uci_section *prev_section, int walk)\
{\
struct uci_context *save_uci_ctx; \
@ -309,6 +306,15 @@ int dmuci_save_package_##UCI_PATH(char *package) \
uci_ctx = save_uci_ctx; \
return res; \
}\
int dmuci_delete_by_section_unnamed_##UCI_PATH(struct uci_section *s, char *option, char *value)\
{\
struct uci_context *save_uci_ctx; \
save_uci_ctx = uci_ctx; \
uci_ctx = uci_ctx_##UCI_PATH; \
int res = dmuci_delete_by_section_unnamed(s, option, value); \
uci_ctx = save_uci_ctx; \
return res; \
}\
int dmuci_init(void);
void dmuci_exit(void);

View file

@ -29,17 +29,16 @@ DM_MAP_OBJ tDynamicObj[] = {
**************************************************************/
static int browseManagementServerInformParameterInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
{
char *inst = NULL, *max_inst = NULL;
struct dmmap_dup *p = NULL;
char *inst = NULL;
LIST_HEAD(dup_list);
synchronize_specific_config_sections_with_dmmap("cwmp", "inform_extra", "dmmap_cwmp", &dup_list);
list_for_each_entry(p, &dup_list, list) {
inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,
p->dmmap_section, "inform_instance", "inform_alias");
inst = handle_instance(dmctx, parent_node, p->dmmap_section, "inform_instance", "inform_alias");
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, inst) == DM_STOP)
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p, inst) == DM_STOP)
break;
}
free_dmmap_config_dup_list(&dup_list);
@ -53,34 +52,31 @@ static int addObjManagementServerInformParameter(char *refparam, struct dmctx *c
{
struct uci_section *s = NULL, *dmmap_s = NULL;
char *last_inst = get_last_instance_bbfdm("dmmap_cwmp", "inform_extra", "inform_instance");
dmuci_add_section("cwmp", "inform_extra", &s);
dmuci_add_section_bbfdm("dmmap_cwmp", "inform_extra", &dmmap_s);
dmuci_set_value_by_section(dmmap_s, "section_name", section_name(s));
*instance = update_instance(last_inst, 2, dmmap_s, "inform_instance");
dmuci_set_value_by_section(dmmap_s, "inform_instance", *instance);
return 0;
}
static int delObjManagementServerInformParameter(char *refparam, struct dmctx *ctx, void *data, char *instance, unsigned char del_action)
{
struct uci_section *s = NULL, *stmp = NULL, *dmmap_s = NULL;
struct uci_section *s = NULL, *stmp = NULL;
switch (del_action) {
case DEL_INST:
get_dmmap_section_of_config_section("dmmap_cwmp", "inform_extra", section_name((struct uci_section *)data), &dmmap_s);
dmuci_delete_by_section_unnamed_bbfdm(dmmap_s, NULL, NULL);
dmuci_delete_by_section((struct uci_section *)data, NULL, NULL);
dmuci_delete_by_section(((struct dmmap_dup *)data)->config_section, NULL, NULL);
dmuci_delete_by_section(((struct dmmap_dup *)data)->dmmap_section, NULL, NULL);
break;
case DEL_ALL:
uci_foreach_sections_safe("cwmp", "inform_extra", stmp, s) {
struct uci_section *dmmap_s = NULL;
get_dmmap_section_of_config_section("dmmap_cwmp", "inform_extra", section_name(s), &dmmap_s);
dmuci_delete_by_section(dmmap_s, NULL, NULL);
dmuci_delete_by_section(s, NULL, NULL);
}
break;
}
@ -115,7 +111,7 @@ static int set_ManagementServer_EnableCWMP(char *refparam, struct dmctx *ctx, vo
static int get_ManagementServerInformParameter_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "enabled", "1");
*value = dmuci_get_value_by_section_fallback_def(((struct dmmap_dup *)data)->config_section, "enabled", "1");
return 0;
}
@ -130,7 +126,7 @@ static int set_ManagementServerInformParameter_Enable(char *refparam, struct dmc
break;
case VALUESET:
string_to_bool(value, &b);
dmuci_set_value_by_section((struct uci_section *)data, "enabled", b ? "1" : "0");
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "enabled", b ? "1" : "0");
break;
}
return 0;
@ -140,7 +136,7 @@ static int get_ManagementServerInformParameter_Alias(char *refparam, struct dmct
{
struct uci_section *dmmap_section = NULL;
get_dmmap_section_of_config_section("dmmap_cwmp", "inform_extra", section_name((struct uci_section *)data), &dmmap_section);
get_dmmap_section_of_config_section("dmmap_cwmp", "inform_extra", section_name(((struct dmmap_dup *)data)->config_section), &dmmap_section);
dmuci_get_value_by_section_string(dmmap_section, "inform_alias", value);
if ((*value)[0] == '\0')
dmasprintf(value, "cpe-%s", instance);
@ -157,7 +153,7 @@ static int set_ManagementServerInformParameter_Alias(char *refparam, struct dmct
return FAULT_9007;
break;
case VALUESET:
get_dmmap_section_of_config_section("dmmap_cwmp", "inform_extra", section_name((struct uci_section *)data), &dmmap_section);
get_dmmap_section_of_config_section("dmmap_cwmp", "inform_extra", section_name(((struct dmmap_dup *)data)->config_section), &dmmap_section);
dmuci_set_value_by_section(dmmap_section, "inform_alias", value);
break;
}
@ -166,7 +162,7 @@ static int set_ManagementServerInformParameter_Alias(char *refparam, struct dmct
static int get_ManagementServerInformParameter_ParameterName(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string((struct uci_section *)data, "parameter", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "parameter", value);
return 0;
}
@ -178,7 +174,7 @@ static int set_ManagementServerInformParameter_ParameterName(char *refparam, str
return FAULT_9007;
break;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "parameter", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "parameter", value);
break;
}
return 0;
@ -186,7 +182,7 @@ static int set_ManagementServerInformParameter_ParameterName(char *refparam, str
static int get_ManagementServerInformParameter_EventList(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
dmuci_get_value_by_section_string((struct uci_section *)data, "events", value);
dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, "events", value);
return 0;
}
@ -198,7 +194,7 @@ static int set_ManagementServerInformParameter_EventList(char *refparam, struct
return FAULT_9007;
break;
case VALUESET:
dmuci_set_value_by_section((struct uci_section *)data, "events", value);
dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, "events", value);
break;
}
return 0;

View file

@ -18,6 +18,18 @@ static int setup(void **state)
return 0;
}
static int setup_alias(void **state)
{
struct dmctx *ctx = calloc(1, sizeof(struct dmctx));
if (!ctx)
return -1;
dm_ctx_init(ctx, INSTANCE_MODE_ALIAS);
*state = ctx;
return 0;
}
static int teardown_commit(void **state)
{
struct dmctx *ctx = (struct dmctx *) *state;
@ -117,7 +129,6 @@ static void test_api_bbfdm_get_set_json_parameter(void **state)
// get value ==> expected "0" error
fault = dm_entry_param_method(ctx, CMD_GET_VALUE, "Device.WiFi.X_IOPSYS_EU_Radio.1.Noise", NULL, NULL);
printf("fault=%d \n", fault);
assert_int_equal(fault, 0);
// validate parameter : name, type, value
@ -184,6 +195,68 @@ static void test_api_bbfdm_get_set_library_parameter(void **state)
validate_parameter(ctx, "Device.ManagementServer.EnableCWMP", "0", "xsd:boolean");
}
static void test_api_bbfdm_get_set_standard_parameter_alias(void **state)
{
struct dmctx *ctx = (struct dmctx *) *state;
int fault = 0;
// get value ==> expected "0" error
fault = dm_entry_param_method(ctx, CMD_GET_VALUE, "Device.WiFi.Radio.[cpe-1].Channel", NULL, NULL);
assert_int_equal(fault, 0);
// validate parameter : name, type, value
validate_parameter(ctx, "Device.WiFi.Radio.[cpe-1].Channel", "64", "xsd:unsignedInt");
// Set Wrong Value ==> expected "9007" error
fault = dm_entry_param_method(ctx, CMD_SET_VALUE, "Device.WiFi.Radio.[cpe-1].Channel", "64t", NULL);
assert_int_equal(fault, FAULT_9007);
// set value ==> expected "0" error
fault = dm_entry_param_method(ctx, CMD_SET_VALUE, "Device.WiFi.Radio.[cpe-1].Channel", "84", NULL);
assert_int_equal(fault, 0);
// apply value ==> expected "0" error
fault = dm_entry_apply(ctx, CMD_SET_VALUE, "test_key");
assert_int_equal(fault, 0);
// get value ==> expected "0" error
fault = dm_entry_param_method(ctx, CMD_GET_VALUE, "Device.WiFi.Radio.[cpe-1].Channel", NULL, NULL);
assert_int_equal(fault, 0);
// validate parameter after setting to 64: name, type, value
validate_parameter(ctx, "Device.WiFi.Radio.[cpe-1].Channel", "84", "xsd:unsignedInt");
// set value ==> expected "0" error
fault = dm_entry_param_method(ctx, CMD_SET_VALUE, "Device.WiFi.Radio.[cpe-1].Alias", "iopsys_test", NULL);
assert_int_equal(fault, 0);
// apply value ==> expected "0" error
fault = dm_entry_apply(ctx, CMD_SET_VALUE, "test_key");
assert_int_equal(fault, 0);
// get value ==> expected "0" error
fault = dm_entry_param_method(ctx, CMD_GET_VALUE, "Device.WiFi.Radio.[iopsys_test].Alias", NULL, NULL);
assert_int_equal(fault, 0);
// validate parameter after setting to 64: name, type, value
validate_parameter(ctx, "Device.WiFi.Radio.[iopsys_test].Alias", "iopsys_test", "xsd:string");
// set value ==> expected "0" error
fault = dm_entry_param_method(ctx, CMD_SET_VALUE, "Device.WiFi.Radio.[iopsys_test].Channel", "74", NULL);
assert_int_equal(fault, 0);
// apply value ==> expected "0" error
fault = dm_entry_apply(ctx, CMD_SET_VALUE, "test_key");
assert_int_equal(fault, 0);
// get value ==> expected "0" error
fault = dm_entry_param_method(ctx, CMD_GET_VALUE, "Device.WiFi.Radio.[iopsys_test].Channel", NULL, NULL);
assert_int_equal(fault, 0);
// validate parameter after setting to 64: name, type, value
validate_parameter(ctx, "Device.WiFi.Radio.[iopsys_test].Channel", "74", "xsd:unsignedInt");
}
static void test_api_bbfdm_add_del_standard_object(void **state)
{
struct dmctx *ctx = (struct dmctx *) *state;
@ -377,6 +450,7 @@ int main(void)
cmocka_unit_test_setup_teardown(test_api_bbfdm_get_set_standard_parameter, setup, teardown_commit),
cmocka_unit_test_setup_teardown(test_api_bbfdm_get_set_json_parameter, setup, teardown_commit),
cmocka_unit_test_setup_teardown(test_api_bbfdm_get_set_library_parameter, setup, teardown_commit),
cmocka_unit_test_setup_teardown(test_api_bbfdm_get_set_standard_parameter_alias, setup_alias, teardown_commit),
// Add/Delete Object method test cases
cmocka_unit_test_setup_teardown(test_api_bbfdm_add_del_standard_object, setup, teardown_commit),

View file

@ -23,6 +23,18 @@ static int setup(void **state)
return 0;
}
static int setup_alias(void **state)
{
struct dmctx *ctx = calloc(1, sizeof(struct dmctx));
if (!ctx)
return -1;
dm_ctx_init(ctx, INSTANCE_MODE_ALIAS);
*state = ctx;
return 0;
}
static int teardown_commit(void **state)
{
struct dmctx *ctx = (struct dmctx *) *state;
@ -116,6 +128,32 @@ static void test_api_bbfdm_get_value_wrong_parameter_path(void **state)
assert_true(&first_entry->list == &ctx->list_parameter);
}
static void test_api_bbfdm_get_value_object_alias(void **state)
{
struct dmctx *ctx = (struct dmctx *) *state;
struct dm_parameter *first_entry;
int fault = 0;
fault = dm_entry_param_method(ctx, CMD_GET_VALUE, "Device.", NULL, NULL);
assert_int_equal(fault, 0);
first_entry = list_first_entry(&ctx->list_parameter, struct dm_parameter, list);
assert_true(&first_entry->list != &ctx->list_parameter);
}
static void test_api_bbfdm_get_value_parameter_alias(void **state)
{
struct dmctx *ctx = (struct dmctx *) *state;
struct dm_parameter *first_entry;
int fault = 0;
fault = dm_entry_param_method(ctx, CMD_GET_VALUE, "Device.WiFi.Radio.[cpe-1].Alias", NULL, NULL);
assert_int_equal(fault, 0);
first_entry = list_first_entry(&ctx->list_parameter, struct dm_parameter, list);
assert_true(&first_entry->list != &ctx->list_parameter);
}
static void test_api_bbfdm_get_name_object(void **state)
{
struct dmctx *ctx = (struct dmctx *) *state;
@ -194,6 +232,19 @@ static void test_api_bbfdm_get_name_wrong_next_level(void **state)
assert_true(&first_entry->list == &ctx->list_parameter);
}
static void test_api_bbfdm_get_name_parameter_alias(void **state)
{
struct dmctx *ctx = (struct dmctx *) *state;
struct dm_parameter *first_entry;
int fault = 0;
fault = dm_entry_param_method(ctx, CMD_GET_NAME, "Device.WiFi.Radio.[cpe-1].Enable", "false", NULL);
assert_int_equal(fault, 0);
first_entry = list_first_entry(&ctx->list_parameter, struct dm_parameter, list);
assert_true(&first_entry->list != &ctx->list_parameter);
}
static void test_api_bbfdm_set_value_object(void **state)
{
struct dmctx *ctx = (struct dmctx *) *state;
@ -275,6 +326,22 @@ static void test_api_bbfdm_set_value_parameter_wrong_value(void **state)
assert_true(&first_fault->list != &ctx->list_fault_param);
}
static void test_api_bbfdm_set_value_parameter_alias(void **state)
{
struct dmctx *ctx = (struct dmctx *) *state;
struct param_fault *first_fault;
int fault = 0;
fault = dm_entry_param_method(ctx, CMD_SET_VALUE, "Device.Users.User.[cpe-1].Username", "test", NULL);
assert_int_equal(fault, 0);
first_fault = list_first_entry(&ctx->list_fault_param, struct param_fault, list);
assert_true(&first_fault->list == &ctx->list_fault_param);
fault = dm_entry_apply(ctx, CMD_SET_VALUE, "test_key");
assert_int_equal(fault, 0);
}
static void test_api_bbfdm_add_object(void **state)
{
struct dmctx *ctx = (struct dmctx *) *state;
@ -657,6 +724,8 @@ int main(void)
cmocka_unit_test_setup_teardown(test_api_bbfdm_get_value_empty, setup, teardown_commit),
cmocka_unit_test_setup_teardown(test_api_bbfdm_get_value_wrong_object_path, setup, teardown_revert),
cmocka_unit_test_setup_teardown(test_api_bbfdm_get_value_wrong_parameter_path, setup, teardown_revert),
cmocka_unit_test_setup_teardown(test_api_bbfdm_get_value_object_alias, setup_alias, teardown_commit),
cmocka_unit_test_setup_teardown(test_api_bbfdm_get_value_parameter_alias, setup_alias, teardown_commit),
// Get Name method test cases
cmocka_unit_test_setup_teardown(test_api_bbfdm_get_name_object, setup, teardown_commit),
@ -665,6 +734,7 @@ int main(void)
cmocka_unit_test_setup_teardown(test_api_bbfdm_get_name_wrong_object_path, setup, teardown_revert),
cmocka_unit_test_setup_teardown(test_api_bbfdm_get_name_without_next_level, setup, teardown_revert),
cmocka_unit_test_setup_teardown(test_api_bbfdm_get_name_wrong_next_level, setup, teardown_revert),
cmocka_unit_test_setup_teardown(test_api_bbfdm_get_name_parameter_alias, setup_alias, teardown_commit),
// Set Value method test cases
cmocka_unit_test_setup_teardown(test_api_bbfdm_set_value_object, setup, teardown_revert),
@ -673,6 +743,7 @@ int main(void)
cmocka_unit_test_setup_teardown(test_api_bbfdm_set_value_wrong_parameter_path, setup, teardown_revert),
cmocka_unit_test_setup_teardown(test_api_bbfdm_set_value_parameter_non_writable, setup, teardown_revert),
cmocka_unit_test_setup_teardown(test_api_bbfdm_set_value_parameter_wrong_value, setup, teardown_revert),
cmocka_unit_test_setup_teardown(test_api_bbfdm_set_value_parameter_alias, setup_alias, teardown_commit),
// Add Object method test cases
cmocka_unit_test_setup_teardown(test_api_bbfdm_add_object, setup, teardown_commit),

View file

@ -347,7 +347,7 @@ def hprintheaderOBJS(objname):
def cprinttopfile(fp, filename):
print("/*", file=fp)
print(" * Copyright (C) 2020 iopsys Software Solutions AB", file=fp)
print(" * Copyright (C) 2021 iopsys Software Solutions AB", file=fp)
print(" *", file=fp)
print(" * This program is free software; you can redistribute it and/or modify", file=fp)
print(" * it under the terms of the GNU Lesser General Public License version 2.1", file=fp)
@ -362,7 +362,7 @@ def cprinttopfile(fp, filename):
def hprinttopfile(fp, filename):
print("/*", file=fp)
print(" * Copyright (C) 2020 iopsys Software Solutions AB", file=fp)
print(" * Copyright (C) 2021 iopsys Software Solutions AB", file=fp)
print(" *", file=fp)
print(" * This program is free software; you can redistribute it and/or modify", file=fp)
print(" * it under the terms of the GNU Lesser General Public License version 2.1", file=fp)
@ -393,10 +393,8 @@ def cprintAddDelObj(faddobj, fdelobj, name, mappingobj, _dmobject):
dm_type, file, sectiontype, dmmapfile, _path, _ref = get_mapping_obj(
mappingobj)
if dm_type == "uci":
print(" struct uci_section *dmmap = NULL, *s = NULL;", file=fp)
print(" struct uci_section *s = NULL, *dmmap = NULL;", file=fp)
print("", file=fp)
print(" char *inst = get_last_instance_bbfdm(\"%s\", \"%s\", \"%s\");" %
(dmmapfile, sectiontype, name+"instance"), file=fp)
print(" dmuci_add_section(\"%s\", \"%s\", &s);" %
(file, sectiontype), file=fp)
print(" //dmuci_set_value_by_section(s, \"option\", \"value\");", file=fp)
@ -405,8 +403,8 @@ def cprintAddDelObj(faddobj, fdelobj, name, mappingobj, _dmobject):
(dmmapfile, sectiontype), file=fp)
print(
" dmuci_set_value_by_section(dmmap, \"section_name\", section_name(s));", file=fp)
print(" *instance = update_instance(inst, 2, dmmap, \"%s\");" %
(name+"instance"), file=fp)
print(
" dmuci_set_value_by_section(dmmap, \"%s\", *instance);" % (name+"instance"), file=fp)
else:
print(" //TODO", file=fp)
print(" return 0;", file=fp)
@ -417,39 +415,27 @@ def cprintAddDelObj(faddobj, fdelobj, name, mappingobj, _dmobject):
if mappingobj is not None:
if dm_type == "uci":
print(
" struct uci_section *s = NULL, *ss = NULL, *dmmap_section = NULL;", file=fp)
print(" int found = 0;", file=fp)
" struct uci_section *s = NULL, *stmp = NULL", file=fp)
print("", file=fp)
print(" switch (del_action) {", file=fp)
if mappingobj is not None:
if dm_type == "uci":
print(" case DEL_INST:", file=fp)
print(" get_dmmap_section_of_config_section(\"%s\", \"%s\", section_name((struct uci_section *)data), &dmmap_section);" %
(dmmapfile, sectiontype), file=fp)
print(" if (dmmap_section != NULL)", file=fp)
print(" dmuci_delete_by_section(dmmap_section, NULL, NULL);", file=fp)
print(
" dmuci_delete_by_section((struct uci_section *)data, NULL, NULL);", file=fp)
" dmuci_delete_by_section(((struct dmmap_dup *)data)->config_section, NULL, NULL);", file=fp)
print(
" dmuci_delete_by_section(((struct dmmap_dup *)data)->dmmap_section, NULL, NULL);", file=fp)
print(" break;", file=fp)
print(" case DEL_ALL:", file=fp)
print(" uci_foreach_sections(\"%s\", \"%s\", s) {" % (
print(" uci_foreach_sections_safe(\"%s\", \"%s\", stmp, s) {" % (
file, sectiontype), file=fp)
print(" if (found != 0) {", file=fp)
print(" get_dmmap_section_of_config_section(\"%s\", \"%s\", section_name(ss), &dmmap_section);" % (
print(" struct uci_section *dmmap_section = NULL;", file=fp)
print("", file=fp)
print(" get_dmmap_section_of_config_section(\"%s\", \"%s\", section_name(s), &dmmap_section);" % (
dmmapfile, sectiontype), file=fp)
print(" if (dmmap_section != NULL)", file=fp)
print(" dmuci_delete_by_section(dmmap_section, NULL, NULL);", file=fp)
print(" dmuci_delete_by_section(ss, NULL, NULL);", file=fp)
print(" }", file=fp)
print(" ss = s;", file=fp)
print(" found++;", file=fp)
print(" }", file=fp)
print(" if (ss != NULL) {", file=fp)
print(" get_dmmap_section_of_config_section(\"%s\", \"%s\", section_name(ss), &dmmap_section);" % (
dmmapfile, sectiontype), file=fp)
print(" if (dmmap_section != NULL)", file=fp)
print(" dmuci_delete_by_section(dmmap_section, NULL, NULL);", file=fp)
print(" dmuci_delete_by_section(ss, NULL, NULL);", file=fp)
print("", file=fp)
print(" dmuci_delete_by_section(s, NULL, NULL);", file=fp)
print(" }", file=fp)
print(" break;", file=fp)
else:
@ -488,8 +474,8 @@ def cprintBrowseObj(fbrowse, name, mappingobj, dmobject):
############################## UCI ########################################
if dm_type == "uci":
print(" char *inst = NULL, *max_inst = NULL;", file=fp)
print(" struct dmmap_dup *p = NULL;", file=fp)
print(" char *inst = NULL;", file=fp)
print(" LIST_HEAD(dup_list);", file=fp)
print("", file=fp)
print(" synchronize_specific_config_sections_with_dmmap(\"%s\", \"%s\", \"%s\", &dup_list);" % (
@ -497,11 +483,10 @@ def cprintBrowseObj(fbrowse, name, mappingobj, dmobject):
print(" list_for_each_entry(p, &dup_list, list) {", file=fp)
print("", file=fp)
print(
" inst = handle_update_instance(1, dmctx, &max_inst, update_instance_alias, 3,", file=fp)
print(" p->dmmap_section, \"%s\", \"%s\");" %
" inst = handle_instance(dmctx, parent_node, p->dmmap_section, \"%s\", \"%s\");" %
(name+"instance", name+"alias"), file=fp)
print("", file=fp)
print(" if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p->config_section, inst) == DM_STOP)", file=fp)
print(" if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)p, inst) == DM_STOP)", file=fp)
print(" break;", file=fp)
print(" }", file=fp)
print(" free_dmmap_config_dup_list(&dup_list);", file=fp)
@ -509,7 +494,7 @@ def cprintBrowseObj(fbrowse, name, mappingobj, dmobject):
############################## UBUS ########################################
elif dm_type == "ubus":
print(" json_object *res = NULL, *obj = NULL, *arrobj = NULL;", file=fp)
print(" char *inst = NULL, *max_inst = NULL;", file=fp)
print(" char *inst = NULL;", file=fp)
print(" int id = 0, i = 0;", file=fp)
print("", file=fp)
if res3 is None and res4 is None:
@ -522,7 +507,7 @@ def cprintBrowseObj(fbrowse, name, mappingobj, dmobject):
print(
" dmjson_foreach_obj_in_array(res, arrobj, obj, i, 1, \"%s\") {" % res5, file=fp)
print("", file=fp)
print(" inst = handle_update_instance(1, dmctx, &max_inst, update_instance_without_section, 1, ++id);", file=fp)
print(" inst = handle_instance_without_section(dmctx, parent_node, ++id);", file=fp)
print("", file=fp)
print(
" if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)obj, inst) == DM_STOP)", file=fp)
@ -585,11 +570,7 @@ def cprintGetSetValue(getvalue, setvalue, mappingparam, instance, typeparam, par
get_value += " }\n"
get_value += " dmasprintf(value, \"%d\", cnt);"
elif "Alias" in dmparam:
get_value += " struct uci_section *dmmap_section = NULL;\n"
get_value += "\n"
get_value += " get_dmmap_section_of_config_section(\"%s\", \"%s\", section_name((struct uci_section *)data), &dmmap_section);\n" % (
res1, res2)
get_value += " dmuci_get_value_by_section_string(dmmap_section, \"%s\", value);\n" % res5
get_value += " dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->dmmap_section, \"%s\", value);\n" % res5
get_value += " if ((*value)[0] == '\\0')\n"
get_value += " dmasprintf(value, \"cpe-%s\", instance);"
elif instance == "TRUE" and res6 is not None:
@ -609,7 +590,7 @@ def cprintGetSetValue(getvalue, setvalue, mappingparam, instance, typeparam, par
get_value += " *value = bbf_uci_get_value(\"%s\", \"%s\", \"%s\", \"%s\");" % (
res6, res1, res3, res5)
elif instance == "TRUE":
get_value += " dmuci_get_value_by_section_string((struct uci_section *)data, \"%s\", value);" % res5
get_value += " dmuci_get_value_by_section_string(((struct dmmap_dup *)data)->config_section, \"%s\", value);" % res5
else:
get_value += " dmuci_get_option_value_string(\"%s\", \"%s\", \"%s\", value);" % (
res1, res3, res5)
@ -623,12 +604,12 @@ def cprintGetSetValue(getvalue, setvalue, mappingparam, instance, typeparam, par
if typeparam == "boolean":
set_value += " string_to_bool(value, &b);\n"
if instance == "TRUE":
set_value += " dmuci_set_value_by_section((struct uci_section *)data, \"%s\", b ? \"1\" : \"0\");" % res5
set_value += " dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, \"%s\", b ? \"1\" : \"0\");" % res5
else:
set_value += " dmuci_set_value(\"%s\", \"%s\", \"%s\", b ? \"1\" : \"0\");" % (
res1, res3, res5)
elif instance == "TRUE":
set_value += " dmuci_set_value_by_section((struct uci_section *)data, \"%s\", value);" % res5
set_value += " dmuci_set_value_by_section(((struct dmmap_dup *)data)->config_section, \"%s\", value);" % res5
else:
set_value += " dmuci_set_value(\"%s\", \"%s\", \"%s\", value);" % (
res1, res3, res5)
@ -664,10 +645,10 @@ def cprintGetSetValue(getvalue, setvalue, mappingparam, instance, typeparam, par
elif i == 2 and res4 == "@Name":
get_value += " if (*value[0] == '\\0')\n"
get_value += " {\n"
get_value += " dmubus_call(\"%s\", \"%s\", UBUS_ARGS{{\"%s\", section_name((struct uci_section *)data), String}}, 1, &res);\n" % (
get_value += " dmubus_call(\"%s\", \"%s\", UBUS_ARGS{{\"%s\", section_name(((struct dmmap_dup *)data)->config_section), String}}, 1, &res);\n" % (
res1, res2, res3)
elif res4 == "@Name":
get_value += " dmubus_call(\"%s\", \"%s\", UBUS_ARGS{{\"%s\", section_name((struct uci_section *)data), String}}, 1, &res);\n" % (
get_value += " dmubus_call(\"%s\", \"%s\", UBUS_ARGS{{\"%s\", section_name(((struct dmmap_dup *)data)->config_section), String}}, 1, &res);\n" % (
res1, res2, res3)
else:
get_value += " dmubus_call(\"%s\", \"%s\", UBUS_ARGS{{\"%s\", \"%s\", String}}, 1, &res);\n" % (
@ -677,7 +658,7 @@ def cprintGetSetValue(getvalue, setvalue, mappingparam, instance, typeparam, par
option = res5.split(".")
if "." in res5:
if option[0] == "@Name":
get_value += " *value = dmjson_get_value(res, 2, section_name((struct uci_section *)data), \"%s\");" % (
get_value += " *value = dmjson_get_value(res, 2, section_name(((struct dmmap_dup *)data)->config_section), \"%s\");" % (
option[1])
else:
get_value += " *value = dmjson_get_value(res, 2, \"%s\", \"%s\");" % (
@ -702,7 +683,7 @@ def cprintGetSetValue(getvalue, setvalue, mappingparam, instance, typeparam, par
# GET VALUE Parameter
if res1[:15] == "/sys/class/net/" and res1[15:20] == "@Name":
get_value += " get_net_device_sysfs(section_name((struct uci_section *)data), \"%s\", value);" % res1[
get_value += " get_net_device_sysfs(section_name(((struct dmmap_dup *)data)->config_section), \"%s\", value);" % res1[
21:]
else:
get_value += " char val[64];\n"