ntp.h revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* Copyright (c) 1996 by Sun Microsystems, Inc.
* All Rights Reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* ntp.h - NTP definitions for the masses
*/
#include "ntp_types.h"
/*
* How to get signed characters. On machines where signed char works,
* use it. On machines where signed char doesn't work, char had better
* be signed.
*/
#ifdef NEED_S_CHAR_TYPEDEF
# if SIZEOF_SIGNED_CHAR
typedef signed char s_char;
# else
typedef char s_char;
# endif
/* XXX: Why is this sequent bit INSIDE this test? */
# ifdef sequent
# endif
#endif
#ifndef TRUE
# define TRUE 1
#endif /* TRUE */
#ifndef FALSE
# define FALSE 0
#endif /* FALSE */
/*
* NTP protocol parameters. See section 3.2.6 of the specification.
*/
/*
* Loop filter parameters. See section 5.1 of the specification.
*
* Note that these are appropriate for a crystal time base. If your
* system clock is line frequency controlled you should read the
* specification for appropriate modifications. Note that the
* loop filter code will have to change if you change CLOCK_MAX
* to be greater than or equal to 500 ms.
*
* Note these parameters have been rescaled for a time constant range from
* 0 through 10, with 2 corresoponding to the old time constant of 0.
*/
/*
* Event timers are actually implemented as a sorted queue of expiry
* times. The queue is slotted, with each slot holding timers which
* expire in a 2**(NTP_MINPOLL-1) (8) second period. The timers in
* each slot are sorted by increasing expiry time. The number of
* slots is 2**(NTP_MAXPOLL-(NTP_MINPOLL-1)), or 512, to cover a time
* period of 2**NTP_MAXPOLL (16384) seconds into the future before
* wrapping.
*/
#define EVENT_TIMEOUT 0 /* one second, that is */
struct event {
void (*event_handler) P((struct peer *));
/* routine to call to handle event */
};
#ifdef TIMERQUEUE_DEBUG
/* use the non-macro versions of these routines from xntpd/ntp_timer.c */
#else /* TIMERQUEUE_DEBUG */
#ifndef SYS_WINNT
/*
* TIMER_ENQUEUE() puts stuff on the timer queue. It takes as
* arguments (ea), an array of event slots, and (iev), the event
* to be inserted. This one searches the hash bucket from the
* end, and is about optimum for the timing requirements of
* NTP peers.
*/
do { \
\
} while(0)
/*
* TIMER_INSERT() also puts stuff on the timer queue, but searches the
* bucket from the top. This is better for things that do very short
* time outs, like clock support.
*/
do { \
\
while (ev->event_time != 0 && \
} while(0)
/*
* Remove an event from the queue.
*/
#define TIMER_DEQUEUE(ev) \
do { \
} \
} while (0)
#else /* SYS_WINNT */
/* Versions of TIMER_ENQUEUE, TIMER_INSERT, and TIMER_DEQUEUE for Windows NT */
{ \
\
\
\
}
{ \
\
\
while (ev->event_time != 0 && \
\
}
#define TIMER_DEQUEUE(ev) \
{ \
\
\
} \
\
}
#endif /* SYS_WINNT */
#endif /* TIMERQUEUE_DEBUG */
/*
* The interface structure is used to hold the addresses and socket
* numbers of each of the interfaces we are using.
*/
struct interface {
int fd; /* socket this is opened on */
int bfd; /* socket for receiving broadcasts */
int flags; /* interface flags */
int last_ttl; /* last TTL specified */
volatile long received; /* number of incoming packets */
long sent; /* number of outgoing packets */
long notsent; /* number of send failures */
};
/*
* Flags for interfaces
*/
/*
* Define flasher bits (tests 1 through 8 in packet procedure)
* These reveal the state at the last grumble from the peer and are
* most handy for diagnosing problems, even if not strictly a state
* variable in the spec. These are recorded in the peer structure.
*/
/*
* The peer structure. Holds state information relating to the guys
* we are peering with. Most of this stuff is from section 3.2 of the
* spec.
*/
struct peer {
/* **Start of clear-to-zero area.*** */
/* Everything that is cleared to zero goes below here */
#define clear_to_zero valid
/* ***End of clear-to-zero area.*** */
/* Everything that is cleared to zero goes above here */
#define end_clear_to_zero filter_order[0]
/*
* statistic counters
*/
};
/*
* Values for peer.leap, sys_leap
*/
/*
* Values for peer.mode
*/
#define MODE_UNSPEC 0 /* unspecified (probably old NTP version) */
/*
* Values for peer.stratum, sys_stratum
*/
/* A stratum of 0 in the packet is mapped to 16 internally */
/*
* Values for peer.flags
*/
/*
* Definitions for the clear() routine. We use memset() to clear
* the parts of the peer structure which go to zero. These are
* used to calculate the start address and length of the area.
*/
#define CLEAR_TO_ZERO(p) ((char *)&((p)->clear_to_zero))
#define END_CLEAR_TO_ZERO(p) ((char *)&((p)->end_clear_to_zero))
- CLEAR_TO_ZERO((struct peer *)0))
/*
* Reference clock identifiers (for pps signal)
*/
/*
* Reference clock types. Added as necessary.
*/
#define REFCLK_NONE 0 /* unknown or missing */
/*
* We tell reference clocks from real peers by giving the reference
* clocks an address of the form 127.127.t.u, where t is the type and
* u is the unit number. We define some of this here since we will need
* some sanity checks to make sure this address isn't interpretted as
* that of a normal peer.
*/
== REFCLOCK_ADDR)
/*
* Macro for checking for invalid addresses. This is really, really
* gross, but is needed so no one configures a host on net 127 now that
* we're encouraging it the the configuration file.
*/
#define LOOPBACKADR 0x7f000001
#define LOOPNETMASK 0xff000000
== (LOOPBACKADR & LOOPNETMASK)) \
/*
* Utilities for manipulating addresses and port numbers
*/
/*
* NTP packet format. The mac field is optional. It isn't really
* an l_fp either, but for now declaring it that way is convenient.
* See Appendix A in the specification.
*
* Note that all u_fp and l_fp values arrive in network byte order
* and must be converted (except the mac, which isn't, really).
*/
struct pkt {
/*l_fp mac;*/
};
/*
* Packets can come in two flavours, one with a mac and one without.
*/
/*
* Minimum size of packet with a MAC: has to include at least a key number.
*/
/*
* Stuff for extracting things from li_vn_mode
*/
/*
* Stuff for putting things back into li_vn_mode
*/
/*
* Dealing with stratum. 0 gets mapped to 16 incoming, and back to 0
* on output.
*/
(STRATUM_UNSPEC) : (s)))
(STRATUM_PKT_UNSPEC) : (s)))
/*
* Format of a recvbuf. These are used by the asynchronous receive
* routine to store incoming packets and related information.
*/
/*
* the maximum length NTP packet is a full length NTP control message with
* the maximum length message authenticator. I hate to hard-code 468 and 12,
* but only a few modules include ntp_control.h...
*/
struct recvbuf {
union {
struct sockaddr_in X_recv_srcadr;
} X_from_where;
int fd; /* fd on which it was received */
int recv_length; /* number of octets received */
union {
struct pkt X_recv_pkt;
char X_recv_buffer[RX_BUFF_SIZE];
} recv_space;
};
/*
*/
#define EVNT_UNSPEC 0
#define EVNT_SYSRESTART 1
#define EVNT_SYSFAULT 2
#define EVNT_SYNCCHG 3
#define EVNT_PEERSTCHG 4
#define EVNT_CLOCKRESET 5
#define EVNT_BADDATETIM 6
#define EVNT_CLOCKEXCPT 7
/*
* Clock event codes
*/
#define CEVNT_NOMINAL 0
#define CEVNT_TIMEOUT 1
#define CEVNT_BADREPLY 2
#define CEVNT_FAULT 3
#define CEVNT_PROP 4
#define CEVNT_BADDATE 5
#define CEVNT_BADTIME 6
#define CEVNT_MAX CEVNT_BADTIME
/*
* Very misplaced value. Default port through which we send traps.
*/
#define TRAPPORT 18447
/*
* To speed lookups, peers are hashed by the low order bits of the remote
* IP address. These definitions relate to that.
*/
#define HASH_SIZE 32
/*
* The poll update procedure takes an extra argument which controls
* how a random perturbation is applied to peer.timer. The choice is
* to not randomize at all, to randomize only if we're going to update
* peer.timer, and to randomize no matter what (almost, the algorithm
* is that we apply the random value if it is less than the current
* timer count).
*/
#define POLL_NOTRANDOM 0 /* don't randomize */
/*
* How we randomize polls. The poll interval is a power of two.
* We chose a random value which is between 1/4 and 3/4 of the
* poll interval we would normally use and which is an even multiple
* of the EVENT_TIMEOUT. The random number routine, given an argument
* spread value of n, returns an integer between 0 and (1<<n)-1. This
* is shifted by EVENT_TIMEOUT and added to the base value.
*/
/*
* min, min3 and max. Makes it easier to transliterate the spec without
* thinking about it.
*/
#define min(a,b) (((a) < (b)) ? (a) : (b))
#define max(a,b) (((a) > (b)) ? (a) : (b))
/*
* Configuration items. These are for the protocol module (proto_config())
*/
#define PROTO_BROADCLIENT 1
#define PROTO_AUTHENTICATE 3
#define PROTO_BROADDELAY 4
#define PROTO_MULTICAST_ADD 6
#define PROTO_MULTICAST_DEL 7
#define PROTO_PLL 8
#define PROTO_PPS 9
#define PROTO_MONITOR 10
#define PROTO_FILEGEN 11
/*
* Configuration items for the loop filter
*/
/*
* Configuration items for the stats printer
*/
/*
* Default parameters. We use these in the absence of something better.
*/
/* (~4 ms as s_fp) */
/* (~100 us as l_fp.l_f) */
/*
* Structure used optionally for monitoring when this is turned on.
*/
struct mon_data {
};
/*
* Values used with mon_enabled to indicate reason for enabling monitoring
*/
/*
* Structure used for restrictlist entries
*/
struct restrictlist {
};
/*
* Access flags
*/
#define RES_ALLFLAGS \
/*
* Match flags
*/
/*
* Restriction configuration ops
*/
/*
* Experimental alternate selection algorithm identifiers
*/
#define SELECT_1 1
#define SELECT_2 2
#define SELECT_3 3
#define SELECT_4 4
#define SELECT_5 5
/*
* Endpoint structure for the select algorithm
*/
struct endpoint {
};