Ticket refs #8597 : Add DNS data model parameters

This commit is contained in:
Anis Ellouze 2016-04-26 14:58:57 +01:00
parent 5aeeda251d
commit a45d47f7ad
7 changed files with 182 additions and 7 deletions

View file

@ -57,7 +57,8 @@ icwmpd_SOURCES += \
../dm/dmtree/tr181/hosts.c \
../dm/dmtree/tr181/dhcp.c \
../dm/dmtree/tr181/ip.c \
../dm/dmtree/tr181/ppp.c
../dm/dmtree/tr181/ppp.c \
../dm/dmtree/tr181/dns.c
endif
icwmpd_CFLAGS = \
$(AM_CFLAGS) \

View file

@ -41,6 +41,7 @@
#include "dhcp.h"
#include "ip.h"
#include "ppp.h"
#include "dns.h"
static char *get_parameter_notification (struct dmctx *ctx, char *param);
static int remove_parameter_notification(char *param);
@ -130,6 +131,7 @@ struct prefix_method prefix_methods[] = {
{ DMROOT"DHCPv4.", 1, NULL, 0, &entry_method_root_dhcp },
{ DMROOT"IP.", 1, NULL, 0, &entry_method_root_ip },
{ DMROOT"PPP.", 1, NULL, 0, &entry_method_root_ppp },
{ DMROOT"DNS.", 1, NULL, 0, &entry_method_root_dns },
#endif
};

View file

@ -2930,7 +2930,7 @@ inline int entry_landevice_wlanconfiguration_associateddevice(struct dmctx *ctx,
{
int id = 0;
json_object *res, *wl_client_obj;
char *idx, *idx_last = NULL;
char *idx, *idx_last = NULL;
struct ldwlanargs *wlanargs = (struct ldwlanargs *)ctx->args;
dmubus_call("router", "sta", UBUS_ARGS{{"vif", wlanargs->wiface}}, 1, &res);

View file

@ -782,7 +782,6 @@ int get_port_lower_layer(char *refparam, struct dmctx *ctx, char **value)
if (*value == NULL)
*value = "";
return 0;
}
int set_port_lower_layer(char *refparam, struct dmctx *ctx, int action, char *value)
@ -845,7 +844,7 @@ int set_port_lower_layer(char *refparam, struct dmctx *ctx, int action, char *va
if(cur_bridging_port_args.ifname[0] == '\0')
dmuci_delete_by_section(cur_bridging_port_args.bridge_port_sec, NULL, NULL);// delete dmmap section after remove br_port_instance to adequate config
}
return 0;
return 0;
}
}
@ -959,7 +958,6 @@ inline int entry_bridging_sub(struct dmctx *ctx)
SUBENTRY(entry_bridge_instance, ctx, br_inst, br_inst_last);
SUBENTRY(entry_bridge_vlan_instance_sub, ctx, br_inst, br_inst_last);
SUBENTRY(entry_bridge_port_sub, ctx, ifname, br_inst, br_inst_last);
}
return 0;
}

149
dm/dmtree/tr181/dns.c Normal file
View file

