xref: /freebsd-src/contrib/ntp/sntp/networking.h (revision 416ba5c74546f32a993436a99516d35008e9f384)
1*2b15cb3dSCy Schubert #ifndef NETWORKING_H
2*2b15cb3dSCy Schubert #define NETWORKING_H
3*2b15cb3dSCy Schubert 
4*2b15cb3dSCy Schubert #include <arpa/inet.h>
5*2b15cb3dSCy Schubert #include <netinet/in.h>
6*2b15cb3dSCy Schubert 
7*2b15cb3dSCy Schubert #include <strings.h>
8*2b15cb3dSCy Schubert #include <errno.h>
9*2b15cb3dSCy Schubert #include <config.h>
10*2b15cb3dSCy Schubert #include <netdb.h>
11*2b15cb3dSCy Schubert #include <unistd.h>
12*2b15cb3dSCy Schubert #include <sys/types.h>
13*2b15cb3dSCy Schubert #include <sys/socket.h>
14*2b15cb3dSCy Schubert 
15*2b15cb3dSCy Schubert #include <ntp_rfc2553.h>
16*2b15cb3dSCy Schubert #include <ntp_stdlib.h>
17*2b15cb3dSCy Schubert #include <ntp_machine.h>
18*2b15cb3dSCy Schubert #include <ntp_unixtime.h>
19*2b15cb3dSCy Schubert #include <ntp_fp.h>
20*2b15cb3dSCy Schubert #include <ntp.h>
21*2b15cb3dSCy Schubert 
22*2b15cb3dSCy Schubert #include "crypto.h"
23*2b15cb3dSCy Schubert #include "log.h"
24*2b15cb3dSCy Schubert #include "sntp-opts.h"
25*2b15cb3dSCy Schubert #include "utilities.h"
26*2b15cb3dSCy Schubert 
27*2b15cb3dSCy Schubert /* FIXME To be replaced by the constants in ntp.h */
28*2b15cb3dSCy Schubert #define SERVER_UNUSEABLE -1 /* Skip server */
29*2b15cb3dSCy Schubert #define PACKET_UNUSEABLE -2 /* Discard packet and try to get a useable packet again if not tried too often */
30*2b15cb3dSCy Schubert #define SERVER_AUTH_FAIL -3 /* Authentication failed, act upon settings */
31*2b15cb3dSCy Schubert #define KOD_DEMOBILIZE -4   /* KOD packet with code DENY or RSTR, stop all communication and save KOD information */
32*2b15cb3dSCy Schubert #define KOD_RATE -5	    /* KOD packet with code RATE, reduce poll intervall */
33*2b15cb3dSCy Schubert #define BROADCAST_FAILED -6
34*2b15cb3dSCy Schubert 
35*2b15cb3dSCy Schubert /* prototypes */
36*2b15cb3dSCy Schubert int sendpkt(SOCKET rsock, sockaddr_u *dest, struct pkt *pkt, int len);
37*2b15cb3dSCy Schubert int recvdata(SOCKET rsock, sockaddr_u *sender, void *rdata,
38*2b15cb3dSCy Schubert 	     int rdata_len);
39*2b15cb3dSCy Schubert int recvpkt(SOCKET rsock, struct pkt *rpkt, unsigned int rsize,
40*2b15cb3dSCy Schubert 	    struct pkt *spkt);
41*2b15cb3dSCy Schubert int process_pkt(struct pkt *rpkt, sockaddr_u *sas, int pkt_len,
42*2b15cb3dSCy Schubert 		int mode, struct pkt *spkt, const char *func_name);
43*2b15cb3dSCy Schubert 
44*2b15cb3dSCy Schubert /* Shortened peer structure. Not absolutely necessary yet */
45*2b15cb3dSCy Schubert struct speer {
46*2b15cb3dSCy Schubert 	struct speer *next;
47*2b15cb3dSCy Schubert 	sockaddr_u srcadr;
48*2b15cb3dSCy Schubert 	u_char version;
49*2b15cb3dSCy Schubert 	u_char hmode;
50*2b15cb3dSCy Schubert 	u_char hpoll;
51*2b15cb3dSCy Schubert 	u_char minpoll;
52*2b15cb3dSCy Schubert 	u_char maxpoll;
53*2b15cb3dSCy Schubert 	u_int flags;
54*2b15cb3dSCy Schubert 	u_char num_events;
55*2b15cb3dSCy Schubert 	u_char ttl;
56*2b15cb3dSCy Schubert 	u_char leap;
57*2b15cb3dSCy Schubert 	u_char pmode;
58*2b15cb3dSCy Schubert 	u_char stratum;
59*2b15cb3dSCy Schubert 	u_char ppoll;
60*2b15cb3dSCy Schubert 	u_char precision;	/* should be s_char */
61*2b15cb3dSCy Schubert 	u_int32 refid;
62*2b15cb3dSCy Schubert 	l_fp reftime;
63*2b15cb3dSCy Schubert 	keyid_t keyid;
64*2b15cb3dSCy Schubert 
65*2b15cb3dSCy Schubert #ifdef AUTOKEY
66*2b15cb3dSCy Schubert #define clear_to_zero opcode
67*2b15cb3dSCy Schubert 	u_int32	opcode;		/* last request opcode */
68*2b15cb3dSCy Schubert 	associd_t assoc;	/* peer association ID */
69*2b15cb3dSCy Schubert 	u_int32	crypto;		/* peer status word */
70*2b15cb3dSCy Schubert 	EVP_PKEY *pkey;		/* public key */
71*2b15cb3dSCy Schubert 	const EVP_MD *digest;	/* message digest algorithm */
72*2b15cb3dSCy Schubert 	char	*subject;	/* certificate subject name */
73*2b15cb3dSCy Schubert 	char	*issuer;	/* certificate issuer name */
74*2b15cb3dSCy Schubert 	struct cert_info *xinfo; /* issuer certificate */
75*2b15cb3dSCy Schubert 	keyid_t	pkeyid;		/* previous key ID */
76*2b15cb3dSCy Schubert 	keyid_t	hcookie;	/* host cookie */
77*2b15cb3dSCy Schubert 	keyid_t	pcookie;	/* peer cookie */
78*2b15cb3dSCy Schubert 	const struct pkey_info *ident_pkey; /* identity key */
79*2b15cb3dSCy Schubert 	BIGNUM	*iffval;	/* identity challenge (IFF, GQ, MV) */
80*2b15cb3dSCy Schubert 	const BIGNUM *grpkey;	/* identity challenge key (GQ) */
81*2b15cb3dSCy Schubert 	struct value cookval;	/* receive cookie values */
82*2b15cb3dSCy Schubert 	struct value recval;	/* receive autokey values */
83*2b15cb3dSCy Schubert 	struct exten *cmmd;	/* extension pointer */
84*2b15cb3dSCy Schubert 	u_long	refresh;	/* next refresh epoch */
85*2b15cb3dSCy Schubert 
86*2b15cb3dSCy Schubert 	/*
87*2b15cb3dSCy Schubert 	 * Variables used by authenticated server
88*2b15cb3dSCy Schubert 	 */
89*2b15cb3dSCy Schubert 	keyid_t	*keylist;	/* session key ID list */
90*2b15cb3dSCy Schubert 	int	keynumber;	/* current key number */
91*2b15cb3dSCy Schubert 	struct value encrypt;	/* send encrypt values */
92*2b15cb3dSCy Schubert 	struct value sndval;	/* send autokey values */
93*2b15cb3dSCy Schubert #else	/* !AUTOKEY follows */
94*2b15cb3dSCy Schubert #define clear_to_zero status
95*2b15cb3dSCy Schubert #endif	/* !AUTOKEY */
96*2b15cb3dSCy Schubert 
97*2b15cb3dSCy Schubert 	l_fp	rec;		/* receive time stamp */
98*2b15cb3dSCy Schubert 	l_fp	xmt;		/* transmit time stamp */
99*2b15cb3dSCy Schubert 	l_fp	dst;		/* destination timestamp */
100*2b15cb3dSCy Schubert 	l_fp	aorg;		/* origin timestamp */
101*2b15cb3dSCy Schubert 	l_fp	borg;		/* alternate origin timestamp */
102*2b15cb3dSCy Schubert 	double	offset;		/* peer clock offset */
103*2b15cb3dSCy Schubert 	double	delay;		/* peer roundtrip delay */
104*2b15cb3dSCy Schubert };
105*2b15cb3dSCy Schubert 
106*2b15cb3dSCy Schubert 
107*2b15cb3dSCy Schubert 
108*2b15cb3dSCy Schubert 
109*2b15cb3dSCy Schubert 
110*2b15cb3dSCy Schubert #endif
111