Coverage Report

Created: 2026-06-25 07:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ndpi/src/lib/protocols/mudfish.c
Line
Count
Source
1
/*
2
 * mudfish.c
3
 *
4
 * Copyright (C) 2011-26 - ntop.org
5
 *
6
 * nDPI is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU Lesser General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * nDPI is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public License
17
 * along with nDPI.  If not, see <http://www.gnu.org/licenses/>.
18
 *
19
 */
20
21
#include "ndpi_protocol_ids.h"
22
23
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_MUDFISH
24
25
#include "ndpi_api.h"
26
#include "ndpi_private.h"
27
28
static void ndpi_int_mudfish_add_connection(struct ndpi_detection_module_struct * const ndpi_struct,
29
                                            struct ndpi_flow_struct * const flow)
30
282
{
31
282
  NDPI_LOG_INFO(ndpi_struct, "found Mudfish\n");
32
282
  ndpi_set_detected_protocol(ndpi_struct, flow,
33
282
                             NDPI_PROTOCOL_MUDFISH,
34
282
                             NDPI_PROTOCOL_UNKNOWN,
35
282
                             NDPI_CONFIDENCE_DPI);
36
282
}
37
38
static void ndpi_search_mudfish(struct ndpi_detection_module_struct *ndpi_struct,
39
                                struct ndpi_flow_struct *flow)
40
4.50M
{
41
4.50M
  struct ndpi_packet_struct const * const packet = &ndpi_struct->packet;
42
43
4.50M
  NDPI_LOG_DBG(ndpi_struct, "search Mudfish\n");
44
45
4.50M
  if (packet->udp != NULL)
46
1.10M
  {
47
1.10M
    if ((packet->udp->source < htons(10000) ||
48
934k
         packet->udp->source > htons(10010)) &&
49
1.06M
        (packet->udp->dest < htons(10000) ||
50
922k
         packet->udp->dest > htons(10010)))
51
1.03M
    {
52
1.03M
      NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow);
53
1.03M
      return;
54
1.03M
    }
55
56
    // Mudfish ping
57
70.5k
    if (packet->payload_packet_len == 1 &&
58
1.85k
        packet->payload[0] == 0x50)
59
557
    {
60
557
      if (flow->packet_counter >= 2)
61
211
        ndpi_int_mudfish_add_connection(ndpi_struct, flow);
62
557
      return;
63
557
    }
64
65
69.9k
    NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow);
66
69.9k
    return;
67
70.5k
  }
68
69
  // Mudfish discovery request
70
3.39M
  if (packet->payload_packet_len == 7 &&
71
39.3k
      get_u_int32_t(packet->payload, 0) == htonl(0x554e2076) &&
72
228
      get_u_int16_t(packet->payload, 4) == htons(0x320d) &&
73
141
      packet->payload[6] == 0x0a)
74
71
  {
75
71
    ndpi_int_mudfish_add_connection(ndpi_struct, flow);
76
71
    return;
77
71
  }
78
79
  // Check discovery response
80
3.39M
  if (packet->payload_packet_len > 8 &&
81
2.38M
      get_u_int32_t(packet->payload, 0) == htonl(0x554e2041) &&
82
12
      get_u_int32_t(packet->payload, 0) == htonl(0x465f494e))
83
0
  {
84
0
    ndpi_int_mudfish_add_connection(ndpi_struct, flow);
85
0
    return;
86
0
  }
87
88
3.39M
  NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow);
89
3.39M
}
90
91
void init_mudfish_dissector(struct ndpi_detection_module_struct *ndpi_struct)
92
20.3k
{
93
20.3k
  ndpi_register_dissector("Mudfish", ndpi_struct,
94
20.3k
                     ndpi_search_mudfish,
95
20.3k
                     NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_OR_UDP_WITH_PAYLOAD_WITHOUT_RETRANSMISSION,
96
20.3k
                     1, NDPI_PROTOCOL_MUDFISH);
97
20.3k
}