TELE 402 Lecture 12: Signal-Driven I/O & Raw Socket 1 Overview Last Lecture –Advanced UDP sockets and threads –Source: Chapters 22&26 of Stevens’ book.

Slides:



Advertisements
Similar presentations
Florida State UniversityCOP Advanced Unix Programming Raw Sockets Datalink Access Chapters 25, 26.
Advertisements

Socket Options. abstraction Introduction getsockopt and setsockopt function socket state Generic socket option IPv4 socket option ICMPv6 socket option.
CS 457 – Lecture 16 Global Internet - BGP Spring 2012.
CSCI 4550/8556 Computer Networks Comer, Chapter 23: An Error Reporting Mechanism (ICMP)
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
Internet Control Message Protocol (ICMP)
1 TDC TDC 365 Network Interconnections Technologies Lecture #4 Notes Spring, 2009.
Networks: TCP/IP Socket Calls1 Elementary TCP Sockets Chapter 4 UNIX Network Programming Vol. 1, Second Ed. Stevens.
Elementary TCP Sockets Chapter 4 UNIX Network Programming Vol. 1, Second Ed. Stevens.
The Network Layer Chapter 5. The IP Protocol The IPv4 (Internet Protocol) header.
Chapter 5 The Network Layer.
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
Socket Options Jari Kellokoski. Introduction So far we have discovered some basic usage of socket With socket options we control sockets more suitable.
Shivkumar Kalyanaraman Rensselaer Polytechnic Institute 1 Internet Control Message Protocol (ICMP) Shivkumar Kalyanaraman Rensselaer Polytechnic Institute.
1 Application Presentation Session Transport Network Datalink Physical OSI model Application IPv4, IPv6 Device Driver Hardware TCPUDP Internet.
1 Internet Control Message Protocol (ICMP) RIZWAN REHMAN CCS, DU.
1 CMPT 471 Networking II ICMP © Janice Regan, 2012.
TELE202 Lecture 10 Internet Protocols (2) 1 Lecturer Dr Z. Huang Overview ¥Last Lecture »Internet Protocols (1) »Source: chapter 15 ¥This Lecture »Internet.
Internet Control Message Protocol ICMP. ICMP has two major purposes: –To report erroneous conditions –To diagnose network problems ICMP has two major.
Petrozavodsk State University, Alex Moschevikin, 2003NET TECHNOLOGIES Internet Control Message Protocol ICMP author -- J. Postel, September The purpose.
Network Layer4-1 NAT: Network Address Translation local network (e.g., home network) /24 rest of.
TCP/IP Protocol Suite 1 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 9 Internet Control Message.
© Janice Regan, CMPT 128, CMPT 371 Data Communications and Networking Network Layer ICMP and fragmentation.
Raw Sockets.
1 Introduction to Raw Sockets 2 IP address Port address MAC address TCP/IP Stack 67 Bootp DHCP OSPF protocol frame type UDP Port # TCP Port.
Shivkumar Kalyanaraman Rensselaer Polytechnic Institute 1 Internet Control Message Protocol (ICMP) Shivkumar Kalyanaraman Rensselaer Polytechnic Institute.
1 IP: putting it all together Part 2 G53ACC Chris Greenhalgh.
Signal-Driven I/O Concepts and steps for using signal-driven I/O
IP Forwarding.
Fall 2005Computer Networks20-1 Chapter 20. Network Layer Protocols: ARP, IPv4, ICMPv4, IPv6, and ICMPv ARP 20.2 IP 20.3 ICMP 20.4 IPv6.
1 Internet Control Message Protocol (ICMP) Used to send error and control messages. It is a necessary part of the TCP/IP suite. It is above the IP module.
CS4550 Computer Networks II IP : internet protocol, part 2 : packet formats, routing, routing tables, ICMP read feit chapter 6.
Internet Protocols. Address Resolution IP Addresses are not recognized by hardware. If we know the IP address of a host, how do we find out the hardware.
1 Network Layer Lecture 16 Imran Ahmed University of Management & Technology.
TELE 402 Lecture 4: I/O multi … 1 Overview Last Lecture –TCP socket and Client-Server example –Source: Chapters 4&5 of Stevens’ book This Lecture –I/O.
Network Programming Chapter 5: Raw Socket Programming.
Chapter 23 Internet Control Message Protocol used to report information and errors IP uses ICMP when it sends an error message ICMP uses IP to transport.
1 Chapter 23 Internetworking Part 3 (Control Messages, Error Handling, ICMP)
Advanced UNIX programming Fall 2002, lecture 16 Instructor: Ashok Srinivasan Acknowledgements: The syllabus and power point presentations are modified.
ICMPv6 Error Message Types Informational Message Types.
THE CLASSIC INTERNET PROTOCOL (RFC 791) Dr. Rocky K. C. Chang 20 September
1 Socket Options getsockopt and setsockopt functions Check options and obtain default values Generic socket options IPv4 socket options IPv6 socket options.
TCP/IP Illustrated, Volume 1: The Protocols Chapter 6. ICMP: Internet Control Message Protocol ( 월 ) 김 철 환
Ioctl Operations. ioctl Function Interface Configuration  Netstat, ifconfig command 에서 사용.
1 Kyung Hee University Chapter 11 User Datagram Protocol.
Lecture 21: Network Primer 7/9/2003 CSCE 590 Summer 2003.
IP Internet Protocol. IP TCP UDP ICMPIGMP ARP PPP Ethernet.
4: Network Layer4-1 Chapter 4: Network Layer r 4. 1 Introduction r 4.2 Virtual circuit and datagram networks r 4.3 What’s inside a router r 4.4 IP: Internet.
Internet Control Message Protocol (ICMP)
Internet Control Message Protocol (ICMP)
Chapter 11 User Datagram Protocol
IPv4 socket option Level => IPPROTO_IP
Socket Option.
COMP2322 Lab 5 IP Steven Lee March 22, 2017.
Internet Control Message Protocol (ICMP)
Internet Control Message Protocol
COMPUTER NETWORKS CS610 Lecture-33 Hammad Khalid Khan.
8 Network Layer Part V Computer Networks Tutun Juhana
Byungchul Park ICMP & ICMPv DPNM Lab. Byungchul Park
CSCD433 Advanced Networks Spring 2016 Lecture 16a
CHAPTER 8 ELEMENTARY UDP SOCKETS
Internet Control Message Protocol (ICMP)
Internet Control Message Protocol (ICMP)
Internet Control Message Protocol (ICMP)
Internet Control Message Protocol (ICMP)
Network Programming CSC- 341
Internet Control Message Protocol (ICMP)
Internet Control Message Protocol Version 4 (ICMPv4)
46 to 1500 bytes TYPE CODE CHECKSUM IDENTIFIER SEQUENCE NUMBER OPTIONAL DATA ICMP Echo message.
32 bit destination IP address
Presentation transcript:

