]> arthur.barton.de Git - netdata.git/blob - src/proc_net_netstat.c
Merge pull request #975 from paulfantom/master
[netdata.git] / src / proc_net_netstat.c
1 #include "common.h"
2
3
4 struct netstat_columns {
5     char *name;
6     uint32_t hash;
7     unsigned long long value;
8     int multiplier;     // not needed everywhere
9     char *label;        // not needed everywhere
10 };
11
12 static struct netstat_columns tcpext_data[] = {
13     { "SyncookiesSent", 0, 0, 1, NULL },
14     { "SyncookiesRecv", 0, 0, 1, NULL },
15     { "SyncookiesFailed", 0, 0, 1, NULL },
16     { "EmbryonicRsts", 0, 0, 1, NULL },
17     { "PruneCalled", 0, 0, 1, NULL },
18     { "RcvPruned", 0, 0, 1, NULL },
19     { "OfoPruned", 0, 0, 1, NULL },
20     { "OutOfWindowIcmps", 0, 0, 1, NULL },
21     { "LockDroppedIcmps", 0, 0, 1, NULL },
22     { "ArpFilter", 0, 0, 1, NULL },
23     { "TW", 0, 0, 1, NULL },
24     { "TWRecycled", 0, 0, 1, NULL },
25     { "TWKilled", 0, 0, 1, NULL },
26     { "PAWSPassive", 0, 0, 1, NULL },
27     { "PAWSActive", 0, 0, 1, NULL },
28     { "PAWSEstab", 0, 0, 1, NULL },
29     { "DelayedACKs", 0, 0, 1, NULL },
30     { "DelayedACKLocked", 0, 0, 1, NULL },
31     { "DelayedACKLost", 0, 0, 1, NULL },
32     { "ListenOverflows", 0, 0, 1, NULL },
33     { "ListenDrops", 0, 0, 1, NULL },
34     { "TCPPrequeued", 0, 0, 1, NULL },
35     { "TCPDirectCopyFromBacklog", 0, 0, 1, NULL },
36     { "TCPDirectCopyFromPrequeue", 0, 0, 1, NULL },
37     { "TCPPrequeueDropped", 0, 0, 1, NULL },
38     { "TCPHPHits", 0, 0, 1, NULL },
39     { "TCPHPHitsToUser", 0, 0, 1, NULL },
40     { "TCPPureAcks", 0, 0, 1, NULL },
41     { "TCPHPAcks", 0, 0, 1, NULL },
42     { "TCPRenoRecovery", 0, 0, 1, NULL },
43     { "TCPSackRecovery", 0, 0, 1, NULL },
44     { "TCPSACKReneging", 0, 0, 1, NULL },
45     { "TCPFACKReorder", 0, 0, 1, NULL },
46     { "TCPSACKReorder", 0, 0, 1, NULL },
47     { "TCPRenoReorder", 0, 0, 1, NULL },
48     { "TCPTSReorder", 0, 0, 1, NULL },
49     { "TCPFullUndo", 0, 0, 1, NULL },
50     { "TCPPartialUndo", 0, 0, 1, NULL },
51     { "TCPDSACKUndo", 0, 0, 1, NULL },
52     { "TCPLossUndo", 0, 0, 1, NULL },
53     { "TCPLostRetransmit", 0, 0, 1, NULL },
54     { "TCPRenoFailures", 0, 0, 1, NULL },
55     { "TCPSackFailures", 0, 0, 1, NULL },
56     { "TCPLossFailures", 0, 0, 1, NULL },
57     { "TCPFastRetrans", 0, 0, 1, NULL },
58     { "TCPForwardRetrans", 0, 0, 1, NULL },
59     { "TCPSlowStartRetrans", 0, 0, 1, NULL },
60     { "TCPTimeouts", 0, 0, 1, NULL },
61     { "TCPLossProbes", 0, 0, 1, NULL },
62     { "TCPLossProbeRecovery", 0, 0, 1, NULL },
63     { "TCPRenoRecoveryFail", 0, 0, 1, NULL },
64     { "TCPSackRecoveryFail", 0, 0, 1, NULL },
65     { "TCPSchedulerFailed", 0, 0, 1, NULL },
66     { "TCPRcvCollapsed", 0, 0, 1, NULL },
67     { "TCPDSACKOldSent", 0, 0, 1, NULL },
68     { "TCPDSACKOfoSent", 0, 0, 1, NULL },
69     { "TCPDSACKRecv", 0, 0, 1, NULL },
70     { "TCPDSACKOfoRecv", 0, 0, 1, NULL },
71     { "TCPAbortOnData", 0, 0, 1, NULL },
72     { "TCPAbortOnClose", 0, 0, 1, NULL },
73     { "TCPAbortOnMemory", 0, 0, 1, NULL },
74     { "TCPAbortOnTimeout", 0, 0, 1, NULL },
75     { "TCPAbortOnLinger", 0, 0, 1, NULL },
76     { "TCPAbortFailed", 0, 0, 1, NULL },
77     { "TCPMemoryPressures", 0, 0, 1, NULL },
78     { "TCPSACKDiscard", 0, 0, 1, NULL },
79     { "TCPDSACKIgnoredOld", 0, 0, 1, NULL },
80     { "TCPDSACKIgnoredNoUndo", 0, 0, 1, NULL },
81     { "TCPSpuriousRTOs", 0, 0, 1, NULL },
82     { "TCPMD5NotFound", 0, 0, 1, NULL },
83     { "TCPMD5Unexpected", 0, 0, 1, NULL },
84     { "TCPSackShifted", 0, 0, 1, NULL },
85     { "TCPSackMerged", 0, 0, 1, NULL },
86     { "TCPSackShiftFallback", 0, 0, 1, NULL },
87     { "TCPBacklogDrop", 0, 0, 1, NULL },
88     { "TCPMinTTLDrop", 0, 0, 1, NULL },
89     { "TCPDeferAcceptDrop", 0, 0, 1, NULL },
90     { "IPReversePathFilter", 0, 0, 1, NULL },
91     { "TCPTimeWaitOverflow", 0, 0, 1, NULL },
92     { "TCPReqQFullDoCookies", 0, 0, 1, NULL },
93     { "TCPReqQFullDrop", 0, 0, 1, NULL },
94     { "TCPRetransFail", 0, 0, 1, NULL },
95     { "TCPRcvCoalesce", 0, 0, 1, NULL },
96     { "TCPOFOQueue", 0, 0, 1, NULL },
97     { "TCPOFODrop", 0, 0, 1, NULL },
98     { "TCPOFOMerge", 0, 0, 1, NULL },
99     { "TCPChallengeACK", 0, 0, 1, NULL },
100     { "TCPSYNChallenge", 0, 0, 1, NULL },
101     { "TCPFastOpenActive", 0, 0, 1, NULL },
102     { "TCPFastOpenActiveFail", 0, 0, 1, NULL },
103     { "TCPFastOpenPassive", 0, 0, 1, NULL },
104     { "TCPFastOpenPassiveFail", 0, 0, 1, NULL },
105     { "TCPFastOpenListenOverflow", 0, 0, 1, NULL },
106     { "TCPFastOpenCookieReqd", 0, 0, 1, NULL },
107     { "TCPSpuriousRtxHostQueues", 0, 0, 1, NULL },
108     { "BusyPollRxPackets", 0, 0, 1, NULL },
109     { "TCPAutoCorking", 0, 0, 1, NULL },
110     { "TCPFromZeroWindowAdv", 0, 0, 1, NULL },
111     { "TCPToZeroWindowAdv", 0, 0, 1, NULL },
112     { "TCPWantZeroWindowAdv", 0, 0, 1, NULL },
113     { "TCPSynRetrans", 0, 0, 1, NULL },
114     { "TCPOrigDataSent", 0, 0, 1, NULL },
115     { "TCPHystartTrainDetect", 0, 0, 1, NULL },
116     { "TCPHystartTrainCwnd", 0, 0, 1, NULL },
117     { "TCPHystartDelayDetect", 0, 0, 1, NULL },
118     { "TCPHystartDelayCwnd", 0, 0, 1, NULL },
119     { "TCPACKSkippedSynRecv", 0, 0, 1, NULL },
120     { "TCPACKSkippedPAWS", 0, 0, 1, NULL },
121     { "TCPACKSkippedSeq", 0, 0, 1, NULL },
122     { "TCPACKSkippedFinWait2", 0, 0, 1, NULL },
123     { "TCPACKSkippedTimeWait", 0, 0, 1, NULL },
124     { "TCPACKSkippedChallenge", 0, 0, 1, NULL },
125     { "TCPWinProbe", 0, 0, 1, NULL },
126     { "TCPKeepAlive", 0, 0, 1, NULL },
127     { "TCPMTUPFail", 0, 0, 1, NULL },
128     { "TCPMTUPSuccess", 0, 0, 1, NULL },
129     { NULL, 0, 0, 0, NULL }
130 };
131
132 static struct netstat_columns ipext_data[] = {
133     { "InNoRoutes", 0, 0, 1, NULL },
134     { "InTruncatedPkts", 0, 0, 1, NULL },
135     { "InMcastPkts", 0, 0, 1, NULL },
136     { "OutMcastPkts", 0, 0, 1, NULL },
137     { "InBcastPkts", 0, 0, 1, NULL },
138     { "OutBcastPkts", 0, 0, 1, NULL },
139     { "InOctets", 0, 0, 1, NULL },
140     { "OutOctets", 0, 0, 1, NULL },
141     { "InMcastOctets", 0, 0, 1, NULL },
142     { "OutMcastOctets", 0, 0, 1, NULL },
143     { "InBcastOctets", 0, 0, 1, NULL },
144     { "OutBcastOctets", 0, 0, 1, NULL },
145     { "InCsumErrors", 0, 0, 1, NULL },
146     { "InNoECTPkts", 0, 0, 1, NULL },
147     { "InECT1Pkts", 0, 0, 1, NULL },
148     { "InECT0Pkts", 0, 0, 1, NULL },
149     { "InCEPkts", 0, 0, 1, NULL },
150     { NULL, 0, 0, 0, NULL }
151 };
152
153 static void hash_array(struct netstat_columns *nc) {
154     int i;
155
156     for(i = 0; nc[i].name ;i++)
157         nc[i].hash = simple_hash(nc[i].name);
158 }
159
160 static unsigned long long *netstat_columns_find(struct netstat_columns *nc, const char *name) {
161     uint32_t i, hash = simple_hash(name);
162
163     for(i = 0; nc[i].name ;i++)
164         if(unlikely(nc[i].hash == hash && !strcmp(nc[i].name, name)))
165             return &nc[i].value;
166
167     fatal("Cannot find key '%s' in /proc/net/netstat internal array.", name);
168 }
169
170 static void parse_line_pair(procfile *ff, struct netstat_columns *nc, uint32_t header_line, uint32_t values_line) {
171     uint32_t hwords = procfile_linewords(ff, header_line);
172     uint32_t vwords = procfile_linewords(ff, values_line);
173     uint32_t w, i;
174
175     if(unlikely(vwords > hwords)) {
176         error("File /proc/net/netstat on header line %u has %u words, but on value line %u has %u words.", header_line, hwords, values_line, vwords);
177         vwords = hwords;
178     }
179
180     for(w = 1; w < vwords ;w++) {
181         char *key = procfile_lineword(ff, header_line, w);
182         uint32_t hash = simple_hash(key);
183
184         for(i = 0 ; nc[i].name ;i++) {
185             if(unlikely(hash == nc[i].hash && !strcmp(key, nc[i].name))) {
186                 nc[i].value = strtoull(procfile_lineword(ff, values_line, w), NULL, 10);
187                 break;
188             }
189         }
190     }
191 }
192
193
194 int do_proc_net_netstat(int update_every, unsigned long long dt) {
195     (void)dt;
196
197     static int do_bandwidth = -1, do_inerrors = -1, do_mcast = -1, do_bcast = -1, do_mcast_p = -1, do_bcast_p = -1, do_ecn = -1, \
198         do_tcpext_reorder = -1, do_tcpext_syscookies = -1, do_tcpext_ofo = -1, do_tcpext_connaborts = -1;
199     static uint32_t hash_ipext = 0, hash_tcpext = 0;
200     static procfile *ff = NULL;
201
202     static unsigned long long *tcpext_TCPRenoReorder = NULL;
203     static unsigned long long *tcpext_TCPFACKReorder = NULL;
204     static unsigned long long *tcpext_TCPSACKReorder = NULL;
205     static unsigned long long *tcpext_TCPTSReorder = NULL;
206
207     static unsigned long long *tcpext_SyncookiesSent = NULL;
208     static unsigned long long *tcpext_SyncookiesRecv = NULL;
209     static unsigned long long *tcpext_SyncookiesFailed = NULL;
210
211     static unsigned long long *tcpext_TCPOFOQueue = NULL; // Number of packets queued in OFO queue
212     static unsigned long long *tcpext_TCPOFODrop = NULL;  // Number of packets meant to be queued in OFO but dropped because socket rcvbuf limit hit.
213     static unsigned long long *tcpext_TCPOFOMerge = NULL; // Number of packets in OFO that were merged with other packets.
214     static unsigned long long *tcpext_OfoPruned = NULL;   // packets dropped from out-of-order queue because of socket buffer overrun
215
216     static unsigned long long *tcpext_TCPAbortOnData = NULL;    // connections reset due to unexpected data
217     static unsigned long long *tcpext_TCPAbortOnClose = NULL;   // connections reset due to early user close
218     static unsigned long long *tcpext_TCPAbortOnMemory = NULL;  // connections aborted due to memory pressure
219     static unsigned long long *tcpext_TCPAbortOnTimeout = NULL; // connections aborted due to timeout
220     static unsigned long long *tcpext_TCPAbortOnLinger = NULL;  // connections aborted after user close in linger timeout
221     static unsigned long long *tcpext_TCPAbortFailed = NULL;    // times unable to send RST due to no memory
222
223 /*
224     // connection rejects
225     static unsigned long long *tcpext_PAWSActive = NULL;  // active connections rejected because of time stamp
226     static unsigned long long *tcpext_PAWSPassive = NULL; // passive connections rejected because of time stamp
227
228     static unsigned long long *tcpext_TCPTimeouts = NULL;
229
230     static unsigned long long *tcpext_TCPDSACKUndo = NULL;
231     static unsigned long long *tcpext_TCPDSACKOldSent = NULL;
232     static unsigned long long *tcpext_TCPDSACKOfoSent = NULL;
233     static unsigned long long *tcpext_TCPDSACKRecv = NULL;
234     static unsigned long long *tcpext_TCPDSACKOfoRecv = NULL;
235     static unsigned long long *tcpext_TCPDSACKIgnoredOld = NULL;
236     static unsigned long long *tcpext_TCPDSACKIgnoredNoUndo = NULL;
237
238
239     static unsigned long long *tcpext_EmbryonicRsts = NULL;
240
241     static unsigned long long *tcpext_PruneCalled = NULL;
242     static unsigned long long *tcpext_RcvPruned = NULL;
243     static unsigned long long *tcpext_OutOfWindowIcmps = NULL;
244     static unsigned long long *tcpext_LockDroppedIcmps = NULL;
245     static unsigned long long *tcpext_ArpFilter = NULL;
246
247     static unsigned long long *tcpext_TW = NULL;
248     static unsigned long long *tcpext_TWRecycled = NULL;
249     static unsigned long long *tcpext_TWKilled = NULL;
250
251     static unsigned long long *tcpext_PAWSEstab = NULL;
252
253     static unsigned long long *tcpext_DelayedACKs = NULL;
254     static unsigned long long *tcpext_DelayedACKLocked = NULL;
255     static unsigned long long *tcpext_DelayedACKLost = NULL;
256
257     static unsigned long long *tcpext_ListenOverflows = NULL;
258     static unsigned long long *tcpext_ListenDrops = NULL;
259
260     static unsigned long long *tcpext_TCPPrequeued = NULL;
261
262     static unsigned long long *tcpext_TCPDirectCopyFromBacklog = NULL;
263     static unsigned long long *tcpext_TCPDirectCopyFromPrequeue = NULL;
264     static unsigned long long *tcpext_TCPPrequeueDropped = NULL;
265
266     static unsigned long long *tcpext_TCPHPHits = NULL;
267     static unsigned long long *tcpext_TCPHPHitsToUser = NULL;
268     static unsigned long long *tcpext_TCPHPAcks = NULL;
269
270     static unsigned long long *tcpext_TCPPureAcks = NULL;
271     static unsigned long long *tcpext_TCPRenoRecovery = NULL;
272
273     static unsigned long long *tcpext_TCPSackRecovery = NULL;
274     static unsigned long long *tcpext_TCPSackFailures = NULL;
275     static unsigned long long *tcpext_TCPSACKReneging = NULL;
276     static unsigned long long *tcpext_TCPSackRecoveryFail = NULL;
277     static unsigned long long *tcpext_TCPSACKDiscard = NULL;
278     static unsigned long long *tcpext_TCPSackShifted = NULL;
279     static unsigned long long *tcpext_TCPSackMerged = NULL;
280     static unsigned long long *tcpext_TCPSackShiftFallback = NULL;
281
282
283     static unsigned long long *tcpext_TCPFullUndo = NULL;
284     static unsigned long long *tcpext_TCPPartialUndo = NULL;
285
286     static unsigned long long *tcpext_TCPLossUndo = NULL;
287     static unsigned long long *tcpext_TCPLostRetransmit = NULL;
288
289     static unsigned long long *tcpext_TCPRenoFailures = NULL;
290
291     static unsigned long long *tcpext_TCPLossFailures = NULL;
292     static unsigned long long *tcpext_TCPFastRetrans = NULL;
293     static unsigned long long *tcpext_TCPForwardRetrans = NULL;
294     static unsigned long long *tcpext_TCPSlowStartRetrans = NULL;
295     static unsigned long long *tcpext_TCPLossProbes = NULL;
296     static unsigned long long *tcpext_TCPLossProbeRecovery = NULL;
297     static unsigned long long *tcpext_TCPRenoRecoveryFail = NULL;
298     static unsigned long long *tcpext_TCPSchedulerFailed = NULL;
299     static unsigned long long *tcpext_TCPRcvCollapsed = NULL;
300
301     static unsigned long long *tcpext_TCPMemoryPressures = NULL;
302     static unsigned long long *tcpext_TCPSpuriousRTOs = NULL;
303     static unsigned long long *tcpext_TCPMD5NotFound = NULL;
304     static unsigned long long *tcpext_TCPMD5Unexpected = NULL;
305
306     static unsigned long long *tcpext_TCPBacklogDrop = NULL;
307     static unsigned long long *tcpext_TCPMinTTLDrop = NULL;
308     static unsigned long long *tcpext_TCPDeferAcceptDrop = NULL;
309     static unsigned long long *tcpext_IPReversePathFilter = NULL;
310     static unsigned long long *tcpext_TCPTimeWaitOverflow = NULL;
311     static unsigned long long *tcpext_TCPReqQFullDoCookies = NULL;
312     static unsigned long long *tcpext_TCPReqQFullDrop = NULL;
313     static unsigned long long *tcpext_TCPRetransFail = NULL;
314     static unsigned long long *tcpext_TCPRcvCoalesce = NULL;
315
316     static unsigned long long *tcpext_TCPChallengeACK = NULL;
317     static unsigned long long *tcpext_TCPSYNChallenge = NULL;
318
319     static unsigned long long *tcpext_TCPFastOpenActive = NULL;
320     static unsigned long long *tcpext_TCPFastOpenActiveFail = NULL;
321     static unsigned long long *tcpext_TCPFastOpenPassive = NULL;
322     static unsigned long long *tcpext_TCPFastOpenPassiveFail = NULL;
323     static unsigned long long *tcpext_TCPFastOpenListenOverflow = NULL;
324     static unsigned long long *tcpext_TCPFastOpenCookieReqd = NULL;
325
326     static unsigned long long *tcpext_TCPSpuriousRtxHostQueues = NULL;
327     static unsigned long long *tcpext_BusyPollRxPackets = NULL;
328     static unsigned long long *tcpext_TCPAutoCorking = NULL;
329     static unsigned long long *tcpext_TCPFromZeroWindowAdv = NULL;
330     static unsigned long long *tcpext_TCPToZeroWindowAdv = NULL;
331     static unsigned long long *tcpext_TCPWantZeroWindowAdv = NULL;
332     static unsigned long long *tcpext_TCPSynRetrans = NULL;
333     static unsigned long long *tcpext_TCPOrigDataSent = NULL;
334
335     static unsigned long long *tcpext_TCPHystartTrainDetect = NULL;
336     static unsigned long long *tcpext_TCPHystartTrainCwnd = NULL;
337     static unsigned long long *tcpext_TCPHystartDelayDetect = NULL;
338     static unsigned long long *tcpext_TCPHystartDelayCwnd = NULL;
339
340     static unsigned long long *tcpext_TCPACKSkippedSynRecv = NULL;
341     static unsigned long long *tcpext_TCPACKSkippedPAWS = NULL;
342     static unsigned long long *tcpext_TCPACKSkippedSeq = NULL;
343     static unsigned long long *tcpext_TCPACKSkippedFinWait2 = NULL;
344     static unsigned long long *tcpext_TCPACKSkippedTimeWait = NULL;
345     static unsigned long long *tcpext_TCPACKSkippedChallenge = NULL;
346
347     static unsigned long long *tcpext_TCPWinProbe = NULL;
348     static unsigned long long *tcpext_TCPKeepAlive = NULL;
349
350     static unsigned long long *tcpext_TCPMTUPFail = NULL;
351     static unsigned long long *tcpext_TCPMTUPSuccess = NULL;
352 */
353
354     static unsigned long long *ipext_InNoRoutes = NULL;
355     static unsigned long long *ipext_InTruncatedPkts = NULL;
356     static unsigned long long *ipext_InMcastPkts = NULL;
357     static unsigned long long *ipext_OutMcastPkts = NULL;
358     static unsigned long long *ipext_InBcastPkts = NULL;
359     static unsigned long long *ipext_OutBcastPkts = NULL;
360     static unsigned long long *ipext_InOctets = NULL;
361     static unsigned long long *ipext_OutOctets = NULL;
362     static unsigned long long *ipext_InMcastOctets = NULL;
363     static unsigned long long *ipext_OutMcastOctets = NULL;
364     static unsigned long long *ipext_InBcastOctets = NULL;
365     static unsigned long long *ipext_OutBcastOctets = NULL;
366     static unsigned long long *ipext_InCsumErrors = NULL;
367     static unsigned long long *ipext_InNoECTPkts = NULL;
368     static unsigned long long *ipext_InECT1Pkts = NULL;
369     static unsigned long long *ipext_InECT0Pkts = NULL;
370     static unsigned long long *ipext_InCEPkts = NULL;
371
372     if(unlikely(do_bandwidth == -1)) {
373         do_bandwidth = config_get_boolean_ondemand("plugin:proc:/proc/net/netstat", "bandwidth", CONFIG_ONDEMAND_ONDEMAND);
374         do_inerrors  = config_get_boolean_ondemand("plugin:proc:/proc/net/netstat", "input errors", CONFIG_ONDEMAND_ONDEMAND);
375         do_mcast     = config_get_boolean_ondemand("plugin:proc:/proc/net/netstat", "multicast bandwidth", CONFIG_ONDEMAND_ONDEMAND);
376         do_bcast     = config_get_boolean_ondemand("plugin:proc:/proc/net/netstat", "broadcast bandwidth", CONFIG_ONDEMAND_ONDEMAND);
377         do_mcast_p   = config_get_boolean_ondemand("plugin:proc:/proc/net/netstat", "multicast packets", CONFIG_ONDEMAND_ONDEMAND);
378         do_bcast_p   = config_get_boolean_ondemand("plugin:proc:/proc/net/netstat", "broadcast packets", CONFIG_ONDEMAND_ONDEMAND);
379         do_ecn       = config_get_boolean_ondemand("plugin:proc:/proc/net/netstat", "ECN packets", CONFIG_ONDEMAND_ONDEMAND);
380
381         do_tcpext_reorder    = config_get_boolean_ondemand("plugin:proc:/proc/net/netstat", "TCP reorders", CONFIG_ONDEMAND_ONDEMAND);
382         do_tcpext_syscookies = config_get_boolean_ondemand("plugin:proc:/proc/net/netstat", "TCP SYN cookies", CONFIG_ONDEMAND_ONDEMAND);
383         do_tcpext_ofo        = config_get_boolean_ondemand("plugin:proc:/proc/net/netstat", "TCP out-of-order queue", CONFIG_ONDEMAND_ONDEMAND);
384         do_tcpext_connaborts = config_get_boolean_ondemand("plugin:proc:/proc/net/netstat", "TCP connection aborts", CONFIG_ONDEMAND_ONDEMAND);
385
386         hash_ipext = simple_hash("IpExt");
387         hash_tcpext = simple_hash("TcpExt");
388
389         hash_array(ipext_data);
390         hash_array(tcpext_data);
391
392         // Reordering
393         tcpext_TCPFACKReorder = netstat_columns_find(tcpext_data, "TCPFACKReorder");
394         tcpext_TCPSACKReorder = netstat_columns_find(tcpext_data, "TCPSACKReorder");
395         tcpext_TCPRenoReorder = netstat_columns_find(tcpext_data, "TCPRenoReorder");
396         tcpext_TCPTSReorder = netstat_columns_find(tcpext_data, "TCPTSReorder");
397
398         // SYN Cookies
399         tcpext_SyncookiesSent = netstat_columns_find(tcpext_data, "SyncookiesSent");
400         tcpext_SyncookiesRecv = netstat_columns_find(tcpext_data, "SyncookiesRecv");
401         tcpext_SyncookiesFailed = netstat_columns_find(tcpext_data, "SyncookiesFailed");
402
403         // Out Of Order Queue
404         // http://www.spinics.net/lists/netdev/msg204696.html
405         tcpext_TCPOFOQueue = netstat_columns_find(tcpext_data, "TCPOFOQueue"); // Number of packets queued in OFO queue
406         tcpext_TCPOFODrop  = netstat_columns_find(tcpext_data, "TCPOFODrop");  // Number of packets meant to be queued in OFO but dropped because socket rcvbuf limit hit.
407         tcpext_TCPOFOMerge = netstat_columns_find(tcpext_data, "TCPOFOMerge"); // Number of packets in OFO that were merged with other packets.
408         tcpext_OfoPruned   = netstat_columns_find(tcpext_data, "OfoPruned");   // packets dropped from out-of-order queue because of socket buffer overrun
409
410         // connection resets
411         // https://github.com/ecki/net-tools/blob/bd8bceaed2311651710331a7f8990c3e31be9840/statistics.c
412         tcpext_TCPAbortOnData    = netstat_columns_find(tcpext_data, "TCPAbortOnData");    // connections reset due to unexpected data
413         tcpext_TCPAbortOnClose   = netstat_columns_find(tcpext_data, "TCPAbortOnClose");   // connections reset due to early user close
414         tcpext_TCPAbortOnMemory  = netstat_columns_find(tcpext_data, "TCPAbortOnMemory");  // connections aborted due to memory pressure
415         tcpext_TCPAbortOnTimeout = netstat_columns_find(tcpext_data, "TCPAbortOnTimeout"); // connections aborted due to timeout
416         tcpext_TCPAbortOnLinger  = netstat_columns_find(tcpext_data, "TCPAbortOnLinger");  // connections aborted after user close in linger timeout
417         tcpext_TCPAbortFailed    = netstat_columns_find(tcpext_data, "TCPAbortFailed");    // times unable to send RST due to no memory
418
419         /*
420         tcpext_EmbryonicRsts = netstat_columns_find(tcpext_data, "EmbryonicRsts");
421         tcpext_PruneCalled = netstat_columns_find(tcpext_data, "PruneCalled");
422         tcpext_RcvPruned = netstat_columns_find(tcpext_data, "RcvPruned");
423         tcpext_OutOfWindowIcmps = netstat_columns_find(tcpext_data, "OutOfWindowIcmps");
424         tcpext_LockDroppedIcmps = netstat_columns_find(tcpext_data, "LockDroppedIcmps");
425         tcpext_ArpFilter = netstat_columns_find(tcpext_data, "ArpFilter");
426         tcpext_TW = netstat_columns_find(tcpext_data, "TW");
427         tcpext_TWRecycled = netstat_columns_find(tcpext_data, "TWRecycled");
428         tcpext_TWKilled = netstat_columns_find(tcpext_data, "TWKilled");
429         tcpext_PAWSPassive = netstat_columns_find(tcpext_data, "PAWSPassive");
430         tcpext_PAWSActive = netstat_columns_find(tcpext_data, "PAWSActive");
431         tcpext_PAWSEstab = netstat_columns_find(tcpext_data, "PAWSEstab");
432         tcpext_DelayedACKs = netstat_columns_find(tcpext_data, "DelayedACKs");
433         tcpext_DelayedACKLocked = netstat_columns_find(tcpext_data, "DelayedACKLocked");
434         tcpext_DelayedACKLost = netstat_columns_find(tcpext_data, "DelayedACKLost");
435         tcpext_ListenOverflows = netstat_columns_find(tcpext_data, "ListenOverflows");
436         tcpext_ListenDrops = netstat_columns_find(tcpext_data, "ListenDrops");
437         tcpext_TCPPrequeued = netstat_columns_find(tcpext_data, "TCPPrequeued");
438         tcpext_TCPDirectCopyFromBacklog = netstat_columns_find(tcpext_data, "TCPDirectCopyFromBacklog");
439         tcpext_TCPDirectCopyFromPrequeue = netstat_columns_find(tcpext_data, "TCPDirectCopyFromPrequeue");
440         tcpext_TCPPrequeueDropped = netstat_columns_find(tcpext_data, "TCPPrequeueDropped");
441         tcpext_TCPHPHits = netstat_columns_find(tcpext_data, "TCPHPHits");
442         tcpext_TCPHPHitsToUser = netstat_columns_find(tcpext_data, "TCPHPHitsToUser");
443         tcpext_TCPPureAcks = netstat_columns_find(tcpext_data, "TCPPureAcks");
444         tcpext_TCPHPAcks = netstat_columns_find(tcpext_data, "TCPHPAcks");
445         tcpext_TCPRenoRecovery = netstat_columns_find(tcpext_data, "TCPRenoRecovery");
446         tcpext_TCPSackRecovery = netstat_columns_find(tcpext_data, "TCPSackRecovery");
447         tcpext_TCPSACKReneging = netstat_columns_find(tcpext_data, "TCPSACKReneging");
448         tcpext_TCPFullUndo = netstat_columns_find(tcpext_data, "TCPFullUndo");
449         tcpext_TCPPartialUndo = netstat_columns_find(tcpext_data, "TCPPartialUndo");
450         tcpext_TCPDSACKUndo = netstat_columns_find(tcpext_data, "TCPDSACKUndo");
451         tcpext_TCPLossUndo = netstat_columns_find(tcpext_data, "TCPLossUndo");
452         tcpext_TCPLostRetransmit = netstat_columns_find(tcpext_data, "TCPLostRetransmit");
453         tcpext_TCPRenoFailures = netstat_columns_find(tcpext_data, "TCPRenoFailures");
454         tcpext_TCPSackFailures = netstat_columns_find(tcpext_data, "TCPSackFailures");
455         tcpext_TCPLossFailures = netstat_columns_find(tcpext_data, "TCPLossFailures");
456         tcpext_TCPFastRetrans = netstat_columns_find(tcpext_data, "TCPFastRetrans");
457         tcpext_TCPForwardRetrans = netstat_columns_find(tcpext_data, "TCPForwardRetrans");
458         tcpext_TCPSlowStartRetrans = netstat_columns_find(tcpext_data, "TCPSlowStartRetrans");
459         tcpext_TCPTimeouts = netstat_columns_find(tcpext_data, "TCPTimeouts");
460         tcpext_TCPLossProbes = netstat_columns_find(tcpext_data, "TCPLossProbes");
461         tcpext_TCPLossProbeRecovery = netstat_columns_find(tcpext_data, "TCPLossProbeRecovery");
462         tcpext_TCPRenoRecoveryFail = netstat_columns_find(tcpext_data, "TCPRenoRecoveryFail");
463         tcpext_TCPSackRecoveryFail = netstat_columns_find(tcpext_data, "TCPSackRecoveryFail");
464         tcpext_TCPSchedulerFailed = netstat_columns_find(tcpext_data, "TCPSchedulerFailed");
465         tcpext_TCPRcvCollapsed = netstat_columns_find(tcpext_data, "TCPRcvCollapsed");
466         tcpext_TCPDSACKOldSent = netstat_columns_find(tcpext_data, "TCPDSACKOldSent");
467         tcpext_TCPDSACKOfoSent = netstat_columns_find(tcpext_data, "TCPDSACKOfoSent");
468         tcpext_TCPDSACKRecv = netstat_columns_find(tcpext_data, "TCPDSACKRecv");
469         tcpext_TCPDSACKOfoRecv = netstat_columns_find(tcpext_data, "TCPDSACKOfoRecv");
470         tcpext_TCPMemoryPressures = netstat_columns_find(tcpext_data, "TCPMemoryPressures");
471         tcpext_TCPSACKDiscard = netstat_columns_find(tcpext_data, "TCPSACKDiscard");
472         tcpext_TCPDSACKIgnoredOld = netstat_columns_find(tcpext_data, "TCPDSACKIgnoredOld");
473         tcpext_TCPDSACKIgnoredNoUndo = netstat_columns_find(tcpext_data, "TCPDSACKIgnoredNoUndo");
474         tcpext_TCPSpuriousRTOs = netstat_columns_find(tcpext_data, "TCPSpuriousRTOs");
475         tcpext_TCPMD5NotFound = netstat_columns_find(tcpext_data, "TCPMD5NotFound");
476         tcpext_TCPMD5Unexpected = netstat_columns_find(tcpext_data, "TCPMD5Unexpected");
477         tcpext_TCPSackShifted = netstat_columns_find(tcpext_data, "TCPSackShifted");
478         tcpext_TCPSackMerged = netstat_columns_find(tcpext_data, "TCPSackMerged");
479         tcpext_TCPSackShiftFallback = netstat_columns_find(tcpext_data, "TCPSackShiftFallback");
480         tcpext_TCPBacklogDrop = netstat_columns_find(tcpext_data, "TCPBacklogDrop");
481         tcpext_TCPMinTTLDrop = netstat_columns_find(tcpext_data, "TCPMinTTLDrop");
482         tcpext_TCPDeferAcceptDrop = netstat_columns_find(tcpext_data, "TCPDeferAcceptDrop");
483         tcpext_IPReversePathFilter = netstat_columns_find(tcpext_data, "IPReversePathFilter");
484         tcpext_TCPTimeWaitOverflow = netstat_columns_find(tcpext_data, "TCPTimeWaitOverflow");
485         tcpext_TCPReqQFullDoCookies = netstat_columns_find(tcpext_data, "TCPReqQFullDoCookies");
486         tcpext_TCPReqQFullDrop = netstat_columns_find(tcpext_data, "TCPReqQFullDrop");
487         tcpext_TCPRetransFail = netstat_columns_find(tcpext_data, "TCPRetransFail");
488         tcpext_TCPRcvCoalesce = netstat_columns_find(tcpext_data, "TCPRcvCoalesce");
489         tcpext_TCPChallengeACK = netstat_columns_find(tcpext_data, "TCPChallengeACK");
490         tcpext_TCPSYNChallenge = netstat_columns_find(tcpext_data, "TCPSYNChallenge");
491         tcpext_TCPFastOpenActive = netstat_columns_find(tcpext_data, "TCPFastOpenActive");
492         tcpext_TCPFastOpenActiveFail = netstat_columns_find(tcpext_data, "TCPFastOpenActiveFail");
493         tcpext_TCPFastOpenPassive = netstat_columns_find(tcpext_data, "TCPFastOpenPassive");
494         tcpext_TCPFastOpenPassiveFail = netstat_columns_find(tcpext_data, "TCPFastOpenPassiveFail");
495         tcpext_TCPFastOpenListenOverflow = netstat_columns_find(tcpext_data, "TCPFastOpenListenOverflow");
496         tcpext_TCPFastOpenCookieReqd = netstat_columns_find(tcpext_data, "TCPFastOpenCookieReqd");
497         tcpext_TCPSpuriousRtxHostQueues = netstat_columns_find(tcpext_data, "TCPSpuriousRtxHostQueues");
498         tcpext_BusyPollRxPackets = netstat_columns_find(tcpext_data, "BusyPollRxPackets");
499         tcpext_TCPAutoCorking = netstat_columns_find(tcpext_data, "TCPAutoCorking");
500         tcpext_TCPFromZeroWindowAdv = netstat_columns_find(tcpext_data, "TCPFromZeroWindowAdv");
501         tcpext_TCPToZeroWindowAdv = netstat_columns_find(tcpext_data, "TCPToZeroWindowAdv");
502         tcpext_TCPWantZeroWindowAdv = netstat_columns_find(tcpext_data, "TCPWantZeroWindowAdv");
503         tcpext_TCPSynRetrans = netstat_columns_find(tcpext_data, "TCPSynRetrans");
504         tcpext_TCPOrigDataSent = netstat_columns_find(tcpext_data, "TCPOrigDataSent");
505         tcpext_TCPHystartTrainDetect = netstat_columns_find(tcpext_data, "TCPHystartTrainDetect");
506         tcpext_TCPHystartTrainCwnd = netstat_columns_find(tcpext_data, "TCPHystartTrainCwnd");
507         tcpext_TCPHystartDelayDetect = netstat_columns_find(tcpext_data, "TCPHystartDelayDetect");
508         tcpext_TCPHystartDelayCwnd = netstat_columns_find(tcpext_data, "TCPHystartDelayCwnd");
509         tcpext_TCPACKSkippedSynRecv = netstat_columns_find(tcpext_data, "TCPACKSkippedSynRecv");
510         tcpext_TCPACKSkippedPAWS = netstat_columns_find(tcpext_data, "TCPACKSkippedPAWS");
511         tcpext_TCPACKSkippedSeq = netstat_columns_find(tcpext_data, "TCPACKSkippedSeq");
512         tcpext_TCPACKSkippedFinWait2 = netstat_columns_find(tcpext_data, "TCPACKSkippedFinWait2");
513         tcpext_TCPACKSkippedTimeWait = netstat_columns_find(tcpext_data, "TCPACKSkippedTimeWait");
514         tcpext_TCPACKSkippedChallenge = netstat_columns_find(tcpext_data, "TCPACKSkippedChallenge");
515         tcpext_TCPWinProbe = netstat_columns_find(tcpext_data, "TCPWinProbe");
516         tcpext_TCPKeepAlive = netstat_columns_find(tcpext_data, "TCPKeepAlive");
517         tcpext_TCPMTUPFail = netstat_columns_find(tcpext_data, "TCPMTUPFail");
518         tcpext_TCPMTUPSuccess = netstat_columns_find(tcpext_data, "TCPMTUPSuccess");
519 */
520         ipext_InNoRoutes = netstat_columns_find(ipext_data, "InNoRoutes");
521         ipext_InTruncatedPkts = netstat_columns_find(ipext_data, "InTruncatedPkts");
522         ipext_InMcastPkts = netstat_columns_find(ipext_data, "InMcastPkts");
523         ipext_OutMcastPkts = netstat_columns_find(ipext_data, "OutMcastPkts");
524         ipext_InBcastPkts = netstat_columns_find(ipext_data, "InBcastPkts");
525         ipext_OutBcastPkts = netstat_columns_find(ipext_data, "OutBcastPkts");
526         ipext_InOctets = netstat_columns_find(ipext_data, "InOctets");
527         ipext_OutOctets = netstat_columns_find(ipext_data, "OutOctets");
528         ipext_InMcastOctets = netstat_columns_find(ipext_data, "InMcastOctets");
529         ipext_OutMcastOctets = netstat_columns_find(ipext_data, "OutMcastOctets");
530         ipext_InBcastOctets = netstat_columns_find(ipext_data, "InBcastOctets");
531         ipext_OutBcastOctets = netstat_columns_find(ipext_data, "OutBcastOctets");
532         ipext_InCsumErrors = netstat_columns_find(ipext_data, "InCsumErrors");
533         ipext_InNoECTPkts = netstat_columns_find(ipext_data, "InNoECTPkts");
534         ipext_InECT1Pkts = netstat_columns_find(ipext_data, "InECT1Pkts");
535         ipext_InECT0Pkts = netstat_columns_find(ipext_data, "InECT0Pkts");
536         ipext_InCEPkts = netstat_columns_find(ipext_data, "InCEPkts");
537     }
538
539     if(unlikely(!ff)) {
540         char filename[FILENAME_MAX + 1];
541         snprintfz(filename, FILENAME_MAX, "%s%s", global_host_prefix, "/proc/net/netstat");
542         ff = procfile_open(config_get("plugin:proc:/proc/net/netstat", "filename to monitor", filename), " \t:", PROCFILE_FLAG_DEFAULT);
543     }
544     if(unlikely(!ff)) return 1;
545
546     ff = procfile_readall(ff);
547     if(unlikely(!ff)) return 0; // we return 0, so that we will retry to open it next time
548
549     uint32_t lines = procfile_lines(ff), l;
550     uint32_t words;
551
552     for(l = 0; l < lines ;l++) {
553         char *key = procfile_lineword(ff, l, 0);
554         uint32_t hash = simple_hash(key);
555
556         if(unlikely(hash == hash_ipext && strcmp(key, "IpExt") == 0)) {
557             uint32_t h = l++;
558
559             if(strcmp(procfile_lineword(ff, l, 0), "IpExt") != 0) {
560                 error("Cannot read IpExt line from /proc/net/netstat.");
561                 break;
562             }
563             words = procfile_linewords(ff, l);
564             if(words < 2) {
565                 error("Cannot read /proc/net/netstat IpExt line. Expected 2+ params, read %u.", words);
566                 continue;
567             }
568
569             parse_line_pair(ff, ipext_data, h, l);
570
571             RRDSET *st;
572
573             // --------------------------------------------------------------------
574
575             if(do_bandwidth == CONFIG_ONDEMAND_YES || (do_bandwidth == CONFIG_ONDEMAND_ONDEMAND && (*ipext_InOctets || *ipext_OutOctets))) {
576                 do_bandwidth = CONFIG_ONDEMAND_YES;
577                 st = rrdset_find("system.ipv4");
578                 if(!st) {
579                     st = rrdset_create("system", "ipv4", NULL, "network", NULL, "IPv4 Bandwidth", "kilobits/s", 500, update_every, RRDSET_TYPE_AREA);
580
581                     rrddim_add(st, "InOctets", "received", 8, 1024, RRDDIM_INCREMENTAL);
582                     rrddim_add(st, "OutOctets", "sent", -8, 1024, RRDDIM_INCREMENTAL);
583                 }
584                 else rrdset_next(st);
585
586                 rrddim_set(st, "InOctets", *ipext_InOctets);
587                 rrddim_set(st, "OutOctets", *ipext_OutOctets);
588                 rrdset_done(st);
589             }
590
591             // --------------------------------------------------------------------
592
593             if(do_inerrors == CONFIG_ONDEMAND_YES || (do_inerrors == CONFIG_ONDEMAND_ONDEMAND && (*ipext_InNoRoutes || *ipext_InTruncatedPkts))) {
594                 do_inerrors = CONFIG_ONDEMAND_YES;
595                 st = rrdset_find("ipv4.inerrors");
596                 if(!st) {
597                     st = rrdset_create("ipv4", "inerrors", NULL, "errors", NULL, "IPv4 Input Errors", "packets/s", 4000, update_every, RRDSET_TYPE_LINE);
598                     st->isdetail = 1;
599
600                     rrddim_add(st, "InNoRoutes", "noroutes", 1, 1, RRDDIM_INCREMENTAL);
601                     rrddim_add(st, "InTruncatedPkts", "truncated", 1, 1, RRDDIM_INCREMENTAL);
602                     rrddim_add(st, "InCsumErrors", "checksum", 1, 1, RRDDIM_INCREMENTAL);
603                 }
604                 else rrdset_next(st);
605
606                 rrddim_set(st, "InNoRoutes", *ipext_InNoRoutes);
607                 rrddim_set(st, "InTruncatedPkts", *ipext_InTruncatedPkts);
608                 rrddim_set(st, "InCsumErrors", *ipext_InCsumErrors);
609                 rrdset_done(st);
610             }
611
612             // --------------------------------------------------------------------
613
614             if(do_mcast == CONFIG_ONDEMAND_YES || (do_mcast == CONFIG_ONDEMAND_ONDEMAND && (*ipext_InMcastOctets || *ipext_OutMcastOctets))) {
615                 do_mcast = CONFIG_ONDEMAND_YES;
616                 st = rrdset_find("ipv4.mcast");
617                 if(!st) {
618                     st = rrdset_create("ipv4", "mcast", NULL, "multicast", NULL, "IPv4 Multicast Bandwidth", "kilobits/s", 9000, update_every, RRDSET_TYPE_AREA);
619                     st->isdetail = 1;
620
621                     rrddim_add(st, "InMcastOctets", "received", 8, 1024, RRDDIM_INCREMENTAL);
622                     rrddim_add(st, "OutMcastOctets", "sent", -8, 1024, RRDDIM_INCREMENTAL);
623                 }
624                 else rrdset_next(st);
625
626                 rrddim_set(st, "InMcastOctets", *ipext_InMcastOctets);
627                 rrddim_set(st, "OutMcastOctets", *ipext_OutMcastOctets);
628                 rrdset_done(st);
629             }
630
631             // --------------------------------------------------------------------
632
633             if(do_bcast == CONFIG_ONDEMAND_YES || (do_bcast == CONFIG_ONDEMAND_ONDEMAND && (*ipext_InBcastOctets || *ipext_OutBcastOctets))) {
634                 do_bcast = CONFIG_ONDEMAND_YES;
635                 st = rrdset_find("ipv4.bcast");
636                 if(!st) {
637                     st = rrdset_create("ipv4", "bcast", NULL, "broadcast", NULL, "IPv4 Broadcast Bandwidth", "kilobits/s", 8000, update_every, RRDSET_TYPE_AREA);
638                     st->isdetail = 1;
639
640                     rrddim_add(st, "InBcastOctets", "received", 8, 1024, RRDDIM_INCREMENTAL);
641                     rrddim_add(st, "OutBcastOctets", "sent", -8, 1024, RRDDIM_INCREMENTAL);
642                 }
643                 else rrdset_next(st);
644
645                 rrddim_set(st, "InBcastOctets", *ipext_InBcastOctets);
646                 rrddim_set(st, "OutBcastOctets", *ipext_OutBcastOctets);
647                 rrdset_done(st);
648             }
649
650             // --------------------------------------------------------------------
651
652             if(do_mcast_p == CONFIG_ONDEMAND_YES || (do_mcast_p == CONFIG_ONDEMAND_ONDEMAND && (*ipext_InMcastPkts || *ipext_OutMcastPkts))) {
653                 do_mcast_p = CONFIG_ONDEMAND_YES;
654                 st = rrdset_find("ipv4.mcastpkts");
655                 if(!st) {
656                     st = rrdset_create("ipv4", "mcastpkts", NULL, "multicast", NULL, "IPv4 Multicast Packets", "packets/s", 8600, update_every, RRDSET_TYPE_LINE);
657                     st->isdetail = 1;
658
659                     rrddim_add(st, "InMcastPkts", "received", 1, 1, RRDDIM_INCREMENTAL);
660                     rrddim_add(st, "OutMcastPkts", "sent", -1, 1, RRDDIM_INCREMENTAL);
661                 }
662                 else rrdset_next(st);
663
664                 rrddim_set(st, "InMcastPkts", *ipext_InMcastPkts);
665                 rrddim_set(st, "OutMcastPkts", *ipext_OutMcastPkts);
666                 rrdset_done(st);
667             }
668
669             // --------------------------------------------------------------------
670
671             if(do_bcast_p == CONFIG_ONDEMAND_YES || (do_bcast_p == CONFIG_ONDEMAND_ONDEMAND && (*ipext_InBcastPkts || *ipext_OutBcastPkts))) {
672                 do_bcast_p = CONFIG_ONDEMAND_YES;
673                 st = rrdset_find("ipv4.bcastpkts");
674                 if(!st) {
675                     st = rrdset_create("ipv4", "bcastpkts", NULL, "broadcast", NULL, "IPv4 Broadcast Packets", "packets/s", 8500, update_every, RRDSET_TYPE_LINE);
676                     st->isdetail = 1;
677
678                     rrddim_add(st, "InBcastPkts", "received", 1, 1, RRDDIM_INCREMENTAL);
679                     rrddim_add(st, "OutBcastPkts", "sent", -1, 1, RRDDIM_INCREMENTAL);
680                 }
681                 else rrdset_next(st);
682
683                 rrddim_set(st, "InBcastPkts", *ipext_InBcastPkts);
684                 rrddim_set(st, "OutBcastPkts", *ipext_OutBcastPkts);
685                 rrdset_done(st);
686             }
687
688             // --------------------------------------------------------------------
689
690             if(do_ecn == CONFIG_ONDEMAND_YES || (do_ecn == CONFIG_ONDEMAND_ONDEMAND && (*ipext_InCEPkts || *ipext_InECT0Pkts || *ipext_InECT1Pkts || *ipext_InNoECTPkts))) {
691                 do_ecn = CONFIG_ONDEMAND_YES;
692                 st = rrdset_find("ipv4.ecnpkts");
693                 if(!st) {
694                     st = rrdset_create("ipv4", "ecnpkts", NULL, "ecn", NULL, "IPv4 ECN Statistics", "packets/s", 8700, update_every, RRDSET_TYPE_LINE);
695                     st->isdetail = 1;
696
697                     rrddim_add(st, "InCEPkts", "CEP", 1, 1, RRDDIM_INCREMENTAL);
698                     rrddim_add(st, "InNoECTPkts", "NoECTP", -1, 1, RRDDIM_INCREMENTAL);
699                     rrddim_add(st, "InECT0Pkts", "ECTP0", 1, 1, RRDDIM_INCREMENTAL);
700                     rrddim_add(st, "InECT1Pkts", "ECTP1", 1, 1, RRDDIM_INCREMENTAL);
701                 }
702                 else rrdset_next(st);
703
704                 rrddim_set(st, "InCEPkts", *ipext_InCEPkts);
705                 rrddim_set(st, "InNoECTPkts", *ipext_InNoECTPkts);
706                 rrddim_set(st, "InECT0Pkts", *ipext_InECT0Pkts);
707                 rrddim_set(st, "InECT1Pkts", *ipext_InECT1Pkts);
708                 rrdset_done(st);
709             }
710         }
711         else if(unlikely(hash == hash_tcpext && strcmp(key, "TcpExt") == 0)) {
712             uint32_t h = l++;
713
714             if(strcmp(procfile_lineword(ff, l, 0), "TcpExt") != 0) {
715                 error("Cannot read TcpExt line from /proc/net/netstat.");
716                 break;
717             }
718             words = procfile_linewords(ff, l);
719             if(words < 2) {
720                 error("Cannot read /proc/net/netstat TcpExt line. Expected 2+ params, read %u.", words);
721                 continue;
722             }
723
724             parse_line_pair(ff, tcpext_data, h, l);
725
726             RRDSET *st;
727
728             // --------------------------------------------------------------------
729
730             if(do_tcpext_connaborts == CONFIG_ONDEMAND_YES || (do_tcpext_connaborts == CONFIG_ONDEMAND_ONDEMAND && (*tcpext_TCPAbortOnData || *tcpext_TCPAbortOnClose || *tcpext_TCPAbortOnMemory || *tcpext_TCPAbortOnTimeout || *tcpext_TCPAbortOnLinger || *tcpext_TCPAbortFailed))) {
731                 do_tcpext_connaborts = CONFIG_ONDEMAND_YES;
732                 st = rrdset_find("ipv4.tcpconnaborts");
733                 if(!st) {
734                     st = rrdset_create("ipv4", "tcpconnaborts", NULL, "tcp", NULL, "TCP Connection Aborts", "connections/s", 3000, update_every, RRDSET_TYPE_LINE);
735
736                     rrddim_add(st, "TCPAbortOnData",    "baddata",     1, 1, RRDDIM_INCREMENTAL);
737                     rrddim_add(st, "TCPAbortOnClose",   "userclosed",  1, 1, RRDDIM_INCREMENTAL);
738                     rrddim_add(st, "TCPAbortOnMemory",  "nomemory",    1, 1, RRDDIM_INCREMENTAL);
739                     rrddim_add(st, "TCPAbortOnTimeout", "timeout",     1, 1, RRDDIM_INCREMENTAL);
740                     rrddim_add(st, "TCPAbortOnLinger",  "linger",      1, 1, RRDDIM_INCREMENTAL);
741                     rrddim_add(st, "TCPAbortFailed",    "failed",     -1, 1, RRDDIM_INCREMENTAL);
742                 }
743                 else rrdset_next(st);
744
745                 rrddim_set(st, "TCPAbortOnData",    *tcpext_TCPAbortOnData);
746                 rrddim_set(st, "TCPAbortOnClose",   *tcpext_TCPAbortOnClose);
747                 rrddim_set(st, "TCPAbortOnMemory",  *tcpext_TCPAbortOnMemory);
748                 rrddim_set(st, "TCPAbortOnTimeout", *tcpext_TCPAbortOnTimeout);
749                 rrddim_set(st, "TCPAbortOnLinger",  *tcpext_TCPAbortOnLinger);
750                 rrddim_set(st, "TCPAbortFailed",    *tcpext_TCPAbortFailed);
751                 rrdset_done(st);
752             }
753             // --------------------------------------------------------------------
754
755             if(do_tcpext_reorder == CONFIG_ONDEMAND_YES || (do_tcpext_reorder == CONFIG_ONDEMAND_ONDEMAND && (*tcpext_TCPRenoReorder || *tcpext_TCPFACKReorder || *tcpext_TCPSACKReorder || *tcpext_TCPTSReorder))) {
756                 do_tcpext_reorder = CONFIG_ONDEMAND_YES;
757                 st = rrdset_find("ipv4.tcpreorders");
758                 if(!st) {
759                     st = rrdset_create("ipv4", "tcpreorders", NULL, "tcp", NULL, "TCP Reordered Packets by Detection Method", "packets/s", 3020, update_every, RRDSET_TYPE_LINE);
760
761                     rrddim_add(st, "TCPTSReorder",   "timestamp",   1, 1, RRDDIM_INCREMENTAL);
762                     rrddim_add(st, "TCPSACKReorder", "sack",        1, 1, RRDDIM_INCREMENTAL);
763                     rrddim_add(st, "TCPFACKReorder", "fack",        1, 1, RRDDIM_INCREMENTAL);
764                     rrddim_add(st, "TCPRenoReorder", "reno",        1, 1, RRDDIM_INCREMENTAL);
765                 }
766                 else rrdset_next(st);
767
768                 rrddim_set(st, "TCPTSReorder",   *tcpext_TCPTSReorder);
769                 rrddim_set(st, "TCPSACKReorder", *tcpext_TCPSACKReorder);
770                 rrddim_set(st, "TCPFACKReorder", *tcpext_TCPFACKReorder);
771                 rrddim_set(st, "TCPRenoReorder", *tcpext_TCPRenoReorder);
772                 rrdset_done(st);
773             }
774
775             // --------------------------------------------------------------------
776
777             if(do_tcpext_ofo == CONFIG_ONDEMAND_YES || (do_tcpext_ofo == CONFIG_ONDEMAND_ONDEMAND && (*tcpext_TCPOFOQueue || *tcpext_TCPOFODrop || *tcpext_TCPOFOMerge))) {
778                 do_tcpext_ofo = CONFIG_ONDEMAND_YES;
779                 st = rrdset_find("ipv4.tcpofo");
780                 if(!st) {
781                     st = rrdset_create("ipv4", "tcpofo", NULL, "tcp", NULL, "TCP Out-Of-Order Queue", "packets/s", 3050, update_every, RRDSET_TYPE_LINE);
782
783                     rrddim_add(st, "TCPOFOQueue", "inqueue",  1, 1, RRDDIM_INCREMENTAL);
784                     rrddim_add(st, "TCPOFODrop",  "dropped", -1, 1, RRDDIM_INCREMENTAL);
785                     rrddim_add(st, "TCPOFOMerge", "merged",   1, 1, RRDDIM_INCREMENTAL);
786                     rrddim_add(st, "OfoPruned",   "pruned",  -1, 1, RRDDIM_INCREMENTAL);
787                 }
788                 else rrdset_next(st);
789
790                 rrddim_set(st, "TCPOFOQueue",   *tcpext_TCPOFOQueue);
791                 rrddim_set(st, "TCPOFODrop",    *tcpext_TCPOFODrop);
792                 rrddim_set(st, "TCPOFOMerge",   *tcpext_TCPOFOMerge);
793                 rrddim_set(st, "OfoPruned",     *tcpext_OfoPruned);
794                 rrdset_done(st);
795             }
796
797             // --------------------------------------------------------------------
798
799             if(do_tcpext_syscookies == CONFIG_ONDEMAND_YES || (do_tcpext_syscookies == CONFIG_ONDEMAND_ONDEMAND && (*tcpext_SyncookiesSent || *tcpext_SyncookiesRecv || *tcpext_SyncookiesFailed))) {
800                 do_tcpext_syscookies = CONFIG_ONDEMAND_YES;
801                 st = rrdset_find("ipv4.tcpsyncookies");
802                 if(!st) {
803                     st = rrdset_create("ipv4", "tcpsyncookies", NULL, "tcp", NULL, "TCP SYN Cookies", "packets/s", 3100, update_every, RRDSET_TYPE_LINE);
804
805                     rrddim_add(st, "SyncookiesRecv",   "received",  1, 1, RRDDIM_INCREMENTAL);
806                     rrddim_add(st, "SyncookiesSent",   "sent",     -1, 1, RRDDIM_INCREMENTAL);
807                     rrddim_add(st, "SyncookiesFailed", "failed",   -1, 1, RRDDIM_INCREMENTAL);
808                 }
809                 else rrdset_next(st);
810
811                 rrddim_set(st, "SyncookiesRecv",   *tcpext_SyncookiesRecv);
812                 rrddim_set(st, "SyncookiesSent",   *tcpext_SyncookiesSent);
813                 rrddim_set(st, "SyncookiesFailed", *tcpext_SyncookiesFailed);
814                 rrdset_done(st);
815             }
816         }
817     }
818
819     return 0;
820 }