From 7d1467c02583676dcf3baa2310a7b8bc33ebad6d Mon Sep 17 00:00:00 2001 From: Maximilian Fridrich Date: Tue, 27 Feb 2024 14:42:14 +0100 Subject: [PATCH] sipsess/listen: improve glare handling (#1071) This implements the UAS behavior exactly as RFC 3261 section 14.2 states that it MUST be. --- src/sipsess/listen.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/sipsess/listen.c b/src/sipsess/listen.c index f50e37289..f41b07345 100644 --- a/src/sipsess/listen.c +++ b/src/sipsess/listen.c @@ -15,6 +15,7 @@ #include #include #include +#include #include "sipsess.h" @@ -250,11 +251,18 @@ static void target_refresh_handler(struct sipsess_sock *sock, if ((is_invite && sess->st) || (sdp && sess->neg_state == SDP_NEG_LOCAL_OFFER)) { - (void)sip_treplyf(NULL, NULL, sip, msg, false, - 500, "Server Internal Error", - "Retry-After: 5\r\n" - "Content-Length: 0\r\n" - "\r\n"); + if (!sess->established) { + uint32_t wait = rand_u16() % 11; + (void)sip_treplyf(NULL, NULL, sip, msg, false, + 500, "Server Internal Error", + "Retry-After: %u\r\n" + "Content-Length: 0\r\n" + "\r\n", wait); + } + else { + (void)sip_treply(NULL, sip, msg, 491, + "Request Pending"); + } return; }