Fri Oct 28 05:26:29 2022 UTC ()
Adjust dccp and sctp for struct inpcb separation


(ozaki-r)
diff -r1.23 -r1.24 src/sys/netinet/dccp_usrreq.c
diff -r1.31 -r1.32 src/sys/netinet/sctp_output.c
diff -r1.6 -r1.7 src/sys/netinet/sctp_pcb.h
diff -r1.13 -r1.14 src/sys/netinet6/dccp6_usrreq.c
diff -r1.22 -r1.23 src/sys/netinet6/sctp6_usrreq.c

cvs diff -r1.23 -r1.24 src/sys/netinet/dccp_usrreq.c (expand / switch to unified diff)

--- src/sys/netinet/dccp_usrreq.c 2022/10/28 05:20:08 1.23
+++ src/sys/netinet/dccp_usrreq.c 2022/10/28 05:26:29 1.24
@@ -1,15 +1,15 @@ @@ -1,15 +1,15 @@
1/* $KAME: dccp_usrreq.c,v 1.67 2005/11/03 16:05:04 nishida Exp $ */ 1/* $KAME: dccp_usrreq.c,v 1.67 2005/11/03 16:05:04 nishida Exp $ */
2/* $NetBSD: dccp_usrreq.c,v 1.23 2022/10/28 05:20:08 ozaki-r Exp $ */ 2/* $NetBSD: dccp_usrreq.c,v 1.24 2022/10/28 05:26:29 ozaki-r Exp $ */
3 3
4/* 4/*
5 * Copyright (c) 2003 Joacim Häggmark, Magnus Erixzon, Nils-Erik Mattsson  5 * Copyright (c) 2003 Joacim Häggmark, Magnus Erixzon, Nils-Erik Mattsson
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 * 11 *
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the 15 * notice, this list of conditions and the following disclaimer in the
@@ -57,27 +57,27 @@ @@ -57,27 +57,27 @@
57 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 57 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64 * SUCH DAMAGE. 64 * SUCH DAMAGE.
65 * 65 *
66 * @(#)udp_usrreq.c 8.6 (Berkeley) 5/23/95 66 * @(#)udp_usrreq.c 8.6 (Berkeley) 5/23/95
67 */ 67 */
68 68
69#include <sys/cdefs.h> 69#include <sys/cdefs.h>
70__KERNEL_RCSID(0, "$NetBSD: dccp_usrreq.c,v 1.23 2022/10/28 05:20:08 ozaki-r Exp $"); 70__KERNEL_RCSID(0, "$NetBSD: dccp_usrreq.c,v 1.24 2022/10/28 05:26:29 ozaki-r Exp $");
71 71
72#ifdef _KERNEL_OPT 72#ifdef _KERNEL_OPT
73#include "opt_inet.h" 73#include "opt_inet.h"
74#include "opt_dccp.h" 74#include "opt_dccp.h"
75#endif 75#endif
76 76
77#include <sys/param.h> 77#include <sys/param.h>
78#include <sys/systm.h> 78#include <sys/systm.h>
79#include <sys/domain.h> 79#include <sys/domain.h>
80#include <sys/kernel.h> 80#include <sys/kernel.h>
81#include <sys/pool.h> 81#include <sys/pool.h>
82#include <sys/lock.h> 82#include <sys/lock.h>
83#include <sys/malloc.h> 83#include <sys/malloc.h>
@@ -433,37 +433,37 @@ dccp_input(struct mbuf *m, int off, int  @@ -433,37 +433,37 @@ dccp_input(struct mbuf *m, int off, int
433 DCCP_DEBUG((LOG_INFO, "Error, sonewconn failed!\n")); 433 DCCP_DEBUG((LOG_INFO, "Error, sonewconn failed!\n"));
434 INP_UNLOCK(inp); 434 INP_UNLOCK(inp);
435 INP_INFO_WUNLOCK(&dccpbinfo); 435 INP_INFO_WUNLOCK(&dccpbinfo);
436 goto badunlocked; 436 goto badunlocked;
437 } 437 }
438 438
439 /* INP_LOCK(inp); XXX */ 439 /* INP_LOCK(inp); XXX */
440 440
441 oinp = inp; 441 oinp = inp;
442 442
443#ifdef INET6 443#ifdef INET6
444 if (isipv6) { 444 if (isipv6) {
445 inp = sotoinpcb(so); 445 inp = sotoinpcb(so);
446 inp->inp_laddr6 = ip6->ip6_dst; 446 in6p_laddr(inp) = ip6->ip6_dst;
447 inp->inp_faddr6 = ip6->ip6_src; 447 in6p_faddr(inp) = ip6->ip6_src;
448 inp->inp_lport = dh->dh_dport; 448 inp->inp_lport = dh->dh_dport;
449 inp->inp_fport = dh->dh_sport; 449 inp->inp_fport = dh->dh_sport;
450 in_pcbstate(inp, INP_CONNECTED); 450 in_pcbstate(inp, INP_CONNECTED);
451 } else  451 } else
452#endif 452#endif
453 { 453 {
454 inp = sotoinpcb(so); 454 inp = sotoinpcb(so);
455 inp->inp_laddr = ip->ip_dst; 455 in4p_laddr(inp) = ip->ip_dst;
456 inp->inp_faddr = ip->ip_src; 456 in4p_faddr(inp) = ip->ip_src;
457 inp->inp_lport = dh->dh_dport; 457 inp->inp_lport = dh->dh_dport;
458 inp->inp_fport = dh->dh_sport; 458 inp->inp_fport = dh->dh_sport;
459 } 459 }
460 460
461 if (!isipv6) 461 if (!isipv6)
462 in_pcbstate(inp, INP_BOUND); 462 in_pcbstate(inp, INP_BOUND);
463 463
464 dp = inp->inp_ppcb; 464 dp = inp->inp_ppcb;
465 465
466 dp->state = DCCPS_LISTEN; 466 dp->state = DCCPS_LISTEN;
467 dp->who = DCCP_SERVER; 467 dp->who = DCCP_SERVER;
468 dp->cslen = ((struct dccpcb *)oinp->inp_ppcb)->cslen; 468 dp->cslen = ((struct dccpcb *)oinp->inp_ppcb)->cslen;
469 dp->avgpsize = ((struct dccpcb *)oinp->inp_ppcb)->avgpsize; 469 dp->avgpsize = ((struct dccpcb *)oinp->inp_ppcb)->avgpsize;
@@ -1343,41 +1343,41 @@ again: @@ -1343,41 +1343,41 @@ again:
1343 error = EMSGSIZE; 1343 error = EMSGSIZE;
1344 goto release; 1344 goto release;
1345 } 1345 }
1346 1346
1347 /* 1347 /*
1348 * Fill in mbuf with extended DCCP header 1348 * Fill in mbuf with extended DCCP header
1349 * and addresses and length put into network format. 1349 * and addresses and length put into network format.
1350 */ 1350 */
1351#ifdef INET6 1351#ifdef INET6
1352 if (isipv6) { 1352 if (isipv6) {
1353 ip6 = mtod(m, struct ip6_hdr *); 1353 ip6 = mtod(m, struct ip6_hdr *);
1354 dh = (struct dccphdr *)(ip6 + 1); 1354 dh = (struct dccphdr *)(ip6 + 1);
1355 ip6->ip6_flow = (ip6->ip6_flow & ~IPV6_FLOWINFO_MASK) | 1355 ip6->ip6_flow = (ip6->ip6_flow & ~IPV6_FLOWINFO_MASK) |
1356 (inp->inp_flowinfo & IPV6_FLOWINFO_MASK); 1356 (in6p_flowinfo(inp) & IPV6_FLOWINFO_MASK);
1357 ip6->ip6_vfc = (ip6->ip6_vfc & ~IPV6_VERSION_MASK) | 1357 ip6->ip6_vfc = (ip6->ip6_vfc & ~IPV6_VERSION_MASK) |
1358 (IPV6_VERSION & IPV6_VERSION_MASK); 1358 (IPV6_VERSION & IPV6_VERSION_MASK);
1359 ip6->ip6_nxt = IPPROTO_DCCP; 1359 ip6->ip6_nxt = IPPROTO_DCCP;
1360 ip6->ip6_src = inp->inp_laddr6; 1360 ip6->ip6_src = in6p_laddr(inp);
1361 ip6->ip6_dst = inp->inp_faddr6; 1361 ip6->ip6_dst = in6p_faddr(inp);
1362 } else  1362 } else
1363#endif 1363#endif
1364 { 1364 {
1365 ip = mtod(m, struct ip *); 1365 ip = mtod(m, struct ip *);
1366 dh = (struct dccphdr *)(ip + 1); 1366 dh = (struct dccphdr *)(ip + 1);
1367 memset(ip, 0, sizeof(struct ip)); 1367 memset(ip, 0, sizeof(struct ip));
1368 ip->ip_p = IPPROTO_DCCP; 1368 ip->ip_p = IPPROTO_DCCP;
1369 ip->ip_src = inp->inp_laddr; 1369 ip->ip_src = in4p_laddr(inp);
1370 ip->ip_dst = inp->inp_faddr; 1370 ip->ip_dst = in4p_faddr(inp);
1371 } 1371 }
1372 dlh = (struct dccplhdr *)dh; 1372 dlh = (struct dccplhdr *)dh;
1373 1373
1374 dh->dh_sport = inp->inp_lport; 1374 dh->dh_sport = inp->inp_lport;
1375 dh->dh_dport = inp->inp_fport; 1375 dh->dh_dport = inp->inp_fport;
1376 dh->dh_cscov = dp->cslen; 1376 dh->dh_cscov = dp->cslen;
1377 dh->dh_ccval = dp->ccval; 1377 dh->dh_ccval = dp->ccval;
1378 dh->dh_type = type; 1378 dh->dh_type = type;
1379 dh->dh_res = 0; /* Reserved field should be zero */ 1379 dh->dh_res = 0; /* Reserved field should be zero */
1380 if (!use_shortseq) {  1380 if (!use_shortseq) {
1381 dlh->dh_res2 = 0; /* Reserved field should be zero */ 1381 dlh->dh_res2 = 0; /* Reserved field should be zero */
1382 dh->dh_off = 4 + (extrah_len / 4) + (optlen / 4); 1382 dh->dh_off = 4 + (extrah_len / 4) + (optlen / 4);
1383 } else  1383 } else
@@ -1497,27 +1497,27 @@ again: @@ -1497,27 +1497,27 @@ again:
1497 cslen); 1497 cslen);
1498#ifndef __OpenBSD__ 1498#ifndef __OpenBSD__
1499 m->m_pkthdr.csum_data = offsetof(struct dccphdr, dh_sum); 1499 m->m_pkthdr.csum_data = offsetof(struct dccphdr, dh_sum);
1500#endif 1500#endif
1501 } 1501 }
1502 1502
1503 dccpstat.dccps_opackets++; 1503 dccpstat.dccps_opackets++;
1504 dccpstat.dccps_obytes += m->m_pkthdr.len; 1504 dccpstat.dccps_obytes += m->m_pkthdr.len;
1505 1505
1506#ifdef INET6 1506#ifdef INET6
1507 if (isipv6) { 1507 if (isipv6) {
1508 DCCP_DEBUG((LOG_INFO, "Calling ip_output6, mbuf->m_len = %u, mbuf->m_pkthdr.len = %u\n", m->m_len, m->m_pkthdr.len)); 1508 DCCP_DEBUG((LOG_INFO, "Calling ip_output6, mbuf->m_len = %u, mbuf->m_pkthdr.len = %u\n", m->m_len, m->m_pkthdr.len));
1509 1509
1510 error = ip6_output(m, inp->inp_outputopts6, &inp->inp_route, 1510 error = ip6_output(m, in6p_outputopts(inp), &inp->inp_route,
1511 (inp->inp_socket->so_options & SO_DONTROUTE), NULL, NULL, 1511 (inp->inp_socket->so_options & SO_DONTROUTE), NULL, NULL,
1512 NULL); 1512 NULL);
1513 } else 1513 } else
1514#endif 1514#endif
1515 { 1515 {
1516 DCCP_DEBUG((LOG_INFO, "Calling ip_output, mbuf->m_len = %u, mbuf->m_pkthdr.len = %u\n", m->m_len, m->m_pkthdr.len)); 1516 DCCP_DEBUG((LOG_INFO, "Calling ip_output, mbuf->m_len = %u, mbuf->m_pkthdr.len = %u\n", m->m_len, m->m_pkthdr.len));
1517 error = ip_output(m, inp->inp_options, &inp->inp_route, 1517 error = ip_output(m, inp->inp_options, &inp->inp_route,
1518 (inp->inp_socket->so_options & SO_DONTROUTE), 0,  1518 (inp->inp_socket->so_options & SO_DONTROUTE), 0,
1519 inp); 1519 inp);
1520 } 1520 }
1521 1521
1522 if (error) { 1522 if (error) {
1523 DCCP_DEBUG((LOG_INFO, "IP output failed! %d\n", error)); 1523 DCCP_DEBUG((LOG_INFO, "IP output failed! %d\n", error));
@@ -1695,27 +1695,27 @@ dccp_connect(struct socket *so, struct s @@ -1695,27 +1695,27 @@ dccp_connect(struct socket *so, struct s
1695 int error; 1695 int error;
1696 struct sockaddr_in *sin; 1696 struct sockaddr_in *sin;
1697 char test[2]; 1697 char test[2];
1698 1698
1699 DCCP_DEBUG((LOG_INFO, "Entering dccp_connect!\n")); 1699 DCCP_DEBUG((LOG_INFO, "Entering dccp_connect!\n"));
1700 1700
1701 INP_INFO_WLOCK(&dccpbinfo); 1701 INP_INFO_WLOCK(&dccpbinfo);
1702 inp = sotoinpcb(so); 1702 inp = sotoinpcb(so);
1703 if (inp == 0) { 1703 if (inp == 0) {
1704 INP_INFO_WUNLOCK(&dccpbinfo); 1704 INP_INFO_WUNLOCK(&dccpbinfo);
1705 return EINVAL; 1705 return EINVAL;
1706 } 1706 }
1707 INP_LOCK(inp); 1707 INP_LOCK(inp);
1708 if (inp->inp_faddr.s_addr != INADDR_ANY) { 1708 if (in4p_faddr(inp).s_addr != INADDR_ANY) {
1709 INP_UNLOCK(inp); 1709 INP_UNLOCK(inp);
1710 INP_INFO_WUNLOCK(&dccpbinfo); 1710 INP_INFO_WUNLOCK(&dccpbinfo);
1711 return EISCONN; 1711 return EISCONN;
1712 } 1712 }
1713 1713
1714 dp = (struct dccpcb *)inp->inp_ppcb; 1714 dp = (struct dccpcb *)inp->inp_ppcb;
1715 1715
1716 if (dp->state == DCCPS_ESTAB) { 1716 if (dp->state == DCCPS_ESTAB) {
1717 DCCP_DEBUG((LOG_INFO, "Why are we in connect when we already have an established connection?\n")); 1717 DCCP_DEBUG((LOG_INFO, "Why are we in connect when we already have an established connection?\n"));
1718 } 1718 }
1719 1719
1720 dp->who = DCCP_CLIENT; 1720 dp->who = DCCP_CLIENT;
1721 dp->seq_snd = (((u_int64_t)random() << 32) | random()) % 281474976710656LL; 1721 dp->seq_snd = (((u_int64_t)random() << 32) | random()) % 281474976710656LL;
@@ -1840,27 +1840,27 @@ dccp_disconnect(struct socket *so) @@ -1840,27 +1840,27 @@ dccp_disconnect(struct socket *so)
1840{ 1840{
1841 struct inpcb *inp; 1841 struct inpcb *inp;
1842 struct dccpcb *dp; 1842 struct dccpcb *dp;
1843 1843
1844 DCCP_DEBUG((LOG_INFO, "Entering dccp_disconnect!\n")); 1844 DCCP_DEBUG((LOG_INFO, "Entering dccp_disconnect!\n"));
1845 INP_INFO_WLOCK(&dccpbinfo); 1845 INP_INFO_WLOCK(&dccpbinfo);
1846#ifndef __NetBSD__ 1846#ifndef __NetBSD__
1847 inp = sotoinpcb(so); 1847 inp = sotoinpcb(so);
1848 if (inp == 0) { 1848 if (inp == 0) {
1849 INP_INFO_WUNLOCK(&dccpbinfo); 1849 INP_INFO_WUNLOCK(&dccpbinfo);
1850 return EINVAL; 1850 return EINVAL;
1851 } 1851 }
1852 INP_LOCK(inp); 1852 INP_LOCK(inp);
1853 if (inp->inp_faddr.s_addr == INADDR_ANY) { 1853 if (in4p_faddr(inp).s_addr == INADDR_ANY) {
1854 INP_INFO_WUNLOCK(&dccpbinfo); 1854 INP_INFO_WUNLOCK(&dccpbinfo);
1855 INP_UNLOCK(inp); 1855 INP_UNLOCK(inp);
1856 return ENOTCONN; 1856 return ENOTCONN;
1857 } 1857 }
1858 1858
1859 dp = (struct dccpcb *)inp->inp_ppcb; 1859 dp = (struct dccpcb *)inp->inp_ppcb;
1860#else /* NetBSD */ 1860#else /* NetBSD */
1861 inp = sotoinpcb(so); 1861 inp = sotoinpcb(so);
1862 if (inp == NULL) { 1862 if (inp == NULL) {
1863 INP_INFO_WUNLOCK(&dccpbinfo); 1863 INP_INFO_WUNLOCK(&dccpbinfo);
1864 return EINVAL; 1864 return EINVAL;
1865 } 1865 }
1866 dp = inp->inp_ppcb; 1866 dp = inp->inp_ppcb;
@@ -2120,30 +2120,30 @@ dccp_newdccpcb(int family, void *aux) @@ -2120,30 +2120,30 @@ dccp_newdccpcb(int family, void *aux)
2120 dp->retrans = 200; 2120 dp->retrans = 200;
2121 dp->avgpsize = 0; 2121 dp->avgpsize = 0;
2122 dp->d_maxseg = 1400; 2122 dp->d_maxseg = 1400;
2123 dp->ref_pseq.hi = 0; 2123 dp->ref_pseq.hi = 0;
2124 dp->ref_pseq.lo = 0; 2124 dp->ref_pseq.lo = 0;
2125 dp->pktlenidx = 0; 2125 dp->pktlenidx = 0;
2126 dp->pktcnt = 0; 2126 dp->pktcnt = 0;
2127 2127
2128 inp = (struct inpcb *)aux; 2128 inp = (struct inpcb *)aux;
2129 dp->d_inpcb = inp; 2129 dp->d_inpcb = inp;
2130 inp->inp_ppcb = dp; 2130 inp->inp_ppcb = dp;
2131 switch (family) { 2131 switch (family) {
2132 case PF_INET: 2132 case PF_INET:
2133 inp->inp_ip.ip_ttl = ip_defttl; 2133 in4p_ip(inp).ip_ttl = ip_defttl;
2134 break; 2134 break;
2135 case PF_INET6: 2135 case PF_INET6:
2136 inp->inp_ip6.ip6_hlim = in6_selecthlim_rt(inp); 2136 in6p_ip6(inp).ip6_hlim = in6_selecthlim_rt(inp);
2137 break; 2137 break;
2138 } 2138 }
2139  2139
2140 if (!dccp_do_feature_nego){ 2140 if (!dccp_do_feature_nego){
2141 dp->cc_state[0] = (*cc_sw[4].cc_send_init)(dp); 2141 dp->cc_state[0] = (*cc_sw[4].cc_send_init)(dp);
2142 dp->cc_state[1] = (*cc_sw[4].cc_recv_init)(dp); 2142 dp->cc_state[1] = (*cc_sw[4].cc_recv_init)(dp);
2143 } 2143 }
2144 2144
2145 return dp; 2145 return dp;
2146} 2146}
2147 2147
2148int 2148int
2149dccp_add_option(struct dccpcb *dp, u_int8_t opt, char *val, u_int8_t val_len) 2149dccp_add_option(struct dccpcb *dp, u_int8_t opt, char *val, u_int8_t val_len)

cvs diff -r1.31 -r1.32 src/sys/netinet/sctp_output.c (expand / switch to unified diff)

--- src/sys/netinet/sctp_output.c 2022/05/31 08:43:16 1.31
+++ src/sys/netinet/sctp_output.c 2022/10/28 05:26:29 1.32
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: sctp_output.c,v 1.31 2022/05/31 08:43:16 andvar Exp $ */ 1/* $NetBSD: sctp_output.c,v 1.32 2022/10/28 05:26:29 ozaki-r Exp $ */
2/* $KAME: sctp_output.c,v 1.48 2005/06/16 18:29:24 jinmei Exp $ */ 2/* $KAME: sctp_output.c,v 1.48 2005/06/16 18:29:24 jinmei Exp $ */
3 3
4/* 4/*
5 * Copyright (C) 2002, 2003, 2004 Cisco Systems Inc, 5 * Copyright (C) 2002, 2003, 2004 Cisco Systems Inc,
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
@@ -20,27 +20,27 @@ @@ -20,27 +20,27 @@
20 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 20 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
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#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33__KERNEL_RCSID(0, "$NetBSD: sctp_output.c,v 1.31 2022/05/31 08:43:16 andvar Exp $"); 33__KERNEL_RCSID(0, "$NetBSD: sctp_output.c,v 1.32 2022/10/28 05:26:29 ozaki-r Exp $");
34 34
35#ifdef _KERNEL_OPT 35#ifdef _KERNEL_OPT
36#include "opt_ipsec.h" 36#include "opt_ipsec.h"
37#include "opt_inet.h" 37#include "opt_inet.h"
38#include "opt_sctp.h" 38#include "opt_sctp.h"
39#endif /* _KERNEL_OPT */ 39#endif /* _KERNEL_OPT */
40 40
41#include <sys/param.h> 41#include <sys/param.h>
42#include <sys/systm.h> 42#include <sys/systm.h>
43#include <sys/malloc.h> 43#include <sys/malloc.h>
44#include <sys/mbuf.h> 44#include <sys/mbuf.h>
45#include <sys/domain.h> 45#include <sys/domain.h>
46#include <sys/protosw.h> 46#include <sys/protosw.h>
@@ -2127,31 +2127,31 @@ sctp_lowlevel_chunk_output(struct sctp_i @@ -2127,31 +2127,31 @@ sctp_lowlevel_chunk_output(struct sctp_i
2127 ip->ip_v = IPVERSION; 2127 ip->ip_v = IPVERSION;
2128 ip->ip_hl = (sizeof(struct ip) >> 2); 2128 ip->ip_hl = (sizeof(struct ip) >> 2);
2129 if (nofragment_flag) { 2129 if (nofragment_flag) {
2130 ip->ip_off = htons(IP_DF); 2130 ip->ip_off = htons(IP_DF);
2131 } else 2131 } else
2132 ip->ip_off = 0; 2132 ip->ip_off = 0;
2133 2133
2134 ip->ip_id = htons(ip_newid(NULL)); 2134 ip->ip_id = htons(ip_newid(NULL));
2135 ip->ip_ttl = inp->inp_ip_ttl; 2135 ip->ip_ttl = inp->inp_ip_ttl;
2136 ip->ip_len = htons(m->m_pkthdr.len); 2136 ip->ip_len = htons(m->m_pkthdr.len);
2137 if (stcb) { 2137 if (stcb) {
2138 if ((stcb->asoc.ecn_allowed) && ecn_ok) { 2138 if ((stcb->asoc.ecn_allowed) && ecn_ok) {
2139 /* Enable ECN */ 2139 /* Enable ECN */
2140 ip->ip_tos = (u_char)((inp->ip_inp.inp.inp_ip.ip_tos & 0x000000fc) | 2140 ip->ip_tos = (u_char)((in4p_ip(&inp->ip_inp.inp).ip_tos & 0x000000fc) |
2141 sctp_get_ect(stcb, chk)); 2141 sctp_get_ect(stcb, chk));
2142 } else { 2142 } else {
2143 /* No ECN */ 2143 /* No ECN */
2144 ip->ip_tos = inp->ip_inp.inp.inp_ip.ip_tos; 2144 ip->ip_tos = in4p_ip(&inp->ip_inp.inp).ip_tos;
2145 } 2145 }
2146 } else { 2146 } else {
2147 /* no association at all */ 2147 /* no association at all */
2148 ip->ip_tos = inp->inp_ip_tos; 2148 ip->ip_tos = inp->inp_ip_tos;
2149 } 2149 }
2150 ip->ip_p = IPPROTO_SCTP; 2150 ip->ip_p = IPPROTO_SCTP;
2151 ip->ip_sum = 0; 2151 ip->ip_sum = 0;
2152#ifdef SCTP_DEBUG 2152#ifdef SCTP_DEBUG
2153 printf("chunk_output: net %p\n", net); 2153 printf("chunk_output: net %p\n", net);
2154#endif 2154#endif
2155 if (net == NULL) { 2155 if (net == NULL) {
2156 ro = &iproute; 2156 ro = &iproute;
2157 memset(&iproute, 0, sizeof(iproute)); 2157 memset(&iproute, 0, sizeof(iproute));
@@ -2289,30 +2289,30 @@ sctp_lowlevel_chunk_output(struct sctp_i @@ -2289,30 +2289,30 @@ sctp_lowlevel_chunk_output(struct sctp_i
2289 u_short prev_port=0; 2289 u_short prev_port=0;
2290 2290
2291 M_PREPEND(m, sizeof(struct ip6_hdr), M_DONTWAIT); 2291 M_PREPEND(m, sizeof(struct ip6_hdr), M_DONTWAIT);
2292 if (m == NULL) { 2292 if (m == NULL) {
2293 /* failed to prepend data, give up */ 2293 /* failed to prepend data, give up */
2294 return (ENOMEM); 2294 return (ENOMEM);
2295 } 2295 }
2296 ip6h = mtod(m, struct ip6_hdr *); 2296 ip6h = mtod(m, struct ip6_hdr *);
2297 2297
2298 /* 2298 /*
2299 * We assume here that inp_flow is in host byte order within 2299 * We assume here that inp_flow is in host byte order within
2300 * the TCB! 2300 * the TCB!
2301 */ 2301 */
2302 flowBottom = ((struct in6pcb *)inp)->in6p_flowinfo & 0x0000ffff; 2302 flowBottom = in6p_flowinfo(inp) & 0x0000ffff;
2303 flowTop = ((((struct in6pcb *)inp)->in6p_flowinfo & 0x000f0000) >> 16); 2303 flowTop = ((in6p_flowinfo(inp) & 0x000f0000) >> 16);
2304 2304
2305 tosTop = (((((struct in6pcb *)inp)->in6p_flowinfo & 0xf0) >> 4) | IPV6_VERSION); 2305 tosTop = (((in6p_flowinfo(inp) & 0xf0) >> 4) | IPV6_VERSION);
2306 2306
2307 /* protect *sin6 from overwrite */ 2307 /* protect *sin6 from overwrite */
2308 memcpy(&tmp, to, sizeof(struct sockaddr_in6)); 2308 memcpy(&tmp, to, sizeof(struct sockaddr_in6));
2309 sin6 = &tmp; 2309 sin6 = &tmp;
2310 2310
2311 /* KAME hack: embed scopeid */ 2311 /* KAME hack: embed scopeid */
2312#if defined(SCTP_BASE_FREEBSD) || defined(__APPLE__) 2312#if defined(SCTP_BASE_FREEBSD) || defined(__APPLE__)
2313 if (in6_embedscope(&sin6->sin6_addr, sin6, NULL, NULL) != 0) 2313 if (in6_embedscope(&sin6->sin6_addr, sin6, NULL, NULL) != 0)
2314#else 2314#else
2315 /* 2315 /*
2316 * XXX: appropriate scope zone must be provided or otherwise 2316 * XXX: appropriate scope zone must be provided or otherwise
2317 * ip6_use_defzone must be 1. 2317 * ip6_use_defzone must be 1.
2318 */ 2318 */
@@ -2321,34 +2321,34 @@ sctp_lowlevel_chunk_output(struct sctp_i @@ -2321,34 +2321,34 @@ sctp_lowlevel_chunk_output(struct sctp_i
2321 return (EINVAL); 2321 return (EINVAL);
2322 if (net == NULL) { 2322 if (net == NULL) {
2323 memset(&ip6route, 0, sizeof(ip6route)); 2323 memset(&ip6route, 0, sizeof(ip6route));
2324 ro = (struct route *)&ip6route; 2324 ro = (struct route *)&ip6route;
2325 /* XXX */ 2325 /* XXX */
2326 rt = rtcache_lookup(ro, (struct sockaddr *) sin6); 2326 rt = rtcache_lookup(ro, (struct sockaddr *) sin6);
2327 rtcache_unref(rt, ro); 2327 rtcache_unref(rt, ro);
2328 } else { 2328 } else {
2329 ro = (struct route *)&net->ro; 2329 ro = (struct route *)&net->ro;
2330 } 2330 }
2331 if (stcb != NULL) { 2331 if (stcb != NULL) {
2332 if ((stcb->asoc.ecn_allowed) && ecn_ok) { 2332 if ((stcb->asoc.ecn_allowed) && ecn_ok) {
2333 /* Enable ECN */ 2333 /* Enable ECN */
2334 tosBottom = (((((struct in6pcb *)inp)->in6p_flowinfo & 0x0c) | sctp_get_ect(stcb, chk)) << 4); 2334 tosBottom = (((in6p_flowinfo(inp) & 0x0c) | sctp_get_ect(stcb, chk)) << 4);
2335 } else { 2335 } else {
2336 /* No ECN */ 2336 /* No ECN */
2337 tosBottom = ((((struct in6pcb *)inp)->in6p_flowinfo & 0x0c) << 4); 2337 tosBottom = ((in6p_flowinfo(inp) & 0x0c) << 4);
2338 } 2338 }
2339 } else { 2339 } else {
2340 /* we could get no asoc if it is a O-O-T-B packet */ 2340 /* we could get no asoc if it is a O-O-T-B packet */
2341 tosBottom = ((((struct in6pcb *)inp)->in6p_flowinfo & 0x0c) << 4); 2341 tosBottom = ((in6p_flowinfo(inp) & 0x0c) << 4);
2342 } 2342 }
2343 ip6h->ip6_flow = htonl(((tosTop << 24) | ((tosBottom|flowTop) << 16) | flowBottom)); 2343 ip6h->ip6_flow = htonl(((tosTop << 24) | ((tosBottom|flowTop) << 16) | flowBottom));
2344 ip6h->ip6_nxt = IPPROTO_SCTP; 2344 ip6h->ip6_nxt = IPPROTO_SCTP;
2345 ip6h->ip6_plen = m->m_pkthdr.len; 2345 ip6h->ip6_plen = m->m_pkthdr.len;
2346 ip6h->ip6_dst = sin6->sin6_addr; 2346 ip6h->ip6_dst = sin6->sin6_addr;
2347 2347
2348 /* 2348 /*
2349 * Add SRC address selection here: 2349 * Add SRC address selection here:
2350 * we can only reuse to a limited degree the kame src-addr-sel, 2350 * we can only reuse to a limited degree the kame src-addr-sel,
2351 * since we can try their selection but it may not be bound. 2351 * since we can try their selection but it may not be bound.
2352 */ 2352 */
2353 memset(&lsa6_tmp, 0, sizeof(lsa6_tmp)); 2353 memset(&lsa6_tmp, 0, sizeof(lsa6_tmp));
2354 lsa6_tmp.sin6_family = AF_INET6; 2354 lsa6_tmp.sin6_family = AF_INET6;
@@ -2406,27 +2406,27 @@ sctp_lowlevel_chunk_output(struct sctp_i @@ -2406,27 +2406,27 @@ sctp_lowlevel_chunk_output(struct sctp_i
2406 } 2406 }
2407 } 2407 }
2408 } 2408 }
2409 } 2409 }
2410 return (EHOSTUNREACH); 2410 return (EHOSTUNREACH);
2411 } 2411 }
2412 2412
2413 ip6h->ip6_src = lsa6->sin6_addr; 2413 ip6h->ip6_src = lsa6->sin6_addr;
2414 2414
2415 /* 2415 /*
2416 * We set the hop limit now since there is a good chance that 2416 * We set the hop limit now since there is a good chance that
2417 * our ro pointer is now filled 2417 * our ro pointer is now filled
2418 */ 2418 */
2419 ip6h->ip6_hlim = in6_selecthlim((struct in6pcb *)&inp->ip_inp.inp, 2419 ip6h->ip6_hlim = in6_selecthlim(&inp->ip_inp.inp,
2420 (ro ? 2420 (ro ?
2421 (rt ? (rt->rt_ifp) : (NULL)) : 2421 (rt ? (rt->rt_ifp) : (NULL)) :
2422 (NULL))); 2422 (NULL)));
2423 o_flgs = 0; 2423 o_flgs = 0;
2424 ifp = rt->rt_ifp; 2424 ifp = rt->rt_ifp;
2425#ifdef SCTP_DEBUG 2425#ifdef SCTP_DEBUG
2426 if (sctp_debug_on & SCTP_DEBUG_OUTPUT3) { 2426 if (sctp_debug_on & SCTP_DEBUG_OUTPUT3) {
2427 /* Copy to be sure something bad is not happening */ 2427 /* Copy to be sure something bad is not happening */
2428 sin6->sin6_addr = ip6h->ip6_dst; 2428 sin6->sin6_addr = ip6h->ip6_dst;
2429 lsa6->sin6_addr = ip6h->ip6_src; 2429 lsa6->sin6_addr = ip6h->ip6_src;
2430 2430
2431 printf("Calling ipv6 output routine from low level\n"); 2431 printf("Calling ipv6 output routine from low level\n");
2432 printf("src: "); 2432 printf("src: ");
@@ -2437,27 +2437,27 @@ sctp_lowlevel_chunk_output(struct sctp_i @@ -2437,27 +2437,27 @@ sctp_lowlevel_chunk_output(struct sctp_i
2437#endif /* SCTP_DEBUG */ 2437#endif /* SCTP_DEBUG */
2438 if (net) { 2438 if (net) {
2439 sin6 = (struct sockaddr_in6 *)&net->ro.ro_sa; 2439 sin6 = (struct sockaddr_in6 *)&net->ro.ro_sa;
2440 /* preserve the port and scope for link local send */ 2440 /* preserve the port and scope for link local send */
2441 prev_scope = sin6->sin6_scope_id; 2441 prev_scope = sin6->sin6_scope_id;
2442 prev_port = sin6->sin6_port; 2442 prev_port = sin6->sin6_port;
2443 } 2443 }
2444 /* XXX NOMPSAFE need to hold ifp here */ 2444 /* XXX NOMPSAFE need to hold ifp here */
2445 rtcache_unref(rt, ro); 2445 rtcache_unref(rt, ro);
2446 ret = ip6_output(m, ((struct in6pcb *)inp)->in6p_outputopts, 2446 ret = ip6_output(m, ((struct in6pcb *)inp)->in6p_outputopts,
2447 ro, 2447 ro,
2448 o_flgs, 2448 o_flgs,
2449 ((struct in6pcb *)inp)->in6p_moptions, 2449 ((struct in6pcb *)inp)->in6p_moptions,
2450 (struct in6pcb *)inp, 2450 (struct inpcb *)inp,
2451 &ifp); 2451 &ifp);
2452 if (net) { 2452 if (net) {
2453 /* for link local this must be done */ 2453 /* for link local this must be done */
2454 sin6->sin6_scope_id = prev_scope; 2454 sin6->sin6_scope_id = prev_scope;
2455 sin6->sin6_port = prev_port; 2455 sin6->sin6_port = prev_port;
2456 } 2456 }
2457#ifdef SCTP_DEBUG 2457#ifdef SCTP_DEBUG
2458 if (sctp_debug_on & SCTP_DEBUG_OUTPUT3) { 2458 if (sctp_debug_on & SCTP_DEBUG_OUTPUT3) {
2459 printf("return from send is %d\n", ret); 2459 printf("return from send is %d\n", ret);
2460 } 2460 }
2461#endif /* SCTP_DEBUG_OUTPUT */ 2461#endif /* SCTP_DEBUG_OUTPUT */
2462 sctp_pegs[SCTP_DATAGRAMS_SENT]++; 2462 sctp_pegs[SCTP_DATAGRAMS_SENT]++;
2463 if (net) { 2463 if (net) {

cvs diff -r1.6 -r1.7 src/sys/netinet/sctp_pcb.h (expand / switch to unified diff)

--- src/sys/netinet/sctp_pcb.h 2022/10/28 05:20:08 1.6
+++ src/sys/netinet/sctp_pcb.h 2022/10/28 05:26:29 1.7
@@ -1,15 +1,15 @@ @@ -1,15 +1,15 @@
1/* $KAME: sctp_pcb.h,v 1.21 2005/07/16 01:18:47 suz Exp $ */ 1/* $KAME: sctp_pcb.h,v 1.21 2005/07/16 01:18:47 suz Exp $ */
2/* $NetBSD: sctp_pcb.h,v 1.6 2022/10/28 05:20:08 ozaki-r Exp $ */ 2/* $NetBSD: sctp_pcb.h,v 1.7 2022/10/28 05:26:29 ozaki-r Exp $ */
3 3
4#ifndef __SCTP_PCB_H__ 4#ifndef __SCTP_PCB_H__
5#define __SCTP_PCB_H__ 5#define __SCTP_PCB_H__
6 6
7/* 7/*
8 * Copyright (c) 2001, 2002, 2003, 2004 Cisco Systems, Inc. 8 * Copyright (c) 2001, 2002, 2003, 2004 Cisco Systems, Inc.
9 * All rights reserved. 9 * All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions 12 * modification, are permitted provided that the following conditions
13 * are met: 13 * are met:
14 * 1. Redistributions of source code must retain the above copyright 14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer. 15 * notice, this list of conditions and the following disclaimer.
@@ -278,27 +278,27 @@ struct sctp_pcb { @@ -278,27 +278,27 @@ struct sctp_pcb {
278 278
279struct sctp_socket_q_list { 279struct sctp_socket_q_list {
280 struct sctp_tcb *tcb; 280 struct sctp_tcb *tcb;
281 TAILQ_ENTRY(sctp_socket_q_list) next_sq; 281 TAILQ_ENTRY(sctp_socket_q_list) next_sq;
282}; 282};
283 283
284struct sctp_inpcb { 284struct sctp_inpcb {
285 /* 285 /*
286 * put an inpcb in front of it all, kind of a waste but we need 286 * put an inpcb in front of it all, kind of a waste but we need
287 * to for compatibility with all the other stuff. 287 * to for compatibility with all the other stuff.
288 */ 288 */
289 union { 289 union {
290 struct inpcb inp; 290 struct inpcb inp;
291 char align[(sizeof(struct inpcb) + SCTP_ALIGNM1) & 291 char align[(sizeof(struct in6pcb) + SCTP_ALIGNM1) &
292 ~SCTP_ALIGNM1]; 292 ~SCTP_ALIGNM1];
293 } ip_inp; 293 } ip_inp;
294 LIST_ENTRY(sctp_inpcb) sctp_list; /* lists all endpoints */ 294 LIST_ENTRY(sctp_inpcb) sctp_list; /* lists all endpoints */
295 /* hash of all endpoints for model */ 295 /* hash of all endpoints for model */
296 LIST_ENTRY(sctp_inpcb) sctp_hash; 296 LIST_ENTRY(sctp_inpcb) sctp_hash;
297 297
298 /* count of local addresses bound, 0 if bound all */ 298 /* count of local addresses bound, 0 if bound all */
299 int laddr_count; 299 int laddr_count;
300 /* list of addrs in use by the EP */ 300 /* list of addrs in use by the EP */
301 struct sctpladdr sctp_addr_list; 301 struct sctpladdr sctp_addr_list;
302 /* used for source address selection rotation */ 302 /* used for source address selection rotation */
303 struct sctp_laddr *next_addr_touse; 303 struct sctp_laddr *next_addr_touse;
304 struct ifnet *next_ifn_touse; 304 struct ifnet *next_ifn_touse;
@@ -743,50 +743,32 @@ struct sctp_tcb *sctp_remove_from_socket @@ -743,50 +743,32 @@ struct sctp_tcb *sctp_remove_from_socket
743 743
744/* Null in last arg inpcb indicate run on ALL ep's. Specific 744/* Null in last arg inpcb indicate run on ALL ep's. Specific
745 * inp in last arg indicates run on ONLY assoc's of the 745 * inp in last arg indicates run on ONLY assoc's of the
746 * specified endpoint. 746 * specified endpoint.
747 */ 747 */
748int 748int
749sctp_initiate_iterator(asoc_func af, uint32_t, uint32_t, void *, uint32_t, 749sctp_initiate_iterator(asoc_func af, uint32_t, uint32_t, void *, uint32_t,
750 end_func ef, struct sctp_inpcb *); 750 end_func ef, struct sctp_inpcb *);
751 751
752void in6_sin6_2_sin (struct sockaddr_in *, 752void in6_sin6_2_sin (struct sockaddr_in *,
753 struct sockaddr_in6 *sin6); 753 struct sockaddr_in6 *sin6);
754 754
755#ifdef __NetBSD__ 755#ifdef __NetBSD__
756#ifndef in6pcb 
757#define in6pcb inpcb 
758#endif 
759#ifndef sotoin6pcb 756#ifndef sotoin6pcb
760#define sotoin6pcb sotoinpcb 757#define sotoin6pcb(so) ((struct in6pcb *)((so)->so_pcb))
761#endif 758#endif
762#ifndef in6p_flags 759#ifndef in6p_flags
763#define in6p_flags inp_flags 760#define in6p_flags in6p_pcb.inp_flags
764#endif 761#endif
765#ifndef in6p_af 762#ifndef in6p_af
766#define in6p_af inp_af 763#define in6p_af in6p_pcb.inp_af
767#endif 
768#ifndef in6p_cksum 
769#define in6p_cksum inp_cksum6 
770#endif 
771#ifndef in6p_hops 
772#define in6p_hops inp_hops6 
773#endif 
774#ifndef in6p_flowinfo 
775#define in6p_flowinfo inp_flowinfo 
776#endif 
777#ifndef in6p_outputopts 
778#define in6p_outputopts inp_outputopts6 
779#endif 
780#ifndef in6p_moptions 
781#define in6p_moptions inp_moptions6 
782#endif 764#endif
783#ifndef inpcb_hdr 765#ifndef inpcb_hdr
784#define inpcb_hdr inpcb 766#define inpcb_hdr inpcb
785#endif 767#endif
786#ifndef sp_inph 768#ifndef sp_inph
787#define sp_inph sp_inp 769#define sp_inph sp_inp
788#endif 770#endif
789#endif 771#endif
790 772
791#endif /* _KERNEL */ 773#endif /* _KERNEL */
792#endif /* !__SCTP_PCB_H__ */ 774#endif /* !__SCTP_PCB_H__ */

cvs diff -r1.13 -r1.14 src/sys/netinet6/dccp6_usrreq.c (expand / switch to unified diff)

--- src/sys/netinet6/dccp6_usrreq.c 2022/10/28 05:20:08 1.13
+++ src/sys/netinet6/dccp6_usrreq.c 2022/10/28 05:26:29 1.14
@@ -1,15 +1,15 @@ @@ -1,15 +1,15 @@
1/* $KAME: dccp6_usrreq.c,v 1.13 2005/07/27 08:42:56 nishida Exp $ */ 1/* $KAME: dccp6_usrreq.c,v 1.13 2005/07/27 08:42:56 nishida Exp $ */
2/* $NetBSD: dccp6_usrreq.c,v 1.13 2022/10/28 05:20:08 ozaki-r Exp $ */ 2/* $NetBSD: dccp6_usrreq.c,v 1.14 2022/10/28 05:26:29 ozaki-r Exp $ */
3 3
4/* 4/*
5 * Copyright (C) 2003 WIDE Project. 5 * Copyright (C) 2003 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
15 * documentation and/or other materials provided with the distribution. 15 * documentation and/or other materials provided with the distribution.
@@ -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: dccp6_usrreq.c,v 1.13 2022/10/28 05:20:08 ozaki-r Exp $"); 34__KERNEL_RCSID(0, "$NetBSD: dccp6_usrreq.c,v 1.14 2022/10/28 05:26:29 ozaki-r Exp $");
35 35
36#ifdef _KERNEL_OPT 36#ifdef _KERNEL_OPT
37#include "opt_inet.h" 37#include "opt_inet.h"
38#include "opt_dccp.h" 38#include "opt_dccp.h"
39#include "opt_net_mpsafe.h" 39#include "opt_net_mpsafe.h"
40#endif 40#endif
41 41
42#include <sys/param.h> 42#include <sys/param.h>
43#include <sys/systm.h> 43#include <sys/systm.h>
44#include <sys/domain.h> 44#include <sys/domain.h>
45#include <sys/kernel.h> 45#include <sys/kernel.h>
46#include <sys/pool.h> 46#include <sys/pool.h>
47#include <sys/lock.h> 47#include <sys/lock.h>
@@ -152,39 +152,39 @@ dccp6_connect(struct socket *so, struct  @@ -152,39 +152,39 @@ dccp6_connect(struct socket *so, struct
152 struct sockaddr_in6 *sin6; 152 struct sockaddr_in6 *sin6;
153 char test[2]; 153 char test[2];
154 154
155 DCCP_DEBUG((LOG_INFO, "Entering dccp6_connect!\n")); 155 DCCP_DEBUG((LOG_INFO, "Entering dccp6_connect!\n"));
156 156
157#ifndef __NetBSD__ 157#ifndef __NetBSD__
158 INP_INFO_WLOCK(&dccpbinfo); 158 INP_INFO_WLOCK(&dccpbinfo);
159 inp = sotoinpcb(so); 159 inp = sotoinpcb(so);
160 if (inp == 0) { 160 if (inp == 0) {
161 INP_INFO_WUNLOCK(&dccpbinfo); 161 INP_INFO_WUNLOCK(&dccpbinfo);
162 return EINVAL; 162 return EINVAL;
163 } 163 }
164 INP_LOCK(inp); 164 INP_LOCK(inp);
165 if (inp->inp_faddr6.s_addr != INADDR_ANY) { 165 if (in6p_faddr(inp).s_addr != INADDR_ANY) {
166 INP_UNLOCK(inp); 166 INP_UNLOCK(inp);
167 INP_INFO_WUNLOCK(&dccpbinfo); 167 INP_INFO_WUNLOCK(&dccpbinfo);
168 return EISCONN; 168 return EISCONN;
169 } 169 }
170 170
171 dp = (struct dccpcb *)inp->inp_ppcb; 171 dp = (struct dccpcb *)inp->inp_ppcb;
172#else 172#else
173 inp = sotoinpcb(so); 173 inp = sotoinpcb(so);
174 if (inp == 0) { 174 if (inp == 0) {
175 return EINVAL; 175 return EINVAL;
176 } 176 }
177 if (!IN6_IS_ADDR_UNSPECIFIED(&inp->inp_faddr6)) { 177 if (!IN6_IS_ADDR_UNSPECIFIED(&in6p_faddr(inp))) {
178 return EISCONN; 178 return EISCONN;
179 } 179 }
180 180
181 dp = (struct dccpcb *)inp->inp_ppcb; 181 dp = (struct dccpcb *)inp->inp_ppcb;
182#endif 182#endif
183 if (dp->state == DCCPS_ESTAB) { 183 if (dp->state == DCCPS_ESTAB) {
184 DCCP_DEBUG((LOG_INFO, "Why are we in connect when we already have a established connection?\n")); 184 DCCP_DEBUG((LOG_INFO, "Why are we in connect when we already have a established connection?\n"));
185 } 185 }
186 186
187 dp->who = DCCP_CLIENT; 187 dp->who = DCCP_CLIENT;
188 dp->seq_snd = (((u_int64_t)random() << 32) | random()) % 281474976710656LL; 188 dp->seq_snd = (((u_int64_t)random() << 32) | random()) % 281474976710656LL;
189 189
190 sin6 = (struct sockaddr_in6 *)nam; 190 sin6 = (struct sockaddr_in6 *)nam;

cvs diff -r1.22 -r1.23 src/sys/netinet6/sctp6_usrreq.c (expand / switch to unified diff)

--- src/sys/netinet6/sctp6_usrreq.c 2020/04/27 19:33:48 1.22
+++ src/sys/netinet6/sctp6_usrreq.c 2022/10/28 05:26:29 1.23
@@ -1,15 +1,15 @@ @@ -1,15 +1,15 @@
1/* $KAME: sctp6_usrreq.c,v 1.38 2005/08/24 08:08:56 suz Exp $ */ 1/* $KAME: sctp6_usrreq.c,v 1.38 2005/08/24 08:08:56 suz Exp $ */
2/* $NetBSD: sctp6_usrreq.c,v 1.22 2020/04/27 19:33:48 rjs Exp $ */ 2/* $NetBSD: sctp6_usrreq.c,v 1.23 2022/10/28 05:26:29 ozaki-r Exp $ */
3 3
4/* 4/*
5 * Copyright (c) 2001, 2002, 2003, 2004 Cisco Systems, Inc. 5 * Copyright (c) 2001, 2002, 2003, 2004 Cisco Systems, Inc.
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
15 * documentation and/or other materials provided with the distribution. 15 * documentation and/or other materials provided with the distribution.
@@ -23,27 +23,27 @@ @@ -23,27 +23,27 @@
23 * THIS SOFTWARE IS PROVIDED BY CISCO SYSTEMS AND CONTRIBUTORS ``AS IS'' AND 23 * THIS SOFTWARE IS PROVIDED BY CISCO SYSTEMS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL CISCO SYSTEMS OR CONTRIBUTORS BE LIABLE 26 * ARE DISCLAIMED. IN NO EVENT SHALL CISCO SYSTEMS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE. 33 * SUCH DAMAGE.
34 */ 34 */
35#include <sys/cdefs.h> 35#include <sys/cdefs.h>
36__KERNEL_RCSID(0, "$NetBSD: sctp6_usrreq.c,v 1.22 2020/04/27 19:33:48 rjs Exp $"); 36__KERNEL_RCSID(0, "$NetBSD: sctp6_usrreq.c,v 1.23 2022/10/28 05:26:29 ozaki-r Exp $");
37 37
38#ifdef _KERNEL_OPT 38#ifdef _KERNEL_OPT
39#include "opt_inet.h" 39#include "opt_inet.h"
40#include "opt_ipsec.h" 40#include "opt_ipsec.h"
41#include "opt_sctp.h" 41#include "opt_sctp.h"
42#include "opt_net_mpsafe.h" 42#include "opt_net_mpsafe.h"
43#endif /* _KERNEL_OPT */ 43#endif /* _KERNEL_OPT */
44 44
45#include <sys/param.h> 45#include <sys/param.h>
46#include <sys/kernel.h> 46#include <sys/kernel.h>
47#include <sys/mbuf.h> 47#include <sys/mbuf.h>
48#include <sys/domain.h> 48#include <sys/domain.h>
49#include <sys/protosw.h> 49#include <sys/protosw.h>
@@ -224,27 +224,27 @@ sctp_skip_csum: @@ -224,27 +224,27 @@ sctp_skip_csum:
224 (u_int8_t *)&chunk_buf); 224 (u_int8_t *)&chunk_buf);
225 sh->v_tag = init_chk->init.initiate_tag; 225 sh->v_tag = init_chk->init.initiate_tag;
226 } 226 }
227 sctp_send_abort(m, iphlen, sh, 0, NULL); 227 sctp_send_abort(m, iphlen, sh, 0, NULL);
228 goto bad; 228 goto bad;
229 } else if (stcb == NULL) { 229 } else if (stcb == NULL) {
230 refcount_up = 1; 230 refcount_up = 1;
231 } 231 }
232 in6p_ip = (struct inpcb *)in6p; 232 in6p_ip = (struct inpcb *)in6p;
233#ifdef IPSEC 233#ifdef IPSEC
234 /* 234 /*
235 * Check AH/ESP integrity. 235 * Check AH/ESP integrity.
236 */ 236 */
237 if (ipsec_used && ipsec_in_reject(m, (struct in6pcb *)in6p_ip)) { 237 if (ipsec_used && ipsec_in_reject(m, in6p_ip)) {
238/* XXX */ 238/* XXX */
239#if 0 239#if 0
240 /* FIX ME: need to find right stat */ 240 /* FIX ME: need to find right stat */
241 ipsec6stat.in_polvio++; 241 ipsec6stat.in_polvio++;
242#endif 242#endif
243 goto bad; 243 goto bad;
244 } 244 }
245#endif /*IPSEC*/ 245#endif /*IPSEC*/
246 246
247 /* 247 /*
248 * Construct sockaddr format source address. 248 * Construct sockaddr format source address.
249 * Stuff source address and datagram in user buffer. 249 * Stuff source address and datagram in user buffer.
250 */ 250 */
@@ -252,29 +252,29 @@ sctp_skip_csum: @@ -252,29 +252,29 @@ sctp_skip_csum:
252#ifndef __OpenBSD__ 252#ifndef __OpenBSD__
253 || (in6p->sctp_socket->so_options & SO_TIMESTAMP) 253 || (in6p->sctp_socket->so_options & SO_TIMESTAMP)
254#endif 254#endif
255 ) { 255 ) {
256#if defined(__FreeBSD__) || defined(__APPLE__) 256#if defined(__FreeBSD__) || defined(__APPLE__)
257#if (defined(SCTP_BASE_FREEBSD) && __FreeBSD_version < 501113) || defined(__APPLE__) 257#if (defined(SCTP_BASE_FREEBSD) && __FreeBSD_version < 501113) || defined(__APPLE__)
258 ip6_savecontrol(in6p_ip, &opts, ip6, m); 258 ip6_savecontrol(in6p_ip, &opts, ip6, m);
259#elif __FreeBSD_version >= 440000 || (defined(SCTP_BASE_FREEBSD) && __FreeBSD_version >= 501113) 259#elif __FreeBSD_version >= 440000 || (defined(SCTP_BASE_FREEBSD) && __FreeBSD_version >= 501113)
260 ip6_savecontrol(in6p_ip, m, &opts); 260 ip6_savecontrol(in6p_ip, m, &opts);
261#else 261#else
262 ip6_savecontrol(in6p_ip, m, &opts, NULL); 262 ip6_savecontrol(in6p_ip, m, &opts, NULL);
263#endif 263#endif
264#elif defined(__NetBSD__) 264#elif defined(__NetBSD__)
265 ip6_savecontrol((struct in6pcb *)in6p_ip, &opts, ip6, m); 265 ip6_savecontrol(in6p_ip, &opts, ip6, m);
266#else 266#else
267 ip6_savecontrol((struct in6pcb *)in6p_ip, m, &opts); 267 ip6_savecontrol(in6p_ip, m, &opts);
268#endif 268#endif
269 } 269 }
270 270
271 /* 271 /*
272 * CONTROL chunk processing 272 * CONTROL chunk processing
273 */ 273 */
274 length = ntohs(ip6->ip6_plen) + iphlen; 274 length = ntohs(ip6->ip6_plen) + iphlen;
275 offset -= sizeof(*ch); 275 offset -= sizeof(*ch);
276 ecn_bits = ((ntohl(ip6->ip6_flow) >> 20) & 0x000000ff); 276 ecn_bits = ((ntohl(ip6->ip6_flow) >> 20) & 0x000000ff);
277 s = splsoftnet(); 277 s = splsoftnet();
278 (void)sctp_common_input_processing(&m, iphlen, offset, length, sh, ch, 278 (void)sctp_common_input_processing(&m, iphlen, offset, length, sh, ch,
279 in6p, stcb, net, ecn_bits); 279 in6p, stcb, net, ecn_bits);
280 /* inp's ref-count reduced && stcb unlocked */ 280 /* inp's ref-count reduced && stcb unlocked */
@@ -473,28 +473,27 @@ sctp6_ctlinput(int cmd, const struct soc @@ -473,28 +473,27 @@ sctp6_ctlinput(int cmd, const struct soc
473 /* inp's ref-count reduced && stcb unlocked */ 473 /* inp's ref-count reduced && stcb unlocked */
474 } else { 474 } else {
475 if (cmd == PRC_HOSTDEAD) { 475 if (cmd == PRC_HOSTDEAD) {
476 cm = EHOSTUNREACH; 476 cm = EHOSTUNREACH;
477 } else { 477 } else {
478 cm = inet6ctlerrmap[cmd]; 478 cm = inet6ctlerrmap[cmd];
479 } 479 }
480 sctp_notify(inp, cm, &sh, sin6tosa(&final), 480 sctp_notify(inp, cm, &sh, sin6tosa(&final),
481 stcb, net); 481 stcb, net);
482 /* inp's ref-count reduced && stcb unlocked */ 482 /* inp's ref-count reduced && stcb unlocked */
483 } 483 }
484 } else { 484 } else {
485 if (PRC_IS_REDIRECT(cmd) && inp) { 485 if (PRC_IS_REDIRECT(cmd) && inp) {
486 in6_rtchange((struct in6pcb *)inp, 486 in6_rtchange((struct inpcb *)inp, inet6ctlerrmap[cmd]);
487 inet6ctlerrmap[cmd]); 
488 } 487 }
489 if (inp) { 488 if (inp) {
490 /* reduce inp's ref-count */ 489 /* reduce inp's ref-count */
491 SCTP_INP_WLOCK(inp); 490 SCTP_INP_WLOCK(inp);
492 SCTP_INP_DECR_REF(inp); 491 SCTP_INP_DECR_REF(inp);
493 SCTP_INP_WUNLOCK(inp); 492 SCTP_INP_WUNLOCK(inp);
494 } 493 }
495 if (stcb) { 494 if (stcb) {
496 SCTP_TCB_UNLOCK(stcb); 495 SCTP_TCB_UNLOCK(stcb);
497 } 496 }
498 } 497 }
499 splx(s); 498 splx(s);
500 } 499 }