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了,为甚还会显示呢?

 

posted on 2015-01-04 11:48 mylinuxer 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/mylinuxer/p/4200727.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值