FD.io VPP  v21.06
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
24 ip6_nd_proxy_add_del (u32 sw_if_index, const ip6_address_t * addr, u8 is_del)
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_address_t ip = {
56  .ip = nh,
57  .version = AF_IP6,
58  };
59  ip_neighbor_del (&ip, sw_if_index);
60  }
61  else
62  {
63  fib_table_entry_path_add (fib_index,
64  &pfx,
68  &nh,
69  sw_if_index,
70  ~0, 1, NULL, FIB_ROUTE_PATH_FLAG_NONE);
71  }
72  return (0);
73 }
74 
75 int
76 ip6_nd_proxy_add (u32 sw_if_index, const ip6_address_t * addr)
77 {
78  return (ip6_nd_proxy_add_del (sw_if_index, addr, 0));
79 }
80 
81 int
82 ip6_nd_proxy_del (u32 sw_if_index, const ip6_address_t * addr)
83 {
84  return (ip6_nd_proxy_add_del (sw_if_index, addr, 1));
85 }
86 
87 static clib_error_t *
89  unformat_input_t * input, vlib_cli_command_t * cmd)
90 {
91  vnet_main_t *vnm = vnet_get_main ();
92  clib_error_t *error = 0;
93  ip6_address_t addr;
95  u8 is_del = 0;
96 
97  if (unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
98  {
99  /* get the rest of the command */
101  {
102  if (unformat (input, "%U", unformat_ip6_address, &addr))
103  break;
104  else if (unformat (input, "delete") || unformat (input, "del"))
105  is_del = 1;
106  else
107  return (unformat_parse_error (input));
108  }
109  }
110 
111  ip6_nd_proxy_add_del (sw_if_index, &addr, is_del);
112 
113  return error;
114 }
115 
116 /* *INDENT-OFF* */
117 VLIB_CLI_COMMAND (set_ip6_nd_proxy_command, static) =
118 {
119  .path = "set ip6 nd proxy",
120  .short_help = "set ip6 nd proxy <interface> [del] <host-ip>",
121  .function = set_ip6_nd_proxy_cmd,
122 };
123 /* *INDENT-ON* */
124 
125 /*
126  * fd.io coding-style-patch-verification: ON
127  *
128  * Local Variables:
129  * eval: (c-set-style "gnu")
130  * End:
131  */
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:558
vl_api_fib_path_nh_t nh
Definition: fib_types.api:126
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:88
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:130
int ip_neighbor_del(const ip_address_t *ip, u32 sw_if_index)
Definition: ip_neighbor.c:574
unsigned char u8
Definition: types.h:56
unsigned int u32
Definition: types.h:88
Aggregate type for a prefix.
Definition: fib_types.h:202
vnet_main_t * vnet_get_main(void)
u16 fp_len
The mask length.
Definition: fib_types.h:206
u32 ip6_fib_table_get_index_for_sw_if_index(u32 sw_if_index)
Definition: ip6_fib.c:353
Definition: fib_entry.h:112
Definition: cJSON.c:88
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
struct _unformat_input_t unformat_input_t
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
unformat_function_t unformat_ip6_address
Definition: format.h:89
#define UNFORMAT_END_OF_INPUT
Definition: format.h:137
int ip6_nd_proxy_del(u32 sw_if_index, const ip6_address_t *addr)
Definition: ip6_nd_proxy.c:82
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:163
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:731
#define unformat_parse_error(input)
Definition: format.h:261
IPv6 Proxy ND.
Definition: fib_source.h:95
vl_api_address_t ip
Definition: l2.api:558
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:163
int ip6_nd_proxy_add(u32 sw_if_index, const ip6_address_t *addr)
Definition: ip6_nd_proxy.c:76