Project

General

Profile

Statistics
| Revision:

root / lab4 / .minix-src / include / net / bpfdesc.h @ 13

History | View | Annotate | Download (5.6 KB)

1
/*        $NetBSD: bpfdesc.h,v 1.38 2013/11/15 00:12:44 rmind Exp $        */
2

    
3
/*
4
 * Copyright (c) 1990, 1991, 1993
5
 *        The Regents of the University of California.  All rights reserved.
6
 *
7
 * This code is derived from the Stanford/CMU enet packet filter,
8
 * (net/enet.c) distributed as part of 4.3BSD, and code contributed
9
 * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence
10
 * Berkeley Laboratory.
11
 *
12
 * Redistribution and use in source and binary forms, with or without
13
 * modification, are permitted provided that the following conditions
14
 * are met:
15
 * 1. Redistributions of source code must retain the above copyright
16
 *    notice, this list of conditions and the following disclaimer.
17
 * 2. Redistributions in binary form must reproduce the above copyright
18
 *    notice, this list of conditions and the following disclaimer in the
19
 *    documentation and/or other materials provided with the distribution.
20
 * 3. Neither the name of the University nor the names of its contributors
21
 *    may be used to endorse or promote products derived from this software
22
 *    without specific prior written permission.
23
 *
24
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34
 * SUCH DAMAGE.
35
 *
36
 *        @(#)bpfdesc.h        8.1 (Berkeley) 6/10/93
37
 *
38
 * @(#) Header: bpfdesc.h,v 1.14 96/06/16 22:28:07 leres Exp  (LBL)
39
 */
40

    
41
#ifndef _NET_BPFDESC_H_
42
#define _NET_BPFDESC_H_
43

    
44
#include <sys/callout.h>
45
#include <sys/selinfo.h>                /* for struct selinfo */
46
#include <net/if.h>                        /* for IFNAMSIZ */
47
#include <net/bpfjit.h>                        /* for bpfjit_function_t */
48

    
49
/*
50
 * Descriptor associated with each open bpf file.
51
 */
52
struct bpf_d {
53
        struct bpf_d        *bd_next;        /* Linked list of descriptors */
54
        /*
55
         * Buffer slots: two mbuf clusters buffer the incoming packets.
56
         *   The model has three slots.  Sbuf is always occupied.
57
         *   sbuf (store) - Receive interrupt puts packets here.
58
         *   hbuf (hold) - When sbuf is full, put cluster here and
59
         *                 wakeup read (replace sbuf with fbuf).
60
         *   fbuf (free) - When read is done, put cluster here.
61
         * On receiving, if sbuf is full and fbuf is 0, packet is dropped.
62
         */
63
        void *                bd_sbuf;        /* store slot */
64
        void *                bd_hbuf;        /* hold slot */
65
        void *                bd_fbuf;        /* free slot */
66
        int                 bd_slen;        /* current length of store buffer */
67
        int                 bd_hlen;        /* current length of hold buffer */
68

    
69
        int                bd_bufsize;        /* absolute length of buffers */
70

    
71
        struct bpf_if *        bd_bif;                /* interface descriptor */
72
        u_long                bd_rtout;        /* Read timeout in 'ticks' */
73
        struct bpf_insn *bd_filter;         /* filter code */
74
        u_long                bd_rcount;        /* number of packets received */
75
        u_long                bd_dcount;        /* number of packets dropped */
76
        u_long                bd_ccount;        /* number of packets captured */
77

    
78
        u_char                bd_promisc;        /* true if listening promiscuously */
79
        u_char                bd_state;        /* idle, waiting, or timed out */
80
        u_char                bd_immediate;        /* true to return on packet arrival */
81
        int                bd_hdrcmplt;        /* false to fill in src lladdr */
82
        int                bd_seesent;        /* true if bpf should see sent packets */
83
        int                 bd_feedback;        /* true to feed back sent packets */
84
        int                bd_async;        /* non-zero if packet reception should generate signal */
85
        pid_t                bd_pgid;        /* process or group id for signal */
86
#if BSD < 199103
87
        u_char                bd_selcoll;        /* true if selects collide */
88
        int                bd_timedout;
89
        struct proc *        bd_selproc;        /* process that last selected us */
90
#else
91
        u_char                bd_pad;                /* explicit alignment */
92
        struct selinfo        bd_sel;                /* bsd select info */
93
#endif
94
        callout_t        bd_callout;        /* for BPF timeouts with select */
95
        pid_t                bd_pid;                /* corresponding PID */
96
        LIST_ENTRY(bpf_d) bd_list;        /* list of all BPF's */
97
        void                *bd_sih;        /* soft interrupt handle */
98
        struct timespec bd_atime;        /* access time */
99
        struct timespec bd_mtime;        /* modification time */
100
        struct timespec bd_btime;        /* birth time */
101
#ifdef _LP64
102
        int                bd_compat32;        /* 32-bit stream on LP64 system */
103
#endif
104
        bpfjit_func_t        bd_jitcode;        /* compiled filter program */
105
};
106

    
107

    
108
/* Values for bd_state */
109
#define BPF_IDLE        0                /* no select in progress */
110
#define BPF_WAITING        1                /* waiting for read timeout in select */
111
#define BPF_TIMED_OUT        2                /* read timeout has expired in select */
112

    
113
/*
114
 * Description associated with the external representation of each
115
 * open bpf file.
116
 */
117
struct bpf_d_ext {
118
        int32_t                bde_bufsize;
119
        uint8_t                bde_promisc;
120
        uint8_t                bde_state;
121
        uint8_t                bde_immediate;
122
        int32_t                bde_hdrcmplt;
123
        int32_t                bde_seesent;
124
        pid_t                bde_pid;
125
        uint64_t        bde_rcount;                /* number of packets received */
126
        uint64_t        bde_dcount;                /* number of packets dropped */
127
        uint64_t        bde_ccount;                /* number of packets captured */
128
        char                bde_ifname[IFNAMSIZ];
129
};
130

    
131

    
132
/*
133
 * Descriptor associated with each attached hardware interface.
134
 */
135
struct bpf_if {
136
        struct bpf_if *bif_next;        /* list of all interfaces */
137
        struct bpf_d *bif_dlist;        /* descriptor list */
138
        struct bpf_if **bif_driverp;        /* pointer into softc */
139
        u_int bif_dlt;                        /* link layer type */
140
        u_int bif_hdrlen;                /* length of header (with padding) */
141
        struct ifnet *bif_ifp;                /* corresponding interface */
142
};
143

    
144
#ifdef _KERNEL
145
int         bpf_setf(struct bpf_d *, struct bpf_program *);
146
#endif
147

    
148
#endif /* !_NET_BPFDESC_H_ */