Packet Through The Linux Network Stack
Packet Through The Linux Network Stack
Packet Through The Linux Network Stack
Assume IP version 4
Codes are from Kernel 2.6.9.EL
(use in Lab 9)
Ideas are similar
Linux High-Level Network Stack
Interface to users
TCP/UDP/IP etc…
Network card
receives a frame
issues an Driver
interrupt handles the interrupt
•Frame RAM
•Allocates sk_buff
(called skb)
•Frame skb
Aside: sk_buff (skbuff.h)
CPU
calls core/dev.c:net_rx_action()
calls calls
ip_rcv_finish() route.c:ip_route_input()
Aside: Finish/Slow suffix
Destination == me?
YES ip_input.c:ip_local_deliver()
NO Calls ip_route_input_slow()
ipv4/route.c:ip_route_input_slow()
Can forward?
•Forwarding enabled?
•Know route?
NO Sends ICMP
Forwarding a Packet
•/proc/sys/net/ipv4/conf/<device>/forwarding
•/proc/sys/net/ipv4/conf/default/forwarding
•/proc/sys/net/ipv4/ip_forwarding
Forwarding a Packet (cont.)
ipv4/ip_forward.c:ip_forward()
IP TTL > 1
YES Decreases TTL
NO Sends ICMP
core/dev.c:dev_queue_xmit()
Default queue: priority FIFO
sched/sch_generic.c:pfifo_fast_enqueue()
Others: FIFO, Stochastic Fair Queuing, etc.
Priority Based Output Scheduling
pfifo_fast_enqueue()
Again, per-device basis
Queue Discipline (Qdisc: pkt_sched.c)
Not exactly a priority queue
Uses three queues (bands)
0 “interactive”
1 “best effort”
2 “bulk”
IP ToS: PPPDTRCX
PPP Precedence
Linux = ignore!
Cisco = Policy-Based Routing (PBR)
D Minimizes Delay
T Maximizes Throughput
R Maximizes Reliability
C Minimizes Cost
X Reserved
Mapping IP ToS to Queue (cont.)
IP ToS Band
0x0 1
pfifo_fast_enqueue()
0x2 2 maps IP ToS to one of
0x4
0x6
2
2
three queues
0x8 1 IP ToS: PPPDTRCX
0xA 2
0xC 0 Mapping array: prior2band
0xE 0
0x10 1
0x12 1
0x14 1
0x16 1
0x18 1
0x1A 1
0x1C 1
0x1E 1
Queue Selection
Change band
Queue Selection (cont.)
Kernel 2.6.9.EL
Qdisc
…
Sending Out a Packet
pfifo_fast_dequeue()
Removes the oldest packet from the
highest priority band
The packet that was just enqueued!
Passes it to the device driver
Lab 9
Scenario
Destination
Linux Router
(Your HDD)
Virtual 1 Virtual 2
Lab 9 Part 2
Default: no IP forwarding
Enable it! /proc/…
Only one router
Default route on “destination”
Lab 9 Part 2
Route???
ping reply
Destination
Linux Router
(Your Linux)
ping echo
Virtual 1 Virtual 2
Lab 9 Part 3
Scenario
Destination
Linux Router
(Your Linux)
Virtual 1 Virtual 2
Lab 9 Part 3 (cont.)
TCP
UDP
Lab 9 Part 5 (cont.)
Lab 9 Part 5 (cont.)
Queue Discipline
http://linux-ip.net/articles/Traffic-Control-HOWTO/classless-qdiscs.html