Skip to content

Commit bd16af3

Browse files
authored
Make HEP capture buffer size configurable via bufsize= (#320)
The per-message HEP capture buffer was hardcoded to 16000 bytes in both the HEPv2 and HEPv3 builders, capping how much of a SIP message could be captured with no way to raise it. Add a `bufsize=` parameter to the HEP capture URI, stored on the transport master as `mr_capt_bufsize`. Both builders read the cap from the master; when `bufsize=` is omitted it defaults to `TPORT_CAPT_BUFSIZE_DEFAULT` (16000), preserving prior behavior. Accepted range is [2048, 65000] (the HEPv3 envelope length is a u16). Example: `udp:host:9060;hep=3;bufsize=32768`
1 parent 54981e1 commit bd16af3

2 files changed

Lines changed: 35 additions & 15 deletions

File tree

‎libsofia-sip-ua/tport/tport_internal.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ struct tport_master {
310310
tport_primary_t *mr_primaries; /**< List of primary contacts */
311311
unsigned mr_prot_ver; /* hep version */
312312
unsigned mr_agent_id; /* agent version */
313+
unsigned mr_capt_bufsize; /* per-message HEP capture buffer cap (bytes). */
313314

314315
tport_params_t mr_params[1];
315316

‎libsofia-sip-ua/tport/tport_logging.c‎

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@
4747

4848
#define TPORT_STAMP_SIZE 144
4949

50+
/** Default per-message HEP capture buffer cap in bytes,
51+
* used when no bufsize= parameter is given in TPORT_CAPT. */
52+
#define TPORT_CAPT_BUFSIZE_DEFAULT 16000
53+
5054
/**@var TPORT_LOG
5155
*
5256
* Environment variable determining if parsed message contents are logged.
@@ -201,13 +205,14 @@ int tport_open_log(tport_master_t *mr, tagi_t *tags)
201205

202206
snprintf(port, sizeof(port), "%d", iport);
203207

204-
/* default values for capture protocol and agent id */
208+
/* default values for capture protocol, agent id, and per-message buffer cap */
205209
mr->mr_prot_ver = 3;
206-
mr->mr_agent_id = 200;
207-
208-
/* get all params */
209-
while(p)
210-
{
210+
mr->mr_agent_id = 200;
211+
mr->mr_capt_bufsize = TPORT_CAPT_BUFSIZE_DEFAULT;
212+
213+
/* get all params */
214+
while(p)
215+
{
211216
/* check ; in the URL */
212217
if( (p = strchr(p+1, ';')) == 0 ) {
213218
break;
@@ -238,8 +243,20 @@ int tport_open_log(tport_master_t *mr, tagi_t *tags)
238243
return n;
239244
}
240245
}
246+
else if(strncmp(p, "bufsize=", 8) == 0) {
247+
unsigned bs;
248+
249+
p += 8;
250+
bs = (unsigned)atoi(p);
251+
/* HEP envelope length is u16; cap accordingly with headroom for chunks */
252+
if (bs < 2048 || bs > 65000) {
253+
su_log("invalid bufsize; must be in [2048, 65000]\n");
254+
return n;
255+
}
256+
mr->mr_capt_bufsize = bs;
257+
}
241258
else {
242-
su_log("unsupported capture param\n");
259+
su_log("unsupported capture param\n");
243260
return n;
244261
}
245262
}
@@ -480,8 +497,8 @@ int tport_capt_msg_hepv2 (tport_t const *self, msg_t *msg, size_t n,
480497
#endif
481498
#if SU_HAVE_IN6
482499
struct hep_ip6hdr hep_ip6header = {{{{0}}}};
483-
#endif
484-
int eth_frame_len = 16000;
500+
#endif
501+
unsigned capt_bufsize;
485502
size_t i, dst = 1;
486503
tport_master_t *mr;
487504

@@ -491,6 +508,7 @@ int tport_capt_msg_hepv2 (tport_t const *self, msg_t *msg, size_t n,
491508
su_self = self->tp_pri->pri_primary->tp_addr;
492509

493510
mr = self->tp_master;
511+
capt_bufsize = mr->mr_capt_bufsize;
494512
if (mr->mr_capt_src_addr) {
495513
/* override SRC address with configuration */
496514
su_self_ext = (void *)mr->mr_capt_src_addr->ai_addr;
@@ -506,7 +524,7 @@ int tport_capt_msg_hepv2 (tport_t const *self, msg_t *msg, size_t n,
506524
}
507525

508526
/*buffer for ethernet frame*/
509-
*buffer = (void*)malloc(eth_frame_len);
527+
*buffer = (void*)malloc(capt_bufsize);
510528

511529
/* VOIP Header */
512530
hep_header.hp_v = mr->mr_prot_ver;
@@ -548,7 +566,7 @@ int tport_capt_msg_hepv2 (tport_t const *self, msg_t *msg, size_t n,
548566
}
549567

550568
/* Copy hepheader */
551-
memset(*buffer, '\0', eth_frame_len);
569+
memset(*buffer, '\0', capt_bufsize);
552570
memcpy(*buffer, &hep_header, sizeof(struct hep_hdr));
553571
buflen = sizeof(struct hep_hdr);
554572

@@ -589,7 +607,7 @@ int tport_capt_msg_hepv2 (tport_t const *self, msg_t *msg, size_t n,
589607
if (len > n)
590608
len = n;
591609
/* if the packet too big for us */
592-
if((buflen + len) > eth_frame_len)
610+
if((buflen + len) > capt_bufsize)
593611
break;
594612

595613
memcpy(*buffer + buflen , (void*)iov[i].mv_base, len);
@@ -626,7 +644,7 @@ int tport_capt_msg_hepv3 (tport_t const *self, msg_t *msg, size_t n,
626644
hep_chunk_ip6_t src_ip6 = {{0}}, dst_ip6 = {{0}};
627645
#endif
628646

629-
int eth_frame_len = 16000;
647+
unsigned capt_bufsize;
630648
size_t i, dst = 1;
631649
tport_master_t *mr;
632650

@@ -636,6 +654,7 @@ int tport_capt_msg_hepv3 (tport_t const *self, msg_t *msg, size_t n,
636654
su_self = self->tp_pri->pri_primary->tp_addr;
637655

638656
mr = self->tp_master;
657+
capt_bufsize = mr->mr_capt_bufsize;
639658
if (mr->mr_capt_src_addr) {
640659
/* override SRC address with configuration */
641660
su_self_ext = (void *)mr->mr_capt_src_addr->ai_addr;
@@ -770,7 +789,7 @@ int tport_capt_msg_hepv3 (tport_t const *self, msg_t *msg, size_t n,
770789
for (i = 0; i < iovused && n > 0; i++) {
771790
size_t len = iov[i].mv_len;
772791
if (len > n) len = n;
773-
if((payload_len + len) > eth_frame_len) break;
792+
if((payload_len + len) > capt_bufsize) break;
774793
payload_len +=len;
775794
n -= len;
776795
}
@@ -827,7 +846,7 @@ int tport_capt_msg_hepv3 (tport_t const *self, msg_t *msg, size_t n,
827846
size_t len = iov[i].mv_len;
828847
if (len > n) len = n;
829848
/* if the packet too big for us */
830-
if((buflen + len) > eth_frame_len)
849+
if((buflen + len) > capt_bufsize)
831850
break;
832851

833852
memcpy(*buffer + buflen , (void*)iov[i].mv_base, len);

0 commit comments

Comments
 (0)