mirror of
				https://gitea.osmocom.org/cellular-infrastructure/osmo-mgw.git
				synced 2025-10-31 03:53:54 +00:00 
			
		
		
		
	gtphub: add assertion to ensure expiry ordering.
Make 100% sure the user adds expiring_items in chronological order by asserting that a newly added expiry is >= the last expiry in the queue. Add llist_last() to facilitate. Sponsored-by: On-Waves ehi
This commit is contained in:
		| @@ -62,6 +62,10 @@ typedef int (*osmo_fd_cb_t)(struct osmo_fd *fd, unsigned int what); | |||||||
| #define llist_first(head, type, entry) \ | #define llist_first(head, type, entry) \ | ||||||
| 	llist_entry(__llist_first(head), type, entry) | 	llist_entry(__llist_first(head), type, entry) | ||||||
|  |  | ||||||
|  | #define __llist_last(head) (((head)->next == (head)) ? NULL : (head)->prev) | ||||||
|  | #define llist_last(head, type, entry) \ | ||||||
|  | 	llist_entry(__llist_last(head), type, entry) | ||||||
|  |  | ||||||
| /* TODO move GTP header stuff to openggsn/gtp/ ? See gtp_decaps*() */ | /* TODO move GTP header stuff to openggsn/gtp/ ? See gtp_decaps*() */ | ||||||
|  |  | ||||||
| enum gtp_rc { | enum gtp_rc { | ||||||
| @@ -564,6 +568,10 @@ void expiry_add(struct expiry *exq, struct expiring_item *item, time_t now) | |||||||
| { | { | ||||||
| 	item->expiry = now + exq->expiry_in_seconds; | 	item->expiry = now + exq->expiry_in_seconds; | ||||||
|  |  | ||||||
|  | 	OSMO_ASSERT(llist_empty(&exq->items) | ||||||
|  | 		    || (item->expiry | ||||||
|  | 			>= llist_last(&exq->items, struct expiring_item, entry)->expiry)); | ||||||
|  |  | ||||||
| 	/* Add/move to the tail to always sort by expiry, ascending. */ | 	/* Add/move to the tail to always sort by expiry, ascending. */ | ||||||
| 	llist_del(&item->entry); | 	llist_del(&item->entry); | ||||||
| 	llist_add_tail(&item->entry, &exq->items); | 	llist_add_tail(&item->entry, &exq->items); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user