Skip to content

Commit

Permalink
Refined "mac_interface" feature #24
Browse files Browse the repository at this point in the history
Closes #24
  • Loading branch information
nemesifier committed Jun 27, 2016
1 parent f338578 commit d9d305e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
12 changes: 7 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ UCI configuration options must go in ``/etc/config/openwisp``.
- ``verify_ssl``: whether SSL verification must be performed or not, defaults to ``1``
- ``shared_secret``: shared secret, needed for `Automatic registration`_
- ``consistent_key``: whether `Consistent key generation`_ is enabled or not, defaults to ``1``
- ``mac_interface``: which interface to use (if it exists) to catch the MAC address, defaults to ``eth0``
- ``merge_config``: whether `Merge configuration`_ is enabled or not, defaults to ``1``
- ``test_config``: whether a new configuration must be tested before being considered applied, defaults to ``1``
- ``test_script``: custom test script, read more about this feature in `Configuration test`_
Expand All @@ -71,6 +70,7 @@ UCI configuration options must go in ``/etc/config/openwisp``.
- ``capath``: value passed to curl ``--capath`` argument, defaults to ``/etc/ssl/certs``; see also `curl capath argument <https://curl.haxx.se/docs/manpage.html#--capath>`_
- ``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>`_
- ``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>`_
- ``mac_interface``: the interface from which the MAC address is taken when performing automatic registration, defaults to ``eth0``;

Automatic registration
----------------------
Expand All @@ -95,11 +95,13 @@ even if reset or reflashed.
The ``key`` is generated consistently with an operation like ``md5sum(mac_address + shared_secret)``;
this allows the controller application to recognize that an existing device is registering itself again.

Verify that the interface of which you take the mac address is always the same with the mac_interface option.
Pay attention on virtual interface like bridges and taps.
The ``mac_interface`` configuration key specifies which interface is used to calculate the mac address,
this setting defaults to ``eth0``. If no ``eth0`` interface exists, the first non-loopback, non-bridge and non-tap
interface is used. You won't need to change this setting often, but if you do, ensure you choose a physical
interface which has constant mac address.

This feature is enabled by default, but must be enabled also in the controller application
in order to work.
The "Consistent key generation" feature is enabled by default, but must be enabled also in the
controller application in order to work.

Merge configuration
-------------------
Expand Down
6 changes: 3 additions & 3 deletions openwisp-config/files/openwisp.agent
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ while [ -n "$1" ]; do
--key) export KEY="$2"; shift;;
--shared-secret) export SHARED_SECRET="$2"; shift;;
--consistent-key) export CONSISTENT_KEY="$2"; shift;;
--mac-interface) export MAC_INTERFACE="$2"; shift;;
--merge-config) export MERGE_CONFIG="$2"; shift;;
--unmanaged) export UNMANAGED="$2"; shift;;
--test-config) export TEST_CONFIG="$2"; shift;;
--test-script) export TEST_SCRIPT="$2"; shift;;
--connect-timeout) export CONNECT_TIMEOUT="$2"; shift;;
--max-time) export MAX_TIME="$2"; shift;;
--capath) export CAPATH="$2"; shift;;
--mac-interface) export MAC_INTERFACE="$2"; shift;;
-*)
echo "Invalid option: $1"
exit 1
Expand Down Expand Up @@ -53,10 +53,10 @@ VERIFY_SSL=${VERIFY_SSL:-1}
MERGE_CONFIG=${MERGE_CONFIG:-1}
TEST_CONFIG=${TEST_CONFIG:-1}
CONSISTENT_KEY=${CONSISTENT_KEY:-1}
MAC_INTERFACE=${MAC_INTERFACE:-eth0}
CONNECT_TIMEOUT=${CONNECT_TIMEOUT:-15}
MAX_TIME=${MAX_TIME:-30}
CAPATH=${CAPATH:-/etc/ssl/certs}
MAC_INTERFACE=${MAC_INTERFACE:-eth0}
WORKING_DIR="/tmp/openwisp"
BASEURL="$URL/controller"
CONFIGURATION_ARCHIVE="$WORKING_DIR/configuration.tar.gz"
Expand Down Expand Up @@ -102,7 +102,7 @@ register() {
local raw=$(ifconfig $MAC_INTERFACE 2&> /dev/null)
if [ -z "$raw" ]; then raw=$(ifconfig); fi
local macaddr=$(echo "$raw " | egrep -v "^(lo|br-|tap[0-9]+)" | awk '/HWaddr/ { print $5 }' | head -n 1)
# use macaddress if hostname is the default one or empty
# use macaddress if hostname is the default one or empty
if [ "$hostname" == "OpenWrt" ] || [ "$hostname" == "lede" ] || [ -z "$hostname" ]; then
hostname="$macaddr"
fi
Expand Down
8 changes: 4 additions & 4 deletions openwisp-config/files/openwisp.init
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,21 @@ start_service() {
key=$(config_get http key)
shared_secret=$(config_get http shared_secret)
consistent_key=$(config_get http consistent_key)
mac_interface=$(config_get http mac_interface)
unmanaged=$(config_get http unmanaged)
merge_config=$(config_get http merge_config)
test_config=$(config_get http test_config)
test_script=$(config_get http test_script)
connect_timeout=$(config_get http connect_timeout)
max_time=$(config_get http max_time)
capath=$(config_get http capath)
mac_interface=$(config_get http mac_interface)
if [ $url ]; then url="--url $url"; fi
if [ $interval ]; then interval="--interval $interval"; fi
if [ $verify_ssl ]; then verify_ssl="--verify-ssl $verify_ssl"; fi
if [ $uuid ]; then uuid="--uuid $uuid"; fi
if [ $key ]; then key="--key $key"; fi
if [ $shared_secret ]; then shared_secret="--shared-secret $shared_secret"; fi
if [ $consistent_key ]; then consistent_key="--consistent-key $consistent_key"; fi
if [ $mac_interface ]; then mac_interface="--mac-interface $mac_interface"; fi
if [ -n "$unmanaged" ]; then
# replace spaces with commas to avoid problems when
# passing this arg to procd_set_param command
Expand All @@ -43,6 +42,7 @@ start_service() {
if [ $connect_timeout ]; then connect_timeout="--connect-timeout $connect_timeout"; fi
if [ $max_time ]; then max_time="--max-time $max_time"; fi
if [ $capath ]; then capath="--capath $capath"; fi
if [ $mac_interface ]; then mac_interface="--mac-interface $mac_interface"; fi

if [ -z "$url" ]; then
logger -s "url is not set, please add it in /etc/config/openwisp" \
Expand All @@ -60,8 +60,8 @@ start_service() {

procd_open_instance
procd_set_param command $PROG $url $interval $verify_ssl $uuid $key $shared_secret \
$consistent_key $mac_interface $unmanaged $merge_config $test_config \
$test_script $connect_timeout $max_time $capath
$consistent_key $unmanaged $merge_config $test_config \
$test_script $connect_timeout $max_time $capath $mac_interface
procd_set_param respawn
procd_close_instance
logger -s "$PROG_NAME started" \
Expand Down

0 comments on commit d9d305e

Please sign in to comment.