npch25

download npch25

of 12

Transcript of npch25

  • 8/13/2019 npch25

    1/12

    1

    Application

    Presentation

    Session

    Transport

    Network

    Datalink

    Physical

    OSI model

    7

    6

    5

    4

    3

    2

    1

    Application

    IPv4, IPv6

    DeviceDriver

    Hardware

    TCP UDP

    Internet protocolsuite

    Sockets

    XTI

    Userprocess

    kernel

    Application

    details

    Communicationsdetails

    Raw SocketsDatalinkAccess

  • 8/13/2019 npch25

    2/12

    2

    Raw Sockets

    Usage

    Creation. Output. Input

    Ping

    Traceroute

  • 8/13/2019 npch25

    3/12

    3

    version

    header

    length type of service total length

    identification 0D

    F

    M

    Ffragment offset

    32-bit source IPv4 address

    32-bit source IPv4 address

    options (if any)

    data

    time to live protocol header checksum

    3 4 7 8 5 6 3

    20 bytes

    Raw Socket Usage

    1 ICMP2 IGMP6 TCP17 UDP

    1. R/W ICMPv4. IGMPv4. ICMPv6

    ex. Ping

    2. R/W other datagrams not processed by kernel

    ex. Gated => implement OSPF (protocol = 89)

    3. Build ones own IPv4 Header

    ex. traceroute

  • 8/13/2019 npch25

    4/12

    4

    RawSocketCreation

    Sockfd = socket ( AF_INET,

    SOCK_RAW, protocol)

    Set IP_HDRINCL socket option

    If (setsockopt(sockfd, IPPROTO_IP,

    IP_HDRINCL, &on, sizeof (on))>0)

    error ;

    BIND

    No port

    number

    concept

    CONNECT

    No port

    number

    concept

  • 8/13/2019 npch25

    5/12

    5

    Raw Socket Output

    1. Sendto / sendmsg+ destination IP

    connect => write / writev / send

    2. Starting Address for the kernel to write

    Starting Addr. = First byte following the IP header

    Set IP_HDRINCL =>

    Starting Addr. = First byte of the IP header

    3. Fragmentationby kernel

    Kernel

    Raw SocketsChecksum:

    IPv4 => By Application

    IPv6 => By Kernel

  • 8/13/2019 npch25

    6/12

    6

    Raw Socket Input

    1. UDP / TCP Never pass to Raw Socket2. Most ICMP Kernel => Raw Socket

    3. All IGMP Kernel => Raw Socket

    4. All Unknown IP Datagram

    Kernel ~> Raw Socket

    5. Fragment In Reassemble ~> Raw Socket

    Kernel

    Raw Sockets

    protocol field

    bound addr. = dest. IP

    connected addr. = source IP

  • 8/13/2019 npch25

    7/12

  • 8/13/2019 npch25

    8/12

    8

    main

    readloop

    recvfrom proc_v4

    proc_v6

    sig_alrm

    send_v4

    send_v6

    or

    or

    Infinite receive loop Send an echo requestonce a second

    Overview ofPing

    Establish signal handlerfor SIGALRM

  • 8/13/2019 npch25

    9/12

    9

    Traceroute with TTL Mechanism

    TTL=1

    ICMP

    Router

    A(Local)

    B(Remote)

  • 8/13/2019 npch25

    10/12

    10

    Example of Traceroute

    Solaris # traceroute gemini.tuc.noao.edu

    traceroute to gemini.tuc.noao.edu (140. 252. 3. 54): 30 hops max, 12

    data bytes

    1 gw.kohala.com (206.62.226.62) 3.839ms 3.595ms 3.722ms2 tuc -1 -s1 -9 .rtd.net (206.85.40.73) 40.014ms 21.078ms 18.826ms

    3 frame -gw.ttn.ep.net (198.32.152.9) 39.283ms 24.598ms 50.037ms

    ...7 gemini.tuc.noao.edu (140.252.3.54) 70.476ms 43.555ms 88.716ms

  • 8/13/2019 npch25

    11/12

    11

    Datalink Access

    Usage

  • 8/13/2019 npch25

    12/12

    12

    Datalink Access

    Watch packets received by datalink layer

    ex. Tcpdumpon normal computer systems=> watch all packets on the local cable

    Run certain programs as normal applications

    instead of part of the kernelex. RARP (R/W over datalink)