dccp_var.h revision 1.3 1 /* $KAME: dccp_var.h,v 1.29 2005/11/03 14:59:28 nishida Exp $ */
2 /* $NetBSD: dccp_var.h,v 1.3 2016/07/07 06:55:43 msaitoh Exp $ */
3
4 /*
5 * Copyright (c) 2003 Joacim Hggmark, Magnus Erixzon, Nils-Erik Mattsson
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 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 *
31 * Id: dccp_var.h,v 1.25 2003/07/31 11:17:15 joahag-9 Exp
32 */
33
34 #ifndef _NETINET_DCCP_VAR_H_
35 #define _NETINET_DCCP_VAR_H_
36
37 typedef u_int64_t dccp_seq;
38
39 #define DSEQ_TO_DHDR(x, y) { \
40 (x)->dh_seq = htons(y >> 32);\
41 (x)->dh_seq2 = htonl(y & 4294967295U);\
42 }
43
44 #define DHDR_TO_DSEQ(x, y) { \
45 x = ((u_int64_t)ntohs(y->dh_seq) << 32) | ntohl(y->dh_seq2);\
46 }
47
48 #define DSEQ_TO_DAHDR(x, y) { \
49 (x).dah_ack = htons(y >> 32);\
50 (x).dah_ack2 = htonl(y & 4294967295U);\
51 }
52
53 #define DAHDR_TO_DSEQ(x, y) { \
54 x = ((u_int64_t)ntohs(y.dah_ack) << 32) | ntohl(y.dah_ack2);\
55 }
56
57 #define CONVERT_TO_LONGSEQ(S, ref) \
58 ((((~(S- ref.lo) +1) <= 0x7fffff) && (S < ref.lo))? \
59 (((u_int64_t)(ref.hi + 1) << 24) | S) % 281474976710656ll: \
60 (((u_int64_t)ref.hi << 24) | S) % 281474976710656ll)
61
62 struct ref_seq {
63 u_int32_t hi;
64 u_int32_t lo;
65 };
66
67 struct dccpcb {
68 u_int8_t state; /* initial, listening, connecting, established,
69 closing, closed etc */
70 u_int8_t who; /* undef, server, client, listener */
71
72 struct callout connect_timer; /* Connection timer */
73 struct callout retrans_timer; /* Retransmit timer */
74 struct callout close_timer; /* Closing timer */
75 struct callout timewait_timer; /* Time wait timer */
76
77 u_int32_t retrans;
78
79 dccp_seq seq_snd;
80 dccp_seq ack_snd; /* ack num to send in Ack or DataAck packet */
81 dccp_seq gsn_rcv; /* Greatest received sequence number */
82
83 /* values representing last incoming packet. are set in dccp_input */
84 dccp_seq seq_rcv; /* Seq num of received packet */
85 dccp_seq ack_rcv; /* Ack num received in Ack or DataAck packet */
86 u_int8_t type_rcv; /* Type of packet received */
87 u_int32_t len_rcv; /* Length of data received */
88 u_int8_t ndp_rcv; /* ndp value of received packet */
89
90 u_int8_t cslen; /* How much of outgoing packets are covered by the checksum */
91 u_int8_t pref_cc; /* Client prefered CC */
92 u_int8_t ndp; /* Number of non data packets */
93 u_int32_t loss_window; /* Loss window (defaults to 1000) */
94 u_int16_t ack_ratio; /* Ack Ratio Feature */
95 int8_t cc_in_use[2]; /* Current CC in use
96 (in each direction) */
97 void *cc_state[2];
98 struct inpcb *d_inpcb; /* Pointer back to Internet PCB */
99 struct in6pcb *d_in6pcb;
100 u_int32_t d_maxseg; /* Maximum segment size */
101 char options[DCCP_MAX_OPTIONS];
102 u_int8_t optlen;
103 char features[DCCP_MAX_OPTIONS];
104 u_int8_t featlen;
105 u_int8_t ccval; /* ccval */
106
107 u_int32_t avgpsize; /* Average packet size */
108
109 /* variables for the local (receiver-side) ack vector */
110 u_char *ackvector; /* For acks, 2 bits per packet */
111 u_char *av_hp; /* head ptr for ackvector */
112 u_int16_t av_size;
113 dccp_seq av_hs, av_ts; /* highest/lowest seq no in ackvector */
114
115 u_int8_t remote_ackvector; /* Is recv side using AckVector? */
116 u_char shortseq; /* use short seq number */
117 u_int32_t scode; /* service core */
118 struct ref_seq ref_seq; /* reference sequence number */
119 struct ref_seq ref_pseq; /* reference peer sequence number */
120
121 #ifndef __FreeBSD__
122 #ifndef INP_IPV6
123 #define INP_IPV6 0x1
124 #endif
125 #ifndef INP_IPV4
126 #define INP_IPV4 0x2
127 #endif
128 u_int8_t inp_vflag;
129 u_int8_t inp_ip_ttl;
130 u_int8_t inp_ip_tos;
131 #endif
132 u_int8_t pktlen[DCCP_MAX_PKTS];
133 u_int16_t pktlenidx;
134 u_int16_t pktcnt;
135 };
136
137 #ifdef _KERNEL
138 struct inp_dp {
139 struct inpcb inp;
140 struct dccpcb dp;
141 };
142 #endif
143
144 #if defined(_NETINET_IN_PCB_H_) && defined(_SYS_SOCKETVAR_H_)
145 struct xdccpcb {
146 size_t xd_len;
147 struct inpcb xd_inp;
148 struct dccpcb xd_dp;
149 #ifdef __FreeBSD__
150 struct xsocket xd_socket;
151 #endif
152 };
153 #endif
154
155 #define intodccpcb(ip) ((struct dccpcb *)((ip)->inp_ppcb))
156 #define in6todccpcb(ip) ((struct dccpcb *)((ip)->in6p_ppcb))
157
158 #ifdef __NetBSD__
159 #define dptosocket(dp) (((dp)->d_inpcb) ? (dp)->d_inpcb->inp_socket : \
160 (((dp)->d_in6pcb) ? (dp)->d_in6pcb->in6p_socket : NULL))
161 #else
162 #define dptosocket(dp) ((dp)->d_inpcb->inp_socket)
163 #endif
164
165 struct dccpstat {
166 u_long dccps_connattempt; /* Initiated connections */
167 u_long dccps_connects; /* Established connections */
168 u_long dccps_ipackets; /* Total input packets */
169 u_long dccps_ibytes; /* Total input bytes */
170 u_long dccps_drops; /* Dropped packets */
171 u_long dccps_badsum; /* Checksum error */
172 u_long dccps_badlen; /* Bad length */
173 u_long dccps_badseq; /* Sequence number not inside loss_window */
174 u_long dccps_noport; /* No socket on port */
175
176 /* TCPlike Sender */
177 u_long tcplikes_send_conn; /* Connections established */
178 u_long tcplikes_send_reploss; /* Data packets reported lost */
179 u_long tcplikes_send_assloss; /* Data packets assumed lost */
180 u_long tcplikes_send_ackrecv; /* Acknowledgement (w/ Ack Vector) packets received */
181 u_long tcplikes_send_missack; /* Ack packets assumed lost */
182 u_long tcplikes_send_badseq; /* Bad sequence number on outgoing packet */
183 u_long tcplikes_send_memerr; /* Memory allocation errors */
184
185 /* TCPlike Receiver */
186 u_long tcplikes_recv_conn; /* Connections established */
187 u_long tcplikes_recv_datarecv; /* Number of data packets received */
188 u_long tcplikes_recv_ackack; /* Ack-on-acks received */
189 u_long tcplikes_recv_acksent; /* Acknowledgement (w/ Ack Vector) packets sent */
190 u_long tcplikes_recv_memerr; /* Memory allocation errors */
191
192 /* Some CCID statistic should also be here */
193
194 u_long dccps_opackets; /* Total output packets */
195 u_long dccps_obytes; /* Total output bytes */
196
197 /* TFRC Sender */
198 u_long tfrcs_send_conn; /* Connections established */
199 u_long tfrcs_send_nomem; /* Not enough memory */
200 u_long tfrcs_send_erropt; /* option error */
201 u_long tfrcs_send_noopt; /* no option */
202 u_long tfrcs_send_fbacks; /* sent feedbacks */
203
204 /* TFRC Receiver */
205 u_long tfrcs_recv_conn; /* established connection */
206 u_long tfrcs_recv_erropt; /* option error */
207 u_long tfrcs_recv_losts; /* lost packets */
208 u_long tfrcs_recv_nomem; /* no memory */
209 u_long tfrcs_recv_noopt; /* no option */
210 u_long tfrcs_recv_fbacks; /* receipt feedbacks */
211
212 };
213
214 /*
215 * Names for DCCP sysctl objects
216 */
217 #define DCCPCTL_LOGINVAIN 1
218 #define DCCPCTL_DOFEATURENEGO 2
219
220 /*
221 * DCCP States
222 */
223
224 #define DCCPS_CLOSED 0
225 #define DCCPS_LISTEN 1
226 #define DCCPS_REQUEST 2
227 #define DCCPS_RESPOND 3
228 #define DCCPS_ESTAB 4
229 #define DCCPS_SERVER_CLOSE 5
230 #define DCCPS_CLIENT_CLOSE 6
231 #define DCCPS_TIME_WAIT 7
232
233 #define DCCP_NSTATES 8
234
235 #ifdef DCCPSTATES
236 const char *dccpstates[] = {
237 "CLOSED", "LISTEN", "REQEST", "RESPOND",
238 "ESTABLISHED", "SERVER-CLOSE", "CLIENT-CLOSE", "TIME_WAIT",
239 };
240 #else
241 extern const char *dccpstates[];
242 #endif
243
244 #define DCCP_UNDEF 0
245 #define DCCP_LISTENER 1
246 #define DCCP_SERVER 2
247 #define DCCP_CLIENT 3
248
249 #define DCCP_SEQ_LT(a, b) ((int)(((a) << 16) - ((b) << 16)) < 0)
250 #define DCCP_SEQ_GT(a, b) ((int)(((a) << 16) - ((b) << 16)) > 0)
251
252 /*
253 * Names for DCCP sysctl objects
254 */
255 #define DCCPCTL_DEFCCID 1 /* Default CCID */
256 #define DCCPCTL_STATS 2 /* statistics (read-only) */
257 #define DCCPCTL_PCBLIST 3
258 #define DCCPCTL_SENDSPACE 4
259 #define DCCPCTL_RECVSPACE 5
260
261 #define DCCPCTL_NAMES { \
262 { 0, 0 }, \
263 { "defccid", CTLTYPE_INT }, \
264 { "stats", CTLTYPE_STRUCT }, \
265 { "sendspace", CTLTYPE_INT }, \
266 { "recvspace", CTLTYPE_INT }, \
267 }
268
269 #ifdef _KERNEL
270
271 #ifdef DCCP_DEBUG_ON
272 #define DCCP_DEBUG(args) dccp_log args
273 #else
274 #define DCCP_DEBUG(args)
275 #endif
276
277 #ifdef ACKDEBUG
278 #define ACK_DEBUG(args) dccp_log args
279 #else
280 #define ACK_DEBUG(args)
281 #endif
282
283 extern const struct pr_usrreqs dccp_usrreqs;
284 extern struct inpcbhead dccpb;
285 extern struct inpcbinfo dccpbinfo;
286 extern u_long dccp_sendspace;
287 extern u_long dccp_recvspace;
288 extern struct dccpstat dccpstat; /* dccp statistics */
289 extern int dccp_log_in_vain; /* if we should log connections to
290 ports w/o listeners */
291 extern int dccp_do_feature_nego;
292
293 extern struct inpcbtable dccpbtable;
294
295 /* These four functions are called from inetsw (in_proto.c) */
296 void dccp_init(void);
297 void dccp_log(int, const char *, ...);
298 void dccp_input(struct mbuf *, ...);
299 void* dccp_ctlinput(int, const struct sockaddr *, void *);
300 int dccp_ctloutput(int , struct socket *, struct sockopt *);
301 int dccp_sysctl(int *, u_int, void *, size_t *, void *, size_t);
302 int dccp_usrreq(struct socket *, int, struct mbuf *, struct mbuf *,
303 struct mbuf *, struct lwp *);
304
305 void dccp_notify(struct inpcb *, int);
306 struct dccpcb *
307 dccp_newdccpcb(int, void *);
308 int dccp_shutdown(struct socket *);
309 int dccp_output(struct dccpcb *, u_int8_t);
310 int dccp_doconnect(struct socket *, struct sockaddr *, struct lwp *, int);
311 int dccp_add_option(struct dccpcb *, u_int8_t, char *, u_int8_t);
312 int dccp_add_feature(struct dccpcb *, u_int8_t, u_int8_t, char *,
313 u_int8_t);
314 int dccp_detach(struct socket *);
315 int dccp_attach(struct socket *, int);
316 int dccp_abort(struct socket *);
317 int dccp_disconnect(struct socket *);
318 int dccp_send(struct socket *, struct mbuf *, struct sockaddr *,
319 struct mbuf *, struct lwp *);
320 void dccp_retrans_t(void *);
321 void dccp_connect_t(void *);
322
323 /* No cc functions */
324 void* dccp_nocc_init(struct dccpcb *);
325 void dccp_nocc_free(void *);
326 int dccp_nocc_send_packet(void*, long);
327 void dccp_nocc_send_packet_sent(void *, int, long);
328 void dccp_nocc_packet_recv(void*, char *, int);
329
330 #endif
331
332 #endif
333