summaryrefslogtreecommitdiffstats
path: root/src/configure.ac
blob: 8b79cff224f3c0d403a2e844c662db4dbd8153f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
AC_INIT([vpp], [18.01], [vpp-dev@fd.io])
LT_INIT
AC_CONFIG_AUX_DIR([.])
AM_INIT_AUTOMAKE([subdir-objects])
AM_SILENT_RULES([yes])
AC_CONFIG_FILES([Makefile plugins/Makefile vpp-api/python/Makefile vpp-api/java/Makefile vpp-api/vapi/Makefile vpp-api/vom/Makefile])
AC_CONFIG_MACRO_DIR([m4])

AC_PROG_CC
AC_PROG_CXX
AC_PROG_CPP
AM_PROG_AS
AM_PROG_LIBTOOL
AC_PROG_YACC
AM_PATH_PYTHON

AM_CONDITIONAL([CROSSCOMPILE], [test "$cross_compiling" == "yes"])

###############################################################################
# Macros
###############################################################################

AC_DEFUN([ENABLE_ARG],
[
  AC_ARG_ENABLE($1,
    AC_HELP_STRING(patsubst([--enable-$1],[_],[-]), $2),
    [enable_$1=yes n_enable_$1=1],
    [enable_$1=no n_enable_$1=0])
  AM_CONDITIONAL(m4_toupper(ENABLE_$1), test "$enable_$1" = "yes")
  m4_append([list_of_enabled], [$1], [, ])
])

AC_DEFUN([DISABLE_ARG],
[
  AC_ARG_ENABLE($1,
    AC_HELP_STRING(patsubst([--disable-$1],[_],[-]), $2),
    [enable_$1=no n_enable_$1=0],
    [enable_$1=yes n_enable_$1=1])
  AM_CONDITIONAL(m4_toupper(ENABLE_$1), test "$enable_$1" = "yes")
  m4_append([list_of_enabled], [$1], [, ])
])

AC_DEFUN([WITH_ARG],
[
  AC_ARG_WITH($1,
    AC_HELP_STRING(patsubst([--with-$1],[_],[-]), $2),
    [with_$1=yes n_with_$1=1],
    [with_$1=no n_with_$1=0])
  AM_CONDITIONAL(m4_toupper(WITH_$1), test "$with_$1" = "yes")
  m4_append([list_of_with], [$1], [, ])
])

AC_DEFUN([WITHOUT_ARG],
[
  AC_ARG_WITH($1,
    AC_HELP_STRING(patsubst([--without-$1],[_],[-]), $2),
    [with_$1=no n_with_$1=0],
    [with_$1=yes n_with_$1=1])
  AM_CONDITIONAL(m4_toupper(WITH_$1), test "$with_$1" = "yes")
  m4_append([list_of_with], [$1], [, ])
])

AC_DEFUN([PLUGIN_ENABLED],
[
   AC_ARG_ENABLE($1_plugin,
     AC_HELP_STRING([--disable-$1-plugin], [Do not build $1 plugin]),
       [enable_$1_plugin=no],
       [enable_$1_plugin=yes ])
  AM_CONDITIONAL(m4_toupper(ENABLE_$1_PLUGIN), test "$enable_$1_plugin" = "yes")
  m4_append([list_of_plugins], [$1], [, ])
])

AC_DEFUN([PLUGIN_DISABLED],
[
   AC_ARG_ENABLE($1_plugin,
     AC_HELP_STRING([--enable-$1-plugin], [Build $1 plugin]),
       [enable_$1_plugin=yes ],
       [enable_$1_plugin=no])
  AM_CONDITIONAL(m4_toupper(ENABLE_$1_PLUGIN), test "$enable_$1_plugin" = "yes")
  m4_append([list_of_plugins], [$1], [, ])
])

AC_DEFUN([PRINT_VAL], [ AC_MSG_RESULT(AC_HELP_STRING($1,$2)) ])

