diff options
author | archie <archie@FreeBSD.org> | 2001-02-19 04:00:52 +0000 |
---|---|---|
committer | archie <archie@FreeBSD.org> | 2001-02-19 04:00:52 +0000 |
commit | 2baf820df6cf54bd3d3306776bea0d3fd6e894c7 (patch) | |
tree | 241d851f8e8f1b8ac6dffaf2718556e334f5a195 | |
parent | 337d7ba539a9d8f5f19110edd365ae6d3a7d8aba (diff) | |
download | FreeBSD-src-2baf820df6cf54bd3d3306776bea0d3fd6e894c7.zip FreeBSD-src-2baf820df6cf54bd3d3306776bea0d3fd6e894c7.tar.gz |
Add an example showing how to configure a node from the command line.
-rw-r--r-- | share/man/man4/ng_bpf.4 | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/share/man/man4/ng_bpf.4 b/share/man/man4/ng_bpf.4 index b1a9a0b..81d18fa 100644 --- a/share/man/man4/ng_bpf.4 +++ b/share/man/man4/ng_bpf.4 @@ -133,6 +133,43 @@ except that the statistics are also atomically cleared. This node shuts down upon receipt of a .Dv NGM_SHUTDOWN control message, or when all hooks have been disconnected. +.Sh EXAMPLE +It is possible to configure a node from the command line, using +.Xr tcpdump 8 +to generate raw BPF instructions which are then fed into an +.Xr awk 1 +script to create the ASCII form of a +.Dv NGM_BPF_SET_PROGRAM +control message, as demonstrated here: +.Bd -literal -offset 4n +#!/bin/sh + +PATTERN="tcp dst port 80" +INHOOK="hook1" +MATCHHOOK="hook2" +NOTMATCHHOOK="hook3" + +cat > /tmp/bpf.awk << xxENDxx +{ + if (!init) { + printf "bpf_prog_len=%d bpf_prog=[", \\$1; + init=1; + } else { + printf " { code=%d jt=%d jf=%d k=%d }", \\$1, \\$2, \\$3, \\$4; + } +} +END { + print " ]" +} +xxENDxx + +BPFPROG=`tcpdump -ddd ${PATTERN} | awk -f /tmp/bpf.awk` + +ngctl msg my_node: setprogram { thisHook=\\"${INHOOK}\\" \\ + ifMatch=\\"${MATCHHOOK}\\" \\ + ifNotMatch=\\"${NOTMATCHHOOK}\\" \\ + ${BPFPROG} } } +.Ed .Sh BUGS When built as a loadable kernel module, this module includes the file .Pa net/bpf_filter.c . |