Also updated the log_v3 sample-plugin to demonstrate how this
works.
$ openvpn --plugin log_v3.so --dev tun
Fri Jul 10 15:17:28 2015 OpenVPN 2.3_git
[git:dev/plugin-version/f05d8623a29078bf+].....
...more.openvpn.logging...
log_v3: OpenVPN 2.3_git (Major: 2, Minor: 3, Patch:
git:dev/plugin-version/f05d8623a29078bf+)
...more.openvpn.logging...
$
Signed-off-by: David Sommerseth <davids@redhat.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <1436534548-21507-3-git-send-email-openvpn.list@topphemmelig.net>
URL: http://article.gmane.org/gmane.network.openvpn.devel/9904
Signed-off-by: Gert Doering <gert@greenie.muc.de>
| ... | ... |
@@ -33,6 +33,9 @@ AC_DEFINE([OPENVPN_VERSION_RESOURCE], [PRODUCT_VERSION_RESOURCE], [Version in wi |
| 33 | 33 |
AC_SUBST([OPENVPN_VERSION_MAJOR], [PRODUCT_VERSION_MAJOR], [OpenVPN major version]) |
| 34 | 34 |
AC_SUBST([OPENVPN_VERSION_MINOR], [PRODUCT_VERSION_MINOR], [OpenVPN minor version]) |
| 35 | 35 |
AC_SUBST([OPENVPN_VERSION_PATCH], [PRODUCT_VERSION_PATCH], [OpenVPN patch level - may be a string or integer]) |
| 36 |
+AC_DEFINE([OPENVPN_VERSION_MAJOR], [PRODUCT_VERSION_MAJOR], [OpenVPN major version - integer]) |
|
| 37 |
+AC_DEFINE([OPENVPN_VERSION_MINOR], [PRODUCT_VERSION_MINOR], [OpenVPN minor version - integer]) |
|
| 38 |
+AC_DEFINE([OPENVPN_VERSION_PATCH], ["PRODUCT_VERSION_PATCH"], [OpenVPN patch level - may be a string or integer]) |
|
| 36 | 39 |
|
| 37 | 40 |
AC_CONFIG_AUX_DIR([.]) |
| 38 | 41 |
AC_CONFIG_HEADERS([config.h]) |
| ... | ... |
@@ -215,8 +215,11 @@ struct openvpn_plugin_string_list |
| 215 | 215 |
* which identifies the SSL implementation OpenVPN is compiled |
| 216 | 216 |
* against. |
| 217 | 217 |
* |
| 218 |
+ * 3 Added ovpn_version, ovpn_version_major, ovpn_version_minor |
|
| 219 |
+ * and ovpn_version_patch to provide the runtime version of |
|
| 220 |
+ * OpenVPN to plug-ins. |
|
| 218 | 221 |
*/ |
| 219 |
-#define OPENVPN_PLUGINv3_STRUCTVER 2 |
|
| 222 |
+#define OPENVPN_PLUGINv3_STRUCTVER 3 |
|
| 220 | 223 |
|
| 221 | 224 |
/** |
| 222 | 225 |
* Definitions needed for the plug-in callback functions. |
| ... | ... |
@@ -311,6 +314,10 @@ struct openvpn_plugin_args_open_in |
| 311 | 311 |
const char ** const envp; |
| 312 | 312 |
struct openvpn_plugin_callbacks *callbacks; |
| 313 | 313 |
const ovpnSSLAPI ssl_api; |
| 314 |
+ const char *ovpn_version; |
|
| 315 |
+ const unsigned int ovpn_version_major; |
|
| 316 |
+ const unsigned int ovpn_version_minor; |
|
| 317 |
+ const char * const ovpn_version_patch; |
|
| 314 | 318 |
}; |
| 315 | 319 |
|
| 316 | 320 |
|
| ... | ... |
@@ -82,6 +82,7 @@ openvpn_plugin_open_v3 (const int v3structver, |
| 82 | 82 |
|
| 83 | 83 |
/* Check that we are API compatible */ |
| 84 | 84 |
if( v3structver != OPENVPN_PLUGINv3_STRUCTVER ) {
|
| 85 |
+ printf("log_v3: ** ERROR ** Incompatible plug-in interface between this plug-in and OpenVPN\n");
|
|
| 85 | 86 |
return OPENVPN_PLUGIN_FUNC_ERROR; |
| 86 | 87 |
} |
| 87 | 88 |
|
| ... | ... |
@@ -90,6 +91,11 @@ openvpn_plugin_open_v3 (const int v3structver, |
| 90 | 90 |
return OPENVPN_PLUGIN_FUNC_ERROR; |
| 91 | 91 |
} |
| 92 | 92 |
|
| 93 |
+ /* Print some version information about the OpenVPN process using this plug-in */ |
|
| 94 |
+ printf("log_v3: OpenVPN %s (Major: %i, Minor: %i, Patch: %s)\n",
|
|
| 95 |
+ args->ovpn_version, args->ovpn_version_major, |
|
| 96 |
+ args->ovpn_version_minor, args->ovpn_version_patch); |
|
| 97 |
+ |
|
| 93 | 98 |
/* Which callbacks to intercept. */ |
| 94 | 99 |
ret->type_mask = |
| 95 | 100 |
OPENVPN_PLUGIN_MASK (OPENVPN_PLUGIN_UP) | |
| ... | ... |
@@ -27,6 +27,9 @@ |
| 27 | 27 |
#elif defined(_MSC_VER) |
| 28 | 28 |
#include "config-msvc.h" |
| 29 | 29 |
#endif |
| 30 |
+#ifdef HAVE_CONFIG_VERSION_H |
|
| 31 |
+#include "config-version.h" |
|
| 32 |
+#endif |
|
| 30 | 33 |
|
| 31 | 34 |
#include "syshead.h" |
| 32 | 35 |
|
| ... | ... |
@@ -347,6 +350,17 @@ static struct openvpn_plugin_callbacks callbacks = {
|
| 347 | 347 |
plugin_vlog |
| 348 | 348 |
}; |
| 349 | 349 |
|
| 350 |
+ |
|
| 351 |
+/* Provide a wrapper macro for a version patch level string to plug-ins. |
|
| 352 |
+ * This is located here purely to not make the code too messy with #ifndef |
|
| 353 |
+ * inside a struct declaration |
|
| 354 |
+ */ |
|
| 355 |
+#ifndef CONFIGURE_GIT_REVISION |
|
| 356 |
+# define _OPENVPN_PATCH_LEVEL OPENVPN_VERSION_PATCH |
|
| 357 |
+#else |
|
| 358 |
+# define _OPENVPN_PATCH_LEVEL "git:" CONFIGURE_GIT_REVISION CONFIGURE_GIT_FLAGS |
|
| 359 |
+#endif |
|
| 360 |
+ |
|
| 350 | 361 |
static void |
| 351 | 362 |
plugin_open_item (struct plugin *p, |
| 352 | 363 |
const struct plugin_option *o, |
| ... | ... |
@@ -375,7 +389,12 @@ plugin_open_item (struct plugin *p, |
| 375 | 375 |
(const char ** const) o->argv, |
| 376 | 376 |
(const char ** const) envp, |
| 377 | 377 |
&callbacks, |
| 378 |
- SSLAPI }; |
|
| 378 |
+ SSLAPI, |
|
| 379 |
+ PACKAGE_VERSION, |
|
| 380 |
+ OPENVPN_VERSION_MAJOR, |
|
| 381 |
+ OPENVPN_VERSION_MINOR, |
|
| 382 |
+ _OPENVPN_PATCH_LEVEL |
|
| 383 |
+ }; |
|
| 379 | 384 |
struct openvpn_plugin_args_open_return retargs; |
| 380 | 385 |
|
| 381 | 386 |
CLEAR(retargs); |