Skip to content

Commit cb96d58

Browse files
Detailed log for unhandled sip requests (#391)
This could make it easy to search logs when we have attributes like the call id but we haven't handled the sip request
1 parent 95a3247 commit cb96d58

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

pkg/sip/inbound.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,27 @@ func (s *Server) onBye(log *slog.Logger, req *sip.Request, tx sip.ServerTransact
304304
}
305305
}
306306

307+
func (s *Server) OnNoRoute(log *slog.Logger, req *sip.Request, tx sip.ServerTransaction) {
308+
callID := ""
309+
if h := req.CallID(); h != nil {
310+
callID = h.Value()
311+
}
312+
from := ""
313+
if h := req.From(); h != nil {
314+
from = h.Address.String()
315+
}
316+
to := ""
317+
if h := req.To(); h != nil {
318+
to = h.Address.String()
319+
}
320+
s.log.Infow("Inbound SIP request not handled",
321+
"method", req.Method.String(),
322+
"callID", callID,
323+
"from", from,
324+
"to", to)
325+
tx.Respond(sip.NewResponseFromRequest(req, 405, "Method Not Allowed", nil))
326+
}
327+
307328
func (s *Server) onNotify(log *slog.Logger, req *sip.Request, tx sip.ServerTransaction) {
308329
tag, err := getFromTag(req)
309330
if err != nil {

pkg/sip/server.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ func (s *Server) Start(agent *sipgo.UserAgent, sc *ServiceConfig, unhandled Requ
261261
s.sipSrv.OnInvite(s.onInvite)
262262
s.sipSrv.OnBye(s.onBye)
263263
s.sipSrv.OnNotify(s.onNotify)
264+
s.sipSrv.OnNoRoute(s.OnNoRoute)
264265
s.sipUnhandled = unhandled
265266

266267
// Ignore ACKs

0 commit comments

Comments
 (0)