Dave Barach | 3bbcfab | 2017-08-15 19:03:44 -0400 | [diff] [blame] | 1 | /* |
| 2 | *------------------------------------------------------------------ |
| 3 | * tcp_api.c - vnet tcp-layer apis |
| 4 | * |
Florin Coras | c5df8c7 | 2019-04-08 07:42:30 -0700 | [diff] [blame] | 5 | * Copyright (c) 2017-2019 Cisco and/or its affiliates. |
Dave Barach | 3bbcfab | 2017-08-15 19:03:44 -0400 | [diff] [blame] | 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> |
Jakub Grajciar | 956819a | 2020-01-03 10:02:32 +0100 | [diff] [blame] | 24 | #include <vnet/ip/ip_types_api.h> |
| 25 | |
Filip Tehlar | ec61e10 | 2021-06-22 20:39:03 +0000 | [diff] [blame^] | 26 | #include <vnet/format_fns.h> |
Dave Barach | 3bbcfab | 2017-08-15 19:03:44 -0400 | [diff] [blame] | 27 | |
Filip Tehlar | ec61e10 | 2021-06-22 20:39:03 +0000 | [diff] [blame^] | 28 | #include <vnet/tcp/tcp.api_enum.h> |
| 29 | #include <vnet/tcp/tcp.api_types.h> |
Dave Barach | 3bbcfab | 2017-08-15 19:03:44 -0400 | [diff] [blame] | 30 | |
Filip Tehlar | ec61e10 | 2021-06-22 20:39:03 +0000 | [diff] [blame^] | 31 | #define REPLY_MSG_ID_BASE tcp_main.msg_id_base |
Dave Barach | 3bbcfab | 2017-08-15 19:03:44 -0400 | [diff] [blame] | 32 | #include <vlibapi/api_helper_macros.h> |
| 33 | |
Dave Barach | 3bbcfab | 2017-08-15 19:03:44 -0400 | [diff] [blame] | 34 | static void |
| 35 | vl_api_tcp_configure_src_addresses_t_handler |
| 36 | (vl_api_tcp_configure_src_addresses_t * mp) |
| 37 | { |
| 38 | vlib_main_t *vm = vlib_get_main (); |
| 39 | vl_api_tcp_configure_src_addresses_reply_t *rmp; |
| 40 | u32 vrf_id; |
| 41 | int rv; |
Jakub Grajciar | 956819a | 2020-01-03 10:02:32 +0100 | [diff] [blame] | 42 | ip46_address_t first_address, last_address; |
| 43 | ip46_type_t fa_af, la_af; |
Dave Barach | 3bbcfab | 2017-08-15 19:03:44 -0400 | [diff] [blame] | 44 | |
| 45 | vrf_id = clib_net_to_host_u32 (mp->vrf_id); |
| 46 | |
Jakub Grajciar | 956819a | 2020-01-03 10:02:32 +0100 | [diff] [blame] | 47 | fa_af = ip_address_decode (&mp->first_address, &first_address); |
| 48 | la_af = ip_address_decode (&mp->last_address, &last_address); |
| 49 | |
| 50 | if (fa_af != la_af) |
| 51 | { |
| 52 | rv = VNET_API_ERROR_INVALID_VALUE; |
| 53 | goto error; |
| 54 | } |
| 55 | |
| 56 | if (fa_af == IP46_TYPE_IP6) |
Dave Barach | 3bbcfab | 2017-08-15 19:03:44 -0400 | [diff] [blame] | 57 | rv = tcp_configure_v6_source_address_range |
Jakub Grajciar | 956819a | 2020-01-03 10:02:32 +0100 | [diff] [blame] | 58 | (vm, &first_address.ip6, &last_address.ip6, vrf_id); |
Dave Barach | 3bbcfab | 2017-08-15 19:03:44 -0400 | [diff] [blame] | 59 | else |
| 60 | rv = tcp_configure_v4_source_address_range |
Jakub Grajciar | 956819a | 2020-01-03 10:02:32 +0100 | [diff] [blame] | 61 | (vm, &first_address.ip4, &last_address.ip4, vrf_id); |
Dave Barach | 3bbcfab | 2017-08-15 19:03:44 -0400 | [diff] [blame] | 62 | |
Jakub Grajciar | 956819a | 2020-01-03 10:02:32 +0100 | [diff] [blame] | 63 | error: |
Dave Barach | 3bbcfab | 2017-08-15 19:03:44 -0400 | [diff] [blame] | 64 | REPLY_MACRO (VL_API_TCP_CONFIGURE_SRC_ADDRESSES_REPLY); |
| 65 | } |
| 66 | |
Filip Tehlar | ec61e10 | 2021-06-22 20:39:03 +0000 | [diff] [blame^] | 67 | #include <vnet/tcp/tcp.api.c> |
Dave Barach | 3bbcfab | 2017-08-15 19:03:44 -0400 | [diff] [blame] | 68 | static clib_error_t * |
| 69 | tcp_api_hookup (vlib_main_t * vm) |
| 70 | { |
Dave Barach | 3bbcfab | 2017-08-15 19:03:44 -0400 | [diff] [blame] | 71 | /* |
| 72 | * Set up the (msg_name, crc, message-id) table |
| 73 | */ |
Filip Tehlar | ec61e10 | 2021-06-22 20:39:03 +0000 | [diff] [blame^] | 74 | REPLY_MSG_ID_BASE = setup_message_id_table (); |
Dave Barach | 3bbcfab | 2017-08-15 19:03:44 -0400 | [diff] [blame] | 75 | |
| 76 | return 0; |
| 77 | } |
| 78 | |
| 79 | VLIB_API_INIT_FUNCTION (tcp_api_hookup); |
| 80 | |
Dave Barach | 3bbcfab | 2017-08-15 19:03:44 -0400 | [diff] [blame] | 81 | /* |
| 82 | * fd.io coding-style-patch-verification: ON |
| 83 | * |
| 84 | * Local Variables: |
| 85 | * eval: (c-set-style "gnu") |
| 86 | * End: |
| 87 | */ |