2 * Routines for syslog message dissection
4 * Copyright 2000, Gerald Combs <gerald@zing.org>
6 * $Id: packet-syslog.c,v 1.11 2001/06/18 02:17:53 guy Exp $
8 * Ethereal - Network traffic analyzer
9 * By Gerald Combs <gerald@zing.org>
10 * Copyright 1998 Gerald Combs
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
40 #define UDP_PORT_SYSLOG 514
42 #define PRIORITY_MASK 0x0007 /* 0000 0111 */
43 #define FACILITY_MASK 0x03f8 /* 1111 1000 */
45 /* The maximum number if priority digits to read in. */
48 #define COL_INFO_LEN 32
49 #define ELLIPSIS "..." /* ISO 8859-1 doesn't appear to have a real ellipsis. */
51 static const value_string short_lev[] = {
63 static const value_string short_fac[] = {
73 { 9, "CRON" }, /* The BSDs, Linux, and others */
76 { 15, "CRON" }, /* Solaris */
88 static const value_string long_lev[] = {
89 { 0, "EMERG - system is unusable" },
90 { 1, "ALERT - action must be taken immediately" },
91 { 2, "CRIT - critical conditions" },
92 { 3, "ERR - error conditions" },
93 { 4, "WARNING - warning conditions" },
94 { 5, "NOTICE - normal but significant condition" },
95 { 6, "INFO - informational" },
96 { 7, "DEBUG - debug-level messages" },
100 static const value_string long_fac[] = {
101 { 0, "KERN - kernel messages" },
102 { 1, "USER - random user-level messages" },
103 { 2, "MAIL - mail system" },
104 { 3, "DAEMON - system daemons" },
105 { 4, "AUTH - security/authorization messages" },
106 { 5, "SYSLOG - messages generated internally by syslogd" },
107 { 6, "LPR - line printer subsystem" },
108 { 7, "NEWS - network news subsystem" },
109 { 8, "UUCP - UUCP subsystem" },
110 { 9, "CRON - clock daemon (BSD, Linux)" },
111 { 10, "AUTHPRIV - security/authorization messages (private)" },
112 { 11, "FTP - ftp daemon" },
113 { 15, "CRON - clock daemon (Solaris)" },
114 { 16, "LOCAL0 - reserved for local use" },
115 { 17, "LOCAL1 - reserved for local use" },
116 { 18, "LOCAL2 - reserved for local use" },
117 { 19, "LOCAL3 - reserved for local use" },
118 { 20, "LOCAL4 - reserved for local use" },
119 { 21, "LOCAL5 - reserved for local use" },
120 { 22, "LOCAL6 - reserved for local use" },
121 { 23, "LOCAL7 - reserved for local use" },
125 static gint proto_syslog = -1;
126 static gint hf_syslog_level = -1;
127 static gint hf_syslog_facility = -1;
128 static gint hf_syslog_msg_len = -1;
130 static gint ett_syslog = -1;
132 /* I couldn't find any documentation for the syslog message format.
133 According to the BSD sources, the message format is '<', P, '>', and
134 T. P is a decimal value, which should be treated as an 8 bit
135 unsigned integer. The lower three bits comprise the level, and the
136 upper five bits are the facility. T is the message text.
139 static void dissect_syslog(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
141 gint pri = -1, lev = -1, fac = -1;
142 gint msg_off = 0, msg_len;
143 gint ellipsis_len = (COL_INFO_LEN - strlen(ELLIPSIS)) - 1;
145 proto_tree *syslog_tree;
146 gchar msg_str[COL_INFO_LEN];
148 if (check_col(pinfo->fd, COL_PROTOCOL))
149 col_set_str(pinfo->fd, COL_PROTOCOL, "Syslog");
150 if (check_col(pinfo->fd, COL_INFO))
151 col_clear(pinfo->fd, COL_INFO);
153 msg_len = tvb_length(tvb);
155 if (tvb_get_guint8(tvb, 0) == '<' && isdigit(tvb_get_guint8(tvb, 1))) {
158 while (isdigit(tvb_get_guint8(tvb, msg_off)) && msg_off <= MAX_DIGITS &&
159 tvb_length_remaining(tvb, msg_off)) {
160 pri = pri * 10 + (tvb_get_guint8(tvb, msg_off) - '0');
163 if (tvb_get_guint8(tvb, msg_off) == '>')
165 fac = (pri & FACILITY_MASK) >> 3;
166 lev = pri & PRIORITY_MASK;
169 /* Copy the message into a string buffer, with a trailing ellipsis if needed. */
170 msg_len = tvb_length_remaining(tvb, msg_off);
171 if (msg_len >= COL_INFO_LEN) {
172 tvb_memcpy(tvb, msg_str, msg_off, ellipsis_len);
173 strcpy (msg_str + ellipsis_len, ELLIPSIS);
175 tvb_memcpy(tvb, msg_str, msg_off, msg_len);
176 msg_str[msg_len] = '\0';
179 if (check_col(pinfo->fd, COL_INFO)) {
181 col_add_fstr(pinfo->fd, COL_INFO, "%s.%s: %s",
182 val_to_str(fac, short_fac, "UNKNOWN"),
183 val_to_str(lev, short_lev, "UNKNOWN"), msg_str);
185 col_add_fstr(pinfo->fd, COL_INFO, "%s", msg_str);
191 ti = proto_tree_add_protocol_format(tree, proto_syslog, tvb, 0,
192 tvb_length(tvb), "Syslog message: %s.%s: %s",
193 val_to_str(fac, short_fac, "UNKNOWN"),
194 val_to_str(lev, short_lev, "UNKNOWN"), msg_str);
196 ti = proto_tree_add_protocol_format(tree, proto_syslog, tvb, 0,
197 tvb_length(tvb), "Syslog message: (unknown): %s", msg_str);
199 syslog_tree = proto_item_add_subtree(ti, ett_syslog);
201 ti = proto_tree_add_uint(syslog_tree, hf_syslog_facility, tvb, 0,
203 ti = proto_tree_add_uint(syslog_tree, hf_syslog_level, tvb, 0,
206 proto_tree_add_uint_format(syslog_tree, hf_syslog_msg_len, tvb, msg_off,
207 msg_len, msg_len, "Message (%d byte%s)", msg_len, plurality(msg_len, "", "s"));
212 /* Register the protocol with Ethereal */
213 void proto_register_syslog(void)
216 /* Setup list of header fields */
217 static hf_register_info hf[] = {
218 { &hf_syslog_facility,
219 { "Facility", "syslog.facility",
220 FT_UINT8, BASE_DEC, VALS(long_fac), FACILITY_MASK,
221 "Message facility", HFILL }
224 { "Level", "syslog.level",
225 FT_UINT8, BASE_DEC, VALS(long_lev), PRIORITY_MASK,
226 "Message level", HFILL }
228 { &hf_syslog_msg_len,
229 { "Message length", "syslog.msg_len",
230 FT_UINT32, BASE_DEC, NULL, 0x0,
231 "Message length, excluding priority descriptor", HFILL }
235 /* Setup protocol subtree array */
236 static gint *ett[] = {
240 /* Register the protocol name and description */
241 proto_syslog = proto_register_protocol("Syslog message", "Syslog", "syslog");
243 /* Required function calls to register the header fields and subtrees used */
244 proto_register_field_array(proto_syslog, hf, array_length(hf));
245 proto_register_subtree_array(ett, array_length(ett));
249 proto_reg_handoff_syslog(void)
251 dissector_add("udp.port", UDP_PORT_SYSLOG, dissect_syslog, proto_syslog);