2 * Routines for syslog message dissection
4 * Copyright 2000, Gerald Combs <gerald[AT]wireshark.org>
6 * Support for passing SS7 MSUs (from the Cisco ITP Packet Logging
7 * facility) to the MTP3 dissector by Abhik Sarkar <sarkar.abhik[AT]gmail.com>
8 * with some rework by Jeff Morriss <jeff.morriss[AT]ulticom.com>
12 * Wireshark - Network traffic analyzer
13 * By Gerald Combs <gerald[AT]wireshark.org>
14 * Copyright 1998 Gerald Combs
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version 2
19 * of the License, or (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
41 #include <epan/packet.h>
42 #include <epan/strutil.h>
44 #define UDP_PORT_SYSLOG 514
46 #define PRIORITY_MASK 0x0007 /* 0000 0111 */
47 #define FACILITY_MASK 0x03f8 /* 1111 1000 */
49 /* The maximum number if priority digits to read in. */
56 #define LEVEL_WARNING 4
57 #define LEVEL_NOTICE 5
60 static const value_string short_lev[] = {
61 { LEVEL_EMERG, "EMERG" },
62 { LEVEL_ALERT, "ALERT" },
63 { LEVEL_CRIT, "CRIT" },
65 { LEVEL_WARNING, "WARNING" },
66 { LEVEL_NOTICE, "NOTICE" },
67 { LEVEL_INFO, "INFO" },
68 { LEVEL_DEBUG, "DEBUG" },
82 #define FAC_AUTHPRIV 10
85 #define FAC_LOGAUDIT 13
86 #define FAC_LOGALERT 14
87 #define FAC_CRON_SOL 15
96 static const value_string short_fac[] = {
100 { FAC_DAEMON, "DAEMON" },
101 { FAC_AUTH, "AUTH" },
102 { FAC_SYSLOG, "SYSLOG" },
104 { FAC_NEWS, "NEWS" },
105 { FAC_UUCP, "UUCP" },
106 { FAC_CRON, "CRON" }, /* The BSDs, Linux, and others */
107 { FAC_AUTHPRIV, "AUTHPRIV" },
110 { FAC_LOGAUDIT, "LOGAUDIT" },
111 { FAC_LOGALERT, "LOGALERT" },
112 { FAC_CRON_SOL, "CRON" }, /* Solaris */
113 { FAC_LOCAL0, "LOCAL0" },
114 { FAC_LOCAL1, "LOCAL1" },
115 { FAC_LOCAL2, "LOCAL2" },
116 { FAC_LOCAL3, "LOCAL3" },
117 { FAC_LOCAL4, "LOCAL4" },
118 { FAC_LOCAL5, "LOCAL5" },
119 { FAC_LOCAL6, "LOCAL6" },
120 { FAC_LOCAL7, "LOCAL7" },
124 static const value_string long_lev[] = {
125 { LEVEL_EMERG, "EMERG - system is unusable" },
126 { LEVEL_ALERT, "ALERT - action must be taken immediately" },
127 { LEVEL_CRIT, "CRIT - critical conditions" },
128 { LEVEL_ERR, "ERR - error conditions" },
129 { LEVEL_WARNING, "WARNING - warning conditions" },
130 { LEVEL_NOTICE, "NOTICE - normal but significant condition" },
131 { LEVEL_INFO, "INFO - informational" },
132 { LEVEL_DEBUG, "DEBUG - debug-level messages" },
136 static const value_string long_fac[] = {
137 { FAC_KERN, "KERN - kernel messages" },
138 { FAC_USER, "USER - random user-level messages" },
139 { FAC_MAIL, "MAIL - mail system" },
140 { FAC_DAEMON, "DAEMON - system daemons" },
141 { FAC_AUTH, "AUTH - security/authorization messages" },
142 { FAC_SYSLOG, "SYSLOG - messages generated internally by syslogd" },
143 { FAC_LPR, "LPR - line printer subsystem" },
144 { FAC_NEWS, "NEWS - network news subsystem" },
145 { FAC_UUCP, "UUCP - UUCP subsystem" },
146 { FAC_CRON, "CRON - clock daemon (BSD, Linux)" },
147 { FAC_AUTHPRIV, "AUTHPRIV - security/authorization messages (private)" },
148 { FAC_FTP, "FTP - ftp daemon" },
149 { FAC_NTP, "NTP - ntp subsystem" },
150 { FAC_LOGAUDIT, "LOGAUDIT - log audit" },
151 { FAC_LOGALERT, "LOGALERT - log alert" },
152 { FAC_CRON_SOL, "CRON - clock daemon (Solaris)" },
153 { FAC_LOCAL0, "LOCAL0 - reserved for local use" },
154 { FAC_LOCAL1, "LOCAL1 - reserved for local use" },
155 { FAC_LOCAL2, "LOCAL2 - reserved for local use" },
156 { FAC_LOCAL3, "LOCAL3 - reserved for local use" },
157 { FAC_LOCAL4, "LOCAL4 - reserved for local use" },
158 { FAC_LOCAL5, "LOCAL5 - reserved for local use" },
159 { FAC_LOCAL6, "LOCAL6 - reserved for local use" },
160 { FAC_LOCAL7, "LOCAL7 - reserved for local use" },
164 static gint proto_syslog = -1;
165 static gint hf_syslog_level = -1;
166 static gint hf_syslog_facility = -1;
167 static gint hf_syslog_msg = -1;
168 static gint hf_syslog_msu_present = -1;
170 static gint ett_syslog = -1;
172 static dissector_handle_t mtp_handle;
174 /* The Cisco ITP's packet logging facility allows selected (SS7) MSUs to be
175 * to be encapsulated in syslog UDP datagrams and sent to a monitoring tool.
176 * However, no actual tool to monitor/decode the MSUs is provided. The aim
177 * of this routine is to extract the hex dump of the MSU from the syslog
178 * packet so that it can be passed on to the mtp3 dissector for decoding.
181 mtp3_msu_present(gint fac, gint level, const char *msg_str)
184 gchar **split_string, *msu_hex_dump;
185 tvbuff_t *mtp3_tvb = NULL;
188 /* In the sample capture I have, all MSUs are LOCAL0.DEBUG.
189 * Try to optimize this routine for most syslog users by short-cutting
192 if (!(fac == FAC_LOCAL0 && level == LEVEL_DEBUG))
195 if (strstr(msg_str, "msu=") == NULL)
198 split_string = g_strsplit(msg_str, "msu=", 2);
199 msu_hex_dump = split_string[1];
201 if (msu_hex_dump && strlen(msu_hex_dump)) {
202 byte_array = convert_string_to_hex(msu_hex_dump, &nbytes);
204 mtp3_tvb = tvb_new_real_data(byte_array, nbytes, nbytes);
205 tvb_set_free_cb(mtp3_tvb, g_free);
208 g_strfreev(split_string);
213 /* The message format is defined in RFC 3164 */
215 dissect_syslog(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
217 gint pri = -1, lev = -1, fac = -1;
218 gint msg_off = 0, msg_len;
220 proto_tree *syslog_tree;
224 if (check_col(pinfo->cinfo, COL_PROTOCOL))
225 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Syslog");
226 if (check_col(pinfo->cinfo, COL_INFO))
227 col_clear(pinfo->cinfo, COL_INFO);
229 if (tvb_get_guint8(tvb, msg_off) == '<') {
230 /* A facility and level follow. */
233 while (tvb_bytes_exist(tvb, msg_off, 1) &&
234 isdigit(tvb_get_guint8(tvb, msg_off)) && msg_off <= MAX_DIGITS) {
235 pri = pri * 10 + (tvb_get_guint8(tvb, msg_off) - '0');
238 if (tvb_get_guint8(tvb, msg_off) == '>')
240 fac = (pri & FACILITY_MASK) >> 3;
241 lev = pri & PRIORITY_MASK;
244 msg_len = tvb_ensure_length_remaining(tvb, msg_off);
245 msg_str = tvb_format_text(tvb, msg_off, msg_len);
247 mtp3_tvb = mtp3_msu_present(fac, lev, msg_str);
249 if (mtp3_tvb == NULL && check_col(pinfo->cinfo, COL_INFO)) {
251 col_add_fstr(pinfo->cinfo, COL_INFO, "%s.%s: %s",
252 val_to_str(fac, short_fac, "UNKNOWN"),
253 val_to_str(lev, short_lev, "UNKNOWN"), msg_str);
255 col_add_str(pinfo->cinfo, COL_INFO, msg_str);
261 ti = proto_tree_add_protocol_format(tree, proto_syslog, tvb, 0, -1,
262 "Syslog message: %s.%s: %s",
263 val_to_str(fac, short_fac, "UNKNOWN"),
264 val_to_str(lev, short_lev, "UNKNOWN"), msg_str);
266 ti = proto_tree_add_protocol_format(tree, proto_syslog, tvb, 0, -1,
267 "Syslog message: (unknown): %s", msg_str);
269 syslog_tree = proto_item_add_subtree(ti, ett_syslog);
271 ti = proto_tree_add_uint(syslog_tree, hf_syslog_facility, tvb, 0,
273 ti = proto_tree_add_uint(syslog_tree, hf_syslog_level, tvb, 0,
276 proto_tree_add_item(syslog_tree, hf_syslog_msg, tvb, msg_off,
280 proto_item *mtp3_item;
281 mtp3_item = proto_tree_add_boolean(syslog_tree, hf_syslog_msu_present,
282 tvb, msg_off, msg_len, TRUE);
283 PROTO_ITEM_SET_GENERATED(mtp3_item);
287 /* Call MTP dissector if encapsulated MSU was found */
289 call_dissector(mtp_handle, mtp3_tvb, pinfo, tree);
295 /* Register the protocol with Wireshark */
296 void proto_register_syslog(void)
299 /* Setup list of header fields */
300 static hf_register_info hf[] = {
301 { &hf_syslog_facility,
302 { "Facility", "syslog.facility",
303 FT_UINT8, BASE_DEC, VALS(long_fac), FACILITY_MASK,
304 "Message facility", HFILL }
307 { "Level", "syslog.level",
308 FT_UINT8, BASE_DEC, VALS(long_lev), PRIORITY_MASK,
309 "Message level", HFILL }
312 { "Message", "syslog.msg",
313 FT_STRING, BASE_NONE, NULL, 0x0,
314 "Message Text", HFILL }
316 { &hf_syslog_msu_present,
317 { "SS7 MSU present", "syslog.msu_present",
318 FT_BOOLEAN, BASE_NONE, NULL, 0x0,
319 "True if an SS7 MSU was detected in the syslog message",
324 /* Setup protocol subtree array */
325 static gint *ett[] = {
329 /* Register the protocol name and description */
330 proto_syslog = proto_register_protocol("Syslog message", "Syslog", "syslog");
332 /* Required function calls to register the header fields and subtrees used */
333 proto_register_field_array(proto_syslog, hf, array_length(hf));
334 proto_register_subtree_array(ett, array_length(ett));
338 proto_reg_handoff_syslog(void)
340 dissector_handle_t syslog_handle;
342 syslog_handle = create_dissector_handle(dissect_syslog, proto_syslog);
343 dissector_add("udp.port", UDP_PORT_SYSLOG, syslog_handle);
345 /* Find the mtp3 dissector */
346 mtp_handle = find_dissector("mtp3");