AC_DEFUN([DPDK_IS_PMD_ENABLED],
[
  AC_MSG_CHECKING([for $1 in rte_config.h])
  AC_COMPILE_IFELSE(
    [AC_LANG_PROGRAM(
      [[#include <rte_config.h>]],
      [[return RTE_$1;]],
    )],
    [with_$2=yes]
    [AC_MSG_RESULT([yes])],
    [with_$2=no]
    [AC_MSG_RESULT([no])]
  )
  AM_CONDITIONAL(m4_toupper(WITH_$2), test "$with_$2" = "yes")
  m4_append_uniq([list_of_with], [$2], [, ])
])

AC_DEFUN([DETECT_DPDK_IS_1702_OR_1705],
[
  AC_MSG_CHECKING([for RTE_VERSION 17.02/17.05 in rte_version.h])
  AC_TRY_RUN(
    [
    #include <rte_version.h>
    int main()
    {
      return ((RTE_VER_YEAR != 17) ||
	      (RTE_VER_MONTH != 2 && RTE_VER_MONTH != 5));
    }
    ],
    [dpdk_is_1702_or_1705=yes]
    [AC_MSG_RESULT([yes])],
    [dpdk_is_1702_or_1705=no]
    [AC_MSG_RESULT([no])]
  )
  AM_CONDITIONAL(DPDK_IS_1702_OR_1705, test "$dpdk_is_1702_or_1705" = "yes")
])

###############################################################################
# configure arguments
###############################################################################

# --enable-X
ENABLE_ARG(tests,	[Enable unit tests])
ENABLE_ARG(dpdk_shared,	[Enable unit tests])
ENABLE_ARG(perftool,	[Enable perftool])
ENABLE_ARG(g2,		[Enable g2])

# --disable-X
DISABLE_ARG(vlib,	[Disable vlib and dependant libs and binaries])
DISABLE_ARG(svm,	[Disable svm and dependant libs and binaries])
DISABLE_ARG(papi,	[Disable Python API bindings])
DISABLE_ARG(japi,	[Disable Java API bindings])
DISABLE_ARG(vom,	[Disable VPP object model bindings])

# --with-X

# --without-X
WITHOUT_ARG(libssl,	[Disable libssl])
WITHOUT_ARG(apicli,	[Disable binary api CLI])

AC_ARG_WITH(unix,
            AC_HELP_STRING([--with-unix],[Compile unix version of clib]),
	    [],
	    [case $host_os in
	      darwin* | linux*) with_unix=yes;;
	      *) with_unix=no;;
	      esac])

AM_CONDITIONAL(WITH_UNIX, test "$with_unix" = "yes")

AC_ARG_WITH(pre-data,
            AC_HELP_STRING([--with-pre-data],[Set buffer rewrite space]),
	    [case $with_pre_data in
	       128) ;;
	       256) ;;
               *) with_pre_data="pre-data-not-set" ;;
	     esac], [with_pre_data=128])

###############################################################################
# Substitutions and defines
###############################################################################

AC_SUBST(PRE_DATA_SIZE,		[$with_pre_data])
AC_SUBST(APICLI,		[-DVPP_API_TEST_BUILTIN=${n_with_apicli}])

AC_DEFINE_UNQUOTED(DPDK_SHARED_LIB,	[${n_enable_dpdk_shared}])
AC_DEFINE_UNQUOTED(WITH_LIBSSL,		[${n_with_libssl}])


# Silence following noise:
# ar: `u' modifier ignored since `D' is the default (see `U')
AR_FLAGS=cr
AC_SUBST(AR_FLAGS)

###############################################################################
# Plugins
###############################################################################

# Please keep alphabetical order
PLUGIN_ENABLED(acl)
PLUGIN_ENABLED(dpdk)
PLUGIN_ENABLED(flowprobe)
PLUGIN_ENABLED(gtpu)
PLUGIN_ENABLED(ila)
PLUGIN_ENABLED(ioam)
PLUGIN_ENABLED(ixge)
PLUGIN_ENABLED(lb)
PLUGIN_ENABLED(memif)
PLUGIN_ENABLED(pppoe)
PLUGIN_ENABLED(sixrd)
PLUGIN_ENABLED(nat)
PLUGIN_ENABLED(stn)

