400 likes | 580 Views
Interface Layer. 2005. 5. 23 백 일 우 steigensonne@hufs.ac.kr. Contents. Intro ifnet Strucure ifaddr Structure sockaddr Structure Ifnet and ifaddr Specialization Network initialization overview Ethernet initialization SLIP initialization Lookback Initialization if_attach Function
E N D
Interface Layer 2005. 5. 23 백 일 우 steigensonne@hufs.ac.kr
Contents • Intro • ifnet Strucure • ifaddr Structure • sockaddr Structure • Ifnet and ifaddr Specialization • Network initialization overview • Ethernet initialization • SLIP initialization • Lookback Initialization • if_attach Function • Ifinit Function
Intro • Interface Layer provides,.. • A well-defined ser of interface functions • A standard set of statistics and control flags • A device-independent method of string protocol addresses • A standard queueing method for outgoing packets • Only Best-effort service • Higher layers must compensate for lacks of reliability • Refer to three particular network interfaces from Net/3 • AMD 7990 LANCE Ethernet interface • Serial Line IP(SLIP) interface • Lookback interface
Code Introduction • Three Hearders and Two C files for structure and init. • Global variables
Ifnet Steucture • Contains information common to all interfaces • A separate ifnet is allocated for each network device • Every ifnet has a list of one ore more protocol addresses Protocol address 1. SLIP support only a single protocol, but Ethernet do multiple protocols - Eth could have Internet and OSI protocols 2. Possiblefor one network interface to offer multiple addresses within a single protocol ※
ifnet structure_con’t If_name : Short string that identifies interface type If_bpf, if_pcount : For BSD Packet filter - A process can receive copies of packets transmitted or received by an interface If_unit : Identifies multiple instances of the same type If_timer - time in senconds until the kernel calls if_watchdog function - if_watchdog may used by device driver to collect interface statistics at regular intervals or reset
Ifnet structure_variables(II) • If System has two SLIP interfaces, • If_name : “sl” • If_unit : 1 for first, 2 is second • if_flags Device_specific flags may or may not be modifiable depending on the device
If_data in ifnet structure /* other ifnet members */
If_data in ifnet structure • If_type specifies hardware address type supported by the interface • If_addrlen is the length of the data_link address • If_hdrlen is the length of the header attached to outgoing packet by HW • Ethernet header length is 14bytes • If_mtuis maximum transmission unit of interface • Control size of packet created by network and transport protocols • Ethernet is 1500 • If_metric is usually 0 • if_baudrate means transmission speed of the interface • Only set by SLIP
If_data in ifnet structure • If_collision : incremented when trans interrupted on shared media such as ethernet • If_noproto : count the packets when the protocol is not supproted • SLIP can support only IP • If_lastchange : the last time any of the statistics were changed
ifqueue in ifnet structure • Each if has its own ifnet and therefore its own output queue • Maximum is set to 50 • From the global integer ifqmaxlen, which is initialized at compile from IFQ_MAXLEN • Queue is made up as a linked list of mbuf chains • Ifq_drops counts packets discarded because of FULL ifq_len : current length of queue ifq_maxlen : maximum length of queue ifq_drops : packets dropped because of full queue
Ifaddr structure • Each interface maintains a linked-list of ifaddr structures • Data_link, such as ethernet, offer more than one protocols • ifaddr structure describes each address assigned to the interface, usually one address per protocol • To support multiple addresses • Many protocols(TCP/IP) supprot multiple addresses assigned to a single physical interface
ifaddr strucuture Counts references to the ifaddr structure - shared by the interface and routing data structures Support routing lookups for the interface ※ MACRO : IFAFREE 1. It decrements counter and return if there are other references 2. Avoids a function call overhead 3. If last reference, IFAFREE call ifafree func, which release the structure
sockaddr structure • Every protocol has its own address format • Net/3 handles generic addresses in a sockaddr structure • sa_len : length of address • sa_family • sa_data is defined to be an array of 14 bytes,.. • But, when sockaddr overlays a larger are of memory, sa_data may be up to 253 bytes long • sa_len is only a single byte, so the size(total) must be less than 256
ifnet and ifaddr Specialization • To accommodate additional device and protocol-specific info • Each driver defines and each protocol allocates a specialized version of ifnet and ifaddr • These structures contain original ifnet or ifaddr as their first member • So, can be accessed without consideration for additional special info • Each device structure begins with ifnet • Lookback declares only ifnet • No need to require any device_dependent data
Arrangement of ifnet within device_dependent Structure • Common to all ethernet drivers and contains info for ARP • and Ethernet multicasting Contains additional info unique to the LANCE ethernet driver
Specialized ifaddr structure • Each protocol has its own specialized ifaddr structure • IP use in_ifaddr, OSI use iso_ifaddr • Kernel assigns each interface a link-level address when init • Kernel construct link-level address : one ifaddr, two sockaddr_dl • One sockaddr for link-level address itself • The other for link-level address mask
Network Initialization Overview • All structures described are allocated and attached during kernel initialization • Some device ,such as SLIP, lookback, are implemented entirely in software • These pseudo-devices are represented by a pdevinit structure • pdevinit is stored in the global pdevinit • Constructed during kernel configuration The number of devices to create
/* none network code */ /* none network code */ /* none network code */ Main Function : Network initialization Locate & Initialize all the Hardware devices Finish initialization of interfaces and protocols Scheduler begins the kernel process scheduler
Ethernet Initialization ac_enaddr : ethernet HW address copied by the LANCE device driver - when? During cpu_startup() ac_ipaddr : the las IP address assigned to the device ac_multiaddrs : a list of ethernet multicast addresses represented by ether_multi structure ac_multicnt : counts the entries in the list
leattach() function for LANCE ethernet driver Hd contains HP-specific info, since this driver is written for an HP workstation Points to specialized ifnet Points to first member of that structure HW address is copied from device to sc_addr Initialize the ifnet structure /* 1500 */ LANCE doesn’t receive its own transmissions Register interface with BPF Insert initialized ifnet into linked-list of interface
SLIP Initialization • Initialized when main calls ‘slattach’ indirectly through the ‘pdev_attach’ pointer in SLIP’s pdevinit structure
SLIP Initialization • sc_fastq : packets requesting low_delay service • sc_ttyp : pointer to the associated terminal • sc_flags • sc_escape : used by IP encapsulation mechanism for SLIP
SLIP Initialization Initialize sl_softc structure 296 bytes(SLMTU) (DEFAULT) ※ Unlike leattach, which initializes only one interface at a time, the kernel calls slattach once and slattach initializes all SLIP interfaces
Lookback Initialization • Places any outgoing packets back on an appropriate input Q • No hardware • Initialized when main calls ‘loopattach’ indirectly through the ‘pdev_attach’ pointer in the lookback’s pdevinit /* 1536 */ No link header or HW address
if_attach Functioan 1. Three times if_attach has been called - leattach => lesoftc structure - slattach => sl_softc, loopattach => loif 2. Create link-level ifaddr(which contains two sockaddr_dl) => p21,22 3. Not yet configured about higherprotocoladdress(eg., IP)
sockaddr_dl • Contains a name and numeric index for interface • Supports a tablelookup for converting between an interface index and the associated ‘ifaddr’ structure /* unused */ Sdl_len : entire address length Sdl_family : address family Sdl_index : interface within kernel - eth index is 1, SLIP 2, loopback 3 If_index : last index assigned by the kernel Sdl_type : initialized by ifent’s if_type
if_attach • Updates Two global variables • if_index : hold the index of the last interface in the system • ifnet_addr : pointer to an array of ifaddr pointers • Have a single argument ‘ifp’ a pointer to the ifnet • While loop locates the end of the list, so saves address of null pointer at the end of the list in ‘p’ • After loop, the new ifnet is attached to the end of the list, if_index is incremented • The new index is assigned to ifp->if_index
if_attach() Previous explanation Array becomes full 1. Blocks the calling process if it needs to wait for free Memory to become available 2. What about M_DONWAIT? No bloack and retuen NULL when not enough memory
if_attach() Constructs the name of the interface from if_unit and if_name - sprint_d converts numeric value if_unit to a string in workbuf Masklength : the number of bytes occupied by the information before sdl_data in the sockaddr_dl array plus size of text name for interface
if_attach : allocate and initialize link-level address Points to the first sockaddr_dl /* ifp pointer type : ifnet */ 1 Second sockaddr_dl is a bit mask 2 3 1 : Initialize the sockaddr_dl address 2 : Initialize the sockaddr_dl mask 3 : ether_ifattach function is called for Ethernet devices
if_attach() • Structures after the first interface has been attached by if_attach • Initialized Ehternet sockaddr_dl structure
ether_ifattach /* it performs ifnet structure initialization common to all Ethernet devices */ /* HW address length is 6 bytes */ /* total length : 14 bytes */ The Ethernet address that was copied into the arpcom structure during system Init is now copied into the link-level address
ifinit Function • After the interface structures are initialized and linked together, main calls ifinit() • The ‘for’ loop traverse the interface list and sets the maximum size of each interface output queue to 50 • If it hasn’t already been set by the interface’s attach function Ifqueue structure
if_slowtimo • if_slowtimo starts the interface watchdog timers • When timer expires, kernel calls watchdog function for the interface • Interface can reset timer periodically to prevent the watchdog func from call • Or, set if_timer to 0 if the watchdog func is not needed Not used It blocks packet processing during if_slowtimo To schedule a call to itself in hz / IFNET_SLOWHZ clock ticks hz : the number of clock ticks in 1sec IFNET_SLOWZ : defined to be 1,. Kernel calls if_slowtimo once every hz clock ticks, which is once per second