udp: fix csum computation when offload disabled
[vpp.git] / src / vnet / ip6-nd / ip6_nd_proxy.c
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>
19 #include <vnet/ip-neighbor/ip_neighbor.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   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   };
37
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 */
53       ip_address_t ip = {
54         .ip = nh,
55         .version = AF_IP6,
56       };
57       ip_neighbor_del (&ip, sw_if_index);
58     }
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
73 int
74 ip6_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
79 int
80 ip6_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
85 static clib_error_t *
86 set_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     }
108   else
109     {
110       return error;
111     }
112
113   ip6_nd_proxy_add_del (sw_if_index, &addr, is_del);
114
115   return error;
116 }
117
118 VLIB_CLI_COMMAND (set_ip6_nd_proxy_command, static) =
119 {
120   .path = "set ip6 nd proxy",
121   .short_help = "set ip6 nd proxy <interface> [del] <host-ip>",
122   .function = set_ip6_nd_proxy_cmd,
123 };
124
125 /*
126  * fd.io coding-style-patch-verification: ON
127  *
128  * Local Variables:
129  * eval: (c-set-style "gnu")
130  * End:
131  */