4 Copyright (C) 2006-2008 Jonathan Zarate
5 rate limit & connection limit by conanxu
12 //#include <sys/stat.h>
14 // read nvram into files
15 void new_arpbind_start(void)
19 char *ipaddr
;//ip address
20 char *macaddr
;//mac address
21 char *s
= "/tmp/new_arpbind_start.sh";
26 const char *router_ip
;
33 if (!nvram_get_int("new_arpbind_enable")) return;
35 //read static dhcp list from nvram
36 p
= nvram_safe_get("dhcpd_static");
38 //read arpbind_list into file
39 if ((f
= fopen(s
, "w")) == NULL
) return;
42 "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"
44 memset(host
, 0, sizeof(host
));
46 //get network ip prefix
47 router_ip
= nvram_safe_get("lan_ipaddr");
48 strlcpy(lan
, router_ip
, sizeof(lan
));
49 if ((p
= strrchr(lan
, '.')) != NULL
) {
54 // 00:aa:bb:cc:dd:ee<123<xxxxxxxxxxxxxxxxxxxxxxxxxx.xyz> = 53 w/ delim
55 // 00:aa:bb:cc:dd:ee<123.123.123.123<xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xyz> = 85 w/ delim
56 // 00:aa:bb:cc:dd:ee,00:aa:bb:cc:dd:ee<123.123.123.123<xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.xyz> = 106 w/ delim
57 p
= nvram_safe_get("dhcpd_static");
58 while ((e
= strchr(p
, '>')) != NULL
) {
65 strncpy(buf_arp
, p
, length
);
69 /* get the MAC address */
70 if ((e
= strchr(buf_arp
, '<')) == NULL
) continue;
74 if ((e
= strchr(macaddr
, ',')) != NULL
){
77 //cprintf ("mac address %s\n", macaddr);
79 /* get the IP adddres */
80 if ((e
= strchr(ipaddr
, '<')) == NULL
) continue;
82 if (strchr(ipaddr
, '.') == NULL
) {
84 if ((ipn
<= 0) || (ipn
> 255)) continue;
85 sprintf(ipbuf
, "%s%d", lan
, ipn
);
89 if (inet_addr(ipaddr
) == INADDR_NONE
) continue;
91 //cprintf ("ip address %s\n", ipaddr);
94 if ((*macaddr
!= 0) && (strcmp(macaddr
, "00:00:00:00:00:00") != 0)) {
95 fprintf(f
, "arp -s %s %s\n", ipaddr
, macaddr
);
96 //cprintf ("arp -s %s %s\n", ipaddr, macaddr);
97 if ((q
= strrchr(ipaddr
, '.')) != NULL
) {
99 if (!strcmp(ipaddr
, lan
)) host
[atoi(q
+1)] = 1;
104 if (nvram_get_int("new_arpbind_only")) {
105 for (i
= 1; i
< 255; i
++) {
107 fprintf(f
, "arp -s %s.%d 00:00:00:00:00:00\n", lan
, i
);
119 if (_eval(argv
, NULL
, 0, &pid
) != 0) {
129 void new_arpbind_stop(void)
132 char *s
= "/tmp/new_arpbind_stop.sh";
136 if (nvram_get_int("new_arpbind_enable")) return;
138 if ((f
= fopen(s
, "w")) == NULL
) return;
142 "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"
152 if (_eval(argv
, NULL
, 0, &pid
) != 0) {