From f4b9464653401b22dedcde9433599012dccd8e8c Mon Sep 17 00:00:00 2001 From: Daniel Stirnimann Date: Mon, 24 Feb 2014 15:23:39 +0100 Subject: [PATCH 1/2] Add IP_Version Add ip_version just like ip_ttl was added. Allows to select ip protocol version 4 or 6 in sql statements. --- src/packet_handler.cpp | 9 ++++++++- src/packet_handler.h | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/packet_handler.cpp b/src/packet_handler.cpp index c20faee..08e23fa 100644 --- a/src/packet_handler.cpp +++ b/src/packet_handler.cpp @@ -191,6 +191,7 @@ void IP_header::reset() dst_port = 0; proto = 0; ip_ttl = 0; + ip_version = 0; id = 0; length = 0; } @@ -204,7 +205,7 @@ int IP_header::decode(unsigned char* data, int itype, int i_id) // ether frame done (ignored mac's) // ip - int ip_version = data[0] >> 4; + ip_version = data[0] >> 4; proto = 0; if (ip_version == 4) { if (ethertype == 0) @@ -429,6 +430,7 @@ void IP_header_to_table::add_packet_columns(Packet_handler& packet_handler) packet_handler.add_packet_column("dst_addr", "", Coltype::_text, COLUMN_DST_ADDR); packet_handler.add_packet_column("protocol", "", Coltype::_int, COLUMN_PROTOCOL); packet_handler.add_packet_column("ip_ttl", "", Coltype::_int, COLUMN_IP_TTL); + packet_handler.add_packet_column("ip_version", "", Coltype::_int, COLUMN_IP_VERSION); packet_handler.add_packet_column("fragments", "", Coltype::_int, COLUMN_FRAGMENTS); } @@ -439,6 +441,7 @@ void IP_header_to_table::on_table_created(Table* table, const std::vector& acc_ether_type = table->get_accessor("ether_type"); acc_protocol = table->get_accessor("protocol"); acc_ip_ttl = table->get_accessor("ip_ttl"); + acc_ip_version = table->get_accessor("ip_version"); acc_src_port = table->get_accessor("src_port"); acc_dst_port = table->get_accessor("dst_port"); acc_s = table->get_accessor("s"); @@ -478,6 +481,10 @@ void IP_header_to_table::assign(Row* row, IP_header* head, const std::vectorip_ttl; break; + case COLUMN_IP_VERSION: + acc_ip_version.value(row) = head->ip_version; + break; + case COLUMN_SRC_PORT: acc_src_port.value(row) = head->src_port; break; diff --git a/src/packet_handler.h b/src/packet_handler.h index 48226af..e2904ed 100644 --- a/src/packet_handler.h +++ b/src/packet_handler.h @@ -89,6 +89,7 @@ class IP_header { , dst_port(0) , proto(0) , ip_ttl(0) + , ip_version(0) , id(0) , length(0) , fragments(0) @@ -110,6 +111,7 @@ class IP_header { unsigned short dst_port; unsigned short proto; unsigned short ip_ttl; + unsigned short ip_version; unsigned int id; unsigned int length; unsigned int fragments; @@ -128,6 +130,7 @@ class IP_header_to_table { COLUMN_ETHER_TYPE, COLUMN_PROTOCOL, COLUMN_IP_TTL, + COLUMN_IP_VERSION, COLUMN_SRC_PORT, COLUMN_DST_PORT, COLUMN_SRC_ADDR, @@ -146,6 +149,7 @@ class IP_header_to_table { Int_accessor acc_ether_type; Int_accessor acc_protocol; Int_accessor acc_ip_ttl; + Int_accessor acc_ip_version; Int_accessor acc_src_port; Int_accessor acc_dst_port; Int_accessor acc_fragments; From 3943ddad977a197fa054e9b2d4152382d3dc9d5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jerry=20Lundstr=C3=B6m?= Date: Thu, 8 Jun 2017 09:47:07 +0200 Subject: [PATCH 2/2] Update documentation and tests --- FIELDS.md | 1 + src/test/test5.gold | 1 + src/test/test7.gold | 59 +++++++++++++++++++++++---------------------- 3 files changed, 32 insertions(+), 29 deletions(-) diff --git a/FIELDS.md b/FIELDS.md index 3e9a016..c7799cc 100644 --- a/FIELDS.md +++ b/FIELDS.md @@ -16,6 +16,7 @@ the dns table, presented as JSON identifiers. { "name": "dst_addr","type": "text" }, { "name": "protocol","type": "int" }, { "name": "ip_ttl","type": "int" }, + { "name": "ip_version","type": "int" }, { "name": "fragments","type": "int" }, { "name": "qname","type": "text" }, { "name": "aname","type": "text" }, diff --git a/src/test/test5.gold b/src/test/test5.gold index 04fb5e6..c1c4a82 100644 --- a/src/test/test5.gold +++ b/src/test/test5.gold @@ -359,6 +359,7 @@ { "name": "dst_addr","type": "text" }, { "name": "protocol","type": "int" }, { "name": "ip_ttl","type": "int" }, + { "name": "ip_version","type": "int" }, { "name": "fragments","type": "int" }, { "name": "type","type": "int" }, { "name": "code","type": "int" }, diff --git a/src/test/test7.gold b/src/test/test7.gold index 2e30690..151c3b5 100644 --- a/src/test/test7.gold +++ b/src/test/test7.gold @@ -13,6 +13,7 @@ { "name": "dst_addr","type": "text" }, { "name": "protocol","type": "int" }, { "name": "ip_ttl","type": "int" }, + { "name": "ip_version","type": "int" }, { "name": "fragments","type": "int" }, { "name": "type","type": "int" }, { "name": "code","type": "int" }, @@ -24,35 +25,35 @@ { "name": "desc","type": "text" } ], "data": [ - [1,1297781718,401023,2048,0,0,"172.18.24.52","172.18.201.234",1,64,0,8,0,17563,0,0,"","","Echo Request"], - [2,1297781719,401120,2048,0,0,"172.18.24.52","172.18.201.234",1,64,0,8,0,17563,1,0,"","","Echo Request"], - [3,1297781720,401368,2048,0,0,"172.18.24.52","172.18.201.234",1,64,0,8,0,17563,2,0,"","","Echo Request"], - [4,1297781729,36800,2048,0,0,"172.18.24.52","172.18.24.1",1,64,0,8,0,17819,0,0,"","","Echo Request"], - [5,1297781729,37210,2048,0,0,"172.18.24.1","172.18.24.52",1,64,0,0,0,17819,0,0,"","","Echo Reply"], - [6,1297781730,37013,2048,0,0,"172.18.24.52","172.18.24.1",1,64,0,8,0,17819,1,0,"","","Echo Request"], - [7,1297781730,37634,2048,0,0,"172.18.24.1","172.18.24.52",1,64,0,0,0,17819,1,0,"","","Echo Reply"], - [8,1297781731,37342,2048,0,0,"172.18.24.52","172.18.24.1",1,64,0,8,0,17819,2,0,"","","Echo Request"], - [9,1297781731,37864,2048,0,0,"172.18.24.1","172.18.24.52",1,64,0,0,0,17819,2,0,"","","Echo Reply"], - [10,1297781733,388527,2048,0,0,"172.18.24.52","172.18.24.12",1,64,0,8,0,18075,0,0,"","","Echo Request"], - [11,1297781733,389073,2048,0,0,"172.18.24.12","172.18.24.52",1,128,0,0,0,18075,0,0,"","","Echo Reply"], - [12,1297781734,388627,2048,0,0,"172.18.24.52","172.18.24.12",1,64,0,8,0,18075,1,0,"","","Echo Request"], - [13,1297781734,388912,2048,0,0,"172.18.24.12","172.18.24.52",1,128,0,0,0,18075,1,0,"","","Echo Reply"], - [14,1297781735,388779,2048,0,0,"172.18.24.52","172.18.24.12",1,64,0,8,0,18075,2,0,"","","Echo Request"], - [15,1297781735,389060,2048,0,0,"172.18.24.12","172.18.24.52",1,128,0,0,0,18075,2,0,"","","Echo Reply"], - [16,1297781739,517764,2048,0,0,"172.18.24.52","172.18.23.12",1,64,0,8,0,18331,0,0,"","","Echo Request"], - [17,1297781740,518089,2048,0,0,"172.18.24.52","172.18.23.12",1,64,0,8,0,18331,1,0,"","","Echo Request"], - [18,1297781741,518404,2048,0,0,"172.18.24.52","172.18.23.12",1,64,0,8,0,18331,2,0,"","","Echo Request"], - [19,1297781745,4951,2048,0,0,"172.18.24.52","173.18.23.12",1,64,0,8,0,19355,0,0,"","","Echo Request"], - [20,1297781746,5090,2048,0,0,"172.18.24.52","173.18.23.12",1,64,0,8,0,19355,1,0,"","","Echo Request"], - [21,1297781747,5403,2048,0,0,"172.18.24.52","173.18.23.12",1,64,0,8,0,19355,2,0,"","","Echo Request"], - [22,1297781749,725341,2048,0,0,"172.18.24.52","174.18.23.12",1,64,0,8,0,19611,0,0,"","","Echo Request"], - [23,1297781750,725507,2048,0,0,"172.18.24.52","174.18.23.12",1,64,0,8,0,19611,1,0,"","","Echo Request"], - [24,1297781750,900759,2048,0,0,"75.160.241.10","172.18.24.52",1,234,0,3,1,0,0,1,"172.18.24.52","174.18.23.12","Destination host unreachable"], - [25,1297781751,725837,2048,0,0,"172.18.24.52","174.18.23.12",1,64,0,8,0,19611,2,0,"","","Echo Request"], - [26,1297781752,726162,2048,0,0,"172.18.24.52","174.18.23.12",1,64,0,8,0,19611,3,0,"","","Echo Request"], - [27,1297781753,726487,2048,0,0,"172.18.24.52","174.18.23.12",1,64,0,8,0,19611,4,0,"","","Echo Request"], - [28,1297781754,726804,2048,0,0,"172.18.24.52","174.18.23.12",1,64,0,8,0,19611,5,0,"","","Echo Request"], - [29,1297781754,903407,2048,0,0,"75.160.241.10","172.18.24.52",1,234,0,3,1,0,0,1,"172.18.24.52","174.18.23.12","Destination host unreachable"] + [1,1297781718,401023,2048,0,0,"172.18.24.52","172.18.201.234",1,64,4,0,8,0,17563,0,0,"","","Echo Request"], + [2,1297781719,401120,2048,0,0,"172.18.24.52","172.18.201.234",1,64,4,0,8,0,17563,1,0,"","","Echo Request"], + [3,1297781720,401368,2048,0,0,"172.18.24.52","172.18.201.234",1,64,4,0,8,0,17563,2,0,"","","Echo Request"], + [4,1297781729,36800,2048,0,0,"172.18.24.52","172.18.24.1",1,64,4,0,8,0,17819,0,0,"","","Echo Request"], + [5,1297781729,37210,2048,0,0,"172.18.24.1","172.18.24.52",1,64,4,0,0,0,17819,0,0,"","","Echo Reply"], + [6,1297781730,37013,2048,0,0,"172.18.24.52","172.18.24.1",1,64,4,0,8,0,17819,1,0,"","","Echo Request"], + [7,1297781730,37634,2048,0,0,"172.18.24.1","172.18.24.52",1,64,4,0,0,0,17819,1,0,"","","Echo Reply"], + [8,1297781731,37342,2048,0,0,"172.18.24.52","172.18.24.1",1,64,4,0,8,0,17819,2,0,"","","Echo Request"], + [9,1297781731,37864,2048,0,0,"172.18.24.1","172.18.24.52",1,64,4,0,0,0,17819,2,0,"","","Echo Reply"], + [10,1297781733,388527,2048,0,0,"172.18.24.52","172.18.24.12",1,64,4,0,8,0,18075,0,0,"","","Echo Request"], + [11,1297781733,389073,2048,0,0,"172.18.24.12","172.18.24.52",1,128,4,0,0,0,18075,0,0,"","","Echo Reply"], + [12,1297781734,388627,2048,0,0,"172.18.24.52","172.18.24.12",1,64,4,0,8,0,18075,1,0,"","","Echo Request"], + [13,1297781734,388912,2048,0,0,"172.18.24.12","172.18.24.52",1,128,4,0,0,0,18075,1,0,"","","Echo Reply"], + [14,1297781735,388779,2048,0,0,"172.18.24.52","172.18.24.12",1,64,4,0,8,0,18075,2,0,"","","Echo Request"], + [15,1297781735,389060,2048,0,0,"172.18.24.12","172.18.24.52",1,128,4,0,0,0,18075,2,0,"","","Echo Reply"], + [16,1297781739,517764,2048,0,0,"172.18.24.52","172.18.23.12",1,64,4,0,8,0,18331,0,0,"","","Echo Request"], + [17,1297781740,518089,2048,0,0,"172.18.24.52","172.18.23.12",1,64,4,0,8,0,18331,1,0,"","","Echo Request"], + [18,1297781741,518404,2048,0,0,"172.18.24.52","172.18.23.12",1,64,4,0,8,0,18331,2,0,"","","Echo Request"], + [19,1297781745,4951,2048,0,0,"172.18.24.52","173.18.23.12",1,64,4,0,8,0,19355,0,0,"","","Echo Request"], + [20,1297781746,5090,2048,0,0,"172.18.24.52","173.18.23.12",1,64,4,0,8,0,19355,1,0,"","","Echo Request"], + [21,1297781747,5403,2048,0,0,"172.18.24.52","173.18.23.12",1,64,4,0,8,0,19355,2,0,"","","Echo Request"], + [22,1297781749,725341,2048,0,0,"172.18.24.52","174.18.23.12",1,64,4,0,8,0,19611,0,0,"","","Echo Request"], + [23,1297781750,725507,2048,0,0,"172.18.24.52","174.18.23.12",1,64,4,0,8,0,19611,1,0,"","","Echo Request"], + [24,1297781750,900759,2048,0,0,"75.160.241.10","172.18.24.52",1,234,4,0,3,1,0,0,1,"172.18.24.52","174.18.23.12","Destination host unreachable"], + [25,1297781751,725837,2048,0,0,"172.18.24.52","174.18.23.12",1,64,4,0,8,0,19611,2,0,"","","Echo Request"], + [26,1297781752,726162,2048,0,0,"172.18.24.52","174.18.23.12",1,64,4,0,8,0,19611,3,0,"","","Echo Request"], + [27,1297781753,726487,2048,0,0,"172.18.24.52","174.18.23.12",1,64,4,0,8,0,19611,4,0,"","","Echo Request"], + [28,1297781754,726804,2048,0,0,"172.18.24.52","174.18.23.12",1,64,4,0,8,0,19611,5,0,"","","Echo Request"], + [29,1297781754,903407,2048,0,0,"75.160.241.10","172.18.24.52",1,234,4,0,3,1,0,0,1,"172.18.24.52","174.18.23.12","Destination host unreachable"] ] } ]