... so there's no need to remember what type of packet it is.
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
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;
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;
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;
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;
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;
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;
*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);
/****************************************************************************/
struct pkt {
- int type;
int len;
struct pkt *next;
unsigned char hdr[8];
/* 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);
#include "openconnect.h"
-#ifdef BSD
+#ifdef __OpenBSD__
#define TUN_HAS_AF_PREFIX 1
#endif
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;
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) {