From 8613afbcf99abfb464e41ae5b1f5ec63f40677c5 Mon Sep 17 00:00:00 2001 From: Denys Smirnov Date: Tue, 15 Jul 2025 21:04:32 +0300 Subject: [PATCH 1/3] Allow setting contact IP in siptest. --- pkg/siptest/client.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/siptest/client.go b/pkg/siptest/client.go index f73a6897..fbf3169a 100644 --- a/pkg/siptest/client.go +++ b/pkg/siptest/client.go @@ -54,6 +54,7 @@ import ( type ClientConfig struct { IP netip.Addr + ContactIP netip.Addr Number string AuthUser string AuthPass string @@ -85,6 +86,10 @@ func NewClient(id string, conf ClientConfig) (*Client, error) { conf.IP = localIP conf.Log.Debug("setting local address", "ip", localIP) } + if !conf.ContactIP.IsValid() { + conf.ContactIP = conf.IP + conf.Log.Debug("setting contact address", "ip", conf.ContactIP) + } if conf.Number == "" { conf.Number = "1000" } @@ -352,7 +357,7 @@ func (c *Client) attemptInvite(ip, uri, number string, offer []byte, authHeader req.SetDestination(ip) req.SetBody(offer) req.AppendHeader(sip.NewHeader("Content-Type", "application/sdp")) - req.AppendHeader(sip.NewHeader("Contact", fmt.Sprintf("", c.conf.IP))) + req.AppendHeader(sip.NewHeader("Contact", fmt.Sprintf("", c.conf.ContactIP))) req.AppendHeader(sip.NewHeader("Allow", "INVITE, ACK, CANCEL, BYE, NOTIFY, REFER, MESSAGE, OPTIONS, INFO, SUBSCRIBE")) if c.id != "" { req.AppendHeader(sip.NewHeader("X-Lk-Test-Id", c.id)) From f65ed5a0316925767e2ed6c87ecfc4f9aa445e03 Mon Sep 17 00:00:00 2001 From: Denys Smirnov Date: Wed, 16 Jul 2025 16:36:21 +0300 Subject: [PATCH 2/3] Add Via with contact IP in siptest. --- pkg/siptest/client.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pkg/siptest/client.go b/pkg/siptest/client.go index fbf3169a..ae84404b 100644 --- a/pkg/siptest/client.go +++ b/pkg/siptest/client.go @@ -359,6 +359,19 @@ func (c *Client) attemptInvite(ip, uri, number string, offer []byte, authHeader req.AppendHeader(sip.NewHeader("Content-Type", "application/sdp")) req.AppendHeader(sip.NewHeader("Contact", fmt.Sprintf("", c.conf.ContactIP))) req.AppendHeader(sip.NewHeader("Allow", "INVITE, ACK, CANCEL, BYE, NOTIFY, REFER, MESSAGE, OPTIONS, INFO, SUBSCRIBE")) + if v, _ := req.GetHeader("Via").(*sip.ViaHeader); v != nil && c.conf.IP != c.conf.ContactIP { + if false { + // TODO: check if we need to remove old one + req.RemoveHeader("Via") + } + v2 := *v + v2.Host = c.conf.ContactIP.String() + if false { + // TODO: check if it matters + v2.Params.Add("rport", "") + } + req.PrependHeader(&v2) + } if c.id != "" { req.AppendHeader(sip.NewHeader("X-Lk-Test-Id", c.id)) } From c42798b2f783f7c9bfc78ec4c0ab365f11467154 Mon Sep 17 00:00:00 2001 From: Denys Smirnov Date: Wed, 16 Jul 2025 16:48:59 +0300 Subject: [PATCH 3/3] Add Via with contact IP in siptest. --- pkg/siptest/client.go | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/pkg/siptest/client.go b/pkg/siptest/client.go index ae84404b..57f852e7 100644 --- a/pkg/siptest/client.go +++ b/pkg/siptest/client.go @@ -33,6 +33,7 @@ import ( "github.com/at-wat/ebml-go" "github.com/at-wat/ebml-go/webm" + sip2 "github.com/emiago/sipgo/sip" "github.com/frostbyte73/core" "github.com/icholy/digest" "github.com/pion/sdp/v3" @@ -359,18 +360,22 @@ func (c *Client) attemptInvite(ip, uri, number string, offer []byte, authHeader req.AppendHeader(sip.NewHeader("Content-Type", "application/sdp")) req.AppendHeader(sip.NewHeader("Contact", fmt.Sprintf("", c.conf.ContactIP))) req.AppendHeader(sip.NewHeader("Allow", "INVITE, ACK, CANCEL, BYE, NOTIFY, REFER, MESSAGE, OPTIONS, INFO, SUBSCRIBE")) - if v, _ := req.GetHeader("Via").(*sip.ViaHeader); v != nil && c.conf.IP != c.conf.ContactIP { - if false { - // TODO: check if we need to remove old one - req.RemoveHeader("Via") - } - v2 := *v - v2.Host = c.conf.ContactIP.String() + if c.conf.IP != c.conf.ContactIP { + p := make(sip2.HeaderParams) + p.Add("alias", "") + p.Add("branch", sip2.GenerateBranch()) if false { // TODO: check if it matters - v2.Params.Add("rport", "") - } - req.PrependHeader(&v2) + p.Add("rport", "") + } + req.PrependHeader(&sip.ViaHeader{ + ProtocolName: "SIP", + ProtocolVersion: "2.0", + Transport: "UDP", // TODO + Host: c.conf.ContactIP.String(), + Port: 5060, + Params: p, + }) } if c.id != "" { req.AppendHeader(sip.NewHeader("X-Lk-Test-Id", c.id))