blob: 1c74cdd241bdce293796beac3f0df881802bf1a9 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
2 * plugin.h: plugin handling
3 *
4 * Copyright (c) 2011 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#ifndef __included_plugin_h__
19#define __included_plugin_h__
20
21#include <vlib/vlib.h>
22#include <vlib/unix/unix.h>
23#include <sys/types.h>
24#include <sys/stat.h>
25#include <unistd.h>
26
27/*
28 * vlib plugin scheme
29 *
30 * Almost anything which can be made to work in a vlib unix
Dave Barach9b8ffd92016-07-08 08:13:45 -040031 * application will also work in a vlib plugin.
32 *
33 * The elf-section magic which registers static objects
Ed Warnickecb9cada2015-12-08 15:45:58 -070034 * works so long as plugins are preset when the vlib unix process
Dave Barach9b8ffd92016-07-08 08:13:45 -040035 * starts. But wait: there's more...
36 *
Ed Warnickecb9cada2015-12-08 15:45:58 -070037 * If an application calls vlib_load_new_plugins() -- possibly after
38 * changing vlib_plugin_main.plugin_path / vlib_plugin_main.plugin_name_filter,
39 * -- new plugins will be loaded. That, in turn, allows considerable
40 * flexibility in terms of adding feature code or fixing bugs without
41 * requiring the data-plane process to restart.
42 *
43 * When the plugin mechanism loads a plugin, it uses dlsym to locate
44 * and call the plugin's function vlib_plugin_register() if it exists.
45 * A plugin which expects to be loaded after the vlib application
46 * starts uses this callback to modify the application. If vlib_plugin_register
47 * returns non-zero, the plugin mechanism dlclose()'s the plugin.
48 *
49 * Applications control the plugin search path and name filter by
50 * declaring the variables vlib_plugin_path and vlib_plugin_name_filter.
Damjan Marion0eca04d2017-01-03 20:11:35 +010051 * libvlib.la supplies weak references for these symbols which
Ed Warnickecb9cada2015-12-08 15:45:58 -070052 * effectively disable the scheme. In order for the elf-section magic to
53 * work, static plugins must be loaded at the earliest possible moment.
54 *
55 * An application can change these parameters at any time and call
56 * vlib_load_new_plugins().
57 */
Ed Warnickecb9cada2015-12-08 15:45:58 -070058
59
Dave Barach9b8ffd92016-07-08 08:13:45 -040060
61typedef struct
62{
Ed Warnickecb9cada2015-12-08 15:45:58 -070063 u8 *name;
Damjan Marionf935e332017-01-06 14:33:05 +010064 u8 *filename;
Ed Warnickecb9cada2015-12-08 15:45:58 -070065 struct stat file_info;
66 void *handle;
67} plugin_info_t;
68
Dave Barach9b8ffd92016-07-08 08:13:45 -040069typedef struct
70{
Ed Warnickecb9cada2015-12-08 15:45:58 -070071 /* loaded plugin info */
72 plugin_info_t *plugin_info;
73 uword *plugin_by_name_hash;
74
75 /* path and name filter */
76 u8 *plugin_path;
77 u8 *plugin_name_filter;
78
79 /* handoff structure get callback */
80 void *handoff_structure_get_cb;
81
82 /* usual */
83 vlib_main_t *vlib_main;
84} plugin_main_t;
85
Damjan Marion6a7acc22016-12-19 16:28:36 +010086extern plugin_main_t vlib_plugin_main;
Ed Warnickecb9cada2015-12-08 15:45:58 -070087
Dave Barach9b8ffd92016-07-08 08:13:45 -040088int vlib_plugin_early_init (vlib_main_t * vm);
89int vlib_load_new_plugins (plugin_main_t * pm, int from_early_init);
Damjan Marionf935e332017-01-06 14:33:05 +010090void *vlib_get_plugin_symbol (char *plugin_name, char *symbol_name);
Ed Warnickecb9cada2015-12-08 15:45:58 -070091
92#endif /* __included_plugin_h__ */
Dave Barach9b8ffd92016-07-08 08:13:45 -040093
94/*
95 * fd.io coding-style-patch-verification: ON
96 *
97 * Local Variables:
98 * eval: (c-set-style "gnu")
99 * End:
100 */