PERFORCE change 113841 for review
Robert Watson
rwatson at FreeBSD.org
Thu Feb 1 15:52:12 UTC 2007
http://perforce.freebsd.org/chv.cgi?CH=113841
Change 113841 by rwatson at rwatson_cinnamon on 2007/02/01 15:51:33
Update zbuf_tap for shared header in buffers.
Affected files ...
.. //depot/projects/zcopybpf/utils/zbuf_tap/zbuf_tap.c#4 edit
Differences ...
==== //depot/projects/zcopybpf/utils/zbuf_tap/zbuf_tap.c#4 (text+ko) ====
@@ -56,7 +56,9 @@
int
main(int argc, char *argv[])
{
- u_char *bufa, *bufb, *buf;
+ struct bpf_zbuf_header *bzh, *bzha, *bzhb; /* Buffer headers. */
+ u_char *zbufa, *zbufb, *zbuf; /* Mapped pages. */
+ u_char *buf; /* Buffers. */
u_int buflen, maxbuflen;
struct pollfd pollfd;
char name[PATH_MAX];
@@ -67,14 +69,18 @@
buflen = getpagesize() * 2;
- bufa = mmap(NULL, buflen, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0);
- if (bufa == MAP_FAILED)
+ zbufa = mmap(NULL, buflen, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0);
+ if (zbufa == MAP_FAILED)
err(-1, "mmap");
- bufb = mmap(NULL, buflen, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0);
- if (bufb == MAP_FAILED)
+ bzha = (struct bpf_zbuf_header *)zbufa;
+
+ zbufb = mmap(NULL, buflen, PROT_READ | PROT_WRITE, MAP_ANON, -1, 0);
+ if (zbufb == MAP_FAILED)
err(-1, "mmap");
+ bzhb = (struct bpf_zbuf_header *)zbufb;
+
tap_fd = tap_open();
if (tap_fd < 0)
err(-1, "tap_open");
@@ -94,7 +100,7 @@
err(-1, "bpf_getzmax");
printf("zmax: %d\n", maxbuflen);
- if (bpf_setzbuf(bpf_fd, bufa, bufb, buflen) < 0)
+ if (bpf_setzbuf(bpf_fd, zbufa, zbufb, buflen) < 0)
err(-1, "bpf_setzbuf");
if (bpf_setimmediate(bpf_fd, 1) < 0)
@@ -113,11 +119,25 @@
* Exercise various poll mechanisms to see which say
* something is ready to read.
*/
- if (bpf_getznext(bpf_fd, (void **)&buf, &buflen) < 0)
+ if (bpf_getznext(bpf_fd, (void **)&zbuf, &buflen) < 0)
err(-1, "bpf_getznext");
- printf("bpf_getznext returned (0x%x, %d)\n", (uintptr_t)buf,
+ printf("bpf_getznext returned (0x%x, %d)\n", (uintptr_t)zbuf,
buflen);
+ if (zbuf != NULL) {
+ bzh = (struct bpf_zbuf_header *)zbuf;
+ if (bzh == bzha)
+ printf("Buffer A is next\n");
+ else if (bzh == bzhb)
+ printf("Buffer B is next\n");
+ else
+ errx(-1, "getznext unrecognized buffer");
+ buf = (u_char *)(bzh + 1);
+ } else {
+ bzh = NULL;
+ buf = NULL;
+ }
+
if (ioctl(bpf_fd, FIONREAD, &i) < 0)
err(-1, "ioctl(FIONREAD)");
printf("FIONREAD returned %d\n", i);
@@ -146,8 +166,8 @@
else
printf("select returned not readable\n");
- if (buf != NULL) {
- if (bpf_ackzbuf(bpf_fd, buf, buflen) < 0)
+ if (zbuf != NULL) {
+ if (bpf_ackzbuf(bpf_fd, zbuf, buflen) < 0)
err(-1, "bpf_ackzbuf(0x%x, %d)",
(uintptr_t)buf, buflen);
}
More information about the p4-projects
mailing list