Skip to content

Commit

Permalink
Mining: cleanup registration
Browse files Browse the repository at this point in the history
Use the same pattern of all the other dissectors: one registration and
one callback.
Spotted by @dsokoloski
  • Loading branch information
IvanNardi committed Mar 24, 2022
1 parent 26df140 commit c3272e9
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions src/lib/protocols/mining.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ static void cacheMiningHostTwins(struct ndpi_detection_module_struct *ndpi_struc

/* ************************************************************************** */

void ndpi_search_mining_udp(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow) {
static void ndpi_search_mining_udp(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow) {
struct ndpi_packet_struct *packet = &ndpi_struct->packet;
u_int16_t source = ntohs(packet->udp->source);
u_int16_t dest = ntohs(packet->udp->dest);
Expand All @@ -49,8 +49,7 @@ void ndpi_search_mining_udp(struct ndpi_detection_module_struct *ndpi_struct,
Ethereum P2P Discovery Protocol
https://github.com/ConsenSys/ethereum-dissectors/blob/master/packet-ethereum-disc.c
*/
if(packet->udp
&& (packet->payload_packet_len > 98)
if((packet->payload_packet_len > 98)
&& (packet->payload_packet_len < 1280)
&& ((source == 30303) || (dest == 30303))
&& (packet->payload[97] <= 0x04 /* NODES */)
Expand Down Expand Up @@ -79,14 +78,14 @@ static u_int8_t isEthPort(u_int16_t dport) {

/* ************************************************************************** */

void ndpi_search_mining_tcp(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow) {
static void ndpi_search_mining_tcp(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow) {
struct ndpi_packet_struct *packet = &ndpi_struct->packet;

NDPI_LOG_DBG(ndpi_struct, "search MINING TCP\n");

/* Check connection over TCP */
if(packet->tcp && (packet->payload_packet_len > 10)) {
if(packet->payload_packet_len > 10) {
if(packet->tcp->source == htons(8333) ||
packet->tcp->dest == htons(8333)) {
/*
Expand Down Expand Up @@ -166,26 +165,27 @@ void ndpi_search_mining_tcp(struct ndpi_detection_module_struct *ndpi_struct,
ndpi_exclude_protocol(ndpi_struct, flow, NDPI_PROTOCOL_MINING, __FILE__, __FUNCTION__, __LINE__);
}

/* ************************************************************************** */

void ndpi_search_mining(struct ndpi_detection_module_struct *ndpi_struct,
struct ndpi_flow_struct *flow) {
struct ndpi_packet_struct *packet = &ndpi_struct->packet;

if(packet->tcp)
return ndpi_search_mining_tcp(ndpi_struct, flow);
return ndpi_search_mining_udp(ndpi_struct, flow);
}


/* ************************************************************************** */

void init_mining_dissector(struct ndpi_detection_module_struct *ndpi_struct,
u_int32_t *id, NDPI_PROTOCOL_BITMASK *detection_bitmask)
{
ndpi_set_bitmask_protocol_detection("Mining", ndpi_struct, detection_bitmask, *id,
NDPI_PROTOCOL_MINING,
ndpi_search_mining_tcp,
NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_WITH_PAYLOAD_WITHOUT_RETRANSMISSION,
SAVE_DETECTION_BITMASK_AS_UNKNOWN,
ADD_TO_DETECTION_BITMASK);

*id += 1;

/* ************ */

ndpi_set_bitmask_protocol_detection("Mining", ndpi_struct, detection_bitmask, *id,
NDPI_PROTOCOL_MINING,
ndpi_search_mining_udp,
NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_UDP_WITH_PAYLOAD,
ndpi_search_mining,
NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_TCP_OR_UDP_WITH_PAYLOAD_WITHOUT_RETRANSMISSION,
SAVE_DETECTION_BITMASK_AS_UNKNOWN,
ADD_TO_DETECTION_BITMASK);

Expand Down

0 comments on commit c3272e9

Please sign in to comment.