Adding logic and testing for single remote port matching.

This commit is contained in:
Pedro Alvarez 2019-05-31 16:29:13 +01:00 committed by Andre Puschmann
parent 326aef4431
commit 0f6c55023b
2 changed files with 25 additions and 17 deletions

View File

@ -33,19 +33,19 @@ tft_packet_filter_t::tft_packet_filter_t(const LIBLTE_MME_PACKET_FILTER_STRUCT&
{
int idx = 0;
while (idx < tft.filter_size) {
switch (tft.filter[idx]) {
uint8_t filter_type = tft.filter[idx];
idx++;
switch (filter_type) {
// IPv4
case IPV4_REMOTE_ADDR_TYPE:
idx++;
active_filters = IPV4_REMOTE_ADDR_FLAG;
memcpy(&ipv4_remote_addr, &tft.filter[idx], 4);
idx += 4;
memcpy(&ipv4_remote_addr, &tft.filter[idx], IPV4_ADDR_SIZE);
idx += IPV4_ADDR_SIZE;
break;
case IPV4_LOCAL_ADDR_TYPE:
idx++;
active_filters = IPV4_LOCAL_ADDR_FLAG;
memcpy(&ipv4_local_addr, &tft.filter[idx], 4);
idx += 4;
memcpy(&ipv4_local_addr, &tft.filter[idx], IPV4_ADDR_SIZE);
idx += IPV4_ADDR_SIZE;
break;
//IPv6
case IPV6_REMOTE_ADDR_TYPE:
@ -56,14 +56,16 @@ tft_packet_filter_t::tft_packet_filter_t(const LIBLTE_MME_PACKET_FILTER_STRUCT&
break;
// Ports
case SINGLE_LOCAL_PORT_TYPE:
idx++;
active_filters = SINGLE_LOCAL_PORT_FLAG;
memcpy(&single_local_port, &tft.filter[idx], 2);
idx += 2;
break;
case LOCAL_PORT_RANGE_TYPE:
break;
case SINGLE_REMOTE_PORT_TYPE:
active_filters = SINGLE_REMOTE_PORT_FLAG;
memcpy(&single_remote_port, &tft.filter[idx], 2);
idx += 2;
break;
case LOCAL_PORT_RANGE_TYPE:
break;
case REMOTE_PORT_RANGE_TYPE:
break;
@ -201,11 +203,17 @@ bool tft_packet_filter_t::match_port(const srslte::unique_byte_buffer_t& pdu)
printf("UDP protocol\n");
udp_pkt = (struct udphdr*)&pdu->msg[ip_pkt->ihl * 4];
printf("%d\n", ntohs(udp_pkt->source));
printf("%d\n", ntohs(udp_pkt->dest));
if (active_filters & SINGLE_LOCAL_PORT_FLAG) {
if (udp_pkt->source != single_local_port) {
return false;
}
}
if (active_filters & SINGLE_REMOTE_PORT_FLAG) {
if (udp_pkt->dest != single_remote_port) {
return false;
}
}
break;
case TCP_PROTOCOL:
printf("TCP protocol\n");

View File

@ -51,14 +51,13 @@ uint32_t ip_message_len1 = sizeof(ip_tst_message1);
// IP test message 2
// Protocol UDP
// Source port 8000, Destination Port 2001
// Source port 8000, Destination Port 9000
uint8_t ip_tst_message2[] = {
0x45, 0x00, 0x00, 0x5c, 0x1c, 0x0e, 0x40, 0x00, 0x40, 0x11, 0x20, 0x81, 0x7f, 0x00, 0x00, 0x01, 0x7f, 0x00, 0x00,
0x01, 0x1f, 0x40, 0x07, 0xd1, 0x00, 0x48, 0xfe, 0x5b, 0xb8, 0x1a, 0x56, 0x0d, 0xd2, 0xa3, 0xf9, 0x11, 0xd5, 0x56,
0xb6, 0x95, 0x60, 0x07, 0x2d, 0x95, 0xe2, 0x53, 0x6b, 0x8f, 0x90, 0xb5, 0x48, 0xd1, 0x71, 0x24, 0xe8, 0x6e, 0x2d,
0x56, 0xec, 0xf1, 0xe5, 0x85, 0xa5, 0x79, 0xc6, 0x5c, 0x90, 0xd6, 0x72, 0x87, 0x20, 0x99, 0x94, 0xfa, 0x82, 0x0d,
0x2a, 0x2c, 0xdf, 0x02, 0x60, 0xef, 0x80, 0x07, 0xe6, 0xe1, 0xef, 0x4f, 0x40, 0x9a, 0x0a, 0xbc};
0x45, 0x00, 0x00, 0x5c, 0xea, 0x16, 0x40, 0x00, 0x40, 0x11, 0x52, 0x78, 0x7f, 0x00, 0x00, 0x01, 0x7f, 0x00, 0x00,
0x01, 0x1f, 0x40, 0x23, 0x28, 0x00, 0x48, 0xfe, 0x5b, 0x64, 0x84, 0x35, 0x90, 0x26, 0x9a, 0xe4, 0x45, 0xe1, 0x6f,
0x67, 0x7a, 0x62, 0x39, 0xb6, 0x73, 0x00, 0x99, 0x39, 0x30, 0x1c, 0xdd, 0xf3, 0x18, 0xa0, 0xd4, 0x7a, 0x02, 0x78,
0x42, 0x0a, 0x5b, 0xc2, 0xbc, 0xd6, 0x2f, 0xe0, 0x3a, 0x76, 0xf8, 0x37, 0xdf, 0x06, 0x01, 0xac, 0xf7, 0x6f, 0x57,
0xf3, 0x39, 0x1e, 0x65, 0x5d, 0xa7, 0xaf, 0x84, 0xcc, 0x6b, 0x00, 0x65, 0x3c, 0xf4, 0x4d, 0xf2};
uint32_t ip_message_len2 = sizeof(ip_tst_message2);
int tft_filter_test_single_local_port()
@ -124,6 +123,7 @@ int tft_filter_test_single_remote_port()
// Filter length: 3 bytes
// Filter type: Single local port
// Local port: 2222
// Remote port: 2001
uint8_t filter_message[3];
filter_message[0] = SINGLE_REMOTE_PORT_TYPE;
srslte::uint16_to_uint8(2001, &filter_message[1]);