mirror of
https://dev.iopsys.eu/bbf/bbfdm.git
synced 2025-12-10 07:44:39 +01:00
Ticket refs #3805: TR-181: Device.DHCPv4.Server.Pool.{i}.Client.{i}.Option.{i}.
- Implement Device.DHCPv4.Server.Pool.{i}.Client.{i}.Option.{i}. object
- Implement Device.DHCPv4.Server.Pool.{i}.Client.{i}.IPv4AddressNumberOfEntries parameter
- Implement Device.DHCPv4.Server.Pool.{i}.Client.{i}.OptionNumberOfEntries parameter
This commit is contained in:
parent
001b7800ee
commit
d1d60dfbe0
3 changed files with 183 additions and 37 deletions
|
|
@ -36,6 +36,11 @@ struct client_args {
|
|||
const struct dhcp_lease *lease;
|
||||
};
|
||||
|
||||
struct client_options_args {
|
||||
char *tag;
|
||||
char *value;
|
||||
};
|
||||
|
||||
struct dhcp_client_args {
|
||||
struct uci_section *dhcp_client_conf;
|
||||
struct uci_section *dhcp_client_dm;
|
||||
|
|
@ -85,6 +90,12 @@ static inline void init_dhcp_client_args(struct client_args *args, const struct
|
|||
args->lease = lease;
|
||||
}
|
||||
|
||||
static inline void init_client_options_args(struct client_options_args *args, char *tag, char *val)
|
||||
{
|
||||
args->tag = tag;
|
||||
args->value = val;
|
||||
}
|
||||
|
||||
/*************************************************************
|
||||
* Other functions
|
||||
**************************************************************/
|
||||
|
|
@ -1411,6 +1422,51 @@ static int get_dhcp_client_active(char *refparam, struct dmctx *ctx, void *data,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int get_DHCPv4ServerPoolClient_IPv4AddressNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
*value = "1";
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int get_DHCPv4ServerPoolClient_OptionNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
FILE *f = fopen(DHCP_CLIENT_OPTIONS_FILE, "r");
|
||||
if (f == NULL) {
|
||||
*value = "0";
|
||||
return 0;
|
||||
}
|
||||
|
||||
const struct client_args *args = (struct client_args *)data;
|
||||
char line[2048], macaddr[24], vcid[128], clid[128], ucid[128];
|
||||
char *inst = NULL, *max_inst = NULL;
|
||||
int nbre_options = 0;
|
||||
|
||||
while (fgets(line, sizeof(line), f) != NULL) {
|
||||
remove_new_line(line);
|
||||
|
||||
sscanf(line, "%24s vcid=%128s clid=%128s ucid=%128s",
|
||||
macaddr, vcid, clid, ucid);
|
||||
|
||||
if (strncmp(macaddr, (char *)args->lease->hwaddr, 24) == 0) {
|
||||
|
||||
if (strcmp(vcid, "-") != 0)
|
||||
nbre_options++;
|
||||
|
||||
if (strcmp(clid, "-") != 0)
|
||||
nbre_options++;
|
||||
|
||||
if (strcmp(ucid, "-") != 0)
|
||||
nbre_options++;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
dmasprintf(value, "%d", nbre_options);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int get_dhcp_client_ipv4address_leasetime(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
const struct client_args *args = data;
|
||||
|
|
@ -1426,6 +1482,24 @@ static int get_dhcp_client_ipv4address_ip_address(char *refparam, struct dmctx *
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int get_DHCPv4ServerPoolClientOption_Tag(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
*value = ((struct client_options_args *)data)->tag;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int get_DHCPv4ServerPoolClientOption_Value(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
const char *tag_value = ((struct client_options_args *)data)->value;
|
||||
char hex[256] = {0};
|
||||
|
||||
if (tag_value && *tag_value)
|
||||
convert_string_to_hex(tag_value, hex);
|
||||
|
||||
*value = dmstrdup(hex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int get_DHCPv4_ClientNumberOfEntries(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
|
||||
{
|
||||
struct uci_section *s, *dmmap_sect;
|
||||
|
|
@ -2609,6 +2683,61 @@ static int browseDhcpClientIPv4Inst(struct dmctx *dmctx, DMNODE *parent_node, vo
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int browseDHCPv4ServerPoolClientOptionInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
|
||||
{
|
||||
FILE *f = fopen(DHCP_CLIENT_OPTIONS_FILE, "r");
|
||||
if (f == NULL)
|
||||
return 0;
|
||||
|
||||
const struct client_args *args = (struct client_args *)prev_data;
|
||||
struct client_options_args curr_client_options_args = {0};
|
||||
char line[2048], macaddr[24], vcid[128], clid[128], ucid[128];
|
||||
char *inst = NULL, *max_inst = NULL;
|
||||
int id = 0;
|
||||
|
||||
while (fgets(line, sizeof(line), f) != NULL) {
|
||||
remove_new_line(line);
|
||||
|
||||
sscanf(line, "%24s vcid=%128s clid=%128s ucid=%128s",
|
||||
macaddr, vcid, clid, ucid);
|
||||
|
||||
if (strncmp(macaddr, (char *)args->lease->hwaddr, 24) == 0) {
|
||||
|
||||
if (strcmp(vcid, "-") != 0) {
|
||||
init_client_options_args(&curr_client_options_args, "60", dmstrdup(vcid));
|
||||
|
||||
inst = handle_update_instance(3, dmctx, &max_inst, update_instance_without_section, 1, ++id);
|
||||
|
||||
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_client_options_args, inst) == DM_STOP)
|
||||
break;
|
||||
}
|
||||
|
||||
if (strcmp(clid, "-") != 0) {
|
||||
init_client_options_args(&curr_client_options_args, "61", dmstrdup(clid));
|
||||
|
||||
inst = handle_update_instance(3, dmctx, &max_inst, update_instance_without_section, 1, ++id);
|
||||
|
||||
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_client_options_args, inst) == DM_STOP)
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (strcmp(ucid, "-") != 0) {
|
||||
init_client_options_args(&curr_client_options_args, "77", dmstrdup(ucid));
|
||||
|
||||
inst = handle_update_instance(3, dmctx, &max_inst, update_instance_without_section, 1, ++id);
|
||||
|
||||
if (DM_LINK_INST_OBJ(dmctx, parent_node, (void *)&curr_client_options_args, inst) == DM_STOP)
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*#Device.DHCPv4.Client.{i}.!UCI:network/interface/dmmap_dhcp_client*/
|
||||
static int browseDHCPv4ClientInst(struct dmctx *dmctx, DMNODE *parent_node, void *prev_data, char *prev_instance)
|
||||
{
|
||||
|
|
@ -2947,7 +3076,10 @@ static int browseDHCPv4RelayForwardingInst(struct dmctx *dmctx, DMNODE *parent_n
|
|||
return 0;
|
||||
}
|
||||
|
||||
/*** DHCPv4. ***/
|
||||
/**********************************************************************************************************************************
|
||||
* OBJ & PARAM DEFINITION
|
||||
***********************************************************************************************************************************/
|
||||
/* *** Device.DHCPv4. *** */
|
||||
DMOBJ tDHCPv4Obj[] = {
|
||||
/* OBJ, permission, addobj, delobj, checkdep, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type, uniqueKeys*/
|
||||
{"Client", &DMWRITE, addObjDHCPv4Client, delObjDHCPv4Client, NULL, browseDHCPv4ClientInst, NULL, NULL, NULL, tDHCPv4ClientObj, tDHCPv4ClientParams, NULL, BBFDM_BOTH, LIST_KEY{"Interface", "Alias", NULL}},
|
||||
|
|
@ -3012,6 +3144,13 @@ DMLEAF tDHCPv4ClientReqOptionParams[] = {
|
|||
{0}
|
||||
};
|
||||
|
||||
/* *** Device.DHCPv4.Server. *** */
|
||||
DMOBJ tDHCPv4ServerObj[] = {
|
||||
/* OBJ, permission, addobj, delobj, checkdep, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type, uniqueKeys*/
|
||||
{"Pool", &DMWRITE, add_dhcp_server, delete_dhcp_server, NULL, browseDhcpInst, NULL, NULL, NULL, tDHCPv4ServerPoolObj, tDHCPv4ServerPoolParams, NULL, BBFDM_BOTH, LIST_KEY{"Alias", NULL}},
|
||||
{0}
|
||||
};
|
||||
|
||||
DMLEAF tDHCPv4ServerParams[] = {
|
||||
/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/
|
||||
//{"Enable", &DMWRITE, DMT_BOOL, get_DHCPv4Server_Enable, set_DHCPv4Server_Enable, NULL, NULL, BBFDM_BOTH},
|
||||
|
|
@ -3019,14 +3158,7 @@ DMLEAF tDHCPv4ServerParams[] = {
|
|||
{0}
|
||||
};
|
||||
|
||||
/*** DHCPv4.Server. ***/
|
||||
DMOBJ tDHCPv4ServerObj[] = {
|
||||
/* OBJ, permission, addobj, delobj, checkdep, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type, uniqueKeys*/
|
||||
{"Pool", &DMWRITE, add_dhcp_server, delete_dhcp_server, NULL, browseDhcpInst, NULL, NULL, NULL, tDHCPv4ServerPoolObj, tDHCPv4ServerPoolParams, NULL, BBFDM_BOTH, LIST_KEY{"Alias", NULL}},
|
||||
{0}
|
||||
};
|
||||
|
||||
/*** DHCPv4.Server.Pool.{i}. ***/
|
||||
/* *** Device.DHCPv4.Server.Pool.{i}. *** */
|
||||
DMOBJ tDHCPv4ServerPoolObj[] = {
|
||||
/* OBJ, permission, addobj, delobj, checkdep, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type, uniqueKeys*/
|
||||
{"StaticAddress", &DMWRITE, add_dhcp_staticaddress, delete_dhcp_staticaddress, NULL, browseDhcpStaticInst, NULL, NULL, NULL, NULL, tDHCPv4ServerPoolStaticAddressParams, NULL, BBFDM_BOTH, LIST_KEY{"Chaddr", "Alias", NULL}},
|
||||
|
|
@ -3035,14 +3167,6 @@ DMOBJ tDHCPv4ServerPoolObj[] = {
|
|||
{0}
|
||||
};
|
||||
|
||||
/*** DHCPv4.Server.Pool.{i}.Client.{i}. ***/
|
||||
DMOBJ tDHCPv4ServerPoolClientObj[] = {
|
||||
/* OBJ, permission, addobj, delobj, checkdep, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type, uniqueKeys*/
|
||||
{"IPv4Address", &DMREAD, NULL, NULL, NULL, browseDhcpClientIPv4Inst, NULL, NULL, NULL, NULL, tDHCPv4ServerPoolClientIPv4AddressParams, NULL, BBFDM_BOTH, LIST_KEY{"IPAddress", NULL}},
|
||||
//{"Option", &DMREAD, NULL, NULL, NULL, browseDHCPv4ServerPoolClientOptionInst, NULL, NULL, NULL, NULL, tDHCPv4ServerPoolClientOptionParams, NULL, BBFDM_BOTH, LIST_KEY{"Tag", NULL}},
|
||||
{0}
|
||||
};
|
||||
|
||||
DMLEAF tDHCPv4ServerPoolParams[] = {
|
||||
/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/
|
||||
{"Alias", &DMWRITE, DMT_STRING, get_server_pool_alias, set_server_pool_alias, NULL, NULL, BBFDM_BOTH},
|
||||
|
|
@ -3064,7 +3188,7 @@ DMLEAF tDHCPv4ServerPoolParams[] = {
|
|||
{0}
|
||||
};
|
||||
|
||||
/*** DHCPv4.Server.Pool.{i}.StaticAddress.{i}. ***/
|
||||
/* *** Device.DHCPv4.Server.Pool.{i}.StaticAddress.{i}. *** */
|
||||
DMLEAF tDHCPv4ServerPoolStaticAddressParams[] = {
|
||||
/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/
|
||||
{"Enable", &DMWRITE, DMT_BOOL, get_dhcp_static_enable, set_dhcp_static_enable, NULL, NULL, BBFDM_BOTH},
|
||||
|
|
@ -3074,23 +3198,6 @@ DMLEAF tDHCPv4ServerPoolStaticAddressParams[] = {
|
|||
{0}
|
||||
};
|
||||
|
||||
/*** 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}
|
||||
};
|
||||
|
||||
/*** DHCPv4.Server.Pool.{i}.Client.{i}.IPv4Address.{i}. ***/
|
||||
DMLEAF tDHCPv4ServerPoolClientIPv4AddressParams[] = {
|
||||
/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/
|
||||
{"LeaseTimeRemaining", &DMREAD, DMT_TIME, get_dhcp_client_ipv4address_leasetime, NULL, NULL, NULL, BBFDM_BOTH},
|
||||
{"IPAddress", &DMREAD, DMT_STRING, get_dhcp_client_ipv4address_ip_address, NULL, NULL, NULL, BBFDM_BOTH},
|
||||
{0}
|
||||
};
|
||||
|
||||
/* *** Device.DHCPv4.Server.Pool.{i}.Option.{i}. *** */
|
||||
DMLEAF tDHCPv4ServerPoolOptionParams[] = {
|
||||
/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/
|
||||
|
|
@ -3101,11 +3208,37 @@ DMLEAF tDHCPv4ServerPoolOptionParams[] = {
|
|||
{0}
|
||||
};
|
||||
|
||||
/* *** Device.DHCPv4.Server.Pool.{i}.Client.{i}. *** */
|
||||
DMOBJ tDHCPv4ServerPoolClientObj[] = {
|
||||
/* OBJ, permission, addobj, delobj, checkdep, browseinstobj, forced_inform, notification, nextdynamicobj, nextobj, leaf, linker, bbfdm_type, uniqueKeys*/
|
||||
{"IPv4Address", &DMREAD, NULL, NULL, NULL, browseDhcpClientIPv4Inst, NULL, NULL, NULL, NULL, tDHCPv4ServerPoolClientIPv4AddressParams, NULL, BBFDM_BOTH, LIST_KEY{"IPAddress", NULL}},
|
||||
{"Option", &DMREAD, NULL, NULL, NULL, browseDHCPv4ServerPoolClientOptionInst, NULL, NULL, NULL, NULL, tDHCPv4ServerPoolClientOptionParams, NULL, BBFDM_BOTH, LIST_KEY{"Tag", NULL}},
|
||||
{0}
|
||||
};
|
||||
|
||||
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},
|
||||
{"IPv4AddressNumberOfEntries", &DMREAD, DMT_UNINT, get_DHCPv4ServerPoolClient_IPv4AddressNumberOfEntries, NULL, NULL, NULL, BBFDM_BOTH},
|
||||
{"OptionNumberOfEntries", &DMREAD, DMT_UNINT, get_DHCPv4ServerPoolClient_OptionNumberOfEntries, NULL, NULL, NULL, BBFDM_BOTH},
|
||||
{0}
|
||||
};
|
||||
|
||||
/* *** Device.DHCPv4.Server.Pool.{i}.Client.{i}.IPv4Address.{i}. *** */
|
||||
DMLEAF tDHCPv4ServerPoolClientIPv4AddressParams[] = {
|
||||
/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/
|
||||
{"LeaseTimeRemaining", &DMREAD, DMT_TIME, get_dhcp_client_ipv4address_leasetime, NULL, NULL, NULL, BBFDM_BOTH},
|
||||
{"IPAddress", &DMREAD, DMT_STRING, get_dhcp_client_ipv4address_ip_address, NULL, NULL, NULL, BBFDM_BOTH},
|
||||
{0}
|
||||
};
|
||||
|
||||
/* *** Device.DHCPv4.Server.Pool.{i}.Client.{i}.Option.{i}. *** */
|
||||
DMLEAF tDHCPv4ServerPoolClientOptionParams[] = {
|
||||
/* PARAM, permission, type, getvalue, setvalue, forced_inform, notification, bbfdm_type*/
|
||||
//{"Tag", &DMREAD, DMT_UNINT, get_DHCPv4ServerPoolClientOption_Tag, NULL, NULL, NULL, BBFDM_BOTH},
|
||||
//{"Value", &DMREAD, DMT_HEXBIN, get_DHCPv4ServerPoolClientOption_Value, NULL, NULL, NULL, BBFDM_BOTH},
|
||||
{"Tag", &DMREAD, DMT_UNINT, get_DHCPv4ServerPoolClientOption_Tag, NULL, NULL, NULL, BBFDM_BOTH},
|
||||
{"Value", &DMREAD, DMT_HEXBIN, get_DHCPv4ServerPoolClientOption_Value, NULL, NULL, NULL, BBFDM_BOTH},
|
||||
{0}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1364,6 +1364,16 @@ int dm_time_format(time_t ts, char **dst)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void convert_string_to_hex(const char *str, char *hex)
|
||||
{
|
||||
int i, j, len = strlen(str);
|
||||
|
||||
for (i = 0, j = 0; i < len; i++, j += 2) {
|
||||
sprintf((char *)hex+j, "%02X", str[i]);
|
||||
}
|
||||
hex[j] = '\0';
|
||||
}
|
||||
|
||||
bool match(const char *string, const char *pattern)
|
||||
{
|
||||
regex_t re;
|
||||
|
|
|
|||
|
|
@ -115,6 +115,7 @@ extern char *SupportedFrequencyBands[];
|
|||
#define MAX_PROC_ROUTING 256
|
||||
#define ROUTING_FILE "/proc/net/route"
|
||||
#define DHCP_LEASES_FILE "/tmp/dhcp.leases"
|
||||
#define DHCP_CLIENT_OPTIONS_FILE "/var/dhcp.client.options"
|
||||
#define DMMAP "dmmap"
|
||||
#define DHCPSTATICADDRESS_DISABLED_CHADDR "00:00:00:00:00:01"
|
||||
#define RANGE_ARGS (struct range_args[])
|
||||
|
|
@ -251,6 +252,7 @@ pid_t get_pid(char *pname);
|
|||
int check_file(char *path);
|
||||
char *cidr2netmask(int bits);
|
||||
bool is_strword_in_optionvalue(char *optionvalue, char *str);
|
||||
void remove_new_line(char *buf);
|
||||
int dmcmd(char *cmd, int n, ...);
|
||||
int dmcmd_read(int pipe, char *buffer, int size);
|
||||
void dmcmd_read_alloc(int pipe, char **value);
|
||||
|
|
@ -309,6 +311,7 @@ int get_net_iface_sysfs(const char *uci_iface, const char *name, char **value);
|
|||
int get_net_device_sysfs(const char *uci_iface, const char *name, char **value);
|
||||
char *get_device_from_wifi_iface(const char *wifi_iface, const char *wifi_section);
|
||||
int dm_time_format(time_t ts, char **dst);
|
||||
void convert_string_to_hex(const char *str, char *hex);
|
||||
bool match(const char *string, const char *pattern);
|
||||
int dm_validate_string(char *value, int min_length, int max_length, char *enumeration[], int enumeration_size, char *pattern[], int pattern_size);
|
||||
int dm_validate_boolean(char *value);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue