2013-12-04 21:33:17 +00:00
|
|
|
#ifndef RECVBUFF_H
|
|
|
|
#define RECVBUFF_H
|
1999-12-09 13:01:21 +00:00
|
|
|
|
|
|
|
#include "ntp.h"
|
2014-12-20 22:52:39 +00:00
|
|
|
#include "ntp_net.h"
|
2013-12-04 21:33:17 +00:00
|
|
|
#include "ntp_lists.h"
|
1999-12-09 13:01:21 +00:00
|
|
|
|
2008-08-18 14:26:05 +00:00
|
|
|
#include <isc/result.h>
|
|
|
|
|
1999-12-09 13:01:21 +00:00
|
|
|
/*
|
|
|
|
* recvbuf memory management
|
|
|
|
*/
|
|
|
|
#define RECV_INIT 10 /* 10 buffers initially */
|
|
|
|
#define RECV_LOWAT 3 /* when we're down to three buffers get more */
|
|
|
|
#define RECV_INC 5 /* get 5 more at a time */
|
|
|
|
#define RECV_TOOMANY 40 /* this is way too many buffers */
|
|
|
|
|
|
|
|
#if defined HAVE_IO_COMPLETION_PORT
|
|
|
|
# include "ntp_iocompletionport.h"
|
2014-12-20 22:52:39 +00:00
|
|
|
# include "ntp_timer.h"
|
1999-12-09 13:01:21 +00:00
|
|
|
|
|
|
|
# define RECV_BLOCK_IO() EnterCriticalSection(&RecvCritSection)
|
|
|
|
# define RECV_UNBLOCK_IO() LeaveCriticalSection(&RecvCritSection)
|
|
|
|
|
|
|
|
/* Return the event which is set when items are added to the full list
|
|
|
|
*/
|
2014-12-20 22:52:39 +00:00
|
|
|
extern HANDLE get_recv_buff_event(void);
|
1999-12-09 13:01:21 +00:00
|
|
|
#else
|
|
|
|
# define RECV_BLOCK_IO()
|
|
|
|
# define RECV_UNBLOCK_IO()
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Format of a recvbuf. These are used by the asynchronous receive
|
|
|
|
* routine to store incoming packets and related information.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2004-07-20 15:01:56 +00:00
|
|
|
* the maximum length NTP packet contains the NTP header, one Autokey
|
|
|
|
* request, one Autokey response and the MAC. Assuming certificates don't
|
2018-02-28 06:23:12 +00:00
|
|
|
* get too big, the maximum packet length is set arbitrarily at 1200.
|
|
|
|
* (was 1000, but that bumps on 2048 RSA keys)
|
1999-12-09 13:01:21 +00:00
|
|
|
*/
|
2018-02-28 06:23:12 +00:00
|
|
|
#define RX_BUFF_SIZE 1200 /* hail Mary */
|
1999-12-09 13:01:21 +00:00
|
|
|
|
2008-08-18 14:26:05 +00:00
|
|
|
|
|
|
|
typedef struct recvbuf recvbuf_t;
|
|
|
|
|
1999-12-09 13:01:21 +00:00
|
|
|
struct recvbuf {
|
2014-12-20 22:52:39 +00:00
|
|
|
recvbuf_t * link; /* next in list */
|
1999-12-09 13:01:21 +00:00
|
|
|
union {
|
2014-12-20 22:52:39 +00:00
|
|
|
sockaddr_u X_recv_srcadr;
|
|
|
|
caddr_t X_recv_srcclock;
|
|
|
|
struct peer * X_recv_peer;
|
1999-12-09 13:01:21 +00:00
|
|
|
} X_from_where;
|
2014-12-20 22:52:39 +00:00
|
|
|
#define recv_srcadr X_from_where.X_recv_srcadr
|
|
|
|
#define recv_srcclock X_from_where.X_recv_srcclock
|
|
|
|
#define recv_peer X_from_where.X_recv_peer
|
2013-12-04 21:33:17 +00:00
|
|
|
#ifndef HAVE_IO_COMPLETION_PORT
|
2014-12-20 22:52:39 +00:00
|
|
|
sockaddr_u srcadr; /* where packet came from */
|
1999-12-09 13:01:21 +00:00
|
|
|
#else
|
2014-12-20 22:52:39 +00:00
|
|
|
int recv_srcadr_len;/* filled in on completion */
|
1999-12-09 13:01:21 +00:00
|
|
|
#endif
|
2014-12-20 22:52:39 +00:00
|
|
|
endpt * dstadr; /* address pkt arrived on */
|
|
|
|
SOCKET fd; /* fd on which it was received */
|
|
|
|
int msg_flags; /* Flags received about the packet */
|
|
|
|
l_fp recv_time; /* time of arrival */
|
|
|
|
void (*receiver)(struct recvbuf *); /* callback */
|
|
|
|
int recv_length; /* number of octets received */
|
1999-12-09 13:01:21 +00:00
|
|
|
union {
|
2014-12-20 22:52:39 +00:00
|
|
|
struct pkt X_recv_pkt;
|
|
|
|
u_char X_recv_buffer[RX_BUFF_SIZE];
|
1999-12-09 13:01:21 +00:00
|
|
|
} recv_space;
|
2014-12-20 22:52:39 +00:00
|
|
|
#define recv_pkt recv_space.X_recv_pkt
|
|
|
|
#define recv_buffer recv_space.X_recv_buffer
|
|
|
|
int used; /* reference count */
|
1999-12-09 13:01:21 +00:00
|
|
|
};
|
|
|
|
|
2014-12-20 22:52:39 +00:00
|
|
|
extern void init_recvbuff(int);
|
1999-12-09 13:01:21 +00:00
|
|
|
|
|
|
|
/* freerecvbuf - make a single recvbuf available for reuse
|
|
|
|
*/
|
2014-12-20 22:52:39 +00:00
|
|
|
extern void freerecvbuf(struct recvbuf *);
|
1999-12-09 13:01:21 +00:00
|
|
|
|
|
|
|
/* Get a free buffer (typically used so an async
|
|
|
|
* read can directly place data into the buffer
|
|
|
|
*
|
|
|
|
* The buffer is removed from the free list. Make sure
|
|
|
|
* you put it back with freerecvbuf() or
|
|
|
|
*/
|
2014-12-20 22:52:39 +00:00
|
|
|
|
|
|
|
/* signal safe - no malloc */
|
|
|
|
extern struct recvbuf *get_free_recv_buffer(void);
|
2016-04-27 05:37:54 +00:00
|
|
|
/* signal unsafe - may malloc, never returs NULL */
|
2014-12-20 22:52:39 +00:00
|
|
|
extern struct recvbuf *get_free_recv_buffer_alloc(void);
|
1999-12-09 13:01:21 +00:00
|
|
|
|
|
|
|
/* Add a buffer to the full list
|
|
|
|
*/
|
2014-12-20 22:52:39 +00:00
|
|
|
extern void add_full_recv_buffer(struct recvbuf *);
|
1999-12-09 13:01:21 +00:00
|
|
|
|
|
|
|
/* number of recvbufs on freelist */
|
2014-12-20 22:52:39 +00:00
|
|
|
extern u_long free_recvbuffs(void);
|
|
|
|
extern u_long full_recvbuffs(void);
|
|
|
|
extern u_long total_recvbuffs(void);
|
|
|
|
extern u_long lowater_additions(void);
|
1999-12-09 13:01:21 +00:00
|
|
|
|
|
|
|
/* Returns the next buffer in the full list.
|
|
|
|
*
|
|
|
|
*/
|
2014-12-20 22:52:39 +00:00
|
|
|
extern struct recvbuf *get_full_recv_buffer(void);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* purge_recv_buffers_for_fd() - purges any previously-received input
|
|
|
|
* from a given file descriptor.
|
|
|
|
*/
|
2016-04-27 05:37:54 +00:00
|
|
|
extern void purge_recv_buffers_for_fd(int);
|
1999-12-09 13:01:21 +00:00
|
|
|
|
2008-08-18 14:26:05 +00:00
|
|
|
/*
|
|
|
|
* Checks to see if there are buffers to process
|
|
|
|
*/
|
2014-12-20 22:52:39 +00:00
|
|
|
extern isc_boolean_t has_full_recv_buffer(void);
|
1999-12-09 13:01:21 +00:00
|
|
|
|
2013-12-04 21:33:17 +00:00
|
|
|
#endif /* RECVBUFF_H */
|