FD.io VPP  v19.04-6-g6f05f72
Vector Packet Processing
l3_proxy_dpo.c
Go to the documentation of this file.
1 /*
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  * @brief
17  * The data-path object representing l3_proxying the packet, i.e. it's for-us
18  */
19 #include <vlib/vlib.h>
20 #include <vnet/ip/ip.h>
21 #include <vnet/dpo/l3_proxy_dpo.h>
22 
23 /**
24  * @brief pool of all l3_proxy DPOs
25  */
27 
28 static l3_proxy_dpo_t *
30 {
31  l3_proxy_dpo_t *l3p;
32 
33  pool_get_aligned(l3_proxy_dpo_pool, l3p, CLIB_CACHE_LINE_BYTES);
34  clib_memset(l3p, 0, sizeof(*l3p));
35 
36  return (l3p);
37 }
38 
39 static l3_proxy_dpo_t *
41 {
42  ASSERT(DPO_L3_PROXY == dpo->dpoi_type);
43 
44  return (l3_proxy_dpo_get(dpo->dpoi_index));
45 }
46 
47 
48 /*
49  * l3_proxy_dpo_add_or_lock
50  *
51  * The next_hop address here is used for source address selection in the DP.
52  * The local adj is added to an interface's l3_proxy prefix, the next-hop
53  * passed here is the local prefix on the same interface.
54  */
55 void
58  dpo_id_t *dpo)
59 {
60  l3_proxy_dpo_t *l3p;
61 
62  l3p = l3_proxy_dpo_alloc();
63 
65 
66  dpo_set(dpo, DPO_L3_PROXY, proto, (l3p - l3_proxy_dpo_pool));
67 }
68 
69 static void
71 {
72  l3_proxy_dpo_t *l3p;
73 
74  l3p = l3_proxy_dpo_get_from_dpo(dpo);
75  l3p->l3p_locks++;
76 }
77 
78 static void
80 {
81  l3_proxy_dpo_t *l3p;
82 
83  l3p = l3_proxy_dpo_get_from_dpo(dpo);
84  l3p->l3p_locks--;
85 
86  if (0 == l3p->l3p_locks)
87  {
88  pool_put(l3_proxy_dpo_pool, l3p);
89  }
90 }
91 
92 static u32
94 {
95  l3_proxy_dpo_t *l3p;
96 
97  l3p = l3_proxy_dpo_get_from_dpo(dpo);
98 
99  return (l3p->l3p_sw_if_index);
100 }
101 
102 static u8*
103 format_l3_proxy_dpo (u8 *s, va_list *ap)
104 {
105  CLIB_UNUSED(index_t index) = va_arg(*ap, index_t);
106  CLIB_UNUSED(u32 indent) = va_arg(*ap, u32);
107  vnet_main_t * vnm = vnet_get_main();
108  l3_proxy_dpo_t *l3p;
109 
110  if (pool_is_free_index(l3_proxy_dpo_pool, index))
111  {
112  return (format(s, "dpo-l3_proxy DELETED"));
113  }
114 
115  l3p = l3_proxy_dpo_get(index);
116 
117  if (~0 != l3p->l3p_sw_if_index)
118  {
119  return (format(s, "dpo-l3_proxy: %U",
122  }
123  else
124  {
125  return (format(s, "dpo-l3-proxy"));
126  }
127 }
128 
129 static void
131 {
132  fib_show_memory_usage("L3 Proxy",
133  pool_elts(l3_proxy_dpo_pool),
134  pool_len(l3_proxy_dpo_pool),
135  sizeof(l3_proxy_dpo_t));
136 }
137 
138 const static dpo_vft_t l3_proxy_vft = {
140  .dv_unlock = l3_proxy_dpo_unlock,
141  .dv_format = format_l3_proxy_dpo,
142  .dv_get_urpf = l3_proxy_dpo_get_urpf,
143  .dv_mem_show = l3_proxy_dpo_mem_show,
144 };
145 
146 /**
147  * @brief The per-protocol VLIB graph nodes that are assigned to a l3_proxy
148  * object.
149  *
150  * this means that these graph nodes are ones from which a l3_proxy is the
151  * parent object in the DPO-graph.
152  */
153 const static char* const l3_proxy_ip4_nodes[] =
154 {
155  "ip4-local",
156  NULL,
157 };
158 const static char* const l3_proxy_ip6_nodes[] =
159 {
160  "ip6-local",
161  NULL,
162 };
163 
164 const static char* const * const l3_proxy_nodes[DPO_PROTO_NUM] =
165 {
168  [DPO_PROTO_MPLS] = NULL,
169 };
170 
171 void
173 {
174  dpo_register(DPO_L3_PROXY, &l3_proxy_vft, l3_proxy_nodes);
175 }
u32 sw_if_index
Definition: ipsec_gre.api:37
dpo_lock_fn_t dv_lock
A reference counting lock function.
Definition: dpo.h:404
#define CLIB_UNUSED(x)
Definition: clib.h:82
A virtual function table regisitered for a DPO type.
Definition: dpo.h:399
static void l3_proxy_dpo_lock(dpo_id_t *dpo)
Definition: l3_proxy_dpo.c:70
vnet_main_t * vnet_get_main(void)
Definition: misc.c:47
void l3_proxy_dpo_module_init(void)
Definition: l3_proxy_dpo.c:172
#define NULL
Definition: clib.h:58
static const char *const l3_proxy_ip4_nodes[]
The per-protocol VLIB graph nodes that are assigned to a l3_proxy object.
Definition: l3_proxy_dpo.c:153
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:41
clib_memset(h->entries, 0, sizeof(h->entries[0])*entries)
static vnet_sw_interface_t * vnet_get_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
static void l3_proxy_dpo_unlock(dpo_id_t *dpo)
Definition: l3_proxy_dpo.c:79
The data-path object representing L3 proxy.
Definition: l3_proxy_dpo.h:27
unsigned char u8
Definition: types.h:56
#define pool_len(p)
Number of elements in pool vector.
Definition: pool.h:140
void dpo_register(dpo_type_t type, const dpo_vft_t *vft, const char *const *const *nodes)
For a given DPO type Register:
Definition: dpo.c:321
static l3_proxy_dpo_t * l3_proxy_dpo_get_from_dpo(const dpo_id_t *dpo)
Definition: l3_proxy_dpo.c:40
static const char *const *const l3_proxy_nodes[DPO_PROTO_NUM]
Definition: l3_proxy_dpo.c:164
void fib_show_memory_usage(const char *name, u32 in_use_elts, u32 allocd_elts, size_t size_elt)
Show the memory usage for a type.
Definition: fib_node.c:220
unsigned int u32
Definition: types.h:88
enum dpo_proto_t_ dpo_proto_t
Data path protocol.
u32 l3p_sw_if_index
The Software interface index on which traffic is l3_proxyd.
Definition: l3_proxy_dpo.h:38
l3_proxy_dpo_t * l3_proxy_dpo_pool
The data-path object representing l3_proxying the packet, i.e.
Definition: l3_proxy_dpo.c:26
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
Definition: dpo.h:168
format_function_t format_vnet_sw_interface_name
dpo_type_t dpoi_type
the type
Definition: dpo.h:172
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:286
#define pool_get_aligned(P, E, A)
Allocate an object E from a pool P with alignment A.
Definition: pool.h:230
static l3_proxy_dpo_t * l3_proxy_dpo_alloc(void)
Definition: l3_proxy_dpo.c:29
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:283
void dpo_set(dpo_id_t *dpo, dpo_type_t type, dpo_proto_t proto, index_t index)
Set/create a DPO ID The DPO will be locked.
Definition: dpo.c:185
static u32 l3_proxy_dpo_get_urpf(const dpo_id_t *dpo)
Definition: l3_proxy_dpo.c:93
static void l3_proxy_dpo_mem_show(void)
Definition: l3_proxy_dpo.c:130
#define ASSERT(truth)
static const char *const l3_proxy_ip6_nodes[]
Definition: l3_proxy_dpo.c:158
static l3_proxy_dpo_t * l3_proxy_dpo_get(index_t index)
Definition: l3_proxy_dpo.h:58
static u8 * format_l3_proxy_dpo(u8 *s, va_list *ap)
Definition: l3_proxy_dpo.c:103
u16 l3p_locks
number oflocks.
Definition: l3_proxy_dpo.h:43
#define DPO_PROTO_NUM
Definition: dpo.h:70
index_t dpoi_index
the index of objects of that type
Definition: dpo.h:184
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:59
void l3_proxy_dpo_add_or_lock(dpo_proto_t proto, u32 sw_if_index, dpo_id_t *dpo)
Definition: l3_proxy_dpo.c:56
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:128