int vpn_add_pollfd(struct anyconnect_info *vpninfo, int fd, short events);
int vpn_mainloop(struct anyconnect_info *vpninfo);
int queue_new_packet(struct pkt **q, int type, void *buf, int len);
+void queue_packet(struct pkt **q, struct pkt *new);
int inflate_and_queue_packet(struct anyconnect_info *vpninfo, int type, void *buf, int len);
#include "anyconnect.h"
-int inflate_and_queue_packet(struct anyconnect_info *vpninfo, int type, void *buf, int len)
+void queue_packet(struct pkt **q, struct pkt *new)
{
- struct pkt **q = &vpninfo->incoming_queue;
-
while (*q)
q = &(*q)->next;
- *q = malloc(sizeof(struct pkt) + vpninfo->mtu);
- if (!*q)
+ new->next = NULL;
+ *q = new;
+}
+
+int inflate_and_queue_packet(struct anyconnect_info *vpninfo, int type, void *buf, int len)
+{
+ struct pkt *new = malloc(sizeof(struct pkt) + vpninfo->mtu);
+
+ if (!new)
return -ENOMEM;
- (*q)->type = type;
- (*q)->next = NULL;
+ new->type = type;
+ new->next = NULL;
vpninfo->inflate_strm.next_in = buf;
vpninfo->inflate_strm.avail_in = len - 4;
- vpninfo->inflate_strm.next_out = (*q)->data;
+ vpninfo->inflate_strm.next_out = new->data;
vpninfo->inflate_strm.avail_out = vpninfo->mtu;
vpninfo->inflate_strm.total_out = 0;
if (inflate(&vpninfo->inflate_strm, Z_SYNC_FLUSH)) {
fprintf(stderr, "inflate failed\n");
- free(*q);
- *q = NULL;
+ free(new);
return -EINVAL;
}
- (*q)->len = vpninfo->inflate_strm.total_out;
+ new->len = vpninfo->inflate_strm.total_out;
vpninfo->inflate_adler32 = adler32(vpninfo->inflate_adler32,
- (*q)->data, (*q)->len);
+ new->data, new->len);
if (vpninfo->inflate_adler32 != ntohl( *(uint32_t *)(buf + len - 4))) {
vpninfo->quit_reason = "Compression (inflate) adler32 failure";
}
+ queue_packet(&vpninfo->incoming_queue, new);
return 0;
}
int queue_new_packet(struct pkt **q, int type, void *buf, int len)
{
- while (*q)
- q = &(*q)->next;
-
- *q = malloc(sizeof(struct pkt) + len);
- if (!*q)
+ struct pkt *new = malloc(sizeof(struct pkt) + len);
+ if (!new)
return -ENOMEM;
- (*q)->type = type;
- (*q)->len = len;
- (*q)->next = NULL;
- memcpy((*q)->data, buf, len);
+ new->type = type;
+ new->len = len;
+ new->next = NULL;
+ memcpy(new->data, buf, len);
+ queue_packet(q, new);
return 0;
}