Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-9]: src Pull up following revision(s) (requested by ozaki-r in ti...



details:   https://anonhg.NetBSD.org/src/rev/cb70d708c0cd
branches:  netbsd-9
changeset: 1001041:cb70d708c0cd
user:      martin <martin%NetBSD.org@localhost>
date:      Wed Oct 23 19:33:07 2019 +0000

description:
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

diffstat:

 sys/netinet6/in6_ifattach.c |  31 +++++++++++++++++++++++++------
 sys/netinet6/in6_ifattach.h |   3 +--
 sys/netinet6/in6_var.h      |   6 ++++--
 sys/netinet6/ip6_input.c    |  45 ++++++++++++++++++++++++++++-----------------
 tests/net/ndp/t_ra.sh       |  11 ++++++++++-
 5 files changed, 68 insertions(+), 28 deletions(-)

diffs (243 lines):

diff -r 28906ca24275 -r cb70d708c0cd sys/netinet6/in6_ifattach.c
--- a/sys/netinet6/in6_ifattach.c       Wed Oct 23 19:28:49 2019 +0000
+++ b/sys/netinet6/in6_ifattach.c       Wed Oct 23 19:33:07 2019 +0000
@@ -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 @@
 
 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 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 @@
 }
 
 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 @@
        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();
diff -r 28906ca24275 -r cb70d708c0cd sys/netinet6/in6_ifattach.h
--- a/sys/netinet6/in6_ifattach.h       Wed Oct 23 19:28:49 2019 +0000
+++ b/sys/netinet6/in6_ifattach.h       Wed Oct 23 19:33:07 2019 +0000
@@ -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 */
diff -r 28906ca24275 -r cb70d708c0cd sys/netinet6/in6_var.h
--- a/sys/netinet6/in6_var.h    Wed Oct 23 19:28:49 2019 +0000
+++ b/sys/netinet6/in6_var.h    Wed Oct 23 19:33:07 2019 +0000
@@ -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 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 @@
 #endif
 
 void   in6_init(void);
+void   in6_tmpaddrtimer_init(void);
 
 void   in6_multi_lock(int);
 void   in6_multi_unlock(void);
@@ -734,6 +734,8 @@
 
 void   in6_sysctl_multicast_setup(struct sysctllog **);
 
+void   in6_tmpaddrtimer_schedule(void);
+
 #endif /* _KERNEL */
 
 #endif /* !_NETINET6_IN6_VAR_H_ */
diff -r 28906ca24275 -r cb70d708c0cd sys/netinet6/ip6_input.c
--- a/sys/netinet6/ip6_input.c  Wed Oct 23 19:28:49 2019 +0000
+++ b/sys/netinet6/ip6_input.c  Wed Oct 23 19:33:07 2019 +0000
@@ -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 *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 @@
        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_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 @@
        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 @@
                       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,
diff -r 28906ca24275 -r cb70d708c0cd tests/net/ndp/t_ra.sh
--- a/tests/net/ndp/t_ra.sh     Wed Oct 23 19:28:49 2019 +0000
+++ b/tests/net/ndp/t_ra.sh     Wed Oct 23 19:33:07 2019 +0000
@@ -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 @@
        # 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



Home | Main Index | Thread Index | Old Index