Root/
1 | filter.txt: Linux Socket Filtering |
2 | Written by: Jay Schulist <jschlst@samba.org> |
3 | |
4 | Introduction |
5 | ============ |
6 | |
7 | Linux Socket Filtering is derived from the Berkeley |
8 | Packet Filter. There are some distinct differences between |
9 | the BSD and Linux Kernel Filtering. |
10 | |
11 | Linux Socket Filtering (LSF) allows a user-space program to |
12 | attach a filter onto any socket and allow or disallow certain |
13 | types of data to come through the socket. LSF follows exactly |
14 | the same filter code structure as the BSD Berkeley Packet Filter |
15 | (BPF), so referring to the BSD bpf.4 manpage is very helpful in |
16 | creating filters. |
17 | |
18 | LSF is much simpler than BPF. One does not have to worry about |
19 | devices or anything like that. You simply create your filter |
20 | code, send it to the kernel via the SO_ATTACH_FILTER ioctl and |
21 | if your filter code passes the kernel check on it, you then |
22 | immediately begin filtering data on that socket. |
23 | |
24 | You can also detach filters from your socket via the |
25 | SO_DETACH_FILTER ioctl. This will probably not be used much |
26 | since when you close a socket that has a filter on it the |
27 | filter is automagically removed. The other less common case |
28 | may be adding a different filter on the same socket where you had another |
29 | filter that is still running: the kernel takes care of removing |
30 | the old one and placing your new one in its place, assuming your |
31 | filter has passed the checks, otherwise if it fails the old filter |
32 | will remain on that socket. |
33 | |
34 | Examples |
35 | ======== |
36 | |
37 | Ioctls- |
38 | setsockopt(sockfd, SOL_SOCKET, SO_ATTACH_FILTER, &Filter, sizeof(Filter)); |
39 | setsockopt(sockfd, SOL_SOCKET, SO_DETACH_FILTER, &value, sizeof(value)); |
40 | |
41 | See the BSD bpf.4 manpage and the BSD Packet Filter paper written by |
42 | Steven McCanne and Van Jacobson of Lawrence Berkeley Laboratory. |
43 |
Branches:
ben-wpan
ben-wpan-stefan
javiroman/ks7010
jz-2.6.34
jz-2.6.34-rc5
jz-2.6.34-rc6
jz-2.6.34-rc7
jz-2.6.35
jz-2.6.36
jz-2.6.37
jz-2.6.38
jz-2.6.39
jz-3.0
jz-3.1
jz-3.11
jz-3.12
jz-3.13
jz-3.15
jz-3.16
jz-3.18-dt
jz-3.2
jz-3.3
jz-3.4
jz-3.5
jz-3.6
jz-3.6-rc2-pwm
jz-3.9
jz-3.9-clk
jz-3.9-rc8
jz47xx
jz47xx-2.6.38
master
Tags:
od-2011-09-04
od-2011-09-18
v2.6.34-rc5
v2.6.34-rc6
v2.6.34-rc7
v3.9