/*
 * Copyright (c) 2015-2019 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.
 */

option version = "2.2.0";
import "vnet/ip/ip_types.api";

/** \brief The types of packets to be punted
*/
enum punt_type
{
    /* L4 (UDP) packets */
    PUNT_API_TYPE_L4,
    /* IP proto (i.e. OSPF, RIP, etc) packets */
    PUNT_API_TYPE_IP_PROTO,
    /* Exception packets handled by the VLIB punt infra */
    PUNT_API_TYPE_EXCEPTION,
};

/** \brief Punt L4 traffic definition
    @param af - Address Family, IPv4 or IPV6
    @param protocol - L4 protocol to be punted
    @param port - TCP/UDP port to be punted
*/
typedef punt_l4
{
    vl_api_address_family_t af;
    vl_api_ip_proto_t protocol;
    u16 port;
};

/** \brief Punt IP protocol traffic definition
    @param af - Address Family, IPv4 or IPV6
    @param protocol - IP protocol to be punted
*/
typedef punt_ip_proto
{
    vl_api_address_family_t af;
    vl_api_ip_proto_t protocol;
};

/** \brief The ID of the punt exception reason
           Dump all the reasons to obtain this
*/
typedef punt_exception
{
    u32 id;
};

/** \brief Union of the different punt packet descriptions
*/
union punt_union
{
    vl_api_punt_exception_t exception;
    vl_api_punt_l4_t l4;
    vl_api_punt_ip_proto_t ip_proto;
};

/** \brief Full description of which packets are requested to be punted
    @param type - Which packet type
    @param punt - Description corresponding to the type
*/
typedef punt
{
    vl_api_punt_type_t type;
    vl_api_punt_union_t punt; 
};

/** \brief Punt traffic to the host
    @param client_index - opaque cookie to identify the sender
    @param context - sender context, to match reply w/ request
    @param is_add - add punt if non-zero, else delete
    @param punt - punt definition, only UDP (0x11) is supported
*/
autoreply define set_punt {
    u32 client_index;
    u32 context;
    u8 is_add;
    vl_api_punt_t punt;
};

/** \brief Punt traffic to the host via socket
    @param client_index - opaque cookie to identify the sender
    @param context - sender context, to match reply w/ request
    @param header_version - expected meta data header version (currently 1)
    @param punt - punt definition
*/
define punt_socket_register {
    u32 client_index;
    u32 context;
    u32 header_version;
    vl_api_punt_t punt;
    u8 pathname[108]; /* Linux sun_path defined to be 108 bytes, see unix(7) */
};

define punt_socket_register_reply
{
    u32 context;
    i32 retval;
    u8 pathname[64];
};

define punt_socket_dump
{
    u32 client_index;
    u32 context;
    vl_api_punt_type_t type;
};

define punt_socket_details
{
    u32 context;
    vl_api_punt_t punt;
    u8 pathname[108];
};

autoreply define punt_socket_deregister {
    u32 client_index;
    u32 context;
    vl_api_punt_t punt;
};

typedef punt_reason
{
    u32 id;
    string name[];
};

/** \brief Dump all or one of the excpetion punt reasons
*   @param - If the string is not set punt dump all reasons
*            else dump only the one specified
*/
define punt_reason_dump
{
    u32 client_index;
    u32 context;
    vl_api_punt_reason_t reason;
};

define punt_reason_details
{
    u32 context;
    vl_api_punt_reason_t reason;
};

/*
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */
