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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include <vlibapi/api.h>
17 #include <vlibmemory/api.h>
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>
25 /* define message IDs */
26 #include <stn/stn.api_enum.h>
27 #include <stn/stn.api_types.h>
29 #define REPLY_MSG_ID_BASE stn_main.msg_id_base
30 #include <vlibapi/api_helper_macros.h>
32 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
33 /* Macro to finish up custom dump fns */
36 vl_print (handle, (char *)s); \
41 * @brief API message custom-dump function
42 * @param mp vl_api_stn_add_del_rule_t * mp the api message
43 * @param handle void * print function handle
44 * @returns u8 * output string
46 static void *vl_api_stn_add_del_rule_t_print
47 (vl_api_stn_add_del_rule_t * mp, void *handle)
51 s = format (0, "SCRIPT: stn_add_del_rule ");
52 s = format (s, "address %U ", format_ip46_address, mp->ip_address);
53 s = format (s, "sw_if_index %d is_add %d", mp->sw_if_index, mp->is_add);
59 vl_api_stn_add_del_rule_t_handler (vl_api_stn_add_del_rule_t * mp)
61 stn_rule_add_del_args_t args;
62 vl_api_stn_add_del_rule_reply_t *rmp;
65 ip_address_decode (&mp->ip_address, &args.address);
66 args.sw_if_index = clib_net_to_host_u32 (mp->sw_if_index);
67 args.del = !mp->is_add;
69 rv = stn_rule_add_del (&args);
71 REPLY_MACRO (VL_API_STN_ADD_DEL_RULE_REPLY);
75 send_stn_rules_details (stn_rule_t * r, vl_api_registration_t * reg,
78 vl_api_stn_rules_details_t *rmp;
80 rmp = vl_msg_api_alloc (sizeof (*rmp));
81 clib_memset (rmp, 0, sizeof (*rmp));
83 clib_host_to_net_u16 (VL_API_STN_RULES_DETAILS + stn_main.msg_id_base);
85 ip_address_encode (&r->address,
86 ip46_address_is_ip4 (&r->address) ? IP46_TYPE_IP4 :
87 IP46_TYPE_IP6, &rmp->ip_address);
88 rmp->context = context;
89 rmp->sw_if_index = clib_host_to_net_u32 (r->sw_if_index);
91 vl_api_send_msg (reg, (u8 *) rmp);
95 vl_api_stn_rules_dump_t_handler (vl_api_stn_rules_dump_t * mp)
97 vl_api_registration_t *reg;
98 stn_main_t *stn = &stn_main;
101 reg = vl_api_client_index_to_registration (mp->client_index);
106 pool_foreach (r, stn->rules,({
107 send_stn_rules_details (r, reg, mp->context);
112 #include <stn/stn.api.c>
114 stn_api_init (vlib_main_t * vm, stn_main_t * sm)
116 /* Ask for a correctly-sized block of API message decode slots */
117 sm->msg_id_base = setup_message_id_table ();
123 * fd.io coding-style-patch-verification: ON
126 * eval: (c-set-style "gnu")