ifconfig源代码分析
一、ifconfig显示
[root@10g-host4 new]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:26:B9:4A:FC:EA
inet addr:192.168.100.4 Bcast:192.168.100.255 Mask:255.255.255.0
inet6 addr: fe80::226:b9ff:fe4a:fcea/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:272 errors:0 dropped:0 overruns:0 frame:0
TX packets:66 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:19904 (19.4 KiB) TX bytes:10312 (10.0 KiB)
eth2 Link encap:Ethernet HWaddr 00:16:31:F0:9E:94
inet addr:192.168.99.4 Bcast:192.168.99.255 Mask:255.255.255.0
inet6 addr: fe80::216:31ff:fef0:9e94/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:941824733 errors:0 dropped:584879511 overruns:0 frame:0
TX packets:941801077 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:56509485448 (52.6 GiB) TX bytes:50857262610 (47.3 GiB)
eth2:0 Link encap:Ethernet HWaddr 00:16:31:F0:9E:94
inet addr:192.168.99.20 Bcast:192.168.99.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:49 errors:0 dropped:0 overruns:0 frame:0
TX packets:49 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:3596 (3.5 KiB) TX bytes:3596 (3.5 KiB)
二、/proc/net/dev
[root@10g-host4 new]# cat /proc/net/dev
Inter-| Receive | Transmit
face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
lo: 3596 49 0 0 0 0 0 0 3596 49 0 0 0 0 0 0
eth0: 39710 560 0 0 0 0 0 118 14850 93 0 0 0 0 0 0
eth1: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
sit0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
eth2:123635538320 2060592241 0 1236548294 0 0 0 0 111270716166 2060568737 0 0 0 0 0 0
eth3: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
二、ifconfig源代码主要路径
ifconfig源码位于net-tool-1.6源码包,主要执行路径如下:
main( )
-> if_print( ) //参数为eth2
->lookup_interface( )
->do_if_fetch( )
->ife_print( )
->ife_print_long( )
这样打印ifconfig看到的收发统计信息:
printf(_("RX packets:%llu errors:%lu dropped:%lu overruns:%lu frame:%lu\n"),
ptr->stats.rx_packets, ptr->stats.rx_errors,
ptr->stats.rx_dropped, ptr->stats.rx_fifo_errors,
ptr->stats.rx_frame_errors);
printf(_("TX packets:%llu errors:%lu dropped:%lu overruns:%lu carrier:%lu\n"),
ptr->stats.tx_packets, ptr->stats.tx_errors,
ptr->stats.tx_dropped, ptr->stats.tx_fifo_errors,
ptr->stats.tx_carrier_errors);
而stats结构体定义如下:
128struct net_device_stats
129{
130 unsigned long rx_packets; /* total packets received */
131 unsigned long tx_packets; /* total packets transmitted */
132 unsigned long rx_bytes; /* total bytes received */
133 unsigned long tx_bytes; /* total bytes transmitted */
134 unsigned long rx_errors; /* bad packets received */
135 unsigned long tx_errors; /* packet transmit problems */
136 unsigned long rx_dropped; /* no space in linux buffers */
137 unsigned long tx_dropped; /* no space available in linux */
138 unsigned long multicast; /* multicast packets received */
139 unsigned long collisions;
140
141 /* detailed rx_errors: */
142 unsigned long rx_length_errors;
143 unsigned long rx_over_errors; /* receiver ring buff overflow */
144 unsigned long rx_crc_errors; /* recved pkt with crc error */
145 unsigned long rx_frame_errors; /* recv'd frame alignment error */
146 unsigned long rx_fifo_errors; /* recv'r fifo overrun */
147 unsigned long rx_missed_errors; /* receiver missed packet */
148
149 /* detailed tx_errors */
150 unsigned long tx_aborted_errors;
151 unsigned long tx_carrier_errors;
152 unsigned long tx_fifo_errors;
153 unsigned long tx_heartbeat_errors;
154 unsigned long tx_window_errors;
155
156 /* for cslip etc */
157 unsigned long rx_compressed;
158 unsigned long tx_compressed;
159};
而这些打印信息是从哪里来的呢?
在ixgbe万兆网卡驱动中,ixgbe_update_stats( )函数中
net_stats->rx_bytes = bytes;
net_stats->rx_packets = packets;
net_stats->tx_bytes = bytes;
net_stats->tx_packets = packets;
/* Rx Errors */
net_stats->rx_errors = hwstats->crcerrs + hwstats->rlec;
net_stats->rx_dropped = 0;
net_stats->rx_length_errors = hwstats->rlec;
net_stats->rx_crc_errors = hwstats->crcerrs;
net_stats->rx_missed_errors = total_mpc;
抠一下细节:
ifconfig明显中的dropped字段值应该来自于net_device_stats->rx_dropped,
可是ixgbe驱动里面设置为0了,为甚还会显示呢?
ifconfig源代码分析的更多相关文章
- hostapd源代码分析(一):网络接口和BSS的初始化
[转]hostapd源代码分析(一):网络接口和BSS的初始化 原文链接:http://blog.csdn.net/qq_21949217/article/details/46004349 最近在做一 ...
- android-plugmgr源代码分析
android-plugmgr是一个Android插件加载框架,它最大的特点就是对插件不需要进行任何约束.关于这个类库的介绍见作者博客,市面上也有一些插件加载框架,但是感觉没有这个好.在这篇文章中,我 ...
- Twitter Storm源代码分析之ZooKeeper中的目录结构
徐明明博客:Twitter Storm源代码分析之ZooKeeper中的目录结构 我们知道Twitter Storm的所有的状态信息都是保存在Zookeeper里面,nimbus通过在zookeepe ...
- 转:SDL2源代码分析
1:初始化(SDL_Init()) SDL简介 有关SDL的简介在<最简单的视音频播放示例7:SDL2播放RGB/YUV>以及<最简单的视音频播放示例9:SDL2播放PCM>中 ...
- 转:RTMPDump源代码分析
0: 主要函数调用分析 rtmpdump 是一个用来处理 RTMP 流媒体的开源工具包,支持 rtmp://, rtmpt://, rtmpe://, rtmpte://, and rtmps://. ...
- 转:ffdshow 源代码分析
ffdshow神奇的功能:视频播放时显示运动矢量和QP FFDShow可以称得上是全能的解码.编码器.最初FFDShow只是mpeg视频解码器,不过现在他能做到的远不止于此.它能够解码的视频格式已经远 ...
- UiAutomator源代码分析之UiAutomatorBridge框架
上一篇文章<UIAutomator源代码分析之启动和执行>我们描写叙述了uitautomator从命令行执行到载入測试用例执行測试的整个流程.过程中我们也描写叙述了UiAutomatorB ...
- MyBatis架构设计及源代码分析系列(一):MyBatis架构
如果不太熟悉MyBatis使用的请先参见MyBatis官方文档,这对理解其架构设计和源码分析有很大好处. 一.概述 MyBatis并不是一个完整的ORM框架,其官方首页是这么介绍自己 The MyBa ...
- hostapd源代码分析(三):管理帧的收发和处理
hostapd源代码分析(三):管理帧的收发和处理 原文链接:http://blog.csdn.net/qq_21949217/article/details/46004379 这篇文章我来讲解一下h ...
随机推荐
- Java数据类型的转换:隐式(自动)转换与强制转换
原文链接:http://java.chinaitlab.com/base/725590.html 一些初学JAVA的朋友可能会遇到JAVA的数据类型之间转换的苦恼,例如,整数和float,double ...
- <转> python的垃圾回收机制
Python的GC模块主要运用了“引用计数”(reference counting)来跟踪和回收垃圾.在引用计数的基础上,还可以通过“标记-清除”(mark and sweep)解决容器对象可能产生的 ...
- 巨蟒python全栈开发django6: FBV&CBV&&单表查询的其他方法
练习CBV用法 截图中的action="/cbv/",应该是这样 上边红图,说明mysql有问题,需要重启一下 返回,输入的内容 @wrapper==>cbv=wrapper ...
- PHP7-MySQLi在分页中的应用
获取页码,设置每页行数 $page = $_POST["page"]; if($page == ""||$page <= 0){ $page = 1; } ...
- Servlet 3.0 介绍
1. 概述 注解代替 web.xml 配置文件 异步处理 对上传的支持 2. 注解代替 web.xml 配置文件 使用方法 在 Servlet 类上添加 @WebServlet(urlPatterns ...
- MySQL中的SQL流程分析简述
分析MySQL中这条语句的整个流程 update table_a set c1=xx where c2=xxx 朋友考我的一个问题在此处列出个人见解 1 客户端连接进来首先进行权限验证 2 验证通过后 ...
- 高斯过程(GP)
随机过程基本概念: 随机过程是一个比随机变量更广泛的概念.在概率论中,通常研究一个或多个这样有限个数的随机变量,即使在大数定律和中心极限定理中考虑了无穷多个随机变量,但也要假设随机变量之间互相独立.而 ...
- easyui-combobox 中多选的默认值设置、获取多选值及JS包含字符串、删除字符串
1.项目中使用到combobox的多选值及相关操作,不多说,直接上代码: <input id="education" name="education" c ...
- 十位用户唯一ID生成策略
新浪微博和twitter 等系统都有一窜数字ID来标示一个唯一的用户,这篇文章就是记录如何实现这种唯一数字ID 原理:使用MYSQL 自增ID 拼接任意字符..然后使用进制转换打乱规则 一般来说实现唯 ...
- Loadrunder之脚本篇——检查点
VuGen判断脚本是否执行成功是根据服务器返回的状态来确定的,如果服务器返回的是HTTP状态为200 OK,那么VuGen就认为脚本正确地运行了,并且是运行通过的.而大多数系统出错时是不会返回错误页面 ...