Kill packet type field; IPv6 and Legacy IP are carried identically
authorDavid Woodhouse <David.Woodhouse@intel.com>
Mon, 2 Nov 2009 09:54:51 +0000 (09:54 +0000)
committerDavid Woodhouse <David.Woodhouse@intel.com>
Mon, 2 Nov 2009 10:19:21 +0000 (10:19 +0000)
... so there's no need to remember what type of packet it is.

Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
cstp.c
dtls.c
mainloop.c
openconnect.h
tun.c

diff --git a/cstp.c b/cstp.c
index d03d5e1..ffa39bd 100644 (file)
--- a/cstp.c
+++ b/cstp.c
@@ -369,14 +369,13 @@ static int cstp_reconnect(struct openconnect_info *vpninfo)
        return 0;
 }
 
-static int inflate_and_queue_packet(struct openconnect_info *vpninfo, int type, void *buf, int len)
+static int inflate_and_queue_packet(struct openconnect_info *vpninfo, void *buf, int len)
 {
        struct pkt *new = malloc(sizeof(struct pkt) + vpninfo->mtu);
 
        if (!new)
                return -ENOMEM;
 
-       new->type = type;
        new->next = NULL;
 
        vpninfo->inflate_strm.next_in = buf;
@@ -461,7 +460,7 @@ int cstp_mainloop(struct openconnect_info *vpninfo, int *timeout)
                        vpninfo->progress(vpninfo, PRG_TRACE,
                                          "Received uncompressed data packet of %d bytes\n",
                                          payload_len);
-                       queue_new_packet(&vpninfo->incoming_queue, AF_INET, buf + 8,
+                       queue_new_packet(&vpninfo->incoming_queue, buf + 8,
                                         payload_len);
                        work_done = 1;
                        continue;
@@ -483,7 +482,7 @@ int cstp_mainloop(struct openconnect_info *vpninfo, int *timeout)
                                vpninfo->progress(vpninfo, PRG_ERR, "Compressed packet received in !deflate mode\n");
                                goto unknown_pkt;
                        }
-                       inflate_and_queue_packet(vpninfo, AF_INET, buf + 8, payload_len);
+                       inflate_and_queue_packet(vpninfo, buf + 8, payload_len);
                        work_done = 1;
                        continue;
 
@@ -617,10 +616,6 @@ int cstp_mainloop(struct openconnect_info *vpninfo, int *timeout)
                vpninfo->outgoing_queue = this->next;
                vpninfo->outgoing_qlen--;
 
-               /* FIXME: Don't know how to handle IPv6 yet */
-               if (this->type != AF_INET)
-                       continue;
-
                if (vpninfo->deflate) {
                        unsigned char *adler;
                        int ret;
diff --git a/dtls.c b/dtls.c
index 99274e0..57a3faf 100644 (file)
--- a/dtls.c
+++ b/dtls.c
@@ -390,7 +390,7 @@ int dtls_mainloop(struct openconnect_info *vpninfo, int *timeout)
 
                switch(buf[0]) {
                case AC_PKT_DATA:
-                       queue_new_packet(&vpninfo->incoming_queue, AF_INET, buf+1, len-1);
+                       queue_new_packet(&vpninfo->incoming_queue, buf+1, len-1);
                        work_done = 1;
                        break;
 
@@ -483,10 +483,6 @@ int dtls_mainloop(struct openconnect_info *vpninfo, int *timeout)
                vpninfo->outgoing_queue = this->next;
                vpninfo->outgoing_qlen--;
 
-               /* FIXME: Don't know how to handle IPv6 yet */
-               if (this->type != AF_INET)
-                       continue;
-
                /* One byte of header */
                this->hdr[7] = AC_PKT_DATA;
 
index 2890d5b..e4ba02d 100644 (file)
@@ -44,13 +44,12 @@ void queue_packet(struct pkt **q, struct pkt *new)
        *q = new;
 }
 
-int queue_new_packet(struct pkt **q, int type, void *buf, int len)
+int queue_new_packet(struct pkt **q, void *buf, int len)
 {
        struct pkt *new = malloc(sizeof(struct pkt) + len);
        if (!new)
                return -ENOMEM;
 
-       new->type = type;
        new->len = len;
        new->next = NULL;
        memcpy(new->data, buf, len);
index 9755afb..7fe2169 100644 (file)
@@ -85,7 +85,6 @@ struct oc_auth_form {
 /****************************************************************************/
 
 struct pkt {
-       int type;
        int len;
        struct pkt *next;
        unsigned char hdr[8];
@@ -295,7 +294,7 @@ int passphrase_from_fsid(struct openconnect_info *vpninfo);
 /* mainloop.c */
 int vpn_add_pollfd(struct openconnect_info *vpninfo, int fd, short events);
 int vpn_mainloop(struct openconnect_info *vpninfo);
-int queue_new_packet(struct pkt **q, int type, void *buf, int len);
+int queue_new_packet(struct pkt **q, void *buf, int len);
 void queue_packet(struct pkt **q, struct pkt *new);
 int keepalive_action(struct keepalive_info *ka, int *timeout);
 int ka_stalled_dpd_time(struct keepalive_info *ka, int *timeout);
diff --git a/tun.c b/tun.c
index a826444..dc913d5 100644 (file)
--- a/tun.c
+++ b/tun.c
@@ -41,7 +41,7 @@
 
 #include "openconnect.h"
 
-#ifdef BSD
+#ifdef __OpenBSD__
 #define TUN_HAS_AF_PREFIX 1
 #endif
 
@@ -357,24 +357,12 @@ int tun_mainloop(struct openconnect_info *vpninfo, int *timeout)
        if (FD_ISSET(vpninfo->tun_fd, &vpninfo->select_rfds)) {
                while ((len = read(vpninfo->tun_fd, buf, sizeof(buf))) > 0) {
                        unsigned char *pkt = buf;
-                       int type;
-#ifdef __OpenBSD__
-                       type = ntohl(*(int *)buf);
-                       if (type != AF_INET && type != AF_INET6)
-                               continue;
+#ifdef TUN_HAS_AF_PREFIX
                        pkt += 4;
                        len -= 4;
-#else
-                       struct ip *iph = (void *)buf;
-                       if (iph->ip_v == 6)
-                               type = AF_INET6;
-                       else if (iph->ip_v == 4)
-                               type = AF_INET;
-                       else
-                               continue;
 #endif
-                       if (queue_new_packet(&vpninfo->outgoing_queue, type,
-                                            pkt, len))
+                       if (queue_new_packet(&vpninfo->outgoing_queue, pkt,
+                                            len))
                                break;
 
                        work_done = 1;
@@ -396,13 +384,30 @@ int tun_mainloop(struct openconnect_info *vpninfo, int *timeout)
                unsigned char *data = this->data;
                int len = this->len;
 
-               vpninfo->incoming_queue = this->next;
-
-#ifdef __OpenBSD__
+#ifdef TUN_HAS_AF_PREFIX
+               struct ip *iph = (void *)data;
+               int type;
+
+               if (iph->ip_v == 6)
+                       type = AF_INET6;
+               else if (iph->ip_v == 4)
+                       type = AF_INET;
+               else {
+                       static int complained = 0;
+                       if (!complained) {
+                               complained = 1;
+                               vpninfo->progress(vpninfo, PRG_ERR,
+                                                 "Unknown packet (len %d) received: %02x %02x %02x %02x...\n",
+                                                 len, data[0], data[1], data[2], data[3]);
+                       }
+                       free(this);
+                       continue;
+               }
                data -= 4;
                len += 4;
-               *(int *)data = htonl(this->type);
+               *(int *)data = htonl(type);
 #endif
+               vpninfo->incoming_queue = this->next;
 
                if (write(vpninfo->tun_fd, data, len) < 0 &&
                    errno == ENOTCONN) {