All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/4] test: process-context-settings: use ip instead of ifconfig/route
@ 2019-07-18 11:49 Martin =?unknown-8bit?q?Hundeb=C3=B8ll?=
  2019-07-18 11:49 ` [PATCH 2/4] test: process-context-settings: print settings to stderr Martin =?unknown-8bit?q?Hundeb=C3=B8ll?=
                   ` (4 more replies)
  0 siblings, 5 replies; 8+ messages in thread
From: Martin =?unknown-8bit?q?Hundeb=C3=B8ll?= @ 2019-07-18 11:49 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 864 bytes --]

---
 test/process-context-settings | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/test/process-context-settings b/test/process-context-settings
index 1d30b30d..a536a771 100755
--- a/test/process-context-settings
+++ b/test/process-context-settings
@@ -41,14 +41,14 @@ for path, properties in modems:
 			print("    IP address is %s" % (address))
 			print("    Gateway is %s" % (gateway))
 
-			cmd = "ifconfig " + interface + " " + address
-			cmd += " netmask 255.255.255.255"
+			cmd = "ip address add dev " + interface + " " + address
+			cmd += "/32"
 			os.system(cmd);
 
 			for i in settings["DomainNameServers"]:
 				print("    Nameserver is %s" % (i))
 
-				cmd = "route add -host " + i
+				cmd = "ip route add  " + i
 				cmd +=" dev " + interface
 				os.system(cmd);
 		print('')
-- 
2.22.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/4] test: process-context-settings: print settings to stderr
  2019-07-18 11:49 [PATCH 1/4] test: process-context-settings: use ip instead of ifconfig/route Martin =?unknown-8bit?q?Hundeb=C3=B8ll?=
@ 2019-07-18 11:49 ` Martin =?unknown-8bit?q?Hundeb=C3=B8ll?=
  2019-07-18 11:49 ` [PATCH 3/4] test: process-context-settings: print commands instead of running them Martin =?unknown-8bit?q?Hundeb=C3=B8ll?=
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Martin =?unknown-8bit?q?Hundeb=C3=B8ll?= @ 2019-07-18 11:49 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 2012 bytes --]

Prepare the test to print commands to execute and let the caller
evaluate those. In that way, more commands can be added to also set up
name servers and default routes without secretly breaking the existing
system network setup.
---
 test/process-context-settings | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/test/process-context-settings b/test/process-context-settings
index a536a771..7ffb12b3 100755
--- a/test/process-context-settings
+++ b/test/process-context-settings
@@ -1,6 +1,7 @@
 #!/usr/bin/python3
 
 import os
+import sys
 import dbus
 
 bus = dbus.SystemBus()
@@ -23,13 +24,14 @@ for path, properties in modems:
 		if properties["Active"] == dbus.Boolean(0):
 			continue
 
-		print("Configuring %s" % (path))
+		print("Configuring %s" % (path), file=sys.stderr)
 
 		settings = properties["Settings"]
 		interface = settings["Interface"]
 
 		if settings["Method"] == "dhcp":
-			print("    Run DHCP on interface %s" % (interface))
+			print("    Run DHCP on interface %s" % (interface),
+				file=sys.stderr)
 		else:
 			address = settings["Address"]
 			try:
@@ -37,18 +39,22 @@ for path, properties in modems:
 			except:
 				gateway = "0.0.0.0";
 
-			print("    Interface is %s" % (interface))
-			print("    IP address is %s" % (address))
-			print("    Gateway is %s" % (gateway))
+			print("    Interface is %s" % (interface),
+				file=sys.stderr)
+			print("    IP address is %s" % (address),
+				file=sys.stderr)
+			print("    Gateway is %s" % (gateway),
+				file=sys.stderr)
 
 			cmd = "ip address add dev " + interface + " " + address
 			cmd += "/32"
 			os.system(cmd);
 
 			for i in settings["DomainNameServers"]:
-				print("    Nameserver is %s" % (i))
+				print("    Nameserver is %s" % (i),
+					file=sys.stderr)
 
 				cmd = "ip route add  " + i
 				cmd +=" dev " + interface
 				os.system(cmd);
