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 ...
随机推荐
- hdu1829(A Bug's Life)
题目链接:传送门 题目大意:有n个昆虫,有m组关系,接下来m行表示两个昆虫性别不同,问是否有矛盾情况(同男同女) 题目思路:并查集的高级应用,开两倍数组大小,后n个数组表示和当前昆虫不同性别的集合 # ...
- poj1837
Balance Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 12995 Accepted: 8142 Descript ...
- 【BZOJ2064】分裂 状压DP
[BZOJ2064]分裂 Description 背景:和久必分,分久必和...题目描述:中国历史上上分分和和次数非常多..通读中国历史的WJMZBMR表示毫无压力.同时经常搞OI的他把这个变成了一个 ...
- EasyNVR现场部署搭配EasyNVS云端集中控制应用于幼儿园直播场景的最佳方案!
在之前的介绍中,我们已经介绍了很多EasyNVR成功应用于幼儿园类教育直播的场景,例如<EasyDarwin幼教云视频平台在幼教平台领域大放异彩!>.<基于EasyDarwin云视频 ...
- 数据库几种连接方式的(左右union all)
A表 id name 1 bai 2 zhang 3 li B表 a_id score 1 80 2 70 1 30 左连接: select A.* ,B.* from A a left outer ...
- JS HTML DOM 事件对象(onclick、onmouseenter)
HTML DOM 事件允许Javascript在HTML文档元素中注册不同事件处理程序. 事件通常与函数结合使用,函数不会在事件发生前被执行! (如用户点击按钮). HTML DOM 事件 DOM: ...
- 实用 35 个 jQuery 小技巧
1. 禁止右键点击 $(document).ready(function(){ $(document).bind("contextmenu",function(e){ return ...
- LinuxCentos系统安装Mariadb过程记录
MariaDB数据库简介 MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可. 开发这个分支的原因之一是:甲骨文公司收购了MySQL后,有将MySQL闭源的潜 ...
- ExtJS4 给同一个formpanel不同的url
formpanel能够这样使用,api上的样例: var panel=Ext.create('Ext.form.Panel', { title: 'Simple Form', bodyPadding: ...
- 005-快捷键,host,查看版本
一.系统快捷键 设置 键盘--查看 shift+ctrl +print 区域截图至剪切版 ctrl+alt+箭头 切换工作区 自定义打开终端快捷键 设置->键盘->自定义:名称: ...