Source-Changes-HG archive

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

[src/trunk]: src/sys/netinet6 Fix PR kern/57037



details:   https://anonhg.NetBSD.org/src/rev/535e181d8206
branches:  trunk
changeset: 371986:535e181d8206
user:      knakahara <knakahara%NetBSD.org@localhost>
date:      Mon Oct 24 01:54:19 2022 +0000

description:
Fix PR kern/57037

Be able to change the behavior sending parameter changing routing messages.
When set net.inet6.ip6.param_rt_msg=0, don't send parameter changing
routing messages.
When set net.inet6.ip6.param_rt_msg=1(default), send parameter changing
routing messages by RTM_NEWADDR.

diffstat:

 share/man/man7/sysctl.7  |   9 +++++++--
 sys/netinet6/in6.c       |  33 +++++++++++++++++++++++++++++++--
 sys/netinet6/in6_proto.c |   5 +++--
 sys/netinet6/ip6_input.c |  12 ++++++++++--
 sys/netinet6/ip6_var.h   |   3 ++-
 5 files changed, 53 insertions(+), 9 deletions(-)

diffs (181 lines):

diff -r 89bc92079a8c -r 535e181d8206 share/man/man7/sysctl.7
--- a/share/man/man7/sysctl.7   Sun Oct 23 23:30:31 2022 +0000
+++ b/share/man/man7/sysctl.7   Mon Oct 24 01:54:19 2022 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: sysctl.7,v 1.161 2022/08/29 09:14:02 knakahara Exp $
+.\"    $NetBSD: sysctl.7,v 1.162 2022/10/24 01:54:19 knakahara Exp $
 .\"
 .\" Copyright (c) 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"    @(#)sysctl.3    8.4 (Berkeley) 5/9/95
 .\"
-.Dd August 29, 2022
+.Dd October 24, 2022
 .Dt SYSCTL 7
 .Os
 .Sh NAME
@@ -1888,6 +1888,7 @@
 .It ip6        maxfragpackets  integer yes
 .It ip6        maxfrags        integer yes
 .It ip6        neighborgcthresh        integer yes
+.It ip6        param_rt_msg    integer yes
 .It ip6        redirect        integer yes
 .It ip6        rr_prune        integer yes
 .It ip6        use_deprecated  integer yes
@@ -2023,6 +2024,10 @@
 Maximum number of entries in neighbor cache per interface.
 Set to negative to disable.
 The default value is 2048.
+.It Li ip6.param_rt_msg
+If set to 0, parameter changing routing message is suppressed.
+If set to 1, parameter changing routing message is sent by RTM_NEWADDR.
+Other values are undefined yet.
 .It Li ip6.redirect
 If set to 1, ICMPv6 redirects may be sent by the node.
 This option is ignored unless the node is routing IP packets,
diff -r 89bc92079a8c -r 535e181d8206 sys/netinet6/in6.c
--- a/sys/netinet6/in6.c        Sun Oct 23 23:30:31 2022 +0000
+++ b/sys/netinet6/in6.c        Mon Oct 24 01:54:19 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: in6.c,v 1.286 2022/09/20 02:23:37 knakahara Exp $      */
+/*     $NetBSD: in6.c,v 1.287 2022/10/24 01:54:19 knakahara Exp $      */
 /*     $KAME: in6.c,v 1.198 2001/07/18 09:12:38 itojun Exp $   */
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.286 2022/09/20 02:23:37 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.287 2022/10/24 01:54:19 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1065,6 +1065,9 @@
        int dad_delay, was_tentative;
        struct in6_ifaddr *ia = iap ? *iap : NULL;
        char ip6buf[INET6_ADDRSTRLEN];
+       bool addrmaskNotChanged = false;
+       bool send_rtm_newaddr = (ip6_param_rt_msg == 1);
+       int saved_flags;
 
        KASSERT((iap == NULL && psref == NULL) ||
            (iap != NULL && psref != NULL));
@@ -1186,6 +1189,21 @@
                        return 0; /* there's nothing to do */
        }
 
