xref: /netbsd/sys/netinet/dccp_var.h (revision 46d75a7b)
1 /*	$KAME: dccp_var.h,v 1.29 2005/11/03 14:59:28 nishida Exp $	*/
2 /*	$NetBSD: dccp_var.h,v 1.7 2022/10/28 05:20:08 ozaki-r Exp $ */
3 
4 /*
5  * Copyright (c) 2003 Joacim H�ggmark, 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 preferred 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 	u_int32_t	d_maxseg;	/* Maximum segment size */
100 	char		options[DCCP_MAX_OPTIONS];
101 	u_int8_t	optlen;
102 	char		features[DCCP_MAX_OPTIONS];
103 	u_int8_t	featlen;
104 	u_int8_t	ccval;		/* ccval */
105 
106 	u_int32_t	avgpsize;	/* Average packet size */
107 
108 	/* variables for the local (receiver-side) ack vector */
109 	u_char *ackvector;  /* For acks, 2 bits per packet */
110 	u_char *av_hp;	/* head ptr for ackvector */
111 	u_int16_t av_size;
112 	dccp_seq av_hs, av_ts; /* highest/lowest seq no in ackvector */
113 
114 	u_int8_t remote_ackvector; /* Is recv side using AckVector? */
115 	u_char      shortseq; /* use short seq number */
116 	u_int32_t	scode;    /* service core */
117 	struct ref_seq	ref_seq;    /* reference sequence number */
118 	struct ref_seq	ref_pseq;   /* reference peer sequence number */
119 
120 #ifndef __FreeBSD__
121 #ifndef INP_IPV6
122 #define INP_IPV6	0x1
123 #endif
124 #ifndef INP_IPV4
125 #define INP_IPV4	0x2
126 #endif
127 	u_int8_t	inp_vflag;
128 	u_int8_t	inp_ip_ttl;
129 	u_int8_t	inp_ip_tos;
130 #endif
131 	u_int8_t	pktlen[DCCP_MAX_PKTS];
132 	u_int16_t	pktlenidx;
133 	u_int16_t	pktcnt;
134 };
135 
136 #ifdef _KERNEL
137 struct inp_dp {
138 	struct inpcb inp;
139 	struct dccpcb dp;
140 };
141 #endif
142 
143 #if defined(_NETINET_IN_PCB_H_) && defined(_SYS_SOCKETVAR_H_)
144 struct xdccpcb {
145 	size_t		xd_len;
146 	struct	inpcb	xd_inp;
147 	struct	dccpcb	xd_dp;
148 #ifdef __FreeBSD__
149 	struct	xsocket	xd_socket;
150 #endif
151 };
152 #endif
153 
154 #define	intodccpcb(ip)	((struct dccpcb *)((ip)->inp_ppcb))
155 #define	dptosocket(dp)	((dp)->d_inpcb->inp_socket)
156 
157 struct	dccpstat {
158 	u_long	dccps_connattempt;	/* Initiated connections */
159 	u_long	dccps_connects;		/* Established connections */
160 	u_long	dccps_ipackets;		/* Total input packets */
161 	u_long	dccps_ibytes;		/* Total input bytes */
162 	u_long	dccps_drops;		/* Dropped packets  */
163 	u_long	dccps_badsum;		/* Checksum error */
164 	u_long	dccps_badlen;		/* Bad length */
165 	u_long	dccps_badseq;		/* Sequence number not inside loss_window  */
166 	u_long	dccps_noport;		/* No socket on port */
167 
168 	/* TCPlike Sender */
169 	u_long	tcplikes_send_conn;	/* Connections established */
170 	u_long	tcplikes_send_reploss;	/* Data packets reported lost */
171 	u_long	tcplikes_send_assloss;	/* Data packets assumed lost */
172 	u_long	tcplikes_send_ackrecv;	/* Acknowledgement (w/ Ack Vector) packets received */
173 	u_long	tcplikes_send_missack;	/* Ack packets assumed lost */
174 	u_long	tcplikes_send_badseq;	/* Bad sequence number on outgoing packet */
175 	u_long	tcplikes_send_memerr;	/* Memory allocation errors */
176 
177 	/* TCPlike Receiver */
178 	u_long	tcplikes_recv_conn;	/* Connections established */
179 	u_long	tcplikes_recv_datarecv; /* Number of data packets received */
180 	u_long	tcplikes_recv_ackack;	/* Ack-on-acks received */
181 	u_long	tcplikes_recv_acksent;	/* Acknowledgement (w/ Ack Vector) packets sent */
182 	u_long	tcplikes_recv_memerr;	/* Memory allocation errors */
183 
184 	/*	Some CCID statistic should also be here */
185 
186 	u_long	dccps_opackets;		/* Total output packets */
187 	u_long	dccps_obytes;		/* Total output bytes */
188 
189 	/* TFRC Sender */
190 	u_long	tfrcs_send_conn;	/* Connections established */
191 	u_long	tfrcs_send_nomem;	/* Not enough memory */
192 	u_long	tfrcs_send_erropt;	/* option error */
193 	u_long	tfrcs_send_noopt;	/* no option  */
194 	u_long	tfrcs_send_fbacks; 	/* sent feedbacks */
195 
196 	/* TFRC Receiver */
197 	u_long	tfrcs_recv_conn;	/* established connection  */
198 	u_long	tfrcs_recv_erropt;	/* option error */
199 	u_long	tfrcs_recv_losts;	/* lost packets */
200 	u_long	tfrcs_recv_nomem;	/* no memory */
201 	u_long	tfrcs_recv_noopt;	/* no option */
202 	u_long	tfrcs_recv_fbacks; 	/* receipt feedbacks */
203 
204 };
205 
206 /*
207  * Names for DCCP sysctl objects
208  */
209 #define DCCPCTL_LOGINVAIN       	1
210 #define DCCPCTL_DOFEATURENEGO       2
211 
212 /*
213  *	DCCP States
214  */
215 
216 #define DCCPS_CLOSED	0
217 #define DCCPS_LISTEN	1
218 #define DCCPS_REQUEST	2
219 #define DCCPS_RESPOND	3
220 #define DCCPS_ESTAB	4
221 #define DCCPS_SERVER_CLOSE	5
222 #define DCCPS_CLIENT_CLOSE	6
223 #define DCCPS_TIME_WAIT 7
224 
225 #define DCCP_NSTATES	8
226 
227 #ifdef DCCPSTATES
228 const char *dccpstates[] = {
229 	"CLOSED",	"LISTEN",	"REQEST",	"RESPOND",
230 	"ESTABLISHED",	"SERVER-CLOSE",	"CLIENT-CLOSE", "TIME_WAIT",
231 };
232 #else
233 extern const char *dccpstates[];
234 #endif
235 
236 #define DCCP_UNDEF	0
237 #define DCCP_LISTENER	1
238 #define DCCP_SERVER	2
239 #define DCCP_CLIENT	3
240 
241 #define DCCP_SEQ_LT(a, b)	((int)(((a) << 16) - ((b) << 16)) < 0)
242 #define DCCP_SEQ_GT(a, b)	((int)(((a) << 16) - ((b) << 16)) > 0)
243 
244 /*
245  * Names for DCCP sysctl objects
246  */
247 #define	DCCPCTL_DEFCCID		1	/* Default CCID */
248 #define DCCPCTL_STATS		2	/* statistics (read-only) */
249 #define DCCPCTL_PCBLIST		3
250 #define DCCPCTL_SENDSPACE	4
251 #define DCCPCTL_RECVSPACE	5
252 
253 #ifdef _KERNEL
254 
255 #ifdef DCCP_DEBUG_ON
256 #define DCCP_DEBUG(args)	dccp_log args
257 #else
258 #define DCCP_DEBUG(args)
259 #endif
260 
261 #ifdef ACKDEBUG
262 #define ACK_DEBUG(args) dccp_log args
263 #else
264 #define ACK_DEBUG(args)
265 #endif
266 
267 extern const struct	pr_usrreqs dccp_usrreqs;
268 extern struct	inpcbhead dccpb;
269 extern struct	inpcbinfo dccpbinfo;
270 extern u_long	dccp_sendspace;
271 extern u_long	dccp_recvspace;
272 extern struct	dccpstat dccpstat; /* dccp statistics */
273 extern int	dccp_log_in_vain; /* if we should log connections to
274 				     ports w/o listeners */
275 extern int	dccp_do_feature_nego;
276 
277 extern struct inpcbtable dccpbtable;
278 
279 /* These four functions are called from inetsw (in_proto.c) */
280 void	dccp_init(void);
281 void	dccp_log(int, const char *, ...);
282 void	dccp_input(struct mbuf *, int, int);
283 void*	dccp_ctlinput(int, const struct sockaddr *, void *);
284 int	dccp_ctloutput(int , struct socket *, struct sockopt *);
285 int	dccp_sysctl(int *, u_int, void *, size_t *, void *, size_t);
286 int	dccp_usrreq(struct socket *, int, struct mbuf *, struct mbuf *,
287     struct mbuf *, struct lwp *);
288 
289 void	dccp_notify(struct inpcb *, int);
290 struct dccpcb *
291 	dccp_newdccpcb(int, void *);
292 int	dccp_shutdown(struct socket *);
293 int	dccp_output(struct dccpcb *, u_int8_t);
294 int	dccp_doconnect(struct socket *, struct sockaddr *, struct lwp *, int);
295 int	dccp_add_option(struct dccpcb *, u_int8_t, char *, u_int8_t);
296 int	dccp_add_feature(struct dccpcb *, u_int8_t, u_int8_t,  char *,
297     u_int8_t);
298 int	dccp_detach(struct socket *);
299 int	dccp_attach(struct socket *, int);
300 int	dccp_abort(struct socket *);
301 int	dccp_disconnect(struct socket *);
302 int	dccp_send(struct socket *, struct mbuf *, struct sockaddr *,
303 		  struct mbuf *, struct lwp *);
304 void	dccp_retrans_t(void *);
305 void	dccp_connect_t(void *);
306 
307 /* No cc functions */
308 void* dccp_nocc_init(struct dccpcb *);
309 void  dccp_nocc_free(void *);
310 int   dccp_nocc_send_packet(void*, long);
311 void  dccp_nocc_send_packet_sent(void *, int, long);
312 void  dccp_nocc_packet_recv(void*, char *, int);
313 
314 #endif
315 
316 #endif
317