/* * igmp_snoopd: an IGMP Snooping Daemon. * Copyright (C) 2011 SPiDCOM Technologies * * 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 Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "internal.h" #include #include #include "utils.h" /** * Extract the Max Response Time value from a query. * \param query The query. * \return The value of Max Response Time specified in the query. */ static duration_sec_t extract_max_resp_time (const struct igmphdr *query) { uint8_t max_response_time_10th_sec = query->code; /* Max Resp Time in the query is represented in units of 1/10 second, */ /* so we convert to seconds */ duration_sec_t max_response_time_sec = (duration_sec_t) (ceil ((double)max_response_time_10th_sec / 10.0)); return max_response_time_sec; } void process_v1_query () { log_debug ("v1 Query"); /* TODO: implement */ } void process_v1_report () { log_debug ("v1 report"); /* TODO: implement */ } void process_v2_query (struct context *ctx, struct igmphdr *igmp_header) { log_debug ("v2 Query"); ctx->metrics.last_query_time = time (NULL); if (igmp_header->group == 0) { log_debug ("General Query"); /* The metrics are only updated if it's a general query, * because a v2 Group-Specific query by its own is not enough to * indicate that the querier is now a v2 querier. It may be that a v3 * querier sent a v2 Group-Specific query because the concerned group * is in v2 Compatibility mode. In that case, the metrics should not be * reset to the defaults values. */ ctx->metrics.robustness_variable = DEFAULT_ROBUSTNESS_VARIABLE; ctx->metrics.query_interval = DEFAULT_QUERY_INTERVAL; ctx->metrics.query_response_interval = extract_max_resp_time (igmp_header); update_computed_metrics (&ctx->metrics); } else { log_debug ("Group-Specific Query"); } update_timer_query_tx (ctx); } void process_v2_report (struct context *ctx, const unsigned char host_eth_addr[ETH_ALEN], struct igmphdr *igmp_header) { log_debug ("v2 Join Report"); if (ignore_multicast_addr (igmp_header->group)) { log_debug ("Ignored"); return; } struct group *grp; struct group_member *member; find_or_add (&ctx->groups_head, &grp, igmp_header->group, &member, host_eth_addr); update_timers (grp, member, &ctx->metrics); time_t now = time (NULL); grp->v2_host_present_timer_end = now + ctx->metrics.older_host_present_interval; grp->last_v2_report_time = now; member->filter_mode = FILTER_MODE_EXCLUDE; group_member_set_sources (member, NULL, 0); } void process_v2_leave (struct context *ctx, const unsigned char host_eth_addr[ETH_ALEN], struct igmphdr *igmp_header) { log_debug ("v2 Leave Report"); if (ignore_multicast_addr (igmp_header->group)) { log_debug ("Ignored"); return; } struct group *grp = find_group (&ctx->groups_head, igmp_header->group); if (grp == NULL) { /* It's a leave for a group we didn't know about. * Nothing to do then. */ return; } struct group_member *member = find_member (grp, host_eth_addr); if (member == NULL) { /* It's a leave from a member we didn't know about. * Nothing to do then. */ return; } member->filter_mode = FILTER_MODE_INCLUDE; group_member_set_sources(member, NULL, 0); trim(grp, member); }