TCP/IP(3)

silups·2024년 10월 24일
0

TCP/IP

목록 보기
5/12

Internet Protocol Version4 (IPv4)

IPv4

  • IP는 network layer(3계층)에서 사용되는 protocol이다.
  • IP는 신뢰성이 없어 전달과정에서 오류가 생기면 packet을 버린다.
  • ICMP는 패킷의 오류 등을 알려줌
  • IGMP는 멀티캐스트 용도로 사용 (Internet Group Management Protocol)
  • ARP는 IP주소로 MAC주소를 얻기위해 사용 (Address Resolution Protocol)

Datagrams

  • Network layer의 Packet을 Datagrams이라 함
  • Datagrams는 header와 data 부분으로 구성되어 있다.
  • header에는 data전송/Routing/Forwarding을 하는데에 있어 필수적인 정보가 들어있음
  • IP Datagrams은 구조체로 정의되어 있음.

IP datagrams

  • datagrams의 최대 크기가 65,535byte인 이유는 Header의 Total length의 크기가 16bits이기 때문이다.

  • datagrams의 최소 크기가 46byte인 이유는 LAN이 최소 64byte의 frame을 받아야 동작을 하기 때문이다. IP
    -> frame이 되는 과정에 붙는 header 및 CRC트레일러의 크기가 18byte
    -> (64 - 18 = 46)

  • 만약, datagrams의 크기가 46byte가 되지 않는다면 가짜 데이터를 붙여 크기를 맞춘다.

  • VER: 버전 정보 (IPv4 = 0100)
  • HLEN: Header 길이.
    -> 4bit만 할당되어 있기 때문에 HLEN * 4가 실제 header 길이이다.
  • Service type: 차별화 서비스 타입 (datagrams마다 처리 순, 방식이 다름)
  • Total length: Datagrams의 전체 길이
  • Identification: IP Packet의 고유 번호
    -> 추후 전송 시 패킷이 단편화(fragmentation)되어도 다시 합칠 수 있도록
    -> LAN의 종류마다 MTU(한번에 최대로 전송할 수 있는 데이터 양)이 다르다.
    -> 따라서 LAN에 맞게 IP Packet을 fragmentation해야 하는 경우가 생긴다.
  • FLGs: fragmentation 허용 여부
  • Flagmentation offset: fragment된 조각들을 재조립하기 위한 위치 표시
  • Time to live: 한 Router를 이동할 때마다 -1. Network에서 존재할 수 있는 시간
    -> 외부 네트워크로 나가지 않게 하고 싶다면 1로 설정하면 됨
    -> 0이 될 경우 폐기
  • Protocol: 상위의 protocol 표기
  • Header checksum: 에러 채킹용도의 값
  • Source IP address: 출발지 주소
  • Destination IP address: 목적지 주소
  • Options + padding: 옵션

Service type

- `Precedence interpretation`: 처리 우선 순위
- `Differential service interpretation`: 통신회사나 인터넷에서 정의해서 사용(아직 정확히 정의되지 않음)

Total length

Protocols

ex7.1

An IP packet has arrived with the first 8 bits as shown:
01000010
The receiver discards the packet. Why?
(01000010으로 시작하는 IP packet이 왜 버려졌는지?)
:
0100 0010에서 0100은 버전 정보로 IPv4를 의미한다.
0010은 헤더 길이로 0010(2) * 4 = 8로 최소 Header 길이인 20보다 작다.
-> 버려진 이유

ex7.2

In and IP packet, the value of HLEN is 1000 in binary. How many bytes of options are being carried by this packet?
(HLEN이 1000일 때 option의 길이는?)
:
HLEN이 1000이면 Header의 길이는 1000(2) * 4 = 32이다.
Header는 최소 20byte이므로 optiondms 32 - 20 = 12byte이다.

ex7.3

In an IP packet, the value of HLEN is 5(16) and the value of the total length field is 0028(16). How many bytes of data are being carried by this packet?
(이 패킷에 전송되는 데이터는?)
:
HLEN = 5(16) * 4 = 20
total length = 0028(16) = 40
total length는 HLEN + data.
Data = 40(total length) - 20(HLEN) = 20byte

ex7.4

An IP packet has arrived with the first few hexadecimal(16) digits as shown below: 45000028000100000102

How many hops can this pacet trabel before being dropped? The data belong to what upper layer protocol?
(Protocol과 앞으로 지날 수 있는 hops의 수)
:
4(VER)/5(HLEN)/00(Service type)/0028(total length)
0001(Identification)/0000(Flas/Fragmentation offset)
01(Time to live)/02(Protocol)/

앞으로 1개의 hops를 더 지날 수 있으며 IGMP에서 넘어옴

Fragmentation

  • datagrams은 여러 Network를 통과한다.
  • 이때, 각 LAN의 MTU가 다르기 때문에 Packet의 크기를 맞춰주어야 한다.
    Fragmentation: Network 이동간 MTU에 맞게 Packet의 크기를 쪼개주는 것
  • Header가 아닌 data부분을 fragmentation 한다..
  • Fragment 조각이 제시간에 도착하지 않으면 버림
  • offset값을 통해 다 왔는지 아닌지 판단 가능

Flags field

`D`: 0 fragment 허용 / 1 fragment 불가 `M`: 0 마지막 단편 조각 / 1 뒤에 단편 조각이 더 있음

fragmentation offset

  • 13bit를 맞추기 위해 /8을 한 값을 기입한다.

fragmentation example

  • 같은 Identification 값을 가진 packet들을 모아서 조립

ex7.5

