Fix a serious bug in the NTPD loopfilter. Basically what happens is that
[dragonfly.git] / contrib / ntp / include / recvbuff.h
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 is a full length NTP control message with
43  *  the maximum length message authenticator.  I hate to hard-code 468 and 12,
44  *  but only a few modules include ntp_control.h...
45  */   
46 #define RX_BUFF_SIZE    (468+12+MAX_MAC_LEN)
47
48 struct recvbuf {
49         struct recvbuf *next;           /* next buffer in chain */
50         union {
51                 struct sockaddr_in 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_in srcadr;      /* where packet came from */
64 #endif
65         struct interface *dstadr;       /* interface datagram arrived thru */
66         int 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