-		print('')
+		print('', file=sys.stderr)
-- 
2.22.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/4] test: process-context-settings: print commands instead of running them
  2019-07-18 11:49 [PATCH 1/4] test: process-context-settings: use ip instead of ifconfig/route Martin =?unknown-8bit?q?Hundeb=C3=B8ll?=
  2019-07-18 11:49 ` [PATCH 2/4] test: process-context-settings: print settings to stderr Martin =?unknown-8bit?q?Hundeb=C3=B8ll?=
@ 2019-07-18 11:49 ` Martin =?unknown-8bit?q?Hundeb=C3=B8ll?=
  2019-07-19  6:28   ` Denis Kenzior
  2019-07-18 11:49 ` [PATCH 4/4] test: process-context-settings: add argument for default connection Martin =?unknown-8bit?q?Hundeb=C3=B8ll?=
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 8+ messages in thread
From: Martin =?unknown-8bit?q?Hundeb=C3=B8ll?= @ 2019-07-18 11:49 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1299 bytes --]

Collect the setup commands and print them to stdout at the end of the
script. This allows users to evaluate the standard output to apply
settings.
---
 test/process-context-settings | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/test/process-context-settings b/test/process-context-settings
index 7ffb12b3..ee3f17d3 100755
--- a/test/process-context-settings
+++ b/test/process-context-settings
@@ -1,6 +1,5 @@
 #!/usr/bin/python3
 
-import os
 import sys
 import dbus
 
@@ -11,6 +10,8 @@ manager = dbus.Interface(bus.get_object('org.ofono', '/'),
 
 modems = manager.GetModems()
 
+commands = []
+
 for path, properties in modems:
 	if "org.ofono.ConnectionManager" not in properties["Interfaces"]:
 		continue
@@ -48,7 +49,7 @@ for path, properties in modems:
 
 			cmd = "ip address add dev " + interface + " " + address
 			cmd += "/32"
-			os.system(cmd);
+			commands.append(cmd)
 
 			for i in settings["DomainNameServers"]:
 				print("    Nameserver is %s" % (i),
@@ -56,5 +57,10 @@ for path, properties in modems:
 
 				cmd = "ip route add  " + i
 				cmd +=" dev " + interface
-				os.system(cmd);
+
+				commands.append(cmd)
+
 		print('', file=sys.stderr)
+
+
+print("\n".join(commands))
-- 
2.22.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 4/4] test: process-context-settings: add argument for default connection
  2019-07-18 11:49 [PATCH 1/4] test: process-context-settings: use ip instead of ifconfig/route Martin =?unknown-8bit?q?Hundeb=C3=B8ll?=
  2019-07-18 11:49 ` [PATCH 2/4] test: process-context-settings: print settings to stderr Martin =?unknown-8bit?q?Hundeb=C3=B8ll?=
  2019-07-18 11:49 ` [PATCH 3/4] test: process-context-settings: print commands instead of running them Martin =?unknown-8bit?q?Hundeb=C3=B8ll?=
@ 2019-07-18 11:49 ` Martin =?unknown-8bit?q?Hundeb=C3=B8ll?=
  2019-07-18 16:38 ` [PATCH 1/4] test: process-context-settings: use ip instead of ifconfig/route Pavel Machek
  2019-07-19  6:26 ` Denis Kenzior
  4 siblings, 0 replies; 8+ messages in thread
From: Martin =?unknown-8bit?q?Hundeb=C3=B8ll?= @ 2019-07-18 11:49 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 2875 bytes --]

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(a)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(a)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(a)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


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/4] test: process-context-settings: use ip instead of ifconfig/route
  2019-07-18 11:49 [PATCH 1/4] test: process-context-settings: use ip instead of ifconfig/route Martin =?unknown-8bit?q?Hundeb=C3=B8ll?=
                   ` (2 preceding siblings ...)
  2019-07-18 11:49 ` [PATCH 4/4] test: process-context-settings: add argument for default connection Martin =?unknown-8bit?q?Hundeb=C3=B8ll?=
@ 2019-07-18 16:38 ` Pavel Machek
  2019-07-18 19:08   ` Martin =?unknown-8bit?q?Hundeb=C3=B8ll?=
  2019-07-19  6:26 ` Denis Kenzior
  4 siblings, 1 reply; 8+ messages in thread
From: Pavel Machek @ 2019-07-18 16:38 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1427 bytes --]

