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
[]);
103 extern int _ifconfig(const char *name
, int flags
, const char *addr
, const char *netmask
, const char *dstaddr
);
104 #define ifconfig(name, flags, addr, netmask) _ifconfig(name, flags, addr, netmask, NULL)
105 extern int route_add(char *name
, int metric
, char *dst
, char *gateway
, char *genmask
);
106 extern void route_del(char *name
, int metric
, char *dst
, char *gateway
, char *genmask
);
107 extern void config_loopback(void);
108 extern int start_vlan(void);
109 extern int stop_vlan(void);
110 extern int config_vlan(void);
111 extern void config_loopback(void);
113 extern int ipv6_mapaddr4(struct in6_addr
*addr6
, int ip6len
, struct in_addr
*addr4
, int ip4mask
);
117 extern int listen_main(int argc
, char **argv
);
120 extern int ipup_main(int argc
, char **argv
);
121 extern int ipdown_main(int argc
, char **argv
);
122 extern int pppevent_main(int argc
, char **argv
);
124 extern int ip6up_main(int argc
, char **argv
);
125 extern int ip6down_main(int argc
, char **argv
);
129 extern void restore_defaults(void);
132 extern int start_redial(void);
133 extern int stop_redial(void);
134 extern int redial_main(int argc
, char **argv
);
137 extern void start_pptp(int mode
);
138 extern void stop_pptp(void);
139 extern void start_pppoe(int);
140 extern void stop_pppoe(void);
141 extern void start_l2tp(void);
142 extern void stop_l2tp(void);
143 extern void start_wan(int mode
);
144 extern void start_wan_done(char *ifname
);
145 extern char *wan_gateway(void);
147 extern void start_wan6_done(const char *wan_ifname
);
149 extern void stop_wan(void);
150 extern void force_to_dial(void);
151 extern void do_wan_routes(char *ifname
, int metric
, int add
);
152 extern void preset_wan(char *ifname
, char *gw
, char *netmask
);
155 extern void set_host_domain_name(void);
156 extern void set_et_qos_mode(int sfd
);
157 extern void start_lan(void);
158 extern void stop_lan(void);
159 extern void hotplug_net(void);
160 extern void do_static_routes(int add
);
161 extern int radio_main(int argc
, char *argv
[]);
162 extern int wldist_main(int argc
, char *argv
[]);
163 extern void stop_wireless(void);
164 extern void start_wireless(void);
165 extern void start_wl(void);
166 extern void unload_wl(void);
167 extern void load_wl(void);
169 extern void enable_ipv6(int enable
);
170 extern void accept_ra(const char *ifname
);
172 #define enable_ipv6(enable) do {} while (0)
173 #define accept_ra(ifname) do {} while (0)
177 extern int dhcpc_event_main(int argc
, char **argv
);
178 extern int dhcpc_release_main(int argc
, char **argv
);
179 extern int dhcpc_renew_main(int argc
, char **argv
);
180 extern void start_dhcpc(void);
181 extern void stop_dhcpc(void);
183 extern int dhcp6c_state_main(int argc
, char **argv
);
184 extern void start_dhcp6c(void);
185 extern void stop_dhcp6c(void);
189 extern void start_cron(void);
190 extern void stop_cron(void);
191 extern void start_zebra(void);
192 extern void stop_zebra(void);
193 extern void start_upnp(void);
194 extern void stop_upnp(void);
195 extern void start_syslog(void);
196 extern void stop_syslog(void);
197 extern void start_igmp_proxy(void);
198 extern void stop_igmp_proxy(void);
199 extern void start_udpxy(void);
200 extern void stop_udpxy(void);
201 extern void start_httpd(void);
202 extern void stop_httpd(void);
203 extern void clear_resolv(void);
204 extern void dns_to_resolv(void);
205 extern void start_dnsmasq(void);
206 extern void stop_dnsmasq(void);
207 extern void set_tz(void);
208 extern void start_ntpc(void);
209 extern void stop_ntpc(void);
210 extern void check_services(void);
211 extern void exec_service(void);
212 extern int service_main(int argc
, char *argv
[]);
213 extern void start_service(const char *name
);
214 extern void stop_service(const char *name
);
215 extern void restart_service(const char *name
);
216 extern void start_services(void);
217 extern void stop_services(void);
218 // !!TB - USB and NAS
220 extern void restart_nas_services(int stop
, int start
);
222 #define restart_nas_services(args...) do { } while(0)
225 extern void start_hotplug2();
226 extern void stop_hotplug2(void);
229 extern void start_ipv6_tunnel(void);
230 extern void stop_ipv6_tunnel(void);
231 extern void start_6rd_tunnel(void);
232 extern void stop_6rd_tunnel(void);
233 extern void start_radvd(void);
234 extern void stop_radvd(void);
235 extern void start_ipv6(void);
236 extern void stop_ipv6(void);
239 // !!TB - USB Support
242 extern void start_usb(void);
243 extern void stop_usb(void);
244 extern int dir_is_mountpoint(const char *root
, const char *dir
);
245 extern void hotplug_usb(void);
246 extern void remove_storage_main(int shutdn
);
248 #define start_usb(args...) do { } while(0)
249 #define stop_usb(args...) do { } while(0)
250 #define dir_is_mountpoint(args...) (0)
251 #define hotplug_usb(args...) do { } while(0)
252 #define remove_storage_main(args...) do { } while(0)
256 extern int wds_enable(void);
257 extern int wl_security_on(void);
258 extern void start_nas(void);
259 extern void stop_nas(void);
260 extern void notify_nas(const char *ifname
);
263 extern wanface_list_t wanfaces
;
264 extern char lanface
[];
266 extern char wan6face
[];
268 extern char lan_cclass
[];
269 extern const char *chain_in_accept
;
270 extern const char *chain_out_drop
;
271 extern const char *chain_out_accept
;
272 extern const char *chain_out_reject
;
273 extern char **layer7_in
;
275 extern void enable_ip_forward(void);
276 extern void enable_ip6_forward(void);
277 extern void ipt_write(const char *format
, ...);
278 extern void ip6t_write(const char *format
, ...);
279 #if defined(TCONFIG_IPV6) && defined(LINUX26)
280 #define ip46t_write(args...) do { ipt_write(args); ip6t_write(args); } while(0)
281 //#define ip46t_flagged_write(do_ip4t, do_ip6t, args...) do { if (do_ip4t) ipt_write(args); if (do_ip6t) ip6t_write(args); } while(0)
282 #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)
283 #define ip46t_cond_write(do_ip6t, args...) do { if (do_ip6t) ip6t_write(args); else ipt_write(args); } while(0)
285 #define ip46t_write ipt_write
286 //#define ip46t_flagged_write(do_ip4t, do_ip6t, args...) do { if (do_ip4t) ipt_write(args); } while(0)
287 #define ip46t_flagged_write(do_ip46t, args...) do { if (do_ip46t & IPT_V4) ipt_write(args); } while(0)
288 #define ip46t_cond_write(do_ip6t, args...) ipt_write(args)
290 extern void ipt_log_unresolved(const char *addr
, const char *addrtype
, const char *categ
, const char *name
);
291 extern int ipt_addr(char *addr
, int maxlen
, const char *s
, const char *dir
, int af
, int strict
, const char *categ
, const char *name
);
292 extern int ipt_dscp(const char *v
, char *opt
);
293 extern int ipt_ipp2p(const char *v
, char *opt
);
294 extern int ipt_layer7(const char *v
, char *opt
);
295 extern void ipt_layer7_inbound(void);
296 extern int start_firewall(void);
297 extern int stop_firewall(void);
299 extern void create_test_iptfile(void);
302 extern void allow_fastnat(const char *service
, int allow
);
303 extern void try_enabling_fastnat(void);
307 extern void ipt_forward(ipt_table_t table
);
308 extern void ipt_triggered(ipt_table_t table
);
311 extern void ip6t_forward(void);
315 extern int rcheck_main(int argc
, char *argv
[]);
316 extern void ipt_restrictions(void);
317 extern void sched_restrictions(void);
320 extern void ipt_qos(void);
321 extern void start_qos(void);
322 extern void stop_qos(void);
326 extern void start_cifs(void);
327 extern void stop_cifs(void);
328 extern int mount_cifs_main(int argc
, char *argv
[]);
330 static inline void start_cifs(void) { };
331 static inline void stop_cifs(void) { };
336 extern void init_jffs2(void);
337 extern void start_jffs2(void);
338 extern void stop_jffs2(void);
340 static inline void init_jffs2(void) { };
341 static inline void start_jffs2(void) { };
342 static inline void stop_jffs2(void) { };
347 extern void start_ddns(void);
348 extern void stop_ddns(void);
349 extern int ddns_update_main(int argc
, char **argv
);
351 static inline void start_ddns(void) { };
352 static inline void stop_ddns(void) { };
356 extern void usage_exit(const char *cmd
, const char *help
) __attribute__ ((noreturn
));
357 #define modprobe(mod, args...) ({ char *argv[] = { "modprobe", "-s", mod, ## args, NULL }; _eval(argv, NULL, 0, NULL); })
358 extern int modprobe_r(const char *mod
);
359 #define xstart(args...) _xstart(args, NULL)
360 extern int _xstart(const char *cmd
, ...);
361 extern void run_nvscript(const char *nv
, const char *arg1
, int wtime
);
362 extern void run_userfile (char *folder
, char *extension
, const char *arg1
, int wtime
);
363 extern void setup_conntrack(void);
364 extern int host_addr_info(const char *name
, int af
, struct sockaddr_storage
*buf
);
365 extern int host_addrtypes(const char *name
, int af
);
366 extern void inc_mac(char *mac
, int plus
);
367 extern void set_mac(const char *ifname
, const char *nvname
, int plus
);
368 extern const char *default_wanif(void);
369 // extern const char *default_wlif(void);
370 #define vstrsep(buf, sep, args...) _vstrsep(buf, sep, args, NULL)
371 extern int _vstrsep(char *buf
, const char *sep
, ...);
372 extern void simple_unlock(const char *name
);
373 extern void simple_lock(const char *name
);
374 extern void killall_tk(const char *name
);
375 extern int mkdir_if_none(const char *path
);
376 extern long fappend(FILE *out
, const char *fname
);
377 extern long fappend_file(const char *path
, const char *fname
);
380 extern void create_passwd(void);
381 extern void start_sshd(void);
382 extern void stop_sshd(void);
383 extern void start_telnetd(void);
384 extern void stop_telnetd(void);
387 extern int mtd_erase(const char *mtdname
);
388 extern int mtd_unlock(const char *mtdname
);
389 extern int mtd_write_main(int argc
, char *argv
[]);
390 extern int mtd_unlock_erase_main(int argc
, char *argv
[]);
393 extern int buttons_main(int argc
, char *argv
[]);
396 extern int blink_main(int argc
, char *argv
[]);
400 extern int blink_5g_main(int argc
, char *argv
[]);
404 extern int led_main(int argc
, char *argv
[]);
407 extern int gpio_main(int argc
, char *argv
[]);
410 extern int sched_main(int argc
, char *argv
[]);
411 extern void start_sched(void);
412 extern void stop_sched(void);
416 extern void start_pptp_client(void);
417 extern void stop_pptp_client(void);
418 extern int write_pptpvpn_resolv(FILE*);
419 extern void clear_pptp_route(void);
421 #define write_pptpvpn_resolv(f) (0)
425 extern int nvram_file2nvram(const char *name
, const char *filename
);
426 extern int nvram_nvram2file(const char *name
, const char *filename
);
430 extern void hotplug_usb(void);
431 extern int usbevent_main(int argc
, char *argv
[]);
432 extern void start_usbevent(void);
433 extern void stop_usbevent(void);
434 extern int usbrescan_main(int argc
, char *argv
[]);
435 extern int hotdiskadd_main(int argc
, char *argv
[]);
436 extern int hotdiskremove_main(int argc
, char *argv
[]);
437 extern int hotdiskerror_main(int argc
, char *argv
[]);
438 extern int umountx_main(int argc
, char *argv
[]);
440 void start_test_1(void);
441 void stop_test_1(void);
444 extern void start_smbd(void);
445 extern void stop_smbd(void);
450 extern void start_bittorrent();
451 extern void stop_bittorrent();
456 extern void start_nfs();
457 extern void stop_nfs();
462 extern void start_snmp();
463 extern void stop_snmp();
468 extern void start_tor();
469 extern void stop_tor();
474 extern void start_ups();
475 extern void stop_ups();
480 extern void start_pptpd(void);
481 extern void stop_pptpd(void);
482 extern void write_pptpd_dnsmasq_config(FILE* f
);
486 #ifdef TCONFIG_OPENVPN
487 extern void start_vpnclient(int clientNum
);
488 extern void stop_vpnclient(int clientNum
);
489 extern void start_vpnserver(int serverNum
);
490 extern void stop_vpnserver(int serverNum
);
491 extern void start_vpn_eas();
492 extern void stop_vpn_eas();
493 extern void run_vpn_firewall_scripts();
494 extern void write_vpn_dnsmasq_config(FILE*);
495 extern int write_vpn_resolv(FILE*);
498 static inline void start_vpnclient(int clientNum) {}
499 static inline void stop_vpnclient(int clientNum) {}
500 static inline void start_vpnserver(int serverNum) {}
501 static inline void stop_vpnserver(int serverNum) {}
502 static inline void run_vpn_firewall_scripts() {}
503 static inline void write_vpn_dnsmasq_config(FILE*) {}
505 static inline void start_vpn_eas() { }
506 static inline void stop_vpn_eas() { }
507 #define write_vpn_resolv(f) (0)
511 extern void ipt_qoslimit(int chain
);
512 extern void new_qoslimit_start(void);
513 extern void new_qoslimit_stop(void);
516 extern void start_arpbind(void);
517 extern void stop_arpbind(void);
521 extern void start_mmc(void);
522 extern void stop_mmc(void);
527 extern void start_nocat();
528 extern void stop_nocat();
529 extern void reset_nocat();
533 extern void start_tomatoanon();
534 extern void stop_tomatoanon();