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