###############################################################################
# Dependency checks
###############################################################################

AM_COND_IF([ENABLE_DPDK_SHARED],
[
  AC_CHECK_HEADERS([rte_config.h],
    [],
    [AC_MSG_ERROR([DPDK header files not found])],)
  AC_CHECK_LIB( [dpdk], [rte_eal_init],
    [],
    [AC_MSG_ERROR([DPDK shared library not found])],)
])

with_aesni_mb_lib=no
with_isa_l_crypto_lib=no

DPDK_IS_PMD_ENABLED(LIBRTE_PMD_AESNI_MB, dpdk_aesni_mb_pmd)
DPDK_IS_PMD_ENABLED(LIBRTE_PMD_AESNI_GCM, dpdk_aesni_gcm_pmd)

DETECT_DPDK_IS_1702_OR_1705()

AM_COND_IF([WITH_DPDK_AESNI_MB_PMD],
[
  AC_CHECK_LIB([IPSec_MB], [submit_job_sse],
	       [with_aesni_mb_lib=yes],
	       [AC_MSG_ERROR([IPSec_MB library not found])])
])

AM_COND_IF([WITH_DPDK_AESNI_GCM_PMD],
[
  AM_COND_IF([DPDK_IS_1702_OR_1705],
  [
    AC_CHECK_LIB([isal_crypto], [aesni_gcm128_init],
		 [with_isa_l_crypto_lib=yes],
		 [AC_MSG_ERROR([isal_crypto library not found])])
  ],
  [
    AC_CHECK_LIB([IPSec_MB], [submit_job_sse],
		 [with_aesni_mb_lib=yes],
		 [AC_MSG_ERROR([IPSec_MB library not found])])
  ])
])

m4_append([list_of_with], [aesni_mb_lib], [, ])
AM_CONDITIONAL(WITH_AESNI_MB_LIB, test "$with_aesni_mb_lib" = "yes")

m4_append([list_of_with], [isa_l_crypto_lib], [, ])
AM_CONDITIONAL(WITH_ISA_L_CRYPTO_LIB, test "$with_isa_l_crypto_lib" = "yes")


with_ibverbs_lib=no
DPDK_IS_PMD_ENABLED(LIBRTE_MLX4_PMD, dpdk_mlx4_pmd)
AM_COND_IF([WITH_DPDK_MLX4_PMD],
[
  AC_CHECK_LIB([ibverbs], [ibv_fork_init],
	       [with_ibverbs_lib=yes],
	       [AC_MSG_ERROR([ibverbs library not found])])
])

DPDK_IS_PMD_ENABLED(LIBRTE_MLX5_PMD, dpdk_mlx5_pmd)
AM_COND_IF([WITH_DPDK_MLX5_PMD],
[
  AC_CHECK_LIB([ibverbs], [ibv_fork_init],
	       [with_ibverbs_lib=yes],
	       [AC_MSG_ERROR([ibverbs library not found])])
])

m4_append([list_of_with], [ibverbs_lib], [, ])
AM_CONDITIONAL(WITH_IBVERBS_LIB, test "$with_ibverbs_lib" = "yes")


AM_COND_IF([ENABLE_G2],
[
  PKG_CHECK_MODULES(g2, gtk+-2.0)
])

# If cross-compiling, we need external vppapigen and we cannot continue without it
# For native builds, we just set dependency on vpppaigen binary in top_builddir
AM_COND_IF([CROSSCOMPILE],
[
  AC_PATH_PROG([VPPAPIGEN], [vppapigen], [no])
  if test "$VPPAPIGEN" = "no"; then
    AC_MSG_ERROR([Externaly built vppapigen is needed when cross-compiling...])
  fi
],[
  VPPAPIGEN=\$\(top_builddir\)/vppapigen
])
AC_SUBST([VPPAPIGEN])


###############################################################################
# JAVA
###############################################################################

AM_COND_IF([ENABLE_JAPI],
[
  AX_VPP_FIND_JDK8
  AC_SUBST(JAVA_HOME)
  AC_SUBST(JAVAC)
  AC_SUBST(JAVAH)
  AC_SUBST(JAR)
])

###############################################################################
# PYTHON
###############################################################################

AM_COND_IF([ENABLE_PAPI],
[
  AM_PATH_PYTHON
])

###############################################################################
# Output
###############################################################################

AC_OUTPUT

AC_MSG_RESULT([==============================================================================])
PRINT_VAL([version], $PACKAGE $VERSION)
PRINT_VAL([prefix], ${prefix})
PRINT_VAL([libdir], ${libdir})
PRINT_VAL([includedir], ${includedir})
PRINT_VAL([CFLAGS], ${CFLAGS})
PRINT_VAL([CPPFLAGS], ${CPPFLAGS})
PRINT_VAL([LDFLAGS], ${LDFLAGS})
AM_COND_IF([ENABLE_JAPI],
[
  PRINT_VAL([JAVA_VERSION], ${JAVA_VERSION})
  PRINT_VAL([JAVA_HOME], ${JAVA_HOME})
])

AC_MSG_RESULT([])
AC_MSG_RESULT([with:])
m4_foreach([x], m4_dquote(list_of_with), [
  AC_MSG_RESULT(AC_HELP_STRING(x, m4_join([], [${with_], x, [}])))
])

AC_MSG_RESULT([])
AC_MSG_RESULT([enabled:])
m4_foreach([x], m4_dquote(list_of_enabled), [
  AC_MSG_RESULT(AC_HELP_STRING(x, m4_join([], [${enable_], x, [}])))
])

