1 / 44

INTRO TO DEVICE DRIVERS ARP & RARP IMPLEMENTATION

INTRO TO DEVICE DRIVERS ARP & RARP IMPLEMENTATION. BY. B.ANURADHA C.MANOJ KUMAR T.CHITTI BABU. DEVICE DRIVERS. Provides interface b/n the OS and the peripherals attached to the machine. Accepts I/O requests from OS and instructs the device to perform those requests.

faith
Download Presentation

INTRO TO DEVICE DRIVERS ARP & RARP IMPLEMENTATION

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. INTRO TO DEVICE DRIVERSARP & RARP IMPLEMENTATION BY B.ANURADHA C.MANOJ KUMAR T.CHITTI BABU

  2. DEVICE DRIVERS • Provides interface b/n the OS and the peripherals attached to the machine • Accepts I/O requests from OS and instructs the device to perform those requests • Provides a uniform interface b/n devices and OS

  3. IN LINUX • A device driver for every device attached to the system • Part of kernel or loaded during the boot process • The devices appear in the OS as files that can be addressed,redirected or piped as normal files. Stored in /dev directory • Each device file is uniquely identified by Major number Minor number

  4. IN LINUX (cont.) Three types of H/W devices Character devices Deals with I/O directly to and from the process memory space.e.g,terminals,printers Deals with I/O in blocks of data to and from the kernel’s buffer cache. e.g,disk drives,high capacity tape drives Block devices Network devices Deals with the sending and receiving of packets. e.g,Ethernet drives./dev/ethN.

  5. PLACE OF A DEVICE DRIVER

  6. NETWORK DEVICE DRIVER IN LINUX • Each network device is represented by a device data structure • The device data structure contains information about the device and the addresses of functions that allow the various supported n/t protocols to use the device services • All network data (packets) transmitted and received are represented by sk_buff data structures • The n/t device driver should register the devices that they control with LINUX during n/t initialization at kernel boot time.

  7. THE DEVICE DATA STRUCTURE NAME: Name of each device.Multiple devices of the same type are numbered upwards from 0. Ethernet devices are known as /dev/eth0,/dev/eth1,/dev/eth2 and so on BUS INFORMATION: Information that the device needs to control the device . Irq number Base address DMA channel INTERFACE FLAGS: describes characteristics and abilities of the n/t device iff_up; iff_broadcast ; iff_debug ; iff_loop back iff_arp; iff_promisc; iff_allmulti; iff_multicast

  8. DEVICE DATA STRUCTURE(cont.) PROTOCOL INFORMATION: Each device describes how it may be used by the network protocol layers: mtu – size of the largest packet excluding link layer headers family – for LINUX it is AF_NET type – hardware interface type. Ethernet, X.25 ,Token ring address – address relevant to the n/t device like IP address. PACKET QUEUE: Queue of sk_buff packets waiting to be transmitted SUPPORT FUNCTIONS: Set of routines that protocol layers call as part of their interface to this device's link layer. setup and frame transmit routines.

  9. THE BUFFER DATA STRUCTURE • Linux uses sk_buffs to pass data between the protocol layers and the network device drivers • Allows n/t protocol header to be easily added and removed • Four data pointers to manipulate and manage the buffer’s data: • Head – points to start of data area • Data – points to current start of protocol data • Tail- points to current end of protocol data • End- points to end of data area in memory • Methods to manipulate the data : Push, Pull, Put, Trim • Doubly linked list

  10. Sk_buff data structure

  11. DEVICE DRIVER DESIGN CHOICE The choice is on the way used to find out if an issued command to the device has completed or not POLLING Reads the device status register until command is completed. Nothing else in the kernel would run until the command completes INTERRUPT Raises an interrupt whenever needs to be serviced. Doesn’t work well for high speed data transfer DMA Data transfer without CPU intervention

  12. SOME ETHERNET DRIVERS • Ethernet High-Performance LAN Adapter Device Driver • Integrated Ethernet Device Driver • 10/100 Mbps Ethernet TX MCA Device Driver • PCI Ethernet Device Driver • Gigabit Ethernet-SX PCI Adapter Device Driver

  13. IMPLEMENTATION OF ARP

  14. A B IP_B IP_A HW_A HW_B PROBLEM OF ADDRESS RESOLUTION • How do I find out B’s physical address,given that I know B’s IP address ??

  15. ARP • ARP binds high-level, IP address to low-level, physical addresses. • Address binding software forms a boundary between higher layers of protocol software, which uses IP addresses, and the lower layers of device-driver software which uses only hardware addresses.

  16. Data Link ARP Reply BASIC ARP OPERATION A B IP_B IP_A Data Link ARP Request HW_A HW_B C

  17. ARP DESIGN ISSUES • CACHE Single cache vs Multiple cache • REPLACEMENT POLICY Local vs Global Replacement • CACHE TIMEOUT AND REMOVAL • QUEUEING OF WAITING PACKETS • EXCLUSIVE ACCESS TO CACHE

  18. HARDWARE TYPE PROTOCOL TYPE HLEN PLEN OPERATION SENDER HA SENDER IP TARGET HA TARGET IP ARP-DATA STRUCTURES • ARP PACKET 1 1 2 4 6 4 2 2 6 Struct arp { short ar_hwtype ; short ar_prtype; char ar_hwlen; char ar_prlen; short ar_op; char ar_sha[6 ]; char ar_spa[4]; char ar_tha[6]; char ar_tpa[4]; }

  19. ARP-DATA STRUCTURES • ARP CACHE TABLE QUEUE COUNT NO. OF RETRIES TTL HW ADDR PR ADDR STATE HWTYPE PRTYPE HWLEN PRLEN PNI STATE : FREE , PENDING , RESOLVED PNI : POINTER TO INTERFACE DATA STRUCTURE TTL : TIME TO LIVE FIELD FOR CACHE ENTRIES

  20. Interface to higher protocols OUTPUT MODULE Netwrite( ) CACHE MANAGER Arptimer( ) INPUT MODULE Arp_in( ) UTILITY PROCEDURES Arpadd ( ) Arpqsend ( ) Arpfind ( ) Arpsend ( ) Arpdequeue ( ) Arpalloc ( ) ARCHITECTURE OF ARP-MODULE Interface to lower-level device drivers

  21. ARP OUTPUT PROCESSING THREE MAIN PROCEDURES • SEARCHING ARP CACHE • BROADCASTING AN ARP REQUEST • OUTPUT PROCEDURE

  22. SEARCHING ARP CACHE • PROCEDURE struct arpentry *arpfind( char *pra, int prtype, struct netif *pni) • FINDS AN ARP ENTRY GIVEN THE PROTOCOL ADDRESS AND NETWORK INTERFACE. • SEARCHES THE CACHE SEQUENTIALLY AND RETURNS A POINTER TO THE ENTRY

  23. BROADCASTING AN ARP REQUEST • PROCEDURE int arpsend( struct arpentry *pae ) • FORMS AN ARP REQUEST FOR THE IP ADDRESS IN THE ARP ENTRY AND TRANSMITS IT • IT USES THE HARDWARE BROADCAST ADDRESS FROM THE INTERFACE STRUCTURE • USES THE WRITE SYSTEM CALL OF UNIX TO TRANSMIT THE MESSAGE

  24. OUTPUT PROCEDURE • PROCEDURE int netwrite( struct netif *pni, struct ep *pep, int len ) • WRITES A PACKET ON AN INTERFACE, USING ARP IF NEEDED • CALLS arpfind ( ) TO LOOK UP AN ENTRY, IF RESOLVED THEN COPIES THE HW ADDR INTO PACKET • IF ADDRESS NOT RESOLVED AND NOT PENDING THEN ALLOCATE NEW ENTRY USING arpalloc( ),FILLS THE FIELDS AND CALLS arpsend( ) • IF PENDING THEN ENQUEUE THE PACKET INTO THE ENTRY’S PACKET QUEUE AND RETURN

  25. ARP INPUT PROCESSING • INPUT PROCEDURE UTILITY PROCEDURES • ADDING RESOLVED ENTRIES TO THE TABLE • SENDING WAITING PACKETS

  26. ADDING RESOLVEDENTRIES TO TABLE • PROCEDURE struct arpentry *arpadd( struct netif *pni, struct arp *parp) • ALLOCATES AN ARP ENTRY FOR THE PACKET ARRIVED • ASSIGNS STATE OF THE ENTRY AS RESOLVED • ASSIGNS THE TTL VALUE FOR THE ENTRY

  27. SENDING WAITING PACKETS • PROCEDURE void arpqsend(struct arpentry *pae) • TRANSMITS WAITING PACKETS WHEN AN ENTRY IS RESOLVED • ITERATES THROUGH THE QUEUE AND PLACES EACH PACKET ON THE NETWORK

  28. INPUT PROCEDURE • PROCEDURE int arp_in(struct netif *pni, struct ep *pep) • HANDLES ETHERNET PACKETS COMING IN FROM THE ETHERNET NETWORK • SEARCHES THE ENTRY FOR THE PACKET IN THE CACHE AND INITIALISES IT’S HARDWARE ADDRESS AND TIMEOUT • IF NOT FOUND ADDS A NEW ENTRY USING arpadd() • CHANGES THE ARP ENTRY STATE TO RESOLVED AND SCHEDULES THE PACKETS WAITING IN THE QUEUE USING arpqsend( ) • IF IT’S AN ARP REQUEST SENDS ARP REPLY

  29. ARP CACHE MANAGEMENT Requires periodic computation independent of I/O • ALLOCATING A NEW CACHE ENTRY • PERIODIC CACHE MAINTENANCE • DEALLOCATING QUEUED PACKETS

  30. ALLOCATING A NEW CACHE ENTRY • PROCEDURE struct arpentry *arpalloc( ) • IMPLEMENTS CACHE REPLACEMENT POLICY • CHOOSE AN UNSUSED ENTRY IF ONE EXISTS OR DELETE ENTRIES IN A ROUND-ROBIN FASHION • MAINTAINS STATE VARIABLE FOR LAST ENTRY ALLOCATED AND STARTS THE SEARCH FROM THAT PLACE

  31. PERIODIC CACHE MAINTENANCE • PROCEDURE void arptimer( int gran ) • int gran PARAMETER PASSED BY THE TIMER- TIME SINCE LAST ITERATION • ITERATES THROUGH THE ARP CACHE AND AGES ARP ENTRIES BY REMOVING THEM • FREE ENTRY, IF STATE PENDING AND NUMBER OF ATTEMPTS IS GREATER THAN ARP_MAXRETRY • NUMBER OF ATTEMPTS < MAX_RETRY THEN SEND PACKET AGAIN USING arpsend ( )

  32. DEALLOCATING QUEUED PACKETS • PROCEDURE void arpdq( struct arpentry *pae ) • DESTROY AN ARP QUEUE THAT HAS EXPIRED • FOR EACH ITEM I N THE QUEUE FREE THE BUFFERS ALLOCATED TO THE PACKETS • IF DESTINATION IS GATEWAY THEN, FOR EACH QUEUE ITEM SENDS AN ICMP “DESTINATION UNREACHABLE” MESSAGE

  33. ARP CONFIGURATION PARAMETERS • SIZE OF THE ARP CACHE • TIMEOUT INTERVAL • NUMBER OF RETRIES • TIME INTERVAL BETWEEN RETRIES • TTL • SIZE OF PACKET RETRANSMISSION QUEUE

  34. ARP CONFIGURATION TWO WAYS OF CONFIGURING ARP • USING SYMBOLIC CONSTANTS FOR PARAMETERS LIKE CACHE SIZE ETC.., ALLOWING SYS. MANAGER TO CHANGE CONFIG. PARAMS • USING UTILITY PROGRAMS THAT ALLOW SYS. MANAGER TO CHANGE PARAMS AT RUN-TIME

  35. REVERSE ADDRESS RESOLUTION PROTOCOL

  36. RARP • Primarily used for diskless workstations RARP is Internet Protocol used to map a physical network address into IP Address. • Used also for detecting the IP Addresses of other machines. • Not advisable for SUN machines • Currently only ethernet address ->IP address works

  37. DATA STRUCTURES INVOLVED.. struct rarp_table { struct rarp_table *next; unsigned long ip; unsigned char ha[MAX_ADDR_LEN]; unsigned char hlen; unsigned char htype ; struct device * dev; }

  38. MAIN MODULES Init_module( ) rarp_init( ) rarp_ioctl( ) • Cleanup_module( ) • Set rarp_ioctl_hook to NULL • destroys all the entries in rarp_table.

  39. INIT_MODULES rarp_init( ) calls rarp_get_info( ) rarp_get_info( ) checks whether there are entries in rarp_table and returns the length of the rarp_table if present or else sends an error message rarp_ioctl( int cmd ,void * arg ) SIOCGRARP: rarp_req_get((struct arpreq*) arg ) Get a RARP cache entry

  40. INIT MODULES (Contd.. ) SIOCDRARP : rarp_destroy( unsigned long ip_addr) release the memory space . Deletes the entry corresponding the given IP addr , and SIOCSRARP : rarp_req_set((struct arpreq*) arg ) Set /create a RARP cache entry when the cache is initially empty { reset initflag } Calls rarp_init_pkt( )

  41. rarp_init_pkt( ) Initates rarp_device_event( ) Sets pckt type as ETH_P_RARP, Initiates rarp_rcv( )

  42. rarp_rcv(struct sk_buff*,struct device*,struct packet_type*) Receives an arp request from the device layer Ignore if not IP(as upper) & not Ethernet(as lower). If found ,reply with the ethernet-addr => [arp_send( )] If it is not RARP request,delete it. • Other wise lookup for the entry in the rarp_table

  43. Flush a Device rarp_device_event( ) Detects whether any device is down calls rarp_destroy_dev( ) rarp_destroy_dev(struct device *dev) Deletes all the entries corresponding to that device

  44. References • Linux Network Drivers , www.scyld.com/network • Device drivers, www.serc.iisc.ernet.in/usr/reference/NetAdm/note42.html • Internetworking with TCP/IP Volume II : Design, Implementation, and Internals ( Comer and D.Stevens),Third ed,1999. • Linux Documentation Project, www.linuxdocs.org • Red hat Linux,Release 6.2, ARP & RARP source code

More Related