Change GWinfo to store vpnmac instead of vpnif

This is required to uniquely find the relation between VPN and
bat after change of MAC adresses.

This requires changes to the MySQL database!

Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
This commit is contained in:
Adrian Schmutzler 2018-01-15 22:39:11 +01:00
parent 0dea6339e2
commit 662bec1a16
5 changed files with 17 additions and 10 deletions

View File

@ -46,7 +46,7 @@ mysql.execute("""
`gw` smallint(5) UNSIGNED NOT NULL,
`mac` char(17) COLLATE utf8_unicode_ci NOT NULL,
`netif` varchar(15) COLLATE utf8_unicode_ci NOT NULL,
`vpnif` varchar(15) COLLATE utf8_unicode_ci DEFAULT NULL
`vpnmac` char(17) COLLATE utf8_unicode_ci DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
""")

View File

@ -28,23 +28,30 @@ def import_gw_data(mysql, gw_data):
newid = mysql.findone("SELECT id FROM gw WHERE name = %s LIMIT 1",(gw_data["hostname"],),"id")
nmacs = {}
for n in gw_data["netifs"]:
nmacs[n["netif"]] = n["mac"]
ndata = []
for n in gw_data["netifs"]:
if len(n["mac"])<17:
continue
if n["netif"].startswith("l2tp"): # Filter l2tp interfaces
continue
if not "vpnif" in n or not n["vpnif"]:
n["vpnif"] = None
ndata.append((newid,n["mac"],n["netif"],n["vpnif"]))
if "vpnif" in n and n["vpnif"]:
n["vpnmac"] = nmacs.get(n["vpnif"],None)
else:
n["vpnmac"] = None
ndata.append((newid,n["mac"],n["netif"],n["vpnmac"]))
mysql.executemany("""
INSERT INTO gw_netif (gw, mac, netif, vpnif)
INSERT INTO gw_netif (gw, mac, netif, vpnmac)
VALUES (%s, %s, %s, %s)
ON DUPLICATE KEY UPDATE
gw=VALUES(gw),
netif=VALUES(netif),
vpnif=VALUES(vpnif)
vpnmac=VALUES(vpnmac)
""",ndata)
adata = []

View File

@ -238,7 +238,7 @@ def gws_info(mysql,selecthood=None):
LEFT JOIN (
gw_netif AS n1
INNER JOIN gw ON n1.gw = gw.id
LEFT JOIN gw_netif AS n2 ON n1.netif = n2.vpnif AND n1.gw = n2.gw
LEFT JOIN gw_netif AS n2 ON n1.mac = n2.vpnmac AND n1.gw = n2.gw
) ON router_gw.mac = n1.mac
{}
GROUP BY router_gw.mac, n2.netif, n2.mac

View File

@ -129,7 +129,7 @@ def router_info(dbid):
LEFT JOIN (
gw_netif AS n1
INNER JOIN gw ON n1.gw = gw.id
LEFT JOIN gw_netif AS n2 ON n1.netif = n2.vpnif AND n1.gw = n2.gw
LEFT JOIN gw_netif AS n2 ON n1.mac = n2.vpnmac AND n1.gw = n2.gw
) ON router_gw.mac = n1.mac
WHERE router = %s
""",(dbid,))

View File

@ -82,7 +82,7 @@ def parse_router_list_search_query(args):
j += """ INNER JOIN router_gw ON router.id = router_gw.router
INNER JOIN (
gw_netif AS n1
INNER JOIN gw_netif AS n2 ON n1.netif = n2.vpnif AND n1.gw = n2.gw
INNER JOIN gw_netif AS n2 ON n1.mac = n2.vpnmac AND n1.gw = n2.gw
) ON router_gw.mac = n1.mac
"""
k = "n2.mac {} REGEXP %s".format(no)
@ -91,7 +91,7 @@ def parse_router_list_search_query(args):
j += """ INNER JOIN router_gw ON router.id = router_gw.router
INNER JOIN (
gw_netif AS n1
INNER JOIN gw_netif AS n2 ON n1.netif = n2.vpnif AND n1.gw = n2.gw
INNER JOIN gw_netif AS n2 ON n1.mac = n2.vpnmac AND n1.gw = n2.gw
) ON router_gw.mac = n1.mac
"""
k = "n2.mac {} REGEXP %s AND router_gw.selected = TRUE".format(no)