FD.io VPP  v18.07-34-g55fbdb9
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(__sync_lock_test_and_set (lb_main.writer_lock, 1))
31 #define lb_put_writer_lock() lb_main.writer_lock[0] = 0
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_l3dsr_ip4[] = { "lb4-l3dsr" , NULL };
53 const static char* const * const lb_dpo_l3dsr_nodes[DPO_PROTO_NUM] =
54  {
56  };
57 
58 const static char * const lb_dpo_nat4_ip4[] = { "lb4-nat4" , NULL };
59 const static char* const * const lb_dpo_nat4_nodes[DPO_PROTO_NUM] =
60  {
62  };
63 
64 const static char * const lb_dpo_nat6_ip6[] = { "lb6-nat6" , NULL };
65 const static char* const * const lb_dpo_nat6_nodes[DPO_PROTO_NUM] =
66  {
68  };
69 
71 {
72  return (u32) (vlib_time_now(vm) + 10000);
73 }
74 
75 u8 *format_lb_main (u8 * s, va_list * args)
76 {
78  lb_main_t *lbm = &lb_main;
79  s = format(s, "lb_main");
80  s = format(s, " ip4-src-address: %U \n", format_ip4_address, &lbm->ip4_src_address);
81  s = format(s, " ip6-src-address: %U \n", format_ip6_address, &lbm->ip6_src_address);
82  s = format(s, " #vips: %u\n", pool_elts(lbm->vips));
83  s = format(s, " #ass: %u\n", pool_elts(lbm->ass) - 1);
84 
85  u32 thread_index;
86  for(thread_index = 0; thread_index < tm->n_vlib_mains; thread_index++ ) {
87  lb_hash_t *h = lbm->per_cpu[thread_index].sticky_ht;
88  if (h) {
89  s = format(s, "core %d\n", thread_index);
90  s = format(s, " timeout: %ds\n", h->timeout);
91  s = format(s, " usage: %d / %d\n", lb_hash_elts(h, lb_hash_time_now(vlib_get_main())), lb_hash_size(h));
92  }
93  }
94 
95  return s;
96 }
97 
98 static char *lb_vip_type_strings[] = {
99  [LB_VIP_TYPE_IP6_GRE6] = "ip6-gre6",
100  [LB_VIP_TYPE_IP6_GRE4] = "ip6-gre4",
101  [LB_VIP_TYPE_IP4_GRE6] = "ip4-gre6",
102  [LB_VIP_TYPE_IP4_GRE4] = "ip4-gre4",
103  [LB_VIP_TYPE_IP4_L3DSR] = "ip4-l3dsr",
104  [LB_VIP_TYPE_IP4_NAT4] = "ip4-nat4",
105  [LB_VIP_TYPE_IP6_NAT6] = "ip6-nat6",
106 };
107 
108 u8 *format_lb_vip_type (u8 * s, va_list * args)
109 {
110  lb_vip_type_t vipt = va_arg (*args, lb_vip_type_t);
111  u32 i;
112  for (i=0; i<LB_VIP_N_TYPES; i++)
113  if (vipt == i)
114  return format(s, lb_vip_type_strings[i]);
115  return format(s, "_WRONG_TYPE_");
116 }
117 
118 uword unformat_lb_vip_type (unformat_input_t * input, va_list * args)
119 {
120  lb_vip_type_t *vipt = va_arg (*args, lb_vip_type_t *);
121  u32 i;
122  for (i=0; i<LB_VIP_N_TYPES; i++)
123  if (unformat(input, lb_vip_type_strings[i])) {
124  *vipt = i;
125  return 1;
126  }
127  return 0;
128 }
129 
130 u8 *format_lb_vip (u8 * s, va_list * args)
131 {
132  lb_vip_t *vip = va_arg (*args, lb_vip_t *);
133  s = format(s, "%U %U new_size:%u #as:%u%s",
134  format_lb_vip_type, vip->type,
136  vip->new_flow_table_mask + 1,
137  pool_elts(vip->as_indexes),
138  (vip->flags & LB_VIP_FLAGS_USED)?"":" removed");
139 
140  if (vip->type == LB_VIP_TYPE_IP4_L3DSR)
141  {
142  s = format(s, " dscp:%u", vip->encap_args.dscp);
143  }
144  else if ((vip->type == LB_VIP_TYPE_IP4_NAT4)
145  || (vip->type == LB_VIP_TYPE_IP6_NAT6))
146  {
148  s = format (s, " type:clusterip port:%u target_port:%u",
149  ntohs (vip->encap_args.port),
150  ntohs (vip->encap_args.target_port));
151  else
152  s = format (s, " type:nodeport node_port:%u target_port:%u",
153  ntohs (vip->encap_args.node_port),
154  ntohs (vip->encap_args.target_port));
155  }
156 
157  return s;
158 }
159 
160 u8 *format_lb_as (u8 * s, va_list * args)
161 {
162  lb_as_t *as = va_arg (*args, lb_as_t *);
163  return format(s, "%U %s", format_ip46_address,
164  &as->address, IP46_TYPE_ANY,
165  (as->flags & LB_AS_FLAGS_USED)?"used":"removed");
166 }
167 
168 u8 *format_lb_vip_detailed (u8 * s, va_list * args)
169 {
170  lb_main_t *lbm = &lb_main;
171  lb_vip_t *vip = va_arg (*args, lb_vip_t *);
172  u32 indent = format_get_indent (s);
173 
174  s = format(s, "%U %U [%lu] %U%s\n"
175  "%U new_size:%u\n",
176  format_white_space, indent,
177  format_lb_vip_type, vip->type,
178  vip - lbm->vips,
180  (vip->flags & LB_VIP_FLAGS_USED)?"":" removed",
181  format_white_space, indent,
182  vip->new_flow_table_mask + 1);
183 
184  if (vip->type == LB_VIP_TYPE_IP4_L3DSR)
185  {
186  s = format(s, "%U dscp:%u\n",
187  format_white_space, indent,
188  vip->encap_args.dscp);
189  }
190  else if ((vip->type == LB_VIP_TYPE_IP4_NAT4)
191  || (vip->type == LB_VIP_TYPE_IP6_NAT6))
192  {
194  s = format (s, "%U type:clusterip port:%u target_port:%u",
195  format_white_space, indent, ntohs (vip->encap_args.port),
196  ntohs (vip->encap_args.target_port));
197  else
198  s = format (s, "%U type:nodeport node_port:%u target_port:%u",
199  format_white_space, indent,
200  ntohs (vip->encap_args.node_port),
201  ntohs (vip->encap_args.target_port));
202  }
203 
204  //Print counters
205  s = format(s, "%U counters:\n",
206  format_white_space, indent);
207  u32 i;
208  for (i=0; i<LB_N_VIP_COUNTERS; i++)
209  s = format(s, "%U %s: %d\n",
210  format_white_space, indent,
211  lbm->vip_counters[i].name,
212  vlib_get_simple_counter(&lbm->vip_counters[i], vip - lbm->vips));
213 
214 
215  s = format(s, "%U #as:%u\n",
216  format_white_space, indent,
217  pool_elts(vip->as_indexes));
218 
219  //Let's count the buckets for each AS
220  u32 *count = 0;
221  vec_validate(count, pool_len(lbm->ass)); //Possibly big alloc for not much...
222  lb_new_flow_entry_t *nfe;
223  vec_foreach(nfe, vip->new_flow_table)
224  count[nfe->as_index]++;
225 
226  lb_as_t *as;
227  u32 *as_index;
228  pool_foreach(as_index, vip->as_indexes, {
229  as = &lbm->ass[*as_index];
230  s = format(s, "%U %U %d buckets %d flows dpo:%u %s\n",
231  format_white_space, indent,
232  format_ip46_address, &as->address, IP46_TYPE_ANY,
233  count[as - lbm->ass],
234  vlib_refcount_get(&lbm->as_refcount, as - lbm->ass),
235  as->dpo.dpoi_index,
236  (as->flags & LB_AS_FLAGS_USED)?"used":" removed");
237  });
238 
239  vec_free(count);
240 
241  /*
242  s = format(s, "%U new flows table:\n", format_white_space, indent);
243  lb_new_flow_entry_t *nfe;
244  vec_foreach(nfe, vip->new_flow_table) {
245  s = format(s, "%U %d: %d\n", format_white_space, indent, nfe - vip->new_flow_table, nfe->as_index);
246  }
247  */
248  return s;
249 }
250 
251 typedef struct {
256 
257 static int lb_pseudorand_compare(void *a, void *b)
258 {
259  lb_as_t *asa, *asb;
260  lb_main_t *lbm = &lb_main;
261  asa = &lbm->ass[((lb_pseudorand_t *)a)->as_index];
262  asb = &lbm->ass[((lb_pseudorand_t *)b)->as_index];
263  return memcmp(&asa->address, &asb->address, sizeof(asb->address));
264 }
265 
267 {
268  lb_main_t *lbm = &lb_main;
269  lb_snat4_key_t m_key4;
270  clib_bihash_kv_8_8_t kv4, value4;
271  lb_snat6_key_t m_key6;
272  clib_bihash_kv_24_8_t kv6, value6;
273  lb_snat_mapping_t *m = 0;
274  ASSERT (lbm->writer_lock[0]);
275 
276  u32 now = (u32) vlib_time_now(vlib_get_main());
278  return;
279 
280  vip->last_garbage_collection = now;
281  lb_as_t *as;
282  u32 *as_index;
283  pool_foreach(as_index, vip->as_indexes, {
284  as = &lbm->ass[*as_index];
285  if (!(as->flags & LB_AS_FLAGS_USED) && //Not used
286  clib_u32_loop_gt(now, as->last_used + LB_CONCURRENCY_TIMEOUT) && //Not recently used
287  (vlib_refcount_get(&lbm->as_refcount, as - lbm->ass) == 0))
288  { //Not referenced
289 
290  if (lb_vip_is_nat4(vip)) {
291  m_key4.addr = as->address.ip4;
292  m_key4.port = vip->encap_args.target_port;
293  m_key4.protocol = 0;
294  m_key4.fib_index = 0;
295 
296  kv4.key = m_key4.as_u64;
297  if(!clib_bihash_search_8_8(&lbm->mapping_by_as4, &kv4, &value4))
298  m = pool_elt_at_index (lbm->snat_mappings, value4.value);
299  ASSERT (m);
300 
301  kv4.value = m - lbm->snat_mappings;
302  clib_bihash_add_del_8_8(&lbm->mapping_by_as4, &kv4, 0);
303  pool_put (lbm->snat_mappings, m);
304  } else if (lb_vip_is_nat6(vip)) {
305  m_key6.addr.as_u64[0] = as->address.ip6.as_u64[0];
306  m_key6.addr.as_u64[1] = as->address.ip6.as_u64[1];
307  m_key6.port = vip->encap_args.target_port;
308  m_key6.protocol = 0;
309  m_key6.fib_index = 0;
310 
311  kv6.key[0] = m_key6.as_u64[0];
312  kv6.key[1] = m_key6.as_u64[1];
313  kv6.key[2] = m_key6.as_u64[2];
314 
315  if (!clib_bihash_search_24_8 (&lbm->mapping_by_as6, &kv6, &value6))
316  m = pool_elt_at_index (lbm->snat_mappings, value6.value);
317  ASSERT (m);
318 
319  kv6.value = m - lbm->snat_mappings;
320  clib_bihash_add_del_24_8(&lbm->mapping_by_as6, &kv6, 0);
321  pool_put (lbm->snat_mappings, m);
322  }
323  fib_entry_child_remove(as->next_hop_fib_entry_index,
324  as->next_hop_child_index);
325  fib_table_entry_delete_index(as->next_hop_fib_entry_index,
326  FIB_SOURCE_RR);
327  as->next_hop_fib_entry_index = FIB_NODE_INDEX_INVALID;
328 
329  pool_put(vip->as_indexes, as_index);
330  pool_put(lbm->ass, as);
331  }
332  });
333 }
334 
336 {
337  lb_main_t *lbm = &lb_main;
339  lb_vip_t *vip;
340  u32 *to_be_removed_vips = 0, *i;
341  pool_foreach(vip, lbm->vips, {
342  lb_vip_garbage_collection(vip);
343 
344  if (!(vip->flags & LB_VIP_FLAGS_USED) &&
345  (pool_elts(vip->as_indexes) == 0)) {
346  vec_add1(to_be_removed_vips, vip - lbm->vips);
347  }
348  });
349 
350  vec_foreach(i, to_be_removed_vips) {
351  vip = &lbm->vips[*i];
352  pool_put(lbm->vips, vip);
353  pool_free(vip->as_indexes);
354  }
355 
356  vec_free(to_be_removed_vips);
358 }
359 
361 {
362  lb_main_t *lbm = &lb_main;
363  lb_new_flow_entry_t *old_table;
364  u32 i, *as_index;
365  lb_new_flow_entry_t *new_flow_table = 0;
366  lb_as_t *as;
367  lb_pseudorand_t *pr, *sort_arr = 0;
368  u32 count;
369 
370  ASSERT (lbm->writer_lock[0]); //We must have the lock
371 
372  //Check if some AS is configured or not
373  i = 0;
374  pool_foreach(as_index, vip->as_indexes, {
375  as = &lbm->ass[*as_index];
376  if (as->flags & LB_AS_FLAGS_USED) { //Not used anymore
377  i = 1;
378  goto out; //Not sure 'break' works in this macro-loop
379  }
380  });
381 
382 out:
383  if (i == 0) {
384  //Only the default. i.e. no AS
385  vec_validate(new_flow_table, vip->new_flow_table_mask);
386  for (i=0; i<vec_len(new_flow_table); i++)
387  new_flow_table[i].as_index = 0;
388 
389  goto finished;
390  }
391 
392  //First, let's sort the ASs
393  sort_arr = 0;
394  vec_alloc(sort_arr, pool_elts(vip->as_indexes));
395 
396  i = 0;
397  pool_foreach(as_index, vip->as_indexes, {
398  as = &lbm->ass[*as_index];
399  if (!(as->flags & LB_AS_FLAGS_USED)) //Not used anymore
400  continue;
401 
402  sort_arr[i].as_index = as - lbm->ass;
403  i++;
404  });
405  _vec_len(sort_arr) = i;
406 
408 
409  //Now let's pseudo-randomly generate permutations
410  vec_foreach(pr, sort_arr) {
411  lb_as_t *as = &lbm->ass[pr->as_index];
412 
413  u64 seed = clib_xxhash(as->address.as_u64[0] ^
414  as->address.as_u64[1]);
415  /* We have 2^n buckets.
416  * skip must be prime with 2^n.
417  * So skip must be odd.
418  * MagLev actually state that M should be prime,
419  * but this has a big computation cost (% operation).
420  * Using 2^n is more better (& operation).
421  */
422  pr->skip = ((seed & 0xffffffff) | 1) & vip->new_flow_table_mask;
423  pr->last = (seed >> 32) & vip->new_flow_table_mask;
424  }
425 
426  //Let's create a new flow table
427  vec_validate(new_flow_table, vip->new_flow_table_mask);
428  for (i=0; i<vec_len(new_flow_table); i++)
429  new_flow_table[i].as_index = ~0;
430 
431  u32 done = 0;
432  while (1) {
433  vec_foreach(pr, sort_arr) {
434  while (1) {
435  u32 last = pr->last;
436  pr->last = (pr->last + pr->skip) & vip->new_flow_table_mask;
437  if (new_flow_table[last].as_index == ~0) {
438  new_flow_table[last].as_index = pr->as_index;
439  break;
440  }
441  }
442  done++;
443  if (done == vec_len(new_flow_table))
444  goto finished;
445  }
446  }
447 
448  vec_free(sort_arr);
449 
450 finished:
451 
452 //Count number of changed entries
453  count = 0;
454  for (i=0; i<vec_len(new_flow_table); i++)
455  if (vip->new_flow_table == 0 ||
456  new_flow_table[i].as_index != vip->new_flow_table[i].as_index)
457  count++;
458 
459  old_table = vip->new_flow_table;
460  vip->new_flow_table = new_flow_table;
461  vec_free(old_table);
462 }
463 
465  u32 per_cpu_sticky_buckets, u32 flow_timeout)
466 {
467  lb_main_t *lbm = &lb_main;
468 
469  if (!is_pow2(per_cpu_sticky_buckets))
470  return VNET_API_ERROR_INVALID_MEMORY_SIZE;
471 
472  lb_get_writer_lock(); //Not exactly necessary but just a reminder that it exists for my future self
475  lbm->per_cpu_sticky_buckets = per_cpu_sticky_buckets;
476  lbm->flow_timeout = flow_timeout;
478  return 0;
479 }
480 
481 static
482 int lb_vip_find_index_with_lock(ip46_address_t *prefix, u8 plen, u32 *vip_index)
483 {
484  lb_main_t *lbm = &lb_main;
485  lb_vip_t *vip;
486  ASSERT (lbm->writer_lock[0]); //This must be called with the lock owned
487  ip46_prefix_normalize(prefix, plen);
488  pool_foreach(vip, lbm->vips, {
489  if ((vip->flags & LB_AS_FLAGS_USED) &&
490  vip->plen == plen &&
491  vip->prefix.as_u64[0] == prefix->as_u64[0] &&
492  vip->prefix.as_u64[1] == prefix->as_u64[1]) {
493  *vip_index = vip - lbm->vips;
494  return 0;
495  }
496  });
497  return VNET_API_ERROR_NO_SUCH_ENTRY;
498 }
499 
500 int lb_vip_find_index(ip46_address_t *prefix, u8 plen, u32 *vip_index)
501 {
502  int ret;
504  ret = lb_vip_find_index_with_lock(prefix, plen, vip_index);
506  return ret;
507 }
508 
509 static int lb_as_find_index_vip(lb_vip_t *vip, ip46_address_t *address, u32 *as_index)
510 {
511  lb_main_t *lbm = &lb_main;
512  ASSERT (lbm->writer_lock[0]); //This must be called with the lock owned
513  lb_as_t *as;
514  u32 *asi;
515  pool_foreach(asi, vip->as_indexes, {
516  as = &lbm->ass[*asi];
517  if (as->vip_index == (vip - lbm->vips) &&
518  as->address.as_u64[0] == address->as_u64[0] &&
519  as->address.as_u64[1] == address->as_u64[1]) {
520  *as_index = as - lbm->ass;
521  return 0;
522  }
523  });
524  return -1;
525 }
526 
527 int lb_vip_add_ass(u32 vip_index, ip46_address_t *addresses, u32 n)
528 {
529  lb_main_t *lbm = &lb_main;
531  lb_vip_t *vip;
532  if (!(vip = lb_vip_get_by_index(vip_index))) {
534  return VNET_API_ERROR_NO_SUCH_ENTRY;
535  }
536 
538  u32 *to_be_added = 0;
539  u32 *to_be_updated = 0;
540  u32 i;
541  u32 *ip;
543 
544  //Sanity check
545  while (n--) {
546 
547  if (!lb_as_find_index_vip(vip, &addresses[n], &i)) {
548  if (lbm->ass[i].flags & LB_AS_FLAGS_USED) {
549  vec_free(to_be_added);
550  vec_free(to_be_updated);
552  return VNET_API_ERROR_VALUE_EXIST;
553  }
554  vec_add1(to_be_updated, i);
555  goto next;
556  }
557 
558  if (ip46_address_type(&addresses[n]) != type) {
559  vec_free(to_be_added);
560  vec_free(to_be_updated);
562  return VNET_API_ERROR_INVALID_ADDRESS_FAMILY;
563  }
564 
565  if (n) {
566  u32 n2 = n;
567  while(n2--) //Check for duplicates
568  if (addresses[n2].as_u64[0] == addresses[n].as_u64[0] &&
569  addresses[n2].as_u64[1] == addresses[n].as_u64[1])
570  goto next;
571  }
572 
573  vec_add1(to_be_added, n);
574 
575 next:
576  continue;
577  }
578 
579  //Update reused ASs
580  vec_foreach(ip, to_be_updated) {
581  lbm->ass[*ip].flags = LB_AS_FLAGS_USED;
582  }
583  vec_free(to_be_updated);
584 
585  //Create those who have to be created
586  vec_foreach(ip, to_be_added) {
587  lb_as_t *as;
588  u32 *as_index;
589  pool_get(lbm->ass, as);
590  as->address = addresses[*ip];
591  as->flags = LB_AS_FLAGS_USED;
592  as->vip_index = vip_index;
593  pool_get(vip->as_indexes, as_index);
594  *as_index = as - lbm->ass;
595 
596  /*
597  * become a child of the FIB entry
598  * so we are informed when its forwarding changes
599  */
600  fib_prefix_t nh = {};
601  if (lb_encap_is_ip4(vip)) {
602  nh.fp_addr.ip4 = as->address.ip4;
603  nh.fp_len = 32;
605  } else {
606  nh.fp_addr.ip6 = as->address.ip6;
607  nh.fp_len = 128;
609  }
610 
613  &nh,
618  lbm->fib_node_type,
619  as - lbm->ass);
620 
621  lb_as_stack(as);
622 
623  if ( lb_vip_is_nat4(vip) || lb_vip_is_nat6(vip) )
624  {
625  /* Add SNAT static mapping */
626  pool_get (lbm->snat_mappings, m);
627  memset (m, 0, sizeof (*m));
628  if (lb_vip_is_nat4(vip)) {
629  lb_snat4_key_t m_key4;
631  m_key4.addr = as->address.ip4;
632  m_key4.port = vip->encap_args.target_port;
633  m_key4.protocol = 0;
634  m_key4.fib_index = 0;
635 
637  {
638  m->src_ip.ip4 = vip->prefix.ip4;
639  m->src_port = vip->encap_args.port;
640  }
641  else if (vip->encap_args.srv_type == LB_SRV_TYPE_NODEPORT)
642  {
643  m->src_ip.ip4 = lbm->ip4_src_address;
644  m->src_port = vip->encap_args.node_port;
645  }
646  m->src_ip_is_ipv6 = 0;
647  m->as_ip.ip4 = as->address.ip4;
648  m->as_ip_is_ipv6 = 0;;
650  m->vrf_id = 0;
651  m->fib_index = 0;
652 
653  kv4.key = m_key4.as_u64;
654  kv4.value = m - lbm->snat_mappings;
655  clib_bihash_add_del_8_8(&lbm->mapping_by_as4, &kv4, 1);
656  } else {
657  lb_snat6_key_t m_key6;
659  m_key6.addr.as_u64[0] = as->address.ip6.as_u64[0];
660  m_key6.addr.as_u64[1] = as->address.ip6.as_u64[1];
661  m_key6.port = vip->encap_args.target_port;
662  m_key6.protocol = 0;
663  m_key6.fib_index = 0;
664 
666  {
667  m->src_ip.ip6.as_u64[0] = vip->prefix.ip6.as_u64[0];
668  m->src_ip.ip6.as_u64[1] = vip->prefix.ip6.as_u64[1];
669  m->src_port = vip->encap_args.port;
670  }
671  else if (vip->encap_args.srv_type == LB_SRV_TYPE_NODEPORT)
672  {
673  m->src_ip.ip6.as_u64[0] = lbm->ip6_src_address.as_u64[0];
674  m->src_ip.ip6.as_u64[1] = lbm->ip6_src_address.as_u64[1];
675  m->src_port = vip->encap_args.node_port;
676  }
677  m->src_ip_is_ipv6 = 1;
678  m->as_ip.ip6.as_u64[0] = as->address.ip6.as_u64[0];
679  m->as_ip.ip6.as_u64[1] = as->address.ip6.as_u64[1];
680  m->as_ip_is_ipv6 = 1;
682  m->vrf_id = 0;
683  m->fib_index = 0;
684 
685  kv6.key[0] = m_key6.as_u64[0];
686  kv6.key[1] = m_key6.as_u64[1];
687  kv6.key[2] = m_key6.as_u64[2];
688  kv6.value = m - lbm->snat_mappings;
689  clib_bihash_add_del_24_8(&lbm->mapping_by_as6, &kv6, 1);
690  }
691  }
692  }
693  vec_free(to_be_added);
694 
695  //Recompute flows
697 
698  //Garbage collection maybe
700 
702  return 0;
703 }
704 
705 int lb_vip_del_ass_withlock(u32 vip_index, ip46_address_t *addresses, u32 n)
706 {
707  lb_main_t *lbm = &lb_main;
708  u32 now = (u32) vlib_time_now(vlib_get_main());
709  u32 *ip = 0;
710 
711  lb_vip_t *vip;
712  if (!(vip = lb_vip_get_by_index(vip_index))) {
713  return VNET_API_ERROR_NO_SUCH_ENTRY;
714  }
715 
716  u32 *indexes = NULL;
717  while (n--) {
718  u32 i;
719  if (lb_as_find_index_vip(vip, &addresses[n], &i)) {
720  vec_free(indexes);
721  return VNET_API_ERROR_NO_SUCH_ENTRY;
722  }
723 
724  if (n) { //Check for duplicates
725  u32 n2 = n - 1;
726  while(n2--) {
727  if (addresses[n2].as_u64[0] == addresses[n].as_u64[0] &&
728  addresses[n2].as_u64[1] == addresses[n].as_u64[1])
729  goto next;
730  }
731  }
732 
733  vec_add1(indexes, i);
734 next:
735  continue;
736  }
737 
738  //Garbage collection maybe
740 
741  if (indexes != NULL) {
742  vec_foreach(ip, indexes) {
743  lbm->ass[*ip].flags &= ~LB_AS_FLAGS_USED;
744  lbm->ass[*ip].last_used = now;
745  }
746 
747  //Recompute flows
749  }
750 
751  vec_free(indexes);
752  return 0;
753 }
754 
755 int lb_vip_del_ass(u32 vip_index, ip46_address_t *addresses, u32 n)
756 {
758  int ret = lb_vip_del_ass_withlock(vip_index, addresses, n);
760  return ret;
761 }
762 
763 /**
764  * Add the VIP adjacency to the ip4 or ip6 fib
765  */
766 static void lb_vip_add_adjacency(lb_main_t *lbm, lb_vip_t *vip)
767 {
768  dpo_proto_t proto = 0;
769  dpo_type_t dpo_type = 0;
770 
771  dpo_id_t dpo = DPO_INVALID;
772  fib_prefix_t pfx = {};
773  if (lb_vip_is_ip4(vip)) {
774  pfx.fp_addr.ip4 = vip->prefix.ip4;
775  pfx.fp_len = vip->plen - 96;
777  proto = DPO_PROTO_IP4;
778  } else {
779  pfx.fp_addr.ip6 = vip->prefix.ip6;
780  pfx.fp_len = vip->plen;
782  proto = DPO_PROTO_IP6;
783  }
784 
785  if (lb_vip_is_gre4(vip))
786  dpo_type = lbm->dpo_gre4_type;
787  else if (lb_vip_is_gre6(vip))
788  dpo_type = lbm->dpo_gre6_type;
789  else if (lb_vip_is_l3dsr(vip))
790  dpo_type = lbm->dpo_l3dsr_type;
791  else if(lb_vip_is_nat4(vip))
792  dpo_type = lbm->dpo_nat4_type;
793  else if (lb_vip_is_nat6(vip))
794  dpo_type = lbm->dpo_nat6_type;
795 
796  dpo_set(&dpo, dpo_type, proto, vip - lbm->vips);
798  &pfx,
801  &dpo);
802  dpo_reset(&dpo);
803 }
804 
805 /**
806  * Deletes the adjacency associated with the VIP
807  */
808 static void lb_vip_del_adjacency(lb_main_t *lbm, lb_vip_t *vip)
809 {
810  fib_prefix_t pfx = {};
811  if (lb_vip_is_ip4(vip)) {
812  pfx.fp_addr.ip4 = vip->prefix.ip4;
813  pfx.fp_len = vip->plen - 96;
815  } else {
816  pfx.fp_addr.ip6 = vip->prefix.ip6;
817  pfx.fp_len = vip->plen;
819  }
821 }
822 
823 int lb_vip_add(lb_vip_add_args_t args, u32 *vip_index)
824 {
825  lb_main_t *lbm = &lb_main;
827  lb_vip_t *vip;
828  lb_vip_type_t type = args.type;
829  u16 node_port = args.encap_args.node_port;
830 
832  ip46_prefix_normalize(&(args.prefix), args.plen);
833 
834  if (!lb_vip_find_index_with_lock(&(args.prefix), args.plen, vip_index)) {
836  return VNET_API_ERROR_VALUE_EXIST;
837  }
838 
839  if (!is_pow2(args.new_length)) {
841  return VNET_API_ERROR_INVALID_MEMORY_SIZE;
842  }
843 
844  if (ip46_prefix_is_ip4(&(args.prefix), args.plen) &&
845  (type != LB_VIP_TYPE_IP4_GRE4) &&
846  (type != LB_VIP_TYPE_IP4_GRE6) &&
847  (type != LB_VIP_TYPE_IP4_L3DSR) &&
848  (type != LB_VIP_TYPE_IP4_NAT4)) {
850  return VNET_API_ERROR_INVALID_ADDRESS_FAMILY;
851  }
852 
853  if ((!ip46_prefix_is_ip4(&(args.prefix), args.plen)) &&
854  (type != LB_VIP_TYPE_IP6_GRE4) &&
855  (type != LB_VIP_TYPE_IP6_GRE6) &&
856  (type != LB_VIP_TYPE_IP6_NAT6)) {
858  return VNET_API_ERROR_INVALID_ADDRESS_FAMILY;
859  }
860 
861  if ((type == LB_VIP_TYPE_IP4_L3DSR) && (args.encap_args.dscp >= 64 ) )
862  {
864  return VNET_API_ERROR_VALUE_EXIST;
865  }
866 
867  //Allocate
868  pool_get(lbm->vips, vip);
869 
870  //Init
871  memcpy (&(vip->prefix), &(args.prefix), sizeof(args.prefix));
872  vip->plen = args.plen;
874  vip->type = args.type;
875 
876  if (args.type == LB_VIP_TYPE_IP4_L3DSR) {
877  vip->encap_args.dscp = args.encap_args.dscp;
878  }
879  else if ((args.type == LB_VIP_TYPE_IP4_NAT4)
880  ||(args.type == LB_VIP_TYPE_IP6_NAT6)) {
882  vip->encap_args.port = clib_host_to_net_u16(args.encap_args.port);
883  vip->encap_args.target_port =
884  clib_host_to_net_u16(args.encap_args.target_port);
885  vip->encap_args.node_port = clib_host_to_net_u16(node_port);
886  }
887 
888  vip->flags = LB_VIP_FLAGS_USED;
889  vip->as_indexes = 0;
890 
891  //Validate counters
892  u32 i;
893  for (i = 0; i < LB_N_VIP_COUNTERS; i++) {
894  vlib_validate_simple_counter(&lbm->vip_counters[i], vip - lbm->vips);
895  vlib_zero_simple_counter(&lbm->vip_counters[i], vip - lbm->vips);
896  }
897 
898  //Configure new flow table
899  vip->new_flow_table_mask = args.new_length - 1;
900  vip->new_flow_table = 0;
901 
902  //Create a new flow hash table full of the default entry
904 
905  //Create adjacency to direct traffic
906  lb_vip_add_adjacency(lbm, vip);
907 
908  if ( (lb_vip_is_nat4(vip) || lb_vip_is_nat6(vip))
910  {
911  u32 key;
912  uword * entry;
913 
914  //Create maping from nodeport to vip_index
915  key = clib_host_to_net_u16(node_port);
916  entry = hash_get_mem (lbm->vip_index_by_nodeport, &key);
917  if (entry) {
919  return VNET_API_ERROR_VALUE_EXIST;
920  }
921 
922  hash_set_mem (lbm->vip_index_by_nodeport, &key, vip - lbm->vips);
923 
924  /* receive packets destined to NodeIP:NodePort */
925  udp_register_dst_port (vm, node_port, lb4_nodeport_node.index, 1);
926  udp_register_dst_port (vm, node_port, lb6_nodeport_node.index, 0);
927  }
928 
929  //Return result
930  *vip_index = vip - lbm->vips;
931 
933  return 0;
934 }
935 
936 int lb_vip_del(u32 vip_index)
937 {
938  lb_main_t *lbm = &lb_main;
939  lb_vip_t *vip;
941  if (!(vip = lb_vip_get_by_index(vip_index))) {
943  return VNET_API_ERROR_NO_SUCH_ENTRY;
944  }
945 
946  //FIXME: This operation is actually not working
947  //We will need to remove state before performing this.
948 
949  {
950  //Remove all ASs
951  ip46_address_t *ass = 0;
952  lb_as_t *as;
953  u32 *as_index;
954  pool_foreach(as_index, vip->as_indexes, {
955  as = &lbm->ass[*as_index];
956  vec_add1(ass, as->address);
957  });
958  if (vec_len(ass))
959  lb_vip_del_ass_withlock(vip_index, ass, vec_len(ass));
960  vec_free(ass);
961  }
962 
963  //Delete adjacency
964  lb_vip_del_adjacency(lbm, vip);
965 
966  //Set the VIP as unused
967  vip->flags &= ~LB_VIP_FLAGS_USED;
968 
970  return 0;
971 }
972 
973 /* *INDENT-OFF* */
975  .version = VPP_BUILD_VER,
976  .description = "Load Balancer",
977 };
978 /* *INDENT-ON* */
979 
980 u8 *format_lb_dpo (u8 * s, va_list * va)
981 {
982  index_t index = va_arg (*va, index_t);
983  CLIB_UNUSED(u32 indent) = va_arg (*va, u32);
984  lb_main_t *lbm = &lb_main;
985  lb_vip_t *vip = pool_elt_at_index (lbm->vips, index);
986  return format (s, "%U", format_lb_vip, vip);
987 }
988 
989 static void lb_dpo_lock (dpo_id_t *dpo) {}
990 static void lb_dpo_unlock (dpo_id_t *dpo) {}
991 
992 static fib_node_t *
994 {
995  lb_main_t *lbm = &lb_main;
996  lb_as_t *as = pool_elt_at_index (lbm->ass, index);
997  return (&as->fib_node);
998 }
999 
1000 static void
1002 {
1003 }
1004 
1005 static lb_as_t *
1007 {
1008  return ((lb_as_t*)(((char*)node) -
1009  STRUCT_OFFSET_OF(lb_as_t, fib_node)));
1010 }
1011 
1012 static void
1014 {
1015  lb_main_t *lbm = &lb_main;
1016  lb_vip_t *vip = &lbm->vips[as->vip_index];
1017  dpo_type_t dpo_type = 0;
1018 
1019  if (lb_vip_is_gre4(vip))
1020  dpo_type = lbm->dpo_gre4_type;
1021  else if (lb_vip_is_gre6(vip))
1022  dpo_type = lbm->dpo_gre6_type;
1023  else if (lb_vip_is_l3dsr(vip))
1024  dpo_type = lbm->dpo_l3dsr_type;
1025  else if(lb_vip_is_nat4(vip))
1026  dpo_type = lbm->dpo_nat4_type;
1027  else if (lb_vip_is_nat6(vip))
1028  dpo_type = lbm->dpo_nat6_type;
1029 
1030  dpo_stack(dpo_type,
1032  &as->dpo,
1035 }
1036 
1040 {
1042  return (FIB_NODE_BACK_WALK_CONTINUE);
1043 }
1044 
1045 int lb_nat4_interface_add_del (u32 sw_if_index, int is_del)
1046 {
1047  if (is_del)
1048  {
1049  vnet_feature_enable_disable ("ip4-unicast", "lb-nat4-in2out",
1050  sw_if_index, 0, 0, 0);
1051  }
1052  else
1053  {
1054  vnet_feature_enable_disable ("ip4-unicast", "lb-nat4-in2out",
1055  sw_if_index, 1, 0, 0);
1056  }
1057 
1058  return 0;
1059 }
1060 
1061 int lb_nat6_interface_add_del (u32 sw_if_index, int is_del)
1062 {
1063  if (is_del)
1064  {
1065  vnet_feature_enable_disable ("ip6-unicast", "lb-nat6-in2out",
1066  sw_if_index, 0, 0, 0);
1067  }
1068  else
1069  {
1070  vnet_feature_enable_disable ("ip6-unicast", "lb-nat6-in2out",
1071  sw_if_index, 1, 0, 0);
1072  }
1073 
1074  return 0;
1075 }
1076 
1077 clib_error_t *
1079 {
1081  lb_main_t *lbm = &lb_main;
1082  lbm->vnet_main = vnet_get_main ();
1083  lbm->vlib_main = vm;
1084 
1085  lb_as_t *default_as;
1086  fib_node_vft_t lb_fib_node_vft = {
1088  .fnv_last_lock = lb_fib_node_last_lock_gone,
1089  .fnv_back_walk = lb_fib_node_back_walk_notify,
1090  };
1091  dpo_vft_t lb_vft = {
1092  .dv_lock = lb_dpo_lock,
1093  .dv_unlock = lb_dpo_unlock,
1094  .dv_format = format_lb_dpo,
1095  };
1096 
1097  lbm->vips = 0;
1098  lbm->per_cpu = 0;
1099  vec_validate(lbm->per_cpu, tm->n_vlib_mains - 1);
1101  lbm->writer_lock[0] = 0;
1104  lbm->ip4_src_address.as_u32 = 0xffffffff;
1105  lbm->ip6_src_address.as_u64[0] = 0xffffffffffffffffL;
1106  lbm->ip6_src_address.as_u64[1] = 0xffffffffffffffffL;
1112  lbm->fib_node_type = fib_node_register_new_type(&lb_fib_node_vft);
1113 
1114  //Init AS reference counters
1116 
1117  //Allocate and init default AS.
1118  lbm->ass = 0;
1119  pool_get(lbm->ass, default_as);
1120  default_as->flags = 0;
1121  default_as->dpo.dpoi_next_node = LB_NEXT_DROP;
1122  default_as->vip_index = ~0;
1123  default_as->address.ip6.as_u64[0] = 0xffffffffffffffffL;
1124  default_as->address.ip6.as_u64[1] = 0xffffffffffffffffL;
1125 
1127  = hash_create_mem (0, sizeof(u16), sizeof (uword));
1128 
1129  clib_bihash_init_8_8 (&lbm->mapping_by_as4,
1130  "mapping_by_as4", LB_MAPPING_BUCKETS,
1132 
1133  clib_bihash_init_24_8 (&lbm->mapping_by_as6,
1134  "mapping_by_as6", LB_MAPPING_BUCKETS,
1136 
1137 #define _(a,b,c) lbm->vip_counters[c].name = b;
1139 #undef _
1140  return NULL;
1141 }
1142 
u32 skip
Definition: lb.c:254
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:437
fib_protocol_t fp_proto
protocol type
Definition: fib_types.h:197
dpo_lock_fn_t dv_lock
A reference counting lock function.
Definition: dpo.h:404
u64 as_u64
Definition: lb.h:371
u32 lb_hash_time_now(vlib_main_t *vm)
Definition: lb.c:70
typedef address
Definition: ip_types.api:35
u64 as_u64[3]
Definition: lb.h:386
int lb_nat4_interface_add_del(u32 sw_if_index, int is_del)
Definition: lb.c:1045
Recursive resolution source.
Definition: fib_entry.h:125
static int lb_pseudorand_compare(void *a, void *b)
Definition: lb.c:257
vnet_main_t * vnet_main
Definition: lb.h:507
Each VIP is configured with a set of application server.
Definition: lb.h:104
#define LB_GARBAGE_RUN
Definition: lb.c:23
#define CLIB_UNUSED(x)
Definition: clib.h:79
A virtual function table regisitered for a DPO type.
Definition: dpo.h:399
ip46_type_t
Definition: format.h:63
#define lb_vip_is_gre6(vip)
Definition: lb.h:312
a
Definition: bitmap.h:538
static bool lb_vip_is_l3dsr(const lb_vip_t *vip)
Definition: lb.h:321
u32 last
Definition: lb.c:253
vnet_main_t * vnet_get_main(void)
Definition: misc.c:47
u32 fib_index
Definition: lb.h:384
static const char *const *const lb_dpo_nat6_nodes[DPO_PROTO_NUM]
Definition: lb.c:65
u32 per_cpu_sticky_buckets
Number of buckets in the per-cpu sticky hash table.
Definition: lb.h:465
clib_error_t * lb_init(vlib_main_t *vm)
Definition: lb.c:1078
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:527
static void lb_fib_node_last_lock_gone(fib_node_t *node)
Definition: lb.c:1001
u64 as_u64[2]
Definition: ip6_packet.h:51
static void lb_vip_update_new_flow_table(lb_vip_t *vip)
Definition: lb.c:360
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:509
#define NULL
Definition: clib.h:55
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:225
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:478
static void lb_vip_del_adjacency(lb_main_t *lbm, lb_vip_t *vip)
Deletes the adjacency associated with the VIP.
Definition: lb.c:808
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:464
#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:527
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:523
ip46_address_t prefix
A Virtual IP represents a given service delivered by a set of application servers.
Definition: lb.h:270
#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:367
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:989
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
#define STRUCT_OFFSET_OF(t, f)
Definition: clib.h:62
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
static void lb_as_stack(lb_as_t *as)
Definition: lb.c:1013
#define lb_vip_get_by_index(index)
Definition: lb.h:542
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:228
u32 vip_index
ASs are indexed by address and VIP Index.
Definition: lb.h:123
#define vec_alloc(V, N)
Allocate space for N more elements (no header, unspecified alignment)
Definition: vec.h:278
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:415
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 const char *const *const lb_dpo_nat4_nodes[DPO_PROTO_NUM]
Definition: lb.c:59
#define LB_MAPPING_BUCKETS
Definition: lb.h:47
#define LB_VIP_FLAGS_USED
Definition: lb.h:295
#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:116
int lb_vip_del_ass_withlock(u32 vip_index, ip46_address_t *addresses, u32 n)
Definition: lb.c:705
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:98
format_function_t format_ip4_address
Definition: format.h:81
#define LB_AS_FLAGS_USED
Definition: lb.h:131
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:443
u8 as_ip_is_ipv6
Definition: lb.h:398
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:156
static bool lb_vip_is_nat4(const lb_vip_t *vip)
Definition: lb.h:326
static lb_as_t * lb_as_from_fib_node(fib_node_t *node)
Definition: lb.c:1006
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
#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:470
A high priority source a plugin can use.
Definition: fib_entry.h:62
Definition: lb.h:418
fib_node_type_t fib_node_type
Node type for registering to fib changes.
Definition: lb.h:489
dpo_type_t dpo_gre4_type
DPO used to send packet from IP4/6 lookup to LB node.
Definition: lb.h:480
Aggregrate type for a prefix.
Definition: fib_types.h:188
static void lb_vip_add_adjacency(lb_main_t *lbm, lb_vip_t *vip)
Add the VIP adjacency to the ip4 or ip6 fib.
Definition: lb.c:766
u16 protocol
Definition: lb.h:368
vlib_refcount_t as_refcount
Each AS has an associated reference counter.
Definition: lb.h:437
lb_vip_encap_args_t encap_args
Definition: lb.h:285
static void lb_vip_garbage_collection(lb_vip_t *vip)
Definition: lb.c:266
u8 * format_lb_main(u8 *s, va_list *args)
Definition: lb.c:75
unsigned int u32
Definition: types.h:88
u8 * format_lb_vip(u8 *s, va_list *args)
Definition: lb.c:130
enum dpo_proto_t_ dpo_proto_t
Data path protocol.
u16 fp_len
The mask length.
Definition: fib_types.h:192
#define lb_vip_is_ip4(vip)
Definition: lb.h:304
vlib_node_registration_t lb6_nodeport_node
(constructor) VLIB_REGISTER_NODE (lb6_nodeport_node)
Definition: node.c:1069
lb_vip_t * vips
Pool of all Virtual IPs.
Definition: lb.h:422
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:142
ip4_address_t ip4_src_address
Source address used for IPv4 encapsulated traffic.
Definition: lb.h:460
Definition: fib_entry.h:275
char * name
The counter collection&#39;s name.
Definition: counter.h:65
u8 plen
The VIP prefix length.
Definition: lb.h:276
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
#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:309
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:464
#define lb_encap_is_ip4(vip)
Definition: lb.h:315
static bool lb_vip_is_nat6(const lb_vip_t *vip)
Definition: lb.h:331
ip46_address_t fp_addr
The address type is not deriveable from the fp_addr member.
Definition: fib_types.h:211
u64 key
the key
Definition: bihash_8_8.h:35
int lb_vip_del(u32 vip_index)
Definition: lb.c:936
u8 * format_lb_vip_type(u8 *s, va_list *args)
Definition: lb.c:108
struct _unformat_input_t unformat_input_t
unsigned short u16
Definition: types.h:57
typedef ip6_address
Definition: ip_types.api:21
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:404
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:274
uword unformat_lb_vip_type(unformat_input_t *input, va_list *args)
Definition: lb.c:118
#define LB_DEFAULT_FLOW_TIMEOUT
Definition: lb.h:46
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:1053
clib_bihash_8_8_t mapping_by_as4
Definition: lb.h:492
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:287
Definition: lb.h:163
fib_node_t fib_node
Registration to FIB event.
Definition: lb.h:108
u8 src_ip_is_ipv6
Definition: lb.h:397
ip46_address_t src_ip
for vip + port case, src_ip = vip; for node ip + node_port, src_ip = node_ip
Definition: lb.h:395
static const char *const lb_dpo_gre6_ip6[]
Definition: lb.c:45
u32 new_length
Definition: lb.h:515
static const dpo_vft_t lb_vft
Definition: load_balance.c:787
#define ip46_prefix_is_ip4(ip46, len)
Definition: util.h:27
static const char *const lb_dpo_nat6_ip6[]
Definition: lb.c:64
#define pool_free(p)
Free a pool.
Definition: pool.h:357
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:36
format_function_t format_ip6_address
Definition: format.h:99
vlib_main_t * vm
Definition: buffer.c:294
u32 vrf_id
Definition: lb.h:406
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:339
volatile u32 * writer_lock
Definition: lb.h:503
#define lb_foreach_vip_counter
Definition: lb.h:167
vlib_main_t * vlib_main
Definition: lb.h:506
fib_node_get_t fnv_get
Definition: fib_node.h:275
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:30
u32 as_index
Definition: lb.h:164
8 octet key, 8 octet key value pair
Definition: bihash_8_8.h:33
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:1038
int lb_vip_del_ass(u32 vip_index, ip46_address_t *addresses, u32 n)
Definition: lb.c:755
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:481
u32 last_garbage_collection
Last time garbage collection was run to free the ASs.
Definition: lb.h:259
lb_as_t * ass
Pool of ASs.
Definition: lb.h:430
uword * vip_index_by_nodeport
Definition: lb.h:440
ip6_address_t addr
Definition: lb.h:381
lb_vip_type_t type
The type of traffic for this.
Definition: lb.h:282
Context passed between object during a back walk.
Definition: fib_node.h:200
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:92
#define ASSERT(truth)
lb_vip_type_t
The load balancer supports IPv4 and IPv6 traffic and GRE4, GRE6, L3DSR and NAT4, NAT6 encap...
Definition: lb.h:193
long ctx[MAX_CONNS]
Definition: main.c:126
u16 target_port
Definition: lb.h:405
int lb_vip_find_index(ip46_address_t *prefix, u8 plen, u32 *vip_index)
Definition: lb.c:500
u8 * format_lb_as(u8 *s, va_list *args)
Definition: lb.c:160
ip46_address_t prefix
Definition: lb.h:512
u32 new_flow_table_mask
New flows table length - 1 (length MUST be a power of 2)
Definition: lb.h:254
static const char *const lb_dpo_nat4_ip4[]
Definition: lb.c:58
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:124
size_t count
Definition: vapi.c:46
lb_vip_encap_args_t encap_args
Definition: lb.h:516
lb_per_cpu_t * per_cpu
Some global data is per-cpu.
Definition: lb.h:445
static void lb_dpo_unlock(dpo_id_t *dpo)
Definition: lb.c:990
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:23
static uword is_pow2(uword x)
Definition: clib.h:229
u16 target_port
Definition: lb.h:221
u32 as_index
Definition: lb.c:252
vlib_simple_counter_main_t vip_counters[LB_N_VIP_COUNTERS]
Per VIP counter.
Definition: lb.h:475
int lb_nat6_interface_add_del(u32 sw_if_index, int is_del)
Definition: lb.c:1061
int lb_vip_add(lb_vip_add_args_t args, u32 *vip_index)
Definition: lb.c:823
static const char *const lb_dpo_gre4_ip6[]
Definition: lb.c:37
#define DPO_PROTO_NUM
Definition: dpo.h:70
ip6_address_t ip6_src_address
Source address used in IPv6 encapsulated traffic.
Definition: lb.h:455
u8 * format_lb_vip_detailed(u8 *s, va_list *args)
Definition: lb.c:168
#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:993
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:982
lb_snat_mapping_t * snat_mappings
Definition: lb.h:496
#define DPO_INVALID
An initialiser for DPOs declared on the stack.
Definition: dpo.h:195
void lb_garbage_collection()
Definition: lb.c:335
u16 port
Definition: lb.h:382
typedef prefix
Definition: ip_types.api:40
static int lb_vip_find_index_with_lock(ip46_address_t *prefix, u8 plen, u32 *vip_index)
Definition: lb.c:482
u32 next_hop_child_index
The child index on the FIB entry.
Definition: lb.h:152
dpo_type_t dpo_l3dsr_type
Definition: lb.h:482
#define hash_get_mem(h, key)
Definition: hash.h:269
A FIB graph nodes virtual function table.
Definition: fib_node.h:274
typedef ip4_address
Definition: ip_types.api:17
static void * clib_mem_alloc_aligned(uword size, uword align)
Definition: mem.h:120
u32 fib_index
Definition: lb.h:407
static vlib_thread_main_t * vlib_get_thread_main()
Definition: global_funcs.h:32
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:383
dpo_id_t dpo
The next DPO in the graph to follow.
Definition: lb.h:157
static const char *const lb_dpo_l3dsr_ip4[]
Definition: lb.c:52
u8 flags
Some per-AS flags.
Definition: lb.h:129
dpo_type_t dpo_nat4_type
Definition: lb.h:483
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:366
clib_bihash_24_8_t mapping_by_as6
Definition: lb.h:493
lb_new_flow_entry_t * new_flow_table
Vector mapping (flow-hash & new_connect_table_mask) to AS index.
Definition: lb.h:248
static const char *const *const lb_dpo_l3dsr_nodes[DPO_PROTO_NUM]
Definition: lb.c:53
u8 flags
Flags related to this VIP.
Definition: lb.h:294
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:62
lb_vip_type_t type
Definition: lb.h:514
static char * lb_vip_type_strings[]
Definition: lb.c:98
u8 * format_lb_dpo(u8 *s, va_list *va)
Definition: lb.c:980
ip46_address_t as_ip
Definition: lb.h:396
Load balancing service is provided per VIP.
Definition: lb.h:240
u32 * as_indexes
Pool of AS indexes used for this VIP.
Definition: lb.h:301
u16 fib_index
Definition: lb.h:368
#define lb_hash_size(h)
Definition: lbhash.h:65
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:233
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
dpo_type_t dpo_nat6_type
Definition: lb.h:484
fib_node_index_t next_hop_fib_entry_index
The FIB entry index for the next-hop.
Definition: lb.h:147
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