Skip to content

Commit c553549

Browse files
committed
[curl] Added curl_interface option #30
Improves #30
1 parent e5ffac2 commit c553549

File tree

5 files changed

+18
-2
lines changed

5 files changed

+18
-2
lines changed

README.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ UCI configuration options must go in ``/etc/config/openwisp``.
7474
- ``connect_timeout``: value passed to curl ``--connect-timeout`` argument, defaults to ``15``; see `curl connect-timeout argument <https://curl.haxx.se/docs/manpage.html#--connect-timeout>`_
7575
- ``max_time``: value passed to curl ``--max-time`` argument, defaults to ``30``; see `curl connect-timeout argument <https://curl.haxx.se/docs/manpage.html#-m>`_
7676
- ``mac_interface``: the interface from which the MAC address is taken when performing automatic registration, defaults to ``eth0``
77+
- ``curl_interface``: the value passed to curl ``--interface`` argument, it may have 3 different type of values:
78+
- ``0``: disabled (default value)
79+
- ``1``: enabled and automatically uses the value of the ``interface`` option
80+
- ``<interface_name>``: explicit interface name, eg: ``br-wan``
7781
- ``pre_reload_hook``: path to custom executable script, see `pre-reload-hook`_
7882

7983
Automatic registration

openwisp-config/files/openwisp-nossl.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@ config controller 'http'
2222
#option max_time '30'
2323
#option capath '/etc/ssl/certs'
2424
#option cacert '/etc/ssl/certs/ca-certificates.crt'
25+
#option curl_interface '0'
2526
# hooks
2627
#option pre_reload_hook '/usr/sbin/my_pre_reload_hook'

openwisp-config/files/openwisp-ssl.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@ config controller 'http'
2222
#option max_time '30'
2323
#option capath '/etc/ssl/certs'
2424
#option cacert '/etc/ssl/certs/ca-certificates.crt'
25+
#option curl_interface '0'
2526
# hooks
2627
#option pre_reload_hook '/usr/sbin/my_pre_reload_hook'

openwisp-config/files/openwisp.agent

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ while [ -n "$1" ]; do
2020
--capath) export CAPATH="$2"; shift;;
2121
--cacert) export CACERT="$2"; shift;;
2222
--mac-interface) export MAC_INTERFACE="$2"; shift;;
23+
--curl-interface) export CURL_INTERFACE="$2"; shift;;
2324
--pre-reload-hook) export PRE_RELOAD_HOOK="$2"; shift;;
2425
-*)
2526
echo "Invalid option: $1"
@@ -69,7 +70,7 @@ STATUS_REPORT="$WORKING_DIR/status_report"
6970
APPLYING_CONF="$WORKING_DIR/applying_conf"
7071
REGISTRATION_URL="$URL/controller/register/"
7172
UNMANAGED_DIR="$WORKING_DIR/unmanaged"
72-
FETCH_COMMAND="curl -s --connect-timeout $CONNECT_TIMEOUT --max-time $MAX_TIME --interface $MAC_INTERFACE"
73+
FETCH_COMMAND="curl -s --connect-timeout $CONNECT_TIMEOUT --max-time $MAX_TIME"
7374
mkdir -p $WORKING_DIR
7475
mkdir -p $UNMANAGED_DIR
7576

@@ -84,6 +85,13 @@ else
8485
fi
8586
fi
8687

88+
if [ "$CURL_INTERFACE" == "1" ]; then
89+
CURL_INTERFACE="$MAC_INTERFACE"
90+
fi
91+
if [ -n "$CURL_INTERFACE" ] && [ "$CURL_INTERFACE" != "0" ]; then
92+
FETCH_COMMAND="$FETCH_COMMAND --interface $CURL_INTERFACE"
93+
fi
94+
8795
if [ -n "$UNMANAGED" ]; then
8896
# replace commas with spaces
8997
UNMANAGED=$(echo $UNMANAGED | tr ',' ' ')

openwisp-config/files/openwisp.init

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ start_service() {
2424
capath=$(config_get http capath)
2525
cacert=$(config_get http cacert)
2626
mac_interface=$(config_get http mac_interface)
27+
curl_interface=$(config_get http curl_interface)
2728
pre_reload_hook=$(config_get http pre_reload_hook)
2829
if [ $url ]; then url="--url $url"; fi
2930
if [ $interval ]; then interval="--interval $interval"; fi
@@ -46,6 +47,7 @@ start_service() {
4647
if [ $capath ]; then capath="--capath $capath"; fi
4748
if [ $cacert ]; then cacert="--cacert $cacert"; fi
4849
if [ $mac_interface ]; then mac_interface="--mac-interface $mac_interface"; fi
50+
if [ $curl_interface ]; then curl_interface="--curl-interface $curl_interface"; fi
4951
if [ $pre_reload_hook ]; then pre_reload_hook="--pre-reload-hook $pre_reload_hook"; fi
5052

5153
if [ -z "$url" ]; then
@@ -66,7 +68,7 @@ start_service() {
6668
procd_set_param command $PROG $url $interval $verify_ssl $uuid $key $shared_secret \
6769
$consistent_key $unmanaged $merge_config $test_config \
6870
$test_script $connect_timeout $max_time $capath $cacert \
69-
$mac_interface $pre_reload_hook
71+
$mac_interface $curl_interface $pre_reload_hook
7072
procd_set_param respawn
7173
procd_close_instance
7274
logger -s "$PROG_NAME started" \

0 commit comments

Comments
 (0)