Skip to content

Commit

Permalink
use explicit ID if requested
Browse files Browse the repository at this point in the history
  • Loading branch information
alandekok committed Jun 14, 2024
1 parent c844539 commit 62c4361
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/lib/packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,8 @@ bool fr_packet_list_id_alloc(fr_packet_list_t *pl, int proto,
*/

id = fd = -1;
if (request->id >= 0 && request->id < 256)
id = request->id;
start_i = fr_rand() & SOCKOFFSET_MASK;

#define ID_i ((i + start_i) & SOCKOFFSET_MASK)
Expand Down Expand Up @@ -831,6 +833,18 @@ bool fr_packet_list_id_alloc(fr_packet_list_t *pl, int proto,
* Otherwise, this socket is OK to use.
*/

/*
* An explicit ID was requested
*/

if (id != -1) {
if ((ps->id[(id >> 3) & 0x1f] & (1 << (id & 0x07))) != 0) continue;

ps->id[(id >> 3) & 0x1f] |= (1 << (id & 0x07));
fd = i;
break;
}

/*
* Look for a free Id, starting from a random number.
*/
Expand Down

0 comments on commit 62c4361

Please sign in to comment.