Outline: Linux Architecture
- Linux overview
- overall architecture
- networking
- comparison to X-kernel, Xinu
- organization
- packet send, receive walkthrough
Linux Overview
- ancestry:
- Unix (Bell Labs): system calls, utilities
- Unix (Berkeley): networking, utilities
- Unix (Posix): standardization, modules?
- X windows: window system
- GNU: open source, gcc, utilities
- Minix: open source, initial impetus
- contributions:
- free Unix -- unlocking the monopoly?
- Open Source movement, BSDI, Free BSD
- hardware-independent Unix (unlike Solaris, Ultrix, SCO, etc)
- teaching, self-teaching, hacker toy
Overall Architecture
- system calls: access to the OS from the application
- interrupts: access to the OS from the hardware
- separate address space for each process, one address space for kernel
- Unix-like file system, device files ("/dev"), configuration
- "/proc" file system for user/application access
to kernel variables (kernel state)
Linux Networking
- three layers (two context switches) on receive:
- interrupt handler
- data link (ethernet, FDDI, slip, etc), IP, transport (TCP, UDP)
- application
- two layers on send:
- application, transport, IP, data link
- interrupt handler
Comparison to Xinu
| Xinu | Linux |
|
purpose: | education | free OS |
|
OS: | primary goal | primary goal |
|
layers: | few | two/three |
|
upcalls: | UPD, ICMP | transport |
|
receive: | queues, downcalls | queues, downcalls |
|
| context switches | context switches |
|
threads: | long-lived | long-lived |
|
messages: | contiguous | contiguous |
|
proj life: | decade+ | half decade |
|
|
Comparison to X-kernel
| x-kernel | Linux |
|
purpose: | research | free OS |
|
OS: | marginal | primary goal |
|
layers: | many | few |
|
upcalls: | pervasive | two/three |
|
receive: | upcalls | queues, downcalls |
|
| | context switches |
|
threads: | packet lifetime | long-lived |
|
messages: | gather-write | contiguous |
|
proj life: | half-decade | half decade |
|
|
Linux Organization
- Linux source code at
http://www.ics.hawaii.edu/~esb/1999spring.ics651/linux
(without SCSI or sound drivers, alpha, M68K, MIPS)
- include/linux/skbuff.h, net/core/skbuff.c: socket buffers
- include/net/sock.h: struct sock
- drivers/net/Space.c: device configuration
- drivers/net/slip.c: simple device
- drivers/net/eexpress.h: ethernet device
Linux Organization, continued
- net/core/dev.c: device management, reading, writing:
- do_dev_queue_xmit: put a packet in a device queue, cause
an interrupt
- netif_rx: find the appropriate queue for an incoming packet
(called by interrupt handler)
- net/ethernet/eth.c: ethernet header
- net/ipv4/*: IP, TCP, UDP
- ip_input.c: read queue, dispatch packet
- ip_output.c: fill in IP header fields
- ip_masq*: IP masquerading (firewall)
- tcp_input.c: TCP input processing
- tcp.c: application-level TCP interface
UDP/IP/Ethernet packet receive
- eexp_irq handles interrupt, calls
eexp_hw_rx_pio to find out which buffers contain data, create
skbuffers pointing to them, then calls netif_rx to queue the buffer
and mark_bh to tell the kernel to execute net_bh
- the kernel calls net_bh, which transmits any pending packets,
removes packets from the queue, and delivers it to all the upcalls that
handle this protocol type
- the upcall for IP is ip_rcv, which after sanity
checks upcalls the transport-level handler
- the UDP upcall is udp_rcv, which finds the appropriate
socket structure and calls udp_deliver which queues the packet
- UDP receive is done by udp_recvmsg, which calls
skb_recv_datagram to blocks if needed. udp_recvmsg then
copies the datagram to user space and returns
UDP/IP/Ethernet packet send
- udp_sendmsg calls
udp_sendto calls
udp_send after locking the socket
- udp_send fills in the UDP and pseudo headers, and calls
ip_build_xmit
- ip_build_xmit fills in the IP header, copies the data
to an skbuffer, and calls dev_queue_xmit, which enters a critical
section in which it calls do_dev_queue_xmit
- do_dev_queue_xmit puts a packet into a device queue and
starts the hardware (dev->hard_start_xmit(skb, dev))