yuezonghe | 824eb0c | 2024-06-27 02:32:26 -0700 | [diff] [blame] | 1 | #include "zte_mainctrl.h" |
| 2 | #include "netapi.h" |
| 3 | #include <asm/unistd.h> |
| 4 | |
| 5 | #define IPV6_RA_FLAG_PD (1<<2) |
| 6 | #define IPV6_RA_FLAG_MANAGED (1<<1) |
| 7 | #define IPV6_RA_FLAG_OTHER_CONFIG (1<<0) |
| 8 | |
| 9 | char defwan_if_old[ZTE_ROUTER_WAN_IF_NAME_LEN] = {0}; |
| 10 | char defwan6_if_old[ZTE_ROUTER_WAN_IF_NAME_LEN] = {0}; |
| 11 | |
| 12 | static const char g_dhcp_conf[]="start %s\nend %s\ninterface %s\noption subnet %s\noption dns %s %s\noption router %s\noption lease 86400\npidfile %s\nlease_file %s\n"; |
| 13 | static const char g_dns_conf[]="nameserver %s\r\n"; |
| 14 | static const char g_dhcp6_pd_conf[]="interface %s {\n\tserver-preference 255;\n\trenew-time 6000;\n\trebind-time 9000;\n\tprefer-life-time 1300;\n\tvalid-life-time 2000;\n\tallow rapid-commit;\n\tlink %s {\n\t\tallow unicast;\n\t\tsend unicast;\n\t\tprefix %s:/%d;\n\t};\n\toption dns_servers %s %s;\n};"; |
| 15 | static const char g_dhcp6_state_conf[]="interface %s {\n\tserver-preference 255;\n\trenew-time 6000;\n\trebind-time 9000;\n\tprefer-life-time 1300;\n\tvalid-life-time 2000;\n\tallow rapid-commit;\n\tlink %s {\n\t\tallow unicast;\n\t\tsend unicast;\n\t\tpool {\n\t\t\trange %s to %s/%d;\n\t\t};\n\t};\n\toption dns_servers %s %s;\n};"; |
| 16 | static const char g_dhcp6_stateless_conf[]="interface %s {\n\tlink %s {\n\t};\n\toption dns_servers %s %s;\n};"; |
| 17 | static const char g_radvd_state_conf[]="interface %s\n{\n\tAdvSendAdvert on;\n\tAdvManagedFlag on;\n};"; |
| 18 | static const char g_radvd_stateless_conf[]="interface %s\n{\n\tAdvSendAdvert on;\n\tAdvOtherConfigFlag on;\n\tMinRtrAdvInterval 30;\n\tMaxRtrAdvInterval 100;\n\n\tprefix %s/%d\n\t{\n\t\tAdvOnLink on;\n\t\tAdvAutonomous on;\n\t\tAdvRouterAddr off;\n\n\t\tAdvValidLifetime 300;\n\t\tAdvPreferredLifetime 120;\n\t};\n};"; |
| 19 | static const char g_radvd_autocfg_conf[]="interface %s\n{\n\tAdvSendAdvert on;\n\tAdvOtherConfigFlag off;\n\tMinRtrAdvInterval 30;\n\tMaxRtrAdvInterval 100;\n\n\tprefix %s/%d\n\t{\n\t\tAdvOnLink on;\n\t\tAdvAutonomous on;\n\t\tAdvRouterAddr off;\n\n\t\tAdvValidLifetime 300;\n\t\tAdvPreferredLifetime 120;\n\t};\n\tRDNSS %s %s\n\t{\n\t\tAdvRDNSSPreference 15;\n\t\tAdvRDNSSOpen on;\n\t};\n};"; |
| 20 | |
| 21 | struct dhcp_conf_info { |
| 22 | char *start; |
| 23 | char *end; |
| 24 | char *interface; |
| 25 | char *subnet; |
| 26 | char *dns1; |
| 27 | char *dns2; |
| 28 | char *router; |
| 29 | char *pidfile; |
| 30 | char *lease_file; |
| 31 | }; |
| 32 | |
| 33 | struct dhcp6_conf_info { |
| 34 | char *interface; |
| 35 | char *link; |
| 36 | char *start; |
| 37 | char *end; |
| 38 | char *prefix; |
| 39 | int prefix_len; |
| 40 | char *dns1; |
| 41 | char *dns2; |
| 42 | }; |
| 43 | |
| 44 | struct radvd_conf_info { |
| 45 | char *interface; |
| 46 | char *prefix; |
| 47 | int prefix_len; |
| 48 | char *dns1; |
| 49 | char *dns2; |
| 50 | }; |
| 51 | |
| 52 | struct in6_ifreq { |
| 53 | struct in6_addr ifr6_addr; |
| 54 | unsigned int ifr6_prefixlen; |
| 55 | int ifr6_ifindex; |
| 56 | }; |
| 57 | |
| 58 | static void save_interface_id(char *nv_name, char * ip6) |
| 59 | { |
| 60 | |
| 61 | int i = 0; |
| 62 | char * postptr = NULL; |
| 63 | int ip6_seg = 0; //ipv6µØÖ·ÖÐðºÅµÄ¸öÊý |
| 64 | int ip6_seg_loc = 0; |
| 65 | int len; |
| 66 | |
| 67 | len = strlen(ip6); |
| 68 | |
| 69 | for (i = 0; i < len; i++) { |
| 70 | if (ip6[i] == ':') { |
| 71 | ip6_seg++; |
| 72 | if (ip6_seg == 4) |
| 73 | ip6_seg_loc = i; |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | if (ip6_seg == 3) //¼¤»îÐÅϢΪipv6ºó׺£¬²»ÐèÒª½Ø¶Ï |
| 78 | postptr = ip6; |
| 79 | |
| 80 | else if (ip6_seg == 7) //¼¤»îÐÅϢΪipv6ǰ׺+ºó׺£¬ÐèÒª½Ø¶Ï´¦Àí |
| 81 | postptr = &ip6[ip6_seg_loc + 1]; |
| 82 | else |
| 83 | softap_assert("ipv6 address %s is wrong!", ip6); |
| 84 | |
| 85 | cfg_set(nv_name, postptr); |
| 86 | } |
| 87 | |
| 88 | static inline void zxic_inet_pton(int af, const char *src, void *dst) |
| 89 | { |
| 90 | if(inet_pton(af, src, dst) < 0) |
| 91 | slog(NET_PRINT, SLOG_ERR, "inet_pton fail, error:%s src:%s\n", strerror(errno), src); |
| 92 | } |
| 93 | |
| 94 | static inline void zxic_inet_ntop(int af, const void *src, char *dst, socklen_t cnt) |
| 95 | { |
| 96 | if(inet_ntop(af, src, dst, cnt) == NULL) |
| 97 | slog(NET_PRINT, SLOG_ERR, "inet_ntop fail, error:%s\n", strerror(errno)); |
| 98 | } |
| 99 | |
| 100 | static inline void zxic_remove(char *filename) |
| 101 | { |
| 102 | if(remove(filename) != 0) |
| 103 | slog(NET_PRINT, SLOG_ERR, "remove fail, error:%s file:%s\n", strerror(errno), filename); |
| 104 | } |
| 105 | |
| 106 | int net_read_file(const char *path, void *vptr, size_t n) |
| 107 | { |
| 108 | int fd; |
| 109 | size_t nleft; |
| 110 | ssize_t nread; |
| 111 | char *ptr; |
| 112 | if (path == NULL || vptr == NULL){ |
| 113 | slog(NET_PRINT, SLOG_ERR, "net_read_file Input err %p %p\n", path, vptr); |
| 114 | return -1; |
| 115 | } |
| 116 | ptr = vptr; |
| 117 | nleft = n; |
| 118 | fd = open(path, O_RDONLY); |
| 119 | if (fd < 0){ |
| 120 | slog(NET_PRINT, SLOG_ERR, "net_read_file Open fail, error:%s path:%s\n", strerror(errno), path); |
| 121 | return -1; |
| 122 | } |
| 123 | while (nleft > 0) { |
| 124 | nread = read(fd, ptr, nleft); |
| 125 | if (nread < 0) { |
| 126 | if (errno == EINTR){ |
| 127 | nread = 0; /* and call read() again */ |
| 128 | }else{ |
| 129 | slog(NET_PRINT, SLOG_ERR, "net_read_file fail, error:%s path:%s\n", strerror(errno), path); |
| 130 | close(fd); |
| 131 | return (-1); |
| 132 | } |
| 133 | } else if (nread == 0){ |
| 134 | slog(NET_PRINT, SLOG_ERR, "Read NULL! path:%s\n", path); |
| 135 | break; /* EOF */ |
| 136 | }else{ |
| 137 | nleft -= nread; |
| 138 | ptr += nread; |
| 139 | } |
| 140 | } |
| 141 | close(fd); |
| 142 | return (n - nleft); /* return >= 0 */ |
| 143 | } |
| 144 | |
| 145 | int net_write_file(const char *path, const char *buf, int len) |
| 146 | { |
| 147 | int fd; |
| 148 | size_t nleft; |
| 149 | ssize_t nwritten; |
| 150 | char *ptr; |
| 151 | int err_no; |
| 152 | |
| 153 | if (path == NULL || buf == NULL){ |
| 154 | slog(NET_PRINT, SLOG_ERR, "net_write_file Input err %p %p\n", path, buf); |
| 155 | return -1; |
| 156 | } |
| 157 | ptr = buf; |
| 158 | nleft = len; |
| 159 | // O_TRUNC:½«Îļþ³¤¶È½Ø¶ÏΪ0£¬×öΪÐÂÎļþдÈë |
| 160 | fd = open(path, O_RDWR | O_CREAT | O_TRUNC | O_SYNC, 777); |
| 161 | if (fd < 0){ |
| 162 | slog(NET_PRINT, SLOG_ERR, "net_write_file Open fail, error:%s, path:%s\n", strerror(errno), path); |
| 163 | return -1; |
| 164 | } |
| 165 | while (nleft > 0){ |
| 166 | if ( (nwritten = write(fd, ptr, nleft)) <= 0){ |
| 167 | err_no = errno; |
| 168 | if (nwritten < 0 && err_no == EINTR){ |
| 169 | nwritten = 0; /* and call write() again */ |
| 170 | }else{ |
| 171 | slog(NET_PRINT, SLOG_ERR, "net_write_file fail, error:%s, left=%d path:%s\n", strerror(err_no), nleft, path); |
| 172 | close(fd); |
| 173 | return -1; |
| 174 | } |
| 175 | } |
| 176 | nleft -= nwritten; |
| 177 | ptr += nwritten; |
| 178 | } |
| 179 | if (fsync(fd) < 0) { |
| 180 | slog(NET_PRINT, SLOG_ERR, "net_write_file Sync fail:%s, path:%s\n", strerror(errno), path); |
| 181 | close(fd); |
| 182 | return -1; |
| 183 | } |
| 184 | close(fd); |
| 185 | return len; |
| 186 | } |
| 187 | |
| 188 | static void kill_pid_by_nv(char *nv_name) |
| 189 | { |
| 190 | char pid_s[16] = {0}; |
| 191 | pid_t pid = 0; |
| 192 | |
| 193 | cfg_get_item(nv_name, pid_s, sizeof(pid_s)); |
| 194 | pid = atoi(pid_s); |
| 195 | if(pid > 0) |
| 196 | { |
| 197 | slog(NET_PRINT, SLOG_NORMAL, "kill %s pid=%d \n", nv_name, pid); |
| 198 | kill(pid, SIGKILL); |
| 199 | } |
| 200 | cfg_set(nv_name, ""); |
| 201 | } |
| 202 | |
| 203 | static void kill_pid_by_path(char *path) |
| 204 | { |
| 205 | char pid_s[16] = {0}; |
| 206 | pid_t pid = 0; |
| 207 | |
| 208 | if(access(path, F_OK)) |
| 209 | return; |
| 210 | if(net_read_file(path, pid_s, sizeof(pid_s)-1) > 0){ |
| 211 | pid = atoi(pid_s); |
| 212 | if(pid > 0) |
| 213 | { |
| 214 | slog(NET_PRINT, SLOG_NORMAL, "kill udhcpd pid=%d \n", pid); |
| 215 | kill(pid, SIGKILL); |
| 216 | } |
| 217 | zxic_remove(path); |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | static void arp_down(int cid) |
| 222 | { |
| 223 | char nv_name[32] = {0}; |
| 224 | |
| 225 | snprintf(nv_name, sizeof(nv_name), "br%d_arp_pid", cid); |
| 226 | kill_pid_by_nv(nv_name); |
| 227 | } |
| 228 | |
| 229 | static void dhcp_down(int cid) |
| 230 | { |
| 231 | char path_conf[16] = {0}; |
| 232 | char path[32] = {0}; |
| 233 | |
| 234 | cfg_get_item("path_conf", path_conf, sizeof(path_conf)); |
| 235 | snprintf(path, sizeof(path), "%s/udhcpd%d.pid", path_conf, cid); |
| 236 | kill_pid_by_path(path); |
| 237 | } |
| 238 | |
| 239 | static void ndp_down(int cid) |
| 240 | { |
| 241 | char nv_name[32] = {0}; |
| 242 | |
| 243 | snprintf(nv_name, sizeof(nv_name), "br%d_ndp_pid", cid); |
| 244 | kill_pid_by_nv(nv_name); |
| 245 | } |
| 246 | |
| 247 | static void dhcp6s_down(int cid) |
| 248 | { |
| 249 | char nv_name[32] = {0}; |
| 250 | |
| 251 | snprintf(nv_name, sizeof(nv_name), "br%d_dhcp6s_pid", cid); |
| 252 | kill_pid_by_nv(nv_name); |
| 253 | } |
| 254 | |
| 255 | static void radvd_down(int cid) |
| 256 | { |
| 257 | char path_tmp[16] = {0}; |
| 258 | char path[32] = {0}; |
| 259 | |
| 260 | cfg_get_item("path_tmp", path_tmp, sizeof(path_tmp)); |
| 261 | snprintf(path, sizeof(path), "%s/radvd%d.pid", path_tmp, cid); |
| 262 | kill_pid_by_path(path); |
| 263 | } |
| 264 | |
| 265 | static int config_udhcpd(const char *path, struct dhcp_conf_info *info) |
| 266 | { |
| 267 | char buf[512] = {0}; |
| 268 | int buf_len = 0; |
| 269 | |
| 270 | if (path == NULL || info == NULL){ |
| 271 | slog(NET_PRINT, SLOG_ERR, "config_udhcpd Input err %p %p\n", path, info); |
| 272 | return -1; |
| 273 | } |
| 274 | buf_len = snprintf(buf, sizeof(buf), g_dhcp_conf, info->start, info->end, info->interface, |
| 275 | info->subnet, info->dns1, info->dns2, info->router, info->pidfile, info->lease_file); |
| 276 | if(buf_len <= 0 || buf_len != strlen(buf)){ |
| 277 | slog(NET_PRINT, SLOG_ERR, "config_udhcpd snprintf err ret=%d cur=%d\n", buf_len, strlen(buf)); |
| 278 | return -1; |
| 279 | } |
| 280 | return net_write_file(path, buf, strlen(buf)); |
| 281 | } |
| 282 | |
| 283 | static int config_dns(const char *path, const char *dns1, const char *dns2) |
| 284 | { |
| 285 | char buf[512] = {0}; |
| 286 | char *pbuf = buf; |
| 287 | int ret = 0; |
| 288 | |
| 289 | if (path == NULL || (dns1 == NULL && dns2 == NULL)){ |
| 290 | slog(NET_PRINT, SLOG_ERR, "config_dns Input err\n"); |
| 291 | return -1; |
| 292 | } |
| 293 | ret = net_read_file(path, buf, sizeof(buf)-1); |
| 294 | if(ret > 0 && ret < (sizeof(buf) >> 1)){ |
| 295 | pbuf = pbuf + strlen(pbuf); |
| 296 | } |
| 297 | else |
| 298 | slog(NET_PRINT, SLOG_ERR, "config_dns read err ret=%d\n",ret); |
| 299 | if(dns1 != NULL && strlen(dns1) > 6){ |
| 300 | snprintf(pbuf, sizeof(buf), g_dns_conf, dns1); |
| 301 | pbuf = pbuf + strlen(pbuf); |
| 302 | } |
| 303 | if(dns2 != NULL && strlen(dns2) > 6){ |
| 304 | snprintf(pbuf, sizeof(buf)-strlen(buf), g_dns_conf, dns2); |
| 305 | } |
| 306 | if(strlen(buf) > 0) |
| 307 | return net_write_file(path, buf, strlen(buf)); |
| 308 | return 0; |
| 309 | } |
| 310 | |
| 311 | /*¼¤»îIPµÄ×îºóÒ»¸öÊý×ÖµÄ2½øÖƵĺó3λÊÇ010 001 000ʱ+2£¬·ñÔò-2*/ |
| 312 | FILE *pdp_direct_config_quick4(const char *nv_pswan, struct pdp_active_info *actinfo) |
| 313 | { |
| 314 | int i = 0; |
| 315 | unsigned int addr = 0; |
| 316 | unsigned int dns1 = 0; |
| 317 | unsigned int dns2 = 0; |
| 318 | unsigned int route_ip = 0; |
| 319 | unsigned int wan_ip = 0; |
| 320 | unsigned int netmask = 0; |
| 321 | char dns1_s[IPV4ADDLEN_MAX] = {0}; |
| 322 | char dns2_s[IPV4ADDLEN_MAX] = {0}; |
| 323 | char route_ip_s[IPV4ADDLEN_MAX] = {0}; |
| 324 | char wan_ip_s[IPV4ADDLEN_MAX] = {0}; |
| 325 | char netmask_s[IPV4ADDLEN_MAX] = {0}; |
| 326 | char path_conf[16] = {0}; |
| 327 | char dev[16] = {0}; |
| 328 | char pidfile[32] = {0}; |
| 329 | char lease_file[32] = {0}; |
| 330 | char path[32] = {0}; |
| 331 | char cmd[64] = {0}; |
| 332 | char nv_name[NV_NAME_LEN] = {0}; |
| 333 | struct dhcp_conf_info info = {0}; |
| 334 | |
| 335 | cfg_get_item("path_conf", path_conf, sizeof(path_conf)); |
| 336 | snprintf(dev, sizeof(dev), "br%d", actinfo->c_id); |
| 337 | snprintf(pidfile, sizeof(pidfile), "%s/udhcpd%d.pid", path_conf, actinfo->c_id); |
| 338 | snprintf(lease_file, sizeof(lease_file), "%s/udhcpd%d.leases", path_conf, actinfo->c_id); |
| 339 | snprintf(path, sizeof(path), "%s/udhcpd%d.conf", path_conf, actinfo->c_id); |
| 340 | zxic_inet_pton(AF_INET, actinfo->act_info.ip, &addr); |
| 341 | zxic_inet_pton(AF_INET, actinfo->act_info.pri_dns, &dns1); |
| 342 | zxic_inet_pton(AF_INET, actinfo->act_info.sec_dns, &dns2); |
| 343 | addr = htonl(addr); |
| 344 | if(dns1) |
| 345 | snprintf(dns1_s, sizeof(dns1_s), "%s", actinfo->act_info.pri_dns); |
| 346 | else |
| 347 | snprintf(dns1_s, sizeof(dns1_s), "%s", "114.114.114.114"); |
| 348 | if(dns2) |
| 349 | snprintf(dns2_s, sizeof(dns2_s), "%s", actinfo->act_info.sec_dns); |
| 350 | else |
| 351 | snprintf(dns2_s, sizeof(dns2_s), "%s", "8.8.8.8"); |
| 352 | |
| 353 | #if 0 //btrunk |
| 354 | netmask = 0xffff0000; |
| 355 | if((addr&0xff) <= 1){ |
| 356 | route_ip = addr+2; |
| 357 | wan_ip = addr+1; |
| 358 | } |
| 359 | else if((addr&0xff) >= 254){ |
| 360 | route_ip = addr-2; |
| 361 | wan_ip = addr-1; |
| 362 | }else{ |
| 363 | route_ip = addr+1; |
| 364 | wan_ip = addr-1; |
| 365 | } |
| 366 | #else |
| 367 | if((addr&7) < 3){ |
| 368 | route_ip = addr+2; |
| 369 | wan_ip = addr+1; |
| 370 | }else{ |
| 371 | route_ip = addr-2; |
| 372 | wan_ip = addr-1; |
| 373 | } |
| 374 | for(i = 3; i < 32; i++){ |
| 375 | /*²»ÊÇÁ¬ÐøµÄÈ«0 && ²»ÊÇÁ¬ÐøµÄÈ«1*/ |
| 376 | if(((addr>>i)<<i) != addr && (((1<<i)-1)|addr) != addr) |
| 377 | break; |
| 378 | } |
| 379 | netmask = 0xfffffff8; |
| 380 | if(i > 3 && i < 32)//cov |
| 381 | netmask = ((netmask>>i)<<i); |
| 382 | #endif |
| 383 | route_ip = htonl(route_ip); |
| 384 | wan_ip = htonl(wan_ip); |
| 385 | netmask = htonl(netmask); |
| 386 | inet_ntop(AF_INET, (void *)&route_ip, route_ip_s, IPV4ADDLEN_MAX); |
| 387 | inet_ntop(AF_INET, (void *)&wan_ip, wan_ip_s, IPV4ADDLEN_MAX); |
| 388 | inet_ntop(AF_INET, (void *)&netmask, netmask_s, IPV4ADDLEN_MAX); |
| 389 | snprintf(nv_name, sizeof(nv_name), "%s%d_pdp_ip", nv_pswan, actinfo->c_id); |
| 390 | cfg_set(nv_name, actinfo->act_info.ip); |
| 391 | snprintf(nv_name, sizeof(nv_name), "%s%d_ip", nv_pswan, actinfo->c_id); |
| 392 | cfg_set(nv_name, wan_ip_s); |
| 393 | snprintf(nv_name, sizeof(nv_name), "br%d_ip", actinfo->c_id); |
| 394 | cfg_set(nv_name, route_ip_s); |
| 395 | snprintf(nv_name, sizeof(nv_name), "br%d_nm", actinfo->c_id);//for mbim |
| 396 | cfg_set(nv_name, netmask_s); |
| 397 | snprintf(nv_name, sizeof(nv_name), "%s%d_pridns", nv_pswan, actinfo->c_id); |
| 398 | cfg_set(nv_name, dns1_s); |
| 399 | snprintf(nv_name, sizeof(nv_name), "%s%d_secdns", nv_pswan, actinfo->c_id); |
| 400 | cfg_set(nv_name, dns2_s); |
| 401 | |
| 402 | info.start = actinfo->act_info.ip; |
| 403 | info.end = actinfo->act_info.ip; |
| 404 | info.interface = dev; |
| 405 | info.subnet = netmask_s; |
| 406 | info.dns1 = dns1_s; |
| 407 | info.dns2 = dns2_s; |
| 408 | info.router = route_ip_s; |
| 409 | info.pidfile = pidfile; |
| 410 | info.lease_file = lease_file; |
| 411 | if(config_udhcpd(path, &info) < 0) |
| 412 | return NULL; |
| 413 | if(config_dns("/etc/resolv.conf", dns1_s, dns2_s) < 0) |
| 414 | return NULL; |
| 415 | snprintf(cmd, sizeof(cmd), "psext_up.sh %d", actinfo->c_id); |
| 416 | dhcp_down(actinfo->c_id); |
| 417 | return popen(cmd, "r"); |
| 418 | } |
| 419 | |
| 420 | static int config_dhcp6s(const char *path, struct dhcp6_conf_info *info, int M_O_flag) |
| 421 | { |
| 422 | char buf[1024] = {0}; |
| 423 | int buf_len = 0;; |
| 424 | |
| 425 | if (path == NULL || info == NULL){ |
| 426 | slog(NET_PRINT, SLOG_ERR, "config_dhcpd6s Input err %p %p\n", path, info); |
| 427 | return -1; |
| 428 | } |
| 429 | if(M_O_flag & IPV6_RA_FLAG_PD){ |
| 430 | buf_len = snprintf(buf, sizeof(buf), g_dhcp6_pd_conf, info->interface, info->link, info->prefix, |
| 431 | info->prefix_len, info->dns1, info->dns2); |
| 432 | }else if(M_O_flag & IPV6_RA_FLAG_MANAGED){ |
| 433 | buf_len = snprintf(buf, sizeof(buf), g_dhcp6_state_conf, info->interface, info->link, info->start, |
| 434 | info->end, info->prefix_len, info->dns1, info->dns2); |
| 435 | }else if(M_O_flag & IPV6_RA_FLAG_OTHER_CONFIG){ |
| 436 | buf_len = snprintf(buf, sizeof(buf), g_dhcp6_stateless_conf, info->interface, info->link, |
| 437 | info->dns1, info->dns2); |
| 438 | }else{ |
| 439 | slog(NET_PRINT, SLOG_ERR, "config_dhcpd6s err m=0 o=0\n"); |
| 440 | return 0; |
| 441 | } |
| 442 | if(buf_len <= 0 || buf_len != strlen(buf)){ |
| 443 | slog(NET_PRINT, SLOG_ERR, "config_dhcpd6s snprintf err ret=%d cur=%d\n", buf_len, strlen(buf)); |
| 444 | return -1; |
| 445 | } |
| 446 | return net_write_file(path, buf, strlen(buf)); |
| 447 | } |
| 448 | |
| 449 | static int config_radvd(const char *path, struct radvd_conf_info *info, int M_O_flag) |
| 450 | { |
| 451 | char buf[1024] = {0}; |
| 452 | int buf_len; |
| 453 | |
| 454 | if (path == NULL || info == NULL){ |
| 455 | slog(NET_PRINT, SLOG_ERR, "config_radvd Input err %p %p\n", path, info); |
| 456 | return -1; |
| 457 | } |
| 458 | if((M_O_flag & IPV6_RA_FLAG_MANAGED) || (M_O_flag & IPV6_RA_FLAG_PD)){ |
| 459 | buf_len = snprintf(buf, sizeof(buf), g_radvd_state_conf, info->interface); |
| 460 | }else if(M_O_flag & IPV6_RA_FLAG_OTHER_CONFIG){ |
| 461 | buf_len = snprintf(buf, sizeof(buf), g_radvd_stateless_conf, info->interface, info->prefix, info->prefix_len); |
| 462 | }else{ |
| 463 | buf_len = snprintf(buf, sizeof(buf), g_radvd_autocfg_conf, info->interface, info->prefix, info->prefix_len, |
| 464 | info->dns1, info->dns2); |
| 465 | } |
| 466 | if(buf_len <= 0 || buf_len != strlen(buf)){ |
| 467 | slog(NET_PRINT, SLOG_ERR, "config_radvd snprintf err ret=%d cur=%d\n", buf_len, strlen(buf)); |
| 468 | return -1; |
| 469 | } |
| 470 | return net_write_file(path, buf, strlen(buf)); |
| 471 | } |
| 472 | |
| 473 | FILE *pdp_direct_config_quick6(const char *nv_pswan, struct pdp_active_info *actinfo, char *prefix, int prefix_len) |
| 474 | { |
| 475 | char cmd[100] = {0}; |
| 476 | char nv_pridns6[NV_NAME_LEN] = {0}; |
| 477 | char nv_secdns6[NV_NAME_LEN] = {0}; |
| 478 | char nv_ip6[NV_NAME_LEN] = {0}; |
| 479 | snprintf(nv_ip6, sizeof(nv_ip6), "%s%d_ipv6_interface_id", nv_pswan, actinfo->c_id); |
| 480 | save_interface_id(nv_ip6, actinfo->act_info.ip6); |
| 481 | snprintf(nv_pridns6, sizeof(nv_pridns6), "%s%d_ipv6_pridns_auto", nv_pswan, actinfo->c_id); |
| 482 | cfg_set(nv_pridns6, actinfo->act_info.pri_dns6); |
| 483 | snprintf(nv_secdns6, sizeof(nv_secdns6), "%s%d_ipv6_secdns_auto", nv_pswan, actinfo->c_id); |
| 484 | cfg_set(nv_secdns6, actinfo->act_info.sec_dns6); |
| 485 | slog(NET_PRINT, SLOG_NORMAL, "pdp_quick6 prefix=%s len=%d \n", prefix, prefix_len); |
| 486 | if(prefix_len > 0) |
| 487 | { |
| 488 | char nv_name[NV_NAME_LEN] = {0}; |
| 489 | struct in6_addr ipv6_addr = {0}; |
| 490 | char br_ip6[IPV6ADDLEN_MAX] = {0}; |
| 491 | char wan_ip6[IPV6ADDLEN_MAX] = {0}; |
| 492 | char pdp_ip6[IPV6ADDLEN_MAX] = {0}; |
| 493 | int M_O_flag = 0; |
| 494 | char PdFlag[4] = {0}; |
| 495 | char AdvManagedFlag[4] = {0}; |
| 496 | char AdvOtherConfigFlag[4] = {0}; |
| 497 | struct dhcp6_conf_info dhcp6_info = {0}; |
| 498 | struct radvd_conf_info radvd_info = {0}; |
| 499 | char path_conf[16] = {0}; |
| 500 | char dev[16] = {0}; |
| 501 | char dhcp6_path[32] = {0}; |
| 502 | char radvd_path[32] = {0}; |
| 503 | |
| 504 | snprintf(nv_name, sizeof(nv_name), "%s%d_ipv6_local", nv_pswan, actinfo->c_id); |
| 505 | cfg_get_item(nv_ip6, cmd, sizeof(cmd)); |
| 506 | snprintf(pdp_ip6, sizeof(pdp_ip6), "fe80::%s", cmd); |
| 507 | cfg_set(nv_name, pdp_ip6);//actinfo->act_info.ip6 |
| 508 | memcpy(pdp_ip6, actinfo->act_info.ip6, IPV6ADDLEN_MAX -1); |
| 509 | if((prefix_len/16)*5 < IPV6ADDLEN_MAX)//kw |
| 510 | memcpy(pdp_ip6, prefix, (prefix_len/16)*5); |
| 511 | pdp_ip6[IPV6ADDLEN_MAX-1]='\0';//kw |
| 512 | snprintf(nv_name, sizeof(nv_name), "%s%d_ipv6_pdp", nv_pswan, actinfo->c_id); |
| 513 | cfg_set(nv_name, pdp_ip6); |
| 514 | snprintf(nv_name, sizeof(nv_name), "%s%d_dhcpv6_end", nv_pswan, actinfo->c_id);//for mbim |
| 515 | cfg_set(nv_name, pdp_ip6); |
| 516 | zxic_inet_pton(AF_INET6, pdp_ip6, &ipv6_addr); |
| 517 | ipv6_addr.s6_addr[14]++; |
| 518 | zxic_inet_ntop(AF_INET6, &ipv6_addr, br_ip6, sizeof(br_ip6)); |
| 519 | snprintf(nv_name, sizeof(nv_name), "br%d_ipv6_ip", actinfo->c_id); |
| 520 | cfg_set(nv_name, br_ip6); |
| 521 | ipv6_addr.s6_addr[14]++; |
| 522 | zxic_inet_ntop(AF_INET6, &ipv6_addr, wan_ip6, sizeof(wan_ip6)); |
| 523 | snprintf(nv_name, sizeof(nv_name), "%s%d_ipv6_ip", nv_pswan, actinfo->c_id); |
| 524 | cfg_set(nv_name, wan_ip6); |
| 525 | snprintf(dev, sizeof(dev), "br%d", actinfo->c_id); |
| 526 | cfg_get_item("path_conf", path_conf, sizeof(path_conf)); |
| 527 | snprintf(dhcp6_path, sizeof(dhcp6_path), "%s/dhcp6s%d.conf", path_conf, actinfo->c_id); |
| 528 | snprintf(radvd_path, sizeof(radvd_path), "%s/radvd%d.conf", path_conf, actinfo->c_id); |
| 529 | cfg_get_item("dhcpv6statePdEnabled", PdFlag, sizeof(PdFlag)); |
| 530 | cfg_get_item("dhcpv6stateEnabled", AdvManagedFlag, sizeof(AdvManagedFlag)); |
| 531 | cfg_get_item("dhcpv6statelessEnabled", AdvOtherConfigFlag, sizeof(AdvOtherConfigFlag)); |
| 532 | if(atoi(PdFlag) == 1) |
| 533 | M_O_flag = M_O_flag|IPV6_RA_FLAG_PD; |
| 534 | if(atoi(AdvManagedFlag) == 1) |
| 535 | M_O_flag = M_O_flag|IPV6_RA_FLAG_MANAGED; |
| 536 | if(atoi(AdvOtherConfigFlag) == 1) |
| 537 | M_O_flag = M_O_flag|IPV6_RA_FLAG_OTHER_CONFIG; |
| 538 | dhcp6_info.interface = dev; |
| 539 | dhcp6_info.link = dev; |
| 540 | dhcp6_info.start = pdp_ip6; |
| 541 | dhcp6_info.end = pdp_ip6; |
| 542 | dhcp6_info.prefix = prefix; |
| 543 | dhcp6_info.prefix_len = prefix_len; |
| 544 | dhcp6_info.dns1 = actinfo->act_info.pri_dns6; |
| 545 | dhcp6_info.dns2 = actinfo->act_info.sec_dns6; |
| 546 | if(config_dhcp6s(dhcp6_path, &dhcp6_info, M_O_flag) < 0) |
| 547 | return NULL; |
| 548 | radvd_info.interface = dev; |
| 549 | radvd_info.prefix = br_ip6; |
| 550 | radvd_info.prefix_len = prefix_len; |
| 551 | radvd_info.dns1 = actinfo->act_info.pri_dns6; |
| 552 | radvd_info.dns2 = actinfo->act_info.sec_dns6; |
| 553 | if(config_radvd(radvd_path, &radvd_info, M_O_flag) < 0) |
| 554 | return NULL; |
| 555 | if(config_dns("/etc/resolv.conf", actinfo->act_info.pri_dns6, actinfo->act_info.sec_dns6) < 0) |
| 556 | return NULL; |
| 557 | snprintf(cmd, sizeof(cmd), "psext_up_ipv6.sh %d", actinfo->c_id); |
| 558 | dhcp6s_down(actinfo->c_id); |
| 559 | return popen(cmd, "r"); |
| 560 | }else{ |
| 561 | sprintf(cmd, "psext_updown_ipv6.sh linkup %d", actinfo->c_id); |
| 562 | return popen(cmd, "r"); |
| 563 | } |
| 564 | } |
| 565 | |
| 566 | void pdp_direct_config_quick(struct pdp_active_info *actinfo, char *prefix, int prefix_len) |
| 567 | { |
| 568 | FILE *fpv4 = NULL; |
| 569 | FILE *fpv6 = NULL; |
| 570 | |
| 571 | zxic_remove("/etc_rw/resolv.conf"); |
| 572 | |
| 573 | if (actinfo->act_info.ip46flag == V4_VALID || actinfo->act_info.ip46flag == V46_VALID) { |
| 574 | fpv4 = pdp_direct_config_quick4(ps_wan, actinfo); |
| 575 | slog(NET_PRINT, SLOG_NORMAL, "psext_up4 popen=%p \n", fpv4); |
| 576 | } |
| 577 | |
| 578 | if (actinfo->act_info.ip46flag == V6_VALID || actinfo->act_info.ip46flag == V46_VALID) { |
| 579 | fpv6 = pdp_direct_config_quick6(ps_wan, actinfo, prefix, prefix_len); |
| 580 | slog(NET_PRINT, SLOG_NORMAL, "psext_up6 popen=%p \n", fpv6); |
| 581 | } |
| 582 | if(fpv4 != NULL) |
| 583 | pclose(fpv4); |
| 584 | if(fpv6 != NULL) |
| 585 | pclose(fpv6); |
| 586 | } |
| 587 | |
| 588 | void net_br_deact_quick(int c_id, unsigned char ip46flag) |
| 589 | { |
| 590 | FILE *fpv4 = NULL; |
| 591 | FILE *fpv6 = NULL; |
| 592 | char cmd[64] = {0}; |
| 593 | |
| 594 | if (ip46flag == V4_VALID || ip46flag == V46_VALID) { |
| 595 | sprintf(cmd, "psext_down.sh %d", c_id); |
| 596 | fpv4 = popen(cmd, "r"); |
| 597 | arp_down(c_id); |
| 598 | dhcp_down(c_id); |
| 599 | } |
| 600 | if (ip46flag == V6_VALID || ip46flag == V46_VALID) { |
| 601 | memset(cmd, 0, sizeof(cmd)); |
| 602 | sprintf(cmd, "psext_down_ipv6.sh %d", c_id); |
| 603 | fpv6 = popen(cmd, "r"); |
| 604 | radvd_down(c_id); |
| 605 | dhcp6s_down(c_id); |
| 606 | ndp_down(c_id); |
| 607 | } |
| 608 | net_write_file("/etc/resolv.conf", "", 0); |
| 609 | if(fpv4 != NULL) |
| 610 | pclose(fpv4); |
| 611 | if(fpv6 != NULL) |
| 612 | pclose(fpv6); |
| 613 | } |
| 614 | |
| 615 | void net_sendmsg_2_atctl(int cid, int iptype, int cmd) |
| 616 | { |
| 617 | int ret = -1; |
| 618 | TScriptMSG scriptmsg; |
| 619 | memset(&scriptmsg, 0, sizeof(TScriptMSG)); |
| 620 | scriptmsg.cid = cid; |
| 621 | scriptmsg.iptype = iptype; |
| 622 | char buffer[128] = {0}; |
| 623 | |
| 624 | slog(NET_PRINT, SLOG_NORMAL, "$$$$$net_sendmsg_2_atctl cid=%d,iptype=%d\n", cid, iptype); |
| 625 | ret = ipc_send_message(MODULE_ID_MAIN_CTRL, MODULE_ID_AT_CTL, cmd, sizeof(TScriptMSG), &scriptmsg, 0); |
| 626 | if (0 != ret) { |
| 627 | softap_assert("send msg to at_ctl error"); |
| 628 | } |
| 629 | snprintf(buffer, sizeof(buffer), "pdp_act_state_%d", cid); |
| 630 | if(cmd == MSG_CMD_LINKUP_END) |
| 631 | cfg_set(buffer, "act"); |
| 632 | else if(cmd == MSG_CMD_LINKDOWN_END) |
| 633 | cfg_set(buffer, "deact"); |
| 634 | } |
| 635 | |
| 636 | void pdp_wan_config_quick(struct pdp_active_info *actinfo, char *prefix, int prefix_len) |
| 637 | { |
| 638 | int flag = 0; |
| 639 | struct in6_addr ipv6_addr = {0}; |
| 640 | char wan_name[NV_NAME_LEN] = {0}; |
| 641 | char br_ip6[IPV6ADDLEN_MAX] = {0}; |
| 642 | char pdp_ip6[IPV6ADDLEN_MAX] = {0}; |
| 643 | char dhcp_ip6_start[IPV6ADDLEN_MAX] = {0}; |
| 644 | char dhcp_ip6_end[IPV6ADDLEN_MAX] = {0}; |
| 645 | char tc_enable[4] = {0}; |
| 646 | char buffer[128] = {0}; |
| 647 | char mtu[16] = {0}; |
| 648 | char xlat_enable[4] = {0}; |
| 649 | |
| 650 | cfg_get_item("tc_enable", tc_enable, sizeof(tc_enable)); |
| 651 | snprintf(wan_name,NV_NAME_LEN, "%s%d", ps_wan, actinfo->c_id); |
| 652 | slog(NET_PRINT, SLOG_NORMAL, "act ifconfig wanname:%s!\n", wan_name); |
| 653 | |
| 654 | //ifconfig wan down |
| 655 | snprintf(buffer, sizeof(buffer), "ifconfig %s down", wan_name); |
| 656 | system_cmd_ex(buffer); |
| 657 | //ifconfig mtu |
| 658 | cfg_get_item("mtu", mtu, sizeof(mtu)); |
| 659 | snprintf(buffer, sizeof(buffer), "ifconfig %s mtu %s", wan_name, mtu); |
| 660 | system_cmd_ex(buffer); |
| 661 | //ifconfig ip |
| 662 | if(actinfo->act_info.ip46flag & V4_VALID){ |
| 663 | snprintf(buffer, sizeof(buffer), "%s_ip", wan_name); |
| 664 | cfg_set(buffer, actinfo->act_info.ip); |
| 665 | snprintf(buffer, sizeof(buffer), "%s_gw", wan_name); |
| 666 | cfg_set(buffer, actinfo->act_info.ip); |
| 667 | snprintf(buffer, sizeof(buffer), "%s_pridns", wan_name); |
| 668 | cfg_set(buffer, actinfo->act_info.pri_dns); |
| 669 | snprintf(buffer, sizeof(buffer), "%s_secdns", wan_name); |
| 670 | cfg_set(buffer, actinfo->act_info.sec_dns); |
| 671 | snprintf(buffer, sizeof(buffer), "ifconfig %s %s netmask 255.255.255.0", wan_name, actinfo->act_info.ip); |
| 672 | system_cmd_ex(buffer); |
| 673 | } |
| 674 | //ifconfig up |
| 675 | snprintf(buffer, sizeof(buffer), "ifconfig %s up", wan_name); |
| 676 | system_cmd_ex(buffer); |
| 677 | //ifconfig ipv6 |
| 678 | if(actinfo->act_info.ip46flag & V6_VALID){ |
| 679 | snprintf(buffer, sizeof(buffer), "%s_ipv6_interface_id", wan_name); |
| 680 | save_interface_id(buffer, actinfo->act_info.ip6); |
| 681 | snprintf(buffer, sizeof(buffer), "%s_ipv6_pridns_auto", wan_name); |
| 682 | cfg_set(buffer, actinfo->act_info.pri_dns6); |
| 683 | snprintf(buffer, sizeof(buffer), "%s_ipv6_secdns_auto", wan_name); |
| 684 | cfg_set(buffer, actinfo->act_info.sec_dns6); |
| 685 | memcpy(pdp_ip6, actinfo->act_info.ip6, IPV6ADDLEN_MAX -1); |
| 686 | if((prefix_len/16)*5 < IPV6ADDLEN_MAX)//kw |
| 687 | memcpy(pdp_ip6, prefix, (prefix_len/16)*5); |
| 688 | pdp_ip6[IPV6ADDLEN_MAX-1]='\0';//kw |
| 689 | snprintf(buffer, sizeof(buffer), "ifconfig %s %s/126", wan_name, pdp_ip6); |
| 690 | system_cmd_ex(buffer); |
| 691 | snprintf(buffer, sizeof(buffer), "%s_ipv6_ip", wan_name); |
| 692 | cfg_set(buffer, pdp_ip6); |
| 693 | zxic_inet_pton(AF_INET6, pdp_ip6, &ipv6_addr); |
| 694 | ipv6_addr.s6_addr[14]++; |
| 695 | zxic_inet_ntop(AF_INET6, &ipv6_addr, br_ip6, sizeof(br_ip6)); |
| 696 | ipv6_addr.s6_addr[14]++; |
| 697 | if (0xFF == ipv6_addr.s6_addr[14]) { |
| 698 | ipv6_addr.s6_addr[14] = 0; |
| 699 | } |
| 700 | zxic_inet_ntop(AF_INET6, &ipv6_addr, dhcp_ip6_start, sizeof(dhcp_ip6_start)); |
| 701 | ipv6_addr.s6_addr[14]++; |
| 702 | zxic_inet_ntop(AF_INET6, &ipv6_addr, dhcp_ip6_end, sizeof(dhcp_ip6_end)); |
| 703 | } |
| 704 | { |
| 705 | char path[32] = {0}; |
| 706 | char path_tmp[32] = {0}; |
| 707 | char dns_path[64] = {0}; |
| 708 | char wan_pri[32] = {0}; |
| 709 | char lan_if[16] = {0}; |
| 710 | int defwan_pri = 0; |
| 711 | int pri = 0; |
| 712 | char defwan_if[ZTE_ROUTER_WAN_IF_NAME_LEN] = {0}; |
| 713 | char defwan_real[ZTE_ROUTER_WAN_IF_NAME_LEN] = {0}; |
| 714 | char defwan_dev_name[ZTE_ROUTER_WAN_IF_NAME_LEN] = {0}; |
| 715 | int defwan4_change = 0; |
| 716 | int defwan6_change = 0; |
| 717 | struct default_dev_info defwan_dev_info = {0}; |
| 718 | |
| 719 | cfg_get_item("lan_name", lan_if, sizeof(lan_if)); |
| 720 | cfg_get_item("path_conf", path, sizeof(path)); |
| 721 | cfg_get_item("path_tmp", path_tmp, sizeof(path_tmp)); |
| 722 | defwan_dev_info.ip46flag = actinfo->act_info.ip46flag; |
| 723 | cfg_get_item("pswan_priority", wan_pri, sizeof(wan_pri)); |
| 724 | pri = atoi(wan_pri); |
| 725 | if(pri < 0 || pri > 65535) |
| 726 | return; |
| 727 | if (actinfo->pdp_type == PDP_NORMAL) { |
| 728 | if(default_route_check()){ |
| 729 | cfg_get_item("default_wan_name", defwan_if, sizeof(defwan_if)); |
| 730 | if(strncmp(defwan_if, wifi_wan, strlen(wifi_wan)) == 0){ |
| 731 | cfg_get_item("wifiwan_priority", wan_pri, sizeof(wan_pri)); |
| 732 | defwan_pri = atoi(wan_pri); |
| 733 | strcpy(defwan_dev_name, wifi_wan); |
| 734 | } |
| 735 | else if (strncmp(defwan_if, eth_wan, strlen(eth_wan)) == 0){ |
| 736 | cfg_get_item("ethwan_priority", wan_pri, sizeof(wan_pri)); |
| 737 | defwan_pri = atoi(wan_pri); |
| 738 | strcpy(defwan_dev_name, eth_wan); |
| 739 | } |
| 740 | } |
| 741 | if (pri > defwan_pri) { |
| 742 | defwan_pri = pri; |
| 743 | snprintf(defwan_if, sizeof(defwan_if), "%s%d", ps_wan, actinfo->c_id); |
| 744 | strcpy(defwan_real, defwan_if); |
| 745 | strcpy(defwan_dev_name, ps_wan); |
| 746 | //½«µ±Ç°ÓÐÐ§Íø¿ÚÖÐÓÅÏȼ¶×î¸ßµÄÉèÖÃΪȱʡÍâÍø¿Ú |
| 747 | if(actinfo->act_info.ip46flag & V4_VALID){ |
| 748 | cfg_set("default_wan_name", defwan_if); |
| 749 | cfg_set("default_wan_rel", defwan_real); |
| 750 | } |
| 751 | if(actinfo->act_info.ip46flag & V6_VALID){ |
| 752 | cfg_set("default_wan6_name", defwan_if); |
| 753 | cfg_set("default_wan6_rel", defwan_real); |
| 754 | } |
| 755 | } |
| 756 | defwan_dev_info.dev_id = getDevId_byname(defwan_dev_name); |
| 757 | net_default_wan_proc(&defwan_dev_info); |
| 758 | } else { |
| 759 | int rt_num = pri*10 + actinfo->c_id; |
| 760 | if(actinfo->act_info.ip46flag & V4_VALID){ |
| 761 | snprintf(buffer, sizeof(buffer), "ip rule add from %s table %d", actinfo->act_info.ip, rt_num); |
| 762 | system_cmd_ex(buffer); |
| 763 | snprintf(buffer, sizeof(buffer), "ip route add default dev %s table %d", wan_name, rt_num); |
| 764 | system_cmd_ex(buffer); |
| 765 | system_cmd_ex("ip route flush cache"); |
| 766 | } |
| 767 | if(actinfo->act_info.ip46flag & V6_VALID){ |
| 768 | snprintf(buffer, sizeof(buffer), "ip -6 rule add from %s table %d", pdp_ip6, rt_num); |
| 769 | system_cmd_ex(buffer); |
| 770 | snprintf(buffer, sizeof(buffer), "ip -6 route add default dev %s table %d", wan_name, rt_num); |
| 771 | system_cmd_ex(buffer); |
| 772 | system_cmd_ex("ip -6 route flush cache"); |
| 773 | } |
| 774 | } |
| 775 | if (0 == strlen(defwan_real)) { |
| 776 | slog(NET_PRINT, SLOG_ERR, "pdp_wan_config_quick defwan_if not selected! \n"); |
| 777 | net_sendmsg_2_atctl(actinfo->c_id, actinfo->act_info.ip46flag, MSG_CMD_LINKUP_END); |
| 778 | return; |
| 779 | } |
| 780 | if(actinfo->act_info.ip46flag & V4_VALID) |
| 781 | defwan4_change = strcmp(defwan_if_old, defwan_real); |
| 782 | if(actinfo->act_info.ip46flag & V6_VALID) |
| 783 | defwan6_change = strcmp(defwan6_if_old, defwan_real); |
| 784 | |
| 785 | //Êý¾ÝÏÈͨ£¬ºó×öÆäËûÅäÖã¬×¢Òâµã: ·À»ðǽ¶Ìʱ¼äÄÚ¿ÉÄÜδÉúЧ |
| 786 | if (defwan4_change && (actinfo->act_info.ip46flag & V4_VALID)) |
| 787 | { |
| 788 | char nat_enable[4] = {0}; |
| 789 | |
| 790 | system_cmd_ex("iptables -P INPUT ACCEPT"); |
| 791 | system_cmd_ex("iptables -P OUTPUT ACCEPT"); |
| 792 | system_cmd_ex("iptables -P FORWARD ACCEPT"); |
| 793 | system_cmd_ex("iptables -t nat -F"); |
| 794 | system_cmd_ex("iptables -t nat -X port_forward"); |
| 795 | system_cmd_ex("iptables -t nat -X DMZ"); |
| 796 | system_cmd_ex("iptables -t nat -X port_mapping"); |
| 797 | system_cmd_ex("iptables -t nat -N port_forward"); |
| 798 | system_cmd_ex("iptables -t nat -N DMZ"); |
| 799 | system_cmd_ex("iptables -t nat -N port_mapping"); |
| 800 | system_cmd_ex("iptables -t nat -I PREROUTING 1 -j port_forward"); |
| 801 | system_cmd_ex("iptables -t nat -I PREROUTING 1 -j DMZ"); |
| 802 | system_cmd_ex("iptables -t nat -I PREROUTING 1 -j port_mapping"); |
| 803 | cfg_get_item("natenable", nat_enable, sizeof(nat_enable)); |
| 804 | |
| 805 | if(strcmp(nat_enable, "0") != 0){ |
| 806 | snprintf(buffer, sizeof(buffer), "iptables -t nat -A POSTROUTING -o %s -j MASQUERADE", defwan_real); |
| 807 | system_cmd_ex(buffer); |
| 808 | } |
| 809 | |
| 810 | net_write_file("/etc/resolv.conf", "", 0); |
| 811 | snprintf(buffer, sizeof(buffer), g_dns_conf, "127.0.0.1"); |
| 812 | net_write_file("/etc/resolv.conf", buffer, strlen(buffer)); |
| 813 | } |
| 814 | if(actinfo->act_info.ip46flag & V6_VALID){ |
| 815 | char dhcp6s_conf[64] = {0}; |
| 816 | char radvd_conf[64] = {0}; |
| 817 | char radvd_pidfile[64] = {0}; |
| 818 | char ndp_log[64] = {0}; |
| 819 | int M_O_flag = 0; |
| 820 | char PdFlag[4] = {0}; |
| 821 | char AdvManagedFlag[4] = {0}; |
| 822 | char AdvOtherConfigFlag[4] = {0}; |
| 823 | struct dhcp6_conf_info dhcp6_info = {0}; |
| 824 | struct radvd_conf_info radvd_info = {0}; |
| 825 | |
| 826 | snprintf(dhcp6s_conf, sizeof(dhcp6s_conf), "%s/dhcp6s_%s.conf", path, defwan_real); |
| 827 | snprintf(radvd_conf, sizeof(radvd_conf), "%s/radvd_%s.conf", path, defwan_real); |
| 828 | snprintf(radvd_pidfile, sizeof(radvd_pidfile), "%s/radvd_%s.pid", path_tmp, defwan_real); |
| 829 | snprintf(ndp_log, sizeof(ndp_log), "%s/ndp_%s.log", path, defwan_real); |
| 830 | |
| 831 | net_write_file("/proc/sys/net/ipv6/conf/all/forwarding", "0", 1); |
| 832 | snprintf(buffer, sizeof(buffer), "ip -6 route add default dev %s", defwan_real); |
| 833 | system_cmd_ex(buffer); |
| 834 | snprintf(buffer, sizeof(buffer), "ip -6 addr add %s/64 dev br0", br_ip6); |
| 835 | system_cmd_ex(buffer); |
| 836 | cfg_set("ipv6_br0_addr", br_ip6); |
| 837 | net_write_file("/proc/sys/net/ipv6/conf/all/forwarding", "1", 1); |
| 838 | net_write_file("/proc/sys/net/ipv6/conf/all/proxy_ndp", "1", 1); |
| 839 | ndp_down(0); |
| 840 | snprintf(buffer, sizeof(buffer), "zte_ndp -a -s br0 -d %s -l %s &", defwan_real, ndp_log); |
| 841 | system_cmd_ex(buffer); |
| 842 | if(actinfo->act_info.ip46flag == V6_VALID){ |
| 843 | cfg_get_item("xlat_enable", xlat_enable, sizeof(xlat_enable)); |
| 844 | if(atoi(xlat_enable) && (default_route_check() == 0)){ |
| 845 | char xlat_prefix[IPV6ADDLEN_MAX] = {0}; |
| 846 | cfg_get_item("xlat_prefix", xlat_prefix, sizeof(xlat_prefix)); |
| 847 | system_cmd_ex("chmod 777 /dev/net/tun"); |
| 848 | if(strlen(xlat_prefix) == 0){ |
| 849 | snprintf(buffer, sizeof(buffer),"clatd -i %s &", defwan_real); |
| 850 | } else { |
| 851 | snprintf(buffer, sizeof(buffer),"clatd -i %s -p %s &", defwan_real, xlat_prefix); |
| 852 | } |
| 853 | system_cmd_ex(buffer); |
| 854 | system_cmd_ex("echo 1 > /proc/sys/net/ipv4/ip_forward"); |
| 855 | snprintf(buffer, sizeof(buffer),"iptables -t nat -A POSTROUTING -o v4-%s -j MASQUERADE", defwan_real); |
| 856 | system_cmd_ex(buffer); |
| 857 | } |
| 858 | } |
| 859 | |
| 860 | //dhcp set |
| 861 | dhcp6s_down(0); |
| 862 | zxic_remove(dhcp6s_conf); |
| 863 | |
| 864 | dhcp6_info.interface = lan_if; |
| 865 | dhcp6_info.link = lan_if; |
| 866 | dhcp6_info.start = dhcp_ip6_start; |
| 867 | dhcp6_info.end= dhcp_ip6_end; |
| 868 | dhcp6_info.prefix= prefix; |
| 869 | dhcp6_info.dns1 = actinfo->act_info.pri_dns6; |
| 870 | dhcp6_info.dns2 = actinfo->act_info.sec_dns6; |
| 871 | dhcp6_info.prefix_len= prefix_len;; |
| 872 | cfg_get_item("dhcpv6statePdEnabled", PdFlag, sizeof(PdFlag)); |
| 873 | cfg_get_item("dhcpv6stateEnabled", AdvManagedFlag, sizeof(AdvManagedFlag)); |
| 874 | cfg_get_item("dhcpv6statelessEnabled", AdvOtherConfigFlag, sizeof(AdvOtherConfigFlag)); |
| 875 | if(atoi(PdFlag) == 1) |
| 876 | M_O_flag = M_O_flag|IPV6_RA_FLAG_PD; |
| 877 | if(atoi(AdvManagedFlag) == 1) |
| 878 | M_O_flag = M_O_flag|IPV6_RA_FLAG_MANAGED; |
| 879 | if(atoi(AdvOtherConfigFlag) == 1) |
| 880 | M_O_flag = M_O_flag|IPV6_RA_FLAG_OTHER_CONFIG; |
| 881 | |
| 882 | memset(buffer, 0, sizeof(buffer)); |
| 883 | snprintf(buffer, sizeof(buffer), "dhcp6s -dDf -c %s %s &", dhcp6s_conf, lan_if); |
| 884 | if(config_dhcp6s(dhcp6s_conf, &dhcp6_info, M_O_flag) < 0) |
| 885 | return; |
| 886 | system_cmd_ex(buffer); |
| 887 | slog(NET_PRINT, SLOG_NORMAL, "start dhcp6s mo=%d:%s\n", M_O_flag, buffer); |
| 888 | |
| 889 | //radvd set |
| 890 | { |
| 891 | char path_tmp[16] = {0}; |
| 892 | char path[32] = {0}; |
| 893 | |
| 894 | cfg_get_item("path_tmp", path_tmp, sizeof(path_tmp)); |
| 895 | snprintf(path, sizeof(path), "%s/radvd_%s.pid", path_tmp, defwan_real); |
| 896 | kill_pid_by_path(path); |
| 897 | } |
| 898 | zxic_remove(radvd_conf); |
| 899 | radvd_info.interface = lan_if; |
| 900 | radvd_info.prefix = br_ip6; |
| 901 | radvd_info.prefix_len = prefix_len; |
| 902 | radvd_info.dns1 = actinfo->act_info.pri_dns6; |
| 903 | radvd_info.dns2 = actinfo->act_info.sec_dns6; |
| 904 | |
| 905 | memset(buffer, 0, sizeof(buffer)); |
| 906 | snprintf(buffer, sizeof(buffer), "radvd -d 3 -C %s -p %s &", radvd_conf, radvd_pidfile); |
| 907 | if(config_radvd(radvd_conf, &radvd_info, M_O_flag) < 0){ |
| 908 | return; |
| 909 | } |
| 910 | zxic_remove(radvd_pidfile); |
| 911 | system_cmd_ex(buffer); |
| 912 | } |
| 913 | system_cmd_ex("killall -9 dnsmasq"); |
| 914 | snprintf(dns_path, sizeof(dns_path), "%s/dnsmasq.conf", path); |
| 915 | net_write_file(dns_path, "", 0); |
| 916 | |
| 917 | if(actinfo->act_info.ip46flag & V4_VALID) { |
| 918 | unsigned int dns1 = 0; |
| 919 | unsigned int dns2 = 0; |
| 920 | unsigned int dns_ext = 0; |
| 921 | char dns1_s[IPV4ADDLEN_MAX] = {0}; |
| 922 | char dns2_s[IPV4ADDLEN_MAX] = {0}; |
| 923 | char ext_dns[IPV4ADDLEN_MAX] = {0}; |
| 924 | |
| 925 | system_cmd_ex("route del default"); |
| 926 | snprintf(buffer, sizeof(buffer),"route add default dev %s", defwan_real); |
| 927 | system_cmd_ex(buffer); |
| 928 | zxic_inet_pton(AF_INET, actinfo->act_info.pri_dns, &dns1); |
| 929 | zxic_inet_pton(AF_INET, actinfo->act_info.sec_dns, &dns2); |
| 930 | if(dns1) |
| 931 | snprintf(dns1_s, sizeof(dns1_s), "%s", actinfo->act_info.pri_dns); |
| 932 | else |
| 933 | snprintf(dns1_s, sizeof(dns1_s), "%s", "114.114.114.114"); |
| 934 | if(dns2) |
| 935 | snprintf(dns2_s, sizeof(dns2_s), "%s", actinfo->act_info.sec_dns); |
| 936 | else |
| 937 | snprintf(dns2_s, sizeof(dns2_s), "%s", "8.8.8.8"); |
| 938 | config_dns(dns_path, dns1_s, dns2_s); |
| 939 | cfg_get_item("dns_extern", ext_dns, sizeof(ext_dns)); |
| 940 | zxic_inet_pton(AF_INET, ext_dns, &dns_ext); |
| 941 | if(dns_ext){ |
| 942 | config_dns(dns_path, NULL, ext_dns); |
| 943 | } |
| 944 | //set ip addr for webui show |
| 945 | cfg_set("wan_ipaddr", actinfo->act_info.ip); |
| 946 | net_write_file("/proc/sys/net/ipv4/ip_forward", "1", 1); |
| 947 | } |
| 948 | if(actinfo->act_info.ip46flag & V6_VALID) { |
| 949 | char ext_dns_v6[IPV6ADDLEN_MAX] = {0}; |
| 950 | struct in6_addr ipv6_dns_ext = {0}; |
| 951 | |
| 952 | config_dns(dns_path, actinfo->act_info.pri_dns6, actinfo->act_info.sec_dns6); |
| 953 | cfg_get_item("ipv6_dns_extern", ext_dns_v6, sizeof(ext_dns_v6)); |
| 954 | if(inet_pton(AF_INET6, pdp_ip6, &ipv6_dns_ext) > 0){ |
| 955 | config_dns(dns_path, NULL, ext_dns_v6); |
| 956 | } |
| 957 | //set ipv6 addr for webui show |
| 958 | cfg_set("ipv6_wan_ipaddr", pdp_ip6); |
| 959 | } |
| 960 | if(atoi(tc_enable)){ |
| 961 | snprintf(buffer, sizeof(buffer),"tc_tbf.sh up %d", actinfo->c_id); |
| 962 | system_cmd_ex(buffer); |
| 963 | } |
| 964 | snprintf(buffer, sizeof(buffer),"dnsmasq -i %s -r %s &", lan_if, dns_path); |
| 965 | system_cmd_ex(buffer); |
| 966 | slog(NET_PRINT, SLOG_NORMAL, "pdp_wan_config_quick defwan_change v4:%d v6:%d \n", defwan4_change, defwan6_change); |
| 967 | |
| 968 | //ȱʡÍâÍø¿Ú·¢Éú±ä»¯ÔòÖØÉènatºÍfilter |
| 969 | if (defwan4_change || defwan6_change) { |
| 970 | zte_router_init(); |
| 971 | if(actinfo->act_info.ip46flag & V4_VALID){ |
| 972 | memset(defwan_if_old, 0, ZTE_ROUTER_WAN_IF_NAME_LEN); |
| 973 | strncpy(defwan_if_old, defwan_real, strlen(defwan_real)); |
| 974 | } |
| 975 | if(actinfo->act_info.ip46flag & V6_VALID){ |
| 976 | memset(defwan6_if_old, 0, ZTE_ROUTER_WAN_IF_NAME_LEN); |
| 977 | strncpy(defwan6_if_old, defwan_real, strlen(defwan_real)); |
| 978 | } |
| 979 | } |
| 980 | zte_unpn_set(); |
| 981 | if(atoi(xlat_enable) && actinfo->act_info.ip46flag == V6_VALID){ |
| 982 | snprintf(buffer, sizeof(buffer),"ip route add default dev v4-%s", defwan_real); |
| 983 | system_cmd_ex(buffer); |
| 984 | } |
| 985 | net_sendmsg_2_atctl(actinfo->c_id, actinfo->act_info.ip46flag, MSG_CMD_LINKUP_END); |
| 986 | } |
| 987 | } |
| 988 | |
| 989 | void check_wan_change(unsigned char ip46flag) |
| 990 | { |
| 991 | if (ip46flag == V4_VALID || ip46flag == V46_VALID) { |
| 992 | char nv_ethwan[ZTE_ROUTER_WAN_IF_NAME_LEN] = {0}; |
| 993 | char nv_wifiwan[ZTE_ROUTER_WAN_IF_NAME_LEN] = {0}; |
| 994 | char ethwan_ip[ZTE_ROUTER_IP_ADDR_LEN] = {0}; |
| 995 | char wifiwan_ip[ZTE_ROUTER_IP_ADDR_LEN] = {0}; |
| 996 | |
| 997 | snprintf(nv_ethwan, sizeof(nv_ethwan), "%s_ip", eth_wan); |
| 998 | cfg_get_item(nv_ethwan, ethwan_ip, sizeof(ethwan_ip)); |
| 999 | snprintf(nv_wifiwan, sizeof(nv_wifiwan), "%s_ip", wifi_wan); |
| 1000 | cfg_get_item(nv_wifiwan, wifiwan_ip, sizeof(wifiwan_ip)); |
| 1001 | if ((0 != strcmp(ethwan_ip, "0.0.0.0") && (0 != strcmp(ethwan_ip, ""))) |
| 1002 | || (0 != strcmp(wifiwan_ip, "0.0.0.0") && (0 != strcmp(wifiwan_ip, "")))) |
| 1003 | proc_wan_change_v4(); |
| 1004 | } |
| 1005 | if (ip46flag == V6_VALID || ip46flag == V46_VALID) { |
| 1006 | char nv_ethwan_ipv6[ZTE_ROUTER_IP_ADDR_LEN] = {0}; |
| 1007 | char nv_wifiwan_ipv6[ZTE_ROUTER_IP_ADDR_LEN] = {0}; |
| 1008 | char ethwan_ipv6[ZTE_ROUTER_IPV6_ADDR_LEN] = {0}; |
| 1009 | char wifiwan_ipv6[ZTE_ROUTER_IPV6_ADDR_LEN] = {0}; |
| 1010 | |
| 1011 | sprintf(nv_ethwan_ipv6, "%s_ipv6_ip", eth_wan); |
| 1012 | cfg_get_item(nv_ethwan_ipv6, ethwan_ipv6, sizeof(ethwan_ipv6)); |
| 1013 | sprintf(nv_wifiwan_ipv6, "%s_ipv6_ip", wifi_wan); |
| 1014 | cfg_get_item(nv_wifiwan_ipv6, wifiwan_ipv6, sizeof(wifiwan_ipv6)); |
| 1015 | if (((0 != strcmp(ethwan_ipv6, "::")) && (0 != strcmp(ethwan_ipv6, ""))) |
| 1016 | || ((0 != strcmp(wifiwan_ipv6, "::")) && (0 != strcmp(wifiwan_ipv6, "")))) |
| 1017 | proc_wan_change_v6(); |
| 1018 | } |
| 1019 | } |
| 1020 | |
| 1021 | void net_wan_deact_quick(int c_id, unsigned char ip46flag) |
| 1022 | { |
| 1023 | char cmd[128] = {0}; |
| 1024 | char wan_name[NV_NAME_LEN] = {0}; |
| 1025 | char default_wan_name[NV_NAME_LEN] = {0}; |
| 1026 | char default_wan6_name[NV_NAME_LEN] = {0}; |
| 1027 | char tc_enable[4] = {0}; |
| 1028 | char wan_pri[32] = {0}; |
| 1029 | char pdp_ip6[IPV6ADDLEN_MAX] = {0}; |
| 1030 | char pdp_ip[IPV4ADDLEN_MAX] = {0}; |
| 1031 | int pri = 0; |
| 1032 | int rt_num = 0; |
| 1033 | |
| 1034 | cfg_get_item("pswan_priority", wan_pri, sizeof(wan_pri)); |
| 1035 | pri = atoi(wan_pri); |
| 1036 | if(pri < 0 || pri > 65535) |
| 1037 | return; |
| 1038 | rt_num = pri*10 + c_id; |
| 1039 | cfg_get_item("tc_enable", tc_enable, sizeof(tc_enable)); |
| 1040 | snprintf(wan_name,NV_NAME_LEN, "%s%d", ps_wan, c_id); |
| 1041 | slog(NET_PRINT, SLOG_NORMAL, "deact ifconfig wanname:%s!\n", wan_name); |
| 1042 | |
| 1043 | //ifconfig wan down |
| 1044 | snprintf(cmd, sizeof(cmd),"ifconfig %s down", wan_name); |
| 1045 | system_cmd_ex(cmd); |
| 1046 | //ifconfig ip |
| 1047 | snprintf(cmd, sizeof(cmd),"ifconfig %s 0.0.0.0 down", wan_name); |
| 1048 | system_cmd_ex(cmd); |
| 1049 | |
| 1050 | cfg_get_item("default_wan_name", default_wan_name, sizeof(default_wan_name)); |
| 1051 | cfg_get_item("default_wan6_name", default_wan6_name, sizeof(default_wan6_name)); |
| 1052 | |
| 1053 | if (ip46flag == V4_VALID || ip46flag == V46_VALID) { |
| 1054 | snprintf(cmd, sizeof(cmd), "%s_ip", wan_name); |
| 1055 | cfg_get_item(cmd, pdp_ip, sizeof(pdp_ip)); |
| 1056 | cfg_set(cmd, ""); |
| 1057 | snprintf(cmd, sizeof(cmd), "%s_gw", wan_name); |
| 1058 | cfg_set(cmd, ""); |
| 1059 | snprintf(cmd, sizeof(cmd), "%s_pridns", wan_name); |
| 1060 | cfg_set(cmd, ""); |
| 1061 | snprintf(cmd, sizeof(cmd), "%s_secdns", wan_name); |
| 1062 | cfg_set(cmd, ""); |
| 1063 | snprintf(cmd, sizeof(cmd), "ip rule del from %s table %d", pdp_ip, rt_num); |
| 1064 | system_cmd_ex(cmd); |
| 1065 | snprintf(cmd, sizeof(cmd), "ip route del default dev %s table %d", wan_name, rt_num); |
| 1066 | system_cmd_ex(cmd); |
| 1067 | if(strcmp(default_wan_name, wan_name) == 0){ |
| 1068 | //net_write_file("/proc/sys/net/ipv4/ip_forward", "0", 1); |
| 1069 | snprintf(cmd, sizeof(cmd),"route del default dev %s", wan_name); |
| 1070 | system_cmd_ex(cmd); |
| 1071 | cfg_set("wan_ipaddr", ""); |
| 1072 | cfg_set("default_cid", ""); |
| 1073 | cfg_set("default_wan_name", ""); |
| 1074 | cfg_set("default_wan_rel", ""); |
| 1075 | } |
| 1076 | } |
| 1077 | if (ip46flag == V6_VALID || ip46flag == V46_VALID) { |
| 1078 | snprintf(cmd, sizeof(cmd), "%s_ipv6_ip", wan_name); |
| 1079 | cfg_get_item(cmd, pdp_ip6, sizeof(pdp_ip6)); |
| 1080 | cfg_set(cmd, ""); |
| 1081 | snprintf(cmd, sizeof(cmd), "%s_ipv6_interface_id", wan_name); |
| 1082 | cfg_set(cmd, ""); |
| 1083 | snprintf(cmd, sizeof(cmd), "%s_ipv6_pridns_auto", wan_name); |
| 1084 | cfg_set(cmd, ""); |
| 1085 | snprintf(cmd, sizeof(cmd), "%s_ipv6_secdns_auto", wan_name); |
| 1086 | cfg_set(cmd, ""); |
| 1087 | snprintf(cmd, sizeof(cmd), "ip -6 rule del from %s table %d", pdp_ip6, rt_num); |
| 1088 | system_cmd_ex(cmd); |
| 1089 | snprintf(cmd, sizeof(cmd), "ip -6 route del default dev %s table %d", wan_name, rt_num); |
| 1090 | system_cmd_ex(cmd); |
| 1091 | if(strcmp(default_wan6_name, wan_name) == 0){ |
| 1092 | char br_ip6[IPV6ADDLEN_MAX] = {0}; |
| 1093 | |
| 1094 | cfg_get_item("ipv6_br0_addr", br_ip6, sizeof(br_ip6)); |
| 1095 | net_write_file("/proc/sys/net/ipv6/conf/all/forwarding", "0", 1); |
| 1096 | net_write_file("/proc/sys/net/ipv6/conf/all/proxy_ndp", "0", 1); |
| 1097 | system_cmd_ex("ip -6 route del default"); |
| 1098 | snprintf(cmd, sizeof(cmd),"ip -6 addr del %s/64 dev br0", br_ip6); |
| 1099 | system_cmd_ex(cmd); |
| 1100 | system_cmd_ex("ip route del default"); |
| 1101 | system_cmd_ex("killall clatd"); |
| 1102 | snprintf(cmd, sizeof(cmd),"iptables -t nat -D POSTROUTING -o v4-%s -j MASQUERADE", wan_name); |
| 1103 | system_cmd_ex(cmd); |
| 1104 | { |
| 1105 | char path_tmp[16] = {0}; |
| 1106 | char path[32] = {0}; |
| 1107 | |
| 1108 | cfg_get_item("path_tmp", path_tmp, sizeof(path_tmp)); |
| 1109 | snprintf(path, sizeof(path), "%s/radvd_%s.pid", path_tmp, wan_name); |
| 1110 | kill_pid_by_path(path); |
| 1111 | } |
| 1112 | dhcp6s_down(0); |
| 1113 | ndp_down(0); |
| 1114 | cfg_set("ipv6_br0_addr", ""); |
| 1115 | cfg_set("ipv6_wan_ipaddr", ""); |
| 1116 | cfg_set("default_cid", ""); |
| 1117 | cfg_set("default_wan6_name", ""); |
| 1118 | cfg_set("default_wan6_rel", ""); |
| 1119 | } |
| 1120 | } |
| 1121 | if(atoi(tc_enable)){ |
| 1122 | snprintf(cmd, sizeof(cmd),"tc_tbf.sh down %d",c_id); |
| 1123 | system_cmd_ex(cmd); |
| 1124 | } |
| 1125 | { |
| 1126 | char cid[20] = {0}; |
| 1127 | cfg_get_item("default_cid", cid, sizeof(cid)); |
| 1128 | if(c_id == atoi(cid)) |
| 1129 | cfg_set("default_cid", ""); |
| 1130 | } |
| 1131 | if(strcmp(default_wan_name, wan_name) == 0 || strcmp(default_wan6_name, wan_name) == 0){ |
| 1132 | net_write_file("/etc/resolv.conf", "", 0); |
| 1133 | check_wan_change(ip46flag); |
| 1134 | } |
| 1135 | } |
| 1136 | /************************************************************************** |
| 1137 | * º¯ÊýÃû³Æ£º pdp_act_proc |
| 1138 | * ¹¦ÄÜÃèÊö£º PSÍøÂçÉ豸¼¤»î½Ó¿Ú |
| 1139 | * ²ÎÊý˵Ã÷£º pdp_active_info(IN):PDP¼¤»îÐÅÏ¢ |
| 1140 | * ·µ »Ø Öµ£º ²Ù×÷³É¹¦·µ»Ø1. |
| 1141 | * ÆäËü˵Ã÷£º atÏà¹ØÓ¦Óýø³Ìµ÷Óã¬Èçatserver¡¢pcserver¡¢VoLTE¡¢²ÊÐŵÈÓ¦Óýø³Ì£» |
| 1142 | * ½Ó¿ÚÄÚ²¿ÊµÏÖ¶ÔÓÚµÄPSÉ豸µÄ¼¤»î¼°ÏàÓ¦µÄÍøÂçÅäÖà |
| 1143 | **************************************************************************/ |
| 1144 | int net_pdp_act_proc(struct pdp_active_info *actinfo) |
| 1145 | { |
| 1146 | char char_cid[10] = {0}; |
| 1147 | char cmd[100] = {0}; |
| 1148 | char need_jilian[NV_NAME_LEN] = {0}; |
| 1149 | char psext_state[NV_NAME_LEN] = {0}; |
| 1150 | char prefix[IPV6ADDLEN_MAX] = {0}; |
| 1151 | int prefix_len = 0; |
| 1152 | char quick_flag[4] = {0}; |
| 1153 | |
| 1154 | cfg_get_item("quick_dial", quick_flag, sizeof(quick_flag)); |
| 1155 | slog(NET_PRINT, SLOG_NORMAL, "net_pdp_act_proc\n"); |
| 1156 | if (!actinfo || actinfo->act_info.ip46flag == V4V6_INVALID) { |
| 1157 | softap_assert("ip46flag error");//klocwork |
| 1158 | return 0; |
| 1159 | } |
| 1160 | |
| 1161 | if (0 == pdp_act_check(actinfo)) { |
| 1162 | softap_assert("already act."); |
| 1163 | } |
| 1164 | set_pdp_mode(actinfo->c_id, actinfo->pdp_type); |
| 1165 | |
| 1166 | set_pdp_act_type(actinfo->c_id, actinfo->act_info.ip46flag); |
| 1167 | |
| 1168 | if (actinfo->act_info.ip46flag == V6_VALID || actinfo->act_info.ip46flag == V46_VALID) { |
| 1169 | prefix_len = syscall(__NR_get_ipv6_prefix,(unsigned char)actinfo->c_id, prefix); |
| 1170 | slog(NET_PRINT, SLOG_NORMAL, "pdp_wan_config prefix=%s len=%d \n", prefix, prefix_len); |
| 1171 | if(prefix_len > 0) |
| 1172 | { |
| 1173 | char nv_name[NV_NAME_LEN] = {0}; |
| 1174 | char len_s[4] = {0}; |
| 1175 | |
| 1176 | snprintf(nv_name, sizeof(nv_name), "%s%d_ipv6_prefix_info", ps_wan, actinfo->c_id); |
| 1177 | cfg_set(nv_name, prefix); |
| 1178 | snprintf(len_s, sizeof(len_s), "%d", prefix_len); |
| 1179 | snprintf(nv_name, sizeof(nv_name), "%s%d_ipv6_prefix_len", ps_wan, actinfo->c_id); |
| 1180 | cfg_set(nv_name, len_s); |
| 1181 | } |
| 1182 | } |
| 1183 | //¶ÔÓÚatserver´¥·¢µÄPDP¼¤»î£¬ÊÇÓÃÓÚÆÕͨÉÏÍâÍøÒµÎñµÄ£¬´æÔÚNATת»» |
| 1184 | if (actinfo->pdp_type == PDP_NORMAL) { |
| 1185 | snprintf(char_cid, sizeof(char_cid), "%d", actinfo->c_id); |
| 1186 | cfg_set("default_cid", char_cid); |
| 1187 | if(quick_flag[0] == '1' && (actinfo->act_info.ip46flag == V4_VALID || prefix_len > 0)) |
| 1188 | pdp_wan_config_quick(actinfo, prefix, prefix_len); |
| 1189 | else |
| 1190 | pdp_wan_config(actinfo); |
| 1191 | //cfg_set("ps_state", "working"); |
| 1192 | } |
| 1193 | //¶ÔÓÚÍâºË´¥·¢µÄPDP¼¤»î£¬½øÐÐÇŽӻò¼¶Áª |
| 1194 | else if (actinfo->pdp_type == PDP_EXT) { |
| 1195 | //cp¼¶Áª£¬apÇÅ½Ó |
| 1196 | if(quick_flag[0] == '1' && (actinfo->act_info.ip46flag == V4_VALID || prefix_len > 0)){ |
| 1197 | pdp_direct_config_quick(actinfo, prefix, prefix_len); |
| 1198 | }else{ |
| 1199 | cfg_get_item("need_jilian", need_jilian, sizeof(need_jilian)); |
| 1200 | if (0 == strcmp(need_jilian, "1")) |
| 1201 | pdp_direct_config(actinfo); |
| 1202 | else if (0 == strcmp(need_jilian, "0")) { |
| 1203 | //sprintf(cmd, "/sbin/psext_updown.sh \"linkup\" \"%d\"", actinfo->c_id); |
| 1204 | sprintf(cmd, "/sbin/psext_updown.sh linkup %d", actinfo->c_id); |
| 1205 | zxic_system(cmd); //kw 3 |
| 1206 | } else |
| 1207 | softap_assert("need_jilian=%s error", need_jilian); |
| 1208 | } |
| 1209 | /*¸ÃÎÊÌâÓÃÓÚUSB ÈȲå°Îʱ״̬±ê¼Ç£¬½öÔÚPDP¼¤»îÖ®ºó£¬ |
| 1210 | ²Å¶ÔÈȲå°ÎÏûÏ¢½øÐд¦Àí*/ |
| 1211 | sprintf(psext_state, "ps_ext%d_pdpstate", actinfo->c_id); |
| 1212 | cfg_set(psext_state, "working"); |
| 1213 | |
| 1214 | } |
| 1215 | //±¾µØÓ¦ÓÃÉÏÍâÍøµÄPDP¼¤»î£¬ÈçVoLTEµÈ |
| 1216 | else if (actinfo->pdp_type == PDP_LOCAL) { |
| 1217 | if(quick_flag[0] == '1' && (actinfo->act_info.ip46flag == V4_VALID || prefix_len > 0)) |
| 1218 | pdp_wan_config_quick(actinfo, prefix, prefix_len); |
| 1219 | else |
| 1220 | pdp_wan_config(actinfo); |
| 1221 | } else if (actinfo->pdp_type == PDP_PPP) { |
| 1222 | //sprintf(char_cid, "%d", actinfo->c_id); |
| 1223 | //cfg_set("ppp_cid", char_cid); |
| 1224 | pdp_ppp_config(actinfo); |
| 1225 | |
| 1226 | cfg_set("ppp_pdpstate", "working"); |
| 1227 | } else { |
| 1228 | softap_assert("pdp_type=%u error", actinfo->pdp_type); |
| 1229 | return 0; |
| 1230 | } |
| 1231 | |
| 1232 | if (actinfo->pdp_type != PDP_NORMAL) |
| 1233 | { |
| 1234 | net_sendmsg_2_atctl(actinfo->c_id, actinfo->act_info.ip46flag, MSG_CMD_LINKUP_END); |
| 1235 | } |
| 1236 | |
| 1237 | system("cat /proc/uptime 1>dev/console 2>&1"); |
| 1238 | slog(NET_PRINT, SLOG_NORMAL, "net_pdp_act_proc success\n"); |
| 1239 | |
| 1240 | return 1; |
| 1241 | } |
| 1242 | |
| 1243 | /************************************************************************** |
| 1244 | * º¯ÊýÃû³Æ£º pdp_deact_proc |
| 1245 | * ¹¦ÄÜÃèÊö£º PSÍøÂçÉ豸ȥ»î½Ó¿Ú |
| 1246 | * ²ÎÊý˵Ã÷£º c_id(IN):PDP¼¤»îc_id. |
| 1247 | * ·µ »Ø Öµ£º ²Ù×÷³É¹¦·µ»Ø1. |
| 1248 | * ÆäËü˵Ã÷£º atÏà¹ØÓ¦Óýø³Ìµ÷Óã¬Èçatserver¡¢pcserver¡¢VoLTE¡¢²ÊÐŵÈÓ¦Óýø³Ì£» |
| 1249 | ½Ó¿ÚÄÚ²¿ÊµÏÖ¶ÔÓÚµÄPSÉ豸ȥ»î£»Ö§³Ö46µ¥Õ»È¥»î£¬ËùÒÔÈë²ÎÐèҪָʾ46Çé¿ö |
| 1250 | **************************************************************************/ |
| 1251 | int net_pdp_deact_proc(int c_id, unsigned char ip46flag) |
| 1252 | { |
| 1253 | char cmd[100] = {0}; |
| 1254 | char pdp_mode_nv[NV_NAME_LEN] = {0}; |
| 1255 | char pdp_mode[NV_NAME_LEN] = {0}; |
| 1256 | char psext_state[NV_NAME_LEN] = {0}; |
| 1257 | //char pppd_user_term[NV_NAME_LEN] = {0}; |
| 1258 | char quick_flag[4] = {0}; |
| 1259 | |
| 1260 | cfg_get_item("quick_dial", quick_flag, sizeof(quick_flag)); |
| 1261 | |
| 1262 | openlog("netapi", LOG_CONS | LOG_PID, LOG_DAEMON); |
| 1263 | |
| 1264 | if (ip46flag == V4V6_INVALID) { |
| 1265 | softap_assert("ip46flag=%u error", ip46flag); |
| 1266 | return 0; |
| 1267 | } |
| 1268 | |
| 1269 | slog(NET_PRINT, SLOG_NORMAL, "zte_mainctrl:net_pdp_deact_proc start!cid=%d,ip46flag=%u\n", c_id, ip46flag); |
| 1270 | |
| 1271 | sprintf(pdp_mode_nv, "pdp_mode%d", c_id); |
| 1272 | cfg_get_item(pdp_mode_nv, pdp_mode, sizeof(pdp_mode)); |
| 1273 | |
| 1274 | reset_pdp_mode(c_id); |
| 1275 | |
| 1276 | closelog(); |
| 1277 | |
| 1278 | //ÍâºËpdpÈ¥»î,È¥ÇÅÈ¥¼¶Áª |
| 1279 | if (0 == strcmp("bridge", pdp_mode)) { |
| 1280 | if(quick_flag[0] == '1'){ |
| 1281 | net_br_deact_quick(c_id, ip46flag); |
| 1282 | }else{ |
| 1283 | if (ip46flag == V4_VALID || ip46flag == V46_VALID) { |
| 1284 | //sprintf(cmd, "/sbin/psext_updown.sh \"linkdown\" \"%d\"", c_id); |
| 1285 | sprintf(cmd, "/sbin/psext_updown.sh linkdown %d", c_id); |
| 1286 | zxic_system(cmd); //kw 3 |
| 1287 | } |
| 1288 | |
| 1289 | if (ip46flag == V6_VALID || ip46flag == V46_VALID) { |
| 1290 | memset(cmd, 0, sizeof(cmd)); |
| 1291 | //sprintf(cmd, "/sbin/psext_updown_ipv6.sh \"linkdown\" \"%d\"", c_id); |
| 1292 | sprintf(cmd, "/sbin/psext_updown_ipv6.sh linkdown %d", c_id); |
| 1293 | zxic_system(cmd); |
| 1294 | } |
| 1295 | } |
| 1296 | sprintf(psext_state, "ps_ext%d_pdpstate", c_id); |
| 1297 | cfg_set(psext_state, "dead"); |
| 1298 | slog(NET_PRINT, SLOG_NORMAL, "zte_mainctrl:net_pdp_deact_proc success!\n"); |
| 1299 | |
| 1300 | net_sendmsg_2_atctl(c_id, ip46flag, MSG_CMD_LINKDOWN_END); |
| 1301 | |
| 1302 | return 1; |
| 1303 | } else if (0 == strcmp("ppp", pdp_mode)) { |
| 1304 | //if (ip46flag == V4_VALID || ip46flag == V46_VALID) { for ipv6 |
| 1305 | #if 0 |
| 1306 | cfg_get_item("pppd_user_term", pppd_user_term, sizeof(pppd_user_term)); //¼ì²â¸ÃpdpÈ¥¼¤»îÊÇ·ñÊÇÓÉÖն˶ϿªpppÁ´½Ó·¢ÆðµÄ |
| 1307 | if (strcmp(pppd_user_term, "terminate") != 0) { |
| 1308 | cfg_set("ppp_pdpstate", "dead"); |
| 1309 | |
| 1310 | } else { |
| 1311 | cfg_set("ppp_pdpstate", "user_terminate"); |
| 1312 | cfg_set("pppd_user_term", ""); |
| 1313 | } |
| 1314 | #endif |
| 1315 | //sprintf(cmd, "/sbin/ppp_updown.sh \"linkdown\" \"%d\"", c_id); |
| 1316 | sprintf(cmd, "/sbin/ppp_updown.sh linkdown %d", c_id); |
| 1317 | zxic_system(cmd); |
| 1318 | cfg_set("ppp_pdpstate", "dead"); |
| 1319 | |
| 1320 | //} |
| 1321 | slog(NET_PRINT, SLOG_NORMAL, "zte_mainctrl:net_pdp_deact_proc success!\n"); |
| 1322 | |
| 1323 | net_sendmsg_2_atctl(c_id, ip46flag, MSG_CMD_LINKDOWN_END); |
| 1324 | return 1; |
| 1325 | } |
| 1326 | //atserver pdpÈ¥»î ½«default_cidÖÃ¿Õ |
| 1327 | else if (0 == strcmp("gateway", pdp_mode)) { |
| 1328 | //cfg_set("default_cid", ""); |
| 1329 | //cfg_set("ps_state", "dead"); |
| 1330 | } |
| 1331 | if(quick_flag[0] == '1'){ |
| 1332 | net_wan_deact_quick(c_id, ip46flag); |
| 1333 | }else{ |
| 1334 | if (ip46flag == V4_VALID || ip46flag == V46_VALID) { |
| 1335 | //sprintf(cmd, "/sbin/wan_ipv4.sh \"linkdown\" \"pswan\" \"%d\"", c_id); |
| 1336 | sprintf(cmd, "/sbin/wan_ipv4.sh linkdown pswan %d", c_id); |
| 1337 | zxic_system(cmd); |
| 1338 | } |
| 1339 | |
| 1340 | if (ip46flag == V6_VALID || ip46flag == V46_VALID) { |
| 1341 | memset(cmd, 0, sizeof(cmd)); |
| 1342 | //sprintf(cmd, "/sbin/wan_ipv6.sh \"linkdown\" \"pswan\" \"%d\"", c_id); |
| 1343 | sprintf(cmd, "/sbin/wan_ipv6.sh linkdown pswan %d", c_id); |
| 1344 | zxic_system(cmd); |
| 1345 | } |
| 1346 | } |
| 1347 | slog(NET_PRINT, SLOG_NORMAL, "zte_mainctrl:net_pdp_deact_proc success!\n"); |
| 1348 | |
| 1349 | net_sendmsg_2_atctl(c_id, ip46flag, MSG_CMD_LINKDOWN_END); |
| 1350 | return 1; |
| 1351 | } |
| 1352 | |
| 1353 | |
| 1354 | /************************************************************************** |
| 1355 | * º¯ÊýÃû³Æ£º netdev_connect_internet |
| 1356 | * ¹¦ÄÜÃèÊö£º webui·¢Ë͵ÄÁ¬½ÓÇëÇó,½Ó¿ÚÄÚ²¿½øÐÐifconfig up£¬²¢Æô¶¯ÏàÓ¦µÄµØÖ··ÖÅä½ø³Ì |
| 1357 | * ²ÎÊý˵Ã÷£º netdev_id£ºÍøÂçÉ豸¶ÔÓ¦µÄºêÃû£¬²Î¼ûUSB_NET_DEVµÈºêÖµ |
| 1358 | * ·µ »Ø Öµ£º ²Ù×÷³É¹¦·µ»Ø1. |
| 1359 | * ÆäËü˵Ã÷£º É豸Ö÷¿ØÄ£¿éµ÷Óô˽ӿÚǰ£¬ÐèÒª¼ì²âµ±Ç°É豸ÎïÀíͨ·ÒÑͨ£¬·ñÔò²»Ó¦¸Ãµ÷Óô˽ӿڣ» |
| 1360 | * Ö÷¿ØÄ£¿éÐèÒªÑÏ¿ØÖظ´µÄµ÷Óøýӿڣ¬ÒòΪÿµ÷ÓÃÒ»´Î¸Ã½Ó¿Ú£¬ÄÚ²¿½Ô»áÖØÐÂÖ´ÐÐÒ»´ÎÍêÕûµÄµØÖ··ÖÅäÁ÷³Ì£» |
| 1361 | **************************************************************************/ |
| 1362 | int net_netdev_connect_internet(unsigned char netdev_id) |
| 1363 | { |
| 1364 | char eth_type[NV_NAME_LEN] = {0}; |
| 1365 | char work_state[NV_NAME_LEN] = {0}; |
| 1366 | char eth_dev[NV_NAME_LEN] = {0}; |
| 1367 | char sw_name[NV_NAME_LEN] = {0}; |
| 1368 | char swport[NV_NAME_LEN] = {0}; |
| 1369 | char cmd[100] = {0}; |
| 1370 | |
| 1371 | slog(NET_PRINT, SLOG_NORMAL, "zte_mainctrl:net_netdev_connect_internet start! netdev_id=%u\n", netdev_id); |
| 1372 | if (netdev_id == RJ45_WAN_DEV) { |
| 1373 | ethwan_id = netdev_id; |
| 1374 | pppoe_encrypt_code(); |
| 1375 | eth_connect(); |
| 1376 | } else if (netdev_id == WIFI_WAN_DEV) { |
| 1377 | wifiwan_id = netdev_id; |
| 1378 | wifi_connect(); |
| 1379 | } else if (netdev_id == RJ45_LAN_DEV) { |
| 1380 | system("landev_updown.sh \"ethlan\" \"up\""); |
| 1381 | slog(NET_PRINT, SLOG_NORMAL, "rj45 as lan connect end!\n"); |
| 1382 | } else if (netdev_id == WIFI_LAN_DEV) { |
| 1383 | system("landev_updown.sh \"wifilan\" \"up\""); |
| 1384 | slog(NET_PRINT, SLOG_NORMAL, "wifi as lan connect end!\n"); |
| 1385 | } else { |
| 1386 | softap_assert("netdev_id=%d error", netdev_id); |
| 1387 | return 0; |
| 1388 | } |
| 1389 | slog(NET_PRINT, SLOG_NORMAL, "zte_mainctrl:net_netdev_connect_internet success!\n"); |
| 1390 | closelog(); |
| 1391 | return 1; |
| 1392 | } |
| 1393 | |
| 1394 | /************************************************************************** |
| 1395 | * º¯ÊýÃû³Æ£º netdev_disconnect_internet |
| 1396 | * ¹¦ÄÜÃèÊö£º webui·¢Ë͵ĶϿªÁ¬½ÓÇëÇó,½Ó¿ÚÄÚ²¿½øÐÐifconfig down£¬²¢É±µôÏàÓ¦µÄµØÖ··ÖÅä½ø³Ì |
| 1397 | * ²ÎÊý˵Ã÷£º netdev_id£ºÍøÂçÉ豸¶ÔÓ¦µÄºêÃû£¬²Î¼ûUSB_NET_DEVµÈºêÖµ |
| 1398 | * ·µ »Ø Öµ£º ²Ù×÷³É¹¦·µ»Ø1. |
| 1399 | * ÆäËü˵Ã÷£º É豸Ö÷¿ØÄ£¿éµ÷ÓÃ´Ë½Ó¿Ú |
| 1400 | **************************************************************************/ |
| 1401 | int net_netdev_disconnect_internet(unsigned char netdev_id) |
| 1402 | { |
| 1403 | char eth_curtype[NV_NAME_LEN] = {0}; |
| 1404 | char eth_dev[NV_NAME_LEN] = {0}; |
| 1405 | char cmd[100] = {0}; |
| 1406 | char wbwanv6_enable[NV_NAME_LEN] = {0}; |
| 1407 | cfg_get_item("wbwanv6_enable", wbwanv6_enable, sizeof(wbwanv6_enable)); |
| 1408 | openlog("netapi", LOG_CONS | LOG_PID, LOG_DAEMON); |
| 1409 | slog(NET_PRINT, SLOG_NORMAL, "zte_mainctrl:net_netdev_disconnect_internet start! netdev_id=%u\n", netdev_id); |
| 1410 | if (netdev_id == RJ45_WAN_DEV) { |
| 1411 | ethwan_id = netdev_id; |
| 1412 | //msg_timedel(); |
| 1413 | deletetimer(ethwan_id); |
| 1414 | slog(NET_PRINT, SLOG_NORMAL, "diconnect ..... deletetimer....."); |
| 1415 | cfg_get_item("eth_curtype", eth_curtype, sizeof(eth_curtype)); |
| 1416 | if (0 == strcmp(eth_curtype, "wan")) |
| 1417 | { |
| 1418 | system("wan_ipv4.sh \"linkdown\" \"ethwan\""); |
| 1419 | if(atoi(wbwanv6_enable) == 1) |
| 1420 | system("wan_ipv6.sh \"linkdown\" \"ethwan\""); |
| 1421 | } |
| 1422 | else if (0 == strcmp(eth_curtype, "lan")) { |
| 1423 | system("landev_updown.sh \"ethwan\" \"down\""); |
| 1424 | slog(NET_PRINT, SLOG_NORMAL, "rj45 as lan disconnect end!\n"); |
| 1425 | } else { //Ϊ·ÀÖ¹eth_curtypeÅжϳö´íËù×öµÄ¼æÈÝ |
| 1426 | system("wan_ipv4.sh \"linkdown\" \"ethwan\""); |
| 1427 | if(atoi(wbwanv6_enable) == 1) |
| 1428 | system("wan_ipv6.sh \"linkdown\" \"ethwan\""); |
| 1429 | system("landev_updown.sh \"ethwan\" \"down\""); |
| 1430 | } |
| 1431 | vlan_config(RJ45_WAN_DEV, "rem"); |
| 1432 | cfg_set("rj45_state", "idle"); |
| 1433 | } else if (netdev_id == WIFI_WAN_DEV) { |
| 1434 | wifiwan_id = netdev_id; |
| 1435 | deletetimer(wifiwan_id); |
| 1436 | system("wan_ipv4.sh \"linkdown\" \"wifiwan\""); |
| 1437 | if(atoi(wbwanv6_enable) == 1) |
| 1438 | system("wan_ipv6.sh \"linkdown\" \"wifiwan\""); |
| 1439 | cfg_set("wifi_state", "idle"); |
| 1440 | } else if (netdev_id == RJ45_LAN_DEV) { |
| 1441 | system("landev_updown.sh \"ethlan\" \"down\""); |
| 1442 | slog(NET_PRINT, SLOG_NORMAL, "rj45 as lan disconnect end!\n"); |
| 1443 | } else if (netdev_id == WIFI_LAN_DEV) { |
| 1444 | system("landev_updown.sh \"wifilan\" \"down\""); |
| 1445 | slog(NET_PRINT, SLOG_NORMAL, "wifi as lan disconnect end!\n"); |
| 1446 | } else { |
| 1447 | softap_assert("netdev_id=%d error", netdev_id); |
| 1448 | return 0; |
| 1449 | } |
| 1450 | slog(NET_PRINT, SLOG_NORMAL, "zte_mainctrl:net_netdev_disconnect_internet success!\n"); |
| 1451 | closelog(); |
| 1452 | return 1; |
| 1453 | } |
| 1454 | |
| 1455 | /************************************************************************** |
| 1456 | * º¯ÊýÃû³Æ£º netdev_plugin_proc |
| 1457 | * ¹¦ÄÜÃèÊö£º ÈȲå°ÎÉ豸²åÈë,½Ó¿ÚÄÚ²¿¼ì²âÊÇ·ñÐèÒª½øÐÐ×Ô¶¯²¦ºÅ£¬ÈçÐèÒª£¬Ö´ÐеØÖ··ÖÅä¡¢×éÍøµÈÁ÷³Ì |
| 1458 | * ²ÎÊý˵Ã÷£º netdev_id£ºÍøÂçÉ豸¶ÔÓ¦µÄºêÃû£¬²Î¼ûUSB_NET_DEVµÈºêÖµ |
| 1459 | * ·µ »Ø Öµ£º ²Ù×÷³É¹¦·µ»Ø1. |
| 1460 | * ÆäËü˵Ã÷£º É豸Ö÷¿Øµ÷Óô˽ӿÚʱ£¬±íÃ÷¸ÃÍøÂçÉ豸ÎïÀíͨ·ÒÑͨ£¬¿ÉÒÔ½øÐÐIPÊý¾Ý°üµÄÊÕ·¢ÁË |
| 1461 | **************************************************************************/ |
| 1462 | int net_netdev_plugin_proc(unsigned char netdev_id) |
| 1463 | { |
| 1464 | |
| 1465 | slog(NET_PRINT, SLOG_NORMAL, "zte_mainctrl:net_netdev_plugin_proc start! netdev_id=%u\n", netdev_id); |
| 1466 | openlog("netapi", LOG_CONS | LOG_PID, LOG_DAEMON); |
| 1467 | //USB½ö´æÔÚÓÚÄÚÍøÖÐ |
| 1468 | if (netdev_id == USB_LAN_DEV) { |
| 1469 | system("landev_updown.sh \"usblan\" \"up\""); |
| 1470 | slog(NET_PRINT, SLOG_ERR, "usb as lan plugin end!\n"); |
| 1471 | } |
| 1472 | //ÈȲå°Î½öÐ迼ÂÇ×Ô¶¯Ä£Ê½£¬²»Ð迼ÂÇÊÖ¹¤²¦ºÅµÄÁ¬½Ó |
| 1473 | //¸Ã·Ö֧ͬʱ´¦ÀíÁËlan/wan/autoÈýÖÖÇé¿ö£¬RJ45_LAN_DEVÔÝʱÎÞ·¨Ê¹Óà |
| 1474 | else if (netdev_id == RJ45_WAN_DEV || netdev_id == SW_WAN_DEV) { |
| 1475 | ethwan_id = netdev_id; |
| 1476 | ethwan_plugin(); |
| 1477 | } else if (netdev_id == WIFI_WAN_DEV) { |
| 1478 | wifiwan_id = netdev_id; |
| 1479 | wifi_plugin(); |
| 1480 | } else if (netdev_id == RJ45_LAN_DEV || netdev_id == SW_LAN_DEV) { |
| 1481 | ethlan_plugin(); |
| 1482 | } else if (netdev_id == WIFI_LAN_DEV) { |
| 1483 | system("landev_updown.sh \"wifilan\" \"up\""); |
| 1484 | slog(NET_PRINT, SLOG_NORMAL, "wifi as lan plugin end!\n"); |
| 1485 | } else if (netdev_id == PS_EXT_DEV1) { |
| 1486 | system("landev_updown.sh \"ps_ext1\" \"up\""); |
| 1487 | } else if (netdev_id == PS_EXT_DEV2) { |
| 1488 | system("landev_updown.sh \"ps_ext2\" \"up\""); |
| 1489 | } else if (netdev_id == PS_EXT_DEV3) { |
| 1490 | system("landev_updown.sh \"ps_ext3\" \"up\""); |
| 1491 | } else if (netdev_id == PS_EXT_DEV4) { |
| 1492 | system("landev_updown.sh \"ps_ext4\" \"up\""); |
| 1493 | } else if (netdev_id == PS_EXT_DEV5) { |
| 1494 | system("landev_updown.sh \"ps_ext5\" \"up\""); |
| 1495 | } else if (netdev_id == PS_EXT_DEV6) { |
| 1496 | system("landev_updown.sh \"ps_ext6\" \"up\""); |
| 1497 | } else if (netdev_id == PS_EXT_DEV7) { |
| 1498 | system("landev_updown.sh \"ps_ext7\" \"up\""); |
| 1499 | } else if (netdev_id == PS_EXT_DEV8) { |
| 1500 | system("landev_updown.sh \"ps_ext8\" \"up\""); |
| 1501 | } else |
| 1502 | slog(NET_PRINT, SLOG_NORMAL, "plugin netdev_id error!!! : netdev_id=%u\n", netdev_id); |
| 1503 | //assert(0); |
| 1504 | slog(NET_PRINT, SLOG_NORMAL, "zte_mainctrl:net_netdev_plugin_proc success!\n"); |
| 1505 | closelog(); |
| 1506 | return 1; |
| 1507 | } |
| 1508 | |
| 1509 | /************************************************************************** |
| 1510 | * º¯ÊýÃû³Æ£º netdev_plugout_proc |
| 1511 | * ¹¦ÄÜÃèÊö£º ÈȲå°ÎÉ豸°Î³ö,½Ó¿ÚÄÚ²¿½øÐÐifconfig down£¬²¢É±µôÏàÓ¦µÄµØÖ··ÖÅä½ø³Ì |
| 1512 | * ²ÎÊý˵Ã÷£º netdev_id£ºÍøÂçÉ豸¶ÔÓ¦µÄºêÃû£¬²Î¼ûUSB_NET_DEVµÈºêÖµ |
| 1513 | * ·µ »Ø Öµ£º ²Ù×÷³É¹¦·µ»Ø1. |
| 1514 | * ÆäËü˵Ã÷£º É豸Ö÷¿Øµ÷Óô˽ӿÚʱ£¬±íÃ÷¸ÃÍøÂçÉ豸ÎïÀíͨ·ÒѶϣ¬²»ÒªÔÙ½øÐÐIPÊý¾Ý°üÊÕ·¢ |
| 1515 | **************************************************************************/ |
| 1516 | int net_netdev_plugout_proc(unsigned char netdev_id) |
| 1517 | { |
| 1518 | char eth_curtype[NV_NAME_LEN] = {0}; |
| 1519 | char cmd[100] = {0}; |
| 1520 | char wbwanv6_enable[NV_NAME_LEN] = {0}; |
| 1521 | cfg_get_item("wbwanv6_enable", wbwanv6_enable, sizeof(wbwanv6_enable)); |
| 1522 | openlog("netapi", LOG_CONS | LOG_PID, LOG_DAEMON); |
| 1523 | slog(NET_PRINT, SLOG_NORMAL, "zte_mainctrl:net_netdev_plugout_proc start! netdev_id=%u\n", netdev_id); |
| 1524 | //ÄÚÍøÇŵãÈ¥³ý |
| 1525 | if (netdev_id == USB_LAN_DEV) { |
| 1526 | system("landev_updown.sh \"usblan\" \"down\""); |
| 1527 | slog(NET_PRINT, SLOG_NORMAL, "usb as lan plugout end!\n"); |
| 1528 | return 1; |
| 1529 | } |
| 1530 | //Ðè񻂿·ÖÄÚÍâÍøÄ£Ê½ |
| 1531 | else if (netdev_id == RJ45_WAN_DEV || netdev_id == SW_WAN_DEV) { |
| 1532 | ethwan_id = netdev_id; |
| 1533 | ethwan_plugout(); |
| 1534 | } else if (netdev_id == WIFI_WAN_DEV) { |
| 1535 | wifiwan_id = netdev_id; |
| 1536 | deletetimer(wifiwan_id); |
| 1537 | system("wan_ipv4.sh \"linkdown\" \"wifiwan\""); |
| 1538 | if(atoi(wbwanv6_enable) == 1) |
| 1539 | system("wan_ipv6.sh \"linkdown\" \"wifiwan\""); |
| 1540 | cfg_set("wifi_state", "dead"); |
| 1541 | |
| 1542 | } else if (netdev_id == RJ45_LAN_DEV || netdev_id == SW_LAN_DEV) { |
| 1543 | ethlan_plugout(); |
| 1544 | } else if (netdev_id == WIFI_LAN_DEV) { |
| 1545 | system("landev_updown.sh \"wifilan\" \"down\""); |
| 1546 | slog(NET_PRINT, SLOG_NORMAL, "wifi as lan plugout end!\n"); |
| 1547 | } else if (netdev_id == PS_EXT_DEV1) { |
| 1548 | system("landev_updown.sh \"ps_ext1\" \"down\""); |
| 1549 | } else if (netdev_id == PS_EXT_DEV2) { |
| 1550 | system("landev_updown.sh \"ps_ext2\" \"down\""); |
| 1551 | } else if (netdev_id == PS_EXT_DEV3) { |
| 1552 | system("landev_updown.sh \"ps_ext3\" \"down\""); |
| 1553 | } else if (netdev_id == PS_EXT_DEV4) { |
| 1554 | system("landev_updown.sh \"ps_ext4\" \"down\""); |
| 1555 | } else if (netdev_id == PS_EXT_DEV5) { |
| 1556 | system("landev_updown.sh \"ps_ext5\" \"down\""); |
| 1557 | } else if (netdev_id == PS_EXT_DEV6) { |
| 1558 | system("landev_updown.sh \"ps_ext6\" \"down\""); |
| 1559 | } else if (netdev_id == PS_EXT_DEV7) { |
| 1560 | system("landev_updown.sh \"ps_ext7\" \"down\""); |
| 1561 | } else if (netdev_id == PS_EXT_DEV8) { |
| 1562 | system("landev_updown.sh \"ps_ext8\" \"down\""); |
| 1563 | } else { |
| 1564 | slog(NET_PRINT, SLOG_ERR, "plugout netdev_id error!!! : netdev_id=%u\n", netdev_id); |
| 1565 | //assert(0); |
| 1566 | return 0; |
| 1567 | } |
| 1568 | //wifi ifconfig downÓÉÆäÄ£¿é¸ºÔð£¬rj45 °Î³ýÉ豸Ïûʧ£¬ÓÉÇý¶¯¸ºÔð |
| 1569 | //memset(cmd, 0, sizeof(cmd)); |
| 1570 | //sprintf(cmd, "ifconfig %s down" , wan_if); |
| 1571 | //system(cmd); |
| 1572 | slog(NET_PRINT, SLOG_NORMAL, "zte_mainctrl:net_netdev_plugout_proc success!\n"); |
| 1573 | closelog(); |
| 1574 | return 1; |
| 1575 | } |
| 1576 | |
| 1577 | /************************************************************************** |
| 1578 | * º¯ÊýÃû³Æ£º net_tc_control |
| 1579 | * ¹¦ÄÜÃèÊö£º Á÷Á¿¿ØÖÆ |
| 1580 | * ²ÎÊý˵Ã÷£º ÐèÒªÁ÷Á¿¼à¿ØµÄÉÏÏÂÐÐÁ¿£¬Êý¾Ý¿¨ÐèÒªÓÐcid£¬ufiģʽ²»ÐèÒª |
| 1581 | * 0±íʾ²»ÐèÒªÁ÷¿Ø |
| 1582 | * ·µ »Ø Öµ£º ²Ù×÷³É¹¦·µ»Ø1. |
| 1583 | * ÆäËü˵Ã÷£º ¸øÐèÒªÁ÷Á¿¿ØÖƵÄÓ¦Óõ÷Óã¬ÈçÉÏÐÐÐèÒªÁ÷¿Ø£¬ÇëµÈÄÜÉÏÍâÍøºóÔÙµ÷Ó㬷ñÔòÎÞ·¨»ñÈ¡ÍâÍø¿Ú½øÐÐÁ÷¿Ø |
| 1584 | **************************************************************************/ |
| 1585 | int net_tc_control(struct tc_control_info *tcinfo, int src_id) |
| 1586 | { |
| 1587 | int ret = 0; |
| 1588 | char cmd[100] = {0}; |
| 1589 | char up[NV_NAME_LEN] = {0}; |
| 1590 | char down[NV_NAME_LEN] = {0}; |
| 1591 | char at_str[32] = {0}; |
| 1592 | |
| 1593 | slog(NET_PRINT, SLOG_NORMAL, "zte_mainctrl:net_tc_control start! c_id:%d, down:%u, up:%u\n \n", tcinfo->c_id, tcinfo->tc_downlink, tcinfo->tc_uplink); |
| 1594 | |
| 1595 | cfg_set("tc_enable", "1"); |
| 1596 | |
| 1597 | /* Á÷Á¿Í³¼ÆÊÇÕë¶ÔByte£¬ËùÒÔÒª³ýÒÔ8 */ |
| 1598 | sprintf(up, "%d", (tcinfo->tc_uplink / 8)); |
| 1599 | cfg_set("tc_uplink", up); |
| 1600 | sprintf(down, "%d", (tcinfo->tc_downlink) / 8); |
| 1601 | cfg_set("tc_downlink", down); |
| 1602 | |
| 1603 | //sprintf(cmd, "/sbin/tc_tbf.sh \"up\" \"%d\"", tcinfo->c_id); |
| 1604 | sprintf(cmd, "/sbin/tc_tbf.sh up %d", tcinfo->c_id); |
| 1605 | zxic_system(cmd); |
| 1606 | |
| 1607 | if(src_id == MODULE_ID_AT_CTL) |
| 1608 | { |
| 1609 | sprintf(at_str, "\r\nOK\r\n"); |
| 1610 | send_rsp_str_to_farps(MODULE_ID_MAIN_CTRL, at_str, strlen(at_str)); |
| 1611 | } |
| 1612 | |
| 1613 | return 1; |
| 1614 | } |
| 1615 | |
| 1616 | /*PPPÐÎ̬µÄPDP¼¤»î£¬ÔÝʱ½öÖ§³ÖIPV4*/ |
| 1617 | int pdp_ppp_config(struct pdp_active_info *actinfo) |
| 1618 | { |
| 1619 | |
| 1620 | char nv_ip[NV_NAME_LEN] = {0}; |
| 1621 | char nv_gw[NV_NAME_LEN] = {0}; |
| 1622 | char nv_pridns[NV_NAME_LEN] = {0}; |
| 1623 | char nv_secdns[NV_NAME_LEN] = {0}; |
| 1624 | char nv_ip6[NV_NAME_LEN] = {0}; |
| 1625 | char nv_pridns6[NV_NAME_LEN] = {0}; |
| 1626 | char nv_secdns6[NV_NAME_LEN] = {0}; |
| 1627 | char cmd[100] = {0}; |
| 1628 | |
| 1629 | if (actinfo->act_info.ip46flag == V4_VALID || actinfo->act_info.ip46flag == V46_VALID) { |
| 1630 | snprintf(nv_ip, sizeof(nv_ip), "%s%d_ip", ps_wan, actinfo->c_id); |
| 1631 | cfg_set(nv_ip, actinfo->act_info.ip); |
| 1632 | snprintf(nv_gw, sizeof(nv_gw), "%s%d_gw", ps_wan, actinfo->c_id); |
| 1633 | cfg_set(nv_gw, actinfo->act_info.ip); |
| 1634 | snprintf(nv_pridns, sizeof(nv_pridns), "%s%d_pridns", ps_wan, actinfo->c_id); |
| 1635 | cfg_set(nv_pridns, actinfo->act_info.pri_dns); |
| 1636 | snprintf(nv_secdns, sizeof(nv_secdns), "%s%d_secdns", ps_wan, actinfo->c_id); |
| 1637 | cfg_set(nv_secdns, actinfo->act_info.sec_dns); |
| 1638 | |
| 1639 | //sprintf(cmd, "/sbin/ppp_updown.sh \"linkup\" \"%d\"", actinfo->c_id); |
| 1640 | //sprintf(cmd, "/sbin/ppp_updown.sh linkup %d", actinfo->c_id); |
| 1641 | //zxic_system(cmd); |
| 1642 | } //else |
| 1643 | //softap_assert("ip46flag=%u error", actinfo->act_info.ip46flag); |
| 1644 | if (actinfo->act_info.ip46flag == V6_VALID || actinfo->act_info.ip46flag == V46_VALID) { |
| 1645 | snprintf(nv_ip6, sizeof(nv_ip6), "%s%d_pppv6_ip", ps_wan, actinfo->c_id); |
| 1646 | cfg_set(nv_ip6, actinfo->act_info.ip6); |
| 1647 | snprintf(nv_ip6, sizeof(nv_ip6), "%s%d_ipv6_interface_id", ps_wan, actinfo->c_id); |
| 1648 | save_interface_id(nv_ip6, actinfo->act_info.ip6); |
| 1649 | snprintf(nv_pridns6, sizeof(nv_pridns6), "%s%d_ipv6_pridns_auto", ps_wan, actinfo->c_id); |
| 1650 | cfg_set(nv_pridns6, actinfo->act_info.pri_dns6); |
| 1651 | snprintf(nv_secdns6, sizeof(nv_secdns6), "%s%d_ipv6_secdns_auto", ps_wan, actinfo->c_id); |
| 1652 | cfg_set(nv_secdns6, actinfo->act_info.sec_dns6); |
| 1653 | } |
| 1654 | sprintf(cmd, "/sbin/ppp_updown.sh linkup %d", actinfo->c_id); |
| 1655 | zxic_system(cmd); |
| 1656 | return 1; |
| 1657 | } |
| 1658 | |
| 1659 | /*NORMALÐÎ̬µÄPDP¼¤»îµÄ˫ջµØÖ·±£´æ£¬²¢´¥·¢ÍâÍø¿ÚµØÖ·ÅäÖýű¾*/ |
| 1660 | int pdp_wan_config(struct pdp_active_info *actinfo) |
| 1661 | { |
| 1662 | char nv_ip[NV_NAME_LEN] = {0}; |
| 1663 | char nv_gw[NV_NAME_LEN] = {0}; |
| 1664 | char nv_pridns[NV_NAME_LEN] = {0}; |
| 1665 | char nv_secdns[NV_NAME_LEN] = {0}; |
| 1666 | char nv_ip6[NV_NAME_LEN] = {0}; |
| 1667 | //char nv_gw6[NV_NAME_LEN] = {0}; |
| 1668 | char nv_pridns6[NV_NAME_LEN] = {0}; |
| 1669 | char nv_secdns6[NV_NAME_LEN] = {0}; |
| 1670 | char cmd[100] = {0}; |
| 1671 | FILE *fpv4 = NULL; |
| 1672 | FILE *fpv6 = NULL; |
| 1673 | |
| 1674 | if (actinfo->act_info.ip46flag == V4_VALID || actinfo->act_info.ip46flag == V46_VALID) { |
| 1675 | snprintf(nv_ip, sizeof(nv_ip), "%s%d_ip", ps_wan, actinfo->c_id); |
| 1676 | cfg_set(nv_ip, actinfo->act_info.ip); |
| 1677 | snprintf(nv_gw, sizeof(nv_gw), "%s%d_gw", ps_wan, actinfo->c_id); |
| 1678 | cfg_set(nv_gw, actinfo->act_info.ip); |
| 1679 | snprintf(nv_pridns, sizeof(nv_pridns), "%s%d_pridns", ps_wan, actinfo->c_id); |
| 1680 | cfg_set(nv_pridns, actinfo->act_info.pri_dns); |
| 1681 | snprintf(nv_secdns, sizeof(nv_secdns), "%s%d_secdns", ps_wan, actinfo->c_id); |
| 1682 | cfg_set(nv_secdns, actinfo->act_info.sec_dns); |
| 1683 | |
| 1684 | //sprintf(cmd, "/sbin/wan_ipv4.sh \"linkup\" \"pswan\" \"%d\"", actinfo->c_id); |
| 1685 | sprintf(cmd, "/sbin/wan_ipv4.sh linkup pswan %d", actinfo->c_id); |
| 1686 | //zxic_system(cmd); |
| 1687 | fpv4 = popen(cmd, "r"); |
| 1688 | } |
| 1689 | |
| 1690 | if (actinfo->act_info.ip46flag == V6_VALID || actinfo->act_info.ip46flag == V46_VALID) { |
| 1691 | snprintf(nv_ip6, sizeof(nv_ip6), "%s%d_ipv6_interface_id", ps_wan, actinfo->c_id); |
| 1692 | //cfg_set(nv_ip6, actinfo->act_info.ip6); |
| 1693 | save_interface_id(nv_ip6, actinfo->act_info.ip6); |
| 1694 | //snprintf(nv_gw6, sizeof(nv_gw6), "%s%d_ipv6_gw", nv_pswan, actinfo->c_id); |
| 1695 | //cfg_set(nv_gw6, actinfo->act_info.gateway6); |
| 1696 | snprintf(nv_pridns6, sizeof(nv_pridns6), "%s%d_ipv6_pridns_auto", ps_wan, actinfo->c_id); |
| 1697 | cfg_set(nv_pridns6, actinfo->act_info.pri_dns6); |
| 1698 | snprintf(nv_secdns6, sizeof(nv_secdns6), "%s%d_ipv6_secdns_auto", ps_wan, actinfo->c_id); |
| 1699 | cfg_set(nv_secdns6, actinfo->act_info.sec_dns6); |
| 1700 | memset(cmd, 0, sizeof(cmd)); |
| 1701 | //sprintf(cmd, "/sbin/wan_ipv6.sh \"linkup\" \"pswan\" \"%d\"", actinfo->c_id); |
| 1702 | sprintf(cmd, "/sbin/wan_ipv6.sh linkup pswan %d", actinfo->c_id); |
| 1703 | //zxic_system(cmd); |
| 1704 | fpv6 = popen(cmd, "r"); |
| 1705 | } |
| 1706 | if(fpv4 != NULL) |
| 1707 | pclose(fpv4); |
| 1708 | if(fpv6 != NULL) |
| 1709 | pclose(fpv6); |
| 1710 | return 1; |
| 1711 | } |
| 1712 | |
| 1713 | /*ÇŽÓÀà×éÍøÅäÖã¬CP²àÓÉÓÚPS²»ÊDZê×¢µÄlinuxÒÔÌ«Íø¿ÚÐÎ̬£¬ËùÒÔÐèÒª½øÐж¨ÖÆÂ·ÓÉ£¬ÒÔʵÏÖÍø¿Ú¹ØÁª£»AP²àÖ±½Óbr0¼´¿É*/ |
| 1714 | int pdp_direct_config(struct pdp_active_info *actinfo) |
| 1715 | { |
| 1716 | char nv_ip[NV_NAME_LEN] = {0}; |
| 1717 | char nv_gw[NV_NAME_LEN] = {0}; |
| 1718 | char nv_pridns[NV_NAME_LEN] = {0}; |
| 1719 | char nv_secdns[NV_NAME_LEN] = {0}; |
| 1720 | char nv_pridns6[NV_NAME_LEN] = {0}; |
| 1721 | char nv_secdns6[NV_NAME_LEN] = {0}; |
| 1722 | char nv_ip6[NV_NAME_LEN] = {0}; |
| 1723 | //char nv_gw6[NV_NAME_LEN] = {0}; |
| 1724 | char cmd[100] = {0}; |
| 1725 | FILE *fpv4 = NULL; |
| 1726 | FILE *fpv6 = NULL; |
| 1727 | |
| 1728 | system("rm /etc_rw/resolv.conf"); |
| 1729 | |
| 1730 | if (actinfo->act_info.ip46flag == V4_VALID || actinfo->act_info.ip46flag == V46_VALID) { |
| 1731 | snprintf(nv_ip, sizeof(nv_ip), "%s%d_pdp_ip", ps_wan, actinfo->c_id); |
| 1732 | cfg_set(nv_ip, actinfo->act_info.ip); |
| 1733 | snprintf(nv_pridns, sizeof(nv_pridns), "%s%d_pridns", ps_wan, actinfo->c_id); |
| 1734 | cfg_set(nv_pridns, actinfo->act_info.pri_dns); |
| 1735 | snprintf(nv_secdns, sizeof(nv_secdns), "%s%d_secdns", ps_wan, actinfo->c_id); |
| 1736 | cfg_set(nv_secdns, actinfo->act_info.sec_dns); |
| 1737 | snprintf(nv_gw, sizeof(nv_gw), "%s%d_gw", ps_wan, actinfo->c_id); |
| 1738 | //Óû§ÅäÖþ²Ì¬gw |
| 1739 | if (0 != strcmp(actinfo->act_info.gateway, "")) { |
| 1740 | cfg_set(nv_gw, actinfo->act_info.gateway); |
| 1741 | } |
| 1742 | //sprintf(cmd, "/sbin/psext_updown.sh \"linkup\" \"%d\"", actinfo->c_id); |
| 1743 | sprintf(cmd, "/sbin/psext_updown.sh linkup %d", actinfo->c_id); |
| 1744 | //zxic_system(cmd); |
| 1745 | fpv4 = popen(cmd, "r"); |
| 1746 | } |
| 1747 | |
| 1748 | if (actinfo->act_info.ip46flag == V6_VALID || actinfo->act_info.ip46flag == V46_VALID) { |
| 1749 | snprintf(nv_ip6, sizeof(nv_ip6), "%s%d_ipv6_interface_id", ps_wan, actinfo->c_id); |
| 1750 | //cfg_set(nv_ip6, actinfo->act_info.ip6); |
| 1751 | save_interface_id(nv_ip6, actinfo->act_info.ip6); |
| 1752 | //snprintf(nv_gw6, sizeof(nv_gw6), "%s%d_ipv6_gw", nv_pswan, actinfo->c_id); |
| 1753 | //cfg_set(nv_gw6, actinfo->act_info.gateway6); |
| 1754 | snprintf(nv_pridns6, sizeof(nv_pridns6), "%s%d_ipv6_pridns_auto", ps_wan, actinfo->c_id); |
| 1755 | cfg_set(nv_pridns6, actinfo->act_info.pri_dns6); |
| 1756 | snprintf(nv_secdns6, sizeof(nv_secdns6), "%s%d_ipv6_secdns_auto", ps_wan, actinfo->c_id); |
| 1757 | cfg_set(nv_secdns6, actinfo->act_info.sec_dns6); |
| 1758 | memset(cmd, 0, sizeof(cmd)); |
| 1759 | //sprintf(cmd, "/sbin/psext_updown_ipv6.sh \"linkup\" \"%d\"", actinfo->c_id); |
| 1760 | sprintf(cmd, "/sbin/psext_updown_ipv6.sh linkup %d", actinfo->c_id); |
| 1761 | //zxic_system(cmd); |
| 1762 | fpv6 = popen(cmd, "r"); |
| 1763 | } |
| 1764 | if(fpv4 != NULL) |
| 1765 | pclose(fpv4); |
| 1766 | if(fpv6 != NULL) |
| 1767 | pclose(fpv6); |
| 1768 | return 1; |
| 1769 | } |
| 1770 | |
| 1771 | //±£´æPDP¼¤»îµÄÓû§Òâͼ£¬ÒÔ±ãPDPÈ¥»îʱÄܹ»×¼È·ÊÍ·ÅÏà¹ØÍøÂç×ÊÔ´ |
| 1772 | void set_pdp_mode(int c_id, unsigned char pdp_type) |
| 1773 | { |
| 1774 | char pdp_mode[NV_NAME_LEN] = {0}; |
| 1775 | |
| 1776 | sprintf(pdp_mode, "pdp_mode%d", c_id); |
| 1777 | if (pdp_type == PDP_NORMAL) |
| 1778 | cfg_set(pdp_mode, "gateway"); |
| 1779 | else if (pdp_type == PDP_EXT) |
| 1780 | cfg_set(pdp_mode, "bridge"); |
| 1781 | else if (pdp_type == PDP_LOCAL) |
| 1782 | cfg_set(pdp_mode, "local"); |
| 1783 | else if (pdp_type == PDP_PPP) |
| 1784 | cfg_set(pdp_mode, "ppp"); |
| 1785 | else |
| 1786 | softap_assert("pdp_type=%u error", pdp_type); |
| 1787 | } |
| 1788 | |
| 1789 | void reset_pdp_mode(int c_id) |
| 1790 | { |
| 1791 | |
| 1792 | char pdp_mode[NV_NAME_LEN] = {0}; |
| 1793 | |
| 1794 | sprintf(pdp_mode, "pdp_mode%d", c_id); |
| 1795 | |
| 1796 | cfg_set(pdp_mode, ""); |
| 1797 | |
| 1798 | } |
| 1799 | |
| 1800 | //ÉèÖÃPDP¼¤»îµÄ˫ջ֧³ÖÇé¿ö£¬ÒÔ±ãÉèÖÃNORMALÍâÍø¿ÚµÄDNSʱʹÓã» |
| 1801 | void set_pdp_act_type(int c_id, unsigned char ip46flag) |
| 1802 | { |
| 1803 | char pdp_act_type[NV_NAME_LEN] = { 0 }; |
| 1804 | sprintf(pdp_act_type, "pdp_act_type%d", c_id); |
| 1805 | |
| 1806 | if (ip46flag == V4_VALID) |
| 1807 | cfg_set(pdp_act_type, "IPv4"); |
| 1808 | else if (ip46flag == V6_VALID) |
| 1809 | cfg_set(pdp_act_type, "IPv6"); |
| 1810 | else if (ip46flag == V46_VALID) |
| 1811 | cfg_set(pdp_act_type, "IPv4v6"); |
| 1812 | else |
| 1813 | softap_assert("ip46flag=%u error", ip46flag); |
| 1814 | } |
| 1815 | |
| 1816 | void vlan_config(unsigned int sw_type, char* act) |
| 1817 | { |
| 1818 | char dev_name[NV_NAME_LEN] = {0}; |
| 1819 | char eth_lan[NV_NAME_LEN] = {0}; |
| 1820 | char sw_name[NV_NAME_LEN] = {0}; |
| 1821 | char swport[NV_NAME_LEN] = {0}; |
| 1822 | char cmd[100] = {0}; |
| 1823 | char* str_point = NULL; |
| 1824 | |
| 1825 | if (sw_type == RJ45_WAN_DEV) { |
| 1826 | cfg_get_item("ethwan", dev_name, sizeof(dev_name)); |
| 1827 | } else { |
| 1828 | cfg_get_item("ethlan", dev_name, sizeof(dev_name)); |
| 1829 | } |
| 1830 | str_point = strchr(dev_name, '.'); |
| 1831 | if (str_point == NULL) |
| 1832 | return; |
| 1833 | if (0 == strcmp(act, "add")) { |
| 1834 | strncpy(swport, str_point + 1, sizeof(swport)-1); |
| 1835 | strncpy(sw_name, dev_name, str_point - dev_name); |
| 1836 | sw_name[str_point - dev_name + 1] = '\0'; |
| 1837 | sprintf(cmd, "/sbin/vconfig add %s %s", sw_name, swport); |
| 1838 | zxic_system(cmd); |
| 1839 | memset(cmd, 0x00, sizeof(cmd)); |
| 1840 | sprintf(cmd, "/sbin/vconfig set_flag %s 1 1", dev_name); |
| 1841 | zxic_system(cmd); |
| 1842 | } else { |
| 1843 | sprintf(cmd, "/sbin/vconfig rem %s", dev_name); |
| 1844 | zxic_system(cmd); |
| 1845 | } |
| 1846 | } |
| 1847 | void ethwan_plugin() |
| 1848 | { |
| 1849 | char eth_dialmode[NV_NAME_LEN] = {0}; |
| 1850 | char eth_type[NV_NAME_LEN] = {0}; |
| 1851 | char ethwan_name[NV_NAME_LEN] = {0}; |
| 1852 | char rj45_pluginstate[NV_NAME_LEN] = {0}; |
| 1853 | int plugstate = 0; |
| 1854 | char wbwanv6_enable[NV_NAME_LEN] = {0}; |
| 1855 | cfg_get_item("wbwanv6_enable", wbwanv6_enable, sizeof(wbwanv6_enable)); |
| 1856 | cfg_get_item("ethwan_dialmode", eth_dialmode, sizeof(eth_dialmode)); |
| 1857 | cfg_get_item("eth_type", eth_type, sizeof(eth_type)); |
| 1858 | cfg_get_item("ethwan", ethwan_name, sizeof(ethwan_name)); |
| 1859 | |
| 1860 | if (0 == strcmp(eth_type, "auto") || 0 == strcmp(eth_type, "")) { |
| 1861 | cfg_set("rj45_state", "idle"); |
| 1862 | cfg_set("eth_curtype", ""); |
| 1863 | vlan_config(RJ45_WAN_DEV, "add"); |
| 1864 | if(strchr(ethwan_name, '.') == NULL)//¸ù¾ÝnvÏîethwanÖµÊÇ·ñÓÐ'.'À´ÅжÏÊÇswitch»¹Êǵ¥phy |
| 1865 | {//Ö»Óе¥phy²ÅÉèÖÃ180s¶¨Ê±Æ÷£¬³¬Ê±»¹Î´»ñÈ¡ipµØÖ·Ôò½«ethwanÌí¼Óbr0ÇÅÏ |
| 1866 | creattimer(ðwan_id); |
| 1867 | } |
| 1868 | system("auto_dial.sh \"ethwan\""); |
| 1869 | } else if (0 == strcmp(eth_type, "wan")) { |
| 1870 | cfg_set("eth_curtype", "wan"); |
| 1871 | if(strchr(ethwan_name, '.') != NULL)//¸ù¾ÝnvÏîethwanÖµÊÇ·ñÓÐ'.'À´ÅжÏÊÇswitch»¹Êǵ¥phy |
| 1872 | { |
| 1873 | set_ethwan_port_mode(1); |
| 1874 | } |
| 1875 | |
| 1876 | vlan_config(RJ45_WAN_DEV, "add"); |
| 1877 | cfg_set("rj45_state", "idle"); |
| 1878 | if (0 == strcmp(eth_dialmode, "auto") || 0 == strcmp(eth_dialmode, "ondemand")) { |
| 1879 | cfg_set("rj45_state", "connect"); |
| 1880 | if(strchr(ethwan_name, '.') == NULL)//¸ù¾ÝnvÏîethwanÖµÊÇ·ñÓÐ'.'À´ÅжÏÊÇswitch»¹Êǵ¥phy |
| 1881 | {//Ö»Óе¥phy²ÅÉèÖÃ180s¶¨Ê±Æ÷£¬³¬Ê±»¹Î´»ñÈ¡ipµØÖ·Ôò½«ethwanÌí¼Óbr0ÇÅÏ |
| 1882 | creattimer(ðwan_id); |
| 1883 | } |
| 1884 | system("wan_ipv4.sh \"linkup\" \"ethwan\""); |
| 1885 | if(atoi(wbwanv6_enable) == 1) |
| 1886 | system("wan_ipv6.sh \"linkup\" \"ethwan\""); |
| 1887 | } |
| 1888 | } else if (0 == strcmp(eth_type, "lan")) { |
| 1889 | cfg_set("eth_curtype", "lan"); |
| 1890 | if(strchr(ethwan_name, '.') != NULL)//¸ù¾ÝnvÏîethwanÖµÊÇ·ñÓÐ'.'À´ÅжÏÊÇswitch»¹Êǵ¥phy |
| 1891 | { |
| 1892 | set_ethwan_port_mode(0); |
| 1893 | cfg_get_item("rj45_pluginstate", rj45_pluginstate, sizeof(rj45_pluginstate)); |
| 1894 | plugstate = atoi(rj45_pluginstate); |
| 1895 | if((plugstate & RJ45_LAN_IN) == 0) |
| 1896 | { |
| 1897 | vlan_config(RJ45_LAN_DEV, "add"); |
| 1898 | system("landev_updown.sh \"ethlan\" \"up\""); |
| 1899 | cfg_set("wanport3_in_lan", "1"); |
| 1900 | } |
| 1901 | } |
| 1902 | else |
| 1903 | { |
| 1904 | system("landev_updown.sh \"ethwan\" \"up\""); |
| 1905 | } |
| 1906 | slog(NET_PRINT, SLOG_NORMAL, "rj45 as lan plugin end!\n"); |
| 1907 | } |
| 1908 | |
| 1909 | } |
| 1910 | void ethlan_plugin() |
| 1911 | { |
| 1912 | char lanflag[8] = {0}; |
| 1913 | char ethwan_name[NV_NAME_LEN] = {0}; |
| 1914 | |
| 1915 | cfg_get_item("ethwan", ethwan_name, sizeof(ethwan_name)); |
| 1916 | cfg_get_item("wanport3_in_lan", lanflag, sizeof(lanflag)); |
| 1917 | if(strchr(ethwan_name, '.') != NULL && strcmp(lanflag, "1") == 0)//¸ù¾ÝnvÏîethwanÖµÊÇ·ñÓÐ'.'À´ÅжÏÊÇswitch»¹Êǵ¥phy |
| 1918 | {//switchÐÎ̬ÇÒwan¿Ú¶ÔÓ¦port3ÒѾ¼ÓÈëvlan100,¼´eth0.100ÒѾ´´½¨ÇÒ¹ÒÔÚbr0Ï |
| 1919 | slog(NET_PRINT, SLOG_NORMAL, "rj45 eth0.100 has been created and mounted to br0!\n"); |
| 1920 | return; |
| 1921 | } |
| 1922 | |
| 1923 | vlan_config(RJ45_LAN_DEV, "add"); |
| 1924 | system("landev_updown.sh \"ethlan\" \"up\""); |
| 1925 | slog(NET_PRINT, SLOG_NORMAL, "rj45 as lan plugin end!\n"); |
| 1926 | } |
| 1927 | |
| 1928 | void ethwan_plugout() |
| 1929 | { |
| 1930 | char eth_curtype[NV_NAME_LEN] = {0}; |
| 1931 | char cmd[100] = {0}; |
| 1932 | char ethwan_name[32] = {0}; |
| 1933 | char rj45_pluginstate[NV_NAME_LEN] = {0}; |
| 1934 | int plugstate = 0; |
| 1935 | char wbwanv6_enable[NV_NAME_LEN] = {0}; |
| 1936 | cfg_get_item("wbwanv6_enable", wbwanv6_enable, sizeof(wbwanv6_enable)); |
| 1937 | //msg_timedel(); |
| 1938 | system("killall eth_auto_connect"); |
| 1939 | deletetimer(ethwan_id); |
| 1940 | slog(NET_PRINT, SLOG_NORMAL, "plugout ..... deletetimer....."); |
| 1941 | cfg_get_item("eth_curtype", eth_curtype, sizeof(eth_curtype)); |
| 1942 | cfg_set("eth_curtype", ""); |
| 1943 | |
| 1944 | cfg_get_item("ethwan", ethwan_name, sizeof(ethwan_name)); |
| 1945 | |
| 1946 | if (0 == strcmp(eth_curtype, "wan")) { |
| 1947 | system("wan_ipv4.sh \"linkdown\" \"ethwan\""); |
| 1948 | if(atoi(wbwanv6_enable) == 1) |
| 1949 | system("wan_ipv6.sh \"linkdown\" \"ethwan\""); |
| 1950 | } else if (0 == strcmp(eth_curtype, "lan")) { |
| 1951 | //switchÐÎ̬´ËʱûÓÐeth0.200Íø¿Ú |
| 1952 | if(strchr(ethwan_name, '.') != NULL)//¸ù¾ÝnvÏîethwanÖµÊÇ·ñÓÐ'.'À´ÅжÏÊÇswitch»¹Êǵ¥phy |
| 1953 | { |
| 1954 | cfg_get_item("rj45_pluginstate", rj45_pluginstate, sizeof(rj45_pluginstate)); |
| 1955 | plugstate = atoi(rj45_pluginstate); |
| 1956 | if((plugstate & RJ45_LAN_IN) == 0) |
| 1957 | { |
| 1958 | system("landev_updown.sh \"ethlan\" \"down\""); |
| 1959 | vlan_config(RJ45_LAN_DEV, "rem"); |
| 1960 | cfg_set("wanport3_in_lan", "0"); |
| 1961 | } |
| 1962 | } |
| 1963 | else |
| 1964 | { |
| 1965 | system("landev_updown.sh \"ethwan\" \"down\""); |
| 1966 | } |
| 1967 | slog(NET_PRINT, SLOG_NORMAL, "rj45 as lan plugout end!\n"); |
| 1968 | } else { |
| 1969 | system("wan_ipv4.sh \"linkdown\" \"ethwan\""); |
| 1970 | if(atoi(wbwanv6_enable) == 1) |
| 1971 | system("wan_ipv6.sh \"linkdown\" \"ethwan\""); |
| 1972 | system("landev_updown.sh \"ethwan\" \"down\""); |
| 1973 | } |
| 1974 | |
| 1975 | cfg_set("rj45_state", "dead"); |
| 1976 | vlan_config(RJ45_WAN_DEV, "rem"); |
| 1977 | if(strchr(ethwan_name, '.') != NULL)//¸ù¾ÝnvÏîethwanÖµÊÇ·ñÓÐ'.'À´ÅжÏÊÇswitch»¹Êǵ¥phy |
| 1978 | { |
| 1979 | set_ethwan_port_mode(1); //½«switchµÄwan¿Úport3»¹Ô³Éwan£¬·ñÔòÏ´βåÈëport3¿ÉÄÜ»¹ÊÇlan¿Ú |
| 1980 | } |
| 1981 | } |
| 1982 | void ethlan_plugout() |
| 1983 | { |
| 1984 | char lanflag[8] = {0}; |
| 1985 | char ethwan_name[NV_NAME_LEN] = {0}; |
| 1986 | |
| 1987 | cfg_get_item("ethwan", ethwan_name, sizeof(ethwan_name)); |
| 1988 | cfg_get_item("wanport3_in_lan", lanflag, sizeof(lanflag)); |
| 1989 | if(strchr(ethwan_name, '.') != NULL && strcmp(lanflag, "1") == 0)//¸ù¾ÝnvÏîethwanÖµÊÇ·ñÓÐ'.'À´ÅжÏÊÇswitch»¹Êǵ¥phy |
| 1990 | {//switchÐÎ̬ÇÒwan¿Ú¶ÔÓ¦port3ÒѾ¼ÓÈëvlan100,¼´eth0.100Ï»¹ÓÐport3¶Ë¿Ú£¬ËùÒÔ»¹²»ÄÜɾ³ýeth0.100 |
| 1991 | slog(NET_PRINT, SLOG_NORMAL, "rj45 eth0.100 has been created and mounted to br0!\n"); |
| 1992 | return; |
| 1993 | } |
| 1994 | |
| 1995 | system("landev_updown.sh \"ethlan\" \"down\""); |
| 1996 | vlan_config(RJ45_LAN_DEV, "rem"); |
| 1997 | slog(NET_PRINT, SLOG_NORMAL, "rj45 as lan plugout end!\n"); |
| 1998 | } |
| 1999 | |
| 2000 | void wifi_plugin() |
| 2001 | { |
| 2002 | char wbwanv6_enable[NV_NAME_LEN] = {0}; |
| 2003 | cfg_get_item("wbwanv6_enable", wbwanv6_enable, sizeof(wbwanv6_enable)); |
| 2004 | cfg_set("wifi_state", "idle"); |
| 2005 | creattimer(&wifiwan_id); |
| 2006 | system("wan_ipv4.sh \"linkup\" \"wifiwan\""); |
| 2007 | if(atoi(wbwanv6_enable) == 1) |
| 2008 | system("wan_ipv6.sh \"linkup\" \"wifiwan\""); |
| 2009 | } |
| 2010 | |
| 2011 | |
| 2012 | /*rj45 ÍâÍø¿Úʱ£¬¸ù¾Ýµ±Ç°×´Ì¬£¬ÈôΪworking or init or nullÔòÏÈlinkdown£¬É±ËÀÏà¹Ø½ø³Ì£¬È»ºóÆôÓã»ÈôΪdeadÔòÖ±½ÓÆôÓÃ*/ |
| 2013 | void eth_connect() |
| 2014 | { |
| 2015 | char ethwan_name[NV_NAME_LEN] = {0}; |
| 2016 | char eth_curtype[NV_NAME_LEN] = {0}; |
| 2017 | char work_state[NV_NAME_LEN] = {0}; |
| 2018 | //rj45Ö§³Öwan/lan¹¦ÄÜ£¬¿ÉÑ¡Ôñ³ÉΪÍâÍø¿Ú»òÄÚÍø¿Ú |
| 2019 | char wbwanv6_enable[NV_NAME_LEN] = {0}; |
| 2020 | cfg_get_item("wbwanv6_enable", wbwanv6_enable, sizeof(wbwanv6_enable)); |
| 2021 | vlan_config(RJ45_WAN_DEV, "add"); |
| 2022 | cfg_get_item("eth_curtype", eth_curtype, sizeof(eth_curtype)); |
| 2023 | cfg_get_item("ethwan", ethwan_name, sizeof(ethwan_name)); |
| 2024 | if (0 == strcmp(eth_curtype, "lan")) { |
| 2025 | system("landev_updown.sh \"ethwan\" \"up\""); |
| 2026 | slog(NET_PRINT, SLOG_NORMAL, "rj45 as lan connect end!\n"); |
| 2027 | } else { // ĬÈÏ×÷Ϊwan¿Ú´¦Àí |
| 2028 | cfg_get_item("rj45_state", work_state, sizeof(work_state)); |
| 2029 | //work_state=deadÔòµ±Ç°´¦ÓÚ¶Ï¿ª×´Ì¬£¬Ö±½Ólinkup£¬ÆäËû×´¿öÏÈlinkdown |
| 2030 | if (0 == strcmp(work_state, "connect") || 0 == strcmp(work_state, "working")) { |
| 2031 | system("wan_ipv4.sh \"linkdown\" \"ethwan\""); |
| 2032 | if(atoi(wbwanv6_enable) == 1) |
| 2033 | system("wan_ipv6.sh \"linkdown\" \"ethwan\""); |
| 2034 | cfg_set("rj45_state", "connect"); |
| 2035 | if(strchr(ethwan_name, '.') == NULL)//¸ù¾ÝnvÏîethwanÖµÊÇ·ñÓÐ'.'À´ÅжÏÊÇswitch»¹Êǵ¥phy |
| 2036 | {//Ö»Óе¥phy²ÅÉèÖÃ180s¶¨Ê±Æ÷£¬³¬Ê±»¹Î´»ñÈ¡ipµØÖ·Ôò½«ethwanÌí¼Óbr0ÇÅÏ |
| 2037 | creattimer(ðwan_id); |
| 2038 | } |
| 2039 | system("wan_ipv4.sh \"linkup\" \"ethwan\""); |
| 2040 | if(atoi(wbwanv6_enable) == 1) |
| 2041 | system("wan_ipv6.sh \"linkup\" \"ethwan\""); |
| 2042 | } else if (0 == strcmp(work_state, "idle")) { |
| 2043 | cfg_set("rj45_state", "connect"); |
| 2044 | if(strchr(ethwan_name, '.') == NULL)//¸ù¾ÝnvÏîethwanÖµÊÇ·ñÓÐ'.'À´ÅжÏÊÇswitch»¹Êǵ¥phy |
| 2045 | {//Ö»Óе¥phy²ÅÉèÖÃ180s¶¨Ê±Æ÷£¬³¬Ê±»¹Î´»ñÈ¡ipµØÖ·Ôò½«ethwanÌí¼Óbr0ÇÅÏ |
| 2046 | creattimer(ðwan_id); |
| 2047 | } |
| 2048 | system("wan_ipv4.sh \"linkup\" \"ethwan\""); |
| 2049 | if(atoi(wbwanv6_enable) == 1) |
| 2050 | system("wan_ipv6.sh \"linkup\" \"ethwan\""); |
| 2051 | } else if (0 == strcmp(work_state, "dead") || 0 == strcmp(work_state, "")) |
| 2052 | return; |
| 2053 | else |
| 2054 | softap_assert("rj45_state=%s error", work_state); |
| 2055 | |
| 2056 | } |
| 2057 | |
| 2058 | } |
| 2059 | |
| 2060 | //wifi stationÍâÍø¿ÚµÄµØÖ··ÖÅäÇëÇóÁ÷³Ì£¬Èô֮ǰÒѾ´¦ÓÚworking̬£¬ÐèÒªÏÈÇå³ýËùÓÐ×ÊÔ´ |
| 2061 | void wifi_connect() |
| 2062 | { |
| 2063 | char work_state[NV_NAME_LEN] = {0}; |
| 2064 | char wbwanv6_enable[NV_NAME_LEN] = {0}; |
| 2065 | cfg_get_item("wbwanv6_enable", wbwanv6_enable, sizeof(wbwanv6_enable)); |
| 2066 | cfg_get_item("wifi_state", work_state, sizeof(work_state)); |
| 2067 | if (0 == strcmp(work_state, "connect") || 0 == strcmp(work_state, "working")) { |
| 2068 | system("wan_ipv4.sh \"linkdown\" \"wifiwan\""); |
| 2069 | if(atoi(wbwanv6_enable) == 1) |
| 2070 | system("wan_ipv6.sh \"linkdown\" \"wifiwan\""); |
| 2071 | cfg_set("wifi_state", "connect"); |
| 2072 | creattimer(&wifiwan_id); |
| 2073 | system("wan_ipv4.sh \"linkup\" \"wifiwan\""); |
| 2074 | if(atoi(wbwanv6_enable) == 1) |
| 2075 | system("wan_ipv6.sh \"linkup\" \"wifiwan\""); |
| 2076 | } else { |
| 2077 | cfg_set("wifi_state", "connect"); |
| 2078 | creattimer(&wifiwan_id); |
| 2079 | system("wan_ipv4.sh \"linkup\" \"wifiwan\""); |
| 2080 | if(atoi(wbwanv6_enable) == 1) |
| 2081 | system("wan_ipv6.sh \"linkup\" \"wifiwan\""); |
| 2082 | } |
| 2083 | } |
| 2084 | |
| 2085 | int pdp_act_check(struct pdp_active_info *actinfo) |
| 2086 | { |
| 2087 | char ps_ip[32] = {0}; |
| 2088 | char ps_ip6[64] = {0}; |
| 2089 | char nv_ip[NV_NAME_LEN] = {0}; |
| 2090 | char nv_ip6[NV_NAME_LEN] = {0}; |
| 2091 | if (actinfo->act_info.ip46flag == V4_VALID || actinfo->act_info.ip46flag == V46_VALID) { |
| 2092 | snprintf(nv_ip, sizeof(nv_ip), "%s%d_ip", ps_wan, actinfo->c_id); |
| 2093 | cfg_get_item(nv_ip, ps_ip, sizeof(ps_ip)); |
| 2094 | if (0 != strcmp(ps_ip, "0.0.0.0") && (0 != strcmp(ps_ip, ""))) { |
| 2095 | slog(NET_PRINT, SLOG_ERR, "pdp_act_init: already act ip=%s", ps_ip); //cov m |
| 2096 | return 0; |
| 2097 | } |
| 2098 | } |
| 2099 | /*if (actinfo->act_info.ip46flag == V6_VALID || actinfo->act_info.ip46flag == V46_VALID) |
| 2100 | { |
| 2101 | sprintf(nv_ip6,"ps%d_ipv6_ip", actinfo->c_id); |
| 2102 | cfg_get_item(nv_ip6, ps_ip6, sizeof(ps_ip6)); |
| 2103 | if ((0 != strcmp(ps_ip6, "::")) && (0 != strcmp(ps_ip6, ""))) |
| 2104 | { |
| 2105 | return 0; |
| 2106 | } |
| 2107 | }*/ |
| 2108 | return 1; |
| 2109 | } |
| 2110 | |
| 2111 | |
| 2112 | void set_def_wan(char *wanif, char *wantype) |
| 2113 | { |
| 2114 | char cmd_test[200] = {0}; |
| 2115 | |
| 2116 | cfg_set("default_wan_name", wanif); |
| 2117 | cfg_set("default_wan_rel", wantype); |
| 2118 | //if(0 == strncmp(wanif,"ps",2)) |
| 2119 | // cfg_set("wan_name", wanif); |
| 2120 | |
| 2121 | slog(NET_PRINT, SLOG_NORMAL, "set default_wan_name = %s \n", wanif); |
| 2122 | //Èç¹ûĬÈÏÍâÍø¿ÚÊǶÔÐÒéÕ»µÄ£¬ÐèÒª½«Íø¿ÚÃû´«µÝ¸øÄÚºËʵÏÖ¿ìËÙת·¢Æ½Ì¨»° |
| 2123 | if (strncmp(wanif, ps_wan, strlen(ps_wan)) == 0) { |
| 2124 | memset(cmd_test, 0, sizeof(cmd_test)); |
| 2125 | sprintf(cmd_test, "echo %s > /proc/net/ps_name", wanif); |
| 2126 | system_cmd_ex(cmd_test); |
| 2127 | } |
| 2128 | } |
| 2129 | |
| 2130 | void set_def_wan6(char *wanif, char *wantype) |
| 2131 | { |
| 2132 | //char cmd_test[200] = {0}; |
| 2133 | |
| 2134 | cfg_set("default_wan6_name", wanif); |
| 2135 | cfg_set("default_wan6_rel", wantype); |
| 2136 | //if(0 == strncmp(wanif,"ps",2)) |
| 2137 | // cfg_set("wan_name6", wanif); |
| 2138 | slog(NET_PRINT, SLOG_NORMAL, "set default_wan6_name = %s, default_wan6_rel = %s \n", wanif, wantype); |
| 2139 | //sprintf(cmd_test,"echo test: set default_wan6_name = %s, default_wan6_rel = %s >> /mnt/jffs2/te.log ", wanif, wantype); |
| 2140 | //system_cmd_ex(cmd_test); |
| 2141 | } |
| 2142 | |
| 2143 | /*set dns in resolv.conf */ |
| 2144 | void defwan_set(char *wanif) |
| 2145 | { |
| 2146 | if (0 == strcmp(wanif, eth_wan)) |
| 2147 | system("defwan_set.sh \"ethwan\""); |
| 2148 | else if (0 == strcmp(wanif, wifi_wan)) |
| 2149 | system("defwan_set.sh \"wifiwan\""); |
| 2150 | else |
| 2151 | system("defwan_set.sh \"pswan\""); |
| 2152 | } |
| 2153 | |
| 2154 | void ddns_set(void) |
| 2155 | { |
| 2156 | char ddns_enable[NV_NAME_LEN] = {0}; |
| 2157 | char ddns_mode[NV_NAME_LEN] = {0}; |
| 2158 | cfg_get_item("DDNS_Enable", ddns_enable, sizeof(ddns_enable)); |
| 2159 | cfg_get_item("DDNS_Mode", ddns_mode, sizeof(ddns_mode)); |
| 2160 | |
| 2161 | if (0 == strcmp(ddns_enable, "1") && 0 == strcmp(ddns_mode, "auto")) |
| 2162 | system_cmd_ex("ddns.sh"); |
| 2163 | } |
| 2164 | |
| 2165 | /* |
| 2166 | deal with msg MSG_CMD_NET_WAN4_CHANGE |
| 2167 | choose the largest xxxwan_priority in wan who is up |
| 2168 | set default_wan nv |
| 2169 | if changed then reset firewall |
| 2170 | */ |
| 2171 | void proc_wan_change_v4(void) |
| 2172 | { |
| 2173 | slog(NET_PRINT, SLOG_NORMAL, "proc_wan_change_v4 start!\n"); |
| 2174 | char wan_pri[32] = {0}; |
| 2175 | char cid[20] = {0}; |
| 2176 | int defwan_pri = 0; |
| 2177 | int pri = 0; |
| 2178 | char nv_pswan[ZTE_ROUTER_WAN_IF_NAME_LEN] = {0}; |
| 2179 | char nv_usbwan[ZTE_ROUTER_WAN_IF_NAME_LEN] = {0}; |
| 2180 | char nv_ethwan[ZTE_ROUTER_WAN_IF_NAME_LEN] = {0}; |
| 2181 | char nv_wifiwan[ZTE_ROUTER_WAN_IF_NAME_LEN] = {0}; |
| 2182 | char pswan_ip[ZTE_ROUTER_IP_ADDR_LEN] = {0}; |
| 2183 | //char usbwan_ip[ZTE_ROUTER_IP_ADDR_LEN] = {0}; |
| 2184 | char ethwan_ip[ZTE_ROUTER_IP_ADDR_LEN] = {0}; |
| 2185 | char wifiwan_ip[ZTE_ROUTER_IP_ADDR_LEN] = {0}; |
| 2186 | char defwan_if[ZTE_ROUTER_WAN_IF_NAME_LEN] = {0}; |
| 2187 | char defwan_real[ZTE_ROUTER_WAN_IF_NAME_LEN] = {0}; |
| 2188 | char defwan_dev_name[ZTE_ROUTER_WAN_IF_NAME_LEN] = {0}; |
| 2189 | char ethwan_actprotl[ZTE_ROUTER_WAN_IF_NAME_LEN] = {0}; |
| 2190 | int defwan_change = 0; |
| 2191 | struct default_dev_info defwan_dev_info; |
| 2192 | defwan_dev_info.ip46flag = V4_VALID; |
| 2193 | |
| 2194 | //sprintf(nv_usbwan,"%s_ip", usb_wan); |
| 2195 | //cfg_get_item(nv_usbwan, usbwan_ip, sizeof(usbwan_ip)); |
| 2196 | //¶ÔÓÚswÍø¿Ú£¬ethwanµÄÉèÖÃÊÇÔÚÈȲ岥ʱÉèÖõģ¬ÔÚzte_routerÆô¶¯£¬ |
| 2197 | //³õʼ»¯eth_wanʱ£¬ÓпÉÄÜÉÐδÍê³É¸ÃÉèÖã¬Òò´ËÐèÒªÖØÐ»ñÈ¡É豸Ãû |
| 2198 | cfg_get_item("ethwan", eth_wan, sizeof(eth_wan)); |
| 2199 | snprintf(nv_ethwan, sizeof(nv_ethwan), "%s_ip", eth_wan); |
| 2200 | cfg_get_item(nv_ethwan, ethwan_ip, sizeof(ethwan_ip)); |
| 2201 | snprintf(nv_wifiwan, sizeof(nv_wifiwan), "%s_ip", wifi_wan); |
| 2202 | cfg_get_item(nv_wifiwan, wifiwan_ip, sizeof(wifiwan_ip)); |
| 2203 | //cfg_get_item("wlan0_ip", wifiwan_ip, sizeof(wifiwan_ip));//wlan0ÊÊÅä |
| 2204 | |
| 2205 | cfg_get_item("default_cid", cid, sizeof(cid)); |
| 2206 | if (0 != strcmp(cid, "")) { |
| 2207 | snprintf(nv_pswan, sizeof(nv_pswan), "%s%s_ip", ps_wan, cid); |
| 2208 | cfg_get_item(nv_pswan, pswan_ip, sizeof(pswan_ip)); |
| 2209 | if (0 != strcmp(pswan_ip, "0.0.0.0") && (0 != strcmp(pswan_ip, ""))) { |
| 2210 | memset(wan_pri, 0, sizeof(wan_pri)); |
| 2211 | cfg_get_item("pswan_priority", wan_pri, sizeof(wan_pri)); |
| 2212 | pri = atoi(wan_pri); |
| 2213 | if (pri > defwan_pri) { |
| 2214 | defwan_pri = pri; |
| 2215 | snprintf(defwan_if, sizeof(defwan_if), "%s%s", ps_wan, cid); |
| 2216 | strcpy(defwan_real, defwan_if); |
| 2217 | strcpy(defwan_dev_name, ps_wan); |
| 2218 | } |
| 2219 | } |
| 2220 | } |
| 2221 | if (0 != strcmp(ethwan_ip, "0.0.0.0") && (0 != strcmp(ethwan_ip, ""))) { |
| 2222 | memset(wan_pri, 0, sizeof(wan_pri)); |
| 2223 | cfg_get_item("ethwan_priority", wan_pri, sizeof(wan_pri)); |
| 2224 | pri = atoi(wan_pri); |
| 2225 | if (pri > defwan_pri) { |
| 2226 | defwan_pri = pri; |
| 2227 | cfg_get_item("eth_curmode", ethwan_actprotl, sizeof(ethwan_actprotl)); |
| 2228 | |
| 2229 | if (0 == strcmp(ethwan_actprotl, "pppoe")) |
| 2230 | strcpy(defwan_real, "ppp0"); |
| 2231 | else |
| 2232 | strcpy(defwan_real, eth_wan); |
| 2233 | strcpy(defwan_if, eth_wan); |
| 2234 | strcpy(defwan_dev_name, eth_wan); |
| 2235 | } |
| 2236 | } |
| 2237 | |
| 2238 | if (0 != strcmp(wifiwan_ip, "0.0.0.0") && (0 != strcmp(wifiwan_ip, ""))) { |
| 2239 | memset(wan_pri, 0, sizeof(wan_pri)); |
| 2240 | cfg_get_item("wifiwan_priority", wan_pri, sizeof(wan_pri)); |
| 2241 | pri = atoi(wan_pri); |
| 2242 | if (pri > defwan_pri) { |
| 2243 | defwan_pri = pri; |
| 2244 | strcpy(defwan_if, wifi_wan); |
| 2245 | strcpy(defwan_real, wifi_wan); |
| 2246 | strcpy(defwan_dev_name, wifi_wan); |
| 2247 | } |
| 2248 | } |
| 2249 | |
| 2250 | //½«µ±Ç°ÓÐÐ§Íø¿ÚÖÐÓÅÏȼ¶×î¸ßµÄÉèÖÃΪȱʡÍâÍø¿Ú |
| 2251 | set_def_wan(defwan_if, defwan_real); |
| 2252 | |
| 2253 | slog(NET_PRINT, SLOG_NORMAL, "proc_wan_change_v4 old:%s, now:%s! \n", defwan_if_old, defwan_real); |
| 2254 | |
| 2255 | //½«È±Ê¡ÍâÍø¿ÚµÄdev_id·¢Ë͸øÖ÷¿Ø |
| 2256 | //if (strlen(defwan_dev_name) == 0 || 0 != strcmp(defwan_if_old, defwan_real)) |
| 2257 | { |
| 2258 | defwan_dev_info.dev_id = getDevId_byname(defwan_dev_name); |
| 2259 | |
| 2260 | net_default_wan_proc(&defwan_dev_info); |
| 2261 | |
| 2262 | //char tmp_name[20]= {0}; |
| 2263 | //sprintf(tmp_name,"zte_blc"); |
| 2264 | } |
| 2265 | //dns_set(defwan_if); |
| 2266 | |
| 2267 | if (0 == strlen(defwan_real)) { |
| 2268 | slog(NET_PRINT, SLOG_ERR, "proc_wan_change_v4 defwan_if not selected! \n"); |
| 2269 | net_sendmsg_2_atctl(atoi(cid), V4_VALID, MSG_CMD_LINKUP_END); |
| 2270 | return; |
| 2271 | } |
| 2272 | |
| 2273 | if (strcmp(defwan_if_old, defwan_real) != 0) |
| 2274 | defwan_change = 1; |
| 2275 | |
| 2276 | //Êý¾ÝÏÈͨ£¬ºó×öÆäËûÅäÖã¬×¢Òâµã: ·À»ðǽ¶Ìʱ¼äÄÚ¿ÉÄÜδÉúЧ |
| 2277 | if (defwan_change) |
| 2278 | system_cmd_ex("nat.sh"); |
| 2279 | defwan_set(defwan_if); |
| 2280 | |
| 2281 | system("cat /proc/uptime 1>dev/console 2>&1"); |
| 2282 | slog(NET_PRINT, SLOG_NORMAL, "proc_wan_change_v4 data ok, defwan_change:%d \n", defwan_change); |
| 2283 | |
| 2284 | //ȱʡÍâÍø¿Ú·¢Éú±ä»¯ÔòÖØÉènatºÍfilter |
| 2285 | if (defwan_change) { |
| 2286 | zte_router_init(); |
| 2287 | //dns_set(defwan_if); |
| 2288 | memset(defwan_if_old, 0, ZTE_ROUTER_WAN_IF_NAME_LEN); |
| 2289 | strncpy(defwan_if_old, defwan_real, strlen(defwan_real)); |
| 2290 | } |
| 2291 | zte_unpn_set(); |
| 2292 | ddns_set(); |
| 2293 | |
| 2294 | net_sendmsg_2_atctl(atoi(cid), V4_VALID, MSG_CMD_LINKUP_END); |
| 2295 | |
| 2296 | system("cat /proc/uptime 1>dev/console 2>&1"); |
| 2297 | slog(NET_PRINT, SLOG_NORMAL, "proc_wan_change_v4 end \n"); |
| 2298 | } |
| 2299 | |
| 2300 | /* |
| 2301 | deal with msg MSG_CMD_NET_WAN6_CHANGE |
| 2302 | choose the largest xxxwan_priority from the up-wans |
| 2303 | set default_wan nv |
| 2304 | if changed then reset firewall |
| 2305 | */ |
| 2306 | void proc_wan_change_v6(void) |
| 2307 | { |
| 2308 | slog(NET_PRINT, SLOG_NORMAL, "proc_wan_change_v6 start!\n"); |
| 2309 | char cid[20] = {0}; |
| 2310 | char wan_pri[32] = {0}; |
| 2311 | int defwan_pri = 0; |
| 2312 | int pri = 0; |
| 2313 | char nv_pswan_ipv6[ZTE_ROUTER_IP_ADDR_LEN] = {0}; |
| 2314 | char nv_ethwan_ipv6[ZTE_ROUTER_IP_ADDR_LEN] = {0}; |
| 2315 | char nv_wifiwan_ipv6[ZTE_ROUTER_IP_ADDR_LEN] = {0}; |
| 2316 | char pswan_ipv6[ZTE_ROUTER_IPV6_ADDR_LEN] = {0}; |
| 2317 | //char usbwan_ipv6[ZTE_ROUTER_IPV6_ADDR_LEN] = {0}; |
| 2318 | char ethwan_ipv6[ZTE_ROUTER_IPV6_ADDR_LEN] = {0}; |
| 2319 | char wifiwan_ipv6[ZTE_ROUTER_IPV6_ADDR_LEN] = {0}; |
| 2320 | char defwan_if_ipv6[ZTE_ROUTER_IP_ADDR_LEN] = {0}; |
| 2321 | char defwan_real_ipv6[ZTE_ROUTER_IP_ADDR_LEN] = {0}; |
| 2322 | char ethwan_actprotl[ZTE_ROUTER_WAN_IF_NAME_LEN] = {0}; |
| 2323 | char defwan_dev_name[ZTE_ROUTER_WAN_IF_NAME_LEN] = {0}; |
| 2324 | struct default_dev_info defwan_dev_info; |
| 2325 | char wbwanv6_enable[NV_NAME_LEN] = {0}; |
| 2326 | cfg_get_item("wbwanv6_enable", wbwanv6_enable, sizeof(wbwanv6_enable)); |
| 2327 | defwan_dev_info.ip46flag = V6_VALID; |
| 2328 | |
| 2329 | cfg_get_item("ethwan", eth_wan, sizeof(eth_wan)); |
| 2330 | sprintf(nv_ethwan_ipv6, "%s_ipv6_ip", eth_wan); |
| 2331 | //cfg_get_item("usb0_ipv6_ipaddr", usbwan_ipv6, sizeof(usbwan_ipv6)); |
| 2332 | |
| 2333 | cfg_get_item(nv_ethwan_ipv6, ethwan_ipv6, sizeof(ethwan_ipv6)); |
| 2334 | sprintf(nv_wifiwan_ipv6, "%s_ipv6_ip", wifi_wan); |
| 2335 | cfg_get_item(nv_wifiwan_ipv6, wifiwan_ipv6, sizeof(wifiwan_ipv6)); |
| 2336 | |
| 2337 | cfg_get_item("default_cid", cid, sizeof(cid)); |
| 2338 | if (0 != strcmp(cid, "")) { |
| 2339 | snprintf(nv_pswan_ipv6, sizeof(nv_pswan_ipv6), "%s%s_ipv6_ip", ps_wan, cid); |
| 2340 | cfg_get_item(nv_pswan_ipv6, pswan_ipv6, sizeof(pswan_ipv6)); |
| 2341 | if ((0 != strcmp(pswan_ipv6, "::")) && (0 != strcmp(pswan_ipv6, ""))) { |
| 2342 | memset(wan_pri, 0, sizeof(wan_pri)); |
| 2343 | cfg_get_item("pswan_priority", wan_pri, sizeof(wan_pri)); |
| 2344 | |
| 2345 | pri = atoi(wan_pri); |
| 2346 | if (pri > defwan_pri) { |
| 2347 | defwan_pri = pri; |
| 2348 | snprintf(defwan_if_ipv6, sizeof(defwan_if_ipv6), "%s%s", ps_wan, cid); |
| 2349 | strcpy(defwan_real_ipv6, defwan_if_ipv6); |
| 2350 | strcpy(defwan_dev_name, ps_wan); |
| 2351 | } |
| 2352 | } |
| 2353 | } |
| 2354 | if ((0 != strcmp(ethwan_ipv6, "::")) && (0 != strcmp(ethwan_ipv6, ""))) { |
| 2355 | memset(wan_pri, 0, sizeof(wan_pri)); |
| 2356 | cfg_get_item("ethwan_priority", wan_pri, sizeof(wan_pri)); |
| 2357 | |
| 2358 | pri = atoi(wan_pri); |
| 2359 | if (pri > defwan_pri) { |
| 2360 | defwan_pri = pri; |
| 2361 | cfg_get_item("eth_curmode", ethwan_actprotl, sizeof(ethwan_actprotl)); |
| 2362 | |
| 2363 | if (0 == strcmp(ethwan_actprotl, "pppoe")) |
| 2364 | strcpy(defwan_real_ipv6, "ppp0"); |
| 2365 | else |
| 2366 | strcpy(defwan_real_ipv6, eth_wan); |
| 2367 | strcpy(defwan_if_ipv6, eth_wan); |
| 2368 | strcpy(defwan_dev_name, eth_wan); |
| 2369 | cfg_set("eth_act_type", "IPv4v6"); |
| 2370 | } |
| 2371 | } |
| 2372 | |
| 2373 | if ((0 != strcmp(wifiwan_ipv6, "::")) && (0 != strcmp(wifiwan_ipv6, ""))) { |
| 2374 | memset(wan_pri, 0, sizeof(wan_pri)); |
| 2375 | cfg_get_item("wifiwan_priority", wan_pri, sizeof(wan_pri)); |
| 2376 | |
| 2377 | pri = atoi(wan_pri); |
| 2378 | if (pri > defwan_pri) { |
| 2379 | defwan_pri = pri; |
| 2380 | strcpy(defwan_if_ipv6, wifi_wan); |
| 2381 | strcpy(defwan_real_ipv6, wifi_wan); |
| 2382 | strcpy(defwan_dev_name, wifi_wan); |
| 2383 | cfg_set("wifi_act_type", "IPv4v6"); |
| 2384 | } |
| 2385 | } |
| 2386 | |
| 2387 | set_def_wan6(defwan_if_ipv6, defwan_real_ipv6); |
| 2388 | //½«È±Ê¡ÍâÍø¿ÚµÄdev_id·¢Ë͸øÖ÷¿Ø |
| 2389 | //if (strlen(defwan_dev_name) == 0 || strcmp(defwan6_if_old, defwan_real_ipv6)!=0) |
| 2390 | { |
| 2391 | defwan_dev_info.dev_id = getDevId_byname(defwan_dev_name); |
| 2392 | |
| 2393 | net_default_wan_proc(&defwan_dev_info); |
| 2394 | |
| 2395 | //char tmp_name[20]= {0}; |
| 2396 | //sprintf(tmp_name,"zte_blc"); |
| 2397 | } |
| 2398 | |
| 2399 | if (0 == strlen(defwan_real_ipv6)) { |
| 2400 | slog(NET_PRINT, SLOG_ERR, "proc_wan_change_v6 defwan_if_ipv6 not selected! \n"); |
| 2401 | net_sendmsg_2_atctl(atoi(cid), V6_VALID, MSG_CMD_LINKUP_END); |
| 2402 | return; |
| 2403 | } |
| 2404 | slog(NET_PRINT, SLOG_NORMAL, "proc_wan_change_v6 %s -> %s \n", defwan6_if_old, defwan_real_ipv6); |
| 2405 | if (strcmp(defwan6_if_old, defwan_real_ipv6) != 0) { |
| 2406 | int ps_wan_len = strlen(ps_wan); |
| 2407 | if (0 == strcmp(defwan6_if_old, eth_wan) && atoi(wbwanv6_enable) == 1) |
| 2408 | system("wan_ipv6.sh \"linkdown\" \"ethwan\""); |
| 2409 | else if (0 == strcmp(defwan6_if_old, wifi_wan) && atoi(wbwanv6_enable) == 1) |
| 2410 | system("wan_ipv6.sh \"linkdown\" \"wifi_wan\""); |
| 2411 | else if (ps_wan_len < strlen(defwan6_if_old) && 0 == strncmp(defwan6_if_old, ps_wan, ps_wan_len)){ |
| 2412 | char cmd[100] = {0}; |
| 2413 | int cid = defwan6_if_old[ps_wan_len] - '0'; |
| 2414 | if(cid > 0 && cid < 9){ |
| 2415 | sprintf(cmd, "/sbin/wan_ipv6.sh linkdown pswan %d", cid); |
| 2416 | zxic_system(cmd); |
| 2417 | } |
| 2418 | } |
| 2419 | } |
| 2420 | //Êý¾ÝÏÈͨ£¬ºó×öÆäËûÅäÖã¬×¢Òâµã: ·À»ðǽ¶Ìʱ¼äÄÚ¿ÉÄÜδÉúЧ |
| 2421 | if (0 == strcmp(defwan_if_ipv6, eth_wan) && atoi(wbwanv6_enable) == 1) |
| 2422 | system("wan_ipv6_config.sh \"ethwan\""); |
| 2423 | else if (0 == strcmp(defwan_if_ipv6, wifi_wan) && atoi(wbwanv6_enable) == 1) |
| 2424 | system("wan_ipv6_config.sh \"wifiwan\""); |
| 2425 | else |
| 2426 | system("wan_ipv6_config.sh \"pswan\""); |
| 2427 | |
| 2428 | defwan_set(defwan_if_ipv6); |
| 2429 | |
| 2430 | system("cat /proc/uptime 1>dev/console 2>&1"); |
| 2431 | slog(NET_PRINT, SLOG_NORMAL, "proc_wan_change_v6 data ok \n"); |
| 2432 | |
| 2433 | //Èç¹ûĬÈÏwan¿ÚÓб䣬ÐèÒªÖØÐÂÅäÖ÷ÓÉ¡¢·À»ðǽµÈÐÅÏ¢ |
| 2434 | if (strcmp(defwan6_if_old, defwan_real_ipv6) != 0) { |
| 2435 | zte_router_init(); |
| 2436 | memset(defwan6_if_old, 0, ZTE_ROUTER_WAN_IF_NAME_LEN); |
| 2437 | strncpy(defwan6_if_old, defwan_real_ipv6, sizeof(defwan6_if_old)-1); |
| 2438 | } |
| 2439 | zte_unpn_set(); |
| 2440 | |
| 2441 | net_sendmsg_2_atctl(atoi(cid), V6_VALID, MSG_CMD_LINKUP_END); |
| 2442 | |
| 2443 | system("cat /proc/uptime 1>dev/console 2>&1"); |
| 2444 | slog(NET_PRINT, SLOG_NORMAL, "proc_wan_change_v6 end \n"); |
| 2445 | } |
| 2446 | |
| 2447 | void * msg_timeout(void* arg) |
| 2448 | { |
| 2449 | int ret = 0; |
| 2450 | unsigned char netdev_id = *(unsigned char*)arg; |
| 2451 | |
| 2452 | ret = ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_MAIN_CTRL, MSG_CMD_NET_TIMER_OUT, sizeof(unsigned char), (UCHAR *)&netdev_id, 0); |
| 2453 | if (0 != ret) { |
| 2454 | softap_assert("send msg to zte_mainctrl error"); |
| 2455 | return NULL;//klocwork |
| 2456 | } |
| 2457 | return NULL; |
| 2458 | } |
| 2459 | |
| 2460 | void msg_timedel() |
| 2461 | { |
| 2462 | int ret = 0; |
| 2463 | |
| 2464 | ret = ipc_send_message(MODULE_ID_WEB_CGI, MODULE_ID_MAIN_CTRL, MSG_CMD_NET_TIMER_DEL, 0, 0, 0); |
| 2465 | if (0 != ret) { |
| 2466 | softap_assert("send msg to zte_mainctrl error"); |
| 2467 | return; |
| 2468 | } |
| 2469 | } |
| 2470 | //µ±³¬Ê±ºó£¬ÍøÂçÄÚ²¿Í£Ö¹µØÖ·ÇëÇóÏà¹Ø¶¯×÷£¬²¢·¢ËÍÏûÏ¢¸øÖ÷¿Ø |
| 2471 | void out_of_time(unsigned char netdev_id) |
| 2472 | { |
| 2473 | struct dialfail_dev_info dialfail_dev_info = {0}; |
| 2474 | dialfail_dev_info.ip46flag = V4_VALID; |
| 2475 | dialfail_dev_info.dev_id = netdev_id; |
| 2476 | dialfail_dev_info.dialfail_reason = TIME_OUT; |
| 2477 | char tmp_name[20] = {0}; |
| 2478 | char rj45_pluginstate[NV_NAME_LEN] = {0}; |
| 2479 | int plugstate = 0; |
| 2480 | char wbwanv6_enable[NV_NAME_LEN] = {0}; |
| 2481 | cfg_get_item("wbwanv6_enable", wbwanv6_enable, sizeof(wbwanv6_enable)); |
| 2482 | if (netdev_id == RJ45_WAN_DEV || netdev_id == SW_WAN_DEV) { |
| 2483 | char eth_dev[NV_NAME_LEN] = {0}; |
| 2484 | char cmd[100] = {0}; |
| 2485 | system("wan_ipv4.sh \"linkdown\" \"ethwan\""); |
| 2486 | if(atoi(wbwanv6_enable) == 1) |
| 2487 | system("wan_ipv6.sh \"linkdown\" \"ethwan\""); |
| 2488 | cfg_set("rj45_state", "idle"); |
| 2489 | cfg_get_item("ethwan", eth_dev, sizeof(eth_dev)); |
| 2490 | if (strchr(eth_dev, '.')) { |
| 2491 | set_ethwan_port_mode(0); |
| 2492 | sprintf(cmd, "/sbin/vconfig rem %s", eth_dev); |
| 2493 | zxic_system(cmd); |
| 2494 | |
| 2495 | cfg_get_item("rj45_pluginstate", rj45_pluginstate, sizeof(rj45_pluginstate)); |
| 2496 | plugstate = atoi(rj45_pluginstate); |
| 2497 | if((plugstate & RJ45_LAN_IN) == 0) |
| 2498 | { |
| 2499 | system("landev_updown.sh \"ethlan\" \"down\""); |
| 2500 | vlan_config(RJ45_LAN_DEV, "rem"); |
| 2501 | cfg_set("wanport3_in_lan", "0"); |
| 2502 | } |
| 2503 | } |
| 2504 | } else if (netdev_id == WIFI_WAN_DEV) { |
| 2505 | system("wan_ipv4.sh \"linkdown\" \"wifiwan\""); |
| 2506 | if(atoi(wbwanv6_enable) == 1) |
| 2507 | system("wan_ipv6.sh \"linkdown\" \"wifiwan\""); |
| 2508 | cfg_set("wifi_state", "idle"); |
| 2509 | ipc_send_message(MODULE_ID_MAIN_CTRL, MODULE_ID_WIFI, MSG_CMD_NET_WAN_DIAL_FAIL, 0, NULL, 0); |
| 2510 | } |
| 2511 | |
| 2512 | //Á¬½Ó³¬Ê±Ö®ºó·¢ËÍÏûÏ¢¸øÖ÷¿Ø |
| 2513 | sprintf(tmp_name, "zte_blc"); |
| 2514 | slog(NET_PRINT, SLOG_ERR, "out_of_time: send MSG_CMD_NET_WAN_DIAL_FAIL msg to mainctl,netdev_id=%u\n", dialfail_dev_info.dev_id); |
| 2515 | |
| 2516 | } |
| 2517 | |
| 2518 | void creattimer(unsigned char *netdev_id) |
| 2519 | { |
| 2520 | DeleteSoftTimer(TIMER_MainCtrl_NetID + *netdev_id); |
| 2521 | CreateSoftTimer(TIMER_MainCtrl_NetID + *netdev_id, TIMER_FLAG_ONCE, ConnectWaitTime, msg_timeout, (void*)netdev_id); |
| 2522 | } |
| 2523 | |
| 2524 | |
| 2525 | |
| 2526 | void deletetimer(unsigned char netdev_id) |
| 2527 | { |
| 2528 | slog(NET_PRINT, SLOG_NORMAL, "deletetimer: netdev_id=%u\n", netdev_id); |
| 2529 | DeleteSoftTimer(TIMER_MainCtrl_NetID + netdev_id); |
| 2530 | } |
| 2531 | |
| 2532 | |