Wed Jan 4 19:37:14 2017 UTC ()
- kill NULL argument from in6_update_ifa
- amend in6_update_ifa1 to return the ia, so that we can use it in pfil hooks
  to avoid NULL pointer crash.


(christos)
diff -r1.229 -r1.230 src/sys/netinet6/in6.c
diff -r1.108 -r1.109 src/sys/netinet6/in6_ifattach.c
diff -r1.87 -r1.88 src/sys/netinet6/in6_var.h
diff -r1.128 -r1.129 src/sys/netinet6/nd6_rtr.c

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

--- src/sys/netinet6/in6.c 2017/01/03 15:14:31 1.229
+++ src/sys/netinet6/in6.c 2017/01/04 19:37:14 1.230
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: in6.c,v 1.229 2017/01/03 15:14:31 christos Exp $ */ 1/* $NetBSD: in6.c,v 1.230 2017/01/04 19:37:14 christos 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.229 2017/01/03 15:14:31 christos Exp $"); 65__KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.230 2017/01/04 19:37:14 christos 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>
@@ -143,26 +143,28 @@ const struct in6_addr in6mask128 = IN6MA @@ -143,26 +143,28 @@ const struct in6_addr in6mask128 = IN6MA
143const struct sockaddr_in6 sa6_any = {sizeof(sa6_any), AF_INET6, 143const struct sockaddr_in6 sa6_any = {sizeof(sa6_any), AF_INET6,
144 0, 0, IN6ADDR_ANY_INIT, 0}; 144 0, 0, IN6ADDR_ANY_INIT, 0};
145 145
146struct pslist_head in6_ifaddr_list; 146struct pslist_head in6_ifaddr_list;
147kmutex_t in6_ifaddr_lock; 147kmutex_t in6_ifaddr_lock;
148 148
149static int in6_lifaddr_ioctl(struct socket *, u_long, void *, 149static int in6_lifaddr_ioctl(struct socket *, u_long, void *,
150 struct ifnet *); 150 struct ifnet *);
151static int in6_ifaddprefix(struct in6_ifaddr *); 151static int in6_ifaddprefix(struct in6_ifaddr *);
152static int in6_ifremprefix(struct in6_ifaddr *); 152static int in6_ifremprefix(struct in6_ifaddr *);
153static int in6_ifinit(struct ifnet *, struct in6_ifaddr *, 153static int in6_ifinit(struct ifnet *, struct in6_ifaddr *,
154 const struct sockaddr_in6 *, int); 154 const struct sockaddr_in6 *, int);
155static void in6_unlink_ifa(struct in6_ifaddr *, struct ifnet *); 155static void in6_unlink_ifa(struct in6_ifaddr *, struct ifnet *);
 156static int in6_update_ifa1(struct ifnet *, struct in6_aliasreq *,
 157 struct in6_ifaddr **, struct psref *, int);
156 158
157void 159void
158in6_init(void) 160in6_init(void)
159{ 161{
160 162
161 PSLIST_INIT(&in6_ifaddr_list); 163 PSLIST_INIT(&in6_ifaddr_list);
162 mutex_init(&in6_ifaddr_lock, MUTEX_DEFAULT, IPL_NONE); 164 mutex_init(&in6_ifaddr_lock, MUTEX_DEFAULT, IPL_NONE);
163} 165}
164 166
165/* 167/*
166 * Add ownaddr as loopback rtentry. We previously add the route only if 168 * Add ownaddr as loopback rtentry. We previously add the route only if
167 * necessary (ex. on a p2p link). However, since we now manage addresses 169 * necessary (ex. on a p2p link). However, since we now manage addresses
168 * separately from prefixes, we should always add the route. We can't 170 * separately from prefixes, we should always add the route. We can't
@@ -691,27 +693,30 @@ in6_control1(struct socket *so, u_long c @@ -691,27 +693,30 @@ in6_control1(struct socket *so, u_long c
691 * ia6t_expire and ia6t_preferred won't be used for now, 693 * ia6t_expire and ia6t_preferred won't be used for now,
692 * so just in case. 694 * so just in case.
693 */ 695 */
694 lt = &ifra->ifra_lifetime; 696 lt = &ifra->ifra_lifetime;
695 if (lt->ia6t_expire != 0) 697 if (lt->ia6t_expire != 0)
696 lt->ia6t_expire = time_wall_to_mono(lt->ia6t_expire); 698 lt->ia6t_expire = time_wall_to_mono(lt->ia6t_expire);
697 if (lt->ia6t_preferred != 0) 699 if (lt->ia6t_preferred != 0)
698 lt->ia6t_preferred = 700 lt->ia6t_preferred =
699 time_wall_to_mono(lt->ia6t_preferred); 701 time_wall_to_mono(lt->ia6t_preferred);
700 /* 702 /*
701 * make (ia == NULL) or update (ia != NULL) the interface 703 * make (ia == NULL) or update (ia != NULL) the interface
702 * address structure, and link it to the list. 704 * address structure, and link it to the list.
703 */ 705 */
704 if ((error = in6_update_ifa(ifp, ifra, ia, 0)) != 0) 706 int s = splnet();
 707 error = in6_update_ifa1(ifp, ifra, &ia, &psref, 0);
 708 splx(s);
 709 if (error)
