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!

Solved GNP NVRAM setting question and Script advice

kstamand

Regular Contributor
Looking for scripting advice on how best to parse the Guest Network Pro (GNP) nvram vlan_rl value??

nvram vlan_rl value question
My setup has 3 custom GNP VLAN where the nvram setting vlan_rl has the value <1>52>0><2>53>0><3>54>0>
My understanding is that vlan_rl consists of columns of information >> SDN # (1, 2, or 3 in my case), Bridge Interface number (52, 53, or 54), and I'm not sure what the third field is for (0)
Question 1 - what is the third column of information in the nvram setting vlan_rl in each of the three SDN (0 in my case)?

Script question/advice, related to the nvram vlan_rl setting
My understanding is that the SDN number can be 1 - 2 characters, as can the Bridge Interface number, and I'm going to assume that third value can be 1 - 2 characters as well. I also understand there can be a variable number of SDN (1 - 9 or more)
Question 2 (I'm not sure how best to ask, but ..), is there some pattern matching magic that allows me to dynamically loop through the nvram vlan_rl string and pull out each SDN combination of information (SDN #, Bridge Interface #, third ??) into an array or separate variables - Something like SDN#: value, BR#: value, XX#, value??

Goal is to have a "somewhat" dynamic DNSMASQ-SDN.POSTCONF for dnsmasq customizations
Currently, my dnsmasq-sdn.postconf has hard coded SDN# references for adding different domain names (and potential other information) for each VLAN (e.g., vlan 1 = home.lan, vlan 2 = adults.lan, ...) and it's working well.
I'm just looking to enhance my scripting skills.
 
Not sure if this is helpful, but when I needed the bridge identifier in a dnsmasq sdn post conf script, I used this kludge:
Bash:
BR=$(nvram get subnet_rl | tr '<' '\n' | awk -F'>' '{print $1 ":" $2}' | grep $SDN":" | awk -F':' '{print $2}')

Where I had previously set the variable SDN to the second received parameter $2.
 
Use the get_mtlan command to see how the nvram is broken up into relatable fields.
Interesting command with useful information for future reference - thank you
 
Last edited:
Not sure if this is helpful, but when I needed the bridge identifier in a dnsmasq sdn post conf script, I used this kludge:
Bash:
BR=$(nvram get subnet_rl | tr '<' '\n' | awk -F'>' '{print $1 ":" $2}' | grep $SDN":" | awk -F':' '{print $2}')

Where I had previously set the variable SDN to the second received parameter $2.
Thanks for the suggestion!!
 
I ended up creating the following script to parse the nvram vlan_rl setting for my current needs, in case it may be helpful for others.

Code:
#!/bin/sh
# set -x # uncomment for debugging purposes

# read the list of vlan from nvram variable vlan_rl
vlan_list="$(nvram get vlan_rl)"

# count the number of vlan in the vlan_list string (each occurrence of the string "<" marks the beginning of a new set of vlan info)
vlan_count=$(echo $vlan_list | grep -o "<" | wc -l)

# get the length of the vlan_list string
vlan_list_length=${#vlan_list}

# calculate the length of each string of vlan info (sdn#, vlanid, ??) by dividing total vlan_list length by the number of vlan in list
let vlan_str_length=$vlan_list_length/$vlan_count

# set substring start position, for extracting individual vlan info set from vlan_list
substring_start=0

# loop through the vlan_list string, for the count of vlans identified
for i in 0 .. $vlan_count; do
    substring="${vlan_list:$substring_start:$vlan_str_length}" # extract a set of vlan info from the vlan_list string

    # strip out the '<' and '>' characters from the substring
    vlan_info="$(echo $substring | tr '<' ' ' | tr '>' ' ')"

    #now pick up each piece of information
    sdn_idx="$(echo $vlan_info | cut -f1 -d ' ')" # capture sdn index number
    vlan_id="$(echo $vlan_info | cut -f2 -d ' ')" # capture vlan id
    unknown_id="$(echo $vlan_info | cut -f3 -d ' ')" # capture unknown id

    echo "sdn_idx - $sdn_idx ; vlan_id - $vlan_id ; unknown_id - $unknown_id"

    #move the substring start position over to the next set of vlan info
    let substring_start=$substring_start+$vlan_str_length
done
 

Latest 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