FD.io VPP  v20.05.1-6-gf53edbc3b
Vector Packet Processing
builtinurl.c
Go to the documentation of this file.
1 /*
2  * builtinurl.c - skeleton vpp engine plug-in
3  *
4  * Copyright (c) 2019 Cisco and/or its affiliates.
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #include <vnet/vnet.h>
19 #include <vnet/plugin/plugin.h>
20 #include <builtinurl/builtinurl.h>
21 
22 #include <vlibapi/api.h>
23 #include <vlibmemory/api.h>
24 #include <vpp/app/version.h>
25 #include <stdbool.h>
26 
27 /* define message IDs */
28 #include <builtinurl/builtinurl.api_enum.h>
29 #include <builtinurl/builtinurl.api_types.h>
30 
31 #define REPLY_MSG_ID_BASE bmp->msg_id_base
33 
35 
36 /* Action function shared between message handler and debug CLI */
37 
38 int
40 {
41  void (*fp) (void *, char *, int);
42 
43  if (bmp->initialized)
44  return 0;
45 
46  /* Look up the builtin URL registration handler */
48  ("http_static_plugin.so", "http_static_server_register_builtin_handler");
49 
50  /* Most likely, the http_static plugin isn't loaded. Done. */
51  if (fp == 0)
52  return VNET_API_ERROR_NO_SUCH_TABLE;
53 
54  bmp->register_handler = fp;
56  bmp->initialized = 1;
57 
58  return 0;
59 }
60 
61 static clib_error_t *
63  unformat_input_t * input,
64  vlib_cli_command_t * cmd)
65 {
67 
68  int rv;
69 
70  rv = builtinurl_enable (bmp);
71 
72  switch (rv)
73  {
74  case 0:
75  break;
76 
77  case VNET_API_ERROR_NO_SUCH_TABLE:
78  return clib_error_return
79  (0, "http_static_server_register_builtin_handler undefined");
80  break;
81 
82  default:
83  return clib_error_return (0, "builtinurl_enable returned %d", rv);
84  }
85  return 0;
86 }
87 
88 /* *INDENT-OFF* */
89 VLIB_CLI_COMMAND (builtinurl_enable_command, static) =
90 {
91  .path = "builtinurl enable",
92  .short_help = "Turn on builtin http/https GET and POST urls",
93  .function = builtinurl_enable_command_fn,
94 };
95 /* *INDENT-ON* */
96 
97 /* API message handler */
100 {
101  vl_api_builtinurl_enable_reply_t *rmp;
103  int rv;
104 
105  rv = builtinurl_enable (bmp);
106 
107  REPLY_MACRO (VL_API_BUILTINURL_ENABLE_REPLY);
108 }
109 
110 #include <builtinurl/builtinurl.api.c>
111 static clib_error_t *
113 {
115 
116  bmp->vlib_main = vm;
117  bmp->vnet_main = vnet_get_main ();
118 
119  /* Ask for a correctly-sized block of API message decode slots */
121 
122  return 0;
123 }
124 
126 
127 /* *INDENT-OFF* */
129 {
130  .version = VPP_BUILD_VER,
131  .description = "vpp built-in URL support",
132 };
133 /* *INDENT-ON* */
134 
135 /*
136  * fd.io coding-style-patch-verification: ON
137  *
138  * Local Variables:
139  * eval: (c-set-style "gnu")
140  * End:
141  */
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
vlib_main_t * vlib_main
Definition: builtinurl.h:40
static clib_error_t * builtinurl_init(vlib_main_t *vm)
Definition: builtinurl.c:112
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:173
#define clib_error_return(e, args...)
Definition: error.h:99
vnet_main_t * vnet_main
Definition: builtinurl.h:41
static void vl_api_builtinurl_enable_t_handler(vl_api_builtinurl_enable_t *mp)
Definition: builtinurl.c:99
struct _unformat_input_t unformat_input_t
#define REPLY_MACRO(t)
vlib_main_t * vm
Definition: in2out_ed.c:1599
API to enable / disable builtinurl on an interface.
Definition: builtinurl.api:37
builtinurl_main_t builtinurl_main
Definition: builtinurl.c:34
void builtinurl_handler_init(builtinurl_main_t *bm)
Definition: builtins.c:188
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:152
void(* register_handler)(void *, char *, int)
Definition: builtinurl.h:34
VLIB_PLUGIN_REGISTER()
void * vlib_get_plugin_symbol(char *plugin_name, char *symbol_name)
Definition: plugin.c:38
static clib_error_t * builtinurl_enable_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: builtinurl.c:62
static void setup_message_id_table(snat_main_t *sm, api_main_t *am)
Definition: nat_api.c:3256
int builtinurl_enable(builtinurl_main_t *bmp)
Definition: builtinurl.c:39