705 break; 710 break;
706 pfil_run_addrhooks(if_pfil, cmd, &ia->ia_ifa); 711 pfil_run_addrhooks(if_pfil, cmd, &ia->ia_ifa);
707 break; 712 break;
708 } 713 }
709 714
710 case SIOCDIFADDR_IN6: 715 case SIOCDIFADDR_IN6:
711 ia6_release(ia, &psref); 716 ia6_release(ia, &psref);
712 ifaref(&ia->ia_ifa); 717 ifaref(&ia->ia_ifa);
713 in6_purgeaddr(&ia->ia_ifa); 718 in6_purgeaddr(&ia->ia_ifa);
714 pfil_run_addrhooks(if_pfil, cmd, &ia->ia_ifa); 719 pfil_run_addrhooks(if_pfil, cmd, &ia->ia_ifa);
715 ifafree(&ia->ia_ifa); 720 ifafree(&ia->ia_ifa);
716 ia = NULL; 721 ia = NULL;
717 break; 722 break;
@@ -769,35 +774,36 @@ in6_control(struct socket *so, u_long cm @@ -769,35 +774,36 @@ in6_control(struct socket *so, u_long cm
769#endif 774#endif
770 splx(s); 775 splx(s);
771 return error; 776 return error;
772} 777}
773 778
774/* 779/*
775 * Update parameters of an IPv6 interface address. 780 * Update parameters of an IPv6 interface address.
776 * If necessary, a new entry is created and linked into address chains. 781 * If necessary, a new entry is created and linked into address chains.
777 * This function is separated from in6_control(). 782 * This function is separated from in6_control().
778 * XXX: should this be performed under splnet()? 783 * XXX: should this be performed under splnet()?
779 */ 784 */
780static int 785static int
781in6_update_ifa1(struct ifnet *ifp, struct in6_aliasreq *ifra, 786in6_update_ifa1(struct ifnet *ifp, struct in6_aliasreq *ifra,
782 struct in6_ifaddr *ia, int flags) 787 struct in6_ifaddr **iap, struct psref *psref, int flags)
783{ 788{
784 int error = 0, hostIsNew = 0, plen = -1; 789 int error = 0, hostIsNew = 0, plen = -1;
785 struct sockaddr_in6 dst6; 790 struct sockaddr_in6 dst6;
786 struct in6_addrlifetime *lt; 791 struct in6_addrlifetime *lt;
787 struct in6_multi_mship *imm; 792 struct in6_multi_mship *imm;
788 struct in6_multi *in6m_sol; 793 struct in6_multi *in6m_sol;
789 struct rtentry *rt; 794 struct rtentry *rt;
790 int dad_delay, was_tentative; 795 int dad_delay, was_tentative;
 796 struct in6_ifaddr *ia = iap ? *iap : NULL;
791 797
792 in6m_sol = NULL; 798 in6m_sol = NULL;
793 799
794 /* Validate parameters */ 800 /* Validate parameters */
795 if (ifp == NULL || ifra == NULL) /* this maybe redundant */ 801 if (ifp == NULL || ifra == NULL) /* this maybe redundant */
796 return EINVAL; 802 return EINVAL;
797 803
798 /* 804 /*
799 * The destination address for a p2p link must have a family 805 * The destination address for a p2p link must have a family
800 * of AF_UNSPEC or AF_INET6. 806 * of AF_UNSPEC or AF_INET6.
801 */ 807 */
802 if ((ifp->if_flags & IFF_POINTOPOINT) != 0 && 808 if ((ifp->if_flags & IFF_POINTOPOINT) != 0 &&
803 ifra->ifra_dstaddr.sin6_family != AF_INET6 && 809 ifra->ifra_dstaddr.sin6_family != AF_INET6 &&
@@ -909,51 +915,51 @@ in6_update_ifa1(struct ifnet *ifp, struc @@ -909,51 +915,51 @@ in6_update_ifa1(struct ifnet *ifp, struc
909 } 915 }
910 916
911 /* 917 /*
912 * If this is a new address, allocate a new ifaddr and link it 918 * If this is a new address, allocate a new ifaddr and link it
913 * into chains. 919 * into chains.
914 */ 920 */
915 if (ia == NULL) { 921 if (ia == NULL) {
916 hostIsNew = 1; 922 hostIsNew = 1;
917 /* 923 /*
918 * When in6_update_ifa() is called in a process of a received 924 * When in6_update_ifa() is called in a process of a received
919 * RA, it is called under an interrupt context. So, we should 925 * RA, it is called under an interrupt context. So, we should
920 * call malloc with M_NOWAIT. 926 * call malloc with M_NOWAIT.
921 */ 927 */
922 ia = (struct in6_ifaddr *) malloc(sizeof(*ia), M_IFADDR, 928 ia = malloc(sizeof(*ia), M_IFADDR, M_NOWAIT|M_ZERO);
923 M_NOWAIT); 
924 if (ia == NULL) 929 if (ia == NULL)
925 return ENOBUFS; 930 return ENOBUFS;
926 memset(ia, 0, sizeof(*ia)); 
927 LIST_INIT(&ia->ia6_memberships); 931 LIST_INIT(&ia->ia6_memberships);
928 /* Initialize the address and masks, and put time stamp */ 932 /* Initialize the address and masks, and put time stamp */
929 ia->ia_ifa.ifa_addr = sin6tosa(&ia->ia_addr); 933 ia->ia_ifa.ifa_addr = sin6tosa(&ia->ia_addr);
930 ia->ia_addr.sin6_family = AF_INET6; 934 ia->ia_addr.sin6_family = AF_INET6;
931 ia->ia_addr.sin6_len = sizeof(ia->ia_addr); 935 ia->ia_addr.sin6_len = sizeof(ia->ia_addr);
932 ia->ia6_createtime = time_uptime; 936 ia->ia6_createtime = time_uptime;
933 if ((ifp->if_flags & (IFF_POINTOPOINT | IFF_LOOPBACK)) != 0) { 937 if ((ifp->if_flags & (IFF_POINTOPOINT | IFF_LOOPBACK)) != 0) {
934 /* 938 /*
935 * XXX: some functions expect that ifa_dstaddr is not 939 * XXX: some functions expect that ifa_dstaddr is not
936 * NULL for p2p interfaces. 940 * NULL for p2p interfaces.
937 */ 941 */
938 ia->ia_ifa.ifa_dstaddr = sin6tosa(&ia->ia_dstaddr); 942 ia->ia_ifa.ifa_dstaddr = sin6tosa(&ia->ia_dstaddr);
939 } else { 943 } else {
940 ia->ia_ifa.ifa_dstaddr = NULL; 944 ia->ia_ifa.ifa_dstaddr = NULL;
941 } 945 }
942 ia->ia_ifa.ifa_netmask = sin6tosa(&ia->ia_prefixmask); 946 ia->ia_ifa.ifa_netmask = sin6tosa(&ia->ia_prefixmask);
943 947
944 ia->ia_ifp = ifp; 948 ia->ia_ifp = ifp;
945 IN6_ADDRLIST_ENTRY_INIT(ia); 949 IN6_ADDRLIST_ENTRY_INIT(ia);
946 ifa_psref_init(&ia->ia_ifa); 950 ifa_psref_init(&ia->ia_ifa);
 951 if (psref)
 952 ia6_acquire(ia, psref);
947 } 953 }
948 954
949 /* update timestamp */ 955 /* update timestamp */
950 ia->ia6_updatetime = time_uptime; 956 ia->ia6_updatetime = time_uptime;
951 957
952 /* set prefix mask */ 958 /* set prefix mask */
953 if (ifra->ifra_prefixmask.sin6_len) { 959 if (ifra->ifra_prefixmask.sin6_len) {
954 if (ia->ia_prefixmask.sin6_len) { 960 if (ia->ia_prefixmask.sin6_len) {
955 /* 961 /*
956 * We prohibit changing the prefix length of an 962 * We prohibit changing the prefix length of an
957 * existing autoconf address, because the operation 963 * existing autoconf address, because the operation
958 * would confuse prefix management. 964 * would confuse prefix management.
959 */ 965 */
@@ -1282,42 +1288,44 @@ in6_update_ifa1(struct ifnet *ifp, struc @@ -1282,42 +1288,44 @@ in6_update_ifa1(struct ifnet *ifp, struc
1282 maxdelay = MAX_RTR_SOLICITATION_DELAY * hz; 1288 maxdelay = MAX_RTR_SOLICITATION_DELAY * hz;
1283 if (maxdelay - mindelay == 0) 1289 if (maxdelay - mindelay == 0)
1284 dad_delay = 0; 1290 dad_delay = 0;
1285 else { 1291 else {
1286 dad_delay = 1292 dad_delay =
1287 (cprng_fast32() % (maxdelay - mindelay)) + 1293 (cprng_fast32() % (maxdelay - mindelay)) +
1288 mindelay; 1294 mindelay;
1289 } 1295 }
1290 } 1296 }
1291 /* +1 ensures callout is always used */ 1297 /* +1 ensures callout is always used */
1292 nd6_dad_start(&ia->ia_ifa, dad_delay + 1); 1298 nd6_dad_start(&ia->ia_ifa, dad_delay + 1);
1293 } 1299 }
1294 1300
 1301 if (iap)
 1302 *iap = ia;
 1303
1295 return 0; 1304 return 0;
1296 1305
1297 cleanup: 1306 cleanup:
1298 in6_purgeaddr(&ia->ia_ifa); 1307 in6_purgeaddr(&ia->ia_ifa);
1299 exit: 1308 exit:
1300 return error; 1309 return error;
1301} 1310}
1302 1311
1303int 1312int
1304in6_update_ifa(struct ifnet *ifp, struct in6_aliasreq *ifra, 1313in6_update_ifa(struct ifnet *ifp, struct in6_aliasreq *ifra, int flags)
1305 struct in6_ifaddr *ia, int flags) 
1306{ 1314{
1307 int rc, s; 1315 int rc, s;
1308 1316
1309 s = splnet(); 1317 s = splnet();
1310 rc = in6_update_ifa1(ifp, ifra, ia, flags); 1318 rc = in6_update_ifa1(ifp, ifra, NULL, NULL, flags);
1311 splx(s); 1319 splx(s);
1312 return rc; 1320 return rc;
1313} 1321}
1314 1322
1315void 1323void
1316in6_purgeaddr(struct ifaddr *ifa) 1324in6_purgeaddr(struct ifaddr *ifa)
1317{ 1325{
1318 struct ifnet *ifp = ifa->ifa_ifp; 1326 struct ifnet *ifp = ifa->ifa_ifp;
1319 struct in6_ifaddr *ia = (struct in6_ifaddr *) ifa; 1327 struct in6_ifaddr *ia = (struct in6_ifaddr *) ifa;
1320 struct in6_multi_mship *imm; 1328 struct in6_multi_mship *imm;
1321 1329
1322 KASSERT(!ifa_held(ifa)); 1330 KASSERT(!ifa_held(ifa));
1323 1331

cvs diff -r1.108 -r1.109 src/sys/netinet6/in6_ifattach.c (expand / switch to unified diff)

--- src/sys/netinet6/in6_ifattach.c 2016/12/19 03:32:54 1.108
+++ src/sys/netinet6/in6_ifattach.c 2017/01/04 19:37:14 1.109
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: in6_ifattach.c,v 1.108 2016/12/19 03:32:54 ozaki-r Exp $ */ 1/* $NetBSD: in6_ifattach.c,v 1.109 2017/01/04 19:37:14 christos Exp $ */
2/* $KAME: in6_ifattach.c,v 1.124 2001/07/18 08:32:51 jinmei Exp $ */ 2/* $KAME: in6_ifattach.c,v 1.124 2001/07/18 08:32:51 jinmei 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: in6_ifattach.c,v 1.108 2016/12/19 03:32:54 ozaki-r Exp $"); 34__KERNEL_RCSID(0, "$NetBSD: in6_ifattach.c,v 1.109 2017/01/04 19:37:14 christos Exp $");
35 35
36#include <sys/param.h> 36#include <sys/param.h>
37#include <sys/systm.h> 37#include <sys/systm.h>
38#include <sys/kmem.h> 38#include <sys/kmem.h>
39#include <sys/socket.h> 39#include <sys/socket.h>
40#include <sys/sockio.h> 40#include <sys/sockio.h>
41#include <sys/kernel.h> 41#include <sys/kernel.h>
42#include <sys/syslog.h> 42#include <sys/syslog.h>
43#include <sys/md5.h> 43#include <sys/md5.h>
44#include <sys/socketvar.h> 44#include <sys/socketvar.h>
45#include <sys/cprng.h> 45#include <sys/cprng.h>
46 46
47#include <net/if.h> 47#include <net/if.h>
@@ -566,28 +566,27 @@ in6_ifattach_linklocal(struct ifnet *ifp @@ -566,28 +566,27 @@ in6_ifattach_linklocal(struct ifnet *ifp
566 return -1; 566 return -1;
567 567
568 sockaddr_in6_init(&ifra.ifra_prefixmask, &in6mask64, 0, 0, 0); 568 sockaddr_in6_init(&ifra.ifra_prefixmask, &in6mask64, 0, 0, 0);
569 /* link-local addresses should NEVER expire. */ 569 /* link-local addresses should NEVER expire. */
570 ifra.ifra_lifetime.ia6t_vltime = ND6_INFINITE_LIFETIME; 570 ifra.ifra_lifetime.ia6t_vltime = ND6_INFINITE_LIFETIME;
571 ifra.ifra_lifetime.ia6t_pltime = ND6_INFINITE_LIFETIME; 571 ifra.ifra_lifetime.ia6t_pltime = ND6_INFINITE_LIFETIME;
572 572
573 /* 573 /*
574 * Now call in6_update_ifa() to do a bunch of procedures to configure 574 * Now call in6_update_ifa() to do a bunch of procedures to configure
575 * a link-local address. We can set the 3rd argument to NULL, because 575 * a link-local address. We can set the 3rd argument to NULL, because
576 * we know there's no other link-local address on the interface 576 * we know there's no other link-local address on the interface
577 * and therefore we are adding one (instead of updating one). 577 * and therefore we are adding one (instead of updating one).
578 */ 578 */
579 if ((error = in6_update_ifa(ifp, &ifra, NULL, 579 if ((error = in6_update_ifa(ifp, &ifra, IN6_IFAUPDATE_DADDELAY)) != 0) {
580 IN6_IFAUPDATE_DADDELAY)) != 0) { 
581 /* 580 /*
582 * XXX: When the interface does not support IPv6, this call 581 * XXX: When the interface does not support IPv6, this call
583 * would fail in the SIOCINITIFADDR ioctl. I believe the 582 * would fail in the SIOCINITIFADDR ioctl. I believe the
584 * notification is rather confusing in this case, so just 583 * notification is rather confusing in this case, so just
585 * suppress it. (jinmei@kame.net 20010130) 584 * suppress it. (jinmei@kame.net 20010130)
586 */ 585 */
587 if (error != EAFNOSUPPORT) 586 if (error != EAFNOSUPPORT)
588 nd6log(LOG_NOTICE, 587 nd6log(LOG_NOTICE,
589 "failed to configure a link-local address on %s " 588 "failed to configure a link-local address on %s "
590 "(errno=%d)\n", 589 "(errno=%d)\n",
591 if_name(ifp), error); 590 if_name(ifp), error);
592 return -1; 591 return -1;
593 } 592 }
@@ -624,27 +623,27 @@ in6_ifattach_loopback(struct ifnet *ifp) @@ -624,27 +623,27 @@ in6_ifattach_loopback(struct ifnet *ifp)
624 sockaddr_in6_init(&ifra.ifra_addr, &in6addr_loopback, 0, 0, 0); 623 sockaddr_in6_init(&ifra.ifra_addr, &in6addr_loopback, 0, 0, 0);
625 624
626 /* the loopback address should NEVER expire. */ 625 /* the loopback address should NEVER expire. */
627 ifra.ifra_lifetime.ia6t_vltime = ND6_INFINITE_LIFETIME; 626 ifra.ifra_lifetime.ia6t_vltime = ND6_INFINITE_LIFETIME;
628 ifra.ifra_lifetime.ia6t_pltime = ND6_INFINITE_LIFETIME; 627 ifra.ifra_lifetime.ia6t_pltime = ND6_INFINITE_LIFETIME;
629 628
630 /* we don't need to perform DAD on loopback interfaces. */ 629 /* we don't need to perform DAD on loopback interfaces. */
631 ifra.ifra_flags |= IN6_IFF_NODAD; 630 ifra.ifra_flags |= IN6_IFF_NODAD;
632 631
633 /* 632 /*
634 * We are sure that this is a newly assigned address, so we can set 633 * We are sure that this is a newly assigned address, so we can set
635 * NULL to the 3rd arg. 634 * NULL to the 3rd arg.
636 */ 635 */
637 if ((error = in6_update_ifa(ifp, &ifra, NULL, 0)) != 0) { 636 if ((error = in6_update_ifa(ifp, &ifra, 0)) != 0) {
638 nd6log(LOG_ERR, "failed to configure " 637 nd6log(LOG_ERR, "failed to configure "
639 "the loopback address on %s (errno=%d)\n", 638 "the loopback address on %s (errno=%d)\n",
640 if_name(ifp), error); 639 if_name(ifp), error);
641 return -1; 640 return -1;
642 } 641 }
643 642
644 return 0; 643 return 0;
645} 644}
646 645
647/* 646/*
648 * compute NI group address, based on the current hostname setting. 647 * compute NI group address, based on the current hostname setting.
649 * see draft-ietf-ipngwg-icmp-name-lookup-* (04 and later). 648 * see draft-ietf-ipngwg-icmp-name-lookup-* (04 and later).
650 * 649 *

cvs diff -r1.87 -r1.88 src/sys/netinet6/in6_var.h (expand / switch to unified diff)

--- src/sys/netinet6/in6_var.h 2016/09/14 16:17:17 1.87
+++ src/sys/netinet6/in6_var.h 2017/01/04 19:37:14 1.88
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: in6_var.h,v 1.87 2016/09/14 16:17:17 christos Exp $ */ 1/* $NetBSD: in6_var.h,v 1.88 2017/01/04 19:37:14 christos Exp $ */
2/* $KAME: in6_var.h,v 1.81 2002/06/08 11:16:51 itojun Exp $ */ 2/* $KAME: in6_var.h,v 1.81 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
@@ -773,28 +773,27 @@ do { \ @@ -773,28 +773,27 @@ do { \
773} while (/*CONSTCOND*/ 0) 773} while (/*CONSTCOND*/ 0)
774#endif 774#endif
775 775
776void in6_init(void); 776void in6_init(void);
777 777
778struct in6_multi *in6_addmulti(struct in6_addr *, struct ifnet *, 778struct in6_multi *in6_addmulti(struct in6_addr *, struct ifnet *,
779 int *, int); 779 int *, int);
780void in6_delmulti(struct in6_multi *); 780void in6_delmulti(struct in6_multi *);
781struct in6_multi_mship *in6_joingroup(struct ifnet *, struct in6_addr *, 781struct in6_multi_mship *in6_joingroup(struct ifnet *, struct in6_addr *,
782 int *, int); 782 int *, int);
783int in6_leavegroup(struct in6_multi_mship *); 783int in6_leavegroup(struct in6_multi_mship *);
784int in6_mask2len(struct in6_addr *, u_char *); 784int in6_mask2len(struct in6_addr *, u_char *);
785int in6_control(struct socket *, u_long, void *, struct ifnet *); 785int in6_control(struct socket *, u_long, void *, struct ifnet *);
786int in6_update_ifa(struct ifnet *, struct in6_aliasreq *, 786int in6_update_ifa(struct ifnet *, struct in6_aliasreq *, int);
787 struct in6_ifaddr *, int); 
788void in6_purgeaddr(struct ifaddr *); 787void in6_purgeaddr(struct ifaddr *);
789void in6_purgeif(struct ifnet *); 788void in6_purgeif(struct ifnet *);
790void in6_savemkludge(struct in6_ifaddr *); 789void in6_savemkludge(struct in6_ifaddr *);
791void in6_setmaxmtu (void); 790void in6_setmaxmtu (void);
792int in6_if2idlen (struct ifnet *); 791int in6_if2idlen (struct ifnet *);
793void *in6_domifattach(struct ifnet *); 792void *in6_domifattach(struct ifnet *);
794void in6_domifdetach(struct ifnet *, void *); 793void in6_domifdetach(struct ifnet *, void *);
795void in6_restoremkludge(struct in6_ifaddr *, struct ifnet *); 794void in6_restoremkludge(struct in6_ifaddr *, struct ifnet *);
796void in6_ifremlocal(struct ifaddr *); 795void in6_ifremlocal(struct ifaddr *);
797void in6_ifaddlocal(struct ifaddr *); 796void in6_ifaddlocal(struct ifaddr *);
798void in6_createmkludge(struct ifnet *); 797void in6_createmkludge(struct ifnet *);
799void in6_purgemkludge(struct ifnet *); 798void in6_purgemkludge(struct ifnet *);
800struct in6_ifaddr * 799struct in6_ifaddr *

cvs diff -r1.128 -r1.129 src/sys/netinet6/nd6_rtr.c (expand / switch to unified diff)

--- src/sys/netinet6/nd6_rtr.c 2016/12/19 07:51:34 1.128
+++ src/sys/netinet6/nd6_rtr.c 2017/01/04 19:37:14 1.129
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: nd6_rtr.c,v 1.128 2016/12/19 07:51:34 ozaki-r Exp $ */ 1/* $NetBSD: nd6_rtr.c,v 1.129 2017/01/04 19:37:14 christos Exp $ */
2/* $KAME: nd6_rtr.c,v 1.95 2001/02/07 08:09:47 itojun Exp $ */ 2/* $KAME: nd6_rtr.c,v 1.95 2001/02/07 08:09:47 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_rtr.c,v 1.128 2016/12/19 07:51:34 ozaki-r Exp $"); 34__KERNEL_RCSID(0, "$NetBSD: nd6_rtr.c,v 1.129 2017/01/04 19:37:14 christos Exp $");
35 35
36#include <sys/param.h> 36#include <sys/param.h>
37#include <sys/systm.h> 37#include <sys/systm.h>
38#include <sys/malloc.h> 38#include <sys/malloc.h>
39#include <sys/mbuf.h> 39#include <sys/mbuf.h>
40#include <sys/socket.h> 40#include <sys/socket.h>
41#include <sys/sockio.h> 41#include <sys/sockio.h>
42#include <sys/time.h> 42#include <sys/time.h>
43#include <sys/kernel.h> 43#include <sys/kernel.h>
44#include <sys/errno.h> 44#include <sys/errno.h>
45#include <sys/ioctl.h> 45#include <sys/ioctl.h>
46#include <sys/syslog.h> 46#include <sys/syslog.h>
47#include <sys/cprng.h> 47#include <sys/cprng.h>
@@ -1978,27 +1978,27 @@ in6_ifadd(struct nd_prefixctl *prc, int  @@ -1978,27 +1978,27 @@ in6_ifadd(struct nd_prefixctl *prc, int
1978 return (NULL); 1978 return (NULL);
1979 } 1979 }
1980 pserialize_read_exit(s); 1980 pserialize_read_exit(s);
1981 1981
1982 /* 1982 /*
1983 * Allocate ifaddr structure, link into chain, etc. 1983 * Allocate ifaddr structure, link into chain, etc.
1984 * If we are going to create a new address upon receiving a multicasted 1984 * If we are going to create a new address upon receiving a multicasted
1985 * RA, we need to impose a random delay before starting DAD. 1985 * RA, we need to impose a random delay before starting DAD.
1986 * [draft-ietf-ipv6-rfc2462bis-02.txt, Section 5.4.2] 1986 * [draft-ietf-ipv6-rfc2462bis-02.txt, Section 5.4.2]
1987 */ 1987 */
1988 updateflags = 0; 1988 updateflags = 0;
1989 if (mcast) 1989 if (mcast)
1990 updateflags |= IN6_IFAUPDATE_DADDELAY; 1990 updateflags |= IN6_IFAUPDATE_DADDELAY;
1991 if ((error = in6_update_ifa(ifp, &ifra, NULL, updateflags)) != 0) { 1991 if ((error = in6_update_ifa(ifp, &ifra, updateflags)) != 0) {
1992 nd6log(LOG_ERR, "failed to make ifaddr %s on %s (errno=%d)\n", 1992 nd6log(LOG_ERR, "failed to make ifaddr %s on %s (errno=%d)\n",
1993 ip6_sprintf(&ifra.ifra_addr.sin6_addr), if_name(ifp), 1993 ip6_sprintf(&ifra.ifra_addr.sin6_addr), if_name(ifp),
1994 error); 1994 error);
1995 return (NULL); /* ifaddr must not have been allocated. */ 1995 return (NULL); /* ifaddr must not have been allocated. */
1996 } 1996 }
1997 1997
1998 ia = in6ifa_ifpwithaddr_psref(ifp, &ifra.ifra_addr.sin6_addr, psref); 1998 ia = in6ifa_ifpwithaddr_psref(ifp, &ifra.ifra_addr.sin6_addr, psref);
1999 1999
2000 return (ia); /* this is always non-NULL */ 2000 return (ia); /* this is always non-NULL */
2001} 2001}
2002 2002
2003int 2003int
2004in6_tmpifadd( 2004in6_tmpifadd(
@@ -2099,27 +2099,27 @@ in6_tmpifadd( @@ -2099,27 +2099,27 @@ in6_tmpifadd(
2099 * Lifetime is greater than REGEN_ADVANCE time units. 2099 * Lifetime is greater than REGEN_ADVANCE time units.
2100 */ 2100 */
2101 if (ifra.ifra_lifetime.ia6t_pltime <= ip6_temp_regen_advance) 2101 if (ifra.ifra_lifetime.ia6t_pltime <= ip6_temp_regen_advance)
2102 return (0); 2102 return (0);
2103 2103
2104 /* XXX: scope zone ID? */ 2104 /* XXX: scope zone ID? */
2105 2105
2106 ifra.ifra_flags |= (IN6_IFF_AUTOCONF|IN6_IFF_TEMPORARY); 2106 ifra.ifra_flags |= (IN6_IFF_AUTOCONF|IN6_IFF_TEMPORARY);
2107 2107
2108 /* allocate ifaddr structure, link into chain, etc. */ 2108 /* allocate ifaddr structure, link into chain, etc. */
2109 updateflags = 0; 2109 updateflags = 0;
2110 if (dad_delay) 2110 if (dad_delay)
2111 updateflags |= IN6_IFAUPDATE_DADDELAY; 2111 updateflags |= IN6_IFAUPDATE_DADDELAY;
2112 if ((error = in6_update_ifa(ifp, &ifra, NULL, updateflags)) != 0) 2112 if ((error = in6_update_ifa(ifp, &ifra, updateflags)) != 0)
2113 return (error); 2113 return (error);
2114 2114
2115 s = pserialize_read_enter(); 2115 s = pserialize_read_enter();
2116 newia = in6ifa_ifpwithaddr(ifp, &ifra.ifra_addr.sin6_addr); 2116 newia = in6ifa_ifpwithaddr(ifp, &ifra.ifra_addr.sin6_addr);
2117 if (newia == NULL) { /* XXX: can it happen? */ 2117 if (newia == NULL) { /* XXX: can it happen? */
2118 pserialize_read_exit(s); 2118 pserialize_read_exit(s);
2119 nd6log(LOG_ERR, 2119 nd6log(LOG_ERR,
2120 "ifa update succeeded, but we got no ifaddr\n"); 2120 "ifa update succeeded, but we got no ifaddr\n");
2121 return (EINVAL); /* XXX */ 2121 return (EINVAL); /* XXX */
2122 } 2122 }
2123 newia->ia6_ndpr = ia0->ia6_ndpr; 2123 newia->ia6_ndpr = ia0->ia6_ndpr;
2124 newia->ia6_ndpr->ndpr_refcnt++; 2124 newia->ia6_ndpr->ndpr_refcnt++;
2125 pserialize_read_exit(s); 2125 pserialize_read_exit(s);