Skip to contentSkip to conversation

Openvpn Traffic handling

Openvpn-devel Roman Vasilyev 1 participant 1 message Feb 6, 2009

lore
Share & tools
lore
#0 lore raw

Hi,

I'm an Anchorfree employee who is adding new functionality to the HSS servers. One of my responsibilities is Intrusion Detection.

The best performance for IDS seems to come from embedding Snort into OpenVPN. In order to achieve this, I have modified OpenVPN to provide packet handling.

Also we need to have our internal statistics on management interface.

My question for you is: would it be possible to integrate my changes into the main OpenVPN branch ?

Please find all this functionality attached in patch file.

Regards

forward.c +7 -0
diff -ru openvpn.orig/forward.c openvpn.new/forward.c
@@ -943,6 +943,8 @@
        * us to examine the IPv4 header.
        */
       process_ipv4_header (c, PIPV4_PASSTOS|PIPV4_MSSFIX, &c->c2.buf);
+      if (plugin_list_handle_ip_in(c->plugins, BPTR(&c->c2.buf), BLEN(&c->c2.buf))==0)
+      {
 
 #ifdef PACKET_TRUNCATION_CHECK
       /* if (c->c2.buf.len > 1) --c->c2.buf.len; */
@@ -954,6 +956,7 @@
 #endif
 
       encrypt_sign (c, true);
+      }
     }
   else
     {
@@ -1147,6 +1150,9 @@
    */
   process_ipv4_header (c, PIPV4_MSSFIX|PIPV4_OUTGOING, &c->c2.to_tun);
 
+  if (plugin_list_handle_ip_out(c->plugins, BPTR(&c->c2.to_tun), BLEN(&c->c2.to_tun))==0)
+  {
+
   if (c->c2.to_tun.len <= MAX_RW_SIZE_TUN (&c->c2.frame))
     {
       /*
@@ -1203,6 +1209,7 @@
 	   c->c2.to_tun.len,
 	   MAX_RW_SIZE_TUN (&c->c2.frame));
     }
+  }
 
   buf_reset (&c->c2.to_tun);
 
init.c +1 -1
diff -ru openvpn.orig/init.c openvpn.new/init.c
@@ -2447,7 +2447,7 @@
 init_management (struct context *c)
 {
   if (!management)
-    management = management_init ();
+    management = management_init (c);
 }
 
 bool
manage.c +9 -2
diff -ru openvpn.orig/manage.c openvpn.new/manage.c
@@ -32,6 +32,7 @@
 
 #ifdef ENABLE_MANAGEMENT
 
+#include "openvpn.h"
 #include "error.h"
 #include "fdmisc.h"
 #include "options.h"
@@ -671,7 +672,12 @@
   struct gc_arena gc = gc_new ();
 
   ASSERT (p[0]);
-  if (streq (p[0], "exit") || streq (p[0], "quit"))
+  if (streq (p[0], "afstat"))
+    {
+      plugin_list_stat(man->ctxt->plugins, p, x_msg);
+      goto done;
+    }
+  else if (streq (p[0], "exit") || streq (p[0], "quit"))
     {
       man->connection.halt = true;
       goto done;
@@ -1457,7 +1463,7 @@
 }
 
 struct management *
-management_init (void)
+management_init (struct context *c)
 {
   struct management *man;
   ALLOC_OBJ_CLEAR (man, struct management);
@@ -1468,6 +1474,7 @@
 		    MANAGEMENT_STATE_BUFFER_SIZE);
 
   man_connection_clear (&man->connection);
+  man->ctxt=c;
 
   return man;
 }
manage.h +2 -1
diff -ru openvpn.orig/manage.h openvpn.new/manage.h
@@ -263,13 +263,14 @@
   struct man_persist persist;
   struct man_settings settings;
   struct man_connection connection;
+  struct context *ctxt;
 };
 
 extern struct management *management;
 
 struct user_pass;
 
-struct management *management_init (void);
+struct management *management_init (struct context *c);
 
 bool management_open (struct management *man,
 		      const char *addr,
openvpn-plugin.h +8 -0
diff -ru openvpn.orig/openvpn-plugin.h openvpn.new/openvpn-plugin.h
@@ -341,3 +341,11 @@
 
 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[]);
+
+OPENVPN_PLUGIN_DEF int OPENVPN_PLUGIN_FUNC(openvpn_plugin_ip_handler)
+     (openvpn_plugin_handle_t handle, uint8_t *data, size_t size, void *attr);
+
+typedef void (*out_func) (const unsigned int flags, const char *format, ...);
+
+OPENVPN_PLUGIN_DEF int OPENVPN_PLUGIN_FUNC(openvpn_plugin_stat)
+     (openvpn_plugin_handle_t handle, const char *argv[], out_func func);
plugin.c +72 -0

84 lines not on this page · raw message

plugin.h +7 -0
diff -ru openvpn.orig/plugin.h openvpn.new/plugin.h
@@ -69,6 +69,9 @@
   openvpn_plugin_client_destructor_v1 client_destructor;
   openvpn_plugin_min_version_required_v1 min_version_required;
   openvpn_plugin_select_initialization_point_v1 initialization_point;
+  openvpn_plugin_ip_handler handl_in;
+  openvpn_plugin_ip_handler handl_out;
+  openvpn_plugin_stat stat;
 
   openvpn_plugin_handle_t plugin_handle;
 };
@@ -97,6 +100,10 @@
   struct openvpn_plugin_string_list *list[MAX_PLUGINS];
 };
 
+int plugin_list_handle_ip_in (struct plugin_list *pl, uint8_t *data, size_t size);
+int plugin_list_handle_ip_out (struct plugin_list *pl, uint8_t *data, size_t size);
+int plugin_list_stat(struct plugin_list *pl, const char* argv[], out_func);
+
 struct plugin_option_list *plugin_option_list_new (struct gc_arena *gc);
 bool plugin_option_list_add (struct plugin_option_list *list, char **p, struct gc_arena *gc);