?? ntp.h
字號:
/* * ntp.h - NTP definitions for the masses */#ifndef NTP_H#define NTP_H#include "ntp_types.h"#include <math.h>#ifdef OPENSSL#include "ntp_crypto.h"#endif /* OPENSSL */#include <ntp_random.h>#include <isc/boolean.h>/* * Calendar arithmetic - contributed by G. Healton */#define YEAR_BREAK 500 /* years < this are tm_year values: * Break < AnyFourDigitYear && Break > * Anytm_yearYear */#define YEAR_PIVOT 98 /* 97/98: years < this are year 2000+ * FYI: official UNIX pivot year is * 68/69 *//* * Number of Days since 1 BC Gregorian to 1 January of given year */#define julian0(year) (((year) * 365 ) + ((year) > 0 ? (((year) + 3) \ / 4 - ((year - 1) / 100) + ((year - 1) / \ 400)) : 0))/* * Number of days since start of NTP time to 1 January of given year */#define ntp0(year) (julian0(year) - julian0(1900))/* * Number of days since start of UNIX time to 1 January of given year */#define unix0(year) (julian0(year) - julian0(1970))/* * LEAP YEAR test for full 4-digit years (e.g, 1999, 2010) */#define isleap_4(y) ((y) % 4 == 0 && !((y) % 100 == 0 && !(y % \ 400 == 0)))/* * LEAP YEAR test for tm_year (struct tm) years (e.g, 99, 110) */#define isleap_tm(y) ((y) % 4 == 0 && !((y) % 100 == 0 && !(((y) \ + 1900) % 400 == 0)))/* * to convert simple two-digit years to tm_year style years: * * if (year < YEAR_PIVOT) * year += 100; * * to convert either two-digit OR tm_year years to four-digit years: * * if (year < YEAR_PIVOT) * year += 100; * * if (year < YEAR_BREAK) * year += 1900; *//* * 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_CHARtypedef signed char s_char;# elsetypedef char s_char;# endif /* XXX: Why is this sequent bit INSIDE this test? */# ifdef sequent# undef SO_RCVBUF# undef SO_SNDBUF# 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. */#define NTP_VERSION ((u_char)4) /* current version number */#define NTP_OLDVERSION ((u_char)1) /* oldest credible version */#define NTP_PORT 123 /* included for non-unix machines *//* * Poll interval parameters */#define NTP_UNREACH 24 /* poll unreach threshold */#define NTP_MINPOLL 4 /* log2 min poll interval (16 s) */#define NTP_MINDPOLL 6 /* log2 default min poll (64 s) */#define NTP_MAXDPOLL 10 /* log2 default max poll (~17 m) */#define NTP_MAXPOLL 17 /* log2 max poll interval (~36 h) */#define NTP_BURST 8 /* packets in burst */#define BURST_DELAY 2 /* interburst delay (s) */#define RESP_DELAY 1 /* crypto response delay (s) *//* * Clock filter algorithm tuning parameters */#define MAXDISPERSE 16. /* max dispersion */#define NTP_SHIFT 8 /* clock filter stages */#define NTP_FWEIGHT .5 /* clock filter weight *//* * Selection algorithm tuning parameters */#define NTP_MINCLOCK 3 /* min survivors */#define NTP_MAXCLOCK 10 /* max candidates */#define NTP_MAXASSOC 50 /* max associations */#define MINDISPERSE .005 /* min dispersion increment */#define MAXDISTANCE 1. /* max root distance (select threshold) */#define CLOCK_SGATE 3. /* popcorn spike gate */#define HUFFPUFF 900 /* huff-n'-puff sample interval (s) */#define MAXHOP 2 /* anti-clockhop threshold */#define MAX_TTL 8 /* max ttl mapping vector size */#define BEACON 7200 /* manycast beacon interval */#define NTP_MAXEXTEN 1024 /* max extension field size *//* * Miscellaneous stuff */#define NTP_MAXKEY 65535 /* max authentication key number *//* * Limits of things */#define MAXFILENAME 128 /* max length of file name */#define MAXHOSTNAME 512 /* max length of host/node name */#define NTP_MAXSTRLEN 256 /* max string length */#define MAXINTERFACES 512 /* max number of interfaces *//* * Operations for jitter calculations (these use doubles). * * Note that we carefully separate the jitter component from the * dispersion component (frequency error plus precision). The frequency * error component is computed as CLOCK_PHI times the difference between * the epoch of the time measurement and the reference time. The * precision componen is computed as the square root of the mean of the * squares of a zero-mean, uniform distribution of unit maximum * amplitude. Whether this makes statistical sense may be arguable. */#define SQUARE(x) ((x) * (x))#define SQRT(x) (sqrt(x))#define DIFF(x, y) (SQUARE((x) - (y)))#define LOGTOD(a) ((a) < 0 ? 1. / (1L << -(a)) : \ 1L << (int)(a)) /* log2 to double */#define UNIVAR(x) (SQUARE(.28867513 * LOGTOD(x))) /* std uniform distr */#define ULOGTOD(a) (1L << (int)(a)) /* ulog2 to double */#define EVENT_TIMEOUT 0 /* one second, that is *//* * The interface structure is used to hold the addresses and socket * numbers of each of the interfaces we are using. */struct interface { SOCKET fd; /* socket this is opened on */ SOCKET bfd; /* socket for receiving broadcasts */ struct sockaddr_storage sin; /* interface address */ struct sockaddr_storage bcast; /* broadcast address */ struct sockaddr_storage mask; /* interface mask */ char name[32]; /* name of interface */ short family; /* Address family */ int flags; /* interface flags */ int last_ttl; /* last TTL specified */ u_int32 addr_refid; /* IPv4 addr or IPv6 hash */ int num_mcast; /* No. of IP addresses in multicast socket */ volatile long received; /* number of incoming packets */ long sent; /* number of outgoing packets */ long notsent; /* number of send failures */ u_int ifindex; /* Interface index */ u_int scopeid; /* Scope used for Multicasting */ isc_boolean_t ignore_packets; /* Specify whether the packet should be ignored */};/* * Flags for interfaces */#define INT_UP 1 /* Interface is up */#define INT_PPP 2 /* Point-to-point interface */#define INT_LOOPBACK 4 /* the loopback interface */#define INT_BROADCAST 8 /* can broadcast out this interface */#define INT_MULTICAST 16 /* can multicast out this interface */#define INT_BCASTOPEN 32 /* broadcast socket is open */#define INT_MCASTOPEN 64 /* multicasting enabled *//* * Define flasher bits (tests 1 through 11 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. * * Packet errors */#define TEST1 0X0001 /* duplicate packet */#define TEST2 0x0002 /* bogus packet */#define TEST3 0x0004 /* protocol unsynchronized */#define TEST4 0x0008 /* access denied */#define TEST5 0x0010 /* authentication error */#define TEST6 0x0020 /* bad synch or stratum */#define TEST7 0x0040 /* bad header data */#define TEST8 0x0080 /* autokey error */#define TEST9 0x0100 /* crypto error */#define PKT_TEST_MASK (TEST1 | TEST2 | TEST3 | TEST4 | TEST5 |\ TEST6 | TEST7 | TEST8 | TEST9)/* * Peer errors */#define TEST10 0x0200 /* peer bad synch or stratum */#define TEST11 0x0400 /* peer distance exceeded */#define TEST12 0x0800 /* peer synchronization loop */#define TEST13 0x1000 /* peer unreacable */#define PEER_TEST_MASK (TEST10 | TEST11 | TEST12 | TEST13)/* * Authentication codes */#define AUTH_NONE 0 /* no authentication */#define AUTH_OK 1 /* authentication OK */#define AUTH_ERROR 2 /* authentication error */#define AUTH_CRYPTO 3 /* crypto-NAK *//* * 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 { struct peer *next; /* pointer to next association */ struct peer *ass_next; /* link pointer in associd hash */ struct sockaddr_storage srcadr; /* address of remote host */ struct interface *dstadr; /* pointer to address on local host */ associd_t associd; /* association ID */ u_char version; /* version number */ u_char hmode; /* local association mode */ u_char hpoll; /* local poll interval */ u_char minpoll; /* min poll interval */ u_char maxpoll; /* max poll interval */ u_int flags; /* association flags */ u_char cast_flags; /* additional flags */ u_int flash; /* protocol error test tally bits */ u_char last_event; /* last peer error code */ u_char num_events; /* number of error events */ u_char ttl; /* ttl/refclock mode */ /* * Variables used by reference clock support */#ifdef REFCLOCK struct refclockproc *procptr; /* refclock structure pointer */ u_char refclktype; /* reference clock type */ u_char refclkunit; /* reference clock unit number */ u_char sstclktype; /* clock type for system status word */#endif /* REFCLOCK */ /* * Variables set by received packet */ u_char leap; /* local leap indicator */ u_char pmode; /* remote association mode */ u_char stratum; /* remote stratum */ u_char ppoll; /* remote poll interval */ s_char precision; /* remote clock precision */ double rootdelay; /* roundtrip delay to primary clock */ double rootdispersion; /* dispersion to primary clock */ u_int32 refid; /* remote reference ID */ l_fp reftime; /* update epoch */ /* * Variables used by authenticated client */ keyid_t keyid; /* current key ID */#ifdef OPENSSL#define clear_to_zero assoc associd_t assoc; /* peer association ID */ u_int32 crypto; /* peer status word */ EVP_PKEY *pkey; /* public key */ const EVP_MD *digest; /* message digest algorithm */ char *subject; /* certificate subject name */ char *issuer; /* certificate issuer name */ keyid_t pkeyid; /* previous key ID */ keyid_t pcookie; /* peer cookie */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -