Download free for 30 days
Sign in
Upload
Language (EN)
Support
Business
Mobile
Social Media
Marketing
Technology
Art & Photos
Career
Design
Education
Presentations & Public Speaking
Government & Nonprofit
Healthcare
Internet
Law
Leadership & Management
Automotive
Engineering
Software
Recruiting & HR
Retail
Sales
Services
Science
Small Business & Entrepreneurship
Food
Environment
Economy & Finance
Data & Analytics
Investor Relations
Sports
Spiritual
News & Politics
Travel
Self Improvement
Real Estate
Entertainment & Humor
Health & Medicine
Devices & Hardware
Lifestyle
Change Language
Language
English
Español
Português
Français
Deutsche
Cancel
Save
EN
Uploaded by
Masaru Oki
PDF, PPTX
1,296 views
Net bsd advent calendar 2015 bpf
BPF Programming basic (in Japanese)
Software
◦
Read more
5
Save
Share
Embed
Embed presentation
Download
Download as PDF, PPTX
1
/ 7
2
/ 7
3
/ 7
4
/ 7
5
/ 7
6
/ 7
7
/ 7
More Related Content
PPTX
Hostsの活用
by
Yoshitaka KATO
ODP
Custom Package Building with Poudriere
by
Yuichiro Naito
PPTX
Rから通知をとばす
by
TokorosawaYoshio
PPTX
Usb
by
chikaratanaka1
PDF
ファイルの隠し方
by
mfumi
PDF
Lagopus as open flow hybrid switch
by
Masaru Oki
PDF
Open flow tunnel extension on lagopus vswitch
by
Masaru Oki
PDF
Using rump on NetBSD 7.0
by
Masaru Oki
Hostsの活用
by
Yoshitaka KATO
Custom Package Building with Poudriere
by
Yuichiro Naito
Rから通知をとばす
by
TokorosawaYoshio
Usb
by
chikaratanaka1
ファイルの隠し方
by
mfumi
Lagopus as open flow hybrid switch
by
Masaru Oki
Open flow tunnel extension on lagopus vswitch
by
Masaru Oki
Using rump on NetBSD 7.0
by
Masaru Oki
Viewers also liked
PDF
Lagopus+pcap pmd
by
Masaru Oki
PDF
Lagopus 0.2.2
by
Masaru Oki
PDF
Lagopus 0.2.4
by
Masaru Oki
PDF
Lagopus 0.2
by
Masaru Oki
PDF
GPD WINが来た!
by
Masaru Oki
PDF
新生Lagopus2017(仮称)
by
Masaru Oki
PDF
OpenFlowでいろんなプロトコルを 話そうとするとどうなるか
by
Masaru Oki
PDF
60分でわかるソケットプログラミング
by
Masahiko Kimoto
PPTX
Volcanic Eruption Communication Model (Final Revision)
by
Jose Radin Garduque
PPT
PARADIGMAS URBANOS. Guía sitio 2016
by
Arquitectura Civil
PPT
8 Issues and My Answers in Pilipinas Debates 2016
by
Jose Radin Garduque
PPTX
The One Who Deserves (Silent Protest)
by
Jose Radin Garduque
PDF
richards keynote
by
richardskd
PPTX
Thailand (Economic Setting)
by
Jose Radin Garduque
PPT
8 Tui Bei Tu Parallelisms to Philippine History
by
Jose Radin Garduque
PPTX
Frances. POWERPOINT.
by
Cristina Gutierrez Ruiz
PPTX
Location shoot
by
Lauren Pratt
PPTX
Myanmar: Political Setting
by
Jose Radin Garduque
PPTX
cgfh
by
Andretam
PPTX
Historia del Cine
by
miiikeeelooodiiiuuum
Lagopus+pcap pmd
by
Masaru Oki
Lagopus 0.2.2
by
Masaru Oki
Lagopus 0.2.4
by
Masaru Oki
Lagopus 0.2
by
Masaru Oki
GPD WINが来た!
by
Masaru Oki
新生Lagopus2017(仮称)
by
Masaru Oki
OpenFlowでいろんなプロトコルを 話そうとするとどうなるか
by
Masaru Oki
60分でわかるソケットプログラミング
by
Masahiko Kimoto
Volcanic Eruption Communication Model (Final Revision)
by
Jose Radin Garduque
PARADIGMAS URBANOS. Guía sitio 2016
by
Arquitectura Civil
8 Issues and My Answers in Pilipinas Debates 2016
by
Jose Radin Garduque
The One Who Deserves (Silent Protest)
by
Jose Radin Garduque
richards keynote
by
richardskd
Thailand (Economic Setting)
by
Jose Radin Garduque
8 Tui Bei Tu Parallelisms to Philippine History
by
Jose Radin Garduque
Frances. POWERPOINT.
by
Cristina Gutierrez Ruiz
Location shoot
by
Lauren Pratt
Myanmar: Political Setting
by
Jose Radin Garduque
cgfh
by
Andretam
Historia del Cine
by
miiikeeelooodiiiuuum
More from Masaru Oki
PDF
NetBSD移植の昔話
by
Masaru Oki
PDF
Rust-DPDK
by
Masaru Oki
PDF
Rust-DPDK
by
Masaru Oki
PDF
Lagopusとvagrant
by
Masaru Oki
PDF
今よりも少し(?)昔、 Windowsを作ろうとした話
by
Masaru Oki
PDF
Onieで遊んでみようとした話
by
Masaru Oki
PDF
Lagopus as open flow hybrid switch 実践編
by
Masaru Oki
PDF
LagopusでPPPoEを使えるか考えてみた件
by
Masaru Oki
PDF
Lagopus どれだけ速いのか
by
Masaru Oki
PDF
Lagopus 0.2.7
by
Masaru Oki
PDF
Ryu+Lagopusで OpenFlowの動きを見てみよう
by
Masaru Oki
PDF
Lagopus match improvements
by
Masaru Oki
PDF
Rumpを使ってみる
by
Masaru Oki
PDF
FreeBSD jail+vnetと戯れた話
by
Masaru Oki
PDF
Open stack+lagopus できるかな
by
Masaru Oki
PDF
SDNソフトウェアスイッチlagopus for FreeBSD
by
Masaru Oki
PDF
Xeon dとlagopusと、pktgen dpdk
by
Masaru Oki
PDF
Running lagopus on Xeon D
by
Masaru Oki
PDF
Using Xeon D 10GBase-T
by
Masaru Oki
PDF
DPDK QoS
by
Masaru Oki
NetBSD移植の昔話
by
Masaru Oki
Rust-DPDK
by
Masaru Oki
Rust-DPDK
by
Masaru Oki
Lagopusとvagrant
by
Masaru Oki
今よりも少し(?)昔、 Windowsを作ろうとした話
by
Masaru Oki
Onieで遊んでみようとした話
by
Masaru Oki
Lagopus as open flow hybrid switch 実践編
by
Masaru Oki
LagopusでPPPoEを使えるか考えてみた件
by
Masaru Oki
Lagopus どれだけ速いのか
by
Masaru Oki
Lagopus 0.2.7
by
Masaru Oki
Ryu+Lagopusで OpenFlowの動きを見てみよう
by
Masaru Oki
Lagopus match improvements
by
Masaru Oki
Rumpを使ってみる
by
Masaru Oki
FreeBSD jail+vnetと戯れた話
by
Masaru Oki
Open stack+lagopus できるかな
by
Masaru Oki
SDNソフトウェアスイッチlagopus for FreeBSD
by
Masaru Oki
Xeon dとlagopusと、pktgen dpdk
by
Masaru Oki
Running lagopus on Xeon D
by
Masaru Oki
Using Xeon D 10GBase-T
by
Masaru Oki
DPDK QoS
by
Masaru Oki
Net bsd advent calendar 2015 bpf
1.
NetBSD Advent Calendar
2015 BPFを使ってパケットを送受信 Dec 8, 2015 Masaru OKI @masaru0714
2.
BPF? Berkeley Packet Filter。 昔から*BSDにある、パケットキャプチャの仕組み。 injectといってパケットを送信することもできる。らしい。 bpf(4)にいろいろ説明が書いてある。 以降、C言語を使ったBPFでのパケット送受信について大雑把に解説する。 自分がハマったところは太字にしている。あちこちにある。うっかりさんである。
3.
BPFによるキャプチャの準備 1. fd =
open(“/dev/bpf”, O_RDWR); で、スペシャルファイルをオープンする。 2. ioctl(fd, BIOCSBLEN, &len); で、バッファサイズを設定する。 バッファには複数パケットの情報が詰めて書き込まれる。 インタフェースを指定する前に設定する必要がある。 3. ioctl(fd, BIOCSSEESENT, &onoff); で送信方向をキャプチャするか指定。 受信方向については常にキャプチャされる。デフォルトは送信方向もキャプチャ。 ※FreeBSDではBIOCSDIECTIONを使う。送信方向のみキャプチャもできる。 4. ioctl(fd, BIOCSETIF, &ifreq); で対象インタフェース名を指定。 ifreq.ifr_nameにインタフェース名を書き込んでおく。 5. 必要に応じて ioctl(fd, BIOCPROMISC, NULL); しておく。
4.
パケットの受信 1. read(fd, buf,
buflen); する。buflenはBIOCSBLENと同じ値でないとエラーになる。 2. bufの中身はstruct bpf_hdr + パケットデータ、が収まるだけ連続している。 3. パケットデータのサイズは bh_caplenにホストバイトオーダで書かれている。 bpf_hdr bpf_hdr bpf_hdr bpf_hdr struct bpf_hdr { struct bpf_timeval bh_tstamp; /* time stamp */ uint32_t bh_caplen; /* length of captured portion */ uint32_t bh_datalen; /* original length of packet */ uint16_t bh_hdrlen; /* length of bpf header (this struct plus alignment padding) */ };
5.
パケットの送信 ふつうに生データをwriteするだけ。1回のwriteで1パケット。bpf_hdrはつけない。 FCSはカーネルが計算してくれる。 ioctl(fd, BIOCSSEESENT, &onoff);
で送信方向のキャプチャを切っておかないと、送った データそのものを受信する。tcpdumpみたいに全部キャプチャするのであれば問題ない が、パケット送受信するプログラムの場合はハマるので注意。
6.
パケットの受信待ち fdをふつうにselectやpollで待てる。 送信でブロックを避けたい場合もselectやpollを使う。
7.
OSによるBPF実装の差異 ● BPFではfilterを設定できるが、NetBSDではfilterのJITコンパイラが使える。 ● FreeBSDではzero
copy bpfなるものが用意されている。 ● 他は未調査…… ● スライドで解説したコードはNetBSD, FreeBSD共通で使える。 ● 昔の*BSDは “/dev/bpf0”, “/dev/bpf1”, … を使っていた(重複open不可)らしいが、 NetBSDやFreeBSDは “/dev/bpf” を複数回openして別I/Fを送受信できる。 おしまい。
Download