mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] net: ifup: check for ctrl+c during ifup
@ 2023-07-21 11:07 Ahmad Fatoum
  2023-07-21 11:07 ` [PATCH 2/2] net: ifup: don't redo ifup -a1 if we have a gateway Ahmad Fatoum
  2023-07-26 10:08 ` [PATCH 1/2] net: ifup: check for ctrl+c during ifup Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2023-07-21 11:07 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

When global.net.server is set, barebox will attempt to bring up all
interfaces on ifup -a1 to see which interface can resolve it.

That can take a while and there's no way to abort that, so stick in a
ctrlc(), so user can change their mind (and e.g. remove
global.net.server, so ifup -a1 takes first interface that has link up).

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 net/ifup.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/net/ifup.c b/net/ifup.c
index 64298b44ebf3..993d2a115fda 100644
--- a/net/ifup.c
+++ b/net/ifup.c
@@ -276,7 +276,7 @@ static bool ifup_edev_need_conf(struct eth_device *edev)
 		edev->global_mode != ETH_MODE_DISABLED;
 }
 
-static void __ifup_all_parallel(unsigned flags)
+static int __ifup_all_parallel(unsigned flags)
 {
 	struct eth_device *edev;
 	unsigned netdev_count = 0;
@@ -292,6 +292,9 @@ static void __ifup_all_parallel(unsigned flags)
 	start = get_time_ns();
 	while (netdev_count && !is_timeout(start, PHY_AN_TIMEOUT * SECOND)) {
 		for_each_netdev(edev) {
+			if (ctrlc())
+				return -EINTR;
+
 			if (!ifup_edev_need_conf(edev))
 				continue;
 
@@ -306,21 +309,28 @@ static void __ifup_all_parallel(unsigned flags)
 			netdev_count--;
 
 			if ((flags & IFUP_FLAG_UNTIL_NET_SERVER) && net_get_server())
-				return;
+				return 0;
 		}
 	}
+
+	return 0;
 }
 
-static void __ifup_all_sequence(unsigned flags)
+static int __ifup_all_sequence(unsigned flags)
 {
 	struct eth_device *edev;
 
 	for_each_netdev(edev) {
+		if (ctrlc())
+			return -EINTR;
+
 		ifup_edev(edev, flags);
 
 		if ((flags & IFUP_FLAG_UNTIL_NET_SERVER) && net_get_server())
-			return;
+			return 0;
 	}
+
+	return 0;
 }
 
 int ifup_all(unsigned flags)
@@ -358,11 +368,9 @@ int ifup_all(unsigned flags)
 		flags &= ~IFUP_FLAG_UNTIL_NET_SERVER;
 
 	if (flags & IFUP_FLAG_PARALLEL)
-		__ifup_all_parallel(flags);
+		return __ifup_all_parallel(flags);
 	else
-		__ifup_all_sequence(flags);
-
-	return 0;
+		return __ifup_all_sequence(flags);
 }
 
 void ifdown_all(void)
-- 
2.39.2




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

* [PATCH 2/2] net: ifup: don't redo ifup -a1 if we have a gateway
  2023-07-21 11:07 [PATCH 1/2] net: ifup: check for ctrl+c during ifup Ahmad Fatoum
@ 2023-07-21 11:07 ` Ahmad Fatoum
  2023-07-26 10:08 ` [PATCH 1/2] net: ifup: check for ctrl+c during ifup Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Ahmad Fatoum @ 2023-07-21 11:07 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

ifup -a -1 is an optimization for switches that have only one port
connected: ifup will poll link on all ports in parallel and early
exit once any port got an IP address. This doesn't work when
global.net.server is set, as the first port to get link up is not
necessary one that is in a network that can resolve global.net.server.

This is needlessly restrictive: Even if global.net.server is set,
it's only a problem if no gateway was set. If there's a gateway, barebox
already knows how to resolve global.net.server, so there's no need to
try to bring up all interfaces when -1 is supplied.

This fixes the delay when using ifup -a1 multiple times in a row.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 net/ifup.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/net/ifup.c b/net/ifup.c
index 993d2a115fda..6866150d93bc 100644
--- a/net/ifup.c
+++ b/net/ifup.c
@@ -292,6 +292,9 @@ static int __ifup_all_parallel(unsigned flags)
 	start = get_time_ns();
 	while (netdev_count && !is_timeout(start, PHY_AN_TIMEOUT * SECOND)) {
 		for_each_netdev(edev) {
+			if ((flags & IFUP_FLAG_UNTIL_NET_SERVER) && net_get_server())
+				return 0;
+
 			if (ctrlc())
 				return -EINTR;
 
@@ -307,9 +310,6 @@ static int __ifup_all_parallel(unsigned flags)
 				continue;
 
 			netdev_count--;
-
-			if ((flags & IFUP_FLAG_UNTIL_NET_SERVER) && net_get_server())
-				return 0;
 		}
 	}
 
