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 # Use user-friendly network names (e.g. "wan", "lan") from options
43 # 'interface_inbound' and 'interface_outbound', but use standard siproxd
44 # parameters 'if_inbound' and 'if_outbound' if explicitly set.
48 local _int_inbound _int_outbound
49 local _dev_inbound _dev_outbound
51 config_get _int_inbound
"$sec" interface_inbound
52 config_get _int_outbound
"$sec" interface_outbound
54 .
/lib
/functions
/network.sh
55 network_get_physdev _dev_inbound
$_int_inbound
56 network_get_physdev _dev_outbound
$_int_outbound
58 default_conf if_inbound
$_dev_inbound
59 default_conf if_outbound
$_dev_outbound
62 # Apply default values to key options if unset in user's UCI config.
67 default_conf sip_listen_port
5060
68 default_conf autosave_registrations
300
69 default_conf rtp_port_low
7070
70 default_conf rtp_port_high
7089
71 default_conf rtp_timeout
300
72 default_conf rtp_dscp
46
73 default_conf tcp_timeout
600
74 default_conf tcp_keepalive
20
75 default_conf default_expires
600
76 default_conf daemonize
0
77 default_conf user
"$SIPROXD_UID"
78 default_conf registration_file
"$REG_DIR/siproxd-$sec.reg"
79 default_conf plugindir
"$PLUGIN_DIR"
82 # Handle activities at start of a new 'siproxd' section.
83 # Initialize section processing and save section name.
88 rm -f "$CONF_DIR/siproxd-$sec.conf"
89 append_conf
"# config auto-generated from /etc/config/siproxd"
92 # Handle activities at close of a 'siproxd' section.
93 # Parse OpenWRT interface names (e.g. "wan"), apply defaults and
99 local conf_file
="$CONF_DIR/siproxd-$sec.conf"
100 local pid_file
="$PID_DIR/siproxd-$sec.pid"
101 local reg_file plugin_dir
103 setup_networks
"$sec"
104 apply_defaults
"$sec"
106 config_get plugin_dir
"$sec" plugindir
107 config_get reg_file
"$sec" registration_file
109 procd_open_instance
"$sec"
110 procd_set_param
command "$PROG" --config "$conf_file"
111 procd_set_param pidfile
"$pid_file"
112 procd_set_param respawn
113 procd_add_jail siproxd log
114 procd_add_jail_mount
/etc
/passwd
/etc
/group
/etc
/TZ
/dev
/null
115 procd_add_jail_mount
"$conf_file"
116 [ -d "$plugin_dir" ] && procd_add_jail_mount
"$plugin_dir"
117 # Ensure registration file exists for jail
118 [ -f "$reg_file" ] ||
touch "$reg_file"
119 chown
"$SIPROXD_UID:$SIPROXD_GID" "$reg_file"
120 procd_add_jail_mount_rw
"$reg_file"
124 # Setup callbacks for parsing siproxd sections, options, and lists.
125 # This avoids hardcoding all supported siproxd configuration parameters.
129 # Section change: close any previous section.
130 [ -n "$cur_sec" ] && section_end
"$cur_sec"
133 # New 'siproxd' section: begin processing.
136 section_start
"$cur_sec"
138 # Config end or unknown section: ignore.
148 [ -z "$sec" ] && return
149 list_contains CONF_SKIP
"$1" && return
150 [ -n "$2" ] && append_conf
"$1" = "$2"
160 procd_add_reload_trigger
"siproxd"
164 mkdir
-p "$CONF_DIR" "$REG_DIR" "$PID_DIR"
165 chmod 755 "$CONF_DIR" "$REG_DIR" "$PID_DIR"
166 chown
"$SIPROXD_UID:$SIPROXD_GID" "$REG_DIR"
169 config_load
'siproxd'