FD.io VPP  v21.06-3-gbb25fbf28
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* */
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  */
api.h
clib_error_return
#define clib_error_return(e, args...)
Definition: error.h:99
vlib_cli_command_t::path
char * path
Definition: cli.h:96
builtinurl_handler_init
void builtinurl_handler_init(builtinurl_main_t *bm)
Definition: builtins.c:188
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
api.h
unformat_input_t
struct _unformat_input_t unformat_input_t
setup_message_id_table
static void setup_message_id_table(api_main_t *am)
Definition: bfd_api.c:451
vl_api_builtinurl_enable_t
API to enable / disable builtinurl on an interface.
Definition: builtinurl.api:37
builtinurl_init
static clib_error_t * builtinurl_init(vlib_main_t *vm)
Definition: builtinurl.c:112
vl_api_builtinurl_enable_t_handler
static void vl_api_builtinurl_enable_t_handler(vl_api_builtinurl_enable_t *mp)
Definition: builtinurl.c:99
builtinurl_main_t::vnet_main
vnet_main_t * vnet_main
Definition: builtinurl.h:41
vnet_get_main
vnet_main_t * vnet_get_main(void)
Definition: pnat_test_stubs.h:56
REPLY_MACRO
#define REPLY_MACRO(t)
Definition: api_helper_macros.h:30
builtinurl_main_t::register_handler
void(* register_handler)(void *, char *, int)
Definition: builtinurl.h:34
VLIB_CLI_COMMAND
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:163
builtinurl_main_t
Definition: builtinurl.h:28
builtinurl_main_t::vlib_main
vlib_main_t * vlib_main
Definition: builtinurl.h:40
plugin.h
builtinurl_main
builtinurl_main_t builtinurl_main
Definition: builtinurl.c:34
builtinurl_main_t::initialized
int initialized
Definition: builtinurl.h:37
VLIB_INIT_FUNCTION
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:172
api_helper_macros.h
VLIB_PLUGIN_REGISTER
VLIB_PLUGIN_REGISTER()
vlib_main_t
Definition: main.h:102
clib_error_t
Definition: clib_error.h:21
vlib_init_function_t
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
Definition: init.h:51
builtinurl_enable
int builtinurl_enable(builtinurl_main_t *bmp)
Definition: builtinurl.c:39
builtinurl_enable_command
static vlib_cli_command_t builtinurl_enable_command
(constructor) VLIB_CLI_COMMAND (builtinurl_enable_command)
Definition: builtinurl.c:89
builtinurl_enable_command_fn
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
rv
int __clib_unused rv
Definition: application.c:491
builtinurl.h
vnet.h
vlib_cli_command_t
Definition: cli.h:92
builtinurl_main_t::msg_id_base
u16 msg_id_base
Definition: builtinurl.h:31
vlib_get_plugin_symbol
void * vlib_get_plugin_symbol(char *plugin_name, char *symbol_name)
Definition: plugin.c:38