40
Interface Layer 2005. 5. 23 백 백 백 [email protected]

Interface Layer 2005. 5. 23 백 일 우 [email protected]

Embed Size (px)

Citation preview

Page 1: Interface Layer 2005. 5. 23 백 일 우 steigensonne@hufs.ac.kr

Interface Layer

2005. 5. 23백 일 우

[email protected]

Page 2: Interface Layer 2005. 5. 23 백 일 우 steigensonne@hufs.ac.kr

2

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

Page 3: Interface Layer 2005. 5. 23 백 일 우 steigensonne@hufs.ac.kr

3

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

Page 4: Interface Layer 2005. 5. 23 백 일 우 steigensonne@hufs.ac.kr

4

Code Introduction

Three Hearders and Two C files for structure and init.

Global variables

Page 5: Interface Layer 2005. 5. 23 백 일 우 steigensonne@hufs.ac.kr

5

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

Page 6: Interface Layer 2005. 5. 23 백 일 우 steigensonne@hufs.ac.kr

6

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

Page 7: Interface Layer 2005. 5. 23 백 일 우 steigensonne@hufs.ac.kr

7

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

Page 8: Interface Layer 2005. 5. 23 백 일 우 steigensonne@hufs.ac.kr

8

If_data in ifnet structure

/* other ifnet members */

Page 9: Interface Layer 2005. 5. 23 백 일 우 steigensonne@hufs.ac.kr

9

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_mtu is 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

Page 10: Interface Layer 2005. 5. 23 백 일 우 steigensonne@hufs.ac.kr

10

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

Page 11: Interface Layer 2005. 5. 23 백 일 우 steigensonne@hufs.ac.kr

11

Interface functions

Page 12: Interface Layer 2005. 5. 23 백 일 우 steigensonne@hufs.ac.kr

12

ifqueue in ifnet structure

ifq_len : current length of queue

ifq_maxlen : maximum length of queue

ifq_drops : packets dropped because of full queue

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

Page 13: Interface Layer 2005. 5. 23 백 일 우 steigensonne@hufs.ac.kr

13

ifqueue routines

Page 14: Interface Layer 2005. 5. 23 백 일 우 steigensonne@hufs.ac.kr

14

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

Page 15: Interface Layer 2005. 5. 23 백 일 우 steigensonne@hufs.ac.kr

15

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

Page 16: Interface Layer 2005. 5. 23 백 일 우 steigensonne@hufs.ac.kr

16

ifnet and ifaddr structures

Page 17: Interface Layer 2005. 5. 23 백 일 우 steigensonne@hufs.ac.kr

17

sockaddr structure

Page 18: Interface Layer 2005. 5. 23 백 일 우 steigensonne@hufs.ac.kr

18

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

sockaddr structure

Page 19: Interface Layer 2005. 5. 23 백 일 우 steigensonne@hufs.ac.kr

19

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

Page 20: Interface Layer 2005. 5. 23 백 일 우 steigensonne@hufs.ac.kr

20

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

Page 21: Interface Layer 2005. 5. 23 백 일 우 steigensonne@hufs.ac.kr

21

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

Page 22: Interface Layer 2005. 5. 23 백 일 우 steigensonne@hufs.ac.kr

22

Ethernet interface with link-level, Internet, OSI address

Page 23: Interface Layer 2005. 5. 23 백 일 우 steigensonne@hufs.ac.kr

23

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

Page 24: Interface Layer 2005. 5. 23 백 일 우 steigensonne@hufs.ac.kr

24

Main Function : Network initialization

/* none network code */

/* none network code */

/* none network code */

Locate & Initialize all the Hardware devices

Finish initialization of interfaces and protocols

Scheduler begins the kernel process scheduler

Page 25: Interface Layer 2005. 5. 23 백 일 우 steigensonne@hufs.ac.kr

25

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

Page 26: Interface Layer 2005. 5. 23 백 일 우 steigensonne@hufs.ac.kr

26

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 */

Register interface with BPF

Insert initialized ifnet into linked-list of interface

LANCE doesn’t receive its own transmissions

Page 27: Interface Layer 2005. 5. 23 백 일 우 steigensonne@hufs.ac.kr

27

SLIP Initialization

Initialized when main calls ‘slattach’ indirectly through the ‘pdev_attach’ pointer in SLIP’s pdevinit structure

Page 28: Interface Layer 2005. 5. 23 백 일 우 steigensonne@hufs.ac.kr

28

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

Page 29: Interface Layer 2005. 5. 23 백 일 우 steigensonne@hufs.ac.kr

29

SLIP Initialization

Initialize sl_softc structure

※ Unlike leattach, which initializes only one interface at a time, the kernel calls slattach once

and slattach initializes all SLIP interfaces

296 bytes(SLMTU)

(DEFAULT)

Page 30: Interface Layer 2005. 5. 23 백 일 우 steigensonne@hufs.ac.kr

30

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

No link header or HW address

/* 1536 */

Page 31: Interface Layer 2005. 5. 23 백 일 우 steigensonne@hufs.ac.kr

31

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)

Page 32: Interface Layer 2005. 5. 23 백 일 우 steigensonne@hufs.ac.kr

32

sockaddr_dl

Contains a name and numeric index for interface Supports a tablelookup for converting between an interface index and

the associated ‘ifaddr’ structure

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

/* unused */

Page 33: Interface Layer 2005. 5. 23 백 일 우 steigensonne@hufs.ac.kr

33

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

Page 34: Interface Layer 2005. 5. 23 백 일 우 steigensonne@hufs.ac.kr

34

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

Page 35: Interface Layer 2005. 5. 23 백 일 우 steigensonne@hufs.ac.kr

35

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

Page 36: Interface Layer 2005. 5. 23 백 일 우 steigensonne@hufs.ac.kr

36

if_attach : allocate and initialize link-level address

Points to the first sockaddr_dl

Second sockaddr_dl is a bit mask

1

2

1 : Initialize the sockaddr_dl address

2 : Initialize the sockaddr_dl mask

3 : ether_ifattach function is called for Ethernet devices

3

/* ifp pointer type : ifnet */

Page 37: Interface Layer 2005. 5. 23 백 일 우 steigensonne@hufs.ac.kr

37

if_attach()

Structures after the first interface has been attached by if_attach

Initialized Ehternet sockaddr_dl structure

Page 38: Interface Layer 2005. 5. 23 백 일 우 steigensonne@hufs.ac.kr

38

ether_ifattach

/* HW address length is 6 bytes *//* total length : 14 bytes */

/* it performs ifnet structure initialization common to all Ethernet devices */

The Ethernet address that was copied into the arpcom structure during system Init is now copied into the link-level

address

Page 39: Interface Layer 2005. 5. 23 백 일 우 steigensonne@hufs.ac.kr

39

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

Page 40: Interface Layer 2005. 5. 23 백 일 우 steigensonne@hufs.ac.kr

40

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