Module Name:    src
Committed By:   martin
Date:           Wed May 18 16:39:03 UTC 2022

Modified Files:
        src/usr.sbin/sysinst: configmenu.c defs.h menus.mi msg.mi.de msg.mi.en
            msg.mi.es msg.mi.fr msg.mi.pl net.c util.c

Log Message:
When not invoked via some explicit "configure network" menu item,
auto-detect an already working network setup and offer to "just use" it
whenver we need connectivity.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/usr.sbin/sysinst/configmenu.c
cvs rdiff -u -r1.81 -r1.82 src/usr.sbin/sysinst/defs.h
cvs rdiff -u -r1.24 -r1.25 src/usr.sbin/sysinst/menus.mi
cvs rdiff -u -r1.37 -r1.38 src/usr.sbin/sysinst/msg.mi.de
cvs rdiff -u -r1.40 -r1.41 src/usr.sbin/sysinst/msg.mi.en
cvs rdiff -u -r1.33 -r1.34 src/usr.sbin/sysinst/msg.mi.es
cvs rdiff -u -r1.38 -r1.39 src/usr.sbin/sysinst/msg.mi.fr
cvs rdiff -u -r1.39 -r1.40 src/usr.sbin/sysinst/msg.mi.pl
cvs rdiff -u -r1.42 -r1.43 src/usr.sbin/sysinst/net.c
cvs rdiff -u -r1.66 -r1.67 src/usr.sbin/sysinst/util.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/sysinst/configmenu.c
diff -u src/usr.sbin/sysinst/configmenu.c:1.16 src/usr.sbin/sysinst/configmenu.c:1.17
--- src/usr.sbin/sysinst/configmenu.c:1.16	Sun May 15 16:38:25 2022
+++ src/usr.sbin/sysinst/configmenu.c	Wed May 18 16:39:03 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: configmenu.c,v 1.16 2022/05/15 16:38:25 jmcneill Exp $ */
+/* $NetBSD: configmenu.c,v 1.17 2022/05/18 16:39:03 martin Exp $ */
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -230,7 +230,7 @@ static int
 set_network(struct menudesc *menu, void *arg)
 {
 	network_up = 0;
-	if (config_network())
+	if (config_network(1))
 		mnt_net_config();
 	return 0;
 }

Index: src/usr.sbin/sysinst/defs.h
diff -u src/usr.sbin/sysinst/defs.h:1.81 src/usr.sbin/sysinst/defs.h:1.82
--- src/usr.sbin/sysinst/defs.h:1.81	Thu Apr 21 17:30:15 2022
+++ src/usr.sbin/sysinst/defs.h	Wed May 18 16:39:03 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: defs.h,v 1.81 2022/04/21 17:30:15 martin Exp $	*/
+/*	$NetBSD: defs.h,v 1.82 2022/05/18 16:39:03 martin Exp $	*/
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -789,7 +789,7 @@ extern int network_up;
 extern char net_namesvr[STRSIZE];
 int	get_via_ftp(unsigned int);
 int	get_via_nfs(void);
-int	config_network(void);
+int	config_network(int force);
 void	mnt_net_config(void);
 void	make_url(char *, struct ftpinfo *, const char *);
 int	get_pkgsrc(void);

