]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/man/man4/bpf.4
This commit was generated by cvs2svn to compensate for changes in r149245,
[FreeBSD/FreeBSD.git] / share / man / man4 / bpf.4
1 .\" Copyright (c) 1990 The Regents of the University of California.
2 .\" All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that: (1) source code distributions
6 .\" retain the above copyright notice and this paragraph in its entirety, (2)
7 .\" distributions including binary code include the above copyright notice and
8 .\" this paragraph in its entirety in the documentation or other materials
9 .\" provided with the distribution, and (3) all advertising materials mentioning
10 .\" features or use of this software display the following acknowledgement:
11 .\" ``This product includes software developed by the University of California,
12 .\" Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
13 .\" the University nor the names of its contributors may be used to endorse
14 .\" or promote products derived from this software without specific prior
15 .\" written permission.
16 .\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
17 .\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
18 .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 .\"
20 .\" This document is derived in part from the enet man page (enet.4)
21 .\" distributed with 4.3BSD Unix.
22 .\"
23 .\" $FreeBSD$
24 .\"
25 .Dd January 16, 1996
26 .Dt BPF 4
27 .Os
28 .Sh NAME
29 .Nm bpf
30 .Nd Berkeley Packet Filter
31 .Sh SYNOPSIS
32 .Cd device bpf
33 .Sh DESCRIPTION
34 The Berkeley Packet Filter
35 provides a raw interface to data link layers in a protocol
36 independent fashion.
37 All packets on the network, even those destined for other hosts,
38 are accessible through this mechanism.
39 .Pp
40 The packet filter appears as a character special device,
41 .Pa /dev/bpf0 ,
42 .Pa /dev/bpf1 ,
43 etc.
44 After opening the device, the file descriptor must be bound to a
45 specific network interface with the
46 .Dv BIOCSETIF
47 ioctl.
48 A given interface can be shared by multiple listeners, and the filter
49 underlying each descriptor will see an identical packet stream.
50 .Pp
51 A separate device file is required for each minor device.
52 If a file is in use, the open will fail and
53 .Va errno
54 will be set to
55 .Er EBUSY .
56 .Pp
57 Associated with each open instance of a
58 .Nm
59 file is a user-settable packet filter.
60 Whenever a packet is received by an interface,
61 all file descriptors listening on that interface apply their filter.
62 Each descriptor that accepts the packet receives its own copy.
63 .Pp
64 Reads from these files return the next group of packets
65 that have matched the filter.
66 To improve performance, the buffer passed to read must be
67 the same size as the buffers used internally by
68 .Nm .
69 This size is returned by the
70 .Dv BIOCGBLEN
71 ioctl (see below), and
72 can be set with
73 .Dv BIOCSBLEN .
74 Note that an individual packet larger than this size is necessarily
75 truncated.
76 .Pp
77 The packet filter will support any link level protocol that has fixed length
78 headers.
79 Currently, only Ethernet,
80 .Tn SLIP ,
81 and
82 .Tn PPP
83 drivers have been modified to interact with
84 .Nm .
85 .Pp
86 Since packet data is in network byte order, applications should use the
87 .Xr byteorder 3
88 macros to extract multi-byte values.
89 .Pp
90 A packet can be sent out on the network by writing to a
91 .Nm
92 file descriptor.
93 The writes are unbuffered, meaning only one packet can be processed per write.
94 Currently, only writes to Ethernets and
95 .Tn SLIP
96 links are supported.
97 .Sh IOCTLS
98 The
99 .Xr ioctl 2
100 command codes below are defined in
101 .In net/bpf.h .
102 All commands require
103 these includes:
104 .Bd -literal
105         #include <sys/types.h>
106         #include <sys/time.h>
107         #include <sys/ioctl.h>
108         #include <net/bpf.h>
109 .Ed
110 .Pp
111 Additionally,
112 .Dv BIOCGETIF
113 and
114 .Dv BIOCSETIF
115 require
116 .In sys/socket.h
117 and
118 .In net/if.h .
119 .Pp
120 In addition to
121 .Dv FIONREAD
122 and
123 .Dv SIOCGIFADDR ,
124 the following commands may be applied to any open
125 .Nm
126 file.
127 The (third) argument to
128 .Xr ioctl 2
129 should be a pointer to the type indicated.
130 .Bl -tag -width BIOCGRTIMEOUT
131 .It Dv BIOCGBLEN
132 .Pq Li u_int
133 Returns the required buffer length for reads on
134 .Nm
135 files.
136 .It Dv BIOCSBLEN
137 .Pq Li u_int
138 Sets the buffer length for reads on
139 .Nm
140 files.
141 The buffer must be set before the file is attached to an interface
142 with
143 .Dv BIOCSETIF .
144 If the requested buffer size cannot be accommodated, the closest
145 allowable size will be set and returned in the argument.
146 A read call will result in
147 .Er EIO
148 if it is passed a buffer that is not this size.
149 .It Dv BIOCGDLT
150 .Pq Li u_int
151 Returns the type of the data link layer underlying the attached interface.
152 .Er EINVAL
153 is returned if no interface has been specified.
154 The device types, prefixed with
155 .Dq Li DLT_ ,
156 are defined in
157 .In net/bpf.h .
158 .It Dv BIOCPROMISC
159 Forces the interface into promiscuous mode.
160 All packets, not just those destined for the local host, are processed.
161 Since more than one file can be listening on a given interface,
162 a listener that opened its interface non-promiscuously may receive
163 packets promiscuously.
164 This problem can be remedied with an appropriate filter.
165 .It Dv BIOCFLUSH
166 Flushes the buffer of incoming packets,
167 and resets the statistics that are returned by BIOCGSTATS.
168 .It Dv BIOCGETIF
169 .Pq Li "struct ifreq"
170 Returns the name of the hardware interface that the file is listening on.
171 The name is returned in the ifr_name field of
172 the
173 .Li ifreq
174 structure.
175 All other fields are undefined.
176 .It Dv BIOCSETIF
177 .Pq Li "struct ifreq"
178 Sets the hardware interface associate with the file.
179 This
180 command must be performed before any packets can be read.
181 The device is indicated by name using the
182 .Li ifr_name
183 field of the
184 .Li ifreq
185 structure.
186 Additionally, performs the actions of
187 .Dv BIOCFLUSH .
188 .It Dv BIOCSRTIMEOUT
189 .It Dv BIOCGRTIMEOUT
190 .Pq Li "struct timeval"
191 Set or get the read timeout parameter.
192 The argument
193 specifies the length of time to wait before timing
194 out on a read request.
195 This parameter is initialized to zero by
196 .Xr open 2 ,
197 indicating no timeout.
198 .It Dv BIOCGSTATS
199 .Pq Li "struct bpf_stat"
200 Returns the following structure of packet statistics:
201 .Bd -literal
202 struct bpf_stat {
203         u_int bs_recv;    /* number of packets received */
204         u_int bs_drop;    /* number of packets dropped */
205 };
206 .Ed
207 .Pp
208 The fields are:
209 .Bl -hang -offset indent
210 .It Li bs_recv
211 the number of packets received by the descriptor since opened or reset
212 (including any buffered since the last read call);
213 and
214 .It Li bs_drop
215 the number of packets which were accepted by the filter but dropped by the
216 kernel because of buffer overflows
217 (i.e., the application's reads are not keeping up with the packet traffic).
218 .El
219 .It Dv BIOCIMMEDIATE
220 .Pq Li u_int
221 Enable or disable
222 .Dq immediate mode ,
223 based on the truth value of the argument.
224 When immediate mode is enabled, reads return immediately upon packet
225 reception.
226 Otherwise, a read will block until either the kernel buffer
227 becomes full or a timeout occurs.
228 This is useful for programs like
229 .Xr rarpd 8
230 which must respond to messages in real time.
231 The default for a new file is off.
232 .It Dv BIOCSETF
233 .Pq Li "struct bpf_program"
234 Sets the filter program used by the kernel to discard uninteresting
235 packets.
236 An array of instructions and its length is passed in using
237 the following structure:
238 .Bd -literal
239 struct bpf_program {
240         int bf_len;
241         struct bpf_insn *bf_insns;
242 };
243 .Ed
244 .Pp
245 The filter program is pointed to by the
246 .Li bf_insns
247 field while its length in units of
248 .Sq Li struct bpf_insn
249 is given by the
250 .Li bf_len
251 field.
252 Also, the actions of
253 .Dv BIOCFLUSH
254 are performed.
255 See section
256 .Sx "FILTER MACHINE"
257 for an explanation of the filter language.
258 .It Dv BIOCVERSION
259 .Pq Li "struct bpf_version"
260 Returns the major and minor version numbers of the filter language currently
261 recognized by the kernel.
262 Before installing a filter, applications must check
263 that the current version is compatible with the running kernel.
264 Version numbers are compatible if the major numbers match and the application minor
265 is less than or equal to the kernel minor.
266 The kernel version number is returned in the following structure:
267 .Bd -literal
268 struct bpf_version {
269         u_short bv_major;
270         u_short bv_minor;
271 };
272 .Ed
273 .Pp
274 The current version numbers are given by
275 .Dv BPF_MAJOR_VERSION
276 and
277 .Dv BPF_MINOR_VERSION
278 from
279 .In net/bpf.h .
280 An incompatible filter
281 may result in undefined behavior (most likely, an error returned by
282 .Fn ioctl
283 or haphazard packet matching).
284 .It Dv BIOCSHDRCMPLT
285 .It Dv BIOCGHDRCMPLT
286 .Pq Li u_int
287 Set or get the status of the
288 .Dq header complete
289 flag.
290 Set to zero if the link level source address should be filled in automatically
291 by the interface output routine.
292 Set to one if the link level source
293 address will be written, as provided, to the wire.
294 This flag is initialized to zero by default.
295 .It Dv BIOCSSEESENT
296 .It Dv BIOCGSEESENT
297 .Pq Li u_int
298 Set or get the flag determining whether locally generated packets on the
299 interface should be returned by BPF.
300 Set to zero to see only incoming packets on the interface.
301 Set to one to see packets originating locally and remotely on the interface.
302 This flag is initialized to one by
303 default.
304 .El
305 .Sh BPF HEADER
306 The following structure is prepended to each packet returned by
307 .Xr read 2 :
308 .Bd -literal
309 struct bpf_hdr {
310         struct timeval bh_tstamp;     /* time stamp */
311         u_long bh_caplen;             /* length of captured portion */
312         u_long bh_datalen;            /* original length of packet */
313         u_short bh_hdrlen;            /* length of bpf header (this struct
314                                          plus alignment padding */
315 };
316 .Ed
317 .Pp
318 The fields, whose values are stored in host order, and are:
319 .Pp
320 .Bl -tag -compact -width bh_datalen
321 .It Li bh_tstamp
322 The time at which the packet was processed by the packet filter.
323 .It Li bh_caplen
324 The length of the captured portion of the packet.
325 This is the minimum of
326 the truncation amount specified by the filter and the length of the packet.
327 .It Li bh_datalen
328 The length of the packet off the wire.
329 This value is independent of the truncation amount specified by the filter.
330 .It Li bh_hdrlen
331 The length of the
332 .Nm
333 header, which may not be equal to
334 .\" XXX - not really a function call
335 .Fn sizeof "struct bpf_hdr" .
336 .El
337 .Pp
338 The
339 .Li bh_hdrlen
340 field exists to account for
341 padding between the header and the link level protocol.
342 The purpose here is to guarantee proper alignment of the packet
343 data structures, which is required on alignment sensitive
344 architectures and improves performance on many other architectures.
345 The packet filter insures that the
346 .Li bpf_hdr
347 and the network layer
348 header will be word aligned.
349 Suitable precautions
350 must be taken when accessing the link layer protocol fields on alignment
351 restricted machines.
352 (This is not a problem on an Ethernet, since
353 the type field is a short falling on an even offset,
354 and the addresses are probably accessed in a bytewise fashion).
355 .Pp
356 Additionally, individual packets are padded so that each starts
357 on a word boundary.
358 This requires that an application
359 has some knowledge of how to get from packet to packet.
360 The macro
361 .Dv BPF_WORDALIGN
362 is defined in
363 .In net/bpf.h
364 to facilitate
365 this process.
366 It rounds up its argument to the nearest word aligned value (where a word is
367 .Dv BPF_ALIGNMENT
368 bytes wide).
369 .Pp
370 For example, if
371 .Sq Li p
372 points to the start of a packet, this expression
373 will advance it to the next packet:
374 .Dl p = (char *)p + BPF_WORDALIGN(p->bh_hdrlen + p->bh_caplen)
375 .Pp
376 For the alignment mechanisms to work properly, the
377 buffer passed to
378 .Xr read 2
379 must itself be word aligned.
380 The
381 .Xr malloc 3
382 function
383 will always return an aligned buffer.
384 .Sh FILTER MACHINE
385 A filter program is an array of instructions, with all branches forwardly
386 directed, terminated by a
387 .Em return
388 instruction.
389 Each instruction performs some action on the pseudo-machine state,
390 which consists of an accumulator, index register, scratch memory store,
391 and implicit program counter.
392 .Pp
393 The following structure defines the instruction format:
394 .Bd -literal
395 struct bpf_insn {
396         u_short code;
397         u_char  jt;
398         u_char  jf;
399         u_long k;
400 };
401 .Ed
402 .Pp
403 The
404 .Li k
405 field is used in different ways by different instructions,
406 and the
407 .Li jt
408 and
409 .Li jf
410 fields are used as offsets
411 by the branch instructions.
412 The opcodes are encoded in a semi-hierarchical fashion.
413 There are eight classes of instructions:
414 .Dv BPF_LD ,
415 .Dv BPF_LDX ,
416 .Dv BPF_ST ,
417 .Dv BPF_STX ,
418 .Dv BPF_ALU ,
419 .Dv BPF_JMP ,
420 .Dv BPF_RET ,
421 and
422 .Dv BPF_MISC .
423 Various other mode and
424 operator bits are or'd into the class to give the actual instructions.
425 The classes and modes are defined in
426 .In net/bpf.h .
427 .Pp
428 Below are the semantics for each defined
429 .Nm
430 instruction.
431 We use the convention that A is the accumulator, X is the index register,
432 P[] packet data, and M[] scratch memory store.
433 P[i:n] gives the data at byte offset
434 .Dq i
435 in the packet,
436 interpreted as a word (n=4),
437 unsigned halfword (n=2), or unsigned byte (n=1).
438 M[i] gives the i'th word in the scratch memory store, which is only
439 addressed in word units.
440 The memory store is indexed from 0 to
441 .Dv BPF_MEMWORDS
442 - 1.
443 .Li k ,
444 .Li jt ,
445 and
446 .Li jf
447 are the corresponding fields in the
448 instruction definition.
449 .Dq len
450 refers to the length of the packet.
451 .Pp
452 .Bl -tag -width BPF_STXx
453 .It Dv BPF_LD
454 These instructions copy a value into the accumulator.
455 The type of the source operand is specified by an
456 .Dq addressing mode
457 and can be a constant
458 .Pq Dv BPF_IMM ,
459 packet data at a fixed offset
460 .Pq Dv BPF_ABS ,
461 packet data at a variable offset
462 .Pq Dv BPF_IND ,
463 the packet length
464 .Pq Dv BPF_LEN ,
465 or a word in the scratch memory store
466 .Pq Dv BPF_MEM .
467 For
468 .Dv BPF_IND
469 and
470 .Dv BPF_ABS ,
471 the data size must be specified as a word
472 .Pq Dv BPF_W ,
473 halfword
474 .Pq Dv BPF_H ,
475 or byte
476 .Pq Dv BPF_B .
477 The semantics of all the recognized
478 .Dv BPF_LD
479 instructions follow.
480 .Pp
481 .Bd -literal
482 BPF_LD+BPF_W+BPF_ABS    A <- P[k:4]
483 BPF_LD+BPF_H+BPF_ABS    A <- P[k:2]
484 BPF_LD+BPF_B+BPF_ABS    A <- P[k:1]
485 BPF_LD+BPF_W+BPF_IND    A <- P[X+k:4]
486 BPF_LD+BPF_H+BPF_IND    A <- P[X+k:2]
487 BPF_LD+BPF_B+BPF_IND    A <- P[X+k:1]
488 BPF_LD+BPF_W+BPF_LEN    A <- len
489 BPF_LD+BPF_IMM          A <- k
490 BPF_LD+BPF_MEM          A <- M[k]
491 .Ed
492 .It Dv BPF_LDX
493 These instructions load a value into the index register.
494 Note that
495 the addressing modes are more restrictive than those of the accumulator loads,
496 but they include
497 .Dv BPF_MSH ,
498 a hack for efficiently loading the IP header length.
499 .Pp
500 .Bd -literal
501 BPF_LDX+BPF_W+BPF_IMM   X <- k
502 BPF_LDX+BPF_W+BPF_MEM   X <- M[k]
503 BPF_LDX+BPF_W+BPF_LEN   X <- len
504 BPF_LDX+BPF_B+BPF_MSH   X <- 4*(P[k:1]&0xf)
505 .Ed
506 .It Dv BPF_ST
507 This instruction stores the accumulator into the scratch memory.
508 We do not need an addressing mode since there is only one possibility
509 for the destination.
510 .Pp
511 .Bd -literal
512 BPF_ST                  M[k] <- A
513 .Ed
514 .It Dv BPF_STX
515 This instruction stores the index register in the scratch memory store.
516 .Pp
517 .Bd -literal
518 BPF_STX                 M[k] <- X
519 .Ed
520 .It Dv BPF_ALU
521 The alu instructions perform operations between the accumulator and
522 index register or constant, and store the result back in the accumulator.
523 For binary operations, a source mode is required
524 .Dv ( BPF_K
525 or
526 .Dv BPF_X ) .
527 .Pp
528 .Bd -literal
529 BPF_ALU+BPF_ADD+BPF_K   A <- A + k
530 BPF_ALU+BPF_SUB+BPF_K   A <- A - k
531 BPF_ALU+BPF_MUL+BPF_K   A <- A * k
532 BPF_ALU+BPF_DIV+BPF_K   A <- A / k
533 BPF_ALU+BPF_AND+BPF_K   A <- A & k
534 BPF_ALU+BPF_OR+BPF_K    A <- A | k
535 BPF_ALU+BPF_LSH+BPF_K   A <- A << k
536 BPF_ALU+BPF_RSH+BPF_K   A <- A >> k
537 BPF_ALU+BPF_ADD+BPF_X   A <- A + X
538 BPF_ALU+BPF_SUB+BPF_X   A <- A - X
539 BPF_ALU+BPF_MUL+BPF_X   A <- A * X
540 BPF_ALU+BPF_DIV+BPF_X   A <- A / X
541 BPF_ALU+BPF_AND+BPF_X   A <- A & X
542 BPF_ALU+BPF_OR+BPF_X    A <- A | X
543 BPF_ALU+BPF_LSH+BPF_X   A <- A << X
544 BPF_ALU+BPF_RSH+BPF_X   A <- A >> X
545 BPF_ALU+BPF_NEG         A <- -A
546 .Ed
547 .It Dv BPF_JMP
548 The jump instructions alter flow of control.
549 Conditional jumps
550 compare the accumulator against a constant
551 .Pq Dv BPF_K
552 or the index register
553 .Pq Dv BPF_X .
554 If the result is true (or non-zero),
555 the true branch is taken, otherwise the false branch is taken.
556 Jump offsets are encoded in 8 bits so the longest jump is 256 instructions.
557 However, the jump always
558 .Pq Dv BPF_JA
559 opcode uses the 32 bit
560 .Li k
561 field as the offset, allowing arbitrarily distant destinations.
562 All conditionals use unsigned comparison conventions.
563 .Pp
564 .Bd -literal
565 BPF_JMP+BPF_JA          pc += k
566 BPF_JMP+BPF_JGT+BPF_K   pc += (A > k) ? jt : jf
567 BPF_JMP+BPF_JGE+BPF_K   pc += (A >= k) ? jt : jf
568 BPF_JMP+BPF_JEQ+BPF_K   pc += (A == k) ? jt : jf
569 BPF_JMP+BPF_JSET+BPF_K  pc += (A & k) ? jt : jf
570 BPF_JMP+BPF_JGT+BPF_X   pc += (A > X) ? jt : jf
571 BPF_JMP+BPF_JGE+BPF_X   pc += (A >= X) ? jt : jf
572 BPF_JMP+BPF_JEQ+BPF_X   pc += (A == X) ? jt : jf
573 BPF_JMP+BPF_JSET+BPF_X  pc += (A & X) ? jt : jf
574 .Ed
575 .It Dv BPF_RET
576 The return instructions terminate the filter program and specify the amount
577 of packet to accept (i.e., they return the truncation amount).
578 A return value of zero indicates that the packet should be ignored.
579 The return value is either a constant
580 .Pq Dv BPF_K
581 or the accumulator
582 .Pq Dv BPF_A .
583 .Pp
584 .Bd -literal
585 BPF_RET+BPF_A           accept A bytes
586 BPF_RET+BPF_K           accept k bytes
587 .Ed
588 .It Dv BPF_MISC
589 The miscellaneous category was created for anything that does not
590 fit into the above classes, and for any new instructions that might need to
591 be added.
592 Currently, these are the register transfer instructions
593 that copy the index register to the accumulator or vice versa.
594 .Pp
595 .Bd -literal
596 BPF_MISC+BPF_TAX        X <- A
597 BPF_MISC+BPF_TXA        A <- X
598 .Ed
599 .El
600 .Pp
601 The
602 .Nm
603 interface provides the following macros to facilitate
604 array initializers:
605 .Fn BPF_STMT opcode operand
606 and
607 .Fn BPF_JUMP opcode operand true_offset false_offset .
608 .Sh FILES
609 .Bl -tag -compact -width /dev/bpfXXX
610 .It Pa /dev/bpf Ns Sy n
611 the packet filter device
612 .El
613 .Sh EXAMPLES
614 The following filter is taken from the Reverse ARP Daemon.
615 It accepts only Reverse ARP requests.
616 .Bd -literal
617 struct bpf_insn insns[] = {
618         BPF_STMT(BPF_LD+BPF_H+BPF_ABS, 12),
619         BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, ETHERTYPE_REVARP, 0, 3),
620         BPF_STMT(BPF_LD+BPF_H+BPF_ABS, 20),
621         BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, REVARP_REQUEST, 0, 1),
622         BPF_STMT(BPF_RET+BPF_K, sizeof(struct ether_arp) +
623                  sizeof(struct ether_header)),
624         BPF_STMT(BPF_RET+BPF_K, 0),
625 };
626 .Ed
627 .Pp
628 This filter accepts only IP packets between host 128.3.112.15 and
629 128.3.112.35.
630 .Bd -literal
631 struct bpf_insn insns[] = {
632         BPF_STMT(BPF_LD+BPF_H+BPF_ABS, 12),
633         BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, ETHERTYPE_IP, 0, 8),
634         BPF_STMT(BPF_LD+BPF_W+BPF_ABS, 26),
635         BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0x8003700f, 0, 2),
636         BPF_STMT(BPF_LD+BPF_W+BPF_ABS, 30),
637         BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0x80037023, 3, 4),
638         BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0x80037023, 0, 3),
639         BPF_STMT(BPF_LD+BPF_W+BPF_ABS, 30),
640         BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 0x8003700f, 0, 1),
641         BPF_STMT(BPF_RET+BPF_K, (u_int)-1),
642         BPF_STMT(BPF_RET+BPF_K, 0),
643 };
644 .Ed
645 .Pp
646 Finally, this filter returns only TCP finger packets.
647 We must parse the IP header to reach the TCP header.
648 The
649 .Dv BPF_JSET
650 instruction
651 checks that the IP fragment offset is 0 so we are sure
652 that we have a TCP header.
653 .Bd -literal
654 struct bpf_insn insns[] = {
655         BPF_STMT(BPF_LD+BPF_H+BPF_ABS, 12),
656         BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, ETHERTYPE_IP, 0, 10),
657         BPF_STMT(BPF_LD+BPF_B+BPF_ABS, 23),
658         BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, IPPROTO_TCP, 0, 8),
659         BPF_STMT(BPF_LD+BPF_H+BPF_ABS, 20),
660         BPF_JUMP(BPF_JMP+BPF_JSET+BPF_K, 0x1fff, 6, 0),
661         BPF_STMT(BPF_LDX+BPF_B+BPF_MSH, 14),
662         BPF_STMT(BPF_LD+BPF_H+BPF_IND, 14),
663         BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 79, 2, 0),
664         BPF_STMT(BPF_LD+BPF_H+BPF_IND, 16),
665         BPF_JUMP(BPF_JMP+BPF_JEQ+BPF_K, 79, 0, 1),
666         BPF_STMT(BPF_RET+BPF_K, (u_int)-1),
667         BPF_STMT(BPF_RET+BPF_K, 0),
668 };
669 .Ed
670 .Sh SEE ALSO
671 .Xr tcpdump 1 ,
672 .Xr ioctl 2 ,
673 .Xr byteorder 3 ,
674 .Xr ng_bpf 4 ,
675 .Xr bpf 9
676 .Rs
677 .%A McCanne, S.
678 .%A Jacobson V.
679 .%T "An efficient, extensible, and portable network monitor"
680 .Re
681 .Sh HISTORY
682 The Enet packet filter was created in 1980 by Mike Accetta and
683 Rick Rashid at Carnegie-Mellon University.
684 Jeffrey Mogul, at
685 Stanford, ported the code to
686 .Bx
687 and continued its development from
688 1983 on.
689 Since then, it has evolved into the Ultrix Packet Filter at
690 .Tn DEC ,
691 a
692 .Tn STREAMS
693 .Tn NIT
694 module under
695 .Tn SunOS 4.1 ,
696 and
697 .Tn BPF .
698 .Sh AUTHORS
699 .An -nosplit
700 .An Steven McCanne ,
701 of Lawrence Berkeley Laboratory, implemented BPF in
702 Summer 1990.
703 Much of the design is due to
704 .An Van Jacobson .
705 .Sh BUGS
706 The read buffer must be of a fixed size (returned by the
707 .Dv BIOCGBLEN
708 ioctl).
709 .Pp
710 A file that does not request promiscuous mode may receive promiscuously
711 received packets as a side effect of another file requesting this
712 mode on the same hardware interface.
713 This could be fixed in the kernel with additional processing overhead.
714 However, we favor the model where
715 all files must assume that the interface is promiscuous, and if
716 so desired, must utilize a filter to reject foreign packets.
717 .Pp
718 Data link protocols with variable length headers are not currently supported.
719 .Pp
720 The
721 .Dv SEESENT
722 flag has been observed to work incorrectly on some interface
723 types, including those with hardware loopback rather than software loopback,
724 and point-to-point interfaces.
725 It appears to function correctly on a
726 broad range of Ethernet-style interfaces.