SCTP: API to add a sub-connection
[vpp.git] / src / vnet / sctp / sctp_api.c
1 /*
2  *------------------------------------------------------------------
3  * sctp_api.c - vnet 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 <vnet/vnet.h>
21 #include <vlibmemory/api.h>
22
23 #include <vnet/sctp/sctp.h>
24
25 #include <vnet/vnet_msg_enum.h>
26
27 #define vl_typedefs             /* define message structures */
28 #include <vnet/vnet_all_api_h.h>
29 #undef vl_typedefs
30
31 #define vl_endianfun            /* define message structures */
32 #include <vnet/vnet_all_api_h.h>
33 #undef vl_endianfun
34
35 /* instantiate all the print functions we know about */
36 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
37 #define vl_printfun
38 #include <vnet/vnet_all_api_h.h>
39 #undef vl_printfun
40
41 #include <vlibapi/api_helper_macros.h>
42
43 #define foreach_sctp_api_msg                                     \
44 _(SCTP_ADD_SRC_DST_CONNECTION, sctp_add_src_dst_connection)
45
46 static void
47   vl_api_sctp_add_src_dst_connection_t_handler
48   (vl_api_sctp_add_src_dst_connection_t * mp)
49 {
50   vlib_main_t *vm = vlib_get_main ();
51   vl_api_sctp_add_src_dst_connection_reply_t *rmp;
52   int rv;
53
54   if (mp->is_ipv6)
55     rv = sctp_sub_connection_add_ip6
56       (vm,
57        (ip6_address_t *) mp->src_address, (ip6_address_t *) mp->dst_address);
58   else
59     rv = sctp_sub_connection_add_ip4
60       (vm,
61        (ip4_address_t *) mp->src_address, (ip4_address_t *) mp->dst_address);
62
63   REPLY_MACRO (VL_API_SCTP_ADD_SRC_DST_CONNECTION_REPLY);
64 }
65
66 #define vl_msg_name_crc_list
67 #include <vnet/sctp/sctp.api.h>
68 #undef vl_msg_name_crc_list
69
70 static void
71 setup_message_id_table (api_main_t * am)
72 {
73 #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id);
74   foreach_vl_msg_name_crc_sctp;
75 #undef _
76 }
77
78 static clib_error_t *
79 sctp_api_hookup (vlib_main_t * vm)
80 {
81   api_main_t *am = &api_main;
82
83 #define _(N,n)                                                  \
84     vl_msg_api_set_handlers(VL_API_##N, #n,                     \
85                            vl_api_##n##_t_handler,              \
86                            vl_noop_handler,                     \
87                            vl_api_##n##_t_endian,               \
88                            vl_api_##n##_t_print,                \
89                            sizeof(vl_api_##n##_t), 1);
90   foreach_sctp_api_msg;
91 #undef _
92
93   /*
94    * Set up the (msg_name, crc, message-id) table
95    */
96   setup_message_id_table (am);
97
98   return 0;
99 }
100
101 VLIB_API_INIT_FUNCTION (sctp_api_hookup);
102
103 void
104 sctp_api_reference (void)
105 {
106 }
107
108 /*
109  * fd.io coding-style-patch-verification: ON
110  *
111  * Local Variables:
112  * eval: (c-set-style "gnu")
113  * End:
114  */