Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

add mac_interface option #24

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ 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 Down Expand Up @@ -94,6 +95,9 @@ 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.

This feature is enabled by default, but must be enabled also in the controller application
in order to work.

Expand Down
1 change: 1 addition & 0 deletions openwisp-config/files/openwisp-nossl.config
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ config controller 'http'
option verify_ssl '0'
#option shared_secret ''
#option consistent_key '1'
#option mac_interface 'eth0'
#option merge_config '1'
#option test_config '1'
#option test_script '/usr/sbin/mytest'
Expand Down
1 change: 1 addition & 0 deletions openwisp-config/files/openwisp-ssl.config
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ config controller 'http'
#option verify_ssl '1'
#option shared_secret ''
#option consistent_key '1'
#option mac_interface 'eth0'
#option merge_config '1'
#option test_config '1'
#option test_script '/usr/sbin/mytest'
Expand Down
8 changes: 5 additions & 3 deletions openwisp-config/files/openwisp.agent
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ 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;;
Expand Down Expand Up @@ -52,6 +53,7 @@ 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}
Expand Down Expand Up @@ -97,10 +99,10 @@ register() {
-p daemon.info
local hostname=$(uci get system.@system[0].hostname)
# use macaddr of eth0 or fallback to first non-loopback interface
local raw=$(ifconfig eth0 2&> /dev/null)
local raw=$(ifconfig $MAC_INTERFACE 2&> /dev/null)
if [ -z "$raw" ]; then raw=$(ifconfig); fi
local macaddr=$(echo "$raw " | grep -v lo | grep HWaddr | awk '/HWaddr/ { print $5 }' | head -n 1)
# use macaddress if hostname has not been changed
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
if [ "$hostname" == "OpenWrt" ] || [ "$hostname" == "lede" ] || [ -z "$hostname" ]; then
hostname="$macaddr"
fi
Expand Down
4 changes: 3 additions & 1 deletion openwisp-config/files/openwisp.init
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ 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)
Expand All @@ -29,6 +30,7 @@ start_service() {
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 Down Expand Up @@ -58,7 +60,7 @@ start_service() {

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