TELE 402 Lecture 12: Signal-Driven I/O & Raw Socket 1 Overview Last Lecture –Advanced UDP sockets and threads –Source: Chapters 22&26 of Stevens’ book This Lecture –Signal-driven I/O, Raw sockets –Source: Chapters 25&28&29 of Stevens’ book Next Lecture –WSN and revision

TELE 402 Lecture 12: Signal-Driven I/O & Raw Socket 2 Introduction Kernel notifies a process with a signal when something happens on a descriptor. SIGIO POSIX provides true asynchronous I/O with aio_XX functions.

TELE 402 Lecture 12: Signal-Driven I/O & Raw Socket 3 Signal-driven I/O for Sockets To use signal-driven I/O with sockets: –Establish a signal handler for the SIGIO signal –Set the socket owner with the F_SETOWN command of fcntl –Turn on the O_ASYNC flag with the F_SETFL command of fcntl to enable signal-driven I/O

TELE 402 Lecture 12: Signal-Driven I/O & Raw Socket 4 Two different UDP servers

TELE 402 Lecture 12: Signal-Driven I/O & Raw Socket 5 Example Data structures for received datagrams and their socket address structures

TELE 402 Lecture 12: Signal-Driven I/O & Raw Socket 6 Raw Sockets Raw sockets provide three capabilites –Read and write ICMPv4, IGMPv4, and ICMPv6 packets –Read and write IPv4 datagrams with an IPv4 protocol field that is not processed by the kernel –With a raw socket, a process can build its own IPv4 header, using the IP_HDRINCL socket option

TELE 402 Lecture 12: Signal-Driven I/O & Raw Socket 7 Raw Socket Creation 1 Steps are: int sockfd; sockfd = socket(AF_INET, SOCK_RAW, protocol); const int on = 1; if (setsockopt(sockfd, IPPROTO_IP, IP_HDRINCL, &on, sizeof(on)) < 0) error –protocol is one of the constants IPPROTO_xxx defined in netinet/in.h, such as IPPROTO_ICMP –Only the superuser can create a raw socket

