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
);
146 extern void start_wan6_done(const char *wan_ifname
);
148 extern void stop_wan(void);
149 extern void force_to_dial(void);
150 extern void do_wan_routes(char *ifname
, int metric
, int add
);
151 extern void preset_wan(char *ifname
, char *gw
, char *netmask
);
154 extern void set_host_domain_name(void);
155 extern void set_et_qos_mode(int sfd
);
156 extern void start_lan(void);
157 extern void stop_lan(void);
158 extern void hotplug_net(void);
159 extern void do_static_routes(int add
);
160 extern int radio_main(int argc
, char *argv
[]);
161 extern int wldist_main(int argc
, char *argv
[]);
162 extern void start_wl(void);
164 extern void enable_ipv6(int enable
);
165 extern void accept_ra(const char *ifname
);
167 #define enable_ipv6(enable) do {} while (0)
168 #define accept_ra(ifname) do {} while (0)
172 extern int dhcpc_event_main(int argc
, char **argv
);
173 extern int dhcpc_release_main(int argc
, char **argv
);
174 extern int dhcpc_renew_main(int argc
, char **argv
);
175 extern void start_dhcpc(void);
176 extern void stop_dhcpc(void);
178 extern int dhcp6c_state_main(int argc
, char **argv
);
179 extern void start_dhcp6c(void);
180 extern void stop_dhcp6c(void);
184 extern void start_cron(void);
185 extern void stop_cron(void);
186 extern void start_zebra(void);
187 extern void stop_zebra(void);
188 extern void start_upnp(void);
189 extern void stop_upnp(void);
190 extern void start_syslog(void);
191 extern void stop_syslog(void);
192 extern void start_igmp_proxy(void);
193 extern void stop_igmp_proxy(void);
194 extern void start_httpd(void);
195 extern void stop_httpd(void);
196 extern void clear_resolv(void);
197 extern void dns_to_resolv(void);
198 extern void start_dnsmasq(void);
199 extern void stop_dnsmasq(void);
200 extern void set_tz(void);
201 extern void start_ntpc(void);
202 extern void stop_ntpc(void);
203 extern void check_services(void);
204 extern void exec_service(void);
205 extern int service_main(int argc
, char *argv
[]);
206 extern void start_service(const char *name
);
207 extern void stop_service(const char *name
);
208 extern void restart_service(const char *name
);
209 extern void start_services(void);
210 extern void stop_services(void);
211 // !!TB - USB and NAS
213 extern void restart_nas_services(int stop
, int start
);
215 #define restart_nas_services(args...) do { } while(0)
218 extern void start_hotplug2();
219 extern void stop_hotplug2(void);
222 extern void start_ipv6_tunnel(void);
223 extern void stop_ipv6_tunnel(void);
224 extern void start_radvd(void);
225 extern void stop_radvd(void);
226 extern void start_ipv6(void);
227 extern void stop_ipv6(void);
230 // !!TB - USB Support
233 extern void start_usb(void);
234 extern void stop_usb(void);
235 extern int dir_is_mountpoint(const char *root
, const char *dir
);
236 extern void hotplug_usb(void);
237 extern void remove_storage_main(int shutdn
);
239 #define start_usb(args...) do { } while(0)
240 #define stop_usb(args...) do { } while(0)
241 #define dir_is_mountpoint(args...) (0)
242 #define hotplug_usb(args...) do { } while(0)
243 #define remove_storage_main(args...) do { } while(0)
247 extern int wds_enable(void);
248 extern int wl_security_on(void);
249 extern void start_nas(void);
250 extern void stop_nas(void);
251 extern void notify_nas(const char *ifname
);
254 extern wanface_list_t wanfaces
;
255 extern char lanface
[];
257 extern char wan6face
[];
259 extern char lan_cclass
[];
260 extern const char *chain_in_accept
;
261 extern const char *chain_out_drop
;
262 extern const char *chain_out_accept
;
263 extern const char *chain_out_reject
;
264 extern char **layer7_in
;
266 extern void enable_ip_forward(void);
267 extern void ipt_write(const char *format
, ...);
268 extern void ip6t_write(const char *format
, ...);
269 #if defined(TCONFIG_IPV6) && defined(LINUX26)
270 #define ip46t_write(args...) do { ipt_write(args); ip6t_write(args); } while(0)
271 //#define ip46t_flagged_write(do_ip4t, do_ip6t, args...) do { if (do_ip4t) ipt_write(args); if (do_ip6t) ip6t_write(args); } while(0)
272 #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)
273 #define ip46t_cond_write(do_ip6t, args...) do { if (do_ip6t) ip6t_write(args); else ipt_write(args); } while(0)
275 #define ip46t_write ipt_write
276 //#define ip46t_flagged_write(do_ip4t, do_ip6t, args...) do { if (do_ip4t) ipt_write(args); } while(0)
277 #define ip46t_flagged_write(do_ip46t, args...) do { if (do_ip46t & IPT_V4) ipt_write(args); } while(0)
278 #define ip46t_cond_write(do_ip6t, args...) ipt_write(args)
280 extern void ipt_log_unresolved(const char *addr
, const char *addrtype
, const char *categ
, const char *name
);
281 extern int ipt_addr(char *addr
, int maxlen
, const char *s
, const char *dir
, int af
, int strict
, const char *categ
, const char *name
);
282 extern int ipt_dscp(const char *v
, char *opt
);
283 extern int ipt_ipp2p(const char *v
, char *opt
);
284 extern int ipt_layer7(const char *v
, char *opt
);
285 extern void ipt_layer7_inbound(void);
286 extern int start_firewall(void);
287 extern int stop_firewall(void);
289 extern void create_test_iptfile(void);
292 extern void allow_fastnat(const char *service
, int allow
);
293 extern void try_enabling_fastnat(void);
297 extern void start_account(void);
298 extern void stop_account(void);
301 extern void start_arpbind(void);
302 extern void stop_arpbind(void);
305 extern void ipt_forward(ipt_table_t table
);
306 extern void ipt_triggered(ipt_table_t table
);
309 extern void ip6t_forward(void);
313 extern int rcheck_main(int argc
, char *argv
[]);
314 extern void ipt_restrictions(void);
315 extern void sched_restrictions(void);
318 extern void ipt_qos(void);
319 extern void start_qos(void);
320 extern void stop_qos(void);
324 extern void start_cifs(void);
325 extern void stop_cifs(void);
326 extern int mount_cifs_main(int argc
, char *argv
[]);
328 static inline void start_cifs(void) { };
329 static inline void stop_cifs(void) { };
334 extern void init_jffs2(void);
335 extern void start_jffs2(void);
336 extern void stop_jffs2(void);
338 static inline void init_jffs2(void) { };
339 static inline void start_jffs2(void) { };
340 static inline void stop_jffs2(void) { };
345 extern void start_ddns(void);
346 extern void stop_ddns(void);
347 extern int ddns_update_main(int argc
, char **argv
);
349 static inline void start_ddns(void) { };
350 static inline void stop_ddns(void) { };
354 extern void usage_exit(const char *cmd
, const char *help
) __attribute__ ((noreturn
));
355 #define modprobe(mod, args...) ({ char *argv[] = { "modprobe", "-s", mod, ## args, NULL }; _eval(argv, NULL, 0, NULL); })
356 extern int modprobe_r(const char *mod
);
357 #define xstart(args...) _xstart(args, NULL)
358 extern int _xstart(const char *cmd
, ...);
359 extern void run_nvscript(const char *nv
, const char *arg1
, int wtime
);
360 extern void run_userfile (char *folder
, char *extension
, const char *arg1
, int wtime
);
361 extern void setup_conntrack(void);
362 extern int host_addr_info(const char *name
, int af
, struct sockaddr_storage
*buf
);
363 extern int host_addrtypes(const char *name
, int af
);
364 extern void inc_mac(char *mac
, int plus
);
365 extern void set_mac(const char *ifname
, const char *nvname
, int plus
);
366 extern const char *default_wanif(void);
367 // extern const char *default_wlif(void);
368 #define vstrsep(buf, sep, args...) _vstrsep(buf, sep, args, NULL)
369 extern int _vstrsep(char *buf
, const char *sep
, ...);
370 extern void simple_unlock(const char *name
);
371 extern void simple_lock(const char *name
);
372 extern void killall_tk(const char *name
);
373 extern int mkdir_if_none(const char *path
);
374 extern long fappend(FILE *out
, const char *fname
);
375 extern long fappend_file(const char *path
, const char *fname
);
378 extern void create_passwd(void);
379 extern void start_sshd(void);
380 extern void stop_sshd(void);
381 extern void start_telnetd(void);
382 extern void stop_telnetd(void);
385 extern int mtd_erase(const char *mtdname
);
386 extern int mtd_unlock(const char *mtdname
);
387 extern int mtd_write_main(int argc
, char *argv
[]);
388 extern int mtd_unlock_erase_main(int argc
, char *argv
[]);
391 extern int buttons_main(int argc
, char *argv
[]);
394 extern int led_main(int argc
, char *argv
[]);
397 extern int gpio_main(int argc
, char *argv
[]);
400 extern int sched_main(int argc
, char *argv
[]);
401 extern void start_sched(void);
402 extern void stop_sched(void);
405 extern void start_snmpd(void);
406 extern void stop_snmpd(void);
410 extern void start_pptp_client(void);
411 extern void stop_pptp_client(void);
412 extern int write_pptpvpn_resolv(FILE*);
414 #define write_vpn_resolv(f) (0)
418 extern int nvram_file2nvram(const char *name
, const char *filename
);
419 extern int nvram_nvram2file(const char *name
, const char *filename
);
423 extern void hotplug_usb(void);
424 extern int usbevent_main(int argc
, char *argv
[]);
425 extern void start_usbevent(void);
426 extern void stop_usbevent(void);
427 extern int usbrescan_main(int argc
, char *argv
[]);
428 extern int hotdiskadd_main(int argc
, char *argv
[]);
429 extern int hotdiskremove_main(int argc
, char *argv
[]);
430 extern int hotdiskerror_main(int argc
, char *argv
[]);
431 extern int umountx_main(int argc
, char *argv
[]);
433 void start_test_1(void);
434 void stop_test_1(void);
437 extern void start_smbd(void);
438 extern void stop_smbd(void);
443 extern void start_snmp();
444 extern void stop_snmp();
448 #ifdef TCONFIG_OPENVPN
449 extern void start_vpnclient(int clientNum
);
450 extern void stop_vpnclient(int clientNum
);
451 extern void start_vpnserver(int serverNum
);
452 extern void stop_vpnserver(int serverNum
);
453 extern void start_vpn_eas();
454 extern void stop_vpn_eas();
455 extern void run_vpn_firewall_scripts();
456 extern void write_vpn_dnsmasq_config(FILE*);
457 extern int write_vpn_resolv(FILE*);
460 static inline void start_vpnclient(int clientNum) {}
461 static inline void stop_vpnclient(int clientNum) {}
462 static inline void start_vpnserver(int serverNum) {}
463 static inline void stop_vpnserver(int serverNum) {}
464 static inline void run_vpn_firewall_scripts() {}
465 static inline void write_vpn_dnsmasq_config(FILE*) {}
467 static inline void start_vpn_eas() { }
468 static inline void stop_vpn_eas() { }
469 #define write_vpn_resolv(f) (0)
473 extern void ipt_qoslimit(int chain
);
474 extern void start_qoslimit(void);
475 extern void stop_qoslimit(void);
478 extern void start_arpbind(void);
479 extern void stop_arpbind(void);
483 extern void start_nocat();
484 extern void stop_nocat();
485 extern void reset_nocat();