dns plugin: Check for "struct ip6_ext".
[collectd.git] / src / netlink.c
1 /**
2  * collectd - src/netlink.c
3  * Copyright (C) 2007-2010  Florian octo Forster
4  * Copyright (C) 2008-2012  Sebastian Harl
5  * Copyright (C) 2013       Andreas Henriksson
6  * Copyright (C) 2013       Marc Fournier
7  *
8  * This program is free software; you can redistribute it and/or modify it
9  * under the terms of the GNU General Public License as published by the
10  * Free Software Foundation; only version 2 of the License is applicable.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
20  *
21  * Authors:
22  *   Florian octo Forster <octo at collectd.org>
23  *   Sebastian Harl <sh at tokkee.org>
24  *   Andreas Henriksson <andreas at fatal.se>
25  *   Marc Fournier <marc.fournier at camptocamp.com>
26  **/
27
28 #include "collectd.h"
29 #include "plugin.h"
30 #include "common.h"
31
32 #include <asm/types.h>
33 #include <sys/socket.h>
34
35 #include <linux/netlink.h>
36 #include <linux/rtnetlink.h>
37 #if HAVE_LINUX_GEN_STATS_H
38 # include <linux/gen_stats.h>
39 #endif
40 #if HAVE_LINUX_PKT_SCHED_H
41 # include <linux/pkt_sched.h>
42 #endif
43
44 #include <libmnl/libmnl.h>
45
46 typedef struct ir_ignorelist_s
47 {
48   char *device;
49   char *type;
50   char *inst;
51   struct ir_ignorelist_s *next;
52 } ir_ignorelist_t;
53
54 static int ir_ignorelist_invert = 1;
55 static ir_ignorelist_t *ir_ignorelist_head = NULL;
56
57 static struct mnl_socket *nl;
58
59 static char **iflist = NULL;
60 static size_t iflist_len = 0;
61
62 static const char *config_keys[] =
63 {
64         "Interface",
65         "VerboseInterface",
66         "QDisc",
67         "Class",
68         "Filter",
69         "IgnoreSelected"
70 };
71 static int config_keys_num = STATIC_ARRAY_SIZE (config_keys);
72
73 static int add_ignorelist (const char *dev, const char *type,
74     const char *inst)
75 {
76   ir_ignorelist_t *entry;
77
78   entry = (ir_ignorelist_t *) malloc (sizeof (ir_ignorelist_t));
79   if (entry == NULL)
80     return (-1);
81
82   memset (entry, '\0', sizeof (ir_ignorelist_t));
83
84   if (strcasecmp (dev, "All") != 0)
85   {
86     entry->device = strdup (dev);
87     if (entry->device == NULL)
88     {
89       sfree (entry);
90       return (-1);
91     }
92   }
93
94   entry->type = strdup (type);
95   if (entry->type == NULL)
96   {
97     sfree (entry->device);
98     sfree (entry);
99     return (-1);
100   }
101
102   if (inst != NULL)
103   {
104     entry->inst = strdup (inst);
105     if (entry->inst == NULL)
106     {
107       sfree (entry->type);
108       sfree (entry->device);
109       sfree (entry);
110       return (-1);
111     }
112   }
113
114   entry->next = ir_ignorelist_head;
115   ir_ignorelist_head = entry;
116
117   return (0);
118 } /* int add_ignorelist */
119
120 /*
121  * Checks wether a data set should be ignored. Returns `true' is the value
122  * should be ignored, `false' otherwise.
123  */
124 static int check_ignorelist (const char *dev,
125     const char *type, const char *type_instance)
126 {
127   ir_ignorelist_t *i;
128
129   assert ((dev != NULL) && (type != NULL));
130
131   if (ir_ignorelist_head == NULL)
132     return (ir_ignorelist_invert ? 0 : 1);
133
134   for (i = ir_ignorelist_head; i != NULL; i = i->next)
135   {
136     /* i->device == NULL  =>  match all devices */
137     if ((i->device != NULL)
138         && (strcasecmp (i->device, dev) != 0))
139       continue;
140
141     if (strcasecmp (i->type, type) != 0)
142       continue;
143
144     if ((i->inst != NULL) && (type_instance != NULL)
145         && (strcasecmp (i->inst, type_instance) != 0))
146       continue;
147
148     DEBUG ("netlink plugin: check_ignorelist: "
149         "(dev = %s; type = %s; inst = %s) matched "
150         "(dev = %s; type = %s; inst = %s)",
151         dev, type,
152         type_instance == NULL ? "(nil)" : type_instance,
153         i->device == NULL ? "(nil)" : i->device,
154         i->type,
155         i->inst == NULL ? "(nil)" : i->inst);
156
157     return (ir_ignorelist_invert ? 0 : 1);
158   } /* for i */
159
160   return (ir_ignorelist_invert);
161 } /* int check_ignorelist */
162
163 static void submit_one (const char *dev, const char *type,
164     const char *type_instance, derive_t value)
165 {
166   value_t values[1];
167   value_list_t vl = VALUE_LIST_INIT;
168
169   values[0].derive = value;
170
171   vl.values = values;
172   vl.values_len = 1;
173   sstrncpy (vl.host, hostname_g, sizeof (vl.host));
174   sstrncpy (vl.plugin, "netlink", sizeof (vl.plugin));
175   sstrncpy (vl.plugin_instance, dev, sizeof (vl.plugin_instance));
176   sstrncpy (vl.type, type, sizeof (vl.type));
177
178   if (type_instance != NULL)
179     sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
180
181   plugin_dispatch_values (&vl);
182 } /* void submit_one */
183
184 static void submit_two (const char *dev, const char *type,
185     const char *type_instance,
186     derive_t rx, derive_t tx)
187 {
188   value_t values[2];
189   value_list_t vl = VALUE_LIST_INIT;
190
191   values[0].derive = rx;
192   values[1].derive = tx;
193
194   vl.values = values;
195   vl.values_len = 2;
196   sstrncpy (vl.host, hostname_g, sizeof (vl.host));
197   sstrncpy (vl.plugin, "netlink", sizeof (vl.plugin));
198   sstrncpy (vl.plugin_instance, dev, sizeof (vl.plugin_instance));
199   sstrncpy (vl.type, type, sizeof (vl.type));
200
201   if (type_instance != NULL)
202     sstrncpy (vl.type_instance, type_instance, sizeof (vl.type_instance));
203
204   plugin_dispatch_values (&vl);
205 } /* void submit_two */
206
207 static int update_iflist (struct ifinfomsg *msg, const char *dev)
208 {
209   /* Update the `iflist'. It's used to know which interfaces exist and query
210    * them later for qdiscs and classes. */
211   if ((msg->ifi_index >= 0) && ((size_t) msg->ifi_index >= iflist_len))
212   {
213     char **temp;
214
215     temp = (char **) realloc (iflist, (msg->ifi_index + 1) * sizeof (char *));
216     if (temp == NULL)
217     {
218       ERROR ("netlink plugin: update_iflist: realloc failed.");
219       return (-1);
220     }
221
222     memset (temp + iflist_len, '\0',
223         (msg->ifi_index + 1 - iflist_len) * sizeof (char *));
224     iflist = temp;
225     iflist_len = msg->ifi_index + 1;
226   }
227   if ((iflist[msg->ifi_index] == NULL)
228       || (strcmp (iflist[msg->ifi_index], dev) != 0))
229   {
230     sfree (iflist[msg->ifi_index]);
231     iflist[msg->ifi_index] = strdup (dev);
232   }
233
234   return (0);
235 } /* int update_iflist */
236
237 static void check_ignorelist_and_submit (const char *dev,
238     struct rtnl_link_stats *stats)
239 {
240
241   if (check_ignorelist (dev, "interface", NULL) == 0)
242   {
243     submit_two (dev, "if_octets", NULL, stats->rx_bytes, stats->tx_bytes);
244     submit_two (dev, "if_packets", NULL, stats->rx_packets, stats->tx_packets);
245     submit_two (dev, "if_errors", NULL, stats->rx_errors, stats->tx_errors);
246   }
247   else
248   {
249     DEBUG ("netlink plugin: Ignoring %s/interface.", dev);
250   }
251
252   if (check_ignorelist (dev, "if_detail", NULL) == 0)
253   {
254     submit_two (dev, "if_dropped", NULL, stats->rx_dropped, stats->tx_dropped);
255     submit_one (dev, "if_multicast", NULL, stats->multicast);
256     submit_one (dev, "if_collisions", NULL, stats->collisions);
257
258     submit_one (dev, "if_rx_errors", "length", stats->rx_length_errors);
259     submit_one (dev, "if_rx_errors", "over", stats->rx_over_errors);
260     submit_one (dev, "if_rx_errors", "crc", stats->rx_crc_errors);
261     submit_one (dev, "if_rx_errors", "frame", stats->rx_frame_errors);
262     submit_one (dev, "if_rx_errors", "fifo", stats->rx_fifo_errors);
263     submit_one (dev, "if_rx_errors", "missed", stats->rx_missed_errors);
264
265     submit_one (dev, "if_tx_errors", "aborted", stats->tx_aborted_errors);
266     submit_one (dev, "if_tx_errors", "carrier", stats->tx_carrier_errors);
267     submit_one (dev, "if_tx_errors", "fifo", stats->tx_fifo_errors);
268     submit_one (dev, "if_tx_errors", "heartbeat", stats->tx_heartbeat_errors);
269     submit_one (dev, "if_tx_errors", "window", stats->tx_window_errors);
270   }
271   else
272   {
273     DEBUG ("netlink plugin: Ignoring %s/if_detail.", dev);
274   }
275
276 } /* void check_ignorelist_and_submit */
277
278 static int link_filter_cb (const struct nlmsghdr *nlh,
279     void *args __attribute__((unused)))
280 {
281   struct ifinfomsg *ifm = mnl_nlmsg_get_payload (nlh);
282   struct nlattr *attr;
283   struct rtnl_link_stats *stats = NULL;
284   const char *dev = NULL;
285
286   if (nlh->nlmsg_type != RTM_NEWLINK)
287   {
288     ERROR ("netlink plugin: link_filter_cb: Don't know how to handle type %i.",
289         nlh->nlmsg_type);
290     return MNL_CB_ERROR;
291   }
292
293   /* Scan attribute list for device name. */
294   mnl_attr_for_each (attr, nlh, sizeof (*ifm))
295   {
296     if (mnl_attr_get_type (attr) != IFLA_IFNAME)
297       continue;
298
299     if (mnl_attr_validate (attr, MNL_TYPE_STRING) < 0)
300     {
301       ERROR ("netlink plugin: link_filter_cb: IFLA_IFNAME mnl_attr_validate failed.");
302       return MNL_CB_ERROR;
303     }
304
305     dev = mnl_attr_get_str (attr);
306     if (update_iflist (ifm, dev) < 0)
307       return MNL_CB_ERROR;
308     break;
309   }
310
311   if (dev == NULL)
312   {
313     ERROR ("netlink plugin: link_filter_cb: dev == NULL");
314     return MNL_CB_ERROR;
315   }
316
317   mnl_attr_for_each (attr, nlh, sizeof (*ifm))
318   {
319     if (mnl_attr_get_type (attr) != IFLA_STATS)
320       continue;
321
322     if (mnl_attr_validate2 (attr, MNL_TYPE_UNSPEC, sizeof (*stats)) < 0)
323     {
324       ERROR ("netlink plugin: link_filter_cb: IFLA_STATS mnl_attr_validate2 failed.");
325       return MNL_CB_ERROR;
326     }
327     stats = mnl_attr_get_payload (attr);
328
329     check_ignorelist_and_submit (dev, stats);
330     break;
331   }
332
333   if (stats == NULL)
334   {
335     DEBUG ("netlink plugin: link_filter: No statistics for interface %s.", dev);
336     return MNL_CB_OK;
337   }
338
339   return MNL_CB_OK;
340 } /* int link_filter_cb */
341
342 #if HAVE_TCA_STATS2
343 static int qos_attr_cb (const struct nlattr *attr, void *data)
344 {
345   struct gnet_stats_basic **bs = (struct gnet_stats_basic **)data;
346
347   /* skip unsupported attribute in user-space */
348   if (mnl_attr_type_valid (attr, TCA_STATS_MAX) < 0)
349     return MNL_CB_OK;
350
351   if (mnl_attr_get_type (attr) == TCA_STATS_BASIC)
352   {
353     if (mnl_attr_validate2 (attr, MNL_TYPE_UNSPEC, sizeof (**bs)) < 0)
354     {
355       ERROR ("netlink plugin: qos_attr_cb: TCA_STATS_BASIC mnl_attr_validate2 failed.");
356       return MNL_CB_ERROR;
357     }
358     *bs = mnl_attr_get_payload (attr);
359     return MNL_CB_STOP;
360   }
361
362   return MNL_CB_OK;
363 } /* qos_attr_cb */
364 #endif
365
366 static int qos_filter_cb (const struct nlmsghdr *nlh, void *args)
367 {
368   struct tcmsg *tm = mnl_nlmsg_get_payload (nlh);
369   struct nlattr *attr;
370
371   int wanted_ifindex = *((int *) args);
372
373   const char *dev;
374   const char *kind = NULL;
375
376   /* char *type_instance; */
377   char *tc_type;
378   char tc_inst[DATA_MAX_NAME_LEN];
379
380   _Bool stats_submitted = 0;
381
382   if (nlh->nlmsg_type == RTM_NEWQDISC)
383     tc_type = "qdisc";
384   else if (nlh->nlmsg_type == RTM_NEWTCLASS)
385     tc_type = "class";
386   else if (nlh->nlmsg_type == RTM_NEWTFILTER)
387     tc_type = "filter";
388   else
389   {
390     ERROR ("netlink plugin: qos_filter_cb: Don't know how to handle type %i.",
391         nlh->nlmsg_type);
392     return MNL_CB_ERROR;
393   }
394
395   if (tm->tcm_ifindex != wanted_ifindex)
396   {
397     DEBUG ("netlink plugin: qos_filter_cb: Got %s for interface #%i, "
398         "but expected #%i.",
399         tc_type, tm->tcm_ifindex, wanted_ifindex);
400     return MNL_CB_OK;
401   }
402
403   if ((tm->tcm_ifindex >= 0)
404       && ((size_t) tm->tcm_ifindex >= iflist_len))
405   {
406     ERROR ("netlink plugin: qos_filter_cb: tm->tcm_ifindex = %i "
407         ">= iflist_len = %zu",
408         tm->tcm_ifindex, iflist_len);
409     return MNL_CB_ERROR;
410   }
411
412   dev = iflist[tm->tcm_ifindex];
413   if (dev == NULL)
414   {
415     ERROR ("netlink plugin: qos_filter_cb: iflist[%i] == NULL",
416         tm->tcm_ifindex);
417     return MNL_CB_ERROR;
418   }
419
420   mnl_attr_for_each (attr, nlh, sizeof (*tm))
421   {
422     if (mnl_attr_get_type (attr) != TCA_KIND)
423       continue;
424
425     if (mnl_attr_validate (attr, MNL_TYPE_STRING) < 0)
426     {
427       ERROR ("netlink plugin: qos_filter_cb: TCA_KIND mnl_attr_validate failed.");
428       return MNL_CB_ERROR;
429     }
430
431     kind = mnl_attr_get_str (attr);
432     break;
433   }
434
435   if (kind == NULL)
436   {
437     ERROR ("netlink plugin: qos_filter_cb: kind == NULL");
438     return (-1);
439   }
440
441   { /* The ID */
442     uint32_t numberic_id;
443
444     numberic_id = tm->tcm_handle;
445     if (strcmp (tc_type, "filter") == 0)
446       numberic_id = tm->tcm_parent;
447
448     ssnprintf (tc_inst, sizeof (tc_inst), "%s-%x:%x",
449         kind,
450         numberic_id >> 16,
451         numberic_id & 0x0000FFFF);
452   }
453
454   DEBUG ("netlink plugin: qos_filter_cb: got %s for %s (%i).",
455       tc_type, dev, tm->tcm_ifindex);
456
457   if (check_ignorelist (dev, tc_type, tc_inst))
458     return MNL_CB_OK;
459
460 #if HAVE_TCA_STATS2
461   mnl_attr_for_each (attr, nlh, sizeof (*tm))
462   {
463     struct gnet_stats_basic *bs = NULL;
464
465     if (mnl_attr_get_type (attr) != TCA_STATS2)
466       continue;
467
468     if (mnl_attr_validate (attr, MNL_TYPE_NESTED) < 0)
469     {
470       ERROR ("netlink plugin: qos_filter_cb: TCA_STATS2 mnl_attr_validate failed.");
471       return MNL_CB_ERROR;
472     }
473
474     mnl_attr_parse_nested (attr, qos_attr_cb, &bs);
475
476     if (bs != NULL)
477     {
478       char type_instance[DATA_MAX_NAME_LEN];
479
480       stats_submitted = 1;
481
482       ssnprintf (type_instance, sizeof (type_instance), "%s-%s",
483           tc_type, tc_inst);
484
485       submit_one (dev, "ipt_bytes", type_instance, bs->bytes);
486       submit_one (dev, "ipt_packets", type_instance, bs->packets);
487     }
488
489     break;
490   }
491 #endif /* TCA_STATS2 */
492
493 #if HAVE_TCA_STATS
494   mnl_attr_for_each (attr, nlh, sizeof (*tm))
495   {
496     struct tc_stats *ts = NULL;
497
498     if (mnl_attr_get_type (attr) != TCA_STATS)
499       continue;
500
501     if (mnl_attr_validate2 (attr, MNL_TYPE_UNSPEC, sizeof (*ts)) < 0)
502     {
503       ERROR ("netlink plugin: qos_filter_cb: TCA_STATS mnl_attr_validate2 failed.");
504       return MNL_CB_ERROR;
505     }
506     ts = mnl_attr_get_payload (attr);
507
508     if (!stats_submitted && ts != NULL)
509     {
510       char type_instance[DATA_MAX_NAME_LEN];
511
512       ssnprintf (type_instance, sizeof (type_instance), "%s-%s",
513           tc_type, tc_inst);
514
515       submit_one (dev, "ipt_bytes", type_instance, ts->bytes);
516       submit_one (dev, "ipt_packets", type_instance, ts->packets);
517     }
518
519     break;
520   }
521
522 #endif /* TCA_STATS */
523
524 #if !(HAVE_TCA_STATS && HAVE_TCA_STATS2)
525   DEBUG ("netlink plugin: qos_filter_cb: Have neither TCA_STATS2 nor "
526       "TCA_STATS.");
527 #endif
528
529   return MNL_CB_OK;
530 } /* int qos_filter_cb */
531
532 static int ir_config (const char *key, const char *value)
533 {
534   char *new_val;
535   char *fields[8];
536   int fields_num;
537   int status = 1;
538
539   new_val = strdup (value);
540   if (new_val == NULL)
541     return (-1);
542
543   fields_num = strsplit (new_val, fields, STATIC_ARRAY_SIZE (fields));
544   if ((fields_num < 1) || (fields_num > 8))
545   {
546     sfree (new_val);
547     return (-1);
548   }
549
550   if ((strcasecmp (key, "Interface") == 0)
551       || (strcasecmp (key, "VerboseInterface") == 0))
552   {
553     if (fields_num != 1)
554     {
555       ERROR ("netlink plugin: Invalid number of fields for option "
556           "`%s'. Got %i, expected 1.", key, fields_num);
557       status = -1;
558     }
559     else
560     {
561       add_ignorelist (fields[0], "interface", NULL);
562       if (strcasecmp (key, "VerboseInterface") == 0)
563         add_ignorelist (fields[0], "if_detail", NULL);
564       status = 0;
565     }
566   }
567   else if ((strcasecmp (key, "QDisc") == 0)
568       || (strcasecmp (key, "Class") == 0)
569       || (strcasecmp (key, "Filter") == 0))
570   {
571     if ((fields_num < 1) || (fields_num > 2))
572     {
573       ERROR ("netlink plugin: Invalid number of fields for option "
574           "`%s'. Got %i, expected 1 or 2.", key, fields_num);
575       return (-1);
576     }
577     else
578     {
579       add_ignorelist (fields[0], key,
580           (fields_num == 2) ? fields[1] : NULL);
581       status = 0;
582     }
583   }
584   else if (strcasecmp (key, "IgnoreSelected") == 0)
585   {
586     if (fields_num != 1)
587     {
588       ERROR ("netlink plugin: Invalid number of fields for option "
589           "`IgnoreSelected'. Got %i, expected 1.", fields_num);
590       status = -1;
591     }
592     else
593     {
594       if (IS_TRUE (fields[0]))
595         ir_ignorelist_invert = 0;
596       else
597         ir_ignorelist_invert = 1;
598       status = 0;
599     }
600   }
601
602   sfree (new_val);
603
604   return (status);
605 } /* int ir_config */
606
607 static int ir_init (void)
608 {
609   nl = mnl_socket_open (NETLINK_ROUTE);
610   if (nl == NULL)
611   {
612     ERROR ("netlink plugin: ir_init: mnl_socket_open failed.");
613     return (-1);
614   }
615
616   if (mnl_socket_bind (nl, 0, MNL_SOCKET_AUTOPID) < 0)
617   {
618     ERROR ("netlink plugin: ir_init: mnl_socket_bind failed.");
619     return (-1);
620   }
621
622   return (0);
623 } /* int ir_init */
624
625 static int ir_read (void)
626 {
627   char buf[MNL_SOCKET_BUFFER_SIZE];
628   struct nlmsghdr *nlh;
629   struct rtgenmsg *rt;
630   int ret;
631   unsigned int seq, portid;
632
633   size_t ifindex;
634
635   static const int type_id[] = { RTM_GETQDISC, RTM_GETTCLASS, RTM_GETTFILTER };
636   static const char *type_name[] = { "qdisc", "class", "filter" };
637
638   portid = mnl_socket_get_portid (nl);
639
640   nlh = mnl_nlmsg_put_header (buf);
641   nlh->nlmsg_type = RTM_GETLINK;
642   nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP;
643   nlh->nlmsg_seq = seq = time (NULL);
644   rt = mnl_nlmsg_put_extra_header (nlh, sizeof (*rt));
645   rt->rtgen_family = AF_PACKET;
646
647   if (mnl_socket_sendto (nl, nlh, nlh->nlmsg_len) < 0)
648   {
649     ERROR ("netlink plugin: ir_read: rtnl_wilddump_request failed.");
650     return (-1);
651   }
652
653   ret = mnl_socket_recvfrom (nl, buf, sizeof (buf));
654   while (ret > 0)
655   {
656     ret = mnl_cb_run (buf, ret, seq, portid, link_filter_cb, NULL);
657     if (ret <= MNL_CB_STOP)
658       break;
659     ret = mnl_socket_recvfrom (nl, buf, sizeof (buf));
660   }
661   if (ret < 0)
662   {
663     ERROR ("netlink plugin: ir_read: mnl_socket_recvfrom failed.");
664     return (-1);
665   }
666
667   /* `link_filter_cb' will update `iflist' which is used here to iterate
668    * over all interfaces. */
669   for (ifindex = 1; ifindex < iflist_len; ifindex++)
670   {
671     struct tcmsg *tm;
672     size_t type_index;
673
674     if (iflist[ifindex] == NULL)
675       continue;
676
677     for (type_index = 0; type_index < STATIC_ARRAY_SIZE (type_id); type_index++)
678     {
679       if (check_ignorelist (iflist[ifindex], type_name[type_index], NULL))
680       {
681         DEBUG ("netlink plugin: ir_read: check_ignorelist (%s, %s, (nil)) "
682             "== TRUE", iflist[ifindex], type_name[type_index]);
683         continue;
684       }
685
686       DEBUG ("netlink plugin: ir_read: querying %s from %s (%zu).",
687           type_name[type_index], iflist[ifindex], ifindex);
688
689       nlh = mnl_nlmsg_put_header (buf);
690       nlh->nlmsg_type = type_id[type_index];
691       nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP;
692       nlh->nlmsg_seq = seq = time (NULL);
693       tm = mnl_nlmsg_put_extra_header (nlh, sizeof (*tm));
694       tm->tcm_family = AF_PACKET;
695       tm->tcm_ifindex = ifindex;
696
697       if (mnl_socket_sendto (nl, nlh, nlh->nlmsg_len) < 0)
698       {
699         ERROR ("netlink plugin: ir_read: mnl_socket_sendto failed.");
700         continue;
701       }
702
703       ret = mnl_socket_recvfrom (nl, buf, sizeof (buf));
704       while (ret > 0)
705       {
706         ret = mnl_cb_run (buf, ret, seq, portid, qos_filter_cb, &ifindex);
707         if (ret <= MNL_CB_STOP)
708           break;
709         ret = mnl_socket_recvfrom (nl, buf, sizeof (buf));
710       }
711       if (ret < 0)
712       {
713         ERROR ("netlink plugin: ir_read:mnl_socket_recvfrom failed.");
714         continue;
715       }
716
717     } /* for (type_index) */
718   } /* for (if_index) */
719
720   return (0);
721 } /* int ir_read */
722
723 static int ir_shutdown (void)
724 {
725   if (nl)
726   {
727     mnl_socket_close (nl);
728     nl = NULL;
729   }
730
731   return (0);
732 } /* int ir_shutdown */
733
734 void module_register (void)
735 {
736   plugin_register_config ("netlink", ir_config, config_keys, config_keys_num);
737   plugin_register_init ("netlink", ir_init);
738   plugin_register_read ("netlink", ir_read);
739   plugin_register_shutdown ("netlink", ir_shutdown);
740 } /* void module_register */
741
742 /*
743  * vim: set shiftwidth=2 softtabstop=2 tabstop=8 :
744  */