From d548764a1c01a89891f7e2be9f427792836a3e74 Mon Sep 17 00:00:00 2001 From: Denys Smirnov Date: Tue, 10 Dec 2024 16:35:07 +0200 Subject: [PATCH] Log auth attempts. --- pkg/sip/outbound.go | 11 +++++++++-- pkg/sip/types.go | 3 +++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/pkg/sip/outbound.go b/pkg/sip/outbound.go index 8180a3f..a41f146 100644 --- a/pkg/sip/outbound.go +++ b/pkg/sip/outbound.go @@ -93,7 +93,7 @@ func (c *Client) newCall(ctx context.Context, conf *config.Config, log logger.Lo call := &outboundCall{ c: c, log: log, - cc: c.newOutbound(id, URI{ + cc: c.newOutbound(log, id, URI{ User: sipConf.from, Host: sipConf.host, Addr: contact.Addr, @@ -516,7 +516,7 @@ func (c *outboundCall) transferCall(ctx context.Context, transferTo string, dial return nil } -func (c *Client) newOutbound(id LocalTag, from, contact URI) *sipOutbound { +func (c *Client) newOutbound(log logger.Logger, id LocalTag, from, contact URI) *sipOutbound { from = from.Normalize() fromHeader := &sip.FromHeader{ DisplayName: from.User, @@ -528,6 +528,7 @@ func (c *Client) newOutbound(id LocalTag, from, contact URI) *sipOutbound { } fromHeader.Params.Add("tag", string(id)) return &sipOutbound{ + log: log, c: c, id: id, from: fromHeader, @@ -537,6 +538,7 @@ func (c *Client) newOutbound(id LocalTag, from, contact URI) *sipOutbound { } type sipOutbound struct { + log logger.Logger c *Client id LocalTag from *sip.FromHeader @@ -648,6 +650,11 @@ authLoop: authHeaderName = "Proxy-Authenticate" authHeaderRespName = "Proxy-Authorization" } + cid := "" + if h := resp.CallID(); h != nil { + cid = h.Value() + } + c.log.Infow("auth requested", "sipCallID", cid, "status", resp.StatusCode, "body", string(resp.Body())) // auth required if user == "" || pass == "" { return nil, errors.New("server required auth, but no username or password was provided") diff --git a/pkg/sip/types.go b/pkg/sip/types.go index 84f6834..1b0ef73 100644 --- a/pkg/sip/types.go +++ b/pkg/sip/types.go @@ -224,6 +224,9 @@ func LoggerWithParams(log logger.Logger, c Signaling) logger.Logger { if tag := c.Tag(); tag != "" { log = log.WithValues("sipTag", tag) } + if cid := c.CallID(); cid != "" { + log = log.WithValues("sipCallID", cid) + } return log }