Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 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> |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 17 | #include <vnet/adj/adj_internal.h> |
| 18 | |
| 19 | /** |
| 20 | * adj_rewrite_add_and_lock |
| 21 | * |
| 22 | * A rewrite sub-type has the rewrite string provided, but no key |
| 23 | */ |
| 24 | adj_index_t |
| 25 | adj_rewrite_add_and_lock (fib_protocol_t nh_proto, |
Neale Ranns | 924d03a | 2016-10-19 08:25:46 +0100 | [diff] [blame] | 26 | vnet_link_t link_type, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 27 | u32 sw_if_index, |
| 28 | u8 *rewrite) |
| 29 | { |
| 30 | ip_adjacency_t *adj; |
| 31 | |
| 32 | adj = adj_alloc(nh_proto); |
| 33 | |
| 34 | adj->lookup_next_index = IP_LOOKUP_NEXT_REWRITE; |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 35 | memset(&adj->sub_type.nbr.next_hop, 0, sizeof(adj->sub_type.nbr.next_hop)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 36 | adj->ia_link = link_type; |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 37 | adj->ia_nh_proto = nh_proto; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 38 | adj->rewrite_header.sw_if_index = sw_if_index; |
| 39 | |
| 40 | ASSERT(NULL != rewrite); |
| 41 | |
| 42 | vnet_rewrite_for_sw_interface(vnet_get_main(), |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 43 | link_type, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 44 | adj->rewrite_header.sw_if_index, |
Neale Ranns | b80c536 | 2016-10-08 13:03:40 +0100 | [diff] [blame] | 45 | adj_get_rewrite_node(link_type), |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 46 | rewrite, |
| 47 | &adj->rewrite_header, |
| 48 | sizeof (adj->rewrite_data)); |
| 49 | |
Neale Ranns | 6c3ebcc | 2016-10-02 21:20:15 +0100 | [diff] [blame] | 50 | adj_lock(adj_get_index(adj)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 51 | |
Neale Ranns | 6c3ebcc | 2016-10-02 21:20:15 +0100 | [diff] [blame] | 52 | return (adj_get_index(adj)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 53 | } |