A packet has arried with an M bit value of 0. Is this the first fragment, the last fragment, or a middle fragment? Do we know if the packet was fragmented?
(M = 0이라면 fragment 여부 및 위치를 알수 있나?
:
M이 0인 경우는 Fragment의 마지막 조각이거나 아예 Fragment되지 않았을 경우이다. M의 정보만으로 두 경우를 구분 할 수 없다.
-> First or last fragment. First라면 fragment X, Last라면 fragment O

ex7.6

A packet has arrived with an M bit value of 1. Is this the first fragment, the last fragment, or a middle fragment? Do we know if the packet was fragmented?
:
M이 1이면 fragment가 이루어진 것은 확실하다. 하지만 First 인지 Middle 인지는 알 수 없다.

ex7.7

A packet has arrived with an M bit value of 1 and a fragmentation offset value of zero. Is this the first fragment, the last fragment, or a middle fragment?
:
offset값이 0이라는 것은 First Fragment를 의미한다.

ex7.8

A packet has arrived in which the offset value is 100. What is the number of the first byte? Do we know the number of The last byte?
:
100 * 8 = 800.
first byte number은 800이다.
Last byte는 알 수 없다.

ex7.9

A packet has arrived in which the offset value is 100, the value of HLEN is 5 and the value of the total length field is 100. What is the number of the first byte and the last byte?
:
first byte number is 100 8 = 800이다.
Data의 길이는 100 - (5
4) = 80byte이다.
Last byte number 는 800 + 79 = 879byte이다.

Options

  • IP datagram의 hearder는 꼭 있어야 하는 부분(20byte)과 없어도 되는 부분(40byte)으로 나누어진다.
  • option은 Network testing이나 Debugging용으로 많이 사용한다.
  • 모든 PC의 소프트웨어는 Optios를 처리할 수 있어야 한다.

Option format

Copy

  • 0Copy only in first fragment: 첫번째 fragment 조각에만 option이 들어감
  • 1Copy into all fragments: 모든 fragment 조각에 option이 들어감

Class

  • 00Datagram control: 일반적인 Datagram control
  • 01,11Reserved: 아직 사용하지 않는 bit
  • 10Debugging and management: 선로 테스트

Number

  • 00000End of option:

  • Option의 끝임을 알림

  • Option이 4byte단위로 끝나면 쓰지 않아도 된다.

  • 00001No operation:

  • Header가 4의 배수의 크기를 가지도록 크기를 맞춰주는 역할

  • 아무 의미도 없다.

  • 2byte가 부족하다면 No operation과 End of option을 하나씩 사용

  • 00011Loose source route:

  • 지정된 경로를 반드시 지나야 하지만 다른 경로를 추가할 수 있음

  • Strict source route와 같은 포맷

  • 00100Timestamp: (ping)

  • O-Flow에는 주소가 부족해 timestamp를 찍지 못한 Router의 개수가 기록된다.

  • flags 0은 Timestamp만, 1은 IP와 Timestamp, 3은 지정된 IP에 해당하는 Router만 Timestamp 기록.

  • Timestamp로 목적지로 packet이 전달 되는데 걸린 시간을 알 수 있음

  • 00111Record route: (-R)

  • 지나온 Router를 기록하는 option

  • 기록된 Router를 통해 경로를 확인 할 수 있다.

  • 9개의 Router까지만 기록 가능
    -> 한 줄이 4byte. 총 40byte를 넘으면 안되기 때문

  • 지나온 Router가 9개 이상이면 9개 이후부터 기록하지 않는다.

  • point: Router 주소를 기록할 위치를 표시 -> 4/8/12/16 등

  • 01001Strict source route:

  • 경로를 미리 지정한다.

  • 설정된 경로를 빼거나 추가하면 안된다.

  • 내가 원하는 Router만 지나감

  • 모든 fragment 조각에 option이 붙어야 한다.

  • 동일하게 9개 까지만 가능

Record-route

- pointer에 해당하는 주소에 Router 주소 기록 - pointer값 증가 - 반복

Strict source route

- 처음부터 모든 주소에 기록되어 있는 다음 목적지가 기록되어 있음. - Router를 이동하면 Destination에 값과 pointer주소에 있는 값을 스왑한다 - 지나온 Router 기록 및 지정 경로로 이동

ex7.10

Which of the six options must be copied to each fragment?
:
Strict source route
Loose source route

ex7.11

Which of the six options are used for datagram control and which for debugging and managements?
Datagram control

  • No operation
  • End of option
  • Record route
  • Strict source route
  • Loose source route

Debugging and management control

  • Timestemp

Checksum

  • IP는 신뢰성이 없어 Error control(에러 알려줌)과 Block control(속도 조절)을 하지 않는다.
  • Checksum: 데이터 전달과정에 파손되지 않았는지 확인하는 것
    1) 내가 보내는 데이터의 합 계산(header만) ->
    2) 결과값에 ~을 붙인 값을 Checksum filed에 저장
    3) 수신측에서 전체를 다 더하면 0이 나옴
    4) 0이 나오지 않으면 데이터가 훼손 된 것
- Carry 발생시 다시 맨 뒤 비트에 더함

IP over ATM

  • ATM Network를 통해 IP datagrams 전달
  • ATM은 53byte packet으로 잘게 쪼게 통신함
  • ATM의 ATM주소를 알기 위해 ATM ARP를 사용 (20Byte 주소)
  • ATM의 VPI, VCI값을 이용해 경로 설정

Security

1) packet sniffing
-> 암호화
2) packet modification
-> 무결성 검증
3) packet spoofing
-> 사용자 인증

IP PACKAGE

  • 각 모듈의 프로그램 구조
profile
NDBT

0개의 댓글