wireguard: add ipv6 support
[vpp.git] / src / plugins / wireguard / wireguard.c
1 /*
2  * Copyright (c) 2020 Doc.ai and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16 #include <vnet/vnet.h>
17 #include <vnet/plugin/plugin.h>
18 #include <vpp/app/version.h>
19
20 #include <wireguard/wireguard_send.h>
21 #include <wireguard/wireguard_key.h>
22 #include <wireguard/wireguard_if.h>
23 #include <wireguard/wireguard.h>
24
25 wg_main_t wg_main;
26
27 static clib_error_t *
28 wg_init (vlib_main_t * vm)
29 {
30   wg_main_t *wmp = &wg_main;
31
32   wmp->vlib_main = vm;
33
34   wmp->in4_fq_index = vlib_frame_queue_main_init (wg4_input_node.index, 0);
35   wmp->in6_fq_index = vlib_frame_queue_main_init (wg6_input_node.index, 0);
36   wmp->out4_fq_index =
37     vlib_frame_queue_main_init (wg4_output_tun_node.index, 0);
38   wmp->out6_fq_index =
39     vlib_frame_queue_main_init (wg6_output_tun_node.index, 0);
40
41   vlib_thread_main_t *tm = vlib_get_thread_main ();
42
43   vec_validate_aligned (wmp->per_thread_data, tm->n_vlib_mains,
44                         CLIB_CACHE_LINE_BYTES);
45
46   wg_timer_wheel_init ();
47
48   return (NULL);
49 }
50
51 VLIB_INIT_FUNCTION (wg_init);
52
53 /* *INDENT-OFF* */
54
55 VNET_FEATURE_INIT (wg4_output_tun, static) = {
56   .arc_name = "ip4-output",
57   .node_name = "wg4-output-tun",
58   .runs_after = VNET_FEATURES ("gso-ip4"),
59 };
60
61 VNET_FEATURE_INIT (wg6_output_tun, static) = {
62   .arc_name = "ip6-output",
63   .node_name = "wg6-output-tun",
64   .runs_after = VNET_FEATURES ("gso-ip6"),
65 };
66
67 VLIB_PLUGIN_REGISTER () =
68 {
69   .version = VPP_BUILD_VER,
70   .description = "Wireguard Protocol",
71 };
72 /* *INDENT-ON* */
73
74 /*
75  * fd.io coding-style-patch-verification: ON
76  *
77  * Local Variables:
78  * eval: (c-set-style "gnu")
79  * End:
80  */