/* * netsniff-ng - the packet sniffing beast * Copyright 2009, 2010 Daniel Borkmann. * Copyright 2014, 2015 Tobias Klauser * Subject to the GPL, version 2. */ #include #include #include #include #include #include #include #include #include #include "xmalloc.h" #include "die.h" #include "ring.h" #include "built_in.h" void setup_ring_layout_generic(struct ring *ring, size_t size, bool jumbo_support) { fmemset(&ring->layout, 0, sizeof(ring->layout)); ring->layout.tp_block_size = (jumbo_support ? RUNTIME_PAGE_SIZE << 4 : RUNTIME_PAGE_SIZE << 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 = size / ring->layout.tp_frame_size; } void mmap_ring_generic(int sock, struct ring *ring) { ring->mm_space = mmap(NULL, ring->mm_len, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_LOCKED | MAP_POPULATE, sock, 0); if (ring->mm_space == MAP_FAILED) panic("Cannot mmap {TX,RX}_RING!\n"); } void alloc_ring_frames_generic(struct ring *ring, size_t num, size_t size) { size_t i, len = num * sizeof(*ring->frames); ring->frames = xmalloc_aligned(len, CO_CACHE_LINE_SIZE); fmemset(ring->frames, 0, len); for (i = 0; i < num; ++i) { ring->frames[i].iov_len = size; ring->frames[i].iov_base = ring->mm_space + (i * size); } } void bind_ring_generic(int sock, struct ring *ring, int ifindex, bool tx_only) { int ret; /* The {TX,RX}_RING registers itself to the networking stack with * dev_add_pack(), so we have one single RX_RING for all devs * otherwise you'll get the packet twice. */ fmemset(&ring->s_ll, 0, sizeof(ring->s_ll)); ring->s_ll.sll_family = AF_PACKET; ring->s_ll.sll_ifindex = ifindex; ring->s_ll.sll_protocol = tx_only ? 0 : htons(ETH_P_ALL); ret = bind(sock, (struct sockaddr *) &ring->s_ll, sizeof(ring->s_ll)); if (ret < 0) panic("Cannot bind {TX,RX}_RING!\n"); } -next.git/log/'>
diff options
context:
space:
mode:
authortang.junhui <tang.junhui@zte.com.cn>2016-10-21 09:35:32 +0800
committerMike Snitzer <snitzer@redhat.com>2016-10-24 11:17:46 -0400
commitdafa724bf582181d9a7d54f5cb4ca0bf8ef29269 (patch)
tree952048cd64778adb6b20056b57912f19ca1eb6a1
parent937fa62e8a00d0b4bc2c0a40567d7c88ab2b2e8d (diff)
dm table: fix missing dm_put_target_type() in dm_table_add_target()
dm_get_target_type() was previously called so any error returned from dm_table_add_target() must first call dm_put_target_type(). Otherwise the DM target module's reference count will leak and the associated kernel module will be unable to be removed. Also, leverage the fact that r is already -EINVAL and remove an extra newline. Fixes: 36a0456 ("dm table: add immutable feature") Fixes: cc6cbe1 ("dm table: add always writeable feature") Fixes: 3791e2f ("dm table: add singleton feature") Cc: stable@vger.kernel.org # 3.2+ Signed-off-by: tang.junhui <tang.junhui@zte.com.cn> Signed-off-by: Mike Snitzer <snitzer@redhat.com>