From owner-p4-projects@FreeBSD.ORG Mon Dec 24 23:05:47 2007 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 93D4F16A41B; Mon, 24 Dec 2007 23:05:47 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C805C16A419 for ; Mon, 24 Dec 2007 23:05:46 +0000 (UTC) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id B310213C448 for ; Mon, 24 Dec 2007 23:05:46 +0000 (UTC) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id lBON5kP1045114 for ; Mon, 24 Dec 2007 23:05:46 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id lBON5k4g045111 for perforce@freebsd.org; Mon, 24 Dec 2007 23:05:46 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Date: Mon, 24 Dec 2007 23:05:46 GMT Message-Id: <200712242305.lBON5k4g045111@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to bb+lists.freebsd.perforce@cyrus.watson.org using -f From: Robert Watson To: Perforce Change Reviews Cc: Subject: PERFORCE change 131558 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 24 Dec 2007 23:05:48 -0000 http://perforce.freebsd.org/chv.cgi?CH=131558 Change 131558 by rwatson@rwatson_cinnamon on 2007/12/24 23:04:49 Fix up commenting, ifdef'ing, and indentation a bit. Affected files ... .. //depot/projects/zcopybpf/src/contrib/libpcap/pcap-bpf.c#18 edit Differences ... ==== //depot/projects/zcopybpf/src/contrib/libpcap/pcap-bpf.c#18 (text+ko) ==== @@ -39,8 +39,6 @@ #include #include -#include - #include #ifdef _AIX @@ -90,6 +88,10 @@ #endif /* _AIX */ +#ifdef BIOCSETBUFMODE +#include +#endif + #include #include #include @@ -156,10 +158,6 @@ { struct bpf_zbuf_header *bzh; - /* - * If we've never used a buffer before, or if the last buffer was - * zbuf2, try zbuf1. - */ if (p->zbuffer == p->zbuf2 || p->zbuffer == NULL) { bzh = (struct bpf_zbuf_header *)p->zbuf1; if (bzh->bzh_user_gen != @@ -243,13 +241,13 @@ "BIOCROTZBUF: %s", strerror(errno)); return (-1); } - - /* - * Last chance for data. - */ return (pcap_next_zbuf_shm(p, cc)); } +/* + * Notify kernel that we are done with the buffer. We don't reset zbuffer so + * that we know which buffer to use next time around. + */ static int pcap_ack_zbuf(pcap_t *p) { @@ -795,15 +793,12 @@ goto bad; } +#ifdef BIOCSETBUFMODE /* - * XXXRW: Depending on the availability of zero-copy BPF, we take one - * of two strategies here: if it is available and usable, we go ahead - * and set it up; otherwise we play the song-and-dance to try to - * probe an acceptable read buffer size. Zero-copy BPF requires that - * buffers be mapped into memory before selecting the interface to - * attach to, so we do that here also. + * If the BPF extension to set buffer mode is present, try setting + * the mode to zero-copy. If that fails, use regular buffering. If + * it succeeds but other setup fails, return an error to the user. */ -#ifdef BIOCSETBUFMODE bufmode = BPF_BUFMODE_ZBUF; if (ioctl(fd, BIOCSETBUFMODE, (caddr_t)&bufmode) == 0) { p->zerocopy = 1; @@ -812,14 +807,9 @@ pcap_strerror(errno)); goto bad; } - - /* - * XXXRW: This logic should be revisited. - */ p->zbufsize = 32768; if (p->zbufsize > zbufmax) p->zbufsize = zbufmax; - p->zbuf1 = mmap(NULL, p->zbufsize, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0); p->zbuf2 = mmap(NULL, p->zbufsize, PROT_READ | PROT_WRITE, @@ -829,18 +819,15 @@ pcap_strerror(errno)); goto bad; } - bzero(&bz, sizeof(bz)); bz.bz_bufa = p->zbuf1; bz.bz_bufb = p->zbuf2; bz.bz_buflen = p->zbufsize; - if (ioctl(fd, BIOCSETZBUF, (caddr_t)&bz) < 0) { snprintf(ebuf, PCAP_ERRBUF_SIZE, "BIOCSETZBUF: %s", pcap_strerror(errno)); goto bad; } - (void)strncpy(ifr.ifr_name, device, sizeof(ifr.ifr_name)); if (ioctl(fd, BIOCSETIF, (caddr_t)&ifr) < 0) { snprintf(ebuf, PCAP_ERRBUF_SIZE, "BIOCSETIF: %s: %s", @@ -852,41 +839,43 @@ } else { #endif - /* - * Try finding a good size for the buffer; 32768 may be too - * big, so keep cutting it in half until we find a size - * that works, or run out of sizes to try. If the default - * is larger, don't make it smaller. - * - * XXX - there should be a user-accessible hook to set the - * initial buffer size. - */ - if ((ioctl(fd, BIOCGBLEN, (caddr_t)&v) < 0) || v < 32768) - v = 32768; - for ( ; v != 0; v >>= 1) { - /* Ignore the return value - this is because the call fails - * on BPF systems that don't have kernel malloc. And if - * the call fails, it's no big deal, we just continue to - * use the standard buffer size. + /* + * Try finding a good size for the buffer; 32768 may be too + * big, so keep cutting it in half until we find a size + * that works, or run out of sizes to try. If the default + * is larger, don't make it smaller. + * + * XXX - there should be a user-accessible hook to set the + * initial buffer size. */ - (void) ioctl(fd, BIOCSBLEN, (caddr_t)&v); + if ((ioctl(fd, BIOCGBLEN, (caddr_t)&v) < 0) || v < 32768) + v = 32768; + for ( ; v != 0; v >>= 1) { + /* Ignore the return value - this is because the call + * fails on BPF systems that don't have kernel + * malloc. And if the call fails, it's no big deal, + * we just continue to use the standard buffer size. + */ + (void) ioctl(fd, BIOCSBLEN, (caddr_t)&v); + + (void)strncpy(ifr.ifr_name, device, + sizeof(ifr.ifr_name)); + if (ioctl(fd, BIOCSETIF, (caddr_t)&ifr) >= 0) + break; /* that size worked; we're done */ - (void)strncpy(ifr.ifr_name, device, sizeof(ifr.ifr_name)); - if (ioctl(fd, BIOCSETIF, (caddr_t)&ifr) >= 0) - break; /* that size worked; we're done */ + if (errno != ENOBUFS) { + snprintf(ebuf, PCAP_ERRBUF_SIZE, + "BIOCSETIF: %s: %s", + device, pcap_strerror(errno)); + goto bad; + } + } - if (errno != ENOBUFS) { - snprintf(ebuf, PCAP_ERRBUF_SIZE, "BIOCSETIF: %s: %s", - device, pcap_strerror(errno)); + if (v == 0) { + snprintf(ebuf, PCAP_ERRBUF_SIZE, + "BIOCSBLEN: %s: No buffer size worked", device); goto bad; } - } - - if (v == 0) { - snprintf(ebuf, PCAP_ERRBUF_SIZE, - "BIOCSBLEN: %s: No buffer size worked", device); - goto bad; - } #ifdef BIOCSETBUFMODE } #endif