Linux数据包的发送过程

发布时间:2021-09-16 23:22:42 作者:chen
来源:亿速云 阅读:144

本篇内容介绍了“Linux数据包的发送过程”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

socket层

               +-------------+                | Application |                +-------------+                      |                      |                      ↓ +------------------------------------------+ | socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP) | +------------------------------------------+                      |                      |                      ↓            +-------------------+            | sendto(sock, ...) |            +-------------------+                      |                      |                      ↓               +--------------+               | inet_sendmsg |               +--------------+                      |                      |                      ↓              +---------------+              | inet_autobind |              +---------------+                      |                      |                      ↓                +-----------+                | UDP layer |                +-----------+

UDP层

     |             |             ↓      +-------------+      | udp_sendmsg |      +-------------+             |             |             ↓  +----------------------+  | ip_route_output_flow |  +----------------------+             |             |             ↓      +-------------+      | ip_make_skb |      +-------------+             |             |             ↓ +------------------------+ | udp_send_skb(skb, fl4) | +------------------------+             |             |             ↓        +----------+        | IP layer |        +----------+

IP层

        |          |          &darr;   +-------------+   | ip_send_skb |   +-------------+          |          |          &darr;  +-------------------+       +-------------------+       +---------------+  | __ip_local_out_sk |------>| NF_INET_LOCAL_OUT |------>| dst_output_sk |  +-------------------+       +-------------------+       +---------------+                                                                  |                                                                  |                                                                  &darr; +------------------+        +----------------------+       +-----------+ | ip_finish_output |<-------| NF_INET_POST_ROUTING |<------| ip_output | +------------------+        +----------------------+       +-----------+          |          |          &darr;  +-------------------+      +------------------+       +----------------------+  | ip_finish_output2 |----->| dst_neigh_output |------>| neigh_resolve_output |  +-------------------+      +------------------+       +----------------------+                                                                   |                                                                   |                                                                   &darr;                                                           +----------------+                                                           | dev_queue_xmit |                                                           +----------------+

netdevice子系统

                      |                         |                         &darr;                  +----------------+ +----------------| dev_queue_xmit | |                +----------------+ |                       | |                       | |                       &darr; |              +-----------------+ |              | Traffic Control | |              +-----------------+ | loopback              | |   or                  +--------------------------------------------------------------+ | IP tunnels            &darr;                                                              | |                       &darr;                                                              | |            +---------------------+  Failed   +----------------------+         +---------------+ +----------->| dev_hard_start_xmit |---------->| raise NET_TX_SOFTIRQ |- - - - >| net_tx_action |              +---------------------+           +----------------------+         +---------------+                         |                         +----------------------------------+                         |                                  |                         &darr;                                  &darr;                 +----------------+              +------------------------+                 | ndo_start_xmit |              | packet taps(AF_PACKET) |                 +----------------+              +------------------------+

Device Driver

ndo_start_xmit会绑定到具体网卡驱动的相应函数,到这步之后,就归网卡驱动管了,不同的网卡驱动有不同的处理方式,这里不做详细介绍,其大概流程如下:

  1. 将skb放入网卡自己的发送队列

  2. 通知网卡发送数据包

  3. 网卡发送完成后发送中断给CPU

  4. 收到中断后进行skb的清理工作

在网卡驱动发送数据***程中,会有一些地方需要和netdevice子系统打交道,比如网卡的队列满了,需要告诉上层不要再发了,等队列有空闲的时候,再通知上层接着发数据。

其它

“Linux数据包的发送过程”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!

推荐阅读:
  1. 路由器转发数据包的封装过程是怎样的
  2. Oracle发送邮件存储过程

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

linux

上一篇:Maven Scope的概念及分类说明

下一篇:xtrabackup与mysqldump的对比测试

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》