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 #define foreach_lcp_itf_pair_flag _ (STALE, 0, "stale")
26 typedef enum lip_flag_t_
28 #define _(a, b, c) LIP_FLAG_##a = (1 << b),
29 foreach_lcp_itf_pair_flag
39 #define N_LCP_ITF_HOST (LCP_ITF_HOST_TUN + 1)
41 typedef struct lcp_itf_phy_adj
43 adj_index_t adj_index[N_AF];
47 * A pair of interfaces
49 typedef struct lcp_itf_pair_t_
51 u32 lip_host_sw_if_index; /* VPP's sw_if_index for the host tap */
52 u32 lip_phy_sw_if_index; /* VPP's sw_if_index for the phy */
53 u8 *lip_host_name; /* linux's name for the tap */
54 u32 lip_vif_index; /* linux's index for the tap */
55 u8 *lip_namespace; /* namespace in which the tap lives */
56 lip_host_type_t lip_host_type; /* type of host interface */
57 lcp_itf_phy_adj_t lip_phy_adjs; /* adjacencies for phy l3 interface */
58 lip_flag_t lip_flags; /* Flags */
59 u8 lip_rewrite_len; /* The length of an L2 MAC rewrite */
60 f64 lip_create_ts; /* Timestamp of creation */
62 extern lcp_itf_pair_t *lcp_itf_pair_pool;
64 extern vlib_node_registration_t lcp_ethernet_node;
66 u8 *format_lcp_itf_pair (u8 *s, va_list *args);
67 void lcp_itf_pair_show (u32 phy_sw_if_index);
68 u32 lcp_itf_num_pairs (void);
71 * Get an interface-pair object from its VPP index
73 extern lcp_itf_pair_t *lcp_itf_pair_get (index_t index);
76 * Find a interface-pair object from the host interface
78 * @param host_sw_if_index host interface
79 * @return VPP's object index
81 extern index_t lcp_itf_pair_find_by_vif (u32 vif_index);
84 * Create an interface-pair
88 extern int lcp_itf_pair_add (u32 host_sw_if_index, u32 phy_sw_if_index,
89 u8 *host_name, u32 host_index,
90 lip_host_type_t host_type, u8 *ns);
91 extern int lcp_itf_pair_add_sub (u32 vif, u8 *host_name, u32 sub_sw_if_index,
92 u32 phy_sw_if_index, u8 *ns);
93 extern int lcp_itf_pair_del (u32 phy_sw_if_index);
96 * Create an interface-pair from PHY sw_if_index and tap name.
100 extern int lcp_itf_pair_create (u32 phy_sw_if_index, u8 *host_if_name,
101 lip_host_type_t host_if_type, u8 *ns);
104 * Delete a LCP_ITF_PAIR
106 extern int lcp_itf_pair_delete (u32 phy_sw_if_index);
109 * Callback function invoked during a walk of all interface-pairs
111 typedef walk_rc_t (*lcp_itf_pair_walk_cb_t) (index_t index, void *ctx);
114 * Walk/visit each of the interface pairs
116 extern void lcp_itf_pair_walk (lcp_itf_pair_walk_cb_t cb, void *ctx);
119 * Begin and End the replace process
121 extern int lcp_itf_pair_replace_begin (void);
122 extern int lcp_itf_pair_replace_end (void);
125 * Retreive the pair in the DP
127 extern index_t *lip_db_by_phy;
128 extern u32 *lip_db_by_host;
130 always_inline index_t
131 lcp_itf_pair_find_by_phy (u32 phy_sw_if_index)
133 if (phy_sw_if_index >= vec_len (lip_db_by_phy))
134 return INDEX_INVALID;
135 return (lip_db_by_phy[phy_sw_if_index]);
138 always_inline index_t
139 lcp_itf_pair_find_by_host (u32 host_sw_if_index)
141 if (host_sw_if_index >= vec_len (lip_db_by_host))
142 return INDEX_INVALID;
143 return (lip_db_by_host[host_sw_if_index]);
147 * manage interface auto creation
149 void lcp_set_auto_intf (u8 is_auto);
150 int lcp_auto_intf (void);
153 * fd.io coding-style-patch-verification: ON
156 * eval: (c-set-style "gnu")