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