blob: 306686255b8ea4245414a6735c21d22c58776042 [file] [log] [blame]
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001/*
2 * Copyright (c) 2016 Cisco 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:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
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.
14 */
15
16#ifndef __ADJ_INTERNAL_H__
17#define __ADJ_INTERNAL_H__
18
19#include <vnet/adj/adj.h>
20#include <vnet/ip/ip.h>
21#include <vnet/mpls/mpls.h>
Neale Ranns5e575b12016-10-03 09:40:25 +010022#include <vnet/adj/adj_l2.h>
Florin Corasce1b4c72017-01-26 14:25:34 -080023#include <vnet/adj/adj_nsh.h>
Neale Ranns0bfe5d82016-08-25 15:29:12 +010024
25/**
26 * big switch to turn on Adjacency debugging
27 */
28#undef ADJ_DEBUG
29
30/*
31 * Debug macro
32 */
33#ifdef ADJ_DEBUG
Neale Ranns6c3ebcc2016-10-02 21:20:15 +010034#define ADJ_DBG(_adj, _fmt, _args...) \
35{ \
36 clib_warning("adj:[%d:%p]:" _fmt, \
37 _adj - adj_pool, _adj, \
38 ##_args); \
Neale Ranns0bfe5d82016-08-25 15:29:12 +010039}
40#else
41#define ADJ_DBG(_e, _fmt, _args...)
42#endif
43
Neale Rannsb80c5362016-10-08 13:03:40 +010044static inline u32
Neale Ranns924d03a2016-10-19 08:25:46 +010045adj_get_rewrite_node (vnet_link_t linkt)
Neale Ranns0bfe5d82016-08-25 15:29:12 +010046{
47 switch (linkt) {
Neale Ranns924d03a2016-10-19 08:25:46 +010048 case VNET_LINK_IP4:
Neale Rannsb80c5362016-10-08 13:03:40 +010049 return (ip4_rewrite_node.index);
Neale Ranns924d03a2016-10-19 08:25:46 +010050 case VNET_LINK_IP6:
Neale Rannsb80c5362016-10-08 13:03:40 +010051 return (ip6_rewrite_node.index);
Neale Ranns924d03a2016-10-19 08:25:46 +010052 case VNET_LINK_MPLS:
Neale Rannsb80c5362016-10-08 13:03:40 +010053 return (mpls_output_node.index);
Neale Ranns924d03a2016-10-19 08:25:46 +010054 case VNET_LINK_ETHERNET:
Neale Rannsb80c5362016-10-08 13:03:40 +010055 return (adj_l2_rewrite_node.index);
Florin Corasce1b4c72017-01-26 14:25:34 -080056 case VNET_LINK_NSH:
57 return (adj_nsh_rewrite_node.index);
Neale Ranns924d03a2016-10-19 08:25:46 +010058 case VNET_LINK_ARP:
Neale Ranns5e575b12016-10-03 09:40:25 +010059 break;
Neale Ranns0bfe5d82016-08-25 15:29:12 +010060 }
Neale Ranns924d03a2016-10-19 08:25:46 +010061 ASSERT(0);
Neale Ranns0bfe5d82016-08-25 15:29:12 +010062 return (0);
63}
64
Neale Rannsb80c5362016-10-08 13:03:40 +010065static inline vnet_link_t
Neale Ranns0bfe5d82016-08-25 15:29:12 +010066adj_fib_proto_2_nd (fib_protocol_t fp)
67{
68 switch (fp)
69 {
70 case FIB_PROTOCOL_IP4:
Neale Rannsb80c5362016-10-08 13:03:40 +010071 return (VNET_LINK_ARP);
Neale Ranns0bfe5d82016-08-25 15:29:12 +010072 case FIB_PROTOCOL_IP6:
Neale Rannsb80c5362016-10-08 13:03:40 +010073 return (VNET_LINK_IP6);
Neale Ranns0bfe5d82016-08-25 15:29:12 +010074 case FIB_PROTOCOL_MPLS:
Neale Rannsb80c5362016-10-08 13:03:40 +010075 return (VNET_LINK_MPLS);
Neale Ranns0bfe5d82016-08-25 15:29:12 +010076 }
77 return (0);
78}
79
Neale Ranns6c3ebcc2016-10-02 21:20:15 +010080/**
81 * @brief
82 * Get a pointer to an adjacency object from its index
83 */
84static inline adj_index_t
85adj_get_index (ip_adjacency_t *adj)
86{
87 return (adj - adj_pool);
88}
89
Neale Rannsb80c5362016-10-08 13:03:40 +010090extern void adj_nbr_update_rewrite_internal (ip_adjacency_t *adj,
Neale Ranns450cd302016-11-09 17:49:42 +000091 ip_lookup_next_t adj_next_index,
Neale Rannsb80c5362016-10-08 13:03:40 +010092 u32 complete_next_index,
93 u32 next_index,
94 u8 *rewrite);
95
Neale Ranns0bfe5d82016-08-25 15:29:12 +010096extern ip_adjacency_t * adj_alloc(fib_protocol_t proto);
97
Neale Ranns177bbdc2016-11-15 09:46:51 +000098extern void adj_nbr_remove(adj_index_t ai,
99 fib_protocol_t nh_proto,
Neale Ranns924d03a2016-10-19 08:25:46 +0100100 vnet_link_t link_type,
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100101 const ip46_address_t *nh_addr,
102 u32 sw_if_index);
103extern void adj_glean_remove(fib_protocol_t proto,
104 u32 sw_if_index);
Neale Ranns32e1c012016-11-22 17:07:28 +0000105extern void adj_mcast_remove(fib_protocol_t proto,
106 u32 sw_if_index);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100107
108#endif