|
12 | 12 | * limitations under the License. */ |
13 | 13 |
|
14 | 14 | #include <vlib/vlib.h> |
| 15 | +#include <vnet/fib/fib_path_list.h> |
15 | 16 | #include <vnet/fib/fib_api.h> |
16 | 17 | #include <vnet/ip/ip_format_fns.h> |
| 18 | +#include <vnet/classify/vnet_classify.h> |
17 | 19 | #include <vlibmemory/api.h> |
18 | 20 | #include <vlibapi/api.h> |
19 | 21 |
|
@@ -105,6 +107,68 @@ vl_api_ip_session_redirect_del_t_handler (vl_api_ip_session_redirect_del_t *mp) |
105 | 107 | REPLY_MACRO (VL_API_IP_SESSION_REDIRECT_DEL_REPLY); |
106 | 108 | } |
107 | 109 |
|
| 110 | +static void |
| 111 | +send_ip_session_redirect_details (vl_api_registration_t *reg, u32 table_index, |
| 112 | + u32 context) |
| 113 | +{ |
| 114 | + ip_session_redirect_main_t *im = &ip_session_redirect_main; |
| 115 | + ip_session_redirect_t *ipr; |
| 116 | + ip_session_redirect_t *iprs = im->pool; |
| 117 | + |
| 118 | + pool_foreach (ipr, iprs) |
| 119 | + { |
| 120 | + if (~0 == table_index || ipr->table_index == table_index) |
| 121 | + { |
| 122 | + vl_api_ip_session_redirect_details_t *rmp; |
| 123 | + vl_api_fib_path_t *fp; |
| 124 | + fib_route_path_t *rpath; |
| 125 | + fib_path_encode_ctx_t walk_ctx = { |
| 126 | + .rpaths = NULL, |
| 127 | + }; |
| 128 | + u8 n_paths = fib_path_list_get_n_paths (ipr->pl); |
| 129 | + /* match_len is computed without table index at the end of the match |
| 130 | + * string */ |
| 131 | + u32 match_len = vec_len (ipr->match_and_table_index) - 4; |
| 132 | + |
| 133 | + rmp = vl_msg_api_alloc_zero (sizeof (*rmp) + |
| 134 | + sizeof (rmp->paths[0]) * n_paths); |
| 135 | + rmp->_vl_msg_id = |
| 136 | + ntohs (REPLY_MSG_ID_BASE + VL_API_IP_SESSION_REDIRECT_DETAILS); |
| 137 | + rmp->context = context; |
| 138 | + rmp->opaque_index = htonl (ipr->opaque_index); |
| 139 | + rmp->table_index = htonl (ipr->table_index); |
| 140 | + rmp->match_length = htonl (match_len); |
| 141 | + rmp->is_punt = ipr->is_punt; |
| 142 | + rmp->is_ip6 = ipr->is_ip6; |
| 143 | + clib_memcpy (rmp->match, ipr->match_and_table_index, match_len); |
| 144 | + rmp->n_paths = n_paths; |
| 145 | + fp = rmp->paths; |
| 146 | + rmp->retval = 0; |
| 147 | + fib_path_list_walk_w_ext (ipr->pl, NULL, fib_path_encode, &walk_ctx); |
| 148 | + vec_foreach (rpath, walk_ctx.rpaths) |
| 149 | + { |
| 150 | + fib_api_path_encode (rpath, fp); |
| 151 | + fp++; |
| 152 | + } |
| 153 | + |
| 154 | + vl_api_send_msg (reg, (u8 *) rmp); |
| 155 | + } |
| 156 | + } |
| 157 | +} |
| 158 | + |
| 159 | +static void |
| 160 | +vl_api_ip_session_redirect_dump_t_handler ( |
| 161 | + vl_api_ip_session_redirect_dump_t *mp) |
| 162 | +{ |
| 163 | + vl_api_registration_t *reg; |
| 164 | + u32 table_index = ntohl (mp->table_index); |
| 165 | + reg = vl_api_client_index_to_registration (mp->client_index); |
| 166 | + if (reg == 0) |
| 167 | + return; |
| 168 | + |
| 169 | + send_ip_session_redirect_details (reg, table_index, mp->context); |
| 170 | +} |
| 171 | + |
108 | 172 | #include "ip_session_redirect.api.c" |
109 | 173 | static clib_error_t * |
110 | 174 | ip_session_redirect_plugin_api_hookup (vlib_main_t *vm) |
|
0 commit comments