Windows XP Windows 7 Windows 2003 Windows Vista Windows教程綜合 Linux 系統教程
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟件教程
 Windows教程網 >> Linux系統教程 >> Linux教程 >> Linux網絡協議棧之網絡設備管理

Linux網絡協議棧之網絡設備管理

日期:2017/2/7 14:39:52      編輯:Linux教程
 

Linux素以優秀的網絡管理能力而著稱,linux為何具有這麼高的效率?我們從網絡設備的管理說起。

Linux為何要對網絡設備單獨管理呢?這是因為。協議棧很多地方都會涉及到網絡設備。小至IP地址的設置。大至IP路由的更新。都離不開高效的網絡設備管理。將網絡設備單獨管理可以提高效率!

每個網絡設備,在linux中都會對應一個數據結構,net_device。 就從這個結構說起

Linux 2。6。21中,對net_device定義如下:

struct net_device

{

//設備的名稱,例如常見的“eth0”等

char name[IFNAMSIZ];

//共享內存的起始,結束地址

unsigned long mem_end; /* shared mem end */

unsigned long mem_start; /* shared mem start */

//網絡設備的I/O基地址

unsigned long base_addr; /* device I/O address */

//被賦予的中斷號

unsigned int irq; /* device IRQ number */

//在多端口設備上使用哪一個端口

unsigned char if_port; /* Selectable AUI, TP,..*/

//為設備分配的DMA通道

unsigned char dma; /* DMA channel */

//設備的狀態

unsigned long state;

// 下一個net_device

struct net_device *next;

//初始化函數。

int (*init)(struct net_device *dev);

struct net_device *next_sched;



/* Interface index. Unique device identifier */

//設備在內核中對應的序號

int ifindex;

int iflink;



//獲得接口狀態的函數指針

struct net_device_stats* (*get_stats)(struct net_device *dev);

struct iw_statistics* (*get_wireless_stats)(struct net_device *dev);



struct iw_handler_def * wireless_handlers;

struct ethtool_ops *ethtool_ops;

//傳輸狀態。檢查傳輸是否被鎖住

unsigned long trans_start; /* Time (in jiffies) of last Tx */

//最使使用的時間

unsigned long last_rx; /* Time of last Rx */

//接口標志

unsigned short flags; /* interface flags (a la BSD) */

unsigned short gflags;

unsigned short priv_flags; /* Like 'flags' but invisible to userspace. */

unsigned short unused_alignment_fixer; /* Because we need priv_flags,

* and we want to be 32-bit aligned.

*/



unsigned mtu; /* interface MTU value */

unsigned short type; /* interface hardware type */

unsigned short hard_header_len; /* hardware hdr length */

void *priv; /* pointer to private data */



struct net_device *master; /* Pointer to master device of a group,

* which this device is member of.

*/



/* Interface address info. */

unsigned char broadcast[MAX_ADDR_LEN]; /* hw bcast add */

unsigned char dev_addr[MAX_ADDR_LEN]; /* hw address */

unsigned char addr_len; /* hardware address length */



struct dev_mc_list *mc_list; /* Multicast mac addresses */

int mc_count; /* Number of installed mcasts */

int promiscuity;

int allmulti;



int watchdog_timeo;

struct timer_list watchdog_timer;



/* Protocol specific pointers */

 

void *atalk_ptr; /* AppleTalk link */

void *ip_ptr; /* IPv4 specific data */

void *dn_ptr; /* DECnet specific data */

void *ip6_ptr; /* IPv6 specific data */

void *ec_ptr; /* Econet specific data */

void *ax25_ptr; /* AX.25 specific data */



struct list_head poll_list; /* Link to poll list */

int quota;

int weight;



struct Qdisc *qdisc;

struct Qdisc *qdisc_sleeping;

struct Qdisc *qdisc_ingress;

struct list_head qdisc_list;

unsigned long tx_queue_len; /* Max frames per queue allowed */



/* ingress path synchronizer */

spinlock_t ingress_lock;

/* hard_start_xmit synchronizer */

spinlock_t xmit_lock;

/* cpu id of processor entered to hard_start_xmit or -1,

if nobody entered there.

*/

int xmit_lock_owner;

/* device queue lock */

spinlock_t queue_lock;

/* Number of references to this device */

atomic_t refcnt;

/* delayed register/unregister */

struct list_head todo_list;

/* device name hash chain */

struct hlist_node name_hlist;

/* device index hash chain */

struct hlist_node index_hlist;

Copyright © Windows教程網 All Rights Reserved