Skip to contentSkip to conversation

dynamic push buffer

PATCH New Peter Warasin 1 participant 1 message Feb 3, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dynamic push buffer

hi guys

i run into the same problem as some of you, since i need the possibility to push way more routes to the clients. but currently the push buffer is limited which does not let you push more than about 15 routes.

so i wrote a patch which removes this limitation. please find the patch attached to this posting. it is agains 2.0.9, tested on linux as client/server.

the patch makes the push_list dynamic and sends it to the clients as chunks. in order not to break older clients this will happen only if the push buffer will be exceeded. however if exceeded, older clients can still connect, print out warnings and connect successfully but certainly don't apply the entire push list.

there is still a limitation. the openvpn routing table is still static and holds max 100 routes, so you will not be able to push more than 100 routes. that value could be easily increased and/or if necessary this could also made dynamic (however with deeper changes to the source).

please let me know what you think.
if you find it useful i will port the patch to the 2.1 branch

peter

Signature · 5 lines
:: e n d i a n
:: open source - open minds

:: peter warasin
:: http://www.endian.it   :: [email protected]...
options.c renamed from options.c.orig +63 -9
@@ -773,6 +773,7 @@
 show_p2mp_parms (const struct options *o)
 {
   struct gc_arena gc = gc_new ();
+  struct push_list_item *item = NULL;
 
 #if P2MP_SERVER
   msg (D_SHOW_PARMS, "  server_network = %s", print_in_addr_t (o->server_network, 0, &gc));
@@ -783,9 +784,12 @@
   msg (D_SHOW_PARMS, "  server_bridge_pool_end = %s", print_in_addr_t (o->server_bridge_pool_end, 0, &gc));
   if (o->push_list)
     {
-      const struct push_list *l = o->push_list;
-      const char *printable_push_list = l->options;
-      msg (D_SHOW_PARMS, "  push_list = '%s'", printable_push_list);
+      msg (D_SHOW_PARMS, "  push_list = {");
+      for (item = o->push_list->options; item != NULL; item = item->next)
+        {
+          msg (D_SHOW_PARMS, "    %s", item->item);
+        }
+      msg (D_SHOW_PARMS, "              }");
     }
   SHOW_BOOL (ifconfig_pool_defined);
   msg (D_SHOW_PARMS, "  ifconfig_pool_start = %s", print_in_addr_t (o->ifconfig_pool_start, 0, &gc));
@@ -828,6 +832,20 @@
 
 #endif /* ENABLE_DEBUG */
 
+
+void
+add_push_option(struct push_list *pl, struct gc_arena *gc, const char *option)
+{
+  struct push_list_item *item;
+
+  ALLOC_OBJ_CLEAR_GC (item, struct push_list_item, gc);
+  strncpy(item->item, option, sizeof(item->item));
+
+  item->next = pl->options;
+  pl->options = item;
+}
+
+
 #if P2MP_SERVER
 
 static void
@@ -901,14 +919,17 @@
 void
 options_detach (struct options *o)
 {
+  struct gc_arena gc = o->gc;
   gc_detach (&o->gc);
   o->routes = NULL;
 #if P2MP_SERVER
   if (o->push_list) /* clone push_list */
     {
       const struct push_list *old = o->push_list;
-      ALLOC_OBJ_GC (o->push_list, struct push_list, &o->gc);
-      strcpy (o->push_list->options, old->options);
+      struct push_list_item *item = NULL;
+      ALLOC_OBJ_CLEAR_GC (o->push_list, struct push_list, &o->gc);
+      for (item = old->options; item != NULL; item = item->next)
+        add_push_option(o->push_list, &o->gc, item->item);
     }
 #endif
 }
@@ -2520,24 +2541,57 @@
     }
 }
 
