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);
114 extern int listen_main(int argc
, char **argv
);
117 extern int ipup_main(int argc
, char **argv
);
118 extern int ipdown_main(int argc
, char **argv
);
119 extern int pppevent_main(int argc
, char **argv
);
121 extern int ip6up_main(int argc
, char **argv
);
122 extern int ip6down_main(int argc
, char **argv
);
126 extern void restore_defaults(void);
129 extern int start_redial(void);
130 extern int stop_redial(void);
131 extern int redial_main(int argc
, char **argv
);
134 extern void start_pptp(int mode
);
135 extern void stop_pptp(void);
136 extern void start_pppoe(int);
137 extern void stop_pppoe(void);
138 extern void start_l2tp(void);
139 extern void stop_l2tp(void);
140 extern void start_wan(int mode
);
141 extern void start_wan_done(char *ifname
);
143 extern void start_wan6_done(const char *wan_ifname
);
145 extern void stop_wan(void);
146 extern void force_to_dial(void);
147 extern void do_wan_routes(char *ifname
, int metric
, int add
);
148 extern void preset_wan(char *ifname
, char *gw
, char *netmask
);
151 extern void set_host_domain_name(void);
152 extern void set_et_qos_mode(int sfd
);
153 extern void start_lan(void);
154 extern void stop_lan(void);
155 extern void hotplug_net(void);
156 extern void do_static_routes(int add
);
157 extern int radio_main(int argc
, char *argv
[]);
158 extern int wldist_main(int argc
, char *argv
[]);
159 extern void start_wl(void);
161 extern void enable_ipv6(int enable
);
162 extern void accept_ra(const char *ifname
);
164 #define enable_ipv6(enable) do {} while (0)
165 #define accept_ra(ifname) do {} while (0)
169 extern int dhcpc_event_main(int argc
, char **argv
);
170 extern int dhcpc_release_main(int argc
, char **argv
);
171 extern int dhcpc_renew_main(int argc
, char **argv
);
172 extern void start_dhcpc(void);
173 extern void stop_dhcpc(void);
175 extern int dhcp6c_state_main(int argc
, char **argv
);
176 extern void start_dhcp6c(void);
177 extern void stop_dhcp6c(void);
181 extern void start_cron(void);
182 extern void stop_cron(void);
183 extern void start_zebra(void);
184 extern void stop_zebra(void);
185 extern void start_upnp(void);
186 extern void stop_upnp(void);
187 extern void start_syslog(void);
188 extern void stop_syslog(void);
189 extern void start_igmp_proxy(void);
190 extern void stop_igmp_proxy(void);
191 extern void start_httpd(void);
192 extern void stop_httpd(void);
193 extern void clear_resolv(void);
194 extern void dns_to_resolv(void);
195 extern void start_dnsmasq(void);
196 extern void stop_dnsmasq(void);
197 extern void set_tz(void);
198 extern void start_ntpc(void);
199 extern void stop_ntpc(void);
200 extern void check_services(void);
201 extern void exec_service(void);
202 extern int service_main(int argc
, char *argv
[]);
203 extern void start_service(const char *name
);
204 extern void stop_service(const char *name
);
205 extern void restart_service(const char *name
);
206 extern void start_services(void);
207 extern void stop_services(void);
208 // !!TB - USB and NAS
210 extern void restart_nas_services(int stop
, int start
);
212 #define restart_nas_services(args...) do { } while(0)
215 extern void start_hotplug2();
216 extern void stop_hotplug2(void);
219 extern void start_ipv6_sit_tunnel(void);
220 extern void stop_ipv6_sit_tunnel(void);
221 extern void start_radvd(void);
222 extern void stop_radvd(void);
223 extern void start_ipv6(void);
224 extern void stop_ipv6(void);
227 // !!TB - USB Support
230 extern void start_usb(void);
231 extern void stop_usb(void);
232 extern void hotplug_usb(void);
233 extern void remove_storage_main(int shutdn
);
235 #define start_usb(args...) do { } while(0)
236 #define stop_usb(args...) do { } while(0)
237 #define hotplug_usb(args...) do { } while(0)
238 #define remove_storage_main(args...) do { } while(0)
242 extern int wds_enable(void);
243 extern void start_nas(void);
244 extern void stop_nas(void);
245 extern void notify_nas(const char *ifname
);
248 extern wanface_list_t wanfaces
;
249 extern char lanface
[];
251 extern char wan6face
[];
253 extern char lan_cclass
[];
254 extern const char *chain_in_accept
;
255 extern const char *chain_out_drop
;
256 extern const char *chain_out_accept
;
257 extern const char *chain_out_reject
;
258 extern char **layer7_in
;
260 extern void enable_ip_forward(void);
261 extern void ipt_write(const char *format
, ...);
262 extern void ip6t_write(const char *format
, ...);
263 #if defined(TCONFIG_IPV6) && defined(LINUX26)
264 #define ip46t_write(args...) do { ipt_write(args); ip6t_write(args); } while(0)
265 //#define ip46t_flagged_write(do_ip4t, do_ip6t, args...) do { if (do_ip4t) ipt_write(args); if (do_ip6t) ip6t_write(args); } while(0)
266 #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)
267 #define ip46t_cond_write(do_ip6t, args...) do { if (do_ip6t) ip6t_write(args); else ipt_write(args); } while(0)
269 #define ip46t_write ipt_write
270 //#define ip46t_flagged_write(do_ip4t, do_ip6t, args...) do { if (do_ip4t) ipt_write(args); } while(0)
271 #define ip46t_flagged_write(do_ip46t, args...) do { if (do_ip46t & IPT_V4) ipt_write(args); } while(0)
272 #define ip46t_cond_write(do_ip6t, args...) ipt_write(args)
274 extern void ipt_log_unresolved(const char *addr
, const char *addrtype
, const char *categ
, const char *name
);
275 extern int ipt_addr(char *addr
, int maxlen
, const char *s
, const char *dir
, int af
, int strict
, const char *categ
, const char *name
);
276 extern int ipt_dscp(const char *v
, char *opt
);
277 extern int ipt_ipp2p(const char *v
, char *opt
);
278 extern int ipt_layer7(const char *v
, char *opt
);
279 extern void ipt_layer7_inbound(void);
280 extern int start_firewall(void);
281 extern int stop_firewall(void);
283 extern void create_test_iptfile(void);
287 extern void ipt_forward(ipt_table_t table
);
288 extern void ipt_triggered(ipt_table_t table
);
290 extern void ip6t_forward(void);
294 extern int rcheck_main(int argc
, char *argv
[]);
295 extern void ipt_restrictions(void);
296 extern void sched_restrictions(void);
299 extern void ipt_qos(void);
300 extern void start_qos(void);
301 extern void stop_qos(void);
305 extern void start_cifs(void);
306 extern void stop_cifs(void);
307 extern int mount_cifs_main(int argc
, char *argv
[]);
309 static inline void start_cifs(void) { };
310 static inline void stop_cifs(void) { };
315 extern void init_jffs2(void);
316 extern void start_jffs2(void);
317 extern void stop_jffs2(void);
319 static inline void init_jffs2(void) { };
320 static inline void start_jffs2(void) { };
321 static inline void stop_jffs2(void) { };
326 extern void start_ddns(void);
327 extern void stop_ddns(void);
328 extern int ddns_update_main(int argc
, char **argv
);
330 static inline void start_ddns(void) { };
331 static inline void stop_ddns(void) { };
335 extern void usage_exit(const char *cmd
, const char *help
) __attribute__ ((noreturn
));
336 #define modprobe(mod, args...) ({ char *argv[] = { "modprobe", "-s", mod, ## args, NULL }; _eval(argv, NULL, 0, NULL); })
337 extern int modprobe_r(const char *mod
);
338 #define xstart(args...) _xstart(args, NULL)
339 extern int _xstart(const char *cmd
, ...);
340 extern void run_nvscript(const char *nv
, const char *arg1
, int wtime
);
341 extern void run_userfile (char *folder
, char *extension
, const char *arg1
, int wtime
);
342 extern void setup_conntrack(void);
343 extern int host_addr_info(const char *name
, int af
, struct sockaddr_storage
*buf
);
344 extern int host_addrtypes(const char *name
, int af
);
345 extern void inc_mac(char *mac
, int plus
);
346 extern void set_mac(const char *ifname
, const char *nvname
, int plus
);
347 extern const char *default_wanif(void);
348 // extern const char *default_wlif(void);
349 #define vstrsep(buf, sep, args...) _vstrsep(buf, sep, args, NULL)
350 extern int _vstrsep(char *buf
, const char *sep
, ...);
351 extern void simple_unlock(const char *name
);
352 extern void simple_lock(const char *name
);
353 extern void killall_tk(const char *name
);
354 extern int mkdir_if_none(const char *path
);
355 extern long fappend(FILE *out
, const char *fname
);
356 extern long fappend_file(const char *path
, const char *fname
);
359 extern void create_passwd(void);
360 extern void start_sshd(void);
361 extern void stop_sshd(void);
362 extern void start_telnetd(void);
363 extern void stop_telnetd(void);
366 extern int mtd_erase(const char *mtdname
);
367 extern int mtd_unlock(const char *mtdname
);
368 extern int mtd_write_main(int argc
, char *argv
[]);
369 extern int mtd_unlock_erase_main(int argc
, char *argv
[]);
372 extern int buttons_main(int argc
, char *argv
[]);
375 extern int led_main(int argc
, char *argv
[]);
378 extern int gpio_main(int argc
, char *argv
[]);
381 extern int sched_main(int argc
, char *argv
[]);
382 extern void start_sched(void);
383 extern void stop_sched(void);
386 extern int nvram_file2nvram(const char *name
, const char *filename
);
387 extern int nvram_nvram2file(const char *name
, const char *filename
);
391 extern void hotplug_usb(void);
392 extern int usbevent_main(int argc
, char *argv
[]);
393 extern void start_usbevent(void);
394 extern void stop_usbevent(void);
395 extern int usbrescan_main(int argc
, char *argv
[]);
396 extern int hotdiskadd_main(int argc
, char *argv
[]);
397 extern int hotdiskremove_main(int argc
, char *argv
[]);
398 extern int hotdiskerror_main(int argc
, char *argv
[]);
399 extern int umountx_main(int argc
, char *argv
[]);
401 void start_test_1(void);
402 void stop_test_1(void);
405 extern void start_smbd(void);
406 extern void stop_smbd(void);
411 extern void start_bittorrent();
412 extern void stop_bittorrent();
416 #ifdef TCONFIG_OPENVPN
417 extern void start_vpnclient(int clientNum
);
418 extern void stop_vpnclient(int clientNum
);
419 extern void start_vpnserver(int serverNum
);
420 extern void stop_vpnserver(int serverNum
);
421 extern void start_vpn_eas();
422 extern void run_vpn_firewall_scripts();
423 extern void write_vpn_dnsmasq_config(FILE*);
424 extern int write_vpn_resolv(FILE*);
427 static inline void start_vpnclient(int clientNum) {}
428 static inline void stop_vpnclient(int clientNum) {}
429 static inline void start_vpnserver(int serverNum) {}
430 static inline void stop_vpnserver(int serverNum) {}
431 static inline void run_vpn_firewall_scripts() {}
432 static inline void write_vpn_dnsmasq_config(FILE*) {}
434 static inline void start_vpn_eas() { }
435 #define write_vpn_resolv(f) (0)
439 extern void ipt_qoslimit(int chain
);
440 extern void new_qoslimit_start(void);
441 extern void new_qoslimit_stop(void);
444 extern void new_arpbind_start(void);
445 extern void new_arpbind_stop(void);