/*
 * 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.
 */
 
option version = "1.0.0";

/** \brief enable/disable name resolution

    @param client_index - opaque cookie to identify the sender
    @param context - sender context, to match reply w/ request
    @param is_enable - 1 = enable, 0 = disable
*/
autoreply define dns_enable_disable {
    u32 client_index;
    u32 context;
    u8 enable;
};

/** \brief add or delete an upstream name server

    @param client_index - opaque cookie to identify the sender
    @param context - sender context, to match reply w/ request
    @param is_ip6 - an ip6 name server
    @param is_add - add = 1, delete = 0
    @param server_address - server ip address
*/
autoreply define dns_name_server_add_del {
    u32 client_index;
    u32 context;
    u8 is_ip6;
    u8 is_add;
    u8 server_address[16];
};

/** \brief DNS name resolution request

    @param client_index - opaque cookie to identify the sender
    @param context - sender context, to match reply w/ request
    @param name - the name to resolve
*/
define dns_resolve_name {
    u32 client_index;
    u32 context;
    u8 name[256];
 };

/** \brief DNS name resolution reply

    @param client_index - opaque cookie to identify the sender
    @param context - sender context, to match reply w/ request
    @param retval - return value, 0 => success
    @param ip4_set - indicates that the ip4 address is valid
    @param ip6_set - indicates that the ip6 address is valid
    @param ip4_address - the ip4 name resolution reply
    @param ip6_address - the ip6 name resolution reply
*/
define dns_resolve_name_reply {
    u32 context;
    i32 retval;
    u8 ip4_set;
    u8 ip6_set;
    u8 ip4_address[4];
    u8 ip6_address[16];
};

/** \brief DNS IP -> name resolution request

    @param client_index - opaque cookie to identify the sender
    @param context - sender context, to match reply w/ request
    @param is_ip6 - set if the reverse-DNS request is an ip6 address
    @param address - the address to map to a name
*/
define dns_resolve_ip {
    u32 client_index;
    u32 context;
    u8 is_ip6;
    u8 address[16];
 };

/** \brief DNS ip->name resolution reply

    @param client_index - opaque cookie to identify the sender
    @param context - sender context, to match reply w/ request
    @param retval - return value, 0 => success
    @param name - canonical name for the indicated IP address
*/
define dns_resolve_ip_reply {
    u32 context;
    i32 retval;
    u8 name[256];
};

