mylinuxer

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

一、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  阅读(3902)  评论(0编辑  收藏  举报