mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] net: on ifup -a only detect devices when necessary
@ 2018-04-06 13:16 Sascha Hauer
  2018-04-06 19:33 ` Lucas Stach
  2018-04-12  8:53 ` Michael Tretter
  0 siblings, 2 replies; 4+ messages in thread
From: Sascha Hauer @ 2018-04-06 13:16 UTC (permalink / raw)
  To: Barebox List; +Cc: mtr

For network boot we once used to hardcode eth0, but in latest changes
this was changed to work with different network devices and the 'ifup
eth0' was replaced with 'ifup -a' which lead to the result that we now
detect all devices in order to eventually also bring up USB network
adapters. In most of the cases this is not desired. When a board has
internal network support this is likely to be used. With this patch
we only detect all devices when we do not have a network device already.
For the unusual case in which a USB network adapter shall be used
even when an internal network interface is present we introduce the
global variable "global.net.ifup_force_detect" which can be used to
force detection of devices.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 net/ifup.c | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/net/ifup.c b/net/ifup.c
index 827c5c03d1..d550f82530 100644
--- a/net/ifup.c
+++ b/net/ifup.c
@@ -28,6 +28,9 @@
 #include <globalvar.h>
 #include <string.h>
 #include <driver.h>
+#include <init.h>
+#include <globalvar.h>
+#include <magicvar.h>
 #include <linux/stat.h>
 
 static int eth_discover(char *file)
@@ -245,6 +248,8 @@ int ifup(const char *ethname, unsigned flags)
 	return ifup_edev(edev, flags);
 }
 
+static int net_ifup_force_detect;
+
 int ifup_all(unsigned flags)
 {
 	struct eth_device *edev;
@@ -266,7 +271,9 @@ int ifup_all(unsigned flags)
 
 	closedir(dir);
 
-	device_detect_all();
+	if ((flags & IFUP_FLAG_FORCE) || net_ifup_force_detect ||
+	    list_empty(&netdev_list))
+		device_detect_all();
 
 	for_each_netdev(edev)
 		ifup_edev(edev, flags);
@@ -274,6 +281,18 @@ int ifup_all(unsigned flags)
 	return 0;
 }
 
+static int ifup_all_init(void)
+{
+	globalvar_add_simple_bool("net.ifup_force_detect", &net_ifup_force_detect);
+
+	return 0;
+}
+late_initcall(ifup_all_init);
+
+BAREBOX_MAGICVAR_NAMED(global_net_ifup_force_detect,
+                       global.net.ifup_force_detect,
+                       "net: force detection of devices on ifup -a");
+
 #if IS_ENABLED(CONFIG_NET_CMD_IFUP)
 
 static int do_ifup(int argc, char *argv[])
-- 
2.16.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH] net: on ifup -a only detect devices when necessary
  2018-04-06 13:16 [PATCH] net: on ifup -a only detect devices when necessary Sascha Hauer
@ 2018-04-06 19:33 ` Lucas Stach
  2018-04-09  6:51   ` Sascha Hauer
  2018-04-12  8:53 ` Michael Tretter
  1 sibling, 1 reply; 4+ messages in thread
From: Lucas Stach @ 2018-04-06 19:33 UTC (permalink / raw)
  To: Sascha Hauer, Barebox List; +Cc: mtr

Am Freitag, den 06.04.2018, 15:16 +0200 schrieb Sascha Hauer:
> For network boot we once used to hardcode eth0, but in latest changes
> this was changed to work with different network devices and the 'ifup
> eth0' was replaced with 'ifup -a' which lead to the result that we
> now
> detect all devices in order to eventually also bring up USB network
> adapters. In most of the cases this is not desired. When a board has
> internal network support this is likely to be used. With this patch
> we only detect all devices when we do not have a network device
> already.
> For the unusual case in which a USB network adapter shall be used
> even when an internal network interface is present we introduce the
> global variable "global.net.ifup_force_detect" which can be used to
> force detection of devices.

This may warrant some more documentation. Without the code change and
the above commit message, the variable doc isn't too verbose about what
it does exactly.

Otherwise I love this change, it makes ifup -a much more useful.

Regards,
Lucas

> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
>  net/ifup.c | 21 ++++++++++++++++++++-
>  1 file changed, 20 insertions(+), 1 deletion(-)
> 
> diff --git a/net/ifup.c b/net/ifup.c
> index 827c5c03d1..d550f82530 100644
> --- a/net/ifup.c
> +++ b/net/ifup.c
> @@ -28,6 +28,9 @@
>  #include <globalvar.h>
>  #include <string.h>
>  #include <driver.h>
> +#include <init.h>
> +#include <globalvar.h>
> +#include <magicvar.h>
>  #include <linux/stat.h>
>  
>  static int eth_discover(char *file)
> @@ -245,6 +248,8 @@ int ifup(const char *ethname, unsigned flags)
>  	return ifup_edev(edev, flags);
>  }
>  
> +static int net_ifup_force_detect;
> +
>  int ifup_all(unsigned flags)
>  {
>  	struct eth_device *edev;
> @@ -266,7 +271,9 @@ int ifup_all(unsigned flags)
>  
>  	closedir(dir);
>  
> -	device_detect_all();
> +	if ((flags & IFUP_FLAG_FORCE) || net_ifup_force_detect ||
> +	    list_empty(&netdev_list))
> +		device_detect_all();
>  
>  	for_each_netdev(edev)
>  		ifup_edev(edev, flags);
> @@ -274,6 +281,18 @@ int ifup_all(unsigned flags)
>  	return 0;
>  }
>  
> +static int ifup_all_init(void)
> +{
> +	globalvar_add_simple_bool("net.ifup_force_detect",
> &net_ifup_force_detect);
> +
> +	return 0;
> +}
> +late_initcall(ifup_all_init);
> +
> +BAREBOX_MAGICVAR_NAMED(global_net_ifup_force_detect,
> +                       global.net.ifup_force_detect,
> +                       "net: force detection of devices on ifup
> -a");
> +
>  #if IS_ENABLED(CONFIG_NET_CMD_IFUP)
>  
>  static int do_ifup(int argc, char *argv[])

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH] net: on ifup -a only detect devices when necessary
  2018-04-06 19:33 ` Lucas Stach
