d804fcb36a40126049476b9dc7b373fcf4f39279
[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 <vnet/ip/ip_types_api.h>
25 #include <vnet/format_fns.h>
26
27 #include <sctp/sctp.h>
28
29 #include <sctp/sctp.api_enum.h>
30 #include <sctp/sctp.api_types.h>
31
32 #define REPLY_MSG_ID_BASE sctp_main.msg_id_base
33 #include <vlibapi/api_helper_macros.h>
34
35 static void
36   vl_api_sctp_add_src_dst_connection_t_handler
37   (vl_api_sctp_add_src_dst_connection_t * mp)
38 {
39   vlib_main_t *vm = vlib_get_main ();
40   vl_api_sctp_add_src_dst_connection_reply_t *rmp;
41   int rv;
42   ip46_address_t src, dst;
43
44   ip_address_decode (&mp->src_address, &src);
45   ip_address_decode (&mp->dst_address, &dst);
46
47   if (ip46_address_is_ip4 (&src) && ip46_address_is_ip4 (&dst))
48     rv = sctp_sub_connection_add_ip4 (vm, &src.ip4, &dst.ip4);
49   else
50     rv = sctp_sub_connection_add_ip6 (vm, &src.ip6, &dst.ip6);
51
52   REPLY_MACRO (VL_API_SCTP_ADD_SRC_DST_CONNECTION_REPLY);
53 }
54
55 static void
56   vl_api_sctp_del_src_dst_connection_t_handler
57   (vl_api_sctp_del_src_dst_connection_t * mp)
58 {
59   vl_api_sctp_del_src_dst_connection_reply_t *rmp;
60   int rv;
61   ip46_address_t src, dst;
62
63   ip_address_decode (&mp->src_address, &src);
64   ip_address_decode (&mp->dst_address, &dst);
65
66   if (ip46_address_is_ip4 (&src) && ip46_address_is_ip4 (&dst))
67     rv = sctp_sub_connection_del_ip4 (&src.ip4, &dst.ip4);
68   else
69     rv = sctp_sub_connection_del_ip6 (&src.ip6, &dst.ip6);
70
71   REPLY_MACRO (VL_API_SCTP_ADD_SRC_DST_CONNECTION_REPLY);
72 }
73
74 static void
75 vl_api_sctp_config_t_handler (vl_api_sctp_config_t * mp)
76 {
77   sctp_user_configuration_t config;
78   vl_api_sctp_config_reply_t *rmp;
79   int rv;
80
81   config.never_delay_sack = mp->never_delay_sack;
82   config.never_bundle = mp->never_bundle;
83   rv = sctp_configure (config);
84
85   REPLY_MACRO (VL_API_SCTP_CONFIG_REPLY);
86 }
87
88 #include <sctp/sctp.api.c>
89 clib_error_t *
90 sctp_plugin_api_hookup (vlib_main_t * vm)
91 {
92   /* Ask for a correctly-sized block of API message decode slots */
93   sctp_main.msg_id_base = setup_message_id_table ();
94
95   return 0;
96 }
97
98 /*
99  * fd.io coding-style-patch-verification: ON
100  *
101  * Local Variables:
102  * eval: (c-set-style "gnu")
103  * End:
104  */