ch. 8 ip : internet protocol 안 진 섭 jinsurby@hufs.ac.kr tcp/ip illustrated vol.2
Post on 13-Dec-2015
226 Views
Preview:
TRANSCRIPT
Ch. 8 IP : Internet ProtocolCh. 8 IP : Internet Protocol
안 진 섭jinsurby@hufs.ac.kr
TCP/IP Illustrated Vol.2
Page 2
Contents 8.1 Introduction 8.2 Code Introduction 8.3 IP packets 8.4 Input Processing : ipintr function 8.5 Forwarding : ip_forward function 8.6 Output Processing : ip_output function 8.7 Internet checksum : in_cksum function 8.8 setsockopt and getsockopt System calls 8.9 ip_sysctl function 8.10 Summary
Page 3
8.1 Introduction Network interface : IP input queue 에 que
uing (ipintrq, software interrupt, Ch.4) ipintr() 은 ‘ ipintrq’ 가 empty 상태가 될
때까지 packet 을 remove 또는 processes
Final destination 일 경우 packet 을 datagram 으로 변환 후 transport
-level protocol 에 전달 Router 이고 , Final destination 이 아닐경우
ip_forward() 에게 전달 Transport protocol 과 ip_forward() 는 o
utgoing packet 을 ip_output() 에게 전달 IP header selects
Output interface Fragment the outgoing packet(if necessary)
IP 는 error 가 발생할 경우 packet 을 버리고 , packet 의 source 에게 error message 전송 (ICMP, Ch. 11)
Page 4
8.2 Code introduction (1/4)
Global variables
Page 5
8.2 Code introduction (2/4) Statistics
Ip_var.h
Page 6
8.2 Code introduction (3/4) eg.) IP statistics
Page 7
8.2 Code introduction (4/4) SNMP variable
Page 8
8.3 IP packets (1/2) UDP 로 application data 를 전달할 때 3 개의 IP
packet 으로 fragmentation 되는 예제
Page 9
8.3 IP packets (2/2) IP header
Figure 8.9 ip structure
ip.h
Page 10
8.4 Input processing : ipintr (1/8)
네트워크 인터페이스가 protocol processing 을 위해 incoming datagram 을 queuing 하는 절차
Ethernet interface 는 ethernet header 의 type field 에 따라 incoming frame 을 demultiplex (Section 4.3)
SLIP interface 는 IP packet 만 지원하기 때문에 demultiplexing 절차가 필요없음 (Section 5.3)
Loopback interface 는 looutput() 에서 output/input processing 을 하고 , destination address 의 sa_family 로 datagram 을 demultiplex
ipintr overview Verification of incoming packets Option processing and forwarding Packet reassembly Demultiplexing
Page 11
8.4 Input processing : ipintr (2/8)
/* input packet processing *//* Figures 8.12, 8.13, 8.15, 10.11, and 12.40 */
Figure 8.11 ipintr function Ip_input.c
// take the first packet off the ifq queue (p.72)
// m = 0 일 때까지 반복하기 위해 jump// 잘못된 IP packet 일 경우 discard
// free all the mbufs in the chain pointed by m
Page 12
8.4 Input processing : ipintr (3/8) Verification
Figure 8.12 ipintr function
Ip_input.c
// 잘못된 IP packet 일 경우 discard(mbuf 해제후 next 로 jump)
// total packets received
// 첫번째 mbuf 의 길이가 IP header 를 수용하지 못할 때 (Ch.2 mbuf)
// memory to data (type cast the pointer to the data area of the mbuf pointed to by m to type)// IP version 이 맞는가 ?
// IP header 의 header length 를 2 bits shifting ( 실제 IP header 의 length 를 저장 )// header length 와 struct ip 와의 크기 비교
// IP checksum 이 맞는가 ?
// reallocates the standard header into a contiguous area of memory
Page 13
8.4 Input processing : ipintr (4/8) Verification (con’t)
Figure 8.12 ipintr function
Ip_input.c
// network byteorder host byteorder// IP total length < IP header 인가 ?
// network byteorder host byteorder 변환
// m_pkthdr.len : the amount of data stored in the mbuf chain
// ip_len : logical size of the packet
// logical size 와 mbuf chain 에 저장된 data size 의 비교
// IP packet 이 minimum size(512bits) 보다 작을 경우 추가되는 extra byte 를 제거
// remove len bytes of data from the mbuf chain pointed by m
Page 14
8.4 Input processing : ipintr (5/8)
// ip_dooptions : IP option 처리 (ch. 9)
To forward or not forward ?
Figure 8.13 ipintr functionIp_input.c
Page 15
8.4 Input processing : ipintr (6/8)
Figure 8.13 ipintr function
// addresses list 를 반복// addresses list 상의 address 와 IP packet 의 destination address 와 일치하는가 ?
To forward or not forward ? (con’t)
// broadcast address 와 일치 ?
// net-directed broadcast address 와 일치 ?
// subnet-directed broadcast address 와 일치 ?
Page 16
8.4 Input processing : ipintr (7/8)
To forward or not forward ? (con’t)
/* multicast code (Figure 12.39) */
// ip packet forwarding 이 enable 되었는가 ?
// 해당 mbuf 해제
// ip_forward() 에게 mbuf pointer 전달
// destination IP address 가 255.255.255.255 인 경우
// destination IP address 가 0.0.0.0 인 경우
Page 17
8.4 Input processing : ipintr (8/8) Reassembly and demultiplexing
/* Reassembly (Figure 10.11) */
Figure 8.15 ipintr continued
Ip_input.c
Page 18
8.5 Forwarding : ip_forward() (1/6) Structure route
Figure 8.16 ‘route’ structure
Route.h
Page 19
8.5 Forwarding : ip_forward() (2/6) Is packet eligible for forwarding ?
Figure 8.17 ip_forward function : route selection
// broadcast 이거나 forwarding 이 불가능한가 ?(class D, E 포함 )
// hostbyte order network byteorder// 만약 TTL 이 1 이하라면
Page 20
8.5 Forwarding : ip_forward() (3/6) Is packet eligible for forwarding ? (con’t)
// mbuf 의 64byte copy(IP packet 의 source 에게 64byte 를 돌려줌 )// ip_ifmatrix : records the number of packets routed between interfaces
// ipforward_rt : 가장 최근의 route 를 cache (IP forwarding algorithm)
// cache 가 비어있거나 IP packet 의 destination 과 다르다면
// cache 가 IP packet 의 destination 과 다를 때
// finds a route to the current packet’s destination
// route 를 찾을 수 없다면 ICMP(destination unreachable) message 전송하고 , return
Page 21
8.5 Forwarding : ip_forward() (4/6) Redirect messages
Figure 8.19 ip_forward continued
Ip_input.c
// mbuf 의 interface 와 route 의 interface pointer 가 일치하는가 ? (rt_ifp : router 의 interface)
// local subnet 으로부터의 packet ?
// 해당 route 가 dynamic routing 을 허용하는가 ?
// gateway 로 설정되었나 ?
// ICMP redirect message set
Page 22
8.5 Forwarding : ip_forward() (5/6) Redirect messages (con’t)
Figure 8.20 ip_forward continued Ip_input.c
// packet 을 redirect 하기위해 다시 ip_output() 으로 넘김
// redirect 에서의 error 처리
Page 23
8.5 Forwarding : ip_forward() (6/6) Redirect messages (con’t)
// ip_output() 오류에 대한 ICMP message 처리
// ICMP messge 의 type, code set
// ICMP messge 전송
// buffer 부족으로 인한 ICMP source quench message
// 해당 outgoing interface 로 전달할 packet 크기가 너무 클 때
Page 24
8.6 Output processing : ip_output() (1/5) The ip_output() receives packet from two sources
Ip_forward() Transport protocols(ICMP, IGMP, UDP, and TCP) (calls ip_output() directly)
Figure 8.22 ip_output function
// argument 로 받은 opt 와 len 으로 IP option 설정
// send(), sendto(), sendmsg() 에서 SO_DONTROUTE option
// SO_BROADCAST option(UDP)
// IP_FORWARDING 과 IP_RAWOUTPUT 이 아닐 경우에만 IP header 생성(length, Offset, TTL, protocol, TOS, destination IP
address 는 transport protocol 에 의해 initialized 되며 , source IP address 나중에 )
// 이미 IP header 가 initialized 되었을 떄 (?)
Page 25
8.6 Output processing : ip_output() (2/5)
Route selection
Figure 8.24 ip_output continued
Ip_output.c
// route cache 가 비어있나 ? (ro 는 ip_forward() 에서 이미 언급 )// 임시 변수인 structure route iproute 로 pointer 지정 & clear
// route cache 가 있고 , route 를 사용할 수 없거나(RTF_UP : route usable)// route 가 destination IP address 와 일치하지 않으면
// route cache 해제
// if the cached destination is not to the current packet’s destination, the route is discarded and the new destination address placed in dst. (?)
Page 26
8.6 Output processing : ip_output() (3/5)
Route selection(con’t)
// setsockopt 의 SO_DONTROUTE option 일 때 ( 정해진 interface 로 직접 )
// 새로운 route allocation
// 새로운 route allocation 후에도 route 가 없다면 ICMP host unreachable message(?) 전송
// interface 의 HW address 와 newtork address 가 0 이라면… // ICMP network unreachable message 전송
// route reference counter ++;
// ro 의 interface 로 지정
// gateway 일 때 IP header 의 dest. IP address 는 바뀌지 않지만 MAC address 는 next hop route 이어야 하므로…
Page 27
8.6 Output processing : ip_output() (4/5)
Source address selection and fragmentation
Figure 8.25 ip_output continued Ip_output.c
// source IP address 가 INADDR_ANY 로 지정되었을 때
// in_broadcast : 해당 interface 에서 broadcast 가 가능할때 1 return
// broadcast 일 때 IP packet 이 MTU 를 초과하는것을 허용하지 않음 (fragmentation 안함 )
// mbuf 의 M_BCAST flag set
// IFF_BROADCAST : broadcast address valid
Page 28
8.6 Output processing : ip_output() (5/5)
Source address selection and fragmentation (con’t)
/* fragmentation (Section 10.3) */
// IP packet 의 길이가 MTU 이하라면
// 정해진 interface 의 if_output() 으로 packet 전달
// 해당 route 를 더 이상 유지할 필요가 없다면 ro 에 cache 된 route 해제
Page 29
8.7 internet checksum : in_cksum() (1/6) 16bit 크기이며 , 이 16 bit 들의 1 의보수의 합 Checksum 확인은 checksum 을 반복했을 때 모든 bit 가 1 이라면
succeed
Page 30
8.7 internet checksum : in_cksum() (2/6)
Figure 8.28 An optimized portable C implementation of the IP checksum calculation
In_cksum.c
// 2byte 단위로 read
Page 31
8.7 internet checksum : in_cksum() (3/6)
// 홀수 byte 로 끝난다면 extra byte 는 next mbuf 의 첫번째 byte 에 위치
Page 32
8.7 internet checksum : in_cksum() (4/6)
// 홀수 byte 로 끝난다면 짝수로 끝나도록 처리
// three loops (16 words 경우 )
Page 33
8.7 internet checksum : in_cksum() (5/6)
// three loops (4words, and 1 word)
Page 34
8.7 internet checksum : in_cksum() (6/6)
Page 35
8.8 setsockopt and getsockopt System calls (1/4)
int setsockopt (int s, int level, int optname, const void *optval, int optlen);int getsockopt (int s, int level, int optname, void *optval, int *optlen);
Page 36
8.8 setsockopt and getsockopt System calls (2/4)
/* PRCO_SETOPT processing (Figure 8.32 and 12.17) */
/* PRCO_GETOPT processing (Figure 8.33 and 12.17) */
Figure 8.31 ip_ctloutput function overview
Ip_output.c
// argument 의 level 이 IPPROTO_IP 아닌가 ?// setsockopt 이라면 mbuf 해제
// setsockopt 에 따른 routine 수행
// 정의되지 않은 setsockopt() option 이라면 error 처리
// *mp 에 대한 reference 해제
// setsockopt 에 따른 routine 수행
// 정의되지 않은 getsockopt() option 이라면 error 처리
Page 37
8.8 setsockopt and getsockopt System calls (3/4)
PRCO_SETOPT processing
Figure 8.32 ip_ctloutput function : PRCO_SETOPT processing
Ip_output.c
// set up IP options in pcb for insertion in output packets
// IP header 의 TOS field 설정
// IP header 의 TTL field 설정
// IP_RECVOPTS option 설정 / 해제
// IP_RECVRETOPTS option 설정 /해제
// IP_RECVDSTADDR option 설정 /해제
Page 38
8.8 setsockopt and getsockopt System calls (4/4)
PRCO_GETOPT processing
Figure 8.32 ip_ctloutput function : PRCO_GETOPT processing Ip_output.c
// mbuf 할당 (socket 에서 option 과 관련된 부분을 저장하기 위한 mbuf)
// IP_RECVOPTS option
// IP_RECVRETOPTS option
// IP_RECVDSTADDR option
// IP header 의 TOS field
// IP header 의 TTL field
Page 39
8.9 ip_sysctl function ip_sysctl() is called when the protocol and family ide
ntifier are 0 in a call to sysctl().
Figure 8.35 ip_sysctl function
top related