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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include <vnet/plugin/plugin.h>
18 #include <vnet/api_errno.h>
20 //GC runs at most once every so many seconds
21 #define LB_GARBAGE_RUN 60
23 //After so many seconds. It is assumed that inter-core race condition will not occur.
24 #define LB_CONCURRENCY_TIMEOUT 10
28 #define lb_get_writer_lock() do {} while(__sync_lock_test_and_set (lb_main.writer_lock, 1))
29 #define lb_put_writer_lock() lb_main.writer_lock[0] = 0
31 u32 lb_hash_time_now(vlib_main_t * vm)
33 return (u32) (vlib_time_now(vm) + 10000);
36 u8 *format_lb_main (u8 * s, va_list * args)
38 vlib_thread_main_t *tm = vlib_get_thread_main();
39 lb_main_t *lbm = &lb_main;
40 s = format(s, "lb_main");
41 s = format(s, " ip4-src-address: %U \n", format_ip4_address, &lbm->ip4_src_address);
42 s = format(s, " ip6-src-address: %U \n", format_ip6_address, &lbm->ip6_src_address);
43 s = format(s, " #vips: %u\n", pool_elts(lbm->vips));
44 s = format(s, " #ass: %u\n", pool_elts(lbm->ass) - 1);
47 for(cpu_index = 0; cpu_index < tm->n_vlib_mains; cpu_index++ ) {
48 lb_hash_t *h = lbm->per_cpu[cpu_index].sticky_ht;
50 s = format(s, "core %d\n", cpu_index);
51 s = format(s, " timeout: %ds\n", h->timeout);
52 s = format(s, " usage: %d / %d\n", lb_hash_elts(h, lb_hash_time_now(vlib_get_main())), lb_hash_size(h));
59 static char *lb_vip_type_strings[] = {
60 [LB_VIP_TYPE_IP6_GRE6] = "ip6-gre6",
61 [LB_VIP_TYPE_IP6_GRE4] = "ip6-gre4",
62 [LB_VIP_TYPE_IP4_GRE6] = "ip4-gre6",
63 [LB_VIP_TYPE_IP4_GRE4] = "ip4-gre4",
66 u8 *format_lb_vip_type (u8 * s, va_list * args)
68 lb_vip_type_t vipt = va_arg (*args, lb_vip_type_t);
70 for (i=0; i<LB_VIP_N_TYPES; i++)
72 return format(s, lb_vip_type_strings[i]);
73 return format(s, "_WRONG_TYPE_");
76 uword unformat_lb_vip_type (unformat_input_t * input, va_list * args)
78 lb_vip_type_t *vipt = va_arg (*args, lb_vip_type_t *);
80 for (i=0; i<LB_VIP_N_TYPES; i++)
81 if (unformat(input, lb_vip_type_strings[i])) {
88 u8 *format_lb_vip (u8 * s, va_list * args)
90 lb_vip_t *vip = va_arg (*args, lb_vip_t *);
91 return format(s, "%U %U new_size:%u #as:%u%s",
92 format_lb_vip_type, vip->type,
93 format_ip46_prefix, &vip->prefix, vip->plen, IP46_TYPE_ANY,
94 vip->new_flow_table_mask + 1,
95 pool_elts(vip->as_indexes),
96 (vip->flags & LB_VIP_FLAGS_USED)?"":" removed");
99 u8 *format_lb_as (u8 * s, va_list * args)
101 lb_as_t *as = va_arg (*args, lb_as_t *);
102 return format(s, "%U %s", format_ip46_address, &as->address, (as->flags & LB_AS_FLAGS_USED)?"used":"removed");
105 u8 *format_lb_vip_detailed (u8 * s, va_list * args)
107 lb_main_t *lbm = &lb_main;
108 lb_vip_t *vip = va_arg (*args, lb_vip_t *);
109 uword indent = format_get_indent (s);
111 s = format(s, "%U %U [%u] %U%s\n"
113 format_white_space, indent,
114 format_lb_vip_type, vip->type,
115 vip - lbm->vips, format_ip46_prefix, &vip->prefix, vip->plen, IP46_TYPE_ANY,
116 (vip->flags & LB_VIP_FLAGS_USED)?"":" removed",
117 format_white_space, indent,
118 vip->new_flow_table_mask + 1);
121 s = format(s, "%U counters:\n",
122 format_white_space, indent);
124 for (i=0; i<LB_N_VIP_COUNTERS; i++)
125 s = format(s, "%U %s: %d\n",
126 format_white_space, indent,
127 lbm->vip_counters[i].name,
128 vlib_get_simple_counter(&lbm->vip_counters[i], vip - lbm->vips));
131 s = format(s, "%U #as:%u\n",
132 format_white_space, indent,
133 pool_elts(vip->as_indexes));
135 //Let's count the buckets for each AS
137 vec_validate(count, pool_len(lbm->ass)); //Possibly big alloc for not much...
138 lb_new_flow_entry_t *nfe;
139 vec_foreach(nfe, vip->new_flow_table)
140 count[nfe->as_index]++;
144 pool_foreach(as_index, vip->as_indexes, {
145 as = &lbm->ass[*as_index];
146 s = format(s, "%U %U %d buckets %d flows adj:%u %s\n",
147 format_white_space, indent,
148 format_ip46_address, &as->address, IP46_TYPE_ANY,
149 count[as - lbm->ass],
150 vlib_refcount_get(&lbm->as_refcount, as - lbm->ass),
152 (as->flags & LB_AS_FLAGS_USED)?"used":" removed");
158 s = format(s, "%U new flows table:\n", format_white_space, indent);
159 lb_new_flow_entry_t *nfe;
160 vec_foreach(nfe, vip->new_flow_table) {
161 s = format(s, "%U %d: %d\n", format_white_space, indent, nfe - vip->new_flow_table, nfe->as_index);
174 static int lb_pseudorand_compare(void *a, void *b)
177 lb_main_t *lbm = &lb_main;
178 asa = &lbm->ass[((lb_pseudorand_t *)a)->as_index];
179 asb = &lbm->ass[((lb_pseudorand_t *)b)->as_index];
180 return memcmp(&asa->address, &asb->address, sizeof(asb->address));
183 static void lb_vip_garbage_collection(lb_vip_t *vip)
185 lb_main_t *lbm = &lb_main;
186 ASSERT (lbm->writer_lock[0]);
188 u32 now = (u32) vlib_time_now(vlib_get_main());
189 if (!clib_u32_loop_gt(now, vip->last_garbage_collection + LB_GARBAGE_RUN))
192 vip->last_garbage_collection = now;
195 pool_foreach(as_index, vip->as_indexes, {
196 as = &lbm->ass[*as_index];
197 if (!(as->flags & LB_AS_FLAGS_USED) && //Not used
198 clib_u32_loop_gt(now, as->last_used + LB_CONCURRENCY_TIMEOUT) && //Not recently used
199 (vlib_refcount_get(&lbm->as_refcount, as - lbm->ass) == 0)) { //Not referenced
200 pool_put(vip->as_indexes, as_index);
201 pool_put(lbm->ass, as);
206 void lb_garbage_collection()
208 lb_main_t *lbm = &lb_main;
209 lb_get_writer_lock();
211 u32 *to_be_removed_vips = 0, *i;
212 pool_foreach(vip, lbm->vips, {
213 lb_vip_garbage_collection(vip);
215 if (!(vip->flags & LB_VIP_FLAGS_USED) &&
216 (pool_elts(vip->as_indexes) == 0)) {
217 vec_add1(to_be_removed_vips, vip - lbm->vips);
221 vec_foreach(i, to_be_removed_vips) {
222 vip = &lbm->vips[*i];
223 pool_put(lbm->vips, vip);
224 pool_free(vip->as_indexes);
227 vec_free(to_be_removed_vips);
228 lb_put_writer_lock();
231 static void lb_vip_update_new_flow_table(lb_vip_t *vip)
233 lb_main_t *lbm = &lb_main;
234 lb_new_flow_entry_t *old_table;
236 lb_new_flow_entry_t *new_flow_table = 0;
238 lb_pseudorand_t *pr, *sort_arr = 0;
241 ASSERT (lbm->writer_lock[0]); //We must have the lock
243 //Check if some AS is configured or not
245 pool_foreach(as_index, vip->as_indexes, {
246 as = &lbm->ass[*as_index];
247 if (as->flags & LB_AS_FLAGS_USED) { //Not used anymore
249 goto out; //Not sure 'break' works in this macro-loop
255 //Only the default. i.e. no AS
256 vec_validate(new_flow_table, vip->new_flow_table_mask);
257 for (i=0; i<vec_len(new_flow_table); i++)
258 new_flow_table[i].as_index = 0;
263 //First, let's sort the ASs
265 vec_alloc(sort_arr, pool_elts(vip->as_indexes));
268 pool_foreach(as_index, vip->as_indexes, {
269 as = &lbm->ass[*as_index];
270 if (!(as->flags & LB_AS_FLAGS_USED)) //Not used anymore
273 sort_arr[i].as_index = as - lbm->ass;
276 _vec_len(sort_arr) = i;
278 vec_sort_with_function(sort_arr, lb_pseudorand_compare);
280 //Now let's pseudo-randomly generate permutations
281 vec_foreach(pr, sort_arr) {
282 lb_as_t *as = &lbm->ass[pr->as_index];
284 u64 seed = clib_xxhash(as->address.as_u64[0] ^
285 as->address.as_u64[1]);
286 /* We have 2^n buckets.
287 * skip must be prime with 2^n.
288 * So skip must be odd.
289 * MagLev actually state that M should be prime,
290 * but this has a big computation cost (% operation).
291 * Using 2^n is more better (& operation).
293 pr->skip = ((seed & 0xffffffff) | 1) & vip->new_flow_table_mask;
294 pr->last = (seed >> 32) & vip->new_flow_table_mask;
297 //Let's create a new flow table
298 vec_validate(new_flow_table, vip->new_flow_table_mask);
299 for (i=0; i<vec_len(new_flow_table); i++)
300 new_flow_table[i].as_index = ~0;
304 vec_foreach(pr, sort_arr) {
307 pr->last = (pr->last + pr->skip) & vip->new_flow_table_mask;
308 if (new_flow_table[last].as_index == ~0) {
309 new_flow_table[last].as_index = pr->as_index;
314 if (done == vec_len(new_flow_table))
323 //Count number of changed entries
325 for (i=0; i<vec_len(new_flow_table); i++)
326 if (vip->new_flow_table == 0 ||
327 new_flow_table[i].as_index != vip->new_flow_table[i].as_index)
330 old_table = vip->new_flow_table;
331 vip->new_flow_table = new_flow_table;
335 int lb_conf(ip4_address_t *ip4_address, ip6_address_t *ip6_address,
336 u32 per_cpu_sticky_buckets, u32 flow_timeout)
338 lb_main_t *lbm = &lb_main;
340 if (!is_pow2(per_cpu_sticky_buckets))
341 return VNET_API_ERROR_INVALID_MEMORY_SIZE;
343 lb_get_writer_lock(); //Not exactly necessary but just a reminder that it exists for my future self
344 lbm->ip4_src_address = *ip4_address;
345 lbm->ip6_src_address = *ip6_address;
346 lbm->per_cpu_sticky_buckets = per_cpu_sticky_buckets;
347 lbm->flow_timeout = flow_timeout;
348 lb_put_writer_lock();
353 int lb_vip_find_index_with_lock(ip46_address_t *prefix, u8 plen, u32 *vip_index)
355 lb_main_t *lbm = &lb_main;
357 ASSERT (lbm->writer_lock[0]); //This must be called with the lock owned
358 ip46_prefix_normalize(prefix, plen);
359 pool_foreach(vip, lbm->vips, {
360 if ((vip->flags & LB_AS_FLAGS_USED) &&
362 vip->prefix.as_u64[0] == prefix->as_u64[0] &&
363 vip->prefix.as_u64[1] == prefix->as_u64[1]) {
364 *vip_index = vip - lbm->vips;
368 return VNET_API_ERROR_NO_SUCH_ENTRY;
371 int lb_vip_find_index(ip46_address_t *prefix, u8 plen, u32 *vip_index)
374 lb_get_writer_lock();
375 ret = lb_vip_find_index_with_lock(prefix, plen, vip_index);
376 lb_put_writer_lock();
380 static int lb_as_find_index_vip(lb_vip_t *vip, ip46_address_t *address, u32 *as_index)
382 lb_main_t *lbm = &lb_main;
383 ASSERT (lbm->writer_lock[0]); //This must be called with the lock owned
386 pool_foreach(asi, vip->as_indexes, {
387 as = &lbm->ass[*asi];
388 if (as->vip_index == (vip - lbm->vips) &&
389 as->address.as_u64[0] == address->as_u64[0] &&
390 as->address.as_u64[1] == address->as_u64[1]) {
391 *as_index = as - lbm->ass;
398 int lb_vip_add_ass(u32 vip_index, ip46_address_t *addresses, u32 n)
400 lb_main_t *lbm = &lb_main;
401 lb_get_writer_lock();
403 if (!(vip = lb_vip_get_by_index(vip_index))) {
404 lb_put_writer_lock();
405 return VNET_API_ERROR_NO_SUCH_ENTRY;
408 ip46_type_t type = lb_vip_is_gre4(vip)?IP46_TYPE_IP4:IP46_TYPE_IP6;
409 u32 *to_be_added = 0;
410 u32 *to_be_updated = 0;
417 if (!lb_as_find_index_vip(vip, &addresses[n], &i)) {
418 if (lbm->ass[i].flags & LB_AS_FLAGS_USED) {
419 vec_free(to_be_added);
420 vec_free(to_be_updated);
421 lb_put_writer_lock();
422 return VNET_API_ERROR_VALUE_EXIST;
424 vec_add1(to_be_updated, i);
428 if (ip46_address_type(&addresses[n]) != type) {
429 vec_free(to_be_added);
430 vec_free(to_be_updated);
431 lb_put_writer_lock();
432 return VNET_API_ERROR_INVALID_ADDRESS_FAMILY;
437 while(n2--) //Check for duplicates
438 if (addresses[n2].as_u64[0] == addresses[n].as_u64[0] &&
439 addresses[n2].as_u64[1] == addresses[n].as_u64[1])
443 vec_add1(to_be_added, n);
450 vec_foreach(ip, to_be_updated) {
451 lbm->ass[*ip].flags = LB_AS_FLAGS_USED;
452 lbm->ass[*ip].adj_index = ~0;
454 vec_free(to_be_updated);
456 //Create those who have to be created
457 vec_foreach(ip, to_be_added) {
460 pool_get(lbm->ass, as);
461 as->address = addresses[*ip];
462 as->flags = LB_AS_FLAGS_USED;
463 as->vip_index = vip_index;
465 pool_get(vip->as_indexes, as_index);
466 *as_index = as - lbm->ass;
468 vec_free(to_be_added);
471 lb_vip_update_new_flow_table(vip);
473 //Garbage collection maybe
474 lb_vip_garbage_collection(vip);
476 lb_put_writer_lock();
480 int lb_vip_del_ass_withlock(u32 vip_index, ip46_address_t *addresses, u32 n)
482 lb_main_t *lbm = &lb_main;
483 u32 now = (u32) vlib_time_now(vlib_get_main());
487 if (!(vip = lb_vip_get_by_index(vip_index))) {
488 return VNET_API_ERROR_NO_SUCH_ENTRY;
494 if (lb_as_find_index_vip(vip, &addresses[n], &i)) {
496 return VNET_API_ERROR_NO_SUCH_ENTRY;
499 if (n) { //Check for duplicates
502 if (addresses[n2].as_u64[0] == addresses[n].as_u64[0] &&
503 addresses[n2].as_u64[1] == addresses[n].as_u64[1])
508 vec_add1(indexes, i);
513 //Garbage collection maybe
514 lb_vip_garbage_collection(vip);
516 if (indexes != NULL) {
517 vec_foreach(ip, indexes) {
518 lbm->ass[*ip].flags &= ~LB_AS_FLAGS_USED;
519 lbm->ass[*ip].last_used = now;
523 lb_vip_update_new_flow_table(vip);
530 int lb_vip_del_ass(u32 vip_index, ip46_address_t *addresses, u32 n)
532 lb_get_writer_lock();
533 int ret = lb_vip_del_ass_withlock(vip_index, addresses, n);
534 lb_put_writer_lock();
538 int lb_as_lookup_bypass(u32 vip_index, ip46_address_t *address, u8 is_disable)
540 /* lb_get_writer_lock(); */
541 /* lb_main_t *lbm = &lb_main; */
546 /* if (!(vip = lb_vip_get_by_index(vip_index)) || */
547 /* lb_as_find_index_vip(vip, address, &as_index)) { */
548 /* lb_put_writer_lock(); */
549 /* return VNET_API_ERROR_NO_SUCH_ENTRY; */
552 /* as = &lbm->ass[as_index]; */
554 /* if (is_disable) { */
555 /* as->adj_index = ~0; */
556 /* } else if (lb_vip_is_gre4(vip)) { */
557 /* uword *p = ip4_get_route (&ip4_main, 0, 0, as->address.ip4.as_u8, 32); */
559 /* lb_put_writer_lock(); */
560 /* return VNET_API_ERROR_NO_SUCH_ENTRY; */
562 /* u32 ai = (u32)p[0]; */
563 /* ip_lookup_main_t *lm4 = &ip4_main.lookup_main; */
564 /* ip_adjacency_t *adj4 = ip_get_adjacency (lm4, ai); */
565 /* if (adj4->lookup_next_index != IP_LOOKUP_NEXT_REWRITE) { */
566 /* lb_put_writer_lock(); */
567 /* return VNET_API_ERROR_INCORRECT_ADJACENCY_TYPE; */
570 /* as->adj_index = ai; */
572 /* u32 ai = ip6_get_route (&ip6_main, 0, 0, &as->address.ip6, 128); */
574 /* lb_put_writer_lock(); */
575 /* return VNET_API_ERROR_NO_SUCH_ENTRY; */
578 /* ip_lookup_main_t *lm6 = &ip6_main.lookup_main; */
579 /* ip_adjacency_t *adj6 = ip_get_adjacency (lm6, ai); */
580 /* if (adj6->lookup_next_index != IP_LOOKUP_NEXT_REWRITE) { */
581 /* lb_put_writer_lock(); */
582 /* return VNET_API_ERROR_INCORRECT_ADJACENCY_TYPE; */
585 /* as->adj_index = ai; */
587 /* lb_put_writer_lock(); */
593 * Add the VIP adjacency to the ip4 or ip6 fib
595 static void lb_vip_add_adjacency(lb_main_t *lbm, lb_vip_t *vip)
597 /* ip_adjacency_t adj; */
599 /* memset (&adj, 0, sizeof (adj)); */
600 /* adj.explicit_fib_index = ~0; */
601 /* lb_adj_data_t *ad = (lb_adj_data_t *) &adj.opaque; */
602 /* ad->vip_index = vip - lbm->vips; */
604 /* ASSERT (lbm->writer_lock[0]); //This must be called with the lock owned */
605 /* u32 lookup_next_index = lbm->ip_lookup_next_index[vip->type]; */
607 /* if (lb_vip_is_ip4(vip)) { */
608 /* adj.lookup_next_index = lookup_next_index; */
609 /* ip4_add_del_route_args_t route_args = {}; */
610 /* ip4_main_t *im4 = &ip4_main; */
611 /* route_args.table_index_or_table_id = 0; */
612 /* route_args.flags = IP4_ROUTE_FLAG_ADD; */
613 /* route_args.dst_address = vip->prefix.ip4; */
614 /* route_args.dst_address_length = vip->plen - 96; */
615 /* route_args.adj_index = ~0; */
616 /* route_args.add_adj = &adj; */
617 /* route_args.n_add_adj = 1; */
618 /* ip4_add_del_route (im4, &route_args); */
620 /* adj.lookup_next_index = lookup_next_index; */
621 /* ip6_add_del_route_args_t route_args = {}; */
622 /* ip6_main_t *im6 = &ip6_main; */
623 /* route_args.table_index_or_table_id = 0; */
624 /* route_args.flags = IP6_ROUTE_FLAG_ADD; */
625 /* route_args.dst_address = vip->prefix.ip6; */
626 /* route_args.dst_address_length = vip->plen; */
627 /* route_args.adj_index = ~0; */
628 /* route_args.add_adj = &adj; */
629 /* route_args.n_add_adj = 1; */
630 /* ip6_add_del_route (im6, &route_args); */
635 * Deletes the adjacency associated with the VIP
637 static void lb_vip_del_adjacency(lb_main_t *lbm, lb_vip_t *vip)
639 /* ASSERT (lbm->writer_lock[0]); //This must be called with the lock owned */
640 /* if (lb_vip_is_ip4(vip)) { */
641 /* ip4_main_t *im4 = &ip4_main; */
642 /* ip4_add_del_route_args_t route_args = {}; */
643 /* route_args.table_index_or_table_id = 0; */
644 /* route_args.flags = IP4_ROUTE_FLAG_DEL; */
645 /* route_args.dst_address = vip->prefix.ip4; */
646 /* route_args.dst_address_length = vip->plen - 96; */
647 /* route_args.adj_index = ~0; */
648 /* route_args.add_adj = NULL; */
649 /* route_args.n_add_adj = 0; */
650 /* ip4_add_del_route (im4, &route_args); */
652 /* ip6_main_t *im6 = &ip6_main; */
653 /* ip6_add_del_route_args_t route_args = {}; */
654 /* route_args.table_index_or_table_id = 0; */
655 /* route_args.flags = IP6_ROUTE_FLAG_DEL; */
656 /* route_args.dst_address = vip->prefix.ip6; */
657 /* route_args.dst_address_length = vip->plen; */
658 /* route_args.adj_index = ~0; */
659 /* route_args.add_adj = NULL; */
660 /* route_args.n_add_adj = 0; */
661 /* ip6_add_del_route (im6, &route_args); */
665 int lb_vip_add(ip46_address_t *prefix, u8 plen, lb_vip_type_t type, u32 new_length, u32 *vip_index)
667 lb_main_t *lbm = &lb_main;
669 lb_get_writer_lock();
670 ip46_prefix_normalize(prefix, plen);
672 if (!lb_vip_find_index_with_lock(prefix, plen, vip_index)) {
673 lb_put_writer_lock();
674 return VNET_API_ERROR_VALUE_EXIST;
677 if (!is_pow2(new_length)) {
678 lb_put_writer_lock();
679 return VNET_API_ERROR_INVALID_MEMORY_SIZE;
682 if (ip46_prefix_is_ip4(prefix, plen) &&
683 (type != LB_VIP_TYPE_IP4_GRE4) &&
684 (type != LB_VIP_TYPE_IP4_GRE6))
685 return VNET_API_ERROR_INVALID_ADDRESS_FAMILY;
689 pool_get(lbm->vips, vip);
692 vip->prefix = *prefix;
694 vip->last_garbage_collection = (u32) vlib_time_now(vlib_get_main());
696 vip->flags = LB_VIP_FLAGS_USED;
701 for (i = 0; i < LB_N_VIP_COUNTERS; i++) {
702 vlib_validate_simple_counter(&lbm->vip_counters[i], vip - lbm->vips);
703 vlib_zero_simple_counter(&lbm->vip_counters[i], vip - lbm->vips);
706 //Configure new flow table
707 vip->new_flow_table_mask = new_length - 1;
708 vip->new_flow_table = 0;
710 //Create a new flow hash table full of the default entry
711 lb_vip_update_new_flow_table(vip);
713 //Create adjacency to direct traffic
714 lb_vip_add_adjacency(lbm, vip);
717 *vip_index = vip - lbm->vips;
719 lb_put_writer_lock();
723 int lb_vip_del(u32 vip_index)
725 lb_main_t *lbm = &lb_main;
727 lb_get_writer_lock();
728 if (!(vip = lb_vip_get_by_index(vip_index))) {
729 lb_put_writer_lock();
730 return VNET_API_ERROR_NO_SUCH_ENTRY;
733 //FIXME: This operation is actually not working
734 //We will need to remove state before performing this.
738 ip46_address_t *ass = 0;
741 pool_foreach(as_index, vip->as_indexes, {
742 as = &lbm->ass[*as_index];
743 vec_add1(ass, as->address);
746 lb_vip_del_ass_withlock(vip_index, ass, vec_len(ass));
751 lb_vip_del_adjacency(lbm, vip);
753 //Set the VIP as unused
754 vip->flags &= ~LB_VIP_FLAGS_USED;
756 lb_put_writer_lock();
761 vlib_plugin_register (vlib_main_t * vm,
762 vnet_plugin_handoff_t * h,
765 clib_error_t *error = 0;
770 lb_init (vlib_main_t * vm)
772 vlib_thread_main_t *tm = vlib_get_thread_main ();
773 lb_main_t *lbm = &lb_main;
777 vec_validate(lbm->per_cpu, tm->n_vlib_mains - 1);
778 lbm->writer_lock = clib_mem_alloc_aligned (CLIB_CACHE_LINE_BYTES, CLIB_CACHE_LINE_BYTES);
779 lbm->writer_lock[0] = 0;
780 lbm->per_cpu_sticky_buckets = LB_DEFAULT_PER_CPU_STICKY_BUCKETS;
781 lbm->flow_timeout = LB_DEFAULT_FLOW_TIMEOUT;
782 lbm->ip4_src_address.as_u32 = 0xffffffff;
783 lbm->ip6_src_address.as_u64[0] = 0xffffffffffffffffL;
784 lbm->ip6_src_address.as_u64[1] = 0xffffffffffffffffL;
786 //Init AS reference counters
787 vlib_refcount_init(&lbm->as_refcount);
789 //Allocate and init default AS.
791 pool_get(lbm->ass, default_as);
792 default_as->flags = 0;
793 default_as->adj_index = ~0;
794 default_as->vip_index = ~0;
795 default_as->address.ip6.as_u64[0] = 0xffffffffffffffffL;
796 default_as->address.ip6.as_u64[1] = 0xffffffffffffffffL;
798 #define _(a,b,c) lbm->vip_counters[c].name = b;
799 lb_foreach_vip_counter
804 VLIB_INIT_FUNCTION (lb_init);