A Protocol Independent Hierarchical FIB (VPP-352)
[vpp.git] / vnet / vnet / adj / adj_rewrite.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/adj/adj_alloc.h>
18 #include <vnet/adj/adj_internal.h>
19
20 /**
21  * adj_rewrite_add_and_lock
22  *
23  * A rewrite sub-type has the rewrite string provided, but no key
24  */
25 adj_index_t
26 adj_rewrite_add_and_lock (fib_protocol_t nh_proto,
27                           fib_link_t link_type,
28                           u32 sw_if_index,
29                           u8 *rewrite)
30 {
31     ip_adjacency_t *adj;
32
33     adj = adj_alloc(nh_proto);
34
35     adj->lookup_next_index = IP_LOOKUP_NEXT_REWRITE;
36     adj->ia_link = link_type;
37     adj->rewrite_header.sw_if_index = sw_if_index;
38
39     ASSERT(NULL != rewrite);
40
41     vnet_rewrite_for_sw_interface(vnet_get_main(),
42                                   adj_fib_link_2_vnet(link_type),
43                                   adj->rewrite_header.sw_if_index,
44                                   adj_get_rewrite_node(link_type)->index,
45                                   rewrite,
46                                   &adj->rewrite_header,
47                                   sizeof (adj->rewrite_data));
48
49     adj_lock(adj->heap_handle);
50
51     return (adj->heap_handle);
52 }