+void
+push_list_to_buf(struct push_list *pl, struct buffer *buf)	
+{
+  struct push_list_item *item;
+  bool first = true;
+
+  if (! pl)
+    return;
+
+  for (item = pl->options; item != NULL; item = item->next)
+    if (first)
+      buf_printf(buf, "%s", item->item);
+    else
+      buf_printf(buf, ",%s", item->item);
+}
+
+void
+store_pull_buffer (struct options *options,
+		   struct buffer *buf)
+{
+  char line[OPTION_PARM_SIZE];
+
+  if (options->pull_buffer == NULL)
+    ALLOC_OBJ_CLEAR_GC (options->pull_buffer, struct push_list, &options->gc);
+
+  while (buf_parse (buf, ',', line, sizeof (line)))
+    add_push_option(options->pull_buffer, &options->gc, line);
+
+  options->pull_buffer->chunks++;
+}
+
 bool
 apply_push_options (struct options *options,
-		    struct buffer *buf,
 		    unsigned int permission_mask,
 		    unsigned int *option_types_found,
 		    struct env_set *es)
 {
-  char line[OPTION_PARM_SIZE];
   int line_num = 0;
   const char *file = "[PUSH-OPTIONS]";
   const int msglevel = D_PUSH_ERRORS|M_OPTERR;
+  struct push_list_item *item = NULL;
 
-  while (buf_parse (buf, ',', line, sizeof (line)))
+  if (! options->pull_buffer)
+    return true;
+
+  for (item = options->pull_buffer->options; item != NULL; item = item->next)
     {
       char *p[MAX_PARMS];
       CLEAR (p);
       ++line_num;
-      if (parse_line (line, p, SIZE (p), file, line_num, msglevel, &options->gc))
+      if (parse_line (item->item, p, SIZE (p), file, line_num, msglevel, &options->gc))
 	{
 	  add_option (options, 0, p, file, line_num, 0, msglevel, permission_mask, option_types_found, es);
 	}
options.h renamed from options.h.orig +21 -3
@@ -59,11 +59,24 @@
 #if P2MP_SERVER
 /* parameters to be pushed to peer */
 
-#define MAX_PUSH_LIST_LEN TLS_CHANNEL_BUF_SIZE /* This parm is related to PLAINTEXT_BUFFER_SIZE in ssl.h */
+/* keep for backwards compatibility */
+#define MAX_PUSH_LIST_LEN TLS_CHANNEL_BUF_SIZE / 2 /* This parm is related to PLAINTEXT_BUFFER_SIZE in ssl.h */
+
+struct push_list_item {
+  /* one option per entry, items are like config file */
+  char item[OPTION_LINE_SIZE];
+  struct push_list_item *next;
+};
 
 struct push_list {
   /* newline delimited options, like config file */
-  char options[MAX_PUSH_LIST_LEN];
+  struct push_list_item *options;
+
+  /* points to the next to be sent item */
+  struct push_list_item *sent;
+
+  /* chunk counter */
+  int chunks;
 };
 #endif
 
@@ -290,6 +303,7 @@
   in_addr_t server_bridge_pool_end;
 
   struct push_list *push_list;
+  struct push_list *pull_buffer;
   bool ifconfig_pool_defined;
   in_addr_t ifconfig_pool_start;
   in_addr_t ifconfig_pool_end;
@@ -516,11 +530,15 @@
 void pre_pull_restore (struct options *o);
 
 bool apply_push_options (struct options *options,
-			 struct buffer *buf,
 			 unsigned int permission_mask,
 			 unsigned int *option_types_found,
 			 struct env_set *es);
 
+void add_push_option(struct push_list *pl, struct gc_arena *gc, const char *option);
+void push_list_to_buf(struct push_list *pl, struct buffer *buf);
+void store_pull_buffer (struct options *options,
+	  	        struct buffer *buf);
+
 bool is_persist_option (const struct options *o);
 bool is_stateful_restart (const struct options *o);
 
push.c renamed from push.c.orig +135 -75

277 lines not on this page · raw message

push.h renamed from push.h.orig +1 -0
@@ -34,6 +34,7 @@
 #define PUSH_MSG_REPLY            2
 #define PUSH_MSG_REQUEST_DEFERRED 3
 #define PUSH_MSG_AUTH_FAILURE     4
+#define PUSH_MSG_CHUNKED_REPLY    5
 
 void incoming_push_message (struct context *c,
 			    const struct buffer *buffer);

begin:vcard
fn:Peter Warasin
n:;Peter Warasin
org:Endian GmbH/Srl
adr:;;Pillhof 47;Frangart/Frangarto;BZ;I-39010;Italien/Italia email;internet:[email protected]...
tel;work:+39 0471 631763
tel;fax:+39 0471 631764
x-mozilla-html:FALSE
url:http://www.endian.it
version:2.1
end:vcard