FD.io VPP  v20.01-48-g3e0dafb74
Vector Packet Processing
ip6_nd_proxy.c
Go to the documentation of this file.
1 /*
2  * ip/ip6_neighbor.c: IP6 neighbor handling
3  *
4  * Copyright (c) 2010 Cisco and/or its affiliates.
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #include <vnet/ip6-nd/ip6_nd.h>
20 
21 #include <vnet/fib/ip6_fib.h>
22 
23 static int
25 {
26  /* *INDENT-OFF* */
27  u32 fib_index;
28  fib_prefix_t pfx = {
29  .fp_len = 128,
30  .fp_proto = FIB_PROTOCOL_IP6,
31  .fp_addr = {
32  .ip6 = *addr,
33  },
34  };
35  ip46_address_t nh = {
36  .ip6 = *addr,
37  };
38  /* *INDENT-ON* */
39 
40  fib_index = ip6_fib_table_get_index_for_sw_if_index (sw_if_index);
41 
42  if (~0 == fib_index)
43  return VNET_API_ERROR_NO_SUCH_FIB;
44 
45  if (is_del)
46  {
47  fib_table_entry_path_remove (fib_index,
48  &pfx,
51  &nh,
52  sw_if_index,
54  /* flush the ND cache of this address if it's there */
55  ip_neighbor_del (&nh, IP46_TYPE_IP6, sw_if_index);
56  }
57  else
58  {
59  fib_table_entry_path_add (fib_index,
60  &pfx,
64  &nh,
65  sw_if_index,
67  }
68  return (0);
69 }
70 
71 int
73 {
74  return (ip6_nd_proxy_add_del (sw_if_index, addr, 0));
75 }
76 
77 int
79 {
80  return (ip6_nd_proxy_add_del (sw_if_index, addr, 1));
81 }
82 
83 static clib_error_t *
85  unformat_input_t * input, vlib_cli_command_t * cmd)
86 {
87  vnet_main_t *vnm = vnet_get_main ();
88  clib_error_t *error = 0;
91  u8 is_del = 0;
92 
93  if (unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
94  {
95  /* get the rest of the command */
97  {
98  if (unformat (input, "%U", unformat_ip6_address, &addr))
99  break;
100  else if (unformat (input, "delete") || unformat (input, "del"))
101  is_del = 1;
102  else
103  return (unformat_parse_error (input));
104  }
105  }
106 
107  ip6_nd_proxy_add_del (sw_if_index, &addr, is_del);
108 
109  return error;
110 }
111 
112 /* *INDENT-OFF* */
113 VLIB_CLI_COMMAND (set_ip6_nd_proxy_command, static) =
114 {
115  .path = "set ip6 nd proxy",
116  .short_help = "set ip6 nd proxy <HOST> <INTERFACE>",
117  .function = set_ip6_nd_proxy_cmd,
118 };
119 /* *INDENT-ON* */
120 
121 /*
122  * fd.io coding-style-patch-verification: ON
123  *
124  * Local Variables:
125  * eval: (c-set-style "gnu")
126  * End:
127  */
fib_node_index_t fib_table_entry_path_add(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source, fib_entry_flag_t flags, dpo_proto_t next_hop_proto, const ip46_address_t *next_hop, u32 next_hop_sw_if_index, u32 next_hop_fib_index, u32 next_hop_weight, fib_mpls_label_t *next_hop_labels, fib_route_path_flags_t path_flags)
Add one path to an entry (aka route) in the FIB.
Definition: fib_table.c:549
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
vl_api_fib_path_nh_t nh
Definition: fib_types.api:126
#define NULL
Definition: clib.h:58
static clib_error_t * set_ip6_nd_proxy_cmd(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: ip6_nd_proxy.c:84
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:989
unformat_function_t unformat_vnet_sw_interface
vhost_vring_addr_t addr
Definition: vhost_user.h:147
unsigned char u8
Definition: types.h:56
int ip_neighbor_del(const ip46_address_t *ip, ip46_type_t type, u32 sw_if_index)
Definition: ip_neighbor.c:543
vl_api_interface_index_t sw_if_index
Definition: gre.api:59
Aggregate type for a prefix.
Definition: fib_types.h:203
unsigned int u32
Definition: types.h:88
u16 fp_len
The mask length.
Definition: fib_types.h:207
u32 ip6_fib_table_get_index_for_sw_if_index(u32 sw_if_index)
Definition: ip6_fib.c:347
Definition: fib_entry.h:112
struct _unformat_input_t unformat_input_t
vlib_main_t * vm
Definition: in2out_ed.c:1810
unformat_function_t unformat_ip6_address
Definition: format.h:89
#define UNFORMAT_END_OF_INPUT
Definition: format.h:145
int ip6_nd_proxy_del(u32 sw_if_index, const ip6_address_t *addr)
Definition: ip6_nd_proxy.c:78
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:152
static int ip6_nd_proxy_add_del(u32 sw_if_index, const ip6_address_t *addr, u8 is_del)
Definition: ip6_nd_proxy.c:24
void fib_table_entry_path_remove(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source, dpo_proto_t next_hop_proto, const ip46_address_t *next_hop, u32 next_hop_sw_if_index, u32 next_hop_fib_index, u32 next_hop_weight, fib_route_path_flags_t path_flags)
remove one path to an entry (aka route) in the FIB.
Definition: fib_table.c:722
#define unformat_parse_error(input)
Definition: format.h:269
IPv6 Proxy ND.
Definition: fib_source.h:92
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:171
int ip6_nd_proxy_add(u32 sw_if_index, const ip6_address_t *addr)
Definition: ip6_nd_proxy.c:72