blob: ad942f415d17e68a3064838cccbe3112d0c2ae71 [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 * @file
17 * @brief LISP sub-interfaces.
18 *
19 */
20
21#ifndef __LISP_GPE_SUB_INTERFACE_H__
22#define __LISP_GPE_SUB_INTERFACE_H__
23
24#include <vnet/lisp-gpe/lisp_gpe.h>
25
26/**
27 * A Key for lookup in the L£ sub-interface DB
28 */
29typedef struct lisp_gpe_sub_interface_key_t_
30{
31 /**
32 * The local-RLOC. This is the interface's 'source' address.
33 */
34 ip_address_t local_rloc;
35
36 /**
37 * The VNI. In network byte order!
38 */
39 u32 vni;
40} lisp_gpe_sub_interface_key_t;
41
42/**
43 * @brief A LISP L3 sub-interface
44 *
45 * A LISP sub-interface is a multi-access interface, whose local address is a
46 * single local-RLOC. Adjacencies that form on this sub-interface, represent
47 * remote RLOCs.
48 * This is analogous to an ethernet interface.
49 * As with all interface types it can only be present in one VRF, hence a
50 * LISP sub-interface is per-local-rloc and per-VNI.
51 */
52typedef struct lisp_gpe_sub_interface_t_
53{
54 /**
55 * The interface's key inthe DB; rloc & vni;
56 * The key is allocated from the heap so it can be used in the hash-table.
57 * if it's part of the object, then it is subjet to realloc, which no-worky.
58 */
59 lisp_gpe_sub_interface_key_t *key;
60
61 /**
62 * The Table-ID in the overlay that this interface is bound to.
63 */
64 u32 eid_table_id;
65
66 /**
67 * A reference counting lock on the number of users of this interface.
68 * When this count drops to 0 the interface is deleted.
69 */
70 u32 locks;
71
72 /**
73 * The SW if index assigned to this sub-interface
74 */
75 u32 sw_if_index;
76
77 /**
78 * The SW IF index assigned to the main interface of which this is a sub.
79 */
80 u32 main_sw_if_index;
81} lisp_gpe_sub_interface_t;
82
83extern index_t lisp_gpe_sub_interface_find_or_create_and_lock (const
84 ip_address_t *
85 lrloc,
86 u32
87 eid_table_id,
88 u32 vni);
89
90extern u8 *format_lisp_gpe_sub_interface (u8 * s, va_list ap);
91
92extern void lisp_gpe_sub_interface_unlock (index_t itf);
93
94extern const lisp_gpe_sub_interface_t *lisp_gpe_sub_interface_get (index_t
95 itf);
96
97/**
98 * A DB of all L3 sub-interfaces. The key is:{VNI,l-RLOC}
99 */
100extern uword *lisp_gpe_sub_interfaces_sw_if_index;
101
102/**
103 * @brief
104 * Get a VNET L3 interface matching the local-RLOC and VNI
105 * Called from the data-plane
106 */
107always_inline u32
108lisp_gpe_sub_interface_find_ip6 (const ip6_address_t * addr, u32 vni)
109{
110 lisp_gpe_sub_interface_key_t key;
111 const uword *p;
112
113 key.local_rloc.ip.v6.as_u64[0] = addr->as_u64[0];
114 key.local_rloc.ip.v6.as_u64[1] = addr->as_u64[1];
115 key.local_rloc.version = IP6;
116 key.vni = vni;
117
118 p = hash_get_mem (&lisp_gpe_sub_interfaces_sw_if_index, &key);
119
120 if (NULL != p)
121 return p[0];
122
123 return (INDEX_INVALID);
124}
125
126/**
127 * @brief
128 * Get a VNET L3 interface matching the local-RLOC and VNI
129 * Called from the data-plane
130 */
131always_inline index_t
132lisp_gpe_sub_interface_find_ip4 (const ip4_address_t * addr, u32 vni)
133{
134 lisp_gpe_sub_interface_key_t key;
135 const uword *p;
136
137 key.local_rloc.ip.v4.as_u32 = addr->as_u32;
138 key.local_rloc.version = IP4;
139 key.vni = vni;
140
141 p = hash_get_mem (&lisp_gpe_sub_interfaces_sw_if_index, &key);
142
143 if (NULL != p)
144 return p[0];
145
146 return (INDEX_INVALID);
147}
148
149/*
150 * fd.io coding-style-patch-verification: ON
151 *
152 * Local Variables:
153 * eval: (c-set-style "gnu")
154 * End:
155 */
156
157#endif