Dave Barach | 3bbcfab | 2017-08-15 19:03:44 -0400 | [diff] [blame] | 1 | /* |
| 2 | *------------------------------------------------------------------ |
| 3 | * tcp_api.c - vnet tcp-layer apis |
| 4 | * |
| 5 | * Copyright (c) 2017 Cisco and/or its affiliates. |
| 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/tcp/tcp.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_tcp_api_msg \ |
| 44 | _(TCP_CONFIGURE_SRC_ADDRESSES, tcp_configure_src_addresses) |
| 45 | |
| 46 | static void |
| 47 | vl_api_tcp_configure_src_addresses_t_handler |
| 48 | (vl_api_tcp_configure_src_addresses_t * mp) |
| 49 | { |
| 50 | vlib_main_t *vm = vlib_get_main (); |
| 51 | vl_api_tcp_configure_src_addresses_reply_t *rmp; |
| 52 | u32 vrf_id; |
| 53 | int rv; |
| 54 | |
| 55 | vrf_id = clib_net_to_host_u32 (mp->vrf_id); |
| 56 | |
| 57 | if (mp->is_ipv6) |
| 58 | rv = tcp_configure_v6_source_address_range |
| 59 | (vm, |
| 60 | (ip6_address_t *) mp->first_address, |
| 61 | (ip6_address_t *) mp->last_address, vrf_id); |
| 62 | else |
| 63 | rv = tcp_configure_v4_source_address_range |
| 64 | (vm, |
| 65 | (ip4_address_t *) mp->first_address, |
| 66 | (ip4_address_t *) mp->last_address, vrf_id); |
| 67 | |
| 68 | REPLY_MACRO (VL_API_TCP_CONFIGURE_SRC_ADDRESSES_REPLY); |
| 69 | } |
| 70 | |
| 71 | #define vl_msg_name_crc_list |
| 72 | #include <vnet/tcp/tcp.api.h> |
| 73 | #undef vl_msg_name_crc_list |
| 74 | |
| 75 | static void |
| 76 | setup_message_id_table (api_main_t * am) |
| 77 | { |
| 78 | #define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id); |
| 79 | foreach_vl_msg_name_crc_tcp; |
| 80 | #undef _ |
| 81 | } |
| 82 | |
| 83 | static clib_error_t * |
| 84 | tcp_api_hookup (vlib_main_t * vm) |
| 85 | { |
| 86 | api_main_t *am = &api_main; |
| 87 | |
| 88 | #define _(N,n) \ |
| 89 | vl_msg_api_set_handlers(VL_API_##N, #n, \ |
| 90 | vl_api_##n##_t_handler, \ |
| 91 | vl_noop_handler, \ |
| 92 | vl_api_##n##_t_endian, \ |
| 93 | vl_api_##n##_t_print, \ |
| 94 | sizeof(vl_api_##n##_t), 1); |
| 95 | foreach_tcp_api_msg; |
| 96 | #undef _ |
| 97 | |
| 98 | /* |
| 99 | * Set up the (msg_name, crc, message-id) table |
| 100 | */ |
| 101 | setup_message_id_table (am); |
| 102 | |
| 103 | return 0; |
| 104 | } |
| 105 | |
| 106 | VLIB_API_INIT_FUNCTION (tcp_api_hookup); |
| 107 | |
| 108 | void |
| 109 | tcp_api_reference (void) |
| 110 | { |
| 111 | } |
| 112 | |
| 113 | /* |
| 114 | * fd.io coding-style-patch-verification: ON |
| 115 | * |
| 116 | * Local Variables: |
| 117 | * eval: (c-set-style "gnu") |
| 118 | * End: |
| 119 | */ |