Sat Aug 31 01:49:46 2019 UTC ()
inet6: don't set an invalid lladdr in nd6_free()

We don't want to announce that we've deleted a hwaddr of all zeros.


(roy)
diff -r1.260 -r1.261 src/sys/netinet6/nd6.c

cvs diff -r1.260 -r1.261 src/sys/netinet6/nd6.c (expand / switch to unified diff)

--- src/sys/netinet6/nd6.c 2019/08/27 21:11:26 1.260
+++ src/sys/netinet6/nd6.c 2019/08/31 01:49:45 1.261
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: nd6.c,v 1.260 2019/08/27 21:11:26 roy Exp $ */ 1/* $NetBSD: nd6.c,v 1.261 2019/08/31 01:49:45 roy Exp $ */
2/* $KAME: nd6.c,v 1.279 2002/06/08 11:16:51 itojun Exp $ */ 2/* $KAME: nd6.c,v 1.279 2002/06/08 11:16:51 itojun Exp $ */
3 3
4/* 4/*
5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -21,27 +21,27 @@ @@ -21,27 +21,27 @@
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE. 30 * SUCH DAMAGE.
31 */ 31 */
32 32
33#include <sys/cdefs.h> 33#include <sys/cdefs.h>
34__KERNEL_RCSID(0, "$NetBSD: nd6.c,v 1.260 2019/08/27 21:11:26 roy Exp $"); 34__KERNEL_RCSID(0, "$NetBSD: nd6.c,v 1.261 2019/08/31 01:49:45 roy Exp $");
35 35
36#ifdef _KERNEL_OPT 36#ifdef _KERNEL_OPT
37#include "opt_net_mpsafe.h" 37#include "opt_net_mpsafe.h"
38#endif 38#endif
39 39
40#include "bridge.h" 40#include "bridge.h"
41#include "carp.h" 41#include "carp.h"
42 42
43#include <sys/param.h> 43#include <sys/param.h>
44#include <sys/systm.h> 44#include <sys/systm.h>
45#include <sys/callout.h> 45#include <sys/callout.h>
46#include <sys/kmem.h> 46#include <sys/kmem.h>
47#include <sys/mbuf.h> 47#include <sys/mbuf.h>
@@ -1182,26 +1182,27 @@ nd6_is_addr_neighbor(const struct sockad @@ -1182,26 +1182,27 @@ nd6_is_addr_neighbor(const struct sockad
1182 1182
1183/* 1183/*
1184 * Free an nd6 llinfo entry. 1184 * Free an nd6 llinfo entry.
1185 * Since the function would cause significant changes in the kernel, DO NOT 1185 * Since the function would cause significant changes in the kernel, DO NOT
1186 * make it global, unless you have a strong reason for the change, and are sure 1186 * make it global, unless you have a strong reason for the change, and are sure
1187 * that the change is safe. 1187 * that the change is safe.
1188 */ 1188 */
1189static void 1189static void
1190nd6_free(struct llentry *ln, int gc) 1190nd6_free(struct llentry *ln, int gc)
1191{ 1191{
1192 struct ifnet *ifp; 1192 struct ifnet *ifp;
1193 struct in6_addr *in6; 1193 struct in6_addr *in6;
1194 struct sockaddr_in6 sin6; 1194 struct sockaddr_in6 sin6;
 1195 const char *lladdr;
1195 1196
1196 KASSERT(ln != NULL); 1197 KASSERT(ln != NULL);
1197 LLE_WLOCK_ASSERT(ln); 1198 LLE_WLOCK_ASSERT(ln);
1198 1199
1199 ifp = ln->lle_tbl->llt_ifp; 1200 ifp = ln->lle_tbl->llt_ifp;
1200 in6 = &ln->r_l3addr.addr6; 1201 in6 = &ln->r_l3addr.addr6;
1201 /* 1202 /*
1202 * we used to have pfctlinput(PRC_HOSTDEAD) here. 1203 * we used to have pfctlinput(PRC_HOSTDEAD) here.
1203 * even though it is not harmful, it was not really necessary. 1204 * even though it is not harmful, it was not really necessary.
1204 */ 1205 */
1205 1206
1206 if (!ip6_forwarding && ln->ln_router) { 1207 if (!ip6_forwarding && ln->ln_router) {
1207 if (ln->ln_state == ND6_LLINFO_STALE && gc) { 1208 if (ln->ln_state == ND6_LLINFO_STALE && gc) {
@@ -1272,28 +1273,28 @@ nd6_free(struct llentry *ln, int gc) @@ -1272,28 +1273,28 @@ nd6_free(struct llentry *ln, int gc)
1272 /* 1273 /*
1273 * If this entry was added by an on-link redirect, remove the 1274 * If this entry was added by an on-link redirect, remove the
1274 * corresponding host route. 1275 * corresponding host route.
1275 */ 1276 */
1276 if (ln->la_flags & LLE_REDIRECT) 1277 if (ln->la_flags & LLE_REDIRECT)
1277 nd6_free_redirect(ln); 1278 nd6_free_redirect(ln);
1278#endif 1279#endif
1279 1280
1280 ND6_UNLOCK(); 1281 ND6_UNLOCK();
1281 LLE_WLOCK(ln); 1282 LLE_WLOCK(ln);
1282 } 1283 }
1283 1284
1284 sockaddr_in6_init(&sin6, in6, 0, 0, 0); 1285 sockaddr_in6_init(&sin6, in6, 0, 0, 0);
1285 rt_clonedmsg(RTM_DELETE, sin6tosa(&sin6), 1286 lladdr = ln->la_flags & LLE_VALID ? (const char *)&ln->ll_addr : NULL;
1286 (const uint8_t *)&ln->ll_addr, ifp); 1287 rt_clonedmsg(RTM_DELETE, sin6tosa(&sin6), lladdr, ifp);
1287 1288
1288 /* 1289 /*
1289 * Save to unlock. We still hold an extra reference and will not 1290 * Save to unlock. We still hold an extra reference and will not
1290 * free(9) in llentry_free() if someone else holds one as well. 1291 * free(9) in llentry_free() if someone else holds one as well.
1291 */ 1292 */
1292 LLE_WUNLOCK(ln); 1293 LLE_WUNLOCK(ln);
1293 IF_AFDATA_LOCK(ifp); 1294 IF_AFDATA_LOCK(ifp);
1294 LLE_WLOCK(ln); 1295 LLE_WLOCK(ln);
1295 1296
1296 lltable_free_entry(LLTABLE6(ifp), ln); 1297 lltable_free_entry(LLTABLE6(ifp), ln);
1297 1298
1298 IF_AFDATA_UNLOCK(ifp); 1299 IF_AFDATA_UNLOCK(ifp);
1299} 1300}