mirror of
https://dev.iopsys.eu/bbf/icwmp.git
synced 2026-02-12 11:00:18 +01:00
Ticket refs #14475 : Setting DNS for LAN clients via TR069
This commit is contained in:
parent
d43a8dd097
commit
2fd7a9a491
7 changed files with 469 additions and 247 deletions
|
|
@ -28,37 +28,6 @@
|
|||
#include "dmcommon.h"
|
||||
#include "dmjson.h"
|
||||
|
||||
int set_uci_dhcpserver_option(struct dmctx *ctx, struct uci_section *s, char *option, char *value)
|
||||
{
|
||||
struct uci_list *v;
|
||||
struct uci_element *e, *tmp;
|
||||
char *pch, *spch, bufopt[8];
|
||||
int len = 0;
|
||||
if (value == NULL)
|
||||
return -1;
|
||||
|
||||
dmuci_get_value_by_section_list(s, "dhcp_option", &v);
|
||||
if (v != NULL) {
|
||||
uci_foreach_element(v, e) {
|
||||
pch = strchr(e->name, ',');
|
||||
if (pch) {
|
||||
len = pch - e->name;
|
||||
strncpy(bufopt, e->name, len);
|
||||
bufopt[len] = '\0';
|
||||
if (strcmp(bufopt, option) == 0) {
|
||||
dmuci_del_list_value_by_section(s, "dhcp_option", e->name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (value[0] != '\0') {
|
||||
dmasprintf(&spch, "%s,%s", option, value);
|
||||
dmuci_add_list_value_by_section(s, "dhcp_option", spch);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int update_uci_dhcpserver_option(struct dmctx *ctx, struct uci_section *s, char *option, char *new_option, char *value)
|
||||
{
|
||||
struct uci_list *v;
|
||||
|
|
@ -67,7 +36,6 @@ int update_uci_dhcpserver_option(struct dmctx *ctx, struct uci_section *s, char
|
|||
int len = 0;
|
||||
if (value == NULL)
|
||||
return -1;
|
||||
|
||||
dmuci_get_value_by_section_list(s, "dhcp_option", &v);
|
||||
if (v != NULL) {
|
||||
uci_foreach_element(v, e) {
|
||||
|
|
@ -782,3 +750,61 @@ int check_ifname_is_vlan(char *ifname)
|
|||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int get_uci_dhcpserver_option(struct uci_section *s, char *option, char *value)
|
||||
{
|
||||
struct uci_list *v;
|
||||
struct uci_element *e;
|
||||
char *pch;
|
||||
char bufopt[8];
|
||||
int len = 0;
|
||||
|
||||
dmuci_get_value_by_section_list(s, "dhcp_option", &v);
|
||||
if (v == NULL)
|
||||
return -1;
|
||||
uci_foreach_element(v, e) {
|
||||
pch = strchr(e->name, ',');
|
||||
if (pch) {
|
||||
len = pch - e->name;
|
||||
strncpy(bufopt, e->name, len);
|
||||
bufopt[len] = '\0';
|
||||
if (strcmp(bufopt, option) == 0) {
|
||||
strcpy(value, pch + 1);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int set_uci_dhcpserver_option(struct uci_section *s, char *option, char *value)
|
||||
{
|
||||
struct uci_list *v;
|
||||
struct uci_element *e;
|
||||
char *pch, bufopt[8];
|
||||
int len = 0;
|
||||
|
||||
if (value == NULL)
|
||||
return -1;
|
||||
|
||||
dmuci_get_value_by_section_list(s, "dhcp_option", &v);
|
||||
if (v != NULL) {
|
||||
uci_foreach_element(v, e) {
|
||||
pch = strchr(e->name, ',');
|
||||
if (pch) {
|
||||
len = pch - e->name;
|
||||
strncpy(bufopt, e->name, len);
|
||||
bufopt[len] = '\0';
|
||||
if (strcmp(bufopt, option) == 0) {
|
||||
dmuci_del_list_value_by_section(s, "dhcp_option", e->name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (value[0] != '\0') {
|
||||
dmasprintf(&pch, "%s,%s", option, value);
|
||||
dmuci_add_list_value_by_section(s, "dhcp_option", pch);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ int filter_lan_ip_interface(struct uci_section *ss, void *v);
|
|||
void remove_interface_from_ifname(char *iface, char *ifname, char *new_ifname);
|
||||
int max_array(int a[], int size);
|
||||
int check_ifname_is_vlan(char *ifname);
|
||||
int set_uci_dhcpserver_option(struct dmctx *ctx, struct uci_section *s, char *option, char *value);
|
||||
int set_uci_dhcpserver_option(struct uci_section *s, char *option, char *value);
|
||||
int update_uci_dhcpserver_option(struct dmctx *ctx, struct uci_section *s, char *option, char * new_option, char *value);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
57
dm/dmcwmp.c
57
dm/dmcwmp.c
|
|
@ -266,7 +266,6 @@ char *update_instance_alias(int action, char **last_inst , void *argv[])
|
|||
struct uci_section *s = (struct uci_section *) argv[0];
|
||||
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)
|
||||
|
|
@ -328,6 +327,62 @@ char *get_last_instance(char *package, char *section, char *opt_inst)
|
|||
return inst;
|
||||
}
|
||||
|
||||
int get_dhcp_option_last_inst(struct uci_section *ss, char *inst_opt)
|
||||
{
|
||||
char *drinst = NULL, *tmp;
|
||||
int dr = 0;
|
||||
struct uci_section *s;
|
||||
uci_path_foreach_sections(icwmpd, "dmmap", section_name(ss), s) {
|
||||
dmuci_get_value_by_section_string(s, inst_opt, &tmp);
|
||||
if (tmp[0] == '\0')
|
||||
break;
|
||||
drinst = tmp;
|
||||
}
|
||||
if (drinst) dr = atoi(drinst);
|
||||
return dr;
|
||||
}
|
||||
|
||||
char *dhcp_option_update_instance_alias_icwmpd(int action, char **last_inst, void *argv[])
|
||||
{
|
||||
char *instance, *alias;
|
||||
char buf[8] = {0};
|
||||
char itf_name[32] = {0};
|
||||
|
||||
struct uci_section *s = (struct uci_section *) argv[0];
|
||||
char *inst_opt = (char *) argv[1];
|
||||
char *alias_opt = (char *) argv[2];
|
||||
bool *find_max = (bool *) argv[3];
|
||||
|
||||
dmuci_get_value_by_section_string(s, inst_opt, &instance);
|
||||
TRACE("instance :%s", instance);
|
||||
if (instance[0] == '\0') {
|
||||
if (*find_max) {
|
||||
int m = get_dhcp_option_last_inst(s, inst_opt);
|
||||
sprintf(buf, "%d", m+1);
|
||||
*find_max = false;
|
||||
}
|
||||
else
|
||||
if (last_inst == NULL) {
|
||||
sprintf(buf, "%d", 1);
|
||||
}
|
||||
else {
|
||||
sprintf(buf, "%d", atoi(*last_inst)+1);
|
||||
}
|
||||
instance = DMUCI_SET_VALUE_BY_SECTION(icwmpd, 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') {
|
||||
sprintf(buf, "cpe-%s", instance);
|
||||
alias = DMUCI_SET_VALUE_BY_SECTION(icwmpd, s, alias_opt, buf);
|
||||
}
|
||||
sprintf(buf, "[%s]", alias);
|
||||
instance = dmstrdup(buf);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
char *get_last_instance_lev2(char *package, char *section, char *opt_inst, char *opt_check, char *value_check)
|
||||
{
|
||||
struct uci_section *s;
|
||||
|
|
|
|||
|
|
@ -71,7 +71,9 @@
|
|||
}
|
||||
|
||||
#define SUBENTRY(f, ctx, ...) { \
|
||||
void *parent_args = ctx->args; \
|
||||
int error = f(ctx, ## __VA_ARGS__); \
|
||||
ctx->args = parent_args; \
|
||||
if ((ctx)->stop) return error; \
|
||||
}
|
||||
|
||||
|
|
@ -264,6 +266,8 @@ 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_icwmpd(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);
|
||||
int get_dhcp_option_last_inst(struct uci_section *ss, char *inst_opt);
|
||||
char *dhcp_option_update_instance_alias_icwmpd(int action, char **last_inst, void *argv[]);
|
||||
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, ...);
|
||||
|
||||
void free_all_list_enabled_lwnotify();
|
||||
|
|
@ -275,9 +279,10 @@ static inline void trace_empty_func()
|
|||
#if TRACE_TYPE == 2
|
||||
#define TRACE(MESSAGE,args...) do { \
|
||||
const char *A[] = {MESSAGE}; \
|
||||
printf("TRACE: %s %s %d\n",__FUNCTION__,__FILE__,__LINE__); fflush(stdout);\
|
||||
printf("TRACE: %s %s %d ",__FUNCTION__,__FILE__,__LINE__); \
|
||||
if(sizeof(A) > 0) \
|
||||
printf(*A,##args); \
|
||||
printf("\n"); fflush(stdout); \
|
||||
} while(0)
|
||||
#elif TRACE_TYPE == 1
|
||||
#define TRACE(MESSAGE, ...) printf(MESSAGE, ## __VA_ARGS__)
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
* Copyright (C) 2012-2014 PIVA SOFTWARE (www.pivasoftware.com)
|
||||
* Author: Imen Bhiri <imen.bhiri@pivasoftware.com>
|
||||
* Author: Feten Besbes <feten.besbes@pivasoftware.com>
|
||||
* Author Omar Kallel <omar.kallel@pivasoftware.com>
|
||||
* Author: Omar Kallel <omar.kallel@pivasoftware.com>
|
||||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
|
|
@ -30,7 +30,7 @@
|
|||
#define MAX_PROC_ARP 256
|
||||
#define DHCP_LEASE_FILE "/var/dhcp.leases"
|
||||
|
||||
inline int entry_landevice_sub_instance(struct dmctx *ctx, struct uci_section *landevice_section, char *idev);
|
||||
inline int entry_landevice_sub_instance(struct dmctx *ctx, struct uci_section *landevice_section, char *interface, char *idev);
|
||||
inline int entry_landevice_ipinterface_instance (struct dmctx *ctx, char *idev, char *ilan);
|
||||
inline int entry_landevice_dhcpstaticaddress_instance(struct dmctx *ctx, char *idev, char *idhcp);
|
||||
inline int entry_landevice_wlanconfiguration_instance(struct dmctx *ctx, char *idev,char *iwlan);
|
||||
|
|
@ -42,8 +42,8 @@ inline int entry_landevice_host_instance(struct dmctx *ctx, char *idev, char *id
|
|||
|
||||
inline int entry_landevice_wlanconfiguration_wepkey_instance(struct dmctx *ctx, char *idev, char *iwlan, char *iwep);
|
||||
inline int entry_landevice_dhcpconditionalservingpool_option_instance(struct dmctx *ctx, char * idev, char *icondpool, char *idx);
|
||||
inline int entry_landevice_lanhostconfigmanagement_dhcpconditionalservingpool_instance(struct dmctx *ctx, char * idev, char *icondpool);
|
||||
inline int entry_landevice_lanhostconfigmanagement_dhcpconditionalservingpool(struct dmctx *ctx, char *idev);
|
||||
inline int entry_landevice_lanhostconfigmanagement_dhcpconditionalservingpool_instance(struct dmctx *ctx, char *interface, char * idev, char *icondpool);
|
||||
inline int entry_landevice_lanhostconfigmanagement_dhcpconditionalservingpool(struct dmctx *ctx, struct uci_section *landevice_section, char *interface, char *idev);
|
||||
|
||||
struct ldlanargs cur_lanargs = {0};
|
||||
struct ldipargs cur_ipargs = {0};
|
||||
|
|
@ -254,75 +254,25 @@ end:
|
|||
FREE(dhcp_param->interface);
|
||||
return;
|
||||
}
|
||||
int get_dhcp_option_last_inst(struct uci_section *ss)
|
||||
{
|
||||
char *drinst = NULL, *tmp;
|
||||
int dr = 0;
|
||||
struct uci_section *s;
|
||||
|
||||
uci_path_foreach_sections(icwmpd, "dmmap", section_name(ss), s) {
|
||||
dmuci_get_value_by_section_string(s, "optioninst", &tmp);
|
||||
if (tmp[0] == '\0')
|
||||
break;
|
||||
drinst = tmp;
|
||||
}
|
||||
if (drinst) dr = atoi(drinst);
|
||||
return dr;
|
||||
}
|
||||
|
||||
char *dhcp_option_update_instance_alias_icwmpd(int action, char **last_inst, void *argv[])
|
||||
{
|
||||
char *instance, *alias;
|
||||
char buf[8] = {0};
|
||||
|
||||
struct uci_section *s = (struct uci_section *) argv[0];
|
||||
char *inst_opt = (char *) argv[1];
|
||||
char *alias_opt = (char *) argv[2];
|
||||
bool *find_max = (bool *) argv[3];
|
||||
|
||||
dmuci_get_value_by_section_string(s, inst_opt, &instance);
|
||||
if (instance[0] == '\0') {
|
||||
if (*find_max) {
|
||||
int m = get_dhcp_option_last_inst(s);
|
||||
sprintf(buf, "%d", m+1);
|
||||
*find_max = false;
|
||||
}
|
||||
else if (last_inst == NULL) {
|
||||
sprintf(buf, "%d", 1);
|
||||
}
|
||||
else {
|
||||
sprintf(buf, "%d", atoi(*last_inst)+1);
|
||||
}
|
||||
instance = DMUCI_SET_VALUE_BY_SECTION(icwmpd, 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') {
|
||||
sprintf(buf, "cpe-%s", instance);
|
||||
alias = DMUCI_SET_VALUE_BY_SECTION(icwmpd, s, alias_opt, buf);
|
||||
}
|
||||
sprintf(buf, "[%s]", alias);
|
||||
instance = dmstrdup(buf);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
/*******************ADD-DEL OBJECT*********************/
|
||||
int add_dhcp_serving_pool_option(struct dmctx *ctx, char **instancepara)
|
||||
{
|
||||
|
||||
char val[64];
|
||||
char *value, *instance, *tmp;
|
||||
struct uci_section *s = NULL;
|
||||
char *value, *instance;
|
||||
struct uci_section *s = NULL, *lan_s = NULL;
|
||||
struct dhcppoolargs *poolargs = (struct dhcppoolargs *)ctx->args;
|
||||
|
||||
instance = get_last_instance(DMMAP, section_name(poolargs->dhcppoolsection), "optioninst");
|
||||
instance = get_last_instance(DMMAP, section_name(poolargs->dhcppoolsection), "option_instance");
|
||||
DMUCI_ADD_SECTION(icwmpd, "dmmap", section_name(poolargs->dhcppoolsection), &s, &value);
|
||||
DMUCI_SET_VALUE_BY_SECTION(icwmpd, s, "dhcp_option", "0");
|
||||
*instancepara = update_instance_icwmpd(s, instance, "optioninst");
|
||||
sprintf(val, "vendorclass%s", *instancepara);
|
||||
DMUCI_SET_VALUE_BY_SECTION(icwmpd, s, "tag", "0");
|
||||
*instancepara = update_instance_icwmpd(s, instance, "option_instance");
|
||||
sprintf(val, "option_%s", *instancepara);
|
||||
DMUCI_SET_VALUE_BY_SECTION(icwmpd, s, "value", val);
|
||||
sprintf(val, "0,vendorclass%s", *instancepara);
|
||||
dmuci_add_list_value_by_section( poolargs->dhcppoolsection, "dhcp_option", val);
|
||||
sprintf(val, "0,option_%s",*instancepara);
|
||||
dmuci_add_list_value_by_section(poolargs->dhcppoolsection, "dhcp_option", val);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -334,6 +284,7 @@ int delete_dhcp_serving_pool_option_all(struct dmctx *ctx)
|
|||
struct uci_list *val;
|
||||
struct uci_section *dmmap_s = NULL;
|
||||
struct uci_section *dmmap_ss = NULL;
|
||||
struct uci_section *lan_s = NULL;
|
||||
struct uci_element *e = NULL, *tmp;
|
||||
int dmmap = 0;
|
||||
uci_path_foreach_sections(icwmpd, "dmmap", section_name(poolargs->dhcppoolsection), dmmap_s)
|
||||
|
|
@ -349,7 +300,7 @@ int delete_dhcp_serving_pool_option_all(struct dmctx *ctx)
|
|||
if (val) {
|
||||
uci_foreach_element_safe(val, e, tmp)
|
||||
{
|
||||
dmuci_del_list_value_by_section(poolargs->dhcppoolsection, "dhcp_option", tmp->name); //TODO test it
|
||||
dmuci_del_list_value_by_section(poolargs->dhcppoolsection, "dhcp_option", tmp->name);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
|
@ -358,108 +309,72 @@ int delete_dhcp_serving_pool_option_all(struct dmctx *ctx)
|
|||
int delete_dhcp_serving_pool_option(struct dmctx *ctx)
|
||||
{
|
||||
int dmmap = 0;
|
||||
char *value, *tag, *instance, *bufopt;
|
||||
struct uci_list *val;
|
||||
struct uci_section *dmmap_s = NULL;
|
||||
struct uci_section *dmmap_ss = NULL;
|
||||
struct uci_element *e = NULL, *tmp;
|
||||
struct dhcppooloptionargs *pooloptionargs = (struct dhcppooloptionargs *)ctx->args;
|
||||
char *value, *tag, *instance, *bufopt;
|
||||
struct uci_list *val;
|
||||
struct uci_section *dmmap_s = NULL;
|
||||
struct uci_section *dmmap_ss = NULL, *lan_s = NULL;
|
||||
struct uci_element *e = NULL, *tmp;
|
||||
struct dhcppooloptionargs *pooloptionargs = (struct dhcppooloptionargs *)ctx->args;
|
||||
|
||||
dmuci_get_value_by_section_string(pooloptionargs->dhcppooloptionsection, "dhcp_option", &tag);
|
||||
dmuci_get_value_by_section_string(pooloptionargs->dhcppooloptionsection, "value", &value);
|
||||
dmasprintf(&bufopt, "%s,%s", tag, value);
|
||||
dmuci_get_value_by_section_list(pooloptionargs->dhcppoolsection, "dhcp_option", &val);
|
||||
if (val) {
|
||||
uci_foreach_element_safe(val, e, tmp)
|
||||
{
|
||||
if (strcmp(tmp->name, bufopt) == 0) {
|
||||
dmuci_del_list_value_by_section(pooloptionargs->dhcppoolsection, "dhcp_option", tmp->name); //TODO test it
|
||||
break;
|
||||
dmuci_get_value_by_section_string(pooloptionargs->dhcppooloptionsection, "tag", &tag);
|
||||
dmuci_get_value_by_section_string(pooloptionargs->dhcppooloptionsection, "value", &value);
|
||||
dmasprintf(&bufopt, "%s,%s", tag, value);
|
||||
dmuci_get_value_by_section_list(pooloptionargs->dhcppoolsection, "dhcp_option", &val);
|
||||
if (val) {
|
||||
uci_foreach_element_safe(val, e, tmp)
|
||||
{
|
||||
if (strcmp(tmp->name, bufopt) == 0) {
|
||||
dmuci_del_list_value_by_section(pooloptionargs->dhcppoolsection, "dhcp_option", tmp->name); //TODO test it
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
dmfree(bufopt);
|
||||
DMUCI_DELETE_BY_SECTION(icwmpd, pooloptionargs->dhcppooloptionsection, NULL, NULL);
|
||||
return 0;
|
||||
dmfree(bufopt);
|
||||
DMUCI_DELETE_BY_SECTION(icwmpd, pooloptionargs->dhcppooloptionsection, NULL, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int add_dhcp_conditional_serving_pool(struct dmctx *ctx, char **instancepara)
|
||||
{
|
||||
char *value;
|
||||
char *instance;
|
||||
struct uci_section *s = NULL;
|
||||
|
||||
instance = get_last_instance("dhcp", "vendorclass", "poulinstance");
|
||||
dmuci_add_section("dhcp", "vendorclass", &s, &value);
|
||||
dmuci_set_value_by_section(s, "dhcp_option", "");
|
||||
*instancepara = update_instance(s, instance, "poulinstance");
|
||||
struct uci_section *dhcp_sec = NULL;
|
||||
uci_foreach_option_eq("dhcp", "dhcp", "interface", "lan", dhcp_sec)
|
||||
{
|
||||
instance = update_instance(dhcp_sec, instance, "poolinstance");
|
||||
}
|
||||
dmuci_add_section("dhcp", "dhcp", &dhcp_sec, &value);
|
||||
dmuci_set_value_by_section(dhcp_sec, "interface", "lan");
|
||||
dmuci_set_value_by_section(dhcp_sec, "start", "100");
|
||||
dmuci_set_value_by_section(dhcp_sec, "leasetime", "12h");
|
||||
dmuci_set_value_by_section(dhcp_sec, "limit", "150");
|
||||
*instancepara = update_instance(dhcp_sec, instance, "poolinstance");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int delete_dhcp_conditional_serving_pool_all(struct dmctx *ctx)
|
||||
{
|
||||
int found = 0;
|
||||
int dmmap = 0;
|
||||
char *lan_name;
|
||||
struct uci_section *s = NULL;
|
||||
struct uci_section *ss = NULL;
|
||||
struct uci_section *dmmap_s = NULL;
|
||||
struct uci_section *dmmap_ss = NULL;
|
||||
|
||||
uci_foreach_sections("dhcp", "vendorclass", s) {
|
||||
int found = 0;
|
||||
char *lan_name;
|
||||
struct uci_section *dhcp_sec = NULL;
|
||||
struct uci_section *ss = NULL;
|
||||
|
||||
uci_foreach_option_eq("dhcp", "dhcp", "interface", "lan", dhcp_sec)
|
||||
{
|
||||
if (found != 0)
|
||||
{
|
||||
uci_path_foreach_sections(icwmpd, "dmmap", section_name(ss), dmmap_s)
|
||||
{
|
||||
if (dmmap != 0)
|
||||
DMUCI_DELETE_BY_SECTION(icwmpd, dmmap_ss, NULL, NULL);
|
||||
dmmap_ss = dmmap_s;
|
||||
dmmap++;
|
||||
}
|
||||
if (dmmap_ss != NULL)
|
||||
DMUCI_DELETE_BY_SECTION(icwmpd, dmmap_ss, NULL, NULL);
|
||||
dmmap = 0;
|
||||
dmmap_ss = NULL;
|
||||
dmuci_delete_by_section(ss, NULL, NULL);
|
||||
}
|
||||
ss = s;
|
||||
ss = dhcp_sec;
|
||||
found++;
|
||||
}
|
||||
if (ss != NULL)
|
||||
{
|
||||
uci_path_foreach_sections(icwmpd, "dmmap", section_name(ss), dmmap_s)
|
||||
{
|
||||
if (dmmap != 0)
|
||||
DMUCI_DELETE_BY_SECTION(icwmpd, dmmap_ss, NULL, NULL);
|
||||
dmmap_ss = dmmap_s;
|
||||
dmmap++;
|
||||
}
|
||||
if (dmmap_ss != NULL)
|
||||
DMUCI_DELETE_BY_SECTION(icwmpd, dmmap_ss, NULL, NULL);
|
||||
dmuci_delete_by_section(ss, NULL, NULL);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int delete_dhcp_conditional_serving_pool(struct dmctx *ctx)
|
||||
{
|
||||
struct dhcppoolargs *poolargs = (struct dhcppoolargs *)ctx->args;
|
||||
int dmmap = 0;
|
||||
struct uci_section *dmmap_s = NULL;
|
||||
struct uci_section *dmmap_ss = NULL;
|
||||
|
||||
|
||||
uci_path_foreach_sections(icwmpd, "dmmap", section_name(poolargs->dhcppoolsection), dmmap_s)
|
||||
{
|
||||
if (dmmap)
|
||||
DMUCI_DELETE_BY_SECTION(icwmpd, dmmap_ss, NULL, NULL);
|
||||
dmmap_ss = dmmap_s;
|
||||
dmmap++;
|
||||
}
|
||||
if (dmmap_ss != NULL)
|
||||
DMUCI_DELETE_BY_SECTION(icwmpd, dmmap_ss, NULL, NULL);
|
||||
dmuci_delete_by_section(poolargs->dhcppoolsection, NULL, NULL);
|
||||
dmuci_delete_by_section(cur_dhcppoolargs.dhcppoolsection, NULL, NULL);
|
||||
return 0;
|
||||
}
|
||||
int add_landevice_dhcpstaticaddress(struct dmctx *ctx, char **instancepara)
|
||||
|
|
@ -469,7 +384,6 @@ int add_landevice_dhcpstaticaddress(struct dmctx *ctx, char **instancepara)
|
|||
struct uci_section *s = NULL;
|
||||
struct ldlanargs *lanargs = (struct ldlanargs *)ctx->args;
|
||||
char *lan_name = section_name(lanargs->ldlansection);
|
||||
|
||||
instance = get_last_instance_lev2("dhcp", "host", "ldhcpinstance", "dhcp", lan_name);
|
||||
dmuci_add_section("dhcp", "host", &s, &value);
|
||||
dmuci_set_value_by_section(s, "dhcp", lan_name);
|
||||
|
|
@ -563,22 +477,21 @@ int delete_landevice_wlanconfiguration(struct dmctx *ctx)
|
|||
int get_lan_dns(char *refparam, struct dmctx *ctx, char **value)
|
||||
{
|
||||
json_object *res;
|
||||
struct uci_section *s = NULL;
|
||||
int len;
|
||||
struct ldlanargs *lanargs = (struct ldlanargs *)ctx->args;
|
||||
char *lan_name = section_name(lanargs->ldlansection);
|
||||
char buf[256] = "";
|
||||
|
||||
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", lan_name, String}}, 1, &res);
|
||||
DM_ASSERT(res, *value = "");
|
||||
*value = dmjson_get_value_array_all(res, DELIMITOR, 1, "dns-server");
|
||||
if ((*value)[0] == '\0') {
|
||||
dmuci_get_value_by_section_string(lanargs->ldlansection, "dns", value);
|
||||
*value = dmstrdup(*value); // MEM WILL BE FREED IN DMMEMCLEAN
|
||||
char *p = *value;
|
||||
while (*p) {
|
||||
if (*p == ' ' && p != *value && *(p-1) != ',')
|
||||
*p++ = ',';
|
||||
else
|
||||
p++;
|
||||
uci_foreach_option_eq("dhcp", "dhcp", "interface", lan_name, s) {
|
||||
if (get_uci_dhcpserver_option(s, "6", buf) == 0) {
|
||||
*value = dmstrdup(buf);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ((*value)[0] == '\0') {
|
||||
|
|
@ -590,22 +503,22 @@ int get_lan_dns(char *refparam, struct dmctx *ctx, char **value)
|
|||
int set_lan_dns(char *refparam, struct dmctx *ctx, int action, char *value)
|
||||
{
|
||||
struct ldlanargs *lanargs = (struct ldlanargs *)ctx->args;
|
||||
struct uci_section *s = NULL, *dmmap_s = NULL;
|
||||
char *lan_name = section_name(lanargs->ldlansection);
|
||||
char *dup, *p;
|
||||
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
return 0;
|
||||
case VALUESET:
|
||||
dup = dmstrdup(value);
|
||||
p = dup;
|
||||
while (*p) {
|
||||
if (*p == ',')
|
||||
*p++ = ' ';
|
||||
else
|
||||
p++;
|
||||
uci_foreach_option_eq("dhcp", "dhcp", "interface", lan_name, s) {
|
||||
set_uci_dhcpserver_option(s, "6", value);
|
||||
break;
|
||||
}
|
||||
uci_path_foreach_option_eq(icwmpd, "dmmap", lan_name, "tag", "6", dmmap_s) {
|
||||
DMUCI_SET_VALUE_BY_SECTION(icwmpd, dmmap_s, "value", value);
|
||||
break;
|
||||
}
|
||||
dmuci_set_value_by_section(lanargs->ldlansection, "dns", dup);
|
||||
dmfree(dup);
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
|
|
@ -3252,7 +3165,7 @@ int set_lan_eth_alias(char *refparam, struct dmctx *ctx, int action, char *value
|
|||
}
|
||||
int get_dhcp_conditional_servingpool_alias(char *refparam, struct dmctx *ctx, char **value)
|
||||
{
|
||||
dmuci_get_value_by_section_string(cur_dhcppoolargs.dhcppoolsection, "poulalias", value);
|
||||
dmuci_get_value_by_section_string(cur_dhcppoolargs.dhcppoolsection, "poolalias", value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -3262,7 +3175,7 @@ int set_dhcp_conditional_servingpool_alias(char *refparam, struct dmctx *ctx, in
|
|||
case VALUECHECK:
|
||||
return 0;
|
||||
case VALUESET:
|
||||
dmuci_set_value_by_section(cur_dhcppoolargs.dhcppoolsection, "poulalias", value);
|
||||
dmuci_set_value_by_section(cur_dhcppoolargs.dhcppoolsection, "poolalias", value);
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
|
|
@ -3337,7 +3250,7 @@ int get_dhcp_servingpool_alias(char *refparam, struct dmctx *ctx, char **value)
|
|||
{
|
||||
struct dhcppooloptionargs *pooloptionargs = (struct dhcppooloptionargs *)ctx->args;
|
||||
|
||||
dmuci_get_value_by_section_string(pooloptionargs->dhcppooloptionsection, "optionalias", value);
|
||||
dmuci_get_value_by_section_string(pooloptionargs->dhcppooloptionsection, "option_alias", value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -3349,7 +3262,7 @@ int set_dhcp_servingpool_alias(char *refparam, struct dmctx *ctx, int action, ch
|
|||
case VALUECHECK:
|
||||
return 0;
|
||||
case VALUESET:
|
||||
DMUCI_SET_VALUE_BY_SECTION(icwmpd, pooloptionargs->dhcppooloptionsection, "optionalias", value);
|
||||
DMUCI_SET_VALUE_BY_SECTION(icwmpd, pooloptionargs->dhcppooloptionsection, "option_alias", value);
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
|
|
@ -3360,7 +3273,7 @@ int get_dhcp_servingpool_tag(char *refparam, struct dmctx *ctx, char **value)
|
|||
{
|
||||
struct dhcppooloptionargs *pooloptionargs = (struct dhcppooloptionargs *)ctx->args;
|
||||
|
||||
dmuci_get_value_by_section_string(pooloptionargs->dhcppooloptionsection, "dhcp_option", value);
|
||||
dmuci_get_value_by_section_string(pooloptionargs->dhcppooloptionsection, "tag", value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -3368,6 +3281,7 @@ int set_dhcp_servingpool_tag(char *refparam, struct dmctx *ctx, int action, char
|
|||
{
|
||||
char *tmp = NULL;
|
||||
char *option_tmp = NULL;
|
||||
struct uci_section *lan_s =NULL;
|
||||
struct dhcppooloptionargs *pooloptionargs = (struct dhcppooloptionargs *)ctx->args;
|
||||
|
||||
switch (action) {
|
||||
|
|
@ -3375,9 +3289,9 @@ int set_dhcp_servingpool_tag(char *refparam, struct dmctx *ctx, int action, char
|
|||
return 0;
|
||||
case VALUESET:
|
||||
dmuci_get_value_by_section_string(pooloptionargs->dhcppooloptionsection, "value", &tmp);
|
||||
dmuci_get_value_by_section_string(pooloptionargs->dhcppooloptionsection, "dhcp_option", &option_tmp);
|
||||
dmuci_get_value_by_section_string(pooloptionargs->dhcppooloptionsection, "tag", &option_tmp);
|
||||
update_uci_dhcpserver_option(ctx, pooloptionargs->dhcppoolsection, option_tmp, value, tmp);
|
||||
DMUCI_SET_VALUE_BY_SECTION(icwmpd, pooloptionargs->dhcppooloptionsection, "dhcp_option", value);
|
||||
DMUCI_SET_VALUE_BY_SECTION(icwmpd, pooloptionargs->dhcppooloptionsection, "tag", value);
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
|
|
@ -3395,14 +3309,15 @@ int set_dhcp_servingpool_value(char *refparam, struct dmctx *ctx, int action, ch
|
|||
{
|
||||
|
||||
char *tmp;
|
||||
struct uci_section *lan_s =NULL;
|
||||
struct dhcppooloptionargs *pooloptionargs = (struct dhcppooloptionargs *)ctx->args;
|
||||
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
return 0;
|
||||
case VALUESET:
|
||||
dmuci_get_value_by_section_string(pooloptionargs->dhcppooloptionsection, "dhcp_option", &tmp);
|
||||
set_uci_dhcpserver_option(ctx, pooloptionargs->dhcppoolsection, tmp, value);
|
||||
dmuci_get_value_by_section_string(pooloptionargs->dhcppooloptionsection, "tag", &tmp);
|
||||
set_uci_dhcpserver_option(pooloptionargs->dhcppoolsection, tmp, value);
|
||||
DMUCI_SET_VALUE_BY_SECTION(icwmpd, pooloptionargs->dhcppooloptionsection, "value", value);
|
||||
|
||||
return 0;
|
||||
|
|
@ -3414,11 +3329,12 @@ inline int entry_landevice_sub(struct dmctx *ctx)
|
|||
{
|
||||
struct uci_section *s = NULL;
|
||||
char *idev = NULL, *idev_last = NULL;
|
||||
|
||||
char *interface = NULL;
|
||||
uci_foreach_filter_func("network", "interface", NULL, &filter_lan_device_interface, s) {
|
||||
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);
|
||||
dmuci_get_value_by_section_string(s, "interface", &interface);
|
||||
SUBENTRY(entry_landevice_sub_instance, ctx, s, interface, idev);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -3576,26 +3492,29 @@ inline int entry_landevice_host(struct dmctx *ctx, struct uci_section *landevice
|
|||
return 0;
|
||||
}
|
||||
|
||||
inline int entry_landevice_lanhostconfigmanagement_dhcpconditionalservingpool(struct dmctx *ctx, char *idev)
|
||||
inline int entry_landevice_lanhostconfigmanagement_dhcpconditionalservingpool(struct dmctx *ctx, struct uci_section *landevice_section, char *interface, char *idev)
|
||||
{
|
||||
struct uci_section *s = NULL;
|
||||
|
||||
struct uci_section *dhcp_sec = NULL;
|
||||
char *icondpool = NULL, *icondpool_last = NULL;
|
||||
uci_foreach_sections("dhcp", "vendorclass", s) {
|
||||
init_args_dhcp_conditional_servingpool_entry(ctx, s);
|
||||
icondpool = handle_update_instance(1, ctx, &icondpool_last, update_instance_alias, 3, s, "poulinstance", "poulalias");
|
||||
SUBENTRY(entry_landevice_lanhostconfigmanagement_dhcpconditionalservingpool_instance, ctx, idev, icondpool);
|
||||
struct ldlanargs *lanargs = (struct ldlanargs *)ctx->args;
|
||||
uci_foreach_option_eq("dhcp", "dhcp", "interface", "lan", dhcp_sec)
|
||||
{
|
||||
init_args_dhcp_conditional_servingpool_entry(ctx, dhcp_sec);
|
||||
icondpool = handle_update_instance(1, ctx, &icondpool_last, update_instance_alias, 3, dhcp_sec, "poolinstance", "poolalias");
|
||||
SUBENTRY(entry_landevice_lanhostconfigmanagement_dhcpconditionalservingpool_instance, ctx, interface, idev, icondpool);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline int entry_landevice_dhcpconditionalservingpool_option(struct dmctx *ctx, char *idev, char *icondpool)
|
||||
inline int entry_landevice_dhcpconditionalservingpool_option(struct dmctx *ctx, char *interface, char *idev, char *icondpool)
|
||||
{
|
||||
int id = 0;
|
||||
char *idx = NULL, *pch, *spch, *name, *value;
|
||||
char *idx_last = NULL;
|
||||
struct uci_list *val;
|
||||
struct uci_element *e = NULL, *tmp;
|
||||
struct uci_section *ss = NULL;
|
||||
struct uci_section *dmmap_s = NULL, *lan_s = NULL;
|
||||
struct dhcppoolargs *poolargs = (struct dhcppoolargs *)ctx->args;
|
||||
bool find_max = true;
|
||||
char *tt;
|
||||
|
|
@ -3603,34 +3522,34 @@ inline int entry_landevice_dhcpconditionalservingpool_option(struct dmctx *ctx,
|
|||
int found = 0;
|
||||
dmuci_get_value_by_section_list(poolargs->dhcppoolsection, "dhcp_option", &val);
|
||||
if (val) {
|
||||
uci_foreach_element_safe(val, e, tmp)
|
||||
{
|
||||
uci_foreach_element_safe(val, e, tmp){
|
||||
tt = dmstrdup(tmp->name);
|
||||
pch = strtok_r(tt, ",", &spch);
|
||||
found = 0;
|
||||
uci_path_foreach_option_eq(icwmpd, "dmmap", section_name(poolargs->dhcppoolsection), "dhcp_option", pch, ss)
|
||||
{
|
||||
dmuci_get_value_by_section_string(ss, "value", &value);
|
||||
uci_path_foreach_option_eq(icwmpd, "dmmap", section_name(poolargs->dhcppoolsection), "tag", pch, dmmap_s){
|
||||
dmuci_get_value_by_section_string(dmmap_s, "value", &value);
|
||||
if (strcmp(spch, value) == 0)
|
||||
{
|
||||
dmuci_get_value_by_section_string(ss, "optioninst", &idx);
|
||||
dmuci_get_value_by_section_string(dmmap_s, "option_instance", &idx);
|
||||
found = 1;
|
||||
}
|
||||
else
|
||||
continue;
|
||||
init_args_pool_option(ctx, ss, poolargs->dhcppoolsection);
|
||||
init_args_pool_option(ctx, dmmap_s, poolargs->dhcppoolsection);
|
||||
SUBENTRY(entry_landevice_dhcpconditionalservingpool_option_instance, ctx, idev, icondpool, idx);
|
||||
dmfree(tt);
|
||||
break;
|
||||
}
|
||||
if (!found)
|
||||
{
|
||||
DMUCI_ADD_SECTION(icwmpd, "dmmap", section_name(poolargs->dhcppoolsection), &ss, &name);
|
||||
DMUCI_SET_VALUE_BY_SECTION(icwmpd, ss, "dhcp_option", pch);
|
||||
DMUCI_SET_VALUE_BY_SECTION(icwmpd, ss, "value", spch);
|
||||
init_args_pool_option(ctx, ss, poolargs->dhcppoolsection);
|
||||
idx = handle_update_instance(1, ctx, &idx_last, dhcp_option_update_instance_alias_icwmpd, 4, ss, "optioninst", "optionalias", &find_max);
|
||||
DMUCI_SET_VALUE_BY_SECTION(icwmpd, ss, "optioninst", idx);
|
||||
if(idx!=NULL)
|
||||
idx_last=dmstrdup(idx);
|
||||
DMUCI_ADD_SECTION(icwmpd, "dmmap", section_name(poolargs->dhcppoolsection), &dmmap_s, &name);
|
||||
DMUCI_SET_VALUE_BY_SECTION(icwmpd, dmmap_s, "tag", pch);
|
||||
DMUCI_SET_VALUE_BY_SECTION(icwmpd, dmmap_s, "value", spch);
|
||||
init_args_pool_option(ctx, dmmap_s, poolargs->dhcppoolsection);
|
||||
idx = handle_update_instance(2, ctx, &idx_last, update_instance_alias, 3, dmmap_s, "option_instance", "option_alias");
|
||||
DMUCI_SET_VALUE_BY_SECTION(icwmpd, dmmap_s, "option_instance", idx);
|
||||
SUBENTRY(entry_landevice_dhcpconditionalservingpool_option_instance, ctx, idev, icondpool, idx);
|
||||
dmfree(tt);
|
||||
}
|
||||
|
|
@ -3650,7 +3569,7 @@ int entry_method_root_LANDevice(struct dmctx *ctx)
|
|||
return FAULT_9005;
|
||||
}
|
||||
|
||||
inline int entry_landevice_sub_instance(struct dmctx *ctx, struct uci_section *landevice_section, char *idev)
|
||||
inline int entry_landevice_sub_instance(struct dmctx *ctx, struct uci_section *landevice_section, char *interface, char *idev)
|
||||
{
|
||||
IF_MATCH(ctx, DMROOT"LANDevice.%s.", idev) {
|
||||
DMOBJECT(DMROOT"LANDevice.%s.", ctx, "0", 0, NULL, NULL, NULL, idev);
|
||||
|
|
@ -3678,13 +3597,13 @@ inline int entry_landevice_sub_instance(struct dmctx *ctx, struct uci_section *l
|
|||
SUBENTRY(entry_landevice_wlanconfiguration, ctx, landevice_section, idev);
|
||||
SUBENTRY(entry_landevice_lanethernetinterfaceconfig, ctx, landevice_section, idev);
|
||||
SUBENTRY(entry_landevice_host, ctx, landevice_section, idev);
|
||||
SUBENTRY(entry_landevice_lanhostconfigmanagement_dhcpconditionalservingpool, ctx, idev);
|
||||
SUBENTRY(entry_landevice_lanhostconfigmanagement_dhcpconditionalservingpool, ctx, landevice_section, interface, idev);
|
||||
return 0;
|
||||
}
|
||||
return FAULT_9005;
|
||||
}
|
||||
|
||||
inline int entry_landevice_lanhostconfigmanagement_dhcpconditionalservingpool_instance(struct dmctx *ctx, char * idev, char *icondpool)
|
||||
inline int entry_landevice_lanhostconfigmanagement_dhcpconditionalservingpool_instance(struct dmctx *ctx, char *interface, char * idev, char *icondpool)
|
||||
{
|
||||
IF_MATCH(ctx, DMROOT"LANDevice.%s.LANHostConfigManagement.DHCPConditionalServingPool.%s.", idev, icondpool) {
|
||||
DMOBJECT(DMROOT"LANDevice.%s.LANHostConfigManagement.DHCPConditionalServingPool.%s.", ctx, "1", 1, NULL, delete_dhcp_conditional_serving_pool, NULL, idev, icondpool);
|
||||
|
|
@ -3693,7 +3612,7 @@ inline int entry_landevice_lanhostconfigmanagement_dhcpconditionalservingpool_in
|
|||
DMPARAM("VendorClassID", ctx, "1", get_dhcp_conditional_servingpool_vendorclassid, set_dhcp_conditional_servingpool_vendorclassid, NULL, 0, 1, UNDEF, NULL);
|
||||
DMPARAM("X_INTENO_COM_Networkid", ctx, "1", get_dhcp_conditional_servingpool_network_id, set_dhcp_conditional_servingpool_network_id, NULL, 0, 1, UNDEF, NULL);
|
||||
DMOBJECT(DMROOT"LANDevice.%s.LANHostConfigManagement.DHCPConditionalServingPool.%s.DHCPOption.", ctx, "1", 0, add_dhcp_serving_pool_option, delete_dhcp_serving_pool_option_all, NULL, idev, icondpool);
|
||||
SUBENTRY(entry_landevice_dhcpconditionalservingpool_option, ctx, idev, icondpool);
|
||||
SUBENTRY(entry_landevice_dhcpconditionalservingpool_option, ctx, interface, idev, icondpool);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
* Copyright (C) 2016 Inteno Broadband Technology AB
|
||||
* Author: Anis Ellouze <anis.ellouze@pivasoftware.com>
|
||||
* Author Omar Kallel <omar.kallel@pivasoftware.com>
|
||||
* Author Feten Besbes <feten.besbes@pivasoftware.com>
|
||||
*/
|
||||
|
||||
#include <uci.h>
|
||||
|
|
@ -24,6 +25,7 @@
|
|||
struct dhcp_args cur_dhcp_args = {0};
|
||||
struct client_args cur_dhcp_client_args = {0};
|
||||
struct dhcp_static_args cur_dhcp_staticargs = {0};
|
||||
struct dhcp_option_args cur_dhcp_optionargs = {0};
|
||||
struct dhcp_client_ipv4address_args cur_dhcp_client_ipv4address_args = {0};
|
||||
|
||||
/*************************************************************
|
||||
|
|
@ -45,6 +47,18 @@ inline int init_args_dhcp_host(struct dmctx *ctx, struct uci_section *s)
|
|||
return 0;
|
||||
}
|
||||
|
||||
inline int init_args_option(struct dmctx *ctx, struct uci_section *pool_option_section, struct uci_section *pool_section, char *ipool, char *interface)
|
||||
{
|
||||
struct dhcp_option_args *args = &cur_dhcp_optionargs;
|
||||
ctx->args = (void *)args;
|
||||
args->dhcpoptionsection = pool_option_section;
|
||||
args->dhcppoolsection = pool_section;
|
||||
args->poolinstance = ipool;
|
||||
args->poolinterface = interface;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
inline int init_dhcp_client_args(struct dmctx *ctx, json_object *client)
|
||||
{
|
||||
struct client_args *args = &cur_dhcp_client_args;
|
||||
|
|
@ -131,12 +145,90 @@ int delete_dhcp_staticaddress(struct dmctx *ctx)
|
|||
dmuci_delete_by_section(dhcpargs->dhcpsection, NULL, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int add_dhcp_option(struct dmctx *ctx, char **instancepara)
|
||||
{
|
||||
char val[64];
|
||||
char *value, *instance;
|
||||
struct uci_section *s = NULL, *lan_s = NULL;
|
||||
struct dhcp_args *dhcpargs = (struct dhcp_args *)ctx->args;
|
||||
char *itf_name = dhcpargs->interface;
|
||||
|
||||
instance = get_last_instance(DMMAP, section_name(dhcpargs->dhcp_sec), "option_instance");
|
||||
DMUCI_ADD_SECTION(icwmpd, "dmmap", section_name(dhcpargs->dhcp_sec), &s, &value);
|
||||
DMUCI_SET_VALUE_BY_SECTION(icwmpd, s, "tag", "0");
|
||||
*instancepara = update_instance_icwmpd(s, instance, "option_instance");
|
||||
sprintf(val, "option_%s", *instancepara);
|
||||
DMUCI_SET_VALUE_BY_SECTION(icwmpd, s, "value", val);
|
||||
sprintf(val, "0,option_%s", *instancepara);
|
||||
dmuci_add_list_value_by_section(dhcpargs->dhcp_sec, "dhcp_option", val);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int delete_dhcp_option_all(struct dmctx *ctx)
|
||||
{
|
||||
struct dhcp_args *poolargs = (struct dhcp_args *)ctx->args;
|
||||
char *value;
|
||||
char *instance;
|
||||
struct uci_list *val;
|
||||
struct uci_section *dmmap_s = NULL;
|
||||
struct uci_section *dmmap_ss = NULL;
|
||||
struct uci_section *lan_s = NULL;
|
||||
struct uci_element *e = NULL, *tmp;
|
||||
int dmmap = 0;
|
||||
uci_path_foreach_sections(icwmpd, "dmmap", section_name(poolargs->dhcp_sec), dmmap_s)
|
||||
{
|
||||
if (dmmap)
|
||||
DMUCI_DELETE_BY_SECTION(icwmpd, dmmap_ss, NULL, NULL);
|
||||
dmmap_ss = dmmap_s;
|
||||
dmmap++;
|
||||
}
|
||||
if (dmmap_ss != NULL)
|
||||
DMUCI_DELETE_BY_SECTION(icwmpd, dmmap_ss, NULL, NULL);
|
||||
dmuci_get_value_by_section_list(poolargs->dhcp_sec, "dhcp_option", &val);
|
||||
if (val) {
|
||||
uci_foreach_element_safe(val, e, tmp)
|
||||
{
|
||||
dmuci_del_list_value_by_section(poolargs->dhcp_sec, "dhcp_option", tmp->name);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int delete_dhcp_option(struct dmctx *ctx)
|
||||
{
|
||||
int dmmap = 0;
|
||||
char *value, *tag, *instance, *bufopt;
|
||||
struct uci_list *val;
|
||||
struct uci_section *dmmap_s = NULL;
|
||||
struct uci_section *dmmap_ss = NULL, *lan_s = NULL;
|
||||
struct uci_element *e = NULL, *tmp;
|
||||
struct dhcp_option_args *pooloptionargs = (struct dhcp_option_args *)ctx->args;
|
||||
//dmmap section
|
||||
dmuci_get_value_by_section_string(pooloptionargs->dhcpoptionsection, "tag", &tag);
|
||||
dmuci_get_value_by_section_string(pooloptionargs->dhcpoptionsection, "value", &value);
|
||||
dmasprintf(&bufopt, "%s,%s", tag, value);
|
||||
dmuci_get_value_by_section_list(pooloptionargs->dhcppoolsection, "dhcp_option", &val);
|
||||
if (val) {
|
||||
uci_foreach_element_safe(val, e, tmp)
|
||||
{
|
||||
if (strcmp(tmp->name, bufopt) == 0) {
|
||||
dmuci_del_list_value_by_section(pooloptionargs->dhcppoolsection, "dhcp_option", tmp->name); //TODO test it
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
dmfree(bufopt);
|
||||
DMUCI_DELETE_BY_SECTION(icwmpd, pooloptionargs->dhcpoptionsection, NULL, NULL);
|
||||
return 0;
|
||||
}
|
||||
/*************************************************************
|
||||
* GET & SET PARAM
|
||||
/*************************************************************/
|
||||
int get_dns_server(char *refparam, struct dmctx *ctx, char **value)
|
||||
{
|
||||
json_object *res;
|
||||
char buf[256] = "";
|
||||
int len;
|
||||
|
||||
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", cur_dhcp_args.interface, String}}, 1, &res);
|
||||
|
|
@ -147,14 +239,8 @@ int get_dns_server(char *refparam, struct dmctx *ctx, char **value)
|
|||
else
|
||||
*value = "";
|
||||
if ((*value)[0] == '\0') {
|
||||
dmuci_get_option_value_string("network", cur_dhcp_args.interface, "dns", value);
|
||||
*value = dmstrdup(*value); // MEM WILL BE FREED IN DMMEMCLEAN
|
||||
char *p = *value;
|
||||
while (*p) {
|
||||
if (*p == ' ' && p != *value && *(p-1) != ',')
|
||||
*p++ = ',';
|
||||
else
|
||||
p++;
|
||||
if (get_uci_dhcpserver_option(cur_dhcp_args.dhcp_sec, "6", buf) == 0) {
|
||||
*value = dmstrdup(buf);
|
||||
}
|
||||
}
|
||||
if ((*value)[0] == '\0') {
|
||||
|
|
@ -166,21 +252,16 @@ int get_dns_server(char *refparam, struct dmctx *ctx, char **value)
|
|||
int set_dns_server(char *refparam, struct dmctx *ctx, int action, char *value)
|
||||
{
|
||||
char *dup, *p;
|
||||
|
||||
struct uci_section *dmmap_s = NULL;
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
return 0;
|
||||
case VALUESET:
|
||||
dup = dmstrdup(value);
|
||||
p = dup;
|
||||
while (*p) {
|
||||
if (*p == ',')
|
||||
*p++ = ' ';
|
||||
else
|
||||
p++;
|
||||
set_uci_dhcpserver_option(cur_dhcp_args.dhcp_sec, "6", value);
|
||||
uci_path_foreach_option_eq(icwmpd, "dmmap", section_name(cur_dhcp_args.dhcp_sec), "tag", "6", dmmap_s) {
|
||||
DMUCI_SET_VALUE_BY_SECTION(icwmpd, dmmap_s, "value", value);
|
||||
break;
|
||||
}
|
||||
dmuci_set_value("network", cur_dhcp_args.interface, "dns", dup);
|
||||
dmfree(dup);
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
|
|
@ -853,6 +934,69 @@ int get_dhcp_client_chaddr(char *refparam, struct dmctx *ctx, char **value)
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int get_dhcp_option_alias(char *refparam, struct dmctx *ctx, char **value)
|
||||
{
|
||||
dmuci_get_value_by_section_string(cur_dhcp_optionargs.dhcpoptionsection, "option_alias", value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int set_dhcp_option_alias(char *refparam, struct dmctx *ctx, int action, char *value)
|
||||
{
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
return 0;
|
||||
case VALUESET:
|
||||
dmuci_get_value_by_section_string(cur_dhcp_optionargs.dhcpoptionsection, "option_alias", value);
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int get_dhcp_option_tag(char *refparam, struct dmctx *ctx, char **value)
|
||||
{
|
||||
dmuci_get_value_by_section_string(cur_dhcp_optionargs.dhcpoptionsection, "tag", value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int set_dhcp_option_tag(char *refparam, struct dmctx *ctx, int action, char *value)
|
||||
{
|
||||
char *cur_tag, *cur_value, *instance;
|
||||
struct dhcp_option_args *pooloptionargs = (struct dhcp_option_args *)ctx->args;
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
return 0;
|
||||
case VALUESET:
|
||||
dmuci_get_value_by_section_string(pooloptionargs->dhcpoptionsection, "value", &cur_value);
|
||||
dmuci_get_value_by_section_string(pooloptionargs->dhcpoptionsection, "tag", &cur_tag);
|
||||
DMUCI_SET_VALUE_BY_SECTION(icwmpd, pooloptionargs->dhcpoptionsection, "tag", value);
|
||||
update_uci_dhcpserver_option(ctx, pooloptionargs->dhcppoolsection, cur_tag, value, cur_value);
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int get_dhcp_option_value(char *refparam, struct dmctx *ctx, char **value)
|
||||
{
|
||||
dmuci_get_value_by_section_string(cur_dhcp_optionargs.dhcpoptionsection, "value", value);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int set_dhcp_option_value(char *refparam, struct dmctx *ctx, int action, char *value)
|
||||
{
|
||||
char *cur_tag, *cur_value;
|
||||
struct dhcp_option_args *pooloptionargs = (struct dhcp_option_args *)ctx->args;
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
return 0;
|
||||
case VALUESET:
|
||||
dmuci_get_value_by_section_string(pooloptionargs->dhcpoptionsection, "tag", &cur_tag);
|
||||
DMUCI_SET_VALUE_BY_SECTION(icwmpd, pooloptionargs->dhcpoptionsection, "value", value);
|
||||
set_uci_dhcpserver_option(pooloptionargs->dhcppoolsection, cur_tag, value);
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*************************************************************
|
||||
* ENTRY METHOD
|
||||
/*************************************************************/
|
||||
|
|
@ -932,6 +1076,8 @@ inline int entry_dhcp_instance(struct dmctx *ctx, char *interface, char *int_num
|
|||
SUBENTRY(entry_dhcp_static_address, ctx, interface, int_num);
|
||||
DMOBJECT(DMROOT"DHCPv4.Server.Pool.%s.Client.", ctx, "0", NULL, NULL, NULL, NULL, int_num); //TODO
|
||||
SUBENTRY(entry_dhcp_client, ctx, interface, int_num);
|
||||
DMOBJECT(DMROOT"DHCPv4.Server.Pool.%s.Option.", ctx, "0", NULL, add_dhcp_option, delete_dhcp_option_all, NULL, int_num);
|
||||
SUBENTRY(entry_dhcp_option, ctx, interface, int_num);
|
||||
return 0;
|
||||
}
|
||||
return FAULT_9005;
|
||||
|
|
@ -949,6 +1095,69 @@ inline int entry_dhcp_static_address(struct dmctx *ctx, char *interface, char *i
|
|||
}
|
||||
}
|
||||
|
||||
inline int entry_dhcp_option (struct dmctx *ctx, char *interface, char *pool_instance)
|
||||
{
|
||||
int id = 0;
|
||||
char *idx = NULL, *pch, *spch, *name, *value;
|
||||
char *idx_last = NULL;
|
||||
struct uci_list *val;
|
||||
struct uci_element *e = NULL, *tmp;
|
||||
struct uci_section *dmmap_s = NULL, *s= NULL;
|
||||
struct dhcp_args *poolargs = (struct dhcp_args *)ctx->args;
|
||||
bool find_max = true;
|
||||
char *tt;
|
||||
|
||||
int found = 0;
|
||||
dmuci_get_value_by_section_list(poolargs->dhcp_sec, "dhcp_option", &val);
|
||||
if (val) {
|
||||
uci_foreach_element_safe(val, e, tmp)
|
||||
{
|
||||
tt = dmstrdup(tmp->name);
|
||||
pch = strtok_r(tt, ",", &spch);
|
||||
found = 0;
|
||||
uci_path_foreach_option_eq(icwmpd, "dmmap", section_name(poolargs->dhcp_sec), "tag", pch, dmmap_s)
|
||||
{
|
||||
dmuci_get_value_by_section_string(dmmap_s, "value", &value);
|
||||
if (strcmp(spch, value) == 0)
|
||||
{
|
||||
dmuci_get_value_by_section_string(dmmap_s, "option_instance", &idx);
|
||||
found = 1;
|
||||
}
|
||||
else
|
||||
continue;
|
||||
init_args_option(ctx, dmmap_s, poolargs->dhcp_sec, pool_instance, interface);
|
||||
SUBENTRY(entry_dhcp_option_instance, ctx, pool_instance, idx);
|
||||
dmfree(tt);
|
||||
break;
|
||||
}
|
||||
if (!found)
|
||||
{
|
||||
if(idx!=NULL)
|
||||
idx_last=dmstrdup(idx);
|
||||
DMUCI_ADD_SECTION(icwmpd, "dmmap", section_name(poolargs->dhcp_sec), &s, &value);
|
||||
DMUCI_SET_VALUE_BY_SECTION(icwmpd, s, "tag", pch);
|
||||
DMUCI_SET_VALUE_BY_SECTION(icwmpd, s, "value", spch);
|
||||
init_args_option(ctx, s, poolargs->dhcp_sec, pool_instance, interface);
|
||||
idx = handle_update_instance(2, ctx, &idx_last, update_instance_alias, 3, s, "option_instance", "option_alias");
|
||||
SUBENTRY(entry_dhcp_option_instance, ctx, pool_instance, idx);
|
||||
dmfree(tt);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline int entry_dhcp_option_instance(struct dmctx *ctx, char * pool_instance, char *option_instance)
|
||||
{
|
||||
IF_MATCH(ctx, DMROOT"DHCPv4.Server.Pool.%s.Option.%s.", pool_instance, option_instance) {
|
||||
DMOBJECT(DMROOT"DHCPv4.Server.Pool.%s.Option.%s.", ctx, "1", 1, NULL, delete_dhcp_option, NULL, pool_instance, option_instance);
|
||||
DMPARAM("Alias", ctx, "1", get_dhcp_option_alias, set_dhcp_option_alias, NULL, 0, 1, UNDEF, NULL);
|
||||
DMPARAM("Tag", ctx, "1", get_dhcp_option_tag, set_dhcp_option_tag, "xsd:unsignedInt", 0, 1, UNDEF, NULL);
|
||||
DMPARAM("Value", ctx, "1", get_dhcp_option_value, set_dhcp_option_value, "xsd:string", 0, 1, UNDEF, NULL);
|
||||
return 0;
|
||||
}
|
||||
return FAULT_9005;
|
||||
}
|
||||
|
||||
inline int entry_dhcp_static_address_instance(struct dmctx *ctx, char *int_num, char *st_address)
|
||||
{
|
||||
IF_MATCH(ctx, DMROOT"DHCPv4.Server.Pool.%s.StaticAddress.%s.", int_num, st_address) {
|
||||
|
|
|
|||
|
|
@ -23,6 +23,14 @@ struct dhcp_static_args
|
|||
struct uci_section *dhcpsection;
|
||||
};
|
||||
|
||||
struct dhcp_option_args
|
||||
{
|
||||
struct uci_section *dhcpoptionsection;
|
||||
struct uci_section *dhcppoolsection;
|
||||
char *poolinstance;
|
||||
char *poolinterface;
|
||||
};
|
||||
|
||||
struct client_args
|
||||
{
|
||||
json_object *client;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue