]>
Commit | Line | Data |
---|---|---|
74335ceb YR |
1 | // SPDX-License-Identifier: GPL-2.0-or-later |
2 | /* | |
83b78f43 | 3 | * Copyright (C) 2021 Vmware, Inc. |
4 | * Pushpasis Sarkar <spushpasis@vmware.com> | |
5 | * Copyright (c) 2023, LabN Consulting, L.L.C. | |
6 | * | |
7 | */ | |
74335ceb YR |
8 | #ifndef _FRR_MGMTD_HISTORY_H_ |
9 | #define _FRR_MGMTD_HISTORY_H_ | |
10 | ||
11 | #include "vrf.h" | |
12 | ||
13 | PREDECL_DLIST(mgmt_cmt_infos); | |
14 | ||
15 | struct mgmt_ds_ctx; | |
16 | ||
17 | /* | |
18 | * Rollback specific commit from commit history. | |
19 | * | |
20 | * vty | |
21 | * VTY context. | |
22 | * | |
23 | * cmtid_str | |
24 | * Specific commit id from commit history. | |
25 | * | |
26 | * Returns: | |
27 | * 0 on success, -1 on failure. | |
28 | */ | |
29 | extern int mgmt_history_rollback_by_id(struct vty *vty, const char *cmtid_str); | |
30 | ||
31 | /* | |
32 | * Rollback n commits from commit history. | |
33 | * | |
34 | * vty | |
35 | * VTY context. | |
36 | * | |
37 | * num_cmts | |
38 | * Number of commits to be rolled back. | |
39 | * | |
40 | * Returns: | |
41 | * 0 on success, -1 on failure. | |
42 | */ | |
43 | extern int mgmt_history_rollback_n(struct vty *vty, int num_cmts); | |
44 | ||
1401ee8b PS |
45 | extern void mgmt_history_rollback_complete(bool success); |
46 | ||
74335ceb YR |
47 | /* |
48 | * Show mgmt commit history. | |
49 | */ | |
50 | extern void show_mgmt_cmt_history(struct vty *vty); | |
51 | ||
52 | extern void mgmt_history_new_record(struct mgmt_ds_ctx *ds_ctx); | |
53 | ||
54 | extern void mgmt_history_destroy(void); | |
55 | extern void mgmt_history_init(void); | |
56 | ||
d31d24c4 CH |
57 | /* |
58 | * 012345678901234567890123456789 | |
59 | * 2023-12-31T12:12:12,012345678 | |
60 | * 20231231121212012345678 | |
61 | */ | |
62 | #define MGMT_LONG_TIME_FMT "%Y-%m-%dT%H:%M:%S" | |
63 | #define MGMT_LONG_TIME_MAX_LEN 30 | |
64 | #define MGMT_SHORT_TIME_FMT "%Y%m%d%H%M%S" | |
65 | #define MGMT_SHORT_TIME_MAX_LEN 24 | |
66 | ||
67 | static inline const char * | |
68 | mgmt_time_to_string(struct timespec *tv, bool long_fmt, char *buffer, size_t sz) | |
69 | { | |
70 | struct tm tm; | |
71 | size_t n; | |
72 | ||
73 | localtime_r(&tv->tv_sec, &tm); | |
74 | ||
75 | if (long_fmt) { | |
76 | n = strftime(buffer, sz, MGMT_LONG_TIME_FMT, &tm); | |
77 | snprintf(&buffer[n], sz - n, ",%09lu", tv->tv_nsec); | |
78 | } else { | |
79 | n = strftime(buffer, sz, MGMT_SHORT_TIME_FMT, &tm); | |
80 | snprintf(&buffer[n], sz - n, "%09lu", tv->tv_nsec); | |
81 | } | |
82 | ||
83 | return buffer; | |
84 | } | |
85 | ||
86 | static inline const char *mgmt_realtime_to_string(struct timeval *tv, char *buf, | |
87 | size_t sz) | |
88 | { | |
89 | struct timespec ts = {.tv_sec = tv->tv_sec, | |
90 | .tv_nsec = tv->tv_usec * 1000}; | |
91 | ||
92 | return mgmt_time_to_string(&ts, true, buf, sz); | |
93 | } | |
94 | ||
74335ceb | 95 | #endif /* _FRR_MGMTD_HISTORY_H_ */ |