CS 498 Lecture 7Network DevicesJennifer HouDepartment of Computer Science University of Illinois at Urbana-ChampaignReading: Chapters 5, The Linux Networking Architecture: Design and Implementation of Network Protocols in the Linux KernelNetwork DevicesAn interface between software-based protocols and network adapters (hardware).Two major functions:z Abstract from the technical properties of network adapters (that implement different layer-1 and layer-2 protocols and are manufactured by different vendors).z Provide a uniform interface for access by protocol instances.Network Device Interfacedriver.cdriver.cnet_txnet_interruptnet_rxskbskbskbskbskbskbnet_start_xmitnet_open net_stopnet_devicenet_devicedev.cdev.cnetif_rxdev->hard_start_xmit dev->open dev->stopdev_queue_xmitdev_open dev_closeHigher Protocol InstancesHigher Protocol InstancesNetwork devices(adapter-independent)Network devicesinterfaceNetwork driver(adapter-specific)Abstraction from Adapter specificsnet_device structurenet_device structureRepresents a general interface between higher protocol instances and the hardware used.Contains a number of function pointers that points to hardware-specific methods of the driver.Are grouped into four categories:z General fieldsz Hardware-specific fieldsz Network layer fieldsz Device driver methods1. General Fields in net_devicename: name of the network device, e.g., eth0-eth4, lo (loopback device)next: points to the next net_device in the list of network devices (that starts with dev_base).owner: points to the module structure of the module that creates net_device.ifindex: a second identifier to a network device.z When a new network device is created, dev_get_index() assigns a new unused index to the device.state: state of the devicez LINK_STATE_START: the network adapter has been opened with devÆopen()z netif_running(dev) can test this flag.z LINK_STATE_XOFF: the network adaptor cannot accept packets or the transmit buffers of the network adapter are all busy.z netif_queue_stopped(dev) can test this flag.z netif_stop_queue(dev) sets the LINK_STATE_XOFFflag, and no packet can be passed onto the adapter.z Usually called by the driver of an adaptor.1. General Fields in net_devicestate: state of the devicez netif_start_queue(dev) deletes the LINK_STATE_XOFFflag, and resumes accepting packets from the kernel.z Usually used by the driver methods of an adaptor, after it has sent a packet from the (ring) transmit buffer.z netif_wake_queue(dev) resumes passing packets, and trigger the NET_TX software interrupt.trans_start: the time (in jiffies) when the transmission of a packet started.z If after some time, the driver has not received an acknowledgement, it can take appropriate actions.1. General Fields in net_device1. General Fields in net_devicelast_rx: the time (in jiffies) when the last packet arrived.priv: a pointer to the private data of a network device.qdisk: a structure of the type Qdisk, and governs the serving discipline of the network device.refcnt: the number of references to the network device.xmit_lock, xmit_lock_owner: are used for mutual exclusion on the transmit queue.z xmit_lock_owner specifies the processor which is currently in the transmit function hard_start_xmt().2. Hardware-Specific Fieldsrmem_end, rmem_start, mem_end, mem_start: specify the common memory space that the network adapter and the kernel share.z (mem_start-mem_end) designates the buffers for packets to be sent; (rmem_start-rmem_end) designates the location for received packets.z When ifconfig is used to initialize a network adaptor, the addresses of memory locations can be specified.base_addr: I/O basic address; set in the driver’s probing routine during the search for a device (I.e., when the kernel is started or the module is loaded).Irq: the # of the interrupt of a network adapter; set in the driver’s probing routine.dma: the number of the DMA channel.2. Hardware-Specific FieldsThe following fields are set by ethersetup() for Ethernet cards.hard_header_length: specifies the length of the layer-2 packet header.z 14 for Ethernet adapters; does not correspond to the length of the actual packet physical layer header, but only to the part passed to the network adapter.mtu: maximum transfer unit in a layer-2 frame (1500 bytes for Ethernet).tx_queue_len: specifies the maximum length of the output queue of the network device.2. Hardware-Specific Fieldstype: specifies the hardware type of the network adapter, e.g., ARPHRD_ETHER, ARPHRD_IEEE802, ARPHRD_LOOPBACKaddr_len, dev_addr[MAX_ADDR_LEN], broadcast[MAX_ADDR_LEN]: the length of the layer-2 address, the layer-2 address, and the broadcast address.dev_mc_list: points to a linear list that contains multicast layer-2 addresses.z set_multicast_list() is used to pass the list to the network adapter.mc_count: the number of addresses in dev_mc_list.2. Hardware-Specific Fieldswatchdog_timer is initialized when a network device starts.The handling routine dev_watchdog() is called after watchdog_timeo time units, and checks whether or not watchdog_timeo time units have passed since the last transmission of a packet.z Yes, tx_timeout() of the driver is called.z No, the watchdog timer is restarted.3. Network Layer Fieldsip_ptr, ip6_ptr: point to the information of layer 3 protocols that use the network device, e.g., ip_ptr points to a structure of type in_device (that keeps track of a list of IP addresses of the network device, a list of IP mluticast groups, and the parameters for the ARP protocol).family: designates the address family of the network device, e.g., AF_INETpa_alen: the length of the addresses, e.g., 4 bytes.pa_addr, pa_braddr, pa_mask: the address, the broadcast address, and the network mask.pa_dstaddr: specifies the address of the other partner in a point-to-point connection.3. Network Layer Fieldsflags: properties of the network devicez IFF_UP: the device is on.z IFF_ARP: the device supports ARPz IFF_BROADCAST: the device is broadcast-enabled. (If this flag is set, then pa_braddr contains the broadcast address.)z IFF_LOOKBACK: the device is a loopback network device. z IFF_POINTTOPOINT: this is a point-to-point connection. (If this flag is set, then pa_dstaddr contains the address on the other end.)z IFF_PROMISC: this flag switches the promiscuous mode on.z IFF_MULTICAST: activates the receipt of multicast packets.4. Device-Driver MethodsFunctions that are related to the network adapter.init(): is used to initialize a network device. z A
View Full Document