test: process-context-settings: add argument for default connection
PATCH v2 1/1 test: process-context-settings: add argument for default connection
Add an optional argument to specify an interface to as default connection for the system. This changes the constructed commands so that the gateway is configured as default route, and nameservers are written to resolv.conf.
---
I decided to drop the print-instead-execute approach, and simply add the interface argument to get the default route and dns settings. These changes were mostly to enable easy setup of internet on my board...
test/process-context-settings | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-)
test/process-context-settings +21 -4
@@ -11,6 +11,11 @@ manager = dbus.Interface(bus.get_object('org.ofono', '/'), modems = manager.GetModems() +default = None +if len(sys.argv) > 1: + default = sys.argv[1] + print("Using %s as default link" % (default), file=sys.stderr) + for path, properties in modems: if "org.ofono.ConnectionManager" not in properties["Interfaces"]: continue
@@ -50,11 +55,23 @@ for path, properties in modems: cmd += "/32" os.system(cmd); - for i in settings["DomainNameServers"]: - print(" Nameserver is %s" % (i), + if interface == default: + cmd = "ip route add default via " + gateway + cmd += " dev " + interface + os.system(cmd) + + for i,dns in enumerate(settings["DomainNameServers"]): + print(" Nameserver is %s" % (dns), file=sys.stderr) - cmd = "ip route add " + i - cmd +=" dev " + interface + if interface == default: + redirect = " > " if i == 0 else " >> " + cmd = "echo nameserver " + dns + redirect + cmd += "/etc/resolv.conf" + else: + cmd = "ip route add " + dns + cmd += " dev " + interface + os.system(cmd); + print('', file=sys.stderr)
Signature · 1 line
2.22.0
Hi Martin,
Quoted 4 lines · Martin Hundebøll
Add an optional argument to specify an interface to as default connection for the system. This changes the constructed commands so that the gateway is configured as default route, and nameservers are written to resolv.conf.
Actually, I would forgo the argument completely, and always set the default route. Just add a metric argument and set it low, like 600+ or so. Or make the metric configurable. That way if WWAN is your only route, then it becomes the default automagically. And if it isn't, then it has a low enough priority that it won't be used.
e.g. ip route add default via $IP dev $FOO metric 600
One can do even fancier things with policy based routing, but this should be good enough for testing.
Quoted 14 lines
---
I decided to drop the print-instead-execute approach, and simply add the interface argument to get the default route and dns settings. These changes were mostly to enable easy setup of internet on my board...
test/process-context-settings | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-)test/process-context-settings +0
-0
test/process-context-settings manager = dbus.Interface(bus.get_object('org.ofono', '/'), · line 18
Quoted 8 lines
test/process-context-settings +5
-0@@ -11,6 +11,11 @@ manager = dbus.Interface(bus.get_object('org.ofono', '/'), modems = manager.GetModems() +default = None +if len(sys.argv) > 1: + default = sys.argv[1] + print("Using %s as default link" % (default), file=sys.stderr) +
I would not take the interface argument from the command line (for safety reasons) if I could help it. And with udev renaming I can never (easily) type what it comes up with :)
Quoted 14 lines
test/process-context-settings +5
-2for path, properties in modems: if "org.ofono.ConnectionManager" not in properties["Interfaces"]: continue@@ -50,11 +55,23 @@ for path, properties in modems: cmd += "/32" os.system(cmd); - for i in settings["DomainNameServers"]: - print(" Nameserver is %s" % (i), + if interface == default: + cmd = "ip route add default via " + gateway + cmd += " dev " + interface + os.system(cmd) +
test/process-context-settings for path, properties in modems: · line 70
Quoted 10 lines
test/process-context-settings +6
-2+ for i,dns in enumerate(settings["DomainNameServers"]): + print(" Nameserver is %s" % (dns), file=sys.stderr) - cmd = "ip route add " + i - cmd +=" dev " + interface + if interface == default: + redirect = " > " if i == 0 else " >> " + cmd = "echo nameserver " + dns + redirect + cmd += "/etc/resolv.conf"
Maybe consider this as a separate command line option (e.g. whether to set the DNS to resolv.conf) ?
test/process-context-settings for path, properties in modems: · line 73
Quoted 3 lines
test/process-context-settings +3
-0+ else: + cmd = "ip route add " + dns + cmd += " dev " + interface
Don't you want to add a route to DNS in all cases? DNS might not be on the same subnet as the IP obtained from the modem..
test/process-context-settings for path, properties in modems: · line 77
Quoted 5 lines
test/process-context-settings +2
-0+ os.system(cmd); + print('', file=sys.stderr)
Regards,
-Denis