Lines Matching defs:ring
16 * ring.c - packet ring buffer functions
28 #include "ring.h"
50 struct packet_ring *ring = &tunnel->ring;
51 ring->numblocks = TP_NUM_BLOCKS;
53 int total_frames = TP_FRAMES * ring->numblocks;
58 .tp_block_nr = ring->numblocks, // Number of blocks.
67 size_t buflen = TP_BLOCK_SIZE * ring->numblocks;
68 ring->base = mmap(NULL, buflen, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_LOCKED|MAP_POPULATE,
70 if (ring->base == MAP_FAILED) {
75 ring->block = 0;
76 ring->slot = 0;
77 ring->numslots = TP_BLOCK_SIZE / TP_FRAME_SIZE;
78 ring->next = (struct tpacket2_hdr *) ring->base;
80 logmsg(ANDROID_LOG_INFO, "Using ring buffer with %d frames (%d bytes) at %p",
81 total_frames, buflen, ring->base);
87 * advances to the next position in the packet ring
88 * ring - packet ring buffer
90 static struct tpacket2_hdr* ring_advance(struct packet_ring *ring) {
91 uint8_t *next = (uint8_t *) ring->next;
93 ring->slot++;
96 if (ring->slot == ring->numslots) {
97 ring->slot = 0;
98 ring->block++;
100 if (ring->block < ring->numblocks) {
103 ring->block = 0;
104 next = (uint8_t *) ring->base;
108 ring->next = (struct tpacket2_hdr *) next;
109 return ring->next;
113 * reads a packet from the ring buffer and translates it
118 void ring_read(struct packet_ring *ring, int write_fd, int to_ipv6) {
119 struct tpacket2_hdr *tp = ring->next;
124 tp = ring_advance(ring);