diff --git a/pkg/sip/inbound.go b/pkg/sip/inbound.go index d4783b5..35660e7 100644 --- a/pkg/sip/inbound.go +++ b/pkg/sip/inbound.go @@ -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") { + } + 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)