/*
* Copyright (c) 2015 Cisco and/or its affiliates.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __included_vnet_l2_input_classify_h__
#define __included_vnet_l2_input_classify_h__
#include <vlib/vlib.h>
#include <vnet/vnet.h>
#include <vnet/pg/pg.h>
#include <vnet/ethernet/ethernet.h>
#include <vnet/ethernet/packet.h>
#include <vnet/ip/ip_packet.h>
#include <vnet/ip/ip4_packet.h>
#include <vnet/ip/ip6_packet.h>
#include <vlib/cli.h>
#include <vnet/l2/l2_input.h>
#include <vnet/l2/l2_output.h>
#include <vnet/l2/feat_bitmap.h>
#include <vppinfra/error.h>
#include <vppinfra/hash.h>
#include <vppinfra/cache.h>
#include <vnet/classify/vnet_classify.h>
typedef enum
{
L2_INPUT_CLASSIFY_NEXT_DROP,
L2_INPUT_CLASSIFY_NEXT_ETHERNET_INPUT,
L2_INPUT_CLASSIFY_NEXT_IP4_INPUT,
L2_INPUT_CLASSIFY_NEXT_IP6_INPUT,
L2_INPUT_CLASSIFY_NEXT_LI,
L2_INPUT_CLASSIFY_N_NEXT,
} l2_input_classify_next_t;
typedef enum
{
L2_INPUT_CLASSIFY_TABLE_IP4,
L2_INPUT_CLASSIFY_TABLE_IP6,
L2_INPUT_CLASSIFY_TABLE_OTHER,
L2_INPUT_CLASSIFY_N_TABLES,
} l2_input_classify_table_id_t;
typedef enum
{
L2_OUTPUT_CLASSIFY_NEXT_DROP,
L2_OUTPUT_CLASSIFY_N_NEXT,
} l2_output_classify_next_t;
typedef enum
{
L2_OUTPUT_CLASSIFY_TABLE_IP4,
L2_OUTPUT_CLASSIFY_TABLE_IP6,
L2_OUTPUT_CLASSIFY_TABLE_OTHER,
L2_OUTPUT_CLASSIFY_N_TABLES,
} l2_output_classify_table_id_t;
typedef struct _l2_classify_main
{
/* Next nodes for L2 input and output features */
u32 l2_inp_feat_next[32];
u32 l2_out_feat_next[32];
/* Per-address-family classifier table vectors */
u32 *classify_table_index_by_sw_if_index[L2_INPUT_CLASSIFY_N_TABLES];
/* convenience variables */
vlib_main_t *vlib_main;
vnet_main_t *vnet_main;
vnet_classify_main_t *vnet_classify_main;
} l2_input_classify_main_t;
typedef struct _l2_classify_main l2_output_classify_main_t;
extern l2_input_classify_main_t l2_input_classify_main;
extern vlib_node_registration_t l2_input_classify_node;
extern l2_output_classify_main_t
@media only all and (prefers-color-scheme: dark) {
.highlight .hll { background-color: #49483e }
.highlight .c { color: #75715e } /* Comment */
.highlight .err { color: #960050; background-color: #1e0010 } /* Error */
.highlight .k { color: #66d9ef } /* Keyword */
.highlight .l { color: #ae81ff } /* Literal */
.highlight .n { color: #f8f8f2 } /* Name */
.highlight .o { color: #f92672 } /* Operator */
.highlight .p { color: #f8f8f2 } /* Punctuation */
.highlight .ch { color: #75715e } /* Comment.Hashbang */
.highlight .cm { color: #75715e } /* Comment.Multiline */
.highlight .cp { color: #75715e } /* Comment.Preproc */
.highlight .cpf { color: #75715e } /* Comment.PreprocFile */
.highlight .c1 { color: #75715e } /* Comment.Single */
.highlight .cs { color: #75715e } /* Comment.Special */
.highlight .gd { color: #f92672 } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gi { color: #a6e22e } /* Generic.Inserted */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #75715e } /* Generic.Subheading */
.highlight .kc { color: #66d9ef } /* Keyword.Constant */
.highlight .kd { color: #66d9ef } /* Keyword.Declaration */
.highlight .kn { color: #f92672 } /* Keyword.Namespace */
.highlight .kp { color: #66d9ef } /* Keyword.Pseudo */
.highlight .kr { color: #66d9ef } /* Keyword.Reserved */
.highlight .kt { color: #66d9ef } /* Keyword.Type */
.highlight .ld { color: #e6db74 } /* Literal.Date */
.highlight .m { color: #ae81ff } /* Literal.Number */
.highlight .s { color: #e6db74 } /* Literal.String */
.highlight .na { color: #a6e22e } /* Name.Attribute */
.highlight .nb { color: #f8f8f2 } /* Name.Builtin */
.highlight .nc { color: #a6e22e } /* Name.Class */
.highlight .no { color: #66d9ef } /* Name.Constant */
.highlight .nd { color: #a6e22e } /* Name.Decorator */
.highlight .ni { color: #f8f8f2 } /* Name.Entity */
.highlight .ne { color: #a6e22e } /* Name.Exception */
.highlight .nf { color: #a6e22e } /* Name.Function */
.highlight .nl { color: #f8f8f2 } /* Name.Label */
.highlight .nn { color: #f8f8f2 } /* Name.Namespace */
.highlight .nx { color: #a6e22e } /* Name.Other */
.highlight .py { color: #f8f8f2 } /* Name.Property */
.highlight .nt { color: #f92672 } /* Name.Tag */
.highlight .nv { color: #f8f8f2 } /* Name.Variable */
.highlight .ow { color: #f92672 } /* Operator.Word */
.highlight .w { color: #f8f8f2 } /* Text.Whitespace */
.highlight .mb { color: #ae81ff } /* Literal.Number.Bin */
.highlight .mf { color: #ae81ff } /* Literal.Number.Float */
.highlight .mh { color: #ae81ff } /* Literal.Number.Hex */
.highlight .mi { color: #ae81ff } /* Literal.Number.Integer */
.highlight .mo { color: #ae81ff } /* Literal.Number.Oct */
.highlight .sa { color: #e6db74 } /* Literal.String.Affix */
.highlight .sb { color: #e6db74 } /* Literal.String.Backtick */
.highlight .sc { color: #e6db74 } /* Literal.String.Char */
.highlight .dl { color: #e6db74 } /* Literal.String.Delimiter */
.highlight .sd { color: #e6db74 } /* Literal.String.Doc */
.highlight .s2 { color: #e6db74 } /* Literal.String.Double */
.highlight .se { color: #ae81ff } /* Literal.String.Escape */
.highlight .sh { color: #e6db74 } /* Literal.String.Heredoc */
.highlight .si { color: #e6db74 } /* Literal.String.Interpol */
.highlight .sx { color: #e6db74 } /* Literal.String.Other */
.highlight .sr { color: #e6db74 } /* Literal.String.Regex */
.highlight .s1 { color: #e6db74 } /* Literal.String.Single */
.highlight .ss { color: #e6db74 } /* Literal.String.Symbol */
.highlight .bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #a6e22e } /* Name.Function.Magic */
.highlight .vc { color: #f8f8f2 } /* Name.Variable.Class */
.highlight .vg { color: #f8f8f2 } /* Name.Variable.Global */
.highlight .vi { color: #f8f8f2 } /* Name.Variable.Instance */
.highlight .vm { color: #f8f8f2 } /* Name.Variable.Magic */
.highlight .il { color: #ae81ff } /* Literal.Number.Integer.Long */
}
@media (prefers-color-scheme: light) {
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */
.highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */
.highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */
.highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */
.highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */
.highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */
.highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */
.highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */
.highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */
.highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */
.highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */
.highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */
.highlight .vc { color: #336699 } /* Name.Variable.Class */
.highlight .vg { color: #dd7700 } /* Name.Variable.Global */
.highlight .vi { color: #3333bb } /* Name.Variable.Instance */
.highlight .vm { color: #336699 } /* Name.Variable.Magic */
.highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
}
/*
*------------------------------------------------------------------
* Copyright (c) 2017 Cisco and/or its affiliates.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*------------------------------------------------------------------
*/
#include <vlib/vlib.h>
#include <vnet/plugin/plugin.h>
#include <vpp/app/version.h>
#include <vnet/ip/ip.h>
#include <vlib/unix/unix.h>
#include <vnet/adj/adj_mcast.h>
#include <igmp/igmp.h>
#include <igmp/error.h>
#include <limits.h>
/* TODO: mld...
typedef enum
{
MLD_INPUT_NEXT_DROP,
...
} mld_input_next_t;
*/
typedef enum
{
IGMP_INPUT_NEXT_DROP,
IGMP_INPUT_NEXT_PARSE_QUERY,
IGMP_INPUT_NEXT_PARSE_REPORT,
IGMP_INPUT_N_NEXT,
} igmp_input_next_t;
typedef enum
{
IGMP_PARSE_QUERY_NEXT_DROP,
IGMP_PARSE_QUERY_N_NEXT,
} igmp_parse_query_next_t;
typedef enum
{
IGMP_PARSE_REPORT_NEXT_DROP,
IGMP_PARSE_REPORT_N_NEXT,
} igmp_parse_report_next_t;
char *igmp_error_strings[] = {
#define _(sym,string) string,
foreach_igmp_error
#undef _
};
typedef struct
{
u32 next_index;
u32 sw_if_index;
u8 packet_data[64];
} igmp_input_trace_t;
static u8 *
format_igmp_input_trace (u8 * s, va_list * va)
{
CLIB_UNUSED (vlib_main_t * vm) = va_arg (*va, vlib_main_t *);
CLIB_UNUSED (vlib_node_t * node) = va_arg (*va, vlib_node_t *);
igmp_input_trace_t *t = va_arg (*va, igmp_input_trace_t *);
s =
format (s, "sw_if_index %u next-index %u", t->sw_if_index, t->next_index);
s =
format (s, "\n%U", format_igmp_header, t->packet_data,
sizeof (t->packet_data));
return s;
}
static u8 *
format_igmp_parse_report_trace (u8 * s, va_list * va)
{
CLIB_UNUSED (vlib_main_t * vm) = va_arg (*va, vlib_main_t *);
CLIB_UNUSED (vlib_node_t * node) = va_arg (*va, vlib_node_t *);
igmp_input_trace_t *t = va_arg (*va, igmp_input_trace_t *);
s =
format (s, "sw_if_index %u next-index %u", t->sw_if_index, t->next_index);
s =
format (s, "\n%U", format_igmp_report_v3, t->packet_data,
sizeof (t->packet_data));
return s;
}
static u8 *
format_igmp_parse_query_trace (u8 * s, va_list * va)
{
CLIB_UNUSED (vlib_main_t * vm) = va_arg (*va, vlib_main_t *);
CLIB_UNUSED (vlib_node_t * node) = va_arg (*va, vlib_node_t *);
igmp_input_trace_t *t = va_arg (*va, igmp_input_trace_t *);
s =
format (s, "sw_if_index %u next-input %u", t->sw_if_index, t->next_index);
s =
format (s, "\n%U", format_igmp_query_v3, t->packet_data,
sizeof (t->packet_data));
return s;
}
uword
igmp_input (vlib_main_t * vm, vlib_node_runtime_t * node,
vlib_frame_t * frame)
{
IGMP_DBG ("IGMP_INPUT");
u32 n_left_from, *from, *to_next;
igmp_parse_query_next_t next_index;
vlib_node_runtime_t *error_node =
vlib_node_get_runtime (vm, igmp_input_node.index);
u8 error;
ip_csum_t sum;
u16 csum;
error = IGMP_ERROR_NONE;
from = vlib_frame_vector_args (frame);
n_left_from = frame->n_vectors;
next_index = node->cached_next_index;
while (n_left_from > 0)
{
u32 n_left_to_next;
vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
while (n_left_from > 0 && n_left_to_next > 0)
{
vlib_buffer_t *b;
ip4_header_t *ip;
u32 bi, next;
next = IGMP_INPUT_NEXT_DROP;
bi = from[0];
to_next[0] = bi;
from++;
to_next++;
n_left_from--;
n_left_to_next--;
b = vlib_get_buffer (vm, bi);
ip = vlib_buffer_get_current (b);
if (ip->protocol != 2)
{
error = IGMP_ERROR_INVALID_PROTOCOL;
next = IGMP_INPUT_NEXT_DROP;
goto next_buffer;
}
vlib_buffer_advance (b, ip4_header_bytes (ip));
igmp_header_t *igmp = vlib_buffer_get_current (b);
u16 checksum = igmp->checksum;
igmp->checksum = 0;
sum = ip_incremental_checksum (0, igmp,
clib_net_to_host_u16 (ip->length) -
ip4_header_bytes (ip));
igmp->checksum = checksum;
csum = ~ip_csum_fold (sum);
if (checksum != csum)
{
error = IGMP_ERROR_BAD_CHECKSUM;
next = IGMP_INPUT_NEXT_DROP;
goto next_buffer;
}
/* TODO: IGMPv2 and IGMPv1 */
switch (igmp->type)
{
case IGMP_TYPE_membership_query:
next = IGMP_INPUT_NEXT_PARSE_QUERY;
break;
case IGMP_TYPE_membership_report_v3:
next = IGMP_INPUT_NEXT_PARSE_REPORT;
break;
default:
error = IGMP_ERROR_UNKNOWN_TYPE;
next = IGMP_INPUT_NEXT_DROP;
break;
}
next_buffer:
b->error = error_node->errors[error];
if (node->flags & VLIB_NODE_FLAG_TRACE)
{
igmp_input_trace_t *tr;
tr = vlib_add_trace (vm, node, b, sizeof (*tr));
tr->next_index = next;
tr->sw_if_index = vnet_buffer (b)->sw_if_index[VLIB_RX];
clib_memcpy (tr->packet_data, vlib_buffer_get_current (b),
sizeof (tr->packet_data));
}
vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
n_left_to_next, bi, next);
}
vlib_put_next_frame (vm, node, next_index, n_left_to_next);
}
return frame->n_vectors;
}
/* *INDENT-OFF* */
VLIB_REGISTER_NODE (igmp_input_node) =
{
.function = igmp_input,
.name = "igmp-input",
.vector_size = sizeof (u32),
.format_buffer = format_igmp_header,
.format_trace = format_igmp_input_trace,
.n_errors = IGMP_N_ERROR,
.error_strings = igmp_error_strings,
.n_next_nodes = IGMP_INPUT_N_NEXT,
.next_nodes = {
[IGMP_INPUT_NEXT_DROP] = "error-drop",
[IGMP_INPUT_NEXT_PARSE_QUERY] = "igmp-parse-query",
[IGMP_INPUT_NEXT_PARSE_REPORT] = "igmp-parse-report",
}
};
/* *INDENT-ON* */
uword
igmp_parse_query (vlib_main_t * vm, vlib_node_runtime_t * node,
vlib_frame_t * frame)
{
IGMP_DBG ("IGMP_PARSE_QUERY");
u32 n_left_from, *from, *to_next;
igmp_parse_query_next_t next_index;
igmp_main_t *im = &igmp_main;
igmp_config_t *config;
from = vlib_frame_vector_args (frame);
n_left_from = frame->n_vectors;
next_index = node->cached_next_index;
while (n_left_from > 0)
{
u32 n_left_to_next;
vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
while (n_left_from > 0 && n_left_to_next > 0)
{
vlib_buffer_t *b;
u32 sw_if_index, bi, next;
next = IGMP_PARSE_QUERY_NEXT_DROP;
bi = from[0];
to_next[0] = bi;
from++;
to_next++;
n_left_from--;
n_left_to_next--;
b = vlib_get_buffer (vm, bi);
sw_if_index = vnet_buffer (b)->sw_if_index[VLIB_RX];
igmp_membership_query_v3_t *igmp = vlib_buffer_get_current (b);
ASSERT (igmp->header.type == IGMP_TYPE_membership_query);
/* if group address is zero, this is a general query */
if (igmp->dst.as_u32 == 0)
{
config = igmp_config_lookup (im, sw_if_index);
if (!config)
{
IGMP_DBG ("No config on interface %u", sw_if_index);
}
else
{
/* WIP
*
* TODO: divide to multipe reports in random time range [now, max resp time]
*/
u32 seed = vlib_time_now (vm);
f64 next_resp_time = random_f64 (&seed) *
(f64) (igmp->header.code / 10) + vlib_time_now (vm);
config->flags |= IGMP_CONFIG_FLAG_CAN_SEND_REPORT;
igmp_create_int_timer (next_resp_time, sw_if_index,
igmp_send_report);
vlib_process_signal_event (vm,
igmp_timer_process_node.index,
IGMP_PROCESS_EVENT_UPDATE_TIMER,
0);
}
}
if (node->flags & VLIB_NODE_FLAG_TRACE)
{
igmp_input_trace_t *tr;
tr = vlib_add_trace (vm, node, b, sizeof (*tr));
tr->next_index = next;
tr->sw_if_index = vnet_buffer (b)->sw_if_index[VLIB_RX];
clib_memcpy (tr->packet_data, vlib_buffer_get_current (b),
sizeof (tr->packet_data));
}
vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
n_left_to_next, bi, next);
}
vlib_put_next_frame (vm, node, next_index, n_left_to_next);
}
return frame->n_vectors;
}
/* *INDENT-OFF* */
VLIB_REGISTER_NODE (igmp_parse_query_node) =
{
.function = igmp_parse_query,
.name = "igmp-parse-query",
.vector_size = sizeof (u32),
.format_buffer = format_igmp_query_v3,
.format_trace = format_igmp_parse_query_trace,
.n_errors = IGMP_N_ERROR,
.error_strings = igmp_error_strings,
.n_next_nodes = IGMP_PARSE_QUERY_N_NEXT,
.next_nodes = {
[IGMP_PARSE_QUERY_NEXT_DROP] = "error-drop",
}
};
/* *INDENT-ON* */
uword
igmp_parse_report (vlib_main_t * vm, vlib_node_runtime_t * node,
vlib_frame_t * frame)
{
IGMP_DBG ("IGMP_PARSE_REPORT");
igmp_main_t *im = &igmp_main;
u32 n_left_from, *from, *to_next;
igmp_input_next_t next_index;
igmp_config_t *config;
igmp_group_t *group;
igmp_src_t *src;
igmp_membership_group_v3_t *igmp_group;
ip4_address_t *src_addr;
igmp_key_t gkey;
igmp_key_t skey;
memset (&gkey, 0, sizeof (igmp_key_t));
memset (&skey, 0, sizeof (igmp_key_t));
ip46_address_t saddr;
memset (&saddr, 0, sizeof (ip46_address_t));
ip46_address_t gaddr;
memset (&gaddr, 0, sizeof (ip46_address_t));
u32 len;
vlib_node_runtime_t *error_node =
vlib_node_get_runtime (vm, igmp_input_node.index);
u8 error;
from = vlib_frame_vector_args (frame);
n_left_from = frame->n_vectors;
next_index = node->cached_next_index;
while (n_left_from > 0)
{
u32 n_left_to_next;
vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
while (n_left_from > 0 && n_left_to_next > 0)
{
vlib_buffer_t *b;
u32 sw_if_index, bi, next;
next = IGMP_PARSE_REPORT_NEXT_DROP;
bi = from[0];
to_next[0] = bi;
from++;
to_next++;
n_left_from--;
n_left_to_next--;
b = vlib_get_buffer (vm, bi);
error = IGMP_ERROR_NONE;
b->error = error_node->errors[error];
sw_if_index = vnet_buffer (b)->sw_if_index[VLIB_RX];
igmp_membership_report_v3_t *igmp = vlib_buffer_get_current (b);
ASSERT (igmp->header.type == IGMP_TYPE_membership_report_v3);
len = sizeof (igmp_membership_report_v3_t);
/* if interface (S,G)s were configured by CLI/API goto next frame */
config = igmp_config_lookup (im, sw_if_index);
if (config)
{
config->flags |= IGMP_CONFIG_FLAG_QUERY_RESP_RECVED;
if (config->cli_api_configured)
{
IGMP_DBG ("Interface %u has (S,G)s configured by CLI/API",
sw_if_index);
error = IGMP_ERROR_CLI_API_CONFIG;
b->error = error_node->errors[error];
goto next_frame;
}
}
IGMP_DBG ("interface %u", sw_if_index);
int i, j = 0;
for (i = 0; i < clib_net_to_host_u16 (igmp->n_groups); i++)
{
igmp_group = group_ptr (igmp, len);
src_addr = igmp_group->src_addresses;
if (igmp_group->type ==
IGMP_MEMBERSHIP_GROUP_mode_is_filter_include)
{
ip46_address_set_ip4 ((ip46_address_t *) & gkey.data,
&igmp_group->dst_address);
gkey.group_type =
IGMP_MEMBERSHIP_GROUP_mode_is_filter_include;
group = igmp_group_lookup (config, &gkey);
if (group)
{
for (j = 0;
j <
clib_net_to_host_u16 (igmp_group->n_src_addresses);
j++)
{
/* update (S,G) expiration timer */
ip46_address_set_ip4 ((ip46_address_t *) &
skey.data, src_addr);
src = igmp_src_lookup (group, &skey);
if (src)
src->exp_time =
vlib_time_now (vm) + IGMP_SRC_TIMER;
src_addr++;
}
}
}
else if (igmp_group->type ==
IGMP_MEMBERSHIP_GROUP_mode_is_filter_exclude)
{
for (j = 0;
j < clib_net_to_host_u16 (igmp_group->n_src_addresses);
j++)
{
/* nothing for now... */
src_addr++;
}
}
else if (igmp_group->type ==
IGMP_MEMBERSHIP_GROUP_change_to_filter_include)
{
for (j = 0;
j < clib_net_to_host_u16 (igmp_group->n_src_addresses);
j++)
{
/* add new (S,G) to interface */
saddr.ip4 = *src_addr;
gaddr.ip4 = igmp_group->dst_address;
igmp_listen (vm, 1, sw_if_index, saddr, gaddr, 0);
src_addr++;
}
}
else if (igmp_group->type ==
IGMP_MEMBERSHIP_GROUP_change_to_filter_exclude)
{
for (j = 0;
j < clib_net_to_host_u16 (igmp_group->n_src_addresses);
j++)
{
/* remove (S,G) from interface */
saddr.ip4 = *src_addr;
gaddr.ip4 = igmp_group->dst_address;
igmp_listen (vm, 0, sw_if_index, saddr, gaddr, 0);
src_addr++;
}
}
else if (igmp_group->type ==
IGMP_MEMBERSHIP_GROUP_allow_new_sources)
{
for (j = 0;
j < clib_net_to_host_u16 (igmp_group->n_src_addresses);
j++)
{
/* nothing for now... */
src_addr++;
}
}
else if (igmp_group->type ==
IGMP_MEMBERSHIP_GROUP_block_old_sources)
{
for (j = 0;
j < clib_net_to_host_u16 (igmp_group->n_src_addresses);
j++)
{
/* remove (S,G) from interface */
saddr.ip4 = *src_addr;
gaddr.ip4 = igmp_group->dst_address;
igmp_listen (vm, 0, sw_if_index, saddr, gaddr, 0);
src_addr++;
}
}
/*
* Unrecognized Record Type values MUST be silently ignored.
*/
/* move ptr to next Group Record */
len +=
sizeof (igmp_membership_group_v3_t) +
(sizeof (ip4_address_t) * j);
}
next_frame:
if (node->flags & VLIB_NODE_FLAG_TRACE)
{
igmp_input_trace_t *tr;
tr = vlib_add_trace (vm, node, b, sizeof (*tr));
tr->next_index = next;
tr->sw_if_index = vnet_buffer (b)->sw_if_index[VLIB_RX];
clib_memcpy (tr->packet_data, vlib_buffer_get_current (b),
sizeof (tr->packet_data));
}
vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
n_left_to_next, bi, next);
}
vlib_put_next_frame (vm, node, next_index, n_left_to_next);
}
return frame->n_vectors;
}
/* *INDENT-OFF* */
VLIB_REGISTER_NODE (igmp_parse_report_node) =
{
.function = igmp_parse_report,
.name = "igmp-parse-report",
.vector_size = sizeof (u32),
.format_buffer = format_igmp_report_v3,
.format_trace = format_igmp_parse_report_trace,
.n_errors = IGMP_N_ERROR,
.error_strings = igmp_error_strings,
.n_next_nodes = IGMP_PARSE_REPORT_N_NEXT,
.next_nodes = {
[IGMP_PARSE_REPORT_NEXT_DROP] = "error-drop",
}
};
/* *INDENT-ON* */
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/