summaryrefslogtreecommitdiff
path: root/cleopatre/application
diff options
context:
space:
mode:
authorYacine Belkadi2011-04-28 11:41:02 +0200
committerYacine Belkadi2011-05-05 18:19:42 +0200
commit57f758cdef46f901c4b52c9a7fc27217cff7c8fe (patch)
tree1faa40a54ef441474d7b33b0c28898fce53f15ce /cleopatre/application
parent41e3fa77b410198b128473252563f059fcb8dade (diff)
cleo/app/igmp_snoopd: add cmdline option to disable query sending, closes #2371
Diffstat (limited to 'cleopatre/application')
-rw-r--r--cleopatre/application/igmp_snoopd/inc/internal.h3
-rw-r--r--cleopatre/application/igmp_snoopd/src/igmp_v1_v2.c5
-rw-r--r--cleopatre/application/igmp_snoopd/src/igmp_v3.c6
-rw-r--r--cleopatre/application/igmp_snoopd/src/main.c128
4 files changed, 99 insertions, 43 deletions
diff --git a/cleopatre/application/igmp_snoopd/inc/internal.h b/cleopatre/application/igmp_snoopd/inc/internal.h
index c2aaff8f24..2ee06d082b 100644
--- a/cleopatre/application/igmp_snoopd/inc/internal.h
+++ b/cleopatre/application/igmp_snoopd/inc/internal.h
@@ -104,6 +104,9 @@ struct context
/** timer for sending queries. */
timer_t timer_query_tx;
+
+ /** Whether to send queries or not, when no querier is present */
+ bool query_tx;
};
/**
diff --git a/cleopatre/application/igmp_snoopd/src/igmp_v1_v2.c b/cleopatre/application/igmp_snoopd/src/igmp_v1_v2.c
index 703856be87..51d03b3b9c 100644
--- a/cleopatre/application/igmp_snoopd/src/igmp_v1_v2.c
+++ b/cleopatre/application/igmp_snoopd/src/igmp_v1_v2.c
@@ -85,7 +85,10 @@ process_v2_query (struct context *ctx,
log_debug ("Group-Specific Query");
}
- update_timer_query_tx (ctx);
+ if (ctx->query_tx)
+ {
+ update_timer_query_tx (ctx);
+ }
}
void
diff --git a/cleopatre/application/igmp_snoopd/src/igmp_v3.c b/cleopatre/application/igmp_snoopd/src/igmp_v3.c
index c40bdbae6f..906518f6de 100644
--- a/cleopatre/application/igmp_snoopd/src/igmp_v3.c
+++ b/cleopatre/application/igmp_snoopd/src/igmp_v3.c
@@ -266,7 +266,11 @@ process_v3_query (struct context *ctx,
}
update_computed_metrics (&ctx->metrics);
- update_timer_query_tx (ctx);
+
+ if (ctx->query_tx)
+ {
+ update_timer_query_tx (ctx);
+ }
}
/**
diff --git a/cleopatre/application/igmp_snoopd/src/main.c b/cleopatre/application/igmp_snoopd/src/main.c
index f9c52dd0b2..50a0597a7f 100644
--- a/cleopatre/application/igmp_snoopd/src/main.c
+++ b/cleopatre/application/igmp_snoopd/src/main.c
@@ -39,7 +39,8 @@
#define INTERFACE_NAME "br0"
/* Command line options */
-#define OPTARG_VLAN "--vlan"
+#define OPTARG_NO_QUERY_TX "--no_query_tx"
+#define OPTARG_VLAN "--vlan"
#define TIMER_SIGNAL SIGALRM
@@ -165,10 +166,11 @@ send_general_query (int sockfd)
* \param[out] ctx The context.
* \param ifname The name of the interface to use
* \param dominant_traffic_type The type of the dominant traffic.
+ * \param query_tx whether to send queries when no querier is present.
*/
static void
-init (int *sockfd_rx, int *sockfd_tx, struct context *ctx,
- const char *ifname, traffic_type_t dominant_traffic_type)
+init (int *sockfd_rx, int *sockfd_tx, struct context *ctx, const char *ifname,
+ traffic_type_t dominant_traffic_type, bool query_tx)
{
LIST_INIT (&ctx->groups_head);
@@ -176,6 +178,8 @@ init (int *sockfd_rx, int *sockfd_tx, struct context *ctx,
ctx->multicast_info = NULL;
+ ctx->query_tx = query_tx;
+
/* Init timer */
struct sigevent evp;
evp.sigev_notify = SIGEV_SIGNAL;
@@ -302,32 +306,35 @@ start_snooping (int sockfd_rx, int sockfd_tx, struct context *ctx,
{
sigset_t sigmask;
- /* Block the signal used for the timer */
- sigemptyset (&sigmask);
- sigaddset (&sigmask, TIMER_SIGNAL);
- if (sigprocmask (SIG_BLOCK, &sigmask, NULL) == -1)
+ if (ctx->query_tx)
{
- log_error ("sigprocmask: %s", strerror (errno));
- exit (EXIT_FAILURE);
- }
+ /* Block the signal used for the timer */
+ sigemptyset (&sigmask);
+ sigaddset (&sigmask, TIMER_SIGNAL);
+ if (sigprocmask (SIG_BLOCK, &sigmask, NULL) == -1)
+ {
+ log_error ("sigprocmask: %s", strerror (errno));
+ exit (EXIT_FAILURE);
+ }
- /* Install a handler for the signal used by the timer */
- struct sigaction sa;
- sa.sa_handler = timer_signal_handler;
- sigemptyset (&sa.sa_mask);
- sa.sa_flags = 0;
- if (sigaction (TIMER_SIGNAL, &sa, NULL) == -1)
- {
- log_error ("sigaction: %s", strerror (errno));
- exit (EXIT_FAILURE);
+ /* Install a handler for the signal used by the timer */
+ struct sigaction sa;
+ sa.sa_handler = timer_signal_handler;
+ sigemptyset (&sa.sa_mask);
+ sa.sa_flags = 0;
+ if (sigaction (TIMER_SIGNAL, &sa, NULL) == -1)
+ {
+ log_error ("sigaction: %s", strerror (errno));
+ exit (EXIT_FAILURE);
+ }
+
+ /* Start timer */
+ update_timer_query_tx (ctx);
}
sigset_t empty_sigmask;
sigemptyset (&empty_sigmask);
- /* Start timer */
- update_timer_query_tx (ctx);
-
while (true)
{
fd_set read_fds;
@@ -357,12 +364,15 @@ start_snooping (int sockfd_rx, int sockfd_tx, struct context *ctx,
{
timer_expired = 0;
- send_general_query (sockfd_tx);
+ if (ctx->query_tx)
+ {
+ send_general_query (sockfd_tx);
- /* In case something bad happens to the query, we re-arm
- * the timer.
- * This will be canceled if the query is received. */
- update_timer_query_tx (ctx);
+ /* In case something bad happens to the query, we re-arm
+ * the timer.
+ * This will be canceled if the query is received. */
+ update_timer_query_tx (ctx);
+ }
}
else
{
@@ -377,6 +387,47 @@ start_snooping (int sockfd_rx, int sockfd_tx, struct context *ctx,
}
}
+/**
+ * Parse command line args.
+ * \param argc args count.
+ * \param argv args.
+ * \param[out] dominant_traffic_type The dominant traffic type.
+ * \param query_tx Whether to send queries or not.
+ * \return 0, on success.
+ * -1, on error.
+ */
+int
+parse_args (int argc, char *argv[],
+ traffic_type_t *dominant_traffic_type, bool *query_tx)
+{
+ /* Defaults */
+ *dominant_traffic_type = TRAFFIC_TYPE_UNTAGGED;
+ *query_tx = true;
+
+ int i;
+ for (i = 1; i < argc; i++)
+ {
+ if (strcmp (argv[i], OPTARG_NO_QUERY_TX) == 0)
+ {
+ *query_tx = false;
+
+ log_debug (OPTARG_NO_QUERY_TX);
+ }
+ else if (strcmp (argv[i], OPTARG_VLAN) == 0)
+ {
+ *dominant_traffic_type = TRAFFIC_TYPE_VLAN_TAGGED;
+
+ log_debug (OPTARG_VLAN);
+ }
+ else
+ {
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
int
main (int argc, char *argv[])
{
@@ -384,21 +435,15 @@ main (int argc, char *argv[])
log_debug ("start");
- /* TODO: get from config file instead of argv */
- traffic_type_t dominant_traffic_type = TRAFFIC_TYPE_UNTAGGED;
+ traffic_type_t dominant_traffic_type;
+ bool query_tx;
- if (argc == 1)
- {
- dominant_traffic_type = TRAFFIC_TYPE_UNTAGGED;
- }
- else if ((argc == 2) && (strcmp (argv[1], OPTARG_VLAN) == 0))
- {
- dominant_traffic_type = TRAFFIC_TYPE_VLAN_TAGGED;
- }
- else
+ /* TODO: get from config file instead of argv */
+ if (parse_args (argc, argv, &dominant_traffic_type, &query_tx) == -1)
{
- printf ("Usage: %s [" OPTARG_VLAN "]\n"
- "\t" OPTARG_VLAN " if the dominant traffic is VLAN tagged.\n", argv[0]);
+ printf ("Usage: %s [" OPTARG_NO_QUERY_TX "] [" OPTARG_VLAN "]\n"
+ "\t" OPTARG_NO_QUERY_TX " don't send queries when no querier is present.\n"
+ "\t" OPTARG_VLAN " if the dominant traffic is VLAN tagged.\n", argv[0]);
return -1;
}
@@ -412,7 +457,8 @@ main (int argc, char *argv[])
/* The context */
struct context ctx;
- init (&sockfd_rx, &sockfd_tx, &ctx, INTERFACE_NAME, dominant_traffic_type);
+ init (&sockfd_rx, &sockfd_tx, &ctx, INTERFACE_NAME, dominant_traffic_type,
+ query_tx);
start_snooping (sockfd_rx, sockfd_tx, &ctx,
LIBSPID_MULTICAST_INFO_PATH); /* never returns */