2000-06-11 05:19:21 +00:00
|
|
|
/* packet-syslog.c
|
|
|
|
* Routines for syslog message dissection
|
|
|
|
*
|
2001-12-03 04:00:26 +00:00
|
|
|
* Copyright 2000, Gerald Combs <gerald@ethereal.com>
|
2000-06-11 05:19:21 +00:00
|
|
|
*
|
2004-07-18 00:24:25 +00:00
|
|
|
* $Id$
|
2000-06-11 05:19:21 +00:00
|
|
|
*
|
|
|
|
* Ethereal - Network traffic analyzer
|
2001-12-03 04:00:26 +00:00
|
|
|
* By Gerald Combs <gerald@ethereal.com>
|
2000-06-11 05:19:21 +00:00
|
|
|
* Copyright 1998 Gerald Combs
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
2000-06-11 05:19:21 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
2000-06-11 05:19:21 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
2000-06-11 05:19:21 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <glib.h>
|
2002-01-21 07:37:49 +00:00
|
|
|
#include <epan/packet.h>
|
2000-06-11 05:19:21 +00:00
|
|
|
|
|
|
|
#define UDP_PORT_SYSLOG 514
|
|
|
|
|
|
|
|
#define PRIORITY_MASK 0x0007 /* 0000 0111 */
|
|
|
|
#define FACILITY_MASK 0x03f8 /* 1111 1000 */
|
|
|
|
|
2000-06-11 15:54:03 +00:00
|
|
|
/* The maximum number if priority digits to read in. */
|
|
|
|
#define MAX_DIGITS 3
|
|
|
|
|
2000-06-18 22:12:14 +00:00
|
|
|
#define COL_INFO_LEN 32
|
2000-06-11 05:19:21 +00:00
|
|
|
#define ELLIPSIS "..." /* ISO 8859-1 doesn't appear to have a real ellipsis. */
|
|
|
|
|
2000-06-11 15:54:03 +00:00
|
|
|
static const value_string short_lev[] = {
|
2000-06-11 05:19:21 +00:00
|
|
|
{ 0, "EMERG" },
|
|
|
|
{ 1, "ALERT" },
|
|
|
|
{ 2, "CRIT" },
|
|
|
|
{ 3, "ERR" },
|
|
|
|
{ 4, "WARNING" },
|
|
|
|
{ 5, "NOTICE" },
|
|
|
|
{ 6, "INFO" },
|
|
|
|
{ 7, "DEBUG" },
|
|
|
|
{ 0, NULL },
|
|
|
|
};
|
|
|
|
|
|
|
|
static const value_string short_fac[] = {
|
|
|
|
{ 0, "KERN" },
|
|
|
|
{ 1, "USER" },
|
|
|
|
{ 2, "MAIL" },
|
|
|
|
{ 3, "DAEMON" },
|
|
|
|
{ 4, "AUTH" },
|
|
|
|
{ 5, "SYSLOG" },
|
|
|
|
{ 6, "LPR" },
|
|
|
|
{ 7, "NEWS" },
|
|
|
|
{ 8, "UUCP" },
|
2000-06-11 15:54:03 +00:00
|
|
|
{ 9, "CRON" }, /* The BSDs, Linux, and others */
|
2000-06-11 05:19:21 +00:00
|
|
|
{ 10, "AUTHPRIV" },
|
|
|
|
{ 11, "FTP" },
|
2000-06-11 15:54:03 +00:00
|
|
|
{ 15, "CRON" }, /* Solaris */
|
2000-06-11 05:19:21 +00:00
|
|
|
{ 16, "LOCAL0" },
|
|
|
|
{ 17, "LOCAL1" },
|
|
|
|
{ 18, "LOCAL2" },
|
|
|
|
{ 19, "LOCAL3" },
|
|
|
|
{ 20, "LOCAL4" },
|
|
|
|
{ 21, "LOCAL5" },
|
|
|
|
{ 22, "LOCAL6" },
|
|
|
|
{ 23, "LOCAL7" },
|
|
|
|
{ 0, NULL },
|
|
|
|
};
|
|
|
|
|
2000-06-11 15:54:03 +00:00
|
|
|
static const value_string long_lev[] = {
|
2000-06-11 05:19:21 +00:00
|
|
|
{ 0, "EMERG - system is unusable" },
|
|
|
|
{ 1, "ALERT - action must be taken immediately" },
|
|
|
|
{ 2, "CRIT - critical conditions" },
|
|
|
|
{ 3, "ERR - error conditions" },
|
|
|
|
{ 4, "WARNING - warning conditions" },
|
|
|
|
{ 5, "NOTICE - normal but significant condition" },
|
|
|
|
{ 6, "INFO - informational" },
|
|
|
|
{ 7, "DEBUG - debug-level messages" },
|
|
|
|
{ 0, NULL },
|
|
|
|
};
|
|
|
|
|
|
|
|
static const value_string long_fac[] = {
|
|
|
|
{ 0, "KERN - kernel messages" },
|
|
|
|
{ 1, "USER - random user-level messages" },
|
|
|
|
{ 2, "MAIL - mail system" },
|
|
|
|
{ 3, "DAEMON - system daemons" },
|
|
|
|
{ 4, "AUTH - security/authorization messages" },
|
|
|
|
{ 5, "SYSLOG - messages generated internally by syslogd" },
|
|
|
|
{ 6, "LPR - line printer subsystem" },
|
|
|
|
{ 7, "NEWS - network news subsystem" },
|
|
|
|
{ 8, "UUCP - UUCP subsystem" },
|
2000-06-11 15:54:03 +00:00
|
|
|
{ 9, "CRON - clock daemon (BSD, Linux)" },
|
2000-06-11 05:19:21 +00:00
|
|
|
{ 10, "AUTHPRIV - security/authorization messages (private)" },
|
|
|
|
{ 11, "FTP - ftp daemon" },
|
2000-06-11 15:54:03 +00:00
|
|
|
{ 15, "CRON - clock daemon (Solaris)" },
|
2000-06-11 05:19:21 +00:00
|
|
|
{ 16, "LOCAL0 - reserved for local use" },
|
|
|
|
{ 17, "LOCAL1 - reserved for local use" },
|
|
|
|
{ 18, "LOCAL2 - reserved for local use" },
|
|
|
|
{ 19, "LOCAL3 - reserved for local use" },
|
|
|
|
{ 20, "LOCAL4 - reserved for local use" },
|
|
|
|
{ 21, "LOCAL5 - reserved for local use" },
|
|
|
|
{ 22, "LOCAL6 - reserved for local use" },
|
|
|
|
{ 23, "LOCAL7 - reserved for local use" },
|
|
|
|
{ 0, NULL },
|
|
|
|
};
|
|
|
|
|
|
|
|
static gint proto_syslog = -1;
|
2000-06-11 15:54:03 +00:00
|
|
|
static gint hf_syslog_level = -1;
|
2000-06-11 05:19:21 +00:00
|
|
|
static gint hf_syslog_facility = -1;
|
2002-05-15 06:51:07 +00:00
|
|
|
static gint hf_syslog_msg = -1;
|
2000-06-11 05:19:21 +00:00
|
|
|
|
|
|
|
static gint ett_syslog = -1;
|
|
|
|
|
2002-08-28 21:04:11 +00:00
|
|
|
/* I couldn't find any documentation for the syslog message format.
|
2000-06-11 15:54:03 +00:00
|
|
|
According to the BSD sources, the message format is '<', P, '>', and
|
|
|
|
T. P is a decimal value, which should be treated as an 8 bit
|
|
|
|
unsigned integer. The lower three bits comprise the level, and the
|
2000-06-11 05:19:21 +00:00
|
|
|
upper five bits are the facility. T is the message text.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void dissect_syslog(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|
|
|
{
|
2000-06-11 15:54:03 +00:00
|
|
|
gint pri = -1, lev = -1, fac = -1;
|
2000-06-11 05:19:21 +00:00
|
|
|
gint msg_off = 0, msg_len;
|
2000-06-11 15:54:03 +00:00
|
|
|
gint ellipsis_len = (COL_INFO_LEN - strlen(ELLIPSIS)) - 1;
|
2000-06-11 05:19:21 +00:00
|
|
|
proto_item *ti;
|
|
|
|
proto_tree *syslog_tree;
|
|
|
|
gchar msg_str[COL_INFO_LEN];
|
|
|
|
|
2001-12-10 00:26:21 +00:00
|
|
|
if (check_col(pinfo->cinfo, COL_PROTOCOL))
|
|
|
|
col_set_str(pinfo->cinfo, COL_PROTOCOL, "Syslog");
|
|
|
|
if (check_col(pinfo->cinfo, COL_INFO))
|
|
|
|
col_clear(pinfo->cinfo, COL_INFO);
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2002-02-02 03:04:07 +00:00
|
|
|
if (tvb_get_guint8(tvb, msg_off) == '<') {
|
|
|
|
/* A facility and level follow. */
|
2000-06-11 05:19:21 +00:00
|
|
|
msg_off++;
|
2000-06-11 15:54:03 +00:00
|
|
|
pri = 0;
|
2002-02-02 03:04:07 +00:00
|
|
|
while (tvb_bytes_exist(tvb, msg_off, 1) &&
|
|
|
|
isdigit(tvb_get_guint8(tvb, msg_off)) && msg_off <= MAX_DIGITS) {
|
2000-06-11 15:54:03 +00:00
|
|
|
pri = pri * 10 + (tvb_get_guint8(tvb, msg_off) - '0');
|
2000-06-11 05:19:21 +00:00
|
|
|
msg_off++;
|
|
|
|
}
|
|
|
|
if (tvb_get_guint8(tvb, msg_off) == '>')
|
|
|
|
msg_off++;
|
2000-06-11 15:54:03 +00:00
|
|
|
fac = (pri & FACILITY_MASK) >> 3;
|
|
|
|
lev = pri & PRIORITY_MASK;
|
2000-06-11 05:19:21 +00:00
|
|
|
}
|
|
|
|
|
2000-06-11 15:54:03 +00:00
|
|
|
/* Copy the message into a string buffer, with a trailing ellipsis if needed. */
|
2002-02-02 03:04:07 +00:00
|
|
|
msg_len = tvb_ensure_length_remaining(tvb, msg_off);
|
2000-06-18 22:12:14 +00:00
|
|
|
if (msg_len >= COL_INFO_LEN) {
|
2000-06-11 15:54:03 +00:00
|
|
|
tvb_memcpy(tvb, msg_str, msg_off, ellipsis_len);
|
2005-10-27 09:43:32 +00:00
|
|
|
g_snprintf(msg_str + ellipsis_len, COL_INFO_LEN-ellipsis_len, "%s", ELLIPSIS);
|
2000-06-11 15:54:03 +00:00
|
|
|
} else {
|
|
|
|
tvb_memcpy(tvb, msg_str, msg_off, msg_len);
|
|
|
|
msg_str[msg_len] = '\0';
|
|
|
|
}
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2001-12-10 00:26:21 +00:00
|
|
|
if (check_col(pinfo->cinfo, COL_INFO)) {
|
2000-06-11 15:54:03 +00:00
|
|
|
if (pri >= 0) {
|
2002-08-28 21:04:11 +00:00
|
|
|
col_add_fstr(pinfo->cinfo, COL_INFO, "%s.%s: %s",
|
2000-06-11 05:19:21 +00:00
|
|
|
val_to_str(fac, short_fac, "UNKNOWN"),
|
2000-06-11 15:54:03 +00:00
|
|
|
val_to_str(lev, short_lev, "UNKNOWN"), msg_str);
|
2000-06-11 05:19:21 +00:00
|
|
|
} else {
|
2001-12-10 00:26:21 +00:00
|
|
|
col_add_fstr(pinfo->cinfo, COL_INFO, "%s", msg_str);
|
2000-06-11 05:19:21 +00:00
|
|
|
}
|
|
|
|
}
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2000-06-11 05:19:21 +00:00
|
|
|
if (tree) {
|
2000-06-11 15:54:03 +00:00
|
|
|
if (pri >= 0) {
|
2002-01-24 09:20:54 +00:00
|
|
|
ti = proto_tree_add_protocol_format(tree, proto_syslog, tvb, 0, -1,
|
|
|
|
"Syslog message: %s.%s: %s",
|
2000-06-11 05:19:21 +00:00
|
|
|
val_to_str(fac, short_fac, "UNKNOWN"),
|
2000-06-11 15:54:03 +00:00
|
|
|
val_to_str(lev, short_lev, "UNKNOWN"), msg_str);
|
2000-06-11 05:19:21 +00:00
|
|
|
} else {
|
2002-01-24 09:20:54 +00:00
|
|
|
ti = proto_tree_add_protocol_format(tree, proto_syslog, tvb, 0, -1,
|
|
|
|
"Syslog message: (unknown): %s", msg_str);
|
2000-06-11 05:19:21 +00:00
|
|
|
}
|
|
|
|
syslog_tree = proto_item_add_subtree(ti, ett_syslog);
|
2000-06-11 15:54:03 +00:00
|
|
|
if (pri >= 0) {
|
2000-06-11 05:19:21 +00:00
|
|
|
ti = proto_tree_add_uint(syslog_tree, hf_syslog_facility, tvb, 0,
|
2000-06-11 15:54:03 +00:00
|
|
|
msg_off, pri);
|
|
|
|
ti = proto_tree_add_uint(syslog_tree, hf_syslog_level, tvb, 0,
|
|
|
|
msg_off, pri);
|
2000-06-11 05:19:21 +00:00
|
|
|
}
|
2002-05-15 06:51:07 +00:00
|
|
|
proto_tree_add_item(syslog_tree, hf_syslog_msg, tvb, msg_off,
|
|
|
|
msg_len, FALSE);
|
2000-06-11 05:19:21 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2002-08-28 21:04:11 +00:00
|
|
|
|
2000-06-11 05:19:21 +00:00
|
|
|
/* Register the protocol with Ethereal */
|
|
|
|
void proto_register_syslog(void)
|
2002-08-28 21:04:11 +00:00
|
|
|
{
|
2000-06-11 05:19:21 +00:00
|
|
|
|
|
|
|
/* Setup list of header fields */
|
|
|
|
static hf_register_info hf[] = {
|
|
|
|
{ &hf_syslog_facility,
|
|
|
|
{ "Facility", "syslog.facility",
|
|
|
|
FT_UINT8, BASE_DEC, VALS(long_fac), FACILITY_MASK,
|
2001-06-18 02:18:27 +00:00
|
|
|
"Message facility", HFILL }
|
2000-06-11 05:19:21 +00:00
|
|
|
},
|
2000-06-11 15:54:03 +00:00
|
|
|
{ &hf_syslog_level,
|
|
|
|
{ "Level", "syslog.level",
|
|
|
|
FT_UINT8, BASE_DEC, VALS(long_lev), PRIORITY_MASK,
|
2001-06-18 02:18:27 +00:00
|
|
|
"Message level", HFILL }
|
2000-06-11 05:19:21 +00:00
|
|
|
},
|
2002-05-15 06:51:07 +00:00
|
|
|
{ &hf_syslog_msg,
|
|
|
|
{ "Message", "syslog.msg",
|
|
|
|
FT_STRING, BASE_NONE, NULL, 0x0,
|
|
|
|
"Message Text", HFILL }
|
2000-06-11 05:19:21 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Setup protocol subtree array */
|
|
|
|
static gint *ett[] = {
|
|
|
|
&ett_syslog,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Register the protocol name and description */
|
2001-01-03 06:56:03 +00:00
|
|
|
proto_syslog = proto_register_protocol("Syslog message", "Syslog", "syslog");
|
2000-06-11 05:19:21 +00:00
|
|
|
|
|
|
|
/* Required function calls to register the header fields and subtrees used */
|
|
|
|
proto_register_field_array(proto_syslog, hf, array_length(hf));
|
|
|
|
proto_register_subtree_array(ett, array_length(ett));
|
2002-05-30 08:34:19 +00:00
|
|
|
}
|
2000-06-11 05:19:21 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
proto_reg_handoff_syslog(void)
|
|
|
|
{
|
2001-12-03 04:00:26 +00:00
|
|
|
dissector_handle_t syslog_handle;
|
|
|
|
|
|
|
|
syslog_handle = create_dissector_handle(dissect_syslog, proto_syslog);
|
|
|
|
dissector_add("udp.port", UDP_PORT_SYSLOG, syslog_handle);
|
2000-06-11 05:19:21 +00:00
|
|
|
}
|