网络设备驱动高级开发

网络设备不同于字符设备和块设备,它没有设备文件 ,但是它有不同于二者的套接字

       套接字缓存区(sk_buff)结构是Linux 网络子系统(网卡)的核心内容,在<Linux/skbuff.h>中被定义

      

       linux 套接字缓冲区支持分配,释放,指针的移动等功能函数

       1>分配   struct sk_buff *dev_alloc_skb(unsigned int len);

       2>释放   void dev_kfree_skb(struct sk_buff *skb);

       3>指针的移动

             a:put 操作

                  unsigned char *skb_put(strcut sk_buff *skb,unsigned int len);

             b:push 操作

unsigned char *skb_push(struct sk_buff *skb,unsigned int len);

             c:pull操作

unsigned char * skb_pull(struct sk_buff *skb,unsigned int len);

             d:reserve 操作

                 void skb_reserve(struct sk_buff *skb,unsigned int len);

       net_device结构在内核中指代一个网络设备,网络驱动程序只需通过填充net_device 的具体成员并注  册,net_device 即可实现硬件操作函数和内核的挂接

       基本方法包括:

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

            int (*stop)(strcut net_device *dev);

            int (*hard_start_xmit)(struct sk_buff *skb,struct net_device *dev);

            int (*hard_header)(struct sk_buff *skb,struct net_device *dev,unsigned short type,void *daddr,void *saddr,unsigned len);

            int (*rebuild_header)(struct sk_buff *skb);

            void(*tx_timeout)(strcut net_device *dev);

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

            int (*set_config)(struct net_device *dev,struct ifmap *map);

            int (*do_ioctl)(struct net_device *dev,struct ifreq *ifr,int cmd);

            void (*set_multicast_list)(struct net_device *dev);

            int (*set_mac_address)(strcut net_device *dev,void *adddr);

            int (*change_mtu)(struct net_device *dev,int new_mtu);

            int (*headerA_cache)(struct neighbour *neigh,struct hh_cache *hh);

            int (*header_cache_update)(struct hh_cache *hh,struct net_device *dev,unsigned char*haddr);

            int(*hard_header_parse)(struct sk_buff *skb,unsigned char *haddr);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值