Index: src/usr.sbin/sysinst/menus.mi
diff -u src/usr.sbin/sysinst/menus.mi:1.24 src/usr.sbin/sysinst/menus.mi:1.25
--- src/usr.sbin/sysinst/menus.mi:1.24	Wed Nov  4 14:29:40 2020
+++ src/usr.sbin/sysinst/menus.mi	Wed May 18 16:39:03 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: menus.mi,v 1.24 2020/11/04 14:29:40 martin Exp $	*/
+/*	$NetBSD: menus.mi,v 1.25 2022/05/18 16:39:03 martin Exp $	*/
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -277,7 +277,7 @@ menu utility, title MSG_NetBSD_VERSION_U
 		action {
 			extern int network_up;
 			network_up = 0;
-			config_network();
+			config_network(1);
 		};
 	option MSG_Partition_a_disk,
 		action {
@@ -407,7 +407,7 @@ menu ftpsource, y=-4, x=0, w=70, no box,
 		action {
 			extern int network_up;
 			network_up = 0;
-			config_network();
+			config_network(1);
 		};
 	option MSG_exit_menu_generic, exit, action { ((arg_rv*)arg)->rv = SET_RETRY; };
 
@@ -428,7 +428,7 @@ menu nfssource, y=-4, x=0, w=70, no box,
 		action {
 			extern int network_up;
 			network_up = 0;
-			config_network();
+			config_network(1);
 		};
 	option MSG_exit_menu_generic, exit, action { *((int*)arg) = SET_RETRY; };
 
@@ -593,7 +593,7 @@ menu binpkg, y=-4, x=0, w=70, no box, no
 		action {
 			extern int network_up;
 			network_up = 0;
-			config_network();
+			config_network(1);
 			mnt_net_config();
 		};
 	option {src_legend(menu, MSG_transfer_method, url_proto(pkg.xfer));},

Index: src/usr.sbin/sysinst/msg.mi.de
diff -u src/usr.sbin/sysinst/msg.mi.de:1.37 src/usr.sbin/sysinst/msg.mi.de:1.38
--- src/usr.sbin/sysinst/msg.mi.de:1.37	Mon May 16 18:44:38 2022
+++ src/usr.sbin/sysinst/msg.mi.de	Wed May 18 16:39:03 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg.mi.de,v 1.37 2022/05/16 18:44:38 martin Exp $	*/
+/*	$NetBSD: msg.mi.de,v 1.38 2022/05/18 16:39:03 martin Exp $	*/
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -1556,3 +1556,8 @@ message clone_target_hdr
 message clone_target_disp		{duplizierte Partition(en)}
 message clone_src_done
 {Quellauswahl OK, weiter mit der Zielauswahl}
+
+message network_ok
+{Ihr Netzwerk scheint bereits zu funktionieren. 
+Möchten Sie die Konfiguration überspringen 
+und die bisherigen Einstellungen verwenden?}

Index: src/usr.sbin/sysinst/msg.mi.en
diff -u src/usr.sbin/sysinst/msg.mi.en:1.40 src/usr.sbin/sysinst/msg.mi.en:1.41
--- src/usr.sbin/sysinst/msg.mi.en:1.40	Mon May 16 18:44:38 2022
+++ src/usr.sbin/sysinst/msg.mi.en	Wed May 18 16:39:03 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg.mi.en,v 1.40 2022/05/16 18:44:38 martin Exp $	*/
+/*	$NetBSD: msg.mi.en,v 1.41 2022/05/18 16:39:03 martin Exp $	*/
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -1493,3 +1493,8 @@ message clone_target_hdr
 message clone_target_disp		{cloned partition(s)}
 message clone_src_done
 {Source selection OK, proceed to target selection}
+
+message network_ok
+{Your network seems to work fine. 
+Should we skip the configuration 
+and just use the network as-is?}

Index: src/usr.sbin/sysinst/msg.mi.es
diff -u src/usr.sbin/sysinst/msg.mi.es:1.33 src/usr.sbin/sysinst/msg.mi.es:1.34
--- src/usr.sbin/sysinst/msg.mi.es:1.33	Mon May 16 18:44:38 2022
+++ src/usr.sbin/sysinst/msg.mi.es	Wed May 18 16:39:03 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg.mi.es,v 1.33 2022/05/16 18:44:38 martin Exp $	*/
+/*	$NetBSD: msg.mi.es,v 1.34 2022/05/18 16:39:03 martin Exp $	*/
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -1541,3 +1541,8 @@ message clone_target_hdr
 message clone_target_disp		{cloned partition(s)}
 message clone_src_done
 {Source selection OK, proceed to target selection}
+
+message network_ok
+{Your network seems to work fine. 
+Should we skip the configuration 
+and just use the network as-is?}

Index: src/usr.sbin/sysinst/msg.mi.fr
diff -u src/usr.sbin/sysinst/msg.mi.fr:1.38 src/usr.sbin/sysinst/msg.mi.fr:1.39
--- src/usr.sbin/sysinst/msg.mi.fr:1.38	Mon May 16 18:44:38 2022
+++ src/usr.sbin/sysinst/msg.mi.fr	Wed May 18 16:39:03 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg.mi.fr,v 1.38 2022/05/16 18:44:38 martin Exp $	*/
+/*	$NetBSD: msg.mi.fr,v 1.39 2022/05/18 16:39:03 martin Exp $	*/
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -1572,3 +1572,8 @@ message clone_target_hdr
 message clone_target_disp		{cloned partition(s)}
 message clone_src_done
 {Source selection OK, proceed to target selection}
+
+message network_ok
+{Your network seems to work fine. 
+Should we skip the configuration 
+and just use the network as-is?}

Index: src/usr.sbin/sysinst/msg.mi.pl
diff -u src/usr.sbin/sysinst/msg.mi.pl:1.39 src/usr.sbin/sysinst/msg.mi.pl:1.40
--- src/usr.sbin/sysinst/msg.mi.pl:1.39	Mon May 16 18:44:38 2022
+++ src/usr.sbin/sysinst/msg.mi.pl	Wed May 18 16:39:03 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: msg.mi.pl,v 1.39 2022/05/16 18:44:38 martin Exp $	*/
+/*	$NetBSD: msg.mi.pl,v 1.40 2022/05/18 16:39:03 martin Exp $	*/
 /*	Based on english version: */
 /*	NetBSD: msg.mi.pl,v 1.36 2004/04/17 18:55:35 atatat Exp       */
 
@@ -1478,3 +1478,8 @@ message clone_target_hdr
 message clone_target_disp		{cloned partition(s)}
 message clone_src_done
 {Source selection OK, proceed to target selection}
+
+message network_ok
+{Your network seems to work fine. 
+Should we skip the configuration 
+and just use the network as-is?}

Index: src/usr.sbin/sysinst/net.c
diff -u src/usr.sbin/sysinst/net.c:1.42 src/usr.sbin/sysinst/net.c:1.43
--- src/usr.sbin/sysinst/net.c:1.42	Sun May 15 17:42:32 2022
+++ src/usr.sbin/sysinst/net.c	Wed May 18 16:39:03 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: net.c,v 1.42 2022/05/15 17:42:32 jmcneill Exp $	*/
+/*	$NetBSD: net.c,v 1.43 2022/05/18 16:39:03 martin Exp $	*/
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -48,6 +48,10 @@
 #include <net/if_media.h>
 #include <netinet/in.h>
 #include <net80211/ieee80211_ioctl.h>
+#include <netinet/ip_var.h>
+#ifdef INET6
+#include <netinet6/ip6_var.h>
+#endif
 
 #include <err.h>
 #include <stdio.h>
@@ -225,6 +229,50 @@ static const char *ignored_if_names[] = 
 	NULL,
 };
 
