1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2008 Alina Friedrichsen
3 # Copyright (C) 2011 OpenWrt.org
9 PROG
="/usr/sbin/siproxd"
10 CONF_DIR
="/var/etc/siproxd"
11 REG_DIR
="/var/lib/siproxd"
12 PID_DIR
="/var/run/siproxd"
13 PLUGIN_DIR
="/usr/lib/siproxd/"
17 # Some options need special handling or conflict with procd/jail setup.
18 append CONF_SKIP
"interface_inbound interface_outbound chrootjail"
19 append CONF_SKIP
"daemonize user plugindir registration_file pid_file"
22 # Check if a UCI option is set, or else apply a provided default.
29 config_get
"$opt" "$sec" "$opt"
30 eval "val=\"\${$opt}\""
32 [ -z "$val" ] ||
return 0
33 [ -n "$default" ] ||
return 0
34 config_set
"$sec" "$opt" "$default"
35 append_conf
"$opt" = "$default"
39 echo $
* >> "$CONF_DIR/siproxd-$sec.conf"
42 # Resolve network device by layer 3 first, then layer 2
44 siproxd_get_device
() {
45 network_get_device
$1 $2 || network_get_physdev
$1 $2
48 # Use user-friendly network names (e.g. "wan", "lan") from options
49 # 'interface_inbound' and 'interface_outbound', but use standard siproxd
50 # parameters 'if_inbound' and 'if_outbound' if explicitly set.
54 local _int_inbound _int_outbound
55 local _dev_inbound _dev_outbound
57 config_get _int_inbound
"$sec" interface_inbound
58 config_get _int_outbound
"$sec" interface_outbound
60 siproxd_get_device _dev_inbound
$_int_inbound
61 siproxd_get_device _dev_outbound
$_int_outbound
63 default_conf if_inbound
$_dev_inbound
64 default_conf if_outbound
$_dev_outbound
67 # Apply default values to key options if unset in user's UCI config.
72 default_conf sip_listen_port
5060
73 default_conf autosave_registrations
300
74 default_conf rtp_port_low
7070
75 default_conf rtp_port_high
7089
76 default_conf rtp_timeout
300
77 default_conf rtp_dscp
46
78 default_conf tcp_timeout
600
79 default_conf tcp_keepalive
20
80 default_conf default_expires
600
81 default_conf daemonize
0
82 default_conf user
"$SIPROXD_UID"
83 default_conf registration_file
"$REG_DIR/siproxd-$sec.reg"
84 default_conf plugindir
"$PLUGIN_DIR"
87 # Handle activities at start of a new 'siproxd' section.
88 # Initialize section processing and save section name.
93 rm -f "$CONF_DIR/siproxd-$sec.conf"
94 append_conf
"# config auto-generated from /etc/config/siproxd"
97 # Handle activities at close of a 'siproxd' section.
98 # Parse OpenWRT interface names (e.g. "wan"), apply defaults and
104 local conf_file
="$CONF_DIR/siproxd-$sec.conf"
105 local pid_file
="$PID_DIR/siproxd-$sec.pid"
106 local reg_file plugin_dir
108 setup_networks
"$sec"
109 apply_defaults
"$sec"
111 config_get plugin_dir
"$sec" plugindir
112 config_get reg_file
"$sec" registration_file
114 procd_open_instance
"$sec"
115 procd_set_param
command "$PROG" --config "$conf_file"
116 procd_set_param pidfile
"$pid_file"
117 procd_set_param respawn
118 procd_add_jail siproxd log
119 procd_add_jail_mount
/etc
/passwd
/etc
/group
/etc
/TZ
/dev
/null
120 procd_add_jail_mount
"$conf_file"
121 [ -d "$plugin_dir" ] && procd_add_jail_mount
"$plugin_dir"
122 # Ensure registration file exists for jail
123 [ -f "$reg_file" ] ||
touch "$reg_file"
124 chown
"$SIPROXD_UID:$SIPROXD_GID" "$reg_file"
125 procd_add_jail_mount_rw
"$reg_file"
129 # Setup callbacks for parsing siproxd sections, options, and lists.
130 # This avoids hardcoding all supported siproxd configuration parameters.
134 # Section change: close any previous section.
135 [ -n "$cur_sec" ] && section_end
"$cur_sec"
138 # New 'siproxd' section: begin processing.
141 section_start
"$cur_sec"
143 # Config end or unknown section: ignore.
153 [ -z "$sec" ] && return
154 list_contains CONF_SKIP
"$1" && return
155 [ -n "$2" ] && append_conf
"$1" = "$2"
165 procd_add_reload_trigger
"siproxd"
169 mkdir
-p "$CONF_DIR" "$REG_DIR" "$PID_DIR"
170 chmod 755 "$CONF_DIR" "$REG_DIR" "$PID_DIR"
171 chown
"$SIPROXD_UID:$SIPROXD_GID" "$REG_DIR"
173 .
/lib
/functions
/network.sh
175 config_load
'siproxd'