@ -0,0 +1,149 @@
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* Copyright (C) 2016 Inteno Broadband Technology AB
* Author: Anis Ellouze <anis.ellouze@pivasoftware.com>
*
*/
#include <uci.h>
#include <stdio.h>
#include <ctype.h>
#include "dmuci.h"
#include "dmubus.h"
#include "dmcwmp.h"
#include "dmcommon.h"
#include "dns.h"
struct dns_args cur_dns_args = {0};
/*************************************************************
* INIT
/*************************************************************/
inline int init_dns_args(struct dmctx *ctx, struct uci_section *int_sec, char *dns_ip, int num)
{
struct dns_args *args = &cur_dns_args;
ctx->args = (void *)args;
args->int_sec = int_sec;
args->dns_ip = dns_ip;
args->num = num;
return 0;
}
/*************************************************************
* GET & SET PARAM
/*************************************************************/
int get_dns_enable(char *refparam, struct dmctx *ctx, char **value)
{
*value = "1";
return 0;
}
int get_dns_alias(char *refparam, struct dmctx *ctx, char **value)
{
dmasprintf(value, "cpe-%d", cur_dns_args.num);
return 0;
}
int get_dns_server_ip(char *refparam, struct dmctx *ctx, char **value)
{
*value = dmstrdup(cur_dns_args.dns_ip);
return 0;
}
int set_dns_server_ip(char *refparam, struct dmctx *ctx, int action, char *value)
{
char *dup, *p, *proto;
switch (action) {
case VALUECHECK:
dmuci_get_value_by_section_string(cur_dns_args.int_sec, "proto", &proto);
if (strcmp(proto, "static"))
return FAULT_9001;
return 0;
case VALUESET:
dup = dmstrdup(value);
for (p = dup; *p ; p++) {
if (*p == ',')
*p = ' ';
}
dmuci_set_value_by_section(cur_dns_args.int_sec, "dns", dup);
dmfree(dup);
return 0;
}
return 0;
}
int get_dns_interface(char *refparam, struct dmctx *ctx, char **value)
{
char *linker;
linker = dmstrdup(section_name(cur_dns_args.int_sec));
adm_entry_get_linker_param(DMROOT"IP.Interface.", linker, value); // MEM WILL BE FREED IN DMMEMCLEAN
if (*value == NULL)
*value = "";
dmfree(linker);
return 0;
}
/*************************************************************
* ENTRY METHOD
/*************************************************************/
int entry_method_root_dns(struct dmctx *ctx)
{
IF_MATCH(ctx, DMROOT"DNS.") {
DMOBJECT(DMROOT"DNS.", ctx, "0", 0, NULL, NULL, NULL);
DMOBJECT(DMROOT"DNS.Client.", ctx, "0", 1, NULL, NULL, NULL);
DMOBJECT(DMROOT"DNS.Client.Server.", ctx, "0", 1, NULL, NULL, NULL);
SUBENTRY(entry_dns, ctx);
return 0;
}
return FAULT_9005;
}
inline int entry_dns(struct dmctx *ctx)
{
struct uci_section *net_sec = NULL;
char *dns_inst;
char *idx, *idx_last = NULL;
json_object *res;
int id = 0;
char *tmp = NULL, *pch, *spch, *dns, *p;
uci_foreach_sections("network", "interface", net_sec) {
dmubus_call("network.interface", "status", UBUS_ARGS{{"interface", section_name(net_sec)}}, 1, &res);
DM_ASSERT(res, tmp = "");
json_parse_array(res, "dns-server", -1, NULL, &tmp);
if (tmp[0] == '\0') {
dmuci_get_value_by_section_string(net_sec, "dns", &dns);
if (dns[0] == '\0')
continue;
tmp = dmstrdup(dns); // MEM WILL BE FREED IN DMMEMCLEAN
for (p = tmp; *p ; p++) {
if (*p == ' ')
*p = ',';
}
}
for (pch = strtok_r(tmp, ",", &spch); pch != NULL; pch = strtok_r(NULL, ",", &spch)) {
idx = handle_update_instance(3, ctx, &idx_last, update_instance_without_section, 1, ++id);
init_dns_args(ctx, net_sec, pch, id);
SUBENTRY(entry_dns_instance, ctx, idx);
}
}
return 0;
}
inline int entry_dns_instance(struct dmctx *ctx, char *int_num)
{
IF_MATCH(ctx, DMROOT"DNS.Client.Server.%s.", int_num) {
DMOBJECT(DMROOT"DNS.Client.Server.%s.", ctx, "0", NULL, NULL, NULL, NULL, int_num);
DMPARAM("Enable", ctx, "0", get_dns_enable, NULL, "xsd:boolean", 0, 0, UNDEF, NULL);
DMPARAM("Status", ctx, "0", get_dns_enable, NULL, NULL, 0, 0, UNDEF, NULL);
DMPARAM("Alias", ctx, "0", get_dns_alias, NULL, NULL, 0, 0, UNDEF, NULL);
DMPARAM("DNSServer", ctx, "1", get_dns_server_ip, set_dns_server_ip, NULL, 0, 0, UNDEF, NULL);
DMPARAM("Interface", ctx, "0", get_dns_interface, NULL, NULL, 0, 0, UNDEF, NULL);
return 0;
}
return FAULT_9005;
}

23
dm/dmtree/tr181/dns.h Normal file
View file

@ -0,0 +1,23 @@
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* Copyright (C) 2016 Inteno Broadband Technology AB
* Author: Anis Ellouze <anis.ellouze@pivasoftware.com>
*
*/
#ifndef __DNS_H
#define __DNS_H
struct dns_args
{
struct uci_section *int_sec;
char *dns_ip;
int num;
};
int entry_method_root_dns(struct dmctx *ctx);
#endif

View file

@ -190,7 +190,7 @@ inline int entry_ip_interface(struct dmctx *ctx)
uci_foreach_sections("network", "interface", net_sec) {
dmuci_get_value_by_section_string(net_sec, "type", &type);
if (!strcmp(type,"alias"))
if (!strcmp(type, "alias"))
continue;
init_ip_args(ctx, net_sec);
ip_int = handle_update_instance(1, ctx, &ip_int_last, update_instance_alias, 3, net_sec, "ip_int_instance", "ip_int_alias");
@ -225,7 +225,9 @@ inline int entry_ipv4_address(struct dmctx *ctx, struct uci_section *net_sec, ch
inline int entry_ip_interface_instance(struct dmctx *ctx, char *int_num)
{
IF_MATCH(ctx, DMROOT"IP.Interface.%s.", int_num) {
DMOBJECT(DMROOT"IP.Interface.%s.", ctx, "0", 1, NULL, NULL, NULL, int_num);
char linker[32];
strcat(linker, section_name(cur_ip_args.ip_sec));
DMOBJECT(DMROOT"IP.Interface.%s.", ctx, "0", 1, NULL, NULL, linker, int_num);
DMPARAM("Alias", ctx, "1", get_ip_int_alias, set_ip_int_alias, NULL, 0, 1, UNDEF, NULL);
DMPARAM("Enable", ctx, "1", get_ip_interface_enable, set_ip_interface_enable, "xsd:boolean", 0, 1, UNDEF, NULL);
DMPARAM("Name", ctx, "0", get_ip_interface_name, NULL, NULL, 0, 1, UNDEF, NULL);