aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeels Hofmeyr <neels@hofmeyr.de>2022-06-17 23:52:05 +0200
committerNeels Hofmeyr <neels@hofmeyr.de>2022-07-20 12:38:30 +0200
commit2e526369589e64b0068164f415e1323a1fd3b802 (patch)
treeddf5c70b93b71574f5c9748f19f30d7e00859408
parent3f002b3d066f27cbf8454855457b5f6bd97fa004 (diff)
separate pfcp_queue_timer_cb() in req and resp
Having separate callbacks for request and response messages makes for an easier read. No functional change. This applies code review from https://gerrit.osmocom.org/c/osmo-upf/+/28244 Ic8d42e201b63064a71b40ca45a5a40e29941e8ac (osmo-upf.git) Related: SYS#5599 Change-Id: Ic8ab71f5efd4cf669689a0b075f9a52ce66bdd5d
-rw-r--r--src/libosmo-pfcp/pfcp_endpoint.c47
1 files changed, 30 insertions, 17 deletions
diff --git a/src/libosmo-pfcp/pfcp_endpoint.c b/src/libosmo-pfcp/pfcp_endpoint.c
index e044e75..32bcd0e 100644
--- a/src/libosmo-pfcp/pfcp_endpoint.c
+++ b/src/libosmo-pfcp/pfcp_endpoint.c
@@ -171,27 +171,38 @@ static bool pfcp_queue_retrans(struct osmo_pfcp_queue_entry *qe)
return true;
}
-/* T1 for a given queue entry has expired */
-static void pfcp_queue_timer_cb(void *data)
+/* T1 for a given sent_requests queue entry has expired */
+static void pfcp_queue_sent_req_timer_cb(void *data)
{
struct osmo_pfcp_queue_entry *qe = data;
bool keep;
- if (qe->m->is_response) {
- /* The response has waited in the queue for any retransmissions of its initiating request. Now that time
- * has passed and the response can be dropped from the queue. */
- keep = false;
- } else {
- /* The request is still here, which means it has not received a response from the remote side.
- * Retransmit the request. */
- keep = pfcp_queue_retrans(qe);
- }
+ /* qe->m is a request sent earlier */
+ OSMO_ASSERT(!qe->m->is_response);
+ /* The request is still here, which means it has not received a response from the remote side.
+ * Retransmit the request. */
+ keep = pfcp_queue_retrans(qe);
if (keep)
return;
+
+ /* Retransmission has elapsed. Notify resp_cb that receiving a response has failed. */
+ if (qe->m->ctx.resp_cb)
+ qe->m->ctx.resp_cb(qe->m, NULL, "PFCP request retransmissions elapsed, no response received");
/* Drop the queue entry. No more retransmissions. */
- if (!qe->m->is_response && qe->m->ctx.resp_cb)
- qe->m->ctx.resp_cb(qe->m, NULL, "PFCP retransmissions elapsed, no response received");
+ osmo_pfcp_queue_del(qe);
+}
+
+/* T1 for a given sent_responses queue entry has expired */
+static void pfcp_queue_sent_resp_timer_cb(void *data)
+{
+ struct osmo_pfcp_queue_entry *qe = data;
+
+ /* qe->m is a response sent earlier */
+ OSMO_ASSERT(qe->m->is_response);
+
+ /* The response has waited in the queue for any retransmissions of its initiating request. Now that time
+ * has passed and the response can be dropped from the queue. */
osmo_pfcp_queue_del(qe);
}
@@ -268,13 +279,15 @@ static int osmo_pfcp_endpoint_retrans_queue_add(struct osmo_pfcp_endpoint *endpo
/* Slight optimization: Add sent requests to the start of the list: we will usually receive a response shortly
* after sending a request, removing that entry from the queue quickly.
* Add sent responses to the end of the list: they will rarely be retransmitted at all. */
- if (m->is_response)
+ if (m->is_response) {
llist_add_tail(&qe->entry, &endpoint->sent_responses);
- else
- llist_add_tail(&qe->entry, &endpoint->sent_requests);
+ osmo_timer_setup(&qe->t1, pfcp_queue_sent_resp_timer_cb, qe);
+ } else {
+ llist_add(&qe->entry, &endpoint->sent_requests);
+ osmo_timer_setup(&qe->t1, pfcp_queue_sent_req_timer_cb, qe);
+ }
talloc_set_destructor(qe, osmo_pfcp_queue_destructor);
- osmo_timer_setup(&qe->t1, pfcp_queue_timer_cb, qe);
osmo_timer_schedule(&qe->t1, timeout/1000, (timeout % 1000) * 1000);
return 0;
}