在好例子网,分享、交流、成长!
您当前所在位置:首页C/C++ 开发实例Linux内核编程 → 嵌入式Linux网络体系结构设计与TCPIP协议栈

嵌入式Linux网络体系结构设计与TCPIP协议栈

Linux内核编程

下载此实例
  • 开发语言:C/C++
  • 实例大小:3.35M
  • 下载次数:1
  • 浏览次数:16
  • 发布时间:2022-01-15
  • 实例类别:Linux内核编程
  • 发 布 人:rz21
  • 文件格式:.pdf
  • 所需积分:2
 相关标签: linux tcpIP 体系结构 tcp 嵌入式

实例介绍

【实例简介】嵌入式Linux网络体系结构设计与TCPIP协议栈 

【实例截图】


【核心代码】

目 录
第 1 章 概述···················································································································1
1.1 Linux 内核组件·······································································································1
1.2 Linux 内核中的活动 ·······························································································3
1.2.1 进程和系统调用··························································································3
1.2.2 硬件中断······································································································4
1.2.3 tasklet ···········································································································6
1.2.4 workqueue····································································································6
1.2.5 软件中断······································································································7
1.3 互斥机制 ·················································································································7
1.3.1 spin lock ·······································································································8
1.3.2 读-写 spin lock························································································10
1.3.3 读-复制-更新(Read-Copy-Update,RCU) ······································10
1.4 内核模块(module)·····························································································11
1.4.1 管理内核模块·····························································································11
1.4.2 自动装载模块····························································································12
1.4.3 模块功能的注册和取消·············································································13
1.4.4 在模块装载时给模块传递参数·································································14
1.4.5 内核和模块的符号表·················································································14
1.5 内存资源 ···············································································································15
1.5.1 高速缓冲区(memory cache)··································································15
1.5.2 高速缓存和哈希链表·················································································16
1.6 时间管理 ···············································································································16
1.7 嵌入式的挑战········································································································17
1.8 本章总结 ···············································································································18
第 2 章 Linux 网络包传输的关键数据结构——Socket Buffer·······································19
2.1 Socket Buffer 设计概述························································································19
2.1.1 Socket Buffer 与 TCP/IP 协议栈································································19
2.1.2 Socket Buffer 的对外接口 ·········································································20
嵌入式 Linux 网络体系结构设计与 TCP/IP 协议栈
VI Linux
2.1.3 Socket Buffer 的特点·················································································20
2.2 Socket Buffer 的构成·····························································································20
2.2.1 Socket Buffer 的基本组成 ·········································································21
2.2.2 Socket Buffer 穿越 TCP/IP 协议栈····························································22
2.3 sk_buff 数据域的设计和含义···············································································24
2.3.1 sk_buff 中的结构管理域···········································································24
2.3.2 常规数据域································································································27
2.3.3 sk_buff 的网络功能配置域·······································································32
2.4 操作 sk_buff 的函数······························································································34
2.4.1 创建和释放 Socket Buffer ·········································································35
2.4.2 数据空间的预留和对齐·············································································40
2.4.3 复制和克隆································································································41
2.4.4 操作队列的函数························································································43
2.4.5 引用计数的操作························································································44
2.4.6 协议头指针操作························································································44
2.5 数据分片和分段····································································································45
2.5.1 为什么要分割数据包·················································································45
2.5.2 设计 skb_shared_info 数据结构的目的·····················································46
2.5.3 操作 skb_shared_info 的函数 ····································································46
2.6 本章总结 ···············································································································47
第 3 章 网络设备在内核中的抽象——struct net_device 数据结构·······························48
3.1 协议栈与网络设备································································································49
3.1.1 协议栈软件与网络设备硬件之间的接口 ·················································49
3.1.2 设备独立接口文件 dev.c ···········································································50
3.1.3 设备驱动程序····························································································51
3.1.4 struct net_device 数据结构·········································································51
3.2 struct net_device 数据结构···················································································52
3.2.1 struct net_device 数据结构的数据域·························································52
3.2.2 struct net_device 数据结构的其他数据域·················································56
3.3 struct net_device 数据结构中数据域的功能分类·················································63
3.3.1 设备管理域································································································64
3.3.2 设备配置管理域························································································64
目 录
Linux VII
3.3.3 设备状态····································································································65
3.3.4 统计············································································································65
3.3.5 设备链表····································································································66
3.3.6 链路层组传送····························································································66
3.3.7 流量管理····································································································66
3.3.8 常规域········································································································69
3.3.9 操作函数结构····························································································69
3.4 函数指针 ···············································································································69
3.4.1 设备初始化································································································70
3.4.2 传送············································································································71
3.4.3 硬件协议头································································································71
3.4.4 网络统计状态····························································································73
3.4.5 修改配置····································································································73
3.5 本章总结 ···············································································································74
第 4 章 网络设备在 Linux 内核中识别··········································································75
4.1 内核初始化的特点································································································76
4.1.1 命令行参数································································································76
4.1.2 网络子系统的命令行参数·········································································78
4.2 内核启动过程········································································································80
4.2.1 用 do_initcall 函数完成的初始化······························································83
4.2.2 标记初始化函数的宏·················································································84
4.2.3 网络子系统初始化 ····················································································85
4.2.4 网络设备的初始化 ····················································································86
4.3 网络设备的注册和 struct net_device 数据结构实例的初始化·····························88
4.3.1 初始化函数的任务 ····················································································88
4.3.2 网络设备的注册和注销·············································································92
4.3.3 网络设备的引用计数(reference count)·················································97
4.3.4 允许和禁止网络设备·················································································98
4.4 网络设备的管理····································································································99
4.4.1 管理网络设备的链表·················································································99
4.4.2 网络设备的搜索函数···············································································101
4.5 事件通知链··········································································································102
嵌入式 Linux 网络体系结构设计与 TCP/IP 协议栈
VIII Linux
4.5.1 事件通知链构成······················································································103
4.5.2 注册回调函数到事件通知链···································································104
4.5.3 通知子系统有事件发生···········································································106
4.5.4 网络子系统中的事件通知链···································································107
4.5.5 网络子系统传送的事件···········································································108
4.6 本章总结 ·············································································································108
第 5 章 网络设备驱动程序·························································································109
5.1 网络设备驱动程序概述······················································································109
5.1.1 网络设备驱动程序的任务········································································110
5.1.2 网络设备驱动程序的构成········································································110
5.2 网络设备与内核的交互·······················································································113
5.2.1 设备与内核的交互方式············································································113
5.2.2 硬件中断···································································································115
5.2.3 中断在内核的实现 ···················································································117
5.2.4 软件中断··································································································120
5.3 网络设备驱动程序的实现··················································································127
5.3.1 网络适配器的初始化···············································································127
5.3.2 网络设备活动功能函数···········································································132
5.3.3 网络设备管理函数 ··················································································143
5.3.4 在适配器中支持组发送···········································································145
5.4 CS8900A 网络适配器驱动程序的实现······························································149
5.4.1 CS8900A 网络控制芯片的功能概述 ······················································149
5.4.2 CS8900A 的 PacketPage 结构··································································151
5.4.3 CS8900A 的操作······················································································153
5.4.4 CS8900A 设备驱动程序分析··································································157
5.5 本章总结 ·············································································································167
第 6 章 数据链路层数据帧的收发 ··············································································168
6.1 关键数据结构······································································································170
6.1.1 struct napi_struct 数据结构······································································170
6.1.2 struct softnet_data 数据结构 ····································································171
6.2 数据帧的接收处理······························································································173
目 录
Linux IX
6.2.1 NAPI 的实现····························································································174
6.2.2 netif_rx 函数分析·····················································································178
6.3 网络接收软件中断······························································································182
6.3.1 net_rx_action 的工作流程········································································182
6.3.2 net_rx_action 函数的实现细节································································183
6.3.3 从输入队列中读取数据帧·······································································185
6.3.4 处理输入数据帧······················································································186
6.4 数据链路层与网络层的接口 ··············································································190
6.4.1 输入数据帧协议解析···············································································190
6.4.2 实现数据链路层与网络层接口的关键数据结构····································192
6.4.3 接口的组织······························································································194
6.5 数据链路层对数据帧发送的处理·······································································196
6.5.1 启动/停止设备发送数据··········································································197
6.5.2 调度设备发送数据帧···············································································198
6.5.3 队列策略接口··························································································200
6.5.4 dev_queue_xmit 函数···············································································203
6.5.5 发送软件中断··························································································206
6.5.6 Watchdog 时钟·························································································209
6.6 本章总结 ··············································································································211
第 7 章 网络层传送····································································································212
7.1 Internet 协议的基本概念·····················································································213
7.1.1 Internet 协议的任务·················································································213
7.1.2 Internet 协议头························································································214
7.1.3 Linux 内核中描述 IP 协议头的数据结构···············································217
7.2 IP 协议实现前的准备工作··················································································217
7.2.1 协议初始化······························································································217
7.2.2 与网络过滤子系统的交互·······································································219
7.2.3 与路由子系统的交互···············································································220
7.3 输入数据包在 IP 层的处理·················································································220
7.3.1 ip_rcv 函数分析·······················································································221
7.3.2 ip_rcv_finish 函数分析············································································224
7.3.3 接收操作中 IP 选项的处理·····································································226
嵌入式 Linux 网络体系结构设计与 TCP/IP 协议栈
X Linux
7.4 IP 选项·················································································································228
7.4.1 IP 选项的格式··························································································228
7.4.2 描述 IP 选项的数据结构·········································································234
7.4.3 Linux 内核对 IP 选项的处理···································································235
7.4.4 Linux 内核对 IP 选项处理的具体实现···················································237
7.5 IPv4 数据包的前送和本地发送··········································································245
7.5.1 数据包的前送··························································································245
7.5.2 dst_output 函数的实现·············································································249
7.5.3 本地发送的处理······················································································250
7.6 在 IP 层的发送····································································································254
7.6.1 执行发送的关键函数···············································································255
7.6.2 发送数据包相关信息的数据结构···························································256
7.6.3 ip_queue_xmit 函数 ·················································································260
7.6.4 ip_append_data 函数预备 ········································································264
7.6.5 ip_append_data 函数分析 ········································································274
7.6.6 ip_append_page 函数 ··············································································279
7.6.7 ip_push_pending_frames 函数 ·································································280
7.6.8 发送数据包的整体过程···········································································282
7.7 与相邻子系统的接口··························································································284
7.8 数据包的分片与重组··························································································286
7.8.1 数据分片需要考虑的问题·······································································287
7.8.2 在上层分片的效率 ··················································································287
7.8.3 数据包分片/重组使用的 IP 协议头数据域············································287
7.9 本章总结 ·············································································································288
第 8 章 传输层 UDP 协议的实现················································································289
8.1 UDP 协议基础·····································································································289
8.2 UDP 协议实现的关键数据结构 ·········································································290
8.2.1 UDP 协议头的数据结构··········································································290
8.2.2 UDP 的控制缓冲区 ·················································································290
8.2.3 UDP 套接字的数据结构··········································································291
8.2.4 应用程序发送给 UDP 负载数据的数据结构··········································291
8.3 UDP、套接字层、IP 层之间的接口··································································292
目 录
Linux XI
8.3.1 UDP 协议实例与套接字层间的接口······················································292
8.3.2 UDP 协议与 IP 层之间的接口 ································································293
8.4 发送 UDP 数据报的实现····················································································294
8.4.1 初始化一个连接······················································································294
8.4.2 在 UDP 套接字上发送数据包·································································297
8.4.3 向 IP 层发送数据包·················································································301
8.4.4 从用户地址空间复制数据到数据报·······················································304
8.5 UDP 协议接收的实现························································································305
8.5.1 UDP 协议接收的处理函数······································································305
8.5.2 将数据包放入套接字接收队列的处理函数············································307
8.5.3 UDP 协议接收广播与组发送数据包······················································308
8.5.4 UDP 的哈希链表 ·····················································································309
8.5.5 将数据包放到套接字接收队列·······························································312
8.6 UDP 协议在套接字层的接收处理······································································313
8.6.1 函数输入参数··························································································313
8.6.2 函数处理流程··························································································313
8.7 本章总结 ·············································································································315
第 9 章 传输层 TCP 协议的实现················································································316
9.1 CP 协议简介········································································································316
9.1.1 CP 是可靠协议 ························································································316
9.1.2 TCP 是面向连接的协议 ··········································································318
9.1.3 TCP 是按字节流交换的协议···································································319
9.1.4 TCP 协议实现的功能··············································································320
9.2 描述 TCP 协议实现的关键数据结构 ·································································320
9.2.1 TCP 协议头数据结构··············································································320
9.2.2 TCP 的控制缓冲区··················································································321
9.2.3 TCP 套接字的数据结构 ··········································································322
9.2.4 TCP 协议选项 Options·············································································323
9.2.5 应用层传送给传输层信息的数据结构 ···················································325
9.3 在 TCP 协议、套接字、IP 层之间的接口·························································326
9.3.1 管理套接字与 TCP 接口的数据结构······················································326
9.3.2 初始化套接字与传输层之间的接口·······················································327
嵌入式 Linux 网络体系结构设计与 TCP/IP 协议栈
XII Linux
9.3.3 TCP 与 IP 层之间的接收接口·································································328
9.3.4 TCP 与 IP 层之间的发送接口·································································329
9.3.5 初始化 TCP 套接字················································································331
9.4 TCP 协议实例接收过程的实现··········································································332
9.4.1 tcp_v4_rcv 函数的实现············································································333
9.4.2 Fast Path 和 prequeue 队列的处理···························································338
9.4.3 处理 TCP 的 Blocklog 队列····································································340
9.4.4 套接字层的接收函数···············································································342
9.5 Linux 内核中 TCP 发送功能的实现··································································348
9.5.1 将数据从用户地址空间复制到内核 Socket Buffer·································349
9.5.2 TCP 数据段输出·····················································································354
9.5.3 发送过程的状态机 ··················································································358
9.6 TCP 套接字的连接管理······················································································358
9.6.1 TCP 连接初始化······················································································361
9.6.2 TCP 状态从 CLOSED 切换到 SYN_SENT·············································362
9.6.3 TCP 连接的状态管理··············································································365
9.6.4 TCP 连接为 ESTABLISHED 状态时的接收处理···································370
9.6.5 TCP 的 TIME_WAIT 状态处理·······························································374
9.7 本章总结 ·············································································································379
第 10 章 套接字层实现 ······························································································380
10.1 套接字概述········································································································380
10.1.1 什么是套接字························································································381
10.1.2 套接字与管理套接字的数据结构·························································383
10.1.3 套接字与文件························································································390
10.2 套接字层的初始化····························································································391
10.3 地址族的值和协议交换表 ················································································392
10.3.1 协议交换表的数据结构·········································································392
10.3.2 套接字支持多协议栈的实现·································································393
10.4 IPv4 中协议成员注册和初始化········································································396
10.5 套接字 API 系统调用的实现············································································397
10.5.1 系统调用简述························································································397
10.5.2 套接字 API 系统调用的实现 ································································398
目 录
Linux XIII
10.6 创建套接字········································································································403
10.6.1 sock_create 函数创建套接字·································································404
10.6.2 协议族套接字创建函数的管理·····························································406
10.6.3 AF_INET 套接字的创建 ·······································································407
10.7 I/O 系统调用和套接字······················································································408
10.8 本章总结············································································································409
第 11 章 应用层——网络应用套接字编程··································································411
11.1 套接字描述符····································································································413
11.1.1 family 参数·····························································································413
11.1.2 type 参数 ·······························································································413
11.1.3 protocol 参数·························································································414
11.1.4 AF_XXX 与 PF_XXX 形式的常数 ·······················································414
11.2 地址格式············································································································416
11.2.1 字节顺序································································································416
11.2.2 地址结构································································································417
11.2.3 支持地址格式转换的函数·····································································419
11.2.4 获取网络配置信息·················································································419
11.2.5 编程示例································································································423
11.2.6 将地址与套接字绑定·············································································426
11.3 套接字连接········································································································427
11.3.1 connect 函数分析···················································································427
11.3.2 服务器套接字建立侦听队列·································································428
11.3.3 建立套接字连接 ····················································································429
11.4 数据的传送········································································································430
11.4.1 send 函数································································································430
11.4.2 传送数据的函数 ····················································································431
11.4.3 接收数据的函数 ····················································································432
11.4.4 recvfrom、recvmsg 函数········································································432
11.4.5 编程示例································································································433
11.5 套接字选项········································································································441
11.5.1 设置套接字选项 ····················································································441
11.5.2 读取套接字选项 ····················································································442
嵌入式 Linux 网络体系结构设计与 TCP/IP 协议栈
XIV Linux
11.6 out-of-band 数据·······························································································443
11.7 非阻塞和异步 I/O 操作·····················································································444
11.8 本章总结············································································································444
第 12 章 嵌入式系统网络应用技术 ············································································445
12.1 嵌入式系统的设计要素····················································································445
12.2 嵌入式系统开发环境的构成 ············································································445
12.2.1 硬件构成································································································446
12.2.2 典型的硬件开发环境·············································································447
12.2.3 软件交叉平台开发环境·········································································448
12.2.4 嵌入式软件的开发步骤·········································································448
12.3 将网络设备驱动程序加入内核·········································································450
12.3.1 配置新网络设备 ····················································································450
12.3.2 编译新驱动程序 ····················································································451
12.4 内核配置············································································································452
12.4.1 目标硬件及内核、库配置·····································································452
12.4.2 内核组件配置························································································454
12.4.3 应用配置································································································459
12.5 集成应用程序并下载至目标板·········································································460
12.5.1 集成应用程序························································································460
12.5.2 将执行文件下载至目标板·····································································461
12.6 本章总结············································································································462

实例下载地址

嵌入式Linux网络体系结构设计与TCPIP协议栈

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
;
报警