Add an optional argument to specify an interface to as default
connection for the system. This changes the printet commands so that the
gateway is configured as default route, and nameservers are written to
resolv.conf.

Output without a default interface:

  root@iwg26:/usr/lib/ofono/test# ./process-context-settings
  Configuring /quectel_0/context1
      Interface is ppp0
      IP address is 100.64.0.151
      Gateway is 0.0.0.0
      Nameserver is 8.8.8.8
      Nameserver is 8.8.4.4

  ip address add dev ppp0 100.64.0.151/32
  ip route add  8.8.8.8 dev ppp0
  ip route add  8.8.4.4 dev ppp0

Output with ppp0 as default interface:

  root@iwg26:/usr/lib/ofono/test# ./process-context-settings ppp0
  Using ppp0 as default link
  Configuring /quectel_0/context1
      Interface is ppp0
      IP address is 100.64.0.151
      Gateway is 0.0.0.0
      Nameserver is 8.8.8.8
      Nameserver is 8.8.4.4

  ip address add dev ppp0 100.64.0.151/32
  ip route add default via 0.0.0.0 dev ppp0
  echo nameserver 8.8.8.8 >  /etc/resolv.conf
  echo nameserver 8.8.4.4 >>  /etc/resolv.conf

Example of evaluating the commands:

  root@iwg26:/usr/lib/ofono/test# eval "$(./process-context-settings ppp0)"
  Using ppp0 as default link
  Configuring /quectel_0/context1
      Interface is ppp0
      IP address is 100.64.0.151
      Gateway is 0.0.0.0
      Nameserver is 8.8.8.8
      Nameserver is 8.8.4.4
---
 test/process-context-settings | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/test/process-context-settings b/test/process-context-settings
index ee3f17d3..15e23618 100755
--- a/test/process-context-settings
+++ b/test/process-context-settings
@@ -10,6 +10,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)
+
 commands = []
 
 for path, properties in modems:
@@ -51,12 +56,22 @@ for path, properties in modems:
                        cmd += "/32"
                        commands.append(cmd)
 
-                       for i in settings["DomainNameServers"]:
-                               print("    Nameserver is %s" % (i),
+                       if interface == default:
+                               cmd = "ip route add default via " + gateway
+                               cmd += " dev " + interface
+                               commands.append(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
 
                                commands.append(cmd)
 
-- 
2.22.0

_______________________________________________
ofono mailing list
[email protected]
https://lists.ofono.org/mailman/listinfo/ofono

Reply via email to