/* * netsniff-ng - the packet sniffing beast * Copyright 2009, 2010 Daniel Borkmann. * Copyright 2009, 2010 Emmanuel Roullit. * Subject to the GPL, version 2. */ #include #include #include #include #include #include #include #include #include #include "die.h" #include "xmalloc.h" #include "ring_tx.h" #include "built_in.h" void set_packet_loss_discard(int sock) { int ret, discard = 1; ret = setsockopt(sock, SOL_PACKET, PACKET_LOSS, (void *) &discard, sizeof(discard)); if (ret < 0) panic("setsockopt: cannot set packet loss"); } void destroy_tx_ring(int sock, struct ring *ring) { int ret; munmap(ring->mm_space, ring->mm_len); ring->mm_len = 0; fmemset(&ring->layout, 0, sizeof(ring->layout)); ret = setsockopt(sock, SOL_PACKET, PACKET_TX_RING, &ring->layout, sizeof(ring->layout)); if (unlikely(ret)) panic("Cannot destroy the TX_RING: %s!\n", strerror(errno)); xfree(ring->frames); } void setup_tx_ring_layout(int sock, struct ring *ring, unsigned int size, bool jumbo_support) { fmemset(&ring->layout, 0, sizeof(ring->layout)); ring->layout.tp_block_size = (jumbo_support ? getpagesize() << 4 : getpagesize() << 2); ring->layout.tp_frame_size = (jumbo_support ? TPACKET_ALIGNMENT << 12 : TPACKET_ALIGNMENT << 7); ring->layout.tp_block_nr = size / ring->layout.tp_block_size; ring->layout.tp_frame_nr = ring->layout.tp_block_size / ring->layout.tp_frame_size * ring->layout.tp_block_nr; set_sockopt_tpacket_v2(sock); ring_verify_layout(ring); } void create_tx_ring(int sock, struct ring *ring, int verbose) { int ret; retry: ret = setsockopt(sock, SOL_PACKET, PACKET_TX_RING, &ring->layout, sizeof(ring->layout)); if (errno == ENOMEM && ring->layout.tp_block_nr > 1) { ring->layout.tp_block_nr >>= 1; ring->layout.tp_frame_nr = ring->layout.tp_block_size / ring->layout.tp_frame_size * ring->layout.tp_block_nr; goto retry; } if (ret < 0) panic("Cannot allocate TX_RING!\n"); ring->mm_len = ring->layout.tp_block_size * ring->layout.tp_block_nr; if (verbose) { printf("TX: %.2Lf MiB, %u Frames, each %u Byte allocated\n", (long double) ring->mm_len / (1 << 20), ring->layout.tp_frame_nr, ring->layout.tp_frame_size); } } void mmap_tx_ring(int sock, struct ring *ring) { mmap_ring_generic(sock, ring); } void alloc_tx_ring_frames(int sock __maybe_unused, struct ring *ring) { alloc_ring_frames_generic(ring, ring->layout.tp_frame_nr, ring->layout.tp_frame_size); } void bind_tx_ring(int sock, struct ring *ring, int ifindex) { bind_ring_generic(sock, ring, ifindex); } h'>path: root/net/batman-adv/soft-interface.c
diff options
context:
space:
mode:
authorSven Eckelmann <sven@narfation.org>2016-02-26 17:56:13 +0100
committerAntonio Quartulli <a@unstable.cc>2016-04-24 15:37:21 +0800
commitc78296665c3d81f040117432ab9e1cb125521b0c (patch)
tree8fdc01e1c914e14e548192e611f036a0f479d0a6 /net/batman-adv/soft-interface.c
parent5f44abd041c5f3be76d57579ab254d78e601315b (diff)
batman-adv: Check skb size before using encapsulated ETH+VLAN header
The encapsulated ethernet and VLAN header may be outside the received ethernet frame. Thus the skb buffer size has to be checked before it can be parsed to find out if it encapsulates another batman-adv packet. Fixes: 420193573f11 ("batman-adv: softif bridge loop avoidance") Signed-off-by: Sven Eckelmann <sven@narfation.org> Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch> Signed-off-by: Antonio Quartulli <a@unstable.cc>
Diffstat (limited to 'net/batman-adv/soft-interface.c')