Coverage Report

Created: 2026-03-01 06:45

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ndpi/src/lib/protocols/syslog.c
Line
Count
Source
1
/*
2
 * syslog.c
3
 *
4
 * Copyright (C) 2009-11 - ipoque GmbH
5
 * Copyright (C) 2011-26 - ntop.org
6
 *
7
 * This file is part of nDPI, an open source deep packet inspection
8
 * library based on the OpenDPI and PACE technology by ipoque GmbH
9
 *
10
 * nDPI is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU Lesser General Public License as published by
12
 * the Free Software Foundation, either version 3 of the License, or
13
 * (at your option) any later version.
14
 *
15
 * nDPI is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU Lesser General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU Lesser General Public License
21
 * along with nDPI.  If not, see <http://www.gnu.org/licenses/>.
22
 * 
23
 */
24
25
#include "ndpi_protocol_ids.h"
26
27
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_SYSLOG
28
29
#include "ndpi_api.h"
30
#include "ndpi_private.h"
31
32
static void ndpi_int_syslog_add_connection(struct ndpi_detection_module_struct
33
             *ndpi_struct, struct ndpi_flow_struct *flow)
34
14
{
35
14
  ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_SYSLOG, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI);
36
14
}
37
38
static void ndpi_search_syslog(struct ndpi_detection_module_struct *ndpi_struct,
39
             struct ndpi_flow_struct *flow)
40
2.47k
{
41
2.47k
  struct ndpi_packet_struct *packet = &ndpi_struct->packet;
42
2.47k
  u_int16_t i;
43
44
2.47k
  NDPI_LOG_DBG(ndpi_struct, "search syslog\n");
45
46
2.47k
  if (packet->payload_packet_len > 20 && packet->payload[0] == '<') {
47
46
    NDPI_LOG_DBG2(ndpi_struct, "checked len>20 and <1024 and first symbol=<\n");
48
49
51
    for (i = 1; i <= 3; i++) {
50
50
      if (packet->payload[i] < '0' || packet->payload[i] > '9') {
51
45
    break;
52
45
      }
53
50
    }
54
46
    NDPI_LOG_DBG2(ndpi_struct,
55
46
             "read symbols while the symbol is a number.\n");
56
57
46
    if (packet->payload[i++] != '>') {
58
18
      NDPI_LOG_DBG(ndpi_struct, "excluded, there is no > following the number\n");
59
18
      NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow);
60
18
      return;
61
28
    } else {
62
28
      NDPI_LOG_DBG2(ndpi_struct, "a > following the number\n");
63
28
    }
64
65
28
    if (packet->payload[i] == 0x20) {
66
0
      NDPI_LOG_DBG2(ndpi_struct, "a blank following the >: increment i\n");
67
0
      i++;
68
28
    } else {
69
28
      NDPI_LOG_DBG2(ndpi_struct, "no blank following the >: do nothing\n");
70
28
    }
71
72
1.14k
    while (i < packet->payload_packet_len - 1)
73
1.13k
    {
74
1.13k
        if (ndpi_isalnum(packet->payload[i]) == 0)
75
19
        {
76
19
            if (packet->payload[i] == ' ' || packet->payload[i] == ':' ||
77
16
                packet->payload[i] == '=' || packet->payload[i] == '[' ||
78
14
                packet->payload[i] == '-')
79
7
            {
80
7
                break;
81
7
            }
82
12
            NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow);
83
12
            return;
84
19
        }
85
86
1.11k
        i++;
87
1.11k
    }
88
89
16
    if (packet->payload[i] == ':')
90
3
    {
91
3
        if (++i >= packet->payload_packet_len ||
92
2
            packet->payload[i] != ' ')
93
2
        {
94
2
            NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow);
95
2
            return;
96
2
        }
97
3
    }
98
99
14
    NDPI_LOG_INFO(ndpi_struct, "found syslog\n");
100
14
    ndpi_int_syslog_add_connection(ndpi_struct, flow);
101
14
    return;
102
16
  }
103
2.43k
  NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow);
104
2.43k
}
105
106
107
void init_syslog_dissector(struct ndpi_detection_module_struct *ndpi_struct)
108
7.18k
{
109
7.18k
  ndpi_register_dissector("Syslog", ndpi_struct,
110
7.18k
                     ndpi_search_syslog,
111
7.18k
                     NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_OR_UDP_WITH_PAYLOAD_WITHOUT_RETRANSMISSION,
112
7.18k
                     1, NDPI_PROTOCOL_SYSLOG);
113
7.18k
}