Module Name:    src
Committed By:   martin
Date:           Wed Oct 23 19:33:07 UTC 2019

Modified Files:
        src/sys/netinet6 [netbsd-9]: in6_ifattach.c in6_ifattach.h in6_var.h
            ip6_input.c
        src/tests/net/ndp [netbsd-9]: t_ra.sh

Log Message:
Pull up following revision(s) (requested by ozaki-r in ticket #368):

        sys/netinet6/in6_ifattach.h: revision 1.14
        sys/netinet6/ip6_input.c: revision 1.212
        sys/netinet6/ip6_input.c: revision 1.213
        sys/netinet6/ip6_input.c: revision 1.214
        sys/netinet6/in6_var.h: revision 1.101
        sys/netinet6/in6_var.h: revision 1.102
        sys/netinet6/in6_ifattach.c: revision 1.116
        sys/netinet6/in6_ifattach.c: revision 1.117
        tests/net/ndp/t_ra.sh: revision 1.33

Reorganize in6_tmpaddrtimer stuffs
- Move the related functions to where in6_tmpaddrtimer_ch exists
- Hide global variable in6_tmpaddrtimer_ch
- Rename ip6_init2 to in6_tmpaddrtimer_init
- Reduce callers of callout_reset
- Use callout_schedule

Validate ip6_temp_preferred_lifetime (net.inet6.ip6.temppltime) on a change
ip6_temp_preferred_lifetime is used to calculate an interval period to
regenerate temporary addresse by
  TEMP_PREFERRED_LIFETIME - REGEN_ADVANCE - DESYNC_FACTOR
as per RFC 3041 3.5.  So it must be greater than (REGEN_ADVANCE +
DESYNC_FACTOR), otherwise it will be negative and go wrong, for example
KASSERT(to_ticks >= 0) in callout_schedule_locked fails.

tests: add tests for the validateion of net.inet6.ip6.temppltime

in6: reset the temporary address timer on a change of the interval period


To generate a diff of this commit:
cvs rdiff -u -r1.115 -r1.115.6.1 src/sys/netinet6/in6_ifattach.c
cvs rdiff -u -r1.13 -r1.13.68.1 src/sys/netinet6/in6_ifattach.h
cvs rdiff -u -r1.100 -r1.100.6.1 src/sys/netinet6/in6_var.h
cvs rdiff -u -r1.208.2.2 -r1.208.2.3 src/sys/netinet6/ip6_input.c
cvs rdiff -u -r1.32 -r1.32.6.1 src/tests/net/ndp/t_ra.sh

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

Modified files:

Index: src/sys/netinet6/in6_ifattach.c
diff -u src/sys/netinet6/in6_ifattach.c:1.115 src/sys/netinet6/in6_ifattach.c:1.115.6.1
--- src/sys/netinet6/in6_ifattach.c:1.115	Tue May  1 07:21:39 2018
+++ src/sys/netinet6/in6_ifattach.c	Wed Oct 23 19:33:07 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: in6_ifattach.c,v 1.115 2018/05/01 07:21:39 maxv Exp $	*/
+/*	$NetBSD: in6_ifattach.c,v 1.115.6.1 2019/10/23 19:33:07 martin Exp $	*/
 /*	$KAME: in6_ifattach.c,v 1.124 2001/07/18 08:32:51 jinmei Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in6_ifattach.c,v 1.115 2018/05/01 07:21:39 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6_ifattach.c,v 1.115.6.1 2019/10/23 19:33:07 martin Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -63,7 +63,7 @@ unsigned long in6_maxmtu = 0;
 
 int ip6_auto_linklocal = 1;	/* enable by default */
 
-callout_t in6_tmpaddrtimer_ch;
+static callout_t in6_tmpaddrtimer_ch;
 
 
 #if 0
@@ -75,6 +75,8 @@ static int get_ifid(struct ifnet *, stru
 static int in6_ifattach_linklocal(struct ifnet *, struct ifnet *);
 static int in6_ifattach_loopback(struct ifnet *);
 
+static void in6_tmpaddrtimer(void *);
+
 #define EUI64_GBIT	0x01
 #define EUI64_UBIT	0x02
 #define EUI64_TO_IFID(in6)	do {(in6)->s6_addr[8] ^= EUI64_UBIT; } while (/*CONSTCOND*/ 0)
@@ -849,6 +851,25 @@ in6_get_tmpifid(struct ifnet *ifp, u_int
 }
 
 void
+in6_tmpaddrtimer_init(void)
+{
+
+	/* timer for regeneration of temporary addresses randomize ID */
+	callout_init(&in6_tmpaddrtimer_ch, CALLOUT_MPSAFE);
+	callout_setfunc(&in6_tmpaddrtimer_ch, in6_tmpaddrtimer, NULL);
+	in6_tmpaddrtimer_schedule();
+}
+
+void
+in6_tmpaddrtimer_schedule(void)
+{
+
+	callout_schedule(&in6_tmpaddrtimer_ch,
+	    (ip6_temp_preferred_lifetime - ip6_desync_factor -
+	    ip6_temp_regen_advance) * hz);
+}
+
+static void
 in6_tmpaddrtimer(void *ignored_arg)
 {
 	struct nd_ifinfo *ndi;
@@ -860,9 +881,7 @@ in6_tmpaddrtimer(void *ignored_arg)
 	mutex_enter(softnet_lock);
 	KERNEL_LOCK(1, NULL);
 
-	callout_reset(&in6_tmpaddrtimer_ch,
-	    (ip6_temp_preferred_lifetime - ip6_desync_factor -
-	    ip6_temp_regen_advance) * hz, in6_tmpaddrtimer, NULL);
+	in6_tmpaddrtimer_schedule();
 
 	memset(nullbuf, 0, sizeof(nullbuf));
 	s = pserialize_read_enter();

Index: src/sys/netinet6/in6_ifattach.h
diff -u src/sys/netinet6/in6_ifattach.h:1.13 src/sys/netinet6/in6_ifattach.h:1.13.68.1
--- src/sys/netinet6/in6_ifattach.h:1.13	Sat Sep 19 13:11:02 2009
+++ src/sys/netinet6/in6_ifattach.h	Wed Oct 23 19:33:07 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: in6_ifattach.h,v 1.13 2009/09/19 13:11:02 christos Exp $	*/
+/*	$NetBSD: in6_ifattach.h,v 1.13.68.1 2019/10/23 19:33:07 martin Exp $	*/
 /*	$KAME: in6_ifattach.h,v 1.8 2000/04/12 03:51:30 itojun Exp $	*/
 
 /*
@@ -37,7 +37,6 @@
 void in6_ifattach(struct ifnet *, struct ifnet *);
 void in6_ifdetach(struct ifnet *);
 int in6_get_tmpifid(struct ifnet *, u_int8_t *, const u_int8_t *, int);
-void in6_tmpaddrtimer(void *);
 int in6_get_hw_ifid(struct ifnet *, struct in6_addr *);
 int in6_nigroup(struct ifnet *, const char *, int, struct sockaddr_in6 *);
 #endif /* _KERNEL */

Index: src/sys/netinet6/in6_var.h
diff -u src/sys/netinet6/in6_var.h:1.100 src/sys/netinet6/in6_var.h:1.100.6.1
--- src/sys/netinet6/in6_var.h:1.100	Tue May 29 04:38:29 2018
+++ src/sys/netinet6/in6_var.h	Wed Oct 23 19:33:07 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: in6_var.h,v 1.100 2018/05/29 04:38:29 ozaki-r Exp $	*/
+/*	$NetBSD: in6_var.h,v 1.100.6.1 2019/10/23 19:33:07 martin Exp $	*/
 /*	$KAME: in6_var.h,v 1.81 2002/06/08 11:16:51 itojun Exp $	*/
 
 /*
@@ -584,7 +584,6 @@ extern const struct in6_addr zeroin6_add
 extern const u_char inet6ctlerrmap[];
 extern unsigned long in6_maxmtu;
 extern bool in6_present;
-extern callout_t in6_tmpaddrtimer_ch;
 
 /*
  * Macro for finding the internet address structure (in6_ifaddr) corresponding
@@ -680,6 +679,7 @@ do {									\
 #endif
 
 void	in6_init(void);
+void	in6_tmpaddrtimer_init(void);
 
 void	in6_multi_lock(int);
 void	in6_multi_unlock(void);
@@ -734,6 +734,8 @@ struct in6pcb;
 
 void	in6_sysctl_multicast_setup(struct sysctllog **);
 
+void	in6_tmpaddrtimer_schedule(void);
+
 #endif /* _KERNEL */
 
 #endif /* !_NETINET6_IN6_VAR_H_ */

Index: src/sys/netinet6/ip6_input.c
diff -u src/sys/netinet6/ip6_input.c:1.208.2.2 src/sys/netinet6/ip6_input.c:1.208.2.3
--- src/sys/netinet6/ip6_input.c:1.208.2.2	Tue Sep 24 03:10:35 2019
+++ src/sys/netinet6/ip6_input.c	Wed Oct 23 19:33:07 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6_input.c,v 1.208.2.2 2019/09/24 03:10:35 martin Exp $	*/
+/*	$NetBSD: ip6_input.c,v 1.208.2.3 2019/10/23 19:33:07 martin Exp $	*/
 /*	$KAME: ip6_input.c,v 1.188 2001/03/29 05:34:31 itojun Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.208.2.2 2019/09/24 03:10:35 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.208.2.3 2019/10/23 19:33:07 martin Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_gateway.h"
@@ -134,7 +134,6 @@ percpu_t *ip6stat_percpu;
 
 percpu_t *ip6_forward_rt_percpu __cacheline_aligned;
 
-static void ip6_init2(void);
 static void ip6intr(void *);
 static bool ip6_badaddr(struct ip6_hdr *);
 static struct m_tag *ip6_setdstifaddr(struct mbuf *, const struct in6_ifaddr *);
@@ -185,7 +184,7 @@ ip6_init(void)
 	frag6_init();
 	ip6_desync_factor = cprng_fast32() % MAX_TEMP_DESYNC_FACTOR;
 
-	ip6_init2();
+	in6_tmpaddrtimer_init();
 #ifdef GATEWAY
 	ip6flow_init(ip6_hashsize);
 #endif
@@ -197,18 +196,6 @@ ip6_init(void)
 	ip6_forward_rt_percpu = rtcache_percpu_alloc();
 }
 
-static void
-ip6_init2(void)
-{
-
-	/* timer for regeneration of temporary addresses randomize ID */
-	callout_init(&in6_tmpaddrtimer_ch, CALLOUT_MPSAFE);
-	callout_reset(&in6_tmpaddrtimer_ch,
-		      (ip6_temp_preferred_lifetime - ip6_desync_factor -
-		       ip6_temp_regen_advance) * hz,
-		      in6_tmpaddrtimer, NULL);
-}
-
 /*
  * IP6 input interrupt handling. Just pass the packet to ip6_input.
  */
@@ -1544,6 +1531,30 @@ sysctl_net_inet6_ip6_stats(SYSCTLFN_ARGS
 	return (NETSTAT_SYSCTL(ip6stat_percpu, IP6_NSTATS));
 }
 
+static int
+sysctl_net_inet6_ip6_temppltime(SYSCTLFN_ARGS)
+{
+	int error;
+	uint32_t pltime;
+	struct sysctlnode node;
+
+	node = *rnode;
+	node.sysctl_data = &pltime;
+	pltime = ip6_temp_preferred_lifetime;
+	error = sysctl_lookup(SYSCTLFN_CALL(&node));
+	if (error || newp == NULL)
+		return error;
+
+	if (pltime <= (MAX_TEMP_DESYNC_FACTOR + TEMPADDR_REGEN_ADVANCE))
+		return EINVAL;
+
+	ip6_temp_preferred_lifetime = pltime;
+
+	in6_tmpaddrtimer_schedule();
+
+	return 0;
+}
+
 static void
 sysctl_net_inet6_ip6_setup(struct sysctllog **clog)
 {
@@ -1755,7 +1766,7 @@ sysctl_net_inet6_ip6_setup(struct sysctl
 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
 		       CTLTYPE_INT, "temppltime",
 		       SYSCTL_DESCR("preferred lifetime of a temporary address"),
-		       NULL, 0, &ip6_temp_preferred_lifetime, 0,
+		       sysctl_net_inet6_ip6_temppltime, 0, NULL, 0,
 		       CTL_NET, PF_INET6, IPPROTO_IPV6,
 		       CTL_CREATE, CTL_EOL);
 	sysctl_createv(clog, 0, NULL, NULL,

Index: src/tests/net/ndp/t_ra.sh
diff -u src/tests/net/ndp/t_ra.sh:1.32 src/tests/net/ndp/t_ra.sh:1.32.6.1
--- src/tests/net/ndp/t_ra.sh:1.32	Sat Nov 25 07:58:47 2017
+++ src/tests/net/ndp/t_ra.sh	Wed Oct 23 19:33:07 2019
@@ -1,4 +1,4 @@
-#	$NetBSD: t_ra.sh,v 1.32 2017/11/25 07:58:47 kre Exp $
+#	$NetBSD: t_ra.sh,v 1.32.6.1 2019/10/23 19:33:07 martin Exp $
 #
 # Copyright (c) 2015 Internet Initiative Japan Inc.
 # All rights reserved.
@@ -695,6 +695,15 @@ ra_temporary_address_body()
 	# autoconf, temporal address should be used as the source address
 	check_echo_request_pkt bus1 $ip_temp $IP6SRV
 
+	#
+	# Testing the validation of net.inet6.ip6.temppltime
+	#
+	# XXX should move to a better place
+	atf_check -s not-exit:0 -e match:'Invalid argument' \
+	    rump.sysctl -w net.inet6.ip6.temppltime=$((600 + 5))
+	atf_check -s exit:0 -o match:'86400 -> 606' \
+	    rump.sysctl -w net.inet6.ip6.temppltime=$((600 + 5 + 1))
+
 	unset RUMP_SERVER
 
 	terminate_rtadvd $PIDFILE

Reply via email to