Pau Espin Pedrol | f0829ff | 2019-06-20 16:58:55 +0200 | [diff] [blame] | 1 | /* |
Harald Welte | 632e843 | 2017-09-05 18:12:14 +0200 | [diff] [blame] | 2 | * OsmoGGSN - Gateway GPRS Support Node |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 3 | * Copyright (C) 2002 Mondru AB. |
Pau Espin Pedrol | f0829ff | 2019-06-20 16:58:55 +0200 | [diff] [blame] | 4 | * |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 5 | * 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 Pedrol | f0829ff | 2019-06-20 16:58:55 +0200 | [diff] [blame] | 9 | * |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 10 | */ |
| 11 | |
| 12 | /* |
| 13 | * Queue.c |
| 14 | * Reliable delivery of signalling messages |
| 15 | */ |
| 16 | |
| 17 | #ifndef _QUEUE_H |
| 18 | #define _QUEUE_H |
| 19 | |
Pau Espin Pedrol | 623c5b3 | 2019-08-16 13:20:09 +0200 | [diff] [blame] | 20 | #include <osmocom/core/linuxlist.h> |
| 21 | |
Pau Espin Pedrol | 8b90bce | 2019-06-20 17:06:13 +0200 | [diff] [blame] | 22 | #include "gtp.h" |
| 23 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 24 | #define QUEUE_DEBUG 0 /* Print debug information */ |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 25 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 26 | #define QUEUE_SIZE 1024 /* Size of retransmission queue */ |
| 27 | #define QUEUE_HASH_SIZE 65536 /* Size of hash table (2^16) */ |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 28 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 29 | struct qmsg_t { /* Holder for queued packets */ |
| 30 | int state; /* 0=empty, 1=full */ |
| 31 | uint16_t seq; /* The sequence number */ |
| 32 | uint8_t type; /* The type of packet */ |
| 33 | void *cbp; /* Application specific pointer */ |
| 34 | union gtp_packet p; /* The packet stored */ |
| 35 | int l; /* Length of the packet */ |
| 36 | int fd; /* Socket packet was sent to / received from */ |
| 37 | struct sockaddr_in peer; /* Address packet was sent to / received from */ |
| 38 | struct qmsg_t *seqnext; /* Pointer to next in sequence hash list */ |
| 39 | int next; /* Pointer to the next in queue. -1: Last */ |
| 40 | int prev; /* Pointer to the previous in queue. -1: First */ |
| 41 | int this; /* Pointer to myself */ |
| 42 | time_t timeout; /* When do we retransmit this packet? */ |
| 43 | int retrans; /* How many times did we retransmit this? */ |
Pau Espin Pedrol | 623c5b3 | 2019-08-16 13:20:09 +0200 | [diff] [blame] | 44 | struct llist_head entry; /* Listed with other qmsg_t belonging to a pdp_t->qmsg_list_req */ |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 45 | }; |
| 46 | |
| 47 | struct queue_t { |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 48 | struct qmsg_t qmsga[QUEUE_SIZE]; /* Array holding signalling messages */ |
| 49 | void *hashseq[QUEUE_HASH_SIZE]; /* Hash array */ |
| 50 | int next; /* Next location in queue to use */ |
| 51 | int first; /* First packet in queue (oldest timeout) */ |
| 52 | int last; /* Last packet in queue (youngest timeout) */ |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 53 | }; |
| 54 | |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 55 | /* Allocates and initialises new queue structure */ |
| 56 | int queue_new(struct queue_t **queue); |
| 57 | /* Deallocates queue structure */ |
| 58 | int queue_free(struct queue_t *queue); |
| 59 | /* Find a new queue element. Return EOF if allready full */ |
| 60 | int queue_newmsg(struct queue_t *queue, struct qmsg_t **qmsg, |
| 61 | struct sockaddr_in *peer, uint16_t seq); |
| 62 | /* Remove an element from the queue. */ |
| 63 | int queue_freemsg(struct queue_t *queue, struct qmsg_t *qmsg); |
| 64 | /* Move an element to the back of the queue */ |
| 65 | int queue_back(struct queue_t *queue, struct qmsg_t *qmsg); |
| 66 | /* Get the first element in the queue (oldest) */ |
| 67 | int queue_getfirst(struct queue_t *queue, struct qmsg_t **qmsg); |
| 68 | /* Get the element with a particular sequence number */ |
| 69 | int queue_seqget(struct queue_t *queue, struct qmsg_t **qmsg, |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 70 | struct sockaddr_in *peer, uint16_t seq); |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 71 | /* Free message based on sequence number */ |
| 72 | int queue_freemsg_seq(struct queue_t *queue, struct sockaddr_in *peer, |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 73 | uint16_t seq, uint8_t * type, void **cbp); |
jjako | 52c2414 | 2002-12-16 13:33:51 +0000 | [diff] [blame] | 74 | |
Harald Welte | bed35df | 2011-11-02 13:06:18 +0100 | [diff] [blame] | 75 | #endif /* !_QUEUE_H */ |