Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 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/vnet.h> |
| 17 | #include <vlibmemory/api.h> |
| 18 | #include <vnet/mfib/mfib_api.h> |
| 19 | #include <vnet/mfib/mfib_table.h> |
| 20 | #include <vnet/fib/fib_api.h> |
| 21 | #include <vnet/ip/ip_types_api.h> |
| 22 | |
| 23 | #include <vnet/vnet_msg_enum.h> |
| 24 | |
| 25 | #define vl_typedefs /* define message structures */ |
| 26 | #include <vnet/vnet_all_api_h.h> |
| 27 | #undef vl_typedefs |
| 28 | |
| 29 | #define vl_endianfun /* define message structures */ |
| 30 | #include <vnet/vnet_all_api_h.h> |
| 31 | #undef vl_endianfun |
| 32 | |
| 33 | /* instantiate all the print functions we know about */ |
| 34 | #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) |
| 35 | #define vl_printfun |
| 36 | #include <vnet/vnet_all_api_h.h> |
| 37 | #undef vl_printfun |
| 38 | |
| 39 | static vl_api_mfib_itf_flags_t |
| 40 | mfib_api_path_itf_flags_encode (mfib_itf_flags_t flags) |
| 41 | { |
| 42 | vl_api_mfib_itf_flags_t out = MFIB_API_ITF_FLAG_NONE; |
| 43 | |
| 44 | switch (flags) |
| 45 | { |
| 46 | case MFIB_ITF_FLAG_NONE: |
| 47 | out = MFIB_API_ITF_FLAG_NONE; |
| 48 | break; |
| 49 | case MFIB_ITF_FLAG_NEGATE_SIGNAL: |
| 50 | out = MFIB_API_ITF_FLAG_NEGATE_SIGNAL; |
| 51 | break; |
| 52 | case MFIB_ITF_FLAG_ACCEPT: |
| 53 | out = MFIB_API_ITF_FLAG_ACCEPT; |
| 54 | break; |
| 55 | case MFIB_ITF_FLAG_FORWARD: |
| 56 | out = MFIB_API_ITF_FLAG_FORWARD; |
| 57 | break; |
| 58 | case MFIB_ITF_FLAG_SIGNAL_PRESENT: |
| 59 | out = MFIB_API_ITF_FLAG_SIGNAL_PRESENT; |
| 60 | break; |
| 61 | case MFIB_ITF_FLAG_DONT_PRESERVE: |
| 62 | out = MFIB_API_ITF_FLAG_DONT_PRESERVE; |
| 63 | break; |
| 64 | } |
| 65 | return (ntohl(out)); |
| 66 | } |
| 67 | |
| 68 | void |
| 69 | mfib_api_path_encode (const fib_route_path_t *in, |
| 70 | vl_api_mfib_path_t *out) |
| 71 | { |
| 72 | out->itf_flags = mfib_api_path_itf_flags_encode(in->frp_mitf_flags); |
| 73 | |
| 74 | fib_api_path_encode(in, &out->path); |
| 75 | } |
| 76 | |
| 77 | static void |
| 78 | mfib_api_path_itf_flags_decode (vl_api_mfib_itf_flags_t in, |
| 79 | mfib_itf_flags_t *out) |
| 80 | { |
| 81 | in = clib_net_to_host_u32(in); |
| 82 | |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 83 | if (in & MFIB_API_ITF_FLAG_NEGATE_SIGNAL) |
| 84 | *out |= MFIB_ITF_FLAG_NEGATE_SIGNAL; |
| 85 | if (in & MFIB_API_ITF_FLAG_ACCEPT) |
| 86 | *out |= MFIB_ITF_FLAG_ACCEPT; |
| 87 | if (in & MFIB_API_ITF_FLAG_FORWARD) |
| 88 | *out |= MFIB_ITF_FLAG_FORWARD; |
| 89 | if (in & MFIB_API_ITF_FLAG_SIGNAL_PRESENT) |
| 90 | *out |= MFIB_ITF_FLAG_SIGNAL_PRESENT; |
| 91 | if (in & MFIB_API_ITF_FLAG_DONT_PRESERVE) |
| 92 | *out |= MFIB_ITF_FLAG_DONT_PRESERVE; |
| 93 | } |
| 94 | |
| 95 | int |
| 96 | mfib_api_path_decode (vl_api_mfib_path_t *in, |
| 97 | fib_route_path_t *out) |
| 98 | { |
| 99 | mfib_api_path_itf_flags_decode(in->itf_flags, &out->frp_mitf_flags); |
| 100 | |
| 101 | return (fib_api_path_decode(&in->path, out)); |
| 102 | } |
| 103 | |
| 104 | int |
| 105 | mfib_api_table_id_decode (fib_protocol_t fproto, |
| 106 | u32 table_id, |
| 107 | u32 *fib_index) |
| 108 | { |
| 109 | *fib_index = mfib_table_find(fproto, table_id); |
| 110 | |
| 111 | if (INDEX_INVALID == *fib_index) |
| 112 | { |
| 113 | return VNET_API_ERROR_NO_SUCH_FIB; |
| 114 | } |
| 115 | |
| 116 | return (0); |
| 117 | } |