Skip to content

Commit

Permalink
fix(migration): network, use truncated names
Browse files Browse the repository at this point in the history
Before the commit, if a network was truncated to 15 chars, the new short name
was used inside the `network` config database but not inside the
`firewall` database: the firewall zone was pointing to a non existing
network,

Example:

- original name of the interface was 'timenet_ftth_12345'

- value saved inside the network db:

    config interface 'timenet_ftth_1'
        option proto 'static'

- value saved inside 'firewall' db:

    config zone 'ns_wan'
        option name 'wan'
        option output 'ACCEPT'
        option input 'DROP'
        option forward 'REJECT'
        list network 'timenet_ftth_12345'
  • Loading branch information
gsanchietti committed Feb 11, 2025
1 parent f3c30e9 commit a82b8d4
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/ns-migration/files/scripts/network
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ alias_zones = dict()
devices = dict()
bond_zones = dict()
bonds = dict()
interface_names = dict()

def exists(key):
try:
Expand Down Expand Up @@ -236,11 +237,12 @@ for a in data['aliases']:

# Create interfaces
for i in data['interfaces']:
iname = utils.sanitize(i["interface"])
siname = utils.sanitize(i["interface"])
if i["proto"] == "pppoe":
iname = iname[0:8] # make sure interface name is 8 chars max, reserve space for "pppoe-" prefix
iname = siname[0:8] # make sure interface name is 8 chars max, reserve space for "pppoe-" prefix
else:
iname = iname[0:14] # make sure interface name is 15 chars max
iname = siname[0:14] # make sure interface name is 15 chars max
interface_names[siname] = iname
nsmigration.vprint(f'Creating interface {iname}')
u.set("network", iname, "interface") # create named record
u.set("network", iname, "proto", i["proto"])
Expand Down Expand Up @@ -290,7 +292,8 @@ for z in data['zones']:
if base_name in z["network"]:
z["network"].remove(base_name) # avoid duplicate bond like bond0 and bond0_lan
z["network"] = z["network"] + bond_zones[z["name"]]
u.set("firewall", zname, "network", [utils.sanitize(n) for n in z["network"]])
# retrieve reduced network name, if present
u.set("firewall", zname, "network", [interface_names.get(utils.sanitize(n), utils.sanitize(n)) for n in z["network"]])
if z["name"].startswith("wan"): # setup masquerading for wans
u.set("firewall", zname, "masq", '1')
u.set("firewall", zname, "mtu_fix", '1')
Expand Down

0 comments on commit a82b8d4

Please sign in to comment.