@pcap.c

int
pcap_inject(pcap_t *p, const void *buf, size_t size)
{
        struct my_ring *me = p;
        u_int si;
 
        ND("cnt %d", cnt);
        /* scan all rings */
        for (si = me->begin; si < me->end; si++) {
                struct netmap_ring *ring = NETMAP_TXRING(me->nifp, si);
 
                ND("ring has %d pkts", ring->avail);
                if (ring->avail == 0)
                        continue;
                u_int i = ring->cur;
                u_int idx = ring->slot[i].buf_idx;
                if (idx < 2) {
                        D("%s bogus TX index %d at offset %d",
                                me->nifp->ni_name, idx, i);
                        sleep(2);
                }
                u_char *dst = (u_char *)NETMAP_BUF(ring, idx);
                ring->slot[i].len = size;
                pkt_copy(buf, dst, size);
                ring->cur = NETMAP_RING_NEXT(ring, i);
                ring->avail--;
                return size;
        }
        errno = ENOBUFS;
        return -1;
}

i call this fun, packet can 't send out my host.

@pkt-gen.c
static int
send_packets(struct netmap_ring *ring, struct pkt *pkt, 
                int size, u_int count, int options)
{
        u_int sent, cur = ring->cur;

        if (ring->avail < count)
                count = ring->avail;

        for (sent = 0; sent < count; sent++) {
                struct netmap_slot *slot = &ring->slot[cur];
                char *p = NETMAP_BUF(ring, slot->buf_idx);

                if (options & OPT_COPY)
                        pkt_copy(pkt, p, size);
                else if (options & OPT_MEMCPY)
                        memcpy(p, pkt, size);
                else if (options & OPT_PREFETCH)
                        prefetch(p);

                slot->len = size;
                if (sent == count - 1)
                        slot->flags |= NS_REPORT;
                cur = NETMAP_RING_NEXT(ring, cur);
        }
        ring->avail -= sent;
        ring->cur = cur;

        return (sent);
}

code like this
if (sent == count - 1)
        slot->flags |= NS_REPORT;

add  code to pcap_inject

if (ring->avail == 0) ioctl(me->fd, NIOCTXSYNC, NULL);

packet can send ,but send too slowly!

have any good idea to be change this?
_______________________________________________
freebsd-current@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to "freebsd-current-unsubscr...@freebsd.org"

Reply via email to