Asterisk modify "TO" header of OPTIONS message

Hi, I tried to modify the header, but it’s always send like this:


OPTIONS sip:14.238.X.XXX SIP/2.0

Via: SIP/2.0/UDP 14.248.XX.XX:5160;branch=z9hG4bK377b1d0a;rport

Max-Forwards: 70

From: "Unknown" <sip:024385XXXXX@14.248.XX.XX:5160>;tag=as2f44f5e8

To: <sip:14.238.X.XXX>

Contact: <sip:024385XXXXX@14.248.XX.XX:5160>

Call-ID: 7bf51a95644973a102b8170179d21b07@14.248.XX.XX:5160

CSeq: 102 OPTIONS

User-Agent: FPBX-15.0.37.9(17.9.3)

Date: Mon, 09 Dec 2024 09:56:28 GMT

Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO, PUBLISH, MESSAGE

Supported: replaces, timer

Content-Length: 0

Even in my trunk I used:

context=custom-context


root@vedax:/etc/asterisk# cat extensions_custom.conf

[custom-context]

exten => s,1,NoOp(Sending custom SIP OPTIONS)

same => n,Set(SIP_HEADER(To)=<sip:024385XXXXX@14.238.X.XXX>)

same => n,Set(SIP_HEADER(From)="Vedax" <sip:024385XXXXX@14.248.XX.XX>)

same => n,Dial(SIP/${EXTEN}@VNPT)

same => n,Hangup()

Can someone help?

This is not enough information to see what your problem is. You’d need to show us your entire SIP configuration. That said, there is usually no need to modify fields like To or From.

That dialplan also doesn’t send a SIP OPTIONS, or use a dialplan function that exists.

Did you ask ChatGPT for help?

1 Like

SIP_HEADER is probably not what you need, maybe SIPAddHeader is your friend, or not. You probably need to ask a decent AI engine for real life answers, :smile: .

1 Like

Also, why are you using the inbound context for outbound requests?

Why do you need to change this? To headers have very little significance, except in REGISTER requests, and a 404 Not found response still indicates good connectivity.

1 Like

Hi all, I already asked ChatGPT for this help. Because the trunk provider need the “TO” information required the phone number for register the trunk

I also tried your suggest:

[vnpt-context]
exten => s,1,NoOp(Sending custom SIP OPTIONS)
same => n,SIP_HEADER(remove,To)
same => n,Set(SIP_HEADER(To)=<sip:024385XXXXX@14.238.X.XXX>)
same => n,Set(SIP_HEADER(From)="Vedax" <sip:024385XXXXX@14.248.XX.XX>)
same => n,Dial(SIP/${EXTEN}@VNPT)
same => n,Hangup()

[vnpt]
exten => s,1,NoOp(Sending custom SIP OPTIONS with modified To header)
same => n,SipAddHeader(To: <sip:024385XXXXX@14.238.X.XXX>)
same => n,Dial(SIP/${EXTEN}@VNPT)
same => n,Hangup()

But still the same:

Here is my sip config

root@vedax:/etc/asterisk# cat sip_general_additional.conf 
;--------------------------------------------------------------------------------;
;          Do NOT edit this file as it is auto-generated by FreePBX.             ;
;--------------------------------------------------------------------------------;
; For information on adding additional paramaters to this file, please visit the ;
; FreePBX.org wiki page, or ask on IRC. This file was created by the new FreePBX ;
; BMO - Big Module Object. Any similarity in naming with BMO from Adventure Time ;
; is totally deliberate.                                                         ;
;--------------------------------------------------------------------------------;
vmexten=*97
useragent=FPBX-15.0.37.9(17.9.3)
language=en
disallow=all
allow=alaw
context=from-sip-external
callerid=Unknown
notifyringing=yes
notifyhold=yes
tos_sip=cs3
tos_audio=ef
tos_video=af41
alwaysauthreject=yes
limitonpeers=yes
rtpend=20000
context=from-sip-external
callerid=Unknown
rtpstart=10000
tcpenable=no
callevents=no
jbenable=no
checkmwi=10
maxexpiry=3600
minexpiry=60
srvlookup=yes
tlsenable=no
allowguest=yes
notifyhold=yes
rtptimeout=30
canreinvite=no
tlsbindaddr=[::]:5161
rtpkeepalive=0
videosupport=no
defaultexpiry=120
notifyringing=yes
maxcallbitrate=384
rtpholdtimeout=300
g726nonstandard=no
registertimeout=20
tlsclientmethod=tlsv1
registerattempts=0
tlsdontverifyserver=yes
nat=force_rport,comedia
ALLOW_SIP_ANON=no
udpbindaddr=0.0.0.0:5160
tlscafile=/etc/ssl/certs/ca-certificates.crt
externip=14.248.XX.XX
localnet=192.168.1.0/24

Here is the trunk config:

root@vedax:/etc/asterisk# cat sip_additional.conf 
;--------------------------------------------------------------------------------;
;          Do NOT edit this file as it is auto-generated by FreePBX.             ;
;--------------------------------------------------------------------------------;
; For information on adding additional paramaters to this file, please visit the ;
; FreePBX.org wiki page, or ask on IRC. This file was created by the new FreePBX ;
; BMO - Big Module Object. Any similarity in naming with BMO from Adventure Time ;
; is totally deliberate.                                                         ;
;--------------------------------------------------------------------------------;

[VNPT]
type=friend
context=vnpt
port=5060
host=14.238.X.XXX
qualify=yes
fromuser=024385XXXXX
fromdomain=14.248.XX.XX

Here is the SNGREP information, because the “TO” is not valid, so the trunk does not response(This is what the Trunk provider explain to me)

Please let me know what I need to do

Yes I need to change this due to the request from provider, the “To” need to add the phonenumber to verify OPTIONS message

I posted all the code above, can you help?

I also tried but not working to me :frowning:

Can you give me some advices? I need to add the number inside “To”, for validate with Trunk provider
I just want to add the phone number to the header only

You’re using chan_sip, I don’t help with that any longer. Someone else may chime in but ultimately it may not be possible.

thanks, I will create pjsip trunk then make new question if it not working

A better approach would be to read the docs and to remember “sapere aude”. If you are trying to do something that FreePBX doesn’t do by itself, you need to know something about the inner workings of FreePBX, additionally get familiar with what Asterisk can actually do and you might still not get what you want. Asterisk does not allow the detailed manipulation of SIP properties like a SIP proxy can do. Another approach is to learn the details of PJSIP, I mean the sources and not its interfaces. Perhaps ChatGPT can help you here (just kidding).

The principle of Occam’s razor could also indicate that there is something wrong with the state of Denmark if you believe that difficult things must be done in order for something simple to work.

The references to ChatGPT were probably sarcastic. People think you already used it, and it is known for giving wrong answers.

Why are you asking about OPTIONS? If this is about registration, it is the REGISTER To that matters, and if that is not the same as the From header, you need to use chan_pjsip as chan_sip only gives independent control of To in INVITE.

thanks, chan pjsip worked to me

thanks, chan pjsip worked to me

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.