@@ -17,6 +17,7 @@ package sip
1717import (
1818 "context"
1919 "fmt"
20+ "github.com/livekit/protocol/rpc"
2021 "math"
2122 "net/netip"
2223 "slices"
@@ -184,7 +185,7 @@ func (s *Server) processInvite(req *sip.Request, tx sip.ServerTransaction) (retE
184185
185186 from , to := cc .From (), cc .To ()
186187
187- cmon := s .mon .NewCall (stats .Inbound , from .Host , cc . To () .Host )
188+ cmon := s .mon .NewCall (stats .Inbound , from .Host , to .Host )
188189 cmon .InviteReq ()
189190 defer cmon .SessionDur ()()
190191 joinDur := cmon .JoinDur ()
@@ -193,7 +194,25 @@ func (s *Server) processInvite(req *sip.Request, tx sip.ServerTransaction) (retE
193194 cc .Processing ()
194195 }
195196
196- r , err := s .handler .GetAuthCredentials (ctx , callID , from .User , to .User , to .Host , src .Addr ())
197+ callInfo := & rpc.SIPCall {
198+ LkCallId : callID ,
199+ SourceIp : src .Addr ().String (),
200+ Address : ToSIPUri ("" , cc .Address ()),
201+ From : ToSIPUri ("" , from ),
202+ To : ToSIPUri ("" , to ),
203+ }
204+ for _ , h := range cc .RemoteHeaders () {
205+ switch h := h .(type ) {
206+ case * sip.ViaHeader :
207+ callInfo .Via = append (callInfo .Via , & livekit.SIPUri {
208+ Host : h .Host ,
209+ Port : uint32 (h .Port ),
210+ Transport : SIPTransportFrom (Transport (h .Transport )),
211+ })
212+ }
213+ }
214+
215+ r , err := s .handler .GetAuthCredentials (ctx , callInfo )
197216 if err != nil {
198217 cmon .InviteErrorShort ("auth-error" )
199218 log .Warnw ("Rejecting inbound, auth check failed" , err )
@@ -245,7 +264,7 @@ func (s *Server) processInvite(req *sip.Request, tx sip.ServerTransaction) (retE
245264 // ok
246265 }
247266
248- call = s .newInboundCall (log , cmon , cc , src , state , nil )
267+ call = s .newInboundCall (log , cmon , cc , callInfo , state , nil )
249268 call .joinDur = joinDur
250269 return call .handleInvite (call .ctx , req , r .TrunkID , s .conf )
251270}
@@ -316,7 +335,7 @@ type inboundCall struct {
316335 attrsToHdr map [string ]string
317336 ctx context.Context
318337 cancel func ()
319- src netip. AddrPort
338+ call * rpc. SIPCall
320339 media * MediaPort
321340 dtmf chan dtmf.Event // buffered
322341 lkRoom * Room // LiveKit room; only active after correct pin is entered
@@ -331,7 +350,7 @@ func (s *Server) newInboundCall(
331350 log logger.Logger ,
332351 mon * stats.CallMonitor ,
333352 cc * sipInbound ,
334- src netip. AddrPort ,
353+ call * rpc. SIPCall ,
335354 state * CallState ,
336355 extra map [string ]string ,
337356) * inboundCall {
@@ -342,7 +361,7 @@ func (s *Server) newInboundCall(
342361 log : log ,
343362 mon : mon ,
344363 cc : cc ,
345- src : src ,
364+ call : call ,
346365 state : state ,
347366 extraAttrs : extra ,
348367 dtmf : make (chan dtmf.Event , 10 ),
@@ -366,14 +385,10 @@ func (c *inboundCall) handleInvite(ctx context.Context, req *sip.Request, trunkI
366385 // Send initial request. In the best case scenario, we will immediately get a room name to join.
367386 // Otherwise, we could even learn that this number is not allowed and reject the call, or ask for pin if required.
368387 disp := c .s .handler .DispatchCall (ctx , & CallInfo {
369- TrunkID : trunkID ,
370- ID : string (c .cc .ID ()),
371- FromUser : c .cc .From ().User ,
372- ToUser : c .cc .To ().User ,
373- ToHost : c .cc .To ().Host ,
374- SrcAddress : c .src .Addr (),
375- Pin : "" ,
376- NoPin : false ,
388+ TrunkID : trunkID ,
389+ Call : c .call ,
390+ Pin : "" ,
391+ NoPin : false ,
377392 })
378393 if disp .ProjectID != "" {
379394 c .log = c .log .WithValues ("projectID" , disp .ProjectID )
@@ -659,14 +674,10 @@ func (c *inboundCall) pinPrompt(ctx context.Context, trunkID string) (disp CallD
659674
660675 c .log .Infow ("Checking Pin for SIP call" , "pin" , pin , "noPin" , noPin )
661676 disp = c .s .handler .DispatchCall (ctx , & CallInfo {
662- TrunkID : trunkID ,
663- ID : string (c .cc .ID ()),
664- FromUser : c .cc .From ().User ,
665- ToUser : c .cc .To ().User ,
666- ToHost : c .cc .To ().Host ,
667- SrcAddress : c .src .Addr (),
668- Pin : pin ,
669- NoPin : noPin ,
677+ TrunkID : trunkID ,
678+ Call : c .call ,
679+ Pin : pin ,
680+ NoPin : noPin ,
670681 })
671682 if disp .ProjectID != "" {
672683 c .log = c .log .WithValues ("projectID" , disp .ProjectID )
@@ -1008,6 +1019,13 @@ func (c *sipInbound) RespondAndDrop(status sip.StatusCode, reason string) {
10081019 c .drop ()
10091020}
10101021
1022+ func (c * sipInbound ) Address () sip.Uri {
1023+ if c .invite == nil {
1024+ return sip.Uri {}
1025+ }
1026+ return c .invite .Recipient
1027+ }
1028+
10111029func (c * sipInbound ) From () sip.Uri {
10121030 if c .from == nil {
10131031 return sip.Uri {}
0 commit comments