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

#include <vnet/ip/ip.h>

/**
 * IPv6 Configuration on an interface
 */

extern int ip6_link_enable (u32 sw_if_index);
extern bool ip6_link_is_enabled (u32 sw_if_index);
extern int ip6_link_disable (u32 sw_if_index);

extern const ip6_address_t *ip6_get_link_local_address (u32 sw_if_index);

extern int ip6_set_link_local_address (u32 sw_if_index,
				       const ip6_address_t * address);
extern adj_index_t ip6_link_get_mcast_adj (u32 sw_if_index);

extern int
ip6_src_address_for_packet (u32 sw_if_index,
			    const ip6_address_t * dst, ip6_address_t * src);

/**
 * Delegates for the interfaces
 *
 * delegates are a means for a external component to 'extend' the config
 * object by adding their own objects (aka delegates).
 */

/**
 * Callback functions for handling actions on the link
 */
typedef void (*ip6_link_enable_fn_t) (u32 sw_if_index);
typedef void (*ip6_link_disable_fn_t) (index_t ildi);
typedef void (*ip6_link_ll_change_fn_t) (u32 ildi, const ip6_address_t * a);
typedef void (*ip6_link_address_change_fn_t) (u32 ildi,
					      const ip6_address_t * a,
					      u8 address_oength);

typedef struct ip6_link_delegate_vft_t_
{
  ip6_link_enable_fn_t ildv_enable;
  ip6_link_disable_fn_t ildv_disable;
  ip6_link_ll_change_fn_t ildv_ll_change;
  ip6_link_address_change_fn_t ildv_addr_add;
  ip6_link_address_change_fn_t ildv_addr_del;
  format_function_t *ildv_format;
} ip6_link_delegate_vft_t;

typedef u32 ip6_link_delegate_id_t;


extern ip6_link_delegate_id_t ip6_link_delegate_register (const
							  ip6_link_delegate_vft_t
							  * vft);
extern index_t ip6_link_delegate_get (u32 sw_if_index,
				      ip6_link_delegate_id_t id);
extern bool ip6_link_delegate_update (u32 sw_if_index,
				      ip6_link_delegate_id_t id, index_t ii);
extern void ip6_link_delegate_remove (u32 sw_if_index,
				      ip6_link_delegate_id_t id, index_t ii);

/*
 * fd.io coding-style-patch-verification: ON
 *
 * Local Variables:
 * eval: (c-set-style "gnu")
 * End:
 */
