# Copyright (c) 2018-2020 Cisco and/or its affiliates. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. add_definitions (-DWITH_LIBSSL=1) include_directories(${OPENSSL_INCLUDE_DIR}) unset(VNET_SOURCES) unset(VNET_HEADERS) unset(VNET_API_FILES) unset(VNET_MULTIARCH_SOURCES) ############################################################################## # Generic stuff ############################################################################## list(APPEND VNET_SOURCES buffer.c config.c devices/devices.c devices/netlink.c flow/flow.c flow/flow_cli.c flow/flow_api.c handoff.c interface.c interface_api.c interface_cli.c interface_format.c interface_output.c interface_stats.c misc.c ) list(APPEND VNET_MULTIARCH_SOURCES interface_output.c interface_stats.c handoff.c ) list(APPEND VNET_HEADERS api_errno.h buffer.h config.h devices/devices.h devices/netlink.h flow/flow.h global_funcs.h handoff.h interface.h interface_funcs.h interface_output.h ip/ip4_to_ip6.h ip/ip6_to_ip4.h ip/ip_types_api.h l3_types.h plugin/plugin.h pipeline.h vnet.h vnet_all_api_h.h vnet_msg_enum.h util/radix.h util/refcount.h format_fns.h ip/ip_format_fns.h ethernet/ethernet_format_fns.h ) list(APPEND VNET_API_FILES interface.api interface_types.api ip/ip_types.api flow/flow_types.api flow/flow.api ) ############################################################################## # Policer infra ############################################################################## list(APPEND VNET_SOURCES policer/node_funcs.c policer/policer.c policer/xlate.c policer/policer_api.c ) list(APPEND VNET_MULTIARCH_SOURCES policer/node_funcs.c ) list(APPEND VNET_HEADERS policer/police.h policer/policer.h policer/xlate.h ) list(APPEND VNET_API_FILES policer/policer.api policer/policer_types.api ) ############################################################################## # Binary API compatibility until vpp 20.12, see the ADL plugin... ############################################################################## list(APPEND VNET_SOURCES cop/cop_api.c ) list(APPEND VNET_API_FILES cop/cop.api) ############################################################################## # Layer 2 protocols go here ############################################################################## ############################################################################## # Layer 2 protocol: Ethernet ############################################################################## list(APPEND VNET_SOURCES ethernet/arp_packet.c ethernet/ethernet_types_api.c ethernet/format.c ethernet/init.c ethernet/interface.c ethernet/mac_address.c ethernet/node.c ethernet/pg.c ethernet/sfp.c ethernet/p2p_ethernet.c ethernet/p2p_ethernet_input.c ethernet/p2p_ethernet_api.c ) list(APPEND VNET_MULTIARCH_SOURCES ethernet/node.c ethernet/p2p_ethernet_input.c ) list(APPEND VNET_HEADERS ethernet/error.def ethernet/ethernet.h ethernet/mac_address.h ethernet/packet.h ethernet/types.def ethernet/sfp.h ethernet/p2p_ethernet.h ethernet/arp_packet.h ) list(APPEND VNET_API_FILES ethernet/p2p_ethernet.api ethernet/ethernet_types.api) ############################################################################## # Layer 2 protocol: Ethernet bridging ############################################################################## list(APPEND VNET_SOURCES l2/feat_bitmap.c l2/l2_api.c l2/l2_arp_term.c l2/l2_bd.c l2/l2_bvi.c l2/l2_bvi_node.c l2/l2_input_classify.c l2/l2_output_classify.c l2/l2_efp_filter.c l2/l2_fib.c l2/l2_flood.c l2/l2_fwd.c l2/l2_input.c l2/l2_input_node.c l2/l2_input_vtr.c l2/l2_learn.c l2/l2_output.c l2/l2_in_out_acl.c l2/l2_in_out_feat_arc.c l2/l2_patch.c l2/l2_rw.c l2/l2_uu_fwd.c l2/l2_vtr.c l2/l2_xcrw.c ) list(APPEND VNET_MULTIARCH_SOURCES l2/l2_bvi_node.c l2/l2_fwd.c l2/l2_learn.c l2/l2_output.c l2/l2_patch.c l2/l2_in_out_feat_arc.c l2/l2_input_classify.c l2/l2_input_node.c l2/l2_output_classify.c l2/l2_flood.c l2/l2_uu_fwd.c l2/l2_efp_filter.c l2/l2_rw.c l2/l2_xcrw.c l2/l2_in_out_acl.c l2/l2_input_vtr.c ) list(APPEND VNET_HEADERS l2/feat_bitmap.h l2/l2_input.h l2/l2_output.h l2/l2_vtr.h l2/l2_input_vtr.h l2/l2_efp_filter.h l2/l2_fwd.h l2/l2_bd.h l2/l2_bvi.h l2/l2_flood.h l2/l2_fib.h l2/l2_rw.h l2/l2_xcrw.h l2/l2_classify.h ) list(APPEND VNET_API_FILES l2/l2.api) ############################################################################## # Layer 2 protocol: SRP ############################################################################## list(APPEND VNET_SOURCES srp/format.c srp/interface.c srp/node.c srp/pg.c ) list(APPEND VNET_HEADERS srp/packet.h srp/srp.h ) ############################################################################## # Layer 2 protocol: PPP ############################################################################## list(APPEND VNET_SOURCES ppp/node.c ppp/pg.c ppp/ppp.c ) list(APPEND VNET_HEADERS ppp/error.def ppp/ppp.h ppp/packet.h ) ############################################################################## # Layer 2 protocol: HDLC ############################################################################## list(APPEND VNET_SOURCES hdlc/node.c hdlc/pg.c hdlc/hdlc.c ) list(APPEND VNET_HEADERS hdlc/error.def hdlc/hdlc.h hdlc/packet.h ) ############################################################################## # Layer 2 protocol: LLC ############################################################################## list(APPEND VNET_SOURCES llc/llc.c llc/node.c llc/pg.c ) list(APPEND VNET_HEADERS llc/llc.h ) ############################################################################## # Layer 2 protocol: SNAP ############################################################################## list(APPEND VNET_SOURCES snap/snap.c snap/node.c snap/pg.c ) list(APPEND VNET_HEADERS snap/snap.h ) ############################################################################## # Layer 2 / vxlan ############################################################################## list(APPEND VNET_SOURCES vxlan/vxlan.c vxlan/encap.c vxlan/decap.c vxlan/vxlan_api.c ) list(APPEND VNET_MULTIARCH_SOURCES vxlan/encap.c ) list(APPEND VNET_HEADERS vxlan/vxlan.h vxlan/vxlan_packet.h vxlan/vxlan_error.def ) list(APPEND VNET_MULTIARCH_SOURCES vxlan/decap.c) list(APPEND VNET_API_FILES vxlan/vxlan.api) ############################################################################## # Layer 2 / Bonding ############################################################################## list(APPEND VNET_SOURCES bonding/cli.c bonding/node.c bonding/device.c bonding/bond_api.c ) list(APPEND VNET_HEADERS bonding/node.h ) list(APPEND VNET_MULTIARCH_SOURCES bonding/node.c bonding/device.c) list(APPEND VNET_API_FILES bonding/bond.api) ############################################################################## # Layer 2/3 "classify" ############################################################################## list(APPEND VNET_SOURCES classify/vnet_classify.c classify/trace_classify.h classify/ip_classify.c classify/in_out_acl.c classify/policer_classify.c classify/flow_classify.c classify/flow_classify_node.c classify/vnet_classify.h classify/classify_api.c ) list(APPEND VNET_MULTIARCH_SOURCES classify/ip_classify.c classify/flow_classify_node.c ) list(APPEND VNET_HEADERS classify/vnet_classify.h classify/trace_classify.h classify/in_out_acl.h classify/policer_classify.h classify/flow_classify.h ) list(APPEND VNET_API_FILES classify/classify.api) ############################################################################## # Layer 3 protocols go here ############################################################################## ############################################################################## # Layer 3 protocol: IP v4/v6 ############################################################################## list(APPEND VNET_SOURCES ip/format.c ip/icmp4.c ip/icmp6.c ip/ip46_cli.c ip/ip_types_api.c ip/ip46_address.c ip/ip4_format.c ip/ip4_forward.c ip/ip4_punt_drop.c ip/ip4_input.c ip/ip4_options.c ip/ip4_mtrie.c ip/ip4_pg.c ip/ip4_source_and_port_range_check.c ip/reass/ip4_full_reass.c ip/reass/ip4_sv_reass.c ip/ip6_format.c ip/ip6_forward.c ip/ip6_ll_table.c ip/ip6_ll_types.c ip/ip6_punt_drop.c ip/ip6_hop_by_hop.c ip/ip6_input.c ip/ip6_link.c ip/ip6_pg.c ip/reass/ip6_full_reass.c ip/reass/ip6_sv_reass.c ip/ip_api.c ip/ip_checksum.c ip/ip_frag.c ip/ip.c ip/ip_interface.c ip/ip_init.c ip/ip_in_out_acl.c ip/ip_punt_drop.c ip/ip_types.c ip/lookup.c ip/punt_api.c ip/punt.c ip/punt_node.c ip/vtep.c ) list(APPEND VNET_MULTIARCH_SOURCES ip/ip4_punt_drop.c ip/reass/ip4_full_reass.c ip/ip6_hop_by_hop.c ip/reass/ip6_full_reass.c ip/reass/ip4_sv_reass.c ip/ip6_hop_by_hop.c ip/reass/ip6_full_reass.c ip/reass/ip6_sv_reass.c ip/ip6_input.c ip/ip6_punt_drop.c ip/punt_node.c ip/ip_in_out_acl.c ) list(APPEND VNET_HEADERS ip/format.h ip/icmp46_packet.h ip/icmp4.h ip/icmp6.h ip/igmp_packet.h ip/ip4_error.h ip/ip4.h ip/ip4_mtrie.h ip/ip4_packet.h ip/ip46_address.h ip/ip6_error.h ip/ip6.h ip/ip6_hop_by_hop.h ip/ip6_hop_by_hop_packet.h ip/ip6_packet.h ip/ip.h ip/ip_table.h ip/ip_interface.h ip/ip_packet.h ip/ip_source_and_port_range_check.h ip/ip_types.h ip/lookup.h ip/ports.def ip/protocols.def ip/punt_error.def ip/punt.h ) list(APPEND VNET_API_FILES ip/ip.api ip/punt.api ) list(APPEND VNET_MULTIARCH_SOURCES ip/ip4_forward.c ip/ip6_forward.c ip/ip4_input.c ) ############################################################################## # Layer 3 neighbours ############################################################################## list(APPEND VNET_SOURCES ip-neighbor/ip_neighbor.c ip-neighbor/ip_neighbor_api.c ip-neighbor/ip_neighbor_dp.c ip-neighbor/ip_neighbor_types.c ip-neighbor/ip_neighbor_watch.c ip-neighbor/ip4_neighbor.c ip-neighbor/ip6_neighbor.c ) list(APPEND VNET_HEADERS ip-neighbor/ip_neighbor.h ip-neighbor/ip_neighbor_types.h ) list(APPEND VNET_API_FILES ip-neighbor/ip_neighbor.api ) ############################################################################## # Bidirectional Forwarding Detection ############################################################################## list(APPEND VNET_HEADERS bfd/bfd_protocol.h bfd/bfd_main.h bfd/bfd_api.h bfd/bfd_udp.h ) list(APPEND VNET_SOURCES bfd/bfd_api.h bfd/bfd_udp.c bfd/bfd_main.c bfd/bfd_protocol.c bfd/bfd_cli.c bfd/bfd_api.c ) list(APPEND VNET_API_FILES bfd/bfd.api) ############################################################################## # Crypto ############################################################################## list(APPEND VNET_SOURCES crypto/cli.c crypto/crypto.c crypto/format.c crypto/node.c crypto/crypto_api.c ) list(APPEND VNET_HEADERS crypto/crypto.h ) list(APPEND VNET_MULTIARCH_SOURCES crypto/node.c) list(APPEND VNET_API_FILES crypto/crypto.api) ############################################################################## # Layer 3 protocol: IPSec ############################################################################## list(APPEND VNET_SOURCES ipsec/ipsec.c ipsec/ipsec_cli.c ipsec/ipsec_format.c ipsec/ipsec_handoff.c ipsec/ipsec_input.c ipsec/ipsec_itf.c ipsec/ipsec_punt.c ipsec/ipsec_sa.c ipsec/ipsec_spd.c ipsec/ipsec_spd_policy.c ipsec/ipsec_tun.c ipsec/ipsec_tun_in.c ipsec/esp_format.c ipsec/esp_encrypt.c ipsec/esp_decrypt.c ipsec/ah_decrypt.c ipsec/ah_encrypt.c ipsec/ipsec_api.c ipsec/ipsec_types_api.c ) list(APPEND VNET_MULTIARCH_SOURCES ipsec/esp_encrypt.c ipsec/esp_decrypt.c ipsec/ah_decrypt.c ipsec/ah_encrypt.c ipsec/ipsec_handoff.c ipsec/ipsec_output.c ipsec/ipsec_input.c ipsec/ipsec_tun_in.c ) list(APPEND VNET_API_FILES ipsec/ipsec_types.api) list(APPEND VNET_API_FILES ipsec/ipsec.api) list(APPEND VNET_SOURCES ipsec/ipsec_output.c ) list(APPEND VNET_HEADERS ipsec/ipsec.h ipsec/ipsec_spd.h ipsec/ipsec_spd_policy.h ipsec/ipsec_sa.h ipsec/ipsec_tun.h ipsec/ipsec_types_api.h ipsec/ipsec_punt.h ipsec/esp.h ipsec/ah.h ) ############################################################################## # Layer 3 protocol: osi ############################################################################## list(APPEND VNET_SOURCES osi/node.c osi/osi.c osi/pg.c ) list(APPEND VNET_HEADERS osi/osi.h ) ############################################################################## # Layer 4 protocol: tcp ############################################################################## list(APPEND VNET_SOURCES tcp/tcp_api.c tcp/tcp_format.c tcp/tcp_pg.c tcp/tcp_syn_filter4.c tcp/tcp_output.c tcp/tcp_input.c tcp/tcp_newreno.c tcp/tcp_bt.c tcp/tcp_cli.c tcp/tcp_cubic.c tcp/tcp_debug.c tcp/tcp_sack.c tcp/tcp_timer.c tcp/tcp.c ) list(APPEND VNET_MULTIARCH_SOURCES tcp/tcp_input.c tcp/tcp_output.c tcp/tcp_syn_filter4.c ) list(APPEND VNET_HEADERS tcp/tcp_packet.h tcp/tcp_timer.h tcp/tcp_bt.h tcp/tcp_cc.h tcp/tcp_debug.h tcp/tcp_inlines.h tcp/tcp_sack.h tcp/tcp_types.h tcp/tcp.h tcp/tcp_error.def ) list(APPEND VNET_API_FILES tcp/tcp.api) ############################################################################## # Layer 4 protocol: udp ############################################################################## list(APPEND VNET_SOURCES udp/udp.c udp/udp_cli.c udp/udp_input.c udp/udp_format.c udp/udp_local.c udp/udp_pg.c udp/udp_encap_node.c udp/udp_encap.c udp/udp_api.c ) list(APPEND VNET_MULTIARCH_SOURCES udp/udp_local.c udp/udp_encap_node.c ) list(APPEND VNET_HEADERS udp/udp_error.def udp/udp.h udp/udp_packet.h udp/udp_inlines.h udp/udp_local.h ) list(APPEND VNET_API_FILES udp/udp.api) ############################################################################## # Tunnel protocol: gre ############################################################################## list(APPEND VNET_SOURCES gre/gre.c gre/node.c gre/interface.c gre/pg.c gre/gre_api.c ) list(APPEND VNET_MULTIARCH_SOURCES gre/node.c gre/gre.c ) list(APPEND VNET_HEADERS gre/gre.h gre/packet.h gre/error.def ) list(APPEND VNET_API_FILES gre/gre.api) ############################################################################## # Tunnel protocol: ipip ############################################################################## list(APPEND VNET_SOURCES ipip/ipip.c ipip/node.c ipip/sixrd.c ipip/ipip_api.c ipip/ipip_cli.c ) list(APPEND VNET_MULTIARCH_SOURCES ipip/node.c ) list(APPEND VNET_HEADERS ipip/ipip.h ) list(APPEND VNET_API_FILES ipip/ipip.api ) ############################################################################## # Tunnel infra ############################################################################## list(APPEND VNET_SOURCES tunnel/tunnel.c tunnel/tunnel_types_api.c ) list(APPEND VNET_API_FILES tunnel/tunnel_types.api ) list(APPEND VNET_HEADERS tunnel/tunnel.h tunnel/tunnel_dp.h ) ############################################################################## # Tunnel protocol: gre+mpls ############################################################################## list(APPEND VNET_SOURCES mpls/mpls.c mpls/mpls_lookup.c mpls/mpls_output.c mpls/mpls_features.c mpls/mpls_input.c mpls/interface.c mpls/mpls_tunnel.c mpls/pg.c mpls/mpls_api.c ) list(APPEND VNET_MULTIARCH_SOURCES mpls/mpls_output.c mpls/mpls_input.c mpls/mpls_lookup.c mpls/mpls_features.c ) list(APPEND VNET_HEADERS mpls/mpls.h mpls/mpls_types.h mpls/mpls_tunnel.h mpls/packet.h mpls/error.def ) list(APPEND VNET_API_FILES mpls/mpls.api) ############################################################################## # Tunnel protocol: vxlan-gbp ############################################################################## list(APPEND VNET_SOURCES vxlan-gbp/decap.c vxlan-gbp/encap.c vxlan-gbp/vxlan_gbp_api.c vxlan-gbp/vxlan_gbp.c vxlan-gbp/vxlan_gbp_packet.c ) list (APPEND VNET_MULTIARCH_SOURCES vxlan-gbp/decap.c vxlan-gbp/encap.c ) list(APPEND VNET_HEADERS vxlan-gbp/vxlan_gbp.h vxlan-gbp/vxlan_gbp_packet.h vxlan-gbp/vxlan_gbp_error.def ) list(APPEND VNET_API_FILES vxlan-gbp/vxlan_gbp.api) ############################################################################## # Tunnel protocol: vxlan-gpe ############################################################################## list(APPEND VNET_SOURCES vxlan-gpe/vxlan_gpe.c vxlan-gpe/encap.c vxlan-gpe/decap.c vxlan-gpe/vxlan_gpe_api.c ) list (APPEND VNET_MULTIARCH_SOURCES vxlan-gpe/decap.c ) list(APPEND VNET_HEADERS vxlan-gpe/vxlan_gpe.h vxlan-gpe/vxlan_gpe_packet.h vxlan-gpe/vxlan_gpe_error.def ) list(APPEND VNET_API_FILES vxlan-gpe/vxlan_gpe.api) ############################################################################## # ipv6 segment routing ############################################################################## list(APPEND VNET_SOURCES srv6/sr.c srv6/sr_localsid.c srv6/sr_policy_rewrite.c srv6/sr_steering.c srv6/sr_api.c ) list(APPEND VNET_HEADERS srv6/sr_packet.h srv6/sr.h ) list(APPEND VNET_API_FILES srv6/sr.api srv6/sr_types.api ) ############################################################################## # mpls segment routing ############################################################################## list(APPEND VNET_SOURCES srmpls/sr_mpls_policy.c srmpls/sr_mpls_steering.c srmpls/sr_mpls_api.c ) list(APPEND VNET_HEADERS srmpls/sr_mpls.h ) list(APPEND VNET_API_FILES srmpls/sr_mpls.api srv6/sr_types.api ) ##############
/*
 *------------------------------------------------------------------
 * memif_api.c - memif api
 *
 * Copyright (c) 2017 Cisco and/or its affiliates.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at:
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *------------------------------------------------------------------
 */

