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