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