britkat1980 / giv_tcp

TCP connection (from inverter) and MQTT implementation
85 stars 37 forks source link

Multiple Networks - One Default Gateway #288

Open AberDino opened 3 days ago

AberDino commented 3 days ago

My Home Assistant setup has two networks (IPv4 only - IPv6 disabled). One has a default gateway set, and the other one doesn't, because it's only for communicating with local devices including the GivEnergy kit and quite a few smart plugs (effectively my IoT network). I used these instructions to set up the second (VLAN) connection, including the "ipv4.never-default" option to avoid traffic routing out of this interface. Within Home Assistant (Settings -> System -> Network), the gateway address for this second interface address appears as "null".

I recently upgraded to GivTCP v3, and it won't start because it appears that it doesn't like the fact that the second network interface does not have a gateway address. Log entry: `2024-10-25 12:30:23,092 - startup - [INFO ] - ==================== STARTING GivTCP========================== Traceback (most recent call last): File "/app/startup.py", line 389, in networks[i]=interface['ipv4']['gateway']+"/"+str(mask)


TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'`

If I enter a valid gateway address for the second network, GivTCP starts up without any issues, but changing the routing metrics does not appear to be working 100%, as in that scenario I do see Home Assistant traffic trying to route out through the IoT VLAN (which is then blocked on the firewall because only some devices on the IoT network are allowed to route out, e.g. the GivEnergy devices). Therefore, my preference would be to get GivTCP working without the gateway address for any additional VLAN(s). Would that be possible?
britkat1980 commented 1 day ago

Sure, I'll have to make assumptions about the subnet mask (/24) and use the ip address found to scan

AberDino commented 23 hours ago

That's great, thank you in advance!

I'm not a programmer, but hopefully you should be able to find the information about the various networks by using the equivalent of "ip addr show". The information returned includes the IP address and subnet mask, so you wouldn't have to make assumptions. However, as the command returns information from all the interfaces, including loopback, docker0, hassio, etc., it might be a challenge to filter out only the details which are relevant. Let me know if I can help with anything.