]> git.ipfire.org Git - thirdparty/chrony.git/blob - ntp_auth.h
ntp: add function to change authentication-specific address
[thirdparty/chrony.git] / ntp_auth.h
1 /*
2 chronyd/chronyc - Programs for keeping computer clocks accurate.
3
4 **********************************************************************
5 * Copyright (C) Miroslav Lichvar 2019
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 *
20 **********************************************************************
21
22 =======================================================================
23
24 Header file for NTP authentication
25 */
26
27 #ifndef GOT_NTP_AUTH_H
28 #define GOT_NTP_AUTH_H
29
30 #include "addressing.h"
31 #include "ntp.h"
32
33 typedef struct NAU_Instance_Record *NAU_Instance;
34
35 /* Create an authenticator instance in a specific mode */
36 extern NAU_Instance NAU_CreateNoneInstance(void);
37 extern NAU_Instance NAU_CreateSymmetricInstance(uint32_t key_id);
38
39 /* Destroy an instance */
40 extern void NAU_DestroyInstance(NAU_Instance instance);
41
42 /* Check if an instance is not in the None mode */
43 extern int NAU_IsAuthEnabled(NAU_Instance instance);
44
45 /* Get NTP version recommended for better compatibility */
46 extern int NAU_GetSuggestedNtpVersion(NAU_Instance instance);
47
48 /* Perform operations necessary for NAU_GenerateRequestAuth() */
49 extern int NAU_PrepareRequestAuth(NAU_Instance instance);
50
51 /* Adjust a transmit timestamp for an estimated minimum time it takes to call
52 NAU_GenerateRequestAuth() */
53 extern void NAU_AdjustRequestTimestamp(NAU_Instance instance, struct timespec *ts);
54
55 /* Extend a request with data required by the authentication mode */
56 extern int NAU_GenerateRequestAuth(NAU_Instance instance, NTP_Packet *request,
57 NTP_PacketInfo *info);
58
59 /* Parse a request or response to detect the authentication mode */
60 extern int NAU_ParsePacket(NTP_Packet *packet, NTP_PacketInfo *info);
61
62 /* Verify that a request is authentic. If it is not authentic and a non-zero
63 kod code is returned, a KoD response should be sent back. */
64 extern int NAU_CheckRequestAuth(NTP_Packet *request, NTP_PacketInfo *info, uint32_t *kod);
65
66 /* Adjust a transmit timestamp for an estimated minimum time it takes to call
67 NAU_GenerateResponseAuth() */
68 extern void NAU_AdjustResponseTimestamp(NTP_Packet *request, NTP_PacketInfo *info,
69 struct timespec *ts);
70
71 /* Extend a response with data required by the authentication mode. This
72 function can be called only if the previous call of NAU_CheckRequestAuth()
73 was on the same request. */
74 extern int NAU_GenerateResponseAuth(NTP_Packet *request, NTP_PacketInfo *request_info,
75 NTP_Packet *response, NTP_PacketInfo *response_info,
76 NTP_Remote_Address *remote_addr,
77 NTP_Local_Address *local_addr,
78 uint32_t kod);
79
80 /* Verify that a response is authentic */
81 extern int NAU_CheckResponseAuth(NAU_Instance instance, NTP_Packet *response,
82 NTP_PacketInfo *info);
83
84 /* Change an authentication-specific address (e.g. after replacing a source) */
85 extern void NAU_ChangeAddress(NAU_Instance instance, IPAddr *address);
86
87 #endif