#include <vlib/vlib.h>
#include <vnet/ethernet/ethernet.h>
#include <vlib/unix/unix.h>
#include <memif/memif.h>
#include <memif/private.h>

#include <vlibapi/api.h>
#include <vlibmemory/api.h>


/* define message IDs */
#include <memif/memif_msg_enum.h>

/* define message structures */
#define vl_typedefs
#include <memif/memif_all_api_h.h>
#undef vl_typedefs

/* define generated endian-swappers */
#define vl_endianfun
#include <memif/memif_all_api_h.h>
#undef vl_endianfun

/* instantiate all the print functions we know about */
#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
#define vl_printfun
#include <memif/memif_all_api_h.h>
#undef vl_printfun

/* Get the API version number */
#define vl_api_version(n,v) static u32 api_version=(v);
#include <memif/memif_all_api_h.h>
#undef vl_api_version

#define REPLY_MSG_ID_BASE mm->msg_id_base
#include <vlibapi/api_helper_macros.h>

#define foreach_memif_plugin_api_msg					\
_(MEMIF_SOCKET_FILENAME_ADD_DEL, memif_socket_filename_add_del)	\
_(MEMIF_CREATE, memif_create)						\
_(MEMIF_DELETE, memif_delete)						\
_(MEMIF_SOCKET_FILENAME_DUMP, memif_socket_filename_dump)		\
_(MEMIF_DUMP, memif_dump)						\


/**
 * @brief Message handler for memif_socket_filename_add_del API.
 * @param mp the vl_api_memif_socket_filename_add_del_t API message
 */
void
  vl_api_memif_socket_filename_add_del_t_handler
  (vl_api_memif_socket_filename_add_del_t * mp)
{
  memif_main_t *mm = &memif_main;
  u8 is_add;
  u32 socket_id;
  u32 len;
  u8 *socket_filename;
  vl_api_memif_socket_filename_add_del_reply_t *rmp;
  int rv;

  /* is_add */
  is_add =