diff --git a/data/conf.json b/data/conf.json index 6c060b7..d867fac 100644 --- a/data/conf.json +++ b/data/conf.json @@ -15,74 +15,75 @@ "threads": 0, "delay": 1000000, "trackcount": false, - "packets": + "l4csum": true, + "eth": + { + "smac": null, + "dmac": null + }, + "ip": + { + "ranges": + [ + "172.16.0.0./16", + "10.60.0.0/24", + "192.168.30.0/24" + ], + "srcip": null, + "dstip": null, + "protocol": "udp", + "tos": 0, + "csum": true, + "ttl": + { + "min": 0, + "max": 0 + }, + "id": + { + "min": 0, + "max": 0 + } + }, + "udp": + { + "srcport": 0, + "dstport": 0 + }, + "tcp": + { + "srcport": 0, + "dstport": 0, + "syn": false, + "ack": false, + "psh": false, + "rst": false, + "fin": false, + "urg": false, + "ece": false, + "cwr": false, + "cooked": false, + "oneconnection": false + }, + "icmp": + { + "code": 0, + "type": 0 + }, + "payloads": [ { - "l4csum": true, - "eth": - { - "smac": null, - "dmac": null - }, - "ip": + "length": { - "ranges": - [ - "172.16.0.0./16", - "10.60.0.0/24", - "192.168.30.0/24" - ], - "srcip": null, - "dstip": null, - "protocol": "udp", - "tos": 0, - "csum": true, - "ttl": - { - "min": 0, - "max": 0 - }, - "id": - { - "min": 0, - "max": 0 - } - }, - "udp": { - "srcport": 0, - "dstport": 0 - }, - "tcp": { - "srcport": 0, - "dstport": 0, - "syn": false, - "ack": false, - "psh": false, - "rst": false, - "fin": false, - "urg": false, - "ece": false, - "cwr": false, - "cooked": false, - "oneconnection": false - }, - "icmp": { - "code": 0, - "type": 0 + "min": 0, + "max": 0 }, - "payload": { - "length": { - "min": 0, - "max": 0 - }, - "isfile": false, - "isstring": false, - "isstatic": false, - "exact": null - } + "isfile": false, + "isstring": false, + "isstatic": false, + "exact": null } ] - } ] } \ No newline at end of file diff --git a/src/cmd_line.c b/src/cmd_line.c index c1a48ef..e6e212b 100644 --- a/src/cmd_line.c +++ b/src/cmd_line.c @@ -151,80 +151,82 @@ void parse_cli(struct cmd_line *cmd, struct config *cfg) cfg->interface = cmd->cl_interface; } - cfg->seq[0].block = cmd->cl_block; - cfg->seq[0].max_count = cmd->cl_count; - cfg->seq[0].time = cmd->cl_time; - cfg->seq[0].delay = cmd->cl_delay; - cfg->seq[0].track_count = cmd->cl_track_count; - cfg->seq[0].max_data = cmd->cl_max_data; - cfg->seq[0].threads = cmd->cl_threads; + struct sequence *seq = &cfg->seq[0]; - struct packet *pckt = &cfg->seq[0].pckts[0]; + seq->block = cmd->cl_block; + seq->max_count = cmd->cl_count; + seq->time = cmd->cl_time; + seq->delay = cmd->cl_delay; + seq->track_count = cmd->cl_track_count; + seq->max_data = cmd->cl_max_data; + seq->threads = cmd->cl_threads; - pckt->l4_csum = cmd->cl_l4_csum; + seq->l4_csum = cmd->cl_l4_csum; - pckt->eth.src_mac = cmd->cl_src_mac; - pckt->eth.dst_mac = cmd->cl_dst_mac; + seq->eth.src_mac = cmd->cl_src_mac; + seq->eth.dst_mac = cmd->cl_dst_mac; - pckt->ip.min_ttl = cmd->cl_ttl_min; - pckt->ip.max_ttl = cmd->cl_ttl_max; - pckt->ip.min_id = cmd->cl_id_min; - pckt->ip.max_id = cmd->cl_id_max; + seq->ip.min_ttl = cmd->cl_ttl_min; + seq->ip.max_ttl = cmd->cl_ttl_max; + seq->ip.min_id = cmd->cl_id_min; + seq->ip.max_id = cmd->cl_id_max; if (cmd->cl_src_ip != NULL) { // Check for range. if (strstr(cmd->cl_src_ip, "/") != NULL) { - pckt->ip.src_ip = 0; - pckt->ip.range_count = 1; - pckt->ip.ranges[0] = cmd->cl_src_ip; + seq->ip.src_ip = 0; + seq->ip.range_count = 1; + seq->ip.ranges[0] = cmd->cl_src_ip; } else { - pckt->ip.src_ip = cmd->cl_src_ip; + seq->ip.src_ip = cmd->cl_src_ip; } } if (cmd->cl_dst_ip != NULL) { - pckt->ip.dst_ip = cmd->cl_dst_ip; + seq->ip.dst_ip = cmd->cl_dst_ip; } - pckt->ip.protocol = cmd->cl_protocol; - pckt->ip.tos = cmd->cl_tos; - pckt->ip.csum = cmd->cl_l3_csum; - - pckt->udp.src_port = cmd->cl_udp_src_port; - pckt->udp.dst_port = cmd->cl_udp_dst_port; - - pckt->tcp.src_port = cmd->cl_tcp_src_port; - pckt->tcp.dst_port = cmd->cl_tcp_dst_port; - pckt->tcp.syn = cmd->cl_tcp_syn; - pckt->tcp.ack = cmd->cl_tcp_ack; - pckt->tcp.psh = cmd->cl_tcp_psh; - pckt->tcp.rst = cmd->cl_tcp_rst; - pckt->tcp.fin = cmd->cl_tcp_fin; - pckt->tcp.urg = cmd->cl_tcp_urg; - pckt->tcp.ece = cmd->cl_tcp_ece; - pckt->tcp.cwr = cmd->cl_tcp_cwr; - pckt->tcp.cooked = cmd->cl_tcp_cooked; - pckt->tcp.one_connection = cmd->cl_tcp_one_connection; - - pckt->icmp.code = cmd->cl_icmp_code; - pckt->icmp.type = cmd->cl_icmp_type; - - pckt->pl.min_len = cmd->cl_pl_min_len; - pckt->pl.max_len = cmd->cl_pl_max_len; - pckt->pl.is_static = cmd->cl_pl_is_static; + seq->ip.protocol = cmd->cl_protocol; + seq->ip.tos = cmd->cl_tos; + seq->ip.csum = cmd->cl_l3_csum; + + seq->udp.src_port = cmd->cl_udp_src_port; + seq->udp.dst_port = cmd->cl_udp_dst_port; + + seq->tcp.cooked = cmd->cl_tcp_cooked; + seq->tcp.one_connection = cmd->cl_tcp_one_connection; + seq->tcp.src_port = cmd->cl_tcp_src_port; + seq->tcp.dst_port = cmd->cl_tcp_dst_port; + seq->tcp.syn = cmd->cl_tcp_syn; + seq->tcp.ack = cmd->cl_tcp_ack; + seq->tcp.psh = cmd->cl_tcp_psh; + seq->tcp.rst = cmd->cl_tcp_rst; + seq->tcp.fin = cmd->cl_tcp_fin; + seq->tcp.urg = cmd->cl_tcp_urg; + seq->tcp.ece = cmd->cl_tcp_ece; + seq->tcp.cwr = cmd->cl_tcp_cwr; + + seq->icmp.code = cmd->cl_icmp_code; + seq->icmp.type = cmd->cl_icmp_type; + + struct payload_opt *pl = &seq->pls[0]; + + pl->min_len = cmd->cl_pl_min_len; + pl->max_len = cmd->cl_pl_max_len; + pl->is_static = cmd->cl_pl_is_static; if (cmd->cl_pl_exact != NULL) { - pckt->pl.exact = cmd->cl_pl_exact; + pl->exact = cmd->cl_pl_exact; } - pckt->pl.is_file = cmd->cl_pl_is_file; - pckt->pl.is_string = cmd->cl_pl_is_string; + pl->is_file = cmd->cl_pl_is_file; + pl->is_string = cmd->cl_pl_is_string; } /** diff --git a/src/config.c b/src/config.c index b496325..0b63ef3 100644 --- a/src/config.c +++ b/src/config.c @@ -111,307 +111,296 @@ int parse_config(const char file_name[], struct config *cfg, int only_seq, int * seq->track_count = json_object_get_boolean(tmp_obj); } - // Retrieve packets. - json_object *pckts_obj; - - if (!json_object_object_get_ex(seq_obj, "packets", &pckts_obj)) + // Retrieve layer-4 checksum. + if (json_object_object_get_ex(seq_obj, "l4csum", &tmp_obj)) { - continue; + seq->l4_csum = json_object_get_boolean(tmp_obj); } - int pckts_len = json_object_array_length(pckts_obj); + // Retrieve ethernet object. + struct json_object *eth_obj; - if (pckts_len < 1) + if (json_object_object_get_ex(seq_obj, "eth", ð_obj)) { - continue; + // Source MAC address. + if (json_object_object_get_ex(eth_obj, "smac", &tmp_obj)) + { + seq->eth.src_mac = (char *) json_object_get_string(tmp_obj); + } + + // Destination MAC address. + if (json_object_object_get_ex(eth_obj, "dmac", &tmp_obj)) + { + seq->eth.dst_mac = (char *) json_object_get_string(tmp_obj); + } } - for (int j = 0; j < pckts_len; j++) - { - struct packet *pckt = &seq->pckts[j]; + // Retrieve IP object. + struct json_object *ip_obj; - struct json_object *pckt_obj = json_object_array_get_idx(pckts_obj, j); + if (json_object_object_get_ex(seq_obj, "ip", &ip_obj)) + { + // Source IP. + if (json_object_object_get_ex(ip_obj, "srcip", &tmp_obj)) + { + seq->ip.src_ip = (char *) json_object_get_string(tmp_obj); + } - // Retrieve layer-4 checksum. - if (json_object_object_get_ex(pckt_obj, "l4csum", &tmp_obj)) + // Destination IP. + if (json_object_object_get_ex(ip_obj, "dstip", &tmp_obj)) { - pckt->l4_csum = json_object_get_boolean(tmp_obj); + seq->ip.dst_ip = (char *) json_object_get_string(tmp_obj); } - // Retrieve ethernet object. - struct json_object *eth_obj; + // Protocol. + if (json_object_object_get_ex(ip_obj, "protocol", &tmp_obj)) + { + seq->ip.protocol = (char *) json_object_get_string(tmp_obj); + } - if (json_object_object_get_ex(pckt_obj, "eth", ð_obj)) + // ToS. + if (json_object_object_get_ex(ip_obj, "tos", &tmp_obj)) { - // Source MAC address. - if (json_object_object_get_ex(eth_obj, "smac", &tmp_obj)) - { - pckt->eth.src_mac = (char *) json_object_get_string(tmp_obj); - } + seq->ip.tos = json_object_get_int(tmp_obj); + } - // Destination MAC address. - if (json_object_object_get_ex(eth_obj, "dmac", &tmp_obj)) - { - pckt->eth.dst_mac = (char *) json_object_get_string(tmp_obj); - } + // Checksum. + if (json_object_object_get_ex(ip_obj, "csum", &tmp_obj)) + { + seq->ip.csum = json_object_get_boolean(tmp_obj); } - // Retrieve IP object. - struct json_object *ip_obj; + // TTL object. + struct json_object *ttl_obj; - if (json_object_object_get_ex(pckt_obj, "ip", &ip_obj)) + if (json_object_object_get_ex(ip_obj, "ttl", &ttl_obj)) { - // Source IP. - if (json_object_object_get_ex(ip_obj, "srcip", &tmp_obj)) + // Minimum TTL. + if (json_object_object_get_ex(ttl_obj, "min", &tmp_obj)) { - pckt->ip.src_ip = (char *) json_object_get_string(tmp_obj); + seq->ip.min_ttl = json_object_get_int(tmp_obj); } - // Destination IP. - if (json_object_object_get_ex(ip_obj, "dstip", &tmp_obj)) + // Maximum TTL. + if (json_object_object_get_ex(ttl_obj, "max", &tmp_obj)) { - pckt->ip.dst_ip = (char *) json_object_get_string(tmp_obj); - } - - // Protocol. - if (json_object_object_get_ex(ip_obj, "protocol", &tmp_obj)) - { - pckt->ip.protocol = (char *) json_object_get_string(tmp_obj); + seq->ip.max_ttl = json_object_get_int(tmp_obj); } + } - // ToS. - if (json_object_object_get_ex(ip_obj, "tos", &tmp_obj)) - { - pckt->ip.tos = json_object_get_int(tmp_obj); - } + // ID object. + struct json_object *id_obj; - // Checksum. - if (json_object_object_get_ex(ip_obj, "csum", &tmp_obj)) + if (json_object_object_get_ex(ip_obj, "id", &id_obj)) + { + // Minimum ID. + if (json_object_object_get_ex(id_obj, "min", &tmp_obj)) { - pckt->ip.csum = json_object_get_boolean(tmp_obj); + seq->ip.min_id = json_object_get_int(tmp_obj); } - // TTL object. - struct json_object *ttl_obj; - - if (json_object_object_get_ex(ip_obj, "ttl", &ttl_obj)) + // Maximum ID. + if (json_object_object_get_ex(id_obj, "max", &tmp_obj)) { - // Minimum TTL. - if (json_object_object_get_ex(ttl_obj, "min", &tmp_obj)) - { - pckt->ip.min_ttl = json_object_get_int(tmp_obj); - } - - // Maximum TTL. - if (json_object_object_get_ex(ttl_obj, "max", &tmp_obj)) - { - pckt->ip.max_ttl = json_object_get_int(tmp_obj); - } + seq->ip.max_id = json_object_get_int(tmp_obj); } + } - // ID object. - struct json_object *id_obj; + // Ranges array. + struct json_object *ranges_obj; - if (json_object_object_get_ex(ip_obj, "id", &id_obj)) - { - // Minimum ID. - if (json_object_object_get_ex(id_obj, "min", &tmp_obj)) - { - pckt->ip.min_id = json_object_get_int(tmp_obj); - } - - // Maximum ID. - if (json_object_object_get_ex(id_obj, "max", &tmp_obj)) - { - pckt->ip.max_id = json_object_get_int(tmp_obj); - } - } - - // Ranges array. - struct json_object *ranges_obj; + if (json_object_object_get_ex(ip_obj, "ranges", &ranges_obj)) + { + int ranges_len = json_object_array_length(ranges_obj); - if (json_object_object_get_ex(ip_obj, "ranges", &ranges_obj)) + if (ranges_len > 0) { - int ranges_len = json_object_array_length(ranges_obj); - - if (ranges_len > 0) + for (int j = 0; j < ranges_len; j++) { - for (int n = 0; n < ranges_len; n++) - { - // Retrieve specific range and add to ranges array. - struct json_object *range_obj = json_object_array_get_idx(ranges_obj, n); + // Retrieve specific range and add to ranges array. + struct json_object *range_obj = json_object_array_get_idx(ranges_obj, j); - pckt->ip.ranges[n] = (char *) json_object_get_string(range_obj); - pckt->ip.range_count++; - } + seq->ip.ranges[j] = (char *) json_object_get_string(range_obj); + seq->ip.range_count++; } } } + } - // UDP object. - struct json_object *udp_obj; + // UDP object. + struct json_object *udp_obj; - if (json_object_object_get_ex(pckt_obj, "udp", &udp_obj)) + if (json_object_object_get_ex(seq_obj, "udp", &udp_obj)) + { + // Source port. + if (json_object_object_get_ex(udp_obj, "srcport", &tmp_obj)) { - // Source port. - if (json_object_object_get_ex(udp_obj, "srcport", &tmp_obj)) - { - pckt->udp.src_port = json_object_get_int(tmp_obj); - } + seq->udp.src_port = json_object_get_int(tmp_obj); + } - // Destination port. - if (json_object_object_get_ex(udp_obj, "dstport", &tmp_obj)) - { - pckt->udp.dst_port = json_object_get_int(tmp_obj); - } + // Destination port. + if (json_object_object_get_ex(udp_obj, "dstport", &tmp_obj)) + { + seq->udp.dst_port = json_object_get_int(tmp_obj); } + } - // TCP object. - struct json_object *tcp_obj; + // TCP object. + struct json_object *tcp_obj; - if (json_object_object_get_ex(pckt_obj, "tcp", &tcp_obj)) + if (json_object_object_get_ex(seq_obj, "tcp", &tcp_obj)) + { + // Cooked socket. + if (json_object_object_get_ex(tcp_obj, "cooked", &tmp_obj)) { - // Cooked socket. - if (json_object_object_get_ex(tcp_obj, "cooked", &tmp_obj)) - { - pckt->tcp.cooked = json_object_get_boolean(tmp_obj); - } + seq->tcp.cooked = json_object_get_boolean(tmp_obj); + } - // One connection. - if (json_object_object_get_ex(tcp_obj, "oneconnection", &tmp_obj)) - { - pckt->tcp.one_connection = json_object_get_boolean(tmp_obj); - } + // One connection. + if (json_object_object_get_ex(tcp_obj, "oneconnection", &tmp_obj)) + { + seq->tcp.one_connection = json_object_get_boolean(tmp_obj); + } - // Source port. - if (json_object_object_get_ex(tcp_obj, "srcport", &tmp_obj)) - { - pckt->tcp.src_port = json_object_get_int(tmp_obj); - } + // Source port. + if (json_object_object_get_ex(tcp_obj, "srcport", &tmp_obj)) + { + seq->tcp.src_port = json_object_get_int(tmp_obj); + } - // Destination port. - if (json_object_object_get_ex(tcp_obj, "dstport", &tmp_obj)) - { - pckt->tcp.dst_port = json_object_get_int(tmp_obj); - } + // Destination port. + if (json_object_object_get_ex(tcp_obj, "dstport", &tmp_obj)) + { + seq->tcp.dst_port = json_object_get_int(tmp_obj); + } - // SYN flag. - if (json_object_object_get_ex(tcp_obj, "syn", &tmp_obj)) - { - pckt->tcp.syn = json_object_get_boolean(tmp_obj); - } + // SYN flag. + if (json_object_object_get_ex(tcp_obj, "syn", &tmp_obj)) + { + seq->tcp.syn = json_object_get_boolean(tmp_obj); + } - // PSH flag. - if (json_object_object_get_ex(tcp_obj, "psh", &tmp_obj)) - { - pckt->tcp.psh = json_object_get_boolean(tmp_obj); - } + // PSH flag. + if (json_object_object_get_ex(tcp_obj, "psh", &tmp_obj)) + { + seq->tcp.psh = json_object_get_boolean(tmp_obj); + } - // FIN flag. - if (json_object_object_get_ex(tcp_obj, "fin", &tmp_obj)) - { - pckt->tcp.fin = json_object_get_boolean(tmp_obj); - } + // FIN flag. + if (json_object_object_get_ex(tcp_obj, "fin", &tmp_obj)) + { + seq->tcp.fin = json_object_get_boolean(tmp_obj); + } - // ACK flag. - if (json_object_object_get_ex(tcp_obj, "ack", &tmp_obj)) - { - pckt->tcp.ack = json_object_get_boolean(tmp_obj); - } + // ACK flag. + if (json_object_object_get_ex(tcp_obj, "ack", &tmp_obj)) + { + seq->tcp.ack = json_object_get_boolean(tmp_obj); + } - // RST flag. - if (json_object_object_get_ex(tcp_obj, "rst", &tmp_obj)) - { - pckt->tcp.rst = json_object_get_boolean(tmp_obj); - } + // RST flag. + if (json_object_object_get_ex(tcp_obj, "rst", &tmp_obj)) + { + seq->tcp.rst = json_object_get_boolean(tmp_obj); + } - // URG flag. - if (json_object_object_get_ex(tcp_obj, "urg", &tmp_obj)) - { - pckt->tcp.urg = json_object_get_boolean(tmp_obj); - } + // URG flag. + if (json_object_object_get_ex(tcp_obj, "urg", &tmp_obj)) + { + seq->tcp.urg = json_object_get_boolean(tmp_obj); + } - // ECE flag. - if (json_object_object_get_ex(tcp_obj, "ece", &tmp_obj)) - { - pckt->tcp.ece = json_object_get_boolean(tmp_obj); - } + // ECE flag. + if (json_object_object_get_ex(tcp_obj, "ece", &tmp_obj)) + { + seq->tcp.ece = json_object_get_boolean(tmp_obj); + } - // CWR flag. - if (json_object_object_get_ex(tcp_obj, "cwr", &tmp_obj)) - { - pckt->tcp.cwr = json_object_get_boolean(tmp_obj); - } + // CWR flag. + if (json_object_object_get_ex(tcp_obj, "cwr", &tmp_obj)) + { + seq->tcp.cwr = json_object_get_boolean(tmp_obj); } + } - // ICMP object. - struct json_object *icmp_obj; + // ICMP object. + struct json_object *icmp_obj; - if (json_object_object_get_ex(pckt_obj, "icmp", &icmp_obj)) + if (json_object_object_get_ex(seq_obj, "icmp", &icmp_obj)) + { + // Code. + if (json_object_object_get_ex(icmp_obj, "code", &tmp_obj)) { - // Code. - if (json_object_object_get_ex(icmp_obj, "code", &tmp_obj)) - { - pckt->icmp.code = json_object_get_int(tmp_obj); - } + seq->icmp.code = json_object_get_int(tmp_obj); + } - // Type. - if (json_object_object_get_ex(icmp_obj, "type", &tmp_obj)) - { - pckt->icmp.type = json_object_get_int(tmp_obj); - } + // Type. + if (json_object_object_get_ex(icmp_obj, "type", &tmp_obj)) + { + seq->icmp.type = json_object_get_int(tmp_obj); } + } - // Payload object. - struct json_object *pl_obj; + // Payloads object. + struct json_object *pls_obj; - if (json_object_object_get_ex(pckt_obj, "payload", &pl_obj)) + if (json_object_object_get_ex(seq_obj, "payloads", &pls_obj)) + { + int pls_len = json_object_array_length(pls_obj); + + if (pls_len > 0) { - // Is static. - if (json_object_object_get_ex(pl_obj, "isstatic", &tmp_obj)) + for (int j = 0; j < pls_len; j++) { - pckt->pl.is_static = json_object_get_boolean(tmp_obj); - } + struct json_object *pl_obj = json_object_array_get_idx(pls_obj, j); - // Is file. - if (json_object_object_get_ex(pl_obj, "isfile", &tmp_obj)) - { - pckt->pl.is_file = json_object_get_boolean(tmp_obj); - } + struct payload_opt *pl = &seq->pls[j]; - // Is string. - if (json_object_object_get_ex(pl_obj, "isstring", &tmp_obj)) - { - pckt->pl.is_string = json_object_get_boolean(tmp_obj); - } + // Is static. + if (json_object_object_get_ex(pl_obj, "isstatic", &tmp_obj)) + { + pl->is_static = json_object_get_boolean(tmp_obj); + } - // Exact. - if (json_object_object_get_ex(pl_obj, "exact", &tmp_obj)) - { - pckt->pl.exact = (char *) json_object_get_string(tmp_obj); - } + // Is file. + if (json_object_object_get_ex(pl_obj, "isfile", &tmp_obj)) + { + pl->is_file = json_object_get_boolean(tmp_obj); + } - // Length object. - struct json_object *len_obj; + // Is string. + if (json_object_object_get_ex(pl_obj, "isstring", &tmp_obj)) + { + pl->is_string = json_object_get_boolean(tmp_obj); + } - if (json_object_object_get_ex(pl_obj, "length", &len_obj)) - { - // Minimum length. - if (json_object_object_get_ex(len_obj, "min", &tmp_obj)) + // Exact. + if (json_object_object_get_ex(pl_obj, "exact", &tmp_obj)) { - pckt->pl.min_len = json_object_get_int(tmp_obj); + pl->exact = (char *) json_object_get_string(tmp_obj); } - // Maximum length. - if (json_object_object_get_ex(len_obj, "max", &tmp_obj)) + // Length object. + struct json_object *len_obj; + + if (json_object_object_get_ex(pl_obj, "length", &len_obj)) { - pckt->pl.max_len = json_object_get_int(tmp_obj); + // Minimum length. + if (json_object_object_get_ex(len_obj, "min", &tmp_obj)) + { + pl->min_len = json_object_get_int(tmp_obj); + } + + // Maximum length. + if (json_object_object_get_ex(len_obj, "max", &tmp_obj)) + { + pl->max_len = json_object_get_int(tmp_obj); + } } + + seq->pl_cnt++; } } - - seq->pckts_cnt++; - } *seq_num += 1; @@ -431,68 +420,67 @@ int parse_config(const char file_name[], struct config *cfg, int only_seq, int * **/ void clear_sequence(struct config *cfg, int seq_num) { - cfg->seq[seq_num].interface = NULL; - cfg->seq[seq_num].block = 1; - cfg->seq[seq_num].max_count = 0; - cfg->seq[seq_num].threads = 0; - cfg->seq[seq_num].time = 0; - cfg->seq[seq_num].delay = 1000000; - - for (int i = 0; i < MAX_PACKETS; i++) - { - struct packet *pkt = &cfg->seq[seq_num].pckts[i]; - - pkt->eth.src_mac = NULL; - pkt->eth.dst_mac = NULL; - - pkt->ip.src_ip = NULL; - pkt->ip.dst_ip = NULL; - pkt->ip.protocol = NULL; - pkt->ip.tos = 0; - pkt->ip.min_ttl = 64; - pkt->ip.max_ttl = 64; - pkt->ip.min_id = 0; - pkt->ip.max_id = 64000; - pkt->ip.csum = 1; - - pkt->udp.src_port = 0; - pkt->udp.dst_port = 0; - - pkt->tcp.syn = 0; - pkt->tcp.ack = 0; - pkt->tcp.psh = 0; - pkt->tcp.rst = 0; - pkt->tcp.fin = 0; - pkt->tcp.urg = 0; - pkt->tcp.cooked = 0; - pkt->tcp.one_connection = 0; - - pkt->icmp.code = 0; - pkt->icmp.type = 0; - - pkt->l4_csum = 1; - - pkt->pl.exact = NULL; - pkt->pl.is_file = 0; - pkt->pl.is_string = 0; - pkt->pl.is_static = 0; - pkt->pl.min_len = 0; - pkt->pl.max_len = 0; - } + struct sequence *seq = &cfg->seq[seq_num]; + + seq->interface = NULL; + seq->block = 1; + seq->max_count = 0; + seq->threads = 0; + seq->time = 0; + seq->delay = 1000000; + + seq->eth.src_mac = NULL; + seq->eth.dst_mac = NULL; + + seq->ip.src_ip = NULL; + seq->ip.dst_ip = NULL; + seq->ip.protocol = NULL; + seq->ip.tos = 0; + seq->ip.min_ttl = 64; + seq->ip.max_ttl = 64; + seq->ip.min_id = 0; + seq->ip.max_id = 64000; + seq->ip.csum = 1; + + seq->udp.src_port = 0; + seq->udp.dst_port = 0; + + seq->tcp.syn = 0; + seq->tcp.ack = 0; + seq->tcp.psh = 0; + seq->tcp.rst = 0; + seq->tcp.fin = 0; + seq->tcp.urg = 0; + seq->tcp.cooked = 0; + seq->tcp.one_connection = 0; + + seq->icmp.code = 0; + seq->icmp.type = 0; + + seq->l4_csum = 1; // Reset includes. - for (int i = 0; i < cfg->seq[seq_num].include_count; i++) + for (int i = 0; i < MAX_INCLUDES; i++) { - cfg->seq[seq_num].includes[i] = NULL; + seq->includes[i] = NULL; } - // Reset source ranges. - for (int i = 0; i < MAX_PACKETS; i++) + // Reset IP ranges. + for (int i = 0; i < MAX_RANGES; i++) { - for (int j = 0; j < cfg->seq[seq_num].pckts[i].ip.range_count; j++) - { - cfg->seq[seq_num].pckts[i].ip.ranges[j] = NULL; - } + seq->ip.ranges[i] = NULL; + } + + // Reset payloads. + for (int i = 0; i < MAX_PAYLOADS; i++) { + struct payload_opt *pl = &seq->pls[i]; + + pl->exact = NULL; + pl->is_file = 0; + pl->is_static = 0; + pl->is_static = 0; + pl->min_len = 0; + pl->max_len = 0; } } @@ -541,81 +529,84 @@ void print_config(struct config *cfg, int seq_cnt) fprintf(stdout, "\t\tDelay => %llu\n", seq->delay); fprintf(stdout, "\t\tThreads => %u\n", seq->threads); - // Packets. - fprintf(stdout, "\t\tPackets\n"); - for (int i = 0; i < seq->pckts_cnt; i++) - { - fprintf(stdout, "\t\t\t#%d\n", i + 1); + // Ethernet settings. + fprintf(stdout, "\t\tEthernet\n"); + fprintf(stdout, "\t\t\tSource MAC => %s\n", seq->eth.src_mac ? seq->eth.src_mac : "N/A"); + fprintf(stdout, "\t\t\tDestination MAC => %s\n", seq->eth.dst_mac ? seq->eth.dst_mac : "N/A"); - struct packet *pckt = &seq->pckts[i]; + // IP settings. + fprintf(stdout, "\t\tIP\n"); + fprintf(stdout, "\t\t\tProtocol => %s\n", seq->ip.protocol ? seq->ip.protocol : "N/A"); - // Ethernet settings. - fprintf(stdout, "\t\t\t\tEthernet\n"); - fprintf(stdout, "\t\t\t\t\tSource MAC => %s\n", pckt->eth.src_mac ? pckt->eth.src_mac : "N/A"); - fprintf(stdout, "\t\t\t\t\tDestination MAC => %s\n", pckt->eth.dst_mac ? pckt->eth.dst_mac : "N/A"); + fprintf(stdout, "\t\t\tSource IP => %s\n", seq->ip.src_ip ? seq->ip.src_ip : "N/A"); + fprintf(stdout, "\t\t\tDestination IP => %s\n", seq->ip.dst_ip ? seq->ip.dst_ip : "N/A"); - // IP settings. - fprintf(stdout, "\t\t\t\tIP\n"); - fprintf(stdout, "\t\t\t\t\tProtocol => %s\n", pckt->ip.protocol ? pckt->ip.protocol : "N/A"); + fprintf(stdout, "\t\t\tType of Service => %d\n", seq->ip.tos); + fprintf(stdout, "\t\t\tMin TTL => %d\n", seq->ip.min_ttl); + fprintf(stdout, "\t\t\tMax TTL => %d\n", seq->ip.max_ttl); + fprintf(stdout, "\t\t\tMin ID => %d\n", seq->ip.min_id); + fprintf(stdout, "\t\t\tMax ID => %d\n", seq->ip.max_id); + fprintf(stdout, "\t\t\tChecksum => %s\n", seq->ip.csum ? "Yes" : "No"); - fprintf(stdout, "\t\t\t\t\tSource IP => %s\n", pckt->ip.src_ip ? pckt->ip.src_ip : "N/A"); - fprintf(stdout, "\t\t\t\t\tDestination IP => %s\n", pckt->ip.dst_ip ? pckt->ip.dst_ip : "N/A"); + if (seq->ip.range_count > 0) + { + fprintf(stdout, "\t\t\tRanges:\n"); - if (pckt->ip.range_count > 0) + for (int j = 0; j < seq->ip.range_count; j++) { - fprintf(stdout, "\t\t\t\t\tRanges:\n"); - - for (int j = 0; j < pckt->ip.range_count; j++) - { - fprintf(stdout, "\t\t\t\t\t\t- %s\n", pckt->ip.ranges[j]); - } + fprintf(stdout, "\t\t\t\t- %s\n", seq->ip.ranges[j]); } + } - fprintf(stdout, "\t\t\t\t\tType of Service => %d\n", pckt->ip.tos); - fprintf(stdout, "\t\t\t\t\tMin TTL => %d\n", pckt->ip.min_ttl); - fprintf(stdout, "\t\t\t\t\tMax TTL => %d\n", pckt->ip.max_ttl); - fprintf(stdout, "\t\t\t\t\tMin ID => %d\n", pckt->ip.min_id); - fprintf(stdout, "\t\t\t\t\tMax ID => %d\n", pckt->ip.max_id); - fprintf(stdout, "\t\t\t\t\tChecksum => %s\n", pckt->ip.csum ? "Yes" : "No"); - - // TCP settings. - fprintf(stdout, "\t\t\t\tTCP\n"); - fprintf(stdout, "\t\t\t\t\tSource Port => %d\n", pckt->tcp.src_port); - fprintf(stdout, "\t\t\t\t\tDest Port => %d\n", pckt->tcp.dst_port); - fprintf(stdout, "\t\t\t\t\tUse Socket => %s\n", pckt->tcp.cooked ? "Yes" : "No"); - fprintf(stdout, "\t\t\t\t\tOne Connection => %s\n", pckt->tcp.one_connection ? "Yes" : "No"); - fprintf(stdout, "\t\t\t\t\tSYN Flag => %s\n", pckt->tcp.syn ? "Yes": "No"); - fprintf(stdout, "\t\t\t\t\tPSH Flag => %s\n", pckt->tcp.psh ? "Yes" : "No"); - fprintf(stdout, "\t\t\t\t\tFIN Flag => %s\n", pckt->tcp.fin ? "Yes" : "No"); - fprintf(stdout, "\t\t\t\t\tACK Flag => %s\n", pckt->tcp.ack ? "Yes" : "No"); - fprintf(stdout, "\t\t\t\t\tRST Flag => %s\n", pckt->tcp.rst ? "Yes" : "No"); - fprintf(stdout, "\t\t\t\t\tURG Flag => %s\n", pckt->tcp.urg ? "Yes" : "No"); - - // UDP settings. - fprintf(stdout, "\t\t\t\tUDP\n"); - fprintf(stdout, "\t\t\t\t\tSrc Port => %d\n", pckt->udp.src_port); - fprintf(stdout, "\t\t\t\t\tDst Port => %d\n", pckt->udp.dst_port); - - // ICMP settings. - fprintf(stdout, "\t\t\t\tICMP\n"); - fprintf(stdout, "\t\t\t\t\tCode => %d\n", pckt->icmp.code); - fprintf(stdout, "\t\t\t\t\tType => %d\n", pckt->icmp.type); - - // Layer 4 setting(s). - fprintf(stdout, "\t\t\t\tLayer 4\n"); - fprintf(stdout, "\t\t\t\t\tChecksum => %s\n", pckt->l4_csum ? "Yes" : "No"); - - // Payload settings. - fprintf(stdout, "\t\t\t\tPayload\n"); - fprintf(stdout, "\t\t\t\t\tMin Length => %d\n", pckt->pl.min_len); - fprintf(stdout, "\t\t\t\t\tMax Length => %d\n", pckt->pl.max_len); - fprintf(stdout, "\t\t\t\t\tIs Static => %s\n", pckt->pl.is_static ? "Yes" : "No"); - fprintf(stdout, "\t\t\t\t\tIs File => %s\n", pckt->pl.is_file ? "Yes" : "No"); - fprintf(stdout, "\t\t\t\t\tIs String => %s\n", pckt->pl.is_string ? "Yes" : "No"); - fprintf(stdout, "\t\t\t\t\tExact String => %s\n", pckt->pl.exact ? pckt->pl.exact : "N/A"); - - fprintf(stdout, "\n\n"); + // TCP settings. + fprintf(stdout, "\t\tTCP\n"); + fprintf(stdout, "\t\t\tSource Port => %d\n", seq->tcp.src_port); + fprintf(stdout, "\t\t\tDest Port => %d\n", seq->tcp.dst_port); + fprintf(stdout, "\t\t\tUse Socket => %s\n", seq->tcp.cooked ? "Yes" : "No"); + fprintf(stdout, "\t\t\tOne Connection => %s\n", seq->tcp.one_connection ? "Yes" : "No"); + fprintf(stdout, "\t\t\tSYN Flag => %s\n", seq->tcp.syn ? "Yes": "No"); + fprintf(stdout, "\t\t\tPSH Flag => %s\n", seq->tcp.psh ? "Yes" : "No"); + fprintf(stdout, "\t\t\tFIN Flag => %s\n", seq->tcp.fin ? "Yes" : "No"); + fprintf(stdout, "\t\t\tACK Flag => %s\n", seq->tcp.ack ? "Yes" : "No"); + fprintf(stdout, "\t\t\tRST Flag => %s\n", seq->tcp.rst ? "Yes" : "No"); + fprintf(stdout, "\t\t\tURG Flag => %s\n", seq->tcp.urg ? "Yes" : "No"); + fprintf(stdout, "\t\t\tECE Flag => %s\n", seq->tcp.ece ? "Yes" : "No"); + fprintf(stdout, "\t\t\tCWR Flag => %s\n", seq->tcp.cwr ? "Yes" : "No"); + + // UDP settings. + fprintf(stdout, "\t\tUDP\n"); + fprintf(stdout, "\t\t\tSrc Port => %d\n", seq->udp.src_port); + fprintf(stdout, "\t\t\tDst Port => %d\n", seq->udp.dst_port); + + // ICMP settings. + fprintf(stdout, "\t\tICMP\n"); + fprintf(stdout, "\t\t\tCode => %d\n", seq->icmp.code); + fprintf(stdout, "\t\t\tType => %d\n", seq->icmp.type); + + // Layer 4 setting(s). + fprintf(stdout, "\t\tLayer 4\n"); + fprintf(stdout, "\t\t\tChecksum => %s\n", seq->l4_csum ? "Yes" : "No"); + + if (seq->pl_cnt > 0) + { + fprintf(stdout, "\t\tPayloads (%d)\n", seq->pl_cnt); + + for (int j = 0; j < seq->pl_cnt; j++) + { + struct payload_opt *pl = &seq->pls[j]; + + fprintf(stdout, "\t\t\t#%d\n", j + 1); + + fprintf(stdout, "\t\t\t\tMin Length => %d\n", pl->min_len); + fprintf(stdout, "\t\t\t\tMax Length => %d\n", pl->max_len); + fprintf(stdout, "\t\t\t\tIs Static => %s\n", pl->is_static ? "Yes" : "No"); + fprintf(stdout, "\t\t\t\tIs File => %s\n", pl->is_file ? "Yes" : "No"); + fprintf(stdout, "\t\t\t\tIs String => %s\n", pl->is_string ? "Yes" : "No"); + fprintf(stdout, "\t\t\t\tExact String => %s\n", pl->exact ? pl->exact : "N/A"); + } } + + fprintf(stdout, "\n\n"); } } \ No newline at end of file diff --git a/src/config.h b/src/config.h index 72f94fa..5ee592f 100644 --- a/src/config.h +++ b/src/config.h @@ -7,7 +7,7 @@ #define MAX_SEQUENCES 256 #define MAX_RANGES 64 -#define MAX_PACKETS 256 +#define MAX_PAYLOADS 256 struct eth_opt { @@ -82,24 +82,6 @@ struct payload_opt char *exact; }; -struct packet -{ - // Ethernet options. - struct eth_opt eth; - - // IP options. - struct ip_opt ip; - - // Layer 4 options. - struct tcp_opt tcp; - struct udp_opt udp; - struct icmp_opt icmp; - unsigned int l4_csum : 1; - - // Payload options. - struct payload_opt pl; -}; - struct sequence { // General options. @@ -114,8 +96,21 @@ struct sequence __u16 include_count; unsigned int track_count : 1; - int pckts_cnt; - struct packet pckts[MAX_PACKETS]; + // Ethernet options. + struct eth_opt eth; + + // IP options. + struct ip_opt ip; + + // Layer 4 options. + struct tcp_opt tcp; + struct udp_opt udp; + struct icmp_opt icmp; + unsigned int l4_csum : 1; + + // Payload options. + int pl_cnt; + struct payload_opt pls[MAX_PAYLOADS]; }; struct config