2 *------------------------------------------------------------------
3 * sctp_api.c - sctp-layer API
5 * Copyright (c) 2018 SUSE LLC.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at:
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *------------------------------------------------------------------
20 #include <vlib/vlib.h>
21 #include <vlibapi/api.h>
22 #include <vlibmemory/api.h>
24 #include <sctp/sctp.h>
26 #include <sctp/sctp_msg_enum.h>
28 #define vl_typedefs /* define message structures */
29 #include <sctp/sctp_all_api_h.h>
32 #define vl_endianfun /* define message structures */
33 #include <sctp/sctp_all_api_h.h>
36 /* instantiate all the print functions we know about */
37 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
39 #include <sctp/sctp_all_api_h.h>
42 #define vl_api_version(n,v) static u32 api_version=(v);
43 #include <sctp/sctp_all_api_h.h>
46 #define REPLY_MSG_ID_BASE sctp_main.msg_id_base
47 #include <vlibapi/api_helper_macros.h>
49 #define foreach_sctp_plugin_api_msg \
50 _(SCTP_ADD_SRC_DST_CONNECTION, sctp_add_src_dst_connection) \
51 _(SCTP_DEL_SRC_DST_CONNECTION, sctp_del_src_dst_connection) \
52 _(SCTP_CONFIG, sctp_config)
55 vl_api_sctp_add_src_dst_connection_t_handler
56 (vl_api_sctp_add_src_dst_connection_t * mp)
58 vlib_main_t *vm = vlib_get_main ();
59 vl_api_sctp_add_src_dst_connection_reply_t *rmp;
63 rv = sctp_sub_connection_add_ip6
65 (ip6_address_t *) mp->src_address, (ip6_address_t *) mp->dst_address);
67 rv = sctp_sub_connection_add_ip4
69 (ip4_address_t *) mp->src_address, (ip4_address_t *) mp->dst_address);
71 REPLY_MACRO (VL_API_SCTP_ADD_SRC_DST_CONNECTION_REPLY);
75 vl_api_sctp_del_src_dst_connection_t_handler
76 (vl_api_sctp_del_src_dst_connection_t * mp)
78 vl_api_sctp_del_src_dst_connection_reply_t *rmp;
82 rv = sctp_sub_connection_del_ip6
83 ((ip6_address_t *) mp->src_address, (ip6_address_t *) mp->dst_address);
85 rv = sctp_sub_connection_del_ip4
86 ((ip4_address_t *) mp->src_address, (ip4_address_t *) mp->dst_address);
88 REPLY_MACRO (VL_API_SCTP_ADD_SRC_DST_CONNECTION_REPLY);
92 vl_api_sctp_config_t_handler (vl_api_sctp_config_t * mp)
94 sctp_user_configuration_t config;
95 vl_api_sctp_config_reply_t *rmp;
98 config.never_delay_sack = mp->never_delay_sack;
99 config.never_bundle = mp->never_bundle;
100 rv = sctp_configure (config);
102 REPLY_MACRO (VL_API_SCTP_CONFIG_REPLY);
105 #define vl_msg_name_crc_list
106 #include <sctp/sctp_all_api_h.h>
107 #undef vl_msg_name_crc_list
110 setup_message_id_table (sctp_main_t * sm, api_main_t * am)
112 #define _(id,n,crc) \
113 vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + sm->msg_id_base);
114 foreach_vl_msg_name_crc_sctp;
119 sctp_plugin_api_hookup (vlib_main_t * vm)
121 sctp_main_t *sm = &sctp_main;
122 api_main_t *am = &api_main;
125 /* Construct the API name */
126 name = format (0, "sctp_%08x%c", api_version, 0);
128 /* Ask for a correctly-sized block of API message decode slots */
129 sctp_main.msg_id_base = vl_msg_api_get_msg_ids
130 ((char *) name, VL_MSG_FIRST_AVAILABLE);
133 vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base), \
135 vl_api_##n##_t_handler, \
137 vl_api_##n##_t_endian, \
138 vl_api_##n##_t_print, \
139 sizeof(vl_api_##n##_t), 1);
140 foreach_sctp_plugin_api_msg;
144 * Set up the (msg_name, crc, message-id) table
146 setup_message_id_table (sm, am);
153 * fd.io coding-style-patch-verification: ON
156 * eval: (c-set-style "gnu")