FD.io VPP  v19.08.1-401-g8e4ed521a
Vector Packet Processing
sctp_api.c
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * sctp_api.c - sctp-layer API
4  *
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:
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
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  *------------------------------------------------------------------
18  */
19 
20 #include <vlib/vlib.h>
21 #include <vlibapi/api.h>
22 #include <vlibmemory/api.h>
23 
24 #include <sctp/sctp.h>
25 
26 #include <sctp/sctp_msg_enum.h>
27 
28 #define vl_typedefs /* define message structures */
29 #include <sctp/sctp_all_api_h.h>
30 #undef vl_typedefs
31 
32 #define vl_endianfun /* define message structures */
33 #include <sctp/sctp_all_api_h.h>
34 #undef vl_endianfun
35 
36 /* instantiate all the print functions we know about */
37 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
38 #define vl_printfun
39 #include <sctp/sctp_all_api_h.h>
40 #undef vl_printfun
41 
42 #define vl_api_version(n,v) static u32 api_version=(v);
43 #include <sctp/sctp_all_api_h.h>
44 #undef vl_api_version
45 
46 #define REPLY_MSG_ID_BASE sctp_main.msg_id_base
48 
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)
53 
54 static void
57 {
59  vl_api_sctp_add_src_dst_connection_reply_t *rmp;
60  int rv;
61 
62  if (mp->is_ipv6)
64  (vm,
66  else
68  (vm,
70 
71  REPLY_MACRO (VL_API_SCTP_ADD_SRC_DST_CONNECTION_REPLY);
72 }
73 
74 static void
77 {
78  vl_api_sctp_del_src_dst_connection_reply_t *rmp;
79  int rv;
80 
81  if (mp->is_ipv6)
84  else
87 
88  REPLY_MACRO (VL_API_SCTP_ADD_SRC_DST_CONNECTION_REPLY);
89 }
90 
91 static void
93 {
95  vl_api_sctp_config_reply_t *rmp;
96  int rv;
97 
98  config.never_delay_sack = mp->never_delay_sack;
99  config.never_bundle = mp->never_bundle;
100  rv = sctp_configure (config);
101 
102  REPLY_MACRO (VL_API_SCTP_CONFIG_REPLY);
103 }
104 
105 #define vl_msg_name_crc_list
106 #include <sctp/sctp_all_api_h.h>
107 #undef vl_msg_name_crc_list
108 
109 static void
111 {
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;
115 #undef _
116 }
117 
118 clib_error_t *
120 {
121  sctp_main_t *sm = &sctp_main;
122  api_main_t *am = &api_main;
123  u8 *name;
124 
125  /* Construct the API name */
126  name = format (0, "sctp_%08x%c", api_version, 0);
127 
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);
131 
132 #define _(N,n) \
133  vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base), \
134  #n, \
135  vl_api_##n##_t_handler, \
136  vl_noop_handler, \
137  vl_api_##n##_t_endian, \
138  vl_api_##n##_t_print, \
139  sizeof(vl_api_##n##_t), 1);
141 #undef _
142 
143  /*
144  * Set up the (msg_name, crc, message-id) table
145  */
146  setup_message_id_table (sm, am);
147  vec_free (name);
148 
149  return 0;
150 }
151 
152 /*
153  * fd.io coding-style-patch-verification: ON
154  *
155  * Local Variables:
156  * eval: (c-set-style "gnu")
157  * End:
158  */
struct _sctp_main sctp_main_t
static void vl_api_sctp_add_src_dst_connection_t_handler(vl_api_sctp_add_src_dst_connection_t *mp)
Definition: sctp_api.c:56
clib_error_t * sctp_plugin_api_hookup(vlib_main_t *vm)
Definition: sctp_api.c:119
#define foreach_sctp_plugin_api_msg
Definition: sctp_api.c:49
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
struct _sctp_user_configuration sctp_user_configuration_t
u8 sctp_configure(sctp_user_configuration_t config)
Definition: sctp.c:415
unsigned char u8
Definition: types.h:56
sctp_main_t sctp_main
Definition: sctp.c:22
u8 sctp_sub_connection_add_ip4(vlib_main_t *vm, ip4_address_t *lcl_addr, ip4_address_t *rmt_addr)
Definition: sctp.c:299
#define REPLY_MACRO(t)
static void setup_message_id_table(sctp_main_t *sm, api_main_t *am)
Definition: sctp_api.c:110
u8 name[64]
Definition: memclnt.api:152
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:203
u8 sctp_sub_connection_del_ip4(ip4_address_t *lcl_addr, ip4_address_t *rmt_addr)
Definition: sctp.c:322
vlib_main_t * vm
Definition: buffer.c:323
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:341
static void vl_api_sctp_config_t_handler(vl_api_sctp_config_t *mp)
Definition: sctp_api.c:92
static void vl_api_sctp_del_src_dst_connection_t_handler(vl_api_sctp_del_src_dst_connection_t *mp)
Definition: sctp_api.c:76
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:23
u8 sctp_sub_connection_del_ip6(ip6_address_t *lcl_addr, ip6_address_t *rmt_addr)
Definition: sctp.c:379
u8 sctp_sub_connection_add_ip6(vlib_main_t *vm, ip6_address_t *lcl_addr, ip6_address_t *rmt_addr)
Definition: sctp.c:356
api_main_t api_main
Definition: api_shared.c:35
Configure SCTP source addresses, for active-open SCTP sessions.
Definition: sctp.api:28
u16 vl_msg_api_get_msg_ids(const char *name, int n)
Definition: api_shared.c:957