]> git.proxmox.com Git - mirror_frr.git/blob - lib/zlog_5424.h
Merge pull request #10816 from anlancs/fix-bgdp-local-es-rt
[mirror_frr.git] / lib / zlog_5424.h
1 /*
2 * Copyright (c) 2021 David Lamparter, for NetDEF, Inc.
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17 #ifndef _FRR_ZLOG_5424_H
18 #define _FRR_ZLOG_5424_H
19
20 #include <sys/stat.h>
21
22 #include "typerb.h"
23 #include "zlog.h"
24 #include "zlog_targets.h"
25 #include "qobj.h"
26
27 struct thread;
28 struct thread_master;
29
30 enum zlog_5424_dst {
31 /* can be used to disable a target temporarily */
32 ZLOG_5424_DST_NONE = 0,
33
34 ZLOG_5424_DST_FD,
35 ZLOG_5424_DST_FILE,
36 ZLOG_5424_DST_FIFO,
37 ZLOG_5424_DST_UNIX,
38
39 #define ZLOG_5424_DST_LAST ZLOG_5424_DST_UNIX
40 };
41
42 enum zlog_5424_format {
43 ZLOG_FMT_5424 = 0,
44 ZLOG_FMT_3164,
45 ZLOG_FMT_LOCAL,
46 ZLOG_FMT_JOURNALD,
47
48 #define ZLOG_FMT_LAST ZLOG_FMT_JOURNALD
49 };
50
51 /* actual RCU'd logging backend */
52 struct zlt_5424;
53
54 struct zlog_cfg_5424 {
55 struct zlt_5424 *active;
56
57 pthread_mutex_t cfg_mtx;
58
59 /* general settings for all dsts */
60 int facility;
61 int prio_min;
62 bool kw_version;
63 bool kw_location;
64 bool kw_uid;
65 bool kw_ec;
66 bool kw_args;
67
68 uint32_t ts_flags;
69
70 enum zlog_5424_format fmt;
71
72 /* destination specifics */
73 enum zlog_5424_dst dst;
74
75 /* pre-opened FD. not the actual fd we log to */
76 int fd;
77
78 /* file, fifo, unix */
79 bool file_nocreate;
80
81 const char *filename;
82 mode_t file_mode;
83 /* -1 = no change */
84 uid_t file_uid;
85 gid_t file_gid;
86
87 /* remaining fields are internally used & updated by the 5424
88 * code - *not* config. don't set these.
89 */
90
91 /* sockets only - read handler to reconnect on errors */
92 struct thread_master *master;
93 struct thread *t_reconnect;
94 unsigned int reconn_backoff, reconn_backoff_cur, reconn_backoff_max;
95 int sock_type;
96 struct sockaddr_storage sa;
97 socklen_t sa_len;
98 };
99
100 /* these don't do malloc/free to allow using a static global */
101 extern void zlog_5424_init(struct zlog_cfg_5424 *zcf);
102
103 /* keepopen = true => for shutdown, just zap the config, keep logging */
104 extern void zlog_5424_fini(struct zlog_cfg_5424 *zcf, bool keepopen);
105
106 /* apply metadata/config changes */
107 extern bool zlog_5424_apply_meta(struct zlog_cfg_5424 *zcf);
108
109 /* apply changes requiring (re-)opening the destination
110 *
111 * also does log cycling/rotate & applies _meta at the same time
112 */
113 extern bool zlog_5424_apply_dst(struct zlog_cfg_5424 *zcf);
114
115 /* SIGHUP log rotation */
116 extern bool zlog_5424_rotate(struct zlog_cfg_5424 *zcf);
117
118 extern void zlog_5424_state(struct zlog_cfg_5424 *zcf, size_t *lost_msgs,
119 int *last_errno, bool *stale_errno,
120 struct timeval *err_ts);
121
122 /* this is the dynamically allocated "variant" */
123 PREDECL_RBTREE_UNIQ(targets);
124
125 struct zlog_cfg_5424_user {
126 struct targets_item targets_item;
127 char *name;
128
129 struct zlog_cfg_5424 cfg;
130
131 char *envvar;
132
133 /* non-const, always same as cfg.filename */
134 char *filename;
135
136 /* uid/gid strings to write back out in show config */
137 char *file_user;
138 char *file_group;
139
140 bool reconf_dst;
141 bool reconf_meta;
142
143 int unix_special;
144
145 QOBJ_FIELDS;
146 };
147
148 DECLARE_QOBJ_TYPE(zlog_cfg_5424_user);
149
150 extern void log_5424_cmd_init(void);
151
152 #endif /* _FRR_ZLOG_5424_H */