@ 2018-04-09  6:51   ` Sascha Hauer
  0 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2018-04-09  6:51 UTC (permalink / raw)
  To: Lucas Stach; +Cc: Barebox List, mtr

On Fri, Apr 06, 2018 at 09:33:37PM +0200, Lucas Stach wrote:
> Am Freitag, den 06.04.2018, 15:16 +0200 schrieb Sascha Hauer:
> > For network boot we once used to hardcode eth0, but in latest changes
> > this was changed to work with different network devices and the 'ifup
> > eth0' was replaced with 'ifup -a' which lead to the result that we
> > now
> > detect all devices in order to eventually also bring up USB network
> > adapters. In most of the cases this is not desired. When a board has
> > internal network support this is likely to be used. With this patch
> > we only detect all devices when we do not have a network device
> > already.
> > For the unusual case in which a USB network adapter shall be used
> > even when an internal network interface is present we introduce the
> > global variable "global.net.ifup_force_detect" which can be used to
> > force detection of devices.
> 
> This may warrant some more documentation. Without the code change and
> the above commit message, the variable doc isn't too verbose about what
> it does exactly.

You're right. I added the following to the docs:

 +------------------------------+--------------+------------------------------------------------+
 | global.net.ifup_force_detect | boolean      | Set to true if your network device is not      |
 |                              |              | detected automatically during start (i.e. for  |
 |                              |              | USB network adapters)                          |
 +------------------------------+--------------+------------------------------------------------+

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* Re: [PATCH] net: on ifup -a only detect devices when necessary
  2018-04-06 13:16 [PATCH] net: on ifup -a only detect devices when necessary Sascha Hauer
  2018-04-06 19:33 ` Lucas Stach
@ 2018-04-12  8:53 ` Michael Tretter
  1 sibling, 0 replies; 4+ messages in thread
From: Michael Tretter @ 2018-04-12  8:53 UTC (permalink / raw)
  To: barebox

On Fri, 06 Apr 2018 15:16:39 +0200, Sascha Hauer wrote:
> For network boot we once used to hardcode eth0, but in latest changes
> this was changed to work with different network devices and the 'ifup
> eth0' was replaced with 'ifup -a' which lead to the result that we now
> detect all devices in order to eventually also bring up USB network
> adapters. In most of the cases this is not desired. When a board has
> internal network support this is likely to be used. With this patch
> we only detect all devices when we do not have a network device already.
> For the unusual case in which a USB network adapter shall be used
> even when an internal network interface is present we introduce the
> global variable "global.net.ifup_force_detect" which can be used to
> force detection of devices.
> 
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>

Tested-by: Michael Tretter <m.tretter@pengutronix.de>

Michael

> ---
>  net/ifup.c | 21 ++++++++++++++++++++-
>  1 file changed, 20 insertions(+), 1 deletion(-)
> 
> diff --git a/net/ifup.c b/net/ifup.c
> index 827c5c03d1..d550f82530 100644
> --- a/net/ifup.c
> +++ b/net/ifup.c
> @@ -28,6 +28,9 @@
>  #include <globalvar.h>
>  #include <string.h>
>  #include <driver.h>
> +#include <init.h>
> +#include <globalvar.h>
> +#include <magicvar.h>
>  #include <linux/stat.h>
>  
>  static int eth_discover(char *file)
> @@ -245,6 +248,8 @@ int ifup(const char *ethname, unsigned flags)
>  	return ifup_edev(edev, flags);
>  }
>  
> +static int net_ifup_force_detect;
> +
>  int ifup_all(unsigned flags)
>  {
>  	struct eth_device *edev;
> @@ -266,7 +271,9 @@ int ifup_all(unsigned flags)
>  
>  	closedir(dir);
>  
> -	device_detect_all();
> +	if ((flags & IFUP_FLAG_FORCE) || net_ifup_force_detect ||
> +	    list_empty(&netdev_list))
> +		device_detect_all();
>  
>  	for_each_netdev(edev)
>  		ifup_edev(edev, flags);
> @@ -274,6 +281,18 @@ int ifup_all(unsigned flags)
>  	return 0;
>  }
>  
> +static int ifup_all_init(void)
> +{
> +	globalvar_add_simple_bool("net.ifup_force_detect", &net_ifup_force_detect);
> +
> +	return 0;
> +}
> +late_initcall(ifup_all_init);
> +
> +BAREBOX_MAGICVAR_NAMED(global_net_ifup_force_detect,
> +                       global.net.ifup_force_detect,
> +                       "net: force detection of devices on ifup -a");
> +
>  #if IS_ENABLED(CONFIG_NET_CMD_IFUP)
>  
>  static int do_ifup(int argc, char *argv[])

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

end of thread, other threads:[~2018-04-12  8:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-06 13:16 [PATCH] net: on ifup -a only detect devices when necessary Sascha Hauer
2018-04-06 19:33 ` Lucas Stach
2018-04-09  6:51   ` Sascha Hauer
2018-04-12  8:53 ` Michael Tretter

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