xref: /freebsd/contrib/ntp/include/recvbuff.h (revision 1e413cf93298b5b97441a21d9a50fdcd0ee9945e)
1 #if !defined __recvbuff_h
2 #define __recvbuff_h
3 
4 #ifdef HAVE_CONFIG_H
5 # include <config.h>
6 #endif
7 
8 #include "ntp.h"
9 #include "ntp_fp.h"
10 #include "ntp_types.h"
11 
12 /*
13  * recvbuf memory management
14  */
15 #define RECV_INIT	10	/* 10 buffers initially */
16 #define RECV_LOWAT	3	/* when we're down to three buffers get more */
17 #define RECV_INC	5	/* get 5 more at a time */
18 #define RECV_TOOMANY	40	/* this is way too many buffers */
19 
20 #if defined HAVE_IO_COMPLETION_PORT
21 # include "ntp_iocompletionport.h"
22 #include "ntp_timer.h"
23 
24 # define RECV_BLOCK_IO()	EnterCriticalSection(&RecvCritSection)
25 # define RECV_UNBLOCK_IO()	LeaveCriticalSection(&RecvCritSection)
26 
27 /*  Return the event which is set when items are added to the full list
28  */
29 extern HANDLE	get_recv_buff_event P((void));
30 #else
31 # define RECV_BLOCK_IO()
32 # define RECV_UNBLOCK_IO()
33 #endif
34 
35 
36 /*
37  * Format of a recvbuf.  These are used by the asynchronous receive
38  * routine to store incoming packets and related information.
39  */
40 
41 /*
42  *  the maximum length NTP packet contains the NTP header, one Autokey
43  *  request, one Autokey response and the MAC. Assuming certificates don't
44  *  get too big, the maximum packet length is set arbitrarily at 1000.
45  */
46 #define	RX_BUFF_SIZE	1000		/* hail Mary */
47 
48 struct recvbuf {
49 	struct recvbuf *next;		/* next buffer in chain */
50 	union {
51 		struct sockaddr_storage X_recv_srcadr;
52 		caddr_t X_recv_srcclock;
53 		struct peer *X_recv_peer;
54 	} X_from_where;
55 #define recv_srcadr	X_from_where.X_recv_srcadr
56 #define	recv_srcclock	X_from_where.X_recv_srcclock
57 #define recv_peer	X_from_where.X_recv_peer
58 #if defined HAVE_IO_COMPLETION_PORT
59         IoCompletionInfo	iocompletioninfo;
60 	WSABUF		wsabuff;
61 	DWORD		AddressLength;
62 #else
63 	struct sockaddr_storage srcadr;	/* where packet came from */
64 #endif
65 	struct interface *dstadr;	/* interface datagram arrived thru */
66 	SOCKET	fd;			/* fd on which it was received */
67 	l_fp recv_time;			/* time of arrival */
68 	void (*receiver) P((struct recvbuf *)); /* routine to receive buffer */
69 	int recv_length;		/* number of octets received */
70 	union {
71 		struct pkt X_recv_pkt;
72 		u_char X_recv_buffer[RX_BUFF_SIZE];
73 	} recv_space;
74 #define	recv_pkt	recv_space.X_recv_pkt
75 #define	recv_buffer	recv_space.X_recv_buffer
76 };
77 
78 extern	void	init_recvbuff	P((int));
79 
80 /* freerecvbuf - make a single recvbuf available for reuse
81  */
82 extern	void	freerecvbuf P((struct recvbuf *));
83 
84 
85 extern	struct recvbuf * getrecvbufs P((void));
86 
87 /*  Get a free buffer (typically used so an async
88  *  read can directly place data into the buffer
89  *
90  *  The buffer is removed from the free list. Make sure
91  *  you put it back with freerecvbuf() or
92  */
93 extern	struct recvbuf *get_free_recv_buffer P((void));
94 
95 /*   Add a buffer to the full list
96  */
97 extern	void	add_full_recv_buffer	 P((struct recvbuf *));
98 
99 /*extern	void	process_recv_buffers	 P((void)); */
100 
101 /* number of recvbufs on freelist */
102 extern u_long free_recvbuffs P((void));
103 extern u_long full_recvbuffs P((void));
104 extern u_long total_recvbuffs P((void));
105 extern u_long lowater_additions P((void));
106 
107 /*  Returns the next buffer in the full list.
108  *
109  */
110 extern	struct recvbuf *get_full_recv_buffer P((void));
111 
112 #endif /* defined __recvbuff_h */
113 
114