January 9, 2001
Router Plugins (Crossbow)
1
Washington
WASHINGTON UNIVERSITY IN ST LOUIS
NetBSD Kernel Topics: IP Processing mbuf structure Loadable Kernel - - PowerPoint PPT Presentation
NetBSD Kernel Topics: IP Processing mbuf structure Loadable Kernel Modules Interrupts Miscellaneous Washington January 9, 2001 Router Plugins (Crossbow) 1 WASHINGTON UNIVERSITY IN ST LOUIS Goals IP Understand the structure of IP
January 9, 2001
Router Plugins (Crossbow)
1
Washington
WASHINGTON UNIVERSITY IN ST LOUIS
January 9, 2001
Router Plugins (Crossbow)
2
Washington
WASHINGTON UNIVERSITY IN ST LOUIS
» accessing src and dst addresses, etc…
» packet size » data location
January 9, 2001
Router Plugins (Crossbow)
3
Washington
WASHINGTON UNIVERSITY IN ST LOUIS
– Everything we talk about will be in terms of IPv4 – Router Plugins also supports IPv6 – The code can be confusing
» use IPv6 structures since they are superset of IPv4
– actually, we’ll talk about some of this…
January 9, 2001
Router Plugins (Crossbow)
4
Washington
WASHINGTON UNIVERSITY IN ST LOUIS
January 9, 2001
Router Plugins (Crossbow)
5
Washington
WASHINGTON UNIVERSITY IN ST LOUIS
January 9, 2001
Router Plugins (Crossbow)
6
Washington
WASHINGTON UNIVERSITY IN ST LOUIS
Derived from Figure 8.7 from Wright/Stevens, Vol. 2
fragment 1 fragment 2 fragment 3
IP UDP application data Application data IP Application data IP
packet
IP UDP application data link link link Application data IP Application data IP
frame
IP
datagram
UDP Application data
message
January 9, 2001
Router Plugins (Crossbow)
7
Washington
WASHINGTON UNIVERSITY IN ST LOUIS
IP Header (with no Options fields) Transport Protocol (e.g. TCP, UDP) Header 8 16 24 31
Vers HLen TOS ID Fragment Offset
Source Address Destination Address
Total length Flags TTL
Protocol
Header Checksum
Source Port . . . Destination Port
Packet Payload
January 9, 2001
Router Plugins (Crossbow)
8
Washington
WASHINGTON UNIVERSITY IN ST LOUIS
ipintrq: ipintr ip_forward ip_output ip6_forward ip6_output atmc_input apic_isr apic_intr ip6_input atmc_output
input packets interrupts
tcp/udp_input tcp/udp_output socket layer apic_devoutput
L I N K D A T A N E T W O R K U P P E R L O W E R
apic_start packet_scheduler PS_Q
T R A N S P O R T
January 9, 2001
Router Plugins (Crossbow)
9
Washington
WASHINGTON UNIVERSITY IN ST LOUIS
ipintrq: ipintr ip_forward ip_output atmc_input apic_isr apic_intr atmc_output
input packets interrupts
tcp/udp_input tcp/udp_output socket layer apic_devoutput
L I N K D A T A N E T W O R K U P P E R L O W E R
User Program
Software Interrupt Waits in Socket Buffer for User Program to pick up
apic_start packet_scheduler PS_Q
T R A N S P O R T
January 9, 2001
Router Plugins (Crossbow)
10
Washington
WASHINGTON UNIVERSITY IN ST LOUIS
T R A N S P O R T
SW Interrupt HW Interrupt
ipintrq: ipintr ip_forward ip_output ip6_forward ip6_output atmc_input apic_isr apic_intr ip6_input atmc_output
input packets interrupts
User Space Kernel
tcp/udp_input tcp/udp_output socket layer apic_devoutput
L I N K D A T A N E T W O R K U P P E R L O W E R
apic_start packet_scheduler PS_Q
sgate dgate
January 9, 2001
Router Plugins (Crossbow)
11
Washington
WASHINGTON UNIVERSITY IN ST LOUIS
– struct ip { } – #define’s
– ipintr() (This is ip_input routine) – ip_forward()
– ip_output()
January 9, 2001
Router Plugins (Crossbow)
12
Washington
WASHINGTON UNIVERSITY IN ST LOUIS
» read INTR_ACK: 0 => not for us, return » apic_isr()
» read NOTIFY_LIST, next rcv channel needing attention
– swap words in each received mbuf (APIC BUG) – link mbufs until we find end of frame – verify CRC (just check flag set by APIC) – atmc_input(packet) – repeat
ipintrq: ipintr ip_forward ip_output atmc_input apic_isr apic_intr atmc_output apic_devoutput
January 9, 2001
Router Plugins (Crossbow)
13
Washington
WASHINGTON UNIVERSITY IN ST LOUIS
» extract type (IP/RATM/…)
» extract length » strip trailer
» aiu_getafix stores a ptr to FTE in packet
ipintrq: ipintr ip_forward ip_output atmc_input apic_isr apic_intr atmc_output apic_devoutput
January 9, 2001
Router Plugins (Crossbow)
14
Washington
WASHINGTON UNIVERSITY IN ST LOUIS
» forward packet ip_forward() -- upcoming slide... » return
ipintrq: ipintr ip_forward ip_output atmc_input apic_isr apic_intr atmc_output apic_devoutput
January 9, 2001
Router Plugins (Crossbow)
15
Washington
WASHINGTON UNIVERSITY IN ST LOUIS
ipintrq: ipintr ip_forward ip_output atmc_input apic_isr apic_intr atmc_output apic_devoutput
Update for Fred’s new Gate also check details of if/when route lookup is done
January 9, 2001
Router Plugins (Crossbow)
16
Washington
WASHINGTON UNIVERSITY IN ST LOUIS
» get route
» ANEP Options
– if DAN then afd_handle_dan_packet() :ACTIVE PROCESSING
ipintrq: ipintr ip_forward ip_output atmc_input apic_isr apic_intr atmc_output apic_devoutput
January 9, 2001
Router Plugins (Crossbow)
17
Washington
WASHINGTON UNIVERSITY IN ST LOUIS
ipintrq: ipintr ip_forward ip_output atmc_input apic_isr apic_intr atmc_output apic_devoutput
January 9, 2001
Router Plugins (Crossbow)
18
Washington
WASHINGTON UNIVERSITY IN ST LOUIS
– IPv6 address structures are a superset of IPv4 – IPv6 address are 128 bits
– e.g. 192.168.5.2 – IPv4 addresses are 32 bits
– Use double colon before address:
– Double colon tells the utilities to set everything to the left to 0’s
January 9, 2001
Router Plugins (Crossbow)
19
Washington
WASHINGTON UNIVERSITY IN ST LOUIS
January 9, 2001
Router Plugins (Crossbow)
20
Washington
WASHINGTON UNIVERSITY IN ST LOUIS
mbuf{}
m_next m_nextpkt m_len m_data m_type m_flags 0-108 MT_xxx
mbuf{}
0-100 MT_xxx
M_PKTHDR
2048-byte cluster mbuf{}
208-2048 MT_xxx
M_EXT
2048
2048-byte cluster mbuf{}
m_pkthdr.len m_pkthdr.rcvif m_ext.ext_buf m_ext.ext_free m_ext.ext_size 208-2048 MT_xxx
M_PKTHDR | M_EXT
2048
Normal mbuf Normal mbuf with Packet Hdr Cluster mbuf Cluster mbuf with Packet Hdr
January 9, 2001
Router Plugins (Crossbow)
21
Washington
WASHINGTON UNIVERSITY IN ST LOUIS
– m_next vs m_nextpkt (figure 2.2 page 35)
» m_next: points to next mbuf in THIS packet » m_nextpkt: points to the first mbuf of the NEXT packet
– m_len vs. m_pkthdr.len – m_ext.ext_buf vs. m_data – Which mbuf structure we use with APIC
– do m_pullup – get data pointer – print out src addr, dst addr and protocol fields – get Transport header pointer – print out dst port Sorry: This was just one
should have been removed before printing
January 9, 2001
Router Plugins (Crossbow)
22
Washington
WASHINGTON UNIVERSITY IN ST LOUIS
mbuf{}
m_next m_nextpkt m_len m_data m_type m_flags MT_DATA
mbuf{}
0-100 MT_xxx
M_PKTHDR
2048-byte cluster mbuf{}
208-2048 MT_xxx
M_EXT
2048
2048-byte cluster mbuf{}
m_pkthdr.len m_pkthdr.rcvif m_ext.ext_buf m_ext.ext_free m_ext.ext_size 208-2048 MT_xxx
M_PKTHDR | M_EXT
2048
Sorry: This was just one
should have been removed before printing
January 9, 2001
Router Plugins (Crossbow)
23
Washington
WASHINGTON UNIVERSITY IN ST LOUIS
mbuf{}
m_next m_nextpkt m_len m_data m_type m_flags MT_DATA m_pkthdr.len
m_pkthdr.rcvif 100 bytes
100 NULL
mbuf{}
m_next m_nextpkt m_len m_data m_type m_flags MT_DATA
50 bytes
50 NULL NULL next mbuf in chain next mbuf in chain next packet in queue
mbuf{}
m_next m_nextpkt m_len m_data m_type m_flags MT_DATA m_pkthdr.len
m_pkthdr.rcvif Ethernet header, IP header, UDP header
M_PKTHDR 192 NULL 42 mbuf packet header head of queue tail of queue
January 9, 2001
Router Plugins (Crossbow)
24
Washington
WASHINGTON UNIVERSITY IN ST LOUIS
mbuf{}
m_next m_nextpkt m_len m_data m_type m_flags MT_HEADER m_pkthdr.len
m_pkthdr.rcvif
M_PKTHDR 1514 NULL 54
mbuf{}
m_next m_nextpkt m_len m_data m_type m_flags MT_DATA m_pkthdr.len
m_pkthdr.rcvif
M_EXT 1460 NULL NULL
Ethernet header, IP header, TCP header
NULL 2048–byte cluster 1460 bytes of data
m_ext.ext_buf m_ext.ext_free m_ext.ext_size 2048
next mbuf in chain mbuf packet header tail of queue
January 9, 2001
Router Plugins (Crossbow)
25
Washington
WASHINGTON UNIVERSITY IN ST LOUIS
January 9, 2001
Router Plugins (Crossbow)
26
Washington
WASHINGTON UNIVERSITY IN ST LOUIS
– modload(8) – modunload(8) – modstat(8)
– System Call modules
» When unloaded, returns to original system call » Any system call can be replace » Take care when replacing ioctl(2) since LKM uses it to load/unload modules!!
– Virtual File System modules – Device Driver modules: Block and character device drivers – Execution Interpreters: For binaries not normally usable by OS – Miscellaneous modules
» No defined interfaces » Up to user/developer to provide hooks to get to the code » This is what Router Plugins uses
January 9, 2001
Router Plugins (Crossbow)
27
Washington
WASHINGTON UNIVERSITY IN ST LOUIS
– ioctl’s will be performed on the open file descriptor
– system(“ld -A /netbsd -e _<entry> -o <outfile> -T <addr=0> <module>”);
– ioctl(lkm_fd, LMRESERV, size_info) – returns kernel load address
– ioctl(lkm_fd, LMLOADBUF, ...)
– ioctl(lkm_fd, LMSTAT, ...)
January 9, 2001
Router Plugins (Crossbow)
28
Washington
WASHINGTON UNIVERSITY IN ST LOUIS
January 9, 2001
Router Plugins (Crossbow)
29
Washington
WASHINGTON UNIVERSITY IN ST LOUIS
– spl0 normal – splsoftclock low-priority clock processing – splnet network protocol processing – spltty terminal I/O – splbio disk and tape I/O – splimp network device I/O – splclock high-priority clock processing – splhigh all interrupts blocked
int i; i = splimp(); [do something at device I/O level] splx(i);
January 9, 2001
Router Plugins (Crossbow)
30
Washington
WASHINGTON UNIVERSITY IN ST LOUIS
January 9, 2001
Router Plugins (Crossbow)
31
Washington
WASHINGTON UNIVERSITY IN ST LOUIS