fix indent code and int type to keep conformity of the rest of the code (u_intxx instead uintxx)

This commit is contained in:
Campus
2016-12-15 12:15:48 +01:00
parent b68f197fea
commit 61f0eb062e
+227 -227
View File
@@ -1,23 +1,23 @@
/* /*
* smpp.c * smpp.c
* *
* Copyright (C) 2016 - Damir Franusic <df@release14.org> * Copyright (C) 2016 - Damir Franusic <df@release14.org>
* Copyright (C) 2016 - ntop.org * Copyright (C) 2016 - ntop.org
* *
* nDPI is free software: you can redistribute it and/or modify * nDPI is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by * it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* nDPI is distributed in the hope that it will be useful, * nDPI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with nDPI. If not, see <http://www.gnu.org/licenses/>. * along with nDPI. If not, see <http://www.gnu.org/licenses/>.
* *
*/ */
#include "ndpi_protocols.h" #include "ndpi_protocols.h"
@@ -39,266 +39,266 @@ void ndpi_search_smpp_tcp(struct ndpi_detection_module_struct* ndpi_struct,
struct ndpi_packet_struct* packet = &flow->packet; struct ndpi_packet_struct* packet = &flow->packet;
// min SMPP packet length = 16 bytes // min SMPP packet length = 16 bytes
if (packet->payload_packet_len < 16) { if (packet->payload_packet_len < 16) {
NDPI_LOG(NDPI_PROTOCOL_SMPP, ndpi_struct, NDPI_LOG_DEBUG, "SMPP excluded\n"); NDPI_LOG(NDPI_PROTOCOL_SMPP, ndpi_struct, NDPI_LOG_DEBUG, "SMPP excluded\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_SMPP); NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_SMPP);
return; return;
} }
// get PDU length // get PDU length
uint32_t pdu_l = ntohl(get_u_int32_t(packet->payload, 0)); u_int32_t pdu_l = ntohl(get_u_int32_t(packet->payload, 0));
NDPI_LOG(NDPI_PROTOCOL_SMPP, NDPI_LOG(NDPI_PROTOCOL_SMPP,
ndpi_struct, ndpi_struct,
NDPI_LOG_DEBUG, NDPI_LOG_DEBUG,
"calculated PDU Length: %d, received PDU Length: %d\n", "calculated PDU Length: %d, received PDU Length: %d\n",
pdu_l, packet->payload_packet_len); pdu_l, packet->payload_packet_len);
// if PDU size was invalid, try the following TCP segments, 3 attempts max // if PDU size was invalid, try the following TCP segments, 3 attempts max
if(flow->packet_counter > 3) { if(flow->packet_counter > 3) {
NDPI_LOG(NDPI_PROTOCOL_SMPP, ndpi_struct, NDPI_LOG_DEBUG, "SMPP excluded\n"); NDPI_LOG(NDPI_PROTOCOL_SMPP, ndpi_struct, NDPI_LOG_DEBUG, "SMPP excluded\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_SMPP); NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_SMPP);
return; return;
} }
// verify PDU length // verify PDU length
if(pdu_l != packet->payload_packet_len) { if(pdu_l != packet->payload_packet_len) {
// check if multiple PDUs included // check if multiple PDUs included
uint32_t total_pdu_l = pdu_l; u_int32_t total_pdu_l = pdu_l;
uint32_t tmp_pdu_l = 0; u_int32_t tmp_pdu_l = 0;
uint16_t pdu_c = 1; u_int16_t pdu_c = 1;
// loop PDUs (check if lengths are valid) // loop PDUs (check if lengths are valid)
while(total_pdu_l < packet->payload_packet_len) { while(total_pdu_l < packet->payload_packet_len) {
// get next PDU length // get next PDU length
tmp_pdu_l = ntohl(get_u_int32_t(packet->payload, total_pdu_l)); tmp_pdu_l = ntohl(get_u_int32_t(packet->payload, total_pdu_l));
// if zero, return, will try the next TCP segment // if zero, return, will try the next TCP segment
if(tmp_pdu_l == 0) return; if(tmp_pdu_l == 0) return;
// inc total PDU length // inc total PDU length
total_pdu_l += ntohl(get_u_int32_t(packet->payload, total_pdu_l)); total_pdu_l += ntohl(get_u_int32_t(packet->payload, total_pdu_l));
// inc total PDU count // inc total PDU count
++pdu_c; ++pdu_c;
} }
NDPI_LOG(NDPI_PROTOCOL_SMPP, NDPI_LOG(NDPI_PROTOCOL_SMPP,
ndpi_struct, ndpi_struct,
NDPI_LOG_DEBUG, NDPI_LOG_DEBUG,
"multiple PDUs included, calculated total PDU Length: %d, PDU count: %d, TCP payload length: %d\n", "multiple PDUs included, calculated total PDU Length: %d, PDU count: %d, TCP payload length: %d\n",
total_pdu_l, pdu_c, packet->payload_packet_len); total_pdu_l, pdu_c, packet->payload_packet_len);
// verify multi PDU total length // verify multi PDU total length
if(total_pdu_l != packet->payload_packet_len){ if(total_pdu_l != packet->payload_packet_len){
// return, will try the next TCP segment // return, will try the next TCP segment
return; return;
} }
} }
// *** check PDU type *** // *** check PDU type ***
uint32_t pdu_type = ntohl(get_u_int32_t(packet->payload, 4)); u_int32_t pdu_type = ntohl(get_u_int32_t(packet->payload, 4));
// first byte of PDU type is either 0x00 of 0x80 // first byte of PDU type is either 0x00 of 0x80
if(!(packet->payload[4] == 0x00 || packet->payload[4] == 0x80)) { if(!(packet->payload[4] == 0x00 || packet->payload[4] == 0x80)) {
NDPI_LOG(NDPI_PROTOCOL_SMPP, ndpi_struct, NDPI_LOG_DEBUG, "SMPP excluded\n"); NDPI_LOG(NDPI_PROTOCOL_SMPP, ndpi_struct, NDPI_LOG_DEBUG, "SMPP excluded\n");
NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_SMPP); NDPI_ADD_PROTOCOL_TO_BITMASK(flow->excluded_protocol_bitmask, NDPI_PROTOCOL_SMPP);
return; return;
} }
// remove 0x80, get request type pdu // remove 0x80, get request type pdu
uint32_t pdu_req = pdu_type & 0x00FFFFFF; u_int32_t pdu_req = pdu_type & 0x00FFFFFF;
// list of known PDU types // list of known PDU types
if((pdu_req >= 0x00000000 && pdu_req <= 0x00000009) || if((pdu_req >= 0x00000000 && pdu_req <= 0x00000009) ||
(pdu_req == 0x0000000B || pdu_req == 0x00000015 || (pdu_req == 0x0000000B || pdu_req == 0x00000015 ||
pdu_req == 0x00000021 || pdu_req == 0x00000102 || pdu_req == 0x00000021 || pdu_req == 0x00000102 ||
pdu_req == 0x00000103)){ pdu_req == 0x00000103)){
NDPI_LOG(NDPI_PROTOCOL_SMPP, NDPI_LOG(NDPI_PROTOCOL_SMPP,
ndpi_struct, ndpi_struct,
NDPI_LOG_DEBUG, NDPI_LOG_DEBUG,
"PDU type: %x, Request PDU type = %x\n", "PDU type: %x, Request PDU type = %x\n",
pdu_type, pdu_req); pdu_type, pdu_req);
// fresult flag // fresult flag
char extra_passed = 1; char extra_passed = 1;
// check PDU type specifics // check PDU type specifics
switch(pdu_type){ switch(pdu_type){
// GENERIC_NACK // GENERIC_NACK
case 0x80000000: case 0x80000000:
// body lengh must be zero // body lengh must be zero
if(pdu_l > 16) extra_passed = 0; if(pdu_l > 16) extra_passed = 0;
break; break;
// BIND_RECEIVER // BIND_RECEIVER
// BIND_TRANSMITTER // BIND_TRANSMITTER
// BIND_TRANSCEIVER // BIND_TRANSCEIVER
case 0x00000001: case 0x00000001:
case 0x00000002: case 0x00000002:
case 0x00000009: case 0x00000009:
// status field must be NULL // status field must be NULL
if(get_u_int32_t(packet->payload, 8) != 0) extra_passed = 0; if(get_u_int32_t(packet->payload, 8) != 0) extra_passed = 0;
// min body lengh = 10 bytes (+16 in header) // min body lengh = 10 bytes (+16 in header)
if(pdu_l < 26) extra_passed = 0; if(pdu_l < 26) extra_passed = 0;
break; break;
// BIND_RECEIVER_RESP // BIND_RECEIVER_RESP
// BIND_TRANSMITTER_RESP // BIND_TRANSMITTER_RESP
// BIND_TRANSCEIVER_RESP // BIND_TRANSCEIVER_RESP
case 0x80000001: case 0x80000001:
case 0x80000002: case 0x80000002:
case 0x80000009: case 0x80000009:
// min body length = 2 bytes (+16 in header) // min body length = 2 bytes (+16 in header)
if(pdu_l < 18) extra_passed = 0; if(pdu_l < 18) extra_passed = 0;
break; break;
// OUTBIND // OUTBIND
case 0x0000000B: case 0x0000000B:
// status field must be NULL // status field must be NULL
if(get_u_int32_t(packet->payload, 8) != 0) extra_passed = 0; if(get_u_int32_t(packet->payload, 8) != 0) extra_passed = 0;
// min body length = 4 bytes (+16 in header) // min body length = 4 bytes (+16 in header)
if(pdu_l < 20) extra_passed = 0; if(pdu_l < 20) extra_passed = 0;
break; break;
// UNBIND // UNBIND
case 0x00000006: case 0x00000006:
// status field must be NULL // status field must be NULL
if(get_u_int32_t(packet->payload, 8) != 0) extra_passed = 0; if(get_u_int32_t(packet->payload, 8) != 0) extra_passed = 0;
// body lengh must be zero // body lengh must be zero
if(pdu_l > 16) extra_passed = 0; if(pdu_l > 16) extra_passed = 0;
break; break;
// UNBIND_RESP // UNBIND_RESP
case 0x80000006: case 0x80000006:
// body lengh must be zero // body lengh must be zero
if(pdu_l > 16) extra_passed = 0; if(pdu_l > 16) extra_passed = 0;
break; break;
// SUBMIT_SM // SUBMIT_SM
case 0x00000004: case 0x00000004:
// status field must be NULL // status field must be NULL
if(get_u_int32_t(packet->payload, 8) != 0) extra_passed = 0; if(get_u_int32_t(packet->payload, 8) != 0) extra_passed = 0;
// min body length = 17 bytes (+16 in header) // min body length = 17 bytes (+16 in header)
if(pdu_l < 33) extra_passed = 0; if(pdu_l < 33) extra_passed = 0;
break; break;
// SUBMIT_SM_RESP // SUBMIT_SM_RESP
case 0x80000004: case 0x80000004:
// - if status != 0, body length is 2 bytes min // - if status != 0, body length is 2 bytes min
// - if status > 0, body lenth must be zero // - if status > 0, body lenth must be zero
if(get_u_int32_t(packet->payload, 8) != 0){ if(get_u_int32_t(packet->payload, 8) != 0){
if(pdu_l > 16) extra_passed = 0; if(pdu_l > 16) extra_passed = 0;
}else if(pdu_l < 18) extra_passed = 0; }else if(pdu_l < 18) extra_passed = 0;
break; break;
// SUBMIT_MULTI // SUBMIT_MULTI
case 0x00000021: case 0x00000021:
// status field must be NULL // status field must be NULL
if(get_u_int32_t(packet->payload, 8) != 0) extra_passed = 0; if(get_u_int32_t(packet->payload, 8) != 0) extra_passed = 0;
// min body length = 17 bytes (+16 in header) // min body length = 17 bytes (+16 in header)
if(pdu_l < 33) extra_passed = 0; if(pdu_l < 33) extra_passed = 0;
break; break;
// SUBMIT_MULTI_RESP // SUBMIT_MULTI_RESP
case 0x80000021: case 0x80000021:
// min body length = 10 bytes (+16 in header) // min body length = 10 bytes (+16 in header)
if(pdu_l < 26) extra_passed = 0; if(pdu_l < 26) extra_passed = 0;
break; break;
// DELIVER_SM // DELIVER_SM
case 0x00000005: case 0x00000005:
// status field must be NULL // status field must be NULL
if(get_u_int32_t(packet->payload, 8) != 0) extra_passed = 0; if(get_u_int32_t(packet->payload, 8) != 0) extra_passed = 0;
// min body length = 17 bytes (+16 in header) // min body length = 17 bytes (+16 in header)
if(pdu_l < 33) extra_passed = 0; if(pdu_l < 33) extra_passed = 0;
break; break;
// DELIVER_SM_RESP // DELIVER_SM_RESP
case 0x80000005: case 0x80000005:
// min body length = 1 byte (+16 in header) // min body length = 1 byte (+16 in header)
if(pdu_l < 17) extra_passed = 0; if(pdu_l < 17) extra_passed = 0;
break; break;
// DATA_SM // DATA_SM
case 0x00000103: case 0x00000103:
// status field must be NULL // status field must be NULL
if(get_u_int32_t(packet->payload, 8) != 0) extra_passed = 0; if(get_u_int32_t(packet->payload, 8) != 0) extra_passed = 0;
// min body length = 10 bytes (+16 in header) // min body length = 10 bytes (+16 in header)
if(pdu_l < 26) extra_passed = 0; if(pdu_l < 26) extra_passed = 0;
break; break;
// DATA_SM_RESP // DATA_SM_RESP
case 0x80000103: case 0x80000103:
// min body length = 2 bytes (+16 in header) // min body length = 2 bytes (+16 in header)
if(pdu_l < 18) extra_passed = 0; if(pdu_l < 18) extra_passed = 0;
break; break;
// QUERY_SM // QUERY_SM
case 0x00000003: case 0x00000003:
// status field must be NULL // status field must be NULL
if(get_u_int32_t(packet->payload, 8) != 0) extra_passed = 0; if(get_u_int32_t(packet->payload, 8) != 0) extra_passed = 0;
// min body length = 4 bytes (+16 in header) // min body length = 4 bytes (+16 in header)
if(pdu_l < 20) extra_passed = 0; if(pdu_l < 20) extra_passed = 0;
break; break;
// QUERY_SM_RESP // QUERY_SM_RESP
case 0x80000003: case 0x80000003:
// min body length = 5 bytes (+16 in header) // min body length = 5 bytes (+16 in header)
if(pdu_l < 21) extra_passed = 0; if(pdu_l < 21) extra_passed = 0;
break; break;
// CANCEL_SM // CANCEL_SM
case 0x00000008: case 0x00000008:
// status field must be NULL // status field must be NULL
if(get_u_int32_t(packet->payload, 8) != 0) extra_passed = 0; if(get_u_int32_t(packet->payload, 8) != 0) extra_passed = 0;
// min body length = 8 bytes (+16 in header) // min body length = 8 bytes (+16 in header)
if(pdu_l < 24) extra_passed = 0; if(pdu_l < 24) extra_passed = 0;
break; break;
// CANCEL_SM_RESP // CANCEL_SM_RESP
case 0x80000008: case 0x80000008:
// body lenth must be zero // body lenth must be zero
if(pdu_l > 16) extra_passed = 0; if(pdu_l > 16) extra_passed = 0;
break; break;
// REPLACE_SM // REPLACE_SM
case 0x00000007: case 0x00000007:
// status field must be NULL // status field must be NULL
if(get_u_int32_t(packet->payload, 8) != 0) extra_passed = 0; if(get_u_int32_t(packet->payload, 8) != 0) extra_passed = 0;
// min body length = 9 bytes (+16 in header) // min body length = 9 bytes (+16 in header)
if(pdu_l < 25) extra_passed = 0; if(pdu_l < 25) extra_passed = 0;
break; break;
// REPLACE_SM_RESP // REPLACE_SM_RESP
case 0x80000007: case 0x80000007:
// body lenth must be zero // body lenth must be zero
if(pdu_l > 16) extra_passed = 0; if(pdu_l > 16) extra_passed = 0;
break; break;
// ENQUIRE_LINK // ENQUIRE_LINK
case 0x00000015: case 0x00000015:
// status field must be NULL // status field must be NULL
if(get_u_int32_t(packet->payload, 8) != 0) extra_passed = 0; if(get_u_int32_t(packet->payload, 8) != 0) extra_passed = 0;
// body lengh must be zero // body lengh must be zero
if(pdu_l > 16) extra_passed = 0; if(pdu_l > 16) extra_passed = 0;
break; break;
// ENQUIRE_LINK_RESP // ENQUIRE_LINK_RESP
case 0x80000015: case 0x80000015:
// body lengh must be zero // body lengh must be zero
if(pdu_l > 16) extra_passed = 0; if(pdu_l > 16) extra_passed = 0;
break; break;
// ALERT_NOTIFICATION // ALERT_NOTIFICATION
case 0x00000102: case 0x00000102:
// status field must be NULL // status field must be NULL
if(get_u_int32_t(packet->payload, 8) != 0) extra_passed = 0; if(get_u_int32_t(packet->payload, 8) != 0) extra_passed = 0;
// min body length = 6 bytes (+16 in header) // min body length = 6 bytes (+16 in header)
if(pdu_l < 22) extra_passed = 0; if(pdu_l < 22) extra_passed = 0;
break; break;
default: break; default: break;
} }
// if extra checks passed, set as identified // if extra checks passed, set as identified
if(extra_passed) { if(extra_passed) {
NDPI_LOG(NDPI_PROTOCOL_SMPP, ndpi_struct, NDPI_LOG_DEBUG, "SMPP identified...\n"); NDPI_LOG(NDPI_PROTOCOL_SMPP, ndpi_struct, NDPI_LOG_DEBUG, "SMPP identified...\n");
ndpi_int_smpp_add_connection(ndpi_struct, flow); ndpi_int_smpp_add_connection(ndpi_struct, flow);
return; return;
} }
} }
// exclude // exclude