TELE 402 Lecture 12: Signal-Driven I/O & Raw Socket 8 Raw Socket Creation 2 bind can be called on the raw socket, but this is rare. A raw socket can only be bound to a local address, not a port number. connect can be called on the raw socket, but this is rare. It only sets the foreign address and allows us to use write or send instead of sendto.

TELE 402 Lecture 12: Signal-Driven I/O & Raw Socket 9 Raw Socket Output 1 Performed by calling sendto or sendmsg with the destination IP address –write or send if the socket is connected If IP_HDRINCL is not set, the starting address of the data for the kernel to send specifies the first byte following the IP header –Kernel will build the IP header and prepend it to the data –Protocol field from protocol in socket call

TELE 402 Lecture 12: Signal-Driven I/O & Raw Socket 10 Raw Socket Output 2 If IP_HDRINCL is set, the starting address of the data for the kernel to write specifies the first byte of IP header. –The amount of data to write must include the size of the IP header. –The process builds the entire IP header, except: the IPv4 identification field can be 0 which tells kernel to set the value kernel always calculates and stores header checksum IP options may or may not be included

TELE 402 Lecture 12: Signal-Driven I/O & Raw Socket 11 Raw Socket Output 3 The kernel fragments raw packets that exceed the outgoing interface MTU With IPv4, the process must calculate and set any payload checksums contained in whatever follows the IPv4 header, e.g. ICMPv4 checksum. With IPv6, the checksum for ICMPv6 is calculated by the kernel.

TELE 402 Lecture 12: Signal-Driven I/O & Raw Socket 12 Raw Socket Input 1 Which datagrams does the kernel pass to raw sockets? –Never pass UDP/TCP packets –Most ICMP packets after the kernel has finished processing the ICMP message –All IGMP packets after the kernel has finished processing the IGMP message –All IP datagrams with a protocol field that the kernel does not understand If fragmented, kernel reassembles before passing datagram to raw socket

TELE 402 Lecture 12: Signal-Driven I/O & Raw Socket 13 Raw Socket Input 2 When the kernel has an IP datagram to pass to the raw sockets, a copy of the IP datagram is delivered to each matching socket (if all three tests are true) –If a nonzero protocol is specified when the raw socket is created, the protocol field of the IP datagram must match the socket’s protocol –If bind is called, destination address of the datagram must match the socket’s bound address –If connect is called, source address of the datagram must match the socket’s connected address

TELE 402 Lecture 12: Signal-Driven I/O & Raw Socket 14 Raw socket input 3 If a raw socket is created with a protocol 0, and neither bind nor connect is called, then that socket receives a copy of every raw datagram the kernel passes to raw sockets Whenever a datagram is passed to a raw IPv4 socket, the entire datagram including IP header is passed to it –For a raw IPv6 socket, only the payload is passed to the socket

TELE 402 Lecture 12: Signal-Driven I/O & Raw Socket 15 Ping How to make a ping program? –A raw socket is created for ICMP protocol –The main function is receiving IP datagrams in a loop When a datagram is received, the sequence number and calculated RTT are printed out. –An alarm is set every second and the SIGALRM signal handler sends an ICMP packet with a sequence number and a timestamp The checksum of the ICMP packet is calculated

TELE 402 Lecture 12: Signal-Driven I/O & Raw Socket 16 Traceroute How to make a traceroute program? –Create two sockets, one is SOCK_DGRAM, the other is SOCK_RAW –The SOCK_DGRAM socket is used to send IP datagrams with TTL starting from 1 ‘time exceeded in transit’ ICMP errors will result until TTL is large enough –The SOCK_RAW is used to receive ICMP packets –Send a datagram, and then wait to receive an ICMP packet –Repeat the above until ‘port unreachable’ ICMP packet received.

TELE 402 Lecture 12: Signal-Driven I/O & Raw Socket 17 ICMP Daemon 1 Allow applications to receive asynchronous ICMP errors in detail (refer to the directory icmpd)

TELE 402 Lecture 12: Signal-Driven I/O & Raw Socket 18 ICMP Daemon 2

TELE 402 Lecture 12: Signal-Driven I/O & Raw Socket 19 ICMP Daemon 3

TELE 402 Lecture 12: Signal-Driven I/O & Raw Socket 20 ICMP Daemon 4

TELE 402 Lecture 12: Signal-Driven I/O & Raw Socket 21 Datalink Access Datalink access provides the following capabilities –The ability to watch the packets received by the datalink layer, allowing programs such as tcpdump to be run on normal computer systems –The ability to run certain programs as normal applications instead of as part of the kernel, e.g. RARP server. –Linux uses PF_PACKET as the domain for sockets to support datalink access