|
|
@@ -2,6 +2,9 @@
|
|
|
#include <sys/stat.h>
|
|
|
#include <sys/statvfs.h>
|
|
|
#include <fcntl.h>
|
|
|
+#include <dirent.h>
|
|
|
+#include <signal.h>
|
|
|
+#include <sys/wait.h>
|
|
|
#include <unistd.h>
|
|
|
#include <string.h>
|
|
|
#include <limits.h>
|
|
|
@@ -42,12 +45,19 @@
|
|
|
#define FILE_NET "/etc/network/interfaces"
|
|
|
#define FILE_DNS "/etc/dnsmasq.conf"
|
|
|
|
|
|
-
|
|
|
+static int net_check(void);
|
|
|
+static int get_pid(char *proc);
|
|
|
+static int get_net(NetworkInfo_t *para, int ipv);
|
|
|
static int set_net(NetworkInfo_t *para, int ipv);
|
|
|
|
|
|
+
|
|
|
static void nic_restart(void)
|
|
|
{
|
|
|
- system("ifdown eth0;ifup eth0");
|
|
|
+ NetworkInfo_t info;
|
|
|
+ char *p=getLocalIpAddress(DFLT_NIC);
|
|
|
+ if(p==NULL) {
|
|
|
+ system("ifdown eth0;ifup eth0;sleep 2");
|
|
|
+ }
|
|
|
}
|
|
|
static void nic_set_mac(void)
|
|
|
{
|
|
|
@@ -229,6 +239,7 @@ static int set_ipaddr(int family, const char* iface, const char* addr, const cha
|
|
|
}
|
|
|
static int get_ipaddr(int family, char *iface, char *addr, char *netmask)
|
|
|
{
|
|
|
+ int r=-1;
|
|
|
struct ifaddrs *ifap, *ifa;
|
|
|
|
|
|
if (getifaddrs(&ifap) == -1) {
|
|
|
@@ -244,14 +255,19 @@ static int get_ipaddr(int family, char *iface, char *addr, char *netmask)
|
|
|
msk = (struct sockaddr_in *) ifa->ifa_netmask;
|
|
|
|
|
|
if(addr) {
|
|
|
- inet_ntop(family, &sa->sin_addr, addr, INET6_ADDRSTRLEN);
|
|
|
- //printf("___addr: %s\n", addr);
|
|
|
+ char *p = (char*)inet_ntop(family, &sa->sin_addr, addr, INET6_ADDRSTRLEN);
|
|
|
+ if(p && strcmp(p, "127.0.0.1") && strcmp(p, "172.17.0.1")) {
|
|
|
+ printf("___addr4: %s\n", addr);
|
|
|
+ r = 0;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if(netmask) {
|
|
|
inet_ntop(family, &msk->sin_addr, netmask, INET6_ADDRSTRLEN);
|
|
|
- //printf("___netmask: %s\n", netmask);
|
|
|
+ //printf("___netmask4: %s\n", netmask);
|
|
|
}
|
|
|
+
|
|
|
+ if(r==0) break;
|
|
|
}
|
|
|
else {
|
|
|
struct sockaddr_in6 *sa,*msk;
|
|
|
@@ -259,20 +275,25 @@ static int get_ipaddr(int family, char *iface, char *addr, char *netmask)
|
|
|
msk = (struct sockaddr_in6 *) ifa->ifa_netmask;
|
|
|
|
|
|
if(addr) {
|
|
|
- inet_ntop(family, &sa->sin6_addr, addr, INET6_ADDRSTRLEN);
|
|
|
- //printf("___addr6: %s\n", addr);
|
|
|
+ char *p = (char*)inet_ntop(family, &sa->sin6_addr, addr, INET6_ADDRSTRLEN);
|
|
|
+ if(p && strcmp(p, "::1")) {
|
|
|
+ printf("___addr6: %s\n", addr);
|
|
|
+ r = 0;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if(netmask) {
|
|
|
inet_ntop(family, &msk->sin6_addr, netmask, INET6_ADDRSTRLEN);
|
|
|
//printf("___netmask6: %s\n", netmask);
|
|
|
}
|
|
|
+
|
|
|
+ if(r==0) break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
freeifaddrs(ifap);
|
|
|
|
|
|
- return 0;
|
|
|
+ return r;
|
|
|
}
|
|
|
|
|
|
static int set_gateway(int family, const char* gateway)
|
|
|
@@ -1374,6 +1395,7 @@ static void* polling_thread(void *arg)
|
|
|
wdog_init();
|
|
|
tmp_create();
|
|
|
while(h->quit==0) {
|
|
|
+ net_check();
|
|
|
wdog_feed();
|
|
|
mem_check();
|
|
|
send_check();
|
|
|
@@ -1518,39 +1540,70 @@ int sys_chmod(void)
|
|
|
}
|
|
|
|
|
|
|
|
|
-static void dhcp_restart(void)
|
|
|
+static int net_check(void)
|
|
|
{
|
|
|
- int r;
|
|
|
+ int r,pid;
|
|
|
+ char tmp[200];
|
|
|
char ipaddr[64],mask[64];
|
|
|
NetworkInfo_t net4,net6;
|
|
|
+ static uint32_t dhcp_cnt=0;
|
|
|
|
|
|
- r = get_net(&net4, IP_V4);
|
|
|
- if(r==0) {
|
|
|
- r = get_ipaddr(AF_INET, DFLT_NIC, ipaddr, mask);
|
|
|
- if(r && net4.mode==IP_DHCP) {
|
|
|
- set_dhcp(1);
|
|
|
+ if(dhcp_cnt%10==0) {
|
|
|
+ printf("__ dhcp check\n");
|
|
|
+ r = get_net(&net4, IP_V4);
|
|
|
+ if(r==0) {
|
|
|
+ r = get_ipaddr(AF_INET, DFLT_NIC, ipaddr, mask);
|
|
|
+ if(r) {
|
|
|
+ if(net4.mode==IP_DHCP) {
|
|
|
+#if 0
|
|
|
+ pid = get_pid("udhcpc");
|
|
|
+ printf("___udhcpc pid: %d\n", pid);
|
|
|
+ if(pid>=0) {
|
|
|
+ kill(pid, SIGUSR2);
|
|
|
+ }
|
|
|
+#else
|
|
|
+ system("killall udhcpc; udhcpc");
|
|
|
+#endif
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ sprintf(tmp, "ifconfig %s %s up", DFLT_NIC, ipaddr);
|
|
|
+ system(tmp);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- r = get_net(&net6, IP_V6);
|
|
|
- if(r==0) {
|
|
|
- r = get_ipaddr(AF_INET6, DFLT_NIC, ipaddr, mask);
|
|
|
- if(r && net6.mode==IP_DHCP) {
|
|
|
-
|
|
|
+ r = get_net(&net6, IP_V6);
|
|
|
+ if(r==0) {
|
|
|
+ r = get_ipaddr(AF_INET6, DFLT_NIC, ipaddr, mask);
|
|
|
+ if(r) {
|
|
|
+ if(net6.mode==IP_DHCP) {
|
|
|
+ pid = get_pid("udhcpc6");
|
|
|
+ printf("___udhcpc6 pid: %d\n", pid);
|
|
|
+ if(pid>=0) {
|
|
|
+ kill(pid, SIGUSR2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ sprintf(tmp, "ip addr add %s/%s dev %s", ipaddr, mask, DFLT_NIC);
|
|
|
+ system(tmp);
|
|
|
+ sprintf(tmp, "ip link set dev %s up", DFLT_NIC);
|
|
|
+ system(tmp);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ dhcp_cnt++;
|
|
|
|
|
|
+ return 0;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
static void net_init(void)
|
|
|
{
|
|
|
- nic_restart();
|
|
|
nic_set_mac();
|
|
|
}
|
|
|
|
|
|
-#include <dirent.h>
|
|
|
-#include <signal.h>
|
|
|
-#include <sys/wait.h>
|
|
|
+
|
|
|
static int get_pid(char *proc)
|
|
|
{
|
|
|
DIR *dir;
|
|
|
@@ -1608,8 +1661,8 @@ int sys_init(void)
|
|
|
sys_chmod();
|
|
|
init_hash_table();
|
|
|
|
|
|
- ui_init();
|
|
|
net_init();
|
|
|
+ ui_init();
|
|
|
thread_start(THREAD_ID_POLLING, polling_thread, NULL);
|
|
|
|
|
|
return 0;
|