/* * 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" static 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); } static void setup_tx_ring_layout(int sock, 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 = ring->layout.tp_block_size / ring->layout.tp_frame_size * ring->layout.tp_block_nr; set_sockopt_tpacket_v2(sock); ring_verify_layout(ring); } static void create_tx_ring(int sock, struct ring *ring, bool 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 = (size_t) ring->layout.tp_block_size * ring->layout.tp_block_nr; if (verbose) { printf("TX,V2: %.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); } } static 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 ring_tx_setup(struct ring *ring, int sock, size_t size, int ifindex, bool jumbo_support, bool verbose) { fmemset(ring, 0, sizeof(*ring)); set_packet_loss_discard(sock); setup_tx_ring_layout(sock, ring, size, jumbo_support); create_tx_ring(sock, ring, verbose); mmap_ring_generic(sock, ring); alloc_tx_ring_frames(sock, ring); bind_ring_generic(sock, ring, ifindex, true); } h'/>
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2016-12-14 11:01:00 -0800
committerLinus Torvalds <torvalds@linux-foundation.org>2016-12-14 11:01:00 -0800
commit775a2e29c3bbcf853432f47d3caa9ff8808807ad (patch)
tree614a7481b68dc9b0b628f392ab9bbdc53bbfe447 /Documentation/men-chameleon-bus.txt
parent2a4c32edd39b7de166e723b1991abcde4db3a701 (diff)
parentef548c551e72dbbdcc6d9ed7c7b3b01083fea8e2 (diff)
Merge tag 'dm-4.10-changes' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm
Pull device mapper updates from Mike Snitzer: - various fixes and improvements to request-based DM and DM multipath - some locking improvements in DM bufio - add Kconfig option to disable the DM block manager's extra locking which mainly serves as a developer tool - a few bug fixes to DM's persistent-data - a couple changes to prepare for multipage biovec support in the block layer - various improvements and cleanups in the DM core, DM cache, DM raid and DM crypt - add ability to have DM crypt use keys from the kernel key retention service - add a new "error_writes" feature to the DM flakey target, reads are left unchanged in this mode * tag 'dm-4.10-changes' of git://git.kernel.org/pub/scm/linux/kernel/git/device-mapper/linux-dm: (40 commits) dm flakey: introduce "error_writes" feature dm cache policy smq: use hash_32() instead of hash_32_generic() dm crypt: reject key strings containing whitespace chars dm space map: always set ev if sm_ll_mutate() succeeds dm space map metadata: skip useless memcpy in metadata_ll_init_index() dm space map metadata: fix 'struct sm_metadata' leak on failed create Documentation: dm raid: define data_offset status field dm raid: fix discard support regression dm raid: don't allow "write behind" with raid4/5/6 dm mpath: use hw_handler_params if attached hw_handler is same as requested dm crypt: add ability to use keys from the kernel key retention service dm array: remove a dead assignment in populate_ablock_with_values() dm ioctl: use offsetof() instead of open-coding it dm rq: simplify use_blk_mq initialization dm: use blk_set_queue_dying() in __dm_destroy() dm bufio: drop the lock when doing GFP_NOIO allocation dm bufio: don't take the lock in dm_bufio_shrink_count dm bufio: avoid sleeping while holding the dm_bufio lock dm table: simplify dm_table_determine_type() dm table: an 'all_blk_mq' table must be loaded for a blk-mq DM device ...
Diffstat (limited to 'Documentation/men-chameleon-bus.txt')