blob: f7f07cb59f620209cfe07ecf6065bcd7cb167849 [file] [log] [blame]
Neale Rannscbe25aa2019-09-30 10:53:31 +00001/*
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>
19#include <vnet/ip-neighbor/ip_neighbor.h>
20
21#include <vnet/fib/ip6_fib.h>
22
23static int
24ip6_nd_proxy_add_del (u32 sw_if_index, const ip6_address_t * addr, u8 is_del)
25{
Neale Rannscbe25aa2019-09-30 10:53:31 +000026 u32 fib_index;
27 fib_prefix_t pfx = {
28 .fp_len = 128,
29 .fp_proto = FIB_PROTOCOL_IP6,
30 .fp_addr = {
31 .ip6 = *addr,
32 },
33 };
34 ip46_address_t nh = {
35 .ip6 = *addr,
36 };
Neale Rannscbe25aa2019-09-30 10:53:31 +000037
38 fib_index = ip6_fib_table_get_index_for_sw_if_index (sw_if_index);
39
40 if (~0 == fib_index)
41 return VNET_API_ERROR_NO_SUCH_FIB;
42
43 if (is_del)
44 {
45 fib_table_entry_path_remove (fib_index,
46 &pfx,
47 FIB_SOURCE_IP6_ND_PROXY,
48 DPO_PROTO_IP6,
49 &nh,
50 sw_if_index,
51 ~0, 1, FIB_ROUTE_PATH_FLAG_NONE);
52 /* flush the ND cache of this address if it's there */
Neale Rannsdc617b82020-08-20 08:22:56 +000053 ip_address_t ip = {
54 .ip = nh,
55 .version = AF_IP6,
56 };
57 ip_neighbor_del (&ip, sw_if_index);
Neale Rannscbe25aa2019-09-30 10:53:31 +000058 }
59 else
60 {
61 fib_table_entry_path_add (fib_index,
62 &pfx,
63 FIB_SOURCE_IP6_ND_PROXY,
64 FIB_ENTRY_FLAG_NONE,
65 DPO_PROTO_IP6,
66 &nh,
67 sw_if_index,
68 ~0, 1, NULL, FIB_ROUTE_PATH_FLAG_NONE);
69 }
70 return (0);
71}
72
73int
74ip6_nd_proxy_add (u32 sw_if_index, const ip6_address_t * addr)
75{
76 return (ip6_nd_proxy_add_del (sw_if_index, addr, 0));
77}
78
79int
80ip6_nd_proxy_del (u32 sw_if_index, const ip6_address_t * addr)
81{
82 return (ip6_nd_proxy_add_del (sw_if_index, addr, 1));
83}
84
85static clib_error_t *
86set_ip6_nd_proxy_cmd (vlib_main_t * vm,
87 unformat_input_t * input, vlib_cli_command_t * cmd)
88{
89 vnet_main_t *vnm = vnet_get_main ();
90 clib_error_t *error = 0;
91 ip6_address_t addr;
92 u32 sw_if_index;
93 u8 is_del = 0;
94
95 if (unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
96 {
97 /* get the rest of the command */
98 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
99 {
100 if (unformat (input, "%U", unformat_ip6_address, &addr))
101 break;
102 else if (unformat (input, "delete") || unformat (input, "del"))
103 is_del = 1;
104 else
105 return (unformat_parse_error (input));
106 }
107 }
Klement Sekera4450b032021-10-13 22:29:49 +0200108 else
109 {
110 return error;
111 }
Neale Rannscbe25aa2019-09-30 10:53:31 +0000112
113 ip6_nd_proxy_add_del (sw_if_index, &addr, is_del);
114
115 return error;
116}
117
Neale Rannscbe25aa2019-09-30 10:53:31 +0000118VLIB_CLI_COMMAND (set_ip6_nd_proxy_command, static) =
119{
120 .path = "set ip6 nd proxy",
Ignas Bacius59a78e92020-02-05 10:45:12 +0200121 .short_help = "set ip6 nd proxy <interface> [del] <host-ip>",
Neale Rannscbe25aa2019-09-30 10:53:31 +0000122 .function = set_ip6_nd_proxy_cmd,
123};
Neale Rannscbe25aa2019-09-30 10:53:31 +0000124
125/*
126 * fd.io coding-style-patch-verification: ON
127 *
128 * Local Variables:
129 * eval: (c-set-style "gnu")
130 * End:
131 */