blob: 76cb7be96760448cdbf7bb41ff0ac32af577ea44 [file] [log] [blame]
Pau Espin Pedrolf0829ff2019-06-20 16:58:55 +02001/*
Harald Welte632e8432017-09-05 18:12:14 +02002 * OsmoGGSN - Gateway GPRS Support Node
jjako52c24142002-12-16 13:33:51 +00003 * Copyright (C) 2002 Mondru AB.
Pau Espin Pedrolf0829ff2019-06-20 16:58:55 +02004 *
jjako52c24142002-12-16 13:33:51 +00005 * The contents of this file may be used under the terms of the GNU
6 * General Public License Version 2, provided that the above copyright
7 * notice and this permission notice is included in all copies or
8 * substantial portions of the software.
Pau Espin Pedrolf0829ff2019-06-20 16:58:55 +02009 *
jjako52c24142002-12-16 13:33:51 +000010 */
11
12/*
13 * Queue.c
14 * Reliable delivery of signalling messages
15 */
16
17#ifndef _QUEUE_H
18#define _QUEUE_H
19
Pau Espin Pedrol8b90bce2019-06-20 17:06:13 +020020#include "gtp.h"
21
Harald Weltebed35df2011-11-02 13:06:18 +010022#define QUEUE_DEBUG 0 /* Print debug information */
jjako52c24142002-12-16 13:33:51 +000023
Harald Weltebed35df2011-11-02 13:06:18 +010024#define QUEUE_SIZE 1024 /* Size of retransmission queue */
25#define QUEUE_HASH_SIZE 65536 /* Size of hash table (2^16) */
jjako52c24142002-12-16 13:33:51 +000026
Harald Weltebed35df2011-11-02 13:06:18 +010027struct qmsg_t { /* Holder for queued packets */
28 int state; /* 0=empty, 1=full */
29 uint16_t seq; /* The sequence number */
30 uint8_t type; /* The type of packet */
31 void *cbp; /* Application specific pointer */
32 union gtp_packet p; /* The packet stored */
33 int l; /* Length of the packet */
34 int fd; /* Socket packet was sent to / received from */
35 struct sockaddr_in peer; /* Address packet was sent to / received from */
36 struct qmsg_t *seqnext; /* Pointer to next in sequence hash list */
37 int next; /* Pointer to the next in queue. -1: Last */
38 int prev; /* Pointer to the previous in queue. -1: First */
39 int this; /* Pointer to myself */
40 time_t timeout; /* When do we retransmit this packet? */
41 int retrans; /* How many times did we retransmit this? */
jjako52c24142002-12-16 13:33:51 +000042};
43
44struct queue_t {
Harald Weltebed35df2011-11-02 13:06:18 +010045 struct qmsg_t qmsga[QUEUE_SIZE]; /* Array holding signalling messages */
46 void *hashseq[QUEUE_HASH_SIZE]; /* Hash array */
47 int next; /* Next location in queue to use */
48 int first; /* First packet in queue (oldest timeout) */
49 int last; /* Last packet in queue (youngest timeout) */
jjako52c24142002-12-16 13:33:51 +000050};
51
jjako52c24142002-12-16 13:33:51 +000052/* Allocates and initialises new queue structure */
53int queue_new(struct queue_t **queue);
54/* Deallocates queue structure */
55int queue_free(struct queue_t *queue);
56/* Find a new queue element. Return EOF if allready full */
57int queue_newmsg(struct queue_t *queue, struct qmsg_t **qmsg,
58 struct sockaddr_in *peer, uint16_t seq);
59/* Remove an element from the queue. */
60int queue_freemsg(struct queue_t *queue, struct qmsg_t *qmsg);
61/* Move an element to the back of the queue */
62int queue_back(struct queue_t *queue, struct qmsg_t *qmsg);
63/* Get the first element in the queue (oldest) */
64int queue_getfirst(struct queue_t *queue, struct qmsg_t **qmsg);
65/* Get the element with a particular sequence number */
66int queue_seqget(struct queue_t *queue, struct qmsg_t **qmsg,
Harald Weltebed35df2011-11-02 13:06:18 +010067 struct sockaddr_in *peer, uint16_t seq);
jjako52c24142002-12-16 13:33:51 +000068/* Free message based on sequence number */
69int queue_freemsg_seq(struct queue_t *queue, struct sockaddr_in *peer,
Harald Weltebed35df2011-11-02 13:06:18 +010070 uint16_t seq, uint8_t * type, void **cbp);
jjako52c24142002-12-16 13:33:51 +000071
Harald Weltebed35df2011-11-02 13:06:18 +010072#endif /* !_QUEUE_H */