@@ -321,13 +321,13 @@ static int __ifup_all_sequence(unsigned flags)
 	struct eth_device *edev;
 
 	for_each_netdev(edev) {
+		if ((flags & IFUP_FLAG_UNTIL_NET_SERVER) && net_get_server())
+			return 0;
+
 		if (ctrlc())
 			return -EINTR;
 
 		ifup_edev(edev, flags);
-
-		if ((flags & IFUP_FLAG_UNTIL_NET_SERVER) && net_get_server())
-			return 0;
 	}
 
 	return 0;
@@ -364,7 +364,7 @@ int ifup_all(unsigned flags)
 	 * empty, i.e. the first DHCP lease setting $global.net.server
 	 * will be what we're going with.
 	 */
-	if (net_get_server())
+	if (net_get_server() && !net_get_gateway())
 		flags &= ~IFUP_FLAG_UNTIL_NET_SERVER;
 
 	if (flags & IFUP_FLAG_PARALLEL)
-- 
2.39.2




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

* Re: [PATCH 1/2] net: ifup: check for ctrl+c during ifup
  2023-07-21 11:07 [PATCH 1/2] net: ifup: check for ctrl+c during ifup Ahmad Fatoum
  2023-07-21 11:07 ` [PATCH 2/2] net: ifup: don't redo ifup -a1 if we have a gateway Ahmad Fatoum
@ 2023-07-26 10:08 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2023-07-26 10:08 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: barebox

On Fri, Jul 21, 2023 at 01:07:43PM +0200, Ahmad Fatoum wrote:
> When global.net.server is set, barebox will attempt to bring up all
> interfaces on ifup -a1 to see which interface can resolve it.
> 
> That can take a while and there's no way to abort that, so stick in a
> ctrlc(), so user can change their mind (and e.g. remove
> global.net.server, so ifup -a1 takes first interface that has link up).
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
>  net/ifup.c | 24 ++++++++++++++++--------
>  1 file changed, 16 insertions(+), 8 deletions(-)
> 

Applied, thanks

Sascha

> diff --git a/net/ifup.c b/net/ifup.c
> index 64298b44ebf3..993d2a115fda 100644
> --- a/net/ifup.c
> +++ b/net/ifup.c
> @@ -276,7 +276,7 @@ static bool ifup_edev_need_conf(struct eth_device *edev)
>  		edev->global_mode != ETH_MODE_DISABLED;
>  }
>  
> -static void __ifup_all_parallel(unsigned flags)
> +static int __ifup_all_parallel(unsigned flags)
>  {
>  	struct eth_device *edev;
>  	unsigned netdev_count = 0;
> @@ -292,6 +292,9 @@ static void __ifup_all_parallel(unsigned flags)
>  	start = get_time_ns();
>  	while (netdev_count && !is_timeout(start, PHY_AN_TIMEOUT * SECOND)) {
>  		for_each_netdev(edev) {
> +			if (ctrlc())
> +				return -EINTR;
> +
>  			if (!ifup_edev_need_conf(edev))
>  				continue;
>  
> @@ -306,21 +309,28 @@ static void __ifup_all_parallel(unsigned flags)
>  			netdev_count--;
>  
>  			if ((flags & IFUP_FLAG_UNTIL_NET_SERVER) && net_get_server())
> -				return;
> +				return 0;
>  		}
>  	}
> +
> +	return 0;
>  }
>  
> -static void __ifup_all_sequence(unsigned flags)
> +static int __ifup_all_sequence(unsigned flags)
>  {
>  	struct eth_device *edev;
>  
>  	for_each_netdev(edev) {
> +		if (ctrlc())
> +			return -EINTR;
> +
>  		ifup_edev(edev, flags);
>  
>  		if ((flags & IFUP_FLAG_UNTIL_NET_SERVER) && net_get_server())
> -			return;
> +			return 0;
>  	}
> +
> +	return 0;
>  }
>  
>  int ifup_all(unsigned flags)
> @@ -358,11 +368,9 @@ int ifup_all(unsigned flags)
>  		flags &= ~IFUP_FLAG_UNTIL_NET_SERVER;
>  
>  	if (flags & IFUP_FLAG_PARALLEL)
> -		__ifup_all_parallel(flags);
> +		return __ifup_all_parallel(flags);
>  	else
> -		__ifup_all_sequence(flags);
> -
> -	return 0;
> +		return __ifup_all_sequence(flags);
>  }
>  
>  void ifdown_all(void)
> -- 
> 2.39.2
> 
> 
> 

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



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

end of thread, other threads:[~2023-07-26 10:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-21 11:07 [PATCH 1/2] net: ifup: check for ctrl+c during ifup Ahmad Fatoum
2023-07-21 11:07 ` [PATCH 2/2] net: ifup: don't redo ifup -a1 if we have a gateway Ahmad Fatoum
2023-07-26 10:08 ` [PATCH 1/2] net: ifup: check for ctrl+c during ifup Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox