From 52e7699273a3009fe4d91e608522401076922785 Mon Sep 17 00:00:00 2001
From: Guus Sliepen <guus@tinc-vpn.org>
Date: Fri, 22 Mar 2002 11:43:48 +0000
Subject: [PATCH] - Added support for jumbograms. - Remove tcpaddress from
 edges, it is not used at all. - Last bits of code to prevent looping
 requests.

---
 acconfig.h          |  3 +++
 configure.in        |  8 +++++++-
 src/edge.c          | 16 +++++++--------
 src/edge.h          |  4 ++--
 src/net.c           |  4 +++-
 src/net.h           | 14 +++++++++----
 src/net_setup.c     |  4 +++-
 src/protocol.c      | 10 ++++++---
 src/protocol.h      |  7 ++++++-
 src/protocol_auth.c | 13 ++++++------
 src/protocol_edge.c | 50 ++++++++++++++++++++++-----------------------
 11 files changed, 80 insertions(+), 53 deletions(-)

diff --git a/acconfig.h b/acconfig.h
index f13c3e4b..41fdb995 100644
--- a/acconfig.h
+++ b/acconfig.h
@@ -67,6 +67,9 @@
 /* Define to the location of if_tun.h */
 #undef LINUX_IF_TUN_H
 
+/* Define to 1 if support for jumbograms is enabled */
+#undef ENABLE_JUMBOGRAMS
+
 /* Define to 1 if checkpoint tracing is enabled */
 #undef ENABLE_TRACING
 
diff --git a/configure.in b/configure.in
index 7e16a066..2c1fa700 100644
--- a/configure.in
+++ b/configure.in
@@ -1,6 +1,6 @@
 dnl Process this file with autoconf to produce a configure script.
 
-dnl $Id: configure.in,v 1.13.2.42 2002/03/10 14:05:35 guus Exp $
+dnl $Id: configure.in,v 1.13.2.43 2002/03/22 11:43:46 guus Exp $
 
 AC_INIT(src/tincd.c)
 AM_INIT_AUTOMAKE(tinc, 1.0-cvs)
@@ -100,6 +100,12 @@ tinc_TUNTAP
 tinc_OPENSSL
 tinc_ZLIB
 
