The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1 | /* |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 2 | * Copyright (c) 1998-2004 Hannes Gredler <hannes@gredler.at> |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 3 | * The TCPDUMP project |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that: (1) source code |
| 7 | * distributions retain the above copyright notice and this paragraph |
| 8 | * in its entirety, and (2) distributions including binary code include |
| 9 | * the above copyright notice and this paragraph in its entirety in |
| 10 | * the documentation or other materials provided with the distribution. |
| 11 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND |
| 12 | * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT |
| 13 | * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 14 | * FOR A PARTICULAR PURPOSE. |
| 15 | */ |
| 16 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 17 | /* \summary: Syslog protocol printer */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 18 | /* specification: RFC 3164 (not RFC 5424) */ |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 19 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 20 | #ifdef HAVE_CONFIG_H |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 21 | #include <config.h> |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 22 | #endif |
| 23 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 24 | #include "netdissect-stdinc.h" |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 25 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 26 | #include "netdissect.h" |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 27 | #include "extract.h" |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 28 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 29 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 30 | /* |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 31 | * tokenlists and #defines taken from Ethereal - Network traffic analyzer |
| 32 | * by Gerald Combs <gerald@ethereal.com> |
| 33 | */ |
| 34 | |
| 35 | #define SYSLOG_SEVERITY_MASK 0x0007 /* 0000 0000 0000 0111 */ |
| 36 | #define SYSLOG_FACILITY_MASK 0x03f8 /* 0000 0011 1111 1000 */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 37 | #define SYSLOG_MAX_DIGITS 3 /* The maximum number of priority digits to read in. */ |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 38 | |
| 39 | static const struct tok syslog_severity_values[] = { |
| 40 | { 0, "emergency" }, |
| 41 | { 1, "alert" }, |
| 42 | { 2, "critical" }, |
| 43 | { 3, "error" }, |
| 44 | { 4, "warning" }, |
| 45 | { 5, "notice" }, |
| 46 | { 6, "info" }, |
| 47 | { 7, "debug" }, |
| 48 | { 0, NULL }, |
| 49 | }; |
| 50 | |
| 51 | static const struct tok syslog_facility_values[] = { |
| 52 | { 0, "kernel" }, |
| 53 | { 1, "user" }, |
| 54 | { 2, "mail" }, |
| 55 | { 3, "daemon" }, |
| 56 | { 4, "auth" }, |
| 57 | { 5, "syslog" }, |
| 58 | { 6, "lpr" }, |
| 59 | { 7, "news" }, |
| 60 | { 8, "uucp" }, |
| 61 | { 9, "cron" }, |
| 62 | { 10, "authpriv" }, |
| 63 | { 11, "ftp" }, |
| 64 | { 12, "ntp" }, |
| 65 | { 13, "security" }, |
| 66 | { 14, "console" }, |
| 67 | { 15, "cron" }, |
| 68 | { 16, "local0" }, |
| 69 | { 17, "local1" }, |
| 70 | { 18, "local2" }, |
| 71 | { 19, "local3" }, |
| 72 | { 20, "local4" }, |
| 73 | { 21, "local5" }, |
| 74 | { 22, "local6" }, |
| 75 | { 23, "local7" }, |
| 76 | { 0, NULL }, |
| 77 | }; |
| 78 | |
| 79 | void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 80 | syslog_print(netdissect_options *ndo, |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 81 | const u_char *pptr, u_int len) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 82 | { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 83 | uint16_t msg_off = 0; |
| 84 | uint16_t pri = 0; |
| 85 | uint16_t facility,severity; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 86 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 87 | ndo->ndo_protocol = "syslog"; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 88 | /* extract decimal figures that are |
| 89 | * encapsulated within < > tags |
| 90 | * based on this decimal figure extract the |
| 91 | * severity and facility values |
| 92 | */ |
| 93 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 94 | if (GET_U_1(pptr) != '<') |
| 95 | goto invalid; |
| 96 | msg_off++; |
| 97 | |
| 98 | while (msg_off <= SYSLOG_MAX_DIGITS && |
| 99 | GET_U_1(pptr + msg_off) >= '0' && |
| 100 | GET_U_1(pptr + msg_off) <= '9') { |
| 101 | pri = pri * 10 + (GET_U_1(pptr + msg_off) - '0'); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 102 | msg_off++; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 103 | } |
| 104 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 105 | if (GET_U_1(pptr + msg_off) != '>') |
| 106 | goto invalid; |
| 107 | msg_off++; |
| 108 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 109 | facility = (pri & SYSLOG_FACILITY_MASK) >> 3; |
| 110 | severity = pri & SYSLOG_SEVERITY_MASK; |
| 111 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 112 | if (ndo->ndo_vflag < 1 ) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 113 | { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 114 | ND_PRINT("SYSLOG %s.%s, length: %u", |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 115 | tok2str(syslog_facility_values, "unknown (%u)", facility), |
| 116 | tok2str(syslog_severity_values, "unknown (%u)", severity), |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 117 | len); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 118 | return; |
| 119 | } |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 120 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 121 | ND_PRINT("SYSLOG, length: %u\n\tFacility %s (%u), Severity %s (%u)\n\tMsg: ", |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 122 | len, |
| 123 | tok2str(syslog_facility_values, "unknown (%u)", facility), |
| 124 | facility, |
| 125 | tok2str(syslog_severity_values, "unknown (%u)", severity), |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 126 | severity); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 127 | |
| 128 | /* print the syslog text in verbose mode */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 129 | /* |
| 130 | * RFC 3164 Section 4.1.3: "There is no ending delimiter to this part. |
| 131 | * The MSG part of the syslog packet MUST contain visible (printing) |
| 132 | * characters." |
| 133 | * |
| 134 | * RFC 5424 Section 8.2: "This document does not impose any mandatory |
| 135 | * restrictions on the MSG or PARAM-VALUE content. As such, they MAY |
| 136 | * contain control characters, including the NUL character." |
| 137 | * |
| 138 | * Hence, to aid in protocol debugging, print the full MSG without |
| 139 | * beautification to make it clear what was transmitted on the wire. |
| 140 | */ |
| 141 | if (len > msg_off) |
| 142 | (void)nd_printn(ndo, pptr + msg_off, len - msg_off, NULL); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 143 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 144 | if (ndo->ndo_vflag > 1) |
| 145 | print_unknown_data(ndo, pptr, "\n\t", len); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 146 | return; |
| 147 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 148 | invalid: |
| 149 | nd_print_invalid(ndo); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 150 | } |