+#define sin6eq(a, b) \
+       ((a)->sin6_len == sizeof(struct sockaddr_in6) && \
+        (b)->sin6_len == sizeof(struct sockaddr_in6) && \
+        IN6_ARE_ADDR_EQUAL(&(a)->sin6_addr, &(b)->sin6_addr))
+
+       if (!send_rtm_newaddr) {
+               if (ia != NULL &&
+                   sin6eq(&ifra->ifra_addr, &ia->ia_addr) &&
+                   sin6eq(&ifra->ifra_prefixmask, &ia->ia_prefixmask)) {
+                       addrmaskNotChanged = true;
+                       saved_flags = ia->ia6_flags;  /* check it later */
+               }
+       }
+#undef sin6eq
+
        /*
         * If this is a new address, allocate a new ifaddr and link it
         * into chains.
@@ -1291,6 +1309,17 @@
                ia->ia6_lifetime.ia6t_preferred = time_uptime;
        }
 
+       if (!send_rtm_newaddr) {
+               /*
+                * We will not send RTM_NEWADDR if the only difference between
+                * ia and ifra is preferred/valid lifetimes, because it is not
+                * very useful for userland programs to be notified of that
+                * changes.
+                */
+               if (addrmaskNotChanged && ia->ia6_flags == saved_flags)
+                       return 0;
+       }
+
        if (hostIsNew) {
                /*
                 * We need a reference to ia before calling in6_ifinit.
diff -r 89bc92079a8c -r 535e181d8206 sys/netinet6/in6_proto.c
--- a/sys/netinet6/in6_proto.c  Sun Oct 23 23:30:31 2022 +0000
+++ b/sys/netinet6/in6_proto.c  Mon Oct 24 01:54:19 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: in6_proto.c,v 1.129 2022/09/03 02:53:18 thorpej Exp $  */
+/*     $NetBSD: in6_proto.c,v 1.130 2022/10/24 01:54:19 knakahara Exp $        */
 /*     $KAME: in6_proto.c,v 1.66 2000/10/10 15:35:47 itojun Exp $      */
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in6_proto.c,v 1.129 2022/09/03 02:53:18 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6_proto.c,v 1.130 2022/10/24 01:54:19 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_gateway.h"
@@ -551,6 +551,7 @@
 int ip6_v6only = 1;
 int ip6_neighborgcthresh = 2048; /* Threshold # of NDP entries for GC */
 int ip6_maxdynroutes = 4096; /* Max # of routes created via redirect */
+int ip6_param_rt_msg = 1; /* How to send parmeter changing rtm */
 
 int ip6_keepfaith = 0;
 time_t ip6_log_time = 0;
diff -r 89bc92079a8c -r 535e181d8206 sys/netinet6/ip6_input.c
--- a/sys/netinet6/ip6_input.c  Sun Oct 23 23:30:31 2022 +0000
+++ b/sys/netinet6/ip6_input.c  Mon Oct 24 01:54:19 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ip6_input.c,v 1.225 2022/09/02 03:50:00 thorpej Exp $  */
+/*     $NetBSD: ip6_input.c,v 1.226 2022/10/24 01:54:19 knakahara 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.225 2022/09/02 03:50:00 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.226 2022/10/24 01:54:19 knakahara Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_gateway.h"
@@ -1803,6 +1803,14 @@
                       NULL, 1, &ip6_maxdynroutes, 0,
                       CTL_NET, PF_INET6, IPPROTO_IPV6,
                       CTL_CREATE, CTL_EOL);
+       sysctl_createv(clog, 0, NULL, NULL,
+                      CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
+                      CTLTYPE_INT, "param_rt_msg",
+                      SYSCTL_DESCR("How to send parameter changing"
+                          " routing message"),
+                      NULL, 0, &ip6_param_rt_msg, 0,
+                      CTL_NET, PF_INET6, IPPROTO_IPV6,
+                      CTL_CREATE, CTL_EOL);
 }
 
 void
diff -r 89bc92079a8c -r 535e181d8206 sys/netinet6/ip6_var.h
--- a/sys/netinet6/ip6_var.h    Sun Oct 23 23:30:31 2022 +0000
+++ b/sys/netinet6/ip6_var.h    Mon Oct 24 01:54:19 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ip6_var.h,v 1.91 2021/08/17 22:00:32 andvar Exp $      */
+/*     $NetBSD: ip6_var.h,v 1.92 2022/10/24 01:54:19 knakahara Exp $   */
 /*     $KAME: ip6_var.h,v 1.33 2000/06/11 14:59:20 jinmei Exp $        */
 
 /*
@@ -257,6 +257,7 @@
 extern int     ip6_v6only;
 extern int     ip6_neighborgcthresh;   /* Threshold # of NDP entries for GC */
 extern int     ip6_maxdynroutes; /* Max # of routes created via redirect */
+extern int     ip6_param_rt_msg;  /* How to send parmeter changing rtm */
 
 
 extern struct socket *ip6_mrouter;     /* multicast routing daemon */



Home | Main Index | Thread Index | Old Index