Line data Source code
1 : /* Copyright (c) 2021-2022 Cisco and/or its affiliates.
2 : * Licensed under the Apache License, Version 2.0 (the "License");
3 : * you may not use this file except in compliance with the License.
4 : * You may obtain a copy of the License at:
5 : *
6 : * http://www.apache.org/licenses/LICENSE-2.0
7 : *
8 : * Unless required by applicable law or agreed to in writing, software
9 : * distributed under the License is distributed on an "AS IS" BASIS,
10 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 : * See the License for the specific language governing permissions and
12 : * limitations under the License. */
13 :
14 : #include <vlib/vlib.h>
15 : #include <vnet/fib/fib_api.h>
16 : #include <vnet/ip/ip_format_fns.h>
17 : #include <vlibmemory/api.h>
18 : #include <vlibapi/api.h>
19 :
20 : #define REPLY_MSG_ID_BASE vl_api_ip_sesion_redirect_msg_id_base
21 : #include <vlibapi/api_helper_macros.h>
22 :
23 : #include "ip_session_redirect.api_enum.h"
24 : #include "ip_session_redirect.api_types.h"
25 :
26 : #include "ip_session_redirect.h"
27 :
28 : static u16 vl_api_ip_sesion_redirect_msg_id_base;
29 :
30 : static int
31 12 : vl_api_ip_session_redirect_add (u32 table_index, u32 opaque_index,
32 : vl_api_fib_path_nh_proto_t proto, int is_punt,
33 : u8 *match, int match_len,
34 : vl_api_fib_path_t *paths, int n_paths)
35 : {
36 12 : vlib_main_t *vm = vlib_get_main ();
37 12 : fib_route_path_t *paths_ = 0;
38 : dpo_proto_t proto_;
39 12 : u8 *match_ = 0;
40 12 : int rv = 0;
41 :
42 12 : if (n_paths <= 0)
43 : {
44 0 : rv = VNET_API_ERROR_NO_PATHS_IN_ROUTE;
45 0 : goto err0;
46 : }
47 :
48 24 : for (int i = 0; i < n_paths; i++)
49 : {
50 : fib_route_path_t path;
51 12 : if ((rv = fib_api_path_decode (&paths[i], &path)))
52 0 : goto err1;
53 12 : vec_add1 (paths_, path);
54 : }
55 :
56 12 : if (~0 == proto)
57 8 : proto_ = paths_[0].frp_proto;
58 : else
59 4 : fib_api_path_nh_proto_to_dpo (ntohl (proto), &proto_);
60 :
61 12 : vec_add (match_, match, match_len);
62 12 : rv = ip_session_redirect_add (vm, ntohl (table_index), ntohl (opaque_index),
63 : proto_, is_punt, match_, paths_);
64 12 : vec_free (match_);
65 :
66 12 : err1:
67 12 : vec_free (paths_);
68 12 : err0:
69 12 : return rv;
70 : }
71 :
72 : static void
73 0 : vl_api_ip_session_redirect_add_t_handler (vl_api_ip_session_redirect_add_t *mp)
74 : {
75 : vl_api_ip_session_redirect_add_reply_t *rmp;
76 0 : int rv = vl_api_ip_session_redirect_add (
77 0 : mp->table_index, mp->opaque_index, ~0 /* proto */, mp->is_punt, mp->match,
78 0 : mp->match_len, mp->paths, mp->n_paths);
79 0 : REPLY_MACRO (VL_API_IP_SESSION_REDIRECT_ADD_REPLY)
80 : }
81 :
82 : static void
83 12 : vl_api_ip_session_redirect_add_v2_t_handler (
84 : vl_api_ip_session_redirect_add_v2_t *mp)
85 : {
86 : vl_api_ip_session_redirect_add_v2_reply_t *rmp;
87 12 : int rv = vl_api_ip_session_redirect_add (
88 12 : mp->table_index, mp->opaque_index, mp->proto, mp->is_punt, mp->match,
89 12 : mp->match_len, mp->paths, mp->n_paths);
90 12 : REPLY_MACRO (VL_API_IP_SESSION_REDIRECT_ADD_V2_REPLY)
91 : }
92 :
93 : static void
94 8 : vl_api_ip_session_redirect_del_t_handler (vl_api_ip_session_redirect_del_t *mp)
95 : {
96 8 : vlib_main_t *vm = vlib_get_main ();
97 : vl_api_ip_session_redirect_del_reply_t *rmp;
98 8 : u8 *match = 0;
99 : int rv;
100 :
101 8 : vec_add (match, mp->match, mp->match_len);
102 8 : rv = ip_session_redirect_del (vm, ntohl (mp->table_index), match);
103 8 : vec_free (match);
104 :
105 8 : REPLY_MACRO (VL_API_IP_SESSION_REDIRECT_DEL_REPLY);
106 : }
107 :
108 : #include "ip_session_redirect.api.c"
109 : static clib_error_t *
110 559 : ip_session_redirect_plugin_api_hookup (vlib_main_t *vm)
111 : {
112 559 : vl_api_ip_sesion_redirect_msg_id_base = setup_message_id_table ();
113 559 : return 0;
114 : }
115 :
116 1119 : VLIB_API_INIT_FUNCTION (ip_session_redirect_plugin_api_hookup);
117 :
118 : /*
119 : * fd.io coding-style-patch-verification: ON
120 : *
121 : * Local Variables:
122 : * eval: (c-set-style "gnu")
123 : * End:
124 : */
|