Coverage Report

Created: 2023-06-29 06:52

/src/ndpi/src/lib/protocols/halflife2_and_mods.c
Line
Count
Source
1
/*
2
 * halflife2_and_mods.c
3
 *
4
 * Copyright (C) 2009-11 - ipoque GmbH
5
 * Copyright (C) 2011-22 - 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
26
#include "ndpi_protocol_ids.h"
27
28
161k
#define NDPI_CURRENT_PROTO NDPI_PROTOCOL_HALFLIFE2
29
30
#include "ndpi_api.h"
31
32
33
static void ndpi_int_halflife2_add_connection(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
34
15
{
35
15
  ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_HALFLIFE2, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI);
36
15
}
37
38
static void ndpi_search_halflife2(struct ndpi_detection_module_struct *ndpi_struct, struct ndpi_flow_struct *flow)
39
161k
{
40
161k
  struct ndpi_packet_struct *packet = &ndpi_struct->packet;
41
  
42
161k
  NDPI_LOG_DBG(ndpi_struct, "search halflife2\n");
43
44
161k
  if (flow->l4.udp.halflife2_stage == 0) {
45
161k
    if (packet->payload_packet_len >= 20
46
161k
      && get_u_int32_t(packet->payload, 0) == 0xFFFFFFFF
47
161k
      && get_u_int32_t(packet->payload, packet->payload_packet_len - 4) == htonl(0x30303000)) {
48
143
      flow->l4.udp.halflife2_stage = 1 + packet->packet_direction;
49
143
      NDPI_LOG_DBG2(ndpi_struct,
50
143
          "halflife2 client req detected, waiting for server reply\n");
51
143
      return;
52
143
    }
53
161k
  } else if (flow->l4.udp.halflife2_stage == 2 - packet->packet_direction) {
54
34
    if (packet->payload_packet_len >= 20
55
34
      && get_u_int32_t(packet->payload, 0) == 0xFFFFFFFF
56
34
      && get_u_int32_t(packet->payload, packet->payload_packet_len - 4) == htonl(0x30303000)) {
57
15
      ndpi_int_halflife2_add_connection(ndpi_struct, flow);
58
15
      NDPI_LOG_INFO(ndpi_struct, "found halflife2\n");
59
15
      return;
60
15
    }
61
34
  }
62
63
161k
  NDPI_EXCLUDE_PROTO(ndpi_struct, flow);
64
161k
}
65
66
67
void init_halflife2_dissector(struct ndpi_detection_module_struct *ndpi_struct, u_int32_t *id)
68
8.55k
{
69
8.55k
  ndpi_set_bitmask_protocol_detection("HalfLife2", ndpi_struct, *id,
70
8.55k
              NDPI_PROTOCOL_HALFLIFE2,
71
8.55k
              ndpi_search_halflife2,
72
8.55k
              NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_UDP_WITH_PAYLOAD,
73
8.55k
              SAVE_DETECTION_BITMASK_AS_UNKNOWN,
74
8.55k
              ADD_TO_DETECTION_BITMASK);
75
76
8.55k
  *id += 1;
77
8.55k
}