FD.io VPP  v19.04.4-rc0-5-ge88582fac
Vector Packet Processing
igmp_ssm_range.c
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * Copyright (c) 2017 Cisco and/or its affiliates.
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *------------------------------------------------------------------
16  */
17 
18 #include <igmp/igmp_ssm_range.h>
19 
20 typedef struct igmp_group_prefix_t
21 {
25 
27 
28 u8 *
29 format_igmp_group_prefix_type (u8 * s, va_list * args)
30 {
31  igmp_group_prefix_type_t type = va_arg (*args, int);
32 
33  switch (type)
34  {
35 #define _(n,f) case IGMP_GROUP_PREFIX_TYPE_##f: return (format (s, "%s", #f));
37 #undef _
38  }
39  return format (s, "unknown:%d", type);
40 }
41 
42 static int
44  const fib_prefix_t * p)
45 {
46  return (fib_prefix_cmp (&gp1->igp_prefix, p));
47 }
48 
49 void
52 {
53  u32 pos;
54 
55  pos =
56  vec_search_with_function (igmp_group_prefixs, pfx, igmp_group_prefix_cmp);
57 
58  if ((~0 == pos) && (IGMP_GROUP_PREFIX_TYPE_SSM == type))
59  {
60  igmp_group_prefix_t gp = {
61  .igp_prefix = *pfx,
62  .igp_type = type,
63  };
64 
65  vec_add1 (igmp_group_prefixs, gp);
66  }
67  if ((~0 != pos) && (IGMP_GROUP_PREFIX_TYPE_ASM == type))
68  {
69  vec_del1 (igmp_group_prefixs, pos);
70  }
71 }
72 
73 static void
75 {
76  igmp_group_prefix_t *ssm_default;
77 
78  vec_add2 (igmp_group_prefixs, ssm_default, 1);
79 
80  ssm_default->igp_prefix.fp_addr.ip4.as_u32 = IGMP_SSM_DEFAULT;
81  ssm_default->igp_prefix.fp_proto = FIB_PROTOCOL_IP4;
82  ssm_default->igp_prefix.fp_len = 8;
83  ssm_default->igp_type = IGMP_GROUP_PREFIX_TYPE_SSM;
84 }
85 
87 igmp_group_prefix_get_type (const ip46_address_t * gaddr)
88 {
90 
91  vec_foreach (igp, igmp_group_prefixs)
92  {
94  &gaddr->ip4,
95  &igp->igp_prefix.fp_addr.ip4,
96  igp->igp_prefix.fp_len))
97  return (IGMP_GROUP_PREFIX_TYPE_SSM);
98  }
99 
100  return (IGMP_GROUP_PREFIX_TYPE_ASM);
101 }
102 
103 void
105 {
106  igmp_group_prefix_t *igp;
107 
108  vec_foreach (igp, igmp_group_prefixs)
109  {
110  if (WALK_STOP == fn (&igp->igp_prefix, igp->igp_type, ctx))
111  break;
112  }
113 }
114 
115 static clib_error_t *
117  unformat_input_t * input, vlib_cli_command_t * cmd)
118 {
119  igmp_group_prefix_t *igp;
120 
121  vec_foreach (igp, igmp_group_prefixs)
122  {
123  vlib_cli_output (vm, "%U => %U",
126  }
127  return (NULL);
128 }
129 
130 /* *INDENT-OFF* */
131 VLIB_CLI_COMMAND (igmp_show_timers_command, static) = {
132  .path = "show igmp ssm-ranges",
133  .short_help = "show igmp ssm-ranges",
134  .function = igmp_ssm_range_show,
135 };
136 /* *INDENT-ON* */
137 
138 static clib_error_t *
140 {
141  clib_error_t *error;
142 
143  if ((error = vlib_call_init_function (vm, igmp_init)))
144  return error;
145 
147 
148  IGMP_DBG ("ssm-range-initialized");
149 
150  return (error);
151 }
152 
154 
155 
156 /*
157  * fd.io coding-style-patch-verification: ON
158  *
159  * Local Variables:
160  * eval: (c-set-style "gnu")
161  * End:
162  */
u8 * format_igmp_group_prefix_type(u8 *s, va_list *args)
fib_protocol_t fp_proto
protocol type
Definition: fib_types.h:212
static clib_error_t * igmp_ssm_range_init(vlib_main_t *vm)
void igmp_ssm_range_walk(igmp_ssm_range_walk_t fn, void *ctx)
#define NULL
Definition: clib.h:58
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:522
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
Definition: vec.h:560
static uword ip4_destination_matches_route(const ip4_main_t *im, const ip4_address_t *key, const ip4_address_t *dest, uword dest_length)
Definition: ip4.h:181
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
static clib_error_t * igmp_init(vlib_main_t *vm)
igmp initialization
Definition: igmp.c:480
unsigned char u8
Definition: types.h:56
#define IGMP_DBG(...)
Definition: igmp.h:38
igmp_group_prefix_type_t igmp_group_prefix_get_type(const ip46_address_t *gaddr)
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:163
u8 * format_fib_prefix(u8 *s, va_list *args)
Definition: fib_types.c:184
static void igmp_ssm_range_populate(void)
Aggregrate type for a prefix.
Definition: fib_types.h:203
#define IGMP_SSM_DEFAULT
Definition: igmp.h:53
unsigned int u32
Definition: types.h:88
u16 fp_len
The mask length.
Definition: fib_types.h:207
#define vlib_call_init_function(vm, x)
Definition: init.h:260
ip46_address_t fp_addr
The address type is not deriveable from the fp_addr member.
Definition: fib_types.h:226
long ctx[MAX_CONNS]
Definition: main.c:144
struct _unformat_input_t unformat_input_t
#define vec_del1(v, i)
Delete the element at index I.
Definition: vec.h:804
vlib_main_t * vm
Definition: buffer.c:312
#define vec_search_with_function(v, E, fn)
Search a vector for the index of the entry that matches.
Definition: vec.h:961
void igmp_group_prefix_set(const fib_prefix_t *pfx, igmp_group_prefix_type_t type)
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:155
static igmp_group_prefix_t * igmp_group_prefixs
int fib_prefix_cmp(const fib_prefix_t *p1, const fib_prefix_t *p2)
Compare two prefixes for equality.
Definition: fib_types.c:112
ip4_main_t ip4_main
Global ip4 main structure.
Definition: ip4_forward.c:905
enum igmp_group_prefix_type_t_ igmp_group_prefix_type_t
#define vec_foreach(var, vec)
Vector iterator.
walk_rc_t(* igmp_ssm_range_walk_t)(const fib_prefix_t *pfx, igmp_group_prefix_type_t type, void *ctx)
fib_prefix_t igp_prefix
static int igmp_group_prefix_cmp(const igmp_group_prefix_t *gp1, const fib_prefix_t *p)
igmp_group_prefix_type_t igp_type
struct igmp_group_prefix_t igmp_group_prefix_t
static clib_error_t * igmp_ssm_range_show(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:762