]> git.ipfire.org Git - ipfire-2.x.git/blob - src/patches/collectd/0004-interface.c-FreeBSD-10-support.patch
Merge branch 'master' into next
[ipfire-2.x.git] / src / patches / collectd / 0004-interface.c-FreeBSD-10-support.patch
1 From 645dadb3fcc466e8880fda4eb23b21ad433631fc Mon Sep 17 00:00:00 2001
2 From: Marc Fournier <marc.fournier@camptocamp.com>
3 Date: Tue, 7 Jan 2014 16:06:10 +0100
4 Subject: [PATCH 04/22] interface.c: FreeBSD-10 support
5
6 Quoting @trtrmitya in github issue #506 : "[...] it is broken on
7 FreeBSD-10, in which getifaddrs() returns not only link level stats for
8 a particular interface, but also entries for each IP configured on that
9 interface. As a result if_submit() is called several times for each
10 interface, which results in incorrect data being logged.
11
12 I am attaching a patch which fixes a problem on FreeBSD (9/10), but it
13 should work for every *BSD because [...] the getifaddrs implementation
14 first appeared in BSDi BSD/OS."
15
16 Many thanks to @trtrmitya for providing the patch !
17 ---
18 src/interface.c | 11 ++++++-----
19 1 file changed, 6 insertions(+), 5 deletions(-)
20
21 diff --git a/src/interface.c b/src/interface.c
22 index db998a3..9b566ea 100644
23 --- a/src/interface.c
24 +++ b/src/interface.c
25 @@ -213,18 +213,19 @@ static int interface_read (void)
26
27 for (if_ptr = if_list; if_ptr != NULL; if_ptr = if_ptr->ifa_next)
28 {
29 - if ((if_data = (struct IFA_DATA *) if_ptr->ifa_data) == NULL)
30 - continue;
31 + if (if_ptr->ifa_addr != NULL && if_ptr->ifa_addr->sa_family == AF_LINK) {
32 + if_data = (struct IFA_DATA *) if_ptr->ifa_data;
33
34 - if_submit (if_ptr->ifa_name, "if_octets",
35 + if_submit (if_ptr->ifa_name, "if_octets",
36 if_data->IFA_RX_BYTES,
37 if_data->IFA_TX_BYTES);
38 - if_submit (if_ptr->ifa_name, "if_packets",
39 + if_submit (if_ptr->ifa_name, "if_packets",
40 if_data->IFA_RX_PACKT,
41 if_data->IFA_TX_PACKT);
42 - if_submit (if_ptr->ifa_name, "if_errors",
43 + if_submit (if_ptr->ifa_name, "if_errors",
44 if_data->IFA_RX_ERROR,
45 if_data->IFA_TX_ERROR);
46 + }
47 }
48
49 freeifaddrs (if_list);
50 --
51 1.9.3
52