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.
16 #include <vnet/fib/fib_entry_delegate.h>
17 #include <vnet/fib/fib_entry.h>
19 static fib_entry_delegate_t *
20 fib_entry_delegate_find_i (const fib_entry_t *fib_entry,
21 fib_entry_delegate_type_t type,
24 fib_entry_delegate_t *delegate;
28 vec_foreach(delegate, fib_entry->fe_delegates)
30 if (delegate->fd_type == type)
46 fib_entry_delegate_t *
47 fib_entry_delegate_get (const fib_entry_t *fib_entry,
48 fib_entry_delegate_type_t type)
50 return (fib_entry_delegate_find_i(fib_entry, type, NULL));
54 fib_entry_delegate_remove (fib_entry_t *fib_entry,
55 fib_entry_delegate_type_t type)
57 fib_entry_delegate_t *fed;
60 fed = fib_entry_delegate_find_i(fib_entry, type, &index);
64 vec_del1(fib_entry->fe_delegates, index);
68 fib_entry_delegate_cmp_for_sort (void * v1,
71 fib_entry_delegate_t *delegate1 = v1, *delegate2 = v2;
73 return (delegate1->fd_type - delegate2->fd_type);
77 fib_entry_delegate_init (fib_entry_t *fib_entry,
78 fib_entry_delegate_type_t type)
81 fib_entry_delegate_t delegate = {
82 .fd_entry_index = fib_entry_get_index(fib_entry),
86 vec_add1(fib_entry->fe_delegates, delegate);
87 vec_sort_with_function(fib_entry->fe_delegates,
88 fib_entry_delegate_cmp_for_sort);
91 fib_entry_delegate_t *
92 fib_entry_delegate_find_or_add (fib_entry_t *fib_entry,
93 fib_entry_delegate_type_t fdt)
95 fib_entry_delegate_t *delegate;
97 delegate = fib_entry_delegate_get(fib_entry, fdt);
101 fib_entry_delegate_init(fib_entry, fdt);
104 return (fib_entry_delegate_get(fib_entry, fdt));
107 fib_entry_delegate_type_t
108 fib_entry_chain_type_to_delegate_type (fib_forward_chain_type_t fct)
112 case FIB_FORW_CHAIN_TYPE_UNICAST_IP4:
113 return (FIB_ENTRY_DELEGATE_CHAIN_UNICAST_IP4);
114 case FIB_FORW_CHAIN_TYPE_UNICAST_IP6:
115 return (FIB_ENTRY_DELEGATE_CHAIN_UNICAST_IP6);
116 case FIB_FORW_CHAIN_TYPE_MPLS_EOS:
117 return (FIB_ENTRY_DELEGATE_CHAIN_MPLS_EOS);
118 case FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS:
119 return (FIB_ENTRY_DELEGATE_CHAIN_MPLS_NON_EOS);
120 case FIB_FORW_CHAIN_TYPE_ETHERNET:
121 return (FIB_ENTRY_DELEGATE_CHAIN_ETHERNET);
124 return (FIB_ENTRY_DELEGATE_CHAIN_UNICAST_IP4);
127 fib_forward_chain_type_t
128 fib_entry_delegate_type_to_chain_type (fib_entry_delegate_type_t fdt)
132 case FIB_ENTRY_DELEGATE_CHAIN_UNICAST_IP4:
133 return (FIB_FORW_CHAIN_TYPE_UNICAST_IP4);
134 case FIB_ENTRY_DELEGATE_CHAIN_UNICAST_IP6:
135 return (FIB_FORW_CHAIN_TYPE_UNICAST_IP6);
136 case FIB_ENTRY_DELEGATE_CHAIN_MPLS_EOS:
137 return (FIB_FORW_CHAIN_TYPE_MPLS_EOS);
138 case FIB_ENTRY_DELEGATE_CHAIN_MPLS_NON_EOS:
139 return (FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS);
140 case FIB_ENTRY_DELEGATE_CHAIN_ETHERNET:
141 return (FIB_FORW_CHAIN_TYPE_ETHERNET);
142 case FIB_ENTRY_DELEGATE_COVERED:
143 case FIB_ENTRY_DELEGATE_ATTACHED_IMPORT:
144 case FIB_ENTRY_DELEGATE_ATTACHED_EXPORT:
148 return (FIB_FORW_CHAIN_TYPE_UNICAST_IP4);