From 1a8ae106ffb6db271df227748edb9e8ff76ea83c Mon Sep 17 00:00:00 2001 From: Pavel Odintsov Date: Thu, 26 Feb 2015 16:26:51 +0300 Subject: [PATCH] Fix syn umbrella code for PFRING 6.0.2 and 6.0.3 support both --- build_syn_umbrella.sh | 4 +++- syn_umbrella.cpp | 24 +++++++++++++++++------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/build_syn_umbrella.sh b/build_syn_umbrella.sh index 9cd99061..ad759434 100755 --- a/build_syn_umbrella.sh +++ b/build_syn_umbrella.sh @@ -1,3 +1,5 @@ #!/bin/bash -g++ syn_umbrella.cpp -I/opt/crafter/include -I/opt/pf_ring/include -lpthread -l/opt/pf_ring/lib/libpfring.so -lnuma -l/opt/crafter/lib/libcrafter.so -o umbrella +g++ syn_umbrella.cpp -I/opt/crafter/include -I/opt/pf_ring/include -lpthread -l/opt/pf_ring/lib/libpfring.so -lnuma -l/opt/crafter/lib/libcrafter.so -o synumbrella + +# ./umbrella -i zc:eth4 -c 1 -o zc:eth4 -g 0 -v diff --git a/syn_umbrella.cpp b/syn_umbrella.cpp index 85305478..18401824 100644 --- a/syn_umbrella.cpp +++ b/syn_umbrella.cpp @@ -64,18 +64,28 @@ int bind2core(int core_id) { } } -// !!!!!! -// TODO: fix it to compile on 6.0.2 PF_RING!!!!! -int max_packet_len(char *device) { - int max_len; - pfring *ring; +int max_packet_len(const char *device) { + int max_len = 0; - ring = pfring_open(device, 1536, PF_RING_PROMISC); + pfring* ring = pfring_open(device, 1536, PF_RING_PROMISC); if (ring == NULL) return 1536; - max_len = pfring_get_max_packet_size(ring); +// pfring_get_card_settings have added in 6.0.3 +#if RING_VERSION_NUM >= 0x060003 + pfring_card_settings settings; + pfring_get_card_settings(ring, &settings); + max_len = settings.max_packet_size; +#else + if (ring->dna.dna_mapped_device) { + max_len = ring->dna.dna_dev.mem_info.rx.packet_memory_slot_len; + } else { + max_len = pfring_get_mtu_size(ring); + if (max_len == 0) max_len = 9000 /* Jumbo */; + max_len += 14 /* Eth */ + 4 /* VLAN */; + } +#endif pfring_close(ring);