2 * Routines for syslog message dissection
4 * Copyright 2000, Gerald Combs <gerald@zing.org>
6 * $Id: packet-syslog.c,v 1.8 2001/01/03 06:55:33 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 CHECK_DISPLAY_AS_DATA(proto_syslog, tvb, pinfo, tree);
150 pinfo->current_proto = "Syslog";
151 msg_len = tvb_length(tvb);
153 if (tvb_get_guint8(tvb, 0) == '<' && isdigit(tvb_get_guint8(tvb, 1))) {
156 while (isdigit(tvb_get_guint8(tvb, msg_off)) && msg_off <= MAX_DIGITS &&
157 tvb_length_remaining(tvb, msg_off)) {
158 pri = pri * 10 + (tvb_get_guint8(tvb, msg_off) - '0');
161 if (tvb_get_guint8(tvb, msg_off) == '>')
163 fac = (pri & FACILITY_MASK) >> 3;
164 lev = pri & PRIORITY_MASK;
167 /* Copy the message into a string buffer, with a trailing ellipsis if needed. */
168 msg_len = tvb_length_remaining(tvb, msg_off);
169 if (msg_len >= COL_INFO_LEN) {
170 tvb_memcpy(tvb, msg_str, msg_off, ellipsis_len);
171 strcpy (msg_str + ellipsis_len, ELLIPSIS);
173 tvb_memcpy(tvb, msg_str, msg_off, msg_len);
174 msg_str[msg_len] = '\0';
177 if (check_col(pinfo->fd, COL_PROTOCOL))
178 col_set_str(pinfo->fd, COL_PROTOCOL, "Syslog");
180 if (check_col(pinfo->fd, COL_INFO)) {
182 col_add_fstr(pinfo->fd, COL_INFO, "%s.%s: %s",
183 val_to_str(fac, short_fac, "UNKNOWN"),
184 val_to_str(lev, short_lev, "UNKNOWN"), msg_str);
186 col_add_fstr(pinfo->fd, COL_INFO, "%s", msg_str);
192 ti = proto_tree_add_protocol_format(tree, proto_syslog, tvb, 0,
193 tvb_length(tvb), "Syslog message: %s.%s: %s",
194 val_to_str(fac, short_fac, "UNKNOWN"),
195 val_to_str(lev, short_lev, "UNKNOWN"), msg_str);
197 ti = proto_tree_add_protocol_format(tree, proto_syslog, tvb, 0,
198 tvb_length(tvb), "Syslog message: (unknown): %s", msg_str);
200 syslog_tree = proto_item_add_subtree(ti, ett_syslog);
202 ti = proto_tree_add_uint(syslog_tree, hf_syslog_facility, tvb, 0,
204 ti = proto_tree_add_uint(syslog_tree, hf_syslog_level, tvb, 0,
207 proto_tree_add_uint_format(syslog_tree, hf_syslog_msg_len, tvb, msg_off,
208 msg_len, msg_len, "Message (%d byte%s)", msg_len, plurality(msg_len, "", "s"));
213 /* Register the protocol with Ethereal */
214 void proto_register_syslog(void)
217 /* Setup list of header fields */
218 static hf_register_info hf[] = {
219 { &hf_syslog_facility,
220 { "Facility", "syslog.facility",
221 FT_UINT8, BASE_DEC, VALS(long_fac), FACILITY_MASK,
225 { "Level", "syslog.level",
226 FT_UINT8, BASE_DEC, VALS(long_lev), PRIORITY_MASK,
229 { &hf_syslog_msg_len,
230 { "Message length", "syslog.msg_len",
231 FT_UINT32, BASE_DEC, NULL, 0x0,
232 "Message length, excluding priority descriptor" }
236 /* Setup protocol subtree array */
237 static gint *ett[] = {
241 /* Register the protocol name and description */
242 proto_syslog = proto_register_protocol("Syslog message", "Syslog", "syslog");
244 /* Required function calls to register the header fields and subtrees used */
245 proto_register_field_array(proto_syslog, hf, array_length(hf));
246 proto_register_subtree_array(ett, array_length(ett));
250 proto_reg_handoff_syslog(void)
252 dissector_add("udp.port", UDP_PORT_SYSLOG, dissect_syslog);