Greatly improve capdiff

This commit is contained in:
Quentin 2019-06-04 17:44:55 +02:00
parent 5bfc545f23
commit 4a110d9697

View file

@ -23,8 +23,7 @@ uint8_t are_packets_equal(struct buffer_packet bpread[]) {
enum pkt_reconstruct_res { PREC_SAME, PREC_DROP, PREC_FAIL };
struct pkt_reconstruct {
enum pkt_reconstruct_res r;
int diff_0;
int diff_1;
int diff[2];
struct buffer_packet single[2][MAX_PKTS_TO_CHECK_FOR_DROP];
};
@ -76,8 +75,8 @@ void reconstruct_action(struct cap_file cf[], struct pkt_reconstruct* pr, GHashT
cap_npeek_bp(&cf[1], m2, &bpread[1]);
if(are_packets_equal(bpread)) {
pr->r = m1 == 0 && m2 == 0 ? PREC_SAME : PREC_DROP;
pr->diff_0 = m1;
pr->diff_1 = m2;
pr->diff[0] = m1;
pr->diff[1] = m2;
for (int m = m1; m >= 0; m--) unroll_packets (cf, bpread, stats, pr, m, 0);
for (int m = m2; m >= 0; m--) unroll_packets (cf, bpread, stats, pr, m, 1);
return;
@ -87,8 +86,8 @@ void reconstruct_action(struct cap_file cf[], struct pkt_reconstruct* pr, GHashT
cap_npeek_bp(&cf[1], m1, &bpread[1]);
if(are_packets_equal(bpread)) {
pr->r = PREC_DROP;
pr->diff_0 = m2;
pr->diff_1 = m1;
pr->diff[0] = m2;
pr->diff[1] = m1;
for (int m = m2; m >= 0; m--) unroll_packets (cf, bpread, stats, pr, m, 0);
for (int m = m1; m >= 0; m--) unroll_packets (cf, bpread, stats, pr, m, 1);
return;
@ -137,17 +136,28 @@ int main(int argc, char** argv) {
int c0 = 0, c1 = 0, stop = 0;
while (c0 < cf[0].sz_obj && c1 < cf[1].sz_obj && !stop) {
reconstruct_action(cf, &pr, stats);
c0 += pr.diff_0 + 1;
c1 += pr.diff_1 + 1;
c0 += pr.diff[0] + 1;
c1 += pr.diff[1] + 1;
switch (pr.r) {
case PREC_SAME:
// Nothing
break;
case PREC_DROP:
fprintf(stderr, "[!!] packets (%d,%d) ", c0, c1);
if (c0 > 0) fprintf(stderr, "%s dropped %d pkts ", cf[0].filename, pr.diff_1);
if (c1 > 0) fprintf(stderr, "%s dropped %d pkts ", cf[1].filename, pr.diff_0);
fprintf(stderr, "[!!] packets (%d,%d), ", c0, c1);
if (pr.diff[1] > 0) fprintf(stderr, "%s dropped %d pkts, ", cf[0].filename, pr.diff[1]);
if (pr.diff[0] > 0) fprintf(stderr, "%s dropped %d pkts ", cf[1].filename, pr.diff[0]);
fprintf(stderr, "\n");
gboolean both_different = pr.diff[1] > 0 && pr.diff[0] > 0;
for (int j=0; j < 2; j++) {
gboolean received_created_packets = strstr(cf[j].filename, "received") != NULL && pr.diff[j] > 0;
if (!both_different && !received_created_packets) continue;
fprintf(stderr, "---- %s contains the following packets that are not in %s ----\n", cf[j].filename, cf[(j+1)%2].filename);
for (int i = pr.diff[j]; i >= 0; i--) {
dump_buffer_packet (&pr.single[j][i]);
}
}
break;
case PREC_FAIL:
fprintf(stderr, "[!!] Unable to remap packets (%d, %d). We should stop\n", c0, c1);