Libpcap: an Architecture and Opdmizadon Methodology for Packet Capture

Libpcap: an Architecture and Opdmizadon Methodology for Packet Capture

libpcap: An Architecture and Op2mizaon Methodology for Packet Capture Sharkfest ’11 Steve McCanne, CTO Riverbed Technology CS 164 • My story begins with a U.C. Berkeley course – Back in spring 1988, I took the the compilers course in computer science at U.C. Berkeley – Taught by a guest lecturer from LBL • Van Jacobson – Learned standard compiler topics • scanning, parsing, code generaon, op2mizaon – Took summer job in Van’s group at end of term LBL • It was a great 2me and place in Internet history – Summer job evolved into staff scien2st posi2on • “Network Research Group” – Van Jacobson – Sally Floyd – Vern PaXson – Steve McCanne • Lucky to be surrounded by such creave intellect LBL Network Research Group • flex • VoIP (RTP) • TCP conges2on control • Mbone tools (vic, vat, wb) • VJ header compression • Scalable reliable mul2cast (CSLIP) (SRM) • BSD packet filter (BPF) • ns - network simulator • tcpdump, pcap • Class-based queuing • traceroute, pathchar (CBQ) • BRO • Random early drop (RED) • SDP/SIP • diffserv Conges2on Control • When I first joined, Van was wrapping up his work on TCP conges2on control – He had figured out why the Arpanet kept collapsing... Packet Capture • Van needed to look at packet traces – to understand the problem – to eXperiment with fiXes – to see that the solu2on was working packet capture tool arpanet etherfind • Frustrated with Sun’s packet capture tool – “etherfind” based on UniX “find” command • Several problems – Clumsy filtering syntax • How many of you do “find . | grep ...” instead? – Protocol decoding was weak and cryp2c – Horrible performance The LAN Boleneck ether find arpanet The LAN Boleneck ether X find arpanet Enter tcpdump • There must be a beger way… – Set out to work on a new model in a tool called tcpdump – “Filter” packets before they come up the stack • Inspired by Jeff Mogul’s prior work on “enet” – Compile high-level filter specificaon into low- level code that filters packets at driver level – Kernel module called Berkeley Packet Filter (BPF) tcpdump user kernel tcp stack sun workstation bpf NIC file system ethernet disk tcpdump “ip host jp.arpa.net and tcp port jp-data” tcpdump user kernel tcp stack sun workstation bpf NIC file system ethernet disk tcpdump “ip host jp.arpa.net and tcp port jp-data” tcpdump (000) ldh [12] (001) jeq #0X800 jt 2 jf 16 user (002) ld [26] (003) jeq #10.0.0.20 jt 6 jf 4 (004) ld [30] (005) jeq #10.0.0.20 jt 6 jf 16 kernel (006) ldb [23] (007) jeq #0X6 jt 8 jf 16 (008) ldh [20] tcp stack (009) jset #0X1fff jt 16 jf 10 (010) ldxb 4*([14]&0Xf) sun (011) ldh [X + 14] (012) jeq #0X14 jt 15 jf 13 (013) ldh [X + 16] (014) jeq #0X14 jt 15 jf 16 workstation (015) ret #65535 bpf (016) ret #0 NIC file system ethernet disk tcpdump Run test program to jp.arpa.net p tcpdump user kernel tcp stack sun workstation bpf NIC file system packets ethernet to/from disk arpanet tcpdump Run test program to jp.arpa.net p tcpdump user arpanet kernel tcp stack packets sun copied to workstation bpf X tcpdump NIC file system packets ethernet LAN traffic to/from blocked by BPF disk arpanet tcpdump Run test program to jp.arpa.net Packets decoded and displayed p tcpdump xterm user arpanet kernel tcp stack packets sun copied to workstation bpf X tcpdump NIC file system packets ethernet LAN traffic to/from blocked by BPF disk arpanet tcpdump Run test program to jp.arpa.net p tcpdump xterm user arpanet kernel tcp stack packets Or packets sun copied to dumped straight workstation bpf X tcpdump to disk NIC file system packets ethernet LAN traffic to/from blocked by BPF disk arpanet The BPF virtual machine • First thing, I had to design a VM model that would run in the kernel • Came up with a virtual machine architecture and set of machine instruc2ons – Knew Apple II from my junior high days – Modeled aer Motorola 6502 – Accumulator (A), indeX register (X) – Packet-based memory model – Arithme2c and condi2onal logic EXample (000) ldh [12] FTP data packets (001) jeq #0X800 jt 2 jf 16 (002) ld [26] for host 10.0.0.20 (003) jeq #10.0.0.20 xtermjt 6 jf 4 (004) ld [30] (005) jeq #10.0.0.20 jt 6 jf 16 (006) ldb [23] (007) jeq #0X6 jt 8 jf 16 (008) ldh [20] (009) jset #0X1fff jt 16 jf 10 (010) ldxb 4*([14]&0Xf) (011) ldh [X + 14] (012) jeq #0X14 jt 15 jf 13 (013) ldh [X + 16] (014) jeq #0X14 jt 15 jf 16 (015) ret #65535 (016) ret #0 EXample (000) ldh [12] FTP data packets (001) jeq #0X800 jt 2 jf 16 (002) ld [26] for host 10.0.0.20 (003) jeq #10.0.0.20 jt 6 jf 4 (004) ld [30] (005) jeq #10.0.0.20 xterm jt 6 jf 16 (006) ldb [23] Is ethernet type IP? (007) jeq #0X6 jt 8 jf 16 (008) ldh [20] (009) jset #0X1fff jt 16 jf 10 (010) ldxb 4*([14]&0Xf) (011) ldh [X + 14] A: X: (012) jeq #0X14 jt 15 jf 13 (013) ldh [X + 16] (014) jeq #0X14 jt 15 jf 16 (015) ret #65535 packet (016) ret #0 ether IP TCP data EXample (000) ldh [12] FTP data packets (001) jeq #0X800 jt 2 jf 16 (002) ld [26] for host 10.0.0.20 (003) jeq #10.0.0.20 jt 6 jf 4 (004) ld [30] (005) jeq #10.0.0.20 xterm jt 6 jf 16 (006) ldb [23] Is ethernet type IP? (007) jeq #0X6 jt 8 jf 16 (008) ldh [20] (009) jset #0X1fff jt 16 jf 10 (010) ldxb 4*([14]&0Xf) (011) ldh [X + 14] A: 0x800 X: (012) jeq #0X14 jt 15 jf 13 (013) ldh [X + 16] (014) jeq #0X14 jt 15 jf 16 (015) ret #65535 packet (016) ret #0 ether IP TCP data EXample (000) ldh [12] FTP data packets (001) jeq #0X800 jt 2 jf 16 (002) ld [26] for host 10.0.0.20 (003) jeq #10.0.0.20 jt 6 jf 4 (004) ld [30] (005) jeq #10.0.0.20 xterm jt 6 jf 16 (006) ldb [23] Is IP src address 10.0.0.20? (007) jeq #0X6 jt 8 jf 16 (008) ldh [20] (009) jset #0X1fff jt 16 jf 10 (010) ldxb 4*([14]&0Xf) (011) ldh [X + 14] A: X: (012) jeq #0X14 jt 15 jf 13 (013) ldh [X + 16] (014) jeq #0X14 jt 15 jf 16 (015) ret #65535 packet (016) ret #0 ether IP TCP data EXample (000) ldh [12] FTP data packets (001) jeq #0X800 jt 2 jf 16 (002) ld [26] for host 10.0.0.20 (003) jeq #10.0.0.20 jt 6 jf 4 (004) ld [30] (005) jeq #10.0.0.20 xterm jt 6 jf 16 (006) ldb [23] Is IP src address 10.0.0.20? (007) jeq #0X6 jt 8 jf 16 (008) ldh [20] (009) jset #0X1fff jt 16 jf 10 (010) ldxb 4*([14]&0Xf) (011) ldh [X + 14] A: 10.0.1.11 X: (012) jeq #0X14 jt 15 jf 13 (013) ldh [X + 16] (014) jeq #0X14 jt 15 jf 16 (015) ret #65535 packet (016) ret #0 ether IP TCP data EXample (000) ldh [12] FTP data packets (001) jeq #0X800 jt 2 jf 16 (002) ld [26] for host 10.0.0.20 (003) jeq #10.0.0.20 jt 6 jf 4 (004) ld [30] (005) jeq #10.0.0.20 xterm jt 6 jf 16 (006) ldb [23] Is IP dst address 10.0.0.20? (007) jeq #0X6 jt 8 jf 16 (008) ldh [20] (009) jset #0X1fff jt 16 jf 10 (010) ldxb 4*([14]&0Xf) (011) ldh [X + 14] A: X: (012) jeq #0X14 jt 15 jf 13 (013) ldh [X + 16] (014) jeq #0X14 jt 15 jf 16 (015) ret #65535 packet (016) ret #0 ether IP TCP data EXample (000) ldh [12] FTP data packets (001) jeq #0X800 jt 2 jf 16 (002) ld [26] for host 10.0.0.20 (003) jeq #10.0.0.20 jt 6 jf 4 (004) ld [30] (005) jeq #10.0.0.20 xterm jt 6 jf 16 (006) ldb [23] Is IP dst address 10.0.0.20? (007) jeq #0X6 jt 8 jf 16 (008) ldh [20] (009) jset #0X1fff jt 16 jf 10 (010) ldxb 4*([14]&0Xf) (011) ldh [X + 14] A: 10.0.0.20 X: (012) jeq #0X14 jt 15 jf 13 (013) ldh [X + 16] (014) jeq #0X14 jt 15 jf 16 (015) ret #65535 packet (016) ret #0 ether IP TCP data EXample (000) ldh [12] FTP data packets (001) jeq #0X800 jt 2 jf 16 (002) ld [26] for host 10.0.0.20 (003) jeq #10.0.0.20 jt 6 jf 4 (004) ld [30] Is IP protocol TCP? (005) jeq #10.0.0.20 xterm jt 6 jf 16 (006) ldb [23] (007) jeq #0X6 jt 8 jf 16 (008) ldh [20] (009) jset #0X1fff jt 16 jf 10 (010) ldxb 4*([14]&0Xf) (011) ldh [X + 14] A: X: (012) jeq #0X14 jt 15 jf 13 (013) ldh [X + 16] (014) jeq #0X14 jt 15 jf 16 (015) ret #65535 packet (016) ret #0 ether IP TCP data EXample (000) ldh [12] FTP data packets (001) jeq #0X800 jt 2 jf 16 (002) ld [26] for host 10.0.0.20 (003) jeq #10.0.0.20 jt 6 jf 4 (004) ld [30] Is IP protocol TCP? (005) jeq #10.0.0.20 xterm jt 6 jf 16 (006) ldb [23] (007) jeq #0X6 jt 8 jf 16 (008) ldh [20] (009) jset #0X1fff jt 16 jf 10 (010) ldxb 4*([14]&0Xf) (011) ldh [X + 14] A: 6 X: (012) jeq #0X14 jt 15 jf 13 (013) ldh [X + 16] (014) jeq #0X14 jt 15 jf 16 (015) ret #65535 packet (016) ret #0 ether IP TCP data EXample (000) ldh [12] FTP data packets (001) jeq #0X800 jt 2 jf 16 (002) ld [26] for host 10.0.0.20 (003) jeq #10.0.0.20 jt 6 jf 4 (004) ld [30] Is it first or only frag? (005) jeq #10.0.0.20 xterm jt 6 jf 16 (006) ldb [23] (007) jeq #0X6 jt 8 jf 16 (008) ldh [20] (009) jset #0X1fff jt 16 jf 10 (010) ldxb 4*([14]&0Xf) (011) ldh [X + 14] A: X: (012) jeq #0X14 jt 15 jf 13 (013) ldh [X + 16] (014) jeq #0X14 jt 15 jf 16 (015) ret #65535 packet (016) ret #0 ether IP TCP data EXample (000) ldh [12] FTP data packets (001) jeq #0X800 jt 2 jf 16 (002) ld [26] for host 10.0.0.20 (003) jeq #10.0.0.20 jt 6 jf 4 (004) ld [30] Is it first or only frag? (005) jeq #10.0.0.20 xterm jt 6 jf 16 (006) ldb [23] (007) jeq #0X6 jt 8 jf 16 (008) ldh [20] (009) jset #0X1fff jt 16 jf 10 (010) ldxb 4*([14]&0Xf) (011) ldh [X + 14] A: 0 X: (012) jeq #0X14 jt 15 jf 13 (013) ldh [X + 16] (014) jeq #0X14 jt 15 jf 16 (015) ret #65535 packet (016) ret #0 ether IP TCP data EXample (000) ldh [12] FTP data packets (001) jeq #0X800 jt 2 jf 16 (002) ld [26] for host 10.0.0.20 (003) jeq #10.0.0.20 jt 6 jf 4 (004) ld [30] (005) jeq #10.0.0.20 xterm jt 6 jf 16 Is TCP src port FTP? (006) ldb [23] (007) jeq #0X6 jt 8 jf 16 (008) ldh [20] (009) jset #0X1fff jt 16 jf 10 (010) ldxb 4*([14]&0Xf) (011) ldh [X + 14] A: X: (012) jeq #0X14 jt 15 jf 13 (013) ldh [X + 16] (014) jeq #0X14 jt 15 jf 16 (015) ret #65535 packet (016) ret #0 ether IP TCP data EXample (000) ldh [12] FTP data packets

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    142 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us