LCOV - code coverage report
Current view: top level - vnet/fib - fib_api.c (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 255 315 81.0 %
Date: 2023-10-26 01:39:38 Functions: 17 18 94.4 %

          Line data    Source code
       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/vnet.h>
      17             : #include <vlibmemory/api.h>
      18             : #include <vnet/fib/fib_api.h>
      19             : #include <vnet/ip/ip_types_api.h>
      20             : #include <vnet/fib/fib_table.h>
      21             : #include <vnet/mfib/mfib_table.h>
      22             : #include <vnet/bier/bier_disp_table.h>
      23             : #include <vpp/api/types.h>
      24             : #include <vnet/classify/vnet_classify.h>
      25             : #include <vnet/ip/ip_format_fns.h>
      26             : 
      27             : #include <vnet/fib/fib.api_enum.h>
      28             : #include <vnet/fib/fib.api_types.h>
      29             : 
      30             : static u16 fib_base_msg_id;
      31             : #define REPLY_MSG_ID_BASE fib_base_msg_id
      32             : #include <vlibapi/api_helper_macros.h>
      33             : 
      34             : int
      35       10806 : fib_api_table_id_decode (fib_protocol_t fproto,
      36             :                          u32 table_id,
      37             :                          u32 *fib_index)
      38             : {
      39       10806 :     *fib_index = fib_table_find(fproto, table_id);
      40             : 
      41       10806 :     if (INDEX_INVALID == *fib_index)
      42             :     {
      43           0 :         return VNET_API_ERROR_NO_SUCH_FIB;
      44             :     }
      45             : 
      46       10806 :     return (0);
      47             : }
      48             : 
      49             : int
      50           4 : fib_api_mtable_id_decode (fib_protocol_t fproto,
      51             :                           u32 table_id,
      52             :                           u32 *fib_index)
      53             : {
      54           4 :     *fib_index = mfib_table_find(fproto, table_id);
      55             : 
      56           4 :     if (~0 == *fib_index)
      57             :     {
      58           0 :         return VNET_API_ERROR_NO_SUCH_FIB;
      59             :     }
      60             : 
      61           4 :     return (0);
      62             : }
      63             : 
      64             : static void
      65        9670 : fib_api_next_hop_decode (const vl_api_fib_path_t *in,
      66             :                          ip46_address_t *out)
      67             : {
      68        9670 :     ASSERT (FIB_API_PATH_NH_PROTO_IP4 == in->proto || FIB_API_PATH_NH_PROTO_IP6 == in->proto);
      69        9670 :     *out = to_ip46 (FIB_API_PATH_NH_PROTO_IP6 == in->proto, (void *)&in->nh.address);
      70        9670 : }
      71             : 
      72             : vl_api_fib_path_nh_proto_t
      73      471514 : fib_api_path_dpo_proto_to_nh (dpo_proto_t dproto)
      74             : {
      75      471514 :     switch (dproto)
      76             :     {
      77      384536 :     case DPO_PROTO_IP4:
      78      384536 :         return (FIB_API_PATH_NH_PROTO_IP4);
      79       46956 :     case DPO_PROTO_IP6:
      80       46956 :         return (FIB_API_PATH_NH_PROTO_IP6);
      81       39986 :     case DPO_PROTO_MPLS:
      82       39986 :         return (FIB_API_PATH_NH_PROTO_MPLS);
      83          26 :     case DPO_PROTO_BIER:
      84          26 :         return (FIB_API_PATH_NH_PROTO_BIER);
      85          10 :     case DPO_PROTO_ETHERNET:
      86          10 :         return (FIB_API_PATH_NH_PROTO_ETHERNET);
      87           0 :     case DPO_PROTO_NSH:
      88           0 :         ASSERT(0);
      89           0 :         break;
      90             :     }
      91           0 :     return (FIB_API_PATH_NH_PROTO_IP4);
      92             : }
      93             : 
      94             : 
      95             : static void
      96      235757 : fib_api_next_hop_encode (const fib_route_path_t *rpath,
      97             :                          vl_api_fib_path_t *fp)
      98             : {
      99      235757 :     fp->proto = fib_api_path_dpo_proto_to_nh(rpath->frp_proto);
     100             : 
     101      235757 :     if (rpath->frp_proto == DPO_PROTO_IP4)
     102      192268 :         clib_memcpy (&fp->nh.address.ip4,
     103             :                 &rpath->frp_addr.ip4,
     104             :                 sizeof (rpath->frp_addr.ip4));
     105       43489 :     else if (rpath->frp_proto == DPO_PROTO_IP6)
     106       23478 :         clib_memcpy (&fp->nh.address.ip6,
     107             :                 &rpath->frp_addr.ip6,
     108             :                 sizeof (rpath->frp_addr.ip6));
     109      235757 : }
     110             : 
     111             : int
     112        9747 : fib_api_path_nh_proto_to_dpo (vl_api_fib_path_nh_proto_t pp,
     113             :                               dpo_proto_t *dproto)
     114             : {
     115        9747 :     switch (pp)
     116             :     {
     117        5668 :     case FIB_API_PATH_NH_PROTO_IP4:
     118        5668 :         *dproto = DPO_PROTO_IP4;
     119        5668 :         break;
     120        4044 :     case FIB_API_PATH_NH_PROTO_IP6:
     121        4044 :         *dproto = DPO_PROTO_IP6;
     122        4044 :         break;
     123          11 :     case FIB_API_PATH_NH_PROTO_MPLS:
     124          11 :         *dproto = DPO_PROTO_MPLS;
     125          11 :         break;
     126          18 :     case FIB_API_PATH_NH_PROTO_BIER:
     127          18 :         *dproto = DPO_PROTO_BIER;
     128          18 :         break;
     129           6 :     case FIB_API_PATH_NH_PROTO_ETHERNET:
     130           6 :         *dproto = DPO_PROTO_ETHERNET;
     131           6 :         break;
     132           0 :     default:
     133           0 :         return (-1);
     134             :     }
     135        9747 :     return (0);
     136             : }
     137             : 
     138             : int
     139        9743 : fib_api_path_decode (vl_api_fib_path_t *in,
     140             :                      fib_route_path_t *out)
     141             : {
     142        9743 :     vnet_classify_main_t *cm = &vnet_classify_main;
     143        9743 :     int rv = 0, n_labels;
     144             :     vnet_main_t *vnm;
     145             :     u8 ii;
     146             : 
     147        9743 :     vnm = vnet_get_main ();
     148        9743 :     clib_memset(&out->frp_dpo, 0, sizeof(out->frp_dpo));
     149             : 
     150             :     /* enums are u32 */
     151        9743 :     in->flags = ntohl (in->flags);
     152        9743 :     in->type = ntohl (in->type);
     153        9743 :     in->proto = ntohl (in->proto);
     154             : 
     155             :     /*
     156             :      * attributes that apply to all path types
     157             :      */
     158        9743 :     out->frp_flags = 0;
     159        9743 :     out->frp_weight = in->weight;
     160        9743 :     if (0 == out->frp_weight)
     161             :     {
     162           0 :         out->frp_weight = 1;
     163             :     }
     164        9743 :     out->frp_preference = in->preference;
     165             : 
     166        9743 :     rv = fib_api_path_nh_proto_to_dpo(in->proto, &out->frp_proto);
     167             : 
     168        9743 :     if (0 != rv)
     169           0 :         return (rv);
     170             : 
     171             :     /*
     172             :      * convert the flags and the AFI to determine the path type
     173             :      */
     174        9743 :     if (in->flags & FIB_API_PATH_FLAG_RESOLVE_VIA_HOST)
     175         134 :         out->frp_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_HOST;
     176        9743 :     if (in->flags & FIB_API_PATH_FLAG_RESOLVE_VIA_ATTACHED)
     177         268 :         out->frp_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_ATTACHED;
     178        9743 :     if (in->flags & FIB_API_PATH_FLAG_POP_PW_CW)
     179           2 :         out->frp_flags |= FIB_ROUTE_PATH_POP_PW_CW;
     180             : 
     181        9743 :     switch (in->type)
     182             :     {
     183           2 :     case FIB_API_PATH_TYPE_DVR:
     184           2 :         out->frp_sw_if_index = ntohl(in->sw_if_index);
     185           2 :         out->frp_flags |= FIB_ROUTE_PATH_DVR;
     186           2 :         break;
     187          10 :     case FIB_API_PATH_TYPE_INTERFACE_RX:
     188          10 :         out->frp_sw_if_index = ntohl(in->sw_if_index);
     189          10 :         out->frp_flags |= FIB_ROUTE_PATH_INTF_RX;
     190          10 :         break;
     191          13 :     case FIB_API_PATH_TYPE_DROP:
     192          13 :         out->frp_flags |= FIB_ROUTE_PATH_DROP;
     193          13 :         break;
     194           3 :     case FIB_API_PATH_TYPE_LOCAL:
     195           3 :         out->frp_flags |= FIB_ROUTE_PATH_LOCAL;
     196           3 :         out->frp_sw_if_index = ntohl(in->sw_if_index);
     197           3 :         break;
     198           2 :     case FIB_API_PATH_TYPE_ICMP_UNREACH:
     199           2 :         out->frp_flags |= FIB_ROUTE_PATH_ICMP_UNREACH;
     200           2 :         break;
     201           2 :     case FIB_API_PATH_TYPE_ICMP_PROHIBIT:
     202           2 :         out->frp_flags |= FIB_ROUTE_PATH_ICMP_PROHIBIT;
     203           2 :         break;
     204           0 :     case FIB_API_PATH_TYPE_CLASSIFY:
     205           0 :         out->frp_flags |= FIB_ROUTE_PATH_CLASSIFY;
     206             : 
     207           0 :         if (pool_is_free_index (cm->tables, ntohl (in->nh.classify_table_index)))
     208             :         {
     209           0 :             return VNET_API_ERROR_NO_SUCH_TABLE;
     210             :         }
     211           0 :         out->frp_classify_table_id = ntohl (in->nh.classify_table_index);
     212           0 :         break;
     213          12 :     case FIB_API_PATH_TYPE_UDP_ENCAP:
     214          12 :         out->frp_flags |= FIB_ROUTE_PATH_UDP_ENCAP;
     215          12 :         out->frp_udp_encap_id = ntohl(in->nh.obj_id);
     216          12 :         break;
     217          10 :     case FIB_API_PATH_TYPE_BIER_IMP:
     218          10 :         out->frp_flags |= FIB_ROUTE_PATH_BIER_IMP;
     219          10 :         out->frp_bier_imp = ntohl (in->nh.obj_id);
     220          10 :         break;
     221             : 
     222           2 :     case FIB_API_PATH_TYPE_SOURCE_LOOKUP:
     223           2 :         out->frp_flags |= FIB_ROUTE_PATH_SOURCE_LOOKUP;
     224             :         /* fall through */
     225        9689 :     case FIB_API_PATH_TYPE_NORMAL:
     226        9689 :         switch (out->frp_proto)
     227             :         {
     228        9670 :         case DPO_PROTO_IP4:
     229             :         case DPO_PROTO_IP6:
     230        9670 :             fib_api_next_hop_decode(in, &out->frp_addr);
     231        9670 :             out->frp_sw_if_index = ntohl(in->sw_if_index);
     232        9670 :             out->frp_rpf_id = ntohl(in->rpf_id);
     233             : 
     234        9670 :             if (0 == out->frp_rpf_id)
     235             :             {
     236             :                 /* allow 0 to be an unset value on the API */
     237        9666 :                 out->frp_rpf_id = ~0;
     238             :             }
     239             : 
     240        9670 :             if (~0 != out->frp_rpf_id)
     241             :             {
     242           4 :                 out->frp_flags |= FIB_ROUTE_PATH_RPF_ID;
     243             :             }
     244             : 
     245        9670 :             if (~0 == out->frp_sw_if_index)
     246             :             {
     247             :                 /* recursive or deag, validate the next-hop FIB */
     248        3364 :                 if (~0 != out->frp_rpf_id)
     249             :                 {
     250           4 :                     rv = fib_api_mtable_id_decode(
     251           4 :                         dpo_proto_to_fib(out->frp_proto),
     252             :                         ntohl(in->table_id),
     253             :                         &out->frp_fib_index);
     254             :                 }
     255             :                 else
     256             :                 {
     257        3360 :                     rv = fib_api_table_id_decode(
     258        3360 :                         dpo_proto_to_fib(out->frp_proto),
     259             :                         ntohl(in->table_id),
     260             :                         &out->frp_fib_index);
     261             :                 }
     262        3364 :                 if (0 != rv)
     263             :                 {
     264           0 :                     return (rv);
     265             :                 }
     266             :             }
     267             :             else
     268             :             {
     269        6306 :                 if (pool_is_free_index (vnm->interface_main.sw_interfaces,
     270        6306 :                                         out->frp_sw_if_index))
     271             :                 {
     272           0 :                     return VNET_API_ERROR_NO_MATCHING_INTERFACE;
     273             :                 }
     274             :             }
     275             : 
     276        9670 :             if (ip46_address_is_zero(&out->frp_addr))
     277             :             {
     278        3721 :                 if (~0 == out->frp_sw_if_index &&
     279          68 :                     ~0 != out->frp_fib_index)
     280             :                 {
     281          68 :                     out->frp_flags |= FIB_ROUTE_PATH_DEAG;
     282             :                 }
     283             :             }
     284             : 
     285        9670 :             break;
     286          11 :         case DPO_PROTO_MPLS:
     287          11 :             out->frp_local_label = ntohl (in->nh.via_label);
     288          11 :             out->frp_eos = MPLS_NON_EOS;
     289          11 :             out->frp_sw_if_index = ~0;
     290          11 :             break;
     291           8 :         case DPO_PROTO_BIER:
     292           8 :             out->frp_sw_if_index = ntohl(in->sw_if_index);
     293           8 :             out->frp_rpf_id = ntohl(in->rpf_id);
     294             : 
     295           8 :             if (!(out->frp_flags & FIB_ROUTE_PATH_BIER_IMP))
     296             :             {
     297             :                 index_t bdti;
     298             : 
     299           8 :                 bdti = bier_disp_table_find(ntohl(in->table_id));
     300             : 
     301           8 :                 if (INDEX_INVALID != bdti)
     302             :                 {
     303           8 :                     out->frp_fib_index = bdti;
     304             :                 }
     305             :                 else
     306             :                 {
     307           0 :                     return (VNET_API_ERROR_NO_SUCH_FIB);
     308             :                 }
     309             :             }
     310           8 :             break;
     311           0 :         case DPO_PROTO_ETHERNET:
     312           0 :             out->frp_sw_if_index = ntohl(in->sw_if_index);
     313           0 :             break;
     314           0 :         case DPO_PROTO_NSH:
     315           0 :             break;
     316             :         }
     317        9743 :     }
     318             : 
     319        9743 :     n_labels = in->n_labels;
     320        9743 :     if (n_labels != 0)
     321             :     {
     322         830 :         vec_validate (out->frp_label_stack, n_labels - 1);
     323        2079 :         for (ii = 0; ii < n_labels; ii++)
     324             :         {
     325        1249 :             out->frp_label_stack[ii].fml_value =
     326        1249 :                 ntohl(in->label_stack[ii].label);
     327        1249 :             out->frp_label_stack[ii].fml_ttl =
     328        1249 :                 in->label_stack[ii].ttl;
     329        1249 :             out->frp_label_stack[ii].fml_exp =
     330        1249 :                 in->label_stack[ii].exp;
     331        1249 :             out->frp_label_stack[ii].fml_mode =
     332        1249 :                 (in->label_stack[ii].is_uniform ?
     333        1249 :                  FIB_MPLS_LSP_MODE_UNIFORM :
     334             :                  FIB_MPLS_LSP_MODE_PIPE);
     335             :         }
     336             :     }
     337             : 
     338        9743 :     return (0);
     339             : }
     340             : 
     341             : void
     342      235757 : fib_api_path_encode (const fib_route_path_t * rpath,
     343             :                      vl_api_fib_path_t *out)
     344             : {
     345      235757 :     memset (out, 0, sizeof (*out));
     346             : 
     347      235757 :     out->weight = rpath->frp_weight;
     348      235757 :     out->preference = rpath->frp_preference;
     349      235757 :     out->sw_if_index = htonl (rpath->frp_sw_if_index);
     350      235757 :     out->proto = fib_api_path_dpo_proto_to_nh(rpath->frp_proto);
     351      235757 :     out->rpf_id = rpath->frp_rpf_id;
     352      235757 :     fib_api_next_hop_encode (rpath, out);
     353             : 
     354      235757 :     if (0 != rpath->frp_fib_index)
     355             :     {
     356       18008 :         if ((DPO_PROTO_IP6 == rpath->frp_proto) ||
     357        9017 :             (DPO_PROTO_IP4 == rpath->frp_proto))
     358             :         {
     359       18008 :             if (rpath->frp_flags & FIB_ROUTE_PATH_RPF_ID)
     360             :             {
     361           6 :                 out->table_id = htonl (mfib_table_get_table_id(
     362             :                                            rpath->frp_fib_index,
     363           6 :                                            dpo_proto_to_fib(rpath->frp_proto)));
     364             :             }
     365             :             else
     366             :             {
     367       18002 :                 out->table_id = htonl (fib_table_get_table_id(
     368             :                                            rpath->frp_fib_index,
     369       18002 :                                            dpo_proto_to_fib(rpath->frp_proto)));
     370             :             }
     371             :         }
     372             :     }
     373             : 
     374      235757 :     if (rpath->frp_flags & FIB_ROUTE_PATH_DVR)
     375             :     {
     376           2 :         out->type = FIB_API_PATH_TYPE_DVR;
     377             :     }
     378      235755 :     else if (rpath->frp_flags & FIB_ROUTE_PATH_ICMP_UNREACH)
     379             :     {
     380           6 :         out->type = FIB_API_PATH_TYPE_ICMP_UNREACH;
     381             :     }
     382      235749 :     else if (rpath->frp_flags & FIB_ROUTE_PATH_ICMP_PROHIBIT)
     383             :     {
     384           2 :         out->type = FIB_API_PATH_TYPE_ICMP_PROHIBIT;
     385             :     }
     386      235747 :     else if (rpath->frp_flags & FIB_ROUTE_PATH_LOCAL)
     387             :     {
     388        8953 :         out->type = FIB_API_PATH_TYPE_LOCAL;
     389             :     }
     390      226794 :     else if (rpath->frp_flags & FIB_ROUTE_PATH_DROP)
     391             :     {
     392       28532 :         out->type = FIB_API_PATH_TYPE_DROP;
     393             :     }
     394      198262 :     else if (rpath->frp_flags & FIB_ROUTE_PATH_UDP_ENCAP)
     395             :     {
     396          18 :         out->type = FIB_API_PATH_TYPE_UDP_ENCAP;
     397          18 :         out->nh.obj_id = rpath->frp_udp_encap_id;
     398             :     }
     399      198244 :     else if (rpath->frp_flags & FIB_ROUTE_PATH_BIER_IMP)
     400             :     {
     401           0 :         out->type = FIB_API_PATH_TYPE_BIER_IMP;
     402           0 :         out->nh.obj_id = rpath->frp_bier_imp;
     403             :     }
     404      198244 :     else if (rpath->frp_flags & FIB_ROUTE_PATH_INTF_RX)
     405             :     {
     406           7 :         out->type = FIB_API_PATH_TYPE_INTERFACE_RX;
     407             :     }
     408             :     else
     409             :     {
     410      198237 :         out->type = FIB_API_PATH_TYPE_NORMAL;
     411             :     }
     412      235757 :     if (rpath->frp_flags & FIB_ROUTE_PATH_RESOLVE_VIA_HOST)
     413             :     {
     414           0 :         out->flags |= FIB_API_PATH_FLAG_RESOLVE_VIA_HOST;
     415             :     }
     416      235757 :     if (rpath->frp_flags & FIB_ROUTE_PATH_RESOLVE_VIA_ATTACHED)
     417             :     {
     418           0 :         out->flags |= FIB_API_PATH_FLAG_RESOLVE_VIA_ATTACHED;
     419             :     }
     420             : 
     421      235757 :     out->flags = htonl (out->flags);
     422      235757 :     out->type = htonl (out->type);
     423      235757 :     out->proto = htonl (out->proto);
     424             : 
     425      235757 :     if (rpath->frp_label_stack)
     426             :     {
     427             :         int ii;
     428             : 
     429      138207 :         for (ii = 0; ii < vec_len(rpath->frp_label_stack); ii++)
     430             :         {
     431       89108 :             out->label_stack[ii].label =
     432       89108 :                 htonl(rpath->frp_label_stack[ii].fml_value);
     433       89108 :             out->label_stack[ii].ttl =
     434       89108 :                 rpath->frp_label_stack[ii].fml_ttl;
     435       89108 :             out->label_stack[ii].exp =
     436       89108 :                 rpath->frp_label_stack[ii].fml_exp;
     437             :         }
     438       49099 :         out->n_labels = ii;
     439             :     }
     440      235757 : }
     441             : 
     442             : int
     443        7436 : fib_api_route_add_del (u8 is_add,
     444             :                        u8 is_multipath,
     445             :                        u32 fib_index,
     446             :                        const fib_prefix_t * prefix,
     447             :                        fib_source_t src,
     448             :                        fib_entry_flag_t entry_flags,
     449             :                        fib_route_path_t *rpaths)
     450             : {
     451        7436 :     if (!fib_prefix_validate(prefix)) {
     452           0 :           return (VNET_API_ERROR_INVALID_PREFIX_LENGTH);
     453             :     }
     454        7436 :     if (is_multipath)
     455             :     {
     456           5 :         if (vec_len(rpaths) == 0)
     457           0 :             return (VNET_API_ERROR_NO_PATHS_IN_ROUTE);
     458             : 
     459             :         /* Iterative path add/remove */
     460           5 :         if (is_add)
     461           0 :             fib_table_entry_path_add2 (fib_index,
     462             :                                        prefix,
     463             :                                        src,
     464             :                                        entry_flags,
     465             :                                        rpaths);
     466             :         else
     467           5 :             fib_table_entry_path_remove2 (fib_index,
     468             :                                           prefix,
     469             :                                           src,
     470             :                                           rpaths);
     471             :     }
     472             :     else
     473             :     {
     474        7431 :         if (is_add)
     475             :         {
     476        4406 :             if (vec_len(rpaths) == 0)
     477           0 :                 return (VNET_API_ERROR_NO_PATHS_IN_ROUTE);
     478             : 
     479             :             /* path replacement */
     480        4406 :             fib_table_entry_update (fib_index,
     481             :                                     prefix,
     482             :                                     src,
     483             :                                     entry_flags,
     484             :                                     rpaths);
     485             :         }
     486             :         else
     487             :             /* entry delete */
     488        3025 :             fib_table_entry_delete (fib_index,
     489             :                                     prefix,
     490             :                                     src);
     491             :     }
     492             : 
     493        7436 :     return (0);
     494             : }
     495             : 
     496             : u8*
     497           0 : format_vl_api_fib_path (u8 * s, va_list * args)
     498             : {
     499           0 :     const vl_api_fib_path_t *path = va_arg (*args, vl_api_fib_path_t*);
     500             : 
     501           0 :     s = format (s, "sw_if_index %d", ntohl (path->sw_if_index));
     502           0 :     switch (clib_net_to_host_u32(path->proto))
     503             :     {
     504           0 :     case FIB_API_PATH_NH_PROTO_IP4:
     505           0 :         s = format (s, " %U", format_vl_api_address_union,
     506             :                     &path->nh.address, ADDRESS_IP4);
     507           0 :         break;
     508           0 :     case FIB_API_PATH_NH_PROTO_IP6:
     509           0 :         s = format (s, " %U", format_vl_api_address_union,
     510             :                     &path->nh.address, ADDRESS_IP6);
     511           0 :         break;
     512           0 :     default:
     513           0 :         break;
     514             :     }
     515           0 :     s = format (s, " weight %d", path->weight);
     516           0 :     s = format (s, " preference %d", path->preference);
     517           0 :     s = format (s, " type %d", ntohl(path->type));
     518           0 :     s = format (s, " proto %d", ntohl(path->proto));
     519           0 :     s = format (s, " flags %d", ntohl(path->flags));
     520           0 :     s = format (s, " n_labels %d", ntohl(path->n_labels));
     521           0 :     s = format (s, " table-id %d", ntohl(path->table_id));
     522           0 :     s = format (s, " rpf-id %d", ntohl(path->rpf_id));
     523             : 
     524           0 :     return (s);
     525             : }
     526             : 
     527             : int
     528          16 : fib_proto_from_api_address_family (vl_api_address_family_t af, fib_protocol_t * out)
     529             : {
     530          16 :     switch (af)
     531             :     {
     532           8 :     case ADDRESS_IP4:
     533           8 :         *out = (FIB_PROTOCOL_IP4);
     534           8 :         return (0);
     535           8 :     case ADDRESS_IP6:
     536           8 :         *out = (FIB_PROTOCOL_IP6);
     537           8 :         return (0);
     538             :     }
     539             : 
     540           0 :     return (VNET_API_ERROR_INVALID_ADDRESS_FAMILY);
     541             : }
     542             : 
     543             : vl_api_address_family_t
     544           4 : fib_proto_to_api_address_family (fib_protocol_t fproto)
     545             : {
     546           4 :     switch (fproto)
     547             :     {
     548           2 :     case FIB_PROTOCOL_IP4:
     549           2 :         return (ADDRESS_IP4);
     550           2 :     case FIB_PROTOCOL_IP6:
     551           2 :         return (ADDRESS_IP6);
     552           0 :     default:
     553           0 :         break;
     554             :     }
     555             : 
     556           0 :     ASSERT(0);
     557           0 :     return (ADDRESS_IP4);
     558             : }
     559             : 
     560             : void
     561           1 : vl_api_fib_source_add_t_handler (vl_api_fib_source_add_t * mp)
     562             : {
     563             :     vl_api_fib_source_add_reply_t *rmp;
     564             :     fib_source_t src;
     565           1 :     int rv = 0;
     566             :     u8 *name;
     567             : 
     568           1 :     name = format (0, "%s", mp->src.name);
     569           1 :     vec_add1 (name, 0);
     570             : 
     571           1 :     src = fib_source_allocate((const char *)name,
     572           1 :                               mp->src.priority,
     573             :                               FIB_SOURCE_BH_API);
     574             : 
     575           1 :     vec_free(name);
     576             : 
     577           1 :     REPLY_MACRO2 (VL_API_FIB_SOURCE_ADD_REPLY,
     578             :     ({
     579             :         rmp->id = src;
     580             :     }));
     581             : }
     582             : 
     583             : typedef struct fib_source_dump_ctx_t_
     584             : {
     585             :     vl_api_registration_t * reg;
     586             :     u32 context;
     587             : } fib_source_dump_ctx_t;
     588             : 
     589             : static walk_rc_t
     590          77 : send_fib_source (fib_source_t id,
     591             :                  const char *name,
     592             :                  fib_source_priority_t prio,
     593             :                  fib_source_behaviour_t bh,
     594             :                  void *data)
     595             : {
     596             :     vl_api_fib_source_details_t *mp;
     597             :     fib_source_dump_ctx_t *ctx;
     598             : 
     599          77 :     ctx = data;
     600          77 :     mp = vl_msg_api_alloc_zero (sizeof (*mp));
     601          77 :     if (!mp)
     602           0 :         return WALK_STOP;
     603             : 
     604          77 :     mp->_vl_msg_id = ntohs (VL_API_FIB_SOURCE_DETAILS + REPLY_MSG_ID_BASE);
     605          77 :     mp->context = ctx->context;
     606             : 
     607          77 :     mp->src.priority = prio;
     608          77 :     mp->src.id = id;
     609          77 :     clib_memcpy(mp->src.name, name,
     610             :                 clib_min(strlen(name), ARRAY_LEN(mp->src.name)));
     611             : 
     612          77 :     vl_api_send_msg (ctx->reg, (u8 *) mp);
     613             : 
     614          77 :     return (WALK_CONTINUE);
     615             : }
     616             : 
     617             : void
     618           2 : vl_api_fib_source_dump_t_handler (vl_api_fib_source_dump_t * mp)
     619             : {
     620             :     vl_api_registration_t *reg;
     621             : 
     622           2 :     reg = vl_api_client_index_to_registration (mp->client_index);
     623           2 :     if (!reg)
     624           0 :         return;
     625             : 
     626           2 :     fib_source_dump_ctx_t ctx = {
     627             :         .reg = reg,
     628           2 :         .context = mp->context,
     629             :     };
     630             : 
     631           2 :     fib_source_walk(send_fib_source, &ctx);
     632             : }
     633             : 
     634             : 
     635             : #include <vnet/fib/fib.api.c>
     636             : 
     637             : static clib_error_t *
     638         575 : fib_api_hookup (vlib_main_t * vm)
     639             : {
     640             :   /*
     641             :    * Set up the (msg_name, crc, message-id) table
     642             :    */
     643         575 :   fib_base_msg_id = setup_message_id_table ();
     644             : 
     645         575 :   return (NULL);
     646             : }
     647             : 
     648       18431 : VLIB_API_INIT_FUNCTION (fib_api_hookup);

Generated by: LCOV version 1.14