mirror of
https://dev.iopsys.eu/bbf/bbfdm.git
synced 2025-12-10 07:44:39 +01:00
Ticker refs #2909: TR-181: some DHCP and Firewall objects are missing Alias parameter
This commit is contained in:
parent
9f48e11e9b
commit
712071eaaf
4 changed files with 178 additions and 1 deletions
|
|
@ -1310,6 +1310,50 @@ static int set_dhcp_staticaddress_yiaddr(char *refparam, struct dmctx *ctx, void
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int get_dhcp_client_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
const struct client_args *args = data;
|
||||
struct uci_section *s = NULL;
|
||||
|
||||
char *hwaddr = (char *)args->lease->hwaddr;
|
||||
uci_path_foreach_sections(bbfdm, "dmmap", "dhcpv4clients", s) {
|
||||
char *macaddr;
|
||||
dmuci_get_value_by_section_string(s, "macaddr", &macaddr);
|
||||
if (strcmp(hwaddr, macaddr) == 0) {
|
||||
dmuci_get_value_by_section_string(s, "alias", value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ((*value)[0] == '\0')
|
||||
dmasprintf(value, "cpe-%s", instance);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int set_dhcp_client_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
|
||||
{
|
||||
const struct client_args *args = data;
|
||||
struct uci_section *s = NULL, *dmmap = NULL;
|
||||
char *macaddr, *v;
|
||||
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
if (dm_validate_string(value, -1, 64, NULL, 0, NULL, 0))
|
||||
return FAULT_9007;
|
||||
break;
|
||||
case VALUESET:
|
||||
macaddr = (char *)args->lease->hwaddr;
|
||||
uci_path_foreach_option_eq(bbfdm, "dmmap", "dhcpv4clients", "macaddr", macaddr, s) {
|
||||
dmuci_set_value_by_section_bbfdm(s, "alias", value);
|
||||
return 0;
|
||||
}
|
||||
dmuci_add_section_bbfdm("dmmap", "dhcpv4clients", &dmmap, &v);
|
||||
dmuci_set_value_by_section(dmmap, "macaddr", macaddr);
|
||||
dmuci_set_value_by_section(dmmap, "alias", value);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int get_dhcp_client_chaddr(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
const struct client_args *args = data;
|
||||
|
|
@ -3009,6 +3053,7 @@ DMLEAF tDHCPv4ServerPoolStaticAddressParams[] = {
|
|||
/*** DHCPv4.Server.Pool.{i}.Client.{i}. ***/
|
||||
DMLEAF tDHCPv4ServerPoolClientParams[] = {
|
||||
/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/
|
||||
{"Alias", &DMWRITE, DMT_STRING, get_dhcp_client_alias, set_dhcp_client_alias, NULL, NULL, BBFDM_BOTH},
|
||||
{"Chaddr", &DMREAD, DMT_STRING, get_dhcp_client_chaddr, NULL, NULL, NULL, BBFDM_BOTH},
|
||||
{"Active", &DMREAD, DMT_BOOL, get_dhcp_client_active, NULL, NULL, NULL, BBFDM_BOTH},
|
||||
{0}
|
||||
|
|
|
|||
|
|
@ -1104,6 +1104,47 @@ static int get_DHCPv6ServerPool_OptionNumberOfEntries(char *refparam, struct dmc
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int get_DHCPv6ServerPoolClient_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
struct uci_section *s = NULL;
|
||||
char *src_addr = ""; //should be updated when SourceAddress parameter is implemented
|
||||
|
||||
uci_path_foreach_sections(bbfdm, "dmmap", "dhcpv6clients", s) {
|
||||
char *srcaddr;
|
||||
dmuci_get_value_by_section_string(s, "srcaddr", &srcaddr);
|
||||
if (strcmp(src_addr, srcaddr) == 0) {
|
||||
dmuci_get_value_by_section_string(s, "alias", value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ((*value)[0] == '\0')
|
||||
dmasprintf(value, "cpe-%s", instance);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int set_DHCPv6ServerPoolClient_Alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
|
||||
{
|
||||
struct uci_section *s = NULL, *dmmap = NULL;
|
||||
char *src_addr = "", *v;
|
||||
|
||||
switch (action) {
|
||||
case VALUECHECK:
|
||||
if (dm_validate_string(value, -1, 64, NULL, 0, NULL, 0))
|
||||
return FAULT_9007;
|
||||
break;
|
||||
case VALUESET:
|
||||
uci_path_foreach_option_eq(bbfdm, "dmmap", "dhcpv6clients", "srcaddr", src_addr, s) {
|
||||
dmuci_set_value_by_section_bbfdm(s, "alias", value);
|
||||
return 0;
|
||||
}
|
||||
dmuci_add_section_bbfdm("dmmap", "dhcpv6clients", &dmmap, &v);
|
||||
dmuci_set_value_by_section(dmmap, "srcaddr", src_addr);
|
||||
dmuci_set_value_by_section(dmmap, "alias", value);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int get_DHCPv6ServerPoolClient_IPv6AddressNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
json_object *address_obj = NULL;
|
||||
|
|
@ -1473,7 +1514,7 @@ DMOBJ tDHCPv6ServerPoolClientObj[] = {
|
|||
|
||||
DMLEAF tDHCPv6ServerPoolClientParams[] = {
|
||||
/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/
|
||||
//{"Alias", &DMWRITE, DMT_STRING, get_DHCPv6ServerPoolClient_Alias, set_DHCPv6ServerPoolClient_Alias, NULL, NULL, BBFDM_BOTH},
|
||||
{"Alias", &DMWRITE, DMT_STRING, get_DHCPv6ServerPoolClient_Alias, set_DHCPv6ServerPoolClient_Alias, NULL, NULL, BBFDM_BOTH},
|
||||
//{"SourceAddress", &DMREAD, DMT_STRING, get_DHCPv6ServerPoolClient_SourceAddress, NULL, NULL, NULL, BBFDM_BOTH},
|
||||
//{"Active", &DMREAD, DMT_BOOL, get_DHCPv6ServerPoolClient_Active, NULL, NULL, NULL, BBFDM_BOTH},
|
||||
{"IPv6AddressNumberOfEntries", &DMREAD, DMT_UNINT, get_DHCPv6ServerPoolClient_IPv6AddressNumberOfEntries, NULL, NULL, NULL, BBFDM_BOTH},
|
||||
|
|
|
|||
|
|
@ -151,6 +151,14 @@ static int get_firewall_chain_number_of_entries(char *refparam, struct dmctx *ct
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int get_level_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
dmuci_get_value_by_section_string((struct uci_section *)data, "firewall_level_alias", value);
|
||||
if ((*value)[0] == '\0')
|
||||
dmasprintf(value, "cpe-%s", instance);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int get_level_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
dmuci_get_value_by_section_string((struct uci_section *)data, "name", value);
|
||||
|
|
@ -207,6 +215,14 @@ static int get_chain_enable(char *refparam, struct dmctx *ctx, void *data, char
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int get_chain_alias(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
dmuci_get_value_by_section_string((struct uci_section *)data, "firewall_chain_alias", value);
|
||||
if ((*value)[0] == '\0')
|
||||
dmasprintf(value, "cpe-%s", instance);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int get_chain_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
dmuci_get_value_by_section_string((struct uci_section *)data, "name", value);
|
||||
|
|
@ -259,6 +275,18 @@ static int get_rule_order(char *refparam, struct dmctx *ctx, void *data, char *i
|
|||
return 0;
|
||||
}
|
||||
|
||||
/*#Device.Firewall.Chain.{i}.Rule.{i}.Alias!UCI:dmmap_firewall/rule,@i-1/user_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);
|
||||
if ((*value)[0] == '\0')
|
||||
dmasprintf(value, "cpe-%s", instance);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*#Device.Firewall.Chain.{i}.Rule.{i}.Target!UCI:firewall/rule,@i-1/name*/
|
||||
static int get_rule_description(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
|
|
@ -646,6 +674,20 @@ static int set_firewall_advanced_level(char *refparam, struct dmctx *ctx, void *
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int set_level_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, 0, NULL, 0))
|
||||
return FAULT_9007;
|
||||
break;
|
||||
case VALUESET:
|
||||
dmuci_set_value_by_section_bbfdm((struct uci_section *)data, "firewall_level_alias", value);
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int set_level_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
|
||||
{
|
||||
switch (action) {
|
||||
|
|
@ -745,6 +787,20 @@ static int set_chain_enable(char *refparam, struct dmctx *ctx, void *data, char
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int set_chain_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, 0, NULL, 0))
|
||||
return FAULT_9007;
|
||||
break;
|
||||
case VALUESET:
|
||||
dmuci_set_value_by_section_bbfdm((struct uci_section *)data, "firewall_chain_alias", value);
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int set_chain_name(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
|
||||
{
|
||||
switch (action) {
|
||||
|
|
@ -789,6 +845,23 @@ static int set_rule_order(char *refparam, struct dmctx *ctx, void *data, char *i
|
|||
return 0;
|
||||
}
|
||||
|
||||
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, 0, NULL, 0))
|
||||
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);
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int set_rule_description(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
|
||||
{
|
||||
switch (action) {
|
||||
|
|
@ -1224,6 +1297,7 @@ DMLEAF tFirewallParams[] = {
|
|||
/* *** Device.Firewall.Level.{i}. *** */
|
||||
DMLEAF tFirewallLevelParams[] = {
|
||||
/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/
|
||||
{"Alias", &DMWRITE, DMT_STRING, get_level_alias, set_level_alias, NULL, NULL, BBFDM_BOTH},
|
||||
{"Name", &DMWRITE, DMT_STRING, get_level_name, set_level_name, NULL, NULL, BBFDM_BOTH},
|
||||
{"Description", &DMWRITE, DMT_STRING, get_level_description, set_level_description, NULL, NULL, BBFDM_BOTH},
|
||||
{"Chain", &DMREAD, DMT_STRING, get_level_chain, NULL, NULL, NULL, BBFDM_BOTH},
|
||||
|
|
@ -1242,6 +1316,7 @@ DMOBJ tFirewallChainObj[] = {
|
|||
DMLEAF tFirewallChainParams[] = {
|
||||
/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/
|
||||
{"Enable", &DMWRITE, DMT_BOOL, get_chain_enable, set_chain_enable, NULL, NULL, BBFDM_BOTH},
|
||||
{"Alias", &DMWRITE, DMT_STRING, get_chain_alias, set_chain_alias, NULL, NULL, BBFDM_BOTH},
|
||||
{"Name", &DMWRITE, DMT_STRING, get_chain_name, set_chain_name, NULL, NULL, BBFDM_BOTH},
|
||||
{"Creator", &DMREAD, DMT_STRING, get_chain_creator, NULL, NULL, NULL, BBFDM_BOTH},
|
||||
{"RuleNumberOfEntries", &DMREAD, DMT_UNINT, get_chain_rule_number_of_entries, NULL, NULL, NULL, BBFDM_BOTH},
|
||||
|
|
@ -1260,6 +1335,7 @@ DMLEAF tFirewallChainRuleParams[] = {
|
|||
{"Enable", &DMWRITE, DMT_BOOL, get_rule_enable, set_rule_enable, NULL, NULL, BBFDM_BOTH},
|
||||
{"Status", &DMREAD, DMT_STRING, get_rule_status, NULL, NULL, NULL, BBFDM_BOTH},
|
||||
{"Order", &DMWRITE, DMT_UNINT, get_rule_order, set_rule_order, NULL, NULL, BBFDM_BOTH},
|
||||
{"Alias", &DMWRITE, DMT_STRING, get_rule_alias, set_rule_alias, NULL, NULL, BBFDM_BOTH},
|
||||
{"Description", &DMWRITE, DMT_STRING, get_rule_description, set_rule_description, NULL, NULL, BBFDM_BOTH},
|
||||
{"Target", &DMWRITE, DMT_STRING, get_rule_target, set_rule_target, NULL, NULL, BBFDM_BOTH},
|
||||
//{"TargetChain", &DMWRITE, DMT_STRING, get_rule_target_chain, set_rule_target_chain, NULL, NULL, BBFDM_BOTH},
|
||||
|
|
|
|||
|
|
@ -61618,6 +61618,21 @@
|
|||
{
|
||||
"max": 64
|
||||
}
|
||||
],
|
||||
"mapping": [
|
||||
{
|
||||
"type": "uci",
|
||||
"uci": {
|
||||
"file": "dmmap_firewall",
|
||||
"section": {
|
||||
"type": "rule",
|
||||
"index": "@i-1"
|
||||
},
|
||||
"option": {
|
||||
"name": "firewall_chain_rule_alias"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"Description": {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue