X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fiptables.c;h=c39aff8fcd8d7d0ce3078bfad5d17ea0ccb2ed02;hb=aff80830f1154a5b6c4da16a0b1033aafde14e24;hp=6f1030fb374549c04983ced5a65aae51db2aa9e5;hpb=f71895576cbd4b488cd66f0c96efb6fd3e7a6faf;p=collectd.git diff --git a/src/iptables.c b/src/iptables.c index 6f1030fb..c39aff8f 100644 --- a/src/iptables.c +++ b/src/iptables.c @@ -1,8 +1,8 @@ /** * collectd - src/iptables.c - * Copyright (C) 2007 Sjoerd van der Berg - * Copyright (C) 2007 Florian octo Forster - * Copyright (C) 2009 Marco Chiappero + * Copyright (C) 2007 Sjoerd van der Berg + * Copyright (C) 2007-2010 Florian octo Forster + * Copyright (C) 2009 Marco Chiappero * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -20,7 +20,7 @@ * * Authors: * Sjoerd van der Berg - * Florian Forster + * Florian Forster * Marco Chiappero **/ @@ -32,12 +32,35 @@ #include #if OWN_LIBIPTC -# include "libiptc/libiptc.h" -# include "libiptc/libip6tc.h" -#else +# include "owniptc/libiptc.h" +# include "owniptc/libip6tc.h" + +# define HAVE_IPTC_HANDLE_T 1 +# define HAVE_IP6TC_HANDLE_T 1 + +#else /* if !OWN_LIBIPTC */ # include # include -#endif + +/* + * iptc_handle_t was available before libiptc was officially available as a + * shared library. Note, that when the shared lib was introduced, the API and + * ABI have changed slightly: + * 'iptc_handle_t' used to be 'struct iptc_handle *' and most functions used + * 'iptc_handle_t *' as an argument. Now, most functions use 'struct + * iptc_handle *' (thus removing one level of pointer indirection). + * + * HAVE_IPTC_HANDLE_T is used to determine which API ought to be used. While + * this is somewhat hacky, I didn't find better way to solve that :-/ + * -tokkee + */ +# ifndef HAVE_IPTC_HANDLE_T +typedef struct iptc_handle iptc_handle_t; +# endif +# ifndef HAVE_IP6TC_HANDLE_T +typedef struct ip6tc_handle ip6tc_handle_t; +# endif +#endif /* !OWN_LIBIPTC */ /* * (Module-)Global variables @@ -274,11 +297,11 @@ static int submit6_match (const struct ip6t_entry_match *match, } sstrncpy (vl.type, "ipt_bytes", sizeof (vl.type)); - values[0].counter = (counter_t) entry->counters.bcnt; + values[0].derive = (derive_t) entry->counters.bcnt; plugin_dispatch_values (&vl); sstrncpy (vl.type, "ipt_packets", sizeof (vl.type)); - values[0].counter = (counter_t) entry->counters.pcnt; + values[0].derive = (derive_t) entry->counters.pcnt; plugin_dispatch_values (&vl); return (0); @@ -335,11 +358,11 @@ static int submit_match (const struct ipt_entry_match *match, } sstrncpy (vl.type, "ipt_bytes", sizeof (vl.type)); - values[0].counter = (counter_t) entry->counters.bcnt; + values[0].derive = (derive_t) entry->counters.bcnt; plugin_dispatch_values (&vl); sstrncpy (vl.type, "ipt_packets", sizeof (vl.type)); - values[0].counter = (counter_t) entry->counters.pcnt; + values[0].derive = (derive_t) entry->counters.pcnt; plugin_dispatch_values (&vl); return (0); @@ -429,8 +452,15 @@ static int iptables_read (void) if ( chain->ip_version == IPV4 ) { - iptc_handle_t handle; +#ifdef HAVE_IPTC_HANDLE_T + iptc_handle_t _handle; + iptc_handle_t *handle = &_handle; + + *handle = iptc_init (chain->table); +#else + iptc_handle_t *handle; handle = iptc_init (chain->table); +#endif if (!handle) { @@ -440,13 +470,20 @@ static int iptables_read (void) continue; } - submit_chain (&handle, chain); - iptc_free (&handle); + submit_chain (handle, chain); + iptc_free (handle); } else if ( chain->ip_version == IPV6 ) { - ip6tc_handle_t handle; +#ifdef HAVE_IP6TC_HANDLE_T + ip6tc_handle_t _handle; + ip6tc_handle_t *handle = &_handle; + + *handle = ip6tc_init (chain->table); +#else + ip6tc_handle_t *handle; handle = ip6tc_init (chain->table); +#endif if (!handle) { @@ -456,8 +493,8 @@ static int iptables_read (void) continue; } - submit6_chain (&handle, chain); - ip6tc_free (&handle); + submit6_chain (handle, chain); + ip6tc_free (handle); } else num_failures++;