网络信息确认

网络丢包

1.查看网卡驱动加载情况

查找网卡驱动模块

syli@syli-PC:~/work/tmp$ lspci -vvv
# 找到网卡驱动模块
00:1f.6 Ethernet controller: Intel Corporation Ethernet Connection (12) I219-V
        Subsystem: ASRock Incorporation Device 0d55
        Control: I/O- Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B- DisINTx+
        Status: Cap+ 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
        Latency: 0
        Interrupt: pin A routed to IRQ 132
        Region 0: Memory at a0300000 (32-bit, non-prefetchable) [size=128K]
        Capabilities: <access denied>
        Kernel driver in use: e1000e
        Kernel modules: e1000e
syli@syli-PC:~/work/tmp$ ifconfig
eno1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.20.52.92  netmask 255.255.255.0  broadcast 10.20.52.255
        inet6 fe80::9c1:81b5:6e62:6570  prefixlen 64  scopeid 0x20<link>
        ether a8:a1:59:59:16:99  txqueuelen 1000  (Ethernet)
        RX packets 3646051  bytes 4088993378 (3.8 GiB)
        RX errors 0  dropped 52016  overruns 0  frame 0
        TX packets 660207  bytes 81797881 (78.0 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 16  memory 0xa0300000-a0320000  
syli@syli-PC:~/work/tmp$ ethtool -i eno1
driver: e1000e
version: 3.8.4-NAPI
firmware-version: 0.2-4
expansion-rom-version: 
bus-info: 0000:00:1f.6
supports-statistics: yes
supports-test: yes
supports-eeprom-access: yes
supports-register-dump: yes
supports-priv-flags: no

查看加载驱动

syli@syli-PC:~/work/tmp$ lsmod
Module                  Size  Used by
e1000e                290816  0

查看驱动信息

syli@syli-PC:~/work/tmp$ modinfo e1000e
filename:       /lib/modules/4.19.0-amd64-desktop/kernel/drivers/net/ethernet/intel/e1000e/e1000e.ko
version:        3.8.4-NAPI
license:        GPL
description:    Intel(R) PRO/1000 Network Driver
author:         Intel Corporation, <linux.nics@intel.com>
srcversion:     16BFB9610ACE529694F9762
alias:          pci:v00008086d00001A1Dsv*sd*bc*sc*i*
......
alias:          pci:v00008086d0000105Esv*sd*bc*sc*i*
depends:        
retpoline:      Y
intree:         Y
name:           e1000e
vermagic:       4.19.0-amd64-desktop SMP mod_unload modversions 
parm:           debug:Debug level (0=none,...,16=all) (int)
parm:           copybreak:Maximum size of packet that is copied to a new buffer on receive (uint)
parm:           TxIntDelay:Transmit Interrupt Delay (array of int)
parm:           TxAbsIntDelay:Transmit Absolute Interrupt Delay (array of int)
parm:           RxIntDelay:Receive Interrupt Delay (array of int)
parm:           RxAbsIntDelay:Receive Absolute Interrupt Delay (array of int)
parm:           InterruptThrottleRate:Interrupt Throttling Rate (array of int)
parm:           IntMode:Interrupt Mode (array of int)
parm:           SmartPowerDownEnable:Enable PHY smart power down (array of int)
parm:           KumeranLockLoss:Enable Kumeran lock loss workaround (array of int)
parm:           CrcStripping:Enable CRC Stripping, disable if your BMC needs the CRC (array of int)
parm:           EEE:Enable/disable on parts that support the feature (array of int)
parm:           Node:[ROUTING] Node to allocate memory on, default -1 (array of int)
ls /lib/modules/4.19.0-amd64-desktop/kernel/drivers/net/

2.查看网络状态

查看网卡物理连接状态

syli@syli-PC:~/work/tmp$ ethtool eno1
Settings for eno1:
        Supported ports: [ TP ]
        Supported link modes:   10baseT/Half 10baseT/Full 
                                100baseT/Half 100baseT/Full 
                                1000baseT/Full 
        Supported pause frame use: No
        Supports auto-negotiation: Yes
        Supported FEC modes: Not reported
        Advertised link modes:  10baseT/Half 10baseT/Full 
                                100baseT/Half 100baseT/Full 
                                1000baseT/Full 
        Advertised pause frame use: No
        Advertised auto-negotiation: Yes
        Advertised FEC modes: Not reported
        Speed: 1000Mb/s
        Duplex: Full
        Port: Twisted Pair
        PHYAD: 2
        Transceiver: internal
        Auto-negotiation: on
        MDI-X: on (auto)
Cannot get wake-on-lan settings: Operation not permitted
        Current message level: 0x00000007 (7)
                               drv probe link
        Link detected: yes

查看网卡协商状态

syli@syli-PC:~/work/tmp$ sudo mii-tool -v eno1
eno1: negotiated 1000baseT-FD flow-control, link ok
  product info: vendor 00:55:00, model 10 rev 0
  basic mode:   autonegotiation enabled
  basic status: autonegotiation complete, link ok
  capabilities: 1000baseT-FD 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD
  advertising:  1000baseT-FD 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD flow-control
  link partner: 1000baseT-FD 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD

查看网络配置

syli@syli-PC:~/work/tmp$ ifconfig
eno1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.20.52.92  netmask 255.255.255.0  broadcast 10.20.52.255
        inet6 fe80::9c1:81b5:6e62:6570  prefixlen 64  scopeid 0x20<link>
        ether a8:a1:59:59:16:99  txqueuelen 1000  (Ethernet)
        RX packets 3648750  bytes 4089446310 (3.8 GiB)
        RX errors 0  dropped 52244  overruns 0  frame 0
        TX packets 660737  bytes 81865464 (78.0 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 16  memory 0xa0300000-a0320000 
syli@syli-PC:~/work/tmp$ route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         10.20.52.1      0.0.0.0         UG    100    0        0 eno1
10.20.52.0      0.0.0.0         255.255.255.0   U     100    0        0 eno1
syli@syli-PC:~/work/tmp$ arp -a
? (10.20.52.116) at a8:a1:59:59:16:16 [ether] on eno1
Rx errors:  表示总的收包的错误数量,这包括 too-long-frames 错误,Ring Buffer 溢出错误,crc 校验错误,帧同步错误,fifo overruns 以及 missed pkg 等等。Rx dropped:  表示数据包已经进入了 Ring Buffer,但是由于内存不够等系统原因,导致在拷贝到内存的过程中被丢弃。Rx overruns:  表示了 fifo 的 overruns,这是由于 Ring Buffer(aka Driver Queue) 传输的 IO 大于 kernel 能够处理的 IO 导致的,而 Ring Buffer 则是指在发起 IRQ 请求之前的那块 buffer。很明显,overruns 的增大意味着数据包没到 Ring Buffer 就被网卡物理层给丢弃了,而 CPU 无法及时的处理中断是造成 Ring Buffer 满的原因之一。Rx frame:

查看网络协议统计

syli@syli-PC:~/work/tmp$ netstat -sIp:    Forwarding: 2    944375 total packets received    1 with invalid addresses    0 forwarded    0 incoming packets discarded    724013 incoming packets delivered    577753 requests sent out    38 dropped because of missing routeIcmp:    992 ICMP messages received    61 input ICMP message failed    ICMP input histogram:        destination unreachable: 59        echo requests: 925        timestamp request: 3        address mask request: 3    1031 ICMP messages sent    0 ICMP messages failed    ICMP output histogram:        destination unreachable: 103        echo replies: 925        timestamp replies: 3IcmpMsg:        InType3: 59        InType8: 925        InType13: 3        InType17: 3        InType37: 1        InType165: 1        OutType0: 925        OutType3: 103        OutType14: 3Tcp:    14115 active connection openings    176 passive connection openings    123 failed connection attempts    1057 connection resets received    76 connections established    595314 segments received    559124 segments sent out    2324 segments retransmitted    50 bad segments received    7452 resets sentUdp:    232740 packets received    188 packets to unknown port received    0 packet receive errors    22646 packets sent    0 receive buffer errors    0 send buffer errors    IgnoredMulti: 232UdpLite:TcpExt:    20 resets received for embryonic SYN_RECV sockets    7972 TCP sockets finished time wait in fast timer    9873 delayed acks sent    5 delayed acks further delayed because of locked socket    Quick ack mode was activated 1230 times    430935 packet headers predicted    39527 acknowledgments not containing data payload received    64413 predicted acknowledgments    TCPSackRecovery: 26    Detected reordering 114 times using SACK    TCPDSACKUndo: 2    33 congestion windows recovered without slow start after partial ack    TCPLostRetransmit: 1756    1 timeouts after reno fast retransmit    TCPSackFailures: 1    1 timeouts in loss state    26 fast retransmits    2 retransmits in slow start    TCPTimeouts: 2290    TCPLossProbes: 260    TCPLossProbeRecovery: 17    TCPSackRecoveryFail: 10    TCPDSACKOldSent: 1230    TCPDSACKOfoSent: 1    TCPDSACKRecv: 41    252 connections reset due to unexpected data    1063 connections reset due to early user close    269 connections aborted due to timeout    TCPDSACKIgnoredNoUndo: 14    TCPSpuriousRTOs: 1    TCPSackShiftFallback: 226    TCPRcvCoalesce: 44931    TCPOFOQueue: 4182    TCPOFOMerge: 1    TCPChallengeACK: 53    TCPSYNChallenge: 50    TCPAutoCorking: 3102    TCPSynRetrans: 284    TCPOrigDataSent: 121756    TCPHystartTrainDetect: 9    TCPHystartTrainCwnd: 348    TCPHystartDelayDetect: 3    TCPHystartDelayCwnd: 87    TCPACKSkippedSeq: 1    TCPACKSkippedTimeWait: 3    TCPACKSkippedChallenge: 1    TCPKeepAlive: 11830    TCPDelivered: 134219    TCPAckCompressed: 2498IpExt:    InMcastPkts: 5799    OutMcastPkts: 4722    InBcastPkts: 102975    OutBcastPkts: 839    InOctets: 3690483541    OutOctets: 61543893    InMcastOctets: 823778    OutMcastOctets: 938098    InBcastOctets: 17345759    OutBcastOctets: 114374    InNoECTPkts: 3078549

3. 查看日志打印信息

syli@syli-PC:~/work/tmp$ sudo dmesg |grep eno1[    3.014941] e1000e 0000:00:1f.6 eno1: renamed from eth0[   21.340385] IPv6: ADDRCONF(NETDEV_UP): eno1: link is not ready[   21.537027] IPv6: ADDRCONF(NETDEV_UP): eno1: link is not ready[   26.461345] e1000e 0000:00:1f.6 eno1: NIC Link is Up 1000 Mbps Full Duplex, Flow Control: None[   26.461397] IPv6: ADDRCONF(NETDEV_CHANGE): eno1: link becomes ready[   58.652901] device eno1 entered promiscuous mode

4. 查看路由信息

syli@syli-PC:~/work/tmp$ traceroute www.baidu.comtraceroute to www.baidu.com (110.242.68.4), 30 hops max, 60 byte packets 1  10.20.52.1 (10.20.52.1)  1.030 ms  1.674 ms  2.353 ms 2  10.20.1.254 (10.20.1.254)  0.992 ms  0.959 ms  0.931 ms 3  113.57.152.129 (113.57.152.129)  2.512 ms  2.533 ms  2.452 ms 4  220.249.83.53 (220.249.83.53)  2.731 ms 218.106.121.213 (218.106.121.213)  2.697 ms 58.19.157.9 (58.19.157.9)  2.680 ms 5  58.19.113.250 (58.19.113.250)  3.648 ms  3.681 ms  3.654 ms 6  58.19.157.165 (58.19.157.165)  16.483 ms * * 7  * * * 8  110.242.66.178 (110.242.66.178)  27.023 ms 110.242.66.182 (110.242.66.182)  25.809 ms 110.242.66.186 (110.242.66.186)  22.786 ms 9  * * *10  * * *11  * * *12  * * *13  * * *14  * * *15  * * *16  * * *17  * * *18  * * *19  * * *20  * * *21  * * *22  * * *23  * * *24  * * *25  * * *26  * * *27  * * *28  * * *29  * * *30  * * *

5. 检查ip冲突

# 在同局域网内其他主机上ping该IP地址,查看返回是否出现多个mac地址响应sudo apt install arpingsudo arping 10.20.52.92

6. 查看网卡信息

查看网卡收发包信息

syli@syli-PC:~/work/tmp$ ethtool -S eno1NIC statistics:     rx_packets: 4016938     tx_packets: 706050     rx_bytes: 4569999243     tx_bytes: 89218346     rx_broadcast: 418677     tx_broadcast: 1666     rx_multicast: 356521     tx_multicast: 6199     rx_errors: 0     tx_errors: 0     tx_dropped: 0     multicast: 356521     collisions: 0     rx_length_errors: 0     rx_over_errors: 0     rx_crc_errors: 0     rx_frame_errors: 0     rx_no_buffer_count: 0     rx_missed_errors: 0     tx_aborted_errors: 0     tx_carrier_errors: 0     tx_fifo_errors: 0     tx_heartbeat_errors: 0     tx_window_errors: 0     tx_abort_late_coll: 0     tx_deferred_ok: 0     tx_single_coll_ok: 0     tx_multi_coll_ok: 0     tx_timeout_count: 0     tx_restart_queue: 0     rx_long_length_errors: 0     rx_short_length_errors: 0     rx_align_errors: 0     tx_tcp_seg_good: 0     tx_tcp_seg_failed: 0     rx_flow_control_xon: 0     rx_flow_control_xoff: 0     tx_flow_control_xon: 0     tx_flow_control_xoff: 0     rx_csum_offload_good: 3581296     rx_csum_offload_errors: 0     rx_header_split: 0     alloc_rx_buff_failed: 0     tx_smbus: 0     rx_smbus: 0     dropped_smbus: 0     rx_dma_failed: 0     tx_dma_failed: 0     rx_hwtstamp_cleared: 0     uncorr_ecc_errors: 0     corr_ecc_errors: 0     tx_hwtstamp_timeouts: 0     tx_hwtstamp_skipped: 0

查看网卡的buffer size

syli@syli-PC:~/work/tmp$ ethtool -g eno1Ring parameters for eno1:Pre-set maximums:RX:             4096RX Mini:        0RX Jumbo:       0TX:             4096Current hardware settings:RX:             256RX Mini:        0RX Jumbo:       0TX:             256

打印网络设备的寄存器

syli@syli-PC:~/work/tmp$ sudo ethtool -d eno1请输入密码:验证成功MAC Registers-------------0x00000: CTRL (Device control register)  0x40180240      Endian mode (buffers):             little      Link reset:                        normal      Set link up:                       1      Invert Loss-Of-Signal:             no      Receive flow control:              disabled      Transmit flow control:             disabled      VLAN mode:                         enabled      Auto speed detect:                 disabled      Speed select:                      1000Mb/s      Force speed:                       no      Force duplex:                      no0x00008: STATUS (Device status register) 0x40080083      Duplex:                            full      Link up:                           link config      TBI mode:                          disabled      Link speed:                        1000Mb/s      Bus type:                          PCI      Bus speed:                         33MHz      Bus width:                         32-bit0x00100: RCTL (Receive control register) 0x0400801A      Receiver:                          enabled      Store bad packets:                 disabled      Unicast promiscuous:               enabled      Multicast promiscuous:             enabled      Long packet:                       disabled      Descriptor minimum threshold size: 1/2      Broadcast accept mode:             accept      VLAN filter:                       disabled      Canonical form indicator:          disabled      Discard pause frames:              filtered      Pass MAC control frames:           don't pass      Receive buffer size:               20480x02808: RDLEN (Receive desc length)     0x000010000x02810: RDH   (Receive desc head)       0x000000AA0x02818: RDT   (Receive desc tail)       0x000000A00x02820: RDTR  (Receive delay timer)     0x000000000x00400: TCTL (Transmit ctrl register)   0x3103F0FA      Transmitter:                       enabled      Pad short packets:                 enabled      Software XOFF Transmission:        disabled      Re-transmit on late collision:     enabled0x03808: TDLEN (Transmit desc length)    0x000010000x03810: TDH   (Transmit desc head)      0x000000900x03818: TDT   (Transmit desc tail)      0x000000900x03820: TIDV  (Transmit delay timer)    0x00000008PHY type:                                unknown

查询指定网络设备的协议卸载和其他特性的状态

syli@syli-PC:~/work/tmp$ ethtool -k eno1Features for eno1:rx-checksumming: ontx-checksumming: on        tx-checksum-ipv4: off [fixed]        tx-checksum-ip-generic: on        tx-checksum-ipv6: off [fixed]        tx-checksum-fcoe-crc: off [fixed]        tx-checksum-sctp: off [fixed]scatter-gather: on        tx-scatter-gather: on        tx-scatter-gather-fraglist: off [fixed]tcp-segmentation-offload: off        tx-tcp-segmentation: off [requested on]        tx-tcp-ecn-segmentation: off [fixed]        tx-tcp-mangleid-segmentation: off        tx-tcp6-segmentation: off [requested on]udp-fragmentation-offload: offgeneric-segmentation-offload: ongeneric-receive-offload: onlarge-receive-offload: off [fixed]rx-vlan-offload: ontx-vlan-offload: onntuple-filters: off [fixed]receive-hashing: onhighdma: on [fixed]rx-vlan-filter: off [fixed]vlan-challenged: off [fixed]tx-lockless: off [fixed]netns-local: off [fixed]tx-gso-robust: off [fixed]tx-fcoe-segmentation: off [fixed]tx-gre-segmentation: off [fixed]tx-gre-csum-segmentation: off [fixed]tx-ipxip4-segmentation: off [fixed]tx-ipxip6-segmentation: off [fixed]tx-udp_tnl-segmentation: off [fixed]tx-udp_tnl-csum-segmentation: off [fixed]tx-gso-partial: off [fixed]tx-sctp-segmentation: off [fixed]tx-esp-segmentation: off [fixed]tx-udp-segmentation: off [fixed]fcoe-mtu: off [fixed]tx-nocache-copy: offloopback: off [fixed]rx-fcs: offrx-all: offtx-vlan-stag-hw-insert: off [fixed]rx-vlan-stag-hw-parse: off [fixed]rx-vlan-stag-filter: off [fixed]l2-fwd-offload: off [fixed]hw-tc-offload: off [fixed]esp-hw-offload: off [fixed]esp-tx-csum-hw-offload: off [fixed]rx-udp_tunnel-port-offload: off [fixed]tls-hw-tx-offload: off [fixed]tls-hw-rx-offload: off [fixed]rx-gro-hw: off [fixed]tls-hw-record: off [fixed]

重启自协商

sudo ethtool -r eno1或sudo mii-tool -r eno1

查看MII状态信息

syli@syli-PC:~$ sudo mii-tool -v eno1eno1: negotiated 1000baseT-FD flow-control, link ok  product info: vendor 00:55:00, model 10 rev 0  basic mode:   autonegotiation enabled  basic status: autonegotiation complete, link ok  capabilities: 1000baseT-FD 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD  advertising:  1000baseT-FD 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD flow-control  link partner: 1000baseT-FD 100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD

观察link状态

syli@syli-PC:~$ sudo mii-tool -w eno113:29:03 eno1: negotiated 1000baseT-FD flow-control, link ok

查看dns服务器

syli@syli-PC:~/work/31-cve/source/haproxy$ cat /etc/resolv.conf # Generated by NetworkManagernameserver 10.20.0.10syli@syli-PC:~/work/31-cve/source/haproxy$ nslookup www.baidu.comServer:         10.20.0.10Address:        10.20.0.10#53Non-authoritative answer:www.baidu.com   canonical name = www.a.shifen.com.Name:   www.a.shifen.comAddress: 110.242.68.3Name:   www.a.shifen.comAddress: 110.242.68.4

7. 排查思路

7.1 确认硬件情况

查看工作模式和link状态
syli@syli-PC:~/work/tmp$ sudo ethtool eno1 |egrep "Speed|Duplex|Link"        Speed: 1000Mb/s        Duplex: Full        Link detected: yes
查看收发包统计
syli@syli-PC:~/work/tmp$ ethtool -S eno1 |egrep "errors|crc|drop"     rx_errors: 0     tx_errors: 0     tx_dropped: 0     rx_length_errors: 0     rx_over_errors: 0     rx_crc_errors: 0     rx_frame_errors: 0     rx_missed_errors: 0     tx_aborted_errors: 0     tx_carrier_errors: 0     tx_fifo_errors: 0     tx_heartbeat_errors: 0     tx_window_errors: 0     rx_long_length_errors: 0     rx_short_length_errors: 0     rx_align_errors: 0     rx_csum_offload_errors: 0     dropped_smbus: 0     uncorr_ecc_errors: 0     corr_ecc_errors: 0
查看buffer大小
syli@syli-PC:~/work/tmp$ ethtool -g eno1Ring parameters for eno1:Pre-set maximums:RX:             4096RX Mini:        0RX Jumbo:       0TX:             4096Current hardware settings:RX:             256RX Mini:        0RX Jumbo:       0TX:             256

8. 网卡工作原理

8.1 收包

​ 网线上的packet首先被网卡获取,网卡会检查packet的CRC校验,保证完整性,然后将packet头去掉,得到frame。网卡会检查MAC包内的目的MAC地址,如果和本网卡的MAC地址不一样则丢弃(混杂模式除外)。

​ 网卡将frame拷贝到网卡内部的FIFO缓冲区,触发硬件中断。

(如有ring buffer的网卡,好像frame可以先存在ring buffer里再触发软件中断,ring buffer是网卡和驱动程序共享,是设备里的内存,但是对操作系统是可见的,因为看到linux内核源码里网卡驱动程序是使用kcalloc来分配的空间,所以ring buffer一般都有上限,另外这个ring buffer size,表示的应该是能存储的frame的个数,而不是字节大小。另外有些系统的 ethtool 命令 并不能改变ring parameters来设置ring buffer的大小,暂时不知道为什么,可能是驱动不支持。)

​ 网卡驱动程序通过硬中断处理函数,构建sk_buff,把frame从网卡FIFO拷贝到内存skb中,接下来交给内核处理。(支持napi的网卡应该是直接放在ring buffer,不触发硬中断,直接使用软中断,拷贝ring buffer里的数据,直接输送给上层处理,每个网卡在一次软中断处理过程能处理weight个frame)
​ 过程中,网卡芯片对frame进行了MAC过滤,以减小系统负荷。(除了混杂模式)

8.2 发包

​ 网卡驱动程序将IP包添加14字节的MAC头,构成frame(暂无CRC)。Frame(暂无CRC)中含有发送端和接收端的MAC地址,由于是驱动程序创建MAC头,所以可以随便输入地址,也可以进行主机伪装。

​ 驱动程序将frame(暂无CRC)拷贝到网卡芯片内部的缓冲区,由网卡处理。

​ 网卡芯片将未完全完成的frame(缺CRC)再次封装为可以发送的packet,也就是添加头部同步信息和CRC校验,然后丢到网线上,就完成一个IP报的发送了,所有接到网线上的网卡都可以看到该packet。

8.3 网卡终端处理函数

​ 产生中断的每个设备都有一个相应的中断处理程序,是设备驱动程序的一部分。每个网卡都有一个中断处理程序,用于通知网卡该中断已经被接收了,以及把网卡缓冲区的数据包拷贝到内存中。

​ 当网卡接收来自网络的数据包时,需要通知内核数据包到了。网卡立即发出中断。内核通过执行网卡已注册的中断处理函数来做出应答。中断处理程序开始执行,通知硬件,拷贝最新的网络数据包到内存,然后读取网卡更多的数据包。

​ 这些都是重要、紧迫而又与硬件相关的工作。内核通常需要快速的拷贝网络数据包到系统内存,因为网卡上接收网络数据包的缓存大小固定,而且相比系统内存也要小得多。所以上述拷贝动作一旦被延迟,必然造成网卡FIFO缓存溢出 - 进入的数据包占满了网卡的缓存,后续的包只能被丢弃,这也应该就是ifconfig里的overrun的来源。

​ 当网络数据包被拷贝到系统内存后,中断的任务算是完成了,这时它把控制权交还给被系统中断前运行的程序。

8.4 缓冲区访问

​ 网卡的内核缓冲区,是在PC内存中,由内核控制,而网卡会有FIFO缓冲区,或者ring buffer,这应该将两者区分开。FIFO比较小,里面有数据便会尽量将数据存在内核缓冲中。

​ 网卡中的缓冲区既不属于内核空间,也不属于用户空间。它属于硬件缓冲,允许网卡与操作系统之间有个缓冲;

​ 内核缓冲区在内核空间,在内存中,用于内核程序,做为读自或写往硬件的数据缓冲区;

​ 用户缓冲区在用户空间,在内存中,用于用户程序,做为读自或写往硬件的数据缓冲区;

​ 另外,为了加快数据的交互,可以将内核缓冲区映射到用户空间,这样,内核程序和用户程序就可以同时访问这一区间了。

​ 对于有ring buffer的网卡,ring buffer是由驱动与网卡共享的,所以内核可以直接访问ring buffer,一般拷贝frames的副本到自己的内核空间进行处理(deliver到上层协议,之后的一个个skb就是按skb的指针传递方式传递,直到用户获得数据,所以,对于ring buffer网卡,大量拷贝发生在frame从ring buffer传递到内核控制的计算机内存里)。

9. 参考链接

https://blog.csdn.net/u011857683/article/details/83758869

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值