Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Via headers for requests for outbound calls #218

Merged
merged 10 commits into from
Nov 18, 2024
19 changes: 19 additions & 0 deletions pkg/sip/inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -1145,12 +1145,31 @@ func (c *sipInbound) swapSrcDst(req *sip.Request) {
req.AppendHeader((*sip.FromHeader)(c.to))
req.RemoveHeader("To")
req.AppendHeader((*sip.ToHeader)(c.from))
// Remove all Via headers
for req.RemoveHeader("Via") {
}
Comment on lines +1148 to +1150
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly, this might be incorrect. Each router is supposed to append it's own Via and then remove that line when requests go back. So I believe we are supposed to add own own line and that's it.

Copy link
Contributor Author

@biglittlebigben biglittlebigben Nov 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The behavior you state above is correct for responses within a given transaction: the responses must have the same VIA headers as the request, and proxies on the way back are supposed to "peel" their own Via entries from the response,. The REFER request is however a new request, in a new transaction, sent directly to the server from the INVITE Contact header. As such, only the IP address of the request initiator should be in the Via header. I believe the examples in the REFER RFC confirm the above: https://www.rfc-editor.org/rfc/rfc3515#section-4

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, you are right, I forgot that's a new request. Makes sense 👍

req.PrependHeader(c.generateViaHeader(req))
if route := req.RecordRoute(); route != nil {
req.RemoveHeader("Record-Route")
req.AppendHeader(&sip.RouteHeader{Address: route.Address})
}
}

func (c *sipInbound) generateViaHeader(req *sip.Request) *sip.ViaHeader {
newvia := &sip.ViaHeader{
ProtocolName: "SIP",
ProtocolVersion: "2.0",
Transport: req.Transport(),
Host: c.s.sconf.SignalingIP.String(), // This can be rewritten by transport layer
Port: c.s.conf.SIPPort, // This can be rewritten by transport layer
Params: sip.NewParams(),
}
// NOTE: Consider lenght of branch configurable
newvia.Params.Add("branch", sip.GenerateBranchN(16))

return newvia
}

func (c *sipInbound) setCSeq(req *sip.Request) {
setCSeq(req, c.nextRequestCSeq)

Expand Down
Loading