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:
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.
17 #include <utils/debug.h>
18 #include <vlibapi/api.h>
19 #include <vlibmemory/api.h>
20 #include <vnet/ipsec/ipsec.h>
21 #include <vnet/vnet.h>
22 #include <collections/hashtable.h>
23 #include <threading/mutex.h>
24 #include <processing/jobs/callback_job.h>
25 #include <vpp-api/client/stat_client.h>
29 /* Include the (first) vlib-api API definition layer */
30 #include <vlibmemory/vl_memory_api_h.h>
31 /* Include the current layer (third) vpp API definition layer */
32 #include <vpp/api/vpe_types.api.h>
33 #include <vpp/api/vpe.api.h>
35 #include <vnet/ip-neighbor/ip_neighbor.api_enum.h>
36 #include <vnet/ip-neighbor/ip_neighbor.api_types.h>
37 #include <vnet/ipsec/ipsec.api_enum.h>
38 #include <vnet/ipsec/ipsec.api_types.h>
39 #include <vnet/interface.api_enum.h>
40 #include <vnet/interface.api_types.h>
44 #include "kernel_vpp_ipsec.h"
45 #include "kernel_vpp_shared.h"
50 #include <sys/socket.h>
51 #include <netinet/in.h>
52 #include <arpa/inet.h>
53 #include <sys/ioctl.h>
55 #include <net/route.h>
58 #include <sys/types.h>
59 #include <net/if_arp.h>
68 * One and only instance of the daemon.
72 typedef struct private_kernel_vpp_ipsec_t private_kernel_vpp_ipsec_t;
75 * Private variables of kernel_vpp_ipsec class.
77 struct private_kernel_vpp_ipsec_t
83 kernel_vpp_ipsec_t public;
86 * Next security association database entry ID to allocate
88 refcount_t next_sad_id;
91 * Next security policy database entry ID to allocate
93 refcount_t next_spd_id;
96 * Mutex to lock access to installed policies
101 * Hash table of instaled SA, as kernel_ipsec_sa_id_t => sa_t
106 * Hash table of security policy databases, as nterface => spd_t
111 * Linked list of installed routes
113 linked_list_t *routes;
116 * Next SPI to allocate
121 * Mix value to distribute SPI allocation randomly
126 * Whether to install routes along policies
131 * Whether to install SAs with tunnel flag. Disabling this can be useful
132 * in some scenarios e.g. using SAs to "ipsec tunnel protect" for the
135 bool use_tunnel_mode_sa;
139 * Security association entry
149 * Security policy database
155 /** Networking interface ID restricting policy */
156 uint32_t sw_if_index;
157 /** Policy count for this SPD */
158 refcount_t policy_num;
166 /** Name of the interface the route is bound to */
168 /** Gateway of route */
170 /** Destination network of route */
172 /** Prefix length of dst_net */
174 /** References for route */
179 ((1 == htonl (1)) ? \
181 ((uint64_t) htonl ((x) &0xFFFFFFFF) << 32) | htonl ((x) >> 32))
183 ((1 == ntohl (1)) ? \
185 ((uint64_t) ntohl ((x) &0xFFFFFFFF) << 32) | ntohl ((x) >> 32))
187 CALLBACK (route_equals, bool, route_entry_t *a, va_list args)
189 host_t *dst_net, *gateway;
193 VA_ARGS_VGET (args, if_name, gateway, dst_net, prefixlen);
195 return a->if_name && if_name && streq (a->if_name, if_name) &&
196 a->gateway->ip_equals (a->gateway, gateway) &&
197 a->dst_net->ip_equals (a->dst_net, dst_net) &&
198 a->prefixlen == *prefixlen;
202 * Clean up a route entry
205 route_destroy (route_entry_t *this)
207 this->dst_net->destroy (this->dst_net);
208 this->gateway->destroy (this->gateway);
209 free (this->if_name);
213 static uint32_t get_sw_if_index ();
216 set_arp (char *ipStr, char *if_name, bool add)
220 vl_api_ip_neighbor_add_del_t *mp = NULL;
221 vl_api_ip_neighbor_add_del_reply_t *rmp = NULL;
223 uint32_t sw_if_index = ~0;
230 char *file = "/proc/net/arp";
231 unsigned char mac[8] = {
236 if (if_name == NULL || ipStr == NULL)
238 DBG2 (DBG_KNL, "para is null\n");
242 DBG2 (DBG_KNL, "from kernel read mac\n");
244 mp = vl_msg_api_alloc (sizeof (*mp));
245 memset (mp, 0, sizeof (*mp));
246 sw_if_index = get_sw_if_index (if_name);
247 if (sw_if_index == ~0)
249 DBG1 (DBG_KNL, "sw_if_index for %s not found", if_name);
253 fp = fopen (file, "rb");
254 while (fp && ((nread = getline (&buffer, &len, fp)) != -1))
256 sscanf (buffer, "%s %*s %*s %s %*s %*s", &buf[0], &buf[1]);
257 inet_aton (&buf[0], &addr);
259 if (addr == *((u32 *) (ipStr)))
261 sscanf (buf[1], "%02x:%02x:%02x:%02x:%02x:%02x", &mac[0], &mac[1],
262 &mac[2], &mac[3], &mac[4], &mac[5]);
264 vl_msg_api_get_msg_index ((u8 *) "ip_neighbor_add_del_0607c257");
265 mp->_vl_msg_id = htons (msg_id);
267 memcpy (mp->neighbor.ip_address.un.ip4, (u8 *) &addr, sizeof (addr));
268 mp->neighbor.ip_address.af = 0;
269 memcpy (mp->neighbor.mac_address, mac, 6);
270 mp->neighbor.sw_if_index = htonl (sw_if_index);
271 mp->neighbor.flags = 1;
273 if (vac->send (vac, (char *) mp, sizeof (*mp), &out, &out_len))
275 DBG1 (DBG_KNL, "vac %s neighbor entry",
276 add ? "adding" : "removing");
283 DBG1 (DBG_KNL, "%s neighbor add rv:%d", add ? "add" : "remove",
284 ntohl (rmp->retval));
290 vl_msg_api_free (mp);
305 vl_msg_api_free (mp);
315 add_Route (char *ipAddr, int len, char *mask, char *gateWay)
319 struct sockaddr_in _sin;
320 struct sockaddr_in *sin = &_sin;
325 fd = socket (AF_INET, SOCK_DGRAM, 0);
328 DBG2 (DBG_KNL, "addRoute: socket error\n");
332 memset (&rt, 0, sizeof (struct rtentry));
333 memset (sin, 0, sizeof (struct sockaddr_in));
334 sin->sin_family = AF_INET;
337 if (inet_aton (gateWay, &sin->sin_addr) < 0)
342 memcpy (&rt.rt_gateway, sin, sizeof (struct sockaddr_in));
344 ((struct sockaddr_in *) &rt.rt_dst)->sin_family = AF_INET;
345 memcpy (&((struct sockaddr_in *) &rt.rt_dst)->sin_addr, ipAddr, len);
347 ((struct sockaddr_in *) &rt.rt_genmask)->sin_family = AF_INET;
349 &((struct sockaddr_in *) &rt.rt_genmask)->sin_addr) < 0)
354 rt.rt_flags = RTF_GATEWAY;
355 if (ioctl (fd, SIOCADDRT, &rt) < 0)
367 set_address (u32 ipAddr, u32 sw_if_index, bool add)
371 vl_api_sw_interface_add_del_address_t *mp;
372 vl_api_sw_interface_add_del_address_reply_t *rmp;
378 mp = vl_msg_api_alloc (sizeof (*mp));
379 memset (mp, 0, sizeof (*mp));
382 vl_msg_api_get_msg_index ((u8 *) "sw_interface_add_del_address_5463d73b");
383 mp->_vl_msg_id = htons (msg_id);
385 memcpy (mp->prefix.address.un.ip4, (u8 *) &ipAddr, sizeof (ipAddr));
387 mp->sw_if_index = sw_if_index;
389 if (vac->send (vac, (char *) mp, sizeof (*mp), &out, &out_len))
391 DBG2 (DBG_KNL, "vac %s neighbor entry", add ? "adding" : "removing");
397 DBG2 (DBG_KNL, "%s neighbor add rv:%d", add ? "add" : "remove",
398 ntohl (rmp->retval));
405 vl_msg_api_free (mp);
410 * (Un)-install a single route
413 manage_route (private_kernel_vpp_ipsec_t *this, bool add,
414 traffic_selector_t *dst_ts, host_t *src, host_t *dst)
416 host_t *dst_net, *gateway;
419 route_entry_t *route;
420 bool route_exist = FALSE;
422 char *netmask = "255.255.255.0";
423 char *tap_gateway = "1.1.1.1";
425 if (dst->is_anyaddr (dst))
430 charon->kernel->get_nexthop (charon->kernel, dst, -1, NULL, &if_name);
431 dst_ts->to_subnet (dst_ts, &dst_net, &prefixlen);
434 if (src->is_anyaddr (src))
438 if (!charon->kernel->get_interface (charon->kernel, src, &if_name))
444 this->routes->find_first (this->routes, route_equals, (void **) &route,
445 if_name, gateway, dst_net, &prefixlen);
448 DBG2 (DBG_KNL, "installing route: %H/%d via %H dev %s", dst_net,
449 prefixlen, gateway, if_name);
452 unsigned int refs_num = ref_get (&route->refs);
453 DBG2 (DBG_KNL, "add route but it exist %d", refs_num);
457 INIT (route, .if_name = strdup (if_name),
458 .gateway = gateway->clone (gateway),
459 .dst_net = dst_net->clone (dst_net), .prefixlen = prefixlen,
461 this->routes->insert_last (this->routes, route);
462 charon->kernel->add_route (charon->kernel,
463 dst_net->get_address (dst_net), prefixlen,
464 gateway, dst, if_name, 1);
467 add_Route (dst_net->get_address (dst_net).ptr,
468 dst_net->get_address (dst_net).len, netmask, tap_gateway);
470 arp_rc = set_arp (gateway->get_address (gateway).ptr, if_name, TRUE);
472 DBG2 (DBG_KNL, "arpGet success!\n");
476 DBG2 (DBG_KNL, "uninstalling route: %H/%d via %H dev %s", dst_net,
477 prefixlen, gateway, if_name);
480 DBG2 (DBG_KNL, "del route but it not exist");
483 if (ref_put (&route->refs))
485 this->routes->remove (this->routes, route, NULL);
486 route_destroy (route);
487 charon->kernel->del_route (charon->kernel,
488 dst_net->get_address (dst_net), prefixlen,
489 gateway, dst, if_name, 1);
495 * Hash function for IPsec SA
498 sa_hash (kernel_ipsec_sa_id_t *sa)
500 return chunk_hash_inc (
501 sa->src->get_address (sa->src),
503 sa->dst->get_address (sa->dst),
504 chunk_hash_inc (chunk_from_thing (sa->spi),
505 chunk_hash (chunk_from_thing (sa->proto)))));
509 * Equality function for IPsec SA
512 sa_equals (kernel_ipsec_sa_id_t *sa, kernel_ipsec_sa_id_t *other_sa)
514 return sa->src->ip_equals (sa->src, other_sa->src) &&
515 sa->dst->ip_equals (sa->dst, other_sa->dst) &&
516 sa->spi == other_sa->spi && sa->proto == other_sa->proto;
520 * Equality function for policy SPD
523 policy_equals (vl_api_ipsec_spd_entry_t *policy,
524 vl_api_ipsec_spd_entry_t *other_policy)
527 /* change protocol due to legacy implementation of ANY protocol inside VPP */
528 if (other_policy->protocol == 255)
529 other_policy->protocol = 0;
531 /* return true if both policies are equal */
532 return !memcmp (policy, other_policy, sizeof (*policy));
536 * Hash function for interface
539 interface_hash (char *interface)
541 return chunk_hash (chunk_from_str (interface));
545 * Equality function for interface
548 interface_equals (char *interface1, char *interface2)
550 return streq (interface1, interface2);
554 * Map an integer x with a one-to-one function using quadratic residues
557 permute (u_int x, u_int p)
562 qr = ((uint64_t) x * x) % p;
571 * Initialize seeds for SPI generation
574 init_spi (private_kernel_vpp_ipsec_t *this)
579 rng = lib->crypto->create_rng (lib->crypto, RNG_STRONG);
585 rng->get_bytes (rng, sizeof (this->nextspi), (uint8_t *) &this->nextspi);
589 rng->get_bytes (rng, sizeof (this->mixspi), (uint8_t *) &this->mixspi);
596 * Calculate policy priority
599 calculate_priority (policy_priority_t policy_priority, traffic_selector_t *src,
600 traffic_selector_t *dst)
602 uint32_t priority = PRIO_BASE;
607 switch (policy_priority)
609 case POLICY_PRIORITY_FALLBACK:
612 case POLICY_PRIORITY_ROUTED:
615 case POLICY_PRIORITY_DEFAULT:
618 case POLICY_PRIORITY_PASS:
621 /* calculate priority based on selector size, small size = high prio */
622 src->to_subnet (src, &net, &mask);
624 proto = src->get_protocol (src);
625 port = net->get_port (net);
628 dst->to_subnet (dst, &net, &mask);
630 proto = max (proto, dst->get_protocol (dst));
631 port = max (port, net->get_port (net));
634 priority <<= 2; /* make some room for the two flags */
635 priority += port ? 0 : 2;
636 priority += proto ? 0 : 1;
641 * Get sw_if_index from interface name
644 get_sw_if_index (char *interface)
647 int out_len, name_filter_len = 0, msg_len = 0;
648 vl_api_sw_interface_dump_t *mp;
649 vl_api_sw_interface_details_t *rmp;
650 uint32_t sw_if_index = ~0;
652 name_filter_len = strlen (interface);
653 msg_len = sizeof (*mp) + name_filter_len;
654 mp = vl_msg_api_alloc (msg_len);
655 clib_memset (mp, 0, msg_len);
656 u16 msg_id = vl_msg_api_get_msg_index ((u8 *) "sw_interface_dump_aa610c27");
657 mp->_vl_msg_id = htons (msg_id);
658 mp->name_filter_valid = TRUE;
659 mp->name_filter.length = htonl (name_filter_len);
660 memcpy ((char *) mp->name_filter.buf, interface, name_filter_len);
662 if (vac->send (vac, (char *) mp, msg_len, &out, &out_len))
670 rmp = (vl_api_sw_interface_details_t *) out;
671 sw_if_index = ntohl (rmp->sw_if_index);
675 vl_msg_api_free (mp);
679 * (Un)-install a security policy database
682 spd_add_del (bool add, uint32_t spd_id)
686 vl_api_ipsec_spd_add_del_t *mp;
687 vl_api_ipsec_spd_add_del_reply_t *rmp;
688 status_t rv = FAILED;
690 mp = vl_msg_api_alloc (sizeof (*mp));
691 memset (mp, 0, sizeof (*mp));
693 u16 msg_id = vl_msg_api_get_msg_index ((u8 *) "ipsec_spd_add_del_20e89a95");
694 mp->_vl_msg_id = htons (msg_id);
696 mp->spd_id = htonl (spd_id);
697 if (vac->send (vac, (char *) mp, sizeof (*mp), &out, &out_len))
699 DBG1 (DBG_KNL, "vac %s SPD failed", add ? "adding" : "removing");
705 DBG1 (DBG_KNL, "%s SPD failed rv:%d", add ? "add" : "remove",
706 ntohl (rmp->retval));
713 vl_msg_api_free (mp);
718 * Enable or disable SPD on an insterface
721 interface_add_del_spd (bool add, uint32_t spd_id, uint32_t sw_if_index)
725 vl_api_ipsec_interface_add_del_spd_t *mp;
726 vl_api_ipsec_interface_add_del_spd_reply_t *rmp;
727 status_t rv = FAILED;
729 mp = vl_msg_api_alloc (sizeof (*mp));
730 memset (mp, 0, sizeof (*mp));
732 vl_msg_api_get_msg_index ((u8 *) "ipsec_interface_add_del_spd_80f80cbb");
733 mp->_vl_msg_id = htons (msg_id);
735 mp->spd_id = htonl (spd_id);
736 mp->sw_if_index = htonl (sw_if_index);
737 if (vac->send (vac, (char *) mp, sizeof (*mp), &out, &out_len))
739 DBG1 (DBG_KNL, "vac %s interface SPD failed",
740 add ? "adding" : "removing");
746 DBG1 (DBG_KNL, "%s interface SPD failed rv:%d", add ? "add" : "remove",
747 ntohl (rmp->retval));
754 vl_msg_api_free (mp);
759 bypass_all (bool add, uint32_t spd_id, uint32_t sa_id)
761 vl_api_ipsec_spd_entry_add_del_t *mp;
762 vl_api_ipsec_spd_entry_add_del_reply_t *rmp;
765 status_t rv = FAILED;
767 DBG2 (DBG_KNL, "bypass_all [%s] spd_id %d sa_id %d", add ? "ADD" : "DEL",
770 mp = vl_msg_api_alloc (sizeof (*mp));
771 memset (mp, 0, sizeof (*mp));
774 vl_msg_api_get_msg_index ((u8 *) "ipsec_spd_entry_add_del_338b7411");
775 mp->_vl_msg_id = ntohs (msg_id);
777 mp->entry.sa_id = ntohl (sa_id);
778 mp->entry.spd_id = ntohl (spd_id);
779 mp->entry.priority = ntohl (INT_MAX - POLICY_PRIORITY_PASS - 1);
780 mp->entry.is_outbound = 0;
781 mp->entry.policy = ntohl (IPSEC_API_SPD_ACTION_BYPASS);
782 memset (mp->entry.local_address_stop.un.ip6, 0xFF, 16);
783 memset (mp->entry.remote_address_stop.un.ip6, 0xFF, 16);
784 mp->entry.remote_port_start = mp->entry.local_port_start = ntohs (0);
785 mp->entry.remote_port_stop = mp->entry.local_port_stop = ntohs (0xFFFF);
786 mp->entry.protocol = IP_API_PROTO_ESP;
787 if (vac->send (vac, (char *) mp, sizeof (*mp), &out, &out_len))
789 DBG1 (DBG_KNL, "vac %s SPD entry failed", add ? "adding" : "removing");
795 DBG1 (DBG_KNL, "%s SPD entry failed rv:%d", add ? "add" : "remove",
796 ntohl (rmp->retval));
799 mp->entry.is_outbound = 1;
800 if (vac->send (vac, (char *) mp, sizeof (*mp), &out, &out_len))
802 DBG1 (DBG_KNL, "vac %s SPD entry failed", add ? "adding" : "removing");
808 DBG1 (DBG_KNL, "%s SPD entry failed rv:%d", add ? "add" : "remove",
809 ntohl (rmp->retval));
812 mp->entry.is_outbound = 0;
813 mp->entry.protocol = IP_API_PROTO_AH;
814 if (vac->send (vac, (char *) mp, sizeof (*mp), &out, &out_len))
816 DBG1 (DBG_KNL, "vac %s SPD entry failed", add ? "adding" : "removing");
822 DBG1 (DBG_KNL, "%s SPD entry failed rv:%d", add ? "add" : "remove",
823 ntohl (rmp->retval));
826 mp->entry.is_outbound = 1;
827 if (vac->send (vac, (char *) mp, sizeof (*mp), &out, &out_len))
829 DBG1 (DBG_KNL, "vac %s SPD entry failed", add ? "adding" : "removing");
835 DBG1 (DBG_KNL, "%s SPD entry failed rv:%d", add ? "add" : "remove",
836 ntohl (rmp->retval));
845 vl_msg_api_free (mp);
851 bypass_port (bool add, uint32_t spd_id, uint32_t sa_id, uint16_t port)
853 vl_api_ipsec_spd_entry_add_del_t *mp;
854 vl_api_ipsec_spd_entry_add_del_reply_t *rmp;
857 status_t rv = FAILED;
859 mp = vl_msg_api_alloc (sizeof (*mp));
860 memset (mp, 0, sizeof (*mp));
863 vl_msg_api_get_msg_index ((u8 *) "ipsec_spd_entry_add_del_338b7411");
864 mp->_vl_msg_id = ntohs (msg_id);
866 mp->entry.sa_id = ntohl (sa_id);
867 mp->entry.spd_id = ntohl (spd_id);
868 mp->entry.priority = ntohl (INT_MAX - POLICY_PRIORITY_PASS - 1);
869 mp->entry.policy = ntohl (IPSEC_API_SPD_ACTION_BYPASS);
870 memset (mp->entry.local_address_stop.un.ip6, 0xFF, 16);
871 memset (mp->entry.remote_address_stop.un.ip6, 0xFF, 16);
872 mp->entry.is_outbound = 0;
873 mp->entry.remote_port_start = mp->entry.local_port_start = ntohs (0);
874 mp->entry.remote_port_stop = mp->entry.local_port_stop = ntohs (0xFFFF);
875 mp->entry.protocol = IP_API_PROTO_HOPOPT;
877 if (vac->send (vac, (char *) mp, sizeof (*mp), &out, &out_len))
879 DBG1 (DBG_KNL, "vac %s SPD entry failed", add ? "adding" : "removing");
885 DBG1 (DBG_KNL, "%s SPD entry failed rv:%d", add ? "add" : "remove",
886 ntohl (rmp->retval));
889 mp->entry.is_outbound = 1;
890 if (vac->send (vac, (char *) mp, sizeof (*mp), &out, &out_len))
892 DBG1 (DBG_KNL, "vac %s SPD entry failed", add ? "adding" : "removing");
898 DBG1 (DBG_KNL, "%s SPD entry failed rv:%d", add ? "add" : "remove",
899 ntohl (rmp->retval));
907 vl_msg_api_free (mp);
913 * Add or remove a bypass policy
916 manage_bypass (bool add, uint32_t spd_id, uint32_t sa_id)
921 bypass_all (add, spd_id, sa_id);
924 lib->settings->get_int (lib->settings, "%s.port", IKEV2_UDP_PORT, lib->ns);
928 rv = bypass_port (add, spd_id, sa_id, port);
935 port = lib->settings->get_int (lib->settings, "%s.port_nat_t",
936 IKEV2_NATT_PORT, lib->ns);
939 rv = bypass_port (add, spd_id, sa_id, port);
950 * Add or remove a policy
953 manage_policy (private_kernel_vpp_ipsec_t *this, bool add,
954 kernel_ipsec_policy_id_t *id,
955 kernel_ipsec_manage_policy_t *data)
958 char *out = NULL, *interface = NULL;
960 uint32_t sw_if_index, spd_id = ~0, sad_id = ~0;
961 status_t rv = FAILED;
962 uint32_t priority, auto_priority;
963 chunk_t src_from, src_to, dst_from, dst_to;
964 host_t *src, *dst, *addr;
965 vl_api_ipsec_spd_entry_add_del_t *mp;
966 vl_api_ipsec_spd_entry_add_del_reply_t *rmp;
969 mp = vl_msg_api_alloc (sizeof (*mp));
970 memset (mp, 0, sizeof (*mp));
972 this->mutex->lock (this->mutex);
975 addr = id->dir == POLICY_IN ? data->dst : data->src;
976 for (int i = 0; i < 5; i++)
978 if (!charon->kernel->get_interface (charon->kernel, addr,
981 DBG1 (DBG_KNL, "policy no interface %H", addr);
988 DBG1 (DBG_KNL, "policy have interface %H", addr);
994 id->interface = interface;
997 DBG2 (DBG_KNL, "manage policy [%s] interface [%s]", add ? "ADD" : "DEL",
1000 spd = this->spds->get (this->spds, id->interface);
1005 DBG1 (DBG_KNL, "SPD for %s not found, should not be deleted",
1009 sw_if_index = get_sw_if_index (id->interface);
1010 DBG1 (DBG_KNL, "firstly created, spd for %s found sw_if_index is %d",
1011 id->interface, sw_if_index);
1012 if (sw_if_index == ~0)
1014 DBG1 (DBG_KNL, "sw_if_index for %s not found", id->interface);
1017 spd_id = ref_get (&this->next_spd_id);
1018 if (spd_add_del (TRUE, spd_id))
1020 DBG1 (DBG_KNL, "spd_add_del %d failed!!!!!", spd_id);
1023 if (interface_add_del_spd (TRUE, spd_id, sw_if_index))
1025 DBG1 (DBG_KNL, "interface_add_del_spd %d %d failed!!!!!", spd_id,
1029 INIT (spd, .spd_id = spd_id, .sw_if_index = sw_if_index,
1031 this->spds->put (this->spds, id->interface, spd);
1035 auto_priority = calculate_priority (data->prio, id->src_ts, id->dst_ts);
1036 priority = data->manual_prio ? data->manual_prio : auto_priority;
1039 vl_msg_api_get_msg_index ((u8 *) "ipsec_spd_entry_add_del_338b7411");
1040 mp->_vl_msg_id = htons (msg_id);
1042 mp->entry.spd_id = htonl (spd->spd_id);
1043 mp->entry.priority = htonl (INT_MAX - POLICY_PRIORITY_PASS);
1044 mp->entry.is_outbound = id->dir == POLICY_OUT;
1048 mp->entry.policy = htonl (IPSEC_API_SPD_ACTION_PROTECT);
1051 mp->entry.policy = htonl (IPSEC_API_SPD_ACTION_BYPASS);
1054 mp->entry.policy = htonl (IPSEC_API_SPD_ACTION_DISCARD);
1057 if ((data->type == POLICY_IPSEC) && data->sa)
1059 kernel_ipsec_sa_id_t id = {
1062 .proto = data->sa->esp.use ? IPPROTO_ESP : IPPROTO_AH,
1063 .spi = data->sa->esp.use ? data->sa->esp.spi : data->sa->ah.spi,
1066 sa = this->sas->get (this->sas, &id);
1069 DBG1 (DBG_KNL, "SA ID not found");
1075 if (manage_bypass (TRUE, spd_id, ~0))
1077 DBG1 (DBG_KNL, "manage_bypass %d failed!!!!", spd_id);
1083 mp->entry.sa_id = htonl (sad_id);
1085 bool is_ipv6 = false;
1086 if (id->src_ts->get_type (id->src_ts) == TS_IPV6_ADDR_RANGE)
1089 mp->entry.local_address_start.af = htonl (ADDRESS_IP6);
1090 mp->entry.local_address_stop.af = htonl (ADDRESS_IP6);
1091 mp->entry.remote_address_start.af = htonl (ADDRESS_IP6);
1092 mp->entry.remote_address_stop.af = htonl (ADDRESS_IP6);
1096 mp->entry.local_address_start.af = htonl (ADDRESS_IP4);
1097 mp->entry.local_address_stop.af = htonl (ADDRESS_IP4);
1098 mp->entry.remote_address_start.af = htonl (ADDRESS_IP4);
1099 mp->entry.remote_address_stop.af = htonl (ADDRESS_IP4);
1101 mp->entry.protocol = id->src_ts->get_protocol (id->src_ts);
1103 if (id->dir == POLICY_OUT)
1105 src_from = id->src_ts->get_from_address (id->src_ts);
1106 src_to = id->src_ts->get_to_address (id->src_ts);
1107 src = host_create_from_chunk (is_ipv6 ? AF_INET6 : AF_INET, src_to, 0);
1108 dst_from = id->dst_ts->get_from_address (id->dst_ts);
1109 dst_to = id->dst_ts->get_to_address (id->dst_ts);
1110 dst = host_create_from_chunk (is_ipv6 ? AF_INET6 : AF_INET, dst_to, 0);
1114 dst_from = id->src_ts->get_from_address (id->src_ts);
1115 dst_to = id->src_ts->get_to_address (id->src_ts);
1116 dst = host_create_from_chunk (is_ipv6 ? AF_INET6 : AF_INET, dst_from, 0);
1117 src_from = id->dst_ts->get_from_address (id->dst_ts);
1118 src_to = id->dst_ts->get_to_address (id->dst_ts);
1119 src = host_create_from_chunk (is_ipv6 ? AF_INET6 : AF_INET, src_from, 0);
1122 if (src->is_anyaddr (src) && dst->is_anyaddr (dst))
1124 memset (mp->entry.local_address_stop.un.ip6, 0xFF, 16);
1125 memset (mp->entry.remote_address_stop.un.ip6, 0xFF, 16);
1129 memcpy (is_ipv6 ? mp->entry.local_address_start.un.ip6 :
1130 mp->entry.local_address_start.un.ip4,
1131 src_from.ptr, src_from.len);
1132 memcpy (is_ipv6 ? mp->entry.local_address_stop.un.ip6 :
1133 mp->entry.local_address_stop.un.ip4,
1134 src_to.ptr, src_to.len);
1135 memcpy (is_ipv6 ? mp->entry.remote_address_start.un.ip6 :
1136 mp->entry.remote_address_start.un.ip4,
1137 dst_from.ptr, dst_from.len);
1138 memcpy (is_ipv6 ? mp->entry.remote_address_stop.un.ip6 :
1139 mp->entry.remote_address_stop.un.ip4,
1140 dst_to.ptr, dst_to.len);
1142 mp->entry.local_port_start = htons (id->src_ts->get_from_port (id->src_ts));
1143 mp->entry.local_port_stop = htons (id->src_ts->get_to_port (id->src_ts));
1144 mp->entry.remote_port_start = htons (id->dst_ts->get_from_port (id->dst_ts));
1145 mp->entry.remote_port_stop = htons (id->dst_ts->get_to_port (id->dst_ts));
1147 /* check if policy exists in SPD */
1148 vl_api_ipsec_spd_dump_t *mp_dump;
1149 vl_api_ipsec_spd_details_t *rmp_dump, *tmp;
1151 mp_dump = vl_msg_api_alloc (sizeof (*mp_dump));
1152 memset (mp_dump, 0, sizeof (*mp_dump));
1154 msg_id = vl_msg_api_get_msg_index ((u8 *) "ipsec_spd_dump_afefbf7d");
1155 mp_dump->_vl_msg_id = htons (msg_id);
1156 mp_dump->spd_id = htonl (spd->spd_id);
1157 mp_dump->sa_id = htonl (sad_id);
1159 if (vac->send_dump (vac, (char *) mp_dump, sizeof (*mp_dump), &out,
1162 DBG1 (DBG_KNL, "vac %s SPD lookup failed", add ? "adding" : "removing");
1166 int num = out_len / sizeof (*rmp_dump);
1169 /* found existing policy */
1173 for (i = 0; i < num; i++)
1177 /* check if found entry equals the new one */
1178 if (policy_equals (&mp->entry, &rmp_dump->entry))
1182 else if (!add && num == 0)
1184 /* VPP doesn't have any policy to delete */
1190 if (vac->send (vac, (char *) mp, sizeof (*mp), &out, &out_len))
1192 DBG1 (DBG_KNL, "vac %s SPD entry failed", add ? "adding" : "removing");
1198 DBG1 (DBG_KNL, "%s SPD entry failed rv:%d", add ? "add" : "remove",
1199 ntohl (rmp->retval));
1206 ref_get (&spd->policy_num);
1210 if (ref_put (&spd->policy_num))
1214 "policy_num's ref is 0, delete spd_id %d sw_if_index %d sad_id %x",
1215 spd->spd_id, spd->sw_if_index, sad_id);
1216 interface_add_del_spd (FALSE, spd->spd_id, spd->sw_if_index);
1217 manage_bypass (FALSE, spd->spd_id, sad_id);
1218 spd_add_del (FALSE, spd->spd_id);
1219 this->spds->remove (this->spds, id->interface);
1223 if (this->install_routes && id->dir == POLICY_OUT && !mp->entry.protocol)
1225 if (data->type == POLICY_IPSEC && data->sa->mode != MODE_TRANSPORT)
1227 manage_route (this, add, id->dst_ts, data->src, data->dst);
1233 vl_msg_api_free (mp_dump);
1234 vl_msg_api_free (mp);
1235 this->mutex->unlock (this->mutex);
1239 METHOD (kernel_ipsec_t, get_features, kernel_feature_t,
1240 private_kernel_vpp_ipsec_t *this)
1242 return KERNEL_ESP_V3_TFC;
1245 METHOD (kernel_ipsec_t, get_spi, status_t, private_kernel_vpp_ipsec_t *this,
1246 host_t *src, host_t *dst, uint8_t protocol, uint32_t *spi)
1248 static const u_int p = 268435399, offset = 0xc0000000;
1250 *spi = htonl (offset + permute (ref_get (&this->nextspi) ^ this->mixspi, p));
1254 METHOD (kernel_ipsec_t, get_cpi, status_t, private_kernel_vpp_ipsec_t *this,
1255 host_t *src, host_t *dst, uint16_t *cpi)
1257 DBG1 (DBG_KNL, "get_cpi is not supported!!!!!!!!!!!!!!!!!!!!!!!!");
1258 return NOT_SUPPORTED;
1262 * Helper struct for expiration events
1267 private_kernel_vpp_ipsec_t *manager;
1269 kernel_ipsec_sa_id_t *sa_id;
1272 * 0 if this is a hard expire, otherwise the offset in s (soft->hard)
1274 uint32_t hard_offset;
1279 * Callback for expiration events
1281 static job_requeue_t
1282 sa_expired (vpp_sa_expired_t *expired)
1284 private_kernel_vpp_ipsec_t *this = expired->manager;
1286 kernel_ipsec_sa_id_t *id = expired->sa_id;
1288 this->mutex->lock (this->mutex);
1289 sa = this->sas->get (this->sas, id);
1293 charon->kernel->expire (charon->kernel, id->proto, id->spi, id->dst,
1298 this->mutex->unlock (this->mutex);
1299 return JOB_REQUEUE_NONE;
1303 * Schedule a job to handle IPsec SA expiration
1306 schedule_expiration (private_kernel_vpp_ipsec_t *this,
1307 kernel_ipsec_add_sa_t *entry,
1308 kernel_ipsec_sa_id_t *entry2)
1310 lifetime_cfg_t *lifetime = entry->lifetime;
1311 vpp_sa_expired_t *expired;
1312 callback_job_t *job;
1314 kernel_ipsec_sa_id_t *id;
1316 if (!lifetime->time.life)
1317 { /* no expiration at all */
1321 INIT (id, .src = entry2->src->clone (entry2->src),
1322 .dst = entry2->dst->clone (entry2->dst), .spi = entry2->spi,
1323 .proto = entry2->proto, );
1325 INIT (expired, .manager = this, .sa_id = id, );
1327 /* schedule a rekey first, a hard timeout will be scheduled then, if any */
1328 expired->hard_offset = lifetime->time.life - lifetime->time.rekey;
1329 timeout = lifetime->time.rekey;
1331 if (lifetime->time.life <= lifetime->time.rekey || lifetime->time.rekey == 0)
1332 { /* no rekey, schedule hard timeout */
1333 expired->hard_offset = 0;
1334 timeout = lifetime->time.life;
1337 job = callback_job_create ((callback_job_cb_t) sa_expired, expired,
1338 (callback_job_cleanup_t) free, NULL);
1339 lib->scheduler->schedule_job (lib->scheduler, (job_t *) job, timeout);
1342 METHOD (kernel_ipsec_t, add_sa, status_t, private_kernel_vpp_ipsec_t *this,
1343 kernel_ipsec_sa_id_t *id, kernel_ipsec_add_sa_t *data)
1347 vl_api_ipsec_sad_entry_add_del_t *mp;
1348 vl_api_ipsec_sad_entry_add_del_reply_t *rmp;
1349 uint32_t sad_id = ref_get (&this->next_sad_id);
1350 uint8_t ca = 0, ia = 0;
1351 status_t rv = FAILED;
1353 kernel_ipsec_sa_id_t *sa_id;
1355 int key_len = data->enc_key.len;
1357 if ((data->enc_alg == ENCR_AES_CTR) ||
1358 (data->enc_alg == ENCR_AES_GCM_ICV8) ||
1359 (data->enc_alg == ENCR_AES_GCM_ICV12) ||
1360 (data->enc_alg == ENCR_AES_GCM_ICV16))
1362 static const int SALT_SIZE =
1363 4; /* See how enc_size is calculated at keymat_v2.derive_child_keys */
1364 key_len = key_len - SALT_SIZE;
1366 natt_port = lib->settings->get_int (
1367 lib->settings, "%s.plugins.socket-default.natt", IKEV2_NATT_PORT, lib->ns);
1368 mp = vl_msg_api_alloc (sizeof (*mp));
1369 memset (mp, 0, sizeof (*mp));
1371 vl_msg_api_get_msg_index ((u8 *) "ipsec_sad_entry_add_del_ab64b5c6");
1372 mp->_vl_msg_id = htons (msg_id);
1374 mp->entry.sad_id = htonl (sad_id);
1375 mp->entry.spi = id->spi;
1376 mp->entry.protocol = id->proto == IPPROTO_ESP ? htonl (IPSEC_API_PROTO_ESP) :
1377 htonl (IPSEC_API_PROTO_AH);
1379 switch (data->enc_alg)
1382 ca = IPSEC_API_CRYPTO_ALG_NONE;
1385 switch (key_len * 8)
1388 ca = IPSEC_API_CRYPTO_ALG_AES_CBC_128;
1391 ca = IPSEC_API_CRYPTO_ALG_AES_CBC_192;
1394 ca = IPSEC_API_CRYPTO_ALG_AES_CBC_256;
1397 DBG1 (DBG_KNL, "Key length %d is not supported by VPP!",
1403 switch (key_len * 8)
1406 ca = IPSEC_API_CRYPTO_ALG_AES_CTR_128;
1409 ca = IPSEC_API_CRYPTO_ALG_AES_CTR_192;
1412 ca = IPSEC_API_CRYPTO_ALG_AES_CTR_256;
1415 DBG1 (DBG_KNL, "Key length %d is not supported by VPP!",
1420 case ENCR_AES_GCM_ICV8:
1421 case ENCR_AES_GCM_ICV12:
1422 case ENCR_AES_GCM_ICV16:
1423 switch (key_len * 8)
1426 ca = IPSEC_API_CRYPTO_ALG_AES_GCM_128;
1429 ca = IPSEC_API_CRYPTO_ALG_AES_GCM_192;
1432 ca = IPSEC_API_CRYPTO_ALG_AES_GCM_256;
1435 DBG1 (DBG_KNL, "Key length %d is not supported by VPP!",
1441 ca = IPSEC_API_CRYPTO_ALG_DES_CBC;
1444 ca = IPSEC_API_CRYPTO_ALG_3DES_CBC;
1447 DBG1 (DBG_KNL, "algorithm %N not supported by VPP!",
1448 encryption_algorithm_names, data->enc_alg);
1451 mp->entry.crypto_algorithm = htonl (ca);
1452 mp->entry.crypto_key.length = key_len < 128 ? key_len : 128;
1453 memcpy (mp->entry.crypto_key.data, data->enc_key.ptr,
1454 mp->entry.crypto_key.length);
1456 /* copy salt for AEAD algorithms */
1457 if ((data->enc_alg == ENCR_AES_CTR) ||
1458 (data->enc_alg == ENCR_AES_GCM_ICV8) ||
1459 (data->enc_alg == ENCR_AES_GCM_ICV12) ||
1460 (data->enc_alg == ENCR_AES_GCM_ICV16))
1462 memcpy (&mp->entry.salt, data->enc_key.ptr + mp->entry.crypto_key.length,
1466 switch (data->int_alg)
1468 case AUTH_UNDEFINED:
1469 ia = IPSEC_API_INTEG_ALG_NONE;
1471 case AUTH_HMAC_MD5_96:
1472 ia = IPSEC_API_INTEG_ALG_MD5_96;
1474 case AUTH_HMAC_SHA1_96:
1475 ia = IPSEC_API_INTEG_ALG_SHA1_96;
1477 case AUTH_HMAC_SHA2_256_96:
1478 ia = IPSEC_API_INTEG_ALG_SHA_256_96;
1480 case AUTH_HMAC_SHA2_256_128:
1481 ia = IPSEC_API_INTEG_ALG_SHA_256_128;
1483 case AUTH_HMAC_SHA2_384_192:
1484 ia = IPSEC_API_INTEG_ALG_SHA_384_192;
1486 case AUTH_HMAC_SHA2_512_256:
1487 ia = IPSEC_API_INTEG_ALG_SHA_512_256;
1490 DBG1 (DBG_KNL, "algorithm %N not supported by VPP!",
1491 integrity_algorithm_names, data->int_alg);
1495 mp->entry.integrity_algorithm = htonl (ia);
1496 mp->entry.integrity_key.length =
1497 data->int_key.len < 128 ? data->int_key.len : 128;
1498 memcpy (mp->entry.integrity_key.data, data->int_key.ptr,
1499 mp->entry.integrity_key.length);
1501 int flags = IPSEC_API_SAD_FLAG_NONE;
1503 flags |= IPSEC_API_SAD_FLAG_IS_INBOUND;
1504 /* like the kernel-netlink plugin, anti-replay can be disabled with zero
1505 * replay_window, but window size cannot be customized for vpp */
1506 if (data->replay_window)
1507 flags |= IPSEC_API_SAD_FLAG_USE_ANTI_REPLAY;
1509 flags |= IPSEC_API_SAD_FLAG_USE_ESN;
1510 if (this->use_tunnel_mode_sa && data->mode == MODE_TUNNEL)
1512 if (id->src->get_family (id->src) == AF_INET6)
1513 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL_V6;
1515 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL;
1519 DBG1 (DBG_KNL, "UDP encap!!!!!!!!!!!!!!!!!!!!");
1520 flags |= IPSEC_API_SAD_FLAG_UDP_ENCAP;
1522 mp->entry.flags = htonl (flags);
1524 bool is_ipv6 = false;
1525 if (id->src->get_family (id->src) == AF_INET6)
1528 mp->entry.tunnel_src.af = htonl (ADDRESS_IP6);
1529 mp->entry.tunnel_dst.af = htonl (ADDRESS_IP6);
1533 mp->entry.tunnel_src.af = htonl (ADDRESS_IP4);
1534 mp->entry.tunnel_dst.af = htonl (ADDRESS_IP4);
1536 src = id->src->get_address (id->src);
1537 memcpy (is_ipv6 ? mp->entry.tunnel_src.un.ip6 : mp->entry.tunnel_src.un.ip4,
1539 dst = id->dst->get_address (id->dst);
1540 memcpy (is_ipv6 ? mp->entry.tunnel_dst.un.ip6 : mp->entry.tunnel_dst.un.ip4,
1542 if (vac->send (vac, (char *) mp, sizeof (*mp), &out, &out_len))
1544 DBG1 (DBG_KNL, "vac adding SA failed");
1550 DBG1 (DBG_KNL, "add SA failed rv:%d", ntohl (rmp->retval));
1554 this->mutex->lock (this->mutex);
1555 INIT (sa_id, .src = id->src->clone (id->src),
1556 .dst = id->dst->clone (id->dst), .spi = id->spi, .proto = id->proto, );
1557 INIT (sa, .sa_id = sad_id, .stat_index = ntohl (rmp->stat_index), );
1558 DBG4 (DBG_KNL, "put sa by its sa_id %x !!!!!!", sad_id);
1559 this->sas->put (this->sas, sa_id, sa);
1560 schedule_expiration (this, data, id);
1561 this->mutex->unlock (this->mutex);
1566 vl_msg_api_free (mp);
1570 METHOD (kernel_ipsec_t, update_sa, status_t, private_kernel_vpp_ipsec_t *this,
1571 kernel_ipsec_sa_id_t *id, kernel_ipsec_update_sa_t *data)
1574 "update sa not supported!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
1575 return NOT_SUPPORTED;
1578 METHOD (kernel_ipsec_t, query_sa, status_t, private_kernel_vpp_ipsec_t *this,
1579 kernel_ipsec_sa_id_t *id, kernel_ipsec_query_sa_t *data,
1580 uint64_t *bytes, uint64_t *packets, time_t *time)
1582 status_t rv = FAILED;
1586 stat_segment_data_t *res;
1588 uint64_t res_bytes = 0;
1589 uint64_t res_packets = 0;
1591 this->mutex->lock (this->mutex);
1592 sa = this->sas->get (this->sas, id);
1593 this->mutex->unlock (this->mutex);
1596 DBG1 (DBG_KNL, "SA not found");
1600 int rv_stat = stat_segment_connect ("/run/vpp/stats.sock");
1603 DBG1 (DBG_KNL, "Not connecting with stats segmentation");
1606 vec_add1 (pattern, (u8 *) "/net/ipsec/sa");
1607 dir = stat_segment_ls ((u8 **) pattern);
1608 res = stat_segment_dump (dir);
1609 /* i-loop for each results find by pattern - here two:
1611 * 2. /net/ipsec/sa/lost
1613 for (i = 0; i < vec_len (res); i++)
1615 switch (res[i].type)
1617 /* type for how many packets are lost */
1618 case STAT_DIR_TYPE_COUNTER_VECTOR_SIMPLE:
1619 if (res[i].simple_counter_vec == 0)
1622 /* type for counter for each SA */
1623 case STAT_DIR_TYPE_COUNTER_VECTOR_COMBINED:
1624 if (res[i].combined_counter_vec == 0)
1626 /* k-loop for each threads - that you run VPP */
1627 for (k = 0; k < vec_len (res[i].combined_counter_vec); k++)
1629 if (sa->stat_index <= vec_len (res[i].combined_counter_vec[k]))
1631 DBG4 (DBG_KNL, "Thread: %d, Packets: %lu, Bytes: %lu", k,
1632 res[i].combined_counter_vec[k][sa->stat_index].packets,
1633 res[i].combined_counter_vec[k][sa->stat_index].bytes);
1635 res[i].combined_counter_vec[k][sa->stat_index].bytes;
1637 res[i].combined_counter_vec[k][sa->stat_index].packets;
1641 case STAT_DIR_TYPE_NAME_VECTOR:
1642 if (res[i].name_vector == 0)
1647 stat_segment_data_free (res);
1648 stat_segment_disconnect ();
1659 *packets = res_packets;
1670 METHOD (kernel_ipsec_t, del_sa, status_t, private_kernel_vpp_ipsec_t *this,
1671 kernel_ipsec_sa_id_t *id, kernel_ipsec_del_sa_t *data)
1675 vl_api_ipsec_sad_entry_add_del_t *mp;
1676 vl_api_ipsec_sad_entry_add_del_reply_t *rmp;
1677 status_t rv = FAILED;
1680 this->mutex->lock (this->mutex);
1681 sa = this->sas->get (this->sas, id);
1684 DBG1 (DBG_KNL, "SA not found");
1688 mp = vl_msg_api_alloc (sizeof (*mp));
1689 memset (mp, 0, sizeof (*mp));
1692 vl_msg_api_get_msg_index ((u8 *) "ipsec_sad_entry_add_del_ab64b5c6");
1693 mp->_vl_msg_id = htons (msg_id);
1694 mp->entry.sad_id = htonl (sa->sa_id);
1696 if (vac->send (vac, (char *) mp, sizeof (*mp), &out, &out_len))
1698 DBG1 (DBG_KNL, "vac removing SA failed");
1704 DBG1 (DBG_KNL, "del SA failed rv:%d", ntohl (rmp->retval));
1708 vl_msg_api_free (mp);
1709 this->sas->remove (this->sas, id);
1713 this->mutex->unlock (this->mutex);
1717 METHOD (kernel_ipsec_t, flush_sas, status_t, private_kernel_vpp_ipsec_t *this)
1719 enumerator_t *enumerator;
1722 vl_api_ipsec_sad_entry_add_del_t *mp;
1725 this->mutex->lock (this->mutex);
1726 enumerator = this->sas->create_enumerator (this->sas);
1727 while (enumerator->enumerate (enumerator, sa, NULL))
1729 mp = vl_msg_api_alloc (sizeof (*mp));
1730 memset (mp, 0, sizeof (*mp));
1732 vl_msg_api_get_msg_index ((u8 *) "ipsec_sad_entry_add_del_ab64b5c6");
1733 mp->_vl_msg_id = htons (msg_id);
1734 mp->entry.sad_id = htonl (sa->sa_id);
1736 if (vac->send (vac, (char *) mp, sizeof (*mp), &out, &out_len))
1738 DBG1 (DBG_KNL, "flush_sas failed!!!!");
1742 vl_msg_api_free (mp);
1743 this->sas->remove_at (this->sas, enumerator);
1745 enumerator->destroy (enumerator);
1746 this->mutex->unlock (this->mutex);
1751 METHOD (kernel_ipsec_t, add_policy, status_t, private_kernel_vpp_ipsec_t *this,
1752 kernel_ipsec_policy_id_t *id, kernel_ipsec_manage_policy_t *data)
1754 return manage_policy (this, TRUE, id, data);
1757 METHOD (kernel_ipsec_t, query_policy, status_t,
1758 private_kernel_vpp_ipsec_t *this, kernel_ipsec_policy_id_t *id,
1759 kernel_ipsec_query_policy_t *data, time_t *use_time)
1761 return NOT_SUPPORTED;
1764 METHOD (kernel_ipsec_t, del_policy, status_t, private_kernel_vpp_ipsec_t *this,
1765 kernel_ipsec_policy_id_t *id, kernel_ipsec_manage_policy_t *data)
1767 return manage_policy (this, FALSE, id, data);
1770 METHOD (kernel_ipsec_t, flush_policies, status_t,
1771 private_kernel_vpp_ipsec_t *this)
1773 return NOT_SUPPORTED;
1776 METHOD (kernel_ipsec_t, bypass_socket, bool, private_kernel_vpp_ipsec_t *this,
1782 METHOD (kernel_ipsec_t, enable_udp_decap, bool,
1783 private_kernel_vpp_ipsec_t *this, int fd, int family, u_int16_t port)
1785 DBG1 (DBG_KNL, "enable_udp_decap not supported!!!!!!!!!!!!!!!!!!!!!!!!!");
1789 METHOD (kernel_ipsec_t, destroy, void, private_kernel_vpp_ipsec_t *this)
1791 this->mutex->destroy (this->mutex);
1792 this->sas->destroy (this->sas);
1793 this->spds->destroy (this->spds);
1794 this->routes->destroy (this->routes);
1798 kernel_vpp_ipsec_t *
1799 kernel_vpp_ipsec_create ()
1801 private_kernel_vpp_ipsec_t *this;
1806 .get_features = _get_features,
1807 .get_spi = _get_spi,
1808 .get_cpi = _get_cpi,
1810 .update_sa = _update_sa,
1811 .query_sa = _query_sa,
1813 .flush_sas = _flush_sas,
1814 .add_policy = _add_policy,
1815 .query_policy = _query_policy,
1816 .del_policy = _del_policy,
1817 .flush_policies = _flush_policies,
1818 .bypass_socket = _bypass_socket,
1819 .enable_udp_decap = _enable_udp_decap,
1820 .destroy = _destroy,
1825 .mutex = mutex_create(MUTEX_TYPE_DEFAULT),
1826 .sas = hashtable_create((hashtable_hash_t)sa_hash,
1827 (hashtable_equals_t)sa_equals, 32),
1828 .spds = hashtable_create((hashtable_hash_t)interface_hash,
1829 (hashtable_equals_t)interface_equals, 4),
1830 .routes = linked_list_create(),
1831 .install_routes = lib->settings->get_bool(lib->settings,
1832 "%s.install_routes", TRUE, lib->ns),
1833 .use_tunnel_mode_sa = lib->settings->get_bool(lib->settings,
1834 "%s.plugins.kernel-vpp.use_tunnel_mode_sa",
1838 if (!init_spi (this))
1844 return &this->public;