I've made some testing and found that filter_body() fails when body is something like "Content-Type:application/sdp\r\n\r\n".
If i use this correction to add a space the filter works correctly :
replace_body_all("Content-Type:application/sdp\r\n\r\n","Content-Type: application/sdp\r\n\r\n"); #Makes the changes to the message persistent, returns 1 if sucessful, 0 if it fails if(msg_apply_changes()) { xnotice("Kamailio_Log : reply_route : Changes to message applied"); }
I looked into the textops.c and found this line which i think might be the problem :
while (find_line_start("Content-Type: ", 14, &start, &len))
If more info is needed please let me know.
Cheers
Thanks for report and analysis. Can you try with master branch or the patch referenced above?
If fixes it, then I will backport.
Hi Daniel,
Thanks for the update.
I'm using kamailio 5.4 and i've copied the textops files from the link you provided and replaced the textops files. Made make clean and make all on the textops folder and got these warnings :
"[root@dev_sbc_a_vts01 textops]# make CC (gcc) [M textops.so] textops.o textops.c: In function ‘find_hdr_line_start’: textops.c:1614:2: warning: implicit declaration of function ‘parse_hname2_str’ [-Wimplicit-function-declaration] if(parse_hname2_str(&sname, &h1)==NULL) { ^ textops.c:1614:34: warning: comparison between pointer and integer [enabled by default] if(parse_hname2_str(&sname, &h1)==NULL) { ^ textops.c: In function ‘ki_remove_hf_idx’: textops.c:1815:34: warning: comparison between pointer and integer [enabled by default] if(parse_hname2_str(hname, &hfm)==NULL) { ^ textops.c: In function ‘ki_str_ifind’: textops.c:4457:2: warning: implicit declaration of function ‘str_casesearch’ [-Wimplicit-function-declaration] p = str_casesearch(txt, needle); ^ textops.c:4457:4: warning: assignment makes pointer from integer without a cast [enabled by default] p = str_casesearch(txt, needle); ^ CC (gcc) [M textops.so] api.o CC (gcc) [M textops.so] txt_var.o LD (gcc) [M textops.so] textops.so "
After that i've done the make all; make install . When restarting Kamailio i receive this error loading the module :
" ERROR: <core> [core/sr_module.c:512]: load_module(): could not open module </usr/local/kamailio-5.4/lib64/kamailio/modules/textops.so>: /usr/local/kamailio-5.4/lib64/kamailio/modules/textops"
Is only replacing the module enough or do i need to install the complete version?
Best Regards,
You need to backport functions from the core, the best is to try with master and see if works, then I can backport easily to 5.5. To older release series it may require more work to backport, first is better to confirm if works.
Hi Daniel,
Sorry for taking too long. I've tried the same scenario with master and with 5.4.1.
5.4.1 has the behaviour described previously.
On master i got some parsing errors on the packet when invoking filter_body("application/sdp") on a multipart body. I've attached a picture with the errors logged. If you want i can send you to packet too.
Cheers 
Can you copy&paste the logs, screenshots are not troubleshooting friendly with only text content? Then it is easy to copy it and search to see where in the code the logs are printed from. Size is also smaller, being friendlier for mobile connections.
Sorry.
This is my code for filtering :
"request_route {
xerr("Before filter_body"); if (filter_body("application/sdp")) { xerr("Filtered with sucess"); } else { xerr("Filtering failed");} "
The log is the following :
"2021-06-02T16:13:53.396443+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[2740]: ERROR: <script>: Before filter_body 2021-06-02T16:13:53.396677+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[2740]: ERROR: <core> [core/parser/parse_hname2.c:275]: parse_sip_header_name(): invalid end of header name for [--unique-bound] 2021-06-02T16:13:53.396886+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[2740]: ERROR: <core> [core/parser/parse_hname2.c:266]: parse_sip_header_name(): invalid header name for [pplication/sdp] 2021-06-02T16:13:53.397141+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[2740]: ERROR: <core> [core/parser/parse_hname2.c:236]: parse_sip_header_name(): invalid start of header name for [#015#012v=0#015#012o=- 184] 2021-06-02T16:13:53.397337+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[2740]: ERROR: <core> [core/parser/parse_hname2.c:266]: parse_sip_header_name(): invalid header name for [v=0#015#012o=- 18454] 2021-06-02T16:13:53.397527+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[2740]: ERROR: <core> [core/parser/parse_hname2.c:266]: parse_sip_header_name(): invalid header name for [o=- 1845407145] 2021-06-02T16:13:53.397716+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[2740]: ERROR: <core> [core/parser/parse_hname2.c:266]: parse_sip_header_name(): invalid header name for [s=-#015#012c=IN IP4 ] 2021-06-02T16:13:53.397914+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[2740]: ERROR: <core> [core/parser/parse_hname2.c:266]: parse_sip_header_name(): invalid header name for [c=IN IP4 212.1] 2021-06-02T16:13:53.398154+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[2740]: ERROR: <core> [core/parser/parse_hname2.c:266]: parse_sip_header_name(): invalid header name for [t=0 0#015#012m=audio] 2021-06-02T16:13:53.398346+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[2740]: ERROR: <core> [core/parser/parse_hname2.c:266]: parse_sip_header_name(): invalid header name for [m=audio 22138 ] 2021-06-02T16:13:53.398548+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[2740]: ERROR: <core> [core/parser/parse_hname2.c:266]: parse_sip_header_name(): invalid header name for [a=rtpmap:101 t] 2021-06-02T16:13:53.398813+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[2740]: ERROR: <core> [core/parser/parse_hname2.c:266]: parse_sip_header_name(): invalid header name for [a=rtpmap:96 CL] 2021-06-02T16:13:53.399037+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[2740]: ERROR: <core> [core/parser/parse_hname2.c:236]: parse_sip_header_name(): invalid start of header name for [#015#012--unique-bou] 2021-06-02T16:13:53.399230+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[2740]: ERROR: <core> [core/parser/parse_hname2.c:275]: parse_sip_header_name(): invalid end of header name for [--unique-bound] 2021-06-02T16:13:53.399428+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[2740]: ERROR: <core> [core/parser/parse_hname2.c:266]: parse_sip_header_name(): invalid header name for [pplication/ISU] 2021-06-02T16:13:53.399621+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[2740]: ERROR: <core> [core/parser/parse_hname2.c:275]: parse_sip_header_name(): invalid end of header name for [Content-Dispos] 2021-06-02T16:13:53.399815+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[2740]: ERROR: <core> [core/parser/parse_hname2.c:236]: parse_sip_header_name(): invalid start of header name for [#015#012#001] 2021-06-02T16:13:53.400028+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[2740]: ERROR: <core> [core/parser/parse_hname2.c:236]: parse_sip_header_name(): invalid start of header name for [#001] 2021-06-02T16:13:53.400234+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[2740]: ERROR: <core> [core/parser/parse_hname2.c:275]: parse_sip_header_name(): invalid end of header name for [--unique-bound] 2021-06-02T16:13:53.400427+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[2740]: ERROR: <script>: Filtering failed "
I've also attached the packet body :
"Message Body MIME Multipart Media Encapsulation, Type: multipart/mixed, Boundary: "unique-boundary-1" [Type: multipart/mixed] First boundary: --unique-boundary-1\r\n Encapsulated multipart part: (application/sdp) Content-Type:application/sdp\r\n\r\n Session Description Protocol Session Description Protocol Version (v): 0 Owner/Creator, Session Id (o): - 1845407145 1 IN IP4 1.1.1.1 Session Name (s): - Connection Information (c): IN IP4 1.1.1.1 Time Description, active time (t): 0 0 Media Description, name and address (m): audio 22138 RTP/AVP 8 0 18 3 13 101 96 Media Attribute (a): rtpmap:101 telephone-event/8000 Media Attribute (a): rtpmap:96 CLEARMODE/8000 Boundary: \r\n--unique-boundary-1\r\n Encapsulated multipart part: (application/isup) Content-Type:application/ISUP;base=itu-t92+;version=itu-t\r\n Content-Disposition:signal;handling=required\r\n\r\n ISDN User Part Message Type: Initial address (1) Nature of Connection Indicators : 0x0 Forward Call Indicators : 0x6001 Calling Party's category : 0xa (ordinary calling subscriber) Transmission medium requirement : 0 (speech) Called Party NumberCalled Party Number: 222222222 Pointer to start of optional part: 10 Parameter: (t=10, l=8) Calling party number: Calling party numberCalling Party Number: 333333333 Parameter: (t=192, l=9) Generic number: Generic numberGeneric Number: 333333333 End of optional parameters (0) Last boundary: \r\n--unique-boundary-1--\r\n"
If more info or testing is needed please let me know.
Can you try again with master branch version? I pushed two more commits.
I've tried with the new code and i get the same errors in the log :
2021-06-02T18:43:29.662320+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[21625]: ERROR: <script>: Before filter_body 2021-06-02T18:43:29.662548+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[21625]: ERROR: <core> [core/parser/parse_hname2.c:275]: parse_sip_header_name(): invalid end of header name for [--unique-bound] 2021-06-02T18:43:29.662733+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[21625]: ERROR: <core> [core/parser/parse_hname2.c:266]: parse_sip_header_name(): invalid header name for [pplication/sdp] 2021-06-02T18:43:29.662922+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[21625]: ERROR: <core> [core/parser/parse_hname2.c:236]: parse_sip_header_name(): invalid start of header name for [#015#012v=0#015#012o=- 184] 2021-06-02T18:43:29.663170+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[21625]: ERROR: <core> [core/parser/parse_hname2.c:266]: parse_sip_header_name(): invalid header name for [v=0#015#012o=- 18455] 2021-06-02T18:43:29.663358+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[21625]: ERROR: <core> [core/parser/parse_hname2.c:266]: parse_sip_header_name(): invalid header name for [o=- 1845520355] 2021-06-02T18:43:29.663535+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[21625]: ERROR: <core> [core/parser/parse_hname2.c:266]: parse_sip_header_name(): invalid header name for [s=-#015#012c=IN IP4 ] 2021-06-02T18:43:29.663709+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[21625]: ERROR: <core> [core/parser/parse_hname2.c:266]: parse_sip_header_name(): invalid header name for [c=IN IP4 212.1] 2021-06-02T18:43:29.663924+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[21625]: ERROR: <core> [core/parser/parse_hname2.c:266]: parse_sip_header_name(): invalid header name for [t=0 0#015#012m=audio] 2021-06-02T18:43:29.664153+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[21625]: ERROR: <core> [core/parser/parse_hname2.c:266]: parse_sip_header_name(): invalid header name for [m=audio 26376 ] 2021-06-02T18:43:29.664333+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[21625]: ERROR: <core> [core/parser/parse_hname2.c:266]: parse_sip_header_name(): invalid header name for [a=rtpmap:101 t] 2021-06-02T18:43:29.664538+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[21625]: ERROR: <core> [core/parser/parse_hname2.c:266]: parse_sip_header_name(): invalid header name for [a=rtpmap:96 CL] 2021-06-02T18:43:29.664718+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[21625]: ERROR: <core> [core/parser/parse_hname2.c:236]: parse_sip_header_name(): invalid start of header name for [#015#012--unique-bou] 2021-06-02T18:43:29.664897+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[21625]: ERROR: <core> [core/parser/parse_hname2.c:275]: parse_sip_header_name(): invalid end of header name for [--unique-bound] 2021-06-02T18:43:29.665119+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[21625]: ERROR: <core> [core/parser/parse_hname2.c:266]: parse_sip_header_name(): invalid header name for [pplication/ISU] 2021-06-02T18:43:29.665323+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[21625]: ERROR: <core> [core/parser/parse_hname2.c:275]: parse_sip_header_name(): invalid end of header name for [Content-Dispos] 2021-06-02T18:43:29.665607+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[21625]: ERROR: <core> [core/parser/parse_hname2.c:236]: parse_sip_header_name(): invalid start of header name for [#015#012#001] 2021-06-02T18:43:29.665864+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[21625]: ERROR: <core> [core/parser/parse_hname2.c:236]: parse_sip_header_name(): invalid start of header name for [#001] 2021-06-02T18:43:29.666135+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[21625]: ERROR: <core> [core/parser/parse_hname2.c:275]: parse_sip_header_name(): invalid end of header name for [--unique-bound] 2021-06-02T18:43:29.666341+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.4/sbin/kamailio[21625]: ERROR: <script>: Filtering failed
Can you give the output for:
``` /usr/local/kamailio-5.4/sbin/kamailio -v ```
Did you backport patches or run master branch?
For the previous test i downloaded and installed the master branch. For this one i only downloaded the core and re-installed.
Should i do a fresh install?
kamailio -v output is the following :
version: kamailio 5.6.0-dev0 (x86_64/linux) flags: USE_TCP, USE_TLS, USE_SCTP, TLS_HOOKS, USE_RAW_SOCKS, DISABLE_NAGLE, USE_MCAST, DNS_IP_HACK, SHM_MMAP, PKG_MALLOC, Q_MALLOC, F_MALLOC, TLSF_MALLOC, DBG_SR_MEMORY, USE_FUTEX, FAST_LOCK-ADAPTIVE_WAIT, USE_DNS_CACHE, USE_DNS_FAILOVER, USE_NAPTR, USE_DST_BLOCKLIST, HAVE_RESOLV_RES ADAPTIVE_WAIT_LOOPS 1024, MAX_RECV_BUFFER_SIZE 262144, MAX_URI_SIZE 1024, BUF_SIZE 65535, DEFAULT PKG_SIZE 8MB poll method support: poll, epoll_lt, epoll_et, sigio_rt, select. id: unknown
Yes, do a fresh install of everything from git master branch.
Hi Daniel. Sorry for the delay.
I did a fresh install from the master branch.
My kamailio -v returns this :
version: kamailio 5.6.0-dev0 (x86_64/linux)
flags: USE_TCP, USE_TLS, USE_SCTP, TLS_HOOKS, USE_RAW_SOCKS, DISABLE_NAGLE, USE_MCAST, DNS_IP_HACK, SHM_MMAP, PKG_MALLOC, Q_MALLOC, F_MALLOC, TLSF_MALLOC, DBG_SR_MEMORY, USE_FUTEX, FAST_LOCK-ADAPTIVE_WAIT, USE_DNS_CACHE, USE_DNS_FAILOVER, USE_NAPTR, USE_DST_BLOCKLIST, HAVE_RESOLV_RES ADAPTIVE_WAIT_LOOPS 1024, MAX_RECV_BUFFER_SIZE 262144, MAX_URI_SIZE 1024, BUF_SIZE 65535, DEFAULT PKG_SIZE 8MB poll method support: poll, epoll_lt, epoll_et, sigio_rt, select.
Now the return from the filtering is the following :
2021-06-08T19:02:30.589519+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.6/sbin/kamailio[22398]: ERROR: <script>: Before filter_body
2021-06-08T19:02:30.589932+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.6/sbin/kamailio[22398]: ERROR: textops [textops.c:1616]: find_hdr_line_start(): not a header name: Content-Type: 2021-06-08T19:02:30.590254+01:00 dev_sbc_a_vts01 /usr/local/kamailio-5.6/sbin/kamailio[22398]: ERROR: <script>: Filtering failed
Here is the body from the message :
Message Body
MIME Multipart Media Encapsulation, Type: multipart/mixed, Boundary: "unique-boundary-1" [Type: multipart/mixed] First boundary: --unique-boundary-1\r\n Encapsulated multipart part: (application/sdp) Content-Type:application/sdp\r\n\r\n Session Description Protocol Session Description Protocol Version (v): 0 Owner/Creator, Session Id (o): - 1372599309 1 IN IP4 1.1.1.1 Session Name (s): - Connection Information (c): IN IP4 1.1.3.1 Time Description, active time (t): 0 0 Media Description, name and address (m): audio 22646 RTP/AVP 8 0 18 3 13 101 96 Media Attribute (a): rtpmap:101 telephone-event/8000 Media Attribute (a): rtpmap:96 CLEARMODE/8000 Boundary: \r\n--unique-boundary-1\r\n Encapsulated multipart part: (application/isup) Content-Type:application/ISUP;base=itu-t92+;version=itu-t\r\n Content-Disposition:signal;handling=required\r\n\r\n ISDN User Part Message Type: Initial address (1) Nature of Connection Indicators : 0x0 Forward Call Indicators : 0x6001 Calling Party's category : 0xa (ordinary calling subscriber) Transmission medium requirement : 0 (speech) Called Party NumberCalled Party Number: 111111111 Pointer to start of optional part: 10 Parameter: (t=10, l=8) Calling party number: Calling party numberCalling Party Number: 222222222 Parameter: (t=192, l=9) Generic number: Generic numberGeneric Number: 222222222 End of optional parameters (0) Last boundary: \r\n--unique-boundary-1--\r\n
If you need more info let me know
Can you attach a pcap file with such SIP request? I will try to reproduce it by resending it to kamailio on my lab.
I've sent it to your e-mail with the subject "filter_body issue #2748".
Got some time to look into it, the pcap helped and I pushed a new commit. Can you try again with master branch?
Hi Daniel,
Thanks for the update. Altough there are no errors in the log now, the filtering is still failing.
I'm using this code :
`request_route {
xerr("Before filter_body"); if (filter_body("application/sdp")) { xerr("Filtered with sucess"); } else { xerr("Filtering failed");}`
I get the "Filtering failed" log and when i check the pcaps, the ISUP is still there.
Let me know if there is any more info i can share to help fix the issue.
Cheers
Hello Daniel,
Any update on this issue?
Cheers
Summer holidays season kept me out of office a lot, I will try to resume on this one soon.
Can you try again with latest master branch?
Closed #2748.
Closing this one, the last patch referenced above should fix it. If not, reopen.