http_static: fix memory hss_session using after be freed
[vpp.git] / src / plugins / http_static / http_static.c
index b8d6931..967b847 100644 (file)
 
 #include <vpp/api/types.h>
 
-#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
 
 #define REPLY_MSG_ID_BASE hsm->msg_id_base
 #include <vlibapi/api_helper_macros.h>
 
 __clib_export void
-hss_register_url_handler (hss_url_handler_t fp, const char *url,
+hss_register_url_handler (hss_url_handler_fn fp, const char *url,
                          http_req_method_t request_type)
 {
   hss_main_t *hsm = &hss_main;
@@ -67,17 +66,18 @@ hss_register_url_handler (hss_url_handler_t fp, const char *url,
  */
 static int
 hss_enable_api (u32 fifo_size, u32 cache_limit, u32 prealloc_fifos,
-               u32 private_segment_size, u8 *www_root, u8 *uri)
+               u32 private_segment_size, u8 *www_root, u8 *uri, u32 max_age)
 {
   hss_main_t *hsm = &hss_main;
   int rv;
 
   hsm->fifo_size = fifo_size;
-  hsm->cache_limit = cache_limit;
+  hsm->cache_size = cache_limit;
   hsm->prealloc_fifos = prealloc_fifos;
   hsm->private_segment_size = private_segment_size;
   hsm->www_root = format (0, "%s%c", www_root, 0);
   hsm->uri = format (0, "%s%c", uri, 0);
+  hsm->max_age = max_age;
 
   if (vec_len (hsm->www_root) < 2)
     return VNET_API_ERROR_INVALID_VALUE;
@@ -85,7 +85,10 @@ hss_enable_api (u32 fifo_size, u32 cache_limit, u32 prealloc_fifos,
   if (hsm->app_index != ~0)
     return VNET_API_ERROR_APP_ALREADY_ATTACHED;
 
-  vnet_session_enable_disable (hsm->vlib_main, 1 /* turn on TCP, etc. */);
+  session_enable_disable_args_t args = { .is_en = 1,
+                                        .rt_engine_type =
+                                          RT_BACKEND_ENGINE_RULE_TABLE };
+  vnet_session_enable_disable (hsm->vlib_main, &args);
 
   rv = hss_create (hsm->vlib_main);
   switch (rv)
@@ -111,14 +114,33 @@ static void vl_api_http_static_enable_t_handler
   mp->uri[ARRAY_LEN (mp->uri) - 1] = 0;
   mp->www_root[ARRAY_LEN (mp->www_root) - 1] = 0;
 
-  rv =
-    hss_enable_api (ntohl (mp->fifo_size), ntohl (mp->cache_size_limit),
-                   ntohl (mp->prealloc_fifos),
-                   ntohl (mp->private_segment_size), mp->www_root, mp->uri);
+  rv = hss_enable_api (ntohl (mp->fifo_size), ntohl (mp->cache_size_limit),
+                      ntohl (mp->prealloc_fifos),
+                      ntohl (mp->private_segment_size), mp->www_root, mp->uri,
+                      HSS_DEFAULT_MAX_AGE);
 
   REPLY_MACRO (VL_API_HTTP_STATIC_ENABLE_REPLY);
 }
 
+/* API message handler */
+static void
+vl_api_http_static_enable_v2_t_handler (vl_api_http_static_enable_v2_t *mp)
+{
+  vl_api_http_static_enable_v2_reply_t *rmp;
+  hss_main_t *hsm = &hss_main;
+  int rv;
+
+  mp->uri[ARRAY_LEN (mp->uri) - 1] = 0;
+  mp->www_root[ARRAY_LEN (mp->www_root) - 1] = 0;
+
+  rv = hss_enable_api (ntohl (mp->fifo_size), ntohl (mp->cache_size_limit),
+                      ntohl (mp->prealloc_fifos),
+                      ntohl (mp->private_segment_size), mp->www_root, mp->uri,
+                      ntohl (mp->max_age));
+
+  REPLY_MACRO (VL_API_HTTP_STATIC_ENABLE_V2_REPLY);
+}
+
 #include <http_static/http_static.api.c>
 static clib_error_t *
 hss_api_init (vlib_main_t *vm)