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_queue { |
---|
75 | struct list_head head; |
---|
76 | unsigned int length; |
---|
77 | }; |
---|
78 | |
---|
79 | static inline const char * |
---|
80 | ksyslog_facility_str(const enum ksyslog_facility facility) |
---|
81 | { |
---|
82 | switch (facility) { |
---|
83 | case KSYSLOG_F_KERN: return "kern"; |
---|
84 | case KSYSLOG_F_USER: return "user"; |
---|
85 | case KSYSLOG_F_MAIL: return "mail"; |
---|
86 | case KSYSLOG_F_DAEMON: return "daemon"; |
---|
87 | case KSYSLOG_F_AUTH: return "auth"; |
---|
88 | case KSYSLOG_F_SYSLOG: return "syslog"; |
---|
89 | case KSYSLOG_F_LPR: return "lpr"; |
---|
90 | case KSYSLOG_F_NEWS: return "news"; |
---|
91 | case KSYSLOG_F_UUCP: return "uucp"; |
---|
92 | case KSYSLOG_F_CRON: return "cron"; |
---|
93 | case KSYSLOG_F_AUTHPRIV: return "authpriv"; |
---|
94 | case KSYSLOG_F_FTP: return "ftp"; |
---|
95 | case KSYSLOG_F_NTP: return "ntp"; |
---|
96 | case KSYSLOG_F_AUDIT: return "audit"; |
---|
97 | case KSYSLOG_F_ALERT: return "alert"; |
---|
98 | case KSYSLOG_F_CRONPRIV: return "cronpriv"; |
---|
99 | case KSYSLOG_F_LOCAL0: return "local0"; |
---|
100 | case KSYSLOG_F_LOCAL1: return "local1"; |
---|
101 | case KSYSLOG_F_LOCAL2: return "local2"; |
---|
102 | case KSYSLOG_F_LOCAL3: return "local3"; |
---|
103 | case KSYSLOG_F_LOCAL4: return "local4"; |
---|
104 | case KSYSLOG_F_LOCAL5: return "local5"; |
---|
105 | case KSYSLOG_F_LOCAL6: return "local6"; |
---|
106 | case KSYSLOG_F_LOCAL7: return "local7"; |
---|
107 | default: return "unknown"; |
---|
108 | } |
---|
109 | } |
---|
110 | |
---|
111 | static inline const char * |
---|
112 | ksyslog_severity_str(const enum ksyslog_severity severity) |
---|
113 | { |
---|
114 | switch (severity) { |
---|
115 | case KSYSLOG_S_EMERG: return "emerg"; |
---|
116 | case KSYSLOG_S_ALERT: return "alert"; |
---|
117 | case KSYSLOG_S_CRIT: return "crit"; |
---|
118 | case KSYSLOG_S_ERR: return "err"; |
---|
119 | case KSYSLOG_S_WARN: return "warn"; |
---|
120 | case KSYSLOG_S_NOTICE: return "notice"; |
---|
121 | case KSYSLOG_S_INFO: return "info"; |
---|
122 | case KSYSLOG_S_DEBUG: return "debug"; |
---|
123 | default: return "unknown"; |
---|
124 | } |
---|
125 | } |
---|
126 | |
---|
127 | static inline unsigned int |
---|
128 | ksyslog_month_num(const char *month) |
---|
129 | { |
---|
130 | if (!memcmp(month, "Jan", 3)) |
---|
131 | return 1; |
---|
132 | else if (!memcmp(month, "Feb", 3)) |
---|
133 | return 2; |
---|
134 | else if (!memcmp(month, "Mar", 3)) |
---|
135 | return 3; |
---|
136 | else if (!memcmp(month, "Apr", 3)) |
---|
137 | return 4; |
---|
138 | else if (!memcmp(month, "May", 3)) |
---|
139 | return 5; |
---|
140 | else if (!memcmp(month, "Jun", 3)) |
---|
141 | return 6; |
---|
142 | else if (!memcmp(month, "Jul", 3)) |
---|
143 | return 7; |
---|
144 | else if (!memcmp(month, "Aug", 3)) |
---|
145 | return 8; |
---|
146 | else if (!memcmp(month, "Sep", 3)) |
---|
147 | return 9; |
---|
148 | else if (!memcmp(month, "Oct", 3)) |
---|
149 | return 10; |
---|
150 | else if (!memcmp(month, "Nov", 3)) |
---|
151 | return 11; |
---|
152 | else if (!memcmp(month, "Dec", 3)) |
---|
153 | return 12; |
---|
154 | else |
---|
155 | return 0; |
---|
156 | } |
---|
157 | |
---|
158 | #endif |
---|