snmp_counter.rst 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789
  1. ============
  2. SNMP counter
  3. ============
  4. This document explains the meaning of SNMP counters.
  5. General IPv4 counters
  6. =====================
  7. All layer 4 packets and ICMP packets will change these counters, but
  8. these counters won't be changed by layer 2 packets (such as STP) or
  9. ARP packets.
  10. * IpInReceives
  11. Defined in `RFC1213 ipInReceives`_
  12. .. _RFC1213 ipInReceives: https://tools.ietf.org/html/rfc1213#page-26
  13. The number of packets received by the IP layer. It gets increasing at the
  14. beginning of ip_rcv function, always be updated together with
  15. IpExtInOctets. It will be increased even if the packet is dropped
  16. later (e.g. due to the IP header is invalid or the checksum is wrong
  17. and so on). It indicates the number of aggregated segments after
  18. GRO/LRO.
  19. * IpInDelivers
  20. Defined in `RFC1213 ipInDelivers`_
  21. .. _RFC1213 ipInDelivers: https://tools.ietf.org/html/rfc1213#page-28
  22. The number of packets delivers to the upper layer protocols. E.g. TCP, UDP,
  23. ICMP and so on. If no one listens on a raw socket, only kernel
  24. supported protocols will be delivered, if someone listens on the raw
  25. socket, all valid IP packets will be delivered.
  26. * IpOutRequests
  27. Defined in `RFC1213 ipOutRequests`_
  28. .. _RFC1213 ipOutRequests: https://tools.ietf.org/html/rfc1213#page-28
  29. The number of packets sent via IP layer, for both single cast and
  30. multicast packets, and would always be updated together with
  31. IpExtOutOctets.
  32. * IpExtInOctets and IpExtOutOctets
  33. They are Linux kernel extensions, no RFC definitions. Please note,
  34. RFC1213 indeed defines ifInOctets and ifOutOctets, but they
  35. are different things. The ifInOctets and ifOutOctets include the MAC
  36. layer header size but IpExtInOctets and IpExtOutOctets don't, they
  37. only include the IP layer header and the IP layer data.
  38. * IpExtInNoECTPkts, IpExtInECT1Pkts, IpExtInECT0Pkts, IpExtInCEPkts
  39. They indicate the number of four kinds of ECN IP packets, please refer
  40. `Explicit Congestion Notification`_ for more details.
  41. .. _Explicit Congestion Notification: https://tools.ietf.org/html/rfc3168#page-6
  42. These 4 counters calculate how many packets received per ECN
  43. status. They count the real frame number regardless the LRO/GRO. So
  44. for the same packet, you might find that IpInReceives count 1, but
  45. IpExtInNoECTPkts counts 2 or more.
  46. * IpInHdrErrors
  47. Defined in `RFC1213 ipInHdrErrors`_. It indicates the packet is
  48. dropped due to the IP header error. It might happen in both IP input
  49. and IP forward paths.
  50. .. _RFC1213 ipInHdrErrors: https://tools.ietf.org/html/rfc1213#page-27
  51. * IpInAddrErrors
  52. Defined in `RFC1213 ipInAddrErrors`_. It will be increased in two
  53. scenarios: (1) The IP address is invalid. (2) The destination IP
  54. address is not a local address and IP forwarding is not enabled
  55. .. _RFC1213 ipInAddrErrors: https://tools.ietf.org/html/rfc1213#page-27
  56. * IpExtInNoRoutes
  57. This counter means the packet is dropped when the IP stack receives a
  58. packet and can't find a route for it from the route table. It might
  59. happen when IP forwarding is enabled and the destination IP address is
  60. not a local address and there is no route for the destination IP
  61. address.
  62. * IpInUnknownProtos
  63. Defined in `RFC1213 ipInUnknownProtos`_. It will be increased if the
  64. layer 4 protocol is unsupported by kernel. If an application is using
  65. raw socket, kernel will always deliver the packet to the raw socket
  66. and this counter won't be increased.
  67. .. _RFC1213 ipInUnknownProtos: https://tools.ietf.org/html/rfc1213#page-27
  68. * IpExtInTruncatedPkts
  69. For IPv4 packet, it means the actual data size is smaller than the
  70. "Total Length" field in the IPv4 header.
  71. * IpInDiscards
  72. Defined in `RFC1213 ipInDiscards`_. It indicates the packet is dropped
  73. in the IP receiving path and due to kernel internal reasons (e.g. no
  74. enough memory).
  75. .. _RFC1213 ipInDiscards: https://tools.ietf.org/html/rfc1213#page-28
  76. * IpOutDiscards
  77. Defined in `RFC1213 ipOutDiscards`_. It indicates the packet is
  78. dropped in the IP sending path and due to kernel internal reasons.
  79. .. _RFC1213 ipOutDiscards: https://tools.ietf.org/html/rfc1213#page-28
  80. * IpOutNoRoutes
  81. Defined in `RFC1213 ipOutNoRoutes`_. It indicates the packet is
  82. dropped in the IP sending path and no route is found for it.
  83. .. _RFC1213 ipOutNoRoutes: https://tools.ietf.org/html/rfc1213#page-29
  84. ICMP counters
  85. =============
  86. * IcmpInMsgs and IcmpOutMsgs
  87. Defined by `RFC1213 icmpInMsgs`_ and `RFC1213 icmpOutMsgs`_
  88. .. _RFC1213 icmpInMsgs: https://tools.ietf.org/html/rfc1213#page-41
  89. .. _RFC1213 icmpOutMsgs: https://tools.ietf.org/html/rfc1213#page-43
  90. As mentioned in the RFC1213, these two counters include errors, they
  91. would be increased even if the ICMP packet has an invalid type. The
  92. ICMP output path will check the header of a raw socket, so the
  93. IcmpOutMsgs would still be updated if the IP header is constructed by
  94. a userspace program.
  95. * ICMP named types
  96. | These counters include most of common ICMP types, they are:
  97. | IcmpInDestUnreachs: `RFC1213 icmpInDestUnreachs`_
  98. | IcmpInTimeExcds: `RFC1213 icmpInTimeExcds`_
  99. | IcmpInParmProbs: `RFC1213 icmpInParmProbs`_
  100. | IcmpInSrcQuenchs: `RFC1213 icmpInSrcQuenchs`_
  101. | IcmpInRedirects: `RFC1213 icmpInRedirects`_
  102. | IcmpInEchos: `RFC1213 icmpInEchos`_
  103. | IcmpInEchoReps: `RFC1213 icmpInEchoReps`_
  104. | IcmpInTimestamps: `RFC1213 icmpInTimestamps`_
  105. | IcmpInTimestampReps: `RFC1213 icmpInTimestampReps`_
  106. | IcmpInAddrMasks: `RFC1213 icmpInAddrMasks`_
  107. | IcmpInAddrMaskReps: `RFC1213 icmpInAddrMaskReps`_
  108. | IcmpOutDestUnreachs: `RFC1213 icmpOutDestUnreachs`_
  109. | IcmpOutTimeExcds: `RFC1213 icmpOutTimeExcds`_
  110. | IcmpOutParmProbs: `RFC1213 icmpOutParmProbs`_
  111. | IcmpOutSrcQuenchs: `RFC1213 icmpOutSrcQuenchs`_
  112. | IcmpOutRedirects: `RFC1213 icmpOutRedirects`_
  113. | IcmpOutEchos: `RFC1213 icmpOutEchos`_
  114. | IcmpOutEchoReps: `RFC1213 icmpOutEchoReps`_
  115. | IcmpOutTimestamps: `RFC1213 icmpOutTimestamps`_
  116. | IcmpOutTimestampReps: `RFC1213 icmpOutTimestampReps`_
  117. | IcmpOutAddrMasks: `RFC1213 icmpOutAddrMasks`_
  118. | IcmpOutAddrMaskReps: `RFC1213 icmpOutAddrMaskReps`_
  119. .. _RFC1213 icmpInDestUnreachs: https://tools.ietf.org/html/rfc1213#page-41
  120. .. _RFC1213 icmpInTimeExcds: https://tools.ietf.org/html/rfc1213#page-41
  121. .. _RFC1213 icmpInParmProbs: https://tools.ietf.org/html/rfc1213#page-42
  122. .. _RFC1213 icmpInSrcQuenchs: https://tools.ietf.org/html/rfc1213#page-42
  123. .. _RFC1213 icmpInRedirects: https://tools.ietf.org/html/rfc1213#page-42
  124. .. _RFC1213 icmpInEchos: https://tools.ietf.org/html/rfc1213#page-42
  125. .. _RFC1213 icmpInEchoReps: https://tools.ietf.org/html/rfc1213#page-42
  126. .. _RFC1213 icmpInTimestamps: https://tools.ietf.org/html/rfc1213#page-42
  127. .. _RFC1213 icmpInTimestampReps: https://tools.ietf.org/html/rfc1213#page-43
  128. .. _RFC1213 icmpInAddrMasks: https://tools.ietf.org/html/rfc1213#page-43
  129. .. _RFC1213 icmpInAddrMaskReps: https://tools.ietf.org/html/rfc1213#page-43
  130. .. _RFC1213 icmpOutDestUnreachs: https://tools.ietf.org/html/rfc1213#page-44
  131. .. _RFC1213 icmpOutTimeExcds: https://tools.ietf.org/html/rfc1213#page-44
  132. .. _RFC1213 icmpOutParmProbs: https://tools.ietf.org/html/rfc1213#page-44
  133. .. _RFC1213 icmpOutSrcQuenchs: https://tools.ietf.org/html/rfc1213#page-44
  134. .. _RFC1213 icmpOutRedirects: https://tools.ietf.org/html/rfc1213#page-44
  135. .. _RFC1213 icmpOutEchos: https://tools.ietf.org/html/rfc1213#page-45
  136. .. _RFC1213 icmpOutEchoReps: https://tools.ietf.org/html/rfc1213#page-45
  137. .. _RFC1213 icmpOutTimestamps: https://tools.ietf.org/html/rfc1213#page-45
  138. .. _RFC1213 icmpOutTimestampReps: https://tools.ietf.org/html/rfc1213#page-45
  139. .. _RFC1213 icmpOutAddrMasks: https://tools.ietf.org/html/rfc1213#page-45
  140. .. _RFC1213 icmpOutAddrMaskReps: https://tools.ietf.org/html/rfc1213#page-46
  141. Every ICMP type has two counters: 'In' and 'Out'. E.g., for the ICMP
  142. Echo packet, they are IcmpInEchos and IcmpOutEchos. Their meanings are
  143. straightforward. The 'In' counter means kernel receives such a packet
  144. and the 'Out' counter means kernel sends such a packet.
  145. * ICMP numeric types
  146. They are IcmpMsgInType[N] and IcmpMsgOutType[N], the [N] indicates the
  147. ICMP type number. These counters track all kinds of ICMP packets. The
  148. ICMP type number definition could be found in the `ICMP parameters`_
  149. document.
  150. .. _ICMP parameters: https://www.iana.org/assignments/icmp-parameters/icmp-parameters.xhtml
  151. For example, if the Linux kernel sends an ICMP Echo packet, the
  152. IcmpMsgOutType8 would increase 1. And if kernel gets an ICMP Echo Reply
  153. packet, IcmpMsgInType0 would increase 1.
  154. * IcmpInCsumErrors
  155. This counter indicates the checksum of the ICMP packet is
  156. wrong. Kernel verifies the checksum after updating the IcmpInMsgs and
  157. before updating IcmpMsgInType[N]. If a packet has bad checksum, the
  158. IcmpInMsgs would be updated but none of IcmpMsgInType[N] would be updated.
  159. * IcmpInErrors and IcmpOutErrors
  160. Defined by `RFC1213 icmpInErrors`_ and `RFC1213 icmpOutErrors`_
  161. .. _RFC1213 icmpInErrors: https://tools.ietf.org/html/rfc1213#page-41
  162. .. _RFC1213 icmpOutErrors: https://tools.ietf.org/html/rfc1213#page-43
  163. When an error occurs in the ICMP packet handler path, these two
  164. counters would be updated. The receiving packet path use IcmpInErrors
  165. and the sending packet path use IcmpOutErrors. When IcmpInCsumErrors
  166. is increased, IcmpInErrors would always be increased too.
  167. relationship of the ICMP counters
  168. ---------------------------------
  169. The sum of IcmpMsgOutType[N] is always equal to IcmpOutMsgs, as they
  170. are updated at the same time. The sum of IcmpMsgInType[N] plus
  171. IcmpInErrors should be equal or larger than IcmpInMsgs. When kernel
  172. receives an ICMP packet, kernel follows below logic:
  173. 1. increase IcmpInMsgs
  174. 2. if has any error, update IcmpInErrors and finish the process
  175. 3. update IcmpMsgOutType[N]
  176. 4. handle the packet depending on the type, if has any error, update
  177. IcmpInErrors and finish the process
  178. So if all errors occur in step (2), IcmpInMsgs should be equal to the
  179. sum of IcmpMsgOutType[N] plus IcmpInErrors. If all errors occur in
  180. step (4), IcmpInMsgs should be equal to the sum of
  181. IcmpMsgOutType[N]. If the errors occur in both step (2) and step (4),
  182. IcmpInMsgs should be less than the sum of IcmpMsgOutType[N] plus
  183. IcmpInErrors.
  184. General TCP counters
  185. ====================
  186. * TcpInSegs
  187. Defined in `RFC1213 tcpInSegs`_
  188. .. _RFC1213 tcpInSegs: https://tools.ietf.org/html/rfc1213#page-48
  189. The number of packets received by the TCP layer. As mentioned in
  190. RFC1213, it includes the packets received in error, such as checksum
  191. error, invalid TCP header and so on. Only one error won't be included:
  192. if the layer 2 destination address is not the NIC's layer 2
  193. address. It might happen if the packet is a multicast or broadcast
  194. packet, or the NIC is in promiscuous mode. In these situations, the
  195. packets would be delivered to the TCP layer, but the TCP layer will discard
  196. these packets before increasing TcpInSegs. The TcpInSegs counter
  197. isn't aware of GRO. So if two packets are merged by GRO, the TcpInSegs
  198. counter would only increase 1.
  199. * TcpOutSegs
  200. Defined in `RFC1213 tcpOutSegs`_
  201. .. _RFC1213 tcpOutSegs: https://tools.ietf.org/html/rfc1213#page-48
  202. The number of packets sent by the TCP layer. As mentioned in RFC1213,
  203. it excludes the retransmitted packets. But it includes the SYN, ACK
  204. and RST packets. Doesn't like TcpInSegs, the TcpOutSegs is aware of
  205. GSO, so if a packet would be split to 2 by GSO, TcpOutSegs will
  206. increase 2.
  207. * TcpActiveOpens
  208. Defined in `RFC1213 tcpActiveOpens`_
  209. .. _RFC1213 tcpActiveOpens: https://tools.ietf.org/html/rfc1213#page-47
  210. It means the TCP layer sends a SYN, and come into the SYN-SENT
  211. state. Every time TcpActiveOpens increases 1, TcpOutSegs should always
  212. increase 1.
  213. * TcpPassiveOpens
  214. Defined in `RFC1213 tcpPassiveOpens`_
  215. .. _RFC1213 tcpPassiveOpens: https://tools.ietf.org/html/rfc1213#page-47
  216. It means the TCP layer receives a SYN, replies a SYN+ACK, come into
  217. the SYN-RCVD state.
  218. * TcpExtTCPRcvCoalesce
  219. When packets are received by the TCP layer and are not be read by the
  220. application, the TCP layer will try to merge them. This counter
  221. indicate how many packets are merged in such situation. If GRO is
  222. enabled, lots of packets would be merged by GRO, these packets
  223. wouldn't be counted to TcpExtTCPRcvCoalesce.
  224. * TcpExtTCPAutoCorking
  225. When sending packets, the TCP layer will try to merge small packets to
  226. a bigger one. This counter increase 1 for every packet merged in such
  227. situation. Please refer to the LWN article for more details:
  228. https://lwn.net/Articles/576263/
  229. * TcpExtTCPOrigDataSent
  230. This counter is explained by kernel commit f19c29e3e391, I pasted the
  231. explanation below::
  232. TCPOrigDataSent: number of outgoing packets with original data (excluding
  233. retransmission but including data-in-SYN). This counter is different from
  234. TcpOutSegs because TcpOutSegs also tracks pure ACKs. TCPOrigDataSent is
  235. more useful to track the TCP retransmission rate.
  236. * TCPSynRetrans
  237. This counter is explained by kernel commit f19c29e3e391, I pasted the
  238. explanation below::
  239. TCPSynRetrans: number of SYN and SYN/ACK retransmits to break down
  240. retransmissions into SYN, fast-retransmits, timeout retransmits, etc.
  241. * TCPFastOpenActiveFail
  242. This counter is explained by kernel commit f19c29e3e391, I pasted the
  243. explanation below::
  244. TCPFastOpenActiveFail: Fast Open attempts (SYN/data) failed because
  245. the remote does not accept it or the attempts timed out.
  246. * TcpExtListenOverflows and TcpExtListenDrops
  247. When kernel receives a SYN from a client, and if the TCP accept queue
  248. is full, kernel will drop the SYN and add 1 to TcpExtListenOverflows.
  249. At the same time kernel will also add 1 to TcpExtListenDrops. When a
  250. TCP socket is in LISTEN state, and kernel need to drop a packet,
  251. kernel would always add 1 to TcpExtListenDrops. So increase
  252. TcpExtListenOverflows would let TcpExtListenDrops increasing at the
  253. same time, but TcpExtListenDrops would also increase without
  254. TcpExtListenOverflows increasing, e.g. a memory allocation fail would
  255. also let TcpExtListenDrops increase.
  256. Note: The above explanation is based on kernel 4.10 or above version, on
  257. an old kernel, the TCP stack has different behavior when TCP accept
  258. queue is full. On the old kernel, TCP stack won't drop the SYN, it
  259. would complete the 3-way handshake. As the accept queue is full, TCP
  260. stack will keep the socket in the TCP half-open queue. As it is in the
  261. half open queue, TCP stack will send SYN+ACK on an exponential backoff
  262. timer, after client replies ACK, TCP stack checks whether the accept
  263. queue is still full, if it is not full, moves the socket to the accept
  264. queue, if it is full, keeps the socket in the half-open queue, at next
  265. time client replies ACK, this socket will get another chance to move
  266. to the accept queue.
  267. TCP Fast Open
  268. =============
  269. * TcpEstabResets
  270. Defined in `RFC1213 tcpEstabResets`_.
  271. .. _RFC1213 tcpEstabResets: https://tools.ietf.org/html/rfc1213#page-48
  272. * TcpAttemptFails
  273. Defined in `RFC1213 tcpAttemptFails`_.
  274. .. _RFC1213 tcpAttemptFails: https://tools.ietf.org/html/rfc1213#page-48
  275. * TcpOutRsts
  276. Defined in `RFC1213 tcpOutRsts`_. The RFC says this counter indicates
  277. the 'segments sent containing the RST flag', but in linux kernel, this
  278. counter indicates the segments kernel tried to send. The sending
  279. process might be failed due to some errors (e.g. memory alloc failed).
  280. .. _RFC1213 tcpOutRsts: https://tools.ietf.org/html/rfc1213#page-52
  281. * TcpExtTCPSpuriousRtxHostQueues
  282. When the TCP stack wants to retransmit a packet, and finds that packet
  283. is not lost in the network, but the packet is not sent yet, the TCP
  284. stack would give up the retransmission and update this counter. It
  285. might happen if a packet stays too long time in a qdisc or driver
  286. queue.
  287. * TcpEstabResets
  288. The socket receives a RST packet in Establish or CloseWait state.
  289. * TcpExtTCPKeepAlive
  290. This counter indicates many keepalive packets were sent. The keepalive
  291. won't be enabled by default. A userspace program could enable it by
  292. setting the SO_KEEPALIVE socket option.
  293. * TcpExtTCPSpuriousRTOs
  294. The spurious retransmission timeout detected by the `F-RTO`_
  295. algorithm.
  296. .. _F-RTO: https://tools.ietf.org/html/rfc5682
  297. TCP Fast Path
  298. =============
  299. When kernel receives a TCP packet, it has two paths to handler the
  300. packet, one is fast path, another is slow path. The comment in kernel
  301. code provides a good explanation of them, I pasted them below::
  302. It is split into a fast path and a slow path. The fast path is
  303. disabled when:
  304. - A zero window was announced from us
  305. - zero window probing
  306. is only handled properly on the slow path.
  307. - Out of order segments arrived.
  308. - Urgent data is expected.
  309. - There is no buffer space left
  310. - Unexpected TCP flags/window values/header lengths are received
  311. (detected by checking the TCP header against pred_flags)
  312. - Data is sent in both directions. The fast path only supports pure senders
  313. or pure receivers (this means either the sequence number or the ack
  314. value must stay constant)
  315. - Unexpected TCP option.
  316. Kernel will try to use fast path unless any of the above conditions
  317. are satisfied. If the packets are out of order, kernel will handle
  318. them in slow path, which means the performance might be not very
  319. good. Kernel would also come into slow path if the "Delayed ack" is
  320. used, because when using "Delayed ack", the data is sent in both
  321. directions. When the TCP window scale option is not used, kernel will
  322. try to enable fast path immediately when the connection comes into the
  323. established state, but if the TCP window scale option is used, kernel
  324. will disable the fast path at first, and try to enable it after kernel
  325. receives packets.
  326. * TcpExtTCPPureAcks and TcpExtTCPHPAcks
  327. If a packet set ACK flag and has no data, it is a pure ACK packet, if
  328. kernel handles it in the fast path, TcpExtTCPHPAcks will increase 1,
  329. if kernel handles it in the slow path, TcpExtTCPPureAcks will
  330. increase 1.
  331. * TcpExtTCPHPHits
  332. If a TCP packet has data (which means it is not a pure ACK packet),
  333. and this packet is handled in the fast path, TcpExtTCPHPHits will
  334. increase 1.
  335. TCP abort
  336. =========
  337. * TcpExtTCPAbortOnData
  338. It means TCP layer has data in flight, but need to close the
  339. connection. So TCP layer sends a RST to the other side, indicate the
  340. connection is not closed very graceful. An easy way to increase this
  341. counter is using the SO_LINGER option. Please refer to the SO_LINGER
  342. section of the `socket man page`_:
  343. .. _socket man page: http://man7.org/linux/man-pages/man7/socket.7.html
  344. By default, when an application closes a connection, the close function
  345. will return immediately and kernel will try to send the in-flight data
  346. async. If you use the SO_LINGER option, set l_onoff to 1, and l_linger
  347. to a positive number, the close function won't return immediately, but
  348. wait for the in-flight data are acked by the other side, the max wait
  349. time is l_linger seconds. If set l_onoff to 1 and set l_linger to 0,
  350. when the application closes a connection, kernel will send a RST
  351. immediately and increase the TcpExtTCPAbortOnData counter.
  352. * TcpExtTCPAbortOnClose
  353. This counter means the application has unread data in the TCP layer when
  354. the application wants to close the TCP connection. In such a situation,
  355. kernel will send a RST to the other side of the TCP connection.
  356. * TcpExtTCPAbortOnMemory
  357. When an application closes a TCP connection, kernel still need to track
  358. the connection, let it complete the TCP disconnect process. E.g. an
  359. app calls the close method of a socket, kernel sends fin to the other
  360. side of the connection, then the app has no relationship with the
  361. socket any more, but kernel need to keep the socket, this socket
  362. becomes an orphan socket, kernel waits for the reply of the other side,
  363. and would come to the TIME_WAIT state finally. When kernel has no
  364. enough memory to keep the orphan socket, kernel would send an RST to
  365. the other side, and delete the socket, in such situation, kernel will
  366. increase 1 to the TcpExtTCPAbortOnMemory. Two conditions would trigger
  367. TcpExtTCPAbortOnMemory:
  368. 1. the memory used by the TCP protocol is higher than the third value of
  369. the tcp_mem. Please refer the tcp_mem section in the `TCP man page`_:
  370. .. _TCP man page: http://man7.org/linux/man-pages/man7/tcp.7.html
  371. 2. the orphan socket count is higher than net.ipv4.tcp_max_orphans
  372. * TcpExtTCPAbortOnTimeout
  373. This counter will increase when any of the TCP timers expire. In such
  374. situation, kernel won't send RST, just give up the connection.
  375. * TcpExtTCPAbortOnLinger
  376. When a TCP connection comes into FIN_WAIT_2 state, instead of waiting
  377. for the fin packet from the other side, kernel could send a RST and
  378. delete the socket immediately. This is not the default behavior of
  379. Linux kernel TCP stack. By configuring the TCP_LINGER2 socket option,
  380. you could let kernel follow this behavior.
  381. * TcpExtTCPAbortFailed
  382. The kernel TCP layer will send RST if the `RFC2525 2.17 section`_ is
  383. satisfied. If an internal error occurs during this process,
  384. TcpExtTCPAbortFailed will be increased.
  385. .. _RFC2525 2.17 section: https://tools.ietf.org/html/rfc2525#page-50
  386. TCP Hybrid Slow Start
  387. =====================
  388. The Hybrid Slow Start algorithm is an enhancement of the traditional
  389. TCP congestion window Slow Start algorithm. It uses two pieces of
  390. information to detect whether the max bandwidth of the TCP path is
  391. approached. The two pieces of information are ACK train length and
  392. increase in packet delay. For detail information, please refer the
  393. `Hybrid Slow Start paper`_. Either ACK train length or packet delay
  394. hits a specific threshold, the congestion control algorithm will come
  395. into the Congestion Avoidance state. Until v4.20, two congestion
  396. control algorithms are using Hybrid Slow Start, they are cubic (the
  397. default congestion control algorithm) and cdg. Four snmp counters
  398. relate with the Hybrid Slow Start algorithm.
  399. .. _Hybrid Slow Start paper: https://pdfs.semanticscholar.org/25e9/ef3f03315782c7f1cbcd31b587857adae7d1.pdf
  400. * TcpExtTCPHystartTrainDetect
  401. How many times the ACK train length threshold is detected
  402. * TcpExtTCPHystartTrainCwnd
  403. The sum of CWND detected by ACK train length. Dividing this value by
  404. TcpExtTCPHystartTrainDetect is the average CWND which detected by the
  405. ACK train length.
  406. * TcpExtTCPHystartDelayDetect
  407. How many times the packet delay threshold is detected.
  408. * TcpExtTCPHystartDelayCwnd
  409. The sum of CWND detected by packet delay. Dividing this value by
  410. TcpExtTCPHystartDelayDetect is the average CWND which detected by the
  411. packet delay.
  412. TCP retransmission and congestion control
  413. =========================================
  414. The TCP protocol has two retransmission mechanisms: SACK and fast
  415. recovery. They are exclusive with each other. When SACK is enabled,
  416. the kernel TCP stack would use SACK, or kernel would use fast
  417. recovery. The SACK is a TCP option, which is defined in `RFC2018`_,
  418. the fast recovery is defined in `RFC6582`_, which is also called
  419. 'Reno'.
  420. The TCP congestion control is a big and complex topic. To understand
  421. the related snmp counter, we need to know the states of the congestion
  422. control state machine. There are 5 states: Open, Disorder, CWR,
  423. Recovery and Loss. For details about these states, please refer page 5
  424. and page 6 of this document:
  425. https://pdfs.semanticscholar.org/0e9c/968d09ab2e53e24c4dca5b2d67c7f7140f8e.pdf
  426. .. _RFC2018: https://tools.ietf.org/html/rfc2018
  427. .. _RFC6582: https://tools.ietf.org/html/rfc6582
  428. * TcpExtTCPRenoRecovery and TcpExtTCPSackRecovery
  429. When the congestion control comes into Recovery state, if sack is
  430. used, TcpExtTCPSackRecovery increases 1, if sack is not used,
  431. TcpExtTCPRenoRecovery increases 1. These two counters mean the TCP
  432. stack begins to retransmit the lost packets.
  433. * TcpExtTCPSACKReneging
  434. A packet was acknowledged by SACK, but the receiver has dropped this
  435. packet, so the sender needs to retransmit this packet. In this
  436. situation, the sender adds 1 to TcpExtTCPSACKReneging. A receiver
  437. could drop a packet which has been acknowledged by SACK, although it is
  438. unusual, it is allowed by the TCP protocol. The sender doesn't really
  439. know what happened on the receiver side. The sender just waits until
  440. the RTO expires for this packet, then the sender assumes this packet
  441. has been dropped by the receiver.
  442. * TcpExtTCPRenoReorder
  443. The reorder packet is detected by fast recovery. It would only be used
  444. if SACK is disabled. The fast recovery algorithm detects recorder by
  445. the duplicate ACK number. E.g., if retransmission is triggered, and
  446. the original retransmitted packet is not lost, it is just out of
  447. order, the receiver would acknowledge multiple times, one for the
  448. retransmitted packet, another for the arriving of the original out of
  449. order packet. Thus the sender would find more ACks than its
  450. expectation, and the sender knows out of order occurs.
  451. * TcpExtTCPTSReorder
  452. The reorder packet is detected when a hole is filled. E.g., assume the
  453. sender sends packet 1,2,3,4,5, and the receiving order is
  454. 1,2,4,5,3. When the sender receives the ACK of packet 3 (which will
  455. fill the hole), two conditions will let TcpExtTCPTSReorder increase
  456. 1: (1) if the packet 3 is not re-retransmitted yet. (2) if the packet
  457. 3 is retransmitted but the timestamp of the packet 3's ACK is earlier
  458. than the retransmission timestamp.
  459. * TcpExtTCPSACKReorder
  460. The reorder packet detected by SACK. The SACK has two methods to
  461. detect reorder: (1) DSACK is received by the sender. It means the
  462. sender sends the same packet more than one times. And the only reason
  463. is the sender believes an out of order packet is lost so it sends the
  464. packet again. (2) Assume packet 1,2,3,4,5 are sent by the sender, and
  465. the sender has received SACKs for packet 2 and 5, now the sender
  466. receives SACK for packet 4 and the sender doesn't retransmit the
  467. packet yet, the sender would know packet 4 is out of order. The TCP
  468. stack of kernel will increase TcpExtTCPSACKReorder for both of the
  469. above scenarios.
  470. * TcpExtTCPSlowStartRetrans
  471. The TCP stack wants to retransmit a packet and the congestion control
  472. state is 'Loss'.
  473. * TcpExtTCPFastRetrans
  474. The TCP stack wants to retransmit a packet and the congestion control
  475. state is not 'Loss'.
  476. * TcpExtTCPLostRetransmit
  477. A SACK points out that a retransmission packet is lost again.
  478. * TcpExtTCPRetransFail
  479. The TCP stack tries to deliver a retransmission packet to lower layers
  480. but the lower layers return an error.
  481. * TcpExtTCPSynRetrans
  482. The TCP stack retransmits a SYN packet.
  483. DSACK
  484. =====
  485. The DSACK is defined in `RFC2883`_. The receiver uses DSACK to report
  486. duplicate packets to the sender. There are two kinds of
  487. duplications: (1) a packet which has been acknowledged is
  488. duplicate. (2) an out of order packet is duplicate. The TCP stack
  489. counts these two kinds of duplications on both receiver side and
  490. sender side.
  491. .. _RFC2883 : https://tools.ietf.org/html/rfc2883
  492. * TcpExtTCPDSACKOldSent
  493. The TCP stack receives a duplicate packet which has been acked, so it
  494. sends a DSACK to the sender.
  495. * TcpExtTCPDSACKOfoSent
  496. The TCP stack receives an out of order duplicate packet, so it sends a
  497. DSACK to the sender.
  498. * TcpExtTCPDSACKRecv
  499. The TCP stack receives a DSACK, which indicates an acknowledged
  500. duplicate packet is received.
  501. * TcpExtTCPDSACKOfoRecv
  502. The TCP stack receives a DSACK, which indicate an out of order
  503. duplicate packet is received.
  504. invalid SACK and DSACK
  505. ======================
  506. When a SACK (or DSACK) block is invalid, a corresponding counter would
  507. be updated. The validation method is base on the start/end sequence
  508. number of the SACK block. For more details, please refer the comment
  509. of the function tcp_is_sackblock_valid in the kernel source code. A
  510. SACK option could have up to 4 blocks, they are checked
  511. individually. E.g., if 3 blocks of a SACk is invalid, the
  512. corresponding counter would be updated 3 times. The comment of commit
  513. 18f02545a9a1 ("[TCP] MIB: Add counters for discarded SACK blocks")
  514. has additional explanation:
  515. * TcpExtTCPSACKDiscard
  516. This counter indicates how many SACK blocks are invalid. If the invalid
  517. SACK block is caused by ACK recording, the TCP stack will only ignore
  518. it and won't update this counter.
  519. * TcpExtTCPDSACKIgnoredOld and TcpExtTCPDSACKIgnoredNoUndo
  520. When a DSACK block is invalid, one of these two counters would be
  521. updated. Which counter will be updated depends on the undo_marker flag
  522. of the TCP socket. If the undo_marker is not set, the TCP stack isn't
  523. likely to re-transmit any packets, and we still receive an invalid
  524. DSACK block, the reason might be that the packet is duplicated in the
  525. middle of the network. In such scenario, TcpExtTCPDSACKIgnoredNoUndo
  526. will be updated. If the undo_marker is set, TcpExtTCPDSACKIgnoredOld
  527. will be updated. As implied in its name, it might be an old packet.
  528. SACK shift
  529. ==========
  530. The linux networking stack stores data in sk_buff struct (skb for
  531. short). If a SACK block acrosses multiple skb, the TCP stack will try
  532. to re-arrange data in these skb. E.g. if a SACK block acknowledges seq
  533. 10 to 15, skb1 has seq 10 to 13, skb2 has seq 14 to 20. The seq 14 and
  534. 15 in skb2 would be moved to skb1. This operation is 'shift'. If a
  535. SACK block acknowledges seq 10 to 20, skb1 has seq 10 to 13, skb2 has
  536. seq 14 to 20. All data in skb2 will be moved to skb1, and skb2 will be
  537. discard, this operation is 'merge'.
  538. * TcpExtTCPSackShifted
  539. A skb is shifted
  540. * TcpExtTCPSackMerged
  541. A skb is merged
  542. * TcpExtTCPSackShiftFallback
  543. A skb should be shifted or merged, but the TCP stack doesn't do it for
  544. some reasons.
  545. TCP out of order
  546. ================
  547. * TcpExtTCPOFOQueue
  548. The TCP layer receives an out of order packet and has enough memory
  549. to queue it.
  550. * TcpExtTCPOFODrop
  551. The TCP layer receives an out of order packet but doesn't have enough
  552. memory, so drops it. Such packets won't be counted into
  553. TcpExtTCPOFOQueue.
  554. * TcpExtTCPOFOMerge
  555. The received out of order packet has an overlay with the previous
  556. packet. the overlay part will be dropped. All of TcpExtTCPOFOMerge
  557. packets will also be counted into TcpExtTCPOFOQueue.
  558. TCP PAWS
  559. ========
  560. PAWS (Protection Against Wrapped Sequence numbers) is an algorithm
  561. which is used to drop old packets. It depends on the TCP
  562. timestamps. For detail information, please refer the `timestamp wiki`_
  563. and the `RFC of PAWS`_.
  564. .. _RFC of PAWS: https://tools.ietf.org/html/rfc1323#page-17
  565. .. _timestamp wiki: https://en.wikipedia.org/wiki/Transmission_Control_Protocol#TCP_timestamps
  566. * TcpExtPAWSActive
  567. Packets are dropped by PAWS in Syn-Sent status.
  568. * TcpExtPAWSEstab
  569. Packets are dropped by PAWS in any status other than Syn-Sent.
  570. TCP ACK skip
  571. ============
  572. In some scenarios, kernel would avoid sending duplicate ACKs too
  573. frequently. Please find more details in the tcp_invalid_ratelimit
  574. section of the `sysctl document`_. When kernel decides to skip an ACK
  575. due to tcp_invalid_ratelimit, kernel would update one of below
  576. counters to indicate the ACK is skipped in which scenario. The ACK
  577. would only be skipped if the received packet is either a SYN packet or
  578. it has no data.
  579. .. _sysctl document: https://www.kernel.org/doc/Documentation/networking/ip-sysctl.rst
  580. * TcpExtTCPACKSkippedSynRecv
  581. The ACK is skipped in Syn-Recv status. The Syn-Recv status means the
  582. TCP stack receives a SYN and replies SYN+ACK. Now the TCP stack is
  583. waiting for an ACK. Generally, the TCP stack doesn't need to send ACK
  584. in the Syn-Recv status. But in several scenarios, the TCP stack need
  585. to send an ACK. E.g., the TCP stack receives the same SYN packet
  586. repeately, the received packet does not pass the PAWS check, or the
  587. received packet sequence number is out of window. In these scenarios,
  588. the TCP stack needs to send ACK. If the ACk sending frequency is higher than
  589. tcp_invalid_ratelimit allows, the TCP stack will skip sending ACK and
  590. increase TcpExtTCPACKSkippedSynRecv.
  591. * TcpExtTCPACKSkippedPAWS
  592. The ACK is skipped due to PAWS (Protect Against Wrapped Sequence
  593. numbers) check fails. If the PAWS check fails in Syn-Recv, Fin-Wait-2
  594. or Time-Wait statuses, the skipped ACK would be counted to
  595. TcpExtTCPACKSkippedSynRecv, TcpExtTCPACKSkippedFinWait2 or
  596. TcpExtTCPACKSkippedTimeWait. In all other statuses, the skipped ACK
  597. would be counted to TcpExtTCPACKSkippedPAWS.
  598. * TcpExtTCPACKSkippedSeq
  599. The sequence number is out of window and the timestamp passes the PAWS
  600. check and the TCP status is not Syn-Recv, Fin-Wait-2, and Time-Wait.
  601. * TcpExtTCPACKSkippedFinWait2
  602. The ACK is skipped in Fin-Wait-2 status, the reason would be either
  603. PAWS check fails or the received sequence number is out of window.
  604. * TcpExtTCPACKSkippedTimeWait
  605. The ACK is skipped in Time-Wait status, the reason would be either
  606. PAWS check failed or the received sequence number is out of window.
  607. * TcpExtTCPACKSkippedChallenge
  608. The ACK is skipped if the ACK is a challenge ACK. The RFC 5961 defines
  609. 3 kind of challenge ACK, please refer `RFC 5961 section 3.2`_,
  610. `RFC 5961 section 4.2`_ and `RFC 5961 section 5.2`_. Besides these
  611. three scenarios, In some TCP status, the linux TCP stack would also
  612. send challenge ACKs if the ACK number is before the first
  613. unacknowledged number (more strict than `RFC 5961 section 5.2`_).
  614. .. _RFC 5961 section 3.2: https://tools.ietf.org/html/rfc5961#page-7
  615. .. _RFC 5961 section 4.2: https://tools.ietf.org/html/rfc5961#page-9
  616. .. _RFC 5961 section 5.2: https://tools.ietf.org/html/rfc5961#page-11
  617. TCP receive window
  618. ==================
  619. * TcpExtTCPWantZeroWindowAdv
  620. Depending on current memory usage, the TCP stack tries to set receive
  621. window to zero. But the receive window might still be a no-zero
  622. value. For example, if the previous window size is 10, and the TCP
  623. stack receives 3 bytes, the current window size would be 7 even if the
  624. window size calculated by the memory usage is zero.
  625. * TcpExtTCPToZeroWindowAdv
  626. The TCP receive window is set to zero from a no-zero value.
  627. * TcpExtTCPFromZeroWindowAdv
  628. The TCP receive window is set to no-zero value from zero.
  629. Delayed ACK
  630. ===========
  631. The TCP Delayed ACK is a technique which is used for reducing the
  632. packet count in the network. For more details, please refer the
  633. `Delayed ACK wiki`_
  634. .. _Delayed ACK wiki: https://en.wikipedia.org/wiki/TCP_delayed_acknowledgment
  635. * TcpExtDelayedACKs
  636. A delayed ACK timer expires. The TCP stack will send a pure ACK packet
  637. and exit the delayed ACK mode.
  638. * TcpExtDelayedACKLocked
  639. A delayed ACK timer expires, but the TCP stack can't send an ACK
  640. immediately due to the socket is locked by a userspace program. The
  641. TCP stack will send a pure ACK later (after the userspace program
  642. unlock the socket). When the TCP stack sends the pure ACK later, the
  643. TCP stack will also update TcpExtDelayedACKs and exit the delayed ACK
  644. mode.
  645. * TcpExtDelayedACKLost
  646. It will be updated when the TCP stack receives a packet which has been
  647. ACKed. A Delayed ACK loss might cause this issue, but it would also be
  648. triggered by other reasons, such as a packet is duplicated in the
  649. network.
  650. Tail Loss Probe (TLP)
  651. =====================
  652. TLP is an algorithm which is used to detect TCP packet loss. For more
  653. details, please refer the `TLP paper`_.
  654. .. _TLP paper: https://tools.ietf.org/html/draft-dukkipati-tcpm-tcp-loss-probe-01
  655. * TcpExtTCPLossProbes
  656. A TLP probe packet is sent.
  657. * TcpExtTCPLossProbeRecovery
  658. A packet loss is detected and recovered by TLP.
  659. TCP Fast Open description
  660. =========================
  661. TCP Fast Open is a technology which allows data transfer before the
  662. 3-way handshake complete. Please refer the `TCP Fast Open wiki`_ for a
  663. general description.
  664. .. _TCP Fast Open wiki: https://en.wikipedia.org/wiki/TCP_Fast_Open
  665. * TcpExtTCPFastOpenActive
  666. When the TCP stack receives an ACK packet in the SYN-SENT status, and
  667. the ACK packet acknowledges the data in the SYN packet, the TCP stack
  668. understand the TFO cookie is accepted by the other side, then it
  669. updates this counter.
  670. * TcpExtTCPFastOpenActiveFail
  671. This counter indicates that the TCP stack initiated a TCP Fast Open,
  672. but it failed. This counter would be updated in three scenarios: (1)
  673. the other side doesn't acknowledge the data in the SYN packet. (2) The
  674. SYN packet which has the TFO cookie is timeout at least once. (3)
  675. after the 3-way handshake, the retransmission timeout happens
  676. net.ipv4.tcp_retries1 times, because some middle-boxes may black-hole
  677. fast open after the handshake.
  678. * TcpExtTCPFastOpenPassive
  679. This counter indicates how many times the TCP stack accepts the fast
  680. open request.
  681. * TcpExtTCPFastOpenPassiveFail
  682. This counter indicates how many times the TCP stack rejects the fast
  683. open request. It is caused by either the TFO cookie is invalid or the
  684. TCP stack finds an error during the socket creating process.
  685. * TcpExtTCPFastOpenListenOverflow
  686. When the pending fast open request number is larger than
  687. fastopenq->max_qlen, the TCP stack will reject the fast open request
  688. and update this counter. When this counter is updated, the TCP stack
  689. won't update TcpExtTCPFastOpenPassive or
  690. TcpExtTCPFastOpenPassiveFail. The fastopenq->max_qlen is set by the
  691. TCP_FASTOPEN socket operation and it could not be larger than
  692. net.core.somaxconn. For example:
  693. setsockopt(sfd, SOL_TCP, TCP_FASTOPEN, &qlen, sizeof(qlen));
  694. * TcpExtTCPFastOpenCookieReqd
  695. This counter indicates how many times a client wants to request a TFO
  696. cookie.
  697. SYN cookies
  698. ===========
  699. SYN cookies are used to mitigate SYN flood, for details, please refer
  700. the `SYN cookies wiki`_.
  701. .. _SYN cookies wiki: https://en.wikipedia.org/wiki/SYN_cookies
  702. * TcpExtSyncookiesSent
  703. It indicates how many SYN cookies are sent.
  704. * TcpExtSyncookiesRecv
  705. How many reply packets of the SYN cookies the TCP stack receives.
  706. * TcpExtSyncookiesFailed
  707. The MSS decoded from the SYN cookie is invalid. When this counter is
  708. updated, the received packet won't be treated as a SYN cookie and the
  709. TcpExtSyncookiesRecv counter won't be updated.
  710. Challenge ACK
  711. =============
  712. For details of challenge ACK, please refer the explanation of
  713. TcpExtTCPACKSkippedChallenge.
  714. * TcpExtTCPChallengeACK
  715. The number of challenge acks sent.
  716. * TcpExtTCPSYNChallenge
  717. The number of challenge acks sent in response to SYN packets. After
  718. updates this counter, the TCP stack might send a challenge ACK and
  719. update the TcpExtTCPChallengeACK counter, or it might also skip to
  720. send the challenge and update the TcpExtTCPACKSkippedChallenge.
  721. prune
  722. =====
  723. When a socket is under memory pressure, the TCP stack will try to
  724. reclaim memory from the receiving queue and out of order queue. One of
  725. the reclaiming method is 'collapse', which means allocate a big skb,
  726. copy the contiguous skbs to the single big skb, and free these
  727. contiguous skbs.
  728. * TcpExtPruneCalled
  729. The TCP stack tries to reclaim memory for a socket. After updates this
  730. counter, the TCP stack will try to collapse the out of order queue and
  731. the receiving queue. If the memory is still not enough, the TCP stack
  732. will try to discard packets from the out of order queue (and update the
  733. TcpExtOfoPruned counter)
  734. * TcpExtOfoPruned
  735. The TCP stack tries to discard packet on the out of order queue.
  736. * TcpExtRcvPruned
  737. After 'collapse' and discard packets from the out of order queue, if
  738. the actually used memory is still larger than the max allowed memory,
  739. this counter will be updated. It means the 'prune' fails.
  740. * TcpExtTCPRcvCollapsed
  741. This counter indicates how many skbs are freed during 'collapse'.
  742. examples
  743. ========
  744. ping test
  745. ---------
  746. Run the ping command against the public dns server 8.8.8.8::
  747. nstatuser@nstat-a:~$ ping 8.8.8.8 -c 1
  748. PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
  749. 64 bytes from 8.8.8.8: icmp_seq=1 ttl=119 time=17.8 ms
  750. --- 8.8.8.8 ping statistics ---
  751. 1 packets transmitted, 1 received, 0% packet loss, time 0ms
  752. rtt min/avg/max/mdev = 17.875/17.875/17.875/0.000 ms
  753. The nstayt result::
  754. nstatuser@nstat-a:~$ nstat
  755. #kernel
  756. IpInReceives 1 0.0
  757. IpInDelivers 1 0.0
  758. IpOutRequests 1 0.0
  759. IcmpInMsgs 1 0.0
  760. IcmpInEchoReps 1 0.0
  761. IcmpOutMsgs 1 0.0
  762. IcmpOutEchos 1 0.0
  763. IcmpMsgInType0 1 0.0
  764. IcmpMsgOutType8 1 0.0
  765. IpExtInOctets 84 0.0
  766. IpExtOutOctets 84 0.0
  767. IpExtInNoECTPkts 1 0.0
  768. The Linux server sent an ICMP Echo packet, so IpOutRequests,
  769. IcmpOutMsgs, IcmpOutEchos and IcmpMsgOutType8 were increased 1. The
  770. server got ICMP Echo Reply from 8.8.8.8, so IpInReceives, IcmpInMsgs,
  771. IcmpInEchoReps and IcmpMsgInType0 were increased 1. The ICMP Echo Reply
  772. was passed to the ICMP layer via IP layer, so IpInDelivers was
  773. increased 1. The default ping data size is 48, so an ICMP Echo packet
  774. and its corresponding Echo Reply packet are constructed by:
  775. * 14 bytes MAC header
  776. * 20 bytes IP header
  777. * 16 bytes ICMP header
  778. * 48 bytes data (default value of the ping command)
  779. So the IpExtInOctets and IpExtOutOctets are 20+16+48=84.
  780. tcp 3-way handshake
  781. -------------------
  782. On server side, we run::
  783. nstatuser@nstat-b:~$ nc -lknv 0.0.0.0 9000
  784. Listening on [0.0.0.0] (family 0, port 9000)
  785. On client side, we run::
  786. nstatuser@nstat-a:~$ nc -nv 192.168.122.251 9000
  787. Connection to 192.168.122.251 9000 port [tcp/*] succeeded!
  788. The server listened on tcp 9000 port, the client connected to it, they
  789. completed the 3-way handshake.
  790. On server side, we can find below nstat output::
  791. nstatuser@nstat-b:~$ nstat | grep -i tcp
  792. TcpPassiveOpens 1 0.0
  793. TcpInSegs 2 0.0
  794. TcpOutSegs 1 0.0
  795. TcpExtTCPPureAcks 1 0.0
  796. On client side, we can find below nstat output::
  797. nstatuser@nstat-a:~$ nstat | grep -i tcp
  798. TcpActiveOpens 1 0.0
  799. TcpInSegs 1 0.0
  800. TcpOutSegs 2 0.0
  801. When the server received the first SYN, it replied a SYN+ACK, and came into
  802. SYN-RCVD state, so TcpPassiveOpens increased 1. The server received
  803. SYN, sent SYN+ACK, received ACK, so server sent 1 packet, received 2
  804. packets, TcpInSegs increased 2, TcpOutSegs increased 1. The last ACK
  805. of the 3-way handshake is a pure ACK without data, so
  806. TcpExtTCPPureAcks increased 1.
  807. When the client sent SYN, the client came into the SYN-SENT state, so
  808. TcpActiveOpens increased 1, the client sent SYN, received SYN+ACK, sent
  809. ACK, so client sent 2 packets, received 1 packet, TcpInSegs increased
  810. 1, TcpOutSegs increased 2.
  811. TCP normal traffic
  812. ------------------
  813. Run nc on server::
  814. nstatuser@nstat-b:~$ nc -lkv 0.0.0.0 9000
  815. Listening on [0.0.0.0] (family 0, port 9000)
  816. Run nc on client::
  817. nstatuser@nstat-a:~$ nc -v nstat-b 9000
  818. Connection to nstat-b 9000 port [tcp/*] succeeded!
  819. Input a string in the nc client ('hello' in our example)::
  820. nstatuser@nstat-a:~$ nc -v nstat-b 9000
  821. Connection to nstat-b 9000 port [tcp/*] succeeded!
  822. hello
  823. The client side nstat output::
  824. nstatuser@nstat-a:~$ nstat
  825. #kernel
  826. IpInReceives 1 0.0
  827. IpInDelivers 1 0.0
  828. IpOutRequests 1 0.0
  829. TcpInSegs 1 0.0
  830. TcpOutSegs 1 0.0
  831. TcpExtTCPPureAcks 1 0.0
  832. TcpExtTCPOrigDataSent 1 0.0
  833. IpExtInOctets 52 0.0
  834. IpExtOutOctets 58 0.0
  835. IpExtInNoECTPkts 1 0.0
  836. The server side nstat output::
  837. nstatuser@nstat-b:~$ nstat
  838. #kernel
  839. IpInReceives 1 0.0
  840. IpInDelivers 1 0.0
  841. IpOutRequests 1 0.0
  842. TcpInSegs 1 0.0
  843. TcpOutSegs 1 0.0
  844. IpExtInOctets 58 0.0
  845. IpExtOutOctets 52 0.0
  846. IpExtInNoECTPkts 1 0.0
  847. Input a string in nc client side again ('world' in our example)::
  848. nstatuser@nstat-a:~$ nc -v nstat-b 9000
  849. Connection to nstat-b 9000 port [tcp/*] succeeded!
  850. hello
  851. world
  852. Client side nstat output::
  853. nstatuser@nstat-a:~$ nstat
  854. #kernel
  855. IpInReceives 1 0.0
  856. IpInDelivers 1 0.0
  857. IpOutRequests 1 0.0
  858. TcpInSegs 1 0.0
  859. TcpOutSegs 1 0.0
  860. TcpExtTCPHPAcks 1 0.0
  861. TcpExtTCPOrigDataSent 1 0.0
  862. IpExtInOctets 52 0.0
  863. IpExtOutOctets 58 0.0
  864. IpExtInNoECTPkts 1 0.0
  865. Server side nstat output::
  866. nstatuser@nstat-b:~$ nstat
  867. #kernel
  868. IpInReceives 1 0.0
  869. IpInDelivers 1 0.0
  870. IpOutRequests 1 0.0
  871. TcpInSegs 1 0.0
  872. TcpOutSegs 1 0.0
  873. TcpExtTCPHPHits 1 0.0
  874. IpExtInOctets 58 0.0
  875. IpExtOutOctets 52 0.0
  876. IpExtInNoECTPkts 1 0.0
  877. Compare the first client-side nstat and the second client-side nstat,
  878. we could find one difference: the first one had a 'TcpExtTCPPureAcks',
  879. but the second one had a 'TcpExtTCPHPAcks'. The first server-side
  880. nstat and the second server-side nstat had a difference too: the
  881. second server-side nstat had a TcpExtTCPHPHits, but the first
  882. server-side nstat didn't have it. The network traffic patterns were
  883. exactly the same: the client sent a packet to the server, the server
  884. replied an ACK. But kernel handled them in different ways. When the
  885. TCP window scale option is not used, kernel will try to enable fast
  886. path immediately when the connection comes into the established state,
  887. but if the TCP window scale option is used, kernel will disable the
  888. fast path at first, and try to enable it after kernel receives
  889. packets. We could use the 'ss' command to verify whether the window
  890. scale option is used. e.g. run below command on either server or
  891. client::
  892. nstatuser@nstat-a:~$ ss -o state established -i '( dport = :9000 or sport = :9000 )
  893. Netid Recv-Q Send-Q Local Address:Port Peer Address:Port
  894. tcp 0 0 192.168.122.250:40654 192.168.122.251:9000
  895. ts sack cubic wscale:7,7 rto:204 rtt:0.98/0.49 mss:1448 pmtu:1500 rcvmss:536 advmss:1448 cwnd:10 bytes_acked:1 segs_out:2 segs_in:1 send 118.2Mbps lastsnd:46572 lastrcv:46572 lastack:46572 pacing_rate 236.4Mbps rcv_space:29200 rcv_ssthresh:29200 minrtt:0.98
  896. The 'wscale:7,7' means both server and client set the window scale
  897. option to 7. Now we could explain the nstat output in our test:
  898. In the first nstat output of client side, the client sent a packet, server
  899. reply an ACK, when kernel handled this ACK, the fast path was not
  900. enabled, so the ACK was counted into 'TcpExtTCPPureAcks'.
  901. In the second nstat output of client side, the client sent a packet again,
  902. and received another ACK from the server, in this time, the fast path is
  903. enabled, and the ACK was qualified for fast path, so it was handled by
  904. the fast path, so this ACK was counted into TcpExtTCPHPAcks.
  905. In the first nstat output of server side, fast path was not enabled,
  906. so there was no 'TcpExtTCPHPHits'.
  907. In the second nstat output of server side, the fast path was enabled,
  908. and the packet received from client qualified for fast path, so it
  909. was counted into 'TcpExtTCPHPHits'.
  910. TcpExtTCPAbortOnClose
  911. ---------------------
  912. On the server side, we run below python script::
  913. import socket
  914. import time
  915. port = 9000
  916. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  917. s.bind(('0.0.0.0', port))
  918. s.listen(1)
  919. sock, addr = s.accept()
  920. while True:
  921. time.sleep(9999999)
  922. This python script listen on 9000 port, but doesn't read anything from
  923. the connection.
  924. On the client side, we send the string "hello" by nc::
  925. nstatuser@nstat-a:~$ echo "hello" | nc nstat-b 9000
  926. Then, we come back to the server side, the server has received the "hello"
  927. packet, and the TCP layer has acked this packet, but the application didn't
  928. read it yet. We type Ctrl-C to terminate the server script. Then we
  929. could find TcpExtTCPAbortOnClose increased 1 on the server side::
  930. nstatuser@nstat-b:~$ nstat | grep -i abort
  931. TcpExtTCPAbortOnClose 1 0.0
  932. If we run tcpdump on the server side, we could find the server sent a
  933. RST after we type Ctrl-C.
  934. TcpExtTCPAbortOnMemory and TcpExtTCPAbortOnTimeout
  935. ---------------------------------------------------
  936. Below is an example which let the orphan socket count be higher than
  937. net.ipv4.tcp_max_orphans.
  938. Change tcp_max_orphans to a smaller value on client::
  939. sudo bash -c "echo 10 > /proc/sys/net/ipv4/tcp_max_orphans"
  940. Client code (create 64 connection to server)::
  941. nstatuser@nstat-a:~$ cat client_orphan.py
  942. import socket
  943. import time
  944. server = 'nstat-b' # server address
  945. port = 9000
  946. count = 64
  947. connection_list = []
  948. for i in range(64):
  949. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  950. s.connect((server, port))
  951. connection_list.append(s)
  952. print("connection_count: %d" % len(connection_list))
  953. while True:
  954. time.sleep(99999)
  955. Server code (accept 64 connection from client)::
  956. nstatuser@nstat-b:~$ cat server_orphan.py
  957. import socket
  958. import time
  959. port = 9000
  960. count = 64
  961. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  962. s.bind(('0.0.0.0', port))
  963. s.listen(count)
  964. connection_list = []
  965. while True:
  966. sock, addr = s.accept()
  967. connection_list.append((sock, addr))
  968. print("connection_count: %d" % len(connection_list))
  969. Run the python scripts on server and client.
  970. On server::
  971. python3 server_orphan.py
  972. On client::
  973. python3 client_orphan.py
  974. Run iptables on server::
  975. sudo iptables -A INPUT -i ens3 -p tcp --destination-port 9000 -j DROP
  976. Type Ctrl-C on client, stop client_orphan.py.
  977. Check TcpExtTCPAbortOnMemory on client::
  978. nstatuser@nstat-a:~$ nstat | grep -i abort
  979. TcpExtTCPAbortOnMemory 54 0.0
  980. Check orphaned socket count on client::
  981. nstatuser@nstat-a:~$ ss -s
  982. Total: 131 (kernel 0)
  983. TCP: 14 (estab 1, closed 0, orphaned 10, synrecv 0, timewait 0/0), ports 0
  984. Transport Total IP IPv6
  985. * 0 - -
  986. RAW 1 0 1
  987. UDP 1 1 0
  988. TCP 14 13 1
  989. INET 16 14 2
  990. FRAG 0 0 0
  991. The explanation of the test: after run server_orphan.py and
  992. client_orphan.py, we set up 64 connections between server and
  993. client. Run the iptables command, the server will drop all packets from
  994. the client, type Ctrl-C on client_orphan.py, the system of the client
  995. would try to close these connections, and before they are closed
  996. gracefully, these connections became orphan sockets. As the iptables
  997. of the server blocked packets from the client, the server won't receive fin
  998. from the client, so all connection on clients would be stuck on FIN_WAIT_1
  999. stage, so they will keep as orphan sockets until timeout. We have echo
  1000. 10 to /proc/sys/net/ipv4/tcp_max_orphans, so the client system would
  1001. only keep 10 orphan sockets, for all other orphan sockets, the client
  1002. system sent RST for them and delete them. We have 64 connections, so
  1003. the 'ss -s' command shows the system has 10 orphan sockets, and the
  1004. value of TcpExtTCPAbortOnMemory was 54.
  1005. An additional explanation about orphan socket count: You could find the
  1006. exactly orphan socket count by the 'ss -s' command, but when kernel
  1007. decide whither increases TcpExtTCPAbortOnMemory and sends RST, kernel
  1008. doesn't always check the exactly orphan socket count. For increasing
  1009. performance, kernel checks an approximate count firstly, if the
  1010. approximate count is more than tcp_max_orphans, kernel checks the
  1011. exact count again. So if the approximate count is less than
  1012. tcp_max_orphans, but exactly count is more than tcp_max_orphans, you
  1013. would find TcpExtTCPAbortOnMemory is not increased at all. If
  1014. tcp_max_orphans is large enough, it won't occur, but if you decrease
  1015. tcp_max_orphans to a small value like our test, you might find this
  1016. issue. So in our test, the client set up 64 connections although the
  1017. tcp_max_orphans is 10. If the client only set up 11 connections, we
  1018. can't find the change of TcpExtTCPAbortOnMemory.
  1019. Continue the previous test, we wait for several minutes. Because of the
  1020. iptables on the server blocked the traffic, the server wouldn't receive
  1021. fin, and all the client's orphan sockets would timeout on the
  1022. FIN_WAIT_1 state finally. So we wait for a few minutes, we could find
  1023. 10 timeout on the client::
  1024. nstatuser@nstat-a:~$ nstat | grep -i abort
  1025. TcpExtTCPAbortOnTimeout 10 0.0
  1026. TcpExtTCPAbortOnLinger
  1027. ----------------------
  1028. The server side code::
  1029. nstatuser@nstat-b:~$ cat server_linger.py
  1030. import socket
  1031. import time
  1032. port = 9000
  1033. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  1034. s.bind(('0.0.0.0', port))
  1035. s.listen(1)
  1036. sock, addr = s.accept()
  1037. while True:
  1038. time.sleep(9999999)
  1039. The client side code::
  1040. nstatuser@nstat-a:~$ cat client_linger.py
  1041. import socket
  1042. import struct
  1043. server = 'nstat-b' # server address
  1044. port = 9000
  1045. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  1046. s.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER, struct.pack('ii', 1, 10))
  1047. s.setsockopt(socket.SOL_TCP, socket.TCP_LINGER2, struct.pack('i', -1))
  1048. s.connect((server, port))
  1049. s.close()
  1050. Run server_linger.py on server::
  1051. nstatuser@nstat-b:~$ python3 server_linger.py
  1052. Run client_linger.py on client::
  1053. nstatuser@nstat-a:~$ python3 client_linger.py
  1054. After run client_linger.py, check the output of nstat::
  1055. nstatuser@nstat-a:~$ nstat | grep -i abort
  1056. TcpExtTCPAbortOnLinger 1 0.0
  1057. TcpExtTCPRcvCoalesce
  1058. --------------------
  1059. On the server, we run a program which listen on TCP port 9000, but
  1060. doesn't read any data::
  1061. import socket
  1062. import time
  1063. port = 9000
  1064. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  1065. s.bind(('0.0.0.0', port))
  1066. s.listen(1)
  1067. sock, addr = s.accept()
  1068. while True:
  1069. time.sleep(9999999)
  1070. Save the above code as server_coalesce.py, and run::
  1071. python3 server_coalesce.py
  1072. On the client, save below code as client_coalesce.py::
  1073. import socket
  1074. server = 'nstat-b'
  1075. port = 9000
  1076. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  1077. s.connect((server, port))
  1078. Run::
  1079. nstatuser@nstat-a:~$ python3 -i client_coalesce.py
  1080. We use '-i' to come into the interactive mode, then a packet::
  1081. >>> s.send(b'foo')
  1082. 3
  1083. Send a packet again::
  1084. >>> s.send(b'bar')
  1085. 3
  1086. On the server, run nstat::
  1087. ubuntu@nstat-b:~$ nstat
  1088. #kernel
  1089. IpInReceives 2 0.0
  1090. IpInDelivers 2 0.0
  1091. IpOutRequests 2 0.0
  1092. TcpInSegs 2 0.0
  1093. TcpOutSegs 2 0.0
  1094. TcpExtTCPRcvCoalesce 1 0.0
  1095. IpExtInOctets 110 0.0
  1096. IpExtOutOctets 104 0.0
  1097. IpExtInNoECTPkts 2 0.0
  1098. The client sent two packets, server didn't read any data. When
  1099. the second packet arrived at server, the first packet was still in
  1100. the receiving queue. So the TCP layer merged the two packets, and we
  1101. could find the TcpExtTCPRcvCoalesce increased 1.
  1102. TcpExtListenOverflows and TcpExtListenDrops
  1103. -------------------------------------------
  1104. On server, run the nc command, listen on port 9000::
  1105. nstatuser@nstat-b:~$ nc -lkv 0.0.0.0 9000
  1106. Listening on [0.0.0.0] (family 0, port 9000)
  1107. On client, run 3 nc commands in different terminals::
  1108. nstatuser@nstat-a:~$ nc -v nstat-b 9000
  1109. Connection to nstat-b 9000 port [tcp/*] succeeded!
  1110. The nc command only accepts 1 connection, and the accept queue length
  1111. is 1. On current linux implementation, set queue length to n means the
  1112. actual queue length is n+1. Now we create 3 connections, 1 is accepted
  1113. by nc, 2 in accepted queue, so the accept queue is full.
  1114. Before running the 4th nc, we clean the nstat history on the server::
  1115. nstatuser@nstat-b:~$ nstat -n
  1116. Run the 4th nc on the client::
  1117. nstatuser@nstat-a:~$ nc -v nstat-b 9000
  1118. If the nc server is running on kernel 4.10 or higher version, you
  1119. won't see the "Connection to ... succeeded!" string, because kernel
  1120. will drop the SYN if the accept queue is full. If the nc client is running
  1121. on an old kernel, you would see that the connection is succeeded,
  1122. because kernel would complete the 3 way handshake and keep the socket
  1123. on half open queue. I did the test on kernel 4.15. Below is the nstat
  1124. on the server::
  1125. nstatuser@nstat-b:~$ nstat
  1126. #kernel
  1127. IpInReceives 4 0.0
  1128. IpInDelivers 4 0.0
  1129. TcpInSegs 4 0.0
  1130. TcpExtListenOverflows 4 0.0
  1131. TcpExtListenDrops 4 0.0
  1132. IpExtInOctets 240 0.0
  1133. IpExtInNoECTPkts 4 0.0
  1134. Both TcpExtListenOverflows and TcpExtListenDrops were 4. If the time
  1135. between the 4th nc and the nstat was longer, the value of
  1136. TcpExtListenOverflows and TcpExtListenDrops would be larger, because
  1137. the SYN of the 4th nc was dropped, the client was retrying.
  1138. IpInAddrErrors, IpExtInNoRoutes and IpOutNoRoutes
  1139. -------------------------------------------------
  1140. server A IP address: 192.168.122.250
  1141. server B IP address: 192.168.122.251
  1142. Prepare on server A, add a route to server B::
  1143. $ sudo ip route add 8.8.8.8/32 via 192.168.122.251
  1144. Prepare on server B, disable send_redirects for all interfaces::
  1145. $ sudo sysctl -w net.ipv4.conf.all.send_redirects=0
  1146. $ sudo sysctl -w net.ipv4.conf.ens3.send_redirects=0
  1147. $ sudo sysctl -w net.ipv4.conf.lo.send_redirects=0
  1148. $ sudo sysctl -w net.ipv4.conf.default.send_redirects=0
  1149. We want to let sever A send a packet to 8.8.8.8, and route the packet
  1150. to server B. When server B receives such packet, it might send a ICMP
  1151. Redirect message to server A, set send_redirects to 0 will disable
  1152. this behavior.
  1153. First, generate InAddrErrors. On server B, we disable IP forwarding::
  1154. $ sudo sysctl -w net.ipv4.conf.all.forwarding=0
  1155. On server A, we send packets to 8.8.8.8::
  1156. $ nc -v 8.8.8.8 53
  1157. On server B, we check the output of nstat::
  1158. $ nstat
  1159. #kernel
  1160. IpInReceives 3 0.0
  1161. IpInAddrErrors 3 0.0
  1162. IpExtInOctets 180 0.0
  1163. IpExtInNoECTPkts 3 0.0
  1164. As we have let server A route 8.8.8.8 to server B, and we disabled IP
  1165. forwarding on server B, Server A sent packets to server B, then server B
  1166. dropped packets and increased IpInAddrErrors. As the nc command would
  1167. re-send the SYN packet if it didn't receive a SYN+ACK, we could find
  1168. multiple IpInAddrErrors.
  1169. Second, generate IpExtInNoRoutes. On server B, we enable IP
  1170. forwarding::
  1171. $ sudo sysctl -w net.ipv4.conf.all.forwarding=1
  1172. Check the route table of server B and remove the default route::
  1173. $ ip route show
  1174. default via 192.168.122.1 dev ens3 proto static
  1175. 192.168.122.0/24 dev ens3 proto kernel scope link src 192.168.122.251
  1176. $ sudo ip route delete default via 192.168.122.1 dev ens3 proto static
  1177. On server A, we contact 8.8.8.8 again::
  1178. $ nc -v 8.8.8.8 53
  1179. nc: connect to 8.8.8.8 port 53 (tcp) failed: Network is unreachable
  1180. On server B, run nstat::
  1181. $ nstat
  1182. #kernel
  1183. IpInReceives 1 0.0
  1184. IpOutRequests 1 0.0
  1185. IcmpOutMsgs 1 0.0
  1186. IcmpOutDestUnreachs 1 0.0
  1187. IcmpMsgOutType3 1 0.0
  1188. IpExtInNoRoutes 1 0.0
  1189. IpExtInOctets 60 0.0
  1190. IpExtOutOctets 88 0.0
  1191. IpExtInNoECTPkts 1 0.0
  1192. We enabled IP forwarding on server B, when server B received a packet
  1193. which destination IP address is 8.8.8.8, server B will try to forward
  1194. this packet. We have deleted the default route, there was no route for
  1195. 8.8.8.8, so server B increase IpExtInNoRoutes and sent the "ICMP
  1196. Destination Unreachable" message to server A.
  1197. Third, generate IpOutNoRoutes. Run ping command on server B::
  1198. $ ping -c 1 8.8.8.8
  1199. connect: Network is unreachable
  1200. Run nstat on server B::
  1201. $ nstat
  1202. #kernel
  1203. IpOutNoRoutes 1 0.0
  1204. We have deleted the default route on server B. Server B couldn't find
  1205. a route for the 8.8.8.8 IP address, so server B increased
  1206. IpOutNoRoutes.
  1207. TcpExtTCPACKSkippedSynRecv
  1208. --------------------------
  1209. In this test, we send 3 same SYN packets from client to server. The
  1210. first SYN will let server create a socket, set it to Syn-Recv status,
  1211. and reply a SYN/ACK. The second SYN will let server reply the SYN/ACK
  1212. again, and record the reply time (the duplicate ACK reply time). The
  1213. third SYN will let server check the previous duplicate ACK reply time,
  1214. and decide to skip the duplicate ACK, then increase the
  1215. TcpExtTCPACKSkippedSynRecv counter.
  1216. Run tcpdump to capture a SYN packet::
  1217. nstatuser@nstat-a:~$ sudo tcpdump -c 1 -w /tmp/syn.pcap port 9000
  1218. tcpdump: listening on ens3, link-type EN10MB (Ethernet), capture size 262144 bytes
  1219. Open another terminal, run nc command::
  1220. nstatuser@nstat-a:~$ nc nstat-b 9000
  1221. As the nstat-b didn't listen on port 9000, it should reply a RST, and
  1222. the nc command exited immediately. It was enough for the tcpdump
  1223. command to capture a SYN packet. A linux server might use hardware
  1224. offload for the TCP checksum, so the checksum in the /tmp/syn.pcap
  1225. might be not correct. We call tcprewrite to fix it::
  1226. nstatuser@nstat-a:~$ tcprewrite --infile=/tmp/syn.pcap --outfile=/tmp/syn_fixcsum.pcap --fixcsum
  1227. On nstat-b, we run nc to listen on port 9000::
  1228. nstatuser@nstat-b:~$ nc -lkv 9000
  1229. Listening on [0.0.0.0] (family 0, port 9000)
  1230. On nstat-a, we blocked the packet from port 9000, or nstat-a would send
  1231. RST to nstat-b::
  1232. nstatuser@nstat-a:~$ sudo iptables -A INPUT -p tcp --sport 9000 -j DROP
  1233. Send 3 SYN repeatedly to nstat-b::
  1234. nstatuser@nstat-a:~$ for i in {1..3}; do sudo tcpreplay -i ens3 /tmp/syn_fixcsum.pcap; done
  1235. Check snmp counter on nstat-b::
  1236. nstatuser@nstat-b:~$ nstat | grep -i skip
  1237. TcpExtTCPACKSkippedSynRecv 1 0.0
  1238. As we expected, TcpExtTCPACKSkippedSynRecv is 1.
  1239. TcpExtTCPACKSkippedPAWS
  1240. -----------------------
  1241. To trigger PAWS, we could send an old SYN.
  1242. On nstat-b, let nc listen on port 9000::
  1243. nstatuser@nstat-b:~$ nc -lkv 9000
  1244. Listening on [0.0.0.0] (family 0, port 9000)
  1245. On nstat-a, run tcpdump to capture a SYN::
  1246. nstatuser@nstat-a:~$ sudo tcpdump -w /tmp/paws_pre.pcap -c 1 port 9000
  1247. tcpdump: listening on ens3, link-type EN10MB (Ethernet), capture size 262144 bytes
  1248. On nstat-a, run nc as a client to connect nstat-b::
  1249. nstatuser@nstat-a:~$ nc -v nstat-b 9000
  1250. Connection to nstat-b 9000 port [tcp/*] succeeded!
  1251. Now the tcpdump has captured the SYN and exit. We should fix the
  1252. checksum::
  1253. nstatuser@nstat-a:~$ tcprewrite --infile /tmp/paws_pre.pcap --outfile /tmp/paws.pcap --fixcsum
  1254. Send the SYN packet twice::
  1255. nstatuser@nstat-a:~$ for i in {1..2}; do sudo tcpreplay -i ens3 /tmp/paws.pcap; done
  1256. On nstat-b, check the snmp counter::
  1257. nstatuser@nstat-b:~$ nstat | grep -i skip
  1258. TcpExtTCPACKSkippedPAWS 1 0.0
  1259. We sent two SYN via tcpreplay, both of them would let PAWS check
  1260. failed, the nstat-b replied an ACK for the first SYN, skipped the ACK
  1261. for the second SYN, and updated TcpExtTCPACKSkippedPAWS.
  1262. TcpExtTCPACKSkippedSeq
  1263. ----------------------
  1264. To trigger TcpExtTCPACKSkippedSeq, we send packets which have valid
  1265. timestamp (to pass PAWS check) but the sequence number is out of
  1266. window. The linux TCP stack would avoid to skip if the packet has
  1267. data, so we need a pure ACK packet. To generate such a packet, we
  1268. could create two sockets: one on port 9000, another on port 9001. Then
  1269. we capture an ACK on port 9001, change the source/destination port
  1270. numbers to match the port 9000 socket. Then we could trigger
  1271. TcpExtTCPACKSkippedSeq via this packet.
  1272. On nstat-b, open two terminals, run two nc commands to listen on both
  1273. port 9000 and port 9001::
  1274. nstatuser@nstat-b:~$ nc -lkv 9000
  1275. Listening on [0.0.0.0] (family 0, port 9000)
  1276. nstatuser@nstat-b:~$ nc -lkv 9001
  1277. Listening on [0.0.0.0] (family 0, port 9001)
  1278. On nstat-a, run two nc clients::
  1279. nstatuser@nstat-a:~$ nc -v nstat-b 9000
  1280. Connection to nstat-b 9000 port [tcp/*] succeeded!
  1281. nstatuser@nstat-a:~$ nc -v nstat-b 9001
  1282. Connection to nstat-b 9001 port [tcp/*] succeeded!
  1283. On nstat-a, run tcpdump to capture an ACK::
  1284. nstatuser@nstat-a:~$ sudo tcpdump -w /tmp/seq_pre.pcap -c 1 dst port 9001
  1285. tcpdump: listening on ens3, link-type EN10MB (Ethernet), capture size 262144 bytes
  1286. On nstat-b, send a packet via the port 9001 socket. E.g. we sent a
  1287. string 'foo' in our example::
  1288. nstatuser@nstat-b:~$ nc -lkv 9001
  1289. Listening on [0.0.0.0] (family 0, port 9001)
  1290. Connection from nstat-a 42132 received!
  1291. foo
  1292. On nstat-a, the tcpdump should have captured the ACK. We should check
  1293. the source port numbers of the two nc clients::
  1294. nstatuser@nstat-a:~$ ss -ta '( dport = :9000 || dport = :9001 )' | tee
  1295. State Recv-Q Send-Q Local Address:Port Peer Address:Port
  1296. ESTAB 0 0 192.168.122.250:50208 192.168.122.251:9000
  1297. ESTAB 0 0 192.168.122.250:42132 192.168.122.251:9001
  1298. Run tcprewrite, change port 9001 to port 9000, change port 42132 to
  1299. port 50208::
  1300. nstatuser@nstat-a:~$ tcprewrite --infile /tmp/seq_pre.pcap --outfile /tmp/seq.pcap -r 9001:9000 -r 42132:50208 --fixcsum
  1301. Now the /tmp/seq.pcap is the packet we need. Send it to nstat-b::
  1302. nstatuser@nstat-a:~$ for i in {1..2}; do sudo tcpreplay -i ens3 /tmp/seq.pcap; done
  1303. Check TcpExtTCPACKSkippedSeq on nstat-b::
  1304. nstatuser@nstat-b:~$ nstat | grep -i skip
  1305. TcpExtTCPACKSkippedSeq 1 0.0