Transcript 第十九讲
ICMP/ARP和通用链路层
罗忠文
http://xgxy.cug.edu.cn/rjgcx/lzw
内容取自UCB的教程
[email protected]
1
第二部分回答的问题
• 链路层做些什么?
• 怎样做?
• 随机访问将下次讲
2
第一部分回答的问题
• 主机在操作前必须知道什么?
– 本地信息
– 远程信息
• 怎样找到这些信息?
3
获取信息涉及…
• 本地: 引导出一个端主机
– 学习其自身配置参数 (DHCP)
– 学习其他结点的链路层地址(ARP)
• 全局: 网络控制消息
– Internet Control Message Protocol (ICMP)
– 利用ICMP发现Internet路径属性
对不同的环境,有不同的机制
4
Internet versus LAN
• 地址: IP地址 vs MAC 地址 (later)
• 规模: 巨大 vs 有限
• 管理: 临时部署(Ad Hoc) vs 可管理
• 传输模型: 非广播 vs 广播
5
机制适合上下文….
• 本地机制: 广播来发现事情
– “引导指令Bootstrapping”
• 远程机制: 调查路径
– 无法广播到整个网络
– 只能问如何使用已经找到的路由
– “网络控制消息”
6
网络控制消息Network Control Messages
(及如何使用他们来发现)
7
路由器可能看到什么错误?
• 死路: 没有到目标的路由
• 环路信号: TTL超时
• 无法物理转发: 包太大
– 并且设置好DF标志
• 无法跟上流量: 缓冲区溢出
• 头损坏 或 病态包
• ….
8
网络如何响应?
• 没有到目标的路径?
– 主机无法检测或修复路由失效.
• TTL过期?
– 主机无法检测或修复路由环路.
• 包太大 (设置好DF)?
– Host can adjust packet size, but can’t tell
difference between congestion drops and MTU drops
• 缓冲区溢出?
– 传输拥塞控制能检测/处理此
• 头损坏或病态包?
9
– Some format problems, but probably not corruption
路由器响应问题?
• 事实上,路由器不必响应
– 最佳效果意味着你永远不用说抱歉
– 因此, IP只用静悄悄地丢弃包
• 网络已经尽其最大努力了
– 路由已经想办法避免环路/死路
– 网络可以减少包尺寸大小 (在DF包中)
– 网络无法减少负载, 也不能修复格式问题
• 还需要多做些什么?
10
错误报告有助于调试
• 静默失败非常难于诊断
• IP包括对于网络问题的反馈机制,因此他们不会不被
检测到
• Internet Control Message Protocol (ICMP)
• Internet “输出print”陈述
• 在IP上运行,但被看成是IP的组成部分
11
Internet Control Message Protocol
• 当IP包遇到问题时触发
– 如, 超时 或 目标不可达
• ICMP包发回到源IP地址
– 包括错误信息 (如, 类型和代码)
– IP头加上源包的8+字节摘要
• 源主机接收到ICMP包
– 检查摘要 (如, 协议/端口)以确定套接字
• 例外: 如果问题包是ICMP不发送
– 且只对片段组的片段0
12
控制消息的类型
• 需要分块
– IP包对链路层太大, 设置数据分块(DF)
• TTL过期
– 每跳减一; 如果是0时产生
• 不可达
– 子类型: 网络 / 主机 / 端口
o (谁产生端口不可达?)
• 源减速
– Old-style signal asking sender to slow down
• Redirect
– Tells source to use a different local router
13
Using ICMP
• ICMP intended to tell host about network
problems
– Diagnosis
– Won’t say more about this….
• Can exploit ICMP to elicit network
information
– Discovery
– Will focus on this….
14
Discovering Network Path Properties
• 发现PMTU: 不用分块能在网络中发送的最大
包?
– Most efficient size to use
– (Plus fragmentation can amplify loss)
• Traceroute:
–包在遍历网络时,经过了哪些路由器?
• Ping:
– Simple RTT measurements
15
Ping: Echo and Reply
• ICMP includes simple “echo” functionality
– Sending node sends an ICMP Echo Request message
– Receiving node sends an ICMP Echo Reply
• Ping tool
– Tests connectivity with a remote host
– … by sending regularly spaced Echo Request
– … and measuring delay until receiving replies
16
Path MTU Discovery
• MTU = Maximum Transmission Unit
– Largest IP packet that a link supports
• Path MTU (PMTU) = minimum end-to-end MTU
– Must keep datagrams no larger to avoid
fragmentation
• How does the sender know the PMTU is?
• Strategy (RFC 1191):
– Try a desired value
– Set DF to prevent fragmentation
– Upon receiving Need Fragmentation ICMP …
o … oops, that didn’t work, try a smaller value
17
Issues with Path MTU Discovery
• What set of values should the sender try?
– Usual strategy: work through “likely suspects”
– E.g., 4352 (FDDI), 1500 (Ethernet), 1480 (IP-in-IP
over Ethernet), 296 (some modems)
• What if the PMTU changes? (how could it?)
– 发送端将立即看到PMTU减少 (怎样?)
– Sender can periodically try larger values
• What if Needs Fragmentation ICMP is lost?
– Retransmission will elicit another one
• How can The Whole Thing Fail?
– “PMTU 黑洞”: routers that don’t send the ICMP
18
Discovering Routing via Time Exceeded
• Host sends an IP packet
– Each router decrements the time-to-live field
• If TTL reaches 0
– Router sends Time Exceeded ICMP back to the source
– Message identifies router sending it
o Since ICMP is sent using IP, it’s just the IP source
address
o And can use PTR record to find name of router
5.6.7.156
1.2.3.7
host
host
...
DNS
host
host
...
DNS
8.9.10.11
Time exceeded
router
router
router
19
Traceroute: Exploiting Time Exceeded
• Time-To-Live field in IP packet header
– Source sends a packet with TTL ranging from 1 to n
– Each router along the path decrements the TTL
– “TTL exceeded” sent when TTL reaches 0
• Traceroute tool exploits this TTL behavior
TTL=1
source
Time
exceeded
destination
TTL=2
Send packets with TTL=1, 2, …
and record source of Time Exceeded message
20
traceroute to www.whitehouse.gov (204.102.114.49),
30 hops max, 40 byte packets
21
traceroute to www.whitehouse.gov (204.102.114.49),
30 hops max, 40 byte packets
1 cory115-1-gw.EECS.Berkeley.EDU (128.32.48.1)
0.829 ms 0.660 ms 0.565 ms
22
traceroute to www.whitehouse.gov (204.102.114.49),
30 hops max, 40 byte packets
1 cory115-1-gw.EECS.Berkeley.EDU (128.32.48.1)
0.829 ms 0.660 ms 0.565 ms
2 cory-cr-1-1-soda-cr-1-2.EECS.Berkeley.EDU (169.229.59.233)
0.953 ms 0.857 ms 0.727 ms
23
traceroute to www.whitehouse.gov (204.102.114.49),
30 hops max, 40 byte packets
1 cory115-1-gw.EECS.Berkeley.EDU (128.32.48.1)
0.829 ms 0.660 ms 0.565 ms
2 cory-cr-1-1-soda-cr-1-2.EECS.Berkeley.EDU (169.229.59.233)
0.953 ms 0.857 ms 0.727 ms
3 soda-cr-1-1-soda-br-6-2.EECS.Berkeley.EDU (169.229.59.225)
1.461 ms 1.260 ms 1.137 ms
4 g3-8.inr-202-reccev.Berkeley.EDU (128.32.255.169)
Lost Reply
1.402 ms 1.298 ms *
5 ge-1-3-0.inr-002-reccev.Berkeley.EDU (128.32.0.38)
1.428 ms 1.889 ms 1.378 ms
6 oak-dc2--ucb-ge.cenic.net (137.164.23.29)
1.731 ms 1.643 ms 1.680 ms
7 dc-oak-dc1--oak-dc2-p2p-2.cenic.net (137.164.22.194)
3.045 ms 1.640 ms 1.630 ms
8***
Router doesn't send ICMPs
9 dc-lax-dc1--sac-dc1-pos.cenic.net (137.164.22.126)
13.104 ms 13.163 ms 12.988 ms
No PTR record for address
10 137.164.22.21 (137.164.22.21)
Final Hop
13.328 ms 42.981 ms 13.548 ms
11 dc-tus-dc1--lax-dc2-pos.cenic.net (137.164.22.43)
18.775 ms 17.469 ms 21.652 ms
12 a204-102-114-49.deploy.akamaitechnologies.com (204.102.114.49)
18.137 ms 14.905 ms 19.730 ms
24
traceroute: Warning: www.whitehouse.gov has multiple addresses; using 192.80.13.27
traceroute to a1128.h.akamai.net (192.80.13.27), 64 hops max, 52 byte packets
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
10.0.1.1 (10.0.1.1)
1.041 ms 0.768 ms 0.625 ms
71.202.16.1 (71.202.16.1)
40.825 ms 30.927 ms 29.656 ms
te-5-3-ur04.santaclara.ca.sfba.comcast.net (68.85.191.53)
10.468 ms 11.817 ms 13.412 ms
te-1-10-0-5-ar01.oakland.ca.sfba.comcast.net (68.85.155.70)
11.269 ms 12.876 ms 12.936 ms
pos-2-1-0-0-cr01.sacramento.ca.ibone.comcast.net (68.86.90.141)
14.421 ms 14.668 ms 16.512 ms
pos-0-6-0-0-cr01.sanjose.ca.ibone.comcast.net (68.86.86.202)
17.841 ms 14.680 ms 14.067 ms
pos-0-0-0-0-pe01.529bryant.ca.ibone.comcast.net (68.86.86.122)
15.069 ms 33.037 ms 19.237 ms
ix-2-3-0-0.tcore1.pdi-paloalto.as6453.net (66.198.127.17)
36.988 ms 15.295 ms 16.306 ms
if-2-2.tcore2.pdi-paloalto.as6453.net (66.198.127.2)
27.754 ms 16.269 ms 16.232 ms
vlan3254.icore1.sqn-sanjose.as6453.net (66.198.144.6)
32.776 ms 18.098 ms 18.946 ms
vlan507.icore1.sqn-sanjose.as6453.net (209.58.116.22)
27.460 ms 47.844 ms 29.565 ms
ae-6.r20.snjsca04.us.bb.gin.ntt.net (129.250.5.12)
28.915 ms 24.836 ms 25.166 ms
ae-4.r20.sttlwa01.us.bb.gin.ntt.net (129.250.3.52)
41.736 ms 34.092 ms 34.564 ms
ae-1.r05.sttlwa01.us.bb.gin.ntt.net (129.250.5.47)
36.052 ms 37.417 ms 35.456 ms
192.80.13.27 (192.80.13.27)
35.653 ms 34.173 ms 35.770 ms
25
Questions to be answered in 1st half
• What must a host know before it can operate?
– Local information
– Remote information
• How do you avoid manual configuration?
– Management: most important issue in networking today!
• How can host learn about local network?
• How can host learn about the rest of the Internet?
26
1st
Half Answers Involve….
• Bootstrapping an end host (local)
– Learning its own configuration parameters (DHCP)
– Learning the link-layer addresses of other nodes (ARP)
• Network control messages (global)
– Internet Control Message Protocol (ICMP)
– Exploiting ICMP for discovering Internet path properties
27
Bootstrapping a Host
28
A Few Facts About the Link-Layer
Since much of bootstrap depends on
it
29
Sending Packets Over Link-Layer
1.2.3.53
host
1.2.3.156
host
...
DNS
IP packet
1.2.3.53
1.2.3.156
router
• Adaptors only understand MAC addresses
– Translate the destination IP address to MAC
address
– Encapsulate the IP packet inside a link-level
frame
30
MAC Address vs. IP Address
• MAC addresses (used in link-layer)
– 在网卡制造时硬编码到只读存储器中
– Like a social security number
– 48位平名字空间 (e.g., 00-0E-9B-6E-49-76)
– Portable, and can stay the same as the host moves
– 用于在同一网络中的接口间得到包
• IP地址
– Configured, or learned dynamically
– Like a postal mailing address
– 32位层次名字空间 (e.g., 12.178.66.9)
– Not portable, and depends on where the host is
attached
– Used to get a packet to destination IP subnet 31
Broadcast at Link-Level
• Use broadcast address: ff:ff:ff:ff:ff:ff
• If have return MAC address, use that in
response
• Unless want everyone to know result
32
Broadcast at IP Level
• Can't broadcast to all IP hosts
• But application might want to send “local”
broadcast
• Uses IP broadcast address 255.255.255.255
• Link-layer then uses link-layer broadcast
33
5 Minute Break
34
Bootstrapping a Host
35
Take a few minutes to think….
• How does a packet get from your dorm to CNN?
– What are the steps?
– Two kinds of steps….
• Sending packets
– Goes on local ethernet (sent to whom?)
– Then goes to Internet as a whole
• Getting addresses
– How do you get needed MAC addresses?
• Let’s go through step by step….
– Hint: you will have to on final, in great
detail….
36
Reaching a Host
• First look up IP address
• Need to know where local DNS server is
– How does a host know this?
• Also needs to know its own IP address
– How does a host know this?
37
Sending a Packet
• On same subnet:
– Use MAC address of destination
– How do a host know that?
• On some other subnet:
– Use MAC address of first-hop router
– How do a host know that?
• And how can a host tell whether destination
is on same or other subnet?
– Use the netmask
– How does a host know that?
38
What Does a Host Need to Know?
• What IP address the host should use?
• What local DNS server to use?
• How to tell which destinations are local?
• How do we address them using local network?
• How to send packets to remote destinations?
??? 1.2.3.7 1.2.3.156
host
host
...
DNS
host
host
...
DNS
5.6.7.0/24
1.2.3.0/23
1.2.3.19
router
router
router
39
Avoiding Manual Configuration
• Dynamic Host Configuration Protocol (DHCP)
– End host learns how to send packets
– Learn IP address, DNS servers, “gateway”,
what’s local
• Have already described DHCP operation
– Sequence of broadcasts, no configuration needed
1.2.3.48 1.2.3.7 1.2.3.156
host
host
1.2.3.0/23
255.255.254.0
...
DNS 1A-2F-BB-76-09-AD
host
host
...
DNS
5.6.7.0/24
1.2.3.19
router
router
router
40
DHCP Supplies Basic Information
• IP address
• Mask
• Gateway router
• DNS server
• Now what?
41
Sending A Packet: Which Destination?
• If destination is on the local network
– Need to address it directly (MAC address)
• If destination is not local (“remote”)
– Need to figure out the first “hop” on the local
network
– Need MAC address of first hop router
1.2.3.48 1.2.3.7 1.2.3.156
host
host
1.2.3.0/23
255.255.254.0
...
DNS 1A-2F-BB-76-09-AD
host
host
...
DNS
5.6.7.0/24
1.2.3.19
router
router
router
42
Determining if Address is Local
• Use the netmask
– E.g., mask destination IP address w/ 255.255.254.0
• Is it same value as our own masked address?
o Yes = local
o No = remote
1.2.3.48 1.2.3.7 1.2.3.156
host
host
1.2.3.0/23
255.255.254.0
...
DNS 1A-2F-BB-76-09-AD
host
host
...
DNS
5.6.7.0/24
1.2.3.19
router
router
router
43
In Both Cases, Need to Send Locally
• If it’s remote, look up first hop in (very
small) local routing table
– E.g., by default, route via 1.2.3.19
– Now do the local case but for 1.2.3.19 rather than
ultimate destination IP address
1.2.3.48 1.2.3.7 1.2.3.156
host
host
1.2.3.0/23
255.255.254.0
...
DNS 1A-2F-BB-76-09-AD
host
host
...
DNS
5.6.7.0/24
1.2.3.19
router
router
router
• For the local case, need to determine the
destination’s MAC address
44
Address Resolution Protocol
• Every node maintains an ARP table
– <IP address, MAC address> pair
• Consult the table when sending a packet
– Map destination IP address to destination MAC
address
– Encapsulate and transmit the data packet
• But: what if IP address not in the table?
– Sender broadcasts: “Who has IP address
1.2.3.156?”
– Receiver responds: “MAC address 58-23-D7-FA-20B0”
45
– Sender caches result in its ARP table
Example: A Sending a Packet to B
How does host A send an IP packet to host B?
A
R
B
Take a few minutes, break into groups,
figure out how this would work…..
46
Example: A Sending a Packet to B
How does host A send an IP packet to host B?
A
R
B
1. A sends packet to R.
2. R sends packet to B.
47
Host A Decides to Send Through R
• Host A constructs an IP packet to send to B
– 源111.111.111.111, 目的 222.222.222.222
• Host A has a gateway router R
– 用于到达 111.111.111.0/24之外的目的地址
– R的地址111.111.111.110 通过DHCP学到
A
R
B48
Host A Sends Packet Through R
• 主机A学习R接口的MAC地址
– ARP 请求: broadcast request for 111.111.111.110
– ARP 响应: R responds with E6-E9-00-17-BB-4B
• Host A encapsulates the packet and sends to R
A
R
B49
R Decides how to Forward Packet
• Router R’s adaptor receives the packet
– R extracts the IP packet from the Ethernet frame
– R 看到IP 包的目标是 222.222.222.222
• 路由器R consults its forwarding table
– Packet matches 222.222.222.0/24 via other adaptor
A
R
B50
R Sends Packet to B
• Router R’s learns the MAC address of host B
– ARP request: broadcast request for 222.222.222.222
– ARP response: B responds with 49-BD-D2-C7-56-2A
• 路由器R封包并发送到B
A
R
B51
Security Analysis of ARP
• Impersonation
– Any node that hears request can answer …
– … and can say whatever they want
• Actual legit receiver never sees a problem
– Because even though later packets carry its IP
address, its NIC doesn’t capture them since not
its MAC address
52
Key Ideas in Both ARP and DHCP
• 广播: Can use broadcast to make contact
– Scalable because of limited size
• Caching: remember the past for a while
– Store the information you learn to reduce overhead
– 记住你自己的地址和其它主机的地址
• 软状态: eventually forget the past
– 对信息关联一个存活时间字段
– … and either refresh or discard the information
– Key for robustness in the face of unpredictable
change
53
Why Not Use DNS-Like Tables?
• When host arrives:
– 指定一个IP地址,其存活期为只要还在就存活
– 在DNS服务器的表中加入一项,映射MAC到IP地址
• 考虑几分钟, 小组讨论
• Answer:
– Names: explicit creation, and are plentiful
– Hosts: come and go without informing network
o Must do mapping on demand
– Addresses: not plentiful, need to reuse and remap
o Soft-state enables dynamic reuse
54
Link-Layer Services
55
Message, Segment, Packet, and Frame
host
host
HTTP message
HTTP
TCP segment
TCP
router
IP
Ethernet
interface
HTTP
IP packet
Ethernet
interface
Ethernet frame
IP
TCP
router
IP packet
SONET
interface
SONET
interface
SONET frame
IP
IP packet
Ethernet
interface
IP
Ethernet
interface
56
Ethernet frame
Focus on Link-Layer
Ethernet
interface
Ethernet
interface
Ethernet frame
SONET
interface
SONET
interface
Ethernet
interface
SONET frame
Ethernet
interface
Ethernet frame
• What functions these technologies provide
• How they implement those functions
• Speaking generally today, focus on Ethernet on Wed.
57
Adaptor-to-Adaptor Communication
datagram
link layer protocol
frame
sending
node
adaptor
frame
adaptor receiving
node
• Link layer implemented in adaptor (network interface card; NIC)
– Ethernet card, 802.11 card (why?)
• Sending side:
– Encapsulates datagram in a frame
– Determines local addressing, adds error checking, controls
transmission
• Receiving side
– Recognizes arrival, looks for errors, possibly acknowledges
– Extracts datagram and passes to receiving node
58
Link-Layer Services
• Encoding
– Representing the 0s and 1s
• Framing
– 封包到帧, 添加头, 尾
– Using MAC addresses rather than IP addresses
• Error detection
– Errors caused by signal attenuation, noise
– 接收端检测存在性, 可能会请求特殊性 (ARQ)
• Resolving contention
– Deciding who gets to transmit when multiple
senders want to use a shared media
• 流控制 (pacing between sender & receiver) 59