FD.io VPP  v18.01.2-1-g9b554f3
Vector Packet Processing
kp.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Intel 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 anated to in writing, software
10  * distributed under the License is distributed on an "POD IS" BPODIS,
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 <kubeproxy/kp.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 KP_GARBAGE_RUN 60
24 
25 //After so many seconds. It is assumed that inter-core race condition will not occur.
26 #define KP_CONCURRENCY_TIMEOUT 10
27 
29 
30 #define kp_get_writer_lock() do {} while(__sync_lock_test_and_set (kp_main.writer_lock, 1))
31 #define kp_put_writer_lock() kp_main.writer_lock[0] = 0
32 
33 static void kp_pod_stack (kp_pod_t *pod);
34 
35 void ip46_prefix_normalize(ip46_address_t *prefix, u8 plen)
36 {
37  if (plen == 0) {
38  prefix->as_u64[0] = 0;
39  prefix->as_u64[1] = 0;
40  } else if (plen <= 64) {
41  prefix->as_u64[0] &= clib_host_to_net_u64(0xffffffffffffffffL << (64 - plen));
42  prefix->as_u64[1] = 0;
43  } else {
44  prefix->as_u64[1] &= clib_host_to_net_u64(0xffffffffffffffffL << (128 - plen));
45  }
46 
47 }
48 
49 uword unformat_ip46_prefix (unformat_input_t * input, va_list * args)
50 {
51  ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
52  u8 *len = va_arg (*args, u8 *);
53  ip46_type_t type = va_arg (*args, ip46_type_t);
54 
55  u32 l;
56  if ((type != IP46_TYPE_IP6) && unformat(input, "%U/%u", unformat_ip4_address, &ip46->ip4, &l)) {
57  if (l > 32)
58  return 0;
59  *len = l + 96;
60  ip46->pad[0] = ip46->pad[1] = ip46->pad[2] = 0;
61  } else if ((type != IP46_TYPE_IP4) && unformat(input, "%U/%u", unformat_ip6_address, &ip46->ip6, &l)) {
62  if (l > 128)
63  return 0;
64  *len = l;
65  } else {
66  return 0;
67  }
68  return 1;
69 }
70 
71 u8 *format_ip46_prefix (u8 * s, va_list * args)
72 {
73  ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
74  u32 len = va_arg (*args, u32); //va_arg cannot use u8 or u16
75  ip46_type_t type = va_arg (*args, ip46_type_t);
76 
77  int is_ip4 = 0;
78  if (type == IP46_TYPE_IP4)
79  is_ip4 = 1;
80  else if (type == IP46_TYPE_IP6)
81  is_ip4 = 0;
82  else
83  is_ip4 = (len >= 96) && ip46_address_is_ip4(ip46);
84 
85  return is_ip4 ?
86  format(s, "%U/%d", format_ip4_address, &ip46->ip4, len - 96):
87  format(s, "%U/%d", format_ip6_address, &ip46->ip6, len);
88 }
89 
90 const static char * const kp_dpo_nat4_ip4[] = { "kp4-nat4" , NULL };
91 const static char * const kp_dpo_nat4_ip6[] = { "kp6-nat4" , NULL };
92 const static char* const * const kp_dpo_nat4_nodes[DPO_PROTO_NUM] =
93  {
96  };
97 
98 const static char * const kp_dpo_nat6_ip4[] = { "kp4-nat6" , NULL };
99 const static char * const kp_dpo_nat6_ip6[] = { "kp6-nat6" , NULL };
100 const static char* const * const kp_dpo_nat6_nodes[DPO_PROTO_NUM] =
101  {
104  };
105 
107 {
108  return (u32) (vlib_time_now(vm) + 10000);
109 }
110 
111 u8 *format_kp_main (u8 * s, va_list * args)
112 {
114  kp_main_t *kpm = &kp_main;
115  s = format(s, "kp_main");
116  s = format(s, " #vips: %u\n", pool_elts(kpm->vips));
117  s = format(s, " #pods: %u\n", pool_elts(kpm->pods) - 1);
118 
119  u32 thread_index;
120  for(thread_index = 0; thread_index < tm->n_vlib_mains; thread_index++ ) {
121  kp_hash_t *h = kpm->per_cpu[thread_index].sticky_ht;
122  if (h) {
123  s = format(s, "core %d\n", thread_index);
124  s = format(s, " timeout: %ds\n", h->timeout);
125  s = format(s, " usage: %d / %d\n", kp_hash_elts(h, kp_hash_time_now(vlib_get_main())), kp_hash_size(h));
126  }
127  }
128 
129  return s;
130 }
131 
132 static char *kp_vip_type_strings[] = {
133  [KP_VIP_TYPE_IP4_NAT44] = "ip4-nat44",
134  [KP_VIP_TYPE_IP4_NAT46] = "ip4-nat46",
135  [KP_VIP_TYPE_IP6_NAT64] = "ip6-nat64",
136  [KP_VIP_TYPE_IP6_NAT66] = "ip6-nat66",
137 };
138 
139 u8 *format_kp_vip_type (u8 * s, va_list * args)
140 {
141  kp_vip_type_t vipt = va_arg (*args, kp_vip_type_t);
142  u32 i;
143  for (i=0; i<KP_VIP_N_TYPES; i++)
144  if (vipt == i)
145  return format(s, kp_vip_type_strings[i]);
146  return format(s, "_WRONG_TYPE_");
147 }
148 
149 uword unformat_kp_vip_type (unformat_input_t * input, va_list * args)
150 {
151  kp_vip_type_t *vipt = va_arg (*args, kp_vip_type_t *);
152  u32 i;
153  for (i=0; i<KP_VIP_N_TYPES; i++)
154  if (unformat(input, kp_vip_type_strings[i])) {
155  *vipt = i;
156  return 1;
157  }
158  return 0;
159 }
160 
161 u8 *format_kp_vip (u8 * s, va_list * args)
162 {
163  kp_vip_t *vip = va_arg (*args, kp_vip_t *);
164  return format(s, "%U %U port:%u target_port:%u node_port:%u "
165  "new_size:%u #pod:%u%s",
166  format_kp_vip_type, vip->type,
168  ntohs(vip->port), ntohs(vip->target_port),
169  ntohs(vip->node_port),
170  vip->new_flow_table_mask + 1,
171  pool_elts(vip->pod_indexes),
172  (vip->flags & KP_VIP_FLAGS_USED)?"":" removed");
173 }
174 
175 u8 *format_kp_pod (u8 * s, va_list * args)
176 {
177  kp_pod_t *pod = va_arg (*args, kp_pod_t *);
178  return format(s, "%U %s", format_ip46_address,
179  &pod->address, IP46_TYPE_ANY,
180  (pod->flags & KP_POD_FLAGS_USED)?"used":"removed");
181 }
182 
183 u8 *format_kp_vip_detailed (u8 * s, va_list * args)
184 {
185  kp_main_t *kpm = &kp_main;
186  kp_vip_t *vip = va_arg (*args, kp_vip_t *);
187  uword indent = format_get_indent (s);
188 
189  s = format(s, "%U %U [%u] %U port:%u target_port:%u node_port:%u%s\n"
190  "%U new_size:%u\n",
191  format_white_space, indent,
192  format_kp_vip_type, vip->type,
193  vip - kpm->vips, format_ip46_prefix, &vip->prefix, vip->plen, IP46_TYPE_ANY,
194  ntohs(vip->port), ntohs(vip->target_port),
195  ntohs(vip->node_port),
196  (vip->flags & KP_VIP_FLAGS_USED)?"":" removed",
197  format_white_space, indent,
198  vip->new_flow_table_mask + 1);
199 
200  //Print counters
201  s = format(s, "%U counters:\n",
202  format_white_space, indent);
203  u32 i;
204  for (i=0; i<KP_N_VIP_COUNTERS; i++)
205  s = format(s, "%U %s: %d\n",
206  format_white_space, indent,
207  kpm->vip_counters[i].name,
208  vlib_get_simple_counter(&kpm->vip_counters[i], vip - kpm->vips));
209 
210 
211  s = format(s, "%U #pod:%u\n",
212  format_white_space, indent,
213  pool_elts(vip->pod_indexes));
214 
215  //Let's count the buckets for each POD
216  u32 *count = 0;
217  vec_validate(count, pool_len(kpm->pods)); //Possibly big alloc for not much...
218  kp_new_flow_entry_t *nfe;
219  vec_foreach(nfe, vip->new_flow_table)
220  count[nfe->pod_index]++;
221 
222  kp_pod_t *pod;
223  u32 *pod_index;
224  pool_foreach(pod_index, vip->pod_indexes, {
225  pod = &kpm->pods[*pod_index];
226  s = format(s, "%U %U %d buckets %d flows dpo:%u %s\n",
227  format_white_space, indent,
228  format_ip46_address, &pod->address, IP46_TYPE_ANY,
229  count[pod - kpm->pods],
230  vlib_refcount_get(&kpm->pod_refcount, pod - kpm->pods),
231  pod->dpo.dpoi_index,
232  (pod->flags & KP_POD_FLAGS_USED)?"used":" removed");
233  });
234 
235  vec_free(count);
236 
237  /*
238  s = format(s, "%U new flows table:\n", format_white_space, indent);
239  kp_new_flow_entry_t *nfe;
240  vec_foreach(nfe, vip->new_flow_table) {
241  s = format(s, "%U %d: %d\n", format_white_space, indent, nfe - vip->new_flow_table, nfe->pod_index);
242  }
243  */
244  return s;
245 }
246 
247 typedef struct {
252 
253 static int kp_pseudorand_compare(void *a, void *b)
254 {
255  kp_pod_t *poda, *podb;
256  kp_main_t *kpm = &kp_main;
257  poda = &kpm->pods[((kp_pseudorand_t *)a)->pod_index];
258  podb = &kpm->pods[((kp_pseudorand_t *)b)->pod_index];
259  return memcmp(&poda->address, &podb->address, sizeof(podb->address));
260 }
261 
263 {
264  kp_main_t *kpm = &kp_main;
265  ASSERT (kpm->writer_lock[0]);
266 
267  u32 now = (u32) vlib_time_now(vlib_get_main());
269  return;
270 
271  vip->last_garbage_collection = now;
272  kp_pod_t *pod;
273  u32 *pod_index;
274  pool_foreach(pod_index, vip->pod_indexes, {
275  pod = &kpm->pods[*pod_index];
276  if (!(pod->flags & KP_POD_FLAGS_USED) && //Not used
277  clib_u32_loop_gt(now, pod->last_used + KP_CONCURRENCY_TIMEOUT) && //Not recently used
278  (vlib_refcount_get(&kpm->pod_refcount, pod - kpm->pods) == 0))
279  { //Not referenced
280  fib_entry_child_remove(pod->next_hop_fib_entry_index,
281  pod->next_hop_child_index);
282  fib_table_entry_delete_index(pod->next_hop_fib_entry_index,
283  FIB_SOURCE_RR);
284  pod->next_hop_fib_entry_index = FIB_NODE_INDEX_INVALID;
285 
286  pool_put(vip->pod_indexes, pod_index);
287  pool_put(kpm->pods, pod);
288  }
289  });
290 }
291 
293 {
294  kp_main_t *kpm = &kp_main;
296  kp_vip_t *vip;
297  u32 *to_be_removed_vips = 0, *i;
298  pool_foreach(vip, kpm->vips, {
299  kp_vip_garbage_collection(vip);
300 
301  if (!(vip->flags & KP_VIP_FLAGS_USED) &&
302  (pool_elts(vip->pod_indexes) == 0)) {
303  vec_add1(to_be_removed_vips, vip - kpm->vips);
304  }
305  });
306 
307  vec_foreach(i, to_be_removed_vips) {
308  vip = &kpm->vips[*i];
309  pool_put(kpm->vips, vip);
310  pool_free(vip->pod_indexes);
311  }
312 
313  vec_free(to_be_removed_vips);
315 }
316 
318 {
319  kp_main_t *kpm = &kp_main;
320  kp_new_flow_entry_t *old_table;
321  u32 i, *pod_index;
322  kp_new_flow_entry_t *new_flow_table = 0;
323  kp_pod_t *pod;
324  kp_pseudorand_t *pr, *sort_arr = 0;
325  u32 count;
326 
327  ASSERT (kpm->writer_lock[0]); //We must have the lock
328 
329  //Check if some POD is configured or not
330  i = 0;
331  pool_foreach(pod_index, vip->pod_indexes, {
332  pod = &kpm->pods[*pod_index];
333  if (pod->flags & KP_POD_FLAGS_USED) { //Not used anymore
334  i = 1;
335  goto out; //Not sure 'break' works in this macro-loop
336  }
337  });
338 
339 out:
340  if (i == 0) {
341  //Only the default. i.e. no POD
342  vec_validate(new_flow_table, vip->new_flow_table_mask);
343  for (i=0; i<vec_len(new_flow_table); i++)
344  new_flow_table[i].pod_index = 0;
345 
346  goto finished;
347  }
348 
349  //First, let's sort the PODs
350  sort_arr = 0;
351  vec_alloc(sort_arr, pool_elts(vip->pod_indexes));
352 
353  i = 0;
354  pool_foreach(pod_index, vip->pod_indexes, {
355  pod = &kpm->pods[*pod_index];
356  if (!(pod->flags & KP_POD_FLAGS_USED)) //Not used anymore
357  continue;
358 
359  sort_arr[i].pod_index = pod - kpm->pods;
360  i++;
361  });
362  _vec_len(sort_arr) = i;
363 
365 
366  //Now let's pseudo-randomly generate permutations
367  vec_foreach(pr, sort_arr) {
368  kp_pod_t *pod = &kpm->pods[pr->pod_index];
369 
370  u64 seed = clib_xxhash(pod->address.as_u64[0] ^
371  pod->address.as_u64[1]);
372  /* We have 2^n buckets.
373  * skip must be prime with 2^n.
374  * So skip must be odd.
375  * MagLev actually state that M should be prime,
376  * but this has a big computation cost (% operation).
377  * Using 2^n is more better (& operation).
378  */
379  pr->skip = ((seed & 0xffffffff) | 1) & vip->new_flow_table_mask;
380  pr->last = (seed >> 32) & vip->new_flow_table_mask;
381  }
382 
383  //Let's create a new flow table
384  vec_validate(new_flow_table, vip->new_flow_table_mask);
385  for (i=0; i<vec_len(new_flow_table); i++)
386  new_flow_table[i].pod_index = ~0;
387 
388  u32 done = 0;
389  while (1) {
390  vec_foreach(pr, sort_arr) {
391  while (1) {
392  u32 last = pr->last;
393  pr->last = (pr->last + pr->skip) & vip->new_flow_table_mask;
394  if (new_flow_table[last].pod_index == ~0) {
395  new_flow_table[last].pod_index = pr->pod_index;
396  break;
397  }
398  }
399  done++;
400  if (done == vec_len(new_flow_table))
401  goto finished;
402  }
403  }
404 
405  vec_free(sort_arr);
406 
407 finished:
408 
409 //Count number of changed entries
410  count = 0;
411  for (i=0; i<vec_len(new_flow_table); i++)
412  if (vip->new_flow_table == 0 ||
413  new_flow_table[i].pod_index != vip->new_flow_table[i].pod_index)
414  count++;
415 
416  old_table = vip->new_flow_table;
417  vip->new_flow_table = new_flow_table;
418  vec_free(old_table);
419 }
420 
421 int kp_conf(u32 per_cpu_sticky_buckets, u32 flow_timeout)
422 {
423  kp_main_t *kpm = &kp_main;
424 
425  if (!is_pow2(per_cpu_sticky_buckets))
426  return VNET_API_ERROR_INVALID_MEMORY_SIZE;
427 
428  kp_get_writer_lock(); //Not exactly necessary but just a reminder that it exists for my future self
429  kpm->per_cpu_sticky_buckets = per_cpu_sticky_buckets;
430  kpm->flow_timeout = flow_timeout;
432  return 0;
433 }
434 
435 static
436 int kp_vip_find_index_with_lock(ip46_address_t *prefix, u8 plen, u32 *vip_index)
437 {
438  kp_main_t *kpm = &kp_main;
439  kp_vip_t *vip;
440  ASSERT (kpm->writer_lock[0]); //This must be called with the lock owned
441  ip46_prefix_normalize(prefix, plen);
442  pool_foreach(vip, kpm->vips, {
443  if ((vip->flags & KP_POD_FLAGS_USED) &&
444  vip->plen == plen &&
445  vip->prefix.as_u64[0] == prefix->as_u64[0] &&
446  vip->prefix.as_u64[1] == prefix->as_u64[1]) {
447  *vip_index = vip - kpm->vips;
448  return 0;
449  }
450  });
451  return VNET_API_ERROR_NO_SUCH_ENTRY;
452 }
453 
454 int kp_vip_find_index(ip46_address_t *prefix, u8 plen, u32 *vip_index)
455 {
456  int ret;
458  ret = kp_vip_find_index_with_lock(prefix, plen, vip_index);
460  return ret;
461 }
462 
463 static int kp_pod_find_index_vip(kp_vip_t *vip, ip46_address_t *address, u32 *pod_index)
464 {
465  kp_main_t *kpm = &kp_main;
466  ASSERT (kpm->writer_lock[0]); //This must be called with the lock owned
467  kp_pod_t *pod;
468  u32 *podi;
469  pool_foreach(podi, vip->pod_indexes, {
470  pod = &kpm->pods[*podi];
471  if (pod->vip_index == (vip - kpm->vips) &&
472  pod->address.as_u64[0] == address->as_u64[0] &&
473  pod->address.as_u64[1] == address->as_u64[1]) {
474  *pod_index = pod - kpm->pods;
475  return 0;
476  }
477  });
478  return -1;
479 }
480 
481 int kp_vip_add_pods(u32 vip_index, ip46_address_t *addresses, u32 n)
482 {
483  kp_main_t *kpm = &kp_main;
485  kp_vip_t *vip;
486  if (!(vip = kp_vip_get_by_index(vip_index))) {
488  return VNET_API_ERROR_NO_SUCH_ENTRY;
489  }
490 
492  u32 *to_be_added = 0;
493  u32 *to_be_updated = 0;
494  u32 i;
495  u32 *ip;
497  kp_snat4_key_t m_key4;
499 
500  //Sanity check
501  while (n--) {
502 
503  if (!kp_pod_find_index_vip(vip, &addresses[n], &i)) {
504  if (kpm->pods[i].flags & KP_POD_FLAGS_USED) {
505  vec_free(to_be_added);
506  vec_free(to_be_updated);
508  return VNET_API_ERROR_VALUE_EXIST;
509  }
510  vec_add1(to_be_updated, i);
511  goto next;
512  }
513 
514  if (ip46_address_type(&addresses[n]) != type) {
515  vec_free(to_be_added);
516  vec_free(to_be_updated);
518  return VNET_API_ERROR_INVALID_ADDRESS_FAMILY;
519  }
520 
521  if (n) {
522  u32 n2 = n;
523  while(n2--) //Check for duplicates
524  if (addresses[n2].as_u64[0] == addresses[n].as_u64[0] &&
525  addresses[n2].as_u64[1] == addresses[n].as_u64[1])
526  goto next;
527  }
528 
529  vec_add1(to_be_added, n);
530 
531 next:
532  continue;
533  }
534 
535  //Update reused PODs
536  vec_foreach(ip, to_be_updated) {
537  kpm->pods[*ip].flags = KP_POD_FLAGS_USED;
538  }
539  vec_free(to_be_updated);
540 
541  //Create those who have to be created
542  vec_foreach(ip, to_be_added) {
543  kp_pod_t *pod;
544  u32 *pod_index;
545  pool_get(kpm->pods, pod);
546  pod->address = addresses[*ip];
547  pod->flags = KP_POD_FLAGS_USED;
548  pod->vip_index = vip_index;
549  pool_get(vip->pod_indexes, pod_index);
550  *pod_index = pod - kpm->pods;
551 
552  /*
553  * become a child of the FIB entry
554  * so we are informed when its forwarding changes
555  */
556  fib_prefix_t nh = {};
557  if (kp_vip_is_nat4(vip)) {
558  nh.fp_addr.ip4 = pod->address.ip4;
559  nh.fp_len = 32;
561  } else {
562  nh.fp_addr.ip6 = pod->address.ip6;
563  nh.fp_len = 128;
565  }
566 
569  &nh,
572  pod->next_hop_child_index =
574  kpm->fib_node_type,
575  pod - kpm->pods);
576 
577  kp_pod_stack(pod);
578 
579  /* Add SNAT static mapping */
580  pool_get (kpm->snat_mappings, m);
581  memset (m, 0, sizeof (*m));
582  if (kp_vip_is_nat4(vip)) {
583  m_key4.addr = pod->address.ip4;
584  m_key4.port = vip->target_port;
585  m_key4.protocol = 0;
586  m_key4.fib_index = 0;
587 
588  m->vip.ip4 = vip->prefix.ip4;;
589  m->node_ip.ip4.as_u32 = 0;
590  m->pod_ip.ip4 = pod->address.ip4;
591  m->vip_is_ipv6 = 0;
592  m->node_ip_is_ipv6 = 0;
593  m->pod_ip_is_ipv6 = 0;
594  m->port = vip->port;
595  m->node_port = vip->node_port;
596  m->target_port = vip->target_port;
597  m->vrf_id = 0;
598  m->fib_index = 0;
599 
600  kv.key = m_key4.as_u64;
601  kv.value = m - kpm->snat_mappings;
602  clib_bihash_add_del_8_8(&kpm->mapping_by_pod, &kv, 1);
603  } else {
604  /* TBD */
605  }
606 
607  }
608  vec_free(to_be_added);
609 
610  //Recompute flows
612 
613  //Garbage collection maybe
615 
617  return 0;
618 }
619 
620 int kp_vip_del_pods_withlock(u32 vip_index, ip46_address_t *addresses, u32 n)
621 {
622  kp_main_t *kpm = &kp_main;
623  u32 now = (u32) vlib_time_now(vlib_get_main());
624  u32 *ip = 0;
625 
626  kp_vip_t *vip;
627  if (!(vip = kp_vip_get_by_index(vip_index))) {
628  return VNET_API_ERROR_NO_SUCH_ENTRY;
629  }
630 
631  u32 *indexes = NULL;
632  while (n--) {
633  u32 i;
634  if (kp_pod_find_index_vip(vip, &addresses[n], &i)) {
635  vec_free(indexes);
636  return VNET_API_ERROR_NO_SUCH_ENTRY;
637  }
638 
639  if (n) { //Check for duplicates
640  u32 n2 = n - 1;
641  while(n2--) {
642  if (addresses[n2].as_u64[0] == addresses[n].as_u64[0] &&
643  addresses[n2].as_u64[1] == addresses[n].as_u64[1])
644  goto next;
645  }
646  }
647 
648  vec_add1(indexes, i);
649 next:
650  continue;
651  }
652 
653  //Garbage collection maybe
655 
656  if (indexes != NULL) {
657  vec_foreach(ip, indexes) {
658  kpm->pods[*ip].flags &= ~KP_POD_FLAGS_USED;
659  kpm->pods[*ip].last_used = now;
660  }
661 
662  //Recompute flows
664  }
665 
666  vec_free(indexes);
667  return 0;
668 }
669 
670 int kp_vip_del_pods(u32 vip_index, ip46_address_t *addresses, u32 n)
671 {
673  int ret = kp_vip_del_pods_withlock(vip_index, addresses, n);
675  return ret;
676 }
677 
678 /**
679  * Add the VIP adjacency to the ip4 or ip6 fib
680  */
681 static void kp_vip_add_adjacency(kp_main_t *kpm, kp_vip_t *vip)
682 {
683  dpo_proto_t proto = 0;
684  dpo_id_t dpo = DPO_INVALID;
685  fib_prefix_t pfx = {};
686  if (kp_vip_is_ip4(vip)) {
687  pfx.fp_addr.ip4 = vip->prefix.ip4;
688  pfx.fp_len = vip->plen - 96;
690  proto = DPO_PROTO_IP4;
691  } else {
692  pfx.fp_addr.ip6 = vip->prefix.ip6;
693  pfx.fp_len = vip->plen;
695  proto = DPO_PROTO_IP6;
696  }
697  dpo_set(&dpo, kp_vip_is_nat4(vip)?kpm->dpo_nat4_type:kpm->dpo_nat6_type,
698  proto, vip - kpm->vips);
700  &pfx,
703  &dpo);
704  dpo_reset(&dpo);
705 }
706 
707 /**
708  * Deletes the adjacency podsociated with the VIP
709  */
710 static void kp_vip_del_adjacency(kp_main_t *kpm, kp_vip_t *vip)
711 {
712  fib_prefix_t pfx = {};
713  if (kp_vip_is_ip4(vip)) {
714  pfx.fp_addr.ip4 = vip->prefix.ip4;
715  pfx.fp_len = vip->plen - 96;
717  } else {
718  pfx.fp_addr.ip6 = vip->prefix.ip6;
719  pfx.fp_len = vip->plen;
721  }
723 }
724 
725 int kp_vip_add(ip46_address_t *prefix, u8 plen, kp_vip_type_t type,
726  u32 new_length, u32 *vip_index,
727  u16 port, u16 target_port, u16 node_port)
728 {
729  kp_main_t *kpm = &kp_main;
730  vlib_main_t *vm = kpm->vlib_main;
731  kp_vip_t *vip;
732  u32 key, *key_copy;
733  uword * entry;
734 
736  ip46_prefix_normalize(prefix, plen);
737 
738  if (!kp_vip_find_index_with_lock(prefix, plen, vip_index)) {
740  return VNET_API_ERROR_VALUE_EXIST;
741  }
742 
743  if (!is_pow2(new_length)) {
745  return VNET_API_ERROR_INVALID_MEMORY_SIZE;
746  }
747 
748  if (ip46_prefix_is_ip4(prefix, plen) &&
749  (type != KP_VIP_TYPE_IP4_NAT44) &&
750  (type != KP_VIP_TYPE_IP4_NAT46)) {
752  return VNET_API_ERROR_INVALID_ADDRESS_FAMILY;
753  }
754 
755 
756  //Allocate
757  pool_get(kpm->vips, vip);
758 
759  //Init
760  vip->prefix = *prefix;
761  vip->plen = plen;
762  vip->port = clib_host_to_net_u16(port);
763  vip->target_port = clib_host_to_net_u16(target_port);
764  vip->node_port = clib_host_to_net_u16(node_port);
766  vip->type = type;
767  vip->flags = KP_VIP_FLAGS_USED;
768  vip->pod_indexes = 0;
769 
770  //Validate counters
771  u32 i;
772  for (i = 0; i < KP_N_VIP_COUNTERS; i++) {
773  vlib_validate_simple_counter(&kpm->vip_counters[i], vip - kpm->vips);
774  vlib_zero_simple_counter(&kpm->vip_counters[i], vip - kpm->vips);
775  }
776 
777  //Configure new flow table
778  vip->new_flow_table_mask = new_length - 1;
779  vip->new_flow_table = 0;
780 
781  //Create a new flow hash table full of the default entry
783 
784  //Create adjacency to direct traffic
785  kp_vip_add_adjacency(kpm, vip);
786 
787  //Create maping from nodeport to vip_index
788  key = clib_host_to_net_u16(node_port);
789  entry = hash_get_mem (kpm->nodeport_by_key, &key);
790  if (entry) {
792  return VNET_API_ERROR_VALUE_EXIST;
793  }
794 
795  key_copy = clib_mem_alloc (sizeof (*key_copy));
796  clib_memcpy (key_copy, &key, sizeof (*key_copy));
797  hash_set_mem (kpm->nodeport_by_key, key_copy, vip - kpm->vips);
798 
799  /* receive packets destined to NodeIP:NodePort */
800  udp_register_dst_port (vm, node_port, kp4_nodeport_node.index, 1);
801  udp_register_dst_port (vm, node_port, kp6_nodeport_node.index, 0);
802 
803  //Return result
804  *vip_index = vip - kpm->vips;
805 
807  return 0;
808 }
809 
810 int kp_vip_del(u32 vip_index)
811 {
812  kp_main_t *kpm = &kp_main;
813  kp_vip_t *vip;
815  if (!(vip = kp_vip_get_by_index(vip_index))) {
817  return VNET_API_ERROR_NO_SUCH_ENTRY;
818  }
819 
820  //FIXME: This operation is actually not working
821  //We will need to remove state before performing this.
822 
823  {
824  //Remove all PODs
825  ip46_address_t *pods = 0;
826  kp_pod_t *pod;
827  u32 *pod_index;
828  pool_foreach(pod_index, vip->pod_indexes, {
829  pod = &kpm->pods[*pod_index];
830  vec_add1(pods, pod->address);
831  });
832  if (vec_len(pods))
833  kp_vip_del_pods_withlock(vip_index, pods, vec_len(pods));
834  vec_free(pods);
835  }
836 
837  //Delete adjacency
838  kp_vip_del_adjacency(kpm, vip);
839 
840  //Set the VIP pod unused
841  vip->flags &= ~KP_VIP_FLAGS_USED;
842 
844  return 0;
845 }
846 
847 /* *INDENT-OFF* */
849  .version = VPP_BUILD_VER,
850  .description = "kube-proxy data plane",
851 };
852 /* *INDENT-ON* */
853 
854 u8 *format_kp_dpo (u8 * s, va_list * va)
855 {
856  index_t index = va_arg (*va, index_t);
857  CLIB_UNUSED(u32 indent) = va_arg (*va, u32);
858  kp_main_t *kpm = &kp_main;
859  kp_vip_t *vip = pool_elt_at_index (kpm->vips, index);
860  return format (s, "%U", format_kp_vip, vip);
861 }
862 
863 static void kp_dpo_lock (dpo_id_t *dpo) {}
864 static void kp_dpo_unlock (dpo_id_t *dpo) {}
865 
866 static fib_node_t *
868 {
869  kp_main_t *kpm = &kp_main;
870  kp_pod_t *pod = pool_elt_at_index (kpm->pods, index);
871  return (&pod->fib_node);
872 }
873 
874 static void
876 {
877 }
878 
879 static kp_pod_t *
881 {
882  return ((kp_pod_t*)(((char*)node) -
883  STRUCT_OFFSET_OF(kp_pod_t, fib_node)));
884 }
885 
886 static void
888 {
889  kp_main_t *kpm = &kp_main;
890  kp_vip_t *vip = &kpm->vips[pod->vip_index];
893  &pod->dpo,
896 }
897 
901 {
904 }
905 
906 int kp_nat4_interface_add_del (u32 sw_if_index, int is_del)
907 {
908  if (is_del)
909  {
910  vnet_feature_enable_disable ("ip4-unicast", "kp-nat4-in2out",
911  sw_if_index, 0, 0, 0);
912  }
913  else
914  {
915  vnet_feature_enable_disable ("ip4-unicast", "kp-nat4-in2out",
916  sw_if_index, 1, 0, 0);
917  }
918 
919  return 0;
920 }
921 
922 clib_error_t *
924 {
926  kp_main_t *kpm = &kp_main;
927  kpm->vnet_main = vnet_get_main ();
928  kpm->vlib_main = vm;
929 
930  kp_pod_t *default_pod;
931  fib_node_vft_t kp_fib_node_vft = {
933  .fnv_last_lock = kp_fib_node_last_lock_gone,
934  .fnv_back_walk = kp_fib_node_back_walk_notify,
935  };
936  dpo_vft_t kp_vft = {
937  .dv_lock = kp_dpo_lock,
938  .dv_unlock = kp_dpo_unlock,
939  .dv_format = format_kp_dpo,
940  };
941 
942  kpm->vips = 0;
943  kpm->per_cpu = 0;
944  vec_validate(kpm->per_cpu, tm->n_vlib_mains - 1);
946  kpm->writer_lock[0] = 0;
951  kpm->fib_node_type = fib_node_register_new_type(&kp_fib_node_vft);
952 
953  //Init POD reference counters
955 
956  //Allocate and init default POD.
957  kpm->pods = 0;
958  pool_get(kpm->pods, default_pod);
959  default_pod->flags = 0;
960  default_pod->dpo.dpoi_next_node = KP_NEXT_DROP;
961  default_pod->vip_index = ~0;
962  default_pod->address.ip6.as_u64[0] = 0xffffffffffffffffL;
963  default_pod->address.ip6.as_u64[1] = 0xffffffffffffffffL;
964 
965  kpm->nodeport_by_key
966  = hash_create_mem (0, sizeof(u16), sizeof (uword));
967 
968  clib_bihash_init_8_8 (&kpm->mapping_by_pod,
969  "mapping_by_pod", KP_MAPPING_BUCKETS,
971 
972 #define _(a,b,c) kpm->vip_counters[c].name = b;
974 #undef _
975  return NULL;
976 }
977 
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:432
fib_protocol_t fp_proto
protocol type
Definition: fib_types.h:181
static void kp_pod_stack(kp_pod_t *pod)
Definition: kp.c:887
dpo_lock_fn_t dv_lock
A reference counting lock function.
Definition: dpo.h:382
Recursive resolution source.
Definition: fib_entry.h:117
sll srl srl sll sra u16x4 i
Definition: vector_sse2.h:337
u8 * format_ip46_prefix(u8 *s, va_list *args)
Definition: kp.c:71
#define CLIB_UNUSED(x)
Definition: clib.h:79
A virtual function table regisitered for a DPO type.
Definition: dpo.h:377
ip46_type_t
Definition: format.h:63
u8 vip_is_ipv6
Definition: kp.h:333
a
Definition: bitmap.h:516
static const char *const *const kp_dpo_nat6_nodes[DPO_PROTO_NUM]
Definition: kp.c:100
ip46_address_t pod_ip
Definition: kp.h:332
vlib_refcount_t pod_refcount
Each POD has an associated reference counter.
Definition: kp.h:371
vnet_main_t * vnet_get_main(void)
Definition: misc.c:47
u32 pod_index
Definition: kp.h:151
static void kp_vip_update_new_flow_table(kp_vip_t *vip)
Definition: kp.c:317
u16 protocol
Definition: kp.h:313
#define kp_vip_is_nat4(vip)
Definition: kp.h:279
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:503
int kp_vip_del_pods_withlock(u32 vip_index, ip46_address_t *addresses, u32 n)
Definition: kp.c:620
uword * nodeport_by_key
Definition: kp.h:374
#define NULL
Definition: clib.h:55
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:224
vlib_simple_counter_main_t vip_counters[KP_N_VIP_COUNTERS]
Per VIP counter.
Definition: kp.h:400
static const char *const kp_dpo_nat6_ip6[]
Definition: kp.c:99
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:459
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:518
#define KP_POD_FLAGS_USED
Definition: kp.h:118
static u64 clib_xxhash(u64 key)
Definition: xxhash.h:58
static heap_elt_t * last(heap_header_t *h)
Definition: heap.c:53
static_always_inline void vlib_refcount_init(vlib_refcount_t *r)
Definition: refcount.h:80
u32 fib_index
Definition: kp.h:340
vnet_main_t * vnet_main
Definition: kp.h:428
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:274
#define STRUCT_OFFSET_OF(t, f)
Definition: clib.h:62
u32 pod_index
Definition: kp.c:248
kp_per_cpu_t * per_cpu
Some global data is per-cpu.
Definition: kp.h:380
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
ip4_address_t addr
Definition: kp.h:311
#define KP_MAPPING_MEMORY_SIZE
Definition: kp.h:45
static void kp_vip_garbage_collection(kp_vip_t *vip)
Definition: kp.c:262
#define ip46_address_type(ip46)
Definition: kp.h:431
void ip46_prefix_normalize(ip46_address_t *prefix, u8 plen)
Definition: kp.c:35
u32 vip_index
PODs are indexed by address and VIP Index.
Definition: kp.h:110
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:225
#define vec_alloc(V, N)
Allocate space for N more elements (no header, unspecified alignment)
Definition: vec.h:275
fib_node_t fib_node
Registration to FIB event.
Definition: kp.h:96
uword unformat_kp_vip_type(unformat_input_t *input, va_list *args)
Definition: kp.c:149
kp_vip_type_t
kube-proxy supports IPv4 and IPv6 traffic and NAT4 and NAT6.
Definition: kp.h:171
#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
int kp_vip_add(ip46_address_t *prefix, u8 plen, kp_vip_type_t type, u32 new_length, u32 *vip_index, u16 port, u16 target_port, u16 node_port)
Definition: kp.c:725
#define KP_GARBAGE_RUN
Definition: kp.c:23
#define KP_MAPPING_BUCKETS
Definition: kp.h:44
#define kp_vip_is_ip4(vip)
Definition: kp.h:277
u16 port
Definition: kp.h:312
static fib_node_back_walk_rc_t kp_fib_node_back_walk_notify(fib_node_t *node, fib_node_back_walk_ctx_t *ctx)
Definition: kp.c:899
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:97
u32 last
Definition: kp.c:249
format_function_t format_ip4_address
Definition: format.h:79
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:438
unformat_function_t unformat_ip4_address
Definition: format.h:76
vlib_main_t * vlib_main
Definition: kp.h:427
u32 vrf_id
Definition: kp.h:339
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:111
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:390
int kp_vip_del(u32 vip_index)
Definition: kp.c:810
clib_error_t * kp_init(vlib_main_t *vm)
Definition: kp.c:923
u32 kp_hash_time_now(vlib_main_t *vm)
Definition: kp.c:106
u8 * format_white_space(u8 *s, va_list *va)
Definition: std-formats.c:113
u32 last_used
Rotating timestamp of when KP_POD_FLAGS_USED flag was last set.
Definition: kp.h:129
u8 plen
The VIP prefix length.
Definition: kp.h:226
vlib_node_registration_t kp6_nodeport_node
(constructor) VLIB_REGISTER_NODE (kp6_nodeport_node)
Definition: kp_node.c:795
A high priority source a plugin can use.
Definition: fib_entry.h:62
static void kp_vip_add_adjacency(kp_main_t *kpm, kp_vip_t *vip)
Add the VIP adjacency to the ip4 or ip6 fib.
Definition: kp.c:681
Aggregrate type for a prefix.
Definition: fib_types.h:172
kp_snat_mapping_t * snat_mappings
Definition: kp.h:417
unsigned long u64
Definition: types.h:89
u8 * format_kp_dpo(u8 *s, va_list *va)
Definition: kp.c:854
Definition: kp.h:150
u32 * pod_indexes
Pool of POD indexes used for this VIP.
Definition: kp.h:264
static void kp_fib_node_last_lock_gone(fib_node_t *node)
Definition: kp.c:875
enum dpo_proto_t_ dpo_proto_t
Data path protocol.
u16 fp_len
The mask length.
Definition: fib_types.h:176
#define kp_vip_get_by_index(index)
Definition: kp.h:460
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:322
Definition: kp.h:352
kp_new_flow_entry_t * new_flow_table
Vector mapping (flow-hash & new_connect_table_mask) to POD index.
Definition: kp.h:198
Definition: fib_entry.h:238
u16 target_port
Pod&#39;s port corresponding to specific service.
Definition: kp.h:236
char * name
The counter collection&#39;s name.
Definition: counter.h:65
VLIB_PLUGIN_REGISTER()
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
Definition: dpo.h:166
#define hash_create_mem(elts, key_bytes, value_bytes)
Definition: hash.h:660
Definition: fib_entry.h:242
dpo_type_t dpo_nat4_type
DPO used to send packet from IP4/6 lookup to KP node.
Definition: kp.h:405
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:459
static const char *const kp_dpo_nat4_ip4[]
Definition: kp.c:90
int kp_vip_del_pods(u32 vip_index, ip46_address_t *addresses, u32 n)
Definition: kp.c:670
ip46_address_t fp_addr
The address type is not deriveable from the fp_addr member.
Definition: fib_types.h:195
u64 key
the key
Definition: bihash_8_8.h:35
struct _unformat_input_t unformat_input_t
ip46_address_t prefix
A Virtual IP represents a given service delivered by a set of PODs.
Definition: kp.h:220
volatile u32 * writer_lock
Definition: kp.h:424
dpo_type_t dpo_nat6_type
Definition: kp.h:406
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:271
static void kp_dpo_unlock(dpo_id_t *dpo)
Definition: kp.c:864
ip46_address_t address
Destination address used to transfer traffic towards to that POD.
Definition: kp.h:103
fib_node_index_t next_hop_fib_entry_index
The FIB entry index for the next-hop.
Definition: kp.h:134
u8 node_ip_is_ipv6
Definition: kp.h:334
u32 last_garbage_collection
last time garbage collection was run to free the PODs.
Definition: kp.h:209
void kp_garbage_collection()
Definition: kp.c:292
ip46_address_t vip
Definition: kp.h:330
An node in the FIB graph.
Definition: fib_node.h:286
#define clib_u32_loop_gt(a, b)
32 bits integer comparison for running values.
Definition: kphash.h:47
static char * kp_vip_type_strings[]
Definition: kp.c:132
u16 fib_index
Definition: kp.h:313
static fib_node_t * kp_fib_node_get_node(fib_node_index_t index)
Definition: kp.c:867
#define ip46_address_is_ip4(ip46)
Definition: ip6_packet.h:76
u8 * format_kp_vip(u8 *s, va_list *args)
Definition: kp.c:161
unformat_function_t unformat_ip6_address
Definition: format.h:94
#define pool_free(p)
Free a pool.
Definition: pool.h:352
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:371
u64 value
the value
Definition: bihash_8_8.h:36
u32 per_cpu_sticky_buckets
Number of buckets in the per-cpu sticky hash table.
Definition: kp.h:390
format_function_t format_ip6_address
Definition: format.h:95
vlib_main_t * vm
Definition: buffer.c:283
vec_header_t h
Definition: buffer.c:282
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:336
static_always_inline u32 kp_hash_elts(kp_hash_t *h, u32 time_now)
Definition: kphash.h:205
u16 node_port
Definition: kp.h:337
Each VIP is configured with a set of PODs.
Definition: kp.h:92
fib_node_get_t fnv_get
Definition: fib_node.h:274
#define clib_memcpy(a, b, c)
Definition: string.h:75
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:29
#define kp_put_writer_lock()
Definition: kp.c:31
8 octet key, 8 octet key value pair
Definition: bihash_8_8.h:33
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:182
u32 skip
Definition: kp.c:250
Context passed between object during a back walk.
Definition: fib_node.h:199
uword unformat_ip46_prefix(unformat_input_t *input, va_list *args)
Definition: kp.c:49
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:290
#define KP_DEFAULT_FLOW_TIMEOUT
Definition: kp.h:43
void vlib_validate_simple_counter(vlib_simple_counter_main_t *cm, u32 index)
validate a simple counter
Definition: counter.c:78
#define ASSERT(truth)
u32 flow_timeout
Flow timeout in seconds.
Definition: kp.h:395
u8 * format_kp_vip_detailed(u8 *s, va_list *args)
Definition: kp.c:183
unsigned int u32
Definition: types.h:88
kp_vip_type_t type
The type of traffic for this.
Definition: kp.h:248
long ctx[MAX_CONNS]
Definition: main.c:122
vlib_node_registration_t kp4_nodeport_node
(constructor) VLIB_REGISTER_NODE (kp4_nodeport_node)
Definition: kp_node.c:774
u16 port
Service port.
Definition: kp.h:231
static kp_pod_t * kp_pod_from_fib_node(fib_node_t *node)
Definition: kp.c:880
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:123
size_t count
Definition: vapi.c:42
u64 as_u64
Definition: kp.h:316
static void * clib_mem_alloc(uword size)
Definition: mem.h:112
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:23
u32 next_hop_child_index
The child index on the FIB entry.
Definition: kp.h:139
static uword is_pow2(uword x)
Definition: clib.h:280
u32 new_flow_table_mask
New flows table length - 1 (length MUST be a power of 2)
Definition: kp.h:204
u64 uword
Definition: types.h:112
u8 * format_kp_pod(u8 *s, va_list *args)
Definition: kp.c:175
int kp_nat4_interface_add_del(u32 sw_if_index, int is_del)
Definition: kp.c:906
u8 * format_kp_main(u8 *s, va_list *args)
Definition: kp.c:111
kp_main_t kp_main
Definition: kp.c:28
unsigned short u16
Definition: types.h:57
#define DPO_PROTO_NUM
Definition: dpo.h:70
static int kp_vip_find_index_with_lock(ip46_address_t *prefix, u8 plen, u32 *vip_index)
Definition: kp.c:436
#define KP_VIP_FLAGS_USED
Definition: kp.h:258
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
u8 * format_kp_vip_type(u8 *s, va_list *args)
Definition: kp.c:139
u8 flags
Flags related to this VIP.
Definition: kp.h:257
unsigned char u8
Definition: types.h:56
dpo_id_t dpo
The next DPO in the graph to follow.
Definition: kp.h:144
u32 timeout
Definition: kphash.h:63
ip46_address_t node_ip
Definition: kp.h:331
static int kp_pod_find_index_vip(kp_vip_t *vip, ip46_address_t *address, u32 *pod_index)
Definition: kp.c:463
#define kp_foreach_vip_counter
Definition: kp.h:154
kp_pod_t * pods
Pool of PODs.
Definition: kp.h:364
#define kp_get_writer_lock()
Definition: kp.c:30
#define vec_sort_with_function(vec, f)
Sort a vector using the supplied element comparison function.
Definition: vec.h:956
#define DPO_INVALID
An initialiser for DPOs declared on the stack.
Definition: dpo.h:193
int kp_vip_add_pods(u32 vip_index, ip46_address_t *addresses, u32 n)
Definition: kp.c:481
u16 target_port
Definition: kp.h:338
#define hash_get_mem(h, key)
Definition: hash.h:268
A FIB graph nodes virtual function table.
Definition: fib_node.h:273
static int kp_pseudorand_compare(void *a, void *b)
Definition: kp.c:253
static void * clib_mem_alloc_aligned(uword size, uword align)
Definition: mem.h:120
static const char *const kp_dpo_nat6_ip4[]
Definition: kp.c:98
kp_vip_t * vips
Pool of all Virtual IPs.
Definition: kp.h:356
static void kp_dpo_lock(dpo_id_t *dpo)
Definition: kp.c:863
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:228
#define vec_foreach(var, vec)
Vector iterator.
int kp_vip_find_index(ip46_address_t *prefix, u8 plen, u32 *vip_index)
Definition: kp.c:454
static const char *const kp_dpo_nat4_ip6[]
Definition: kp.c:91
fib_node_type_t fib_node_type
Node type for registering to fib changes.
Definition: kp.h:411
static void kp_vip_del_adjacency(kp_main_t *kpm, kp_vip_t *vip)
Deletes the adjacency podsociated with the VIP.
Definition: kp.c:710
u16 dpoi_next_node
The next VLIB node to follow.
Definition: dpo.h:178
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
#define ip46_prefix_is_ip4(ip46, len)
Definition: kp.h:432
u8 pod_ip_is_ipv6
Definition: kp.h:335
u8 flags
Some per-POD flags.
Definition: kp.h:116
clib_bihash_8_8_t mapping_by_pod
Definition: kp.h:414
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:67
#define kp_hash_size(h)
Definition: kphash.h:68
Load balancing service is provided per VIP.
Definition: kp.h:190
#define KP_DEFAULT_PER_CPU_STICKY_BUCKETS
kp-plugin implements a MagLev-like load balancer.
Definition: kp.h:42
static const char *const *const kp_dpo_nat4_nodes[DPO_PROTO_NUM]
Definition: kp.c:92
int kp_conf(u32 per_cpu_sticky_buckets, u32 flow_timeout)
Fix global kube-proxy parameters.
Definition: kp.c:421
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:972
u16 node_port
Node&#39;s port, can access service via NodeIP:node_port.
Definition: kp.h:241
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:229
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:470
kp_hash_t * sticky_ht
Each CPU has its own sticky flow hash table.
Definition: kp.h:348
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:128