Fall 2014:: CSE 506:: Section 2 (PhD)
Linux Networking
Nima Honarmand (Based on slides by Don Porter and Mike Ferdman)
Linux Networking Nima Honarmand (Based on slides by Don Porter and - - PowerPoint PPT Presentation
Fall 2014:: CSE 506:: Section 2 (PhD) Linux Networking Nima Honarmand (Based on slides by Don Porter and Mike Ferdman) Fall 2014:: CSE 506:: Section 2 (PhD) 4- to 7-Layer Diagram Used in Read World OSI and TCP/IP Stacks (From Understanding
Fall 2014:: CSE 506:: Section 2 (PhD)
Nima Honarmand (Based on slides by Don Porter and Mike Ferdman)
Fall 2014:: CSE 506:: Section 2 (PhD)
OSI and TCP/IP Stacks (From Understanding Linux Network Internals)
Used in Read World
Fall 2014:: CSE 506:: Section 2 (PhD)
– Header
– Data block (payload) – Checksum
Fall 2014:: CSE 506:: Section 2 (PhD)
Source: http://www.industrialethernetu.com/courses/401_3.htm
Fall 2014:: CSE 506:: Section 2 (PhD)
coax cable)
– Hardware filters out traffic intended for other hosts
– Can be put in “promiscuous” mode
– Hardware automatically retries after a random delay
Fall 2014:: CSE 506:: Section 2 (PhD)
switched
– Both are boxes that link multiple computers together – Hubs broadcast to all plugged-in computers
– Switches track who is plugged in
Fall 2014:: CSE 506:: Section 2 (PhD)
– Version 4 widely used in practice – Version 6 should be used in practice – but isn’t
– Along with netmask – Netmask determines if IP is on local LAN or not
– Packet sent to LAN’s gateway – At each gateway, payload sent to next hop
Fall 2014:: CSE 506:: Section 2 (PhD)
– And switch needs to know which port to send it to
– “physical” address of the NIC
– Broadcast “who has 10.22.17.20” on the LAN – Whoever responds is the physical location
– ARP responses cached to avoid lookup for each packet
Fall 2014:: CSE 506:: Section 2 (PhD)
– A simple integer – Multiplexes many applications on one device – Ports below 1k reserved for privileged applications
– Send packet, receive packet – No association between packets in underlying protocol
Fall 2014:: CSE 506:: Section 2 (PhD)
– But different ports – i.e., TCP port 22 isn’t the same port as UDP port 22
– Transparent to applications – Lots of features
– Pretty complicated
Fall 2014:: CSE 506:: Section 2 (PhD)
From Understanding Linux Network Internals
Fall 2014:: CSE 506:: Section 2 (PhD)
– Or IP or TCP packets
– Stream of messages or bytes between two applications – Applications specify protocol (TCP or UDP), remote IP address and port number
connection (Server)
– All headers are added/stripped by OS
Fall 2014:: CSE 506:: Section 2 (PhD)
– So are TCP, UDP, and IP
– Application not involved in TCP ACKs, retransmit, etc.
– Kernel trusted with correct delivery of packets
– sys_socketcall(call, args)
Fall 2014:: CSE 506:: Section 2 (PhD)
– Passed through a stack of protocol handlers – Handlers update bookkeeping, wrap headers, etc.
– Sends/receives packets on the wire
Fall 2014:: CSE 506:: Section 2 (PhD)
is better than removing headers
headers is more efficient than re-copy
head/end vs. data/tail pointers in sk_buff (From Understanding Linux Network Internals)
Fall 2014:: CSE 506:: Section 2 (PhD)
Source: http://www.cs.unh.edu/cnrg/people/gherrin/linux-net.html
Fall 2014:: CSE 506:: Section 2 (PhD)
– Allocate/get a buffer (sk_buff) – Copy received data into the buffer – Initialize a few fields – Call “bottom half” handler
– Systems allocate ring of sk_buffs and give to NIC – Just “take” the buff from the ring
Fall 2014:: CSE 506:: Section 2 (PhD)
– Use to trigger the “top half” handler from IDT
– Or, “bottom half”
– To minimize time in an interrupt handler with other interrupts disabled – Simplifies service routines (defer complicated operations to a more general processing context)
– Gives kernel more scheduling flexibility
Fall 2014:: CSE 506:: Section 2 (PhD)
– Two canonical ways: Softirq and Tasklet – More general than just networking
– Tuples of <function, data>
– Right time: Return from exceptions/interrupts/syscalls – Each CPU also has a kernel thread ksoftirqd_CPU#
nothing else to do
Fall 2014:: CSE 506:: Section 2 (PhD)
time
– Doesn’t need to be reentrant
– Need to be thread-safe
Fall 2014:: CSE 506:: Section 2 (PhD)
– For the faint of heart (and faint of locking prowess)
– Useful for poorly synchronized device drivers
– Downside: All tasklets are serialized
Fall 2014:: CSE 506:: Section 2 (PhD)
– Pass a copy to any taps (sniffers) – Do any MAC-layer processing, like bridging – Pass a copy to the appropriate protocol handler (e.g., IP)
Fall 2014:: CSE 506:: Section 2 (PhD)
– Check to see if a task is blocked on input for this socket
Fall 2014:: CSE 506:: Section 2 (PhD)
– Allocate sk_buff for data – Be sure to leave plenty of head and tail room!
– Receive handling not counted toward app
– Interrupt handler just frees the sk_buff
Fall 2014:: CSE 506:: Section 2 (PhD)
frequency?
– You spend all of your time handling interrupts!
progress
– Because spends all of its time starting to process new packets – Bottom halves never execute
just the top half on a million
Fall 2014:: CSE 506:: Section 2 (PhD)
Source: Mogul & Ramakrishnan, ToCS, Aug 1997
Ideal
Fall 2014:: CSE 506:: Section 2 (PhD)
some
– Stop taking packets off of the network card
Fall 2014:: CSE 506:: Section 2 (PhD)
– Ask if there is more work once you’ve done the first batch
– And the application, and then get a response back out
Fall 2014:: CSE 506:: Section 2 (PhD)
– If incoming traffic is rare, want high-priority
Fall 2014:: CSE 506:: Section 2 (PhD)
– Interrupts are better
– Polling is better
Fall 2014:: CSE 506:: Section 2 (PhD)
– Inherently rate limited
– It can’t issue more
Fall 2014:: CSE 506:: Section 2 (PhD)
– Passes packets received by the device to kernel
softirq
– Can disable the interrupt under heavy loads
– Bonus: Some NICs have a built-in timer
– Under heavy-load, device will overwrite some packets