tcp: timestamp adjustment
[vpp.git] / src / plugins / sctp / sctp_api.c
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
47 #include <vlibapi/api_helper_macros.h>
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
55   vl_api_sctp_add_src_dst_connection_t_handler
56   (vl_api_sctp_add_src_dst_connection_t * mp)
57 {
58   vlib_main_t *vm = vlib_get_main ();
59   vl_api_sctp_add_src_dst_connection_reply_t *rmp;
60   int rv;
61
62   if (mp->is_ipv6)
63     rv = sctp_sub_connection_add_ip6
64       (vm,
65        (ip6_address_t *) mp->src_address, (ip6_address_t *) mp->dst_address);
66   else
67     rv = sctp_sub_connection_add_ip4
68       (vm,
69        (ip4_address_t *) mp->src_address, (ip4_address_t *) mp->dst_address);
70
71   REPLY_MACRO (VL_API_SCTP_ADD_SRC_DST_CONNECTION_REPLY);
72 }
73
74 static void
75   vl_api_sctp_del_src_dst_connection_t_handler
76   (vl_api_sctp_del_src_dst_connection_t * mp)
77 {
78   vl_api_sctp_del_src_dst_connection_reply_t *rmp;
79   int rv;
80
81   if (mp->is_ipv6)
82     rv = sctp_sub_connection_del_ip6
83       ((ip6_address_t *) mp->src_address, (ip6_address_t *) mp->dst_address);
84   else
85     rv = sctp_sub_connection_del_ip4
86       ((ip4_address_t *) mp->src_address, (ip4_address_t *) mp->dst_address);
87
88   REPLY_MACRO (VL_API_SCTP_ADD_SRC_DST_CONNECTION_REPLY);
89 }
90
91 static void
92 vl_api_sctp_config_t_handler (vl_api_sctp_config_t * mp)
93 {
94   sctp_user_configuration_t config;
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
110 setup_message_id_table (sctp_main_t * sm, api_main_t * am)
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 *
119 sctp_plugin_api_hookup (vlib_main_t * vm)
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);
140   foreach_sctp_plugin_api_msg;
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  */