| 1 |
/* |
|---|
| 2 |
* network.c |
|---|
| 3 |
* |
|---|
| 4 |
* Copyright (C) 2007 Sebastian Gottschall <gottschall@dd-wrt.com> |
|---|
| 5 |
* |
|---|
| 6 |
* This program is free software; you can redistribute it and/or |
|---|
| 7 |
* modify it under the terms of the GNU General Public License |
|---|
| 8 |
* as published by the Free Software Foundation; either version 2 |
|---|
| 9 |
* of the License. |
|---|
| 10 |
* |
|---|
| 11 |
* This program is distributed in the hope that it will be useful, |
|---|
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 |
* GNU General Public License for more details. |
|---|
| 15 |
* |
|---|
| 16 |
* You should have received a copy of the GNU General Public License |
|---|
| 17 |
* along with this program; if not, write to the Free Software |
|---|
| 18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|---|
| 19 |
* |
|---|
| 20 |
* $Id: |
|---|
| 21 |
*/ |
|---|
| 22 |
|
|---|
| 23 |
#include <stdio.h> |
|---|
| 24 |
#include <stdlib.h> |
|---|
| 25 |
#include <errno.h> |
|---|
| 26 |
#include <syslog.h> |
|---|
| 27 |
#include <ctype.h> |
|---|
| 28 |
#include <string.h> |
|---|
| 29 |
#include <signal.h> |
|---|
| 30 |
#include <unistd.h> |
|---|
| 31 |
#include <math.h> |
|---|
| 32 |
#include <sys/stat.h> |
|---|
| 33 |
#include <sys/ioctl.h> |
|---|
| 34 |
#include <sys/types.h> |
|---|
| 35 |
#include <sys/socket.h> |
|---|
| 36 |
#include <net/if.h> |
|---|
| 37 |
#include <netinet/in.h> |
|---|
| 38 |
#include <arpa/inet.h> |
|---|
| 39 |
#include <net/if_arp.h> |
|---|
| 40 |
#include <sys/sysinfo.h> |
|---|
| 41 |
|
|---|
| 42 |
typedef u_int64_t u64; |
|---|
| 43 |
typedef u_int32_t u32; |
|---|
| 44 |
typedef u_int16_t u16; |
|---|
| 45 |
typedef u_int8_t u8; |
|---|
| 46 |
|
|---|
| 47 |
typedef u_int64_t __u64; |
|---|
| 48 |
typedef u_int32_t __u32; |
|---|
| 49 |
typedef u_int16_t __u16; |
|---|
| 50 |
typedef u_int8_t __u8; |
|---|
| 51 |
|
|---|
| 52 |
#include <limits.h> |
|---|
| 53 |
#include <unistd.h> |
|---|
| 54 |
#include <stdlib.h> |
|---|
| 55 |
#include <stdio.h> |
|---|
| 56 |
#include <stdint.h> |
|---|
| 57 |
#include <fcntl.h> |
|---|
| 58 |
#include <errno.h> |
|---|
| 59 |
#include <error.h> |
|---|
| 60 |
#include <time.h> |
|---|
| 61 |
#include <sys/ioctl.h> |
|---|
| 62 |
#include <sys/types.h> |
|---|
| 63 |
#include <sys/param.h> |
|---|
| 64 |
#include <sys/mount.h> |
|---|
| 65 |
#include <sys/stat.h> |
|---|
| 66 |
#include <sys/reboot.h> |
|---|
| 67 |
#include <sys/sysinfo.h> |
|---|
| 68 |
|
|---|
| 69 |
#include <string.h> |
|---|
| 70 |
#include <linux/version.h> |
|---|
| 71 |
|
|---|
| 72 |
#include <linux/sockios.h> |
|---|
| 73 |
#include <linux/ethtool.h> |
|---|
| 74 |
// #include <libbridge.h> |
|---|
| 75 |
|
|---|
| 76 |
#include <bcmnvram.h> |
|---|
| 77 |
#include <netconf.h> |
|---|
| 78 |
#include <shutils.h> |
|---|
| 79 |
#include <code_pattern.h> |
|---|
| 80 |
#include <wlutils.h> |
|---|
| 81 |
#include <utils.h> |
|---|
| 82 |
#include <rc.h> |
|---|
| 83 |
#include "ledcontrol.h" |
|---|
| 84 |
#include <cy_conf.h> |
|---|
| 85 |
#include <cymac.h> |
|---|
| 86 |
#include <bcmutils.h> |
|---|
| 87 |
#include <nvparse.h> |
|---|
| 88 |
#include <etsockio.h> |
|---|
| 89 |
#include <bcmparams.h> |
|---|
| 90 |
#include <services.h> |
|---|
| 91 |
|
|---|
| 92 |
extern int br_add_bridge(const char *brname); |
|---|
| 93 |
extern int br_del_bridge(const char *brname); |
|---|
| 94 |
extern int br_add_interface(const char *br, const char *dev); |
|---|
| 95 |
extern int br_del_interface(const char *br, const char *dev); |
|---|
| 96 |
extern int br_set_stp_state(const char *br, int stp_state); |
|---|
| 97 |
void start_set_routes(void); |
|---|
| 98 |
|
|---|
| 99 |
#define PTABLE_MAGIC 0xbadc0ded |
|---|
| 100 |
#define PTABLE_SLT1 1 |
|---|
| 101 |
#define PTABLE_SLT2 2 |
|---|
| 102 |
#define PTABLE_ACKW 3 |
|---|
| 103 |
#define PTABLE_ADHM 4 |
|---|
| 104 |
#define PTABLE_END 0xffffffff |
|---|
| 105 |
|
|---|
| 106 |
/* |
|---|
| 107 |
* phy types |
|---|
| 108 |
*/ |
|---|
| 109 |
#define PHY_TYPE_A 0 |
|---|
| 110 |
#define PHY_TYPE_B 1 |
|---|
| 111 |
#define PHY_TYPE_G 2 |
|---|
| 112 |
#define PHY_TYPE_NULL 0xf |
|---|
| 113 |
|
|---|
| 114 |
#define WL_IOCTL(name, cmd, buf, len) (wl_ioctl((name), (cmd), (buf), (len))) |
|---|
| 115 |
|
|---|
| 116 |
#define TXPWR_MAX 251 |
|---|
| 117 |
#define TXPWR_DEFAULT 70 |
|---|
| 118 |
|
|---|
| 119 |
#define IFUP (IFF_UP | IFF_RUNNING | IFF_BROADCAST | IFF_MULTICAST) |
|---|
| 120 |
#define sin_addr(s) (((struct sockaddr_in *)(s))->sin_addr) |
|---|
| 121 |
/* |
|---|
| 122 |
* configure loopback interface |
|---|
| 123 |
*/ |
|---|
| 124 |
void config_loopback(void) |
|---|
| 125 |
{ |
|---|
| 126 |
/* |
|---|
| 127 |
* Bring up loopback interface |
|---|
| 128 |
*/ |
|---|
| 129 |
ifconfig("lo", IFUP, "127.0.0.1", "255.0.0.0"); |
|---|
| 130 |
|
|---|
| 131 |
/* |
|---|
| 132 |
* Add to routing table |
|---|
| 133 |
*/ |
|---|
| 134 |
route_add("lo", 0, "127.0.0.0", "0.0.0.0", "255.0.0.0"); |
|---|
| 135 |
} |
|---|
| 136 |
|
|---|
| 137 |
char *getMacAddr(char *ifname, char *mac) |
|---|
| 138 |
{ |
|---|
| 139 |
unsigned char hwbuff[16]; |
|---|
| 140 |
int i = wl_hwaddr(ifname, hwbuff); |
|---|
| 141 |
|
|---|
| 142 |
if (i < 0) |
|---|
| 143 |
return NULL; |
|---|
| 144 |
sprintf(mac, "%02X:%02X:%02X:%02X:%02X:%02X", hwbuff[0], hwbuff[1], |
|---|
| 145 |
hwbuff[2], hwbuff[3], hwbuff[4], hwbuff[5]); |
|---|
| 146 |
return mac; |
|---|
| 147 |
} |
|---|
| 148 |
|
|---|
| 149 |
static unsigned long ptable[128]; |
|---|
| 150 |
static unsigned long kmem_offset; |
|---|
| 151 |
static inline void wlc_get_mem_offset(void) |
|---|
| 152 |
{ |
|---|
| 153 |
FILE *f; |
|---|
| 154 |
char s[64]; |
|---|
| 155 |
|
|---|
| 156 |
/* |
|---|
| 157 |
* yes, i'm lazy ;) |
|---|
| 158 |
*/ |
|---|
| 159 |
f = popen("grep '\\[wl]' /proc/ksyms | sort", "r"); |
|---|
| 160 |
if (fgets(s, 64, f) == 0) { |
|---|
| 161 |
return; |
|---|
| 162 |
} |
|---|
| 163 |
pclose(f); |
|---|
| 164 |
|
|---|
| 165 |
s[8] = 0; |
|---|
| 166 |
kmem_offset = strtoul(s, NULL, 16); |
|---|
| 167 |
|
|---|
| 168 |
/* |
|---|
| 169 |
* sanity check |
|---|
| 170 |
*/ |
|---|
| 171 |
if (kmem_offset < 0xc0000000) |
|---|
| 172 |
kmem_offset = 0; |
|---|
| 173 |
return; |
|---|
| 174 |
} |
|---|
| 175 |
|
|---|
| 176 |
static int ptable_init(void) |
|---|
| 177 |
{ |
|---|
| 178 |
struct stat statbuf; |
|---|
| 179 |
int fd; |
|---|
| 180 |
|
|---|
| 181 |
if (ptable[0] == PTABLE_MAGIC) |
|---|
| 182 |
return 0; |
|---|
| 183 |
|
|---|
| 184 |
if ((fd = open("/etc/patchtable.bin", O_RDONLY)) < 0) |
|---|
| 185 |
return -1; |
|---|
| 186 |
|
|---|
| 187 |
if (fstat(fd, &statbuf) < 0) |
|---|
| 188 |
goto failed; |
|---|
| 189 |
|
|---|
| 190 |
if (statbuf.st_size < 512) |
|---|
| 191 |
goto failed; |
|---|
| 192 |
|
|---|
| 193 |
// if (lseek(fd, statbuf.st_size - 512, SEEK_SET) < 0) { |
|---|
| 194 |
// perror("lseek"); |
|---|
| 195 |
// goto failed; |
|---|
| 196 |
// } |
|---|
| 197 |
|
|---|
| 198 |
if (read(fd, ptable, 512) < 512) |
|---|
| 199 |
goto failed; |
|---|
| 200 |
|
|---|
| 201 |
if (ptable[0] != PTABLE_MAGIC) |
|---|
| 202 |
goto failed; |
|---|
| 203 |
|
|---|
| 204 |
close(fd); |
|---|
| 205 |
|
|---|
| 206 |
wlc_get_mem_offset(); |
|---|
| 207 |
if (kmem_offset == 0) |
|---|
| 208 |
return -1; |
|---|
| 209 |
|
|---|
| 210 |
return 0; |
|---|
| 211 |
|
|---|
| 212 |
failed: |
|---|
| 213 |
close(fd); |
|---|
| 214 |
|
|---|
| 215 |
return -1; |
|---|
| 216 |
} |
|---|
| 217 |
|
|---|
| 218 |
static inline unsigned long wlc_kmem_read(unsigned long offset) |
|---|
| 219 |
{ |
|---|
| 220 |
int fd; |
|---|
| 221 |
unsigned long ret; |
|---|
| 222 |
|
|---|
| 223 |
if ((fd = open("/dev/kmem", O_RDONLY)) < 0) |
|---|
| 224 |
return -1; |
|---|
| 225 |
|
|---|
| 226 |
lseek(fd, 0x70000000, SEEK_SET); |
|---|
| 227 |
lseek(fd, (kmem_offset - 0x70000000) + offset, SEEK_CUR); |
|---|
| 228 |
read(fd, &ret, 4); |
|---|
| 229 |
close(fd); |
|---|
| 230 |
|
|---|
| 231 |
return ret; |
|---|
| 232 |
} |
|---|
| 233 |
|
|---|
| 234 |
static inline void wlc_kmem_write(unsigned long offset, unsigned long value) |
|---|
| 235 |
{ |
|---|
| 236 |
int fd; |
|---|
| 237 |
|
|---|
| 238 |
if ((fd = open("/dev/kmem", O_WRONLY)) < 0) |
|---|
| 239 |
return; |
|---|
| 240 |
|
|---|
| 241 |
lseek(fd, 0x70000000, SEEK_SET); |
|---|
| 242 |
lseek(fd, (kmem_offset - 0x70000000) + offset, SEEK_CUR); |
|---|
| 243 |
write(fd, &value, 4); |
|---|
| 244 |
close(fd); |
|---|
| 245 |
} |
|---|
| 246 |
|
|---|
| 247 |
static int wlc_patcher_getval(unsigned long key, unsigned long *val) |
|---|
| 248 |
{ |
|---|
| 249 |
unsigned long *pt = &ptable[1]; |
|---|
| 250 |
unsigned long tmp; |
|---|
| 251 |
|
|---|
| 252 |
if (ptable_init() < 0) { |
|---|
| 253 |
fprintf(stderr, "Could not load the ptable\n"); |
|---|
| 254 |
return -1; |
|---|
| 255 |
} |
|---|
| 256 |
|
|---|
| 257 |
while (*pt != PTABLE_END) { |
|---|
| 258 |
if (*pt == key) { |
|---|
| 259 |
tmp = wlc_kmem_read(pt[1]); |
|---|
| 260 |
|
|---|
| 261 |
if (tmp == pt[2]) |
|---|
| 262 |
*val = 0xffffffff; |
|---|
| 263 |
else |
|---|
| 264 |
*val = tmp; |
|---|
| 265 |
|
|---|
| 266 |
return 0; |
|---|
| 267 |
} |
|---|
| 268 |
pt += 3; |
|---|
| 269 |
} |
|---|
| 270 |
|
|---|
| 271 |
return -1; |
|---|
| 272 |
} |
|---|
| 273 |
|
|---|
| 274 |
static int wlc_patcher_setval(unsigned long key, unsigned long val) |
|---|
| 275 |
{ |
|---|
| 276 |
unsigned long *pt = &ptable[1]; |
|---|
| 277 |
|
|---|
| 278 |
if (ptable_init() < 0) { |
|---|
| 279 |
fprintf(stderr, "Could not load the ptable\n"); |
|---|
| 280 |
return -1; |
|---|
| 281 |
} |
|---|
| 282 |
|
|---|
| 283 |
if (val != 0xffffffff) |
|---|
| 284 |
val = (pt[2] & ~(0xffff)) | (val & 0xffff); |
|---|
| 285 |
|
|---|
| 286 |
while (*pt != PTABLE_END) { |
|---|
| 287 |
if (*pt == key) { |
|---|
| 288 |
if (val == 0xffffffff) /* default */ |
|---|
| 289 |
val = pt[2]; |
|---|
| 290 |
|
|---|
| 291 |
wlc_kmem_write(pt[1], val); |
|---|
| 292 |
} |
|---|
| 293 |
pt += 3; |
|---|
| 294 |
} |
|---|
| 295 |
|
|---|
| 296 |
return 0; |
|---|
| 297 |
} |
|---|
| 298 |
|
|---|
| 299 |
/* |
|---|
| 300 |
* static int get_wlc_slottime(wlc_param param, void *data, void *value) { |
|---|
| 301 |
* int *val = (int *) value; int ret = 0; |
|---|
| 302 |
* |
|---|
| 303 |
* ret = wlc_patcher_getval(PTABLE_SLT1, (unsigned long *) val); if (*val != |
|---|
| 304 |
* 0xffffffff) *val &= 0xffff; } return ret; } |
|---|
| 305 |
*/ |
|---|
| 306 |
static int set_wlc_slottime(int value) |
|---|
| 307 |
{ |
|---|
| 308 |
int ret = 0; |
|---|
| 309 |
|
|---|
| 310 |
wlc_patcher_setval(PTABLE_SLT1, value); |
|---|
| 311 |
wlc_patcher_setval(PTABLE_SLT2, ((value == -1) ? value : value + 510)); |
|---|
| 312 |
return ret; |
|---|
| 313 |
} |
|---|
| 314 |
|
|---|
| 315 |
static int wlc_noack(int value) |
|---|
| 316 |
{ |
|---|
| 317 |
int ret = 0; |
|---|
| 318 |
|
|---|
| 319 |
// if ((param & PARAM_MODE) == SET) { |
|---|
| 320 |
wlc_patcher_setval(PTABLE_ACKW, (value ? 1 : 0)); |
|---|
| 321 |
// } else if ((param & PARAM_MODE) == GET) { |
|---|
| 322 |
// ret = wlc_patcher_getval(PTABLE_ACKW, (unsigned long *) val); |
|---|
| 323 |
// *val &= 0xffff; |
|---|
| 324 |
// *val = (*val ? 1 : 0); |
|---|
| 325 |
// } |
|---|
| 326 |
|
|---|
| 327 |
return ret; |
|---|
| 328 |
} |
|---|
| 329 |
|
|---|
| 330 |
#ifndef HAVE_MADWIFI |
|---|
| 331 |
#ifndef HAVE_RT2880 |
|---|
| 332 |
static int notify_nas(char *type, char *ifname, char *action); |
|---|
| 333 |
#endif |
|---|
| 334 |
#endif |
|---|
| 335 |
|
|---|
| 336 |
void start_dhcpc(char *wan_ifname) |
|---|
| 337 |
{ |
|---|
| 338 |
pid_t pid; |
|---|
| 339 |
char *wan_hostname = nvram_get("wan_hostname"); |
|---|
| 340 |
char *vendorclass = nvram_get("dhcpc_vendorclass"); |
|---|
| 341 |
char *requestip = nvram_get("dhcpc_requestip"); |
|---|
| 342 |
|
|---|
| 343 |
symlink("/sbin/rc", "/tmp/udhcpc"); |
|---|
| 344 |
|
|---|
| 345 |
nvram_set("wan_get_dns", ""); |
|---|
| 346 |
killall("udhcpc", SIGTERM); |
|---|
| 347 |
|
|---|
| 348 |
char *dhcp_argv[] = { "udhcpc", |
|---|
| 349 |
"-i", wan_ifname, |
|---|
| 350 |
"-p", "/var/run/udhcpc.pid", |
|---|
| 351 |
"-s", "/tmp/udhcpc", |
|---|
| 352 |
NULL, NULL, |
|---|
| 353 |
NULL, NULL, |
|---|
| 354 |
NULL, NULL, |
|---|
| 355 |
NULL |
|---|
| 356 |
}; |
|---|
| 357 |
|
|---|
| 358 |
int i = 7; |
|---|
| 359 |
|
|---|
| 360 |
if (vendorclass != NULL && strlen(vendorclass) > 0) { |
|---|
| 361 |
dhcp_argv[i] = "-V"; |
|---|
| 362 |
i++; |
|---|
| 363 |
dhcp_argv[i] = vendorclass; |
|---|
| 364 |
i++; |
|---|
| 365 |
} |
|---|
| 366 |
|
|---|
| 367 |
if (requestip != NULL && strlen(requestip) > 0) { |
|---|
| 368 |
dhcp_argv[i] = "-r"; |
|---|
| 369 |
i++; |
|---|
| 370 |
dhcp_argv[i] = requestip; |
|---|
| 371 |
i++; |
|---|
| 372 |
} |
|---|
| 373 |
|
|---|
| 374 |
if (wan_hostname != NULL && strlen(wan_hostname) > 0) { |
|---|
| 375 |
dhcp_argv[i] = "-H"; |
|---|
| 376 |
i++; |
|---|
| 377 |
dhcp_argv[i] = wan_hostname; |
|---|
| 378 |
i++; |
|---|
| 379 |
} |
|---|
| 380 |
|
|---|
| 381 |
_evalpid(dhcp_argv, NULL, 0, &pid); |
|---|
| 382 |
|
|---|
| 383 |
} |
|---|
| 384 |
|
|---|
| 385 |
/* |
|---|
| 386 |
* Enable WET DHCP relay for ethernet clients |
|---|
| 387 |
*/ |
|---|
| 388 |
static int enable_dhcprelay(char *ifname) |
|---|
| 389 |
{ |
|---|
| 390 |
char name[80], *next; |
|---|
| 391 |
|
|---|
| 392 |
dprintf("%s\n", ifname); |
|---|
| 393 |
|
|---|
| 394 |
/* |
|---|
| 395 |
* WET interface is meaningful only in bridged environment |
|---|
| 396 |
*/ |
|---|
| 397 |
if (strncmp(ifname, "br", 2) == 0) { |
|---|
| 398 |
foreach(name, nvram_safe_get("lan_ifnames"), next) { |
|---|
| 399 |
|
|---|
| 400 |
char mode[] = "wlXXXXXXXXXX_mode"; |
|---|
| 401 |
int unit; |
|---|
| 402 |
|
|---|
| 403 |
/* |
|---|
| 404 |
* make sure the interface is indeed of wl |
|---|
| 405 |
*/ |
|---|
| 406 |
if (wl_probe(name)) |
|---|
| 407 |
continue; |
|---|
| 408 |
|
|---|
| 409 |
/* |
|---|
| 410 |
* get the instance number of the wl i/f |
|---|
| 411 |
*/ |
|---|
| 412 |
wl_ioctl(name, WLC_GET_INSTANCE, &unit, sizeof(unit)); |
|---|
| 413 |
snprintf(mode, sizeof(mode), "wl%d_mode", unit); |
|---|
| 414 |
|
|---|
| 415 |
/* |
|---|
| 416 |
* enable DHCP relay, there should be only one WET i/f |
|---|
| 417 |
*/ |
|---|
| 418 |
if (nvram_match(mode, "wet") |
|---|
| 419 |
|| nvram_match(mode, "apstawet")) { |
|---|
| 420 |
uint32 ip; |
|---|
| 421 |
|
|---|
| 422 |
inet_aton(nvram_safe_get("lan_ipaddr"), |
|---|
| 423 |
(struct in_addr *)&ip); |
|---|
| 424 |
if (wl_iovar_setint(name, "wet_host_ipv4", ip)) |
|---|
| 425 |
perror("wet_host_ipv4"); |
|---|
| 426 |
break; |
|---|
| 427 |
} |
|---|
| 428 |
} |
|---|
| 429 |
} |
|---|
| 430 |
return 0; |
|---|
| 431 |
} |
|---|
| 432 |
|
|---|
| 433 |
static int wlconf_up(char *name) |
|---|
| 434 |
{ |
|---|
| 435 |
|
|---|
| 436 |
int phytype, gmode, val, ret; |
|---|
| 437 |
|
|---|
| 438 |
#if defined(HAVE_MADWIFI) || defined(HAVE_RT2880) |
|---|
| 439 |
return -1; |
|---|
| 440 |
#endif |
|---|
| 441 |
if (!strncmp(name, "vlan", 4)) |
|---|
| 442 |
return -1; |
|---|
| 443 |
if (!strncmp(name, "br", 2)) |
|---|
| 444 |
return -1; |
|---|
| 445 |
#ifdef HAVE_ONLYCLIENT |
|---|
| 446 |
if (nvram_match("wl_mode", "ap")) { |
|---|
| 447 |
cprintf("this version does only support the client mode\n"); |
|---|
| 448 |
nvram_set("wl_mode", "sta"); |
|---|
| 449 |
nvram_commit(); |
|---|
| 450 |
} |
|---|
| 451 |
#endif |
|---|
| 452 |
int instance = get_wl_instance(name); |
|---|
| 453 |
|
|---|
| 454 |
if (instance == -1) |
|---|
| 455 |
return -1; // no wireless device |
|---|
| 456 |
if (nvram_nmatch("infra", "wl%d_mode", instance)) { |
|---|
| 457 |
nvram_nset("0", "wl%d_infra", instance); |
|---|
| 458 |
} else { |
|---|
| 459 |
nvram_nset("1", "wl%d_infra", instance); |
|---|
| 460 |
} |
|---|
| 461 |
ret = eval("wlconf", name, "up"); |
|---|
| 462 |
/* |
|---|
| 463 |
* eval("wl","radio","off"); eval("wl","atten","0","0","60"); |
|---|
| 464 |
* eval("wl","lrl","16"); eval("wl","srl","16"); |
|---|
| 465 |
* eval("wl","interference","0"); eval("wl","radio","on"); |
|---|
| 466 |
*/ |
|---|
| 467 |
gmode = atoi(nvram_nget("wl%d_gmode", instance)); |
|---|
| 468 |
|
|---|
| 469 |
/* |
|---|
| 470 |
* Get current phy type |
|---|
| 471 |
*/ |
|---|
| 472 |
WL_IOCTL(name, WLC_GET_PHYTYPE, &phytype, sizeof(phytype)); |
|---|
| 473 |
|
|---|
| 474 |
// set preamble type for b cards |
|---|
| 475 |
if (phytype == PHY_TYPE_B || gmode == 0) { |
|---|
| 476 |
if (nvram_nmatch("long", "wl%d_plcphdr", instance)) |
|---|
| 477 |
val = WLC_PLCP_LONG; |
|---|
| 478 |
else if (nvram_nmatch("short", "wl%d_plcphdr", instance)) |
|---|
| 479 |
val = WLC_PLCP_SHORT; |
|---|
| 480 |
else |
|---|
| 481 |
val = WLC_PLCP_AUTO; |
|---|
| 482 |
WL_IOCTL(name, WLC_SET_PLCPHDR, &val, sizeof(val)); |
|---|
| 483 |
} |
|---|
| 484 |
// adjust txpwr and txant |
|---|
| 485 |
val = atoi(nvram_nget("wl%d_txpwr", instance)); |
|---|
| 486 |
if (val < 1 || val > TXPWR_MAX) |
|---|
| 487 |
val = TXPWR_DEFAULT; |
|---|
| 488 |
char pwr[8]; |
|---|
| 489 |
sprintf(pwr, "%d", val); |
|---|
| 490 |
eval("wl", "-i", name, "txpwr1", "-m", "-o", pwr); |
|---|
| 491 |
/* |
|---|
| 492 |
* Set txant |
|---|
| 493 |
*/ |
|---|
| 494 |
val = atoi(nvram_nget("wl%d_txant", instance)); |
|---|
| 495 |
if (val < 0 || val > 3 || val == 2) |
|---|
| 496 |
val = 3; |
|---|
| 497 |
WL_IOCTL(name, WLC_SET_TXANT, &val, sizeof(val)); |
|---|
| 498 |
|
|---|
| 499 |
/* |
|---|
| 500 |
* if (nvram_match ("boardtype", "bcm94710dev")) { if (val == 0) val = 1; |
|---|
| 501 |
* if (val == 1) val = 0; } |
|---|
| 502 |
*/ |
|---|
| 503 |
val = atoi(nvram_nget("wl%d_antdiv", instance)); |
|---|
| 504 |
WL_IOCTL(name, WLC_SET_ANTDIV, &val, sizeof(val)); |
|---|
| 505 |
|
|---|
| 506 |
/* |
|---|
| 507 |
* search for "afterburner" string |
|---|
| 508 |
*/ |
|---|
| 509 |
char *afterburner = nvram_nget("wl%d_afterburner", instance); |
|---|
| 510 |
|
|---|
| 511 |
if (!strcmp(afterburner, "on")) |
|---|
| 512 |
eval("wl", "-i", name, "afterburner_override", "1"); |
|---|
| 513 |
else if (!strcmp(afterburner, "off")) |
|---|
| 514 |
eval("wl", "-i", name, "afterburner_override", "0"); |
|---|
| 515 |
else // auto |
|---|
| 516 |
eval("wl", "-i", name, "afterburner_override", "-1"); |
|---|
| 517 |
|
|---|
| 518 |
char *shortslot = nvram_nget("wl%d_shortslot", instance); |
|---|
| 519 |
|
|---|
| 520 |
if (!strcmp(shortslot, "long")) |
|---|
| 521 |
eval("wl", "-i", name, "shortslot_override", "0"); |
|---|
| 522 |
else if (!strcmp(shortslot, "short")) |
|---|
| 523 |
eval("wl", "-i", name, "shortslot_override", "1"); |
|---|
| 524 |
else // auto |
|---|
| 525 |
eval("wl", "-i", name, "shortslot_override", "-1"); |
|---|
| 526 |
|
|---|
| 527 |
// Set ACK Timing. Thx to Nbd |
|---|
| 528 |
char *v; |
|---|
| 529 |
|
|---|
| 530 |
if ((v = nvram_nget("wl%d_distance", instance))) { |
|---|
| 531 |
rw_reg_t reg; |
|---|
| 532 |
uint32 shm; |
|---|
| 533 |
|
|---|
| 534 |
val = atoi(v); |
|---|
| 535 |
if (val == 0) { |
|---|
| 536 |
#ifdef HAVE_ACK |
|---|
| 537 |
eval("wl", "-i", name, "noack", "1"); |
|---|
| 538 |
#endif |
|---|
| 539 |
// wlc_noack (0); |
|---|
| 540 |
return 0; |
|---|
| 541 |
} else { |
|---|
| 542 |
#ifdef HAVE_ACK |
|---|
| 543 |
eval("wl", "-i", name, "noack", "0"); |
|---|
| 544 |
#endif |
|---|
| 545 |
// wlc_noack (1); |
|---|
| 546 |
} |
|---|
| 547 |
|
|---|
| 548 |
val = 9 + (val / 150) + ((val % 150) ? 1 : 0); |
|---|
| 549 |
#ifdef HAVE_ACK |
|---|
| 550 |
char strv[32]; |
|---|
| 551 |
|
|---|
| 552 |
sprintf(strv, "%d", val); |
|---|
| 553 |
eval("wl", "-i", name, "acktiming", strv); |
|---|
| 554 |
#endif |
|---|
| 555 |
} |
|---|
| 556 |
|
|---|
| 557 |
/* |
|---|
| 558 |
* if (nvram_match("wl0_mode","sta") || nvram_match("wl0_mode","infra")) |
|---|
| 559 |
* { val = 0; WL_IOCTL(name, WLC_SET_WET, &val, sizeof(val)); if |
|---|
| 560 |
* (nvram_match("wl_mode", "infra")){ val = 0; WL_IOCTL(name, |
|---|
| 561 |
* WLC_SET_INFRA, &val, sizeof(val)); } else{ val = 1; WL_IOCTL(name, |
|---|
| 562 |
* WLC_SET_INFRA, &val, sizeof(val)); } } |
|---|
| 563 |
*/ |
|---|
| 564 |
|
|---|
| 565 |
if (nvram_nmatch("infra", "wl%d_mode", instance)) { |
|---|
| 566 |
eval("wl", "-i", name, "infra", "0"); |
|---|
| 567 |
eval("wl", "-i", name, "ssid", |
|---|
| 568 |
nvram_nget("wl%d_ssid", instance)); |
|---|
| 569 |
} |
|---|
| 570 |
#if !defined(HAVE_MADWIFI) && !defined(HAVE_RT2880) |
|---|
| 571 |
eval("wl", "-i", name, "vlan_mode", "0"); |
|---|
| 572 |
char ifinst[32]; |
|---|
| 573 |
|
|---|
| 574 |
sprintf(ifinst, "wl%d", instance); |
|---|
| 575 |
set_vifsmac(ifinst); |
|---|
| 576 |
#endif |
|---|
| 577 |
return ret; |
|---|
| 578 |
} |
|---|
| 579 |
|
|---|
| 580 |
int isClient(void) |
|---|
| 581 |
{ |
|---|
| 582 |
if (getSTA()) |
|---|
| 583 |
return 1; |
|---|
| 584 |
return 0; |
|---|
| 585 |
|
|---|
| 586 |
} |
|---|
| 587 |
|
|---|
| 588 |
void start_wlconf(void) |
|---|
| 589 |
{ |
|---|
| 590 |
int cnt = get_wl_instances(); |
|---|
| 591 |
int c; |
|---|
| 592 |
|
|---|
| 593 |
for (c = 0; c < cnt; c++) { |
|---|
| 594 |
if (!nvram_nmatch("disabled", "wl%d_net_mode", c)) |
|---|
| 595 |
wlconf_up(get_wl_instance_name(c)); |
|---|
| 596 |
} |
|---|
| 597 |
} |
|---|
| 598 |
|
|---|
| 599 |
// #ifdef HAVE_PORTSETUP |
|---|
| 600 |
#ifdef HAVE_RT2880 |
|---|
| 601 |
#define IFMAP(a) getRADev(a) |
|---|
| 602 |
#else |
|---|
| 603 |
#define IFMAP(a) (a) |
|---|
| 604 |
#endif |
|---|
| 605 |
|
|---|
| 606 |
static void do_portsetup(char *lan, char *ifname) |
|---|
| 607 |
{ |
|---|
| 608 |
char var[64]; |
|---|
| 609 |
char var2[64]; |
|---|
| 610 |
|
|---|
| 611 |
sprintf(var, "%s_bridged", IFMAP(ifname)); |
|---|
| 612 |
if (nvram_default_match(var, "1", "1")) { |
|---|
| 613 |
br_add_interface(getBridge(IFMAP(ifname)), IFMAP(ifname)); |
|---|
| 614 |
} else { |
|---|
| 615 |
ifconfig(ifname, IFUP, nvram_nget("%s_ipaddr", IFMAP(ifname)), |
|---|
| 616 |
nvram_nget("%s_netmask", ifname)); |
|---|
| 617 |
} |
|---|
| 618 |
|
|---|
| 619 |
} |
|---|
| 620 |
|
|---|
| 621 |
// #endif |
|---|
| 622 |
|
|---|
| 623 |
#define PORTSETUPWAN(a) if (strlen(a)>0 && strlen(nvram_safe_get ("wan_ifname2"))>0) \ |
|---|
| 624 |
{ \ |
|---|
| 625 |
nvram_set ("wan_ifname", nvram_safe_get ("wan_ifname2")); \ |
|---|
| 626 |
nvram_set ("wan_ifnames", nvram_safe_get ("wan_ifname2"));\ |
|---|
| 627 |
} \ |
|---|
| 628 |
else \ |
|---|
| 629 |
{ \ |
|---|
| 630 |
nvram_set ("wan_ifname",a); \ |
|---|
| 631 |
nvram_set ("wan_ifnames",a); \ |
|---|
| 632 |
} |
|---|
| 633 |
|
|---|
| 634 |
/* |
|---|
| 635 |
* add wan ifname to lan_ifnames if we use fullswitch |
|---|
| 636 |
*/ |
|---|
| 637 |
void set_fullswitch(void) |
|---|
| 638 |
{ |
|---|
| 639 |
char wanifname[8]; |
|---|
| 640 |
char lanifnames[128]; |
|---|
| 641 |
|
|---|
| 642 |
strcpy(wanifname, nvram_safe_get("wan_ifname")); |
|---|
| 643 |
strcpy(lanifnames, nvram_safe_get("lan_ifnames")); |
|---|
| 644 |
|
|---|
| 645 |
if (nvram_match("fullswitch", "1") |
|---|
| 646 |
&& (getSTA() || getWET() |
|---|
| 647 |
|| nvram_match("wan_proto", "disabled"))) { |
|---|
| 648 |
if (!nvram_match("fullswitch_set", "1")) { |
|---|
| 649 |
nvram_set("lan_default", lanifnames); |
|---|
| 650 |
nvram_set("fullswitch_set", "1"); |
|---|
| 651 |
} |
|---|
| 652 |
sprintf(lanifnames, "%s %s", nvram_safe_get("lan_default"), |
|---|
| 653 |
nvram_safe_get("wan_default")); |
|---|
| 654 |
strcpy(wanifname, ""); |
|---|
| 655 |
} else { |
|---|
| 656 |
if (nvram_match("fullswitch_set", "1")) { |
|---|
| 657 |
strcpy(lanifnames, nvram_safe_get("lan_default")); |
|---|
| 658 |
nvram_unset("lan_default"); |
|---|
| 659 |
strcpy(wanifname, nvram_safe_get("wan_default")); |
|---|
| 660 |
nvram_unset("fullswitch_set"); |
|---|
| 661 |
} |
|---|
| 662 |
} |
|---|
| 663 |
|
|---|
| 664 |
nvram_set("lan_ifnames", lanifnames); |
|---|
| 665 |
nvram_set("wan_ifname", wanifname); |
|---|
| 666 |
nvram_set("wan_ifnames", wanifname); |
|---|
| 667 |
nvram_set("pppoe_wan_ifname", wanifname); |
|---|
| 668 |
nvram_set("pppoe_ifname", wanifname); |
|---|
| 669 |
|
|---|
| 670 |
return; |
|---|
| 671 |
} |
|---|
| 672 |
|
|---|
| 673 |
void reset_hwaddr(char *ifname) |
|---|
| 674 |
{ |
|---|
| 675 |
struct ifreq ifr; |
|---|
| 676 |
char eabuf[32]; |
|---|
| 677 |
int s; |
|---|
| 678 |
if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) |
|---|
| 679 |
return; |
|---|
| 680 |
/* |
|---|
| 681 |
* Get current LAN hardware address |
|---|
| 682 |
*/ |
|---|
| 683 |
|
|---|
| 684 |
strncpy(ifr.ifr_name, ifname, IFNAMSIZ); |
|---|
| 685 |
if (ioctl(s, SIOCGIFHWADDR, &ifr) == 0) { |
|---|
| 686 |
nvram_set("lan_hwaddr", |
|---|
| 687 |
ether_etoa(ifr.ifr_hwaddr.sa_data, eabuf)); |
|---|
| 688 |
if (getRouterBrand() == ROUTER_DLINK_DIR320) { |
|---|
| 689 |
if (strlen(nvram_safe_get("et0macaddr")) == 12) { |
|---|
| 690 |
char wlmac[32]; |
|---|
| 691 |
|
|---|
| 692 |
strcpy(wlmac, nvram_safe_get("wl0_hwaddr")); |
|---|
| 693 |
MAC_SUB(wlmac); |
|---|
| 694 |
nvram_set("et0macaddr", wlmac); |
|---|
| 695 |
nvram_unset("lan_hwaddr"); |
|---|
| 696 |
nvram_unset("wan_hwaddr"); |
|---|
| 697 |
// fis dlink quirk, by restarting system. utils.c will |
|---|
| 698 |
// automaticly assign the et0macaddr then |
|---|
| 699 |
nvram_commit(); |
|---|
| 700 |
eval("event", "5", "1", "15"); |
|---|
| 701 |
} |
|---|
| 702 |
} |
|---|
| 703 |
#ifdef HAVE_RB500 |
|---|
| 704 |
nvram_set("et0macaddr", nvram_safe_get("lan_hwaddr")); |
|---|
| 705 |
#endif |
|---|
| 706 |
#ifdef HAVE_XSCALE |
|---|
| 707 |
#ifndef HAVE_GATEWORX |
|---|
| 708 |
nvram_set("et0macaddr", nvram_safe_get("lan_hwaddr")); |
|---|
| 709 |
#endif |
|---|
| 710 |
#endif |
|---|
| 711 |
#ifdef HAVE_MAGICBOX |
|---|
| 712 |
nvram_set("et0macaddr", nvram_safe_get("lan_hwaddr")); |
|---|
| 713 |
#endif |
|---|
| 714 |
#ifdef HAVE_FONERA |
|---|
| 715 |
nvram_set("et0macaddr", nvram_safe_get("lan_hwaddr")); |
|---|
| 716 |
#endif |
|---|
| 717 |
#ifdef HAVE_RT2880 |
|---|
| 718 |
nvram_set("et0macaddr", nvram_safe_get("lan_hwaddr")); |
|---|
| 719 |
#endif |
|---|
| 720 |
#ifdef HAVE_LS2 |
|---|
| 721 |
nvram_set("et0macaddr", nvram_safe_get("lan_hwaddr")); |
|---|
| 722 |
#endif |
|---|
| 723 |
#ifdef HAVE_LS5 |
|---|
| 724 |
nvram_set("et0macaddr", nvram_safe_get("lan_hwaddr")); |
|---|
| 725 |
#endif |
|---|
| 726 |
#ifdef HAVE_WHRAG108 |
|---|
| 727 |
nvram_set("et0macaddr", nvram_safe_get("lan_hwaddr")); |
|---|
| 728 |
#endif |
|---|
| 729 |
#ifdef HAVE_PB42 |
|---|
| 730 |
nvram_set("et0macaddr", nvram_safe_get("lan_hwaddr")); |
|---|
| 731 |
#endif |
|---|
| 732 |
#ifdef HAVE_LSX |
|---|
| 733 |
nvram_set("et0macaddr", nvram_safe_get("lan_hwaddr")); |
|---|
| 734 |
#endif |
|---|
| 735 |
#ifdef HAVE_DANUBE |
|---|
| 736 |
nvram_set("et0macaddr", nvram_safe_get("lan_hwaddr")); |
|---|
| 737 |
#endif |
|---|
| 738 |
#ifdef HAVE_STORM |
|---|
| 739 |
nvram_set("et0macaddr", nvram_safe_get("lan_hwaddr")); |
|---|
| 740 |
#endif |
|---|
| 741 |
#ifdef HAVE_ADM5120 |
|---|
| 742 |
nvram_set("et0macaddr", nvram_safe_get("lan_hwaddr")); |
|---|
| 743 |
#endif |
|---|
| 744 |
#ifdef HAVE_TW6600 |
|---|
| 745 |
nvram_set("et0macaddr", nvram_safe_get("lan_hwaddr")); |
|---|
| 746 |
#endif |
|---|
| 747 |
#ifdef HAVE_CA8 |
|---|
| 748 |
nvram_set("et0macaddr", nvram_safe_get("lan_hwaddr")); |
|---|
| 749 |
#endif |
|---|
| 750 |
} |
|---|
| 751 |
|
|---|
| 752 |
close(s); |
|---|
| 753 |
|
|---|
| 754 |
} |
|---|
| 755 |
|
|---|
| 756 |
#ifdef HAVE_3G |
|---|
| 757 |
#define CANBRIDGE() (nvram_match( "wan_proto", "disabled" ) || nvram_match( "wan_proto", "3g" )) |
|---|
| 758 |
#else |
|---|
| 759 |
#define CANBRIDGE() nvram_match( "wan_proto", "disabled" ) |
|---|
| 760 |
#endif |
|---|
| 761 |
|
|---|
| 762 |
void start_lan(void) |
|---|
| 763 |
{ |
|---|
| 764 |
if (strlen(nvram_safe_get("wan_default")) > 0) { |
|---|
| 765 |
PORTSETUPWAN(nvram_safe_get("wan_default")); // setup |
|---|
| 766 |
// default |
|---|
| 767 |
// wan ports, |
|---|
| 768 |
// or |
|---|
| 769 |
// reassign |
|---|
| 770 |
// wan if |
|---|
| 771 |
// required |
|---|
| 772 |
// by network |
|---|
| 773 |
// setup |
|---|
| 774 |
set_fullswitch(); // for broadcom - add wan to switch ... |
|---|
| 775 |
} |
|---|
| 776 |
struct ifreq ifr; |
|---|
| 777 |
unsigned char mac[20]; |
|---|
| 778 |
int s; |
|---|
| 779 |
char eabuf[32]; |
|---|
| 780 |
|
|---|
| 781 |
if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) |
|---|
| 782 |
return; |
|---|
| 783 |
|
|---|
| 784 |
#ifdef HAVE_RB500 |
|---|
| 785 |
if (getSTA() || getWET() || CANBRIDGE()) { |
|---|
| 786 |
nvram_set("lan_ifname", "br0"); |
|---|
| 787 |
nvram_set("lan_ifnames", |
|---|
| 788 |
"eth0 eth1 eth2 eth3 eth4 eth5 eth6 eth7 eth8 ath0 ath1 ath2 ath3 ath4 ath5"); |
|---|
| 789 |
PORTSETUPWAN(""); |
|---|
| 790 |
} else { |
|---|
| 791 |
nvram_set("lan_ifname", "br0"); |
|---|
| 792 |
nvram_set("lan_ifnames", |
|---|
| 793 |
"eth1 eth2 eth3 eth4 eth5 eth6 eth7 eth8 ath0 ath1 ath2 ath3 ath4 ath5"); |
|---|
| 794 |
PORTSETUPWAN("eth0"); |
|---|
| 795 |
} |
|---|
| 796 |
|
|---|
| 797 |
strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); |
|---|
| 798 |
ioctl(s, SIOCGIFHWADDR, &ifr); |
|---|
| 799 |
nvram_set("et0macaddr", ether_etoa(ifr.ifr_hwaddr.sa_data, eabuf)); |
|---|
| 800 |
#endif |
|---|
| 801 |
|
|---|
| 802 |
#ifdef HAVE_MAGICBOX |
|---|
| 803 |
if (getSTA() || getWET() || CANBRIDGE()) { |
|---|
| 804 |
nvram_set("lan_ifname", "br0"); |
|---|
| 805 |
nvram_set("lan_ifnames", "eth0 eth1 ath0"); |
|---|
| 806 |
PORTSETUPWAN(""); |
|---|
| 807 |
} else { |
|---|
| 808 |
nvram_set("lan_ifname", "br0"); |
|---|
| 809 |
nvram_set("lan_ifnames", "eth1 ath0"); |
|---|
| 810 |
PORTSETUPWAN("eth0"); |
|---|
| 811 |
} |
|---|
| 812 |
|
|---|
| 813 |
strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); |
|---|
| 814 |
ioctl(s, SIOCGIFHWADDR, &ifr); |
|---|
| 815 |
nvram_set("et0macaddr", ether_etoa(ifr.ifr_hwaddr.sa_data, eabuf)); |
|---|
| 816 |
strcpy(mac, nvram_safe_get("et0macaddr")); |
|---|
| 817 |
MAC_ADD(mac); |
|---|
| 818 |
ether_atoe(mac, ifr.ifr_hwaddr.sa_data); |
|---|
| 819 |
ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER; |
|---|
| 820 |
strncpy(ifr.ifr_name, "eth1", IFNAMSIZ); |
|---|
| 821 |
ioctl(s, SIOCSIFHWADDR, &ifr); |
|---|
| 822 |
#endif |
|---|
| 823 |
#if defined(HAVE_FONERA) && !defined(HAVE_DIR300) && !defined(HAVE_WRT54G2) && !defined(HAVE_MR3202A) |
|---|
| 824 |
if (getRouterBrand() == ROUTER_BOARD_FONERA2200) { |
|---|
| 825 |
if (getSTA() || getWET() || CANBRIDGE()) { |
|---|
| 826 |
nvram_set("lan_ifname", "br0"); |
|---|
| 827 |
nvram_set("lan_ifnames", "vlan0 vlan1 ath0"); |
|---|
| 828 |
PORTSETUPWAN(""); |
|---|
| 829 |
} else { |
|---|
| 830 |
nvram_set("lan_ifname", "br0"); |
|---|
| 831 |
nvram_set("lan_ifnames", "vlan1 vlan0 ath0"); |
|---|
| 832 |
PORTSETUPWAN("vlan1"); |
|---|
| 833 |
} |
|---|
| 834 |
} else { |
|---|
| 835 |
if (getSTA() || getWET() |
|---|
| 836 |
|| CANBRIDGE()) { |
|---|
| 837 |
nvram_set("lan_ifname", "br0"); |
|---|
| 838 |
nvram_set("lan_ifnames", "eth0 ath0"); |
|---|
| 839 |
PORTSETUPWAN(""); |
|---|
| 840 |
} else { |
|---|
| 841 |
nvram_set("lan_ifname", "br0"); |
|---|
| 842 |
nvram_set("lan_ifnames", "eth0 ath0"); |
|---|
| 843 |
PORTSETUPWAN("eth0"); |
|---|
| 844 |
} |
|---|
| 845 |
} |
|---|
| 846 |
strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); |
|---|
| 847 |
ioctl(s, SIOCGIFHWADDR, &ifr); |
|---|
| 848 |
nvram_set("et0macaddr", ether_etoa(ifr.ifr_hwaddr.sa_data, eabuf)); |
|---|
| 849 |
strcpy(mac, nvram_safe_get("et0macaddr")); |
|---|
| 850 |
#endif |
|---|
| 851 |
#ifdef HAVE_WRT54G2 |
|---|
| 852 |
if (getSTA() || getWET() || CANBRIDGE()) { |
|---|
| 853 |
nvram_set("lan_ifname", "br0"); |
|---|
| 854 |
nvram_set("lan_ifnames", "vlan1 vlan2 ath0"); |
|---|
| 855 |
PORTSETUPWAN(""); |
|---|
| 856 |
} else { |
|---|
| 857 |
nvram_set("lan_ifname", "br0"); |
|---|
| 858 |
nvram_set("lan_ifnames", "vlan1 vlan2 ath0"); |
|---|
| 859 |
PORTSETUPWAN("vlan2"); |
|---|
| 860 |
} |
|---|
| 861 |
strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); |
|---|
| 862 |
ioctl(s, SIOCGIFHWADDR, &ifr); |
|---|
| 863 |
nvram_set("et0macaddr", ether_etoa(ifr.ifr_hwaddr.sa_data, eabuf)); |
|---|
| 864 |
strcpy(mac, nvram_safe_get("et0macaddr")); |
|---|
| 865 |
#endif |
|---|
| 866 |
#ifdef HAVE_DIR300 |
|---|
| 867 |
if (getSTA() || getWET() || CANBRIDGE()) { |
|---|
| 868 |
nvram_set("lan_ifname", "br0"); |
|---|
| 869 |
nvram_set("lan_ifnames", "vlan0 vlan2 ath0"); |
|---|
| 870 |
PORTSETUPWAN(""); |
|---|
| 871 |
} else { |
|---|
| 872 |
nvram_set("lan_ifname", "br0"); |
|---|
| 873 |
nvram_set("lan_ifnames", "vlan0 vlan2 ath0"); |
|---|
| 874 |
PORTSETUPWAN("vlan2"); |
|---|
| 875 |
} |
|---|
| 876 |
strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); |
|---|
| 877 |
ioctl(s, SIOCGIFHWADDR, &ifr); |
|---|
| 878 |
nvram_set("et0macaddr", ether_etoa(ifr.ifr_hwaddr.sa_data, eabuf)); |
|---|
| 879 |
strcpy(mac, nvram_safe_get("et0macaddr")); |
|---|
| 880 |
#endif |
|---|
| 881 |
#ifdef HAVE_RS |
|---|
| 882 |
if (getSTA() || getWET() || CANBRIDGE()) { |
|---|
| 883 |
nvram_set("lan_ifname", "br0"); |
|---|
| 884 |
nvram_set("lan_ifnames", "eth0 eth1 ath0 ath1 ath2"); |
|---|
| 885 |
PORTSETUPWAN(""); |
|---|
| 886 |
} else { |
|---|
| 887 |
nvram_set("lan_ifname", "br0"); |
|---|
| 888 |
nvram_set("lan_ifnames", "eth0 eth1 ath0 ath1 ath2"); |
|---|
| 889 |
PORTSETUPWAN("eth0"); |
|---|
| 890 |
} |
|---|
| 891 |
strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); |
|---|
| 892 |
ioctl(s, SIOCGIFHWADDR, &ifr); |
|---|
| 893 |
nvram_set("et0macaddr", ether_etoa(ifr.ifr_hwaddr.sa_data, eabuf)); |
|---|
| 894 |
strcpy(mac, nvram_safe_get("et0macaddr")); |
|---|
| 895 |
#elif HAVE_LSX |
|---|
| 896 |
if (getSTA() || getWET() || CANBRIDGE()) { |
|---|
| 897 |
nvram_set("lan_ifname", "br0"); |
|---|
| 898 |
nvram_set("lan_ifnames", "eth0 ath0"); |
|---|
| 899 |
PORTSETUPWAN(""); |
|---|
| 900 |
} else { |
|---|
| 901 |
nvram_set("lan_ifname", "br0"); |
|---|
| 902 |
nvram_set("lan_ifnames", "eth0 ath0"); |
|---|
| 903 |
PORTSETUPWAN("eth0"); |
|---|
| 904 |
} |
|---|
| 905 |
strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); |
|---|
| 906 |
ioctl(s, SIOCGIFHWADDR, &ifr); |
|---|
| 907 |
nvram_set("et0macaddr", ether_etoa(ifr.ifr_hwaddr.sa_data, eabuf)); |
|---|
| 908 |
strcpy(mac, nvram_safe_get("et0macaddr")); |
|---|
| 909 |
#endif |
|---|
| 910 |
#ifdef HAVE_DANUBE |
|---|
| 911 |
if (getSTA() || getWET() || CANBRIDGE()) { |
|---|
| 912 |
nvram_set("lan_ifname", "br0"); |
|---|
| 913 |
nvram_set("lan_ifnames", "eth0 ath0"); |
|---|
| 914 |
PORTSETUPWAN(""); |
|---|
| 915 |
} else { |
|---|
| 916 |
nvram_set("lan_ifname", "br0"); |
|---|
| 917 |
nvram_set("lan_ifnames", "eth0 ath0"); |
|---|
| 918 |
PORTSETUPWAN("eth0"); |
|---|
| 919 |
} |
|---|
| 920 |
strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); |
|---|
| 921 |
ioctl(s, SIOCGIFHWADDR, &ifr); |
|---|
| 922 |
nvram_set("et0macaddr", ether_etoa(ifr.ifr_hwaddr.sa_data, eabuf)); |
|---|
| 923 |
strcpy(mac, nvram_safe_get("et0macaddr")); |
|---|
| 924 |
#endif |
|---|
| 925 |
#ifdef HAVE_RT2880 |
|---|
| 926 |
if (getRouterBrand() == ROUTER_BOARD_ECB9750) // lets load |
|---|
| 927 |
{ |
|---|
| 928 |
if (getSTA() || getWET() |
|---|
| 929 |
|| CANBRIDGE()) { |
|---|
| 930 |
nvram_set("lan_ifname", "br0"); |
|---|
| 931 |
nvram_set("lan_ifnames", "eth2 ra0"); |
|---|
| 932 |
PORTSETUPWAN(""); |
|---|
| 933 |
} else { |
|---|
| 934 |
nvram_set("lan_ifname", "br0"); |
|---|
| 935 |
nvram_set("lan_ifnames", "eth2 ra0"); |
|---|
| 936 |
PORTSETUPWAN("eth2"); |
|---|
| 937 |
} |
|---|
| 938 |
} else { |
|---|
| 939 |
if (getSTA() || getWET() |
|---|
| 940 |
|| CANBRIDGE()) { |
|---|
| 941 |
nvram_set("lan_ifname", "br0"); |
|---|
| 942 |
nvram_set("lan_ifnames", "vlan1 vlan2 ra0"); |
|---|
| 943 |
PORTSETUPWAN(""); |
|---|
| 944 |
} else { |
|---|
| 945 |
nvram_set("lan_ifname", "br0"); |
|---|
| 946 |
nvram_set("lan_ifnames", "vlan1 vlan2 ra0"); |
|---|
| 947 |
PORTSETUPWAN("vlan2"); |
|---|
| 948 |
} |
|---|
| 949 |
} |
|---|
| 950 |
strncpy(ifr.ifr_name, "eth2", IFNAMSIZ); |
|---|
| 951 |
ioctl(s, SIOCGIFHWADDR, &ifr); |
|---|
| 952 |
nvram_set("et0macaddr", ether_etoa(ifr.ifr_hwaddr.sa_data, eabuf)); |
|---|
| 953 |
strcpy(mac, nvram_safe_get("et0macaddr")); |
|---|
| 954 |
#endif |
|---|
| 955 |
#ifdef HAVE_STORM |
|---|
| 956 |
if (getSTA() || getWET() || CANBRIDGE()) { |
|---|
| 957 |
nvram_set("lan_ifname", "br0"); |
|---|
| 958 |
nvram_set("lan_ifnames", "eth0 ath0"); |
|---|
| 959 |
PORTSETUPWAN(""); |
|---|
| 960 |
} else { |
|---|
| 961 |
nvram_set("lan_ifname", "br0"); |
|---|
| 962 |
nvram_set("lan_ifnames", "eth0 ath0"); |
|---|
| 963 |
PORTSETUPWAN("eth0"); |
|---|
| 964 |
} |
|---|
| 965 |
strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); |
|---|
| 966 |
ioctl(s, SIOCGIFHWADDR, &ifr); |
|---|
| 967 |
nvram_set("et0macaddr", ether_etoa(ifr.ifr_hwaddr.sa_data, eabuf)); |
|---|
| 968 |
strcpy(mac, nvram_safe_get("et0macaddr")); |
|---|
| 969 |
#endif |
|---|
| 970 |
#ifdef HAVE_ADM5120 |
|---|
| 971 |
|
|---|
| 972 |
if (getRouterBrand() == ROUTER_BOARD_WP54G |
|---|
| 973 |
|| getRouterBrand() == ROUTER_BOARD_NP28G) { |
|---|
| 974 |
if (getSTA() || getWET() |
|---|
| 975 |
|| CANBRIDGE()) { |
|---|
| 976 |
nvram_set("lan_ifname", "br0"); |
|---|
| 977 |
nvram_set("lan_ifnames", "eth0 eth1 ath0"); |
|---|
| 978 |
PORTSETUPWAN(""); |
|---|
| 979 |
} else { |
|---|
| 980 |
nvram_set("lan_ifname", "br0"); |
|---|
| 981 |
nvram_set("lan_ifnames", "eth0 eth1 ath0"); |
|---|
| 982 |
PORTSETUPWAN("eth1"); |
|---|
| 983 |
} |
|---|
| 984 |
} else { |
|---|
| 985 |
|
|---|
| 986 |
if (getSTA() || getWET() |
|---|
| 987 |
|| CANBRIDGE()) { |
|---|
| 988 |
nvram_set("lan_ifname", "br0"); |
|---|
| 989 |
nvram_set("lan_ifnames", "eth0 ath0"); |
|---|
| 990 |
PORTSETUPWAN(""); |
|---|
| 991 |
} else { |
|---|
| 992 |
nvram_set("lan_ifname", "br0"); |
|---|
| 993 |
nvram_set("lan_ifnames", "eth0 ath0"); |
|---|
| 994 |
PORTSETUPWAN("eth0"); |
|---|
| 995 |
} |
|---|
| 996 |
} |
|---|
| 997 |
|
|---|
| 998 |
strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); |
|---|
| 999 |
ioctl(s, SIOCGIFHWADDR, &ifr); |
|---|
| 1000 |
nvram_set("et0macaddr", ether_etoa(ifr.ifr_hwaddr.sa_data, eabuf)); |
|---|
| 1001 |
strcpy(mac, nvram_safe_get("et0macaddr")); |
|---|
| 1002 |
#endif |
|---|
| 1003 |
#ifdef HAVE_MR3202A |
|---|
| 1004 |
if (getSTA() || getWET() || CANBRIDGE()) { |
|---|
| 1005 |
nvram_set("lan_ifname", "br0"); |
|---|
| 1006 |
nvram_set("lan_ifnames", "vlan1 vlan2 ath0"); |
|---|
| 1007 |
PORTSETUPWAN(""); |
|---|
| 1008 |
} else { |
|---|
| 1009 |
nvram_set("lan_ifname", "br0"); |
|---|
| 1010 |
nvram_set("lan_ifnames", "vlan1 vlan2 ath0"); |
|---|
| 1011 |
PORTSETUPWAN("vlan2"); |
|---|
| 1012 |
} |
|---|
| 1013 |
strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); |
|---|
| 1014 |
ioctl(s, SIOCGIFHWADDR, &ifr); |
|---|
| 1015 |
nvram_set("et0macaddr", ether_etoa(ifr.ifr_hwaddr.sa_data, eabuf)); |
|---|
| 1016 |
strcpy(mac, nvram_safe_get("et0macaddr")); |
|---|
| 1017 |
#endif |
|---|
| 1018 |
#ifdef HAVE_LS2 |
|---|
| 1019 |
if (getSTA() || getWET() || CANBRIDGE()) { |
|---|
| 1020 |
#if defined(HAVE_NS2) || defined(HAVE_BS2) || defined(HAVE_LC2) || defined(HAVE_BS2HP) || defined(HAVE_MS2) || defined(HAVE_PICO2) || defined(HAVE_PICO2HP) |
|---|
| 1021 |
nvram_set("lan_ifname", "br0"); |
|---|
| 1022 |
nvram_set("lan_ifnames", "eth0 ath0"); |
|---|
| 1023 |
PORTSETUPWAN(""); |
|---|
| 1024 |
#else |
|---|
| 1025 |
nvram_set("lan_ifname", "br0"); |
|---|
| 1026 |
nvram_set("lan_ifnames", "vlan0 vlan2 ath0"); |
|---|
| 1027 |
PORTSETUPWAN(""); |
|---|
| 1028 |
#endif |
|---|
| 1029 |
} else { |
|---|
| 1030 |
#if defined(HAVE_NS2) || defined(HAVE_BS2) || defined(HAVE_LC2) || defined(HAVE_BS2HP) || defined(HAVE_MS2) || defined(HAVE_PICO2) || defined(HAVE_PICO2HP) |
|---|
| 1031 |
nvram_set("lan_ifname", "br0"); |
|---|
| 1032 |
nvram_set("lan_ifnames", "eth0 ath0"); |
|---|
| 1033 |
PORTSETUPWAN("eth0"); |
|---|
| 1034 |
#else |
|---|
| 1035 |
nvram_set("lan_ifname", "br0"); |
|---|
| 1036 |
#ifdef HAVE_BWRG1000 |
|---|
| 1037 |
nvram_set("lan_ifnames", "vlan0 vlan2 ath0"); |
|---|
| 1038 |
PORTSETUPWAN("vlan2"); |
|---|
| 1039 |
#else |
|---|
| 1040 |
nvram_set("lan_ifnames", "vlan0 vlan2 ath0"); |
|---|
| 1041 |
PORTSETUPWAN("vlan0"); |
|---|
| 1042 |
#endif |
|---|
| 1043 |
#endif |
|---|
| 1044 |
} |
|---|
| 1045 |
|
|---|
| 1046 |
strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); |
|---|
| 1047 |
ioctl(s, SIOCGIFHWADDR, &ifr); |
|---|
| 1048 |
nvram_set("et0macaddr", ether_etoa(ifr.ifr_hwaddr.sa_data, eabuf)); |
|---|
| 1049 |
strcpy(mac, nvram_safe_get("et0macaddr")); |
|---|
| 1050 |
#endif |
|---|
| 1051 |
#ifdef HAVE_LS5 |
|---|
| 1052 |
if (getSTA() || getWET() || CANBRIDGE()) { |
|---|
| 1053 |
nvram_set("lan_ifname", "br0"); |
|---|
| 1054 |
nvram_set("lan_ifnames", "eth0 ath0"); |
|---|
| 1055 |
PORTSETUPWAN(""); |
|---|
| 1056 |
} else { |
|---|
| 1057 |
nvram_set("lan_ifname", "br0"); |
|---|
| 1058 |
nvram_set("lan_ifnames", "eth0 ath0"); |
|---|
| 1059 |
PORTSETUPWAN("eth0"); |
|---|
| 1060 |
} |
|---|
| 1061 |
|
|---|
| 1062 |
strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); |
|---|
| 1063 |
ioctl(s, SIOCGIFHWADDR, &ifr); |
|---|
| 1064 |
nvram_set("et0macaddr", ether_etoa(ifr.ifr_hwaddr.sa_data, eabuf)); |
|---|
| 1065 |
strcpy(mac, nvram_safe_get("et0macaddr")); |
|---|
| 1066 |
#endif |
|---|
| 1067 |
#ifdef HAVE_TW6600 |
|---|
| 1068 |
if (getSTA() || getWET() || CANBRIDGE()) { |
|---|
| 1069 |
nvram_set("lan_ifname", "br0"); |
|---|
| 1070 |
nvram_set("lan_ifnames", "eth0 ath0 ath1"); |
|---|
| 1071 |
PORTSETUPWAN(""); |
|---|
| 1072 |
} else { |
|---|
| 1073 |
nvram_set("lan_ifname", "br0"); |
|---|
| 1074 |
nvram_set("lan_ifnames", "eth0 ath0 ath1"); |
|---|
| 1075 |
PORTSETUPWAN("eth0"); |
|---|
| 1076 |
} |
|---|
| 1077 |
|
|---|
| 1078 |
strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); |
|---|
| 1079 |
ioctl(s, SIOCGIFHWADDR, &ifr); |
|---|
| 1080 |
nvram_set("et0macaddr", ether_etoa(ifr.ifr_hwaddr.sa_data, eabuf)); |
|---|
| 1081 |
strcpy(mac, nvram_safe_get("et0macaddr")); |
|---|
| 1082 |
#endif |
|---|
| 1083 |
#ifdef HAVE_PB42 |
|---|
| 1084 |
if (getSTA() || getWET() || CANBRIDGE()) { |
|---|
| 1085 |
nvram_set("lan_ifname", "br0"); |
|---|
| 1086 |
nvram_set("lan_ifnames", "eth0 eth1 ath0 ath1"); |
|---|
| 1087 |
PORTSETUPWAN(""); |
|---|
| 1088 |
} else { |
|---|
| 1089 |
nvram_set("lan_ifname", "br0"); |
|---|
| 1090 |
nvram_set("lan_ifnames", "eth0 eth1 ath0 ath1"); |
|---|
| 1091 |
PORTSETUPWAN("eth0"); |
|---|
| 1092 |
} |
|---|
| 1093 |
|
|---|
| 1094 |
strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); |
|---|
| 1095 |
ioctl(s, SIOCGIFHWADDR, &ifr); |
|---|
| 1096 |
nvram_set("et0macaddr", ether_etoa(ifr.ifr_hwaddr.sa_data, eabuf)); |
|---|
| 1097 |
strcpy(mac, nvram_safe_get("et0macaddr")); |
|---|
| 1098 |
#endif |
|---|
| 1099 |
#ifdef HAVE_WHRAG108 |
|---|
| 1100 |
if (getSTA() || getWET() || CANBRIDGE()) { |
|---|
| 1101 |
nvram_set("lan_ifname", "br0"); |
|---|
| 1102 |
nvram_set("lan_ifnames", "eth0 eth1 ath0 ath1"); |
|---|
| 1103 |
PORTSETUPWAN(""); |
|---|
| 1104 |
} else { |
|---|
| 1105 |
nvram_set("lan_ifname", "br0"); |
|---|
| 1106 |
nvram_set("lan_ifnames", "eth0 eth1 ath0 ath1"); |
|---|
| 1107 |
PORTSETUPWAN("eth1"); |
|---|
| 1108 |
} |
|---|
| 1109 |
|
|---|
| 1110 |
strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); |
|---|
| 1111 |
ioctl(s, SIOCGIFHWADDR, &ifr); |
|---|
| 1112 |
nvram_set("et0macaddr", ether_etoa(ifr.ifr_hwaddr.sa_data, eabuf)); |
|---|
| 1113 |
strcpy(mac, nvram_safe_get("et0macaddr")); |
|---|
| 1114 |
#endif |
|---|
| 1115 |
#ifdef HAVE_CA8 |
|---|
| 1116 |
if (getSTA() || getWET() || CANBRIDGE()) { |
|---|
| 1117 |
if (getRouterBrand() == ROUTER_BOARD_CA8PRO) { |
|---|
| 1118 |
nvram_set("lan_ifname", "br0"); |
|---|
| 1119 |
nvram_set("lan_ifnames", "vlan0 vlan1 ath0"); |
|---|
| 1120 |
PORTSETUPWAN(""); |
|---|
| 1121 |
} else if (getRouterBrand() == ROUTER_BOARD_RCAA01) { |
|---|
| 1122 |
nvram_set("lan_ifname", "br0"); |
|---|
| 1123 |
nvram_set("lan_ifnames", "vlan0 vlan1 ath0 ath1"); |
|---|
| 1124 |
PORTSETUPWAN(""); |
|---|
| 1125 |
} else if (getRouterBrand() == ROUTER_BOARD_RDAT81) { |
|---|
| 1126 |
nvram_set("lan_ifname", "br0"); |
|---|
| 1127 |
nvram_set("lan_ifnames", "eth0 ath0 ath1"); |
|---|
| 1128 |
PORTSETUPWAN(""); |
|---|
| 1129 |
} else { |
|---|
| 1130 |
nvram_set("lan_ifname", "br0"); |
|---|
| 1131 |
nvram_set("lan_ifnames", "eth0 ath0"); |
|---|
| 1132 |
PORTSETUPWAN(""); |
|---|
| 1133 |
} |
|---|
| 1134 |
} else { |
|---|
| 1135 |
if (getRouterBrand() == ROUTER_BOARD_CA8PRO) { |
|---|
| 1136 |
nvram_set("lan_ifname", "br0"); |
|---|
| 1137 |
nvram_set("lan_ifnames", "vlan0 vlan1 ath0"); |
|---|
| 1138 |
PORTSETUPWAN("vlan1"); |
|---|
| 1139 |
} else if (getRouterBrand() == ROUTER_BOARD_RCAA01) { |
|---|
| 1140 |
nvram_set("lan_ifname", "br0"); |
|---|
| 1141 |
nvram_set("lan_ifnames", "vlan0 vlan1 ath0 ath1"); |
|---|
| 1142 |
PORTSETUPWAN("vlan1"); |
|---|
| 1143 |
} else if (getRouterBrand() == ROUTER_BOARD_RDAT81) { |
|---|
| 1144 |
nvram_set("lan_ifname", "br0"); |
|---|
| 1145 |
nvram_set("lan_ifnames", "eth0 ath0 ath1"); |
|---|
| 1146 |
PORTSETUPWAN("eth0"); |
|---|
| 1147 |
} else { |
|---|
| 1148 |
nvram_set("lan_ifname", "br0"); |
|---|
| 1149 |
nvram_set("lan_ifnames", "eth0 ath0"); |
|---|
| 1150 |
PORTSETUPWAN("eth0"); |
|---|
| 1151 |
} |
|---|
| 1152 |
} |
|---|
| 1153 |
|
|---|
| 1154 |
strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); |
|---|
| 1155 |
ioctl(s, SIOCGIFHWADDR, &ifr); |
|---|
| 1156 |
nvram_set("et0macaddr", ether_etoa(ifr.ifr_hwaddr.sa_data, eabuf)); |
|---|
| 1157 |
strcpy(mac, nvram_safe_get("et0macaddr")); |
|---|
| 1158 |
#endif |
|---|
| 1159 |
#ifdef HAVE_GATEWORX |
|---|
| 1160 |
if (getSTA() || getWET() || CANBRIDGE()) { |
|---|
| 1161 |
if (getRouterBrand() == ROUTER_BOARD_GATEWORX_SWAP) { |
|---|
| 1162 |
nvram_set("lan_ifname", "br0"); |
|---|
| 1163 |
if (nvram_match("intel_eth", "1")) |
|---|
| 1164 |
nvram_set("lan_ifnames", |
|---|
| 1165 |
"ixp0 eth0 eth1 ath0 ath1 ath2 ath3 ofdm"); |
|---|
| 1166 |
else |
|---|
| 1167 |
nvram_set("lan_ifnames", |
|---|
| 1168 |
"ixp0 ath0 ath1 ath2 ath3 ofdm"); |
|---|
| 1169 |
PORTSETUPWAN(""); |
|---|
| 1170 |
} else if (getRouterBrand() == ROUTER_BOARD_GATEWORX_GW2345) { |
|---|
| 1171 |
nvram_set("lan_ifname", "br0"); |
|---|
| 1172 |
if (nvram_match("intel_eth", "1")) |
|---|
| 1173 |
nvram_set("lan_ifnames", |
|---|
| 1174 |
"ixp0 ixp1 eth0 eth1 ath0 ath1 ath2 ath3 ofdm"); |
|---|
| 1175 |
else |
|---|
| 1176 |
nvram_set("lan_ifnames", |
|---|
| 1177 |
"ixp0 ixp1 ath0 ath1 ath2 ath3 ofdm"); |
|---|
| 1178 |
PORTSETUPWAN(""); |
|---|
| 1179 |
} else { |
|---|
| 1180 |
nvram_set("lan_ifname", "br0"); |
|---|
| 1181 |
if (nvram_match("intel_eth", "1")) |
|---|
| 1182 |
nvram_set("lan_ifnames", |
|---|
| 1183 |
"ixp0 ixp1 eth0 eth1 ath0 ath1 ath2 ath3 ofdm"); |
|---|
| 1184 |
else |
|---|
| 1185 |
nvram_set("lan_ifnames", |
|---|
| 1186 |
"ixp0 ixp1 ath0 ath1 ath2 ath3 ofdm"); |
|---|
| 1187 |
PORTSETUPWAN(""); |
|---|
| 1188 |
} |
|---|
| 1189 |
} else { |
|---|
| 1190 |
if (getRouterBrand() == ROUTER_BOARD_GATEWORX_SWAP) { |
|---|
| 1191 |
nvram_set("lan_ifname", "br0"); |
|---|
| 1192 |
if (nvram_match("intel_eth", "1")) |
|---|
| 1193 |
nvram_set("lan_ifnames", |
|---|
| 1194 |
"eth0 eth1 ixp0 ath0 ath1 ath2 ath3 ofdm"); |
|---|
| 1195 |
else |
|---|
| 1196 |
nvram_set("lan_ifnames", |
|---|
| 1197 |
"ixp0 ath0 ath1 ath2 ath3 ofdm"); |
|---|
| 1198 |
PORTSETUPWAN("ixp0"); |
|---|
| 1199 |
} else if (getRouterBrand() == ROUTER_BOARD_GATEWORX_GW2345) { |
|---|
| 1200 |
nvram_set("lan_ifname", "br0"); |
|---|
| 1201 |
if (nvram_match("intel_eth", "1")) |
|---|
| 1202 |
nvram_set("lan_ifnames", |
|---|
| 1203 |
"eth0 eth1 ixp0 ixp1 ath0 ath1 ath2 ath3 ofdm"); |
|---|
| 1204 |
else |
|---|
| 1205 |
nvram_set("lan_ifnames", |
|---|
| 1206 |
"ixp0 ixp1 ath0 ath1 ath2 ath3 ofdm"); |
|---|
| 1207 |
PORTSETUPWAN("ixp1"); |
|---|
| 1208 |
} else { |
|---|
| 1209 |
#ifdef HAVE_XIOCOM |
|---|
| 1210 |
nvram_set("lan_ifname", "br0"); |
|---|
| 1211 |
if (nvram_match("intel_eth", "1")) |
|---|
| 1212 |
nvram_set("lan_ifnames", |
|---|
| 1213 |
"eth0 eth1 ixp0 ixp1 ath0 ath1 ath2 ath3 ofdm"); |
|---|
| 1214 |
else |
|---|
| 1215 |
nvram_set("lan_ifnames", |
|---|
| 1216 |
"ixp0 ixp1 ath0 ath1 ath2 ath3 ofdm"); |
|---|
| 1217 |
|
|---|
| 1218 |
PORTSETUPWAN("ixp0"); |
|---|
| 1219 |
|
|---|
| 1220 |
#else |
|---|
| 1221 |
nvram_set("lan_ifname", "br0"); |
|---|
| 1222 |
if (nvram_match("intel_eth", "1")) |
|---|
| 1223 |
nvram_set("lan_ifnames", |
|---|
| 1224 |
"eth0 eth1 ixp0 ixp1 ath0 ath1 ath2 ath3 ofdm"); |
|---|
| 1225 |
else |
|---|
| 1226 |
nvram_set("lan_ifnames", |
|---|
| 1227 |
"ixp0 ixp1 ath0 ath1 ath2 ath3 ofdm"); |
|---|
| 1228 |
|
|---|
| 1229 |
PORTSETUPWAN("ixp1"); |
|---|
| 1230 |
#endif |
|---|
| 1231 |
} |
|---|
| 1232 |
} |
|---|
| 1233 |
strncpy(ifr.ifr_name, "ixp0", IFNAMSIZ); |
|---|
| 1234 |
if (ioctl(s, SIOCGIFHWADDR, &ifr) != 0) { |
|---|
| 1235 |
strncpy(ifr.ifr_name, "ixp0", IFNAMSIZ); |
|---|
| 1236 |
ioctl(s, SIOCGIFHWADDR, &ifr); |
|---|
| 1237 |
} |
|---|
| 1238 |
nvram_set("et0macaddr", ether_etoa(ifr.ifr_hwaddr.sa_data, eabuf)); |
|---|
| 1239 |
/* |
|---|
| 1240 |
* strncpy (ifr.ifr_name, "ixp1", IFNAMSIZ); ioctl (s, SIOCGIFHWADDR, |
|---|
| 1241 |
* &ifr); nvram_set ("et0macaddr", ether_etoa (ifr.ifr_hwaddr.sa_data, |
|---|
| 1242 |
* eabuf)); strcpy (mac, nvram_safe_get ("et0macaddr")); MAC_ADD (mac); |
|---|
| 1243 |
* ether_atoe (mac, ifr.ifr_hwaddr.sa_data); ifr.ifr_hwaddr.sa_family = |
|---|
| 1244 |
* ARPHRD_ETHER; strncpy (ifr.ifr_name, "eth1", IFNAMSIZ); ioctl (s, |
|---|
| 1245 |
* SIOCSIFHWADDR, &ifr); |
|---|
| 1246 |
*/ |
|---|
| 1247 |
#endif |
|---|
| 1248 |
#ifdef HAVE_X86 |
|---|
| 1249 |
if (getSTA() || getWET()) { |
|---|
| 1250 |
nvram_set("lan_ifname", "br0"); |
|---|
| 1251 |
#ifdef HAVE_NOWIFI |
|---|
| 1252 |
nvram_set("lan_ifnames", |
|---|
| 1253 |
"eth0 eth1 eth2 eth3 eth4 eth5 eth6 eth7 eth8 eth9 eth10"); |
|---|
| 1254 |
#else |
|---|
| 1255 |
if (nvram_match("wifi_bonding", "1")) |
|---|
| 1256 |
nvram_set("lan_ifnames", |
|---|
| 1257 |
"eth0 eth1 eth2 eth3 eth4 eth5 eth6 eth7 eth8 eth9 eth10 bond0"); |
|---|
| 1258 |
else |
|---|
| 1259 |
nvram_set("lan_ifnames", |
|---|
| 1260 |
"eth0 eth1 eth2 eth3 eth4 eth5 eth6 eth7 eth8 eth9 eth10 ath0 ath1 ath2 ath3 ath4 ath5 ath6 ath7 ath8"); |
|---|
| 1261 |
|
|---|
| 1262 |
#endif |
|---|
| 1263 |
PORTSETUPWAN(""); |
|---|
| 1264 |
} else if (CANBRIDGE()) { |
|---|
| 1265 |
nvram_set("lan_ifname", "br0"); |
|---|
| 1266 |
#ifdef HAVE_NOWIFI |
|---|
| 1267 |
nvram_set("lan_ifnames", |
|---|
| 1268 |
"eth0 eth1 eth2 eth3 eth4 eth5 eth6 eth7 eth8 eth9 eth10"); |
|---|
| 1269 |
#else |
|---|
| 1270 |
if (nvram_match("wifi_bonding", "1")) |
|---|
| 1271 |
nvram_set("lan_ifnames", |
|---|
| 1272 |
"eth0 eth1 eth2 eth3 eth4 eth5 eth6 eth7 eth8 eth9 eth10 bond0"); |
|---|
| 1273 |
else |
|---|
| 1274 |
nvram_set("lan_ifnames", |
|---|
| 1275 |
"eth0 eth1 eth2 eth3 eth4 eth5 eth6 eth7 eth8 eth9 eth10 ath0 ath1 ath2 ath3 ath4 ath5 ath6 ath7 ath8"); |
|---|
| 1276 |
#endif |
|---|
| 1277 |
PORTSETUPWAN(""); |
|---|
| 1278 |
} else { |
|---|
| 1279 |
nvram_set("lan_ifname", "br0"); |
|---|
| 1280 |
#ifdef HAVE_NOWIFI |
|---|
| 1281 |
nvram_set("lan_ifnames", |
|---|
| 1282 |
"eth0 eth1 eth2 eth3 eth4 eth5 eth6 eth7 eth8 eth9 eth10"); |
|---|
| 1283 |
#else |
|---|
| 1284 |
if (nvram_match("wifi_bonding", "1")) |
|---|
| 1285 |
nvram_set("lan_ifnames", |
|---|
| 1286 |
"eth0 eth1 eth2 eth3 eth4 eth5 eth6 eth7 eth8 eth9 eth10 bond0"); |
|---|
| 1287 |
else |
|---|
| 1288 |
nvram_set("lan_ifnames", |
|---|
| 1289 |
"eth0 eth1 eth2 eth3 eth4 eth5 eth6 eth7 eth8 eth9 eth10 ath0 ath1 ath2 ath3 ath4 ath5 ath6 ath7 ath8"); |
|---|
| 1290 |
#endif |
|---|
| 1291 |
#ifdef HAVE_GW700 |
|---|
| 1292 |
PORTSETUPWAN("eth1"); |
|---|
| 1293 |
#else |
|---|
| 1294 |
PORTSETUPWAN("eth0"); |
|---|
| 1295 |
#endif |
|---|
| 1296 |
|
|---|
| 1297 |
} |
|---|
| 1298 |
strncpy(ifr.ifr_name, "eth0", IFNAMSIZ); |
|---|
| 1299 |
ioctl(s, SIOCGIFHWADDR, &ifr); |
|---|
| 1300 |
nvram_set("et0macaddr", ether_etoa(ifr.ifr_hwaddr.sa_data, eabuf)); |
|---|
| 1301 |
|
|---|
| 1302 |
/* |
|---|
| 1303 |
* strncpy (ifr.ifr_name, "ixp1", IFNAMSIZ); ioctl (s, SIOCGIFHWADDR, |
|---|
| 1304 |
* &ifr); nvram_set ("et0macaddr", ether_etoa (ifr.ifr_hwaddr.sa_data, |
|---|
| 1305 |
* eabuf)); strcpy (mac, nvram_safe_get ("et0macaddr")); MAC_ADD (mac); |
|---|
| 1306 |
* ether_atoe (mac, ifr.ifr_hwaddr.sa_data); ifr.ifr_hwaddr.sa_family = |
|---|
| 1307 |
* ARPHRD_ETHER; strncpy (ifr.ifr_name, "eth1", IFNAMSIZ); ioctl (s, |
|---|
| 1308 |
* SIOCSIFHWADDR, &ifr); |
|---|
| 1309 |
*/ |
|---|
| 1310 |
#endif |
|---|
| 1311 |
char *lan_ifname = strdup(nvram_safe_get("lan_ifname")); |
|---|
| 1312 |
char *wan_ifname = strdup(nvram_safe_get("wan_ifname")); |
|---|
| 1313 |
char *lan_ifnames = strdup(nvram_safe_get("lan_ifnames")); |
|---|
| 1314 |
char name[80], *next, *svbuf; |
|---|
| 1315 |
char realname[80]; |
|---|
| 1316 |
char wl_face[10]; |
|---|
| 1317 |
|
|---|
| 1318 |
strcpy(lan_ifname, nvram_safe_get("lan_ifname")); |
|---|
| 1319 |
strcpy(wan_ifname, nvram_safe_get("wan_ifname")); |
|---|
| 1320 |
strcpy(lan_ifnames, nvram_safe_get("lan_ifnames")); |
|---|
| 1321 |
|
|---|
| 1322 |
cprintf("%s\n", lan_ifname); |
|---|
| 1323 |
|
|---|
| 1324 |
// If running in client-mode, remove old WAN-configuration |
|---|
| 1325 |
if (getSTA()) { |
|---|
| 1326 |
// #ifdef HAVE_SKYTRON |
|---|
| 1327 |
// ifconfig(wan_ifname,IFUP,"172.16.1.1","255.255.255.0"); |
|---|
| 1328 |
// #else |
|---|
| 1329 |
ifconfig(wan_ifname, IFUP, "0.0.0.0", NULL); |
|---|
| 1330 |
// #endif |
|---|
| 1331 |
|
|---|
| 1332 |
} |
|---|
| 1333 |
// find wireless interface |
|---|
| 1334 |
diag_led(DIAG, STOP_LED); // stop that blinking |
|---|
| 1335 |
strcpy(wl_face, get_wdev()); |
|---|
| 1336 |
#if defined(HAVE_MADWIFI) || defined(HAVE_RT2880) |
|---|
| 1337 |
#ifndef HAVE_NOWIFI |
|---|
| 1338 |
deconfigure_wifi(); |
|---|
| 1339 |
#endif |
|---|
| 1340 |
#else |
|---|
| 1341 |
eval("wlconf", wl_face, "down"); |
|---|
| 1342 |
#endif |
|---|
| 1343 |
#ifdef HAVE_WAVESAT |
|---|
| 1344 |
deconfigure_wimax(); |
|---|
| 1345 |
#endif |
|---|
| 1346 |
|
|---|
| 1347 |
/* |
|---|
| 1348 |
* you gotta bring it down before you can set its MAC |
|---|
| 1349 |
*/ |
|---|
| 1350 |
cprintf("configure wl_face %s\n", wl_face); |
|---|
| 1351 |
ifconfig(wl_face, 0, 0, 0); |
|---|
| 1352 |
#if !defined(HAVE_MADWIFI) && !defined(HAVE_RT2880) |
|---|
| 1353 |
|
|---|
| 1354 |
if (nvram_match("mac_clone_enable", "1") && |
|---|
| 1355 |
nvram_invmatch("def_whwaddr", "00:00:00:00:00:00") && |
|---|
| 1356 |
nvram_invmatch("def_whwaddr", "")) { |
|---|
| 1357 |
ether_atoe(nvram_safe_get("def_whwaddr"), |
|---|
| 1358 |
ifr.ifr_hwaddr.sa_data); |
|---|
| 1359 |
|
|---|
| 1360 |
} else { |
|---|
| 1361 |
getWirelessMac(mac); |
|---|
| 1362 |
|
|---|
| 1363 |
ether_atoe(mac, ifr.ifr_hwaddr.sa_data); |
|---|
| 1364 |
|
|---|
| 1365 |
if (nvram_match("wl0_hwaddr", "") || !nvram_get("wl0_hwaddr")) { |
|---|
| 1366 |
nvram_set("wl0_hwaddr", mac); |
|---|
| 1367 |
nvram_commit(); |
|---|
| 1368 |
} |
|---|
| 1369 |
} |
|---|
| 1370 |
/* |
|---|
| 1371 |
* Write wireless mac |
|---|
| 1372 |
*/ |
|---|
| 1373 |
cprintf("Write wireless mac\n"); |
|---|
| 1374 |
ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER; |
|---|
| 1375 |
strncpy(ifr.ifr_name, wl_face, IFNAMSIZ); |
|---|
| 1376 |
|
|---|
| 1377 |
eval("wl", "-i", wl_face, "down"); |
|---|
| 1378 |
if (ioctl(s, SIOCSIFHWADDR, &ifr) == -1) |
|---|
| 1379 |
perror("Write wireless mac fail : "); |
|---|
| 1380 |
else |
|---|
| 1381 |
cprintf("Write wireless mac successfully\n"); |
|---|
| 1382 |
eval("wl", "-i", wl_face, "up"); |
|---|
| 1383 |
start_config_macs(wl_face); |
|---|
| 1384 |
#endif |
|---|
| 1385 |
if (getSTA()) { |
|---|
| 1386 |
unsigned char mac[20]; |
|---|
| 1387 |
|
|---|
| 1388 |
getWANMac(mac); |
|---|
| 1389 |
|
|---|
| 1390 |
nvram_set("wan_hwaddr", mac); |
|---|
| 1391 |
} |
|---|
| 1392 |
|
|---|
| 1393 |
cprintf("wl_face up %s\n", wl_face); |
|---|
| 1394 |
ifconfig(wl_face, IFUP, 0, 0); |
|---|
| 1395 |
#ifdef HAVE_MICRO |
|---|
| 1396 |
br_init(); |
|---|
| 1397 |
#endif |
|---|
| 1398 |
/* |
|---|
| 1399 |
* Bring up bridged interface |
|---|
| 1400 |
*/ |
|---|
| 1401 |
#ifdef HAVE_EAD |
|---|
| 1402 |
char eadline[64]; |
|---|
| 1403 |
|
|---|
| 1404 |
memset(eadline, 0, 64); |
|---|
| 1405 |
#endif |
|---|
| 1406 |
|
|---|
| 1407 |
if (strncmp(lan_ifname, "br0", 3) == 0) { |
|---|
| 1408 |
br_add_bridge(lan_ifname); |
|---|
| 1409 |
if (nvram_match("lan_stp", "0")) |
|---|
| 1410 |
br_set_stp_state(lan_ifname, 0); |
|---|
| 1411 |
else |
|---|
| 1412 |
br_set_stp_state(lan_ifname, 1); |
|---|
| 1413 |
#ifdef HAVE_MICRO |
|---|
| 1414 |
br_set_bridge_forward_delay(lan_ifname, 1); |
|---|
| 1415 |
#else |
|---|
| 1416 |
br_set_bridge_forward_delay(lan_ifname, 1); |
|---|
| 1417 |
#endif |
|---|
| 1418 |
#ifdef HAVE_EAD |
|---|
| 1419 |
eval("killall", "-9", "ead"); |
|---|
| 1420 |
#endif |
|---|
| 1421 |
foreach(name, lan_ifnames, next) { |
|---|
| 1422 |
if (!ifexists(name)) |
|---|
| 1423 |
continue; |
|---|
| 1424 |
#ifdef HAVE_EAD |
|---|
| 1425 |
#if defined(HAVE_RT2880) || defined(HAVE_MADWIFI) |
|---|
| 1426 |
if (strncmp(name, "ath", 3) && strncmp(name, "ra", 2)) |
|---|
| 1427 |
#else |
|---|
| 1428 |
if (wl_probe(name)) |
|---|
| 1429 |
#endif |
|---|
| 1430 |
sprintf(eadline, "%s%s %s ", eadline, "-d", |
|---|
| 1431 |
name); |
|---|
| 1432 |
#endif |
|---|
| 1433 |
if (nvram_match("wan_ifname", name)) |
|---|
| 1434 |
continue; |
|---|
| 1435 |
#if defined(HAVE_MADWIFI) && !defined(HAVE_RB500) && !defined(HAVE_XSCALE) && !defined(HAVE_MAGICBOX) && !defined(HAVE_FONERA) && !defined(HAVE_WHRAG108) && !defined(HAVE_X86) && !defined(HAVE_LS2) && !defined(HAVE_LS5) && !defined(HAVE_CA8) && !defined(HAVE_TW6600) && !defined(HAVE_PB42) && !defined(HAVE_LSX) && !defined(HAVE_DANUBE) && !defined(HAVE_STORM) && !defined(HAVE_ADM5120) && !defined(HAVE_RT2880) |
|---|
| 1436 |
if (!strcmp(name, "eth2")) { |
|---|
| 1437 |
strcpy(realname, "ath0"); |
|---|
| 1438 |
} else |
|---|
| 1439 |
#endif |
|---|
| 1440 |
strcpy(realname, name); |
|---|
| 1441 |
|
|---|
| 1442 |
cprintf("name=[%s] lan_ifname=[%s]\n", realname, |
|---|
| 1443 |
lan_ifname); |
|---|
| 1444 |
|
|---|
| 1445 |
/* |
|---|
| 1446 |
* Bring up interface |
|---|
| 1447 |
*/ |
|---|
| 1448 |
if (ifconfig(realname, IFUP, "0.0.0.0", NULL)) |
|---|
| 1449 |
continue; |
|---|
| 1450 |
|
|---|
| 1451 |
// set proper mtu |
|---|
| 1452 |
eval("ifconfig", realname, "mtu", getMTU(realname)); |
|---|
| 1453 |
|
|---|
| 1454 |
/* |
|---|
| 1455 |
* Set the logical bridge address to that of the first interface |
|---|
| 1456 |
*/ |
|---|
| 1457 |
|
|---|
| 1458 |
#if !defined(HAVE_MADWIFI) && !defined(HAVE_RT2880) |
|---|
| 1459 |
strncpy(ifr.ifr_name, lan_ifname, IFNAMSIZ); |
|---|
| 1460 |
if (ioctl(s, SIOCGIFHWADDR, &ifr) == 0 && |
|---|
| 1461 |
memcmp(ifr.ifr_hwaddr.sa_data, "\0\0\0\0\0\0", |
|---|
| 1462 |
ETHER_ADDR_LEN) == 0 |
|---|
| 1463 |
&& strcmp(wl_face, realname) == 0) { |
|---|
| 1464 |
strncpy(ifr.ifr_name, realname, IFNAMSIZ); |
|---|
| 1465 |
if (ioctl(s, SIOCGIFHWADDR, &ifr) == 0) { |
|---|
| 1466 |
strncpy(ifr.ifr_name, lan_ifname, |
|---|
| 1467 |
IFNAMSIZ); |
|---|
| 1468 |
ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER; |
|---|
| 1469 |
ioctl(s, SIOCSIFHWADDR, &ifr); |
|---|
| 1470 |
cprintf("=====> set %s hwaddr to %s\n", |
|---|
| 1471 |
lan_ifname, realname); |
|---|
| 1472 |
} else |
|---|
| 1473 |
perror(lan_ifname); |
|---|
| 1474 |
} else |
|---|
| 1475 |
perror(lan_ifname); |
|---|
| 1476 |
#endif |
|---|
| 1477 |
/* |
|---|
| 1478 |
* If not a wl i/f then simply add it to the bridge |
|---|
| 1479 |
*/ |
|---|
| 1480 |
#if !defined(HAVE_MADWIFI) && !defined(HAVE_RT2880) |
|---|
| 1481 |
if (wlconf_up(name)) { |
|---|
| 1482 |
// #ifdef HAVE_PORTSETUP |
|---|
| 1483 |
do_portsetup(lan_ifname, name); |
|---|
| 1484 |
// #else |
|---|
| 1485 |
// br_add_interface (getBridge (name), name); |
|---|
| 1486 |
// #endif |
|---|
| 1487 |
} else { |
|---|
| 1488 |
|
|---|
| 1489 |
if (nvram_match("mac_clone_enable", "1") && |
|---|
| 1490 |
nvram_invmatch("def_whwaddr", |
|---|
| 1491 |
"00:00:00:00:00:00") |
|---|
| 1492 |
&& nvram_invmatch("def_whwaddr", "")) { |
|---|
| 1493 |
ether_atoe(nvram_safe_get |
|---|
| 1494 |
("def_whwaddr"), |
|---|
| 1495 |
ifr.ifr_hwaddr.sa_data); |
|---|
| 1496 |
|
|---|
| 1497 |
} else { |
|---|
| 1498 |
getWirelessMac(mac); |
|---|
| 1499 |
|
|---|
| 1500 |
ether_atoe(mac, ifr.ifr_hwaddr.sa_data); |
|---|
| 1501 |
int instance = get_wl_instance(name); |
|---|
| 1502 |
|
|---|
| 1503 |
if (instance == -1) |
|---|
| 1504 |
continue; // no wireless device |
|---|
| 1505 |
if (nvram_nmatch |
|---|
| 1506 |
("", "wl%d_hwaddr", instance) |
|---|
| 1507 |
|| !nvram_nget("wl%d_hwaddr", |
|---|
| 1508 |
instance)) { |
|---|
| 1509 |
nvram_nset(mac, "wl%d_hwaddr", |
|---|
| 1510 |
instance); |
|---|
| 1511 |
nvram_commit(); |
|---|
| 1512 |
ifr.ifr_hwaddr.sa_family = |
|---|
| 1513 |
ARPHRD_ETHER; |
|---|
| 1514 |
strncpy(ifr.ifr_name, name, |
|---|
| 1515 |
IFNAMSIZ); |
|---|
| 1516 |
|
|---|
| 1517 |
eval("wl", "-i", name, "down"); |
|---|
| 1518 |
if (ioctl |
|---|
| 1519 |
(s, SIOCSIFHWADDR, |
|---|
| 1520 |
&ifr) == -1) |
|---|
| 1521 |
perror |
|---|
| 1522 |
("Write wireless mac fail : "); |
|---|
| 1523 |
else |
|---|
| 1524 |
cprintf |
|---|
| 1525 |
("Write wireless mac successfully\n"); |
|---|
| 1526 |
eval("wl", "-i", name, "up"); |
|---|
| 1527 |
start_config_macs(name); |
|---|
| 1528 |
} |
|---|
| 1529 |
} |
|---|
| 1530 |
|
|---|
| 1531 |
#else |
|---|
| 1532 |
cprintf("configure %s\n", name); |
|---|
| 1533 |
if (strcmp(name, "wl0")) // check if the interface is a |
|---|
| 1534 |
// buffalo wireless |
|---|
| 1535 |
{ |
|---|
| 1536 |
do_portsetup(lan_ifname, name); |
|---|
| 1537 |
} else { |
|---|
| 1538 |
|
|---|
| 1539 |
#endif |
|---|
| 1540 |
/* |
|---|
| 1541 |
* get the instance number of the wl i/f |
|---|
| 1542 |
*/ |
|---|
| 1543 |
char wl_name[] = "wlXXXXXXXXXX_mode"; |
|---|
| 1544 |
int unit; |
|---|
| 1545 |
|
|---|
| 1546 |
#if defined(HAVE_MADWIFI) || defined(HAVE_RT2880) |
|---|
| 1547 |
unit = 0; |
|---|
| 1548 |
#else |
|---|
| 1549 |
wl_ioctl(name, WLC_GET_INSTANCE, &unit, |
|---|
| 1550 |
sizeof(unit)); |
|---|
| 1551 |
#endif |
|---|
| 1552 |
snprintf(wl_name, sizeof(wl_name), "wl%d_mode", |
|---|
| 1553 |
unit); |
|---|
| 1554 |
/* |
|---|
| 1555 |
* Do not attach the main wl i/f if in wds or client/adhoc |
|---|
| 1556 |
*/ |
|---|
| 1557 |
|
|---|
| 1558 |
led_control(LED_BRIDGE, LED_OFF); |
|---|
| 1559 |
if (nvram_match(wl_name, "wet") |
|---|
| 1560 |
|| nvram_match(wl_name, "apstawet")) { |
|---|
| 1561 |
ifconfig(name, IFUP | IFF_ALLMULTI, NULL, NULL); // from |
|---|
| 1562 |
// up |
|---|
| 1563 |
br_add_interface(getBridge(IFMAP(name)), |
|---|
| 1564 |
name); |
|---|
| 1565 |
led_control(LED_BRIDGE, LED_ON); |
|---|
| 1566 |
/* Enable host DHCP relay */ |
|---|
| 1567 |
if (nvram_match("lan_dhcp", "1")) { |
|---|
| 1568 |
wl_iovar_set(name, |
|---|
| 1569 |
"wet_host_mac", |
|---|
| 1570 |
ifr. |
|---|
| 1571 |
ifr_hwaddr.sa_data, |
|---|
| 1572 |
ETHER_ADDR_LEN); |
|---|
| 1573 |
} |
|---|
| 1574 |
/* Enable WET DHCP relay if requested */ |
|---|
| 1575 |
if (nvram_match("dhcp_relay", "1")) // seems to fix some dhcp problems, also Netgear does it this way |
|---|
| 1576 |
{ |
|---|
| 1577 |
enable_dhcprelay(lan_ifname); |
|---|
| 1578 |
} |
|---|
| 1579 |
do_mssid(name); |
|---|
| 1580 |
} |
|---|
| 1581 |
#ifdef HAVE_WAVESAT |
|---|
| 1582 |
if (nvram_match(wl_name, "bridge")) { |
|---|
| 1583 |
ifconfig(name, IFUP | IFF_ALLMULTI, NULL, NULL); // from |
|---|
| 1584 |
// up |
|---|
| 1585 |
br_add_interface(getBridge(IFMAP(name)), |
|---|
| 1586 |
name); |
|---|
| 1587 |
led_control(LED_BRIDGE, LED_ON); |
|---|
| 1588 |
} |
|---|
| 1589 |
#endif |
|---|
| 1590 |
|
|---|
| 1591 |
if (nvram_match(wl_name, "ap")) { |
|---|
| 1592 |
|
|---|
| 1593 |
do_portsetup(lan_ifname, name); |
|---|
| 1594 |
// br_add_interface (getBridge (name), name); //eval |
|---|
| 1595 |
// ("brctl", "addif", lan_ifname, name); |
|---|
| 1596 |
do_mssid(name); |
|---|
| 1597 |
} |
|---|
| 1598 |
if (nvram_match(wl_name, "apsta")) { |
|---|
| 1599 |
#if !defined(HAVE_MADWIFI) && !defined(HAVE_RT2880) |
|---|
| 1600 |
// eval ("wl", "ap", "0"); |
|---|
| 1601 |
eval("wl", "-i", name, "ap", "0"); |
|---|
| 1602 |
// eval ("wl", "infra", "1"); |
|---|
| 1603 |
eval("wl", "-i", name, "infra", "1"); |
|---|
| 1604 |
wl_ioctl(wl_name, WLC_SCAN, svbuf, |
|---|
| 1605 |
sizeof(svbuf)); |
|---|
| 1606 |
wlconf_up(name); |
|---|
| 1607 |
#endif |
|---|
| 1608 |
// eval("wlconf", name, "up"); |
|---|
| 1609 |
ifconfig(name, IFUP | IFF_ALLMULTI, |
|---|
| 1610 |
NULL, NULL); |
|---|
| 1611 |
#if !defined(HAVE_MADWIFI) && !defined(HAVE_RT2880) |
|---|
| 1612 |
// eval ("wl", "ap", "0"); |
|---|
| 1613 |
eval("wl", "-i", name, "ap", "0"); |
|---|
| 1614 |
// eval ("wl", "ssid", nvram_get ("wl0_ssid")); |
|---|
| 1615 |
eval("wl", "-i", name, "ssid", |
|---|
| 1616 |
nvram_nget("wl%d_ssid", |
|---|
| 1617 |
get_wl_instance(name))); |
|---|
| 1618 |
// eval ("brctl", "addif", lan_ifname, name); |
|---|
| 1619 |
#ifndef HAVE_FON |
|---|
| 1620 |
if (nvram_match("fon_enable", "0")) |
|---|
| 1621 |
do_mssid(name); |
|---|
| 1622 |
#endif |
|---|
| 1623 |
#endif |
|---|
| 1624 |
} |
|---|
| 1625 |
|
|---|
| 1626 |
/* |
|---|
| 1627 |
* if client/wet mode, turn off ap mode et al |
|---|
| 1628 |
*/ |
|---|
| 1629 |
if (nvram_match(wl_name, "infra")) { |
|---|
| 1630 |
#if !defined(HAVE_MADWIFI) && !defined(HAVE_RT2880) |
|---|
| 1631 |
// eval ("wl", "ap", "0"); |
|---|
| 1632 |
eval("wl", "-i", name, "ap", "0"); |
|---|
| 1633 |
// eval ("wl", "infra", "0"); |
|---|
| 1634 |
eval("wl", "-i", name, "infra", "0"); |
|---|
| 1635 |
wl_ioctl(wl_name, WLC_SCAN, svbuf, |
|---|
| 1636 |
sizeof(svbuf)); |
|---|
| 1637 |
wlconf_up(name); |
|---|
| 1638 |
#endif |
|---|
| 1639 |
// eval ("wl", "infra", "0"); |
|---|
| 1640 |
eval("wl", "-i", name, "infra", "0"); |
|---|
| 1641 |
// eval ("wl", "ssid", nvram_safe_get ("wl0_ssid")); |
|---|
| 1642 |
ifconfig(name, IFUP | IFF_ALLMULTI, |
|---|
| 1643 |
NULL, NULL); |
|---|
| 1644 |
eval("wl", "-i", name, "ssid", |
|---|
| 1645 |
nvram_nget("wl%d_ssid", |
|---|
| 1646 |
get_wl_instance(name))); |
|---|
| 1647 |
do_portsetup(lan_ifname, name); |
|---|
| 1648 |
} |
|---|
| 1649 |
|
|---|
| 1650 |
if (nvram_match(wl_name, "sta")) { |
|---|
| 1651 |
#if !defined(HAVE_MADWIFI) && !defined(HAVE_RT2880) |
|---|
| 1652 |
// eval ("wl", "ap", "0"); |
|---|
| 1653 |
eval("wl", "-i", name, "ap", "0"); |
|---|
| 1654 |
// eval ("wl", "infra", "1"); |
|---|
| 1655 |
eval("wl", "-i", name, "infra", "1"); |
|---|
| 1656 |
wlconf_up(name); |
|---|
| 1657 |
wl_ioctl(name, WLC_SCAN, svbuf, |
|---|
| 1658 |
sizeof(svbuf)); |
|---|
| 1659 |
#endif |
|---|
| 1660 |
// eval("wlconf", name, "up"); |
|---|
| 1661 |
ifconfig(name, IFUP | IFF_ALLMULTI, |
|---|
| 1662 |
NULL, NULL); |
|---|
| 1663 |
#if !defined(HAVE_MADWIFI) && !defined(HAVE_RT2880) |
|---|
| 1664 |
// eval ("wl", "ap", "0"); |
|---|
| 1665 |
eval("wl", "-i", name, "ap", "0"); |
|---|
| 1666 |
// eval ("wl", "ssid", nvram_get ("wl0_ssid")); |
|---|
| 1667 |
eval("wl", "-i", name, "ssid", |
|---|
| 1668 |
nvram_nget("wl%d_ssid", |
|---|
| 1669 |
get_wl_instance(name))); |
|---|
| 1670 |
#endif |
|---|
| 1671 |
} |
|---|
| 1672 |
#ifdef HAVE_WAVESAT |
|---|
| 1673 |
if (nvram_match(wl_name, "router")) { |
|---|
| 1674 |
|
|---|
| 1675 |
do_portsetup(lan_ifname, name); |
|---|
| 1676 |
// br_add_interface (getBridge (name), name); //eval |
|---|
| 1677 |
// ("brctl", "addif", lan_ifname, name); |
|---|
| 1678 |
do_mssid(name); |
|---|
| 1679 |
} |
|---|
| 1680 |
#endif |
|---|
| 1681 |
|
|---|
| 1682 |
} |
|---|
| 1683 |
|
|---|
| 1684 |
} |
|---|
| 1685 |
} |
|---|
| 1686 |
|
|---|
| 1687 |
free(lan_ifname); |
|---|
| 1688 |
free(wan_ifname); |
|---|
| 1689 |
free(lan_ifnames); |
|---|
| 1690 |
#ifdef HAVE_EAD |
|---|
| 1691 |
if (strlen(eadline) > 0) |
|---|
| 1692 |
sysprintf("ead %s -B", eadline); |
|---|
| 1693 |
#endif |
|---|
| 1694 |
#if defined(HAVE_MADWIFI) || defined(HAVE_RT2880) |
|---|
| 1695 |
#ifndef HAVE_NOWIFI |
|---|
| 1696 |
if (nvram_match("mac_clone_enable", "1") && |
|---|
| 1697 |
nvram_invmatch("def_hwaddr", "00:00:00:00:00:00") && |
|---|
| 1698 |
nvram_invmatch("def_hwaddr", "")) { |
|---|
| 1699 |
ether_atoe(nvram_safe_get("def_whwaddr"), |
|---|
| 1700 |
ifr.ifr_hwaddr.sa_data); |
|---|
| 1701 |
ifr.ifr_hwaddr.sa_family = ARPHRD_IEEE80211; |
|---|
| 1702 |
char *ifs = getSTA(); |
|---|
| 1703 |
char *wifi = NULL; |
|---|
| 1704 |
|
|---|
| 1705 |
if (ifs) |
|---|
| 1706 |
wifi = getWifi(ifs); |
|---|
| 1707 |
if (wifi) { |
|---|
| 1708 |
strncpy(ifr.ifr_name, wifi, IFNAMSIZ); |
|---|
| 1709 |
eval("ifconfig", wifi, "down"); |
|---|
| 1710 |
if (ioctl(s, SIOCSIFHWADDR, &ifr) == -1) |
|---|
| 1711 |
perror("Write wireless mac fail : "); |
|---|
| 1712 |
else |
|---|
| 1713 |
cprintf("Write wireless mac successfully\n"); |
|---|
| 1714 |
eval("ifconfig", wifi, "up"); |
|---|
| 1715 |
} |
|---|
| 1716 |
} |
|---|
| 1717 |
if (nvram_match("mac_clone_enable", "1") && |
|---|
| 1718 |
nvram_invmatch("def_whwaddr", "00:00:00:00:00:00") && |
|---|
| 1719 |
nvram_invmatch("def_whwaddr", "")) { |
|---|
| 1720 |
ether_atoe(nvram_safe_get("def_whwaddr"), |
|---|
| 1721 |
ifr.ifr_hwaddr.sa_data); |
|---|
| 1722 |
ifr.ifr_hwaddr.sa_family = ARPHRD_IEEE80211; |
|---|
| 1723 |
char *ifs = getWDSSTA(); |
|---|
| 1724 |
char *wifi = NULL; |
|---|
| 1725 |
|
|---|
| 1726 |
if (!ifs) |
|---|
| 1727 |
ifs = getWET(); |
|---|
| 1728 |
if (ifs) |
|---|
| 1729 |
wifi = getWifi(ifs); |
|---|
| 1730 |
if (wifi) { |
|---|
| 1731 |
strncpy(ifr.ifr_name, wifi, IFNAMSIZ); |
|---|
| 1732 |
eval("ifconfig", wifi, "down"); |
|---|
| 1733 |
if (ioctl(s, SIOCSIFHWADDR, &ifr) == -1) |
|---|
| 1734 |
perror("Write wireless mac fail : "); |
|---|
| 1735 |
else |
|---|
| 1736 |
cprintf("Write wireless mac successfully\n"); |
|---|
| 1737 |
eval("ifconfig", wifi, "up"); |
|---|
| 1738 |
} |
|---|
| 1739 |
} |
|---|
| 1740 |
configure_wifi(); |
|---|
| 1741 |
#endif |
|---|
| 1742 |
#endif |
|---|
| 1743 |
#ifdef HAVE_WAVESAT |
|---|
| 1744 |
configure_wimax(); |
|---|
| 1745 |
#endif |
|---|
| 1746 |
lan_ifname = strdup(nvram_safe_get("lan_ifname")); |
|---|
| 1747 |
lan_ifnames = strdup(nvram_safe_get("lan_ifnames")); |
|---|
| 1748 |
|
|---|
| 1749 |
/* |
|---|
| 1750 |
* specific non-bridged lan i/f |
|---|
| 1751 |
*/ |
|---|
| 1752 |
if (strcmp(lan_ifname, "")) { // FIXME |
|---|
| 1753 |
/* |
|---|
| 1754 |
* Bring up interface |
|---|
| 1755 |
*/ |
|---|
| 1756 |
ifconfig(lan_ifname, IFUP, NULL, NULL); |
|---|
| 1757 |
#if !defined(HAVE_MADWIFI) && !defined(HAVE_RT2880) |
|---|
| 1758 |
/* |
|---|
| 1759 |
* config wireless i/f |
|---|
| 1760 |
*/ |
|---|
| 1761 |
if (!wlconf_up(lan_ifname)) { |
|---|
| 1762 |
char tmp[100], prefix[] = "wanXXXXXXXXXX_"; |
|---|
| 1763 |
int unit; |
|---|
| 1764 |
|
|---|
| 1765 |
/* |
|---|
| 1766 |
* get the instance number of the wl i/f |
|---|
| 1767 |
*/ |
|---|
| 1768 |
wl_ioctl(lan_ifname, WLC_GET_INSTANCE, &unit, |
|---|
| 1769 |
sizeof(unit)); |
|---|
| 1770 |
snprintf(prefix, sizeof(prefix), "wl%d_", unit); |
|---|
| 1771 |
/* |
|---|
| 1772 |
* Receive all multicast frames in WET mode |
|---|
| 1773 |
*/ |
|---|
| 1774 |
if (nvram_match(strcat_r(prefix, "mode", tmp), "sta")) |
|---|
| 1775 |
ifconfig(lan_ifname, IFUP | IFF_ALLMULTI, NULL, |
|---|
| 1776 |
NULL); |
|---|
| 1777 |
if (nvram_match(strcat_r(prefix, "mode", tmp), "apsta")) |
|---|
| 1778 |
ifconfig(lan_ifname, IFUP | IFF_ALLMULTI, NULL, |
|---|
| 1779 |
NULL); |
|---|
| 1780 |
|
|---|
| 1781 |
} |
|---|
| 1782 |
#endif |
|---|
| 1783 |
|
|---|
| 1784 |
} |
|---|
| 1785 |
|
|---|
| 1786 |
/* |
|---|
| 1787 |
* Bring up and configure LAN interface |
|---|
| 1788 |
*/ |
|---|
| 1789 |
ifconfig(lan_ifname, IFUP, nvram_safe_get("lan_ipaddr"), |
|---|
| 1790 |
nvram_safe_get("lan_netmask")); |
|---|
| 1791 |
|
|---|
| 1792 |
char staticlan[32]; |
|---|
| 1793 |
|
|---|
| 1794 |
sprintf(staticlan, "%s:0", lan_ifname); |
|---|
| 1795 |
#if defined(HAVE_FONERA) || defined(HAVE_CA8) && !defined(HAVE_MR3202A) |
|---|
| 1796 |
if (getRouterBrand() != ROUTER_BOARD_FONERA2200 |
|---|
| 1797 |
&& getRouterBrand() != ROUTER_BOARD_CA8PRO |
|---|
| 1798 |
&& getRouterBrand() != ROUTER_BOARD_RCAA01) |
|---|
| 1799 |
if (nvram_match("ath0_mode", "sta") |
|---|
| 1800 |
|| nvram_match("ath0_mode", "wdssta") |
|---|
| 1801 |
|| nvram_match("ath0_mode", "wet") |
|---|
| 1802 |
|| CANBRIDGE()) { |
|---|
| 1803 |
#endif |
|---|
| 1804 |
|
|---|
| 1805 |
eval("ifconfig", "eth0:0", "down"); |
|---|
| 1806 |
// add fallback ip |
|---|
| 1807 |
eval("ifconfig", staticlan, "169.254.255.1", "netmask", |
|---|
| 1808 |
"255.255.0.0"); |
|---|
| 1809 |
|
|---|
| 1810 |
#if defined(HAVE_FONERA) || defined(HAVE_CA8) && !defined(HAVE_MR3202A) |
|---|
| 1811 |
} else |
|---|
| 1812 |
eval("ifconfig", staticlan, "0.0.0.0", "down"); |
|---|
| 1813 |
#endif |
|---|
| 1814 |
close(s); |
|---|
| 1815 |
reset_hwaddr(lan_ifname); |
|---|
| 1816 |
|
|---|
| 1817 |
cprintf("%s %s\n", |
|---|
| 1818 |
nvram_safe_get("lan_ipaddr"), nvram_safe_get("lan_netmask")); |
|---|
| 1819 |
|
|---|
| 1820 |
#ifndef HAVE_MADWIFI |
|---|
| 1821 |
#ifndef HAVE_RT2880 |
|---|
| 1822 |
int cnt = get_wl_instances(); |
|---|
| 1823 |
int c; |
|---|
| 1824 |
|
|---|
| 1825 |
for (c = 0; c < cnt; c++) { |
|---|
| 1826 |
#ifdef HAVE_MADWIFI |
|---|
| 1827 |
char br1enable[32]; |
|---|
| 1828 |
char br1ipaddr[32]; |
|---|
| 1829 |
char br1netmask[32]; |
|---|
| 1830 |
|
|---|
| 1831 |
sprintf(br1enable, "ath%d_br1_enable", c); |
|---|
| 1832 |
sprintf(br1ipaddr, "ath%d_br1_ipaddr", c); |
|---|
| 1833 |
sprintf(br1netmask, "ath%d_br1_netmask", c); |
|---|
| 1834 |
#else |
|---|
| 1835 |
char br1enable[32]; |
|---|
| 1836 |
char br1ipaddr[32]; |
|---|
| 1837 |
char br1netmask[32]; |
|---|
| 1838 |
|
|---|
| 1839 |
sprintf(br1enable, "wl%d_br1_enable", c); |
|---|
| 1840 |
sprintf(br1ipaddr, "wl%d_br1_ipaddr", c); |
|---|
| 1841 |
sprintf(br1netmask, "wl%d_br1_netmask", c); |
|---|
| 1842 |
#endif |
|---|
| 1843 |
if (nvram_get(br1enable) == NULL) |
|---|
| 1844 |
nvram_set(br1enable, "0"); |
|---|
| 1845 |
if (nvram_get(br1ipaddr) == NULL) |
|---|
| 1846 |
nvram_set(br1ipaddr, "0.0.0.0"); |
|---|
| 1847 |
if (nvram_get(br1netmask) == NULL) |
|---|
| 1848 |
nvram_set(br1netmask, "255.255.255.0"); |
|---|
| 1849 |
if (nvram_match(br1enable, "1")) { |
|---|
| 1850 |
ifconfig("br1", 0, 0, 0); |
|---|
| 1851 |
|
|---|
| 1852 |
// eval ("ifconfig", "br1", "down"); |
|---|
| 1853 |
br_del_bridge("br1"); |
|---|
| 1854 |
br_add_bridge("br1"); |
|---|
| 1855 |
|
|---|
| 1856 |
if (nvram_match("lan_stp", "0")) |
|---|
| 1857 |
br_set_stp_state("br1", 0); // eval ("brctl", "stp", |
|---|
| 1858 |
// "br1", "off"); |
|---|
| 1859 |
else |
|---|
| 1860 |
br_set_stp_state("br1", 1); // eval ("brctl", "stp", |
|---|
| 1861 |
// "br1", "off"); |
|---|
| 1862 |
br_set_bridge_forward_delay("br1", 1); |
|---|
| 1863 |
|
|---|
| 1864 |
/* |
|---|
| 1865 |
* Bring up and configure br1 interface |
|---|
| 1866 |
*/ |
|---|
| 1867 |
if (nvram_invmatch(br1ipaddr, "0.0.0.0")) { |
|---|
| 1868 |
ifconfig("br1", IFUP, nvram_safe_get(br1ipaddr), |
|---|
| 1869 |
nvram_safe_get(br1netmask)); |
|---|
| 1870 |
|
|---|
| 1871 |
if (nvram_match("lan_stp", "0")) |
|---|
| 1872 |
br_set_stp_state("br1", 0); // eval ("brctl", |
|---|
| 1873 |
// "stp", "br1", |
|---|
| 1874 |
// "off"); |
|---|
| 1875 |
else |
|---|
| 1876 |
br_set_stp_state("br1", 1); // eval ("brctl", |
|---|
| 1877 |
// "stp", "br1", |
|---|
| 1878 |
// "off"); |
|---|
| 1879 |
|
|---|
| 1880 |
sleep(2); |
|---|
| 1881 |
#if !defined(HAVE_MADWIFI) && !defined(HAVE_RT2880) |
|---|
| 1882 |
notify_nas("lan", "br1", "up"); |
|---|
| 1883 |
#endif |
|---|
| 1884 |
} |
|---|
| 1885 |
|
|---|
| 1886 |
} |
|---|
| 1887 |
} |
|---|
| 1888 |
/* |
|---|
| 1889 |
* Sveasoft - Bring up and configure wds interfaces |
|---|
| 1890 |
*/ |
|---|
| 1891 |
/* |
|---|
| 1892 |
* logic - if separate ip defined bring it up |
|---|
| 1893 |
*/ |
|---|
| 1894 |
/* |
|---|
| 1895 |
* else if flagged for br1 and br1 is enabled add to br1 |
|---|
| 1896 |
*/ |
|---|
| 1897 |
/* |
|---|
| 1898 |
* else add it to the br0 bridge |
|---|
| 1899 |
*/ |
|---|
| 1900 |
for (c = 0; c < cnt; c++) { |
|---|
| 1901 |
|
|---|
| 1902 |
for (s = 1; s <= MAX_WDS_DEVS; s++) { |
|---|
| 1903 |
char wdsvarname[32] = { 0 }; |
|---|
| 1904 |
char wdsdevname[32] = { 0 }; |
|---|
| 1905 |
char *dev; |
|---|
| 1906 |
|
|---|
| 1907 |
#ifdef HAVE_MADWIFI |
|---|
| 1908 |
char br1enable[32]; |
|---|
| 1909 |
|
|---|
| 1910 |
sprintf(wdsvarname, "ath%d_wds%d_enable", c, s); |
|---|
| 1911 |
sprintf(wdsdevname, "ath%d_wds%d_if", c, s); |
|---|
| 1912 |
sprintf(br1enable, "ath%d_br1_enable", c); |
|---|
| 1913 |
if (nvram_get(wdsvarname) == NULL) |
|---|
| 1914 |
nvram_set(wdsvarname, "0"); |
|---|
| 1915 |
#else |
|---|
| 1916 |
char br1enable[32]; |
|---|
| 1917 |
|
|---|
| 1918 |
sprintf(wdsvarname, "wl%d_wds%d_enable", c, s); |
|---|
| 1919 |
sprintf(wdsdevname, "wl%d_wds%d_if", c, s); |
|---|
| 1920 |
sprintf(br1enable, "wl%d_br1_enable", c); |
|---|
| 1921 |
if (nvram_get(wdsvarname) == NULL) |
|---|
| 1922 |
nvram_set(wdsvarname, "0"); |
|---|
| 1923 |
#endif |
|---|
| 1924 |
dev = nvram_safe_get(wdsdevname); |
|---|
| 1925 |
if (strlen(dev) == 0) |
|---|
| 1926 |
continue; |
|---|
| 1927 |
#ifdef HAVE_RT2880 |
|---|
| 1928 |
dev = getWDSDev(dev); |
|---|
| 1929 |
#endif |
|---|
| 1930 |
ifconfig(dev, 0, 0, 0); |
|---|
| 1931 |
|
|---|
| 1932 |
// eval ("ifconfig", dev, "down"); |
|---|
| 1933 |
if (nvram_match(wdsvarname, "1")) { |
|---|
| 1934 |
char *wdsip; |
|---|
| 1935 |
char *wdsnm; |
|---|
| 1936 |
char wdsbc[32] = { 0 }; |
|---|
| 1937 |
#ifdef HAVE_MADWIFI |
|---|
| 1938 |
wdsip = nvram_nget("ath%d_wds%d_ipaddr", c, s); |
|---|
| 1939 |
wdsnm = nvram_nget("ath%d_wds%d_netmask", c, s); |
|---|
| 1940 |
#else |
|---|
| 1941 |
wdsip = nvram_nget("wl%d_wds%d_ipaddr", c, s); |
|---|
| 1942 |
wdsnm = nvram_nget("wl%d_wds%d_netmask", c, s); |
|---|
| 1943 |
#endif |
|---|
| 1944 |
|
|---|
| 1945 |
snprintf(wdsbc, 31, "%s", wdsip); |
|---|
| 1946 |
get_broadcast(wdsbc, wdsnm); |
|---|
| 1947 |
eval("ifconfig", dev, wdsip, "broadcast", |
|---|
| 1948 |
wdsbc, "netmask", wdsnm, "up"); |
|---|
| 1949 |
} else if (nvram_match(wdsvarname, "2") |
|---|
| 1950 |
&& nvram_match(br1enable, "1")) { |
|---|
| 1951 |
eval("ifconfig", dev, "up"); |
|---|
| 1952 |
sleep(1); |
|---|
| 1953 |
br_add_interface("br1", dev); |
|---|
| 1954 |
} else if (nvram_match(wdsvarname, "3")) { |
|---|
| 1955 |
ifconfig(dev, IFUP, 0, 0); |
|---|
| 1956 |
sleep(1); |
|---|
| 1957 |
br_add_interface(getBridge(dev), dev); |
|---|
| 1958 |
} |
|---|
| 1959 |
} |
|---|
| 1960 |
} |
|---|
| 1961 |
#endif |
|---|
| 1962 |
#endif |
|---|
| 1963 |
#ifdef HAVE_XSCALE |
|---|
| 1964 |
#define HAVE_RB500 |
|---|
| 1965 |
#endif |
|---|
| 1966 |
#ifdef HAVE_PB42 |
|---|
| 1967 |
#define HAVE_RB500 |
|---|
| 1968 |
#endif |
|---|
| 1969 |
#ifdef HAVE_LSX |
|---|
| 1970 |
#define HAVE_RB500 |
|---|
| 1971 |
#endif |
|---|
| 1972 |
#ifdef HAVE_DANUBE |
|---|
| 1973 |
#define HAVE_RB500 |
|---|
| 1974 |
#endif |
|---|
| 1975 |
#ifdef HAVE_STORM |
|---|
| 1976 |
#define HAVE_RB500 |
|---|
| 1977 |
#endif |
|---|
| 1978 |
#ifdef HAVE_ADM5120 |
|---|
| 1979 |
#define HAVE_RB500 |
|---|
| 1980 |
#endif |
|---|
| 1981 |
#ifdef HAVE_MAGICBOX |
|---|
| 1982 |
#define HAVE_RB500 |
|---|
| 1983 |
#endif |
|---|
| 1984 |
#ifdef HAVE_RT2880 |
|---|
| 1985 |
#define HAVE_RB500 |
|---|
| 1986 |
#endif |
|---|
| 1987 |
#ifdef HAVE_FONERA |
|---|
| 1988 |
#define HAVE_RB500 |
|---|
| 1989 |
#endif |
|---|
| 1990 |
#ifdef HAVE_LS2 |
|---|
| 1991 |
#define HAVE_RB500 |
|---|
| 1992 |
#endif |
|---|
| 1993 |
#ifdef HAVE_LS5 |
|---|
| 1994 |
#define HAVE_RB500 |
|---|
| 1995 |
#endif |
|---|
| 1996 |
#ifdef HAVE_WHRAG108 |
|---|
| 1997 |
#define HAVE_RB500 |
|---|
| 1998 |
#endif |
|---|
| 1999 |
#ifdef HAVE_TW6600 |
|---|
| 2000 |
#define HAVE_RB500 |
|---|
| 2001 |
#endif |
|---|
| 2002 |
#ifdef HAVE_CA8 |
|---|
| 2003 |
#define HAVE_RB500 |
|---|
| 2004 |
#endif |
|---|
| 2005 |
#ifndef HAVE_RB500 |
|---|
| 2006 |
/* |
|---|
| 2007 |
* Set QoS mode |
|---|
| 2008 |
*/ |
|---|
| 2009 |
if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) >= 0) { |
|---|
| 2010 |
int i, qos; |
|---|
| 2011 |
caddr_t ifrdata; |
|---|
| 2012 |
struct ethtool_drvinfo info; |
|---|
| 2013 |
|
|---|
| 2014 |
qos = (strcmp(nvram_safe_get("wl_wme"), "on")) ? 0 : 1; |
|---|
| 2015 |
for (i = 1; i <= DEV_NUMIFS; i++) { |
|---|
| 2016 |
ifr.ifr_ifindex = i; |
|---|
| 2017 |
if (ioctl(s, SIOCGIFNAME, &ifr)) |
|---|
| 2018 |
continue; |
|---|
| 2019 |
if (ioctl(s, SIOCGIFHWADDR, &ifr)) |
|---|
| 2020 |
continue; |
|---|
| 2021 |
if (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) |
|---|
| 2022 |
continue; |
|---|
| 2023 |
/* |
|---|
| 2024 |
* get flags |
|---|
| 2025 |
*/ |
|---|
| 2026 |
if (ioctl(s, SIOCGIFFLAGS, &ifr)) |
|---|
| 2027 |
continue; |
|---|
| 2028 |
/* |
|---|
| 2029 |
* if up(wan not up yet at this point) |
|---|
| 2030 |
*/ |
|---|
| 2031 |
if (ifr.ifr_flags & IFF_UP) { |
|---|
| 2032 |
ifrdata = ifr.ifr_data; |
|---|
| 2033 |
memset(&info, 0, sizeof(info)); |
|---|
| 2034 |
info.cmd = ETHTOOL_GDRVINFO; |
|---|
| 2035 |
ifr.ifr_data = (caddr_t) & info; |
|---|
| 2036 |
if (ioctl(s, SIOCETHTOOL, &ifr) >= 0) { |
|---|
| 2037 |
/* |
|---|
| 2038 |
* currently only need to set QoS to et devices |
|---|
| 2039 |
*/ |
|---|
| 2040 |
if (!strncmp(info.driver, "et", 2)) { |
|---|
| 2041 |
ifr.ifr_data = (caddr_t) & qos; |
|---|
| 2042 |
ioctl(s, SIOCSETCQOS, &ifr); |
|---|
| 2043 |
} |
|---|
| 2044 |
} |
|---|
| 2045 |
ifr.ifr_data = ifrdata; |
|---|
| 2046 |
} |
|---|
| 2047 |
} |
|---|
| 2048 |
close(s); |
|---|
| 2049 |
} |
|---|
| 2050 |
#undef HAVE_RB500 |
|---|
| 2051 |
#endif |
|---|
| 2052 |
/* |
|---|
| 2053 |
* Sveasoft - set default IP gateway defined |
|---|
| 2054 |
*/ |
|---|
| 2055 |
if (strcmp(nvram_safe_get("lan_gateway"), "0.0.0.0")) |
|---|
| 2056 |
eval("ip", "ro", "add", "default", "via", |
|---|
| 2057 |
nvram_safe_get("lan_gateway"), "dev", "br0"); |
|---|
| 2058 |
|
|---|
| 2059 |
#if !defined(HAVE_MADWIFI) && !defined(HAVE_RT2880) |
|---|
| 2060 |
for (c = 0; c < cnt; c++) { |
|---|
| 2061 |
eval("wl", "-i", get_wl_instance_name(c), "vlan_mode", "0"); |
|---|
| 2062 |
} |
|---|
| 2063 |
#endif |
|---|
| 2064 |
/* |
|---|
| 2065 |
* Bring up local host interface |
|---|
| 2066 |
*/ |
|---|
| 2067 |
config_loopback(); |
|---|
| 2068 |
|
|---|
| 2069 |
/* |
|---|
| 2070 |
* Set additional lan static routes if need |
|---|
| 2071 |
*/ |
|---|
| 2072 |
start_set_routes(); |
|---|
| 2073 |
#if !defined(HAVE_MADWIFI) && !defined(HAVE_RT2880) |
|---|
| 2074 |
for (c = 0; c < cnt; c++) { |
|---|
| 2075 |
eval("wl", "-i", get_wl_instance_name(c), "radio", |
|---|
| 2076 |
nvram_nmatch("disabled", "wl%d_net_mode", |
|---|
| 2077 |
c) ? "off" : "on"); |
|---|
| 2078 |
} |
|---|
| 2079 |
#endif |
|---|
| 2080 |
/* |
|---|
| 2081 |
* Disable wireless will cause diag led blink, so we want to stop it. |
|---|
| 2082 |
*/ |
|---|
| 2083 |
if (check_hw_type() == BCM4712_CHIP) { |
|---|
| 2084 |
diag_led(DIAG, STOP_LED); |
|---|
| 2085 |
/* |
|---|
| 2086 |
* Light or go out the DMZ led even if there is no wan ip. |
|---|
| 2087 |
*/ |
|---|
| 2088 |
if (nvram_invmatch("dmz_ipaddr", "") |
|---|
| 2089 |
&& nvram_invmatch("dmz_ipaddr", "0")) |
|---|
| 2090 |
diag_led(DMZ, START_LED); |
|---|
| 2091 |
else |
|---|
| 2092 |
diag_led(DMZ, STOP_LED); |
|---|
| 2093 |
} |
|---|
| 2094 |
|
|---|
| 2095 |
if (nvram_match("lan_stp", "0")) |
|---|
| 2096 |
br_set_stp_state("br0", 0); |
|---|
| 2097 |
else |
|---|
| 2098 |
br_set_stp_state("br0", 1); |
|---|
| 2099 |
|
|---|
| 2100 |
free(lan_ifnames); |
|---|
| 2101 |
free(lan_ifname); |
|---|
| 2102 |
// eval ("rm", "/tmp/hosts"); |
|---|
| 2103 |
addHost("localhost", "127.0.0.1"); |
|---|
| 2104 |
if (strlen(nvram_safe_get("wan_hostname")) > 0) |
|---|
| 2105 |
addHost(nvram_safe_get("wan_hostname"), |
|---|
| 2106 |
nvram_safe_get("lan_ipaddr")); |
|---|
| 2107 |
else if (strlen(nvram_safe_get("router_name")) > 0) |
|---|
| 2108 |
addHost(nvram_safe_get("router_name"), |
|---|
| 2109 |
nvram_safe_get("lan_ipaddr")); |
|---|
| 2110 |
#ifdef HAVE_MICRO |
|---|
| 2111 |
br_shutdown(); |
|---|
| 2112 |
#endif |
|---|
| 2113 |
} |
|---|
| 2114 |
|
|---|
| 2115 |
void stop_lan(void) |
|---|
| 2116 |
{ |
|---|
| 2117 |
char *lan_ifname = nvram_safe_get("lan_ifname"); |
|---|
| 2118 |
char name[80], *next; |
|---|
| 2119 |
|
|---|
| 2120 |
cprintf("%s\n", lan_ifname); |
|---|
| 2121 |
/* |
|---|
| 2122 |
* Bring down LAN interface |
|---|
| 2123 |
*/ |
|---|
| 2124 |
ifconfig(lan_ifname, 0, NULL, NULL); |
|---|
| 2125 |
#ifdef HAVE_MICRO |
|---|
| 2126 |
br_init(); |
|---|
| 2127 |
#endif |
|---|
| 2128 |
|
|---|
| 2129 |
#if !defined(HAVE_MADWIFI) && !defined(HAVE_RT2880) |
|---|
| 2130 |
br_del_interface(lan_ifname, "wl0.1"); |
|---|
| 2131 |
ifconfig("wl0.1", 0, NULL, NULL); |
|---|
| 2132 |
br_del_interface(lan_ifname, "wl0.2"); |
|---|
| 2133 |
ifconfig("wl0.2", 0, NULL, NULL); |
|---|
| 2134 |
br_del_interface(lan_ifname, "wl0.3"); |
|---|
| 2135 |
ifconfig("wl0.3", 0, NULL, NULL); |
|---|
| 2136 |
br_del_interface(lan_ifname, "wl1.1"); |
|---|
| 2137 |
ifconfig("wl1.1", 0, NULL, NULL); |
|---|
| 2138 |
br_del_interface(lan_ifname, "wl1.2"); |
|---|
| 2139 |
ifconfig("wl1.2", 0, NULL, NULL); |
|---|
| 2140 |
br_del_interface(lan_ifname, "wl1.3"); |
|---|
| 2141 |
ifconfig("wl1.3", 0, NULL, NULL); |
|---|
| 2142 |
#endif |
|---|
| 2143 |
/* |
|---|
| 2144 |
* Bring down bridged interfaces |
|---|
| 2145 |
*/ |
|---|
| 2146 |
if (strncmp(lan_ifname, "br", 2) == 0) { |
|---|
| 2147 |
foreach(name, nvram_safe_get("lan_ifnames"), next) { |
|---|
| 2148 |
if (nvram_match("wan_ifname", name)) |
|---|
| 2149 |
continue; |
|---|
| 2150 |
if (!ifexists(name)) |
|---|
| 2151 |
continue; |
|---|
| 2152 |
#if !defined(HAVE_MADWIFI) && !defined(HAVE_RT2880) |
|---|
| 2153 |
eval("wlconf", name, "down"); |
|---|
| 2154 |
#endif |
|---|
| 2155 |
ifconfig(name, 0, NULL, NULL); |
|---|
| 2156 |
br_del_interface(lan_ifname, name); |
|---|
| 2157 |
} |
|---|
| 2158 |
br_del_bridge(lan_ifname); |
|---|
| 2159 |
} |
|---|
| 2160 |
/* |
|---|
| 2161 |
* Bring down specific interface |
|---|
| 2162 |
*/ |
|---|
| 2163 |
#if !defined(HAVE_MADWIFI) && !defined(HAVE_RT2880) |
|---|
| 2164 |
else if (strcmp(lan_ifname, "")) |
|---|
| 2165 |
eval("wlconf", lan_ifname, "down"); |
|---|
| 2166 |
#endif |
|---|
| 2167 |
#ifdef HAVE_MICRO |
|---|
| 2168 |
br_shutdown(); |
|---|
| 2169 |
#endif |
|---|
| 2170 |
|
|---|
| 2171 |
cprintf("done\n"); |
|---|
| 2172 |
} |
|---|
| 2173 |
|
|---|
| 2174 |
#define sin_addr(s) (((struct sockaddr_in *)(s))->sin_addr) |
|---|
| 2175 |
|
|---|
| 2176 |
int wan_valid(char *ifname) |
|---|
| 2177 |
{ |
|---|
| 2178 |
char name[80], *next; |
|---|
| 2179 |
|
|---|
| 2180 |
foreach(name, nvram_safe_get("wan_ifnames"), next) |
|---|
| 2181 |
if (ifname && !strcmp(ifname, name)) |
|---|
| 2182 |
return 1; |
|---|
| 2183 |
|
|---|
| 2184 |
if (getSTA() && !strcmp(getSTA(), ifname)) |
|---|
| 2185 |
return 1; |
|---|
| 2186 |
|
|---|
| 2187 |
return 0; |
|---|
| 2188 |
} |
|---|
| 2189 |
|
|---|
| 2190 |
void start_force_to_dial(void); |
|---|
| 2191 |
|
|---|
| 2192 |
void start_wan(int status) |
|---|
| 2193 |
{ |
|---|
| 2194 |
FILE *fp; |
|---|
| 2195 |
char *wan_ifname = get_wan_face(); |
|---|
| 2196 |
char *wan_proto = nvram_safe_get("wan_proto"); |
|---|
| 2197 |
int s; |
|---|
| 2198 |
struct ifreq ifr; |
|---|
| 2199 |
if (isClient()) { |
|---|
| 2200 |
char *ifn = getSTA(); |
|---|
| 2201 |
int count = 10; |
|---|
| 2202 |
while ((count--) > 0) // wait until wan is available (10 sek max) |
|---|
| 2203 |
{ |
|---|
| 2204 |
if (ifexists(ifn)) { |
|---|
| 2205 |
break; |
|---|
| 2206 |
} |
|---|
| 2207 |
sleep(1); |
|---|
| 2208 |
} |
|---|
| 2209 |
} |
|---|
| 2210 |
|
|---|
| 2211 |
eval("ifconfig", nvram_safe_get("wan_ifname"), "allmulti", "promisc"); |
|---|
| 2212 |
|
|---|
| 2213 |
#ifdef HAVE_PPPOE |
|---|
| 2214 |
#ifdef HAVE_RB500 |
|---|
| 2215 |
char *pppoe_wan_ifname = nvram_invmatch("pppoe_wan_ifname", |
|---|
| 2216 |
"") ? |
|---|
| 2217 |
nvram_safe_get("pppoe_wan_ifname") : nvram_safe_get("wan_ifname"); |
|---|
| 2218 |
#else |
|---|
| 2219 |
|
|---|
| 2220 |
#ifdef HAVE_XSCALE |
|---|
| 2221 |
char *pppoe_wan_ifname = nvram_invmatch("pppoe_wan_ifname", |
|---|
| 2222 |
"") ? |
|---|
| 2223 |
nvram_safe_get("pppoe_wan_ifname") : "ixp1"; |
|---|
| 2224 |
#elif HAVE_MAGICBOX |
|---|
| 2225 |
char *pppoe_wan_ifname = nvram_invmatch("pppoe_wan_ifname", |
|---|
| 2226 |
"") ? |
|---|
| 2227 |
nvram_safe_get("pppoe_wan_ifname") : "eth0"; |
|---|
| 2228 |
#elif HAVE_WRT54G2 |
|---|
| 2229 |
char *pppoe_wan_ifname = nvram_invmatch("pppoe_wan_ifname", |
|---|
| 2230 |
"") ? |
|---|
| 2231 |
nvram_safe_get("pppoe_wan_ifname") : "vlan1"; |
|---|
| 2232 |
#elif HAVE_DIR300 |
|---|
| 2233 |
char *pppoe_wan_ifname = nvram_invmatch("pppoe_wan_ifname", |
|---|
| 2234 |
"") ? |
|---|
| 2235 |
nvram_safe_get("pppoe_wan_ifname") : "vlan2"; |
|---|
| 2236 |
#elif HAVE_BWRG1000 |
|---|
| 2237 |
char *pppoe_wan_ifname = nvram_invmatch("pppoe_wan_ifname", |
|---|
| 2238 |
"") ? |
|---|
| 2239 |
nvram_safe_get("pppoe_wan_ifname") : "vlan2"; |
|---|
| 2240 |
#elif HAVE_ECB9750 |
|---|
| 2241 |
char *pppoe_wan_ifname = nvram_invmatch("pppoe_wan_ifname", |
|---|
| 2242 |
"") ? |
|---|
| 2243 |
nvram_safe_get("pppoe_wan_ifname") : "eth2"; |
|---|
| 2244 |
#elif HAVE_RT2880 |
|---|
| 2245 |
char *pppoe_wan_ifname = nvram_invmatch("pppoe_wan_ifname", |
|---|
| 2246 |
"") ? |
|---|
| 2247 |
nvram_safe_get("pppoe_wan_ifname") : "vlan2"; |
|---|
| 2248 |
#elif HAVE_MR3202A |
|---|
| 2249 |
char *pppoe_wan_ifname = nvram_invmatch("pppoe_wan_ifname", |
|---|
| 2250 |
"") ? |
|---|
| 2251 |
nvram_safe_get("pppoe_wan_ifname") : "vlan2"; |
|---|
| 2252 |
#elif HAVE_FONERA |
|---|
| 2253 |
char *pppoe_wan_ifname = NULL; |
|---|
| 2254 |
|
|---|
| 2255 |
if (getRouterBrand() == ROUTER_BOARD_FONERA2200) |
|---|
| 2256 |
pppoe_wan_ifname = |
|---|
| 2257 |
nvram_invmatch("pppoe_wan_ifname", |
|---|
| 2258 |
"") ? nvram_safe_get("pppoe_wan_ifname") : |
|---|
| 2259 |
"vlan1"; |
|---|
| 2260 |
else |
|---|
| 2261 |
pppoe_wan_ifname = |
|---|
| 2262 |
nvram_invmatch("pppoe_wan_ifname", |
|---|
| 2263 |
"") ? nvram_safe_get("pppoe_wan_ifname") : |
|---|
| 2264 |
"eth0"; |
|---|
| 2265 |
#elif HAVE_NS2 |
|---|
| 2266 |
char *pppoe_wan_ifname = nvram_invmatch("pppoe_wan_ifname", |
|---|
| 2267 |
"") ? |
|---|
| 2268 |
nvram_safe_get("pppoe_wan_ifname") : "eth0"; |
|---|
| 2269 |
#elif HAVE_BS2 |
|---|
| 2270 |
char *pppoe_wan_ifname = nvram_invmatch("pppoe_wan_ifname", |
|---|
| 2271 |
"") ? |
|---|
| 2272 |
nvram_safe_get("pppoe_wan_ifname") : "eth0"; |
|---|
| 2273 |
#elif HAVE_PICO2 |
|---|
| 2274 |
char *pppoe_wan_ifname = nvram_invmatch("pppoe_wan_ifname", |
|---|
| 2275 |
"") ? |
|---|
| 2276 |
nvram_safe_get("pppoe_wan_ifname") : "eth0"; |
|---|
| 2277 |
#elif HAVE_PICO2HP |
|---|
| 2278 |
char *pppoe_wan_ifname = nvram_invmatch("pppoe_wan_ifname", |
|---|
| 2279 |
"") ? |
|---|
| 2280 |
nvram_safe_get("pppoe_wan_ifname") : "eth0"; |
|---|
| 2281 |
#elif HAVE_MS2 |
|---|
| 2282 |
char *pppoe_wan_ifname = nvram_invmatch("pppoe_wan_ifname", |
|---|
| 2283 |
"") ? |
|---|
| 2284 |
nvram_safe_get("pppoe_wan_ifname") : "eth0"; |
|---|
| 2285 |
#elif HAVE_BS2HP |
|---|
| 2286 |
char *pppoe_wan_ifname = nvram_invmatch("pppoe_wan_ifname", |
|---|
| 2287 |
"") ? |
|---|
| 2288 |
nvram_safe_get("pppoe_wan_ifname") : "eth0"; |
|---|
| 2289 |
#elif HAVE_LC2 |
|---|
| 2290 |
char *pppoe_wan_ifname = nvram_invmatch("pppoe_wan_ifname", |
|---|
| 2291 |
"") ? |
|---|
| 2292 |
nvram_safe_get("pppoe_wan_ifname") : "eth0"; |
|---|
| 2293 |
#elif HAVE_LS2 |
|---|
| 2294 |
char *pppoe_wan_ifname = nvram_invmatch("pppoe_wan_ifname", |
|---|
| 2295 |
"") ? |
|---|
| 2296 |
nvram_safe_get("pppoe_wan_ifname") : nvram_safe_get("wan_ifname"); |
|---|
| 2297 |
#elif HAVE_LSX |
|---|
| 2298 |
char *pppoe_wan_ifname = nvram_invmatch("pppoe_wan_ifname", |
|---|
| 2299 |
"") ? |
|---|
| 2300 |
nvram_safe_get("pppoe_wan_ifname") : "eth0"; |
|---|
| 2301 |
#elif HAVE_DANUBE |
|---|
| 2302 |
char *pppoe_wan_ifname = nvram_invmatch("pppoe_wan_ifname", |
|---|
| 2303 |
"") ? |
|---|
| 2304 |
nvram_safe_get("pppoe_wan_ifname") : "eth0"; |
|---|
| 2305 |
#elif HAVE_STORM |
|---|
| 2306 |
char *pppoe_wan_ifname = nvram_invmatch("pppoe_wan_ifname", |
|---|
| 2307 |
"") ? |
|---|
| 2308 |
nvram_safe_get("pppoe_wan_ifname") : "eth0"; |
|---|
| 2309 |
#elif HAVE_ADM5120 |
|---|
| 2310 |
char *pppoe_wan_ifname = nvram_invmatch("pppoe_wan_ifname", |
|---|
| 2311 |
"") ? |
|---|
| 2312 |
nvram_safe_get("pppoe_wan_ifname") : "eth0"; |
|---|
| 2313 |
#elif HAVE_LS5 |
|---|
| 2314 |
char *pppoe_wan_ifname = nvram_invmatch("pppoe_wan_ifname", |
|---|
| 2315 |
"") ? |
|---|
| 2316 |
nvram_safe_get("pppoe_wan_ifname") : "eth0"; |
|---|
| 2317 |
#elif HAVE_WHRAG108 |
|---|
| 2318 |
char *pppoe_wan_ifname = nvram_invmatch("pppoe_wan_ifname", |
|---|
| 2319 |
"") ? |
|---|
| 2320 |
nvram_safe_get("pppoe_wan_ifname") : "eth1"; |
|---|
| 2321 |
#elif HAVE_PB42 |
|---|
| 2322 |
char *pppoe_wan_ifname = nvram_invmatch("pppoe_wan_ifname", |
|---|
| 2323 |
"") ? |
|---|
| 2324 |
nvram_safe_get("pppoe_wan_ifname") : "eth0"; |
|---|
| 2325 |
#elif HAVE_TW6600 |
|---|
| 2326 |
char *pppoe_wan_ifname = nvram_invmatch("pppoe_wan_ifname", |
|---|
| 2327 |
"") ? |
|---|
| 2328 |
nvram_safe_get("pppoe_wan_ifname") : "eth0"; |
|---|
| 2329 |
#elif HAVE_RDAT81 |
|---|
| 2330 |
char *pppoe_wan_ifname = nvram_invmatch("pppoe_wan_ifname", |
|---|
| 2331 |
"") ? |
|---|
| 2332 |
nvram_safe_get("pppoe_wan_ifname") : "eth0"; |
|---|
| 2333 |
#elif HAVE_RCAA01 |
|---|
| 2334 |
char *pppoe_wan_ifname = nvram_invmatch("pppoe_wan_ifname", |
|---|
| 2335 |
"") ? |
|---|
| 2336 |
nvram_safe_get("pppoe_wan_ifname") : "vlan1"; |
|---|
| 2337 |
#elif HAVE_CA8PRO |
|---|
| 2338 |
char *pppoe_wan_ifname = nvram_invmatch("pppoe_wan_ifname", |
|---|
| 2339 |
"") ? |
|---|
| 2340 |
nvram_safe_get("pppoe_wan_ifname") : "vlan1"; |
|---|
| 2341 |
#elif HAVE_CA8 |
|---|
| 2342 |
char *pppoe_wan_ifname = nvram_invmatch("pppoe_wan_ifname", |
|---|
| 2343 |
"") ? |
|---|
| 2344 |
nvram_safe_get("pppoe_wan_ifname") : "eth0"; |
|---|
| 2345 |
#elif HAVE_X86 |
|---|
| 2346 |
char *pppoe_wan_ifname = nvram_invmatch("pppoe_wan_ifname", |
|---|
| 2347 |
"") ? |
|---|
| 2348 |
nvram_safe_get("pppoe_wan_ifname") : nvram_safe_get("wan_ifname"); |
|---|
| 2349 |
#else |
|---|
| 2350 |
char *pppoe_wan_ifname = nvram_invmatch("pppoe_wan_ifname", |
|---|
| 2351 |
"") ? |
|---|
| 2352 |
nvram_safe_get("pppoe_wan_ifname") : "vlan1"; |
|---|
| 2353 |
#endif |
|---|
| 2354 |
#ifdef HAVE_MULTICAST |
|---|
| 2355 |
if (!nvram_match("dtag_vlan8", "1")) |
|---|
| 2356 |
stop_igmp_proxy(); |
|---|
| 2357 |
#endif |
|---|
| 2358 |
|
|---|
| 2359 |
#endif |
|---|
| 2360 |
#if !defined(HAVE_MADWIFI) && !defined(HAVE_RT2880) |
|---|
| 2361 |
if (getWET()) { |
|---|
| 2362 |
dns_to_resolv(); |
|---|
| 2363 |
return; |
|---|
| 2364 |
} |
|---|
| 2365 |
if (isClient()) { |
|---|
| 2366 |
pppoe_wan_ifname = getSTA(); |
|---|
| 2367 |
} |
|---|
| 2368 |
#else |
|---|
| 2369 |
if (isClient()) { |
|---|
| 2370 |
pppoe_wan_ifname = getSTA(); |
|---|
| 2371 |
int count = 10; |
|---|
| 2372 |
while ((count--) > 0) { |
|---|
| 2373 |
|
|---|
| 2374 |
} |
|---|
| 2375 |
} |
|---|
| 2376 |
#endif |
|---|
| 2377 |
#endif |
|---|
| 2378 |
// fprintf(stderr,"%s %s\n", wan_ifname, wan_proto); |
|---|
| 2379 |
|
|---|
| 2380 |
if ((s = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) |
|---|
| 2381 |
return; |
|---|
| 2382 |
/* |
|---|
| 2383 |
* Check PPPoE version, RP or linksys |
|---|
| 2384 |
*/ |
|---|
| 2385 |
#ifdef HAVE_PPPOE |
|---|
| 2386 |
if (nvram_match("wan_proto", "pppoe")) |
|---|
| 2387 |
strncpy(ifr.ifr_name, pppoe_wan_ifname, IFNAMSIZ); |
|---|
| 2388 |
else |
|---|
| 2389 |
#endif |
|---|
| 2390 |
strncpy(ifr.ifr_name, wan_ifname, IFNAMSIZ); |
|---|
| 2391 |
|
|---|
| 2392 |
/* |
|---|
| 2393 |
* Set WAN hardware address before bringing interface up |
|---|
| 2394 |
*/ |
|---|
| 2395 |
memset(ifr.ifr_hwaddr.sa_data, 0, ETHER_ADDR_LEN); |
|---|
| 2396 |
|
|---|
| 2397 |
ifconfig(wan_ifname, 0, NULL, NULL); |
|---|
| 2398 |
#if defined(HAVE_FONERA) || defined(HAVE_CA8) && !defined(HAVE_MR3202A) |
|---|
| 2399 |
if (getRouterBrand() != ROUTER_BOARD_FONERA2200 |
|---|
| 2400 |
&& getRouterBrand() != ROUTER_BOARD_CA8PRO) { |
|---|
| 2401 |
char staticlan[32]; |
|---|
| 2402 |
|
|---|
| 2403 |
sprintf(staticlan, "%s:0", wan_ifname); |
|---|
| 2404 |
if (!nvram_match("ath0_mode", "sta") |
|---|
| 2405 |
&& !nvram_match("ath0_mode", "wdssta") |
|---|
| 2406 |
&& !nvram_match("ath0_mode", "wet") |
|---|
| 2407 |
&& !CANBRIDGE()) { |
|---|
| 2408 |
eval("ifconfig", "br0:0", "down"); |
|---|
| 2409 |
eval("ifconfig", staticlan, "169.254.255.1", "netmask", |
|---|
| 2410 |
"255.255.0.0"); |
|---|
| 2411 |
} else |
|---|
| 2412 |
eval("ifconfig", staticlan, "0.0.0.0", "down"); |
|---|
| 2413 |
} |
|---|
| 2414 |
#endif |
|---|
| 2415 |
|
|---|
| 2416 |
// fprintf(stderr,"%s %s\n", wan_ifname, wan_proto); |
|---|
| 2417 |
char *wlifname = getSTA(); |
|---|
| 2418 |
|
|---|
| 2419 |
if (!wlifname) { |
|---|
| 2420 |
wlifname = getWET(); |
|---|
| 2421 |
} |
|---|
| 2422 |
|
|---|
| 2423 |
unsigned char mac[20]; |
|---|
| 2424 |
|
|---|
| 2425 |
if (nvram_match("mac_clone_enable", "1") && |
|---|
| 2426 |
nvram_invmatch("def_hwaddr", "00:00:00:00:00:00") && |
|---|
| 2427 |
nvram_invmatch("def_hwaddr", "")) { |
|---|
| 2428 |
ether_atoe(nvram_safe_get("def_hwaddr"), |
|---|
| 2429 |
ifr.ifr_hwaddr.sa_data); |
|---|
| 2430 |
} else { |
|---|
| 2431 |
|
|---|
| 2432 |
if (wlifname && !strcmp(wan_ifname, wlifname)) // sta mode |
|---|
| 2433 |
{ |
|---|
| 2434 |
getWirelessMac(mac); |
|---|
| 2435 |
ether_atoe(mac, ifr.ifr_hwaddr.sa_data); |
|---|
| 2436 |
} else { |
|---|
| 2437 |
#ifdef HAVE_X86 |
|---|
| 2438 |
ioctl(s, SIOCGIFHWADDR, &ifr); |
|---|
| 2439 |
#else |
|---|
| 2440 |
getWANMac(mac); |
|---|
| 2441 |
ether_atoe(mac, ifr.ifr_hwaddr.sa_data); |
|---|
| 2442 |
#endif |
|---|
| 2443 |
} |
|---|
| 2444 |
} |
|---|
| 2445 |
|
|---|
| 2446 |
if (memcmp(ifr.ifr_hwaddr.sa_data, "\0\0\0\0\0\0", ETHER_ADDR_LEN)) { |
|---|
| 2447 |
ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER; |
|---|
| 2448 |
#if !defined(HAVE_MADWIFI) && !defined(HAVE_RT2880) |
|---|
| 2449 |
|
|---|
| 2450 |
if (wlifname && !strcmp(wan_ifname, wlifname)) |
|---|
| 2451 |
eval("wl", "-i", wan_ifname, "down"); |
|---|
| 2452 |
ioctl(s, SIOCSIFHWADDR, &ifr); |
|---|
| 2453 |
#else |
|---|
| 2454 |
if (!wlifname) { |
|---|
| 2455 |
ioctl(s, SIOCSIFHWADDR, &ifr); |
|---|
| 2456 |
// eval("ifconfig",wan_ifname,"promisc"); // set wan to promisc, since we now have usually different mac addresses on vlans |
|---|
| 2457 |
} |
|---|
| 2458 |
#endif |
|---|
| 2459 |
#if !defined(HAVE_MADWIFI) && !defined(HAVE_RT2880) |
|---|
| 2460 |
if (wlifname && !strcmp(wan_ifname, wlifname)) { |
|---|
| 2461 |
eval("wl", "-i", wan_ifname, "up"); |
|---|
| 2462 |
start_config_macs(wan_ifname); |
|---|
| 2463 |
} |
|---|
| 2464 |
#endif |
|---|
| 2465 |
cprintf("Write WAN mac successfully\n"); |
|---|
| 2466 |
} else |
|---|
| 2467 |
perror("Write WAN mac fail : \n"); |
|---|
| 2468 |
// fprintf(stderr,"%s %s\n", wan_ifname, wan_proto); |
|---|
| 2469 |
|
|---|
| 2470 |
/* |
|---|
| 2471 |
* Set MTU |
|---|
| 2472 |
*/ |
|---|
| 2473 |
init_mtu(wan_proto); // add by honor 2002/12/27 |
|---|
| 2474 |
// fprintf(stderr,"%s %s\n", wan_ifname, wan_proto); |
|---|
| 2475 |
|
|---|
| 2476 |
// Set our Interface to the right MTU |
|---|
| 2477 |
#ifdef HAVE_PPPOE |
|---|
| 2478 |
if (nvram_match("wan_proto", "pppoe")) { |
|---|
| 2479 |
ifr.ifr_mtu = atoi(getMTU(wan_ifname)); // default ethernet frame size |
|---|
| 2480 |
} else |
|---|
| 2481 |
#endif |
|---|
| 2482 |
{ |
|---|
| 2483 |
int mtu = atoi(nvram_safe_get("wan_mtu")); |
|---|
| 2484 |
if (mtu == 1500) |
|---|
| 2485 |
mtu = atoi(getMTU(wan_ifname)); |
|---|
| 2486 |
ifr.ifr_mtu = mtu; |
|---|
| 2487 |
} |
|---|
| 2488 |
// fprintf(stderr,"set mtu for %s to %d\n",ifr.ifr_name,ifr.ifr_mtu); |
|---|
| 2489 |
ioctl(s, SIOCSIFMTU, &ifr); |
|---|
| 2490 |
|
|---|
| 2491 |
if (strcmp(wan_proto, "disabled") == 0) { |
|---|
| 2492 |
start_wan_done(wan_ifname); |
|---|
| 2493 |
return; |
|---|
| 2494 |
} |
|---|
| 2495 |
|
|---|
| 2496 |
/* |
|---|
| 2497 |
* Bring up WAN interface |
|---|
| 2498 |
*/ |
|---|
| 2499 |
#ifdef HAVE_PPPOE |
|---|
| 2500 |
/* |
|---|
| 2501 |
* AhMan March 19 2005 |
|---|
| 2502 |
*/ |
|---|
| 2503 |
/* |
|---|
| 2504 |
* ice-man March 19 2005 |
|---|
| 2505 |
*/ |
|---|
| 2506 |
/* |
|---|
| 2507 |
* pppoe_wan interface must be up in order to use any pppoe client |
|---|
| 2508 |
*/ |
|---|
| 2509 |
if (strcmp(wan_proto, "pppoe") == 0) |
|---|
| 2510 |
ifconfig(pppoe_wan_ifname, IFUP, NULL, NULL); |
|---|
| 2511 |
else { |
|---|
| 2512 |
ifconfig(wan_ifname, IFUP, NULL, NULL); |
|---|
| 2513 |
} |
|---|
| 2514 |
#else |
|---|
| 2515 |
|
|---|
| 2516 |
ifconfig(wan_ifname, IFUP, NULL, NULL); |
|---|
| 2517 |
if (nvram_match("wl0_mode", "infra")) { |
|---|
| 2518 |
eval("wl", "infra", "0"); |
|---|
| 2519 |
eval("wl", "ssid", nvram_safe_get("wl0_ssid")); |
|---|
| 2520 |
} |
|---|
| 2521 |
#endif |
|---|
| 2522 |
set_host_domain_name(); |
|---|
| 2523 |
|
|---|
| 2524 |
// Remove the current value of pppd_pppifname |
|---|
| 2525 |
nvram_set("pppd_pppifname", ""); |
|---|
| 2526 |
|
|---|
| 2527 |
/* |
|---|
| 2528 |
* Configure WAN interface |
|---|
| 2529 |
*/ |
|---|
| 2530 |
#ifdef HAVE_3G |
|---|
| 2531 |
if ((strcmp(wan_proto, "3g") == 0)) { |
|---|
| 2532 |
char *controldevice = get3GControlDevice(); |
|---|
| 2533 |
|
|---|
| 2534 |
mkdir("/tmp/ppp", 0777); |
|---|
| 2535 |
int timeout = 5; |
|---|
| 2536 |
|
|---|
| 2537 |
/* init PIN */ |
|---|
| 2538 |
if (strlen(nvram_safe_get("wan_pin"))) |
|---|
| 2539 |
sysprintf("export COMGTPIN=%s;comgt PIN -d %s\n", |
|---|
| 2540 |
nvram_safe_get("wan_pin"), controldevice); |
|---|
| 2541 |
if (strlen(nvram_safe_get("wan_apn"))) |
|---|
| 2542 |
if (!nvram_match("wan_dial", "2")) |
|---|
| 2543 |
sysprintf |
|---|
| 2544 |
("export COMGTAPN=\"%s\";comgt APN -d %s\n", |
|---|
| 2545 |
nvram_safe_get("wan_apn"), controldevice); |
|---|
| 2546 |
// Lets open option file and enter all the parameters. |
|---|
| 2547 |
fp = fopen("/tmp/ppp/options.pppoe", "w"); |
|---|
| 2548 |
fprintf(fp, "defaultroute\n"); |
|---|
| 2549 |
fprintf(fp, "usepeerdns\n"); |
|---|
| 2550 |
fprintf(fp, "noipdefault\n"); |
|---|
| 2551 |
fprintf(fp, "noauth\n"); |
|---|
| 2552 |
fprintf(fp, "ipcp-max-failure 30\n"); |
|---|
| 2553 |
fprintf(fp, "lcp-echo-interval 10\n"); |
|---|
| 2554 |
fprintf(fp, "lcp-echo-failure 3\n"); |
|---|
| 2555 |
if (nvram_match("mtu_enable", "1")) { |
|---|
| 2556 |
if (atoi(nvram_safe_get("wan_mtu")) > 0) { |
|---|
| 2557 |
fprintf(fp, "mtu %s\n", |
|---|
| 2558 |
nvram_safe_get("wan_mtu")); |
|---|
| 2559 |
fprintf(fp, "mru %s\n", |
|---|
| 2560 |
nvram_safe_get("wan_mtu")); |
|---|
| 2561 |
} |
|---|
| 2562 |
|
|---|
| 2563 |
} |
|---|
| 2564 |
fprintf(fp, "crtscts\n"); |
|---|
| 2565 |
fprintf(fp, "460800\n"); |
|---|
| 2566 |
// fprintf(fp,"connect \"/usr/sbin/comgt DIAL -d %s\"\n",controldevice); |
|---|
| 2567 |
char *dial = "*99***1#"; |
|---|
| 2568 |
if (nvram_match("wan_dial", "0")) |
|---|
| 2569 |
dial = "ATD*99***1#"; |
|---|
| 2570 |
if (nvram_match("wan_dial", "1")) |
|---|
| 2571 |
dial = "ATD*99#"; |
|---|
| 2572 |
if (nvram_match("wan_dial", "2")) |
|---|
| 2573 |
dial = "ATDT#777"; |
|---|
| 2574 |
fprintf(fp, |
|---|
| 2575 |
"connect \"COMGTDIAL='%s' /usr/sbin/comgt DIAL -d %s >/tmp/comgt.out 2>&1\"\n", |
|---|
| 2576 |
dial, nvram_safe_get("3gdata")); |
|---|
| 2577 |
if (strlen(nvram_safe_get("ppp_username"))) |
|---|
| 2578 |
fprintf(fp, "user %s\n", |
|---|
| 2579 |
nvram_safe_get("ppp_username")); |
|---|
| 2580 |
if (strlen(nvram_safe_get("ppp_passwd"))) |
|---|
| 2581 |
fprintf(fp, "password %s\n", |
|---|
| 2582 |
nvram_safe_get("ppp_passwd")); |
|---|
| 2583 |
fprintf(fp, "%s\n", nvram_get("3gdata")); |
|---|
| 2584 |
|
|---|
| 2585 |
fclose(fp); |
|---|
| 2586 |
|
|---|
| 2587 |
symlink("/sbin/rc", "/tmp/ppp/ip-up"); |
|---|
| 2588 |
symlink("/sbin/rc", "/tmp/ppp/ip-down"); |
|---|
| 2589 |
unlink("/tmp/ppp/log"); |
|---|
| 2590 |
|
|---|
| 2591 |
// Clean pppoe linksys client files - Added by ice-man (Wed Jun 1) |
|---|
| 2592 |
unlink("/tmp/ppp/connect-log"); |
|---|
| 2593 |
unlink("/tmp/ppp/set-pppoepid"); |
|---|
| 2594 |
|
|---|
| 2595 |
stop_dhcpc(); |
|---|
| 2596 |
#ifdef HAVE_PPTP |
|---|
| 2597 |
stop_pptp(); |
|---|
| 2598 |
#endif |
|---|
| 2599 |
eval("pppd", "file", "/tmp/ppp/options.pppoe"); |
|---|
| 2600 |
|
|---|
| 2601 |
/* |
|---|
| 2602 |
* Pretend that the WAN interface is up |
|---|
| 2603 |
*/ |
|---|
| 2604 |
if (nvram_match("ppp_demand", "1")) { |
|---|
| 2605 |
/* |
|---|
| 2606 |
* Wait for ppp0 to be created |
|---|
| 2607 |
*/ |
|---|
| 2608 |
while (ifconfig("ppp0", IFUP, NULL, NULL) && timeout--) |
|---|
| 2609 |
sleep(1); |
|---|
| 2610 |
strncpy(ifr.ifr_name, "ppp0", IFNAMSIZ); |
|---|
| 2611 |
|
|---|
| 2612 |
/* |
|---|
| 2613 |
* Set temporary IP address |
|---|
| 2614 |
*/ |
|---|
| 2615 |
timeout = 3; |
|---|
| 2616 |
while (ioctl(s, SIOCGIFADDR, &ifr) && timeout--) { |
|---|
| 2617 |
perror("ppp0"); |
|---|
| 2618 |
printf("Wait ppp inteface to init (1) ...\n"); |
|---|
| 2619 |
sleep(1); |
|---|
| 2620 |
}; |
|---|
| 2621 |
char client[32]; |
|---|
| 2622 |
|
|---|
| 2623 |
nvram_set("wan_ipaddr", |
|---|
| 2624 |
inet_ntop(AF_INET, &sin_addr(&ifr.ifr_addr), |
|---|
| 2625 |
client, 16)); |
|---|
| 2626 |
nvram_set("wan_netmask", "255.255.255.255"); |
|---|
| 2627 |
|
|---|
| 2628 |
/* |
|---|
| 2629 |
* Set temporary P-t-P address |
|---|
| 2630 |
*/ |
|---|
| 2631 |
timeout = 3; |
|---|
| 2632 |
while (ioctl(s, SIOCGIFDSTADDR, &ifr) && timeout--) { |
|---|
| 2633 |
perror("ppp0"); |
|---|
| 2634 |
printf("Wait ppp inteface to init (2) ...\n"); |
|---|
| 2635 |
sleep(1); |
|---|
| 2636 |
} |
|---|
| 2637 |
char *peer = |
|---|
| 2638 |
inet_ntop(AF_INET, &sin_addr(&ifr.ifr_dstaddr), |
|---|
| 2639 |
client, |
|---|
| 2640 |
16); |
|---|
| 2641 |
|
|---|
| 2642 |
nvram_set("wan_gateway", peer); |
|---|
| 2643 |
|
|---|
| 2644 |
start_wan_done("ppp0"); |
|---|
| 2645 |
|
|---|
| 2646 |
// if user press Connect" button from web, we must force to dial |
|---|
| 2647 |
if (nvram_match("action_service", "start_3g")) { |
|---|
| 2648 |
sleep(3); |
|---|
| 2649 |
start_force_to_dial(); |
|---|
| 2650 |
nvram_unset("action_service"); |
|---|
| 2651 |
} |
|---|
| 2652 |
} else { |
|---|
| 2653 |
if (status != REDIAL) { |
|---|
| 2654 |
start_redial(); |
|---|
| 2655 |
} |
|---|
| 2656 |
} |
|---|
| 2657 |
|
|---|
| 2658 |
} else |
|---|
| 2659 |
#endif |
|---|
| 2660 |
#ifdef HAVE_PPPOE |
|---|
| 2661 |
if ((strcmp(wan_proto, "pppoe") == 0)) { |
|---|
| 2662 |
char username[80], passwd[80]; |
|---|
| 2663 |
char idletime[20], retry_num[20]; |
|---|
| 2664 |
|
|---|
| 2665 |
snprintf(idletime, sizeof(idletime), "%d", |
|---|
| 2666 |
atoi(nvram_safe_get("ppp_idletime")) * 60); |
|---|
| 2667 |
snprintf(retry_num, sizeof(retry_num), "%d", |
|---|
| 2668 |
(atoi(nvram_safe_get("ppp_redialperiod")) / 5) - 1); |
|---|
| 2669 |
|
|---|
| 2670 |
snprintf(username, sizeof(username), "%s", |
|---|
| 2671 |
nvram_safe_get("ppp_username")); |
|---|
| 2672 |
snprintf(passwd, sizeof(passwd), "%s", |
|---|
| 2673 |
nvram_safe_get("ppp_passwd")); |
|---|
| 2674 |
|
|---|
| 2675 |
mkdir("/tmp/ppp", 0777); |
|---|
| 2676 |
int timeout = 5; |
|---|
| 2677 |
|
|---|
| 2678 |
// Lets open option file and enter all the parameters. |
|---|
| 2679 |
fp = fopen("/tmp/ppp/options.pppoe", "w"); |
|---|
| 2680 |
// rp-pppoe kernelmode plugin |
|---|
| 2681 |
#if defined(HAVE_ADM5120) && !defined(HAVE_WP54G) && !defined(HAVE_NP28G) |
|---|
| 2682 |
fprintf(fp, "plugin /lib/rp-pppoe.so"); |
|---|
| 2683 |
#else |
|---|
| 2684 |
fprintf(fp, "plugin /usr/lib/rp-pppoe.so"); |
|---|
| 2685 |
#endif |
|---|
| 2686 |
if (nvram_invmatch("pppoe_service", "")) |
|---|
| 2687 |
fprintf(fp, " rp_pppoe_service %s", |
|---|
| 2688 |
nvram_safe_get("pppoe_service")); |
|---|
| 2689 |
fprintf(fp, "\n"); |
|---|
| 2690 |
char vlannic[32]; |
|---|
| 2691 |
char tvnic[32]; |
|---|
| 2692 |
|
|---|
| 2693 |
if (!strncmp(pppoe_wan_ifname, "vlan", 4)) { |
|---|
| 2694 |
if (nvram_match("wan_vdsl", "1")) { |
|---|
| 2695 |
char *ifn = enable_dtag_vlan(1); |
|---|
| 2696 |
|
|---|
| 2697 |
if (nvram_match("dtag_vlan8", "1")) { |
|---|
| 2698 |
sprintf(vlannic, "%s.0008", ifn); |
|---|
| 2699 |
if (!ifexists(vlannic)) { |
|---|
| 2700 |
eval("vconfig", "set_name_type", |
|---|
| 2701 |
"DEV_PLUS_VID"); |
|---|
| 2702 |
eval("vconfig", "add", ifn, |
|---|
| 2703 |
"8"); |
|---|
| 2704 |
eval("ifconfig", vlannic, "up"); |
|---|
| 2705 |
} |
|---|
| 2706 |
nvram_set("tvnicfrom", vlannic); |
|---|
| 2707 |
symlink("/sbin/rc", "/tmp/udhcpc_tv"); |
|---|
| 2708 |
eval("udhcpc", "-i", vlannic, "-s", |
|---|
| 2709 |
"/tmp/udhcpc_tv", "-q"); |
|---|
| 2710 |
} |
|---|
| 2711 |
sprintf(vlannic, "%s.0007", ifn); |
|---|
| 2712 |
if (!ifexists(vlannic)) { |
|---|
| 2713 |
eval("vconfig", "set_name_type", |
|---|
| 2714 |
"DEV_PLUS_VID"); |
|---|
| 2715 |
eval("vconfig", "add", ifn, "7"); |
|---|
| 2716 |
eval("ifconfig", vlannic, "up"); |
|---|
| 2717 |
} |
|---|
| 2718 |
|
|---|
| 2719 |
fprintf(fp, "nic-%s\n", vlannic); |
|---|
| 2720 |
} else { |
|---|
| 2721 |
char *ifn = enable_dtag_vlan(0); |
|---|
| 2722 |
|
|---|
| 2723 |
sprintf(vlannic, "%s.0007", ifn); |
|---|
| 2724 |
if (ifexists(vlannic)) |
|---|
| 2725 |
eval("vconfig", "rem", vlannic); |
|---|
| 2726 |
sprintf(vlannic, "%s.0008", ifn); |
|---|
| 2727 |
if (ifexists(vlannic)) |
|---|
| 2728 |
eval("vconfig", "rem", vlannic); |
|---|
| 2729 |
fprintf(fp, "nic-%s\n", pppoe_wan_ifname); |
|---|
| 2730 |
} |
|---|
| 2731 |
|
|---|
| 2732 |
} else { |
|---|
| 2733 |
if (nvram_match("wan_vdsl", "1")) // Deutsche Telekom |
|---|
| 2734 |
// VDSL2 Vlan 7 Tag |
|---|
| 2735 |
{ |
|---|
| 2736 |
if (nvram_match("dtag_vlan8", "1")) { |
|---|
| 2737 |
sprintf(vlannic, "%s.0008", |
|---|
| 2738 |
pppoe_wan_ifname); |
|---|
| 2739 |
if (!ifexists(vlannic)) { |
|---|
| 2740 |
eval("vconfig", "set_name_type", |
|---|
| 2741 |
"DEV_PLUS_VID"); |
|---|
| 2742 |
eval("vconfig", "add", |
|---|
| 2743 |
pppoe_wan_ifname, "8"); |
|---|
| 2744 |
eval("ifconfig", vlannic, "up"); |
|---|
| 2745 |
nvram_set("tvnicfrom", vlannic); |
|---|
| 2746 |
symlink("/sbin/rc", |
|---|
| 2747 |
"/tmp/udhcpc_tv"); |
|---|
| 2748 |
eval("udhcpc", "-i", vlannic, |
|---|
| 2749 |
"-s", "/tmp/udhcpc_tv", |
|---|
| 2750 |
"-q"); |
|---|
| 2751 |
} |
|---|
| 2752 |
} |
|---|
| 2753 |
sprintf(vlannic, "%s.0007", pppoe_wan_ifname); |
|---|
| 2754 |
if (!ifexists(vlannic)) { |
|---|
| 2755 |
eval("vconfig", "set_name_type", |
|---|
| 2756 |
"DEV_PLUS_VID"); |
|---|
| 2757 |
eval("vconfig", "add", pppoe_wan_ifname, |
|---|
| 2758 |
"7"); |
|---|
| 2759 |
eval("ifconfig", vlannic, "up"); |
|---|
| 2760 |
} |
|---|
| 2761 |
fprintf(fp, "nic-%s\n", vlannic); |
|---|
| 2762 |
} else { |
|---|
| 2763 |
sprintf(vlannic, "%s.0008", pppoe_wan_ifname); |
|---|
| 2764 |
if (ifexists(vlannic)) |
|---|
| 2765 |
eval("vconfig", "rem", vlannic); |
|---|
| 2766 |
sprintf(vlannic, "%s.0007", pppoe_wan_ifname); |
|---|
| 2767 |
if (ifexists(vlannic)) |
|---|
| 2768 |
eval("vconfig", "rem", vlannic); |
|---|
| 2769 |
fprintf(fp, "nic-%s\n", pppoe_wan_ifname); |
|---|
| 2770 |
} |
|---|
| 2771 |
} |
|---|
| 2772 |
|
|---|
| 2773 |
// Those are default options we use + user/passwd |
|---|
| 2774 |
// By using user/password options we dont have to deal with chap/pap |
|---|
| 2775 |
// secrets files. |
|---|
| 2776 |
if (nvram_match("ppp_compression", "1")) { |
|---|
| 2777 |
fprintf(fp, "mppc\n"); |
|---|
| 2778 |
} else { |
|---|
| 2779 |
fprintf(fp, "noccp\n"); |
|---|
| 2780 |
fprintf(fp, "nomppc\n"); |
|---|
| 2781 |
} |
|---|
| 2782 |
fprintf(fp, "noipdefault\n" |
|---|
| 2783 |
"noauth\n" |
|---|
| 2784 |
"defaultroute\n" "noaccomp\n" "nobsdcomp\n" |
|---|
| 2785 |
"nodeflate\n" |
|---|
| 2786 |
// "debug\n" |
|---|
| 2787 |
// "maxfail 0\n" |
|---|
| 2788 |
// "nocrtscts\n" |
|---|
| 2789 |
// "sync\n" |
|---|
| 2790 |
// "local\n" |
|---|
| 2791 |
// "noixp\n" |
|---|
| 2792 |
// "lock\n" |
|---|
| 2793 |
// "noproxyarp\n" |
|---|
| 2794 |
// "ipcp-accept-local\n" |
|---|
| 2795 |
// "ipcp-accept-remote\n" |
|---|
| 2796 |
// "nodetach\n" |
|---|
| 2797 |
"nopcomp\n"); |
|---|
| 2798 |
// "novj\n" |
|---|
| 2799 |
// "novjccomp\n"); |
|---|
| 2800 |
if (nvram_invmatch("ppp_mppe", "")) |
|---|
| 2801 |
fprintf(fp, "%s\n", nvram_safe_get("ppp_mppe")); |
|---|
| 2802 |
else |
|---|
| 2803 |
fprintf(fp, "nomppe\n"); |
|---|
| 2804 |
fprintf(fp, "usepeerdns\n" |
|---|
| 2805 |
"user '%s'\n" "password '%s'\n", username, passwd); |
|---|
| 2806 |
|
|---|
| 2807 |
// This is a tricky one. When used it could improve speed of PPPoE |
|---|
| 2808 |
// but not all ISP's can support it. |
|---|
| 2809 |
// default-asyncmap escapes all control characters. By using asyncmap |
|---|
| 2810 |
// 0 PPPD will not escape any control characters |
|---|
| 2811 |
// Not all ISP's can handle this. By default use default-asyncmap |
|---|
| 2812 |
// and if ppp_asyncmap=1 do not escape |
|---|
| 2813 |
if (nvram_match("ppp_asyncmap", "1")) |
|---|
| 2814 |
fprintf(fp, "asyncmap 0\n"); |
|---|
| 2815 |
else |
|---|
| 2816 |
fprintf(fp, "default-asyncmap\n"); |
|---|
| 2817 |
|
|---|
| 2818 |
// Allow users some control on PPP interface MTU and MRU |
|---|
| 2819 |
// If pppoe_ppp_mtu > 0 will set mtu of pppX interface to the value |
|---|
| 2820 |
// in the nvram variable |
|---|
| 2821 |
// If pppoe_ppp_mru > 0 will set mru of pppX interface to the value |
|---|
| 2822 |
// in the nvram variable |
|---|
| 2823 |
// if none is specified PPPD will autonegotiate the values with ISP |
|---|
| 2824 |
// (sometimes not desirable) |
|---|
| 2825 |
// Do not forget this should be at least 8 bytes less then physycal |
|---|
| 2826 |
// interfaces mtu. |
|---|
| 2827 |
|
|---|
| 2828 |
// if MRU is not Auto force MTU/MRU of interface to value selected by |
|---|
| 2829 |
// theuser on web page |
|---|
| 2830 |
if (nvram_match("mtu_enable", "1")) { |
|---|
| 2831 |
if (atoi(nvram_safe_get("wan_mtu")) > 0) { |
|---|
| 2832 |
fprintf(fp, "mtu %s\n", |
|---|
| 2833 |
nvram_safe_get("wan_mtu")); |
|---|
| 2834 |
fprintf(fp, "mru %s\n", |
|---|
| 2835 |
nvram_safe_get("wan_mtu")); |
|---|
| 2836 |
} |
|---|
| 2837 |
|
|---|
| 2838 |
} else { |
|---|
| 2839 |
// If MRU set to Auto we still allow custom MTU/MRU settings for |
|---|
| 2840 |
// expirienced users |
|---|
| 2841 |
if (nvram_invmatch("pppoe_ppp_mtu", "")) |
|---|
| 2842 |
if (atoi(nvram_safe_get("pppoe_ppp_mtu")) > 0) |
|---|
| 2843 |
fprintf(fp, "mtu %s\n", |
|---|
| 2844 |
nvram_safe_get |
|---|
| 2845 |
("pppoe_ppp_mtu")); |
|---|
| 2846 |
if (nvram_invmatch("pppoe_ppp_mru", "")) |
|---|
| 2847 |
if (atoi(nvram_safe_get("pppoe_ppp_mru")) > 0) |
|---|
| 2848 |
fprintf(fp, "mru %s\n", |
|---|
| 2849 |
nvram_safe_get |
|---|
| 2850 |
("pppoe_ppp_mru")); |
|---|
| 2851 |
} |
|---|
| 2852 |
|
|---|
| 2853 |
// Allow runtime debugging |
|---|
| 2854 |
if (nvram_match("ppp_debug", "1")) |
|---|
| 2855 |
fprintf(fp, "debug\n"); |
|---|
| 2856 |
|
|---|
| 2857 |
// Demand dial.. This is not pretty. |
|---|
| 2858 |
// The first problems i see is that if connection is lost it would |
|---|
| 2859 |
// take PPPoE (idletime * 2) * 3 to notice it. |
|---|
| 2860 |
// In other words if idle is set to 30 seconds, it would take 30*2*3 |
|---|
| 2861 |
// (180) seconds to detect the lost connection. |
|---|
| 2862 |
// We have to increase the lcp-echo-interval to idletime*2 so that we |
|---|
| 2863 |
// do not upset the idletime counter. |
|---|
| 2864 |
// When not using demand dialing, it only takes 15 seconds to detect |
|---|
| 2865 |
// the lost connection. |
|---|
| 2866 |
if (nvram_match("ppp_demand", "1")) |
|---|
| 2867 |
fprintf(fp, "demand\n" |
|---|
| 2868 |
"idle %s\n" |
|---|
| 2869 |
"10.112.112.112:10.112.112.113\n" |
|---|
| 2870 |
"lcp-echo-interval %d\n" |
|---|
| 2871 |
"lcp-echo-failure 3\n" |
|---|
| 2872 |
"ipcp-accept-remote\n" |
|---|
| 2873 |
"ipcp-accept-local\n" |
|---|
| 2874 |
"connect true\n" "ktune\n", idletime, |
|---|
| 2875 |
atoi(idletime) * 2); |
|---|
| 2876 |
else |
|---|
| 2877 |
fprintf(fp, "persist\n" |
|---|
| 2878 |
"lcp-echo-interval 5\n" |
|---|
| 2879 |
"lcp-echo-failure 10\n"); |
|---|
| 2880 |
|
|---|
| 2881 |
fclose(fp); |
|---|
| 2882 |
|
|---|
| 2883 |
symlink("/sbin/rc", "/tmp/ppp/ip-up"); |
|---|
| 2884 |
symlink("/sbin/rc", "/tmp/ppp/ip-down"); |
|---|
| 2885 |
unlink("/tmp/ppp/log"); |
|---|
| 2886 |
|
|---|
| 2887 |
// Clean pppoe linksys client files - Added by ice-man (Wed Jun 1) |
|---|
| 2888 |
unlink("/tmp/ppp/connect-log"); |
|---|
| 2889 |
unlink("/tmp/ppp/set-pppoepid"); |
|---|
| 2890 |
|
|---|
| 2891 |
stop_dhcpc(); |
|---|
| 2892 |
#ifdef HAVE_PPTP |
|---|
| 2893 |
stop_pptp(); |
|---|
| 2894 |
#endif |
|---|
| 2895 |
eval("killall", "pppd"); |
|---|
| 2896 |
eval("pppd", "file", "/tmp/ppp/options.pppoe"); |
|---|
| 2897 |
|
|---|
| 2898 |
// This is horrible. |
|---|
| 2899 |
// What if pppoe recconects with ppp1? |
|---|
| 2900 |
|
|---|
| 2901 |
/* |
|---|
| 2902 |
* Pretend that the WAN interface is up |
|---|
| 2903 |
*/ |
|---|
| 2904 |
if (nvram_match("ppp_demand", "1")) { |
|---|
| 2905 |
/* |
|---|
| 2906 |
* Wait for ppp0 to be created |
|---|
| 2907 |
*/ |
|---|
| 2908 |
while (ifconfig("ppp0", IFUP, NULL, NULL) && timeout--) |
|---|
| 2909 |
sleep(1); |
|---|
| 2910 |
strncpy(ifr.ifr_name, "ppp0", IFNAMSIZ); |
|---|
| 2911 |
|
|---|
| 2912 |
/* |
|---|
| 2913 |
* Set temporary IP address |
|---|
| 2914 |
*/ |
|---|
| 2915 |
timeout = 3; |
|---|
| 2916 |
while (ioctl(s, SIOCGIFADDR, &ifr) && timeout--) { |
|---|
| 2917 |
perror("ppp0"); |
|---|
| 2918 |
printf("Wait ppp inteface to init (1) ...\n"); |
|---|
| 2919 |
sleep(1); |
|---|
| 2920 |
}; |
|---|
| 2921 |
char client[32]; |
|---|
| 2922 |
|
|---|
| 2923 |
nvram_set("wan_ipaddr", |
|---|
| 2924 |
inet_ntop(AF_INET, &sin_addr(&ifr.ifr_addr), |
|---|
| 2925 |
client, 16)); |
|---|
| 2926 |
nvram_set("wan_netmask", "255.255.255.255"); |
|---|
| 2927 |
|
|---|
| 2928 |
/* |
|---|
| 2929 |
* Set temporary P-t-P address |
|---|
| 2930 |
*/ |
|---|
| 2931 |
timeout = 3; |
|---|
| 2932 |
while (ioctl(s, SIOCGIFDSTADDR, &ifr) && timeout--) { |
|---|
| 2933 |
perror("ppp0"); |
|---|
| 2934 |
printf("Wait ppp inteface to init (2) ...\n"); |
|---|
| 2935 |
sleep(1); |
|---|
| 2936 |
} |
|---|
| 2937 |
char *peer = |
|---|
| 2938 |
inet_ntop(AF_INET, &sin_addr(&ifr.ifr_dstaddr), |
|---|
| 2939 |
client, |
|---|
| 2940 |
16); |
|---|
| 2941 |
|
|---|
| 2942 |
nvram_set("wan_gateway", peer); |
|---|
| 2943 |
|
|---|
| 2944 |
start_wan_done("ppp0"); |
|---|
| 2945 |
|
|---|
| 2946 |
// if user press Connect" button from web, we must force to dial |
|---|
| 2947 |
if (nvram_match("action_service", "start_pppoe")) { |
|---|
| 2948 |
sleep(3); |
|---|
| 2949 |
start_force_to_dial(); |
|---|
| 2950 |
nvram_unset("action_service"); |
|---|
| 2951 |
} |
|---|
| 2952 |
} else { |
|---|
| 2953 |
if (status != REDIAL) { |
|---|
| 2954 |
start_redial(); |
|---|
| 2955 |
} |
|---|
| 2956 |
} |
|---|
| 2957 |
} else |
|---|
| 2958 |
#endif |
|---|
| 2959 |
if (strcmp(wan_proto, "dhcp") == 0) { |
|---|
| 2960 |
start_dhcpc(wan_ifname); |
|---|
| 2961 |
} |
|---|
| 2962 |
#ifdef HAVE_PPTP |
|---|
| 2963 |
else if (strcmp(wan_proto, "pptp") == 0) { |
|---|
| 2964 |
start_pptp(status); |
|---|
| 2965 |
} |
|---|
| 2966 |
#endif |
|---|
| 2967 |
#ifdef HAVE_L2TP |
|---|
| 2968 |
else if (strcmp(wan_proto, "l2tp") == 0) { |
|---|
| 2969 |
start_dhcpc(wan_ifname); |
|---|
| 2970 |
} |
|---|
| 2971 |
#endif |
|---|
| 2972 |
#ifdef HAVE_HEARTBEAT |
|---|
| 2973 |
else if (strcmp(wan_proto, "heartbeat") == 0) { |
|---|
| 2974 |
start_dhcpc(wan_ifname); |
|---|
| 2975 |
} |
|---|
| 2976 |
#endif |
|---|
| 2977 |
else { |
|---|
| 2978 |
ifconfig(wan_ifname, IFUP, |
|---|
| 2979 |
nvram_safe_get("wan_ipaddr"), |
|---|
| 2980 |
nvram_safe_get("wan_netmask")); |
|---|
| 2981 |
start_wan_done(wan_ifname); |
|---|
| 2982 |
} |
|---|
| 2983 |
cprintf("dhcp client ready\n"); |
|---|
| 2984 |
|
|---|
| 2985 |
/* |
|---|
| 2986 |
* Get current WAN hardware address |
|---|
| 2987 |
*/ |
|---|
| 2988 |
if (!strncmp(wan_ifname, "ppp", 3)) |
|---|
| 2989 |
strncpy(ifr.ifr_name, nvram_safe_get("wan_ifname"), IFNAMSIZ); |
|---|
| 2990 |
else |
|---|
| 2991 |
strncpy(ifr.ifr_name, wan_ifname, IFNAMSIZ); |
|---|
| 2992 |
cprintf("get current hardware adress"); |
|---|
| 2993 |
{ |
|---|
| 2994 |
if (ioctl(s, SIOCGIFHWADDR, &ifr) == 0) { |
|---|
| 2995 |
char eabuf[32]; |
|---|
| 2996 |
|
|---|
| 2997 |
nvram_set("wan_hwaddr", |
|---|
| 2998 |
ether_etoa(ifr.ifr_hwaddr.sa_data, eabuf)); |
|---|
| 2999 |
// fprintf(stderr,"write wan addr |
|---|
| 3000 |
// %s\n",nvram_safe_get("wan_hwaddr")); |
|---|
| 3001 |
} |
|---|
| 3002 |
|
|---|
| 3003 |
} |
|---|
| 3004 |
|
|---|
| 3005 |
close(s); |
|---|
| 3006 |
|
|---|
| 3007 |
// set_ip_forward('1'); |
|---|
| 3008 |
|
|---|
| 3009 |
// =================================================================================== |
|---|
| 3010 |
// Tallest move herei(from "start_lan" function ). Fixed when wireless |
|---|
| 3011 |
// disable, wireless LED dosen't off. |
|---|
| 3012 |
// =================================================================================== |
|---|
| 3013 |
/* |
|---|
| 3014 |
* Disable wireless will cause diag led blink, so we want to stop it. |
|---|
| 3015 |
*/ |
|---|
| 3016 |
|
|---|
| 3017 |
cprintf("diag led control\n"); |
|---|
| 3018 |
if ((check_hw_type() == BCM4712_CHIP) |
|---|
| 3019 |
|| (check_hw_type() == BCM5325E_CHIP)) { |
|---|
| 3020 |
// Barry will put disable WLAN here |
|---|
| 3021 |
if (nvram_match("wl_gmode", "-1")) { |
|---|
| 3022 |
diag_led(WL, STOP_LED); |
|---|
| 3023 |
#if 0 |
|---|
| 3024 |
eval("wlled", "0 0 1"); |
|---|
| 3025 |
eval("wlled", "0 1 1"); |
|---|
| 3026 |
#endif |
|---|
| 3027 |
} |
|---|
| 3028 |
diag_led(DIAG, STOP_LED); |
|---|
| 3029 |
} |
|---|
| 3030 |
/* |
|---|
| 3031 |
* Light or go out the DMZ led even if there is no wan ip. |
|---|
| 3032 |
*/ |
|---|
| 3033 |
if (nvram_match("dmz_enable", "1") && nvram_invmatch("dmz_ipaddr", "") |
|---|
| 3034 |
&& nvram_invmatch("dmz_ipaddr", "0")) |
|---|
| 3035 |
diag_led(DMZ, START_LED); |
|---|
| 3036 |
else |
|---|
| 3037 |
diag_led(DMZ, STOP_LED); |
|---|
| 3038 |
|
|---|
| 3039 |
cprintf("%s %s\n", nvram_safe_get("wan_ipaddr"), |
|---|
| 3040 |
nvram_safe_get("wan_netmask")); |
|---|
| 3041 |
|
|---|
| 3042 |
if (nvram_match("wan_proto", "l2tp")) { |
|---|
| 3043 |
/* |
|---|
| 3044 |
* Delete all default routes |
|---|
| 3045 |
*/ |
|---|
| 3046 |
while (route_del(get_wan_face(), 0, NULL, NULL, NULL) == 0) ; |
|---|
| 3047 |
} |
|---|
| 3048 |
cprintf("wep handling\n"); |
|---|
| 3049 |
cprintf("disable stp if needed\n"); |
|---|
| 3050 |
if (nvram_match("lan_stp", "0")) { |
|---|
| 3051 |
#ifdef HAVE_MICRO |
|---|
| 3052 |
br_init(); |
|---|
| 3053 |
#endif |
|---|
| 3054 |
|
|---|
| 3055 |
br_set_stp_state("br0", 0); |
|---|
| 3056 |
|
|---|
| 3057 |
#ifdef HAVE_MICRO |
|---|
| 3058 |
br_shutdown(); |
|---|
| 3059 |
#endif |
|---|
| 3060 |
|
|---|
| 3061 |
} else { |
|---|
| 3062 |
#ifdef HAVE_MICRO |
|---|
| 3063 |
br_init(); |
|---|
| 3064 |
#endif |
|---|
| 3065 |
|
|---|
| 3066 |
br_set_stp_state("br0", 1); |
|---|
| 3067 |
#ifdef HAVE_MICRO |
|---|
| 3068 |
br_shutdown(); |
|---|
| 3069 |
#endif |
|---|
| 3070 |
|
|---|
| 3071 |
} |
|---|
| 3072 |
|
|---|
| 3073 |
cprintf("done()()()\n"); |
|---|
| 3074 |
} |
|---|
| 3075 |
|
|---|
| 3076 |
void start_wan_boot(void) |
|---|
| 3077 |
{ |
|---|
| 3078 |
start_wan(BOOT); |
|---|
| 3079 |
} |
|---|
| 3080 |
|
|---|
| 3081 |
void start_wan_redial(void) |
|---|
| 3082 |
{ |
|---|
| 3083 |
start_wan(REDIAL); |
|---|
| 3084 |
} |
|---|
| 3085 |
|
|---|
| 3086 |
void start_wan_service(void) |
|---|
| 3087 |
{ |
|---|
| 3088 |
stop_process_monitor(); |
|---|
| 3089 |
stop_ddns(); |
|---|
| 3090 |
cprintf("start process monitor\n"); |
|---|
| 3091 |
start_process_monitor(); |
|---|
| 3092 |
sleep(5); |
|---|
| 3093 |
cprintf("start ddns\n"); |
|---|
| 3094 |
start_ddns(); |
|---|
| 3095 |
} |
|---|
| 3096 |
|
|---|
| 3097 |
void start_wan_done(char *wan_ifname) |
|---|
| 3098 |
{ |
|---|
| 3099 |
cprintf("%s %s\n", wan_ifname, nvram_safe_get("wan_proto")); |
|---|
| 3100 |
|
|---|
| 3101 |
if (nvram_match("wan_proto", "l2tp")) { |
|---|
| 3102 |
/* |
|---|
| 3103 |
* Delete all default routes |
|---|
| 3104 |
*/ |
|---|
| 3105 |
while (route_del |
|---|
| 3106 |
(nvram_safe_get("wan_ifname"), 0, NULL, NULL, |
|---|
| 3107 |
NULL) == 0) ; |
|---|
| 3108 |
} |
|---|
| 3109 |
|
|---|
| 3110 |
/* |
|---|
| 3111 |
* Delete all default routes |
|---|
| 3112 |
*/ |
|---|
| 3113 |
while (route_del(wan_ifname, 0, NULL, NULL, NULL) == 0) ; |
|---|
| 3114 |
|
|---|
| 3115 |
if ((nvram_match("wan_proto", "pppoe")) && check_wan_link(1)) { |
|---|
| 3116 |
while (route_del |
|---|
| 3117 |
(nvram_safe_get("wan_ifname_1"), 0, NULL, NULL, |
|---|
| 3118 |
NULL) == 0) ; |
|---|
| 3119 |
} |
|---|
| 3120 |
|
|---|
| 3121 |
if (nvram_invmatch("wan_proto", "disabled")) { |
|---|
| 3122 |
int timeout = 5; |
|---|
| 3123 |
|
|---|
| 3124 |
/* |
|---|
| 3125 |
* Set default route to gateway if specified |
|---|
| 3126 |
*/ |
|---|
| 3127 |
char *gateway = nvram_match("wan_proto", |
|---|
| 3128 |
"pptp") ? |
|---|
| 3129 |
nvram_safe_get("pptp_get_ip") : |
|---|
| 3130 |
nvram_safe_get("wan_gateway"); |
|---|
| 3131 |
if (strcmp(gateway, "0.0.0.0")) |
|---|
| 3132 |
while (route_add |
|---|
| 3133 |
(wan_ifname, 0, "0.0.0.0", gateway, "0.0.0.0") |
|---|
| 3134 |
&& timeout--) { |
|---|
| 3135 |
if ((nvram_match("wan_proto", "pppoe")) |
|---|
| 3136 |
&& nvram_match("ppp_demand", "1")) { |
|---|
| 3137 |
printf |
|---|
| 3138 |
("Wait ppp interface to init (3) ...\n"); |
|---|
| 3139 |
sleep(1); |
|---|
| 3140 |
} else |
|---|
| 3141 |
break; |
|---|
| 3142 |
|
|---|
| 3143 |
} |
|---|
| 3144 |
} |
|---|
| 3145 |
|
|---|
| 3146 |
/* |
|---|
| 3147 |
* Delete all default routes |
|---|
| 3148 |
*/ |
|---|
| 3149 |
// while (route_del(wan_ifname, 0, NULL, NULL, NULL) == 0); |
|---|
| 3150 |
|
|---|
| 3151 |
/* |
|---|
| 3152 |
* Set default route to gateway if specified |
|---|
| 3153 |
*/ |
|---|
| 3154 |
/* |
|---|
| 3155 |
* while (strcmp(nvram_safe_get("wan_proto"), "disabled") && |
|---|
| 3156 |
* route_add(wan_ifname, 0, "0.0.0.0", nvram_safe_get("wan_gateway"), |
|---|
| 3157 |
* "0.0.0.0") && timeout-- ){ if (nvram_match("wan_proto", "pppoe") && |
|---|
| 3158 |
* nvram_match("ppp_demand", "1")) { printf("Wait ppp interface to init |
|---|
| 3159 |
* (3) ...\n"); sleep(1); } } |
|---|
| 3160 |
*/ |
|---|
| 3161 |
if (nvram_match("wan_proto", "pptp")) { |
|---|
| 3162 |
route_del(nvram_safe_get("wan_iface"), 0, |
|---|
| 3163 |
nvram_safe_get("wan_gateway"), NULL, |
|---|
| 3164 |
"255.255.255.255"); |
|---|
| 3165 |
route_del(nvram_safe_get("wan_iface"), 0, |
|---|
| 3166 |
nvram_safe_get("pptp_server_ip"), NULL, |
|---|
| 3167 |
"255.255.255.255"); |
|---|
| 3168 |
route_add(nvram_safe_get("wan_iface"), 0, |
|---|
| 3169 |
nvram_safe_get("pptp_get_ip"), NULL, |
|---|
| 3170 |
"255.255.255.255"); |
|---|
| 3171 |
} else if (nvram_match("wan_proto", "l2tp")) { |
|---|
| 3172 |
route_del(nvram_safe_get("wan_iface"), 0, |
|---|
| 3173 |
nvram_safe_get("wan_gateway"), NULL, |
|---|
| 3174 |
"255.255.255.255"); |
|---|
| 3175 |
route_add(nvram_safe_get("wan_iface"), 0, |
|---|
| 3176 |
nvram_safe_get("l2tp_get_ip"), NULL, |
|---|
| 3177 |
"255.255.255.255"); |
|---|
| 3178 |
route_add(nvram_safe_get("wan_ifname"), 0, nvram_safe_get("l2tp_server_ip"), nvram_safe_get("wan_gateway_buf"), "255.255.255.255"); // fixed |
|---|
| 3179 |
// routing |
|---|
| 3180 |
// problem |
|---|
| 3181 |
// in |
|---|
| 3182 |
// Israel |
|---|
| 3183 |
// by |
|---|
| 3184 |
// kanki |
|---|
| 3185 |
} |
|---|
| 3186 |
|
|---|
| 3187 |
/* |
|---|
| 3188 |
* save dns to resolv.conf |
|---|
| 3189 |
*/ |
|---|
| 3190 |
cprintf("dns to resolv\n"); |
|---|
| 3191 |
dns_to_resolv(); |
|---|
| 3192 |
|
|---|
| 3193 |
cprintf("restart dhcp server\n"); |
|---|
| 3194 |
/* |
|---|
| 3195 |
* Restart DHCP server |
|---|
| 3196 |
*/ |
|---|
| 3197 |
#ifdef HAVE_UDHCPD |
|---|
| 3198 |
stop_udhcpd(); |
|---|
| 3199 |
start_udhcpd(); |
|---|
| 3200 |
#endif |
|---|
| 3201 |
cprintf("restart dns proxy\n"); |
|---|
| 3202 |
/* |
|---|
| 3203 |
* Restart DNS proxy stop_dnsmasq (); start_dnsmasq (); |
|---|
| 3204 |
*/ |
|---|
| 3205 |
cprintf("start firewall\n"); |
|---|
| 3206 |
/* |
|---|
| 3207 |
* Start firewall |
|---|
| 3208 |
*/ |
|---|
| 3209 |
start_firewall(); |
|---|
| 3210 |
|
|---|
| 3211 |
/* |
|---|
| 3212 |
* Set additional wan static routes if need |
|---|
| 3213 |
*/ |
|---|
| 3214 |
|
|---|
| 3215 |
start_set_routes(); |
|---|
| 3216 |
cprintf("routes done\n"); |
|---|
| 3217 |
if (nvram_match("wan_proto", "pppoe") |
|---|
| 3218 |
|| nvram_match("wan_proto", "pptp") |
|---|
| 3219 |
|| nvram_match("wan_proto", "l2tp") |
|---|
| 3220 |
|| nvram_match("wan_proto", "3g")) { |
|---|
| 3221 |
if (nvram_match("ppp_demand", "1")) { // ntp and ddns will trigger DOD, so we must |
|---|
| 3222 |
// stop them when wan is unavaile. |
|---|
| 3223 |
FILE *fp; |
|---|
| 3224 |
|
|---|
| 3225 |
if ((fp = fopen("/tmp/ppp/link", "r"))) { |
|---|
| 3226 |
start_wan_service(); |
|---|
| 3227 |
fclose(fp); |
|---|
| 3228 |
} |
|---|
| 3229 |
} else { |
|---|
| 3230 |
start_wan_service(); |
|---|
| 3231 |
} |
|---|
| 3232 |
} else { |
|---|
| 3233 |
start_wan_service(); |
|---|
| 3234 |
} |
|---|
| 3235 |
|
|---|
| 3236 |
#ifdef HAVE_UPNP |
|---|
| 3237 |
stop_upnp(); |
|---|
| 3238 |
#endif |
|---|
| 3239 |
#ifdef HAVE_BIRD |
|---|
| 3240 |
stop_zebra(); |
|---|
| 3241 |
#endif |
|---|
| 3242 |
// stop_cron (); |
|---|
| 3243 |
stop_wshaper(); |
|---|
| 3244 |
cprintf("start zebra\n"); |
|---|
| 3245 |
#ifdef HAVE_BIRD |
|---|
| 3246 |
start_zebra(); |
|---|
| 3247 |
#endif |
|---|
| 3248 |
cprintf("start upnp\n"); |
|---|
| 3249 |
#ifdef HAVE_UPNP |
|---|
| 3250 |
start_upnp(); |
|---|
| 3251 |
#endif |
|---|
| 3252 |
// cprintf ("start cron\n"); |
|---|
| 3253 |
// start_OAcron (); |
|---|
| 3254 |
cprintf("start wshaper\n"); |
|---|
| 3255 |
stop_wland(); |
|---|
| 3256 |
start_wshaper(); |
|---|
| 3257 |
start_wland(); |
|---|
| 3258 |
if (nvram_match("wan_proto", "pptp")) { |
|---|
| 3259 |
|
|---|
| 3260 |
if (nvram_invmatch("pptp_customipup", "")) { |
|---|
| 3261 |
|
|---|
| 3262 |
// We not going to assume that /tmp/ppp is created.. |
|---|
| 3263 |
mkdir("/tmp/ppp", 0700); |
|---|
| 3264 |
|
|---|
| 3265 |
// Create our custom pptp ipup script and change its attributes |
|---|
| 3266 |
nvram2file("pptp_customipup", |
|---|
| 3267 |
"/tmp/ppp/sh_pptp_customipup"); |
|---|
| 3268 |
chmod("/tmp/ppp/sh_pptp_customipup", 0744); |
|---|
| 3269 |
|
|---|
| 3270 |
// Execute our custom ipup script |
|---|
| 3271 |
system2("/tmp/ppp/sh_pptp_customipup"); |
|---|
| 3272 |
|
|---|
| 3273 |
} |
|---|
| 3274 |
} |
|---|
| 3275 |
cprintf("std on\n"); |
|---|
| 3276 |
#ifdef HAVE_MICRO |
|---|
| 3277 |
br_init(); |
|---|
| 3278 |
#endif |
|---|
| 3279 |
|
|---|
| 3280 |
if (nvram_match("lan_stp", "0")) |
|---|
| 3281 |
br_set_stp_state(nvram_safe_get("lan_ifname"), 0); |
|---|
| 3282 |
else |
|---|
| 3283 |
br_set_stp_state(nvram_safe_get("lan_ifname"), 1); |
|---|
| 3284 |
#ifdef HAVE_MICRO |
|---|
| 3285 |
br_shutdown(); |
|---|
| 3286 |
#endif |
|---|
| 3287 |
|
|---|
| 3288 |
cprintf("check wan link\n"); |
|---|
| 3289 |
if (check_wan_link(0)) |
|---|
| 3290 |
SET_LED(GOT_IP); |
|---|
| 3291 |
else if ((!check_wan_link(0)) && nvram_match("wan_proto", "auto")) { |
|---|
| 3292 |
SET_LED(GET_IP_ERROR); |
|---|
| 3293 |
} |
|---|
| 3294 |
/* |
|---|
| 3295 |
* check ip addresses for validity |
|---|
| 3296 |
*/ |
|---|
| 3297 |
uint32 wanip; |
|---|
| 3298 |
uint32 wannm; |
|---|
| 3299 |
|
|---|
| 3300 |
inet_aton(nvram_safe_get("wan_ipaddr"), (struct in_addr *)&wanip); |
|---|
| 3301 |
inet_aton(nvram_safe_get("wan_netmask"), (struct in_addr *)&wannm); |
|---|
| 3302 |
uint32 lanip; |
|---|
| 3303 |
uint32 lannm; |
|---|
| 3304 |
|
|---|
| 3305 |
inet_aton(nvram_safe_get("lan_ipaddr"), (struct in_addr *)&lanip); |
|---|
| 3306 |
inet_aton(nvram_safe_get("lan_netmask"), (struct in_addr *)&lannm); |
|---|
| 3307 |
|
|---|
| 3308 |
if (wanip != 0 && nvram_match("wan_ipaddr", "0.0.0.0") |
|---|
| 3309 |
&& !nvram_match("wan_proto", "disabled")) { |
|---|
| 3310 |
int iperror = 0; |
|---|
| 3311 |
|
|---|
| 3312 |
if ((wanip & wannm) == (lanip & wannm)) |
|---|
| 3313 |
iperror = 1; |
|---|
| 3314 |
if ((lanip & lannm) == (wanip & lannm)) |
|---|
| 3315 |
iperror = 1; |
|---|
| 3316 |
if (iperror) |
|---|
| 3317 |
eval("ledtool", "5"); // blink 5 times the 3 time interval |
|---|
| 3318 |
} |
|---|
| 3319 |
/* |
|---|
| 3320 |
* end |
|---|
| 3321 |
*/ |
|---|
| 3322 |
|
|---|
| 3323 |
cprintf("running custom DD-WRT ipup scripts\n"); |
|---|
| 3324 |
runStartup("/etc/config", ".ipup"); |
|---|
| 3325 |
#ifdef HAVE_RB500 |
|---|
| 3326 |
runStartup("/usr/local/etc/config", ".ipup"); |
|---|
| 3327 |
#else |
|---|
| 3328 |
runStartup("/jffs/etc/config", ".ipup"); |
|---|
| 3329 |
runStartup("/mmc/etc/config", ".ipup"); |
|---|
| 3330 |
#endif |
|---|
| 3331 |
cprintf("trigger gpio"); |
|---|
| 3332 |
|
|---|
| 3333 |
led_control(LED_CONNECTED, LED_ON); |
|---|
| 3334 |
|
|---|
| 3335 |
if (!nvram_match("wan_proto", "disabled")) |
|---|
| 3336 |
dd_syslog(LOG_INFO, "WAN is up. IP: %s\n", |
|---|
| 3337 |
nvram_safe_get("wan_ipaddr")); |
|---|
| 3338 |
|
|---|
| 3339 |
float sys_uptime; |
|---|
| 3340 |
FILE *up; |
|---|
| 3341 |
|
|---|
| 3342 |
up = fopen("/proc/uptime", "r"); |
|---|
| 3343 |
fscanf(up, "%f", &sys_uptime); |
|---|
| 3344 |
fclose(up); |
|---|
| 3345 |
|
|---|
| 3346 |
up = fopen("/tmp/.wanuptime", "w"); |
|---|
| 3347 |
fprintf(up, "%f", sys_uptime); |
|---|
| 3348 |
fclose(up); |
|---|
| 3349 |
|
|---|
| 3350 |
cprintf("done\n"); |
|---|
| 3351 |
|
|---|
| 3352 |
nvram_set("wan_iface", nvram_safe_get("wan_ifname")); |
|---|
| 3353 |
|
|---|
| 3354 |
#ifdef HAVE_OPENVPN |
|---|
| 3355 |
cprintf("starting openvpn\n"); |
|---|
| 3356 |
stop_openvpn(); |
|---|
| 3357 |
start_openvpn(); |
|---|
| 3358 |
cprintf("done\n"); |
|---|
| 3359 |
|
|---|
| 3360 |
#endif |
|---|
| 3361 |
#ifdef HAVE_OPENVPN |
|---|
| 3362 |
stop_openvpnserverwan(); |
|---|
| 3363 |
start_openvpnserverwan(); |
|---|
| 3364 |
#endif |
|---|
| 3365 |
#ifdef HAVE_DHCPFORWARD |
|---|
| 3366 |
stop_dhcpfwd(); |
|---|
| 3367 |
start_dhcpfwd(); |
|---|
| 3368 |
#endif |
|---|
| 3369 |
nvram_set("wanup", "1"); |
|---|
| 3370 |
#ifdef HAVE_MILKFISH |
|---|
| 3371 |
if (nvram_match("milkfish_enabled", "1")) { |
|---|
| 3372 |
cprintf("starting milkfish netup script\n"); |
|---|
| 3373 |
eval("/etc/config/milkfish.netup"); |
|---|
| 3374 |
} |
|---|
| 3375 |
#endif |
|---|
| 3376 |
#ifdef HAVE_SPUTNIK_APD |
|---|
| 3377 |
stop_sputnik(); |
|---|
| 3378 |
start_sputnik(); |
|---|
| 3379 |
#endif |
|---|
| 3380 |
|
|---|
| 3381 |
#ifdef HAVE_FON |
|---|
| 3382 |
#ifdef HAVE_MICRO |
|---|
| 3383 |
br_init(); |
|---|
| 3384 |
#endif |
|---|
| 3385 |
|
|---|
| 3386 |
if (nvram_match("wl0_mode", "apsta")) { |
|---|
| 3387 |
br_del_interface(nvram_safe_get("lan_ifname"), "wl0.1"); |
|---|
| 3388 |
ifconfig("wl0.1", IFUP | IFF_ALLMULTI, "0.0.0.0", NULL); |
|---|
| 3389 |
} else if (nvram_match("wl0_mode", "ap")) { |
|---|
| 3390 |
br_del_interface(nvram_safe_get("lan_ifname"), get_wdev()); |
|---|
| 3391 |
ifconfig(get_wdev(), IFUP | IFF_ALLMULTI, "0.0.0.0", NULL); |
|---|
| 3392 |
} |
|---|
| 3393 |
#ifdef HAVE_CHILLI |
|---|
| 3394 |
stop_chilli(); |
|---|
| 3395 |
start_chilli(); |
|---|
| 3396 |
#endif |
|---|
| 3397 |
#else |
|---|
| 3398 |
if (nvram_match("fon_enable", "1") |
|---|
| 3399 |
|| (nvram_match("chilli_nowifibridge", "1") |
|---|
| 3400 |
&& nvram_match("chilli_enable", "1"))) { |
|---|
| 3401 |
if (nvram_match("wl0_mode", "apsta")) { |
|---|
| 3402 |
br_del_interface(nvram_safe_get("lan_ifname"), "wl0.1"); |
|---|
| 3403 |
ifconfig("wl0.1", IFUP | IFF_ALLMULTI, "0.0.0.0", NULL); |
|---|
| 3404 |
} else if (nvram_match("wl0_mode", "ap")) { |
|---|
| 3405 |
br_del_interface(nvram_safe_get("lan_ifname"), |
|---|
| 3406 |
get_wdev()); |
|---|
| 3407 |
ifconfig(get_wdev(), IFUP | IFF_ALLMULTI, "0.0.0.0", |
|---|
| 3408 |
NULL); |
|---|
| 3409 |
} |
|---|
| 3410 |
#ifdef HAVE_CHILLI |
|---|
| 3411 |
stop_chilli(); |
|---|
| 3412 |
start_chilli(); |
|---|
| 3413 |
#endif |
|---|
| 3414 |
} |
|---|
| 3415 |
#endif |
|---|
| 3416 |
#ifdef HAVE_MICRO |
|---|
| 3417 |
br_shutdown(); |
|---|
| 3418 |
#endif |
|---|
| 3419 |
#if defined(HAVE_MADWIFI) || defined(HAVE_RT2880) |
|---|
| 3420 |
#ifndef HAVE_NOWIFI |
|---|
| 3421 |
start_hostapdwan(); |
|---|
| 3422 |
#endif |
|---|
| 3423 |
#endif |
|---|
| 3424 |
cprintf("start igmp proxy\n"); |
|---|
| 3425 |
#ifdef HAVE_MULTICAST |
|---|
| 3426 |
if (!nvram_match("dtag_vlan8", "1")) |
|---|
| 3427 |
stop_igmp_proxy(); |
|---|
| 3428 |
start_igmp_proxy(); |
|---|
| 3429 |
#endif |
|---|
| 3430 |
cprintf("ready\n"); |
|---|
| 3431 |
start_anchorfree(); |
|---|
| 3432 |
start_anchorfreednat(); |
|---|
| 3433 |
#ifdef HAVE_MADWIFI |
|---|
| 3434 |
start_duallink(); |
|---|
| 3435 |
#endif |
|---|
| 3436 |
} |
|---|
| 3437 |
|
|---|
| 3438 |
void stop_wan(void) |
|---|
| 3439 |
{ |
|---|
| 3440 |
char *wan_ifname = get_wan_face(); |
|---|
| 3441 |
|
|---|
| 3442 |
nvram_set("wanup", "0"); |
|---|
| 3443 |
|
|---|
| 3444 |
led_control(LED_CONNECTED, LED_OFF); |
|---|
| 3445 |
unlink("/tmp/.wanuptime"); |
|---|
| 3446 |
|
|---|
| 3447 |
cprintf("%s %s\n", wan_ifname, nvram_safe_get("wan_proto")); |
|---|
| 3448 |
#ifdef HAVE_OPENVPN |
|---|
| 3449 |
stop_openvpnserverwan(); |
|---|
| 3450 |
stop_openvpn(); |
|---|
| 3451 |
#endif |
|---|
| 3452 |
#ifdef HAVE_DHCPFORWARD |
|---|
| 3453 |
stop_dhcpfwd(); |
|---|
| 3454 |
#endif |
|---|
| 3455 |
/* |
|---|
| 3456 |
* Stop firewall |
|---|
| 3457 |
*/ |
|---|
| 3458 |
stop_firewall(); |
|---|
| 3459 |
/* |
|---|
| 3460 |
* Kill any WAN client daemons or callbacks |
|---|
| 3461 |
*/ |
|---|
| 3462 |
#ifdef HAVE_PPPOE |
|---|
| 3463 |
stop_pppoe(); |
|---|
| 3464 |
#endif |
|---|
| 3465 |
#ifdef HAVE_L2TP |
|---|
| 3466 |
stop_l2tp(); |
|---|
| 3467 |
#endif |
|---|
| 3468 |
stop_dhcpc(); |
|---|
| 3469 |
#ifdef HAVE_HEARTBEAT |
|---|
| 3470 |
stop_heartbeat(); |
|---|
| 3471 |
#endif |
|---|
| 3472 |
#ifdef HAVE_PPTP |
|---|
| 3473 |
stop_pptp(); |
|---|
| 3474 |
#endif |
|---|
| 3475 |
#ifdef HAVE_SPUTNIK_APD |
|---|
| 3476 |
stop_sputnik(); |
|---|
| 3477 |
#endif |
|---|
| 3478 |
stop_ntpc(); |
|---|
| 3479 |
stop_redial(); |
|---|
| 3480 |
nvram_set("wan_get_dns", ""); |
|---|
| 3481 |
|
|---|
| 3482 |
// Reset pppd's pppX interface |
|---|
| 3483 |
nvram_set("pppd_pppifname", ""); |
|---|
| 3484 |
|
|---|
| 3485 |
/* |
|---|
| 3486 |
* Bring down WAN interfaces |
|---|
| 3487 |
*/ |
|---|
| 3488 |
ifconfig(wan_ifname, 0, NULL, NULL); |
|---|
| 3489 |
eval("ifconfig", wan_ifname, "down"); // to allow for MAC clone to |
|---|
| 3490 |
// take effect |
|---|
| 3491 |
#ifdef HAVE_PPP |
|---|
| 3492 |
#endif |
|---|
| 3493 |
#ifndef HAVE_FON |
|---|
| 3494 |
if (nvram_match("fon_enable", "1") |
|---|
| 3495 |
|| (nvram_match("chilli_nowifibridge", "1") |
|---|
| 3496 |
&& nvram_match("chilli_enable", "1"))) |
|---|
| 3497 |
#endif |
|---|
| 3498 |
{ |
|---|
| 3499 |
#ifdef HAVE_MICRO |
|---|
| 3500 |
br_init(); |
|---|
| 3501 |
#endif |
|---|
| 3502 |
|
|---|
| 3503 |
br_add_interface(getBridge(get_wdev()), get_wdev()); |
|---|
| 3504 |
#ifdef HAVE_MICRO |
|---|
| 3505 |
br_shutdown(); |
|---|
| 3506 |
#endif |
|---|
| 3507 |
|
|---|
| 3508 |
} |
|---|
| 3509 |
|
|---|
| 3510 |
cprintf("done\n"); |
|---|
| 3511 |
} |
|---|
| 3512 |
|
|---|
| 3513 |
void start_set_routes(void) |
|---|
| 3514 |
{ |
|---|
| 3515 |
char word[80], *tmp; |
|---|
| 3516 |
char *ipaddr, *netmask, *gateway, *metric, *ifname; |
|---|
| 3517 |
|
|---|
| 3518 |
if (!nvram_match("lan_gateway", "0.0.0.0")) { |
|---|
| 3519 |
eval("route", "del", "default"); |
|---|
| 3520 |
eval("route", "add", "default", "gw", |
|---|
| 3521 |
nvram_safe_get("lan_gateway")); |
|---|
| 3522 |
} |
|---|
| 3523 |
char *defgateway; |
|---|
| 3524 |
|
|---|
| 3525 |
if (nvram_match("wan_proto", "pptp")) |
|---|
| 3526 |
defgateway = nvram_safe_get("pptp_get_ip"); |
|---|
| 3527 |
else if (nvram_match("wan_proto", "l2tp")) |
|---|
| 3528 |
defgateway = nvram_safe_get("l2tp_get_ip"); |
|---|
| 3529 |
else |
|---|
| 3530 |
defgateway = nvram_safe_get("wan_gateway"); |
|---|
| 3531 |
if (strcmp(defgateway, "0.0.0.0") |
|---|
| 3532 |
&& !nvram_match("wan_proto", "disabled")) { |
|---|
| 3533 |
eval("route", "del", "default"); |
|---|
| 3534 |
eval("route", "add", "default", "gw", defgateway); |
|---|
| 3535 |
} |
|---|
| 3536 |
foreach(word, nvram_safe_get("static_route"), tmp) { |
|---|
| 3537 |
netmask = word; |
|---|
| 3538 |
ipaddr = strsep(&netmask, ":"); |
|---|
| 3539 |
if (!ipaddr || !netmask) |
|---|
| 3540 |
continue; |
|---|
| 3541 |
gateway = netmask; |
|---|
| 3542 |
netmask = strsep(&gateway, ":"); |
|---|
| 3543 |
if (!netmask || !gateway) |
|---|
| 3544 |
continue; |
|---|
| 3545 |
metric = gateway; |
|---|
| 3546 |
gateway = strsep(&metric, ":"); |
|---|
| 3547 |
if (!gateway || !metric) |
|---|
| 3548 |
continue; |
|---|
| 3549 |
ifname = metric; |
|---|
| 3550 |
metric = strsep(&ifname, ":"); |
|---|
| 3551 |
if (!metric || !ifname) |
|---|
| 3552 |
continue; |
|---|
| 3553 |
if (!strcmp(ipaddr, "0.0.0.0") && !strcmp(gateway, "0.0.0.0")) |
|---|
| 3554 |
continue; |
|---|
| 3555 |
if (!strcmp(ipaddr, "0.0.0.0")) { |
|---|
| 3556 |
eval("route", "del", "default"); |
|---|
| 3557 |
eval("route", "add", "default", "gw", gateway); |
|---|
| 3558 |
} else if (!strcmp(ifname, "any")) { |
|---|
| 3559 |
eval("route", "add", "-net", ipaddr, "netmask", netmask, |
|---|
| 3560 |
"gw", gateway, "metric", metric); |
|---|
| 3561 |
} else |
|---|
| 3562 |
route_add(ifname, atoi(metric) + 1, ipaddr, gateway, |
|---|
| 3563 |
netmask); |
|---|
| 3564 |
} |
|---|
| 3565 |
if (f_exists("/tmp/tvrouting")) |
|---|
| 3566 |
system("sh /tmp/tvrouting"); |
|---|
| 3567 |
} |
|---|
| 3568 |
|
|---|
| 3569 |
#if !defined(HAVE_MADWIFI) && !defined(HAVE_RT2880) |
|---|
| 3570 |
static int notify_nas(char *type, char *ifname, char *action) |
|---|
| 3571 |
{ |
|---|
| 3572 |
char *argv[] = { "nas4not", type, ifname, action, |
|---|
| 3573 |
NULL, /* role */ |
|---|
| 3574 |
NULL, /* crypto */ |
|---|
| 3575 |
NULL, /* auth */ |
|---|
| 3576 |
NULL, /* passphrase */ |
|---|
| 3577 |
NULL, /* ssid */ |
|---|
| 3578 |
NULL |
|---|
| 3579 |
}; |
|---|
| 3580 |
char *str = NULL; |
|---|
| 3581 |
int retries = 10; |
|---|
| 3582 |
char tmp[100], prefix[] = "wlXXXXXXXXXX_"; |
|---|
| 3583 |
int unit; |
|---|
| 3584 |
char remote[ETHER_ADDR_LEN]; |
|---|
| 3585 |
char ssid[48], pass[80], auth[16], crypto[16], role[8]; |
|---|
| 3586 |
int i; |
|---|
| 3587 |
|
|---|
| 3588 |
/* |
|---|
| 3589 |
* the wireless interface must be configured to run NAS |
|---|
| 3590 |
*/ |
|---|
| 3591 |
wl_ioctl(ifname, WLC_GET_INSTANCE, &unit, sizeof(unit)); |
|---|
| 3592 |
snprintf(prefix, sizeof(prefix), "wl%d_", unit); |
|---|
| 3593 |
if (nvram_match(strcat_r(prefix, "akm", tmp), "") && |
|---|
| 3594 |
nvram_match(strcat_r(prefix, "auth_mode", tmp), "none")) |
|---|
| 3595 |
return 0; |
|---|
| 3596 |
|
|---|
| 3597 |
while (retries-- > 0 && !(str = file2str("/tmp/nas.wl0lan.pid"))) |
|---|
| 3598 |
sleep(1); |
|---|
| 3599 |
if (!str) { |
|---|
| 3600 |
return -1; |
|---|
| 3601 |
} |
|---|
| 3602 |
free(str); |
|---|
| 3603 |
sleep(3); |
|---|
| 3604 |
/* |
|---|
| 3605 |
* find WDS link configuration |
|---|
| 3606 |
*/ |
|---|
| 3607 |
wl_ioctl(ifname, WLC_WDS_GET_REMOTE_HWADDR, remote, ETHER_ADDR_LEN); |
|---|
| 3608 |
for (i = 0; i < MAX_NVPARSE; i++) { |
|---|
| 3609 |
char mac[ETHER_ADDR_STR_LEN]; |
|---|
| 3610 |
uint8 ea[ETHER_ADDR_LEN]; |
|---|
| 3611 |
|
|---|
| 3612 |
if (get_wds_wsec(unit, i, mac, role, crypto, auth, ssid, pass) |
|---|
| 3613 |
&& ether_atoe(mac, ea) |
|---|
| 3614 |
&& !bcmp(ea, remote, ETHER_ADDR_LEN)) { |
|---|
| 3615 |
argv[4] = role; |
|---|
| 3616 |
argv[5] = crypto; |
|---|
| 3617 |
argv[6] = auth; |
|---|
| 3618 |
argv[7] = pass; |
|---|
| 3619 |
argv[8] = ssid; |
|---|
| 3620 |
break; |
|---|
| 3621 |
} |
|---|
| 3622 |
} |
|---|
| 3623 |
|
|---|
| 3624 |
/* |
|---|
| 3625 |
* did not find WDS link configuration, use wireless' |
|---|
| 3626 |
*/ |
|---|
| 3627 |
if (i == MAX_NVPARSE) { |
|---|
| 3628 |
/* |
|---|
| 3629 |
* role |
|---|
| 3630 |
*/ |
|---|
| 3631 |
argv[4] = "auto"; |
|---|
| 3632 |
/* |
|---|
| 3633 |
* crypto |
|---|
| 3634 |
*/ |
|---|
| 3635 |
argv[5] = nvram_safe_get(strcat_r(prefix, "crypto", tmp)); |
|---|
| 3636 |
/* |
|---|
| 3637 |
* auth mode |
|---|
| 3638 |
*/ |
|---|
| 3639 |
argv[6] = nvram_safe_get(strcat_r(prefix, "akm", tmp)); |
|---|
| 3640 |
/* |
|---|
| 3641 |
* passphrase |
|---|
| 3642 |
*/ |
|---|
| 3643 |
argv[7] = nvram_safe_get(strcat_r(prefix, "wpa_psk", tmp)); |
|---|
| 3644 |
/* |
|---|
| 3645 |
* ssid |
|---|
| 3646 |
*/ |
|---|
| 3647 |
argv[8] = nvram_safe_get(strcat_r(prefix, "ssid", tmp)); |
|---|
| 3648 |
} |
|---|
| 3649 |
int pid; |
|---|
| 3650 |
|
|---|
| 3651 |
return _evalpid(argv, ">/dev/console", 0, &pid); |
|---|
| 3652 |
} |
|---|
| 3653 |
#endif |
|---|
| 3654 |
/* |
|---|
| 3655 |
* static int notify_nas(char *type, char *ifname, char *action) { char |
|---|
| 3656 |
* *argv[] = {"nas4not", type, ifname, action, NULL, NULL, NULL, NULL, |
|---|
| 3657 |
* NULL, NULL}; char *str = NULL; int retries = 10; char tmp[100], prefix[] |
|---|
| 3658 |
* = "wlXXXXXXXXXX_"; int unit; char remote[ETHER_ADDR_LEN]; char ssid[48], |
|---|
| 3659 |
* pass[80], auth[16], crypto[16], role[8]; int i; |
|---|
| 3660 |
* |
|---|
| 3661 |
* wl_ioctl(ifname, WLC_GET_INSTANCE, &unit, sizeof(unit)); snprintf(prefix, |
|---|
| 3662 |
* sizeof(prefix), "wl%d_", unit); #ifdef WPA2_WMM if |
|---|
| 3663 |
* (nvram_match(strcat_r(prefix, "akm", tmp), "") && |
|---|
| 3664 |
* nvram_match(strcat_r(prefix, "auth_mode", tmp), "none")) #else if |
|---|
| 3665 |
* (nvram_match(strcat_r(prefix, "auth_mode", tmp), "open") || |
|---|
| 3666 |
* nvram_match(strcat_r(prefix, "auth_mode", tmp), "shared")) #endif return |
|---|
| 3667 |
* 0; |
|---|
| 3668 |
* |
|---|
| 3669 |
* wl_ioctl(ifname, WLC_WDS_GET_REMOTE_HWADDR, remote, ETHER_ADDR_LEN); for |
|---|
| 3670 |
* (i = 0; i < MAX_NVPARSE; i ++) { char mac[ETHER_ADDR_STR_LEN]; uint8 |
|---|
| 3671 |
* ea[ETHER_ADDR_LEN]; |
|---|
| 3672 |
* |
|---|
| 3673 |
* if (get_wds_wsec(unit, i, mac, role, crypto, auth, ssid, pass) && |
|---|
| 3674 |
* ether_atoe(mac, ea) && !bcmp(ea, remote, ETHER_ADDR_LEN)) { argv[4] = |
|---|
| 3675 |
* role; argv[5] = crypto; argv[6] = auth; argv[7] = pass; argv[8] = ssid; |
|---|
| 3676 |
* break; } } |
|---|
| 3677 |
* |
|---|
| 3678 |
* if (i == MAX_NVPARSE) { |
|---|
| 3679 |
* |
|---|
| 3680 |
* argv[4] = "auto"; |
|---|
| 3681 |
* |
|---|
| 3682 |
* argv[5] = nvram_safe_get(strcat_r(prefix, "crypto", tmp)); |
|---|
| 3683 |
* |
|---|
| 3684 |
* #ifdef WPA2_WMM argv[6] = nvram_safe_get(strcat_r(prefix, "akm", tmp)); |
|---|
| 3685 |
* #else argv[6] = nvram_safe_get(strcat_r(prefix, "auth_mode", tmp)); #endif |
|---|
| 3686 |
* |
|---|
| 3687 |
* argv[7] = nvram_safe_get(strcat_r(prefix, "wpa_psk", tmp)); |
|---|
| 3688 |
* |
|---|
| 3689 |
* argv[8] = nvram_safe_get(strcat_r(prefix, "ssid", tmp)); } |
|---|
| 3690 |
* |
|---|
| 3691 |
* while (retries -- > 0 && !(str = file2str("/tmp/nas.lan.pid"))) sleep(1); |
|---|
| 3692 |
* if (str) { int pid; free(str); return _eval(argv, ">/dev/console", 0, |
|---|
| 3693 |
* &pid); } return -1; |
|---|
| 3694 |
* |
|---|
| 3695 |
* } |
|---|
| 3696 |
*/ |
|---|
| 3697 |
void start_hotplug_net(void) |
|---|
| 3698 |
{ |
|---|
| 3699 |
#ifdef HAVE_MADWIFI |
|---|
| 3700 |
char *interface, *action; |
|---|
| 3701 |
|
|---|
| 3702 |
interface = getenv("INTERFACE"); |
|---|
| 3703 |
if (!interface) |
|---|
| 3704 |
return; |
|---|
| 3705 |
action = getenv("ACTION"); |
|---|
| 3706 |
if (!action) |
|---|
| 3707 |
return; |
|---|
| 3708 |
// sysprintf("echo \"Hotplug %s=%s\" > /dev/console\n",action,interface); |
|---|
| 3709 |
if (strncmp(interface, "ath", 3)) |
|---|
| 3710 |
return; |
|---|
| 3711 |
|
|---|
| 3712 |
// try to parse |
|---|
| 3713 |
char ifname[32]; |
|---|
| 3714 |
|
|---|
| 3715 |
memset(ifname, 0, 32); |
|---|
| 3716 |
int index = indexof(interface, '.'); |
|---|
| 3717 |
|
|---|
| 3718 |
if (index == -1) |
|---|
| 3719 |
return; |
|---|
| 3720 |
strncpy(ifname, interface + index + 1, strlen(interface) - (index + 1)); |
|---|
| 3721 |
if (strncmp(ifname, "sta", 3)) { |
|---|
| 3722 |
return; |
|---|
| 3723 |
} |
|---|
| 3724 |
char nr[32]; |
|---|
| 3725 |
|
|---|
| 3726 |
memset(nr, 0, 32); |
|---|
| 3727 |
strcpy(nr, ((unsigned char *)&ifname[0]) + 3); |
|---|
| 3728 |
memset(ifname, 0, 32); |
|---|
| 3729 |
strncpy(ifname, interface, index); |
|---|
| 3730 |
char bridged[32]; |
|---|
| 3731 |
|
|---|
| 3732 |
sprintf(bridged, "%s_bridged", ifname); |
|---|
| 3733 |
|
|---|
| 3734 |
if (!strcmp(action, "add")) { |
|---|
| 3735 |
fprintf(stderr, "adding WDS %s\n", interface); |
|---|
| 3736 |
|
|---|
| 3737 |
eval("ifconfig", interface, "up"); |
|---|
| 3738 |
if (nvram_match(bridged, "1")) |
|---|
| 3739 |
br_add_interface(getBridge(ifname), interface); |
|---|
| 3740 |
} |
|---|
| 3741 |
if (!strcmp(action, "remove")) { |
|---|
| 3742 |
fprintf(stderr, "removing WDS %s\n", interface); |
|---|
| 3743 |
eval("ifconfig", interface, "down"); |
|---|
| 3744 |
if (nvram_match(bridged, "1")) |
|---|
| 3745 |
br_del_interface(getBridge(ifname), interface); |
|---|
| 3746 |
} |
|---|
| 3747 |
return; |
|---|
| 3748 |
#else |
|---|
| 3749 |
|
|---|
| 3750 |
// char *lan_ifname = nvram_safe_get("lan_ifname"); |
|---|
| 3751 |
char *interface, *action; |
|---|
| 3752 |
|---|