PERFORCE change 128899 for review
Robert Watson
rwatson at FreeBSD.org
Sat Nov 10 07:44:04 PST 2007
http://perforce.freebsd.org/chv.cgi?CH=128899
Change 128899 by rwatson at rwatson_cinnamon on 2007/11/10 15:43:12
Allow bpfnull to build on systems without zero-copy definitions,
but then necessarily without zero-copy support.
Affected files ...
.. //depot/projects/zcopybpf/utils/bpfnull/bpfnull.c#19 edit
Differences ...
==== //depot/projects/zcopybpf/utils/bpfnull/bpfnull.c#19 (text+ko) ====
@@ -75,6 +75,20 @@
static u_char *bufa, *bufb;
static unsigned long packet_count;
+#ifndef BPF_BUFMODE_ZBUF
+/*
+ * bpfnull uses certain constructs that depend on zero-copy definitions being
+ * present in bpf.h even when running in normal buffer mode. If the system
+ * doesn't have these constructs, define them locally.
+ */
+struct bpf_zbuf {
+ void *bz_bufa;
+ void *bz_bufb;
+ size_t bz_buflen;
+};
+#warning "BPF_BUFMODE_ZBUF not present, building without zero-copy support"
+#endif
+
static int
handle_int(int sig __unused)
{
@@ -189,7 +203,9 @@
(void) fprintf(stderr, "select wakeup\n");
if (n != 0 && !FD_ISSET(fd, &r_set) && vflag)
printf("No timeout and fd is not ready!\n");
+#ifdef BPF_BUFMODE_ZBUF
if (zflag == 0) {
+#endif
c = rdtsc();
n = read(fd, pbuf, bflag);
d = rdtsc();
@@ -203,6 +219,7 @@
bpf_process_packets(&bz, "W");
a = rdtsc();
sum += a - b;
+#ifdef BPF_BUFMODE_ZBUF
} else {
bzha = (struct bpf_zbuf_header *)bufa;
bzhb = (struct bpf_zbuf_header *)bufb;
@@ -242,6 +259,7 @@
bzhb->bzh_user_gen++;
}
}
+#endif
f = rdtsc();
ssum += f - e;
}
@@ -273,6 +291,7 @@
exit(0);
}
+#ifdef BPF_BUFMODE_ZBUF
static int
bpf_zbuf_init(int fd, struct bpf_zbuf *bz)
{
@@ -301,15 +320,18 @@
"DEBUG: bufa=%p bufb=%p\n", bufa, bufb);
return (0);
}
+#endif
static int
bpf_rbuf_init(int fd)
{
int v, bmode;
+#ifdef BPF_BUFMODE_ZBUF
bmode = BPF_BUFMODE_BUFFER;
if (ioctl(fd, BIOCGETBUFMODE, &bmode) < 0)
err(1, "ioctl(BIOCGETBUFMODE)");
+#endif
for (v = bflag; v != 0; v >>= 1) {
(void) ioctl(fd, BIOCSBLEN, &v);
if (ioctl(fd, BIOCSETIF, &ifr) == 0)
@@ -364,9 +386,11 @@
case 'v':
vflag++;
break;
+#ifdef BPF_BUFMODE_ZBUF
case 'z':
zflag++;
break;
+#endif
default:
usage();
}
@@ -386,6 +410,7 @@
(void) fprintf(stderr,
"DEBUG: obtained bpf fd=%d\n", in);
bpf_init_dumpfile();
+#ifdef BPF_BUFMODE_ZBUF
if (zflag) {
if (vflag)
(void) fprintf(stderr,
@@ -395,11 +420,14 @@
if (ioctl(in, BIOCSETIF, &ifr) < 0)
err(1, "ioctl(BIOCSETIF)");
} else {
+#endif
if (vflag)
(void) fprintf(stderr,
"DEBUG: bufmode=buffer\n");
bpf_rbuf_init(in);
+#ifdef BPF_BUFMODE_ZBUF
}
+#endif
if (Iflag) {
if (vflag)
(void) fprintf(stderr,
More information about the p4-projects
mailing list