Fri Mar 1 23:50:28 2024 UTC (94d)
netinet6: Avoid NPD on `ifconfig ifN inet6 ... pltime 0 vltime 0'.

PR kern/53922


(riastradh)
diff -r1.291 -r1.292 src/sys/netinet6/in6.c

cvs diff -r1.291 -r1.292 src/sys/netinet6/in6.c (expand / switch to unified diff)

--- src/sys/netinet6/in6.c 2023/12/09 15:21:02 1.291
+++ src/sys/netinet6/in6.c 2024/03/01 23:50:27 1.292
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: in6.c,v 1.291 2023/12/09 15:21:02 pgoyette Exp $ */ 1/* $NetBSD: in6.c,v 1.292 2024/03/01 23:50:27 riastradh Exp $ */
2/* $KAME: in6.c,v 1.198 2001/07/18 09:12:38 itojun Exp $ */ 2/* $KAME: in6.c,v 1.198 2001/07/18 09:12:38 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
@@ -52,27 +52,27 @@ @@ -52,27 +52,27 @@
52 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 52 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
53 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 53 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59 * SUCH DAMAGE. 59 * SUCH DAMAGE.
60 * 60 *
61 * @(#)in.c 8.2 (Berkeley) 11/15/93 61 * @(#)in.c 8.2 (Berkeley) 11/15/93
62 */ 62 */
63 63
64#include <sys/cdefs.h> 64#include <sys/cdefs.h>
65__KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.291 2023/12/09 15:21:02 pgoyette Exp $"); 65__KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.292 2024/03/01 23:50:27 riastradh Exp $");
66 66
67#ifdef _KERNEL_OPT 67#ifdef _KERNEL_OPT
68#include "opt_inet.h" 68#include "opt_inet.h"
69#include "opt_compat_netbsd.h" 69#include "opt_compat_netbsd.h"
70#include "opt_net_mpsafe.h" 70#include "opt_net_mpsafe.h"
71#endif 71#endif
72 72
73#include <sys/param.h> 73#include <sys/param.h>
74#include <sys/ioctl.h> 74#include <sys/ioctl.h>
75#include <sys/errno.h> 75#include <sys/errno.h>
76#include <sys/malloc.h> 76#include <sys/malloc.h>
77#include <sys/socket.h> 77#include <sys/socket.h>
78#include <sys/socketvar.h> 78#include <sys/socketvar.h>
@@ -716,27 +716,34 @@ in6_control1(struct socket *so, u_long c @@ -716,27 +716,34 @@ in6_control1(struct socket *so, u_long c
716 lt = &ifra->ifra_lifetime; 716 lt = &ifra->ifra_lifetime;
717 if (lt->ia6t_expire != 0) 717 if (lt->ia6t_expire != 0)
718 lt->ia6t_expire = time_wall_to_mono(lt->ia6t_expire); 718 lt->ia6t_expire = time_wall_to_mono(lt->ia6t_expire);
719 if (lt->ia6t_preferred != 0) 719 if (lt->ia6t_preferred != 0)
720 lt->ia6t_preferred = 720 lt->ia6t_preferred =
721 time_wall_to_mono(lt->ia6t_preferred); 721 time_wall_to_mono(lt->ia6t_preferred);
722 /* 722 /*
723 * make (ia == NULL) or update (ia != NULL) the interface 723 * make (ia == NULL) or update (ia != NULL) the interface
724 * address structure, and link it to the list. 724 * address structure, and link it to the list.
725 */ 725 */
726 int s = splsoftnet(); 726 int s = splsoftnet();
727 error = in6_update_ifa1(ifp, ifra, &ia, &psref, 0); 727 error = in6_update_ifa1(ifp, ifra, &ia, &psref, 0);
728 splx(s); 728 splx(s);
729 if (error) 729 /*
 730 * in6_update_ifa1 doesn't create the address if its
 731 * valid lifetime (vltime) is zero, since we would just
 732 * delete the address immediately in that case anyway.
 733 * So it may succeed but return null ia. In that case,
 734 * nothing left to do.
 735 */
 736 if (error || ia == NULL)
730 break; 737 break;
731 pfil_run_addrhooks(if_pfil, cmd, &ia->ia_ifa); 738 pfil_run_addrhooks(if_pfil, cmd, &ia->ia_ifa);
732 break; 739 break;
733 } 740 }
734 741
735 case SIOCDIFADDR_IN6: 742 case SIOCDIFADDR_IN6:
736 ia6_release(ia, &psref); 743 ia6_release(ia, &psref);
737 ifaref(&ia->ia_ifa); 744 ifaref(&ia->ia_ifa);
738 in6_purgeaddr(&ia->ia_ifa); 745 in6_purgeaddr(&ia->ia_ifa);
739 pfil_run_addrhooks(if_pfil, cmd, &ia->ia_ifa); 746 pfil_run_addrhooks(if_pfil, cmd, &ia->ia_ifa);
740 ifafree(&ia->ia_ifa); 747 ifafree(&ia->ia_ifa);
741 ia = NULL; 748 ia = NULL;
742 break; 749 break;