From owner-freebsd-current@FreeBSD.ORG Wed May 30 15:39:56 2012 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 6846E106566C for ; Wed, 30 May 2012 15:39:56 +0000 (UTC) (envelope-from luigi@onelab2.iet.unipi.it) Received: from onelab2.iet.unipi.it (onelab2.iet.unipi.it [131.114.59.238]) by mx1.freebsd.org (Postfix) with ESMTP id 26D9E8FC15 for ; Wed, 30 May 2012 15:39:56 +0000 (UTC) Received: by onelab2.iet.unipi.it (Postfix, from userid 275) id 59CC37300A; Wed, 30 May 2012 18:00:30 +0200 (CEST) Date: Wed, 30 May 2012 18:00:30 +0200 From: rizzo To: "root@9du.org" Message-ID: <20120530160030.GA61877@onelab2.iet.unipi.it> References: <20120530120027.2CDAF1065678@hub.freebsd.org> <201205302331315153849@9du.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <201205302331315153849@9du.org> User-Agent: Mutt/1.4.2.3i Cc: freebsd-current Subject: Re: about netmap libpcap pcap_inject X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 30 May 2012 15:39:56 -0000 On Wed, May 30, 2012 at 11:31:36PM +0800, root@9du.org wrote: > @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. the packet go out when you issue an ioctl or poll/select on the netmap file descriptor. Many libpcap apps do that implicitly because they run around an event loop, but if yours does not then you need to insert the call yourself, either as you did in the example below (the NS_REPORT is not necessary), or as part of your normal processing loop when you perhaps are blocking to check for other file descriptors. cheers luigi > @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?