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