From 39d1e35cc2fc0d3bf82fd55f04f982ccc788a7b2 Mon Sep 17 00:00:00 2001 From: Yacine Belkadi Date: Thu, 17 Mar 2011 16:37:44 +0100 Subject: cleo/devkit/plcd: Rename plcd_mcast* to plcd_multicast* --- cleopatre/devkit/plcd/inc/plcd.h | 4 +- cleopatre/devkit/plcd/src/plcd_mcast.c | 261 ----------------------------- cleopatre/devkit/plcd/src/plcd_multicast.c | 261 +++++++++++++++++++++++++++++ cleopatre/devkit/plcd/src/plcd_process.c | 4 +- 4 files changed, 265 insertions(+), 265 deletions(-) delete mode 100644 cleopatre/devkit/plcd/src/plcd_mcast.c create mode 100644 cleopatre/devkit/plcd/src/plcd_multicast.c (limited to 'cleopatre/devkit/plcd') diff --git a/cleopatre/devkit/plcd/inc/plcd.h b/cleopatre/devkit/plcd/inc/plcd.h index 75f7404a52..d80ee791cf 100644 --- a/cleopatre/devkit/plcd/inc/plcd.h +++ b/cleopatre/devkit/plcd/inc/plcd.h @@ -195,12 +195,12 @@ int plcd_send_recv_drv_mme (const plcd_ctx_t *ctx, const mme_ctx_t *request_ctx, * \return LIBSPID_TRUE, if the multicast info has been updated. * LIBSPID_FALSE, if no update since last check. */ -libspid_boolean_t plcd_mcast_info_updated (plcd_ctx_t *ctx); +libspid_boolean_t plcd_multicast_info_updated (plcd_ctx_t *ctx); /** * Process the multicast info. * \param ctx the plcd context. */ -void plcd_mcast_process (plcd_ctx_t *ctx); +void plcd_multicast_process (plcd_ctx_t *ctx); #endif /* PLCD_H */ diff --git a/cleopatre/devkit/plcd/src/plcd_mcast.c b/cleopatre/devkit/plcd/src/plcd_mcast.c deleted file mode 100644 index 84db28be33..0000000000 --- a/cleopatre/devkit/plcd/src/plcd_mcast.c +++ /dev/null @@ -1,261 +0,0 @@ -/* SPC300 bundle {{{ - * - * Copyright (C) 2010 Spidcom - * - * <<>> - * - * }}} */ -/** - * \file devkit/plcd/src/plcd_mcast.c - * \brief multicast related processing in the PLC Daemon - * \ingroup plcd - */ - -#include -#include -#include -#include - -#include "libmme.h" -#include "libspid.h" -#include "plcd.h" - -/** - * Send the multicast info. - * \param ctx The context - * \param mcast_info The multicast info. If NULL, empty data will be sent. - */ -static void -plcd_mcast_send_info (plcd_ctx_t *ctx, - const libspid_multicast_info_t *mcast_info) -{ - PLCD_ASSERT (ctx != NULL); - - syslog (LOG_INFO, __func__); - - mme_ctx_t request_ctx; - mme_ctx_t confirm_ctx; - unsigned char mme_buffer[ETH_DATA_LEN] = {0}; - - mme_error_t status; - - status = mme_init (&request_ctx, - MME_TYPE_DRV_STA_SET_MCAST_LIST | MME_TYPE_REQ, - mme_buffer, sizeof (mme_buffer)); - - if (status != MME_SUCCESS) - { - syslog (LOG_ERR, "mme_init failed (%d)", status); - return; - } - - status = mme_init (&confirm_ctx, - MME_TYPE_DRV_STA_SET_MCAST_LIST | MME_TYPE_CNF, - mme_buffer, sizeof (mme_buffer)); - - if (status != MME_SUCCESS) - { - syslog (LOG_ERR, "mme_init failed (%d)", status); - return; - } - - uint8_t group_count = (mcast_info != NULL) ? mcast_info->entry_count : 0; - - unsigned int result_length; - if (mme_put (&request_ctx, - (void *) &group_count, - sizeof (uint8_t), - &result_length) != MME_SUCCESS) - { - syslog (LOG_ERR, "failed to mme_put group count"); - return; - } - - uint8_t group_idx; - for (group_idx = 0; group_idx < group_count; group_idx++) - { - const libspid_multicast_info_entry_t *entry = &mcast_info->entries[group_idx]; - - result_length = 0; - if (mme_put (&request_ctx, - (void *) entry->group_mac_addr, - ETHER_ADDR_LEN, - &result_length) != MME_SUCCESS) - { - syslog (LOG_ERR, "failed to mme_put group mac address"); - return; - } - - result_length = 0; - if (mme_put (&request_ctx, - (void *) &entry->member_count, - sizeof (uint8_t), - &result_length) != MME_SUCCESS) - { - syslog (LOG_ERR, "failed to mme_put member count"); - return; - } - - uint8_t member_idx; - for (member_idx = 0; member_idx < entry->member_count; member_idx++) - { - result_length = 0; - if (mme_put (&request_ctx, - (void *) &entry->members_mac_addr[member_idx], - ETHER_ADDR_LEN, - &result_length) != MME_SUCCESS) - { - syslog (LOG_ERR, "failed to mme_put member mac address"); - return; - } - } - } - - syslog (LOG_INFO, "sending MCAST MME..."); - uint8_t confirm_result; - if (plcd_send_recv_drv_mme (ctx, &request_ctx, &confirm_ctx, NULL) == -1) - { - syslog (LOG_ERR, "send recv drv mme failed"); - return; - } - if (mme_pull (&confirm_ctx, &confirm_result, sizeof (confirm_result), &result_length) != MME_SUCCESS) - { - syslog (LOG_WARNING, "mme pull failed"); - return; - } - if (confirm_result != MME_RESULT_SUCCESS) - { - syslog (LOG_ERR, "confirmation result not successful: %d", confirm_result); - return; - } - - syslog (LOG_INFO, "sent successfully"); -} - -libspid_boolean_t -plcd_mcast_info_updated (plcd_ctx_t *ctx) -{ - PLCD_ASSERT (ctx != NULL); - - struct stat file_stat; - memset (&file_stat, 0, sizeof (struct stat)); - - if (stat (LIBSPID_MULTICAST_INFO_PATH, &file_stat) == 0) - { - /* >= instead of > because the precision is up to the second. - * If we use >, we may miss an update that happened in the same second - * as the last check but a few millisecondes later. - * e.g: last_check at 345.00 secondes and update at 345.9999 seconds. - * The downside is that we may process many times the same file if - * multiple signals arrive in the same second as the last_check.*/ - if (file_stat.st_mtime >= ctx->mcast_last_check) - { - return LIBSPID_TRUE; - } - } - else - { - syslog (LOG_ERR, "stat: %s", strerror (errno)); - } - - return LIBSPID_FALSE; -} - -/** - * Read multicast info from the file, and update last_check value. - * \param mcast_info The multicast_info structure to fill with data from - * the file. - * \param mcast_last_check The last_check value to update if the file is - * successfully read. - */ -static void -plcd_mcast_read_file (libspid_multicast_info_t *mcast_info, - time_t *mcast_last_check) -{ - PLCD_ASSERT (mcast_info != NULL); - PLCD_ASSERT (mcast_last_check != NULL); - - /* Record the time just _before_ reading from the file. - * If we record the time after reading from the file, we could miss - * an update of the file that happened during the read. */ - time_t last_file_check = time (NULL); - - libspid_multicast_info_read_status_t read_status; - - libspid_error_t status = - libspid_multicast_info_read_file (mcast_info, &read_status); - - if (status == LIBSPID_SUCCESS) - { - /* We timestamp only if we were able to read the file. - * We don't update ctx->mcast_last_check on MCAST_READ_ERROR, - * because if we do, that will prevent us from reading the file - * again later. - * We do want to try again later, in case the error was a one - * time anomaly. */ - *mcast_last_check = last_file_check; - - if ((read_status & LIBSPID_MULTICAST_INFO_READ_TOO_MANY_GROUPS) != 0) - { - syslog (LOG_WARNING, "too many multicast groups"); - } - - if ((read_status & LIBSPID_MULTICAST_INFO_READ_TOO_MANY_MEMBERS) != 0) - { - syslog (LOG_WARNING, "too many members in group"); - } - } - else - { - if (status == LIBSPID_ERROR_PROCESSING) - { - if ((read_status & LIBSPID_MULTICAST_INFO_READ_EMPTY_GROUP) != 0) - { - syslog (LOG_ERR, "group with no members"); - } - - if ((read_status & LIBSPID_MULTICAST_INFO_READ_NOT_MULTICAST_ADDR) - != 0) - { - syslog (LOG_ERR, "not a multicast mac address"); - } - - if ((read_status & LIBSPID_MULTICAST_INFO_READ_PARSING_ERROR) != 0) - { - syslog (LOG_ERR, "parsing error"); - } - } - else if (status == LIBSPID_ERROR_SYSTEM) - { - syslog (LOG_ERR, "%s", strerror(errno)); - } - else - { - syslog (LOG_ERR, "libspid returned: %d", (int) status); - } - } -} - -void -plcd_mcast_process (plcd_ctx_t *ctx) -{ - PLCD_ASSERT (ctx != NULL); - - libspid_multicast_info_t *mcast_info = - malloc (sizeof (libspid_multicast_info_t)); - - if (mcast_info != NULL) - { - plcd_mcast_read_file (mcast_info, &ctx->mcast_last_check); - } - - /* If an error occured, (mcast_info == NULL) or - * (mcast_info->entry_count == 0). - * So as a precaution, the multicast info will be cleared. - * This will make Cesar stop its filtering. */ - - /* Send the info to Cesar */ - plcd_mcast_send_info (ctx, mcast_info); - - free (mcast_info); -} diff --git a/cleopatre/devkit/plcd/src/plcd_multicast.c b/cleopatre/devkit/plcd/src/plcd_multicast.c new file mode 100644 index 0000000000..81ad3eb903 --- /dev/null +++ b/cleopatre/devkit/plcd/src/plcd_multicast.c @@ -0,0 +1,261 @@ +/* SPC300 bundle {{{ + * + * Copyright (C) 2010 Spidcom + * + * <<>> + * + * }}} */ +/** + * \file devkit/plcd/src/plcd_mcast.c + * \brief multicast related processing in the PLC Daemon + * \ingroup plcd + */ + +#include +#include +#include +#include + +#include "libmme.h" +#include "libspid.h" +#include "plcd.h" + +/** + * Send the multicast info. + * \param ctx The context + * \param mcast_info The multicast info. If NULL, empty data will be sent. + */ +static void +plcd_multicast_send_info (plcd_ctx_t *ctx, + const libspid_multicast_info_t *mcast_info) +{ + PLCD_ASSERT (ctx != NULL); + + syslog (LOG_INFO, __func__); + + mme_ctx_t request_ctx; + mme_ctx_t confirm_ctx; + unsigned char mme_buffer[ETH_DATA_LEN] = {0}; + + mme_error_t status; + + status = mme_init (&request_ctx, + MME_TYPE_DRV_STA_SET_MCAST_LIST | MME_TYPE_REQ, + mme_buffer, sizeof (mme_buffer)); + + if (status != MME_SUCCESS) + { + syslog (LOG_ERR, "mme_init failed (%d)", status); + return; + } + + status = mme_init (&confirm_ctx, + MME_TYPE_DRV_STA_SET_MCAST_LIST | MME_TYPE_CNF, + mme_buffer, sizeof (mme_buffer)); + + if (status != MME_SUCCESS) + { + syslog (LOG_ERR, "mme_init failed (%d)", status); + return; + } + + uint8_t group_count = (mcast_info != NULL) ? mcast_info->entry_count : 0; + + unsigned int result_length; + if (mme_put (&request_ctx, + (void *) &group_count, + sizeof (uint8_t), + &result_length) != MME_SUCCESS) + { + syslog (LOG_ERR, "failed to mme_put group count"); + return; + } + + uint8_t group_idx; + for (group_idx = 0; group_idx < group_count; group_idx++) + { + const libspid_multicast_info_entry_t *entry = &mcast_info->entries[group_idx]; + + result_length = 0; + if (mme_put (&request_ctx, + (void *) entry->group_mac_addr, + ETHER_ADDR_LEN, + &result_length) != MME_SUCCESS) + { + syslog (LOG_ERR, "failed to mme_put group mac address"); + return; + } + + result_length = 0; + if (mme_put (&request_ctx, + (void *) &entry->member_count, + sizeof (uint8_t), + &result_length) != MME_SUCCESS) + { + syslog (LOG_ERR, "failed to mme_put member count"); + return; + } + + uint8_t member_idx; + for (member_idx = 0; member_idx < entry->member_count; member_idx++) + { + result_length = 0; + if (mme_put (&request_ctx, + (void *) &entry->members_mac_addr[member_idx], + ETHER_ADDR_LEN, + &result_length) != MME_SUCCESS) + { + syslog (LOG_ERR, "failed to mme_put member mac address"); + return; + } + } + } + + syslog (LOG_INFO, "sending MCAST MME..."); + uint8_t confirm_result; + if (plcd_send_recv_drv_mme (ctx, &request_ctx, &confirm_ctx, NULL) == -1) + { + syslog (LOG_ERR, "send recv drv mme failed"); + return; + } + if (mme_pull (&confirm_ctx, &confirm_result, sizeof (confirm_result), &result_length) != MME_SUCCESS) + { + syslog (LOG_WARNING, "mme pull failed"); + return; + } + if (confirm_result != MME_RESULT_SUCCESS) + { + syslog (LOG_ERR, "confirmation result not successful: %d", confirm_result); + return; + } + + syslog (LOG_INFO, "sent successfully"); +} + +libspid_boolean_t +plcd_multicast_info_updated (plcd_ctx_t *ctx) +{ + PLCD_ASSERT (ctx != NULL); + + struct stat file_stat; + memset (&file_stat, 0, sizeof (struct stat)); + + if (stat (LIBSPID_MULTICAST_INFO_PATH, &file_stat) == 0) + { + /* >= instead of > because the precision is up to the second. + * If we use >, we may miss an update that happened in the same second + * as the last check but a few millisecondes later. + * e.g: last_check at 345.00 secondes and update at 345.9999 seconds. + * The downside is that we may process many times the same file if + * multiple signals arrive in the same second as the last_check.*/ + if (file_stat.st_mtime >= ctx->mcast_last_check) + { + return LIBSPID_TRUE; + } + } + else + { + syslog (LOG_ERR, "stat: %s", strerror (errno)); + } + + return LIBSPID_FALSE; +} + +/** + * Read multicast info from the file, and update last_check value. + * \param mcast_info The multicast_info structure to fill with data from + * the file. + * \param mcast_last_check The last_check value to update if the file is + * successfully read. + */ +static void +plcd_multicast_read_file (libspid_multicast_info_t *mcast_info, + time_t *mcast_last_check) +{ + PLCD_ASSERT (mcast_info != NULL); + PLCD_ASSERT (mcast_last_check != NULL); + + /* Record the time just _before_ reading from the file. + * If we record the time after reading from the file, we could miss + * an update of the file that happened during the read. */ + time_t last_file_check = time (NULL); + + libspid_multicast_info_read_status_t read_status; + + libspid_error_t status = + libspid_multicast_info_read_file (mcast_info, &read_status); + + if (status == LIBSPID_SUCCESS) + { + /* We timestamp only if we were able to read the file. + * We don't update ctx->mcast_last_check on MCAST_READ_ERROR, + * because if we do, that will prevent us from reading the file + * again later. + * We do want to try again later, in case the error was a one + * time anomaly. */ + *mcast_last_check = last_file_check; + + if ((read_status & LIBSPID_MULTICAST_INFO_READ_TOO_MANY_GROUPS) != 0) + { + syslog (LOG_WARNING, "too many multicast groups"); + } + + if ((read_status & LIBSPID_MULTICAST_INFO_READ_TOO_MANY_MEMBERS) != 0) + { + syslog (LOG_WARNING, "too many members in group"); + } + } + else + { + if (status == LIBSPID_ERROR_PROCESSING) + { + if ((read_status & LIBSPID_MULTICAST_INFO_READ_EMPTY_GROUP) != 0) + { + syslog (LOG_ERR, "group with no members"); + } + + if ((read_status & LIBSPID_MULTICAST_INFO_READ_NOT_MULTICAST_ADDR) + != 0) + { + syslog (LOG_ERR, "not a multicast mac address"); + } + + if ((read_status & LIBSPID_MULTICAST_INFO_READ_PARSING_ERROR) != 0) + { + syslog (LOG_ERR, "parsing error"); + } + } + else if (status == LIBSPID_ERROR_SYSTEM) + { + syslog (LOG_ERR, "%s", strerror(errno)); + } + else + { + syslog (LOG_ERR, "libspid returned: %d", (int) status); + } + } +} + +void +plcd_multicast_process (plcd_ctx_t *ctx) +{ + PLCD_ASSERT (ctx != NULL); + + libspid_multicast_info_t *mcast_info = + malloc (sizeof (libspid_multicast_info_t)); + + if (mcast_info != NULL) + { + plcd_multicast_read_file (mcast_info, &ctx->mcast_last_check); + } + + /* If an error occured, (mcast_info == NULL) or + * (mcast_info->entry_count == 0). + * So as a precaution, the multicast info will be cleared. + * This will make Cesar stop its filtering. */ + + /* Send the info to Cesar */ + plcd_multicast_send_info (ctx, mcast_info); + + free (mcast_info); +} diff --git a/cleopatre/devkit/plcd/src/plcd_process.c b/cleopatre/devkit/plcd/src/plcd_process.c index 13a36208a7..1f953614e6 100644 --- a/cleopatre/devkit/plcd/src/plcd_process.c +++ b/cleopatre/devkit/plcd/src/plcd_process.c @@ -655,8 +655,8 @@ plcd_process_signal (plcd_ctx_t *ctx) } /* mcast.info */ - if (plcd_mcast_info_updated (ctx) == LIBSPID_TRUE) + if (plcd_multicast_info_updated (ctx) == LIBSPID_TRUE) { - plcd_mcast_process (ctx); + plcd_multicast_process (ctx); } } -- cgit v1.2.3