diff options
Diffstat (limited to 'ring_rx.c')
-rw-r--r-- | ring_rx.c | 43 |
1 files changed, 6 insertions, 37 deletions
@@ -43,9 +43,11 @@ void setup_rx_ring_layout(int sock, struct ring *ring, unsigned int size, 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 * @@ -77,6 +79,7 @@ void create_rx_ring(int sock, struct ring *ring, int verbose) retry: ret = setsockopt(sock, SOL_PACKET, PACKET_RX_RING, &ring->raw, v3 ? sizeof(ring->layout3) : 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 / @@ -98,49 +101,15 @@ retry: void mmap_rx_ring(int sock, struct ring *ring) { - ring->mm_space = mmap(0, ring->mm_len, PROT_READ | PROT_WRITE, - MAP_SHARED | MAP_LOCKED | MAP_POPULATE, sock, 0); - if (ring->mm_space == MAP_FAILED) { - destroy_rx_ring(sock, ring); - panic("Cannot mmap RX_RING!\n"); - } + mmap_ring_generic(sock, ring); } void alloc_rx_ring_frames(struct ring *ring) { - int i; - size_t len = ring->layout.tp_frame_nr * sizeof(*ring->frames); - - ring->frames = xmalloc_aligned(len, CO_CACHE_LINE_SIZE); - fmemset(ring->frames, 0, len); - - for (i = 0; i < ring->layout.tp_frame_nr; ++i) { - ring->frames[i].iov_len = ring->layout.tp_frame_size; - ring->frames[i].iov_base = ring->mm_space + - (i * ring->layout.tp_frame_size); - } + alloc_ring_frames_generic(ring); } void bind_rx_ring(int sock, struct ring *ring, int ifindex) { - int ret; - /* - * The 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_protocol = htons(ETH_P_ALL); - ring->s_ll.sll_ifindex = ifindex; - ring->s_ll.sll_hatype = 0; - ring->s_ll.sll_halen = 0; - ring->s_ll.sll_pkttype = 0; - - ret = bind(sock, (struct sockaddr *) &ring->s_ll, sizeof(ring->s_ll)); - if (ret < 0) { - destroy_rx_ring(sock, ring); - panic("Cannot bind RX_RING!\n"); - } + bind_ring_generic(sock, ring, ifindex); } |