|
Lines 32-37
Link Here
|
| 32 |
#include <sys/snoop.h> |
32 |
#include <sys/snoop.h> |
| 33 |
#include <sys/vnode.h> |
33 |
#include <sys/vnode.h> |
| 34 |
|
34 |
|
|
|
35 |
MALLOC_DEFINE(M_SNP, "snp", "Snoop Interface"); |
| 36 |
|
| 35 |
static d_open_t snpopen; |
37 |
static d_open_t snpopen; |
| 36 |
static d_close_t snpclose; |
38 |
static d_close_t snpclose; |
| 37 |
static d_read_t snpread; |
39 |
static d_read_t snpread; |
|
Lines 62-69
Link Here
|
| 62 |
#define MIN(a,b) (((a)<(b))?(a):(b)) |
64 |
#define MIN(a,b) (((a)<(b))?(a):(b)) |
| 63 |
#endif |
65 |
#endif |
| 64 |
|
66 |
|
| 65 |
static struct snoop snoopsw[NSNP]; |
|
|
| 66 |
|
| 67 |
static struct tty *snpdevtotty __P((dev_t dev)); |
67 |
static struct tty *snpdevtotty __P((dev_t dev)); |
| 68 |
static int snp_detach __P((struct snoop *snp)); |
68 |
static int snp_detach __P((struct snoop *snp)); |
| 69 |
|
69 |
|
|
Lines 90-97
Link Here
|
| 90 |
struct uio *uio; |
90 |
struct uio *uio; |
| 91 |
int flag; |
91 |
int flag; |
| 92 |
{ |
92 |
{ |
| 93 |
int unit = minor(dev), len, i, error; |
93 |
int len, i, error; |
| 94 |
struct snoop *snp = &snoopsw[unit]; |
94 |
struct snoop *snp = dev->si_drv1; |
| 95 |
struct tty *tp; |
95 |
struct tty *tp; |
| 96 |
char c[SNP_INPUT_BUF]; |
96 |
char c[SNP_INPUT_BUF]; |
| 97 |
|
97 |
|
|
Lines 131-138
Link Here
|
| 131 |
struct uio *uio; |
131 |
struct uio *uio; |
| 132 |
int flag; |
132 |
int flag; |
| 133 |
{ |
133 |
{ |
| 134 |
int unit = minor(dev), s; |
134 |
int s; |
| 135 |
struct snoop *snp = &snoopsw[unit]; |
135 |
struct snoop *snp = dev->si_drv1; |
| 136 |
int len, n, nblen, error = 0; |
136 |
int len, n, nblen, error = 0; |
| 137 |
caddr_t from; |
137 |
caddr_t from; |
| 138 |
char *nbuf; |
138 |
char *nbuf; |
|
Lines 174-182
Link Here
|
| 174 |
if (((nblen / 2) >= SNOOP_MINLEN) && (nblen / 2) >= snp->snp_len) { |
174 |
if (((nblen / 2) >= SNOOP_MINLEN) && (nblen / 2) >= snp->snp_len) { |
| 175 |
while (((nblen / 2) >= snp->snp_len) && ((nblen / 2) >= SNOOP_MINLEN)) |
175 |
while (((nblen / 2) >= snp->snp_len) && ((nblen / 2) >= SNOOP_MINLEN)) |
| 176 |
nblen = nblen / 2; |
176 |
nblen = nblen / 2; |
| 177 |
if ((nbuf = malloc(nblen, M_TTYS, M_NOWAIT)) != NULL) { |
177 |
if ((nbuf = malloc(nblen, M_SNP, M_NOWAIT)) != NULL) { |
| 178 |
bcopy(snp->snp_buf + snp->snp_base, nbuf, snp->snp_len); |
178 |
bcopy(snp->snp_buf + snp->snp_base, nbuf, snp->snp_len); |
| 179 |
free(snp->snp_buf, M_TTYS); |
179 |
free(snp->snp_buf, M_SNP); |
| 180 |
snp->snp_buf = nbuf; |
180 |
snp->snp_buf = nbuf; |
| 181 |
snp->snp_blen = nblen; |
181 |
snp->snp_blen = nblen; |
| 182 |
snp->snp_base = 0; |
182 |
snp->snp_base = 0; |
|
Lines 213-224
Link Here
|
| 213 |
if (n == 0) |
213 |
if (n == 0) |
| 214 |
return 0; |
214 |
return 0; |
| 215 |
|
215 |
|
| 216 |
#ifdef DIAGNOSTIC |
|
|
| 217 |
if (!(snp->snp_flags & SNOOP_OPEN)) { |
| 218 |
printf("Snoop: data coming to closed device.\n"); |
| 219 |
return 0; |
| 220 |
} |
| 221 |
#endif |
| 222 |
if (snp->snp_flags & SNOOP_DOWN) { |
216 |
if (snp->snp_flags & SNOOP_DOWN) { |
| 223 |
printf("Snoop: more data to down interface.\n"); |
217 |
printf("Snoop: more data to down interface.\n"); |
| 224 |
return 0; |
218 |
return 0; |
|
Lines 246-254
Link Here
|
| 246 |
nblen = snp->snp_blen * 2; |
240 |
nblen = snp->snp_blen * 2; |
| 247 |
s_free = nblen - (snp->snp_len + snp->snp_base); |
241 |
s_free = nblen - (snp->snp_len + snp->snp_base); |
| 248 |
} |
242 |
} |
| 249 |
if ((n <= s_free) && (nbuf = malloc(nblen, M_TTYS, M_NOWAIT))) { |
243 |
if ((n <= s_free) && (nbuf = malloc(nblen, M_SNP, M_NOWAIT))) { |
| 250 |
bcopy(snp->snp_buf + snp->snp_base, nbuf, snp->snp_len); |
244 |
bcopy(snp->snp_buf + snp->snp_base, nbuf, snp->snp_len); |
| 251 |
free(snp->snp_buf, M_TTYS); |
245 |
free(snp->snp_buf, M_SNP); |
| 252 |
snp->snp_buf = nbuf; |
246 |
snp->snp_buf = nbuf; |
| 253 |
snp->snp_blen = nblen; |
247 |
snp->snp_blen = nblen; |
| 254 |
snp->snp_base = 0; |
248 |
snp->snp_base = 0; |
|
Lines 291-316
Link Here
|
| 291 |
struct proc *p; |
285 |
struct proc *p; |
| 292 |
{ |
286 |
{ |
| 293 |
struct snoop *snp; |
287 |
struct snoop *snp; |
| 294 |
register int unit, error; |
288 |
register int error; |
| 295 |
|
289 |
|
| 296 |
if ((error = suser(p)) != 0) |
290 |
if ((error = suser(p)) != 0) |
| 297 |
return (error); |
291 |
return (error); |
| 298 |
|
292 |
|
| 299 |
if ((unit = minor(dev)) >= NSNP) |
293 |
snp = dev->si_drv1; |
| 300 |
return (ENXIO); |
|
|
| 301 |
|
294 |
|
| 302 |
snp = &snoopsw[unit]; |
295 |
if (snp) |
|
|
296 |
return (EBUSY); |
| 303 |
|
297 |
|
| 304 |
if (snp->snp_flags & SNOOP_OPEN) |
298 |
make_dev(&snp_cdevsw, minor(dev), 0, 0, 0600, "bpf%d", lminor(dev)); |
| 305 |
return (ENXIO); |
299 |
MALLOC(snp, struct snoop *, sizeof(*snp), M_SNP, M_WAITOK); |
|
|
300 |
bzero(snp, sizeof(*snp)); |
| 301 |
dev->si_drv1 = snp; |
| 306 |
|
302 |
|
| 307 |
/* |
303 |
snp->snp_buf = malloc(SNOOP_MINLEN, M_SNP, M_WAITOK); |
| 308 |
* We intentionally do not OR flags with SNOOP_OPEN,but set them so |
|
|
| 309 |
* all previous settings (especially SNOOP_OFLOW) will be cleared. |
| 310 |
*/ |
| 311 |
snp->snp_flags = SNOOP_OPEN; |
| 312 |
|
| 313 |
snp->snp_buf = malloc(SNOOP_MINLEN, M_TTYS, M_WAITOK); |
| 314 |
snp->snp_blen = SNOOP_MINLEN; |
304 |
snp->snp_blen = SNOOP_MINLEN; |
| 315 |
snp->snp_base = 0; |
305 |
snp->snp_base = 0; |
| 316 |
snp->snp_len = 0; |
306 |
snp->snp_len = 0; |
|
Lines 367-380
Link Here
|
| 367 |
int fmt; |
357 |
int fmt; |
| 368 |
struct proc *p; |
358 |
struct proc *p; |
| 369 |
{ |
359 |
{ |
| 370 |
register int unit = minor(dev); |
360 |
int error; |
| 371 |
struct snoop *snp = &snoopsw[unit]; |
361 |
struct snoop *snp = dev->si_drv1; |
| 372 |
|
362 |
|
| 373 |
snp->snp_blen = 0; |
363 |
free(snp->snp_buf, M_SNP); |
| 374 |
free(snp->snp_buf, M_TTYS); |
364 |
error = snp_detach(snp); |
| 375 |
snp->snp_flags &= ~SNOOP_OPEN; |
365 |
FREE(snp, M_SNP); |
|
|
366 |
dev->si_drv1 = 0; |
| 376 |
|
367 |
|
| 377 |
return (snp_detach(snp)); |
368 |
return (error); |
| 378 |
} |
369 |
} |
| 379 |
|
370 |
|
| 380 |
int |
371 |
int |
|
Lines 382-389
Link Here
|
| 382 |
struct snoop *snp; |
373 |
struct snoop *snp; |
| 383 |
{ |
374 |
{ |
| 384 |
snp->snp_blen = SNOOP_MINLEN; |
375 |
snp->snp_blen = SNOOP_MINLEN; |
| 385 |
free(snp->snp_buf, M_TTYS); |
376 |
free(snp->snp_buf, M_SNP); |
| 386 |
snp->snp_buf = malloc(SNOOP_MINLEN, M_TTYS, M_WAITOK); |
377 |
snp->snp_buf = malloc(SNOOP_MINLEN, M_SNP, M_WAITOK); |
| 387 |
snp->snp_flags |= SNOOP_DOWN; |
378 |
snp->snp_flags |= SNOOP_DOWN; |
| 388 |
|
379 |
|
| 389 |
return (snp_detach(snp)); |
380 |
return (snp_detach(snp)); |
|
Lines 398-406
Link Here
|
| 398 |
int flags; |
389 |
int flags; |
| 399 |
struct proc *p; |
390 |
struct proc *p; |
| 400 |
{ |
391 |
{ |
| 401 |
int unit = minor(dev), s; |
392 |
int s; |
| 402 |
dev_t tdev; |
393 |
dev_t tdev; |
| 403 |
struct snoop *snp = &snoopsw[unit]; |
394 |
struct snoop *snp = dev->si_drv1; |
| 404 |
struct tty *tp, *tpo; |
395 |
struct tty *tp, *tpo; |
| 405 |
|
396 |
|
| 406 |
switch (cmd) { |
397 |
switch (cmd) { |
|
Lines 489-496
Link Here
|
| 489 |
int events; |
480 |
int events; |
| 490 |
struct proc *p; |
481 |
struct proc *p; |
| 491 |
{ |
482 |
{ |
| 492 |
int unit = minor(dev); |
483 |
struct snoop *snp = dev->si_drv1; |
| 493 |
struct snoop *snp = &snoopsw[unit]; |
|
|
| 494 |
int revents = 0; |
484 |
int revents = 0; |
| 495 |
|
485 |
|
| 496 |
|
486 |
|
|
Lines 514-523
Link Here
|
| 514 |
snp_drvinit(unused) |
504 |
snp_drvinit(unused) |
| 515 |
void *unused; |
505 |
void *unused; |
| 516 |
{ |
506 |
{ |
| 517 |
int i; |
|
|
| 518 |
|
507 |
|
| 519 |
for (i = 0; i < NSNP; i++) |
508 |
cdevsw_add(&snp_cdevsw); |
| 520 |
make_dev(&snp_cdevsw, i, 0, 0, 0600, "snp%d", i); |
|
|
| 521 |
} |
509 |
} |
| 522 |
|
510 |
|
| 523 |
SYSINIT(snpdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,snp_drvinit,NULL) |
511 |
SYSINIT(snpdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,snp_drvinit,NULL) |