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