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