On Thu 2019-07-18 13:49:34, Martin Hundebøll wrote:
> ---
>  test/process-context-settings | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/test/process-context-settings b/test/process-context-settings
> index 1d30b30d..a536a771 100755
> --- a/test/process-context-settings
> +++ b/test/process-context-settings
> @@ -41,14 +41,14 @@ for path, properties in modems:
>  			print("    IP address is %s" % (address))
>  			print("    Gateway is %s" % (gateway))
>  
> -			cmd = "ifconfig " + interface + " " + address
> -			cmd += " netmask 255.255.255.255"
> +			cmd = "ip address add dev " + interface + " " + address
> +			cmd += "/32"
>  			os.system(cmd);
>  
>  			for i in settings["DomainNameServers"]:
>  				print("    Nameserver is %s" % (i))
>  
> -				cmd = "route add -host " + i
> +				cmd = "ip route add  " + i
>  				cmd +=" dev " + interface
>  				os.system(cmd);

So.. you move from one tool to another one, fixing it on some systems
and braking on some.

But I guess better solution would be to use python module, not execing
external programs.

...which certainly should not be executed using os.system(). Network
interface called `> /etc/passwd` would be a lot of phun, right? :-).

									Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/4] test: process-context-settings: use ip instead of ifconfig/route
  2019-07-18 16:38 ` [PATCH 1/4] test: process-context-settings: use ip instead of ifconfig/route Pavel Machek
@ 2019-07-18 19:08   ` Martin =?unknown-8bit?q?Hundeb=C3=B8ll?=
  0 siblings, 0 replies; 8+ messages in thread
From: Martin =?unknown-8bit?q?Hundeb=C3=B8ll?= @ 2019-07-18 19:08 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1569 bytes --]

On 18/07/2019 18.38, Pavel Machek wrote:
> On Thu 2019-07-18 13:49:34, Martin Hundebøll wrote:
>> ---
>>   test/process-context-settings | 6 +++---
>>   1 file changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/test/process-context-settings b/test/process-context-settings
>> index 1d30b30d..a536a771 100755
>> --- a/test/process-context-settings
>> +++ b/test/process-context-settings
>> @@ -41,14 +41,14 @@ for path, properties in modems:
>>   			print("    IP address is %s" % (address))
>>   			print("    Gateway is %s" % (gateway))
>>   
>> -			cmd = "ifconfig " + interface + " " + address
>> -			cmd += " netmask 255.255.255.255"
>> +			cmd = "ip address add dev " + interface + " " + address
>> +			cmd += "/32"
>>   			os.system(cmd);
>>   
>>   			for i in settings["DomainNameServers"]:
>>   				print("    Nameserver is %s" % (i))
>>   
>> -				cmd = "route add -host " + i
>> +				cmd = "ip route add  " + i
>>   				cmd +=" dev " + interface
>>   				os.system(cmd);
> 
> So.. you move from one tool to another one, fixing it on some systems
> and braking on some.

`ifconfig` and friends have been obsolete for quite some time now. Even 
busybox has been shipping `ip` since 2002...

> But I guess better solution would be to use python module, not execing
> external programs.
> 
> ...which certainly should not be executed using os.system(). Network
> interface called `> /etc/passwd` would be a lot of phun, right? :-).

I'll leave it up to ofono to choose sane names for interfaces :)

// Martin

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/4] test: process-context-settings: use ip instead of ifconfig/route
  2019-07-18 11:49 [PATCH 1/4] test: process-context-settings: use ip instead of ifconfig/route Martin =?unknown-8bit?q?Hundeb=C3=B8ll?=
                   ` (3 preceding siblings ...)
  2019-07-18 16:38 ` [PATCH 1/4] test: process-context-settings: use ip instead of ifconfig/route Pavel Machek