+dnl Check if support for jumbograms is requested 
+AC_ARG_ENABLE(jumbograms,
+  [  --enable-jumbograms     enable support for jumbograms (packets up to 9000 bytes)],
+  [ AC_DEFINE(ENABLE_JUMBOGRAMS) ]
+)
+
 dnl Check if checkpoint tracing has to be enabled
 AC_ARG_ENABLE(tracing,
   [  --enable-tracing        enable checkpoint tracing (debugging only)],
diff --git a/src/edge.c b/src/edge.c
index b834879e..f0337e1e 100644
--- a/src/edge.c
+++ b/src/edge.c
@@ -17,7 +17,7 @@
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-    $Id: edge.c,v 1.1.2.7 2002/02/18 16:25:16 guus Exp $
+    $Id: edge.c,v 1.1.2.8 2002/03/22 11:43:46 guus Exp $
 */
 
 #include "config.h"
@@ -197,17 +197,17 @@ cp
   for(node = edge_tree->head; node; node = node->next)
     {
       e = (edge_t *)node->data;
-      from_tcp = sockaddr2hostname(&e->from.tcpaddress);
+//      from_tcp = sockaddr2hostname(&e->from.tcpaddress);
       from_udp = sockaddr2hostname(&e->from.udpaddress);
-      to_tcp = sockaddr2hostname(&e->to.tcpaddress);
+//      to_tcp = sockaddr2hostname(&e->to.tcpaddress);
       to_udp = sockaddr2hostname(&e->to.udpaddress);
-      syslog(LOG_DEBUG, _(" %s tcp at %s udp at %s - %s tcp at %s udp at %s options %ld weight %d"),
-             e->from.node->name, from_tcp, from_udp,
-	     e->to.node->name, to_tcp, to_udp,
+      syslog(LOG_DEBUG, _(" %s at %s - %s at %s options %ld weight %d"),
+             e->from.node->name, from_udp,
+	     e->to.node->name, to_udp,
 	     e->options, e->weight);
-      free(from_tcp);
+//      free(from_tcp);
       free(from_udp);
-      free(to_tcp);	
+//      free(to_tcp);	
       free(to_udp);	
     }
 
diff --git a/src/edge.h b/src/edge.h
index e3fa078a..604082f8 100644
--- a/src/edge.h
+++ b/src/edge.h
@@ -17,7 +17,7 @@
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-    $Id: edge.h,v 1.1.2.6 2002/02/18 16:25:16 guus Exp $
+    $Id: edge.h,v 1.1.2.7 2002/03/22 11:43:46 guus Exp $
 */
 
 #ifndef __TINC_EDGE_H__
@@ -31,7 +31,7 @@
 
 typedef struct halfconnection_t {
   struct node_t *node;             /* node associated with this end of the connection */
-  sockaddr_t tcpaddress;           /* real (internet) ip on this end of the meta connection */
+//  sockaddr_t tcpaddress;           /* real (internet) ip on this end of the meta connection */
   sockaddr_t udpaddress;           /* real (internet) ip on this end of the vpn connection */
 } halfconnection_t;
 
diff --git a/src/net.c b/src/net.c
index 2b79263e..5fd38235 100644
--- a/src/net.c
+++ b/src/net.c
@@ -17,7 +17,7 @@
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-    $Id: net.c,v 1.35.4.164 2002/03/18 22:47:20 guus Exp $
+    $Id: net.c,v 1.35.4.165 2002/03/22 11:43:46 guus Exp $
 */
 
 #include "config.h"
@@ -405,6 +405,8 @@ cp
           if(routing_mode== RMODE_SWITCH)
 	    age_mac();
 
+          age_past_requests();
+
           /* Should we regenerate our key? */
 
           if(keyexpires < now)
diff --git a/src/net.h b/src/net.h
index a5765762..f1493eb1 100644
--- a/src/net.h
+++ b/src/net.h
@@ -17,7 +17,7 @@
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-    $Id: net.h,v 1.9.4.47 2002/03/18 22:47:20 guus Exp $
+    $Id: net.h,v 1.9.4.48 2002/03/22 11:43:48 guus Exp $
 */
 
 #ifndef __TINC_NET_H__
@@ -30,10 +30,16 @@
 
 #include "config.h"
 
-#define MTU 1514     /* 1500 bytes payload + 14 bytes ethernet header */
-#define MAXSIZE 1600 /* MTU + header (seqno) and trailer (CBC padding and HMAC) */
+#ifdef ENABLE_JUMBOGRAMS
+ #define MTU 9014        /* 9000 bytes payload + 14 bytes ethernet header */
+ #define MAXSIZE 9100    /* MTU + header (seqno) and trailer (CBC padding and HMAC) */
+ #define MAXBUFSIZE 9100 /* Must support TCP packets of length 9000. */
+#else
+ #define MTU 1514        /* 1500 bytes payload + 14 bytes ethernet header */
+ #define MAXSIZE 1600    /* MTU + header (seqno) and trailer (CBC padding and HMAC) */
+ #define MAXBUFSIZE 2100 /* Quite large but needed for support of keys up to 8192 bits. */
+#endif
 
-#define MAXBUFSIZE 2048 /* Probably way too much, but it must fit every possible request. */
 #define MAXSOCKETS 128 /* Overkill... */
 
 typedef struct mac_t
diff --git a/src/net_setup.c b/src/net_setup.c
index f4c9e534..376d5a7e 100644
--- a/src/net_setup.c
+++ b/src/net_setup.c
@@ -17,7 +17,7 @@
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-    $Id: net_setup.c,v 1.1.2.11 2002/03/18 22:47:20 guus Exp $
+    $Id: net_setup.c,v 1.1.2.12 2002/03/22 11:43:48 guus Exp $
 */
 
 #include "config.h"
@@ -529,6 +529,7 @@ cp
   init_nodes();
   init_edges();
   init_events();
+  init_requests();
 
   if(get_config_int(lookup_config(config_tree, "PingTimeout"), &pingtimeout))
     {
@@ -581,6 +582,7 @@ cp
       close(listen_socket[i].udp);
     }
 
+  exit_requests();
   exit_events();
   exit_edges();
   exit_subnets();
diff --git a/src/protocol.c b/src/protocol.c
index 4e63728b..9125cf6e 100644
--- a/src/protocol.c
+++ b/src/protocol.c
@@ -17,7 +17,7 @@
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-    $Id: protocol.c,v 1.28.4.124 2002/03/21 23:11:53 guus Exp $
+    $Id: protocol.c,v 1.28.4.125 2002/03/22 11:43:48 guus Exp $
 */
 
 #include "config.h"
@@ -159,7 +159,7 @@ cp
 cp
 }
 
-void exit_request(void)
+void exit_requests(void)
 {
 cp
   avl_delete_tree(past_request_tree);
@@ -173,7 +173,11 @@ cp
   p.request = request;
 
   if(avl_search(past_request_tree, &p))
-    return 1;
+    {
+      if(debug_lvl >= DEBUG_SCARY_THINGS)
+        syslog(LOG_DEBUG, _("Already seen request"));
+      return 1;
+    }
   else
     {
       new = (past_request_t *)xmalloc(sizeof(*new));
diff --git a/src/protocol.h b/src/protocol.h
index 258642c1..a4e480a0 100644
--- a/src/protocol.h
+++ b/src/protocol.h
@@ -17,7 +17,7 @@
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-    $Id: protocol.h,v 1.5.4.28 2002/03/21 23:11:53 guus Exp $
+    $Id: protocol.h,v 1.5.4.29 2002/03/22 11:43:48 guus Exp $
 */
 
 #ifndef __TINC_PROTOCOL_H__
@@ -64,6 +64,11 @@ extern int send_request(connection_t*, const char*, ...);
 extern int receive_request(connection_t *);
 extern int check_id(char *);
 
+extern void init_requests(void);
+extern void exit_requests(void);
+extern int seen_request(char *);
+extern void age_past_requests(void);
+
 /* Requests */
 
 extern int send_id(connection_t *);
diff --git a/src/protocol_auth.c b/src/protocol_auth.c
index e37d7671..92e076a8 100644
--- a/src/protocol_auth.c
+++ b/src/protocol_auth.c
@@ -17,7 +17,7 @@
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-    $Id: protocol_auth.c,v 1.1.4.3 2002/02/20 19:25:09 guus Exp $
+    $Id: protocol_auth.c,v 1.1.4.4 2002/03/22 11:43:48 guus Exp $
 */
 
 #include "config.h"
@@ -515,8 +515,7 @@ void send_everything(connection_t *c)
 
 int ack_h(connection_t *c)
 {
-  char address[MAX_STRING_SIZE];
-  char port[MAX_STRING_SIZE];
+  char myaddress[MAX_STRING_SIZE];
   char hisport[MAX_STRING_SIZE];
   char *hisaddress, *dummy;
   int weight;
@@ -525,7 +524,7 @@ int ack_h(connection_t *c)
   connection_t *other;
   avl_node_t *node;
 cp
-  if(sscanf(c->buffer, "%*d "MAX_STRING" "MAX_STRING" "MAX_STRING" %d %d", hisport, address, port, &weight, &options) != 5)
+  if(sscanf(c->buffer, "%*d "MAX_STRING" "MAX_STRING" %d %d", hisport, myaddress, &weight, &options) != 4)
     {
        syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "ACK", c->name, c->hostname);
        return -1;
@@ -563,10 +562,10 @@ cp
   c->edge = new_edge();
 cp  
   c->edge->from.node = myself;
-  c->edge->from.tcpaddress = str2sockaddr(address, port);
-  c->edge->from.udpaddress = str2sockaddr(address, myport);
+//  c->edge->from.tcpaddress = str2sockaddr(address, port);
+  c->edge->from.udpaddress = str2sockaddr(myaddress, myport);
   c->edge->to.node = n;
-  c->edge->to.tcpaddress = c->address;
+//  c->edge->to.tcpaddress = c->address;
   sockaddr2str(&c->address, &hisaddress, &dummy);
   c->edge->to.udpaddress = str2sockaddr(hisaddress, hisport);
   free(hisaddress);
diff --git a/src/protocol_edge.c b/src/protocol_edge.c
index 4fd5354b..69a1e286 100644
--- a/src/protocol_edge.c
+++ b/src/protocol_edge.c
@@ -17,7 +17,7 @@
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-    $Id: protocol_edge.c,v 1.1.4.3 2002/03/21 23:11:53 guus Exp $
+    $Id: protocol_edge.c,v 1.1.4.4 2002/03/22 11:43:48 guus Exp $
 */
 
 #include "config.h"
@@ -48,23 +48,23 @@
 int send_add_edge(connection_t *c, edge_t *e)
 {
   int x;
-  char *from_tcpaddress, *from_tcpport, *from_udpaddress, *from_udpport;
-  char *to_tcpaddress, *to_tcpport, *to_udpaddress, *to_udpport;
+  char *from_udpaddress, *from_udpport;
+  char *to_udpaddress, *to_udpport;
 cp
-  sockaddr2str(&e->from.tcpaddress, &from_tcpaddress, &from_tcpport);
+//  sockaddr2str(&e->from.tcpaddress, &from_tcpaddress, &from_tcpport);
   sockaddr2str(&e->from.udpaddress, &from_udpaddress, &from_udpport);
-  sockaddr2str(&e->to.tcpaddress, &to_tcpaddress, &to_tcpport);
+//  sockaddr2str(&e->to.tcpaddress, &to_tcpaddress, &to_tcpport);
   sockaddr2str(&e->to.udpaddress, &to_udpaddress, &to_udpport);
-  x = send_request(c, "%d %lx %s %s %s %s %s %s %s %s %lx %d", ADD_EDGE, random(),
-                      e->from.node->name, from_tcpaddress, from_tcpport, from_udpport,
-		      e->to.node->name, to_tcpaddress, to_tcpport, to_udpport,
+  x = send_request(c, "%d %lx %s %s %s %s %s %s %lx %d", ADD_EDGE, random(),
+                      e->from.node->name, from_udpaddress, from_udpport,
+		      e->to.node->name, to_udpaddress, to_udpport,
 		      e->options, e->weight);
-  free(from_tcpaddress);
-  free(from_tcpport);
+//  free(from_tcpaddress);
+//  free(from_tcpport);
   free(from_udpaddress);
   free(from_udpport);
-  free(to_tcpaddress);
-  free(to_tcpport);
+//  free(to_tcpaddress);
+//  free(to_tcpport);
   free(to_udpaddress);
   free(to_udpport);
 cp
@@ -79,20 +79,20 @@ int add_edge_h(connection_t *c)
   char from_name[MAX_STRING_SIZE];
   char to_name[MAX_STRING_SIZE];
   char from_address[MAX_STRING_SIZE];
-  char from_tcpport[MAX_STRING_SIZE];
+//  char from_tcpport[MAX_STRING_SIZE];
   char from_udpport[MAX_STRING_SIZE];
   char to_address[MAX_STRING_SIZE];
-  char to_tcpport[MAX_STRING_SIZE];
+//  char to_tcpport[MAX_STRING_SIZE];
   char to_udpport[MAX_STRING_SIZE];
-  sockaddr_t from_tcpaddress, from_udpaddress;
-  sockaddr_t to_tcpaddress, to_udpaddress;
+  sockaddr_t from_udpaddress;
+  sockaddr_t to_udpaddress;
   long int options;
   int weight;
   avl_node_t *node;
 cp
-  if(sscanf(c->buffer, "%*d %*lx "MAX_STRING" "MAX_STRING" "MAX_STRING" "MAX_STRING" "MAX_STRING" "MAX_STRING" "MAX_STRING" "MAX_STRING" %lx %d",
-            from_name, from_address, from_tcpport, from_udpport,
-	    to_name, to_address, to_tcpport, to_udpport,
+  if(sscanf(c->buffer, "%*d %*lx "MAX_STRING" "MAX_STRING" "MAX_STRING" "MAX_STRING" "MAX_STRING" "MAX_STRING" %lx %d",
+            from_name, from_address, from_udpport,
+	    to_name, to_address, to_udpport,
 	    &options, &weight) != 10)
     {
        syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "ADD_EDGE", c->name, c->hostname);
@@ -138,9 +138,9 @@ cp
 
   /* Convert addresses */
   
-  from_tcpaddress = str2sockaddr(from_address, from_tcpport);
+//  from_tcpaddress = str2sockaddr(from_address, from_tcpport);
   from_udpaddress = str2sockaddr(from_address, from_udpport);
-  to_tcpaddress = str2sockaddr(to_address, to_tcpport);
+//  to_tcpaddress = str2sockaddr(to_address, to_tcpport);
   to_udpaddress = str2sockaddr(to_address, to_udpport);
 
   /* Check if edge already exists */
@@ -150,8 +150,8 @@ cp
   if(e)
   {
     if(e->weight != weight || e->options != options
-       || ((e->from.node == from) && (sockaddrcmp(&e->from.tcpaddress, &from_tcpaddress) || sockaddrcmp(&e->from.udpaddress, &from_udpaddress) || sockaddrcmp(&e->to.tcpaddress, &to_tcpaddress) || sockaddrcmp(&e->to.udpaddress, &to_udpaddress)))
-       || ((e->from.node == to) && (sockaddrcmp(&e->from.tcpaddress, &to_tcpaddress) || sockaddrcmp(&e->from.udpaddress, &to_udpaddress) || sockaddrcmp(&e->to.tcpaddress, &from_tcpaddress) || sockaddrcmp(&e->to.udpaddress, &from_udpaddress)))
+       || ((e->from.node == from) && (sockaddrcmp(&e->from.udpaddress, &from_udpaddress)|| sockaddrcmp(&e->to.udpaddress, &to_udpaddress)))
+       || ((e->from.node == to) && (sockaddrcmp(&e->from.udpaddress, &to_udpaddress) || sockaddrcmp(&e->to.udpaddress, &from_udpaddress)))
       )
     {
       if(from == myself || to == myself)
@@ -185,10 +185,10 @@ cp
 
   e = new_edge();
   e->from.node = from;
-  e->from.tcpaddress = from_tcpaddress;
+//  e->from.tcpaddress = from_tcpaddress;
   e->from.udpaddress = from_udpaddress;
   e->to.node = to;
-  e->to.tcpaddress = to_tcpaddress;
+//  e->to.tcpaddress = to_tcpaddress;
   e->to.udpaddress = to_udpaddress;
   e->options = options;
   e->weight = weight;
-- 
2.39.5