2 * Copyright (c) 2020 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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
15 #ifndef __LCP_ITF_PAIR_H__
16 #define __LCP_ITF_PAIR_H__
18 #include <vnet/dpo/dpo.h>
19 #include <vnet/adj/adj.h>
20 #include <vnet/ip/ip_types.h>
22 #include <plugins/linux-cp/lcp.h>
24 extern vlib_log_class_t lcp_itf_pair_logger;
26 #define LCP_ITF_PAIR_DBG(...) \
27 vlib_log_debug (lcp_itf_pair_logger, __VA_ARGS__);
29 #define LCP_ITF_PAIR_INFO(...) \
30 vlib_log_info (lcp_itf_pair_logger, __VA_ARGS__);
32 #define LCP_ITF_PAIR_NOTICE(...) \
33 vlib_log_notice (lcp_itf_pair_logger, __VA_ARGS__);
35 #define LCP_ITF_PAIR_WARN(...) \
36 vlib_log_warn (lcp_itf_pair_logger, __VA_ARGS__);
38 #define LCP_ITF_PAIR_ERR(...) vlib_log_err (lcp_itf_pair_logger, __VA_ARGS__);
40 #define foreach_lcp_itf_pair_flag _ (STALE, 0, "stale")
42 typedef enum lip_flag_t_
44 #define _(a, b, c) LIP_FLAG_##a = (1 << b),
45 foreach_lcp_itf_pair_flag
55 #define N_LCP_ITF_HOST (LCP_ITF_HOST_TUN + 1)
57 typedef struct lcp_itf_phy_adj
59 adj_index_t adj_index[N_AF];
63 * A pair of interfaces
65 typedef struct lcp_itf_pair_t_
67 u32 lip_host_sw_if_index; /* VPP's sw_if_index for the host tap */
68 u32 lip_phy_sw_if_index; /* VPP's sw_if_index for the phy */
69 u8 *lip_host_name; /* linux's name for the tap */
70 u32 lip_vif_index; /* linux's index for the tap */
71 u8 *lip_namespace; /* namespace in which the tap lives */
72 lip_host_type_t lip_host_type; /* type of host interface */
73 lcp_itf_phy_adj_t lip_phy_adjs; /* adjacencies for phy l3 interface */
74 lip_flag_t lip_flags; /* Flags */
75 u8 lip_rewrite_len; /* The length of an L2 MAC rewrite */
76 f64 lip_create_ts; /* Timestamp of creation */
78 extern lcp_itf_pair_t *lcp_itf_pair_pool;
80 extern vlib_node_registration_t lcp_ethernet_node;
82 u8 *format_lcp_itf_pair (u8 *s, va_list *args);
83 void lcp_itf_pair_show (u32 phy_sw_if_index);
84 u32 lcp_itf_num_pairs (void);
87 * Get an interface-pair object from its VPP index
89 extern lcp_itf_pair_t *lcp_itf_pair_get (index_t index);
92 * Find a interface-pair object from the host interface
94 * @param host_sw_if_index host interface
95 * @return VPP's object index
97 extern index_t lcp_itf_pair_find_by_vif (u32 vif_index);
100 * Create an interface-pair
104 extern int lcp_itf_pair_add (u32 host_sw_if_index, u32 phy_sw_if_index,
105 u8 *host_name, u32 host_index,
106 lip_host_type_t host_type, u8 *ns);
107 extern int lcp_itf_pair_del (u32 phy_sw_if_index);
110 * Create an interface-pair from PHY sw_if_index and tap name.
114 extern int lcp_itf_pair_create (u32 phy_sw_if_index, u8 *host_if_name,
115 lip_host_type_t host_if_type, u8 *ns,
116 u32 *host_sw_if_indexp);
119 * Delete a LCP_ITF_PAIR
121 extern int lcp_itf_pair_delete (u32 phy_sw_if_index);
124 * Callback function invoked during a walk of all interface-pairs
126 typedef walk_rc_t (*lcp_itf_pair_walk_cb_t) (index_t index, void *ctx);
129 * Walk/visit each of the interface pairs
131 extern void lcp_itf_pair_walk (lcp_itf_pair_walk_cb_t cb, void *ctx);
134 * Begin and End the replace process
136 extern int lcp_itf_pair_replace_begin (void);
137 extern int lcp_itf_pair_replace_end (void);
140 * Retreive the pair in the DP
142 extern index_t *lip_db_by_phy;
143 extern u32 *lip_db_by_host;
145 always_inline index_t
146 lcp_itf_pair_find_by_phy (u32 phy_sw_if_index)
148 if (phy_sw_if_index >= vec_len (lip_db_by_phy))
149 return INDEX_INVALID;
150 return (lip_db_by_phy[phy_sw_if_index]);
153 always_inline index_t
154 lcp_itf_pair_find_by_host (u32 host_sw_if_index)
156 if (host_sw_if_index >= vec_len (lip_db_by_host))
157 return INDEX_INVALID;
158 return (lip_db_by_host[host_sw_if_index]);
161 typedef void (*lcp_itf_pair_add_cb_t) (lcp_itf_pair_t *);
162 typedef void (*lcp_itf_pair_del_cb_t) (lcp_itf_pair_t *);
164 typedef struct lcp_itf_pair_vft
166 lcp_itf_pair_add_cb_t pair_add_fn;
167 lcp_itf_pair_del_cb_t pair_del_fn;
168 } lcp_itf_pair_vft_t;
170 void lcp_itf_pair_register_vft (lcp_itf_pair_vft_t *lcp_itf_vft);
173 * sub-interface auto creation/deletion for LCP
175 void lcp_set_auto_subint (u8 is_auto);
176 int lcp_auto_subint (void);
179 * sync state changes from VPP into LCP
181 void lcp_set_sync (u8 is_auto);
184 /* Set TAP and Linux host link state */
185 void lcp_itf_set_link_state (const lcp_itf_pair_t *lip, u8 state);
187 /* Set any VPP L3 addresses on Linux host device */
188 void lcp_itf_set_interface_addr (const lcp_itf_pair_t *lip);
190 /* Sync all state from VPP to a specific Linux device, all sub-interfaces
191 * of a hardware interface, or all interfaces in the system.
193 * Note: in some circumstances, this syncer will (have to) make changes to
194 * the VPP interface, for example if its MTU is greater than its parent.
195 * See the function for rationale.
197 void lcp_itf_pair_sync_state (lcp_itf_pair_t *lip);
198 void lcp_itf_pair_sync_state_hw (vnet_hw_interface_t *hi);
199 void lcp_itf_pair_sync_state_all ();
202 * fd.io coding-style-patch-verification: ON
205 * eval: (c-set-style "gnu")