forked from fiorix/go-diameter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dwr.go
51 lines (48 loc) · 1.4 KB
/
dwr.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright 2013-2015 go-diameter authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package sm
import (
"github.com/fiorix/go-diameter/v4/diam"
"github.com/fiorix/go-diameter/v4/diam/avp"
"github.com/fiorix/go-diameter/v4/diam/datatype"
"github.com/fiorix/go-diameter/v4/diam/sm/smparser"
)
// handleDWR handles Device-Watchdog-Request messages.
//
// If mandatory AVPs such as Origin-Host or Origin-Realm are missing,
// we ignore the message.
//
// See RFC 6733 section 5.5 for details.
func handleDWR(sm *StateMachine) diam.HandlerFunc {
return func(c diam.Conn, m *diam.Message) {
dwr := new(smparser.DWR)
err := dwr.Parse(m)
if err != nil {
sm.Error(&diam.ErrorReport{
Conn: c,
Message: m,
Error: err,
})
return
}
a := m.Answer(diam.Success)
// Fix for Same H2H and E2E Identifier in success response
a.Header.HopByHopID = m.Header.HopByHopID
a.Header.EndToEndID = m.Header.EndToEndID
a.NewAVP(avp.OriginHost, avp.Mbit, 0, sm.cfg.OriginHost)
a.NewAVP(avp.OriginRealm, avp.Mbit, 0, sm.cfg.OriginRealm)
if sm.cfg.OriginStateID != 0 {
stateid := datatype.Unsigned32(sm.cfg.OriginStateID)
m.NewAVP(avp.OriginStateID, avp.Mbit, 0, stateid)
}
_, err = a.WriteTo(c)
if err != nil {
sm.Error(&diam.ErrorReport{
Conn: c,
Message: m,
Error: err,
})
}
}
}