AC_MSG_RESULT([])
AC_MSG_RESULT([plugins:])
m4_foreach([x], m4_dquote(list_of_plugins), [
  AC_MSG_RESULT(AC_HELP_STRING(x, m4_join([], [${enable_], x, [_plugin}])))
])
AC_MSG_RESULT([==============================================================================])
walk.h> /** * The two midchain tx feature node indices */ static u32 adj_midchain_tx_feature_node[VNET_LINK_NUM]; static u32 adj_midchain_tx_no_count_feature_node[VNET_LINK_NUM]; /** * @brief Trace data for packets traversing the midchain tx node */ typedef struct adj_midchain_tx_trace_t_ { /** * @brief the midchain adj we are traversing */ adj_index_t ai; } adj_midchain_tx_trace_t; always_inline uword adj_midchain_tx_inline (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame, int interface_count) { u32 * from, * to_next, n_left_from, n_left_to_next; u32 next_index; vnet_main_t *vnm = vnet_get_main (); vnet_interface_main_t *im = &vnm->interface_main; u32 thread_index = vm->thread_index; /* Vector of buffer / pkt indices we're supposed to process */ from = vlib_frame_vector_args (frame); /* Number of buffers / pkts */ n_left_from = frame->n_vectors; /* Speculatively send the first buffer to the last disposition we used */ next_index = node->cached_next_index; while (n_left_from > 0) { /* set up to enqueue to our disposition with index = next_index */ vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next); while (n_left_from >= 4 && n_left_to_next > 2) { u32 bi0, adj_index0, next0; const ip_adjacency_t * adj0; const dpo_id_t *dpo0; vlib_buffer_t * b0; u32 bi1, adj_index1, next1; const ip_adjacency_t * adj1; const dpo_id_t *dpo1; vlib_buffer_t * b1; /* Prefetch next iteration. */ { vlib_buffer_t * p2, * p3; p2 = vlib_get_buffer (vm, from[2]); p3 = vlib_get_buffer (vm, from[3]); vlib_prefetch_buffer_header (p2, LOAD); vlib_prefetch_buffer_header (p3, LOAD); CLIB_PREFETCH (p2->data, CLIB_CACHE_LINE_BYTES, STORE); CLIB_PREFETCH (p3->data, CLIB_CACHE_LINE_BYTES, STORE); } bi0 = from[0]; to_next[0] = bi0; bi1 = from[1]; to_next[1] = bi1; from += 2; to_next += 2; n_left_from -= 2; n_left_to_next -= 2; b0 = vlib_get_buffer(vm, bi0); b1 = vlib_get_buffer(vm, bi1); /* Follow the DPO on which the midchain is stacked */ adj_index0 = vnet_buffer(b0)->ip.adj_index[VLIB_TX]; adj_index1 = vnet_buffer(b1)->ip.adj_index[VLIB_TX]; adj0 = adj_get(adj_index0); adj1 = adj_get(adj_index1); dpo0 = &adj0->sub_type.midchain.next_dpo; dpo1 = &adj1->sub_type.midchain.next_dpo; next0 = dpo0->dpoi_next_node; next1 = dpo1->dpoi_next_node; vnet_buffer(b1)->ip.adj_index[VLIB_TX] = dpo1->dpoi_index; vnet_buffer(b0)->ip.adj_index[VLIB_TX] = dpo0->dpoi_index; if (interface_count) { vlib_increment_combined_counter (im->combined_sw_if_counters + VNET_INTERFACE_COUNTER_TX, thread_index, adj0->rewrite_header.sw_if_index, 1, vlib_buffer_length_in_chain (vm, b0)); vlib_increment_combined_counter (im->combined_sw_if_counters + VNET_INTERFACE_COUNTER_TX, thread_index, adj1->rewrite_header.sw_if_index, 1, vlib_buffer_length_in_chain (vm, b1)); } if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED)) { adj_midchain_tx_trace_t *tr = vlib_add_trace (vm, node, b0, sizeof (*tr)); tr->ai = adj_index0; } if (PREDICT_FALSE(b1->flags & VLIB_BUFFER_IS_TRACED)) { adj_midchain_tx_trace_t *tr = vlib_add_trace (vm, node, b1, sizeof (*tr)); tr->ai = adj_index1; } vlib_validate_buffer_enqueue_x2 (vm, node, next_index, to_next, n_left_to_next, bi0, bi1, next0, next1); } while (n_left_from > 0 && n_left_to_next > 0) { u32 bi0, adj_index0, next0; const ip_adjacency_t * adj0; const dpo_id_t *dpo0; vlib_buffer_t * b0; bi0 = from[0]; to_next[0] = bi0; from += 1; to_next += 1; n_left_from -= 1; n_left_to_next -= 1; b0 = vlib_get_buffer(vm, bi0); /* Follow the DPO on which the midchain is stacked */ adj_index0 = vnet_buffer(b0)->ip.adj_index[VLIB_TX]; adj0 = adj_get(adj_index0); dpo0 = &adj0->sub_type.midchain.next_dpo; next0 = dpo0->dpoi_next_node; vnet_buffer(b0)->ip.adj_index[VLIB_TX] = dpo0->dpoi_index; if (interface_count) { vlib_increment_combined_counter (im->combined_sw_if_counters + VNET_INTERFACE_COUNTER_TX, thread_index, adj0->rewrite_header.sw_if_index, 1, vlib_buffer_length_in_chain (vm, b0)); } if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED)) { adj_midchain_tx_trace_t *tr = vlib_add_trace (vm, node, b0, sizeof (*tr)); tr->ai = adj_index0; } vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next, n_left_to_next, bi0, next0); } vlib_put_next_frame (vm, node, next_index, n_left_to_next); } return frame->n_vectors; } static u8 * format_adj_midchain_tx_trace (u8 * s, va_list * args) { CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *); CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); adj_midchain_tx_trace_t *tr = va_arg (*args, adj_midchain_tx_trace_t*); s = format(s, "adj-midchain:[%d]:%U", tr->ai, format_ip_adjacency, tr->ai, FORMAT_IP_ADJACENCY_NONE); return (s); } static uword adj_midchain_tx (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame) { return (adj_midchain_tx_inline(vm, node, frame, 1)); } VLIB_REGISTER_NODE (adj_midchain_tx_node, static) = { .function = adj_midchain_tx, .name = "adj-midchain-tx", .vector_size = sizeof (u32), .format_trace = format_adj_midchain_tx_trace, .n_next_nodes = 1, .next_nodes = { [0] = "error-drop", }, }; static uword adj_midchain_tx_no_count (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame) { return (adj_midchain_tx_inline(vm, node, frame, 0)); } VLIB_REGISTER_NODE (adj_midchain_tx_no_count_node, static) = { .function = adj_midchain_tx_no_count, .name = "adj-midchain-tx-no-count", .vector_size = sizeof (u32), .format_trace = format_adj_midchain_tx_trace, .n_next_nodes = 1, .next_nodes = { [0] = "error-drop", }, }; VNET_FEATURE_INIT (adj_midchain_tx_ip4, static) = { .arc_name = "ip4-output", .node_name = "adj-midchain-tx", .runs_before = VNET_FEATURES ("interface-output"), .feature_index_ptr = &adj_midchain_tx_feature_node[VNET_LINK_IP4], }; VNET_FEATURE_INIT (adj_midchain_tx_no_count_ip4, static) = { .arc_name = "ip4-output", .node_name = "adj-midchain-tx-no-count", .runs_before = VNET_FEATURES ("interface-output"), .feature_index_ptr = &adj_midchain_tx_no_count_feature_node[VNET_LINK_IP4], }; VNET_FEATURE_INIT (adj_midchain_tx_ip6, static) = { .arc_name = "ip6-output", .node_name = "adj-midchain-tx", .runs_before = VNET_FEATURES ("interface-output"), .feature_index_ptr = &adj_midchain_tx_feature_node[VNET_LINK_IP6], }; VNET_FEATURE_INIT (adj_midchain_tx_no_count_ip6, static) = { .arc_name = "ip6-output", .node_name = "adj-midchain-tx-no-count", .runs_before = VNET_FEATURES ("interface-output"), .feature_index_ptr = &adj_midchain_tx_no_count_feature_node[VNET_LINK_IP6], }; VNET_FEATURE_INIT (adj_midchain_tx_mpls, static) = { .arc_name = "mpls-output", .node_name = "adj-midchain-tx", .runs_before = VNET_FEATURES ("interface-output"), .feature_index_ptr = &adj_midchain_tx_feature_node[VNET_LINK_MPLS], }; VNET_FEATURE_INIT (adj_midchain_tx_no_count_mpls, static) = { .arc_name = "mpls-output", .node_name = "adj-midchain-tx-no-count", .runs_before = VNET_FEATURES ("interface-output"), .feature_index_ptr = &adj_midchain_tx_no_count_feature_node[VNET_LINK_MPLS], }; VNET_FEATURE_INIT (adj_midchain_tx_ethernet, static) = { .arc_name = "ethernet-output", .node_name = "adj-midchain-tx", .runs_before = VNET_FEATURES ("error-drop"), .feature_index_ptr = &adj_midchain_tx_feature_node[VNET_LINK_ETHERNET], }; VNET_FEATURE_INIT (adj_midchain_tx_no_count_ethernet, static) = { .arc_name = "ethernet-output", .node_name = "adj-midchain-tx-no-count", .runs_before = VNET_FEATURES ("error-drop"), .feature_index_ptr = &adj_midchain_tx_no_count_feature_node[VNET_LINK_ETHERNET], }; VNET_FEATURE_INIT (adj_midchain_tx_nsh, static) = { .arc_name = "nsh-output", .node_name = "adj-midchain-tx", .runs_before = VNET_FEATURES ("error-drop"), .feature_index_ptr = &adj_midchain_tx_feature_node[VNET_LINK_NSH], }; VNET_FEATURE_INIT (adj_midchain_tx_no_count_nsh, static) = { .arc_name = "nsh-output", .node_name = "adj-midchain-tx-no-count", .runs_before = VNET_FEATURES ("error-drop"), .feature_index_ptr = &adj_midchain_tx_no_count_feature_node[VNET_LINK_NSH], }; static inline u32 adj_get_midchain_node (vnet_link_t link) { switch (link) { case VNET_LINK_IP4: return (ip4_midchain_node.index); case VNET_LINK_IP6: return (ip6_midchain_node.index); case VNET_LINK_MPLS: return (mpls_midchain_node.index); case VNET_LINK_ETHERNET: return (adj_l2_midchain_node.index); case VNET_LINK_NSH: return (adj_nsh_midchain_node.index); case VNET_LINK_ARP: break; } ASSERT(0); return (0); } static u8 adj_midchain_get_feature_arc_index_for_link_type (const ip_adjacency_t *adj) { u8 arc = (u8) ~0; switch (adj->ia_link) { case VNET_LINK_IP4: { arc = ip4_main.lookup_main.output_feature_arc_index; break; } case VNET_LINK_IP6: { arc = ip6_main.lookup_main.output_feature_arc_index; break; } case VNET_LINK_MPLS: { arc = mpls_main.output_feature_arc_index; break; } case VNET_LINK_ETHERNET: { arc = ethernet_main.output_feature_arc_index; break; } case VNET_LINK_NSH: { arc = nsh_main_dummy.output_feature_arc_index; break; } case VNET_LINK_ARP: ASSERT(0); break; } ASSERT (arc != (u8) ~0); return (arc); } static u32 adj_nbr_midchain_get_tx_node (ip_adjacency_t *adj) { return ((adj->ia_flags & ADJ_FLAG_MIDCHAIN_NO_COUNT) ? adj_midchain_tx_no_count_node.index : adj_midchain_tx_node.index); } /** * adj_midchain_setup * * Setup the adj as a mid-chain */ void adj_midchain_setup (adj_index_t adj_index, adj_midchain_fixup_t fixup, adj_flags_t flags) { u32 feature_index, tx_node; ip_adjacency_t *adj; u8 arc_index; ASSERT(ADJ_INDEX_INVALID != adj_index); adj = adj_get(adj_index); adj->sub_type.midchain.fixup_func = fixup; adj->ia_flags |= flags; arc_index = adj_midchain_get_feature_arc_index_for_link_type (adj); feature_index = (flags & ADJ_FLAG_MIDCHAIN_NO_COUNT) ? adj_midchain_tx_no_count_feature_node[adj->ia_link] : adj_midchain_tx_feature_node[adj->ia_link]; tx_node = adj_nbr_midchain_get_tx_node(adj); vnet_feature_enable_disable_with_index (arc_index, feature_index, adj->rewrite_header.sw_if_index, 1 /* enable */, 0, 0); /* * stack the midchain on the drop so it's ready to forward in the adj-midchain-tx. * The graph arc used/created here is from the midchain-tx node to the * child's registered node. This is because post adj processing the next * node are any output features, then the midchain-tx. from there we * need to get to the stacked child's node. */ dpo_stack_from_node(tx_node, &adj->sub_type.midchain.next_dpo, drop_dpo_get(vnet_link_to_dpo_proto(adj->ia_link))); } /** * adj_nbr_midchain_update_rewrite * * Update the adjacency's rewrite string. A NULL string implies the * rewrite is reset (i.e. when ARP/ND etnry is gone). * NB: the adj being updated may be handling traffic in the DP. */ void adj_nbr_midchain_update_rewrite (adj_index_t adj_index, adj_midchain_fixup_t fixup, adj_flags_t flags, u8 *rewrite) { ip_adjacency_t *adj; ASSERT(ADJ_INDEX_INVALID != adj_index); adj = adj_get(adj_index); /* * one time only update. since we don't support chainging the tunnel * src,dst, this is all we need. */ ASSERT(adj->lookup_next_index == IP_LOOKUP_NEXT_ARP); /* * tunnels can always provide a rewrite. */ ASSERT(NULL != rewrite); adj_midchain_setup(adj_index, fixup, flags); /* * update the rewirte with the workers paused. */ adj_nbr_update_rewrite_internal(adj, IP_LOOKUP_NEXT_MIDCHAIN, adj_get_midchain_node(adj->ia_link), adj_nbr_midchain_get_tx_node(adj), rewrite); } /** * adj_nbr_midchain_unstack * * Unstack the adj. stack it on drop */ void adj_nbr_midchain_unstack (adj_index_t adj_index) { ip_adjacency_t *adj; ASSERT(ADJ_INDEX_INVALID != adj_index); adj = adj_get(adj_index); /* * stack on the drop */ dpo_stack(DPO_ADJACENCY_MIDCHAIN, vnet_link_to_dpo_proto(adj->ia_link), &adj->sub_type.midchain.next_dpo, drop_dpo_get(vnet_link_to_dpo_proto(adj->ia_link))); CLIB_MEMORY_BARRIER(); } /** * adj_nbr_midchain_stack */ void adj_nbr_midchain_stack (adj_index_t adj_index, const dpo_id_t *next) { ip_adjacency_t *adj; ASSERT(ADJ_INDEX_INVALID != adj_index); adj = adj_get(adj_index); ASSERT((IP_LOOKUP_NEXT_MIDCHAIN == adj->lookup_next_index) || (IP_LOOKUP_NEXT_MCAST_MIDCHAIN == adj->lookup_next_index)); dpo_stack_from_node(adj_nbr_midchain_get_tx_node(adj), &adj->sub_type.midchain.next_dpo, next); } u8* format_adj_midchain (u8* s, va_list *ap) { index_t index = va_arg(*ap, index_t); u32 indent = va_arg(*ap, u32); ip_adjacency_t * adj = adj_get(index); s = format (s, "%U", format_vnet_link, adj->ia_link); s = format (s, " via %U ", format_ip46_address, &adj->sub_type.nbr.next_hop); s = format (s, " %U", format_vnet_rewrite, &adj->rewrite_header, sizeof (adj->rewrite_data), indent); s = format (s, "\n%Ustacked-on:\n%U%U", format_white_space, indent, format_white_space, indent+2, format_dpo_id, &adj->sub_type.midchain.next_dpo, indent+2); return (s); } static void adj_dpo_lock (dpo_id_t *dpo) { adj_lock(dpo->dpoi_index); } static void adj_dpo_unlock (dpo_id_t *dpo) { adj_unlock(dpo->dpoi_index); } const static dpo_vft_t adj_midchain_dpo_vft = { .dv_lock = adj_dpo_lock, .dv_unlock = adj_dpo_unlock, .dv_format = format_adj_midchain, }; /** * @brief The per-protocol VLIB graph nodes that are assigned to a midchain * object. * * this means that these graph nodes are ones from which a midchain is the * parent object in the DPO-graph. */ const static char* const midchain_ip4_nodes[] = { "ip4-midchain", NULL, }; const static char* const midchain_ip6_nodes[] = { "ip6-midchain", NULL, }; const static char* const midchain_mpls_nodes[] = { "mpls-midchain", NULL, }; const static char* const midchain_ethernet_nodes[] = { "adj-l2-midchain", NULL, }; const static char* const midchain_nsh_nodes[] = { "adj-nsh-midchain", NULL, }; const static char* const * const midchain_nodes[DPO_PROTO_NUM] = { [DPO_PROTO_IP4] = midchain_ip4_nodes, [DPO_PROTO_IP6] = midchain_ip6_nodes, [DPO_PROTO_MPLS] = midchain_mpls_nodes, [DPO_PROTO_ETHERNET] = midchain_ethernet_nodes, [DPO_PROTO_NSH] = midchain_nsh_nodes, }; void adj_midchain_module_init (void) { dpo_register(DPO_ADJACENCY_MIDCHAIN, &adj_midchain_dpo_vft, midchain_nodes); }