blob: 1277bd65af7cb6b07bbbcaba16aa7dd4766487c7 [file] [log] [blame]
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001/*
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 "fib_entry.h"
17#include "fib_entry_src.h"
18#include "fib_path_list.h"
19
20/**
21 * Source initialisation Function
22 */
23static void
24fib_entry_src_api_init (fib_entry_src_t *src)
25{
26}
27
28/**
29 * Source deinitialisation Function
30 */
31static void
32fib_entry_src_api_deinit (fib_entry_src_t *src)
33{
34}
35
36static void
37fib_entry_src_api_path_swap (fib_entry_src_t *src,
38 const fib_entry_t *entry,
39 fib_path_list_flags_t pl_flags,
40 const fib_route_path_t *paths)
41{
42 src->fes_pl = fib_path_list_create((FIB_PATH_LIST_FLAG_SHARED | pl_flags),
43 paths);
44}
45
46static void
47fib_entry_src_api_path_add (fib_entry_src_t *src,
48 const fib_entry_t *entry,
49 fib_path_list_flags_t pl_flags,
50 const fib_route_path_t *paths)
51{
52 if (FIB_NODE_INDEX_INVALID == src->fes_pl)
53 {
54 src->fes_pl =
55 fib_path_list_create((FIB_PATH_LIST_FLAG_SHARED | pl_flags), paths);
56 }
57 else
58 {
59 src->fes_pl =
60 fib_path_list_copy_and_path_add(src->fes_pl,
61 (FIB_PATH_LIST_FLAG_SHARED | pl_flags),
62 paths);
63 }
64}
65
66static void
67fib_entry_src_api_path_remove (fib_entry_src_t *src,
68 fib_path_list_flags_t pl_flags,
69 const fib_route_path_t *paths)
70{
71 if (FIB_NODE_INDEX_INVALID != src->fes_pl)
72 {
73 src->fes_pl =
74 fib_path_list_copy_and_path_remove(src->fes_pl,
75 (FIB_PATH_LIST_FLAG_SHARED | pl_flags),
76 paths);
77 }
78}
79
80static void
81fib_entry_src_api_add (fib_entry_src_t *src,
82 const fib_entry_t *entry,
83 fib_entry_flag_t flags,
84 fib_protocol_t proto,
85 const dpo_id_t *dpo)
86{
87 if (FIB_ENTRY_FLAG_NONE != flags)
88 {
89 src->fes_pl = fib_path_list_create_special(
90 proto,
91 fib_entry_src_flags_2_path_list_flags(flags),
92 dpo);
93 }
94}
95
96static void
97fib_entry_src_api_remove (fib_entry_src_t *src)
98{
99 src->fes_pl = FIB_NODE_INDEX_INVALID;
100}
101
102const static fib_entry_src_vft_t api_src_vft = {
103 .fesv_init = fib_entry_src_api_init,
104 .fesv_deinit = fib_entry_src_api_deinit,
105 .fesv_add = fib_entry_src_api_add,
106 .fesv_remove = fib_entry_src_api_remove,
107 .fesv_path_add = fib_entry_src_api_path_add,
108 .fesv_path_swap = fib_entry_src_api_path_swap,
109 .fesv_path_remove = fib_entry_src_api_path_remove,
110};
111
112void
113fib_entry_src_api_register (void)
114{
115 fib_entry_src_register(FIB_SOURCE_PLUGIN_HI, &api_src_vft);
116 fib_entry_src_register(FIB_SOURCE_API, &api_src_vft);
117 fib_entry_src_register(FIB_SOURCE_CLI, &api_src_vft);
118 fib_entry_src_register(FIB_SOURCE_DHCP, &api_src_vft);
Neale Ranns3f844d02017-02-18 00:03:54 -0800119 fib_entry_src_register(FIB_SOURCE_IP6_ND_PROXY, &api_src_vft);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100120}