FD.io VPP  v21.06
Vector Packet Processing
lcp_interface.h
Go to the documentation of this file.
1 /*
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:
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 #ifndef __LCP_ITF_PAIR_H__
16 #define __LCP_ITF_PAIR_H__
17 
18 #include <vnet/dpo/dpo.h>
19 #include <vnet/adj/adj.h>
20 #include <vnet/ip/ip_types.h>
21 
22 #include <plugins/linux-cp/lcp.h>
23 
24 #define foreach_lcp_itf_pair_flag _ (STALE, 0, "stale")
25 
26 typedef enum lip_flag_t_
27 {
28 #define _(a, b, c) LIP_FLAG_##a = (1 << b),
30 #undef _
31 } lip_flag_t;
32 
33 typedef enum
34 {
38 
39 #define N_LCP_ITF_HOST (LCP_ITF_HOST_TUN + 1)
40 
41 typedef struct lcp_itf_phy_adj
42 {
45 
46 /**
47  * A pair of interfaces
48  */
49 typedef struct lcp_itf_pair_t_
50 {
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 */
63 
65 
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);
69 
70 /**
71  * Get an interface-pair object from its VPP index
72  */
74 
75 /**
76  * Find a interface-pair object from the host interface
77  *
78  * @param host_sw_if_index host interface
79  * @return VPP's object index
80  */
81 extern index_t lcp_itf_pair_find_by_vif (u32 vif_index);
82 
83 /**
84  * Create an interface-pair
85  *
86  * @return error code
87  */
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);
94 
95 /**
96  * Create an interface-pair from PHY sw_if_index and tap name.
97  *
98  * @return error code
99  */
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,
102  u32 *host_sw_if_indexp);
103 
104 /**
105  * Delete a LCP_ITF_PAIR
106  */
107 extern int lcp_itf_pair_delete (u32 phy_sw_if_index);
108 
109 /**
110  * Callback function invoked during a walk of all interface-pairs
111  */
113 
114 /**
115  * Walk/visit each of the interface pairs
116  */
117 extern void lcp_itf_pair_walk (lcp_itf_pair_walk_cb_t cb, void *ctx);
118 
119 /**
120  * Begin and End the replace process
121  */
122 extern int lcp_itf_pair_replace_begin (void);
123 extern int lcp_itf_pair_replace_end (void);
124 
125 /**
126  * Retreive the pair in the DP
127  */
128 extern index_t *lip_db_by_phy;
129 extern u32 *lip_db_by_host;
130 
132 lcp_itf_pair_find_by_phy (u32 phy_sw_if_index)
133 {
134  if (phy_sw_if_index >= vec_len (lip_db_by_phy))
135  return INDEX_INVALID;
136  return (lip_db_by_phy[phy_sw_if_index]);
137 }
138 
140 lcp_itf_pair_find_by_host (u32 host_sw_if_index)
141 {
142  if (host_sw_if_index >= vec_len (lip_db_by_host))
143  return INDEX_INVALID;
144  return (lip_db_by_host[host_sw_if_index]);
145 }
146 
147 /**
148  * manage interface auto creation
149  */
150 void lcp_set_auto_intf (u8 is_auto);
151 int lcp_auto_intf (void);
152 
153 /*
154  * fd.io coding-style-patch-verification: ON
155  *
156  * Local Variables:
157  * eval: (c-set-style "gnu")
158  * End:
159  */
160 
161 #endif
lip_host_type_t lip_host_type
Definition: lcp_interface.h:56
vlib_node_registration_t lcp_ethernet_node
lip_host_type_t
Definition: lcp_interface.h:33
index_t lcp_itf_pair_find_by_vif(u32 vif_index)
Find a interface-pair object from the host interface.
struct lcp_itf_pair_t_ lcp_itf_pair_t
A pair of interfaces.
#define foreach_lcp_itf_pair_flag
Definition: lcp_interface.h:24
index_t * lip_db_by_phy
Retreive the pair in the DP.
Definition: lcp_interface.c:60
A pair of interfaces.
Definition: lcp_interface.h:49
enum lip_flag_t_ lip_flag_t
u32 index_t
A Data-Path Object is an object that represents actions that are applied to packets are they are swit...
Definition: dpo.h:43
lip_flag_t_
Definition: lcp_interface.h:26
walk_rc_t(* lcp_itf_pair_walk_cb_t)(index_t index, void *ctx)
Callback function invoked during a walk of all interface-pairs.
u32 lcp_itf_num_pairs(void)
Definition: lcp_interface.c:48
unsigned char u8
Definition: types.h:56
static index_t lcp_itf_pair_find_by_phy(u32 phy_sw_if_index)
double f64
Definition: types.h:142
unsigned int u32
Definition: types.h:88
enum walk_rc_t_ walk_rc_t
Walk return code.
int lcp_itf_pair_delete(u32 phy_sw_if_index)
Delete a LCP_ITF_PAIR.
lcp_itf_pair_t * lcp_itf_pair_pool
Pool of LIP objects.
Definition: lcp_interface.c:45
void lcp_itf_pair_show(u32 phy_sw_if_index)
u8 * format_lcp_itf_pair(u8 *s, va_list *args)
Definition: lcp_interface.c:70
int lcp_itf_pair_del(u32 phy_sw_if_index)
long ctx[MAX_CONNS]
Definition: main.c:144
lip_flag_t lip_flags
Definition: lcp_interface.h:58
int lcp_itf_pair_add(u32 host_sw_if_index, u32 phy_sw_if_index, u8 *host_name, u32 host_index, lip_host_type_t host_type, u8 *ns)
Create an interface-pair.
int lcp_itf_pair_replace_begin(void)
Begin and End the replace process.
int lcp_itf_pair_add_sub(u32 vif, u8 *host_name, u32 sub_sw_if_index, u32 phy_sw_if_index, u8 *ns)
int lcp_auto_intf(void)
Definition: lcp_api.c:53
static index_t lcp_itf_pair_find_by_host(u32 host_sw_if_index)
void lcp_set_auto_intf(u8 is_auto)
manage interface auto creation
Definition: lcp_api.c:45
u32 index
Definition: flow_types.api:221
u32 adj_index_t
An index for adjacencies.
Definition: adj_types.h:30
u32 * lip_db_by_host
Definition: lcp_interface.c:61
int lcp_itf_pair_create(u32 phy_sw_if_index, u8 *host_if_name, lip_host_type_t host_if_type, u8 *ns, u32 *host_sw_if_indexp)
Create an interface-pair from PHY sw_if_index and tap name.
#define always_inline
Definition: rdma_mlx5dv.h:23
lcp_itf_phy_adj_t lip_phy_adjs
Definition: lcp_interface.h:57
struct _vlib_node_registration vlib_node_registration_t
#define N_AF
Definition: ip_types.h:27
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
#define INDEX_INVALID
Invalid index - used when no index is known blazoned capitals INVALID speak volumes where ~0 does not...
Definition: dpo.h:49
void lcp_itf_pair_walk(lcp_itf_pair_walk_cb_t cb, void *ctx)
Walk/visit each of the interface pairs.
adj_index_t adj_index[N_AF]
Definition: lcp_interface.h:43
struct lcp_itf_phy_adj lcp_itf_phy_adj_t
int lcp_itf_pair_replace_end(void)
lcp_itf_pair_t * lcp_itf_pair_get(index_t index)
Get an interface-pair object from its VPP index.