Gabriel Oginski | 4e88e04 | 2022-06-29 12:54:30 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2022 Intel 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 <utils/debug.h> |
| 17 | #include <vlibapi/api.h> |
| 18 | #include <vlibmemory/api.h> |
| 19 | |
| 20 | #define vl_typedefs |
| 21 | #define vl_endianfun |
| 22 | /* Include the (first) vlib-api API definition layer */ |
| 23 | #include <vlibmemory/vl_memory_api_h.h> |
| 24 | /* Include the current layer (third) vpp API definition layer */ |
| 25 | #include <vpp/api/vpe_types.api.h> |
| 26 | #include <vpp/api/vpe.api.h> |
| 27 | #undef vl_typedefs |
| 28 | #undef vl_endianfun |
| 29 | |
| 30 | #include "kernel_vpp_plugin.h" |
| 31 | #include "kernel_vpp_shared.h" |
| 32 | #include "kernel_vpp_ipsec.h" |
| 33 | #include "kernel_vpp_net.h" |
| 34 | |
| 35 | typedef struct private_kernel_vpp_plugin_t private_kernel_vpp_plugin_t; |
| 36 | |
| 37 | /** |
| 38 | * private data of kernel vpp plugin |
| 39 | */ |
| 40 | struct private_kernel_vpp_plugin_t |
| 41 | { |
| 42 | /** |
| 43 | * implements plugin interface |
| 44 | */ |
| 45 | kernel_vpp_plugin_t public; |
| 46 | |
| 47 | vac_t *vac; |
| 48 | }; |
| 49 | |
| 50 | METHOD (plugin_t, get_name, char *, private_kernel_vpp_plugin_t *this) |
| 51 | { |
| 52 | return "kernel-vpp"; |
| 53 | } |
| 54 | |
| 55 | METHOD (plugin_t, get_features, int, private_kernel_vpp_plugin_t *this, |
| 56 | plugin_feature_t *features[]) |
| 57 | { |
| 58 | static plugin_feature_t f[] = { |
| 59 | PLUGIN_CALLBACK (kernel_ipsec_register, kernel_vpp_ipsec_create), |
| 60 | PLUGIN_PROVIDE (CUSTOM, "kernel-ipsec"), |
| 61 | PLUGIN_CALLBACK (kernel_net_register, kernel_vpp_net_create), |
| 62 | PLUGIN_PROVIDE (CUSTOM, "kernel-net"), |
| 63 | }; |
| 64 | *features = f; |
| 65 | return countof (f); |
| 66 | } |
| 67 | |
| 68 | METHOD (plugin_t, destroy, void, private_kernel_vpp_plugin_t *this) |
| 69 | { |
| 70 | if (this->vac) |
| 71 | { |
| 72 | lib->set (lib, "kernel-vpp-vac", NULL); |
| 73 | this->vac->destroy (this->vac); |
| 74 | } |
| 75 | free (this); |
| 76 | } |
| 77 | |
| 78 | plugin_t * |
| 79 | kernel_vpp_plugin_create () |
| 80 | { |
| 81 | private_kernel_vpp_plugin_t *this; |
| 82 | |
| 83 | INIT(this, |
| 84 | .public = { |
| 85 | .plugin = { |
| 86 | .get_name = _get_name, |
| 87 | .get_features = _get_features, |
| 88 | .destroy = _destroy, |
| 89 | }, |
| 90 | }, |
| 91 | ); |
| 92 | |
| 93 | this->vac = vac_create ("strongswan"); |
| 94 | if (!this->vac) |
| 95 | { |
| 96 | DBG1 (DBG_KNL, "vac_create failed"); |
| 97 | destroy (this); |
| 98 | return NULL; |
| 99 | } |
| 100 | lib->set (lib, "kernel-vpp-vac", this->vac); |
| 101 | |
| 102 | return &this->public.plugin; |
| 103 | } |