From e05fbfc2964e62b55750017f5350a352fb8edfe1 Mon Sep 17 00:00:00 2001 From: M_ars Date: Thu, 21 Jul 2022 12:52:33 +0200 Subject: [PATCH] IPv6: extend GUI status page (status-overview.asp) - show DUID --- .../src-rt-6.x.4708/router/dhcpv6/common.c | 20 +++++++++++++++++++ release/src-rt-6.x.4708/router/httpd/misc.c | 18 +++++++++++++++-- .../router/shared/ipv6_shared.h | 3 +++ .../router/www/status-data.jsx | 1 + .../router/www/status-overview.asp | 3 +++ 5 files changed, 43 insertions(+), 2 deletions(-) diff --git a/release/src-rt-6.x.4708/router/dhcpv6/common.c b/release/src-rt-6.x.4708/router/dhcpv6/common.c index 1371ceeac4..eed7335d47 100644 --- a/release/src-rt-6.x.4708/router/dhcpv6/common.c +++ b/release/src-rt-6.x.4708/router/dhcpv6/common.c @@ -86,6 +86,10 @@ #include #include +#ifdef TOMATO +#include +#endif + #ifdef __linux__ /* from /usr/include/linux/ipv6.h */ @@ -995,6 +999,10 @@ get_duid(idfile, duid) struct duid *duid; { FILE *fp = NULL; +#ifdef TOMATO + FILE *fp2 = NULL; + char duid_buf[TOMATO_DUID_MAX_LEN] = { 0 }; +#endif u_int16_t len = 0, hwtype; int hwlen = 0; char tmpbuf[256]; /* HWID should be no more than 256 bytes */ @@ -1068,6 +1076,18 @@ get_duid(idfile, duid) duidstr(duid)); } +#ifdef TOMATO + if ((fp2 = fopen(TOMATO_DUID_GUI, "w+")) == NULL) { /* if file already exists override it (empty it) */ + dprintf(LOG_ERR, FNAME, "failed to open TOMATO_DUID_GUI file for save"); + } + else { + snprintf(duid_buf, TOMATO_DUID_MAX_LEN-1, "%s", duidstr(duid)); + duid_buf[TOMATO_DUID_MAX_LEN-1] = '\0'; + fputs(duid_buf, fp2); + fclose(fp2); + } +#endif + /* save the (new) ID to the file for next time */ if (!fp) { if ((fp = fopen(idfile, "w+")) == NULL) { diff --git a/release/src-rt-6.x.4708/router/httpd/misc.c b/release/src-rt-6.x.4708/router/httpd/misc.c index 710a2282c1..c32efc80d3 100644 --- a/release/src-rt-6.x.4708/router/httpd/misc.c +++ b/release/src-rt-6.x.4708/router/httpd/misc.c @@ -303,7 +303,9 @@ static char* get_cfeversion(char *buf) } #ifdef TCONFIG_IPV6 -static void print_ipv6_addrs(void) /* show IPv6 addresses: wan, dns, lan, lan-ll, lan1, lan1-ll, lan2, lan2-ll, lan3, lan3-ll */ +#define NOT_AVAIL "--" + +static void print_ipv6_infos(void) /* show IPv6 DUID and addresses: wan, dns, lan, lan-ll, lan1, lan1-ll, lan2, lan2-ll, lan3, lan3-ll */ { char buffer[INET6_ADDRSTRLEN]; char buffer2[16]; @@ -313,10 +315,22 @@ static void print_ipv6_addrs(void) /* show IPv6 addresses: wan, dns, lan, lan-ll struct in6_addr addr; int cnt = 0; char br; + FILE *fp = NULL; + char line[TOMATO_DUID_MAX_LEN]; if (!ipv6_enabled()) return; + /* DUID */ + if ((fp = fopen(TOMATO_DUID_GUI, "r")) != NULL) { + fgets(line, sizeof(line), fp); + web_printf("\tip6_duid: '%s',\n", line); + fclose(fp); + } + else { + web_printf("\tip6_duid: '%s',\n", NOT_AVAIL); + } + /* check LAN */ for (br = 0; br < BRIDGE_COUNT; br++) { char bridge[2] = "0"; @@ -603,7 +617,7 @@ void asp_sysinfo(int argc, char **argv) web_puts("\nsysinfo = {\n"); #ifdef TCONFIG_IPV6 - print_ipv6_addrs(); + print_ipv6_infos(); #endif sysinfo(&si); get_memory(&mem); diff --git a/release/src-rt-6.x.4708/router/shared/ipv6_shared.h b/release/src-rt-6.x.4708/router/shared/ipv6_shared.h index 9e86d19701..cb930394b7 100644 --- a/release/src-rt-6.x.4708/router/shared/ipv6_shared.h +++ b/release/src-rt-6.x.4708/router/shared/ipv6_shared.h @@ -7,6 +7,9 @@ #ifndef _ipv6_shared_h_ #define _ipv6_shared_h_ +#define TOMATO_DUID_MAX_LEN 64 +#define TOMATO_DUID_GUI "/var/dhcp6c_duid_gui" + #define IPV6_MIN_LIFETIME 120 #define ONEMONTH_LIFETIME (30 * 24 * 60 * 60) #define INFINITE_LIFETIME 0xffffffff diff --git a/release/src-rt-6.x.4708/router/www/status-data.jsx b/release/src-rt-6.x.4708/router/www/status-data.jsx index 4f8260d993..504a554923 100644 --- a/release/src-rt-6.x.4708/router/www/status-data.jsx +++ b/release/src-rt-6.x.4708/router/www/status-data.jsx @@ -141,6 +141,7 @@ for (var uidx = 1; uidx <= nvram.mwan_num; ++uidx) { } /* IPV6-BEGIN */ +stats.ip6_duid = ((typeof(sysinfo.ip6_duid) != 'undefined') ? sysinfo.ip6_duid : '')+''; stats.ip6_wan = ((typeof(sysinfo.ip6_wan) != 'undefined') ? sysinfo.ip6_wan : '')+''; stats.ip6_wan_dns1 = ((typeof(sysinfo.ip6_wan_dns1) != 'undefined') ? sysinfo.ip6_wan_dns1 : '')+''; stats.ip6_wan_dns2 = ((typeof(sysinfo.ip6_wan_dns2) != 'undefined') ? sysinfo.ip6_wan_dns2 : '')+''; diff --git a/release/src-rt-6.x.4708/router/www/status-overview.asp b/release/src-rt-6.x.4708/router/www/status-overview.asp index 67be6d0f34..6af242bef3 100644 --- a/release/src-rt-6.x.4708/router/www/status-overview.asp +++ b/release/src-rt-6.x.4708/router/www/status-overview.asp @@ -295,6 +295,8 @@ function show() { elem.display('swap', stats.swap != ''); c('nvram_stat', scaleSize(nvstat.size - nvstat.free)+' / '+scaleSize(nvstat.size)+' ('+((nvstat.size - nvstat.free) / nvstat.size * 100.0).toFixed(2)+'%)<\/small>
<\/div><\/div><\/div>'); /* IPV6-BEGIN */ + c('ip6_duid', stats.ip6_duid); + elem.display('ip6_duid', stats.ip6_duid != ''); c('ip6_wan', stats.ip6_wan); elem.display('ip6_wan', stats.ip6_wan != ''); c('ip6_wan_dns1', stats.ip6_wan_dns1); @@ -532,6 +534,7 @@ function init() { { title: 'Subnet Mask', rid: 'wan'+u+'netmask', text: stats.wannetmask[uidx - 1] }, { title: 'Gateway', rid: 'wan'+u+'gateway', text: stats.wangateway[uidx - 1] }, /* IPV6-BEGIN */ + { title: 'IPv6 DUID', rid: 'ip6_duid', text: stats.ip6_duid, hidden: (stats.ip6_duid == '') }, { title: 'IPv6 Address', rid: 'ip6_wan', text: stats.ip6_wan, hidden: (stats.ip6_wan == '') }, { title: 'IPv6 DNS1', rid: 'ip6_wan_dns1', text: stats.ip6_wan_dns1, hidden: (stats.ip6_wan_dns1 == '') }, { title: 'IPv6 DNS2', rid: 'ip6_wan_dns2', text: stats.ip6_wan_dns2, hidden: (stats.ip6_wan_dns2 == '') },