FD.io VPP  v19.01.2-3-gf61a1a8
Vector Packet Processing
lb.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 #include <lb/lb.h>
17 #include <vnet/plugin/plugin.h>
18 #include <vpp/app/version.h>
19 #include <vnet/api_errno.h>
20 #include <vnet/udp/udp.h>
21 
22 //GC runs at most once every so many seconds
23 #define LB_GARBAGE_RUN 60
24 
25 //After so many seconds. It is assumed that inter-core race condition will not occur.
26 #define LB_CONCURRENCY_TIMEOUT 10
27 
29 
30 #define lb_get_writer_lock() do {} while(clib_atomic_test_and_set (lb_main.writer_lock))
31 #define lb_put_writer_lock() clib_atomic_release (lb_main.writer_lock)
32 
33 static void lb_as_stack (lb_as_t *as);
34 
35 
36 const static char * const lb_dpo_gre4_ip4[] = { "lb4-gre4" , NULL };
37 const static char * const lb_dpo_gre4_ip6[] = { "lb6-gre4" , NULL };
38 const static char* const * const lb_dpo_gre4_nodes[DPO_PROTO_NUM] =
39  {
42  };
43 
44 const static char * const lb_dpo_gre6_ip4[] = { "lb4-gre6" , NULL };
45 const static char * const lb_dpo_gre6_ip6[] = { "lb6-gre6" , NULL };
46 const static char* const * const lb_dpo_gre6_nodes[DPO_PROTO_NUM] =
47  {
50  };
51 
52 const static char * const lb_dpo_gre4_ip4_port[] = { "lb4-gre4-port" , NULL };
53 const static char * const lb_dpo_gre4_ip6_port[] = { "lb6-gre4-port" , NULL };
54 const static char* const * const lb_dpo_gre4_port_nodes[DPO_PROTO_NUM] =
55  {
58  };
59 
60 const static char * const lb_dpo_gre6_ip4_port[] = { "lb4-gre6-port" , NULL };
61 const static char * const lb_dpo_gre6_ip6_port[] = { "lb6-gre6-port" , NULL };
62 const static char* const * const lb_dpo_gre6_port_nodes[DPO_PROTO_NUM] =
63  {
66  };
67 
68 const static char * const lb_dpo_l3dsr_ip4[] = {"lb4-l3dsr" , NULL};
69 const static char* const * const lb_dpo_l3dsr_nodes[DPO_PROTO_NUM] =
70  {
72  };
73 
74 const static char * const lb_dpo_l3dsr_ip4_port[] = {"lb4-l3dsr-port" , NULL};
75 const static char* const * const lb_dpo_l3dsr_port_nodes[DPO_PROTO_NUM] =
76  {
78  };
79 
80 const static char * const lb_dpo_nat4_ip4_port[] = { "lb4-nat4-port" , NULL };
81 const static char* const * const lb_dpo_nat4_port_nodes[DPO_PROTO_NUM] =
82  {
84  };
85 
86 const static char * const lb_dpo_nat6_ip6_port[] = { "lb6-nat6-port" , NULL };
87 const static char* const * const lb_dpo_nat6_port_nodes[DPO_PROTO_NUM] =
88  {
90  };
91 
93 {
94  return (u32) (vlib_time_now(vm) + 10000);
95 }
96 
97 u8 *format_lb_main (u8 * s, va_list * args)
98 {
100  lb_main_t *lbm = &lb_main;
101  s = format(s, "lb_main");
102  s = format(s, " ip4-src-address: %U \n", format_ip4_address, &lbm->ip4_src_address);
103  s = format(s, " ip6-src-address: %U \n", format_ip6_address, &lbm->ip6_src_address);
104  s = format(s, " #vips: %u\n", pool_elts(lbm->vips));
105  s = format(s, " #ass: %u\n", pool_elts(lbm->ass) - 1);
106 
107  u32 thread_index;
108  for(thread_index = 0; thread_index < tm->n_vlib_mains; thread_index++ ) {
109  lb_hash_t *h = lbm->per_cpu[thread_index].sticky_ht;
110  if (h) {
111  s = format(s, "core %d\n", thread_index);
112  s = format(s, " timeout: %ds\n", h->timeout);
113  s = format(s, " usage: %d / %d\n", lb_hash_elts(h, lb_hash_time_now(vlib_get_main())), lb_hash_size(h));
114  }
115  }
116 
117  return s;
118 }
119 
120 static char *lb_vip_type_strings[] = {
121  [LB_VIP_TYPE_IP6_GRE6] = "ip6-gre6",
122  [LB_VIP_TYPE_IP6_GRE4] = "ip6-gre4",
123  [LB_VIP_TYPE_IP4_GRE6] = "ip4-gre6",
124  [LB_VIP_TYPE_IP4_GRE4] = "ip4-gre4",
125  [LB_VIP_TYPE_IP4_L3DSR] = "ip4-l3dsr",
126  [LB_VIP_TYPE_IP4_NAT4] = "ip4-nat4",
127  [LB_VIP_TYPE_IP6_NAT6] = "ip6-nat6",
128 };
129 
130 u8 *format_lb_vip_type (u8 * s, va_list * args)
131 {
132  lb_vip_type_t vipt = va_arg (*args, lb_vip_type_t);
133  u32 i;
134  for (i=0; i<LB_VIP_N_TYPES; i++)
135  if (vipt == i)
136  return format(s, lb_vip_type_strings[i]);
137  return format(s, "_WRONG_TYPE_");
138 }
139 
140 uword unformat_lb_vip_type (unformat_input_t * input, va_list * args)
141 {
142  lb_vip_type_t *vipt = va_arg (*args, lb_vip_type_t *);
143  u32 i;
144  for (i=0; i<LB_VIP_N_TYPES; i++)
145  if (unformat(input, lb_vip_type_strings[i])) {
146  *vipt = i;
147  return 1;
148  }
149  return 0;
150 }
151 
152 u8 *format_lb_vip (u8 * s, va_list * args)
153 {
154  lb_vip_t *vip = va_arg (*args, lb_vip_t *);
155  s = format(s, "%U %U new_size:%u #as:%u%s",
156  format_lb_vip_type, vip->type,
158  vip->new_flow_table_mask + 1,
159  pool_elts(vip->as_indexes),
160  (vip->flags & LB_VIP_FLAGS_USED)?"":" removed");
161 
162  if (vip->port != 0)
163  {
164  s = format(s, " protocol:%u port:%u ", vip->protocol, vip->port);
165  }
166 
167  if (vip->type == LB_VIP_TYPE_IP4_L3DSR)
168  {
169  s = format(s, " dscp:%u", vip->encap_args.dscp);
170  }
171  else if ((vip->type == LB_VIP_TYPE_IP4_NAT4)
172  || (vip->type == LB_VIP_TYPE_IP6_NAT6))
173  {
174  s = format (s, " type:%s port:%u target_port:%u",
175  (vip->encap_args.srv_type == LB_SRV_TYPE_CLUSTERIP)?"clusterip":
176  "nodeport",
177  ntohs(vip->port), ntohs(vip->encap_args.target_port));
178  }
179 
180  return s;
181 }
182 
183 u8 *format_lb_as (u8 * s, va_list * args)
184 {
185  lb_as_t *as = va_arg (*args, lb_as_t *);
186  return format(s, "%U %s", format_ip46_address,
187  &as->address, IP46_TYPE_ANY,
188  (as->flags & LB_AS_FLAGS_USED)?"used":"removed");
189 }
190 
191 u8 *format_lb_vip_detailed (u8 * s, va_list * args)
192 {
193  lb_main_t *lbm = &lb_main;
194  lb_vip_t *vip = va_arg (*args, lb_vip_t *);
195  u32 indent = format_get_indent (s);
196 
197  s = format(s, "%U %U [%lu] %U%s\n"
198  "%U new_size:%u\n",
199  format_white_space, indent,
200  format_lb_vip_type, vip->type,
201  vip - lbm->vips,
203  (vip->flags & LB_VIP_FLAGS_USED)?"":" removed",
204  format_white_space, indent,
205  vip->new_flow_table_mask + 1);
206 
207  if (vip->port != 0)
208  {
209  s = format(s, "%U protocol:%u port:%u\n",
210  format_white_space, indent,
211  vip->protocol, vip->port);
212  }
213 
214  if (vip->type == LB_VIP_TYPE_IP4_L3DSR)
215  {
216  s = format(s, "%U dscp:%u\n",
217  format_white_space, indent,
218  vip->encap_args.dscp);
219  }
220  else if ((vip->type == LB_VIP_TYPE_IP4_NAT4)
221  || (vip->type == LB_VIP_TYPE_IP6_NAT6))
222  {
223  s = format (s, "%U type:%s port:%u target_port:%u",
224  format_white_space, indent,
225  (vip->encap_args.srv_type == LB_SRV_TYPE_CLUSTERIP)?"clusterip":
226  "nodeport",
227  ntohs(vip->port), ntohs(vip->encap_args.target_port));
228  }
229 
230  //Print counters
231  s = format(s, "%U counters:\n",
232  format_white_space, indent);
233  u32 i;
234  for (i=0; i<LB_N_VIP_COUNTERS; i++)
235  s = format(s, "%U %s: %Lu\n",
236  format_white_space, indent,
237  lbm->vip_counters[i].name,
238  vlib_get_simple_counter(&lbm->vip_counters[i], vip - lbm->vips));
239 
240 
241  s = format(s, "%U #as:%u\n",
242  format_white_space, indent,
243  pool_elts(vip->as_indexes));
244 
245  //Let's count the buckets for each AS
246  u32 *count = 0;
247  vec_validate(count, pool_len(lbm->ass)); //Possibly big alloc for not much...
248  lb_new_flow_entry_t *nfe;
249  vec_foreach(nfe, vip->new_flow_table)
250  count[nfe->as_index]++;
251 
252  lb_as_t *as;
253  u32 *as_index;
254  pool_foreach(as_index, vip->as_indexes, {
255  as = &lbm->ass[*as_index];
256  s = format(s, "%U %U %u buckets %Lu flows dpo:%u %s\n",
257  format_white_space, indent,
258  format_ip46_address, &as->address, IP46_TYPE_ANY,
259  count[as - lbm->ass],
260  vlib_refcount_get(&lbm->as_refcount, as - lbm->ass),
261  as->dpo.dpoi_index,
262  (as->flags & LB_AS_FLAGS_USED)?"used":" removed");
263  });
264 
265  vec_free(count);
266  return s;
267 }
268 
269 typedef struct {
274 
275 static int lb_pseudorand_compare(void *a, void *b)
276 {
277  lb_as_t *asa, *asb;
278  lb_main_t *lbm = &lb_main;
279  asa = &lbm->ass[((lb_pseudorand_t *)a)->as_index];
280  asb = &lbm->ass[((lb_pseudorand_t *)b)->as_index];
281  return memcmp(&asa->address, &asb->address, sizeof(asb->address));
282 }
283 
285 {
286  lb_main_t *lbm = &lb_main;
287  lb_snat4_key_t m_key4;
288  clib_bihash_kv_8_8_t kv4, value4;
289  lb_snat6_key_t m_key6;
290  clib_bihash_kv_24_8_t kv6, value6;
291  lb_snat_mapping_t *m = 0;
292  ASSERT (lbm->writer_lock[0]);
293 
294  u32 now = (u32) vlib_time_now(vlib_get_main());
296  return;
297 
298  vip->last_garbage_collection = now;
299  lb_as_t *as;
300  u32 *as_index;
301  pool_foreach(as_index, vip->as_indexes, {
302  as = &lbm->ass[*as_index];
303  if (!(as->flags & LB_AS_FLAGS_USED) && //Not used
304  clib_u32_loop_gt(now, as->last_used + LB_CONCURRENCY_TIMEOUT) &&
305  (vlib_refcount_get(&lbm->as_refcount, as - lbm->ass) == 0))
306  { //Not referenced
307 
308  if (lb_vip_is_nat4_port(vip)) {
309  m_key4.addr = as->address.ip4;
310  m_key4.port = vip->encap_args.target_port;
311  m_key4.protocol = 0;
312  m_key4.fib_index = 0;
313 
314  kv4.key = m_key4.as_u64;
315  if(!clib_bihash_search_8_8(&lbm->mapping_by_as4, &kv4, &value4))
316  m = pool_elt_at_index (lbm->snat_mappings, value4.value);
317  ASSERT (m);
318 
319  kv4.value = m - lbm->snat_mappings;
320  clib_bihash_add_del_8_8(&lbm->mapping_by_as4, &kv4, 0);
321  pool_put (lbm->snat_mappings, m);
322  } else if (lb_vip_is_nat6_port(vip)) {
323  m_key6.addr.as_u64[0] = as->address.ip6.as_u64[0];
324  m_key6.addr.as_u64[1] = as->address.ip6.as_u64[1];
325  m_key6.port = vip->encap_args.target_port;
326  m_key6.protocol = 0;
327  m_key6.fib_index = 0;
328 
329  kv6.key[0] = m_key6.as_u64[0];
330  kv6.key[1] = m_key6.as_u64[1];
331  kv6.key[2] = m_key6.as_u64[2];
332 
333  if (!clib_bihash_search_24_8 (&lbm->mapping_by_as6, &kv6, &value6))
334  m = pool_elt_at_index (lbm->snat_mappings, value6.value);
335  ASSERT (m);
336 
337  kv6.value = m - lbm->snat_mappings;
338  clib_bihash_add_del_24_8(&lbm->mapping_by_as6, &kv6, 0);
339  pool_put (lbm->snat_mappings, m);
340  }
341  fib_entry_child_remove(as->next_hop_fib_entry_index,
342  as->next_hop_child_index);
343  fib_table_entry_delete_index(as->next_hop_fib_entry_index,
344  FIB_SOURCE_RR);
345  as->next_hop_fib_entry_index = FIB_NODE_INDEX_INVALID;
346 
347  pool_put(vip->as_indexes, as_index);
348  pool_put(lbm->ass, as);
349  }
350  });
351 }
352 
354 {
355  lb_main_t *lbm = &lb_main;
357  lb_vip_t *vip;
358  u32 *to_be_removed_vips = 0, *i;
359  pool_foreach(vip, lbm->vips, {
360  lb_vip_garbage_collection(vip);
361 
362  if (!(vip->flags & LB_VIP_FLAGS_USED) &&
363  (pool_elts(vip->as_indexes) == 0)) {
364  vec_add1(to_be_removed_vips, vip - lbm->vips);
365  }
366  });
367 
368  vec_foreach(i, to_be_removed_vips) {
369  vip = &lbm->vips[*i];
370  pool_put(lbm->vips, vip);
371  pool_free(vip->as_indexes);
372  }
373 
374  vec_free(to_be_removed_vips);
376 }
377 
379 {
380  lb_main_t *lbm = &lb_main;
381  lb_new_flow_entry_t *old_table;
382  u32 i, *as_index;
383  lb_new_flow_entry_t *new_flow_table = 0;
384  lb_as_t *as;
385  lb_pseudorand_t *pr, *sort_arr = 0;
386 
387  ASSERT (lbm->writer_lock[0]); //We must have the lock
388 
389  //Check if some AS is configured or not
390  i = 0;
391  pool_foreach(as_index, vip->as_indexes, {
392  as = &lbm->ass[*as_index];
393  if (as->flags & LB_AS_FLAGS_USED) { //Not used anymore
394  i = 1;
395  goto out; //Not sure 'break' works in this macro-loop
396  }
397  });
398 
399 out:
400  if (i == 0) {
401  //Only the default. i.e. no AS
402  vec_validate(new_flow_table, vip->new_flow_table_mask);
403  for (i=0; i<vec_len(new_flow_table); i++)
404  new_flow_table[i].as_index = 0;
405 
406  goto finished;
407  }
408 
409  //First, let's sort the ASs
410  vec_alloc(sort_arr, pool_elts(vip->as_indexes));
411 
412  i = 0;
413  pool_foreach(as_index, vip->as_indexes, {
414  as = &lbm->ass[*as_index];
415  if (!(as->flags & LB_AS_FLAGS_USED)) //Not used anymore
416  continue;
417 
418  sort_arr[i].as_index = as - lbm->ass;
419  i++;
420  });
421  _vec_len(sort_arr) = i;
422 
424 
425  //Now let's pseudo-randomly generate permutations
426  vec_foreach(pr, sort_arr) {
427  lb_as_t *as = &lbm->ass[pr->as_index];
428 
429  u64 seed = clib_xxhash(as->address.as_u64[0] ^
430  as->address.as_u64[1]);
431  /* We have 2^n buckets.
432  * skip must be prime with 2^n.
433  * So skip must be odd.
434  * MagLev actually state that M should be prime,
435  * but this has a big computation cost (% operation).
436  * Using 2^n is more better (& operation).
437  */
438  pr->skip = ((seed & 0xffffffff) | 1) & vip->new_flow_table_mask;
439  pr->last = (seed >> 32) & vip->new_flow_table_mask;
440  }
441 
442  //Let's create a new flow table
443  vec_validate(new_flow_table, vip->new_flow_table_mask);
444  for (i=0; i<vec_len(new_flow_table); i++)
445  new_flow_table[i].as_index = ~0;
446 
447  u32 done = 0;
448  while (1) {
449  vec_foreach(pr, sort_arr) {
450  while (1) {
451  u32 last = pr->last;
452  pr->last = (pr->last + pr->skip) & vip->new_flow_table_mask;
453  if (new_flow_table[last].as_index == ~0) {
454  new_flow_table[last].as_index = pr->as_index;
455  break;
456  }
457  }
458  done++;
459  if (done == vec_len(new_flow_table))
460  goto finished;
461  }
462  }
463 
464 finished:
465  vec_free(sort_arr);
466 
467  old_table = vip->new_flow_table;
468  vip->new_flow_table = new_flow_table;
469  vec_free(old_table);
470 }
471 
473  u32 per_cpu_sticky_buckets, u32 flow_timeout)
474 {
475  lb_main_t *lbm = &lb_main;
476 
477  if (!is_pow2(per_cpu_sticky_buckets))
478  return VNET_API_ERROR_INVALID_MEMORY_SIZE;
479 
480  lb_get_writer_lock(); //Not exactly necessary but just a reminder that it exists for my future self
483  lbm->per_cpu_sticky_buckets = per_cpu_sticky_buckets;
484  lbm->flow_timeout = flow_timeout;
486  return 0;
487 }
488 
489 
490 
491 static
492 int lb_vip_port_find_index(ip46_address_t *prefix, u8 plen,
493  u8 protocol, u16 port,
494  lb_lkp_type_t lkp_type,
495  u32 *vip_index)
496 {
497  lb_main_t *lbm = &lb_main;
498  lb_vip_t *vip;
499  ASSERT (lbm->writer_lock[0]); //This must be called with the lock owned
500  ip46_prefix_normalize(prefix, plen);
501  pool_foreach(vip, lbm->vips, {
502  if ((vip->flags & LB_AS_FLAGS_USED) &&
503  vip->plen == plen &&
504  vip->prefix.as_u64[0] == prefix->as_u64[0] &&
505  vip->prefix.as_u64[1] == prefix->as_u64[1])
506  {
507  if((lkp_type == LB_LKP_SAME_IP_PORT &&
508  vip->protocol == protocol &&
509  vip->port == port) ||
510  (lkp_type == LB_LKP_ALL_PORT_IP &&
511  vip->port == 0) ||
512  (lkp_type == LB_LKP_DIFF_IP_PORT &&
513  (vip->protocol != protocol ||
514  vip->port != port) ) )
515  {
516  *vip_index = vip - lbm->vips;
517  return 0;
518  }
519  }
520  });
521  return VNET_API_ERROR_NO_SUCH_ENTRY;
522 }
523 
524 static
525 int lb_vip_port_find_index_with_lock(ip46_address_t *prefix, u8 plen,
526  u8 protocol, u16 port, u32 *vip_index)
527 {
528  return lb_vip_port_find_index(prefix, plen, protocol, port,
529  LB_LKP_SAME_IP_PORT, vip_index);
530 }
531 
532 static
533 int lb_vip_port_find_all_port_vip(ip46_address_t *prefix, u8 plen,
534  u32 *vip_index)
535 {
536  return lb_vip_port_find_index(prefix, plen, ~0, 0,
537  LB_LKP_ALL_PORT_IP, vip_index);
538 }
539 
540 /* Find out per-port-vip entry with different protocol and port */
541 static
542 int lb_vip_port_find_diff_port(ip46_address_t *prefix, u8 plen,
543  u8 protocol, u16 port, u32 *vip_index)
544 {
545  return lb_vip_port_find_index(prefix, plen, protocol, port,
546  LB_LKP_DIFF_IP_PORT, vip_index);
547 }
548 
549 int lb_vip_find_index(ip46_address_t *prefix, u8 plen, u8 protocol,
550  u16 port, u32 *vip_index)
551 {
552  int ret;
554  ret = lb_vip_port_find_index_with_lock(prefix, plen,
555  protocol, port, vip_index);
557  return ret;
558 }
559 
560 static int lb_as_find_index_vip(lb_vip_t *vip, ip46_address_t *address, u32 *as_index)
561 {
562  lb_main_t *lbm = &lb_main;
563  ASSERT (lbm->writer_lock[0]); //This must be called with the lock owned
564  lb_as_t *as;
565  u32 *asi;
566  pool_foreach(asi, vip->as_indexes, {
567  as = &lbm->ass[*asi];
568  if (as->vip_index == (vip - lbm->vips) &&
569  as->address.as_u64[0] == address->as_u64[0] &&
570  as->address.as_u64[1] == address->as_u64[1])
571  {
572  *as_index = as - lbm->ass;
573  return 0;
574  }
575  });
576  return -1;
577 }
578 
579 int lb_vip_add_ass(u32 vip_index, ip46_address_t *addresses, u32 n)
580 {
581  lb_main_t *lbm = &lb_main;
583  lb_vip_t *vip;
584  if (!(vip = lb_vip_get_by_index(vip_index))) {
586  return VNET_API_ERROR_NO_SUCH_ENTRY;
587  }
588 
590  u32 *to_be_added = 0;
591  u32 *to_be_updated = 0;
592  u32 i;
593  u32 *ip;
595 
596  //Sanity check
597  while (n--) {
598 
599  if (!lb_as_find_index_vip(vip, &addresses[n], &i)) {
600  if (lbm->ass[i].flags & LB_AS_FLAGS_USED) {
601  vec_free(to_be_added);
602  vec_free(to_be_updated);
604  return VNET_API_ERROR_VALUE_EXIST;
605  }
606  vec_add1(to_be_updated, i);
607  goto next;
608  }
609 
610  if (ip46_address_type(&addresses[n]) != type) {
611  vec_free(to_be_added);
612  vec_free(to_be_updated);
614  return VNET_API_ERROR_INVALID_ADDRESS_FAMILY;
615  }
616 
617  if (n) {
618  u32 n2 = n;
619  while(n2--) //Check for duplicates
620  if (addresses[n2].as_u64[0] == addresses[n].as_u64[0] &&
621  addresses[n2].as_u64[1] == addresses[n].as_u64[1])
622  goto next;
623  }
624 
625  vec_add1(to_be_added, n);
626 
627 next:
628  continue;
629  }
630 
631  //Update reused ASs
632  vec_foreach(ip, to_be_updated) {
633  lbm->ass[*ip].flags = LB_AS_FLAGS_USED;
634  }
635  vec_free(to_be_updated);
636 
637  //Create those who have to be created
638  vec_foreach(ip, to_be_added) {
639  lb_as_t *as;
640  u32 *as_index;
641  pool_get(lbm->ass, as);
642  as->address = addresses[*ip];
643  as->flags = LB_AS_FLAGS_USED;
644  as->vip_index = vip_index;
645  pool_get(vip->as_indexes, as_index);
646  *as_index = as - lbm->ass;
647 
648  /*
649  * become a child of the FIB entry
650  * so we are informed when its forwarding changes
651  */
652  fib_prefix_t nh = {};
653  if (lb_encap_is_ip4(vip)) {
654  nh.fp_addr.ip4 = as->address.ip4;
655  nh.fp_len = 32;
657  } else {
658  nh.fp_addr.ip6 = as->address.ip6;
659  nh.fp_len = 128;
661  }
662 
665  &nh,
670  lbm->fib_node_type,
671  as - lbm->ass);
672 
673  lb_as_stack(as);
674 
675  if ( lb_vip_is_nat4_port(vip) || lb_vip_is_nat6_port(vip) )
676  {
677  /* Add SNAT static mapping */
678  pool_get (lbm->snat_mappings, m);
679  clib_memset (m, 0, sizeof (*m));
680  if (lb_vip_is_nat4_port(vip)) {
681  lb_snat4_key_t m_key4;
683  m_key4.addr = as->address.ip4;
684  m_key4.port = vip->encap_args.target_port;
685  m_key4.protocol = 0;
686  m_key4.fib_index = 0;
687 
689  {
690  m->src_ip.ip4 = vip->prefix.ip4;
691  }
692  else if (vip->encap_args.srv_type == LB_SRV_TYPE_NODEPORT)
693  {
694  m->src_ip.ip4 = lbm->ip4_src_address;
695  }
696  m->src_ip_is_ipv6 = 0;
697  m->as_ip.ip4 = as->address.ip4;
698  m->as_ip_is_ipv6 = 0;
699  m->src_port = vip->port;
701  m->vrf_id = 0;
702  m->fib_index = 0;
703 
704  kv4.key = m_key4.as_u64;
705  kv4.value = m - lbm->snat_mappings;
706  clib_bihash_add_del_8_8(&lbm->mapping_by_as4, &kv4, 1);
707  } else {
708  lb_snat6_key_t m_key6;
710  m_key6.addr.as_u64[0] = as->address.ip6.as_u64[0];
711  m_key6.addr.as_u64[1] = as->address.ip6.as_u64[1];
712  m_key6.port = vip->encap_args.target_port;
713  m_key6.protocol = 0;
714  m_key6.fib_index = 0;
715 
717  {
718  m->src_ip.ip6.as_u64[0] = vip->prefix.ip6.as_u64[0];
719  m->src_ip.ip6.as_u64[1] = vip->prefix.ip6.as_u64[1];
720  }
721  else if (vip->encap_args.srv_type == LB_SRV_TYPE_NODEPORT)
722  {
723  m->src_ip.ip6.as_u64[0] = lbm->ip6_src_address.as_u64[0];
724  m->src_ip.ip6.as_u64[1] = lbm->ip6_src_address.as_u64[1];
725  }
726  m->src_ip_is_ipv6 = 1;
727  m->as_ip.ip6.as_u64[0] = as->address.ip6.as_u64[0];
728  m->as_ip.ip6.as_u64[1] = as->address.ip6.as_u64[1];
729  m->as_ip_is_ipv6 = 1;
730  m->src_port = vip->port;
732  m->vrf_id = 0;
733  m->fib_index = 0;
734 
735  kv6.key[0] = m_key6.as_u64[0];
736  kv6.key[1] = m_key6.as_u64[1];
737  kv6.key[2] = m_key6.as_u64[2];
738  kv6.value = m - lbm->snat_mappings;
739  clib_bihash_add_del_24_8(&lbm->mapping_by_as6, &kv6, 1);
740  }
741  }
742  }
743  vec_free(to_be_added);
744 
745  //Recompute flows
747 
748  //Garbage collection maybe
750 
752  return 0;
753 }
754 
755 int
756 lb_flush_vip_as (u32 vip_index, u32 as_index)
757 {
758  u32 thread_index;
760  lb_main_t *lbm = &lb_main;
761 
762  for(thread_index = 0; thread_index < tm->n_vlib_mains; thread_index++ ) {
763  lb_hash_t *h = lbm->per_cpu[thread_index].sticky_ht;
764  if (h != NULL) {
765  u32 i;
766  lb_hash_bucket_t *b;
767 
768  lb_hash_foreach_entry(h, b, i) {
769  if ((vip_index == ~0)
770  || ((b->vip[i] == vip_index) && (as_index == ~0))
771  || ((b->vip[i] == vip_index) && (b->value[i] == as_index)))
772  {
773  vlib_refcount_add(&lbm->as_refcount, thread_index, b->value[i], -1);
774  vlib_refcount_add(&lbm->as_refcount, thread_index, 0, 1);
775  b->vip[i] = ~0;
776  b->value[i] = ~0;
777  }
778  }
779  if (vip_index == ~0)
780  {
781  lb_hash_free(h);
782  lbm->per_cpu[thread_index].sticky_ht = 0;
783  }
784  }
785  }
786 
787  return 0;
788 }
789 
790 int lb_vip_del_ass_withlock(u32 vip_index, ip46_address_t *addresses, u32 n,
791  u8 flush)
792 {
793  lb_main_t *lbm = &lb_main;
794  u32 now = (u32) vlib_time_now(vlib_get_main());
795  u32 *ip = 0;
796  u32 as_index = 0;
797 
798  lb_vip_t *vip;
799  if (!(vip = lb_vip_get_by_index(vip_index))) {
800  return VNET_API_ERROR_NO_SUCH_ENTRY;
801  }
802 
803  u32 *indexes = NULL;
804  while (n--) {
805  if (lb_as_find_index_vip(vip, &addresses[n], &as_index)) {
806  vec_free(indexes);
807  return VNET_API_ERROR_NO_SUCH_ENTRY;
808  }
809 
810  if (n) { //Check for duplicates
811  u32 n2 = n - 1;
812  while(n2--) {
813  if (addresses[n2].as_u64[0] == addresses[n].as_u64[0] &&
814  addresses[n2].as_u64[1] == addresses[n].as_u64[1])
815  goto next;
816  }
817  }
818 
819  vec_add1(indexes, as_index);
820 next:
821  continue;
822  }
823 
824  //Garbage collection maybe
826 
827  if (indexes != NULL) {
828  vec_foreach(ip, indexes) {
829  lbm->ass[*ip].flags &= ~LB_AS_FLAGS_USED;
830  lbm->ass[*ip].last_used = now;
831 
832  if(flush)
833  {
834  /* flush flow table for deleted ASs*/
835  lb_flush_vip_as(vip_index, *ip);
836  }
837  }
838 
839  //Recompute flows
841  }
842 
843  vec_free(indexes);
844  return 0;
845 }
846 
847 int lb_vip_del_ass(u32 vip_index, ip46_address_t *addresses, u32 n, u8 flush)
848 {
850  int ret = lb_vip_del_ass_withlock(vip_index, addresses, n, flush);
852 
853  return ret;
854 }
855 
856 static int
858 {
859  /*
860  * Check for dynamically allocaetd instance number.
861  */
862  u32 bit;
863 
865 
867 
868  return bit;
869 }
870 
871 static int
873 {
874 
875  if (clib_bitmap_get (lbm->vip_prefix_indexes, instance) == 0)
876  {
877  return -1;
878  }
879 
881  instance, 0);
882 
883  return 0;
884 }
885 
886 /**
887  * Add the VIP adjacency to the ip4 or ip6 fib
888  */
889 static void lb_vip_add_adjacency(lb_main_t *lbm, lb_vip_t *vip,
890  u32 *vip_prefix_index)
891 {
892  dpo_proto_t proto = 0;
893  dpo_type_t dpo_type = 0;
894  u32 vip_idx = 0;
895 
896  if (vip->port != 0)
897  {
898  /* for per-port vip, if VIP adjacency has been added,
899  * no need to add adjacency. */
900  if (!lb_vip_port_find_diff_port(&(vip->prefix), vip->plen,
901  vip->protocol, vip->port, &vip_idx))
902  {
903  return;
904  }
905 
906  /* Allocate an index for per-port vip */
907  *vip_prefix_index = lb_vip_prefix_index_alloc(lbm);
908  }
909  else
910  {
911  *vip_prefix_index = vip - lbm->vips;
912  }
913 
914  dpo_id_t dpo = DPO_INVALID;
915  fib_prefix_t pfx = {};
916  if (lb_vip_is_ip4(vip->type)) {
917  pfx.fp_addr.ip4 = vip->prefix.ip4;
918  pfx.fp_len = vip->plen - 96;
920  proto = DPO_PROTO_IP4;
921  } else {
922  pfx.fp_addr.ip6 = vip->prefix.ip6;
923  pfx.fp_len = vip->plen;
925  proto = DPO_PROTO_IP6;
926  }
927 
928  if (lb_vip_is_gre4(vip))
929  dpo_type = lbm->dpo_gre4_type;
930  else if (lb_vip_is_gre6(vip))
931  dpo_type = lbm->dpo_gre6_type;
932  else if (lb_vip_is_gre4_port(vip))
933  dpo_type = lbm->dpo_gre4_port_type;
934  else if (lb_vip_is_gre6_port(vip))
935  dpo_type = lbm->dpo_gre6_port_type;
936  else if (lb_vip_is_l3dsr(vip))
937  dpo_type = lbm->dpo_l3dsr_type;
938  else if (lb_vip_is_l3dsr_port(vip))
939  dpo_type = lbm->dpo_l3dsr_port_type;
940  else if(lb_vip_is_nat4_port(vip))
941  dpo_type = lbm->dpo_nat4_port_type;
942  else if (lb_vip_is_nat6_port(vip))
943  dpo_type = lbm->dpo_nat6_port_type;
944 
945  dpo_set(&dpo, dpo_type, proto, *vip_prefix_index);
947  &pfx,
950  &dpo);
951  dpo_reset(&dpo);
952 }
953 
954 /**
955  * Add the VIP filter entry
956  */
958  u32 vip_prefix_index, u32 vip_idx)
959 {
960  vip_port_key_t key;
962 
963  key.vip_prefix_index = vip_prefix_index;
964  key.protocol = vip->protocol;
965  key.port = clib_host_to_net_u16(vip->port);
966  key.rsv = 0;
967 
968  kv.key = key.as_u64;
969  kv.value = vip_idx;
970  clib_bihash_add_del_8_8(&lbm->vip_index_per_port, &kv, 1);
971 
972  return 0;
973 }
974 
975 /**
976  * Del the VIP filter entry
977  */
979 {
980  vip_port_key_t key;
981  clib_bihash_kv_8_8_t kv, value;
982  lb_vip_t *m = 0;
983 
985  key.protocol = vip->protocol;
986  key.port = clib_host_to_net_u16(vip->port);
987 
988  kv.key = key.as_u64;
989  if(clib_bihash_search_8_8(&lbm->vip_index_per_port, &kv, &value) == 0)
990  m = pool_elt_at_index (lbm->vips, value.value);
991  ASSERT (m);
992 
993  kv.value = m - lbm->vips;
994  clib_bihash_add_del_8_8(&lbm->vip_index_per_port, &kv, 0);
995 
996  return 0;
997 }
998 
999 /**
1000  * Deletes the adjacency associated with the VIP
1001  */
1002 static void lb_vip_del_adjacency(lb_main_t *lbm, lb_vip_t *vip)
1003 {
1004  fib_prefix_t pfx = {};
1005  u32 vip_idx = 0;
1006 
1007  if (vip->port != 0)
1008  {
1009  /* If this vip adjacency is used by other per-port vip,
1010  * no need to del this adjacency. */
1011  if (!lb_vip_port_find_diff_port(&(vip->prefix), vip->plen,
1012  vip->protocol, vip->port, &vip_idx))
1013  {
1015  return;
1016  }
1017 
1018  /* Return vip_prefix_index for per-port vip */
1020 
1021  }
1022 
1023  if (lb_vip_is_ip4(vip->type)) {
1024  pfx.fp_addr.ip4 = vip->prefix.ip4;
1025  pfx.fp_len = vip->plen - 96;
1026  pfx.fp_proto = FIB_PROTOCOL_IP4;
1027  } else {
1028  pfx.fp_addr.ip6 = vip->prefix.ip6;
1029  pfx.fp_len = vip->plen;
1030  pfx.fp_proto = FIB_PROTOCOL_IP6;
1031  }
1033 }
1034 
1035 int lb_vip_add(lb_vip_add_args_t args, u32 *vip_index)
1036 {
1037  lb_main_t *lbm = &lb_main;
1039  lb_vip_t *vip;
1040  lb_vip_type_t type = args.type;
1041  u32 vip_prefix_index = 0;
1042 
1044  ip46_prefix_normalize(&(args.prefix), args.plen);
1045 
1046  if (!lb_vip_port_find_index_with_lock(&(args.prefix), args.plen,
1047  args.protocol, args.port,
1048  vip_index))
1049  {
1051  return VNET_API_ERROR_VALUE_EXIST;
1052  }
1053 
1054  /* Make sure we can't add a per-port VIP entry
1055  * when there already is an all-port VIP for the same prefix. */
1056  if ((args.port != 0) &&
1057  !lb_vip_port_find_all_port_vip(&(args.prefix), args.plen, vip_index))
1058  {
1060  return VNET_API_ERROR_VALUE_EXIST;
1061  }
1062 
1063  /* Make sure we can't add a all-port VIP entry
1064  * when there already is an per-port VIP for the same prefix. */
1065  if ((args.port == 0) &&
1066  !lb_vip_port_find_diff_port(&(args.prefix), args.plen,
1067  args.protocol, args.port, vip_index))
1068  {
1070  return VNET_API_ERROR_VALUE_EXIST;
1071  }
1072 
1073  /* Make sure all VIP for a given prefix (using different ports) have the same type. */
1074  if ((args.port != 0) &&
1075  !lb_vip_port_find_diff_port(&(args.prefix), args.plen,
1076  args.protocol, args.port, vip_index)
1077  && (args.type != lbm->vips[*vip_index].type))
1078  {
1080  return VNET_API_ERROR_INVALID_ARGUMENT;
1081  }
1082 
1083  if (!is_pow2(args.new_length)) {
1085  return VNET_API_ERROR_INVALID_MEMORY_SIZE;
1086  }
1087 
1088  if (ip46_prefix_is_ip4(&(args.prefix), args.plen) &&
1089  !lb_vip_is_ip4(type)) {
1091  return VNET_API_ERROR_INVALID_ADDRESS_FAMILY;
1092  }
1093 
1094  if ((!ip46_prefix_is_ip4(&(args.prefix), args.plen)) &&
1095  !lb_vip_is_ip6(type)) {
1097  return VNET_API_ERROR_INVALID_ADDRESS_FAMILY;
1098  }
1099 
1100  if ((type == LB_VIP_TYPE_IP4_L3DSR) &&
1101  (args.encap_args.dscp >= 64) )
1102  {
1104  return VNET_API_ERROR_VALUE_EXIST;
1105  }
1106 
1107  //Allocate
1108  pool_get(lbm->vips, vip);
1109 
1110  //Init
1111  memcpy (&(vip->prefix), &(args.prefix), sizeof(args.prefix));
1112  vip->plen = args.plen;
1113  if (args.port != 0)
1114  {
1115  vip->protocol = args.protocol;
1116  vip->port = args.port;
1117  }
1118  else
1119  {
1120  vip->protocol = (u8)~0;
1121  vip->port = 0;
1122  }
1124  vip->type = args.type;
1125 
1126  if (args.type == LB_VIP_TYPE_IP4_L3DSR) {
1127  vip->encap_args.dscp = args.encap_args.dscp;
1128  }
1129  else if ((args.type == LB_VIP_TYPE_IP4_NAT4)
1130  ||(args.type == LB_VIP_TYPE_IP6_NAT6)) {
1131  vip->encap_args.srv_type = args.encap_args.srv_type;
1132  vip->encap_args.target_port =
1133  clib_host_to_net_u16(args.encap_args.target_port);
1134  }
1135 
1136  vip->flags = LB_VIP_FLAGS_USED;
1137  vip->as_indexes = 0;
1138 
1139  //Validate counters
1140  u32 i;
1141  for (i = 0; i < LB_N_VIP_COUNTERS; i++) {
1142  vlib_validate_simple_counter(&lbm->vip_counters[i], vip - lbm->vips);
1143  vlib_zero_simple_counter(&lbm->vip_counters[i], vip - lbm->vips);
1144  }
1145 
1146  //Configure new flow table
1147  vip->new_flow_table_mask = args.new_length - 1;
1148  vip->new_flow_table = 0;
1149 
1150  //Update flow hash table
1152 
1153  //Create adjacency to direct traffic
1154  lb_vip_add_adjacency(lbm, vip, &vip_prefix_index);
1155 
1156  if ( (lb_vip_is_nat4_port(vip) || lb_vip_is_nat6_port(vip))
1158  {
1159  u32 key;
1160  uword * entry;
1161 
1162  //Create maping from nodeport to vip_index
1163  key = clib_host_to_net_u16(args.port);
1164  entry = hash_get_mem (lbm->vip_index_by_nodeport, &key);
1165  if (entry) {
1167  return VNET_API_ERROR_VALUE_EXIST;
1168  }
1169 
1170  hash_set_mem (lbm->vip_index_by_nodeport, &key, vip - lbm->vips);
1171 
1172  /* receive packets destined to NodeIP:NodePort */
1173  udp_register_dst_port (vm, args.port, lb4_nodeport_node.index, 1);
1174  udp_register_dst_port (vm, args.port, lb6_nodeport_node.index, 0);
1175  }
1176 
1177  *vip_index = vip - lbm->vips;
1178  //Create per-port vip filtering table
1179  if (args.port != 0)
1180  {
1181  lb_vip_add_port_filter(lbm, vip, vip_prefix_index, *vip_index);
1182  vip->vip_prefix_index = vip_prefix_index;
1183  }
1184 
1186  return 0;
1187 }
1188 
1189 int lb_vip_del(u32 vip_index)
1190 {
1191  lb_main_t *lbm = &lb_main;
1192  lb_vip_t *vip;
1193 
1194  /* Does not remove default vip, i.e. vip_index = 0 */
1195  if (vip_index == 0)
1196  return 0;
1197 
1199  if (!(vip = lb_vip_get_by_index(vip_index))) {
1201  return VNET_API_ERROR_NO_SUCH_ENTRY;
1202  }
1203 
1204  //FIXME: This operation is actually not working
1205  //We will need to remove state before performing this.
1206 
1207  {
1208  //Remove all ASs
1209  ip46_address_t *ass = 0;
1210  lb_as_t *as;
1211  u32 *as_index;
1212 
1213  pool_foreach(as_index, vip->as_indexes, {
1214  as = &lbm->ass[*as_index];
1215  vec_add1(ass, as->address);
1216  });
1217  if (vec_len(ass))
1218  lb_vip_del_ass_withlock(vip_index, ass, vec_len(ass), 0);
1219  vec_free(ass);
1220  }
1221 
1222  //Delete adjacency
1223  lb_vip_del_adjacency(lbm, vip);
1224 
1225  //Delete per-port vip filtering entry
1226  if (vip->port != 0)
1227  {
1228  lb_vip_del_port_filter(lbm, vip);
1229  }
1230 
1231  //Set the VIP as unused
1232  vip->flags &= ~LB_VIP_FLAGS_USED;
1233 
1235  return 0;
1236 }
1237 
1238 /* *INDENT-OFF* */
1239 VLIB_PLUGIN_REGISTER () = {
1240  .version = VPP_BUILD_VER,
1241  .description = "Load Balancer (LB)",
1242 };
1243 /* *INDENT-ON* */
1244 
1245 u8 *format_lb_dpo (u8 * s, va_list * va)
1246 {
1247  index_t index = va_arg (*va, index_t);
1248  CLIB_UNUSED(u32 indent) = va_arg (*va, u32);
1249  lb_main_t *lbm = &lb_main;
1250  lb_vip_t *vip = pool_elt_at_index (lbm->vips, index);
1251  return format (s, "%U", format_lb_vip, vip);
1252 }
1253 
1254 static void lb_dpo_lock (dpo_id_t *dpo) {}
1255 static void lb_dpo_unlock (dpo_id_t *dpo) {}
1256 
1257 static fib_node_t *
1259 {
1260  lb_main_t *lbm = &lb_main;
1261  lb_as_t *as = pool_elt_at_index (lbm->ass, index);
1262  return (&as->fib_node);
1263 }
1264 
1265 static void
1267 {
1268 }
1269 
1270 static lb_as_t *
1272 {
1273  return ((lb_as_t*)(((char*)node) -
1274  STRUCT_OFFSET_OF(lb_as_t, fib_node)));
1275 }
1276 
1277 static void
1279 {
1280  lb_main_t *lbm = &lb_main;
1281  lb_vip_t *vip = &lbm->vips[as->vip_index];
1282  dpo_type_t dpo_type = 0;
1283 
1284  if (lb_vip_is_gre4(vip))
1285  dpo_type = lbm->dpo_gre4_type;
1286  else if (lb_vip_is_gre6(vip))
1287  dpo_type = lbm->dpo_gre6_type;
1288  else if (lb_vip_is_gre4_port(vip))
1289  dpo_type = lbm->dpo_gre4_port_type;
1290  else if (lb_vip_is_gre6_port(vip))
1291  dpo_type = lbm->dpo_gre6_port_type;
1292  else if (lb_vip_is_l3dsr(vip))
1293  dpo_type = lbm->dpo_l3dsr_type;
1294  else if (lb_vip_is_l3dsr_port(vip))
1295  dpo_type = lbm->dpo_l3dsr_port_type;
1296  else if(lb_vip_is_nat4_port(vip))
1297  dpo_type = lbm->dpo_nat4_port_type;
1298  else if (lb_vip_is_nat6_port(vip))
1299  dpo_type = lbm->dpo_nat6_port_type;
1300 
1301  dpo_stack(dpo_type,
1303  &as->dpo,
1306 }
1307 
1311 {
1313  return (FIB_NODE_BACK_WALK_CONTINUE);
1314 }
1315 
1317 {
1318  if (is_del)
1319  {
1320  vnet_feature_enable_disable ("ip4-unicast", "lb-nat4-in2out",
1321  sw_if_index, 0, 0, 0);
1322  }
1323  else
1324  {
1325  vnet_feature_enable_disable ("ip4-unicast", "lb-nat4-in2out",
1326  sw_if_index, 1, 0, 0);
1327  }
1328 
1329  return 0;
1330 }
1331 
1333 {
1334  if (is_del)
1335  {
1336  vnet_feature_enable_disable ("ip6-unicast", "lb-nat6-in2out",
1337  sw_if_index, 0, 0, 0);
1338  }
1339  else
1340  {
1341  vnet_feature_enable_disable ("ip6-unicast", "lb-nat6-in2out",
1342  sw_if_index, 1, 0, 0);
1343  }
1344 
1345  return 0;
1346 }
1347 
1348 clib_error_t *
1350 {
1352  lb_main_t *lbm = &lb_main;
1353  lbm->vnet_main = vnet_get_main ();
1354  lbm->vlib_main = vm;
1355 
1356  lb_vip_t *default_vip;
1357  lb_as_t *default_as;
1358  fib_node_vft_t lb_fib_node_vft = {
1360  .fnv_last_lock = lb_fib_node_last_lock_gone,
1361  .fnv_back_walk = lb_fib_node_back_walk_notify,
1362  };
1363  dpo_vft_t lb_vft = {
1364  .dv_lock = lb_dpo_lock,
1365  .dv_unlock = lb_dpo_unlock,
1366  .dv_format = format_lb_dpo,
1367  };
1368 
1369  //Allocate and init default VIP.
1370  lbm->vips = 0;
1371  pool_get(lbm->vips, default_vip);
1372  default_vip->prefix.ip6.as_u64[0] = 0xffffffffffffffffL;
1373  default_vip->prefix.ip6.as_u64[1] = 0xffffffffffffffffL;
1374  default_vip->protocol = ~0;
1375  default_vip->port = 0;
1376  default_vip->flags = LB_VIP_FLAGS_USED;
1377 
1378  lbm->per_cpu = 0;
1379  vec_validate(lbm->per_cpu, tm->n_vlib_mains - 1);
1381  lbm->writer_lock[0] = 0;
1384  lbm->ip4_src_address.as_u32 = 0xffffffff;
1385  lbm->ip6_src_address.as_u64[0] = 0xffffffffffffffffL;
1386  lbm->ip6_src_address.as_u64[1] = 0xffffffffffffffffL;
1393  lbm->dpo_l3dsr_type = dpo_register_new_type(&lb_vft,
1401  lbm->fib_node_type = fib_node_register_new_type(&lb_fib_node_vft);
1402 
1403  //Init AS reference counters
1405 
1406  //Allocate and init default AS.
1407  lbm->ass = 0;
1408  pool_get(lbm->ass, default_as);
1409  default_as->flags = 0;
1410  default_as->dpo.dpoi_next_node = LB_NEXT_DROP;
1411  default_as->vip_index = ~0;
1412  default_as->address.ip6.as_u64[0] = 0xffffffffffffffffL;
1413  default_as->address.ip6.as_u64[1] = 0xffffffffffffffffL;
1414 
1416  = hash_create_mem (0, sizeof(u16), sizeof (uword));
1417 
1418  clib_bihash_init_8_8 (&lbm->vip_index_per_port,
1419  "vip_index_per_port", LB_VIP_PER_PORT_BUCKETS,
1421 
1422  clib_bihash_init_8_8 (&lbm->mapping_by_as4,
1423  "mapping_by_as4", LB_MAPPING_BUCKETS,
1425 
1426  clib_bihash_init_24_8 (&lbm->mapping_by_as6,
1427  "mapping_by_as6", LB_MAPPING_BUCKETS,
1429 
1430 #define _(a,b,c) lbm->vip_counters[c].name = b;
1432 #undef _
1433  return NULL;
1434 }
1435 
u32 skip
Definition: lb.c:272
int lb_vip_del_ass(u32 vip_index, ip46_address_t *addresses, u32 n, u8 flush)
Definition: lb.c:847
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:439
fib_protocol_t fp_proto
protocol type
Definition: fib_types.h:212
dpo_lock_fn_t dv_lock
A reference counting lock function.
Definition: dpo.h:404
static void lb_vip_add_adjacency(lb_main_t *lbm, lb_vip_t *vip, u32 *vip_prefix_index)
Add the VIP adjacency to the ip4 or ip6 fib.
Definition: lb.c:889
u64 as_u64
Definition: lb.h:422
u32 lb_hash_time_now(vlib_main_t *vm)
Definition: lb.c:92
static int lb_vip_port_find_all_port_vip(ip46_address_t *prefix, u8 plen, u32 *vip_index)
Definition: lb.c:533
typedef address
Definition: ip_types.api:30
u64 as_u64[3]
Definition: lb.h:437
int lb_nat4_interface_add_del(u32 sw_if_index, int is_del)
Definition: lb.c:1316
Recursive resolution source.
Definition: fib_entry.h:125
static int lb_pseudorand_compare(void *a, void *b)
Definition: lb.c:275
vnet_main_t * vnet_main
Definition: lb.h:568
Each VIP is configured with a set of application server.
Definition: lb.h:107
#define LB_GARBAGE_RUN
Definition: lb.c:23
#define CLIB_UNUSED(x)
Definition: clib.h:82
A virtual function table regisitered for a DPO type.
Definition: dpo.h:399
#define lb_vip_is_gre6(vip)
Definition: lb.h:353
a
Definition: bitmap.h:538
static bool lb_vip_is_l3dsr(const lb_vip_t *vip)
Definition: lb.h:366
#define lb_vip_is_gre6_port(vip)
Definition: lb.h:361
u32 last
Definition: lb.c:271
vnet_main_t * vnet_get_main(void)
Definition: misc.c:47
u32 fib_index
Definition: lb.h:435
u32 per_cpu_sticky_buckets
Number of buckets in the per-cpu sticky hash table.
Definition: lb.h:521
clib_error_t * lb_init(vlib_main_t *vm)
Definition: lb.c:1349
u64 as_u64
Definition: bihash_doc.h:63
u32 fib_entry_child_add(fib_node_index_t fib_entry_index, fib_node_type_t child_type, fib_node_index_t child_index)
Definition: fib_entry.c:555
static void lb_fib_node_last_lock_gone(fib_node_t *node)
Definition: lb.c:1266
u64 as_u64[2]
Definition: ip6_packet.h:51
static void lb_vip_update_new_flow_table(lb_vip_t *vip)
Definition: lb.c:378
unsigned long u64
Definition: types.h:89
static int lb_as_find_index_vip(lb_vip_t *vip, ip46_address_t *address, u32 *as_index)
Definition: lb.c:560
#define LB_VIP_PER_PORT_MEMORY_SIZE
Definition: lb.h:51
static const char *const lb_dpo_gre4_ip6_port[]
Definition: lb.c:53
#define NULL
Definition: clib.h:58
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:232
enum fib_node_back_walk_rc_t_ fib_node_back_walk_rc_t
Return code from a back walk function.
const dpo_id_t * fib_entry_contribute_ip_forwarding(fib_node_index_t fib_entry_index)
Definition: fib_entry.c:506
static int lb_vip_prefix_index_alloc(lb_main_t *lbm)
Definition: lb.c:857
static void lb_vip_del_adjacency(lb_main_t *lbm, lb_vip_t *vip)
Deletes the adjacency associated with the VIP.
Definition: lb.c:1002
int lb_conf(ip4_address_t *ip4_address, ip6_address_t *ip6_address, u32 per_cpu_sticky_buckets, u32 flow_timeout)
Fix global load-balancer parameters.
Definition: lb.c:472
#define lb_get_writer_lock()
Definition: lb.c:30
u8 * format_ip46_prefix(u8 *s, va_list *args)
Definition: util.c:54
int lb_vip_add_ass(u32 vip_index, ip46_address_t *addresses, u32 n)
Definition: lb.c:579
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
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:525
ip46_address_t prefix
A Virtual IP represents a given service delivered by a set of application servers.
Definition: lb.h:291
#define clib_u32_loop_gt(a, b)
32 bits integer comparison for running values.
Definition: util.h:38
static u64 clib_xxhash(u64 key)
Definition: xxhash.h:58
static heap_elt_t * last(heap_header_t *h)
Definition: heap.c:53
u16 port
Definition: lb.h:418
static_always_inline void vlib_refcount_init(vlib_refcount_t *r)
Definition: refcount.h:80
int i
static void lb_dpo_lock(dpo_id_t *dpo)
Definition: lb.c:1254
static uword * clib_bitmap_set(uword *ai, uword i, uword value)
Sets the ith bit of a bitmap to new_value Removes trailing zeros from the bitmap. ...
Definition: bitmap.h:167
u32 vip_prefix_index
Definition: lb.h:244
format_function_t format_ip46_address
Definition: format.h:61
static u32 format_get_indent(u8 *s)
Definition: format.h:72
#define hash_set_mem(h, key, value)
Definition: hash.h:275
clib_memset(h->entries, 0, sizeof(h->entries[0])*entries)
#define STRUCT_OFFSET_OF(t, f)
Definition: clib.h:65
#define lb_vip_is_ip4(type)
Definition: lb.h:334
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
static void lb_as_stack(lb_as_t *as)
Definition: lb.c:1278
u32 vip[LBHASH_ENTRY_PER_BUCKET]
Definition: lbhash.h:54
#define lb_vip_get_by_index(index)
Definition: lb.h:606
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:236
u32 vip_index
ASs are indexed by address and VIP Index.
Definition: lb.h:126
#define vec_alloc(V, N)
Allocate space for N more elements (no header, unspecified alignment)
Definition: vec.h:280
static const char *const *const lb_dpo_gre6_nodes[DPO_PROTO_NUM]
Definition: lb.c:46
lb_hash_t * sticky_ht
Each CPU has its own sticky flow hash table.
Definition: lb.h:466
unsigned char u8
Definition: types.h:56
#define pool_len(p)
Number of elements in pool vector.
Definition: pool.h:140
fib_node_type_t fib_node_register_new_type(const fib_node_vft_t *vft)
Create a new FIB node type and Register the function table for it.
Definition: fib_node.c:80
static int lb_vip_del_port_filter(lb_main_t *lbm, lb_vip_t *vip)
Del the VIP filter entry.
Definition: lb.c:978
#define LB_MAPPING_BUCKETS
Definition: lb.h:47
#define LB_VIP_FLAGS_USED
Definition: lb.h:325
#define ip46_address_type(ip46)
Definition: util.h:26
ip46_address_t address
Destination address used to tunnel traffic towards that application server.
Definition: lb.h:119
u32 timeout
Definition: lbhash.h:60
static counter_t vlib_get_simple_counter(vlib_simple_counter_main_t *cm, u32 index)
Get the value of a simple counter Scrapes the entire set of per-thread counters.
Definition: counter.h:113
format_function_t format_ip4_address
Definition: format.h:75
#define LB_AS_FLAGS_USED
Definition: lb.h:134
enum dpo_type_t_ dpo_type_t
Common types of data-path objects New types can be dynamically added using dpo_register_new_type() ...
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:490
u8 as_ip_is_ipv6
Definition: lb.h:449
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:163
static lb_as_t * lb_as_from_fib_node(fib_node_t *node)
Definition: lb.c:1271
u32 sw_if_index
Definition: vxlan_gbp.api:37
void fib_table_entry_special_remove(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source)
Remove a &#39;special&#39; entry from the FIB.
Definition: fib_table.c:407
VLIB_PLUGIN_REGISTER()
u8 * format_white_space(u8 *s, va_list *va)
Definition: std-formats.c:113
lb_lkp_type_t
Lookup type.
Definition: lb.h:196
#define LB_DEFAULT_PER_CPU_STICKY_BUCKETS
lb-plugin implements a MagLev-like load balancer.
Definition: lb.h:45
#define LB_MAPPING_MEMORY_SIZE
Definition: lb.h:48
lb_main_t lb_main
Definition: lb.c:28
static const char *const lb_dpo_gre4_ip4[]
Definition: lb.c:36
u32 flow_timeout
Flow timeout in seconds.
Definition: lb.h:526
A high priority source a plugin can use.
Definition: fib_entry.h:62
u16 port
Definition: lb.h:303
Definition: lb.h:469
fib_node_type_t fib_node_type
Node type for registering to fib changes.
Definition: lb.h:547
dpo_type_t dpo_gre4_type
DPO used to send packet from IP4/6 lookup to LB node.
Definition: lb.h:536
Aggregrate type for a prefix.
Definition: fib_types.h:203
u16 protocol
Definition: lb.h:419
static const char *const *const lb_dpo_nat4_port_nodes[DPO_PROTO_NUM]
Definition: lb.c:81
u8 protocol
Definition: lb.h:300
vlib_refcount_t as_refcount
Each AS has an associated reference counter.
Definition: lb.h:493
lb_vip_encap_args_t encap_args
Definition: lb.h:315
static const char *const lb_dpo_gre6_ip4_port[]
Definition: lb.c:60
static void lb_vip_garbage_collection(lb_vip_t *vip)
Definition: lb.c:284
u8 * format_lb_main(u8 *s, va_list *args)
Definition: lb.c:97
uword * vip_prefix_indexes
bitmap for vip prefix to support per-port vip
Definition: lb.h:478
unsigned int u32
Definition: types.h:88
u8 * format_lb_vip(u8 *s, va_list *args)
Definition: lb.c:152
enum dpo_proto_t_ dpo_proto_t
Data path protocol.
u16 fp_len
The mask length.
Definition: fib_types.h:207
vlib_node_registration_t lb6_nodeport_node
(constructor) VLIB_REGISTER_NODE (lb6_nodeport_node)
Definition: node.c:1220
lb_vip_t * vips
Pool of all Virtual IPs.
Definition: lb.h:473
dpo_type_t dpo_register_new_type(const dpo_vft_t *vft, const char *const *const *nodes)
Create and register a new DPO type.
Definition: dpo.c:341
u32 last_used
Rotating timestamp of when LB_AS_FLAGS_USED flag was last set.
Definition: lb.h:145
ip4_address_t ip4_src_address
Source address used for IPv4 encapsulated traffic.
Definition: lb.h:516
static const char *const lb_dpo_l3dsr_ip4_port[]
Definition: lb.c:74
Definition: fib_entry.h:275
char * name
The counter collection&#39;s name.
Definition: counter.h:64
u8 plen
The VIP prefix length.
Definition: lb.h:297
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
static const char *const lb_dpo_nat6_ip6_port[]
Definition: lb.c:86
static const char *const lb_dpo_nat4_ip4_port[]
Definition: lb.c:80
#define hash_create_mem(elts, key_bytes, value_bytes)
Definition: hash.h:661
Definition: fib_entry.h:279
#define lb_vip_is_gre4(vip)
Definition: lb.h:348
static const char *const lb_dpo_gre6_ip4[]
Definition: lb.c:44
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:511
#define lb_vip_is_gre4_port(vip)
Definition: lb.h:357
static const char *const *const lb_dpo_gre4_port_nodes[DPO_PROTO_NUM]
Definition: lb.c:54
#define lb_encap_is_ip4(vip)
Definition: lb.h:343
u32 value[LBHASH_ENTRY_PER_BUCKET]
Definition: lbhash.h:55
ip46_address_t fp_addr
The address type is not deriveable from the fp_addr member.
Definition: fib_types.h:226
u64 key
the key
Definition: bihash_8_8.h:33
int lb_vip_del(u32 vip_index)
Definition: lb.c:1189
long ctx[MAX_CONNS]
Definition: main.c:144
u8 * format_lb_vip_type(u8 *s, va_list *args)
Definition: lb.c:130
struct _unformat_input_t unformat_input_t
unsigned short u16
Definition: types.h:57
u16 src_port
Network byte order for vip + port case, src_port = port; for node ip + node_port, src_port = node_por...
Definition: lb.h:455
static const char *const *const lb_dpo_l3dsr_port_nodes[DPO_PROTO_NUM]
Definition: lb.c:75
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:286
uword unformat_lb_vip_type(unformat_input_t *input, va_list *args)
Definition: lb.c:140
int lb_flush_vip_as(u32 vip_index, u32 as_index)
Definition: lb.c:756
#define LB_DEFAULT_FLOW_TIMEOUT
Definition: lb.h:46
static int lb_vip_port_find_index(ip46_address_t *prefix, u8 plen, u8 protocol, u16 port, lb_lkp_type_t lkp_type, u32 *vip_index)
Definition: lb.c:492
void ip46_prefix_normalize(ip46_address_t *prefix, u8 plen)
Definition: util.c:18
vlib_node_registration_t lb4_nodeport_node
(constructor) VLIB_REGISTER_NODE (lb4_nodeport_node)
Definition: node.c:1204
clib_bihash_8_8_t mapping_by_as4
Definition: lb.h:553
static const char *const *const lb_dpo_gre4_nodes[DPO_PROTO_NUM]
Definition: lb.c:38
An node in the FIB graph.
Definition: fib_node.h:291
Definition: lb.h:166
fib_node_t fib_node
Registration to FIB event.
Definition: lb.h:111
u16 port
Definition: lb.h:245
u8 src_ip_is_ipv6
Definition: lb.h:448
static_always_inline void vlib_refcount_add(vlib_refcount_t *r, u32 thread_index, u32 counter_index, i32 v)
Definition: refcount.h:68
#define lb_hash_foreach_entry(h, bucket, i)
Definition: lbhash.h:72
ip46_address_t src_ip
for vip + port case, src_ip = vip; for node ip + node_port, src_ip = node_ip
Definition: lb.h:446
static const char *const lb_dpo_gre6_ip6[]
Definition: lb.c:45
u32 new_length
Definition: lb.h:578
static const dpo_vft_t lb_vft
Definition: load_balance.c:874
#define ip46_prefix_is_ip4(ip46, len)
Definition: util.h:27
#define pool_free(p)
Free a pool.
Definition: pool.h:404
static bool lb_vip_is_nat4_port(const lb_vip_t *vip)
Definition: lb.h:377
fib_node_index_t fib_table_entry_special_add(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source, fib_entry_flag_t flags)
Add a &#39;special&#39; entry to the FIB.
Definition: fib_table.c:388
u64 value
the value
Definition: bihash_8_8.h:34
dpo_type_t dpo_l3dsr_port_type
Definition: lb.h:541
dpo_type_t dpo_nat4_port_type
Definition: lb.h:542
static const char *const lb_dpo_gre6_ip6_port[]
Definition: lb.c:61
format_function_t format_ip6_address
Definition: format.h:93
vlib_main_t * vm
Definition: buffer.c:301
static int lb_vip_prefix_index_free(lb_main_t *lbm, u32 instance)
Definition: lb.c:872
dpo_type_t dpo_gre4_port_type
Definition: lb.h:538
u32 vrf_id
Definition: lb.h:457
#define lb_vip_is_ip6(type)
Definition: lb.h:339
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:341
volatile u32 * writer_lock
Definition: lb.h:564
static bool lb_vip_is_nat6_port(const lb_vip_t *vip)
Definition: lb.h:382
#define lb_foreach_vip_counter
Definition: lb.h:170
vlib_main_t * vlib_main
Definition: lb.h:567
fib_node_get_t fnv_get
Definition: fib_node.h:279
u8 ip6_address[16]
Definition: ip_types.api:18
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:30
u32 as_index
Definition: lb.h:167
8 octet key, 8 octet key value pair
Definition: bihash_8_8.h:31
static fib_node_back_walk_rc_t lb_fib_node_back_walk_notify(fib_node_t *node, fib_node_back_walk_ctx_t *ctx)
Definition: lb.c:1309
static uword clib_bitmap_get(uword *ai, uword i)
Gets the ith bit value from a bitmap.
Definition: bitmap.h:197
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
dpo_type_t dpo_gre6_type
Definition: lb.h:537
u32 last_garbage_collection
Last time garbage collection was run to free the ASs.
Definition: lb.h:280
static_always_inline void lb_hash_free(lb_hash_t *h)
Definition: lbhash.h:99
lb_as_t * ass
Pool of ASs.
Definition: lb.h:486
uword * vip_index_by_nodeport
Definition: lb.h:496
ip6_address_t addr
Definition: lb.h:432
lb_vip_type_t type
The type of traffic for this.
Definition: lb.h:312
Context passed between object during a back walk.
Definition: fib_node.h:204
fib_node_index_t fib_table_entry_special_dpo_add(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source, fib_entry_flag_t flags, const dpo_id_t *dpo)
Add a &#39;special&#39; entry to the FIB that links to the DPO passed A special entry is an entry that the FI...
Definition: fib_table.c:307
void vlib_validate_simple_counter(vlib_simple_counter_main_t *cm, u32 index)
validate a simple counter
Definition: counter.c:91
#define ASSERT(truth)
static int lb_vip_port_find_diff_port(ip46_address_t *prefix, u8 plen, u8 protocol, u16 port, u32 *vip_index)
Definition: lb.c:542
int lb_vip_del_ass_withlock(u32 vip_index, ip46_address_t *addresses, u32 n, u8 flush)
Definition: lb.c:790
lb_vip_type_t
The load balancer supports IPv4 and IPv6 traffic and GRE4, GRE6, L3DSR and NAT4, NAT6 encap...
Definition: lb.h:207
u16 target_port
Definition: lb.h:456
ip46_type_t
Definition: ip6_packet.h:70
int lb_vip_find_index(ip46_address_t *prefix, u8 plen, u8 protocol, u16 port, u32 *vip_index)
Definition: lb.c:549
u8 * format_lb_as(u8 *s, va_list *args)
Definition: lb.c:183
ip46_address_t prefix
Definition: lb.h:573
u32 new_flow_table_mask
New flows table length - 1 (length MUST be a power of 2)
Definition: lb.h:275
dpo_type_t dpo_gre6_port_type
Definition: lb.h:539
static const char *const *const lb_dpo_nat6_port_nodes[DPO_PROTO_NUM]
Definition: lb.c:87
static void vlib_zero_simple_counter(vlib_simple_counter_main_t *cm, u32 index)
Clear a simple counter Clears the set of per-thread u16 counters, and the u64 counter.
Definition: counter.h:139
size_t count
Definition: vapi.c:47
lb_vip_encap_args_t encap_args
Definition: lb.h:579
u32 vip_prefix_index
Definition: lb.h:306
lb_per_cpu_t * per_cpu
Some global data is per-cpu.
Definition: lb.h:501
static void lb_dpo_unlock(dpo_id_t *dpo)
Definition: lb.c:1255
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:23
static uword is_pow2(uword x)
Definition: clib.h:235
u16 target_port
Definition: lb.h:232
u32 as_index
Definition: lb.c:270
vlib_simple_counter_main_t vip_counters[LB_N_VIP_COUNTERS]
Per VIP counter.
Definition: lb.h:531
int lb_nat6_interface_add_del(u32 sw_if_index, int is_del)
Definition: lb.c:1332
u64 as_u64
Definition: lb.h:249
int lb_vip_add(lb_vip_add_args_t args, u32 *vip_index)
Definition: lb.c:1035
static int lb_vip_port_find_index_with_lock(ip46_address_t *prefix, u8 plen, u8 protocol, u16 port, u32 *vip_index)
Definition: lb.c:525
u8 ip4_address[4]
Definition: ip_types.api:17
static const char *const lb_dpo_gre4_ip6[]
Definition: lb.c:37
#define DPO_PROTO_NUM
Definition: dpo.h:70
#define LB_VIP_PER_PORT_BUCKETS
Definition: lb.h:50
ip6_address_t ip6_src_address
Source address used in IPv6 encapsulated traffic.
Definition: lb.h:511
u8 * format_lb_vip_detailed(u8 *s, va_list *args)
Definition: lb.c:191
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static fib_node_t * lb_fib_node_get_node(fib_node_index_t index)
Definition: lb.c:1258
u64 uword
Definition: types.h:112
#define vec_sort_with_function(vec, f)
Sort a vector using the supplied element comparison function.
Definition: vec.h:984
lb_snat_mapping_t * snat_mappings
Definition: lb.h:557
#define DPO_INVALID
An initialiser for DPOs declared on the stack.
Definition: dpo.h:195
void lb_garbage_collection()
Definition: lb.c:353
static bool lb_vip_is_l3dsr_port(const lb_vip_t *vip)
Definition: lb.h:372
u8 protocol
Definition: lb.h:246
u16 port
Definition: lb.h:433
typedef prefix
Definition: ip_types.api:35
u32 next_hop_child_index
The child index on the FIB entry.
Definition: lb.h:155
dpo_type_t dpo_l3dsr_type
Definition: lb.h:540
#define hash_get_mem(h, key)
Definition: hash.h:269
A FIB graph nodes virtual function table.
Definition: fib_node.h:278
static void * clib_mem_alloc_aligned(uword size, uword align)
Definition: mem.h:140
u32 fib_index
Definition: lb.h:458
static vlib_thread_main_t * vlib_get_thread_main()
Definition: global_funcs.h:32
clib_bihash_8_8_t vip_index_per_port
Definition: lb.h:550
static int lb_vip_add_port_filter(lb_main_t *lbm, lb_vip_t *vip, u32 vip_prefix_index, u32 vip_idx)
Add the VIP filter entry.
Definition: lb.c:957
void dpo_reset(dpo_id_t *dpo)
reset a DPO ID The DPO will be unlocked.
Definition: dpo.c:231
#define vec_foreach(var, vec)
Vector iterator.
u16 protocol
Definition: lb.h:434
dpo_id_t dpo
The next DPO in the graph to follow.
Definition: lb.h:160
static const char *const lb_dpo_l3dsr_ip4[]
Definition: lb.c:68
static const char *const lb_dpo_gre4_ip4_port[]
Definition: lb.c:52
u8 flags
Some per-AS flags.
Definition: lb.h:132
u16 dpoi_next_node
The next VLIB node to follow.
Definition: dpo.h:180
void udp_register_dst_port(vlib_main_t *vm, udp_dst_port_t dst_port, u32 node_index, u8 is_ip4)
Definition: udp_local.c:492
ip4_address_t addr
Definition: lb.h:417
clib_bihash_24_8_t mapping_by_as6
Definition: lb.h:554
lb_new_flow_entry_t * new_flow_table
Vector mapping (flow-hash & new_connect_table_mask) to AS index.
Definition: lb.h:269
static const char *const *const lb_dpo_l3dsr_nodes[DPO_PROTO_NUM]
Definition: lb.c:69
dpo_type_t dpo_nat6_port_type
Definition: lb.h:543
static uword clib_bitmap_first_clear(uword *ai)
Return the lowest numbered clear bit in a bitmap.
Definition: bitmap.h:445
u8 flags
Flags related to this VIP.
Definition: lb.h:324
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:59
lb_vip_type_t type
Definition: lb.h:577
static const char *const *const lb_dpo_gre6_port_nodes[DPO_PROTO_NUM]
Definition: lb.c:62
static char * lb_vip_type_strings[]
Definition: lb.c:120
u8 * format_lb_dpo(u8 *s, va_list *va)
Definition: lb.c:1245
ip46_address_t as_ip
Definition: lb.h:447
Load balancing service is provided per VIP+protocol+port.
Definition: lb.h:261
u32 * as_indexes
Pool of AS indexes used for this VIP.
Definition: lb.h:331
u16 fib_index
Definition: lb.h:419
#define lb_hash_size(h)
Definition: lbhash.h:65
u8 rsv
Definition: lb.h:247
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:972
int vnet_feature_enable_disable(const char *arc_name, const char *node_name, u32 sw_if_index, int enable_disable, void *feature_config, u32 n_feature_config_bytes)
Definition: feature.c:274
void dpo_stack(dpo_type_t child_type, dpo_proto_t child_proto, dpo_id_t *dpo, const dpo_id_t *parent)
Stack one DPO object on another, and thus establish a child-parent relationship.
Definition: dpo.c:515
#define lb_put_writer_lock()
Definition: lb.c:31
fib_node_index_t next_hop_fib_entry_index
The FIB entry index for the next-hop.
Definition: lb.h:150
static_always_inline u32 lb_hash_elts(lb_hash_t *h, u32 time_now)
Definition: lbhash.h:185
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:128