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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include <vnet/vnet.h>
17 #include <vnet/plugin/plugin.h>
18 #include <vpp/app/version.h>
19 #include <vnet/crypto/crypto.h>
21 #include <wireguard/wireguard_send.h>
22 #include <wireguard/wireguard_key.h>
23 #include <wireguard/wireguard_if.h>
24 #include <wireguard/wireguard.h>
27 wg_async_post_next_t wg_encrypt_async_next;
28 wg_async_post_next_t wg_decrypt_async_next;
31 wg_set_async_mode (u32 is_enabled)
34 wg_op_mode_set_ASYNC ();
36 wg_op_mode_unset_ASYNC ();
40 wireguard_register_post_node (vlib_main_t *vm)
43 wg_async_post_next_t *eit;
44 wg_async_post_next_t *dit;
46 eit = &wg_encrypt_async_next;
47 dit = &wg_decrypt_async_next;
50 vnet_crypto_register_post_node (vm, "wg4-output-tun-post-node");
52 vnet_crypto_register_post_node (vm, "wg6-output-tun-post-node");
55 vnet_crypto_register_post_node (vm, "wg4-input-post-node");
57 vnet_crypto_register_post_node (vm, "wg6-input-post-node");
61 wg_secure_zero_memory (void *v, size_t n)
63 static void *(*const volatile memset_v) (void *, int, size_t) = &memset;
68 wg_init (vlib_main_t * vm)
70 wg_main_t *wmp = &wg_main;
74 wmp->in4_fq_index = vlib_frame_queue_main_init (wg4_input_node.index, 0);
75 wmp->in6_fq_index = vlib_frame_queue_main_init (wg6_input_node.index, 0);
77 vlib_frame_queue_main_init (wg4_output_tun_node.index, 0);
79 vlib_frame_queue_main_init (wg6_output_tun_node.index, 0);
81 vlib_thread_main_t *tm = vlib_get_thread_main ();
83 vec_validate_aligned (wmp->per_thread_data, tm->n_vlib_mains,
84 CLIB_CACHE_LINE_BYTES);
86 wg_timer_wheel_init ();
87 wireguard_register_post_node (vm);
88 wmp->op_mode_flags = 0;
93 VLIB_INIT_FUNCTION (wg_init);
97 VNET_FEATURE_INIT (wg4_output_tun, static) = {
98 .arc_name = "ip4-output",
99 .node_name = "wg4-output-tun",
100 .runs_after = VNET_FEATURES ("gso-ip4"),
103 VNET_FEATURE_INIT (wg6_output_tun, static) = {
104 .arc_name = "ip6-output",
105 .node_name = "wg6-output-tun",
106 .runs_after = VNET_FEATURES ("gso-ip6"),
109 VLIB_PLUGIN_REGISTER () =
111 .version = VPP_BUILD_VER,
112 .description = "Wireguard Protocol",
117 * fd.io coding-style-patch-verification: ON
120 * eval: (c-set-style "gnu")