Based on what I learned here, I am hoping someone could please review this script and let me know if they think this is a proper way to get the bridge and subnet info for a dsnmasq-sdn.postconf script:
Thank you!
EDIT: Fixed error based on information found in Merlin source code (names of parameters in the NVRAM values)
Bash:
#!/bin/sh
CONFIG=$1
SDN=$2
source /usr/sbin/helper.sh
#Determine bridge name and subnet info of this SDN
sdn_rl=$(nvram get sdn_rl)
subnet_rl=$(nvram get subnet_rl)
#From mtlan_utils.c:
#sdn_rl
# sdn_idx, sdn_name, sdn_enable, vlan_idx, subnet_idx,
# apg_idx, vpnc_idx, vpns_idx, dnsf_idx,
# urlf_idx, nwf_idx, cp_idx, gre_idx, fw_idx,
# killsw_sw, ahs_sw, wan_idx, ppprelay_sw, wan6_idx,
# createby, mtwan_idx, mswan_idx, prio
#subnet_rl
# idx, ifname, addr, netmask, dhcp_enable, dhcp_min, dhcp_max,
# dhcp_lease, domain_name, dns, wins, dhcp_res, dhcp_res_idx,
# v6_enable, v6_autoconf, addr6, dhcp6_min, dhcp6_max, dns6,
# dot_enable, dot_tls
#get subnet_idx
SDNidx=$(echo $sdn_rl | tr '<' '\n' | awk -F'>' '{print $1 ":" $5}' | grep "^"$SDN":" | awk -F':' '{print $2}')
#get ifname, addr, netmask
SUBNETrow=$(echo $subnet_rl | tr '<' '\n' | awk -F'>' '{print $1 ":" $2 " " $3 " " $4}' | grep "^"$SDNidx":" | awk -F':' '{print $2}')
BR=$(echo $SUBNETrow | awk '{print $1}')
IPBASE=$(echo $SUBNETrow | awk '{print $2}')
IPMASK=$(echo $SUBNETrow | awk '{print $3}')
#make config changes here:
#
if [ -n "$BR" ]; then
logger -t "dnsmasq-sdn.postconf" "Updated dnsmasq-"$SDN "configuration with bridge" $BR "on subnet "$IPBASE"/"$IPMASK
else
logger -t "dnsmasq-sdn.postconf" "Error: Subnet info for SDN" $SDN "not found"
fi
Thank you!
EDIT: Fixed error based on information found in Merlin source code (names of parameters in the NVRAM values)
Last edited:
