FreeBSD Bugzilla – Attachment 57684 Details for
Bug 87014
BPF_MTAP/bpf_mtap are not threadsafe and cause panics on SMP systems
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
bpfspin.c
bpfspin.c (text/x-csrc), 3.61 KB, created by
Mark Gooderum
on 2005-10-07 06:03:12 UTC
(
hide
)
Description:
bpfspin.c
Filename:
MIME Type:
Creator:
Mark Gooderum
Created:
2005-10-07 06:03:12 UTC
Size:
3.61 KB
patch
obsolete
>/* > * Test program to open and close a BPF a _lot_. > */ > >#include <errno.h> >#include <string.h> >#include <stdio.h> >#include <stdlib.h> >#include <signal.h> > >#include <sys/types.h> >#include <sys/ioctl.h> >#include <net/bpf.h> >#include <unistd.h> > >#include "pcap.h" > >#define CAP_LEN 100 > >const char *argv0; >const char *iname; > >/* Default to something that won't match anything */ >char *filter = "ip proto 199"; > >pcap_t * >open_bpf(const char *ifname); > >void >close_bpf(pcap_t *pct); > >int debug_level; >int freq = 10; > >int on_sleep; >int off_sleep; >int per_cycle; >int num_cycles = -1; >int quit_flag; > >void >usage(int badopt); > >void >catchsig(int signo); > > >int >main(int argc, char *argv[]) >{ > u_int64_t npass = 0; > const char *estr; > int eno; > pcap_t *pct; > int ch; > > argv0 = strrchr(argv[0], '/'); > if (argv0 == NULL) { > argv0 = argv[0]; > } else { > argv0++; > } > > signal(SIGTERM, catchsig); > signal(SIGHUP, catchsig); > signal(SIGQUIT, catchsig); > signal(SIGINT, catchsig); > > /* > * Args... > */ > while ((ch = getopt(argc, argv, "df:hn:o:")) != -1) { > switch (ch) { > case 'd': > debug_level++; > break; > > case 'f': > freq = atoi(optarg); > break; > > case 'h': > usage(0); > exit(0); > > case 'n': > num_cycles = atoi(optarg); > break; > > case '0': > on_sleep = atoi(optarg); > break; > > default: > usage(optopt); > exit(1); > } > > } > > argc -= optind; > argv += (optind - 1); > > if (argc < 1) { > fprintf(stderr, "Error: <ifname> argument required.\n"); > usage(-1); > } > iname = argv[1]; > > if (freq) { > per_cycle = 1000000 / freq; > off_sleep = per_cycle; > } > if (on_sleep) { > off_sleep = per_cycle - on_sleep; > } > > while (num_cycles) { > pct = open_bpf(iname); > if (pct == NULL) { > eno = errno; > estr = strerror(eno); > if (estr == NULL) { > estr = "<Unknown>"; > } > fprintf(stderr, "Error: open_bpf(%s) failed %d/%s\n", > iname, eno, estr); > exit(3); > } > if (on_sleep) { > usleep(on_sleep); > } > > close_bpf(pct); > if (on_sleep) { > usleep(off_sleep); > } > > if (num_cycles > 0) { > num_cycles--; > } > npass++; > if (quit_flag) { > break; > } > } > printf("Open/Closed bpf on %s %llu times.\n", iname, npass); > exit(0); >} > >pcap_t * >open_bpf(const char *ifname) >{ > pcap_t *pct; > int pfd; > u_int one = 1; > char ebuf[PCAP_ERRBUF_SIZE]; > struct bpf_program dfilter; > u_int32_t network = 0, netmask = 0; > > pct = pcap_open_live(ifname, CAP_LEN, 0, 1000, ebuf); > if (pct == NULL) { > perror("pcap_open_live failed"); > return(NULL); > } > pfd = pcap_get_selectable_fd(pct); > if (ioctl(pfd, BIOCIMMEDIATE, &one) < 0) { > perror("BIOCIMMEDIATE failed"); > pcap_close(pct); > return(NULL); > } >#if 0 > /* Must be needed? */ > if(pcap_lookupnet(ifname, &network, &netmask, 0) < 0) { > perror("pcap_lookupnet failed"); > pcap_close(pct); > return(NULL); > } >#endif > /* Compile the Dummy filter pcap program */ > bzero(&dfilter, sizeof(struct bpf_program)); > if (pcap_compile(pct, &dfilter, filter, 0, netmask) < 0) { > perror("pcap_compile failed"); > pcap_close(pct); > return(NULL); > } > if (pcap_setfilter(pct, &dfilter) < 0) > { > perror("pcap_setfilter failed"); > pcap_close(pct); > return(NULL); > } > return(pct); >} > >void >close_bpf(pcap_t *pct) >{ > pcap_close(pct); >} > > >void >usage(int badopt) >{ > if (badopt > 0) { > fprintf(stderr, "%s: Bad option [-%c]\n", argv0, > (char) badopt); > } > fprintf(stderr, "Usage: %s [-dh] [-f <freq>] <ifname>\n", argv0); > fprintf(stderr, "\t-d\tIncrease debug level by 1\n"); > fprintf(stderr, "\t-f\tSet Flap Freq to <freq>\n"); > fprintf(stderr, "\t-h\tPrint this help\n"); > exit(badopt != 0); >} > >void >catchsig(int signo) >{ > switch (signo) { > case SIGHUP: > case SIGTERM: > case SIGQUIT: > case SIGINT: > quit_flag = 1; > break; > default: > abort(); > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 87014
:
57683
| 57684 |
57685