一、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源代码分析的更多相关文章

  1. hostapd源代码分析(一):网络接口和BSS的初始化

    [转]hostapd源代码分析(一):网络接口和BSS的初始化 原文链接:http://blog.csdn.net/qq_21949217/article/details/46004349 最近在做一 ...

  2. android-plugmgr源代码分析

    android-plugmgr是一个Android插件加载框架,它最大的特点就是对插件不需要进行任何约束.关于这个类库的介绍见作者博客,市面上也有一些插件加载框架,但是感觉没有这个好.在这篇文章中,我 ...

  3. Twitter Storm源代码分析之ZooKeeper中的目录结构

    徐明明博客:Twitter Storm源代码分析之ZooKeeper中的目录结构 我们知道Twitter Storm的所有的状态信息都是保存在Zookeeper里面,nimbus通过在zookeepe ...

  4. 转:SDL2源代码分析

    1:初始化(SDL_Init()) SDL简介 有关SDL的简介在<最简单的视音频播放示例7:SDL2播放RGB/YUV>以及<最简单的视音频播放示例9:SDL2播放PCM>中 ...

  5. 转:RTMPDump源代码分析

    0: 主要函数调用分析 rtmpdump 是一个用来处理 RTMP 流媒体的开源工具包,支持 rtmp://, rtmpt://, rtmpe://, rtmpte://, and rtmps://. ...

  6. 转:ffdshow 源代码分析

    ffdshow神奇的功能:视频播放时显示运动矢量和QP FFDShow可以称得上是全能的解码.编码器.最初FFDShow只是mpeg视频解码器,不过现在他能做到的远不止于此.它能够解码的视频格式已经远 ...

  7. UiAutomator源代码分析之UiAutomatorBridge框架

    上一篇文章<UIAutomator源代码分析之启动和执行>我们描写叙述了uitautomator从命令行执行到载入測试用例执行測试的整个流程.过程中我们也描写叙述了UiAutomatorB ...

  8. MyBatis架构设计及源代码分析系列(一):MyBatis架构

    如果不太熟悉MyBatis使用的请先参见MyBatis官方文档,这对理解其架构设计和源码分析有很大好处. 一.概述 MyBatis并不是一个完整的ORM框架,其官方首页是这么介绍自己 The MyBa ...

  9. hostapd源代码分析(三):管理帧的收发和处理

    hostapd源代码分析(三):管理帧的收发和处理 原文链接:http://blog.csdn.net/qq_21949217/article/details/46004379 这篇文章我来讲解一下h ...

随机推荐

  1. joisino's travel

    D - joisino's travel Time limit : 2sec / Memory limit : 256MB Score : 400 points Problem Statement T ...

  2. (转)免费天气预报接口API以及全国所有地区代码!!

    国家气象局提供的天气预报接口 接口地址: http://www.weather.com.cn/data/sk/101010100.html http://www.weather.com.cn/data ...

  3. mesos cluster

    http://spark.apache.org/docs/latest/running-on-mesos.html http://stackoverflow.com/questions/1993985 ...

  4. 接口测试工具 — postman(get请求)

    一.Postman说明 Postman是一种网页调试与发送网页http请求的chrome插件.我们可以用来很方便的模拟get或者post或者其他方式的请求来调试接口. 二.postman安装(略) 三 ...

  5. SQLServer中行列转换Pivot UnPivot

    PIVOT用于将列值旋转为列名(即行转列),在SQL Server 2000可以用聚合函数配合CASE语句实现 PIVOT的一般语法是:PIVOT(聚合函数(列) FOR 列 in (…) )AS P ...

  6. Python3.6全栈开发实例[006]

    6.检查传入字典的每一个value的长度,如果大于2,那么仅保留前两个长度的内容,并将新内容返回给调用者. dic = {"k1": "v1v1", " ...

  7. phonegap file api

    https://github.com/chrisben/imgcache.js/tree/master/examples 1.FILE API file api最大的两个功能是download和upl ...

  8. Git处理 行结束符

    Dealing with line endings (Windows) 如果你正在使用Git在GitHub上和别人协作的话,确保Git处理行结束符的配置已经正确配置了. 每次在键盘上按下return键 ...

  9. Python之模块和包(Day21)

    一.Python模块 Python模块(module),是一个Python文件,以.py结尾,包含了Python对象定义和Python语句. 模块让你能够有逻辑的组织你的Python代码段 把相关的代 ...

  10. OJ 1101 谁是中间的那个

    前言:主要考察排序用法 sort(cow+1,cow+1+n,cmp);//数组按cmp方法排序 Description 一天,农夫乔伊像往常一样来到了他的牧场,他突然对他的奶牛产奶量产生了兴趣.他想 ...