Skip to content

Instantly share code, notes, and snippets.

@stargieg
Created March 29, 2015 08:47
Show Gist options
  • Save stargieg/b0bc0e589f519e9dd723 to your computer and use it in GitHub Desktop.
Save stargieg/b0bc0e589f519e9dd723 to your computer and use it in GitHub Desktop.
olsrd dyn hna6 announcement
#!/bin/sh
. /lib/functions.sh
. /usr/share/libubox/jshn.sh
update_hna6() {
local cfg="$1"
local address="$2"
local mask="$3"
config_get interface $cfg interface
if [ "$interface" == "wan6" ] ; then
config_get cfg_address $cfg netaddr
if [ "$cfg_address" != "$address" ] ; then
uci_set olsrd6 "$cfg" prefix "$mask"
uci_set olsrd6 "$cfg" netaddr "$address"
uci_commit olsrd6
local reload=1
fi
local wan6_prefix=1
fi
}
local address=0
local mask=0
local wan6_prefix=0
local reload=0
#get wan6 ip status
wan6_data=`ubus call network.interface.wan6 status`
json_load "$wan6_data"
json_get_keys wan6_res
json_select "ipv6_prefix"
json_select "1"
json_get_var address address
json_get_var mask mask
echo "$address/$mask"
if [ $address != 0 -a $mask != 0 ] ; then
config_load olsrd6
config_foreach update_hna6 Hna6 $address $mask
logger -t "olsrd_dyn_hna6" "wan6 prefix $adress/$mask"
if [ $wan6_prefix == 0 ] ; then
#add Hna6 for auto configuration
uci_add olsrd6 Hna6 ; hna_sec="$CONFIG_SECTION"
uci_set olsrd6 "$hna_sec" prefix "$mask"
uci_set olsrd6 "$hna_sec" netaddr "$address"
uci_set olsrd6 "$hna_sec" interface "wan6"
#add Hna6 as default gateway
uci_add olsrd6 Hna6 ; hna_sec="$CONFIG_SECTION"
uci_set olsrd6 "$hna_sec" prefix "0"
uci_set olsrd6 "$hna_sec" netaddr "::"
uci_set olsrd6 "$hna_sec" interface "wan6"
uci_commit olsrd6
local reload=1
fi
#if [ $reload != 0 ] ; then
# /etc/init.d.olsrd6 restart
#fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment