FD.io VPP  v21.10.1-2-g0a485f517
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 
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,
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  };
60  }
61  else
62  {
63  fib_table_entry_path_add (fib_index,
64  &pfx,
68  &nh,
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 
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 
112 
113  return error;
114 }
115 
116 /* *INDENT-OFF* */
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  */
ip_address
Definition: ip_types.h:79
fib_table_entry_path_add
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:563
unformat_user
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:989
vlib_cli_command_t::path
char * path
Definition: cli.h:96
ip6_nd_proxy_add
int ip6_nd_proxy_add(u32 sw_if_index, const ip6_address_t *addr)
Definition: ip6_nd_proxy.c:76
fib_prefix_t_::fp_len
u16 fp_len
The mask length.
Definition: fib_types.h:206
unformat_parse_error
#define unformat_parse_error(input)
Definition: format.h:261
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
unformat_input_t
struct _unformat_input_t unformat_input_t
addr
vhost_vring_addr_t addr
Definition: vhost_user.h:130
error
Definition: cJSON.c:88
unformat
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
set_ip6_nd_proxy_cmd
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
fib_table_entry_path_remove
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:736
vnet_get_main
vnet_main_t * vnet_get_main(void)
Definition: pnat_test_stubs.h:56
set_ip6_nd_proxy_command
static vlib_cli_command_t set_ip6_nd_proxy_command
(constructor) VLIB_CLI_COMMAND (set_ip6_nd_proxy_command)
Definition: ip6_nd_proxy.c:117
unformat_check_input
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:163
FIB_ENTRY_FLAG_NONE
@ FIB_ENTRY_FLAG_NONE
Definition: fib_entry.h:112
VLIB_CLI_COMMAND
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:163
nh
vl_api_fib_path_nh_t nh
Definition: fib_types.api:126
ip6_fib_table_get_index_for_sw_if_index
u32 ip6_fib_table_get_index_for_sw_if_index(u32 sw_if_index)
Definition: ip6_fib.c:353
ip_neighbor_del
int ip_neighbor_del(const ip_address_t *ip, u32 sw_if_index)
Definition: ip_neighbor.c:574
vnet_main_t
Definition: vnet.h:76
ip_neighbor.h
unformat_vnet_sw_interface
unformat_function_t unformat_vnet_sw_interface
Definition: interface_funcs.h:462
DPO_PROTO_IP6
@ DPO_PROTO_IP6
Definition: dpo.h:65
FIB_ROUTE_PATH_FLAG_NONE
@ FIB_ROUTE_PATH_FLAG_NONE
Definition: fib_types.h:332
u32
unsigned int u32
Definition: types.h:88
ip6_nd_proxy_del
int ip6_nd_proxy_del(u32 sw_if_index, const ip6_address_t *addr)
Definition: ip6_nd_proxy.c:82
FIB_SOURCE_IP6_ND_PROXY
@ FIB_SOURCE_IP6_ND_PROXY
IPv6 Proxy ND.
Definition: fib_source.h:95
FIB_PROTOCOL_IP6
@ FIB_PROTOCOL_IP6
Definition: fib_types.h:37
AF_IP6
@ AF_IP6
Definition: ip_types.h:24
ip6_fib.h
vlib_main_t
Definition: main.h:102
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
ip
vl_api_address_t ip
Definition: l2.api:558
unformat_ip6_address
unformat_function_t unformat_ip6_address
Definition: format.h:89
vlib_cli_command_t
Definition: cli.h:92
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
fib_prefix_t_
Aggregate type for a prefix.
Definition: fib_types.h:202
ip6_nd.h
UNFORMAT_END_OF_INPUT
#define UNFORMAT_END_OF_INPUT
Definition: format.h:137
ip6_nd_proxy_add_del
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