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