/src/frr/mgmtd/mgmt_history.h
Line | Count | Source (jump to first uncovered line) |
1 | | // SPDX-License-Identifier: GPL-2.0-or-later |
2 | | /* |
3 | | * Copyright (C) 2021 Vmware, Inc. |
4 | | * Pushpasis Sarkar <spushpasis@vmware.com> |
5 | | * Copyright (c) 2023, LabN Consulting, L.L.C. |
6 | | * |
7 | | */ |
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 | | |
45 | | extern void mgmt_history_rollback_complete(bool success); |
46 | | |
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 | | |
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 | 0 | { |
70 | 0 | struct tm tm; |
71 | 0 | size_t n; |
72 | 0 |
|
73 | 0 | localtime_r(&tv->tv_sec, &tm); |
74 | 0 |
|
75 | 0 | if (long_fmt) { |
76 | 0 | n = strftime(buffer, sz, MGMT_LONG_TIME_FMT, &tm); |
77 | 0 | assert(n < sz); |
78 | 0 | snprintf(&buffer[n], sz - n, ",%09lu", tv->tv_nsec); |
79 | 0 | } else { |
80 | 0 | n = strftime(buffer, sz, MGMT_SHORT_TIME_FMT, &tm); |
81 | 0 | assert(n < sz); |
82 | 0 | snprintf(&buffer[n], sz - n, "%09lu", tv->tv_nsec); |
83 | 0 | } |
84 | 0 |
|
85 | 0 | return buffer; |
86 | 0 | } |
87 | | |
88 | | static inline const char *mgmt_realtime_to_string(struct timeval *tv, char *buf, |
89 | | size_t sz) |
90 | 0 | { |
91 | 0 | struct timespec ts = {.tv_sec = tv->tv_sec, |
92 | 0 | .tv_nsec = tv->tv_usec * 1000}; |
93 | 0 |
|
94 | 0 | return mgmt_time_to_string(&ts, true, buf, sz); |
95 | 0 | } |
96 | | |
97 | | #endif /* _FRR_MGMTD_HISTORY_H_ */ |