Thank you, I have figured out those things (but not all of them, so thanks for the detailed explanation).
The problem that I have is that I have not found good examples about the structure of the environment variable (I have seen the: get_env function in simple.c so I will try to print that variable to the log or to the stdout to study its structure and data stored on it). Thanks to all for the help. As a suggestion, I would upload a mini-howto about making plugins at the website, description made by David Sommerset in this email can be very helpful and if it was a wiki, all people could collaborate. Thanks again, I will tell you about my success or not about making the plugin. -- Jose Sánchez <jose dot informatica at centrolamilagrosa dot org> El sáb, 20-09-2008 a las 09:59 +0200, David Sommerseth escribió: > > Jose Sanchez wrote: > > Hello, I am new at openvpn, I am trying to do a very simple plugin to > > see connections/disconnections and to be able to notify to another > > system in "real" time. > > > > The problem is that I haven't found any documentation about the code or > > about how to make plugins except on the code (I have been reading the > > comments and I have some code of my plugin). > > > > The main problem is that there are two functions: OPENVPN_PLUGIN_DEF int > > OPENVPN_PLUGIN_FUNC(openvpn_plugin_func_v1) > > (openvpn_plugin_handle_t handle, const int type, const char > > *argv[], const char *envp[]); > > and > > OPENVPN_PLUGIN_DEF int OPENVPN_PLUGIN_FUNC(openvpn_plugin_func_v2) > > (openvpn_plugin_handle_t handle, > > const int type, > > const char *argv[], > > const char *envp[], > > void *per_client_context, > > struct openvpn_plugin_string_list **return_list); > > > > What I need is to obtain the public (inet IP) and the private (vpn ip) > > when a client connects/disconnect to notify it to another program (I > > know I can make a ping or similar things but it seems to be too slow > > when there are a lot of clients connected (> 100)). > > > > What I need is to know in which variable is that data and which function > > I need to implement (v1 or v2) and how these functions works (Is any > > documentation on any site?). > > > > In openvpn_plugin_open_v1 I have registered the events: *type_mask = > > OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_CLIENT_CONNECT) | > > OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_CLIENT_DISCONNECT); and even on > > openvpn_plugin_func_v1 I can know if there is if (type == > > OPENVPN_PLUGIN_CLIENT_CONNECT) or OPENVPN_PLUGIN_CLIENT_DISCONNECT but I > > don't know how to recover IP information. > > > > If somebody could help me or saying me where the documentation is would > > be great. > > > > Thanks in advance and excuse my english (I have written this too > > quickly) and excuse me if what i am asking is answered on another place > > that I haven't found. > > > > Hi! > > I'm writing a plugin as well, and I have been through the same as you're > facing now. It's not hard > or difficult at all, but it requires some testing before you figure out all > the pieces. Anyway, > have a look on those plugins available in the plugin directory in the OpenVPN > source code and you > might find some help here. Here it is several different approaches. I used > auth-pam as a starting > point for my project. This is btw. using the v1 plugin interface. I see > that a v2. version is > available, but have not ported my project to this interface yet. > > But I'll give you a quick overview here now. You basically need 3 OpenVPN > based function in your > plugin: > > OPENVPN_EXPORT openvpn_plugin_handle_t > openvpn_plugin_open_v1(unsigned int *type_mask, const char *argv[], const > char *envp[]) > > OPENVPN_EXPORT int > openvpn_plugin_func_v1(openvpn_plugin_handle_t handle, > const int type, > const char *argv[], const char *envp[]) > > OPENVPN_EXPORT void > openvpn_plugin_close_v1(openvpn_plugin_handle_t handle) > > > The first one initialises your plugin, you set a side a memory buffer for you > plugin data (which is > not per connection based, afaik). Here is also where you set the > OPENVPN_PLUGIN_MASK ... f.ex. > > *type_mask = OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_CLIENT_CONNECT) > | OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_CLIENT_DISCONNECT); > > You also return the pointer to your memory buffer from this function. > > > The second one is the one which is called on every plugin event from OpenVPN. > Here's where your > plugin does it's main work. The handle variable is the pointer to your > memory buffer with your > plugin data. > > The third one cleans up after you plugin when OpenVPN shuts down. Again, > handle points at your > plugin data. > > > >From here, it is pretty much straight forward for the rest of the plugin. > >But have a look on the > other plugins as well, as they give more ideas how to do things more > advanced, like using > environment variables (where you'll find your IP addresses). > > > I hope this could help you out. > > > > kind regards, > > David Sommerseth