Hi Mikhail,
Many thanks for your contribution. I have slightly reviewed your patch
to test libpcap for pcap_setdirection() in configure.ac (as doing it the
way you did would fail compiling for older libpcap versions). See the
commit log here (of course with kudos to you):
https://github.com/pmacct/pmacct/commit/0780a48136f0f8bf9ad1e796253cfa100f64a90f
I will review soon your other patch.
Paolo
On Fri, Jan 17, 2020 at 01:01:52PM +0100, Mikhail Sennikovsky wrote:
> The pcap direction configuration was explicitly disabled
> in 81fe649917036b9ef1ed4b3ea521befcaf36496b,
> however even before that commit it apparently did not work,
> because the pcap_setdirection must be called after pcap_activate,
> not before it.
>
> Introduce a new config variable, pcap_set_direction
> to allow pmacctd do pcap_setdirection.
>
> Signed-off-by: Mikhail Sennikovsky
> ---
> src/cfg.c | 1 +
> src/cfg.h | 1 +
> src/cfg_handlers.c | 14 ++
> src/cfg_handlers.h | 1 +
> src/pmacctd.c | 15 +++
> 5 files changed, 24 insertions(+), 8 deletions(-)
>
> diff --git a/src/cfg.c b/src/cfg.c
> index 0dcf061..ddad54c 100644
> --- a/src/cfg.c
> +++ b/src/cfg.c
> @@ -47,6 +47,7 @@ static const struct _dictionary_line dictionary[] = {
>{"pcap_interface_wait", cfg_key_pcap_interface_wait},
>{"pcap_direction", cfg_key_pcap_direction},
>{"pcap_ifindex", cfg_key_pcap_ifindex},
> + {"pcap_set_direction", cfg_key_pcap_set_direction},
>{"pcap_interfaces_map", cfg_key_pcap_interfaces_map},
>{"core_proc_name", cfg_key_proc_name},
>{"proc_priority", cfg_key_proc_priority},
> diff --git a/src/cfg.h b/src/cfg.h
> index 3641935..631b19b 100644
> --- a/src/cfg.h
> +++ b/src/cfg.h
> @@ -474,6 +474,7 @@ struct configuration {
>char *pcap_savefile;
>int pcap_direction;
>int pcap_ifindex;
> + int pcap_set_direction;
>char *pcap_interfaces_map;
>char *pcap_if;
>int pcap_if_wait;
> diff --git a/src/cfg_handlers.c b/src/cfg_handlers.c
> index 0818b12..eac176c 100644
> --- a/src/cfg_handlers.c
> +++ b/src/cfg_handlers.c
> @@ -547,6 +547,20 @@ int cfg_key_pcap_ifindex(char *filename, char *name,
> char *value_ptr)
>return changes;
> }
>
> +int cfg_key_pcap_set_direction(char *filename, char *name, char *value_ptr)
> +{
> + struct plugins_list_entry *list = plugins_list;
> + int value, changes = 0;
> +
> + value = parse_truefalse(value_ptr);
> + if (value < 0) return ERR;
> +
> + for (; list; list = list->next, changes++) list->cfg.pcap_set_direction =
> value;
> + if (name) Log(LOG_WARNING, "WARN: [%s] plugin name not supported for key
> 'pcap_set_direction'. Globalized.\n", filename);
> +
> + return changes;
> +}
> +
> int cfg_key_pcap_interfaces_map(char *filename, char *name, char *value_ptr)
> {
>struct plugins_list_entry *list = plugins_list;
> diff --git a/src/cfg_handlers.h b/src/cfg_handlers.h
> index 3fdd103..5ab0585 100644
> --- a/src/cfg_handlers.h
> +++ b/src/cfg_handlers.h
> @@ -48,6 +48,7 @@ extern int cfg_key_pcap_savefile_delay(char *, char *, char
> *);
> extern int cfg_key_pcap_savefile_replay(char *, char *, char *);
> extern int cfg_key_pcap_direction(char *, char *, char *);
> extern int cfg_key_pcap_ifindex(char *, char *, char *);
> +extern int cfg_key_pcap_set_direction(char *, char *, char *);
> extern int cfg_key_pcap_interfaces_map(char *, char *, char *);
> extern int cfg_key_use_ip_next_hop(char *, char *, char *);
> extern int cfg_key_decode_arista_trailer(char *, char *, char *);
> diff --git a/src/pmacctd.c b/src/pmacctd.c
> index 88fc367..1376a13 100644
> --- a/src/pmacctd.c
> +++ b/src/pmacctd.c
> @@ -152,18 +152,17 @@ pcap_t *pm_pcap_open(const char *dev_ptr, int snaplen,
> int promisc,
>if (protocol)
> Log(LOG_WARNING, "WARN ( %s/core ): pcap_protocol specified but linked
> against a version of libpcap that does not support pcap_set_protocol().\n",
> config.name);
> #endif
> -
> - /* XXX: rely on external filtering for now */
> -/*
> - ret = pcap_setdirection(p, direction);
> - if (ret < 0 && direction != PCAP_D_INOUT)
> -Log(LOG_WARNING, "INFO ( %s/core ): direction specified but linked
> against a version of libpcap that does not support pcap_setdirection().\n",
> config.name);
> -*/
> -
> +
>ret = pcap_activate(p);
>if (ret < 0)
> goto err;
>
> + if (config.pcap_set_direction) {
> +ret = pcap_setdirection(p, direction);
> +if (ret < 0 && direction != PCAP_D_INOUT)
> + Log(LOG_WARNING, "INFO ( %s/core ): direction specified but linked
> against a version of libpcap that does not support pcap_setdirection()\n",
> config.name);
> + }
> +
>return p;
>
> err:
> --
> 2.7.4
>
>
> ___
> pmacct-discussion mailing list
> http://www.pmacct.net/#mailinglists
___
pmacct-discussion mailing list
http://www.pmacct.net/#mailinglists