@ 2019-07-19  6:26 ` Denis Kenzior
  4 siblings, 0 replies; 8+ messages in thread
From: Denis Kenzior @ 2019-07-19  6:26 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 216 bytes --]

Hi Martin,

On 7/18/19 6:49 AM, Martin Hundebøll wrote:
> ---
>   test/process-context-settings | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
> 

Patch 1 & 2 applied.

Regards,
-Denis


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 3/4] test: process-context-settings: print commands instead of running them
  2019-07-18 11:49 ` [PATCH 3/4] test: process-context-settings: print commands instead of running them Martin =?unknown-8bit?q?Hundeb=C3=B8ll?=
@ 2019-07-19  6:28   ` Denis Kenzior
  0 siblings, 0 replies; 8+ messages in thread
From: Denis Kenzior @ 2019-07-19  6:28 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1782 bytes --]

Hi Martin,

On 7/18/19 6:49 AM, Martin Hundebøll wrote:
> Collect the setup commands and print them to stdout at the end of the
> script. This allows users to evaluate the standard output to apply
> settings.
> ---
>   test/process-context-settings | 12 +++++++++---
>   1 file changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/test/process-context-settings b/test/process-context-settings
> index 7ffb12b3..ee3f17d3 100755
> --- a/test/process-context-settings
> +++ b/test/process-context-settings
> @@ -1,6 +1,5 @@
>   #!/usr/bin/python3
>   
> -import os
>   import sys
>   import dbus
>   
> @@ -11,6 +10,8 @@ manager = dbus.Interface(bus.get_object('org.ofono', '/'),
>   
>   modems = manager.GetModems()
>   
> +commands = []
> +
>   for path, properties in modems:
>   	if "org.ofono.ConnectionManager" not in properties["Interfaces"]:
>   		continue
> @@ -48,7 +49,7 @@ for path, properties in modems:
>   
>   			cmd = "ip address add dev " + interface + " " + address
>   			cmd += "/32"
> -			os.system(cmd);
> +			commands.append(cmd)
>   
>   			for i in settings["DomainNameServers"]:
>   				print("    Nameserver is %s" % (i),
> @@ -56,5 +57,10 @@ for path, properties in modems:
>   
>   				cmd = "ip route add  " + i
>   				cmd +=" dev " + interface
> -				os.system(cmd);
> +
> +				commands.append(cmd)
> +
>   		print('', file=sys.stderr)
> +
> +
> +print("\n".join(commands))
> 

Can we actually keep the current behavior of executing all the generated 
commands?  process-context-settings is used in testing and it is a pain 
to unlearn the old way.  Perhaps you can add a command line option to 
only print the commands.  E.g. --dry-run or --print-only or something.

Regards,
-Denis

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2019-07-19  6:28 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-18 11:49 [PATCH 1/4] test: process-context-settings: use ip instead of ifconfig/route Martin =?unknown-8bit?q?Hundeb=C3=B8ll?=
2019-07-18 11:49 ` [PATCH 2/4] test: process-context-settings: print settings to stderr Martin =?unknown-8bit?q?Hundeb=C3=B8ll?=
2019-07-18 11:49 ` [PATCH 3/4] test: process-context-settings: print commands instead of running them Martin =?unknown-8bit?q?Hundeb=C3=B8ll?=
2019-07-19  6:28   ` Denis Kenzior
2019-07-18 11:49 ` [PATCH 4/4] test: process-context-settings: add argument for default connection Martin =?unknown-8bit?q?Hundeb=C3=B8ll?=
2019-07-18 16:38 ` [PATCH 1/4] test: process-context-settings: use ip instead of ifconfig/route Pavel Machek
2019-07-18 19:08   ` Martin =?unknown-8bit?q?Hundeb=C3=B8ll?=
2019-07-19  6:26 ` Denis Kenzior

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.