IP Multicast FIB (mfib)
[vpp.git] / src / vnet / fib / fib_entry_src.c
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 <vnet/adj/adj.h>
17 #include <vnet/dpo/load_balance.h>
18 #include <vnet/dpo/mpls_label_dpo.h>
19 #include <vnet/dpo/drop_dpo.h>
20
21 #include <vnet/fib/fib_entry_src.h>
22 #include <vnet/fib/fib_table.h>
23 #include <vnet/fib/fib_path_ext.h>
24 #include <vnet/fib/fib_urpf_list.h>
25
26 /*
27  * per-source type vft
28  */
29 static fib_entry_src_vft_t fib_entry_src_vft[FIB_SOURCE_MAX];
30
31 static fib_protocol_t
32 fib_entry_get_proto (const fib_entry_t * fib_entry)
33 {
34     return (fib_entry->fe_prefix.fp_proto);
35 }
36
37 void
38 fib_entry_src_register (fib_source_t source,
39                         const fib_entry_src_vft_t *vft)
40 {
41     fib_entry_src_vft[source] = *vft;
42 }
43
44 static int
45 fib_entry_src_cmp_for_sort (void * v1,
46                             void * v2)
47 {
48     fib_entry_src_t *esrc1 = v1, *esrc2 = v2;
49
50     return (esrc1->fes_src - esrc2->fes_src);
51 }
52
53 void
54 fib_entry_src_action_init (fib_entry_t *fib_entry,
55                            fib_source_t source)
56
57 {
58     fib_entry_src_t esrc = {
59         .fes_pl = FIB_NODE_INDEX_INVALID,
60         .fes_flags = FIB_ENTRY_SRC_FLAG_NONE,
61         .fes_src = source,
62     };
63
64     if (NULL != fib_entry_src_vft[source].fesv_init)
65     {
66         fib_entry_src_vft[source].fesv_init(&esrc);
67     }
68
69     vec_add1(fib_entry->fe_srcs, esrc);
70     vec_sort_with_function(fib_entry->fe_srcs,
71                            fib_entry_src_cmp_for_sort);
72 }
73
74 static fib_entry_src_t *
75 fib_entry_src_find (const fib_entry_t *fib_entry,
76                     fib_source_t source,
77                     u32 *index)
78
79 {
80     fib_entry_src_t *esrc;
81     int ii;
82
83     ii = 0;
84     vec_foreach(esrc, fib_entry->fe_srcs)
85     {
86         if (esrc->fes_src == source)
87         {
88             if (NULL != index)
89             {
90                 *index = ii;
91             }
92             return (esrc);
93         }
94         else
95         {
96             ii++;
97         }
98     }
99
100     return (NULL);
101 }
102
103 int
104 fib_entry_is_sourced (fib_node_index_t fib_entry_index,
105                       fib_source_t source)
106 {
107     fib_entry_t *fib_entry;
108
109     fib_entry = fib_entry_get(fib_entry_index);
110
111     return (NULL != fib_entry_src_find(fib_entry, source, NULL));
112 }
113
114 static fib_entry_src_t *
115 fib_entry_src_find_or_create (fib_entry_t *fib_entry,
116                               fib_source_t source,
117                               u32 *index)
118 {
119     fib_entry_src_t *esrc;
120
121     esrc = fib_entry_src_find(fib_entry, source, NULL);
122
123     if (NULL == esrc)
124     {
125         fib_entry_src_action_init(fib_entry, source);
126     }
127
128     return (fib_entry_src_find(fib_entry, source, NULL));
129 }
130
131 void
132 fib_entry_src_action_deinit (fib_entry_t *fib_entry,
133                              fib_source_t source)
134
135 {
136     fib_entry_src_t *esrc;
137     u32 index = ~0;
138
139     esrc = fib_entry_src_find(fib_entry, source, &index);
140
141     ASSERT(NULL != esrc);
142
143     if (NULL != fib_entry_src_vft[source].fesv_deinit)
144     {
145         fib_entry_src_vft[source].fesv_deinit(esrc);
146     }
147
148     vec_free(esrc->fes_path_exts);
149     vec_del1(fib_entry->fe_srcs, index);
150 }
151
152 fib_entry_src_cover_res_t
153 fib_entry_src_action_cover_change (fib_entry_t *fib_entry,
154                                    fib_source_t source)
155 {
156     if (NULL != fib_entry_src_vft[source].fesv_cover_change)
157     {
158         return (fib_entry_src_vft[source].fesv_cover_change(
159                     fib_entry_src_find(fib_entry, source, NULL),
160                     fib_entry));
161     }
162
163     fib_entry_src_cover_res_t res = {
164         .install = !0,
165         .bw_reason = FIB_NODE_BW_REASON_FLAG_NONE,
166     };
167     return (res);
168 }
169
170 fib_entry_src_cover_res_t
171 fib_entry_src_action_cover_update (fib_entry_t *fib_entry,
172                                    fib_source_t source)
173 {
174     if (NULL != fib_entry_src_vft[source].fesv_cover_update)
175     {
176         return (fib_entry_src_vft[source].fesv_cover_update(
177                     fib_entry_src_find(fib_entry, source, NULL),
178                     fib_entry));
179     }
180
181     fib_entry_src_cover_res_t res = {
182         .install = !0,
183         .bw_reason = FIB_NODE_BW_REASON_FLAG_NONE,
184     };
185     return (res);
186 }
187
188 typedef struct fib_entry_src_collect_forwarding_ctx_t_
189 {
190     load_balance_path_t * next_hops;
191     const fib_entry_t *fib_entry;
192     const fib_entry_src_t *esrc;
193     fib_forward_chain_type_t fct;
194     int is_recursive;
195 } fib_entry_src_collect_forwarding_ctx_t;
196
197 /**
198  * @brief Determine whether this FIB entry should use a load-balance MAP
199  * to support PIC edge fast convergence
200  */
201 load_balance_flags_t
202 fib_entry_calc_lb_flags (fib_entry_src_collect_forwarding_ctx_t *ctx)
203 {
204     /**
205      * We'll use a LB map is the path-list has recursive paths.
206      * recursive paths implies BGP, and hence scale.
207      */
208     if (ctx->is_recursive)
209     {
210         return (LOAD_BALANCE_FLAG_USES_MAP);
211     }
212     return (LOAD_BALANCE_FLAG_NONE);
213 }
214
215 static int
216 fib_entry_src_valid_out_label (mpls_label_t label)
217 {
218     return ((MPLS_LABEL_IS_REAL(label) ||
219              MPLS_IETF_IPV4_EXPLICIT_NULL_LABEL == label ||
220              MPLS_IETF_IPV6_EXPLICIT_NULL_LABEL == label ||
221              MPLS_IETF_IMPLICIT_NULL_LABEL == label));
222 }
223
224 /**
225  * @brief Turn the chain type requested by the client into the one they
226  * really wanted
227  */
228 fib_forward_chain_type_t
229 fib_entry_chain_type_fixup (const fib_entry_t *entry,
230                             fib_forward_chain_type_t fct)
231 {
232     ASSERT(FIB_FORW_CHAIN_TYPE_MPLS_EOS == fct);
233
234     /*
235      * The EOS chain is a tricky since one cannot know the adjacency
236      * to link to without knowing what the packets payload protocol
237      * will be once the label is popped.
238      */
239     fib_forward_chain_type_t dfct;
240
241     dfct = fib_entry_get_default_chain_type(entry);
242
243     if (FIB_FORW_CHAIN_TYPE_MPLS_EOS == dfct)
244     {
245         /*
246          * If the entry being asked is a eos-MPLS label entry,
247          * then use the payload-protocol field, that we stashed there
248          * for just this purpose
249          */
250         return (fib_forw_chain_type_from_dpo_proto(
251                     entry->fe_prefix.fp_payload_proto));
252     }
253     /*
254      * else give them what this entry would be by default. i.e. if it's a v6
255      * entry, then the label its local labelled should be carrying v6 traffic.
256      * If it's a non-EOS label entry, then there are more labels and we want
257      * a non-eos chain.
258      */
259     return (dfct);
260 }
261
262 static int
263 fib_entry_src_collect_forwarding (fib_node_index_t pl_index,
264                                   fib_node_index_t path_index,
265                                   void *arg)
266 {
267     fib_entry_src_collect_forwarding_ctx_t *ctx;
268     fib_path_ext_t *path_ext;
269
270     ctx = arg;
271
272     /*
273      * if the path is not resolved, don't include it.
274      */
275     if (!fib_path_is_resolved(path_index))
276     {
277         return (!0);
278     }
279
280     if (fib_path_is_recursive(path_index))
281     {
282         ctx->is_recursive = 1;
283     }
284
285     /*
286      * get the matching path-extension for the path being visited.
287      */
288     vec_foreach(path_ext, ctx->esrc->fes_path_exts)
289     {
290         if (path_ext->fpe_path_index == path_index)
291             break;
292     }
293     
294     if (NULL != path_ext &&
295         path_ext->fpe_path_index == path_index &&
296         fib_entry_src_valid_out_label(path_ext->fpe_label_stack[0]))
297     {
298         /*
299          * found a matching extension. stack it to obtain the forwarding
300          * info for this path.
301          */
302         ctx->next_hops = fib_path_ext_stack(path_ext, ctx->fib_entry, ctx->fct, ctx->next_hops);
303     }
304     else
305     {
306         load_balance_path_t *nh;
307
308         /*
309          * no extension => no out-going label for this path. that's OK
310          * in the case of an IP or EOS chain, but not for non-EOS
311          */
312         switch (ctx->fct)
313         {
314         case FIB_FORW_CHAIN_TYPE_UNICAST_IP4:
315         case FIB_FORW_CHAIN_TYPE_UNICAST_IP6:
316         case FIB_FORW_CHAIN_TYPE_MCAST_IP4:
317         case FIB_FORW_CHAIN_TYPE_MCAST_IP6:
318             /*
319              * EOS traffic with no label to stack, we need the IP Adj
320              */
321             vec_add2(ctx->next_hops, nh, 1);
322
323             nh->path_index = path_index;
324             nh->path_weight = fib_path_get_weight(path_index);
325             fib_path_contribute_forwarding(path_index, ctx->fct, &nh->path_dpo);
326
327             break;
328         case FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS:
329             if (fib_path_is_exclusive(path_index) ||
330                 fib_path_is_deag(path_index))
331             {
332                 vec_add2(ctx->next_hops, nh, 1);
333
334                 nh->path_index = path_index;
335                 nh->path_weight = fib_path_get_weight(path_index);
336                 fib_path_contribute_forwarding(path_index,
337                                                FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS,
338                                                &nh->path_dpo);
339             }
340             break;
341         case FIB_FORW_CHAIN_TYPE_MPLS_EOS:
342         {
343             /*
344              * no label. we need a chain based on the payload. fixup.
345              */
346             vec_add2(ctx->next_hops, nh, 1);
347
348             nh->path_index = path_index;
349             nh->path_weight = fib_path_get_weight(path_index);
350             fib_path_contribute_forwarding(path_index,
351                                            fib_entry_chain_type_fixup(ctx->fib_entry,
352                                                                       ctx->fct),
353                                            &nh->path_dpo);
354
355             break;
356         }
357         case FIB_FORW_CHAIN_TYPE_ETHERNET:
358             ASSERT(0);
359             break;
360         }
361     }
362
363     return (!0);
364 }
365
366 void
367 fib_entry_src_mk_lb (fib_entry_t *fib_entry,
368                      const fib_entry_src_t *esrc,
369                      fib_forward_chain_type_t fct,
370                      dpo_id_t *dpo_lb)
371 {
372     dpo_proto_t lb_proto;
373
374     /*
375      * If the entry has path extensions then we construct a load-balance
376      * by stacking the extensions on the forwarding chains of the paths.
377      * Otherwise we use the load-balance of the path-list
378      */
379     fib_entry_src_collect_forwarding_ctx_t ctx = {
380         .esrc = esrc,
381         .fib_entry = fib_entry,
382         .next_hops = NULL,
383         .is_recursive = 0,
384         .fct = fct,
385     };
386
387     /*
388      * As an optimisation we allocate the vector of next-hops to be sized
389      * equal to the maximum nuber of paths we will need, which is also the
390      * most likely number we will need, since in most cases the paths are 'up'.
391      */
392     vec_validate(ctx.next_hops, fib_path_list_get_n_paths(esrc->fes_pl));
393     vec_reset_length(ctx.next_hops);
394
395     lb_proto = fib_proto_to_dpo(fib_entry->fe_prefix.fp_proto);
396
397     fib_path_list_walk(esrc->fes_pl,
398                        fib_entry_src_collect_forwarding,
399                        &ctx);
400
401     if (esrc->fes_entry_flags & FIB_ENTRY_FLAG_EXCLUSIVE)
402     {
403         /*
404          * the client provided the DPO that the entry should link to.
405          * all entries must link to a LB, so if it is an LB already
406          * then we can use it.
407          */
408         if ((1 == vec_len(ctx.next_hops)) &&
409             (DPO_LOAD_BALANCE == ctx.next_hops[0].path_dpo.dpoi_type))
410         {
411             dpo_copy(dpo_lb, &ctx.next_hops[0].path_dpo);
412             dpo_reset(&ctx.next_hops[0].path_dpo);
413             return;
414         }
415     }
416
417     if (!dpo_id_is_valid(dpo_lb))
418     {
419         /*
420          * first time create
421          */
422         flow_hash_config_t fhc;
423
424         fhc = fib_table_get_flow_hash_config(fib_entry->fe_fib_index,
425                                              dpo_proto_to_fib(lb_proto));
426         dpo_set(dpo_lb,
427                 DPO_LOAD_BALANCE,
428                 lb_proto,
429                 load_balance_create(0, lb_proto, fhc));
430     }
431
432     load_balance_multipath_update(dpo_lb,
433                                   ctx.next_hops,
434                                   fib_entry_calc_lb_flags(&ctx));
435     vec_free(ctx.next_hops);
436
437     /*
438      * if this entry is sourced by the uRPF-exempt source then we
439      * append the always present local0 interface (index 0) to the
440      * uRPF list so it is not empty. that way packets pass the loose check.
441      */
442     index_t ui = fib_path_list_get_urpf(esrc->fes_pl);
443
444     if (fib_entry_is_sourced(fib_entry_get_index(fib_entry),
445                              FIB_SOURCE_URPF_EXEMPT) &&
446         (0 == fib_urpf_check_size(ui)))
447     {
448         /*
449          * The uRPF list we get from the path-list is shared by all
450          * other users of the list, but the uRPF exemption applies
451          * only to this prefix. So we need our own list.
452          */
453         ui = fib_urpf_list_alloc_and_lock();
454         fib_urpf_list_append(ui, 0);
455         fib_urpf_list_bake(ui);
456         load_balance_set_urpf(dpo_lb->dpoi_index, ui);
457         fib_urpf_list_unlock(ui);
458     }
459     else
460     {
461         load_balance_set_urpf(dpo_lb->dpoi_index, ui);
462     }
463     load_balance_set_fib_entry_flags(dpo_lb->dpoi_index,
464                                      fib_entry_get_flags_i(fib_entry));
465 }
466
467 void
468 fib_entry_src_action_install (fib_entry_t *fib_entry,
469                               fib_source_t source)
470 {
471     /*
472      * Install the forwarding chain for the given source into the forwarding
473      * tables
474      */
475     fib_forward_chain_type_t fct;
476     fib_entry_src_t *esrc;
477     int insert;
478
479     fct = fib_entry_get_default_chain_type(fib_entry);
480     esrc = fib_entry_src_find(fib_entry, source, NULL);
481
482     /*
483      * Every entry has its own load-balance object. All changes to the entry's
484      * forwarding result in an inplace modify of the load-balance. This means
485      * the load-balance object only needs to be added to the forwarding
486      * DB once, when it is created.
487      */
488     insert = !dpo_id_is_valid(&fib_entry->fe_lb);
489
490     fib_entry_src_mk_lb(fib_entry, esrc, fct, &fib_entry->fe_lb);
491
492     ASSERT(dpo_id_is_valid(&fib_entry->fe_lb));
493     FIB_ENTRY_DBG(fib_entry, "install: %d", fib_entry->fe_lb);
494
495     /*
496      * insert the adj into the data-plane forwarding trie
497      */
498     if (insert)
499     {
500        fib_table_fwding_dpo_update(fib_entry->fe_fib_index,
501                                    &fib_entry->fe_prefix,
502                                    &fib_entry->fe_lb);
503     }
504
505     /*
506      * if any of the other chain types are already created they will need
507      * updating too
508      */
509     fib_entry_delegate_type_t fdt;
510     fib_entry_delegate_t *fed;
511
512     FOR_EACH_DELEGATE_CHAIN(fib_entry, fdt, fed,
513     {
514         fib_entry_src_mk_lb(fib_entry, esrc,
515                             fib_entry_delegate_type_to_chain_type(fdt),
516                             &fed->fd_dpo);
517     });
518 }
519
520 void
521 fib_entry_src_action_uninstall (fib_entry_t *fib_entry)
522 {
523     /*
524      * uninstall the forwarding chain from the forwarding tables
525      */
526     FIB_ENTRY_DBG(fib_entry, "uninstall: %d",
527                   fib_entry->fe_adj_index);
528
529     if (dpo_id_is_valid(&fib_entry->fe_lb))
530     {
531         fib_table_fwding_dpo_remove(
532             fib_entry->fe_fib_index,
533             &fib_entry->fe_prefix,
534             &fib_entry->fe_lb);
535
536         dpo_reset(&fib_entry->fe_lb);
537     }
538 }
539
540 static void
541 fib_entry_recursive_loop_detect_i (fib_node_index_t path_list_index)
542 {
543     fib_node_index_t *entries = NULL;
544
545     fib_path_list_recursive_loop_detect(path_list_index, &entries);
546
547     vec_free(entries);
548 }
549
550 void
551 fib_entry_src_action_activate (fib_entry_t *fib_entry,
552                                fib_source_t source)
553
554 {
555     int houston_we_are_go_for_install;
556     fib_entry_src_t *esrc;
557
558     esrc = fib_entry_src_find(fib_entry, source, NULL);
559
560     ASSERT(!(esrc->fes_flags & FIB_ENTRY_SRC_FLAG_ACTIVE));
561     ASSERT(esrc->fes_flags & FIB_ENTRY_SRC_FLAG_ADDED);
562
563     esrc->fes_flags |= FIB_ENTRY_SRC_FLAG_ACTIVE;
564
565     if (NULL != fib_entry_src_vft[source].fesv_activate)
566     {
567         houston_we_are_go_for_install =
568             fib_entry_src_vft[source].fesv_activate(esrc, fib_entry);
569     }
570     else
571     {
572         /*
573          * the source is not providing an activate function, we'll assume
574          * therefore it has no objection to installing the entry
575          */
576         houston_we_are_go_for_install = !0;
577     }
578
579     /*
580      * link to the path-list provided by the source, and go check
581      * if that forms any loops in the graph.
582      */
583     fib_entry->fe_parent = esrc->fes_pl;
584     fib_entry->fe_sibling =
585         fib_path_list_child_add(fib_entry->fe_parent,
586                                 FIB_NODE_TYPE_ENTRY,
587                                 fib_entry_get_index(fib_entry));
588
589     fib_entry_recursive_loop_detect_i(fib_entry->fe_parent);
590
591     FIB_ENTRY_DBG(fib_entry, "activate: %d",
592                   fib_entry->fe_parent);
593
594     if (0 != houston_we_are_go_for_install)
595     {
596         fib_entry_src_action_install(fib_entry, source);
597     }
598     else
599     {
600         fib_entry_src_action_uninstall(fib_entry);
601     }
602 }
603
604 void
605 fib_entry_src_action_deactivate (fib_entry_t *fib_entry,
606                                  fib_source_t source)
607
608 {
609     fib_node_index_t path_list_index;
610     fib_entry_src_t *esrc;
611
612     esrc = fib_entry_src_find(fib_entry, source, NULL);
613
614     ASSERT(esrc->fes_flags & FIB_ENTRY_SRC_FLAG_ACTIVE);
615
616     if (NULL != fib_entry_src_vft[source].fesv_deactivate)
617     {
618         fib_entry_src_vft[source].fesv_deactivate(esrc, fib_entry);
619     }
620
621     esrc->fes_flags &= ~FIB_ENTRY_SRC_FLAG_ACTIVE;
622
623     FIB_ENTRY_DBG(fib_entry, "deactivate: %d", fib_entry->fe_parent);
624
625     /*
626      * un-link from an old path-list. Check for any loops this will clear
627      */
628     path_list_index = fib_entry->fe_parent;
629     fib_entry->fe_parent = FIB_NODE_INDEX_INVALID;
630
631     fib_entry_recursive_loop_detect_i(path_list_index);
632
633     /*
634      * this will unlock the path-list, so it may be invalid thereafter.
635      */
636     fib_path_list_child_remove(path_list_index, fib_entry->fe_sibling);
637     fib_entry->fe_sibling = FIB_NODE_INDEX_INVALID;
638 }
639
640 static void
641 fib_entry_src_action_fwd_update (const fib_entry_t *fib_entry,
642                                  fib_source_t source)
643 {
644     fib_entry_src_t *esrc;
645
646     vec_foreach(esrc, fib_entry->fe_srcs)
647     {
648         if (NULL != fib_entry_src_vft[esrc->fes_src].fesv_fwd_update)
649         {
650             fib_entry_src_vft[esrc->fes_src].fesv_fwd_update(esrc,
651                                                              fib_entry,
652                                                              source);
653         }
654     }
655 }
656
657 void
658 fib_entry_src_action_reactivate (fib_entry_t *fib_entry,
659                                  fib_source_t source)
660 {
661     fib_node_index_t path_list_index;
662     fib_entry_src_t *esrc;
663
664     esrc = fib_entry_src_find(fib_entry, source, NULL);
665
666     ASSERT(esrc->fes_flags & FIB_ENTRY_SRC_FLAG_ACTIVE);
667
668     FIB_ENTRY_DBG(fib_entry, "reactivate: %d to %d",
669                   fib_entry->fe_parent,
670                   esrc->fes_pl);
671
672     if (fib_entry->fe_parent != esrc->fes_pl)
673     {
674         /*
675          * un-link from an old path-list. Check for any loops this will clear
676          */
677         path_list_index = fib_entry->fe_parent;
678         fib_entry->fe_parent = FIB_NODE_INDEX_INVALID;
679
680         /*
681          * temporary lock so it doesn't get deleted when this entry is no
682          * longer a child.
683          */
684         fib_path_list_lock(path_list_index);
685
686         /*
687          * this entry is no longer a child. after unlinking check if any loops
688          * were broken
689          */
690         fib_path_list_child_remove(path_list_index,
691                                    fib_entry->fe_sibling);
692
693         fib_entry_recursive_loop_detect_i(path_list_index);
694
695         /*
696          * link to the path-list provided by the source, and go check
697          * if that forms any loops in the graph.
698          */
699         fib_entry->fe_parent = esrc->fes_pl;
700         fib_entry->fe_sibling =
701             fib_path_list_child_add(fib_entry->fe_parent,
702                                     FIB_NODE_TYPE_ENTRY,
703                                     fib_entry_get_index(fib_entry));
704
705         fib_entry_recursive_loop_detect_i(fib_entry->fe_parent);
706         fib_path_list_unlock(path_list_index);
707     }
708     fib_entry_src_action_install(fib_entry, source);
709     fib_entry_src_action_fwd_update(fib_entry, source);
710 }
711
712 void
713 fib_entry_src_action_installed (const fib_entry_t *fib_entry,
714                                 fib_source_t source)
715 {
716     fib_entry_src_t *esrc;
717
718     esrc = fib_entry_src_find(fib_entry, source, NULL);
719
720     if (NULL != fib_entry_src_vft[source].fesv_installed)
721     {
722         fib_entry_src_vft[source].fesv_installed(esrc,
723                                                  fib_entry);
724     }
725
726     fib_entry_src_action_fwd_update(fib_entry, source);
727 }
728
729 /*
730  * fib_entry_src_action_add
731  *
732  * Adding a source can result in a new fib_entry being created, which
733  * can inturn mean the pool is realloc'd and thus the entry passed as
734  * an argument it also realloc'd
735  * @return the original entry
736  */
737 fib_entry_t *
738 fib_entry_src_action_add (fib_entry_t *fib_entry,
739                           fib_source_t source,
740                           fib_entry_flag_t flags,
741                           const dpo_id_t *dpo)
742 {
743     fib_node_index_t fib_entry_index;
744     fib_entry_src_t *esrc;
745
746     esrc = fib_entry_src_find_or_create(fib_entry, source, NULL);
747
748     esrc->fes_ref_count++;
749
750     if (1 != esrc->fes_ref_count)
751     {
752         /*
753          * we only want to add the source on the 0->1 transition
754          */
755         return (fib_entry);
756     }
757
758     esrc->fes_entry_flags = flags;
759
760     /*
761      * save variable so we can recover from a fib_entry realloc.
762      */
763     fib_entry_index = fib_entry_get_index(fib_entry);
764
765     if (NULL != fib_entry_src_vft[source].fesv_add)
766     {
767         fib_entry_src_vft[source].fesv_add(esrc,
768                                            fib_entry,
769                                            flags,
770                                            fib_entry_get_proto(fib_entry),
771                                            dpo);
772     }
773
774     fib_entry = fib_entry_get(fib_entry_index);
775
776     esrc->fes_flags |= FIB_ENTRY_SRC_FLAG_ADDED;
777
778     fib_path_list_lock(esrc->fes_pl);
779
780     /*
781      * the source owns a lock on the entry
782      */
783     fib_entry_lock(fib_entry_get_index(fib_entry));
784
785     return (fib_entry);
786 }
787
788 /*
789  * fib_entry_src_action_update
790  *
791  * Adding a source can result in a new fib_entry being created, which
792  * can inturn mean the pool is realloc'd and thus the entry passed as
793  * an argument it also realloc'd
794  * @return the original entry
795  */
796 fib_entry_t *
797 fib_entry_src_action_update (fib_entry_t *fib_entry,
798                              fib_source_t source,
799                              fib_entry_flag_t flags,
800                              const dpo_id_t *dpo)
801 {
802     fib_node_index_t fib_entry_index, old_path_list_index;
803     fib_entry_src_t *esrc;
804
805     esrc = fib_entry_src_find_or_create(fib_entry, source, NULL);
806
807     if (NULL == esrc)
808         return (fib_entry_src_action_add(fib_entry, source, flags, dpo));
809
810     old_path_list_index = esrc->fes_pl;
811     esrc->fes_entry_flags = flags;
812
813     /*
814      * save variable so we can recover from a fib_entry realloc.
815      */
816     fib_entry_index = fib_entry_get_index(fib_entry);
817
818     if (NULL != fib_entry_src_vft[source].fesv_add)
819     {
820         fib_entry_src_vft[source].fesv_add(esrc,
821                                            fib_entry,
822                                            flags,
823                                            fib_entry_get_proto(fib_entry),
824                                            dpo);
825     }
826
827     fib_entry = fib_entry_get(fib_entry_index);
828
829     esrc->fes_flags |= FIB_ENTRY_SRC_FLAG_ADDED;
830
831     fib_path_list_lock(esrc->fes_pl);
832     fib_path_list_unlock(old_path_list_index);
833
834     return (fib_entry);
835 }
836
837
838 fib_entry_src_flag_t
839 fib_entry_src_action_remove (fib_entry_t *fib_entry,
840                              fib_source_t source)
841
842 {
843     fib_node_index_t old_path_list;
844     fib_entry_src_flag_t sflags;
845     fib_entry_src_t *esrc;
846
847     esrc = fib_entry_src_find(fib_entry, source, NULL);
848
849     if (NULL == esrc)
850         return (FIB_ENTRY_SRC_FLAG_ACTIVE);
851
852     esrc->fes_ref_count--;
853     sflags = esrc->fes_flags;
854
855     if (0 != esrc->fes_ref_count)
856     {
857         /*
858          * only remove the source on the 1->0 transisition
859          */
860         return (sflags);
861     }
862
863     if (esrc->fes_flags & FIB_ENTRY_SRC_FLAG_ACTIVE)
864     {
865         fib_entry_src_action_deactivate(fib_entry, source);
866     }
867
868     old_path_list = esrc->fes_pl;
869
870     if (NULL != fib_entry_src_vft[source].fesv_remove)
871     {
872         fib_entry_src_vft[source].fesv_remove(esrc);
873     }
874
875     fib_path_list_unlock(old_path_list);
876     fib_entry_unlock(fib_entry_get_index(fib_entry));
877
878     sflags &= ~FIB_ENTRY_SRC_FLAG_ADDED;
879     fib_entry_src_action_deinit(fib_entry, source);
880
881     return (sflags);
882 }
883
884 static inline int
885 fib_route_recurses_via_self (const fib_prefix_t *prefix,
886                              const fib_route_path_t *rpath)
887 {
888     /*
889      * not all zeros next hop &&
890      * is recursive path &&
891      * nexthop is same as the route's address
892      */
893     return ((!ip46_address_is_zero(&rpath->frp_addr)) &&
894             (~0 == rpath->frp_sw_if_index) &&
895             (0 == ip46_address_cmp(&rpath->frp_addr, &prefix->fp_addr)));
896
897 }
898
899 /*
900  * fib_route_attached_cross_table
901  *
902  * Return true the the route is attached via an interface that
903  * is not in the same table as the route
904  */
905 static inline int
906 fib_route_attached_cross_table (const fib_entry_t *fib_entry,
907                                 const fib_route_path_t *rpath)
908 {
909     /*
910      * - All zeros next-hop
911      * - a valid interface
912      * - entry's fib index not equeal to interface's index
913      */
914     if (ip46_address_is_zero(&rpath->frp_addr) &&
915         (~0 != rpath->frp_sw_if_index) &&
916         (fib_entry->fe_fib_index != 
917          fib_table_get_index_for_sw_if_index(fib_entry_get_proto(fib_entry),
918                                              rpath->frp_sw_if_index)))
919     {
920         return (!0);
921     }
922     return (0);
923 }
924
925 /*
926  * fib_route_attached_cross_table
927  *
928  * Return true the the route is attached via an interface that
929  * is not in the same table as the route
930  */
931 static inline int
932 fib_path_is_attached (const fib_route_path_t *rpath)
933 {
934     /*
935      * - All zeros next-hop
936      * - a valid interface
937      */
938     if (ip46_address_is_zero(&rpath->frp_addr) &&
939         (~0 != rpath->frp_sw_if_index))
940     {
941         return (!0);
942     }
943     return (0);
944 }
945
946 fib_path_list_flags_t
947 fib_entry_src_flags_2_path_list_flags (fib_entry_flag_t eflags)
948 {
949     fib_path_list_flags_t plf = FIB_PATH_LIST_FLAG_NONE;
950
951     if (eflags & FIB_ENTRY_FLAG_DROP)
952     {
953         plf |= FIB_PATH_LIST_FLAG_DROP;
954     }
955     if (eflags & FIB_ENTRY_FLAG_LOCAL)
956     {
957         plf |= FIB_PATH_LIST_FLAG_LOCAL;
958     }
959     if (eflags & FIB_ENTRY_FLAG_EXCLUSIVE)
960     {
961         plf |= FIB_PATH_LIST_FLAG_EXCLUSIVE;
962     }
963
964     return (plf);
965 }
966
967 static void
968 fib_entry_flags_update (const fib_entry_t *fib_entry,
969                         const fib_route_path_t *rpath,
970                         fib_path_list_flags_t *pl_flags,
971                         fib_entry_src_t *esrc)
972 {
973     /*
974      * don't allow the addition of a recursive looped path for prefix
975      * via itself.
976      */
977     if (fib_route_recurses_via_self(&fib_entry->fe_prefix, rpath))      
978     {
979         /*
980          * force the install of a drop path-list.
981          * we want the entry to have some path-list, mainly so
982          * the dodgy path can be rmeoved when the source stops playing
983          * silly buggers.
984          */
985         *pl_flags |= FIB_PATH_LIST_FLAG_DROP;
986     }
987     else
988     {
989         *pl_flags &= ~FIB_PATH_LIST_FLAG_DROP;
990     }
991
992     if ((esrc->fes_src == FIB_SOURCE_API) ||
993         (esrc->fes_src == FIB_SOURCE_CLI))
994     {
995         if (fib_path_is_attached(rpath))
996         {
997             esrc->fes_entry_flags |= FIB_ENTRY_FLAG_ATTACHED;
998         }
999         else
1000         {
1001             esrc->fes_entry_flags &= ~FIB_ENTRY_FLAG_ATTACHED;
1002         }
1003     }
1004     if (fib_route_attached_cross_table(fib_entry, rpath))
1005     {
1006         esrc->fes_entry_flags |= FIB_ENTRY_FLAG_IMPORT;
1007     }
1008     else
1009     {
1010         esrc->fes_entry_flags &= ~FIB_ENTRY_FLAG_IMPORT;
1011     }
1012 }
1013
1014 /*
1015  * fib_entry_src_path_ext_add
1016  *
1017  * append a path extension to the entry's list
1018  */
1019 static void
1020 fib_entry_src_path_ext_append (fib_entry_src_t *esrc,
1021                                const fib_route_path_t *rpath)
1022 {
1023     if (NULL != rpath->frp_label_stack)
1024     {
1025         fib_path_ext_t *path_ext;
1026
1027         vec_add2(esrc->fes_path_exts, path_ext, 1);
1028
1029         fib_path_ext_init(path_ext, esrc->fes_pl, rpath);
1030     }
1031 }
1032
1033 /*
1034  * fib_entry_src_path_ext_insert
1035  *
1036  * insert, sorted, a path extension to the entry's list.
1037  * It's not strictly necessary in sort the path extensions, since each
1038  * extension has the path index to which it resolves. However, by being
1039  * sorted the load-balance produced has a deterministic order, not an order
1040  * based on the sequence of extension additions. this is a considerable benefit.
1041  */
1042 static void
1043 fib_entry_src_path_ext_insert (fib_entry_src_t *esrc,
1044                                const fib_route_path_t *rpath)
1045 {
1046     if (0 == vec_len(esrc->fes_path_exts))
1047         return (fib_entry_src_path_ext_append(esrc, rpath));
1048
1049     if (NULL != rpath->frp_label_stack)
1050     {
1051         fib_path_ext_t path_ext;
1052         int i = 0;
1053
1054         fib_path_ext_init(&path_ext, esrc->fes_pl, rpath);
1055
1056         while (i < vec_len(esrc->fes_path_exts) &&
1057                (fib_path_ext_cmp(&esrc->fes_path_exts[i], rpath) < 0))
1058         {
1059             i++;
1060         }
1061
1062         vec_insert_elts(esrc->fes_path_exts, &path_ext, 1, i);
1063     }
1064 }
1065
1066 /*
1067  * fib_entry_src_action_add
1068  *
1069  * Adding a source can result in a new fib_entry being created, which
1070  * can inturn mean the pool is realloc'd and thus the entry passed as
1071  * an argument it also realloc'd
1072  * @return the entry
1073  */
1074 fib_entry_t*
1075 fib_entry_src_action_path_add (fib_entry_t *fib_entry,
1076                                fib_source_t source,
1077                                fib_entry_flag_t flags,
1078                                const fib_route_path_t *rpath)
1079 {
1080     fib_node_index_t old_path_list, fib_entry_index;
1081     fib_path_list_flags_t pl_flags;
1082     fib_path_ext_t *path_ext;
1083     fib_entry_src_t *esrc;
1084
1085     /*
1086      * save variable so we can recover from a fib_entry realloc.
1087      */
1088     fib_entry_index = fib_entry_get_index(fib_entry);
1089
1090     esrc = fib_entry_src_find(fib_entry, source, NULL);
1091     if (NULL == esrc)
1092     {
1093         fib_entry =
1094             fib_entry_src_action_add(fib_entry,
1095                                      source,
1096                                      flags,
1097                                      drop_dpo_get(
1098                                          fib_proto_to_dpo(
1099                                              fib_entry_get_proto(fib_entry))));
1100         esrc = fib_entry_src_find(fib_entry, source, NULL);
1101     }
1102
1103     /*
1104      * we are no doubt modifying a path-list. If the path-list
1105      * is shared, and hence not modifiable, then the index returned
1106      * will be for a different path-list. This FIB entry to needs
1107      * to maintain its lock appropriately.
1108      */
1109     old_path_list = esrc->fes_pl;
1110
1111     ASSERT(NULL != fib_entry_src_vft[source].fesv_path_add);
1112
1113     pl_flags = fib_entry_src_flags_2_path_list_flags(fib_entry_get_flags_i(fib_entry));
1114     fib_entry_flags_update(fib_entry, rpath, &pl_flags, esrc);
1115
1116     fib_entry_src_vft[source].fesv_path_add(esrc, fib_entry, pl_flags, rpath);
1117     fib_entry = fib_entry_get(fib_entry_index);
1118
1119     /*
1120      * re-resolve all the path-extensions with the new path-list
1121      */
1122     vec_foreach(path_ext, esrc->fes_path_exts)
1123     {
1124         fib_path_ext_resolve(path_ext, esrc->fes_pl);
1125     }
1126     /*
1127      * if the path has a label we need to add a path extension
1128      */
1129     fib_entry_src_path_ext_insert(esrc, rpath);
1130
1131     fib_path_list_lock(esrc->fes_pl);
1132     fib_path_list_unlock(old_path_list);
1133
1134     return (fib_entry);
1135 }
1136
1137 /*
1138  * fib_entry_src_action_swap
1139  *
1140  * The source is providing new paths to replace the old ones.
1141  * Adding a source can result in a new fib_entry being created, which
1142  * can inturn mean the pool is realloc'd and thus the entry passed as
1143  * an argument it also realloc'd
1144  * @return the entry
1145  */
1146 fib_entry_t*
1147 fib_entry_src_action_path_swap (fib_entry_t *fib_entry,
1148                                 fib_source_t source,
1149                                 fib_entry_flag_t flags,                         
1150                                 const fib_route_path_t *rpaths)
1151 {
1152     fib_node_index_t old_path_list, fib_entry_index;
1153     fib_path_list_flags_t pl_flags;
1154     const fib_route_path_t *rpath;
1155     fib_path_ext_t *path_ext;
1156     fib_entry_src_t *esrc;
1157
1158     esrc = fib_entry_src_find(fib_entry, source, NULL);
1159
1160     /*
1161      * save variable so we can recover from a fib_entry realloc.
1162      */
1163     fib_entry_index = fib_entry_get_index(fib_entry);
1164
1165     if (NULL == esrc)
1166     {
1167         fib_entry = fib_entry_src_action_add(fib_entry,
1168                                              source,
1169                                              flags,
1170                                              drop_dpo_get(
1171                                                  fib_proto_to_dpo(
1172                                                      fib_entry_get_proto(fib_entry))));
1173         esrc = fib_entry_src_find(fib_entry, source, NULL);
1174     }
1175
1176     /*
1177      * swapping paths may create a new path-list (or may use an existing shared)
1178      * but we are certainly getting a different one. This FIB entry to needs
1179      * to maintain its lock appropriately.
1180      */
1181     old_path_list = esrc->fes_pl;
1182
1183     ASSERT(NULL != fib_entry_src_vft[source].fesv_path_swap);
1184
1185     pl_flags = fib_entry_src_flags_2_path_list_flags(flags);
1186
1187     vec_foreach(rpath, rpaths)
1188     {
1189         fib_entry_flags_update(fib_entry, rpath, &pl_flags, esrc);
1190     }
1191
1192     fib_entry_src_vft[source].fesv_path_swap(esrc,
1193                                              fib_entry,
1194                                              pl_flags,
1195                                              rpaths);
1196
1197     vec_foreach(path_ext, esrc->fes_path_exts)
1198     {
1199         vec_free(path_ext->fpe_label_stack);
1200     }
1201     vec_free(esrc->fes_path_exts);
1202
1203     vec_foreach(rpath, rpaths)
1204     {
1205         fib_entry_src_path_ext_append(esrc, rpath);
1206     }
1207
1208     fib_entry = fib_entry_get(fib_entry_index);
1209
1210     fib_path_list_lock(esrc->fes_pl);
1211     fib_path_list_unlock(old_path_list);
1212
1213     return (fib_entry);
1214 }
1215
1216 fib_entry_src_flag_t
1217 fib_entry_src_action_path_remove (fib_entry_t *fib_entry,
1218                                   fib_source_t source,
1219                                   const fib_route_path_t *rpath)
1220 {
1221     fib_path_list_flags_t pl_flags;
1222     fib_node_index_t old_path_list;
1223     fib_path_ext_t *path_ext;
1224     fib_entry_src_t *esrc;
1225
1226     esrc = fib_entry_src_find(fib_entry, source, NULL);
1227
1228     ASSERT(NULL != esrc);
1229     ASSERT(esrc->fes_flags & FIB_ENTRY_SRC_FLAG_ADDED);
1230
1231     /*
1232      * we no doubt modifying a path-list. If the path-list
1233      * is shared, and hence not modifiable, then the index returned
1234      * will be for a different path-list. This FIB entry to needs
1235      * to maintain its lock appropriately.
1236      */
1237     old_path_list = esrc->fes_pl;
1238
1239     ASSERT(NULL != fib_entry_src_vft[source].fesv_path_remove);
1240
1241     pl_flags = fib_entry_src_flags_2_path_list_flags(fib_entry_get_flags_i(fib_entry));
1242     fib_entry_flags_update(fib_entry, rpath, &pl_flags, esrc);
1243
1244     fib_entry_src_vft[source].fesv_path_remove(esrc, pl_flags, rpath);
1245     /*
1246      * find the matching path extension and remove it
1247      */
1248     vec_foreach(path_ext, esrc->fes_path_exts)
1249     {
1250         if (!fib_path_ext_cmp(path_ext, rpath))
1251         {
1252             /*
1253              * delete the element moving the remaining elements down 1 position.
1254              * this preserves the sorted order.
1255              */
1256             vec_free(path_ext->fpe_label_stack);
1257             vec_delete(esrc->fes_path_exts, 1, (path_ext - esrc->fes_path_exts));
1258             break;
1259         }
1260     }
1261     /*
1262      * re-resolve all the path-extensions with the new path-list
1263      */
1264     vec_foreach(path_ext, esrc->fes_path_exts)
1265     {
1266         fib_path_ext_resolve(path_ext, esrc->fes_pl);
1267     }
1268
1269     /*
1270      * lock the new path-list, unlock the old if it had one
1271      */
1272     fib_path_list_unlock(old_path_list);
1273
1274     if (FIB_NODE_INDEX_INVALID != esrc->fes_pl) {
1275         fib_path_list_lock(esrc->fes_pl);
1276         return (FIB_ENTRY_SRC_FLAG_ADDED);
1277     }
1278     else
1279     {
1280         /*
1281          * no more paths left from this source
1282          */
1283         fib_entry_src_action_remove(fib_entry, source);
1284         return (FIB_ENTRY_SRC_FLAG_NONE);
1285     }
1286 }
1287
1288 u8*
1289 fib_entry_src_format (fib_entry_t *fib_entry,
1290                       fib_source_t source,
1291                       u8* s)
1292 {
1293     fib_entry_src_t *esrc;
1294
1295     esrc = fib_entry_src_find(fib_entry, source, NULL);
1296
1297     if (NULL != fib_entry_src_vft[source].fesv_format)
1298     {
1299         return (fib_entry_src_vft[source].fesv_format(esrc, s));
1300     }
1301     return (s);
1302 }
1303
1304 adj_index_t
1305 fib_entry_get_adj_for_source (fib_node_index_t fib_entry_index,
1306                               fib_source_t source)
1307 {
1308     fib_entry_t *fib_entry;
1309     fib_entry_src_t *esrc;
1310
1311     if (FIB_NODE_INDEX_INVALID == fib_entry_index)
1312         return (ADJ_INDEX_INVALID);
1313
1314     fib_entry = fib_entry_get(fib_entry_index);
1315     esrc = fib_entry_src_find(fib_entry, source, NULL);
1316
1317     if (NULL != esrc)
1318     {
1319         if (FIB_NODE_INDEX_INVALID != esrc->fes_pl)
1320         {
1321             return (fib_path_list_get_adj(
1322                         esrc->fes_pl,
1323                         fib_entry_get_default_chain_type(fib_entry)));
1324         }
1325     }
1326     return (ADJ_INDEX_INVALID);
1327 }
1328
1329 const int
1330 fib_entry_get_dpo_for_source (fib_node_index_t fib_entry_index,
1331                               fib_source_t source,
1332                               dpo_id_t *dpo)
1333 {
1334     fib_entry_t *fib_entry;
1335     fib_entry_src_t *esrc;
1336
1337     if (FIB_NODE_INDEX_INVALID == fib_entry_index)
1338         return (0);
1339
1340     fib_entry = fib_entry_get(fib_entry_index);
1341     esrc = fib_entry_src_find(fib_entry, source, NULL);
1342
1343     if (NULL != esrc)
1344     {
1345         if (FIB_NODE_INDEX_INVALID != esrc->fes_pl)
1346         {
1347             fib_path_list_contribute_forwarding(
1348                 esrc->fes_pl,
1349                 fib_entry_get_default_chain_type(fib_entry),
1350                 dpo);
1351
1352             return (dpo_id_is_valid(dpo));
1353         }
1354     }
1355     return (0);
1356 }
1357
1358 u32
1359 fib_entry_get_resolving_interface_for_source (fib_node_index_t entry_index,
1360                                               fib_source_t source)
1361 {
1362     fib_entry_t *fib_entry;
1363     fib_entry_src_t *esrc;
1364
1365     fib_entry = fib_entry_get(entry_index);
1366
1367     esrc = fib_entry_src_find(fib_entry, source, NULL);
1368
1369     if (NULL != esrc)
1370     {
1371         if (FIB_NODE_INDEX_INVALID != esrc->fes_pl)
1372         {
1373             return (fib_path_list_get_resolving_interface(esrc->fes_pl));
1374         }
1375     }
1376     return (~0);
1377 }
1378
1379 fib_entry_flag_t
1380 fib_entry_get_flags_for_source (fib_node_index_t entry_index,
1381                                 fib_source_t source)
1382 {
1383     fib_entry_t *fib_entry;
1384     fib_entry_src_t *esrc;
1385
1386     fib_entry = fib_entry_get(entry_index);
1387
1388     esrc = fib_entry_src_find(fib_entry, source, NULL);
1389
1390     if (NULL != esrc)
1391     {
1392         return (esrc->fes_entry_flags);
1393     }
1394
1395     return (FIB_ENTRY_FLAG_NONE);
1396 }
1397
1398 fib_entry_flag_t
1399 fib_entry_get_flags_i (const fib_entry_t *fib_entry)
1400 {
1401     fib_entry_flag_t flags;
1402
1403     /*
1404      * the vector of sources is deliberately arranged in priority order
1405      */
1406     if (0 == vec_len(fib_entry->fe_srcs))
1407     {
1408         flags = FIB_ENTRY_FLAG_NONE;
1409     }
1410     else
1411     {
1412         fib_entry_src_t *esrc;
1413
1414         esrc = vec_elt_at_index(fib_entry->fe_srcs, 0);
1415         flags = esrc->fes_entry_flags;
1416     }
1417
1418     return (flags);
1419 }
1420
1421 void
1422 fib_entry_set_source_data (fib_node_index_t fib_entry_index,
1423                            fib_source_t source,
1424                            const void *data)
1425 {
1426     fib_entry_t *fib_entry;
1427     fib_entry_src_t *esrc;
1428
1429     fib_entry = fib_entry_get(fib_entry_index);
1430     esrc = fib_entry_src_find(fib_entry, source, NULL);
1431
1432     if (NULL != esrc &&
1433         NULL != fib_entry_src_vft[source].fesv_set_data)
1434     {
1435         fib_entry_src_vft[source].fesv_set_data(esrc, fib_entry, data);
1436     }
1437 }
1438
1439 const void*
1440 fib_entry_get_source_data (fib_node_index_t fib_entry_index,
1441                            fib_source_t source)
1442 {
1443     fib_entry_t *fib_entry;
1444     fib_entry_src_t *esrc;
1445
1446     fib_entry = fib_entry_get(fib_entry_index);
1447     esrc = fib_entry_src_find(fib_entry, source, NULL);
1448
1449     if (NULL != esrc &&
1450         NULL != fib_entry_src_vft[source].fesv_get_data)
1451     {
1452         return (fib_entry_src_vft[source].fesv_get_data(esrc, fib_entry));
1453     }
1454     return (NULL);
1455 }
1456
1457 void
1458 fib_entry_src_module_init (void)
1459 {
1460     fib_entry_src_rr_register();
1461     fib_entry_src_interface_register();
1462     fib_entry_src_default_route_register();
1463     fib_entry_src_special_register();
1464     fib_entry_src_api_register();
1465     fib_entry_src_adj_register();
1466     fib_entry_src_mpls_register();
1467     fib_entry_src_lisp_register();
1468 }