Mon Mar 6 07:31:15 2017 UTC ()
Make sure icmp_redirect_timeout_q and ip_mtudisc_timeout_q are initialized on bootup

Fix PR kern/52029


(ozaki-r)
diff -r1.159 -r1.160 src/sys/netinet/ip_icmp.c
diff -r1.351 -r1.352 src/sys/netinet/ip_input.c

cvs diff -r1.159 -r1.160 src/sys/netinet/ip_icmp.c (expand / switch to unified diff)

--- src/sys/netinet/ip_icmp.c 2017/02/17 04:32:10 1.159
+++ src/sys/netinet/ip_icmp.c 2017/03/06 07:31:15 1.160
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ip_icmp.c,v 1.159 2017/02/17 04:32:10 ozaki-r Exp $ */ 1/* $NetBSD: ip_icmp.c,v 1.160 2017/03/06 07:31:15 ozaki-r Exp $ */
2 2
3/* 3/*
4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -84,27 +84,27 @@ @@ -84,27 +84,27 @@
84 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 84 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
85 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 85 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
86 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 86 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
87 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 87 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
88 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 88 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
89 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 89 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
90 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 90 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
91 * SUCH DAMAGE. 91 * SUCH DAMAGE.
92 * 92 *
93 * @(#)ip_icmp.c 8.2 (Berkeley) 1/4/94 93 * @(#)ip_icmp.c 8.2 (Berkeley) 1/4/94
94 */ 94 */
95 95
96#include <sys/cdefs.h> 96#include <sys/cdefs.h>
97__KERNEL_RCSID(0, "$NetBSD: ip_icmp.c,v 1.159 2017/02/17 04:32:10 ozaki-r Exp $"); 97__KERNEL_RCSID(0, "$NetBSD: ip_icmp.c,v 1.160 2017/03/06 07:31:15 ozaki-r Exp $");
98 98
99#ifdef _KERNEL_OPT 99#ifdef _KERNEL_OPT
100#include "opt_ipsec.h" 100#include "opt_ipsec.h"
101#endif 101#endif
102 102
103#include <sys/param.h> 103#include <sys/param.h>
104#include <sys/systm.h> 104#include <sys/systm.h>
105#include <sys/mbuf.h> 105#include <sys/mbuf.h>
106#include <sys/protosw.h> 106#include <sys/protosw.h>
107#include <sys/socket.h> 107#include <sys/socket.h>
108#include <sys/socketvar.h> /* For softnet_lock */ 108#include <sys/socketvar.h> /* For softnet_lock */
109#include <sys/kmem.h> 109#include <sys/kmem.h>
110#include <sys/time.h> 110#include <sys/time.h>
@@ -185,30 +185,27 @@ static void _icmp_input(struct mbuf *, i @@ -185,30 +185,27 @@ static void _icmp_input(struct mbuf *, i
185 185
186void 186void
187icmp_init(void) 187icmp_init(void)
188{ 188{
189 189
190 sysctl_netinet_icmp_setup(NULL); 190 sysctl_netinet_icmp_setup(NULL);
191 191
192 mutex_init(&icmp_mtx, MUTEX_DEFAULT, IPL_NONE); 192 mutex_init(&icmp_mtx, MUTEX_DEFAULT, IPL_NONE);
193 /* 193 /*
194 * This is only useful if the user initializes redirtimeout to 194 * This is only useful if the user initializes redirtimeout to
195 * something other than zero. 195 * something other than zero.
196 */ 196 */
197 mutex_enter(&icmp_mtx); 197 mutex_enter(&icmp_mtx);
198 if (icmp_redirtimeout != 0) { 198 icmp_redirect_timeout_q = rt_timer_queue_create(icmp_redirtimeout);
199 icmp_redirect_timeout_q = 
200 rt_timer_queue_create(icmp_redirtimeout); 
201 } 
202 mutex_exit(&icmp_mtx); 199 mutex_exit(&icmp_mtx);
203 200
204 icmpstat_percpu = percpu_alloc(sizeof(uint64_t) * ICMP_NSTATS); 201 icmpstat_percpu = percpu_alloc(sizeof(uint64_t) * ICMP_NSTATS);
205 icmp_wqinput = wqinput_create("icmp", _icmp_input); 202 icmp_wqinput = wqinput_create("icmp", _icmp_input);
206} 203}
207 204
208void 205void
209icmp_mtudisc_lock(void) 206icmp_mtudisc_lock(void)
210{ 207{
211 208
212 mutex_enter(&icmp_mtx); 209 mutex_enter(&icmp_mtx);
213} 210}
214 211
@@ -1195,28 +1192,26 @@ icmp_mtudisc(struct icmp *icp, struct in @@ -1195,28 +1192,26 @@ icmp_mtudisc(struct icmp *icp, struct in
1195 1192
1196 error = rtrequest(RTM_ADD, dst, rt->rt_gateway, NULL, 1193 error = rtrequest(RTM_ADD, dst, rt->rt_gateway, NULL,
1197 RTF_GATEWAY | RTF_HOST | RTF_DYNAMIC, &nrt); 1194 RTF_GATEWAY | RTF_HOST | RTF_DYNAMIC, &nrt);
1198 if (error) { 1195 if (error) {
1199 rt_unref(rt); 1196 rt_unref(rt);
1200 return; 1197 return;
1201 } 1198 }
1202 nrt->rt_rmx = rt->rt_rmx; 1199 nrt->rt_rmx = rt->rt_rmx;
1203 rt_unref(rt); 1200 rt_unref(rt);
1204 rt = nrt; 1201 rt = nrt;
1205 } 1202 }
1206 1203
1207 mutex_enter(&icmp_mtx); 1204 mutex_enter(&icmp_mtx);
1208 if (ip_mtudisc_timeout_q == NULL) 
1209 ip_mtudisc_timeout_q = rt_timer_queue_create(ip_mtudisc_timeout); 
1210 error = rt_timer_add(rt, icmp_mtudisc_timeout, ip_mtudisc_timeout_q); 1205 error = rt_timer_add(rt, icmp_mtudisc_timeout, ip_mtudisc_timeout_q);
1211 mutex_exit(&icmp_mtx); 1206 mutex_exit(&icmp_mtx);
1212 if (error) { 1207 if (error) {
1213 rt_unref(rt); 1208 rt_unref(rt);
1214 return; 1209 return;
1215 } 1210 }
1216 1211
1217 if (mtu == 0) { 1212 if (mtu == 0) {
1218 int i = 0; 1213 int i = 0;
1219 1214
1220 mtu = ntohs(icp->icmp_ip.ip_len); 1215 mtu = ntohs(icp->icmp_ip.ip_len);
1221 /* Some 4.2BSD-based routers incorrectly adjust the ip_len */ 1216 /* Some 4.2BSD-based routers incorrectly adjust the ip_len */
1222 if (mtu > rt->rt_rmx.rmx_mtu && rt->rt_rmx.rmx_mtu != 0) 1217 if (mtu > rt->rt_rmx.rmx_mtu && rt->rt_rmx.rmx_mtu != 0)

cvs diff -r1.351 -r1.352 src/sys/netinet/ip_input.c (expand / switch to unified diff)

--- src/sys/netinet/ip_input.c 2017/02/17 18:09:25 1.351
+++ src/sys/netinet/ip_input.c 2017/03/06 07:31:15 1.352
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ip_input.c,v 1.351 2017/02/17 18:09:25 ozaki-r Exp $ */ 1/* $NetBSD: ip_input.c,v 1.352 2017/03/06 07:31:15 ozaki-r Exp $ */
2 2
3/* 3/*
4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -81,27 +81,27 @@ @@ -81,27 +81,27 @@
81 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 81 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
82 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 82 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
83 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 83 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
84 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 84 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
85 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 85 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
86 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 86 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
87 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 87 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
88 * SUCH DAMAGE. 88 * SUCH DAMAGE.
89 * 89 *
90 * @(#)ip_input.c 8.2 (Berkeley) 1/4/94 90 * @(#)ip_input.c 8.2 (Berkeley) 1/4/94
91 */ 91 */
92 92
93#include <sys/cdefs.h> 93#include <sys/cdefs.h>
94__KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.351 2017/02/17 18:09:25 ozaki-r Exp $"); 94__KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.352 2017/03/06 07:31:15 ozaki-r Exp $");
95 95
96#ifdef _KERNEL_OPT 96#ifdef _KERNEL_OPT
97#include "opt_inet.h" 97#include "opt_inet.h"
98#include "opt_compat_netbsd.h" 98#include "opt_compat_netbsd.h"
99#include "opt_gateway.h" 99#include "opt_gateway.h"
100#include "opt_ipsec.h" 100#include "opt_ipsec.h"
101#include "opt_mrouting.h" 101#include "opt_mrouting.h"
102#include "opt_mbuftrace.h" 102#include "opt_mbuftrace.h"
103#include "opt_inet_csum.h" 103#include "opt_inet_csum.h"
104#include "opt_net_mpsafe.h" 104#include "opt_net_mpsafe.h"
105#endif 105#endif
106 106
107#include "arp.h" 107#include "arp.h"
@@ -343,26 +343,28 @@ ip_init(void) @@ -343,26 +343,28 @@ ip_init(void)
343 inet_pfil_hook = pfil_head_create(PFIL_TYPE_AF, (void *)AF_INET); 343 inet_pfil_hook = pfil_head_create(PFIL_TYPE_AF, (void *)AF_INET);
344 KASSERT(inet_pfil_hook != NULL); 344 KASSERT(inet_pfil_hook != NULL);
345 345
346#ifdef MBUFTRACE 346#ifdef MBUFTRACE
347 MOWNER_ATTACH(&ip_tx_mowner); 347 MOWNER_ATTACH(&ip_tx_mowner);
348 MOWNER_ATTACH(&ip_rx_mowner); 348 MOWNER_ATTACH(&ip_rx_mowner);
349#endif /* MBUFTRACE */ 349#endif /* MBUFTRACE */
350 350
351 ipstat_percpu = percpu_alloc(sizeof(uint64_t) * IP_NSTATS); 351 ipstat_percpu = percpu_alloc(sizeof(uint64_t) * IP_NSTATS);
352 352
353 ipforward_rt_percpu = percpu_alloc(sizeof(struct route)); 353 ipforward_rt_percpu = percpu_alloc(sizeof(struct route));
354 if (ipforward_rt_percpu == NULL) 354 if (ipforward_rt_percpu == NULL)
355 panic("failed to allocate ipforward_rt_percpu"); 355 panic("failed to allocate ipforward_rt_percpu");
 356
 357 ip_mtudisc_timeout_q = rt_timer_queue_create(ip_mtudisc_timeout);
356} 358}
357 359
358static struct in_ifaddr * 360static struct in_ifaddr *
359ip_match_our_address(struct ifnet *ifp, struct ip *ip, int *downmatch) 361ip_match_our_address(struct ifnet *ifp, struct ip *ip, int *downmatch)
360{ 362{
361 struct in_ifaddr *ia = NULL; 363 struct in_ifaddr *ia = NULL;
362 int checkif; 364 int checkif;
363 365
364 /* 366 /*
365 * Enable a consistency check between the destination address 367 * Enable a consistency check between the destination address
366 * and the arrival interface for a unicast packet (the RFC 1122 368 * and the arrival interface for a unicast packet (the RFC 1122
367 * strong ES model) if IP forwarding is disabled and the packet 369 * strong ES model) if IP forwarding is disabled and the packet
368 * is not locally generated. 370 * is not locally generated.