summaryrefslogtreecommitdiff
path: root/cleopatre/application
diff options
context:
space:
mode:
authorYacine Belkadi2011-04-21 17:58:48 +0200
committerYacine Belkadi2011-05-05 18:19:40 +0200
commit9c2caeda89f170dfa941271962a7729ea9af9d33 (patch)
tree129cdd024de00809dda5e0e22e81a439b0fbe07b /cleopatre/application
parentab85f3a5377e9629f9bca9b8d7cc868bb8c90009 (diff)
cleo/app/igmp_snoopd: refactor: add receive_and_process(), refs #2371
Move code about receiving the packets and processing them to a new function receive_and_process().
Diffstat (limited to 'cleopatre/application')
-rw-r--r--cleopatre/application/igmp_snoopd/src/main.c99
1 files changed, 57 insertions, 42 deletions
diff --git a/cleopatre/application/igmp_snoopd/src/main.c b/cleopatre/application/igmp_snoopd/src/main.c
index ff58f69467..22a151f504 100644
--- a/cleopatre/application/igmp_snoopd/src/main.c
+++ b/cleopatre/application/igmp_snoopd/src/main.c
@@ -145,6 +145,62 @@ log_libspid_error(const char *fct_name, libspid_error_t status)
}
}
+
+/**
+ * Receive a packet and process it.
+ * \param sockfd The socket file descriptor.
+ * \param ctx The context.
+ * \param mcast_info_file The path of the multicast info file.
+ */
+static void
+receive_and_process (int sockfd,
+ struct context *ctx,
+ const char *mcast_info_file)
+{
+ unsigned char msg[MSG_LEN];
+ ssize_t len = recvfrom (sockfd, msg, sizeof (msg), 0, NULL, NULL);
+ if (len == -1)
+ {
+ log_error ("recvfrom: %s", strerror (errno));
+ }
+
+ bool was_of_interest = process_packet (ctx, msg, (size_t)len);
+
+ if (! was_of_interest)
+ {
+ log_debug ("packet was not of interest");
+ return;
+ }
+
+ del_inactive (ctx);
+
+ dump (ctx);
+
+ bool should_update_mcast_info_file
+ = update_multicast_info (&ctx->multicast_info, &ctx->groups_head);
+
+ if (! should_update_mcast_info_file)
+ {
+ log_debug ("no need to update multicast file");
+ return;
+ }
+
+ libspid_error_t status;
+
+ status = libspid_multicast_info_write_file (ctx->multicast_info);
+ if (status != LIBSPID_SUCCESS)
+ {
+ log_libspid_error ("libspid_multicast_info_write_file", status);
+ return;
+ }
+
+ status = libspid_system_file_update_warn (getpid (), mcast_info_file);
+ if (status != LIBSPID_SUCCESS)
+ {
+ log_libspid_error ("libspid_system_file_update_warn", status);
+ }
+}
+
/**
* Start IGMP Snooping.
* \param ifname The name of the network interface.
@@ -167,48 +223,7 @@ igmp_snooping (const char *ifname,
while (true)
{
- unsigned char msg[MSG_LEN];
- ssize_t len = recvfrom (sockfd, msg, sizeof (msg), 0, NULL, NULL);
- if (len == -1)
- {
- log_error ("recvfrom: %s", strerror (errno));
- }
-
- bool was_of_interest = process_packet (ctx, msg, (size_t)len);
-
- if (! was_of_interest)
- {
- log_debug ("packet was not of interest");
- continue;
- }
-
- del_inactive (ctx);
-
- dump (ctx);
-
- bool should_update_mcast_info_file
- = update_multicast_info (&ctx->multicast_info, &ctx->groups_head);
-
- if (! should_update_mcast_info_file)
- {
- log_debug ("no need to update multicast file");
- continue;
- }
-
- libspid_error_t status;
-
- status = libspid_multicast_info_write_file (ctx->multicast_info);
- if (status != LIBSPID_SUCCESS)
- {
- log_libspid_error ("libspid_multicast_info_write_file", status);
- continue;
- }
-
- status = libspid_system_file_update_warn (getpid (), mcast_info_file);
- if (status != LIBSPID_SUCCESS)
- {
- log_libspid_error ("libspid_system_file_update_warn", status);
- }
+ receive_and_process (sockfd, ctx, mcast_info_file);
}
}