您的位置:首页 > 理论基础 > 计算机网络

深入理解linux网络内幕--API总结

2014-11-09 10:37 387 查看
1. unsigned char *skb_put(struct sk_buff *skb, unsigned int len)

添加数据到sk_buff的尾部(tail)

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

添加数据到sk_buff的头部,

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

//从sk_buffer的开始移除数据,skb_pull和skb_push时相反的过程

4. void skb_reserve(struct sk_buff *skb, int len)

//预留空间,只能针对空buffer有效

5. struct sk_buff *alloc_skb(unsigned int size,gfp_t priority)

//分配一个缓冲区

6.struct sk_buff *netdev_alloc_skb(struct net_device *dev,

unsigned int length)

//特定网络设备驱动用于在中断处理函数中,分配一个缓冲区,

7. void kfree_skb(struct sk_buff *skb)

//减少skb_buffer的引用计数,如果为0,则释放内存

8. void skb_queue_head_init(struct sk_buff_head *list) //初始化缓冲区队列

void skb_queue_head(struct sk_buff_head *list, struct sk_buff *newsk)//把sk_buffer放在队列头部

void skb_queue_tail(struct sk_buff_head *list, struct sk_buff *newsk)//把sk_buffer放在队列尾部

struct sk_buff *skb_dequeue_tail(struct sk_buff_head *list)//从队列尾部获取sk_buffer

struct sk_buff *skb_dequeue(struct sk_buff_head *list)//从队列头部获取sk_buffer

skb_queue_walk(queue,skb)

9.给设备添加多播地址

int dev_mc_add(struct net_device *dev, const unsigned char *addr)

int dev_mc_del(struct net_device *dev, const unsigned char *addr)

10.分配net_device设备

struct net_device *alloc_netdev_mqs(int sizeof_priv, const char *name,

void (*setup)(struct net_device *),

unsigned int txqs, unsigned int rxqs)

alloc_netdev和alloc_netdev_mq是此函数的封装

11 net_device发送队列开启/关闭

void netif_tx_start_all_queues(struct net_device *dev)//清除标志位

void netif_wake_subqueue(struct net_device *dev, u16 queue_index)//清除标志位,并重新调度

void netif_tx_stop_all_queues(struct net_device *dev)

void netif_stop_subqueue(struct net_device *dev, u16 queue_index)//停止某一个队列

void __netif_schedule(struct Qdisc *q) //add a tx task,and raise SOFTTX irq

2.6.26之前的API接口是

void netif_start_queue(struct net_device *dev)

void netif_stop_queue(struct net_device *dev)

12.发送数据

int dev_queue_xmit(struct sk_buff *skb)//最终通过net_device的ndo_start_xmit发送出去

13.获取网络设备

//通过网络设备名字获取

struct net_device *dev_get_by_name(struct net *net, const char *name)

//通过网络设备index获取

struct net_device *__dev_get_by_index(struct net *net, int ifindex)

14.开启设备传输载波功能

void netif_carrier_off(struct net_device *dev)

void netif_carrier_on(struct net_device *dev)

15.irq相关函数

__raise_softirq_irqoff(unsigned int nr)//标记软中断为未决状态

raise_softirq_irqoff(unsigned int nr)//标记软件中断为未决状态,如果为非interrupt上下文,则唤醒softirqd

local_bh_enable() //使能cpu下部分中断

local_bh_disable()//关闭cpu下部分中断

in_interrupt()//判断是否为硬中断和软件中断上下文

in_irq()//判断是否为硬中断上下文

preempt_disabel() //禁止抢占

preempt_enable() //使能抢占
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: