update lan_interfaces to support alias

update alias mechanism and landevice update instance (part2)
This commit is contained in:
Anis Ellouze 2016-02-26 19:42:34 +01:00
parent dfdc4cec83
commit 643ffcc00b
8 changed files with 142 additions and 135 deletions

View file

@ -761,15 +761,15 @@ int get_global_config(struct config *conf)
}
if((error = get_amd_version_config())!= CWMP_OK)
{
return error;
return error;
}
if((error = get_instance_mode_config())!= CWMP_OK)
{
return error;
}
{
return error;
}
if((error = get_session_timeout_config())!= CWMP_OK)
{
return error;
return error;
}
return CWMP_OK;
}
@ -783,12 +783,9 @@ int get_amd_version_config()
if((error = uci_get_value(UCI_CPE_AMD_VERSION ,&value)) == CWMP_OK)
{
cwmp->conf.amd_version = DEFAULT_AMD_VERSION;
printf("DEFAULT conf->amd_version = %d \n", cwmp->conf.amd_version );
if(value != NULL)
{
a = atoi(value) ;
printf("conf : value = %s \n", value );
printf("conf : a = %d \n", a );
if ( a >= 1 ) {
cwmp->conf.amd_version = a;
}
@ -847,7 +844,6 @@ int get_instance_mode_config()
free(value);
value = NULL;
}
printf("config : conf->instance_mode = %d \n", cwmp->conf.instance_mode );
}
else
{

View file

@ -392,3 +392,55 @@ void remove_vid_interfaces_from_ifname(char *vid, char *ifname, char *new_ifname
dmstrappendend(p);
dmfree(ifname);
}
void update_section_option_list(char *config, char *section, char *option, char *option_2,char *val, char *val_2, char *name)
{
char *add_value;
int i = 0;
char *baseifname;
struct uci_section *prev_s= NULL, *s;
char *instance = NULL, *last_instance = NULL, *value;
bool add_sec = true;
if (name[0] == '\0') {
add_sec = false;
}
uci_foreach_option_eq(config, section, option_2, val_2, s) {
dmuci_get_value_by_section_string(s, option, &baseifname);
if (!strstr(name, baseifname))
{
//delete section if baseifname does not belong to name
if (prev_s) {
dmuci_delete_by_section(prev_s, NULL, NULL);
}
prev_s = s;
} else if (strstr(name, baseifname) && (strcmp(baseifname,val) ==0)) {
//dont add baseifname if exist
add_sec = false;
}
}
if (prev_s) {
dmuci_delete_by_section(prev_s, NULL, NULL);
}
if(add_sec) {
dmuci_add_section(config, section, &s, &add_value);
dmuci_set_value_by_section(s, option, val);
dmuci_set_value_by_section(s, option_2, val_2);
}
}
void update_section_list(char *config, char *section, char *option, int number, char *wlan)
{
char *add_value;
struct uci_section *s = NULL;
int i = 0;
uci_foreach_option_eq(config, section, option, wlan, s) {
return;
}
while (i<number) {
dmuci_add_section(config, section, &s, &add_value);
dmuci_set_value_by_section(s, option, wlan);
i++;
}
}

View file

@ -68,5 +68,7 @@ int ipcalc_rev_start(char *ip_str, char *mask_str, char *ipstart_str, char *star
int ipcalc_rev_end(char *ip_str, char *mask_str, char *start_str, char *ipend_str, char *end_str);
int network_get_ipaddr(char **value, char *iface);
void remove_vid_interfaces_from_ifname(char *vid, char *ifname, char *new_ifname);
void update_section_option_list(char *config, char *section, char *option, char *option_2,char *val, char *val_2, char *name);
void update_section_list(char *config, char *section, char *option, int number, char *wlan);
#endif

View file

@ -31,6 +31,7 @@
#include "ippingdiagnostics.h"
#include "x_inteno_syslog.h"
#include "dmentry.h"
#include "dmcommon.h"
static char *get_parameter_notification (char *param);
static int remove_parameter_notification(char *param);
@ -119,8 +120,10 @@ int dm_entry_set_prefix_methods_enable(void)
}
return 0;
}
char *handle_update_instance(int instance_ranck, struct dmctx *ctx, char * (*up_instance)(int action, void *argv[]), int argc, ...)
/***************************
* update instance & alias
***************************/
char *handle_update_instance(int instance_ranck, struct dmctx *ctx, char **last_inst, char * (*up_instance)(int action, char **last_inst, void *argv[]), int argc, ...)
{
va_list arg;
char *instance, *inst_mode;
@ -136,7 +139,6 @@ char *handle_update_instance(int instance_ranck, struct dmctx *ctx, char * (*up_
argv[i] = va_arg(arg, void*);
}
va_end(arg);
printf("ctx->amd_version = %d \n", ctx->amd_version);
if (ctx->amd_version >= 4) {
if(pos < ctx->nbrof_instance) {
action = (ctx->alias_register & (1 << pos)) ? INSTANCE_UPDATE_ALIAS : INSTANCE_UPDATE_NUMBER;
@ -146,7 +148,7 @@ char *handle_update_instance(int instance_ranck, struct dmctx *ctx, char * (*up_
} else {
action = INSTANCE_UPDATE_NUMBER;
}
instance = up_instance(action, argv);
instance = up_instance(action, last_inst, argv);
return instance;
}
@ -166,47 +168,38 @@ char *update_instance(struct uci_section *s, char *last_inst, char *inst_opt)
return instance;
}
char *update_instance_alias(int action, void *argv[])
char *update_instance_alias(int action, char **last_inst , void *argv[])
{
char *instance;
char *alias;
char buf[12] = {0};
struct uci_section *s = (struct uci_section *) argv[0];
char *last_inst = (char *) argv[1];
char *inst_opt = (char *) argv[2];
char *alias_opt = (char *) argv[3];
char *inst_opt = (char *) argv[1];
char *alias_opt = (char *) argv[2];
dmuci_get_value_by_section_string(s, inst_opt, &instance);
if (instance[0] == '\0') {
if (*last_inst == NULL)
sprintf(buf, "%d", 1);
else
sprintf(buf, "%d", atoi(*last_inst)+1);
instance = dmuci_set_value_by_section(s, inst_opt, buf);
}
*last_inst = instance;
if (action == INSTANCE_MODE_ALIAS) {
dmuci_get_value_by_section_string(s, alias_opt, &alias);
if (alias[0] == '\0') {
dmuci_get_value_by_section_string(s, inst_opt, &instance);
if (instance[0] == '\0') {
if (last_inst == NULL)
sprintf(buf, "%d", 1);
else
sprintf(buf, "%d", atoi(last_inst)+1);
instance = dmuci_set_value_by_section(s, inst_opt, buf);
}
sprintf(buf, "cpe-%s", instance);
alias = dmuci_set_value_by_section(s, alias_opt, buf);
}
sprintf(buf, "[%s]", alias);
instance = dmstrdup(buf);
} else {
dmuci_get_value_by_section_string(s, inst_opt, &instance);
if (instance[0] == '\0') {
if (last_inst == NULL)
sprintf(buf, "%d", 1);
else
sprintf(buf, "%d", atoi(last_inst)+1);
instance = dmuci_set_value_by_section(s, inst_opt, buf);
}
}
return instance;
}
char *update_instance_without_section(int action, void *argv[])
char *update_instance_without_section(int action, char **last_inst, void *argv[])
{
char *instance;
char *alias;
@ -244,7 +237,6 @@ char *get_last_instance_lev2(char *package, char *section, char *opt_inst, char
return instance;
}
int get_empty(char *refparam, struct dmctx *args, char **value)
{
*value = "";

View file

@ -211,8 +211,8 @@ extern struct list_head list_enabled_notify;
extern struct list_head list_enabled_lw_notify;
char *update_instance(struct uci_section *s, char *last_inst, char *inst_opt);
char *update_instance_alias(int action, void *argv[]);
char *update_instance_without_section(int action, void *argv[]);
char *update_instance_alias(int action, char **last_inst , void *argv[]);
char *update_instance_without_section(int action, char **last_inst, void *argv[]);
int get_empty(char *refparam, struct dmctx *args, char **value);
void add_list_paramameter(struct dmctx *ctx, char *param_name, char *param_data, char *param_type);
void del_list_parameter(struct dm_parameter *dm_parameter);
@ -241,7 +241,7 @@ void dm_update_enabled_notify(struct dm_enabled_notify *p, char *new_value);
void dm_update_enabled_notify_byname(char *name, char *new_value);
char *get_last_instance(char *package, char *section, char *opt_inst);
char *get_last_instance_lev2(char *package, char *section, char *opt_inst, char *opt_check, char *value_check);
char *handle_update_instance(int instance_ranck, struct dmctx *ctx, char * (*up_instance)(int action, void *argv[]), int argc, ...);
char *handle_update_instance(int instance_ranck, struct dmctx *ctx, char **last_inst, char * (*up_instance)(int action, char **last_inst, void *argv[]), int argc, ...);
#ifndef TRACE
#define TRACE_TYPE 0

View file

@ -39,8 +39,6 @@ static int dm_ctx_init_custom(struct dmctx *ctx, int custom)
INIT_LIST_HEAD(&ctx->list_fault_param);
ctx->amd_version = cwmp->conf.amd_version;
ctx->instance_mode = cwmp->conf.instance_mode;
printf("ctx->amd_version = %d \n", ctx->amd_version);
printf("ctx->instance_mode = %d \n", ctx->instance_mode);
return 0;
}
@ -91,10 +89,8 @@ void dmentry_instance_lookup_inparam(struct dmctx *ctx)
{
char *pch, *spch, *in_param;
in_param = dmstrdup(ctx->in_param);
pch = strtok_r(in_param, ".", &spch);
int i = 0;
for (pch = strtok_r(in_param, ".", &spch); pch != NULL; pch = strtok_r(NULL, ".", &spch)) {
printf("alz: pch = %s \n", pch);
if (pch[0]== '[') {
ctx->alias_register |= (1 << i);
i++;
@ -105,7 +101,6 @@ void dmentry_instance_lookup_inparam(struct dmctx *ctx)
}
dmfree(in_param);
ctx->nbrof_instance = i;
printf("ctx->nbrof_instance = %d \n", ctx->nbrof_instance );
}
int dm_entry_param_method(struct dmctx *ctx, int cmd, char *inparam, char *arg1, char *arg2)

View file

@ -94,15 +94,15 @@ inline void init_laninterface_lan(struct dmctx *ctx)
/////////////SUB ENTRIES///////////////
inline int entry_laninterface_lan(struct dmctx *ctx)
{
int ei=1, i=0;
char ei[12];
int i=0;
struct linterfargs *args = &cur_linterfargs;
ctx->args = (void *)args;
laninterface_lookup(args->eths, &(args->eths_size));
while (args->eths[i]) {
init_lan_interface_args(args->eths[i]);
sprintf(ei,"%d",++i);
SUBENTRY(entry_laninterface_lan_instance, ctx, ei);
i++;
ei++;
}
return 0;
}
@ -110,10 +110,11 @@ inline int entry_laninterface_lan(struct dmctx *ctx)
inline int entry_laninterface_wlan(struct dmctx *ctx)
{
struct uci_section *s = NULL;
int wi=1;
char wi[12];
int i=0;
uci_foreach_sections("wireless", "wifi-iface", s) {
sprintf(wi,"%d",++i);
SUBENTRY(entry_laninterface_wlan_instance, ctx, wi);
wi++;
}
return 0;
}
@ -134,15 +135,15 @@ int entry_method_root_InternetGatewayDevice_LANInterfaces(struct dmctx *ctx)
return FAULT_9005;
}
inline int entry_laninterface_lan_instance(struct dmctx *ctx, int li)
inline int entry_laninterface_lan_instance(struct dmctx *ctx, char *li)
{
DMOBJECT(DMROOT"LANInterfaces.LANEthernetInterfaceConfig.%d.", ctx, "0", 1, NULL, NULL, NULL, li);
DMOBJECT(DMROOT"LANInterfaces.LANEthernetInterfaceConfig.%s.", ctx, "0", 1, NULL, NULL, NULL, li);
DMPARAM("X_INTENO_COM_EthName", ctx, "0", get_eth_name, NULL, NULL, 0, 1, UNDEF, NULL);
return 0;
}
inline int entry_laninterface_wlan_instance(struct dmctx *ctx, int wli)
inline int entry_laninterface_wlan_instance(struct dmctx *ctx, char *wli)
{
DMOBJECT(DMROOT"LANInterfaces.WLANConfiguration.%d.", ctx, "0", 1, NULL, NULL, NULL, wli);
DMOBJECT(DMROOT"LANInterfaces.WLANConfiguration.%s.", ctx, "0", 1, NULL, NULL, NULL, wli);
return 0;
}

View file

@ -2718,14 +2718,34 @@ int set_wmm_enabled(char *refparam, struct dmctx *ctx, int action, char *value)
}
return 0;
}
void lan_eth_update_section_option_list (char *name, char *sec_name, char *wan_eth)
{
char *pch, *spch, *ifname;
if (name[0] == '\0') {
update_section_option_list("dmmap", "lan_eth", "ifname", "network", "", sec_name, name);
}
ifname = dmstrdup(name);
for (pch = strtok_r(ifname, " ,", &spch);
pch != NULL;
pch = strtok_r(NULL, " ,", &spch)) {
if (strncmp(pch, "eth", 3) != 0 || strncmp(pch, wan_eth, 4) == 0)
continue;
update_section_option_list("dmmap", "lan_eth", "ifname", "network", pch, sec_name, name);
}
dmfree(ifname);
}
/////////////SUB ENTRIES///////////////
inline int entry_landevice_sub(struct dmctx *ctx)
{
struct uci_section *s = NULL;
char *idev = NULL;
char *idev = NULL, *idev_last = NULL;
int action;
uci_foreach_filter_func("network", "interface", NULL, &filter_lan_device_interface, s) {
idev = handle_update_instance(1, ctx, update_instance_alias, 4, s, idev, "ldinstance", "ldalias");
idev = handle_update_instance(1, ctx, &idev_last, update_instance_alias, 3, s, "ldinstance", "ldalias");
init_ldargs_lan(ctx, s, idev);
SUBENTRY(entry_landevice_sub_instance, ctx, s, idev);
}
@ -2736,15 +2756,15 @@ inline int entry_landevice_ipinterface_and_dhcpstaticaddress(struct dmctx *ctx,
{
struct uci_section *ss = NULL;
struct uci_section *sss = NULL;
char *ilan = NULL;
char *idhcp = NULL;
char *ilan = NULL, *ilan_last = NULL;
char *idhcp = NULL, *idhcp_last = NULL;
uci_foreach_filter_func("network", "interface", landevice_section, filter_lan_ip_interface, ss) {
ilan = handle_update_instance(2, ctx, update_instance_alias, 4, ss, ilan, "lipinstance", "lipalias");
ilan = handle_update_instance(2, ctx, &ilan_last, update_instance_alias, 3, ss, "lipinstance", "lipalias");
init_ldargs_ip(ctx, ss);
SUBENTRY(entry_landevice_ipinterface_instance, ctx, idev, ilan);
uci_foreach_option_cont("dhcp", "host", "interface", section_name(ss), sss) {
idhcp = handle_update_instance(2, ctx, update_instance_alias, 4, sss, idhcp, "ldhcpinstance", "ldhcpalias");
idhcp = handle_update_instance(2, ctx, &idhcp_last, update_instance_alias, 3, sss, "ldhcpinstance", "ldhcpalias");
init_ldargs_dhcp(ctx, sss);
SUBENTRY(entry_landevice_dhcpstaticaddress_instance, ctx, idev, idhcp);
}
@ -2757,7 +2777,7 @@ inline int entry_landevice_wlanconfiguration(struct dmctx *ctx, struct uci_secti
struct uci_section *ss = NULL;
struct uci_section *sss = NULL;
json_object *res;
char *iwlan = NULL;
char *iwlan = NULL, *iwlan_last = NULL;
char *network , *wiface, buf[8];
iwlan = get_last_instance_lev2("wireless", "wifi-iface", "lwlaninstance", "network", section_name(landevice_section));
@ -2767,7 +2787,7 @@ inline int entry_landevice_wlanconfiguration(struct dmctx *ctx, struct uci_secti
dmuci_get_value_by_section_string(sss, "network", &network);
if (strcmp(network, section_name(landevice_section)) != 0)
continue;
iwlan = handle_update_instance(2, ctx, update_instance_alias, 4, sss, iwlan, "lwlaninstance", "lwlanalias");
iwlan = handle_update_instance(2, ctx, &iwlan_last, update_instance_alias, 3, sss, "lwlaninstance", "lwlanalias");
wiface = section_name(ss);
if (wlctl_num != 0) {
sprintf(buf, "%s.%d", wiface, wlctl_num);
@ -2782,30 +2802,16 @@ inline int entry_landevice_wlanconfiguration(struct dmctx *ctx, struct uci_secti
return 0;
}
void update_section_list(char *config, char *section, int nbr)
{
char *add_value;
struct uci_section *s = NULL;
int i = 0;
uci_foreach_sections(config, section,s) {
return;
}
while (i<nbr) {
dmuci_add_section(config, section, &s, &add_value);
i++;
}
}
inline int entry_landevice_wlanconfiguration_wepkey(struct dmctx *ctx, char *idev, char *iwlan)
{
int i = 0;
char *iwep = NULL;
char *iwep = NULL, *iwep_last = NULL;
struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args;
struct uci_section *s = NULL;
update_section_list("dmmap","wlan-wepkey", 4);
uci_foreach_sections("dmmap","wlan-wepkey",s) {
iwep = handle_update_instance(3, ctx, update_instance_alias, 4, s, iwep, "wepinstance", "wepalias");
update_section_list("dmmap","wlan-wepkey", "wlan", 4, section_name(wlanargs->lwlansection));
uci_foreach_option_eq("dmmap", "wlan-wepkey", "wlan", section_name(wlanargs->lwlansection), s) {
iwep = handle_update_instance(3, ctx, &iwep_last, update_instance_alias, 3, s, "wepinstance", "wepalias");
SUBENTRY(entry_landevice_wlanconfiguration_wepkey_instance, ctx, idev, iwlan, iwep);
}
return 0;
@ -2813,16 +2819,17 @@ inline int entry_landevice_wlanconfiguration_wepkey(struct dmctx *ctx, char *ide
inline int entry_landevice_wlanconfiguration_presharedkey(struct dmctx *ctx, char *idev, char *iwlan)
{
int i = 0;
char *ipk = NULL;
char *ipk = NULL, *ipk_last = NULL ;
struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args;
struct uci_section *s = NULL;
update_section_list("dmmap","wlan-psk", 10);
uci_foreach_sections("dmmap","wlan-psk",s) {
i++;
wlanargs->pki = i; //TODO TOCHECK
ipk = handle_update_instance(3, ctx, update_instance_alias, 4, s, ipk, "pskinstance", "pskalias");
wlanargs->pki = 0;
//update section list of wlan-psk before update instance
update_section_list("dmmap","wlan-psk", "wlan", 10, section_name(wlanargs->lwlansection));
uci_foreach_option_eq("dmmap", "wlan-psk", "wlan", section_name(wlanargs->lwlansection), s) {
wlanargs->pki++;
printf("CHEK PKI = %d \n", wlanargs->pki);
ipk = handle_update_instance(3, ctx, &ipk_last, update_instance_alias, 3, s, "pskinstance", "pskalias");
SUBENTRY(entry_landevice_wlanconfiguration_presharedkey_instance, ctx, idev, iwlan, ipk); //"$wunit" "$wlctl_num" "$uci_num" are not needed
}
return 0;
@ -2832,15 +2839,14 @@ inline int entry_landevice_wlanconfiguration_associateddevice(struct dmctx *ctx,
{
int id = 0;
json_object *res, *wl_client_obj;
char *idx;
char *idx, *idx_last = NULL;
struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args;
dmubus_call("router", "sta", UBUS_ARGS{{"vif", wlanargs->wiface}}, 1, &res);
if (res) {
char *value;
json_object_object_foreach(res, key, wl_client_obj) {
id++;
idx = handle_update_instance(3, ctx, update_instance_without_section, 1, id);
idx = handle_update_instance(3, ctx, &idx_last, update_instance_without_section, 1, ++id);
json_select(wl_client_obj, "macaddr", 0, NULL, &value, NULL);
init_wl_client_args(ctx, value, wlanargs->wiface);
SUBENTRY(entry_landevice_wlanconfiguration_associateddevice_instance, ctx, idev, iwlan, idx);
@ -2849,59 +2855,23 @@ inline int entry_landevice_wlanconfiguration_associateddevice(struct dmctx *ctx,
return 0;
}
void update_section_option_list(char *config, char *section, char *option, char *option_2,char *val, char *val_2, struct uci_section **s)
{
char *add_value;
int i = 0;
char *network;
struct uci_section *prev_s= NULL;
char *instance = NULL, *last_instance = NULL, *value;
int delete = 0;
uci_foreach_option_eq(config, section, option, val, *s) {
dmuci_get_value_by_section_string(*s, option_2, &network);
if(strcmp(network, val_2) == 0) {
return;
}
else {
prev_s = *s;
delete = 1;
}
}
if (delete == 1){
dmuci_delete_by_section(prev_s, NULL, NULL);
dmuci_add_section(config, section, s, &value);
dmuci_set_value_by_section(*s, option, val);
dmuci_set_value_by_section(*s, option_2, val_2);
return;
}
dmuci_add_section(config, section, s, &add_value);
dmuci_set_value_by_section(*s, option, val);
dmuci_set_value_by_section(*s, option_2, val_2);
}
inline int entry_landevice_lanethernetinterfaceconfig(struct dmctx *ctx, struct uci_section *landevice_section, char *idev)
{
int i = 0;
char *pch, *spch;
char *ifname, *wan_eth;
char *ieth = NULL;
char *ifname, *wan_eth, *baseifname;
char *ieth = NULL, *ieth_last = NULL;
struct uci_section *s = NULL;
dmuci_get_option_value_string("layer2_interface_ethernet", "ethernet_interface", "baseifname", &wan_eth);
dmuci_get_value_by_section_string(landevice_section, "ifname", &ifname);
ifname = dmstrdup(ifname);
for (pch = strtok_r(ifname, " ,", &spch);
pch != NULL;
pch = strtok_r(NULL, " ,", &spch)) {
if (strncmp(pch, "eth", 3) != 0 || strncmp(pch, wan_eth, 4) == 0)
continue;
init_ldargs_eth_cfg(ctx, pch);
update_section_option_list("dmmap", "lan_eth", "ifname", "network", pch, section_name(landevice_section), &s);
ieth = handle_update_instance(2, ctx, update_instance_alias, 4, s, ieth, "ethinstance", "ethalias");
lan_eth_update_section_option_list(ifname, section_name(landevice_section), wan_eth);
uci_foreach_option_eq("dmmap", "lan_eth", "network", section_name(landevice_section), s) {
dmuci_get_value_by_section_string(s, "ifname", &baseifname);
init_ldargs_eth_cfg(ctx, baseifname);
ieth = handle_update_instance(2, ctx, &ieth_last, update_instance_alias, 3, s, "ethinstance", "ethalias");
SUBENTRY(entry_landevice_lanethernetinterfaceconfig_instance, ctx, idev, ieth);
}
dmfree(ifname);
return 0;
}
@ -2910,16 +2880,15 @@ inline int entry_landevice_host(struct dmctx *ctx, struct uci_section *landevice
//HOST DYNAMIC
json_object *res, *client_obj;
char *network;
char *idx;
char *idx, *idx_last = NULL;
int id = 0;
dmubus_call("router", "clients", UBUS_ARGS{}, 0, &res);
if (res) {
json_object_object_foreach(res, key, client_obj) {
json_select(client_obj, "network", 0, NULL, &network, NULL);
if (strcmp(network, section_name(landevice_section)) == 0) {
id++;
init_client_args(ctx, client_obj, section_name(landevice_section));
idx = handle_update_instance(2, ctx, update_instance_without_section, 1, id);
idx = handle_update_instance(2, ctx, &idx_last, update_instance_without_section, 1, ++id);
SUBENTRY(entry_landevice_host_instance, ctx, idev, idx);
}
}