1 /*        $KAME: sctp_var.h,v 1.24 2005/03/06 16:04:19 itojun Exp $   */
2 /*        $NetBSD: sctp_var.h,v 1.4 2020/04/27 19:21:43 rjs Exp $ */
3 
4 /*
5  * Copyright (c) 2001, 2002, 2003, 2004 Cisco Systems, Inc.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. All advertising materials mentioning features or use of this software
17  *    must display the following acknowledgement:
18  *      This product includes software developed by Cisco Systems, Inc.
19  * 4. Neither the name of the project nor the names of its contributors
20  *    may be used to endorse or promote products derived from this software
21  *    without specific prior written permission.
22  *
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
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED.  IN NO EVENT SHALL CISCO SYSTEMS OR CONTRIBUTORS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
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
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
33  * SUCH DAMAGE.
34  */
35 
36 #ifndef _NETINET_SCTP_VAR_H_
37 #define _NETINET_SCTP_VAR_H_
38 
39 #include <sys/socketvar.h>
40 #include <netinet/sctp_uio.h>
41 
42 /* SCTP Kernel structures */
43 
44 /*
45  * Names for SCTP sysctl objects
46  */
47 #ifndef __APPLE__
48 #define   SCTPCTL_MAXDGRAM        1     /* max datagram size */
49 #define   SCTPCTL_RECVSPACE       2     /* default receive buffer space */
50 #define SCTPCTL_AUTOASCONF          3   /* auto asconf enable/disable flag */
51 #define SCTPCTL_ECN_ENABLE          4   /* Is ecn allowed */
52 #define SCTPCTL_ECN_NONCE           5   /* Is ecn nonce allowed */
53 #define SCTPCTL_STRICT_SACK         6   /* strictly require sack'd TSN's to be
54                                                    * smaller than sndnxt.
55                                                    */
56 #define SCTPCTL_NOCSUM_LO           7   /* Require that the Loopback NOT have
57                                                  * the crc32 checksum on packets routed over
58                                                    * it.
59                                                  */
60 #define SCTPCTL_STRICT_INIT         8
61 #define SCTPCTL_PEER_CHK_OH         9
62 #define SCTPCTL_MAXBURST            10
63 #define SCTPCTL_MAXCHUNKONQ         11
64 #define SCTPCTL_DELAYED_SACK        12
65 #define SCTPCTL_HB_INTERVAL         13
66 #define SCTPCTL_PMTU_RAISE          14
67 #define SCTPCTL_SHUTDOWN_GUARD      15
68 #define SCTPCTL_SECRET_LIFETIME     16
69 #define SCTPCTL_RTO_MAX             17
70 #define SCTPCTL_RTO_MIN             18
71 #define SCTPCTL_RTO_INITIAL         19
72 #define SCTPCTL_INIT_RTO_MAX        20
73 #define SCTPCTL_COOKIE_LIFE         21
74 #define SCTPCTL_INIT_RTX_MAX        22
75 #define SCTPCTL_ASSOC_RTX_MAX       23
76 #define SCTPCTL_PATH_RTX_MAX        24
77 #define SCTPCTL_NR_OUTGOING_STREAMS 25
78 #ifdef SCTP_DEBUG
79 #define SCTPCTL_DEBUG               26
80 #endif
81 
82 #endif
83 
84 #if defined(_KERNEL)
85 
86 extern const struct pr_usrreqs sctp_usrreqs;
87 
88 int sctp_usrreq(struct socket *, int, struct mbuf *, struct mbuf *,
89                           struct mbuf *, struct lwp *);
90 
91 #define   sctp_sbspace(sb) ((long) (((sb)->sb_hiwat > (sb)->sb_cc) ? ((sb)->sb_hiwat - (sb)->sb_cc) : 0))
92 
93 #define sctp_sbspace_sub(a,b) ((a > b) ? (a - b) : 0)
94 
95 extern int          sctp_sendspace;
96 extern int          sctp_recvspace;
97 extern int      sctp_ecn;
98 extern int      sctp_ecn_nonce;
99 
100 #define sctp_ucount_incr(val) { \
101           val++; \
102 }
103 
104 #define sctp_ucount_decr(val) { \
105           if (val > 0) { \
106                     val--; \
107           } else { \
108                     val = 0; \
109           } \
110 }
111 
112 #define sctp_flight_size_decrease(tp1) do { \
113           if (tp1->whoTo->flight_size >= tp1->book_size) \
114                     tp1->whoTo->flight_size -= tp1->book_size; \
115           else \
116                     tp1->whoTo->flight_size = 0; \
117 } while (0)
118 
119 #define sctp_flight_size_increase(tp1) do { \
120        (tp1)->whoTo->flight_size += (tp1)->book_size; \
121 } while (0)
122 
123 #define sctp_total_flight_decrease(stcb, tp1) do { \
124           if (stcb->asoc.total_flight >= tp1->book_size) { \
125                     stcb->asoc.total_flight -= tp1->book_size; \
126                     if (stcb->asoc.total_flight_count > 0) \
127                               stcb->asoc.total_flight_count--; \
128           } else { \
129                     stcb->asoc.total_flight = 0; \
130                     stcb->asoc.total_flight_count = 0; \
131           } \
132 } while (0)
133 
134 #define sctp_total_flight_increase(stcb, tp1) do { \
135        (stcb)->asoc.total_flight_count++; \
136        (stcb)->asoc.total_flight += (tp1)->book_size; \
137 } while (0)
138 
139 
140 struct sctp_nets;
141 struct sctp_inpcb;
142 struct sctp_tcb;
143 struct sctphdr;
144 
145 void*     sctp_ctlinput(int, const struct sockaddr *, void *);
146 int       sctp_ctloutput(int, struct socket *, struct sockopt *);
147 void      sctp_input(struct mbuf *, int, int);
148 void      sctp_drain(void);
149 void      sctp_init(void);
150 int       sctp_shutdown(struct socket *);
151 void      sctp_notify(struct sctp_inpcb *, int, struct sctphdr *,
152                                struct sockaddr *, struct sctp_tcb *,
153                                struct sctp_nets *);
154 int sctp_rcvd(struct socket *, int, struct lwp *);
155 int sctp_send(struct socket *, struct mbuf *, struct sockaddr *,
156                     struct mbuf *, struct lwp *);
157 
158 #if defined(INET6)
159 void ip_2_ip6_hdr(struct ip6_hdr *, struct ip *);
160 #endif
161 
162 int sctp_bindx(struct socket *, int, struct sockaddr_storage *,
163           int, int, struct lwp *);
164 int sctp_do_connect_x(struct socket *, struct sctp_connectx_addrs *,
165           struct lwp *, int);
166 
167 /* can't use sctp_assoc_t here */
168 int sctp_peeloff(struct socket *, struct socket *, int, vaddr_t, int *);
169 
170 
171 sctp_assoc_t sctp_getassocid(struct sockaddr *);
172 int sctp_sockaddr(struct socket *, struct sockaddr *);
173 int sctp_peeraddr(struct socket *, struct sockaddr *);
174 int sctp_listen(struct socket *, struct lwp *);
175 int sctp_accept(struct socket *, struct sockaddr *);
176 
177 int sctp_sysctl(int *, u_int, void *, size_t *, void *, size_t);
178 
179 #endif /* _KERNEL */
180 
181 #endif /* !_NETINET_SCTP_VAR_H_ */
182