LCOV - code coverage report
Current view: top level - plugins/stn - stn_api.c (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 27 28 96.4 %
Date: 2023-10-26 01:39:38 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2017 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 <vlibapi/api.h>
      17             : #include <vlibmemory/api.h>
      18             : 
      19             : #include <plugins/stn/stn.h>
      20             : #include <vnet/ip/format.h>
      21             : #include <vnet/format_fns.h>
      22             : #include <vnet/ip/ip_types_api.h>
      23             : #include <vppinfra/byte_order.h>
      24             : 
      25             : /* define message IDs */
      26             : #include <stn/stn.api_enum.h>
      27             : #include <stn/stn.api_types.h>
      28             : 
      29             : #define REPLY_MSG_ID_BASE stn_main.msg_id_base
      30             : #include <vlibapi/api_helper_macros.h>
      31             : 
      32             : #define FINISH                                                                \
      33             :   vec_add1 (s, 0);                                                            \
      34             :   vlib_cli_output (handle, (char *) s);                                       \
      35             :   vec_free (s);                                                               \
      36             :   return handle;
      37             : 
      38             : static void
      39           2 : vl_api_stn_add_del_rule_t_handler (vl_api_stn_add_del_rule_t * mp)
      40             : {
      41             :   stn_rule_add_del_args_t args;
      42             :   vl_api_stn_add_del_rule_reply_t *rmp;
      43           2 :   int rv = 0;
      44             : 
      45           2 :   ip_address_decode (&mp->ip_address, &args.address);
      46           2 :   args.sw_if_index = clib_net_to_host_u32 (mp->sw_if_index);
      47           2 :   args.del = !mp->is_add;
      48             : 
      49           2 :   rv = stn_rule_add_del (&args);
      50             : 
      51           2 :   REPLY_MACRO (VL_API_STN_ADD_DEL_RULE_REPLY);
      52             : }
      53             : 
      54             : static void
      55           1 : send_stn_rules_details (stn_rule_t * r, vl_api_registration_t * reg,
      56             :                         u32 context)
      57             : {
      58             :   vl_api_stn_rules_details_t *rmp;
      59             : 
      60           1 :   rmp = vl_msg_api_alloc (sizeof (*rmp));
      61           1 :   clib_memset (rmp, 0, sizeof (*rmp));
      62           1 :   rmp->_vl_msg_id =
      63           1 :     clib_host_to_net_u16 (VL_API_STN_RULES_DETAILS + stn_main.msg_id_base);
      64             : 
      65           1 :   ip_address_encode (&r->address,
      66           1 :                      ip46_address_is_ip4 (&r->address) ? IP46_TYPE_IP4 :
      67             :                      IP46_TYPE_IP6, &rmp->ip_address);
      68           1 :   rmp->context = context;
      69           1 :   rmp->sw_if_index = clib_host_to_net_u32 (r->sw_if_index);
      70             : 
      71           1 :   vl_api_send_msg (reg, (u8 *) rmp);
      72           1 : }
      73             : 
      74             : static void
      75           1 : vl_api_stn_rules_dump_t_handler (vl_api_stn_rules_dump_t * mp)
      76             : {
      77             :   vl_api_registration_t *reg;
      78           1 :   stn_main_t *stn = &stn_main;
      79             :   stn_rule_t *r;
      80             : 
      81           1 :   reg = vl_api_client_index_to_registration (mp->client_index);
      82           1 :   if (reg == 0)
      83           0 :     return;
      84             : 
      85             :   /* *INDENT-OFF* */
      86           2 :   pool_foreach (r, stn->rules) {
      87           1 :     send_stn_rules_details (r, reg, mp->context);
      88             :   }
      89             :   /* *INDENT-ON* */
      90             : }
      91             : 
      92             : #include <stn/stn.api.c>
      93             : clib_error_t *
      94         575 : stn_api_init (vlib_main_t * vm, stn_main_t * sm)
      95             : {
      96             :   /* Ask for a correctly-sized block of API message decode slots */
      97         575 :   sm->msg_id_base = setup_message_id_table ();
      98             : 
      99         575 :   return 0;
     100             : }
     101             : 
     102             : /*
     103             :  * fd.io coding-style-patch-verification: ON
     104             :  *
     105             :  * Local Variables:
     106             :  * eval: (c-set-style "gnu")
     107             :  * End:
     108             :  */

Generated by: LCOV version 1.14