+static bool
+have_working_ipv4(void)
+{
+	uint64_t ipstats[IP_NSTATS];
+	size_t size = sizeof(ipstats);
+
+	/* At least some packets delivered to upper layers? */
+	if (sysctlbyname("net.inet.ip.stats", ipstats, &size, NULL, 0) == -1)
+		return false;
+	if (ipstats[IP_STAT_DELIVERED] < 10)	/* arbitrary threshold */
+		return false;
+
+	/* do we have a default route? */
+	if (run_program(RUN_SILENT|RUN_ERROR_OK,
+	    "/sbin/route  get -inet default") != 0)
+		return false;
+
+	return true;
+}
+
+#ifdef INET6
+static bool
+have_working_ipv6(void)
+{
+	uint64_t ipstats[IP6_NSTATS];
+	size_t size = sizeof(ipstats);
+
+	/* At least some packets delivered to upper layers? */
+	if (sysctlbyname("net.inet6.ip6.stats", ipstats, &size, NULL, 0) == -1)
+		return false;
+	if (ipstats[IP6_STAT_DELIVERED] < 10)	/* arbitrary threshold */
+		return false;
+
+	/* do we have a default route? */
+	if (run_program(RUN_SILENT|RUN_ERROR_OK,
+	    "/sbin/route  get -inet6 default") != 0)
+		return false;
+
+	return true;
+}
+#else
+#define	have_working_ipv6()	false
+#endif
+
 static int
 get_ifconfig_info(struct net_desc *devs)
 {
@@ -483,7 +531,7 @@ handle_license(const char *dev)
  * make sure both the gateway and the name server are up.
  */
 int
-config_network(void)
+config_network(int force)
 {
 	char *textbuf;
 	int  octet0;
@@ -519,6 +567,13 @@ config_network(void)
 		return -1;
 	}
 
+	if (!force && (have_working_ipv4() || have_working_ipv6())) {
+		if (ask_yesno(MSG_network_ok)) {
+			network_up = 1;
+			return 1;
+		}
+	}
+
 	net_menu = calloc(num_devs, sizeof(*net_menu));
 	if (net_menu == NULL) {
 		err_msg_win(err_outofmem);
@@ -972,6 +1027,9 @@ get_via_ftp(unsigned int xfer)
 {
 	arg_rv arg;
 
+	if (!network_up)
+		config_network(0);
+
 	arg.rv = -1;
 	arg.arg = (void*)(uintptr_t)(xfer);
 	process_menu(MENU_ftpsource, &arg);

Index: src/usr.sbin/sysinst/util.c
diff -u src/usr.sbin/sysinst/util.c:1.66 src/usr.sbin/sysinst/util.c:1.67
--- src/usr.sbin/sysinst/util.c:1.66	Thu Apr 21 17:30:15 2022
+++ src/usr.sbin/sysinst/util.c	Wed May 18 16:39:03 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: util.c,v 1.66 2022/04/21 17:30:15 martin Exp $	*/
+/*	$NetBSD: util.c,v 1.67 2022/05/18 16:39:03 martin Exp $	*/
 
 /*
  * Copyright 1997 Piermont Information Systems Inc.
@@ -1225,7 +1225,7 @@ entropy_get_file(bool use_netbsd_seed, c
 	case 2:
 #ifndef DEBUG
 		if (!network_up)
-			config_network();
+			config_network(0);
 #endif
 		server.xfer = rv == 1 ? XFER_HTTP : XFER_FTP;
 		arg.arg = &server;
@@ -1251,7 +1251,7 @@ entropy_get_file(bool use_netbsd_seed, c
 	case 3:
 #ifndef DEBUG
 		if (!network_up)
-			config_network();
+			config_network(0);
 #endif
 		rv = -1;
 		msg_display_add_subst(MSG_entropy_via_nfs, 1, file_desc);

Reply via email to