4 Copyright (C) 2006-2008 Jonathan Zarate
5 rate limit & connection limit by conanxu
11 //#include <sys/stat.h>
13 // read nvram into files
14 void new_arpbind_start(void)
18 char *ipaddr
;//ip address
19 char *macaddr
;//mac address
20 char *s
= "/tmp/new_arpbind_start.sh";
25 const char *router_ip
;
32 if (!nvram_get_int("new_arpbind_enable")) return;
34 //read static dhcp list from nvram
35 p
= nvram_safe_get("dhcpd_static");
37 //read arpbind_list into file
38 if ((f
= fopen(s
, "w")) == NULL
) return;
41 "for HOST in `cat /proc/net/arp |sed -n 's/\\([0-9]*\\.[0-9]*\\.[0-9]*\\.[0-9]*\\).*/\\1/p'`; do arp -d $HOST; done\n"
43 memset(host
, 0, sizeof(host
));
45 //get network ip prefix
46 router_ip
= nvram_safe_get("lan_ipaddr");
47 strlcpy(lan
, router_ip
, sizeof(lan
));
48 if ((p
= strrchr(lan
, '.')) != NULL
) {
53 // 00:aa:bb:cc:dd:ee<123<xxxxxxxxxxxxxxxxxxxxxxxxxx.xyz> = 53 w/ delim
54 // 00:aa:bb:cc:dd:ee<123.123.123.123<xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xyz> = 85 w/ delim
55 // 00:aa:bb:cc:dd:ee,00:aa:bb:cc:dd:ee<123.123.123.123<xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xyz> = 106 w/ delim
56 p
= nvram_safe_get("dhcpd_static");
57 while ((e
= strchr(p
, '>')) != NULL
) {
64 strncpy(buf_arp
, p
, length
);
68 /* get the MAC address */
69 if ((e
= strchr(buf_arp
, '<')) == NULL
) continue;
73 if ((e
= strchr(macaddr
, ',')) != NULL
){
76 //cprintf ("mac address %s\n", macaddr);
78 /* get the IP adddres */
79 if ((e
= strchr(ipaddr
, '<')) == NULL
) continue;
81 if (strchr(ipaddr
, '.') == NULL
) {
83 if ((ipn
<= 0) || (ipn
> 255)) continue;
84 sprintf(ipbuf
, "%s%d", lan
, ipn
);
88 if (inet_addr(ipaddr
) == INADDR_NONE
) continue;
90 //cprintf ("ip address %s\n", ipaddr);
93 if ((*macaddr
!= 0) && (strcmp(macaddr
, "00:00:00:00:00:00") != 0)) {
94 fprintf(f
, "arp -s %s %s\n", ipaddr
, macaddr
);
95 //cprintf ("arp -s %s %s\n", ipaddr, macaddr);
96 if ((q
= strrchr(ipaddr
, '.')) != NULL
) {
98 if (!strcmp(ipaddr
, lan
)) host
[atoi(q
+1)] = 1;
103 if (nvram_get_int("new_arpbind_only")) {
104 for (i
= 1; i
< 255; i
++) {
106 fprintf(f
, "arp -s %s.%d 00:00:00:00:00:00\n", lan
, i
);
118 if (_eval(argv
, NULL
, 0, &pid
) != 0) {
128 void new_arpbind_stop(void)
131 char *s
= "/tmp/new_arpbind_stop.sh";
135 if (nvram_get_int("new_arpbind_enable")) return;
137 if ((f
= fopen(s
, "w")) == NULL
) return;
141 "for HOST in `cat /proc/net/arp |sed -n 's/\\([0-9]*\\.[0-9]*\\.[0-9]*\\.[0-9]*\\).*/\\1/p'`; do arp -d $HOST; done\n"
151 if (_eval(argv
, NULL
, 0, &pid
) != 0) {