2 * Router rc control script
4 * Copyright 2005, Broadcom Corporation
7 * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
8 * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
9 * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
10 * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
12 * $Id: rc.h,v 1.39 2005/03/29 02:00:06 honor Exp $
23 #include <ctype.h> // !!TB
27 #include <netinet/in.h>
36 #include <tomato_profile.h>
37 #include <tomato_config.h>
39 // #define DEBUG_IPTFILE
40 // #define DEBUG_RCTEST
41 // #define DEBUG_NOISY
44 #define TRACE_PT(args...) do { _dprintf("[%d:%s +%ld] ", getpid(), __FUNCTION__, get_uptime()); _dprintf(args); } while(0)
46 #define TRACE_PT(args...) do { } while(0)
49 #define MOUNT_ROOT "/tmp/mnt"
50 #define PROC_SCSI_ROOT "/proc/scsi"
51 #define USB_STORAGE "usb-storage"
61 #define RELEASE_IP 0x02
62 #define GET_IP_ERROR 0x03
63 #define RELEASE_WAN_CONTROL 0x04
64 #define USB_DATA_ACCESS 0x05 //For WRTSL54GS
65 #define USB_CONNECT 0x06 //For WRTSL54GS
66 #define USB_DISCONNECT 0x07 //For WRTSL54GS
70 #define SET_LED(val) \
73 if(check_hw_type() == BCM4704_BCM5325F_CHIP) { \
74 if ((filep = open("/dev/ctmisc", O_RDWR,0))) \
76 ioctl(filep, val, 0); \
83 #define SET_LED(val) do { } while(0)
85 typedef enum { IPT_TABLE_NAT
, IPT_TABLE_FILTER
, IPT_TABLE_MANGLE
} ipt_table_t
;
87 #define IFUP (IFF_UP | IFF_RUNNING | IFF_BROADCAST | IFF_MULTICAST)
89 #define sin_addr(s) (((struct sockaddr_in *)(s))->sin_addr)
90 #define sin6_addr(s) (((struct sockaddr_in6 *)(s))->sin6_addr)
94 #define IPT_ANY_AF (IPT_V4 | IPT_V6)
95 #define IPT_AF_IS_EMPTY(f) ((f & IPT_ANY_AF) == 0)
98 extern int init_main(int argc
, char *argv
[]);
99 extern int reboothalt_main(int argc
, char *argv
[]);
100 extern int console_main(int argc
, char *argv
[]);
101 extern void restore_defaults_module(char *prefix
);
104 extern int _ifconfig(const char *name
, int flags
, const char *addr
, const char *netmask
, const char *dstaddr
);
105 #define ifconfig(name, flags, addr, netmask) _ifconfig(name, flags, addr, netmask, NULL)
106 extern int route_add(char *name
, int metric
, char *dst
, char *gateway
, char *genmask
);
107 extern void route_del(char *name
, int metric
, char *dst
, char *gateway
, char *genmask
);
108 extern void config_loopback(void);
109 extern int start_vlan(void);
110 extern int stop_vlan(void);
111 extern int config_vlan(void);
112 extern void config_loopback(void);
114 extern int ipv6_mapaddr4(struct in6_addr
*addr6
, int ip6len
, struct in_addr
*addr4
, int ip4mask
);
118 extern int listen_main(int argc
, char **argv
);
121 extern int ipup_main(int argc
, char **argv
);
122 extern int ipdown_main(int argc
, char **argv
);
123 extern int pppevent_main(int argc
, char **argv
);
125 extern int ip6up_main(int argc
, char **argv
);
126 extern int ip6down_main(int argc
, char **argv
);
130 //extern void restore_defaults(void);
133 extern int start_redial(void);
134 extern int stop_redial(void);
135 extern int redial_main(int argc
, char **argv
);
138 extern void start_pptp(int mode
);
139 extern void stop_pptp(void);
140 extern void start_pppoe(int);
141 extern void stop_pppoe(void);
142 extern void start_l2tp(void);
143 extern void stop_l2tp(void);
144 extern void start_wan(int mode
);
145 extern void start_wan_done(char *ifname
);
146 extern char *wan_gateway(void);
148 extern void start_wan6_done(const char *wan_ifname
);
150 extern void stop_wan(void);
151 extern void force_to_dial(void);
152 extern void do_wan_routes(char *ifname
, int metric
, int add
);
153 extern void preset_wan(char *ifname
, char *gw
, char *netmask
);
156 extern void set_host_domain_name(void);
157 extern void set_et_qos_mode(int sfd
);
158 extern void start_lan(void);
159 extern void stop_lan(void);
160 extern void hotplug_net(void);
161 extern void do_static_routes(int add
);
162 extern int radio_main(int argc
, char *argv
[]);
163 extern int wldist_main(int argc
, char *argv
[]);
164 extern void stop_wireless(void);
165 extern void start_wireless(void);
166 extern void start_wl(void);
167 extern void unload_wl(void);
168 extern void load_wl(void);
170 extern void enable_ipv6(int enable
);
171 extern void accept_ra(const char *ifname
);
173 #define enable_ipv6(enable) do {} while (0)
174 #define accept_ra(ifname) do {} while (0)
178 extern int dhcpc_event_main(int argc
, char **argv
);
179 extern int dhcpc_release_main(int argc
, char **argv
);
180 extern int dhcpc_renew_main(int argc
, char **argv
);
181 extern void start_dhcpc(void);
182 extern void stop_dhcpc(void);
184 extern int dhcp6c_state_main(int argc
, char **argv
);
185 extern void start_dhcp6c(void);
186 extern void stop_dhcp6c(void);
190 extern void start_cron(void);
191 extern void stop_cron(void);
192 extern void start_zebra(void);
193 extern void stop_zebra(void);
194 extern void start_upnp(void);
195 extern void stop_upnp(void);
196 extern void start_syslog(void);
197 extern void stop_syslog(void);
198 extern void start_igmp_proxy(void);
199 extern void stop_igmp_proxy(void);
200 extern void start_udpxy(void);
201 extern void stop_udpxy(void);
202 extern void start_httpd(void);
203 extern void stop_httpd(void);
204 extern void clear_resolv(void);
205 extern void dns_to_resolv(void);
206 extern void start_dnsmasq(void);
207 extern void stop_dnsmasq(void);
208 extern void set_tz(void);
209 extern void start_ntpc(void);
210 extern void stop_ntpc(void);
211 extern void check_services(void);
212 extern void exec_service(void);
213 extern int service_main(int argc
, char *argv
[]);
214 extern void start_service(const char *name
);
215 extern void stop_service(const char *name
);
216 extern void restart_service(const char *name
);
217 extern void start_services(void);
218 extern void stop_services(void);
219 // !!TB - USB and NAS
221 extern void restart_nas_services(int stop
, int start
);
223 #define restart_nas_services(args...) do { } while(0)
226 extern void start_hotplug2();
227 extern void stop_hotplug2(void);
230 extern void start_ipv6_tunnel(void);
231 extern void stop_ipv6_tunnel(void);
232 extern void start_6rd_tunnel(void);
233 extern void stop_6rd_tunnel(void);
234 extern void start_radvd(void);
235 extern void stop_radvd(void);
236 extern void start_ipv6(void);
237 extern void stop_ipv6(void);
240 // !!TB - USB Support
243 extern void start_usb(void);
244 extern void stop_usb(void);
245 extern int dir_is_mountpoint(const char *root
, const char *dir
);
246 extern void hotplug_usb(void);
247 extern void remove_storage_main(int shutdn
);
249 #define start_usb(args...) do { } while(0)
250 #define stop_usb(args...) do { } while(0)
251 #define dir_is_mountpoint(args...) (0)
252 #define hotplug_usb(args...) do { } while(0)
253 #define remove_storage_main(args...) do { } while(0)
257 extern int wds_enable(void);
258 extern int wl_security_on(void);
259 extern void start_nas(void);
260 extern void stop_nas(void);
261 extern void notify_nas(const char *ifname
);
264 extern wanface_list_t wanfaces
;
265 extern char lanface
[];
267 extern char wan6face
[];
269 extern char lan_cclass
[];
270 extern const char *chain_in_accept
;
271 extern const char *chain_out_drop
;
272 extern const char *chain_out_accept
;
273 extern const char *chain_out_reject
;
274 extern char **layer7_in
;
276 extern void enable_ip_forward(void);
277 extern void enable_ip6_forward(void);
278 extern void ipt_write(const char *format
, ...);
279 extern void ip6t_write(const char *format
, ...);
280 #if defined(TCONFIG_IPV6) && defined(LINUX26)
281 #define ip46t_write(args...) do { ipt_write(args); ip6t_write(args); } while(0)
282 //#define ip46t_flagged_write(do_ip4t, do_ip6t, args...) do { if (do_ip4t) ipt_write(args); if (do_ip6t) ip6t_write(args); } while(0)
283 #define ip46t_flagged_write(do_ip46t, args...) do { if (do_ip46t & IPT_V4) ipt_write(args); if (do_ip46t & IPT_V6) ip6t_write(args); } while(0)
284 #define ip46t_cond_write(do_ip6t, args...) do { if (do_ip6t) ip6t_write(args); else ipt_write(args); } while(0)
285 #define ipt_flagged_write(do_ip46t, args...) do { if (do_ip46t & IPT_V4) ipt_write(args); if (do_ip46t & IPT_V6) ip6t_write(args); } while(0)
286 #define ipt_cond_write(do_ip6t, args...) do { if (do_ip6t) ip6t_write(args); else ipt_write(args); } while(0)
288 #define ip46t_write ipt_write
289 //#define ip46t_flagged_write(do_ip4t, do_ip6t, args...) do { if (do_ip4t) ipt_write(args); } while(0)
290 #define ip46t_flagged_write(do_ip46t, args...) do { if (do_ip46t & IPT_V4) ipt_write(args); } while(0)
291 #define ip46t_cond_write(do_ip6t, args...) ipt_write(args)
293 extern void ipt_log_unresolved(const char *addr
, const char *addrtype
, const char *categ
, const char *name
);
294 extern int ipt_addr(char *addr
, int maxlen
, const char *s
, const char *dir
, int af
, int strict
, const char *categ
, const char *name
);
295 extern int ipt_dscp(const char *v
, char *opt
);
296 extern int ipt_ipp2p(const char *v
, char *opt
);
297 extern int ipt_layer7(const char *v
, char *opt
);
298 extern void ipt_layer7_inbound(void);
299 extern int start_firewall(void);
300 extern int stop_firewall(void);
302 extern void create_test_iptfile(void);
305 extern void allow_fastnat(const char *service
, int allow
);
306 extern void try_enabling_fastnat(void);
310 extern void ipt_forward(ipt_table_t table
);
311 extern void ipt_triggered(ipt_table_t table
);
314 extern void ip6t_forward(void);
318 extern int rcheck_main(int argc
, char *argv
[]);
319 extern void ipt_restrictions(void);
320 extern void sched_restrictions(void);
323 extern void ipt_qos(void);
324 extern void start_qos(void);
325 extern void stop_qos(void);
329 extern void start_cifs(void);
330 extern void stop_cifs(void);
331 extern int mount_cifs_main(int argc
, char *argv
[]);
333 static inline void start_cifs(void) { };
334 static inline void stop_cifs(void) { };
339 extern void init_jffs2(void);
340 extern void start_jffs2(void);
341 extern void stop_jffs2(void);
343 static inline void init_jffs2(void) { };
344 static inline void start_jffs2(void) { };
345 static inline void stop_jffs2(void) { };
350 extern void start_ddns(void);
351 extern void stop_ddns(void);
352 extern int ddns_update_main(int argc
, char **argv
);
354 static inline void start_ddns(void) { };
355 static inline void stop_ddns(void) { };
359 extern void usage_exit(const char *cmd
, const char *help
) __attribute__ ((noreturn
));
360 #define modprobe(mod, args...) ({ char *argv[] = { "modprobe", "-s", mod, ## args, NULL }; _eval(argv, NULL, 0, NULL); })
361 extern int modprobe_r(const char *mod
);
362 #define xstart(args...) _xstart(args, NULL)
363 extern int _xstart(const char *cmd
, ...);
364 extern void run_nvscript(const char *nv
, const char *arg1
, int wtime
);
365 extern void run_userfile (char *folder
, char *extension
, const char *arg1
, int wtime
);
366 extern void setup_conntrack(void);
367 extern int host_addr_info(const char *name
, int af
, struct sockaddr_storage
*buf
);
368 extern int host_addrtypes(const char *name
, int af
);
369 extern void inc_mac(char *mac
, int plus
);
370 extern void set_mac(const char *ifname
, const char *nvname
, int plus
);
371 extern const char *default_wanif(void);
372 // extern const char *default_wlif(void);
373 #define vstrsep(buf, sep, args...) _vstrsep(buf, sep, args, NULL)
374 extern int _vstrsep(char *buf
, const char *sep
, ...);
375 extern void simple_unlock(const char *name
);
376 extern void simple_lock(const char *name
);
377 extern void killall_tk(const char *name
);
378 extern int mkdir_if_none(const char *path
);
379 extern long fappend(FILE *out
, const char *fname
);
380 extern long fappend_file(const char *path
, const char *fname
);
383 extern void create_passwd(void);
384 extern void start_sshd(void);
385 extern void stop_sshd(void);
386 extern void start_telnetd(void);
387 extern void stop_telnetd(void);
390 extern int mtd_erase(const char *mtdname
);
391 extern int mtd_unlock(const char *mtdname
);
392 #ifdef TCONFIG_BCMARM
393 extern int mtd_erase_old(const char *mtdname
);
394 extern int mtd_write_main_old(int argc
, char *argv
[]);
395 extern int mtd_unlock_erase_main_old(int argc
, char *argv
[]);
396 extern int mtd_write(const char *path
, const char *mtd
);
398 extern int mtd_write_main(int argc
, char *argv
[]);
399 extern int mtd_unlock_erase_main(int argc
, char *argv
[]);
403 extern int buttons_main(int argc
, char *argv
[]);
406 extern int blink_main(int argc
, char *argv
[]);
410 extern int blink_5g_main(int argc
, char *argv
[]);
414 extern int led_main(int argc
, char *argv
[]);
417 extern int gpio_main(int argc
, char *argv
[]);
420 extern int sched_main(int argc
, char *argv
[]);
421 extern void start_sched(void);
422 extern void stop_sched(void);
426 extern void start_pptp_client(void);
427 extern void stop_pptp_client(void);
428 extern int write_pptpvpn_resolv(FILE*);
429 extern void clear_pptp_route(void);
431 #define write_pptpvpn_resolv(f) (0)
435 extern int nvram_file2nvram(const char *name
, const char *filename
);
436 extern int nvram_nvram2file(const char *name
, const char *filename
);
440 extern void hotplug_usb(void);
441 extern int usbevent_main(int argc
, char *argv
[]);
442 extern void start_usbevent(void);
443 extern void stop_usbevent(void);
444 extern int usbrescan_main(int argc
, char *argv
[]);
445 extern int hotdiskadd_main(int argc
, char *argv
[]);
446 extern int hotdiskremove_main(int argc
, char *argv
[]);
447 extern int hotdiskerror_main(int argc
, char *argv
[]);
448 extern int umountx_main(int argc
, char *argv
[]);
450 void start_test_1(void);
451 void stop_test_1(void);
454 extern void start_smbd(void);
455 extern void stop_smbd(void);
460 extern void start_bittorrent();
461 extern void stop_bittorrent();
466 extern void start_nfs();
467 extern void stop_nfs();
472 extern void start_snmp();
473 extern void stop_snmp();
478 extern void start_tor();
479 extern void stop_tor();
484 extern void start_ups();
485 extern void stop_ups();
490 extern void start_pptpd(void);
491 extern void stop_pptpd(void);
492 extern void write_pptpd_dnsmasq_config(FILE* f
);
496 #ifdef TCONFIG_OPENVPN
497 extern void start_vpnclient(int clientNum
);
498 extern void stop_vpnclient(int clientNum
);
499 extern void start_vpnserver(int serverNum
);
500 extern void stop_vpnserver(int serverNum
);
501 extern void start_vpn_eas();
502 extern void stop_vpn_eas();
503 extern void run_vpn_firewall_scripts();
504 extern void write_vpn_dnsmasq_config(FILE*);
505 extern int write_vpn_resolv(FILE*);
508 static inline void start_vpnclient(int clientNum) {}
509 static inline void stop_vpnclient(int clientNum) {}
510 static inline void start_vpnserver(int serverNum) {}
511 static inline void stop_vpnserver(int serverNum) {}
512 static inline void run_vpn_firewall_scripts() {}
513 static inline void write_vpn_dnsmasq_config(FILE*) {}
515 static inline void start_vpn_eas() { }
516 static inline void stop_vpn_eas() { }
517 #define write_vpn_resolv(f) (0)
522 extern void start_tinc();
523 extern void start_tinc_wanup();
524 extern void stop_tinc();
525 extern void run_tinc_firewall_script();
529 extern void ipt_qoslimit(int chain
);
530 extern void new_qoslimit_start(void);
531 extern void new_qoslimit_stop(void);
534 extern void start_arpbind(void);
535 extern void stop_arpbind(void);
539 extern void start_mmc(void);
540 extern void stop_mmc(void);
545 extern void start_nocat();
546 extern void stop_nocat();
547 extern void reset_nocat();
552 extern void nginx_write(const char *format
, ...);
553 extern void start_nginx();
554 extern void stop_nginx();
555 extern void start_nginxfp();
556 extern void stop_nginxfp();
560 extern void start_tomatoanon();
561 extern void stop_tomatoanon();