Coverage Report

Created: 2025-06-13 06:05

/src/ndpi/src/lib/protocols/git.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * git.c
3
 *
4
 * Copyright (C) 2012-22 - ntop.org
5
 *
6
 * This module 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
 * This module 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
 * 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_GIT
24
25
#include "ndpi_api.h"
26
#include "ndpi_private.h"
27
28
29
0
#define GIT_PORT 9418
30
31
static void ndpi_search_git(struct ndpi_detection_module_struct *ndpi_struct,
32
          struct ndpi_flow_struct *flow)
33
0
{
34
0
  struct ndpi_packet_struct * packet = &ndpi_struct->packet;
35
36
0
  NDPI_LOG_DBG(ndpi_struct, "search Git\n");
37
38
0
  if((packet->tcp != NULL) && (packet->payload_packet_len > 4)) {
39
0
    if((ntohs(packet->tcp->source) == GIT_PORT)
40
0
       || (ntohs(packet->tcp->dest) == GIT_PORT)) {
41
0
      const u_int8_t * pp = packet->payload;
42
0
      u_int16_t payload_len = packet->payload_packet_len;  
43
0
      u_int8_t found_git = 1;
44
0
      u_int16_t offset = 0;
45
      
46
0
      while((offset+4) < payload_len) {
47
0
  char len[5];
48
0
  u_int32_t git_pkt_len;
49
50
0
  memcpy(&len, &pp[offset], 4), len[4] = 0;
51
0
  if(sscanf(len, "%x", &git_pkt_len) != 1) {
52
0
    found_git = 0;
53
0
    break;
54
0
  }
55
56
0
  if((payload_len < git_pkt_len) || (git_pkt_len == 0 /* Bad */)) {
57
0
    found_git = 0;
58
0
    break;
59
0
  } else
60
0
    offset += git_pkt_len, payload_len -= git_pkt_len;      
61
0
      }
62
63
0
      if(found_git) {
64
0
  NDPI_LOG_INFO(ndpi_struct, "found Git\n");
65
0
  ndpi_set_detected_protocol(ndpi_struct, flow, NDPI_PROTOCOL_GIT, NDPI_PROTOCOL_UNKNOWN, NDPI_CONFIDENCE_DPI);
66
0
  return;
67
0
      }
68
0
    }
69
0
  }
70
  
71
0
  NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow);
72
0
}
73
74
75
/* ***************************************************************** */
76
77
void init_git_dissector(struct ndpi_detection_module_struct *ndpi_struct)
78
1
{
79
1
  register_dissector("Git", ndpi_struct,
80
1
                     ndpi_search_git,
81
1
                     NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_WITH_PAYLOAD_WITHOUT_RETRANSMISSION,
82
1
                     1, NDPI_PROTOCOL_GIT);
83
1
}