mirror of
https://github.com/yibaiba/hideck.git
synced 2026-12-06 08:02:21 +00:00
fix(ims): skip outbound follow-up REGISTER when only Supported
2degrees advertises Supported: outbound without Path;ob or Require. The extra REGISTER after the 200 then 503s and tore down SMS. Only complete the outbound binding on Require, Path;ob, or an echoed reg-id. If that follow-up fails without Require, keep the first 200.
This commit is contained in:
1 parent
e2ffbccf27
commit
f05145cbcd
4 files changed
+61
-2
No files matched your search
+17
-1
@@ -113,7 +113,13 @@ func (s *Service) registerLocked(ctx context.Context) error {
|
||||
if err == nil && s.needsOutboundBindingRefresh() {
|
||||
logging.Info("IMS REGISTER completing outbound flow", "device", s.DeviceID())
|
||||
if again, againErr := s.runRegisterFlow(ctx); againErr != nil {
|
||||
err = againErr
|
||||
if s.outboundBindingRequired() {
|
||||
err = againErr
|
||||
} else {
|
||||
logging.WarnRate("ims-outbound-refresh-"+s.DeviceID(), 30*time.Second,
|
||||
"IMS outbound binding refresh failed; keep current registration",
|
||||
"device", s.DeviceID(), "err", againErr)
|
||||
}
|
||||
} else {
|
||||
expires = again
|
||||
}
|
||||
@@ -127,6 +133,7 @@ func (s *Service) registerLocked(ctx context.Context) error {
|
||||
s.signalingFailureReason = err.Error()
|
||||
s.sipOutboundKeepalive = false
|
||||
s.sipOutbound = false
|
||||
s.sipOutboundRequired = false
|
||||
s.outboundContactOffered = false
|
||||
s.outboundContactRegistered = false
|
||||
s.flowTimer = 0
|
||||
@@ -729,6 +736,15 @@ func (s *Service) needsOutboundBindingRefresh() bool {
|
||||
return s.sipOutbound && !s.outboundContactRegistered
|
||||
}
|
||||
|
||||
func (s *Service) outboundBindingRequired() bool {
|
||||
if s == nil {
|
||||
return false
|
||||
}
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
return s.sipOutboundRequired
|
||||
}
|
||||
|
||||
func withOutboundContactParams(order []string) []string {
|
||||
result := append([]string(nil), order...)
|
||||
if !containsContactParamName(result, "sip_instance") {
|
||||
|
||||
@@ -25,7 +25,12 @@ func (s *Service) logRegisterFlowNegotiation(response *sipResponse) {
|
||||
contactRegID := containsSIPParameter(contact, "reg-id")
|
||||
s.mu.Lock()
|
||||
s.sipOutboundKeepalive = requiredOutbound || viaKeep
|
||||
s.sipOutbound = supportedOutbound || requiredOutbound || pathOB || contactRegID
|
||||
// RFC 5626: Supported: outbound only means the registrar understands
|
||||
// outbound. A follow-up REGISTER with reg-id is for an actual flow
|
||||
// (Require, Path;ob, or an echoed reg-id). 2degrees advertises
|
||||
// Supported and 503s the extra REGISTER (hideck#6).
|
||||
s.sipOutboundRequired = requiredOutbound
|
||||
s.sipOutbound = requiredOutbound || pathOB || contactRegID
|
||||
if s.outboundContactOffered {
|
||||
s.outboundContactRegistered = true
|
||||
}
|
||||
|
||||
@@ -450,6 +450,43 @@ func TestInitialRegisterOmitsOutboundContactWithoutSupportedOutbound(t *testing.
|
||||
}
|
||||
}
|
||||
|
||||
func TestSupportedOutboundDoesNotRequireFollowUpRegister(t *testing.T) {
|
||||
service := &Service{cfg: &IMSConfig{
|
||||
IMPI: "user@ims.example", IMPU: "sip:user@ims.example", Domain: "ims.example",
|
||||
LocalIP: net.ParseIP("192.0.2.10"), LocalPort: 5060, Transport: "udp",
|
||||
}}
|
||||
service.logRegisterFlowNegotiation(&sipResponse{
|
||||
StatusCode: 200,
|
||||
Headers: map[string]string{
|
||||
"Supported": "path, outbound",
|
||||
"Path": "<sip:pcscf.example;lr>",
|
||||
},
|
||||
})
|
||||
if service.needsOutboundBindingRefresh() {
|
||||
t.Fatal("Supported: outbound without Path;ob or Require must not send a follow-up REGISTER")
|
||||
}
|
||||
if service.outboundBindingRequired() {
|
||||
t.Fatal("Supported: outbound is not Require: outbound")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRequireOutboundRequiresFollowUpRegister(t *testing.T) {
|
||||
service := &Service{cfg: &IMSConfig{
|
||||
IMPI: "user@ims.example", IMPU: "sip:user@ims.example", Domain: "ims.example",
|
||||
LocalIP: net.ParseIP("192.0.2.10"), LocalPort: 5060, Transport: "udp",
|
||||
}}
|
||||
service.logRegisterFlowNegotiation(&sipResponse{
|
||||
StatusCode: 200,
|
||||
Headers: map[string]string{"Require": "outbound"},
|
||||
})
|
||||
if !service.needsOutboundBindingRefresh() {
|
||||
t.Fatal("Require: outbound must trigger a follow-up REGISTER with reg-id")
|
||||
}
|
||||
if !service.outboundBindingRequired() {
|
||||
t.Fatal("Require: outbound must fail registration if the follow-up REGISTER fails")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPathOBRequiresFollowUpRegisterWithRegID(t *testing.T) {
|
||||
service := &Service{cfg: &IMSConfig{
|
||||
IMPI: "user@ims.example", IMPU: "sip:user@ims.example", Domain: "ims.example",
|
||||
|
||||
@@ -215,6 +215,7 @@ type Service struct {
|
||||
tcpCRLFPongWait time.Duration
|
||||
sipOutboundKeepalive bool
|
||||
sipOutbound bool
|
||||
sipOutboundRequired bool
|
||||
outboundContactOffered bool
|
||||
outboundContactRegistered bool
|
||||
flowTimer time.Duration
|
||||
|
||||
Reference in new issue
Block a user