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
132 * Security association entry
142 * Security policy database
148 /** Networking interface ID restricting policy */
149 uint32_t sw_if_index;
150 /** Policy count for this SPD */
151 refcount_t policy_num;
159 /** Name of the interface the route is bound to */
161 /** Gateway of route */
163 /** Destination network of route */
165 /** Prefix length of dst_net */
167 /** References for route */
172 ((1 == htonl (1)) ? \
174 ((uint64_t) htonl ((x) &0xFFFFFFFF) << 32) | htonl ((x) >> 32))
176 ((1 == ntohl (1)) ? \
178 ((uint64_t) ntohl ((x) &0xFFFFFFFF) << 32) | ntohl ((x) >> 32))
180 CALLBACK (route_equals, bool, route_entry_t *a, va_list args)
182 host_t *dst_net, *gateway;
186 VA_ARGS_VGET (args, if_name, gateway, dst_net, prefixlen);
188 return a->if_name && if_name && streq (a->if_name, if_name) &&
189 a->gateway->ip_equals (a->gateway, gateway) &&
190 a->dst_net->ip_equals (a->dst_net, dst_net) &&
191 a->prefixlen == *prefixlen;
195 * Clean up a route entry
198 route_destroy (route_entry_t *this)
200 this->dst_net->destroy (this->dst_net);
201 this->gateway->destroy (this->gateway);
202 free (this->if_name);
206 static uint32_t get_sw_if_index ();
209 set_arp (char *ipStr, char *if_name, bool add)
213 vl_api_ip_neighbor_add_del_t *mp;
214 vl_api_ip_neighbor_add_del_reply_t *rmp;
216 uint32_t sw_if_index = ~0;
223 char *file = "/proc/net/arp";
224 unsigned char mac[8] = {
229 if (if_name == NULL || ipStr == NULL)
231 DBG2 (DBG_KNL, "para is null\n");
234 DBG2 (DBG_KNL, "from kernel read mac\n");
236 mp = vl_msg_api_alloc (sizeof (*mp));
237 memset (mp, 0, sizeof (*mp));
238 sw_if_index = get_sw_if_index (if_name);
239 if (sw_if_index == ~0)
241 DBG1 (DBG_KNL, "sw_if_index for %s not found", if_name);
245 fp = fopen (file, "rb");
246 while ((nread = getline (&buffer, &len, fp)) != -1)
248 sscanf (buffer, "%s %*s %*s %s %*s %*s", &buf[0], &buf[1]);
249 inet_aton (&buf[0], &addr);
251 if (addr == *((u32 *) (ipStr)))
253 sscanf (buf[1], "%02x:%02x:%02x:%02x:%02x:%02x", &mac[0], &mac[1],
254 &mac[2], &mac[3], &mac[4], &mac[5]);
256 vl_msg_api_get_msg_index ((u8 *) "ip_neighbor_add_del_0607c257");
257 mp->_vl_msg_id = htons (msg_id);
259 memcpy (mp->neighbor.ip_address.un.ip4, (u8 *) &addr, sizeof (addr));
260 mp->neighbor.ip_address.af = 0;
261 memcpy (mp->neighbor.mac_address, mac, 6);
262 mp->neighbor.sw_if_index = htonl (sw_if_index);
263 mp->neighbor.flags = 1;
265 if (vac->send (vac, (char *) mp, sizeof (*mp), &out, &out_len))
267 DBG1 (DBG_KNL, "vac %s neighbor entry",
268 add ? "adding" : "removing");
274 DBG1 (DBG_KNL, "%s neighbor add rv:%d", add ? "add" : "remove",
275 ntohl (rmp->retval));
286 vl_msg_api_free (mp);
291 add_Route (char *ipAddr, int len, char *mask, char *gateWay)
295 struct sockaddr_in _sin;
296 struct sockaddr_in *sin = &_sin;
301 fd = socket (AF_INET, SOCK_DGRAM, 0);
304 DBG2 (DBG_KNL, "addRoute: socket error\n");
308 memset (&rt, 0, sizeof (struct rtentry));
309 memset (sin, 0, sizeof (struct sockaddr_in));
310 sin->sin_family = AF_INET;
313 if (inet_aton (gateWay, &sin->sin_addr) < 0)
318 memcpy (&rt.rt_gateway, sin, sizeof (struct sockaddr_in));
320 ((struct sockaddr_in *) &rt.rt_dst)->sin_family = AF_INET;
321 memcpy (&((struct sockaddr_in *) &rt.rt_dst)->sin_addr, ipAddr, len);
323 ((struct sockaddr_in *) &rt.rt_genmask)->sin_family = AF_INET;
325 &((struct sockaddr_in *) &rt.rt_genmask)->sin_addr) < 0)
330 rt.rt_flags = RTF_GATEWAY;
331 if (ioctl (fd, SIOCADDRT, &rt) < 0)
343 set_address (u32 ipAddr, u32 sw_if_index, bool add)
347 vl_api_sw_interface_add_del_address_t *mp;
348 vl_api_sw_interface_add_del_address_reply_t *rmp;
354 mp = vl_msg_api_alloc (sizeof (*mp));
355 memset (mp, 0, sizeof (*mp));
358 vl_msg_api_get_msg_index ((u8 *) "sw_interface_add_del_address_5463d73b");
359 mp->_vl_msg_id = htons (msg_id);
361 memcpy (mp->prefix.address.un.ip4, (u8 *) &ipAddr, sizeof (ipAddr));
363 mp->sw_if_index = sw_if_index;
365 if (vac->send (vac, (char *) mp, sizeof (*mp), &out, &out_len))
367 DBG2 (DBG_KNL, "vac %s neighbor entry", add ? "adding" : "removing");
373 DBG2 (DBG_KNL, "%s neighbor add rv:%d", add ? "add" : "remove",
374 ntohl (rmp->retval));
381 vl_msg_api_free (mp);
386 * (Un)-install a single route
389 manage_route (private_kernel_vpp_ipsec_t *this, bool add,
390 traffic_selector_t *dst_ts, host_t *src, host_t *dst)
392 host_t *dst_net, *gateway;
395 route_entry_t *route;
396 bool route_exist = FALSE;
398 char *netmask = "255.255.255.0";
399 char *tap_gateway = "1.1.1.1";
401 if (dst->is_anyaddr (dst))
406 charon->kernel->get_nexthop (charon->kernel, dst, -1, NULL, &if_name);
407 dst_ts->to_subnet (dst_ts, &dst_net, &prefixlen);
410 if (src->is_anyaddr (src))
414 if (!charon->kernel->get_interface (charon->kernel, src, &if_name))
420 this->routes->find_first (this->routes, route_equals, (void **) &route,
421 if_name, gateway, dst_net, &prefixlen);
424 DBG2 (DBG_KNL, "installing route: %H/%d via %H dev %s", dst_net,
425 prefixlen, gateway, if_name);
428 unsigned int refs_num = ref_get (&route->refs);
429 DBG2 (DBG_KNL, "add route but it exist %d", refs_num);
433 INIT (route, .if_name = strdup (if_name),
434 .gateway = gateway->clone (gateway),
435 .dst_net = dst_net->clone (dst_net), .prefixlen = prefixlen,
437 this->routes->insert_last (this->routes, route);
438 charon->kernel->add_route (charon->kernel,
439 dst_net->get_address (dst_net), prefixlen,
440 gateway, dst, if_name, 1);
443 add_Route (dst_net->get_address (dst_net).ptr,
444 dst_net->get_address (dst_net).len, netmask, tap_gateway);
446 arp_rc = set_arp (gateway->get_address (gateway).ptr, if_name, TRUE);
448 DBG2 (DBG_KNL, "arpGet success!\n");
452 DBG2 (DBG_KNL, "uninstalling route: %H/%d via %H dev %s", dst_net,
453 prefixlen, gateway, if_name);
456 DBG2 (DBG_KNL, "del route but it not exist");
459 if (ref_put (&route->refs))
461 this->routes->remove (this->routes, route, NULL);
462 route_destroy (route);
463 charon->kernel->del_route (charon->kernel,
464 dst_net->get_address (dst_net), prefixlen,
465 gateway, dst, if_name, 1);
471 * Hash function for IPsec SA
474 sa_hash (kernel_ipsec_sa_id_t *sa)
476 return chunk_hash_inc (
477 sa->src->get_address (sa->src),
479 sa->dst->get_address (sa->dst),
480 chunk_hash_inc (chunk_from_thing (sa->spi),
481 chunk_hash (chunk_from_thing (sa->proto)))));
485 * Equality function for IPsec SA
488 sa_equals (kernel_ipsec_sa_id_t *sa, kernel_ipsec_sa_id_t *other_sa)
490 return sa->src->ip_equals (sa->src, other_sa->src) &&
491 sa->dst->ip_equals (sa->dst, other_sa->dst) &&
492 sa->spi == other_sa->spi && sa->proto == other_sa->proto;
496 * Hash function for interface
499 interface_hash (char *interface)
501 return chunk_hash (chunk_from_str (interface));
505 * Equality function for interface
508 interface_equals (char *interface1, char *interface2)
510 return streq (interface1, interface2);
514 * Map an integer x with a one-to-one function using quadratic residues
517 permute (u_int x, u_int p)
522 qr = ((uint64_t) x * x) % p;
531 * Initialize seeds for SPI generation
534 init_spi (private_kernel_vpp_ipsec_t *this)
539 rng = lib->crypto->create_rng (lib->crypto, RNG_STRONG);
545 rng->get_bytes (rng, sizeof (this->nextspi), (uint8_t *) &this->nextspi);
549 rng->get_bytes (rng, sizeof (this->mixspi), (uint8_t *) &this->mixspi);
556 * Calculate policy priority
559 calculate_priority (policy_priority_t policy_priority, traffic_selector_t *src,
560 traffic_selector_t *dst)
562 uint32_t priority = PRIO_BASE;
567 switch (policy_priority)
569 case POLICY_PRIORITY_FALLBACK:
572 case POLICY_PRIORITY_ROUTED:
575 case POLICY_PRIORITY_DEFAULT:
578 case POLICY_PRIORITY_PASS:
581 /* calculate priority based on selector size, small size = high prio */
582 src->to_subnet (src, &net, &mask);
584 proto = src->get_protocol (src);
585 port = net->get_port (net);
588 dst->to_subnet (dst, &net, &mask);
590 proto = max (proto, dst->get_protocol (dst));
591 port = max (port, net->get_port (net));
594 priority <<= 2; /* make some room for the two flags */
595 priority += port ? 0 : 2;
596 priority += proto ? 0 : 1;
601 * Get sw_if_index from interface name
604 get_sw_if_index (char *interface)
607 int out_len, name_filter_len = 0, msg_len = 0;
608 vl_api_sw_interface_dump_t *mp;
609 vl_api_sw_interface_details_t *rmp;
610 uint32_t sw_if_index = ~0;
612 name_filter_len = strlen (interface);
613 msg_len = sizeof (*mp) + name_filter_len;
614 mp = vl_msg_api_alloc (msg_len);
615 clib_memset (mp, 0, msg_len);
616 u16 msg_id = vl_msg_api_get_msg_index ((u8 *) "sw_interface_dump_aa610c27");
617 mp->_vl_msg_id = htons (msg_id);
618 mp->name_filter_valid = TRUE;
619 mp->name_filter.length = htonl (name_filter_len);
620 memcpy ((char *) mp->name_filter.buf, interface, name_filter_len);
622 if (vac->send (vac, (char *) mp, msg_len, &out, &out_len))
630 rmp = (vl_api_sw_interface_details_t *) out;
631 sw_if_index = ntohl (rmp->sw_if_index);
635 vl_msg_api_free (mp);
639 * (Un)-install a security policy database
642 spd_add_del (bool add, uint32_t spd_id)
646 vl_api_ipsec_spd_add_del_t *mp;
647 vl_api_ipsec_spd_add_del_reply_t *rmp;
648 status_t rv = FAILED;
650 mp = vl_msg_api_alloc (sizeof (*mp));
651 memset (mp, 0, sizeof (*mp));
653 u16 msg_id = vl_msg_api_get_msg_index ((u8 *) "ipsec_spd_add_del_20e89a95");
654 mp->_vl_msg_id = htons (msg_id);
656 mp->spd_id = htonl (spd_id);
657 if (vac->send (vac, (char *) mp, sizeof (*mp), &out, &out_len))
659 DBG1 (DBG_KNL, "vac %s SPD failed", add ? "adding" : "removing");
665 DBG1 (DBG_KNL, "%s SPD failed rv:%d", add ? "add" : "remove",
666 ntohl (rmp->retval));
673 vl_msg_api_free (mp);
678 * Enable or disable SPD on an insterface
681 interface_add_del_spd (bool add, uint32_t spd_id, uint32_t sw_if_index)
685 vl_api_ipsec_interface_add_del_spd_t *mp;
686 vl_api_ipsec_interface_add_del_spd_reply_t *rmp;
687 status_t rv = FAILED;
689 mp = vl_msg_api_alloc (sizeof (*mp));
690 memset (mp, 0, sizeof (*mp));
692 vl_msg_api_get_msg_index ((u8 *) "ipsec_interface_add_del_spd_80f80cbb");
693 mp->_vl_msg_id = htons (msg_id);
695 mp->spd_id = htonl (spd_id);
696 mp->sw_if_index = htonl (sw_if_index);
697 if (vac->send (vac, (char *) mp, sizeof (*mp), &out, &out_len))
699 DBG1 (DBG_KNL, "vac %s interface SPD failed",
700 add ? "adding" : "removing");
706 DBG1 (DBG_KNL, "%s interface SPD failed rv:%d", add ? "add" : "remove",
707 ntohl (rmp->retval));
714 vl_msg_api_free (mp);
719 bypass_all (bool add, uint32_t spd_id, uint32_t sa_id)
721 vl_api_ipsec_spd_entry_add_del_t *mp;
722 vl_api_ipsec_spd_entry_add_del_reply_t *rmp;
725 status_t rv = FAILED;
727 DBG2 (DBG_KNL, "bypass_all [%s] spd_id %d sa_id %d", add ? "ADD" : "DEL",
730 mp = vl_msg_api_alloc (sizeof (*mp));
731 memset (mp, 0, sizeof (*mp));
734 vl_msg_api_get_msg_index ((u8 *) "ipsec_spd_entry_add_del_338b7411");
735 mp->_vl_msg_id = ntohs (msg_id);
737 mp->entry.sa_id = ntohl (sa_id);
738 mp->entry.spd_id = ntohl (spd_id);
739 mp->entry.priority = ntohl (INT_MAX - POLICY_PRIORITY_PASS - 1);
740 mp->entry.is_outbound = 0;
741 mp->entry.policy = ntohl (IPSEC_API_SPD_ACTION_BYPASS);
742 memset (mp->entry.local_address_stop.un.ip6, 0xFF, 16);
743 memset (mp->entry.remote_address_stop.un.ip6, 0xFF, 16);
744 mp->entry.remote_port_start = mp->entry.local_port_start = ntohs (0);
745 mp->entry.remote_port_stop = mp->entry.local_port_stop = ntohs (0xFFFF);
746 mp->entry.protocol = IP_API_PROTO_ESP;
747 if (vac->send (vac, (char *) mp, sizeof (*mp), &out, &out_len))
749 DBG1 (DBG_KNL, "vac %s SPD entry failed", add ? "adding" : "removing");
755 DBG1 (DBG_KNL, "%s SPD entry failed rv:%d", add ? "add" : "remove",
756 ntohl (rmp->retval));
759 mp->entry.is_outbound = 1;
760 if (vac->send (vac, (char *) mp, sizeof (*mp), &out, &out_len))
762 DBG1 (DBG_KNL, "vac %s SPD entry failed", add ? "adding" : "removing");
768 DBG1 (DBG_KNL, "%s SPD entry failed rv:%d", add ? "add" : "remove",
769 ntohl (rmp->retval));
772 mp->entry.is_outbound = 0;
773 mp->entry.protocol = IP_API_PROTO_AH;
774 if (vac->send (vac, (char *) mp, sizeof (*mp), &out, &out_len))
776 DBG1 (DBG_KNL, "vac %s SPD entry failed", add ? "adding" : "removing");
782 DBG1 (DBG_KNL, "%s SPD entry failed rv:%d", add ? "add" : "remove",
783 ntohl (rmp->retval));
786 mp->entry.is_outbound = 1;
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));
805 vl_msg_api_free (mp);
811 bypass_port (bool add, uint32_t spd_id, uint32_t sa_id, uint16_t port)
813 vl_api_ipsec_spd_entry_add_del_t *mp;
814 vl_api_ipsec_spd_entry_add_del_reply_t *rmp;
817 status_t rv = FAILED;
819 mp = vl_msg_api_alloc (sizeof (*mp));
820 memset (mp, 0, sizeof (*mp));
823 vl_msg_api_get_msg_index ((u8 *) "ipsec_spd_entry_add_del_338b7411");
824 mp->_vl_msg_id = ntohs (msg_id);
826 mp->entry.sa_id = ntohl (sa_id);
827 mp->entry.spd_id = ntohl (spd_id);
828 mp->entry.priority = ntohl (INT_MAX - POLICY_PRIORITY_PASS - 1);
829 mp->entry.policy = ntohl (IPSEC_API_SPD_ACTION_BYPASS);
830 memset (mp->entry.local_address_stop.un.ip6, 0xFF, 16);
831 memset (mp->entry.remote_address_stop.un.ip6, 0xFF, 16);
832 mp->entry.is_outbound = 0;
833 mp->entry.remote_port_start = mp->entry.local_port_start = ntohs (0);
834 mp->entry.remote_port_stop = mp->entry.local_port_stop = ntohs (0xFFFF);
835 mp->entry.protocol = IP_API_PROTO_HOPOPT;
837 if (vac->send (vac, (char *) mp, sizeof (*mp), &out, &out_len))
839 DBG1 (DBG_KNL, "vac %s SPD entry failed", add ? "adding" : "removing");
845 DBG1 (DBG_KNL, "%s SPD entry failed rv:%d", add ? "add" : "remove",
846 ntohl (rmp->retval));
849 mp->entry.is_outbound = 1;
850 if (vac->send (vac, (char *) mp, sizeof (*mp), &out, &out_len))
852 DBG1 (DBG_KNL, "vac %s SPD entry failed", add ? "adding" : "removing");
858 DBG1 (DBG_KNL, "%s SPD entry failed rv:%d", add ? "add" : "remove",
859 ntohl (rmp->retval));
867 vl_msg_api_free (mp);
873 * Add or remove a bypass policy
876 manage_bypass (bool add, uint32_t spd_id, uint32_t sa_id)
881 bypass_all (add, spd_id, sa_id);
884 lib->settings->get_int (lib->settings, "%s.port", IKEV2_UDP_PORT, lib->ns);
888 rv = bypass_port (add, spd_id, sa_id, port);
895 port = lib->settings->get_int (lib->settings, "%s.port_nat_t",
896 IKEV2_NATT_PORT, lib->ns);
899 rv = bypass_port (add, spd_id, sa_id, port);
910 * Add or remove a policy
913 manage_policy (private_kernel_vpp_ipsec_t *this, bool add,
914 kernel_ipsec_policy_id_t *id,
915 kernel_ipsec_manage_policy_t *data)
918 char *out = NULL, *interface = NULL;
920 uint32_t sw_if_index, spd_id = ~0, sad_id = ~0;
921 status_t rv = FAILED;
922 uint32_t priority, auto_priority;
923 chunk_t src_from, src_to, dst_from, dst_to;
924 host_t *src, *dst, *addr;
925 vl_api_ipsec_spd_entry_add_del_t *mp;
926 vl_api_ipsec_spd_entry_add_del_reply_t *rmp;
929 mp = vl_msg_api_alloc (sizeof (*mp));
930 memset (mp, 0, sizeof (*mp));
932 this->mutex->lock (this->mutex);
935 addr = id->dir == POLICY_IN ? data->dst : data->src;
936 for (int i = 0; i < 5; i++)
938 if (!charon->kernel->get_interface (charon->kernel, addr,
941 DBG1 (DBG_KNL, "policy no interface %H", addr);
948 DBG1 (DBG_KNL, "policy have interface %H", addr);
954 id->interface = interface;
957 DBG2 (DBG_KNL, "manage policy [%s] interface [%s]", add ? "ADD" : "DEL",
960 spd = this->spds->get (this->spds, id->interface);
965 DBG1 (DBG_KNL, "SPD for %s not found, should not be deleted",
969 sw_if_index = get_sw_if_index (id->interface);
970 DBG1 (DBG_KNL, "firstly created, spd for %s found sw_if_index is %d",
971 id->interface, sw_if_index);
972 if (sw_if_index == ~0)
974 DBG1 (DBG_KNL, "sw_if_index for %s not found", id->interface);
977 spd_id = ref_get (&this->next_spd_id);
978 if (spd_add_del (TRUE, spd_id))
980 DBG1 (DBG_KNL, "spd_add_del %d failed!!!!!", spd_id);
983 if (interface_add_del_spd (TRUE, spd_id, sw_if_index))
985 DBG1 (DBG_KNL, "interface_add_del_spd %d %d failed!!!!!", spd_id,
989 INIT (spd, .spd_id = spd_id, .sw_if_index = sw_if_index,
991 this->spds->put (this->spds, id->interface, spd);
995 auto_priority = calculate_priority (data->prio, id->src_ts, id->dst_ts);
996 priority = data->manual_prio ? data->manual_prio : auto_priority;
999 vl_msg_api_get_msg_index ((u8 *) "ipsec_spd_entry_add_del_338b7411");
1000 mp->_vl_msg_id = htons (msg_id);
1002 mp->entry.spd_id = htonl (spd->spd_id);
1003 mp->entry.priority = htonl (INT_MAX - POLICY_PRIORITY_PASS);
1004 mp->entry.is_outbound = id->dir == POLICY_OUT;
1008 mp->entry.policy = htonl (IPSEC_API_SPD_ACTION_PROTECT);
1011 mp->entry.policy = htonl (IPSEC_API_SPD_ACTION_BYPASS);
1014 mp->entry.policy = htonl (IPSEC_API_SPD_ACTION_DISCARD);
1017 if ((data->type == POLICY_IPSEC) && data->sa)
1019 kernel_ipsec_sa_id_t id = {
1022 .proto = data->sa->esp.use ? IPPROTO_ESP : IPPROTO_AH,
1023 .spi = data->sa->esp.use ? data->sa->esp.spi : data->sa->ah.spi,
1026 sa = this->sas->get (this->sas, &id);
1029 DBG1 (DBG_KNL, "SA ID not found");
1035 if (manage_bypass (TRUE, spd_id, ~0))
1037 DBG1 (DBG_KNL, "manage_bypass %d failed!!!!", spd_id);
1043 mp->entry.sa_id = htonl (sad_id);
1045 bool is_ipv6 = false;
1046 if (id->src_ts->get_type (id->src_ts) == TS_IPV6_ADDR_RANGE)
1049 mp->entry.local_address_start.af = htonl (ADDRESS_IP6);
1050 mp->entry.local_address_stop.af = htonl (ADDRESS_IP6);
1051 mp->entry.remote_address_start.af = htonl (ADDRESS_IP6);
1052 mp->entry.remote_address_stop.af = htonl (ADDRESS_IP6);
1056 mp->entry.local_address_start.af = htonl (ADDRESS_IP4);
1057 mp->entry.local_address_stop.af = htonl (ADDRESS_IP4);
1058 mp->entry.remote_address_start.af = htonl (ADDRESS_IP4);
1059 mp->entry.remote_address_stop.af = htonl (ADDRESS_IP4);
1061 mp->entry.protocol = id->src_ts->get_protocol (id->src_ts);
1063 if (id->dir == POLICY_OUT)
1065 src_from = id->src_ts->get_from_address (id->src_ts);
1066 src_to = id->src_ts->get_to_address (id->src_ts);
1067 src = host_create_from_chunk (is_ipv6 ? AF_INET6 : AF_INET, src_to, 0);
1068 dst_from = id->dst_ts->get_from_address (id->dst_ts);
1069 dst_to = id->dst_ts->get_to_address (id->dst_ts);
1070 dst = host_create_from_chunk (is_ipv6 ? AF_INET6 : AF_INET, dst_to, 0);
1074 dst_from = id->src_ts->get_from_address (id->src_ts);
1075 dst_to = id->src_ts->get_to_address (id->src_ts);
1076 dst = host_create_from_chunk (is_ipv6 ? AF_INET6 : AF_INET, dst_from, 0);
1077 src_from = id->dst_ts->get_from_address (id->dst_ts);
1078 src_to = id->dst_ts->get_to_address (id->dst_ts);
1079 src = host_create_from_chunk (is_ipv6 ? AF_INET6 : AF_INET, src_from, 0);
1082 if (src->is_anyaddr (src) && dst->is_anyaddr (dst))
1084 memset (mp->entry.local_address_stop.un.ip6, 0xFF, 16);
1085 memset (mp->entry.remote_address_stop.un.ip6, 0xFF, 16);
1089 memcpy (is_ipv6 ? mp->entry.local_address_start.un.ip6 :
1090 mp->entry.local_address_start.un.ip4,
1091 src_from.ptr, src_from.len);
1092 memcpy (is_ipv6 ? mp->entry.local_address_stop.un.ip6 :
1093 mp->entry.local_address_stop.un.ip4,
1094 src_to.ptr, src_to.len);
1095 memcpy (is_ipv6 ? mp->entry.remote_address_start.un.ip6 :
1096 mp->entry.remote_address_start.un.ip4,
1097 dst_from.ptr, dst_from.len);
1098 memcpy (is_ipv6 ? mp->entry.remote_address_stop.un.ip6 :
1099 mp->entry.remote_address_stop.un.ip4,
1100 dst_to.ptr, dst_to.len);
1102 mp->entry.local_port_start = htons (id->src_ts->get_from_port (id->src_ts));
1103 mp->entry.local_port_stop = htons (id->src_ts->get_to_port (id->src_ts));
1104 mp->entry.remote_port_start = htons (id->dst_ts->get_from_port (id->dst_ts));
1105 mp->entry.remote_port_stop = htons (id->dst_ts->get_to_port (id->dst_ts));
1107 if (vac->send (vac, (char *) mp, sizeof (*mp), &out, &out_len))
1109 DBG1 (DBG_KNL, "vac %s SPD entry failed", add ? "adding" : "removing");
1115 DBG1 (DBG_KNL, "%s SPD entry failed rv:%d", add ? "add" : "remove",
1116 ntohl (rmp->retval));
1122 ref_get (&spd->policy_num);
1126 if (ref_put (&spd->policy_num))
1130 "policy_num's ref is 0, delete spd_id %d sw_if_index %d sad_id %x",
1131 spd->spd_id, spd->sw_if_index, sad_id);
1132 interface_add_del_spd (FALSE, spd->spd_id, spd->sw_if_index);
1133 manage_bypass (FALSE, spd->spd_id, sad_id);
1134 spd_add_del (FALSE, spd->spd_id);
1135 this->spds->remove (this->spds, id->interface);
1139 if (this->install_routes && id->dir == POLICY_OUT && !mp->entry.protocol)
1141 if (data->type == POLICY_IPSEC && data->sa->mode != MODE_TRANSPORT)
1143 manage_route (this, add, id->dst_ts, data->src, data->dst);
1149 vl_msg_api_free (mp);
1150 this->mutex->unlock (this->mutex);
1154 METHOD (kernel_ipsec_t, get_features, kernel_feature_t,
1155 private_kernel_vpp_ipsec_t *this)
1157 return KERNEL_ESP_V3_TFC;
1160 METHOD (kernel_ipsec_t, get_spi, status_t, private_kernel_vpp_ipsec_t *this,
1161 host_t *src, host_t *dst, uint8_t protocol, uint32_t *spi)
1163 static const u_int p = 268435399, offset = 0xc0000000;
1165 *spi = htonl (offset + permute (ref_get (&this->nextspi) ^ this->mixspi, p));
1169 METHOD (kernel_ipsec_t, get_cpi, status_t, private_kernel_vpp_ipsec_t *this,
1170 host_t *src, host_t *dst, uint16_t *cpi)
1172 DBG1 (DBG_KNL, "get_cpi is not supported!!!!!!!!!!!!!!!!!!!!!!!!");
1173 return NOT_SUPPORTED;
1177 * Helper struct for expiration events
1182 private_kernel_vpp_ipsec_t *manager;
1184 kernel_ipsec_sa_id_t *sa_id;
1187 * 0 if this is a hard expire, otherwise the offset in s (soft->hard)
1189 uint32_t hard_offset;
1194 * Callback for expiration events
1196 static job_requeue_t
1197 sa_expired (vpp_sa_expired_t *expired)
1199 private_kernel_vpp_ipsec_t *this = expired->manager;
1201 kernel_ipsec_sa_id_t *id = expired->sa_id;
1203 this->mutex->lock (this->mutex);
1204 sa = this->sas->get (this->sas, id);
1208 charon->kernel->expire (charon->kernel, id->proto, id->spi, id->dst,
1213 this->mutex->unlock (this->mutex);
1214 return JOB_REQUEUE_NONE;
1218 * Schedule a job to handle IPsec SA expiration
1221 schedule_expiration (private_kernel_vpp_ipsec_t *this,
1222 kernel_ipsec_add_sa_t *entry,
1223 kernel_ipsec_sa_id_t *entry2)
1225 lifetime_cfg_t *lifetime = entry->lifetime;
1226 vpp_sa_expired_t *expired;
1227 callback_job_t *job;
1229 kernel_ipsec_sa_id_t *id;
1231 if (!lifetime->time.life)
1232 { /* no expiration at all */
1236 INIT (id, .src = entry2->src->clone (entry2->src),
1237 .dst = entry2->dst->clone (entry2->dst), .spi = entry2->spi,
1238 .proto = entry2->proto, );
1240 INIT (expired, .manager = this, .sa_id = id, );
1242 /* schedule a rekey first, a hard timeout will be scheduled then, if any */
1243 expired->hard_offset = lifetime->time.life - lifetime->time.rekey;
1244 timeout = lifetime->time.rekey;
1246 if (lifetime->time.life <= lifetime->time.rekey || lifetime->time.rekey == 0)
1247 { /* no rekey, schedule hard timeout */
1248 expired->hard_offset = 0;
1249 timeout = lifetime->time.life;
1252 job = callback_job_create ((callback_job_cb_t) sa_expired, expired,
1253 (callback_job_cleanup_t) free, NULL);
1254 lib->scheduler->schedule_job (lib->scheduler, (job_t *) job, timeout);
1257 METHOD (kernel_ipsec_t, add_sa, status_t, private_kernel_vpp_ipsec_t *this,
1258 kernel_ipsec_sa_id_t *id, kernel_ipsec_add_sa_t *data)
1262 vl_api_ipsec_sad_entry_add_del_t *mp;
1263 vl_api_ipsec_sad_entry_add_del_reply_t *rmp;
1264 uint32_t sad_id = ref_get (&this->next_sad_id);
1265 uint8_t ca = 0, ia = 0;
1266 status_t rv = FAILED;
1268 kernel_ipsec_sa_id_t *sa_id;
1270 int key_len = data->enc_key.len;
1272 if ((data->enc_alg == ENCR_AES_CTR) ||
1273 (data->enc_alg == ENCR_AES_GCM_ICV8) ||
1274 (data->enc_alg == ENCR_AES_GCM_ICV12) ||
1275 (data->enc_alg == ENCR_AES_GCM_ICV16))
1277 static const int SALT_SIZE =
1278 4; /* See how enc_size is calculated at keymat_v2.derive_child_keys */
1279 key_len = key_len - SALT_SIZE;
1281 natt_port = lib->settings->get_int (
1282 lib->settings, "%s.plugins.socket-default.natt", IKEV2_NATT_PORT, lib->ns);
1283 mp = vl_msg_api_alloc (sizeof (*mp));
1284 memset (mp, 0, sizeof (*mp));
1286 vl_msg_api_get_msg_index ((u8 *) "ipsec_sad_entry_add_del_ab64b5c6");
1287 mp->_vl_msg_id = htons (msg_id);
1289 mp->entry.sad_id = htonl (sad_id);
1290 mp->entry.spi = id->spi;
1291 mp->entry.protocol = id->proto == IPPROTO_ESP ? htonl (IPSEC_API_PROTO_ESP) :
1292 htonl (IPSEC_API_PROTO_AH);
1294 switch (data->enc_alg)
1297 ca = IPSEC_API_CRYPTO_ALG_NONE;
1300 switch (key_len * 8)
1303 ca = IPSEC_API_CRYPTO_ALG_AES_CBC_128;
1306 ca = IPSEC_API_CRYPTO_ALG_AES_CBC_192;
1309 ca = IPSEC_API_CRYPTO_ALG_AES_CBC_256;
1312 DBG1 (DBG_KNL, "Key length %d is not supported by VPP!",
1318 switch (key_len * 8)
1321 ca = IPSEC_API_CRYPTO_ALG_AES_CTR_128;
1324 ca = IPSEC_API_CRYPTO_ALG_AES_CTR_192;
1327 ca = IPSEC_API_CRYPTO_ALG_AES_CTR_256;
1330 DBG1 (DBG_KNL, "Key length %d is not supported by VPP!",
1335 case ENCR_AES_GCM_ICV8:
1336 case ENCR_AES_GCM_ICV12:
1337 case ENCR_AES_GCM_ICV16:
1338 switch (key_len * 8)
1341 ca = IPSEC_API_CRYPTO_ALG_AES_GCM_128;
1344 ca = IPSEC_API_CRYPTO_ALG_AES_GCM_192;
1347 ca = IPSEC_API_CRYPTO_ALG_AES_GCM_256;
1350 DBG1 (DBG_KNL, "Key length %d is not supported by VPP!",
1356 ca = IPSEC_API_CRYPTO_ALG_DES_CBC;
1359 ca = IPSEC_API_CRYPTO_ALG_3DES_CBC;
1362 DBG1 (DBG_KNL, "algorithm %N not supported by VPP!",
1363 encryption_algorithm_names, data->enc_alg);
1366 mp->entry.crypto_algorithm = htonl (ca);
1367 mp->entry.crypto_key.length = key_len < 128 ? key_len : 128;
1368 memcpy (mp->entry.crypto_key.data, data->enc_key.ptr,
1369 mp->entry.crypto_key.length);
1371 /* copy salt for AEAD algorithms */
1372 if ((data->enc_alg == ENCR_AES_CTR) ||
1373 (data->enc_alg == ENCR_AES_GCM_ICV8) ||
1374 (data->enc_alg == ENCR_AES_GCM_ICV12) ||
1375 (data->enc_alg == ENCR_AES_GCM_ICV16))
1377 memcpy (&mp->entry.salt, data->enc_key.ptr + mp->entry.crypto_key.length,
1381 switch (data->int_alg)
1383 case AUTH_UNDEFINED:
1384 ia = IPSEC_API_INTEG_ALG_NONE;
1386 case AUTH_HMAC_MD5_96:
1387 ia = IPSEC_API_INTEG_ALG_MD5_96;
1389 case AUTH_HMAC_SHA1_96:
1390 ia = IPSEC_API_INTEG_ALG_SHA1_96;
1392 case AUTH_HMAC_SHA2_256_96:
1393 ia = IPSEC_API_INTEG_ALG_SHA_256_96;
1395 case AUTH_HMAC_SHA2_256_128:
1396 ia = IPSEC_API_INTEG_ALG_SHA_256_128;
1398 case AUTH_HMAC_SHA2_384_192:
1399 ia = IPSEC_API_INTEG_ALG_SHA_384_192;
1401 case AUTH_HMAC_SHA2_512_256:
1402 ia = IPSEC_API_INTEG_ALG_SHA_512_256;
1405 DBG1 (DBG_KNL, "algorithm %N not supported by VPP!",
1406 integrity_algorithm_names, data->int_alg);
1410 mp->entry.integrity_algorithm = htonl (ia);
1411 mp->entry.integrity_key.length =
1412 data->int_key.len < 128 ? data->int_key.len : 128;
1413 memcpy (mp->entry.integrity_key.data, data->int_key.ptr,
1414 mp->entry.integrity_key.length);
1416 int flags = IPSEC_API_SAD_FLAG_NONE;
1418 flags |= IPSEC_API_SAD_FLAG_USE_ESN;
1419 if (data->mode == MODE_TUNNEL)
1421 if (id->src->get_family (id->src) == AF_INET6)
1422 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL_V6;
1424 flags |= IPSEC_API_SAD_FLAG_IS_TUNNEL;
1428 DBG1 (DBG_KNL, "UDP encap!!!!!!!!!!!!!!!!!!!!");
1429 flags |= IPSEC_API_SAD_FLAG_UDP_ENCAP;
1431 mp->entry.flags = htonl (flags);
1433 bool is_ipv6 = false;
1434 if (id->src->get_family (id->src) == AF_INET6)
1437 mp->entry.tunnel_src.af = htonl (ADDRESS_IP6);
1438 mp->entry.tunnel_dst.af = htonl (ADDRESS_IP6);
1442 mp->entry.tunnel_src.af = htonl (ADDRESS_IP4);
1443 mp->entry.tunnel_dst.af = htonl (ADDRESS_IP4);
1445 src = id->src->get_address (id->src);
1446 memcpy (is_ipv6 ? mp->entry.tunnel_src.un.ip6 : mp->entry.tunnel_src.un.ip4,
1448 dst = id->dst->get_address (id->dst);
1449 memcpy (is_ipv6 ? mp->entry.tunnel_dst.un.ip6 : mp->entry.tunnel_dst.un.ip4,
1451 if (vac->send (vac, (char *) mp, sizeof (*mp), &out, &out_len))
1453 DBG1 (DBG_KNL, "vac adding SA failed");
1459 DBG1 (DBG_KNL, "add SA failed rv:%d", ntohl (rmp->retval));
1463 this->mutex->lock (this->mutex);
1464 INIT (sa_id, .src = id->src->clone (id->src),
1465 .dst = id->dst->clone (id->dst), .spi = id->spi, .proto = id->proto, );
1466 INIT (sa, .sa_id = sad_id, .stat_index = ntohl (rmp->stat_index), );
1467 DBG4 (DBG_KNL, "put sa by its sa_id %x !!!!!!", sad_id);
1468 this->sas->put (this->sas, sa_id, sa);
1469 schedule_expiration (this, data, id);
1470 this->mutex->unlock (this->mutex);
1475 vl_msg_api_free (mp);
1479 METHOD (kernel_ipsec_t, update_sa, status_t, private_kernel_vpp_ipsec_t *this,
1480 kernel_ipsec_sa_id_t *id, kernel_ipsec_update_sa_t *data)
1483 "update sa not supported!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
1484 return NOT_SUPPORTED;
1487 METHOD (kernel_ipsec_t, query_sa, status_t, private_kernel_vpp_ipsec_t *this,
1488 kernel_ipsec_sa_id_t *id, kernel_ipsec_query_sa_t *data,
1489 uint64_t *bytes, uint64_t *packets, time_t *time)
1491 status_t rv = FAILED;
1495 stat_segment_data_t *res;
1497 uint64_t res_bytes = 0;
1498 uint64_t res_packets = 0;
1500 this->mutex->lock (this->mutex);
1501 sa = this->sas->get (this->sas, id);
1502 this->mutex->unlock (this->mutex);
1505 DBG1 (DBG_KNL, "SA not found");
1509 int rv_stat = stat_segment_connect ("/run/vpp/stats.sock");
1512 DBG1 (DBG_KNL, "Not connecting with stats segmentation");
1515 vec_add1 (pattern, (u8 *) "/net/ipsec/sa");
1516 dir = stat_segment_ls ((u8 **) pattern);
1517 res = stat_segment_dump (dir);
1518 /* i-loop for each results find by pattern - here two:
1520 * 2. /net/ipsec/sa/lost
1522 for (i = 0; i < vec_len (res); i++)
1524 switch (res[i].type)
1526 /* type for how many packets are lost */
1527 case STAT_DIR_TYPE_COUNTER_VECTOR_SIMPLE:
1528 if (res[i].simple_counter_vec == 0)
1531 /* type for counter for each SA */
1532 case STAT_DIR_TYPE_COUNTER_VECTOR_COMBINED:
1533 if (res[i].combined_counter_vec == 0)
1535 /* k-loop for each threads - that you run VPP */
1536 for (k = 0; k < vec_len (res[i].combined_counter_vec); k++)
1538 if (sa->stat_index <= vec_len (res[i].combined_counter_vec[k]))
1540 DBG4 (DBG_KNL, "Thread: %d, Packets: %lu, Bytes: %lu", k,
1541 res[i].combined_counter_vec[k][sa->stat_index].packets,
1542 res[i].combined_counter_vec[k][sa->stat_index].bytes);
1544 res[i].combined_counter_vec[k][sa->stat_index].bytes;
1546 res[i].combined_counter_vec[k][sa->stat_index].packets;
1550 case STAT_DIR_TYPE_NAME_VECTOR:
1551 if (res[i].name_vector == 0)
1556 stat_segment_data_free (res);
1557 stat_segment_disconnect ();
1568 *packets = res_packets;
1579 METHOD (kernel_ipsec_t, del_sa, status_t, private_kernel_vpp_ipsec_t *this,
1580 kernel_ipsec_sa_id_t *id, kernel_ipsec_del_sa_t *data)
1584 vl_api_ipsec_sad_entry_add_del_t *mp;
1585 vl_api_ipsec_sad_entry_add_del_reply_t *rmp;
1586 status_t rv = FAILED;
1589 this->mutex->lock (this->mutex);
1590 sa = this->sas->get (this->sas, id);
1593 DBG1 (DBG_KNL, "SA not found");
1597 mp = vl_msg_api_alloc (sizeof (*mp));
1598 memset (mp, 0, sizeof (*mp));
1601 vl_msg_api_get_msg_index ((u8 *) "ipsec_sad_entry_add_del_ab64b5c6");
1602 mp->_vl_msg_id = htons (msg_id);
1603 mp->entry.sad_id = htonl (sa->sa_id);
1605 if (vac->send (vac, (char *) mp, sizeof (*mp), &out, &out_len))
1607 DBG1 (DBG_KNL, "vac removing SA failed");
1613 DBG1 (DBG_KNL, "del SA failed rv:%d", ntohl (rmp->retval));
1617 vl_msg_api_free (mp);
1618 this->sas->remove (this->sas, id);
1622 this->mutex->unlock (this->mutex);
1626 METHOD (kernel_ipsec_t, flush_sas, status_t, private_kernel_vpp_ipsec_t *this)
1628 enumerator_t *enumerator;
1631 vl_api_ipsec_sad_entry_add_del_t *mp;
1634 this->mutex->lock (this->mutex);
1635 enumerator = this->sas->create_enumerator (this->sas);
1636 while (enumerator->enumerate (enumerator, sa, NULL))
1638 mp = vl_msg_api_alloc (sizeof (*mp));
1639 memset (mp, 0, sizeof (*mp));
1641 vl_msg_api_get_msg_index ((u8 *) "ipsec_sad_entry_add_del_ab64b5c6");
1642 mp->_vl_msg_id = htons (msg_id);
1643 mp->entry.sad_id = htonl (sa->sa_id);
1645 if (vac->send (vac, (char *) mp, sizeof (*mp), &out, &out_len))
1647 DBG1 (DBG_KNL, "flush_sas failed!!!!");
1651 vl_msg_api_free (mp);
1652 this->sas->remove_at (this->sas, enumerator);
1654 enumerator->destroy (enumerator);
1655 this->mutex->unlock (this->mutex);
1660 METHOD (kernel_ipsec_t, add_policy, status_t, private_kernel_vpp_ipsec_t *this,
1661 kernel_ipsec_policy_id_t *id, kernel_ipsec_manage_policy_t *data)
1663 return manage_policy (this, TRUE, id, data);
1666 METHOD (kernel_ipsec_t, query_policy, status_t,
1667 private_kernel_vpp_ipsec_t *this, kernel_ipsec_policy_id_t *id,
1668 kernel_ipsec_query_policy_t *data, time_t *use_time)
1670 return NOT_SUPPORTED;
1673 METHOD (kernel_ipsec_t, del_policy, status_t, private_kernel_vpp_ipsec_t *this,
1674 kernel_ipsec_policy_id_t *id, kernel_ipsec_manage_policy_t *data)
1676 return manage_policy (this, FALSE, id, data);
1679 METHOD (kernel_ipsec_t, flush_policies, status_t,
1680 private_kernel_vpp_ipsec_t *this)
1682 return NOT_SUPPORTED;
1685 METHOD (kernel_ipsec_t, bypass_socket, bool, private_kernel_vpp_ipsec_t *this,
1691 METHOD (kernel_ipsec_t, enable_udp_decap, bool,
1692 private_kernel_vpp_ipsec_t *this, int fd, int family, u_int16_t port)
1694 DBG1 (DBG_KNL, "enable_udp_decap not supported!!!!!!!!!!!!!!!!!!!!!!!!!");
1698 METHOD (kernel_ipsec_t, destroy, void, private_kernel_vpp_ipsec_t *this)
1700 this->mutex->destroy (this->mutex);
1701 this->sas->destroy (this->sas);
1702 this->spds->destroy (this->spds);
1703 this->routes->destroy (this->routes);
1707 kernel_vpp_ipsec_t *
1708 kernel_vpp_ipsec_create ()
1710 private_kernel_vpp_ipsec_t *this;
1715 .get_features = _get_features,
1716 .get_spi = _get_spi,
1717 .get_cpi = _get_cpi,
1719 .update_sa = _update_sa,
1720 .query_sa = _query_sa,
1722 .flush_sas = _flush_sas,
1723 .add_policy = _add_policy,
1724 .query_policy = _query_policy,
1725 .del_policy = _del_policy,
1726 .flush_policies = _flush_policies,
1727 .bypass_socket = _bypass_socket,
1728 .enable_udp_decap = _enable_udp_decap,
1729 .destroy = _destroy,
1734 .mutex = mutex_create(MUTEX_TYPE_DEFAULT),
1735 .sas = hashtable_create((hashtable_hash_t)sa_hash,
1736 (hashtable_equals_t)sa_equals, 32),
1737 .spds = hashtable_create((hashtable_hash_t)interface_hash,
1738 (hashtable_equals_t)interface_equals, 4),
1739 .routes = linked_list_create(),
1740 .install_routes = lib->settings->get_bool(lib->settings,
1741 "%s.install_routes", TRUE, lib->ns),
1744 if (!init_spi (this))
1750 return &this->public;