Line data Source code
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 : static vl_api_mfib_itf_flags_t 24 5927 : mfib_api_path_itf_flags_encode (mfib_itf_flags_t flags) 25 : { 26 5927 : vl_api_mfib_itf_flags_t out = MFIB_API_ITF_FLAG_NONE; 27 : 28 5927 : switch (flags) 29 : { 30 900 : case MFIB_ITF_FLAG_NONE: 31 900 : out = MFIB_API_ITF_FLAG_NONE; 32 900 : break; 33 0 : case MFIB_ITF_FLAG_NEGATE_SIGNAL: 34 0 : out = MFIB_API_ITF_FLAG_NEGATE_SIGNAL; 35 0 : break; 36 1350 : case MFIB_ITF_FLAG_ACCEPT: 37 1350 : out = MFIB_API_ITF_FLAG_ACCEPT; 38 1350 : break; 39 3673 : case MFIB_ITF_FLAG_FORWARD: 40 3673 : out = MFIB_API_ITF_FLAG_FORWARD; 41 3673 : break; 42 0 : case MFIB_ITF_FLAG_SIGNAL_PRESENT: 43 0 : out = MFIB_API_ITF_FLAG_SIGNAL_PRESENT; 44 0 : break; 45 0 : case MFIB_ITF_FLAG_DONT_PRESERVE: 46 0 : out = MFIB_API_ITF_FLAG_DONT_PRESERVE; 47 0 : break; 48 : } 49 5927 : return (ntohl(out)); 50 : } 51 : 52 : void 53 5927 : mfib_api_path_encode (const fib_route_path_t *in, 54 : vl_api_mfib_path_t *out) 55 : { 56 5927 : out->itf_flags = mfib_api_path_itf_flags_encode(in->frp_mitf_flags); 57 : 58 5927 : fib_api_path_encode(in, &out->path); 59 5927 : } 60 : 61 : static void 62 3591 : mfib_api_path_itf_flags_decode (vl_api_mfib_itf_flags_t in, 63 : mfib_itf_flags_t *out) 64 : { 65 3591 : in = clib_net_to_host_u32(in); 66 : 67 3591 : if (in & MFIB_API_ITF_FLAG_NEGATE_SIGNAL) 68 1 : *out |= MFIB_ITF_FLAG_NEGATE_SIGNAL; 69 3591 : if (in & MFIB_API_ITF_FLAG_ACCEPT) 70 915 : *out |= MFIB_ITF_FLAG_ACCEPT; 71 3591 : if (in & MFIB_API_ITF_FLAG_FORWARD) 72 2684 : *out |= MFIB_ITF_FLAG_FORWARD; 73 3591 : if (in & MFIB_API_ITF_FLAG_SIGNAL_PRESENT) 74 0 : *out |= MFIB_ITF_FLAG_SIGNAL_PRESENT; 75 3591 : if (in & MFIB_API_ITF_FLAG_DONT_PRESERVE) 76 0 : *out |= MFIB_ITF_FLAG_DONT_PRESERVE; 77 3591 : } 78 : 79 : mfib_entry_flags_t 80 938 : mfib_api_path_entry_flags_decode (vl_api_mfib_entry_flags_t in) 81 : { 82 : mfib_entry_flags_t out; 83 : 84 938 : out = MFIB_ENTRY_FLAG_NONE; 85 938 : in = clib_net_to_host_u32(in); 86 : 87 938 : if (in & MFIB_API_ENTRY_FLAG_SIGNAL) 88 2 : out |= MFIB_ENTRY_FLAG_SIGNAL; 89 938 : if (in & MFIB_API_ENTRY_FLAG_DROP) 90 0 : out |= MFIB_ENTRY_FLAG_DROP; 91 938 : if (in & MFIB_API_ENTRY_FLAG_CONNECTED) 92 2 : out |= MFIB_ENTRY_FLAG_CONNECTED; 93 938 : if (in & MFIB_API_ENTRY_FLAG_ACCEPT_ALL_ITF) 94 0 : out |= MFIB_ENTRY_FLAG_ACCEPT_ALL_ITF; 95 : 96 938 : return (out); 97 : } 98 : 99 : int 100 3591 : mfib_api_path_decode (vl_api_mfib_path_t *in, 101 : fib_route_path_t *out) 102 : { 103 3591 : mfib_api_path_itf_flags_decode(in->itf_flags, &out->frp_mitf_flags); 104 : 105 3591 : return (fib_api_path_decode(&in->path, out)); 106 : } 107 : 108 : int 109 938 : mfib_api_table_id_decode (fib_protocol_t fproto, 110 : u32 table_id, 111 : u32 *fib_index) 112 : { 113 938 : *fib_index = mfib_table_find(fproto, table_id); 114 : 115 938 : if (INDEX_INVALID == *fib_index) 116 : { 117 0 : return VNET_API_ERROR_NO_SUCH_FIB; 118 : } 119 : 120 938 : return (0); 121 : }