summaryrefslogtreecommitdiffstats
path: root/src/plugins/pppoe/pppoe_cp.c
blob: b99bf79679d2ba1e125cc79d8e5a5dac8cebbc28 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
 *------------------------------------------------------------------
 * Copyright (c) 2017 Intel 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 <pppoe/pppoe.h>

static clib_error_t *
pppoe_add_del_cp_command_fn (vlib_main_t * vm,
			     unformat_input_t * input,
			     vlib_cli_command_t * cmd)
{
  unformat_input_t _line_input, *line_input = &_line_input;
  pppoe_main_t *pem = &pppoe_main;
  u8 is_add = 1;
  u8 cp_if_index_set = 0;
  u32 cp_if_index = 0;
  clib_error_t *error = NULL;

  /* Get a line of input. */
  if (!unformat_user (input, unformat_line_input, line_input))
    return 0;

  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
    {
      if (unformat (line_input, "del"))
	{
	  is_add = 0;
	}
      else if (unformat (line_input, "cp-if-index %d", &cp_if_index))
	cp_if_index_set = 1;
      else
	{
	  error = clib_error_return (0, "parse error: '%U'",
				     format_unformat_error, line_input);
	  goto done;
	}
    }

  if (cp_if_index_set == 0)
    {
      error = clib_error_return (0, "cp if index not specified");
      goto done;
    }

  if (is_add)
    {
      pem->cp_if_index = cp_if_index;
    }
  else
    {
      pem->cp_if_index = ~0;
    }

done:
  unformat_free (line_input);

  return error;
}

/* *INDENT-OFF* */
VLIB_CLI_COMMAND (create_pppoe_cp_cmd, static) =
{
    .path = "create pppoe cp",
    .short_help = "create pppoe cp if-name <intfc> [del]",
    .function = pppoe_add_del_cp_command_fn,
};
/* *INDENT-ON* */

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */
; } u8 * format_igmp_filter_mode (u8 * s, va_list * args) { igmp_filter_mode_t mode = va_arg (*args, igmp_filter_mode_t); switch (mode) { #define _(n,f) case IGMP_FILTER_MODE_##f: return (format (s, "%s", #f)); foreach_igmp_filter_mode #undef _ } return (format (s, "unknown:%d", mode)); } u8 * format_igmp_mode (u8 * s, va_list * args) { igmp_mode_t mode = va_arg (*args, igmp_mode_t); switch (mode) { #define _(n,f) case IGMP_MODE_##f: return (format (s, "%s", #f)); foreach_igmp_mode #undef _ } return (format (s, "unknown:%d", mode)); } u8 * format_igmp_header (u8 * s, va_list * args) { igmp_header_t *hdr = va_arg (*args, igmp_header_t *); u32 max_header_bytes = va_arg (*args, u32); u32 indent; if (max_header_bytes < sizeof (hdr[0])) return format (s, "IGMP header truncated"); indent = format_get_indent (s); indent += 2; s = format (s, "%U%U: code %u, checksum 0x%04x", format_white_space, indent, format_igmp_type, hdr->type, hdr->code, clib_net_to_host_u16 (hdr->checksum)); return s; } u8 * format_igmp_report_v3 (u8 * s, va_list * args) { igmp_membership_report_v3_t *igmp = va_arg (*args, igmp_membership_report_v3_t *); u32 max_header_bytes = va_arg (*args, u32); igmp_membership_group_v3_t *group; u32 len = sizeof (igmp_membership_report_v3_t); u32 indent; if (max_header_bytes < sizeof (igmp[0])) return format (s, "IGMP report truncated"); indent = format_get_indent (s); indent += 2; s = format (s, "%Un_groups %u", format_white_space, indent, clib_net_to_host_u16 (igmp->n_groups)); indent += 2; int i, j = 0; for (i = 0; i < clib_net_to_host_u16 (igmp->n_groups); i++) { group = group_ptr (igmp, len); s = format (s, "\n%U%U: %U, sources %u", format_white_space, indent, format_igmp_membership_group_type, group->type, format_ip4_address, &group->group_address, clib_net_to_host_u16 (group->n_src_addresses)); indent += 2; for (j = 0; j < clib_net_to_host_u16 (group->n_src_addresses); j++) { s = format (s, "\n%U%U", format_white_space, indent, format_ip4_address, &group->src_addresses[j]); } indent -= 2; len += sizeof (igmp_membership_group_v3_t) + (sizeof (ip4_address_t) * clib_net_to_host_u16 (group->n_src_addresses)); } return s; } u8 * format_igmp_query_v3 (u8 * s, va_list * args) { igmp_membership_query_v3_t *igmp = va_arg (*args, igmp_membership_query_v3_t *); u32 max_header_bytes = va_arg (*args, u32); u32 indent; int i; if (max_header_bytes < sizeof (igmp[0])) return format (s, "IGMP query truncated"); indent = format_get_indent (s); indent += 2; ip4_address_t tmp; tmp.as_u32 = 0; if ((!ip4_address_compare (&igmp->group_address, &tmp)) && (igmp->n_src_addresses == 0)) s = format (s, "%UGeneral Query", format_white_space, indent); else if (igmp->n_src_addresses == 0) s = format (s, "%UGroup-Specific Query: %U", format_white_space, indent, format_ip4_address, &igmp->group_address); else { s = format (s, "%UGroup-and-Source-Specific Query: %U", format_white_space, indent, format_ip4_address, &igmp->group_address); indent += 2; for (i = 0; i < clib_net_to_host_u16 (igmp->n_src_addresses); i++) { s = format (s, "\n%U%U", format_white_space, indent, format_ip4_address, &igmp->src_addresses[i]); } } return s; } u8 * format_igmp_src_addr_list (u8 * s, va_list * args) { ip46_address_t *ss, *srcs; srcs = va_arg (*args, ip46_address_t *); s = format (s, "["); vec_foreach (ss, srcs) { s = format (s, "%U ", format_ip46_address, ss, IP46_TYPE_ANY); } s = format (s, "]"); return (s); } u8 * format_igmp_key (u8 * s, va_list * args) { const igmp_key_t *key = va_arg (*args, const igmp_key_t *); s = format (s, "%U", format_ip46_address, key, IP46_TYPE_ANY); return (s); } u8 * format_igmp_proxy_device_id (u8 * s, va_list * args) { u32 id = va_arg (*args, u32); s = (id == ~0) ? s : format (s, "proxy device: %u", id); return (s); } /* * fd.io coding-style-patch-verification: ON * * Local Variables: * eval: (c-set-style "gnu") * End: */