What's new
  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

dnsmasq.conf.add not working on Guest Network Pro clients

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:

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:
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:
I’m not in a position to make any comment on whether the code is correctly written or offer improvements but I would like to check something and ask if you would consider an option in it, if I may?

Does it just provide details (only) of the sdn and br parameters, the former for the naming of the multiple dnsmasq-sdn.conf.add files in /jffs/config/ and the latter for (e.g.) any iptables entries in firewall-start, or does it actually go on to create (at least) the dnsmasq files i.e. hat does the section “# make config changes here:” do? Also, can I ask why you chose to log to dnsmasq-sdn.postconf and not dnsmasq-sdn.conf.add?

If yes, it actually creates the files (to populate manually with manual assignments later), would it be possible to have it ask the question whether you want to do that first, so you can say no and it does not then overwrite any existing files you may have manually created or were created by YazDHCP? If I’ve misread what it might be doing, then put it down to lack of understanding and curiosity!
 
Last edited:
I have had use cases that needed the bridge/subnet information during dnsmasq configuration (e.g. creating and assigning an ULA to the virtual bridge and adding that to the configuration file). During configuration, one only gets the SDN index and would need to use that to get everything else. In general, I am hoping the experts can tell me if this is the wrong path or at least provide advice on how to find out more info.
 
Btw, the Wiki for custom Merlin configs (Link) states "dnsmasq-sdn.postconf (the SDN index number is passed as second argument, 1 is the first instance)". Does the info in this thread mean this statement should be updated?
 
I recently created a function that parses the get_mtlan output and makes it easy to query SDN entries and their related information, including the SDN name, bridge name, SDN index, and IPv6 status (enabled/disabled). The forum doesn't allow me to post the code here for some reason, so here's a link to my repo:

The function can output either pipe-separated (default) or human-readable formats. It also makes it easy to extract any field you need using awk. You can invoke it without arguments to list all SDNs, or pass an SDN index or bridge name to retrieve specific SDN properties.

Usage examples:
Code:
kuchkovsky@rt:/tmp/home/root# list_sdn  # default pipe-separated output
Guest|br54|3|0
IoT|br56|5|0
kuchkovsky@rt:/tmp/home/root# list_sdn -h  # human-readable output
name=Guest br=br54 sdn_idx=3
name=IoT br=br56 sdn_idx=5
kuchkovsky@rt:/tmp/home/root# list_sdn 3  # find SDN by index
Guest|br54|3|0
kuchkovsky@rt:/tmp/home/root# list_sdn 3 | awk -F '|' '{ print $2 }'  # extract the bridge name
br54
kuchkovsky@rt:/tmp/home/root# list_sdn br56  # find SDN by bridge name
IoT|br56|5|0
kuchkovsky@rt:/tmp/home/root# list_sdn br56 | awk -F '|' '{ print $3 }'  # extract the SDN index
5
 
I recently created a function that parses the get_mtlan output and makes it easy to query SDN entries and their related information, including the SDN name, bridge name, SDN index, and IPv6 status (enabled/disabled).
I had a wee look around your GitHub page, impressive collection, quite some work (most of it well beyond me), but well done!

Keeping on topic, if someone wanted to use your particular script can you do so in isolation i.e. just save the one script to /jffs/scripts/ and run it …. or per your main page, do you still need to clone your repository, make backups (always a good idea) and allow the various existing scripts to be amended (nervous about doing this and probably will not attempt it for the one script, at least not right now).

No problem if not able to run in isolation, but then for this purpose I’d still really like to see @rung’s script developed to completion.
 
Keeping on topic, if someone wanted to use your particular script can you do so in isolation i.e. just save the one script to /jffs/scripts/ and run it …. or per your main page, do you still need to clone your repository, make backups (always a good idea) and allow the various existing scripts to be amended (nervous about doing this and probably will not attempt it for the one script, at least not right now).
That's only if you need the functionality of a specific add-on (basically, a set of related scripts) listed in README. I'll probably create proper installers for them later.

Regarding the specific list_sdn function, it can be copied and used directly, as it doesn't have any dependencies. It's part of an add-on, but it can be used separately. You can even paste it directly into SSH and then invoke it.
 
Regarding the specific list_sdn function, it can be copied and used directly, as it doesn't have any dependencies. It's part of an add-on, but it can be used separately. You can even paste it directly into SSH and then invoke it.
That’s great, thank you for the clear explanation, much appreciated.

[EDIT]. Works a treat!

IMG_2656.jpeg
 
Last edited:
That's only if you need the functionality of a specific add-on (basically, a set of related scripts) listed in README. I'll probably create proper installers for them later.

Regarding the specific list_sdn function, it can be copied and used directly, as it doesn't have any dependencies. It's part of an add-on, but it can be used separately. You can even paste it directly into SSH and then invoke it.
Nice job on the scripts! Btw, not sure there is any advantage one way or the other, but here is what I use to list the bridges:
Bash:
brctl show | awk 'NF>1 && NR>1 {print $1}'

Rung
 

Similar threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Back
Top