Device.IP. object: fix the get/set of IPv6Enable and IPv6Status parameters

This commit is contained in:
Amin Ben Ramdhane 2020-05-29 16:42:29 +01:00
parent c7a4c3eb7c
commit 842d091a9e
2 changed files with 30 additions and 2 deletions

View file

@ -186,18 +186,34 @@ static int get_IP_IPv6Capable(char *refparam, struct dmctx *ctx, void *data, cha
static int get_IP_IPv6Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = "1";
char buf[64] = {0};
*value = "0";
int pp = dmcmd("sysctl", 1, "net.ipv6.conf.all.disable_ipv6");
if (pp) {
int r = dmcmd_read(pp, buf, sizeof(buf));
close(pp);
char *val = NULL;
if (r > 0 && (val = strchr(buf, '=')))
*value = (strcmp(val+2, "1") == 0) ? "0" : "1";
}
return 0;
}
static int set_IP_IPv6Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action)
{
char buf[64] = {0};
bool b;
switch (action) {
case VALUECHECK:
if (dm_validate_boolean(value))
return FAULT_9007;
break;
case VALUESET:
string_to_bool(value, &b);
snprintf(buf, sizeof(buf), "net.ipv6.conf.all.disable_ipv6=%d", b ? 0 : 1);
DMCMD("sysctl", 2, "-w", buf);
break;
}
return 0;
@ -205,7 +221,10 @@ static int set_IP_IPv6Enable(char *refparam, struct dmctx *ctx, void *data, char
static int get_IP_IPv6Status(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value)
{
*value = "Enabled";
char buf[16];
dm_read_sysfs_file("/proc/sys/net/ipv6/conf/all/disable_ipv6", buf, sizeof(buf));
*value = (strcmp(buf, "1") == 0) ? "Disabled" : "Enabled";
return 0;
}

View file

@ -201,6 +201,14 @@ bool is_strword_in_optionvalue(char *optionvalue, char *str)
return false;
}
void remove_new_line(char *buf)
{
int len;
len = strlen(buf) - 1;
if (buf[len] == '\n')
buf[len] = 0;
}
int dmcmd(char *cmd, int n, ...)
{
va_list arg;
@ -303,6 +311,7 @@ int dmcmd_read(int pipe, char *buffer, int size)
int rd;
if (size < 2) return -1;
if ((rd = read(pipe, buffer, (size-1))) > 0) {
remove_new_line(buffer);
buffer[rd] = '\0';
return (rd + 1);
} else {