1 /* $NetBSD: recvbuff.h,v 1.4 2007/06/24 16:55:12 kardel Exp $ */
3 #if !defined __recvbuff_h
12 #include "ntp_types.h"
15 #include <isc/result.h>
18 * recvbuf memory management
20 #define RECV_INIT 10 /* 10 buffers initially */
21 #define RECV_LOWAT 3 /* when we're down to three buffers get more */
22 #define RECV_INC 5 /* get 5 more at a time */
23 #define RECV_TOOMANY 40 /* this is way too many buffers */
25 #if defined HAVE_IO_COMPLETION_PORT
26 # include "ntp_iocompletionport.h"
27 #include "ntp_timer.h"
29 # define RECV_BLOCK_IO() EnterCriticalSection(&RecvCritSection)
30 # define RECV_UNBLOCK_IO() LeaveCriticalSection(&RecvCritSection)
32 /* Return the event which is set when items are added to the full list
34 extern HANDLE get_recv_buff_event
P((void));
36 # define RECV_BLOCK_IO()
37 # define RECV_UNBLOCK_IO()
42 * Format of a recvbuf. These are used by the asynchronous receive
43 * routine to store incoming packets and related information.
47 * the maximum length NTP packet contains the NTP header, one Autokey
48 * request, one Autokey response and the MAC. Assuming certificates don't
49 * get too big, the maximum packet length is set arbitrarily at 1000.
51 #define RX_BUFF_SIZE 1000 /* hail Mary */
54 typedef struct recvbuf recvbuf_t
;
57 ISC_LINK(recvbuf_t
) link
;
59 struct sockaddr_storage X_recv_srcadr
;
60 caddr_t X_recv_srcclock
;
61 struct peer
*X_recv_peer
;
63 #define recv_srcadr X_from_where.X_recv_srcadr
64 #define recv_srcclock X_from_where.X_recv_srcclock
65 #define recv_peer X_from_where.X_recv_peer
66 #if defined HAVE_IO_COMPLETION_PORT
69 struct sockaddr_storage srcadr
; /* where packet came from */
71 int src_addr_len
; /* source address length */
72 struct interface
*dstadr
; /* interface datagram arrived thru */
73 SOCKET fd
; /* fd on which it was received */
74 int msg_flags
; /* Flags received about the packet */
75 l_fp recv_time
; /* time of arrival */
76 void (*receiver
) P((struct recvbuf
*)); /* routine to receive buffer */
77 int recv_length
; /* number of octets received */
79 struct pkt X_recv_pkt
;
80 u_char X_recv_buffer
[RX_BUFF_SIZE
];
83 #define recv_pkt recv_space.X_recv_pkt
84 #define recv_buffer recv_space.X_recv_buffer
87 extern void init_recvbuff
P((int));
89 /* freerecvbuf - make a single recvbuf available for reuse
91 extern void freerecvbuf
P((struct recvbuf
*));
93 /* Get a free buffer (typically used so an async
94 * read can directly place data into the buffer
96 * The buffer is removed from the free list. Make sure
97 * you put it back with freerecvbuf() or
99 extern struct recvbuf
*get_free_recv_buffer
P((void)); /* signal safe - no malloc */
100 extern struct recvbuf
*get_free_recv_buffer_alloc
P((void)); /* signal unsafe - may malloc */
102 /* Add a buffer to the full list
104 extern void add_full_recv_buffer
P((struct recvbuf
*));
106 /*extern void process_recv_buffers P((void)); */
108 /* number of recvbufs on freelist */
109 extern u_long free_recvbuffs
P((void));
110 extern u_long full_recvbuffs
P((void));
111 extern u_long total_recvbuffs
P((void));
112 extern u_long lowater_additions
P((void));
114 /* Returns the next buffer in the full list.
117 extern struct recvbuf
*get_full_recv_buffer
P((void));
120 * Checks to see if there are buffers to process
122 extern isc_boolean_t has_full_recv_buffer
P((void));
124 #endif /* defined __recvbuff_h */