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