]>
Commit | Line | Data |
---|---|---|
1 | // SPDX-License-Identifier: ISC | |
2 | /* | |
3 | * Copyright (c) 2021 David Lamparter, for NetDEF, Inc. | |
4 | */ | |
5 | ||
6 | #ifndef _FRR_ZLOG_5424_H | |
7 | #define _FRR_ZLOG_5424_H | |
8 | ||
9 | #include <sys/stat.h> | |
10 | ||
11 | #include "typerb.h" | |
12 | #include "zlog.h" | |
13 | #include "zlog_targets.h" | |
14 | #include "qobj.h" | |
15 | ||
16 | struct thread; | |
17 | struct thread_master; | |
18 | ||
19 | enum zlog_5424_dst { | |
20 | /* can be used to disable a target temporarily */ | |
21 | ZLOG_5424_DST_NONE = 0, | |
22 | ||
23 | ZLOG_5424_DST_FD, | |
24 | ZLOG_5424_DST_FILE, | |
25 | ZLOG_5424_DST_FIFO, | |
26 | ZLOG_5424_DST_UNIX, | |
27 | ||
28 | #define ZLOG_5424_DST_LAST ZLOG_5424_DST_UNIX | |
29 | }; | |
30 | ||
31 | enum zlog_5424_format { | |
32 | ZLOG_FMT_5424 = 0, | |
33 | ZLOG_FMT_3164, | |
34 | ZLOG_FMT_LOCAL, | |
35 | ZLOG_FMT_JOURNALD, | |
36 | ||
37 | #define ZLOG_FMT_LAST ZLOG_FMT_JOURNALD | |
38 | }; | |
39 | ||
40 | /* actual RCU'd logging backend */ | |
41 | struct zlt_5424; | |
42 | ||
43 | struct zlog_cfg_5424 { | |
44 | struct zlt_5424 *active; | |
45 | ||
46 | pthread_mutex_t cfg_mtx; | |
47 | ||
48 | /* general settings for all dsts */ | |
49 | int facility; | |
50 | int prio_min; | |
51 | bool kw_version; | |
52 | bool kw_location; | |
53 | bool kw_uid; | |
54 | bool kw_ec; | |
55 | bool kw_args; | |
56 | ||
57 | uint32_t ts_flags; | |
58 | ||
59 | enum zlog_5424_format fmt; | |
60 | ||
61 | /* destination specifics */ | |
62 | enum zlog_5424_dst dst; | |
63 | ||
64 | /* pre-opened FD. not the actual fd we log to */ | |
65 | int fd; | |
66 | ||
67 | /* file, fifo, unix */ | |
68 | bool file_nocreate; | |
69 | ||
70 | const char *filename; | |
71 | mode_t file_mode; | |
72 | /* -1 = no change */ | |
73 | uid_t file_uid; | |
74 | gid_t file_gid; | |
75 | ||
76 | /* remaining fields are internally used & updated by the 5424 | |
77 | * code - *not* config. don't set these. | |
78 | */ | |
79 | ||
80 | /* sockets only - read handler to reconnect on errors */ | |
81 | struct thread_master *master; | |
82 | struct thread *t_reconnect; | |
83 | unsigned int reconn_backoff, reconn_backoff_cur, reconn_backoff_max; | |
84 | int sock_type; | |
85 | struct sockaddr_storage sa; | |
86 | socklen_t sa_len; | |
87 | }; | |
88 | ||
89 | /* these don't do malloc/free to allow using a static global */ | |
90 | extern void zlog_5424_init(struct zlog_cfg_5424 *zcf); | |
91 | ||
92 | /* keepopen = true => for shutdown, just zap the config, keep logging */ | |
93 | extern void zlog_5424_fini(struct zlog_cfg_5424 *zcf, bool keepopen); | |
94 | ||
95 | /* apply metadata/config changes */ | |
96 | extern bool zlog_5424_apply_meta(struct zlog_cfg_5424 *zcf); | |
97 | ||
98 | /* apply changes requiring (re-)opening the destination | |
99 | * | |
100 | * also does log cycling/rotate & applies _meta at the same time | |
101 | */ | |
102 | extern bool zlog_5424_apply_dst(struct zlog_cfg_5424 *zcf); | |
103 | ||
104 | /* SIGHUP log rotation */ | |
105 | extern bool zlog_5424_rotate(struct zlog_cfg_5424 *zcf); | |
106 | ||
107 | extern void zlog_5424_state(struct zlog_cfg_5424 *zcf, size_t *lost_msgs, | |
108 | int *last_errno, bool *stale_errno, | |
109 | struct timeval *err_ts); | |
110 | ||
111 | /* this is the dynamically allocated "variant" */ | |
112 | PREDECL_RBTREE_UNIQ(targets); | |
113 | ||
114 | struct zlog_cfg_5424_user { | |
115 | struct targets_item targets_item; | |
116 | char *name; | |
117 | ||
118 | struct zlog_cfg_5424 cfg; | |
119 | ||
120 | char *envvar; | |
121 | ||
122 | /* non-const, always same as cfg.filename */ | |
123 | char *filename; | |
124 | ||
125 | /* uid/gid strings to write back out in show config */ | |
126 | char *file_user; | |
127 | char *file_group; | |
128 | ||
129 | bool reconf_dst; | |
130 | bool reconf_meta; | |
131 | ||
132 | int unix_special; | |
133 | ||
134 | QOBJ_FIELDS; | |
135 | }; | |
136 | ||
137 | DECLARE_QOBJ_TYPE(zlog_cfg_5424_user); | |
138 | ||
139 | extern void log_5424_cmd_init(void); | |
140 | ||
141 | #endif /* _FRR_ZLOG_5424_H */ |