1 | /* |
---|
2 | * ksyslog: In-kernel syslog receiver |
---|
3 | * Copyright(C) 2013 Atzm WATANABE All rights reserved |
---|
4 | * Distributed under the GPL |
---|
5 | */ |
---|
6 | |
---|
7 | #ifndef KSYSLOG_H |
---|
8 | #define KSYSLOG_H |
---|
9 | |
---|
10 | #define UDP_ENCAP_KSYSLOG 16 |
---|
11 | |
---|
12 | enum ksyslog_facility { |
---|
13 | KSYSLOG_F_KERN, |
---|
14 | KSYSLOG_F_USER, |
---|
15 | KSYSLOG_F_MAIL, |
---|
16 | KSYSLOG_F_DAEMON, |
---|
17 | KSYSLOG_F_AUTH, |
---|
18 | KSYSLOG_F_SYSLOG, |
---|
19 | KSYSLOG_F_LPR, |
---|
20 | KSYSLOG_F_NEWS, |
---|
21 | KSYSLOG_F_UUCP, |
---|
22 | KSYSLOG_F_CRON, |
---|
23 | KSYSLOG_F_AUTHPRIV, |
---|
24 | KSYSLOG_F_FTP, |
---|
25 | KSYSLOG_F_NTP, |
---|
26 | KSYSLOG_F_AUDIT, |
---|
27 | KSYSLOG_F_ALERT, |
---|
28 | KSYSLOG_F_CRONPRIV, /* ? */ |
---|
29 | KSYSLOG_F_LOCAL0, |
---|
30 | KSYSLOG_F_LOCAL1, |
---|
31 | KSYSLOG_F_LOCAL2, |
---|
32 | KSYSLOG_F_LOCAL3, |
---|
33 | KSYSLOG_F_LOCAL4, |
---|
34 | KSYSLOG_F_LOCAL5, |
---|
35 | KSYSLOG_F_LOCAL6, |
---|
36 | KSYSLOG_F_LOCAL7, |
---|
37 | __KSYSLOG_F_MAX, |
---|
38 | }; |
---|
39 | |
---|
40 | enum ksyslog_severity { |
---|
41 | KSYSLOG_S_EMERG, |
---|
42 | KSYSLOG_S_ALERT, |
---|
43 | KSYSLOG_S_CRIT, |
---|
44 | KSYSLOG_S_ERR, |
---|
45 | KSYSLOG_S_WARN, |
---|
46 | KSYSLOG_S_NOTICE, |
---|
47 | KSYSLOG_S_INFO, |
---|
48 | KSYSLOG_S_DEBUG, |
---|
49 | __KSYSLOG_S_MAX, |
---|
50 | }; |
---|
51 | |
---|
52 | struct ksyslog_entry { |
---|
53 | struct list_head list; |
---|
54 | struct timeval tv; |
---|
55 | |
---|
56 | unsigned long time; |
---|
57 | unsigned int priority; |
---|
58 | enum ksyslog_facility facility; |
---|
59 | enum ksyslog_severity severity; |
---|
60 | |
---|
61 | union { |
---|
62 | __u8 addr8[4]; |
---|
63 | __be32 addr32; |
---|
64 | } daddr, saddr; |
---|
65 | |
---|
66 | __be16 dport, sport; |
---|
67 | |
---|
68 | size_t length; |
---|
69 | char *data; |
---|
70 | |
---|
71 | struct rcu_head rcu; |
---|
72 | }; |
---|
73 | |
---|
74 | struct ksyslog_stats { |
---|
75 | atomic64_t bytes; |
---|
76 | atomic64_t packets; |
---|
77 | }; |
---|
78 | |
---|
79 | struct ksyslog_queue { |
---|
80 | struct list_head head; |
---|
81 | struct work_struct work; |
---|
82 | spinlock_t lock; |
---|
83 | atomic64_t size; |
---|
84 | struct ksyslog_stats write_stats; |
---|
85 | struct ksyslog_stats drop_stats; |
---|
86 | struct ksyslog_stats discard_stats; |
---|
87 | }; |
---|
88 | |
---|
89 | static inline void |
---|
90 | ksyslog_stats_zero(struct ksyslog_stats *stats) |
---|
91 | { |
---|
92 | atomic64_set(&stats->bytes, 0); |
---|
93 | atomic64_set(&stats->packets, 0); |
---|
94 | } |
---|
95 | |
---|
96 | static inline void |
---|
97 | ksyslog_stats_add(struct ksyslog_stats *stats, unsigned int len) |
---|
98 | { |
---|
99 | atomic64_add(len, &stats->bytes); |
---|
100 | atomic64_inc(&stats->packets); |
---|
101 | } |
---|
102 | |
---|
103 | static inline const char * |
---|
104 | ksyslog_facility_str(const enum ksyslog_facility facility) |
---|
105 | { |
---|
106 | switch (facility) { |
---|
107 | case KSYSLOG_F_KERN: return "kern"; |
---|
108 | case KSYSLOG_F_USER: return "user"; |
---|
109 | case KSYSLOG_F_MAIL: return "mail"; |
---|
110 | case KSYSLOG_F_DAEMON: return "daemon"; |
---|
111 | case KSYSLOG_F_AUTH: return "auth"; |
---|
112 | case KSYSLOG_F_SYSLOG: return "syslog"; |
---|
113 | case KSYSLOG_F_LPR: return "lpr"; |
---|
114 | case KSYSLOG_F_NEWS: return "news"; |
---|
115 | case KSYSLOG_F_UUCP: return "uucp"; |
---|
116 | case KSYSLOG_F_CRON: return "cron"; |
---|
117 | case KSYSLOG_F_AUTHPRIV: return "authpriv"; |
---|
118 | case KSYSLOG_F_FTP: return "ftp"; |
---|
119 | case KSYSLOG_F_NTP: return "ntp"; |
---|
120 | case KSYSLOG_F_AUDIT: return "audit"; |
---|
121 | case KSYSLOG_F_ALERT: return "alert"; |
---|
122 | case KSYSLOG_F_CRONPRIV: return "cronpriv"; |
---|
123 | case KSYSLOG_F_LOCAL0: return "local0"; |
---|
124 | case KSYSLOG_F_LOCAL1: return "local1"; |
---|
125 | case KSYSLOG_F_LOCAL2: return "local2"; |
---|
126 | case KSYSLOG_F_LOCAL3: return "local3"; |
---|
127 | case KSYSLOG_F_LOCAL4: return "local4"; |
---|
128 | case KSYSLOG_F_LOCAL5: return "local5"; |
---|
129 | case KSYSLOG_F_LOCAL6: return "local6"; |
---|
130 | case KSYSLOG_F_LOCAL7: return "local7"; |
---|
131 | default: return "unknown"; |
---|
132 | } |
---|
133 | } |
---|
134 | |
---|
135 | static inline const char * |
---|
136 | ksyslog_severity_str(const enum ksyslog_severity severity) |
---|
137 | { |
---|
138 | switch (severity) { |
---|
139 | case KSYSLOG_S_EMERG: return "emerg"; |
---|
140 | case KSYSLOG_S_ALERT: return "alert"; |
---|
141 | case KSYSLOG_S_CRIT: return "crit"; |
---|
142 | case KSYSLOG_S_ERR: return "err"; |
---|
143 | case KSYSLOG_S_WARN: return "warn"; |
---|
144 | case KSYSLOG_S_NOTICE: return "notice"; |
---|
145 | case KSYSLOG_S_INFO: return "info"; |
---|
146 | case KSYSLOG_S_DEBUG: return "debug"; |
---|
147 | default: return "unknown"; |
---|
148 | } |
---|
149 | } |
---|
150 | |
---|
151 | static inline unsigned int |
---|
152 | ksyslog_month_num(const char *month) |
---|
153 | { |
---|
154 | const u32 m = *((u32 *)month); |
---|
155 | |
---|
156 | if (m == *((u32 *)"Jan")) |
---|
157 | return 1; |
---|
158 | else if (m == *((u32 *)"Feb")) |
---|
159 | return 2; |
---|
160 | else if (m == *((u32 *)"Mar")) |
---|
161 | return 3; |
---|
162 | else if (m == *((u32 *)"Apr")) |
---|
163 | return 4; |
---|
164 | else if (m == *((u32 *)"May")) |
---|
165 | return 5; |
---|
166 | else if (m == *((u32 *)"Jun")) |
---|
167 | return 6; |
---|
168 | else if (m == *((u32 *)"Jul")) |
---|
169 | return 7; |
---|
170 | else if (m == *((u32 *)"Aug")) |
---|
171 | return 8; |
---|
172 | else if (m == *((u32 *)"Sep")) |
---|
173 | return 9; |
---|
174 | else if (m == *((u32 *)"Oct")) |
---|
175 | return 10; |
---|
176 | else if (m == *((u32 *)"Nov")) |
---|
177 | return 11; |
---|
178 | else if (m == *((u32 *)"Dec")) |
---|
179 | return 12; |
---|
180 | return 0; |
---|
181 | } |
---|
182 | |
---|
183 | #endif |
---|