Packet queues fixed. They caused the trouble when resending keys.
This commit is contained in:
parent
04db888b1a
commit
5b72422857
2 changed files with 57 additions and 22 deletions
78
src/net.c
78
src/net.c
|
@ -152,7 +152,7 @@ cp
|
||||||
*/
|
*/
|
||||||
void add_queue(packet_queue_t **q, void *packet, size_t s)
|
void add_queue(packet_queue_t **q, void *packet, size_t s)
|
||||||
{
|
{
|
||||||
queue_element_t *e, *p;
|
queue_element_t *e;
|
||||||
cp
|
cp
|
||||||
if(debug_lvl > 3)
|
if(debug_lvl > 3)
|
||||||
syslog(LOG_DEBUG, "packet to queue: %d", s);
|
syslog(LOG_DEBUG, "packet to queue: %d", s);
|
||||||
|
@ -160,21 +160,65 @@ cp
|
||||||
e = xmalloc(sizeof(queue_element_t));
|
e = xmalloc(sizeof(queue_element_t));
|
||||||
e->packet = xmalloc(s);
|
e->packet = xmalloc(s);
|
||||||
memcpy(e->packet, packet, s);
|
memcpy(e->packet, packet, s);
|
||||||
|
|
||||||
if(!*q)
|
if(!*q)
|
||||||
{
|
{
|
||||||
*q = xmalloc(sizeof(packet_queue_t));
|
*q = xmalloc(sizeof(packet_queue_t));
|
||||||
(*q)->head = (*q)->tail = NULL;
|
(*q)->head = (*q)->tail = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
e->next = NULL;
|
e->next = NULL; /* We insert at the tail */
|
||||||
|
|
||||||
if((*q)->tail != NULL)
|
if((*q)->tail) /* Do we have a tail? */
|
||||||
(*q)->tail->next = e;
|
{
|
||||||
|
(*q)->tail->next = e;
|
||||||
|
e->prev = (*q)->tail;
|
||||||
|
}
|
||||||
|
else /* No tail -> no head too */
|
||||||
|
{
|
||||||
|
(*q)->head = e;
|
||||||
|
e->prev = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
(*q)->tail = e;
|
(*q)->tail = e;
|
||||||
|
cp
|
||||||
|
}
|
||||||
|
|
||||||
if((*q)->head == NULL)
|
/* Remove a queue element */
|
||||||
(*q)->head = e;
|
void del_queue(packet_queue_t **q, packet_element_t *e)
|
||||||
|
{
|
||||||
|
queue_element_t *p, *n;
|
||||||
|
cp
|
||||||
|
free(e->packet);
|
||||||
|
|
||||||
|
if(e->next) /* There is a successor, so we are not tail */
|
||||||
|
{
|
||||||
|
if(e->prev) /* There is a predecessor, so we are not head */
|
||||||
|
{
|
||||||
|
e->next->prev = e->prev;
|
||||||
|
e->prev->next = e->next;
|
||||||
|
}
|
||||||
|
else /* We are head */
|
||||||
|
{
|
||||||
|
e->next->prev = NULL;
|
||||||
|
(*q)->head = e->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else /* We are tail (or all alone!) */
|
||||||
|
{
|
||||||
|
if(e->prev) /* We are not alone :) */
|
||||||
|
{
|
||||||
|
e->prev->next = NULL;
|
||||||
|
(*q)->tail = e->prev;
|
||||||
|
}
|
||||||
|
else /* Adieu */
|
||||||
|
{
|
||||||
|
free(*q);
|
||||||
|
*q = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
free(e);
|
||||||
cp
|
cp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,28 +227,18 @@ cp
|
||||||
each packet, and removing it when that
|
each packet, and removing it when that
|
||||||
returned a zero exit code
|
returned a zero exit code
|
||||||
*/
|
*/
|
||||||
void flush_queue(conn_list_t *cl, packet_queue_t *pq,
|
void flush_queue(conn_list_t *cl, packet_queue_t **pq,
|
||||||
int (*function)(conn_list_t*,void*))
|
int (*function)(conn_list_t*,void*))
|
||||||
{
|
{
|
||||||
queue_element_t *p, *prev = NULL, *next = NULL;
|
queue_element_t *p, *prev = NULL, *next = NULL;
|
||||||
cp
|
cp
|
||||||
for(p = pq->head; p != NULL; )
|
for(p = (*pq)->head; p != NULL; )
|
||||||
{
|
{
|
||||||
next = p->next;
|
next = p->next;
|
||||||
|
|
||||||
if(!function(cl, p->packet))
|
if(!function(cl, p->packet))
|
||||||
{
|
del_queue(pq, p);
|
||||||
if(prev)
|
|
||||||
prev->next = next;
|
|
||||||
else
|
|
||||||
pq->head = next;
|
|
||||||
|
|
||||||
free(p->packet);
|
|
||||||
free(p);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
prev = p;
|
|
||||||
|
|
||||||
p = next;
|
p = next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,7 +260,7 @@ cp
|
||||||
if(debug_lvl > 1)
|
if(debug_lvl > 1)
|
||||||
syslog(LOG_DEBUG, "Flushing send queue for " IP_ADDR_S,
|
syslog(LOG_DEBUG, "Flushing send queue for " IP_ADDR_S,
|
||||||
IP_ADDR_V(cl->vpn_ip));
|
IP_ADDR_V(cl->vpn_ip));
|
||||||
flush_queue(cl, cl->sq, xsend);
|
flush_queue(cl, &(cl->sq), xsend);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(cl->rq)
|
if(cl->rq)
|
||||||
|
@ -234,7 +268,7 @@ cp
|
||||||
if(debug_lvl > 1)
|
if(debug_lvl > 1)
|
||||||
syslog(LOG_DEBUG, "Flushing receive queue for " IP_ADDR_S,
|
syslog(LOG_DEBUG, "Flushing receive queue for " IP_ADDR_S,
|
||||||
IP_ADDR_V(cl->vpn_ip));
|
IP_ADDR_V(cl->vpn_ip));
|
||||||
flush_queue(cl, cl->rq, xrecv);
|
flush_queue(cl, &(cl->rq), xrecv);
|
||||||
}
|
}
|
||||||
cp
|
cp
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,6 +83,7 @@ typedef struct status_bits_t {
|
||||||
|
|
||||||
typedef struct queue_element_t {
|
typedef struct queue_element_t {
|
||||||
void *packet;
|
void *packet;
|
||||||
|
struct queue_element_t *prev;
|
||||||
struct queue_element_t *next;
|
struct queue_element_t *next;
|
||||||
} queue_element_t;
|
} queue_element_t;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue