Skip to content

Commit

Permalink
Tear down assocation on ABORT chunk
Browse files Browse the repository at this point in the history
Properly tear down the association when we receive an ABORT
chunk.
  • Loading branch information
Sean-Der committed Feb 1, 2020
1 parent 879b876 commit 807f7b9
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions association.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,11 +426,12 @@ func (a *Association) readLoop() {

atomic.AddUint64(&a.bytesReceived, uint64(n))
if err = a.handleInbound(buffer[:n]); err != nil {
a.log.Warnf("[%s] %s]", a.name, errors.Wrap(err, "failed to push SCTP packet").Error())
closeErr = err
break
}
}

a.log.Debugf("[%s] readLoop exited", a.name)
a.log.Debugf("[%s] readLoop exited %s %s", a.name, closeErr)
}

func (a *Association) writeLoop() {
Expand Down Expand Up @@ -487,19 +488,20 @@ func (a *Association) unregisterStream(s *Stream, err error) {
func (a *Association) handleInbound(raw []byte) error {
p := &packet{}
if err := p.unmarshal(raw); err != nil {
return errors.Wrap(err, "unable to parse SCTP packet")
a.log.Warnf("[%s] unable to parse SCTP packet %s", a.name, err)
return nil
}

if err := checkPacket(p); err != nil {
return errors.Wrap(err, "failed validating packet")
a.log.Warnf("[%s] failed validating packet %s", a.name, err)
return nil
}

a.handleChunkStart(p)

for _, c := range p.chunks {
err := a.handleChunk(p, c)
if err != nil {
a.log.Warnf("[%s] %s", a.name, errors.Wrap(err, "failed handling chunk").Error())
if err := a.handleChunk(p, c); err != nil {
return err
}
}

Expand Down Expand Up @@ -1963,8 +1965,8 @@ func (a *Association) handleChunk(p *packet, c chunk) error {
var err error

if _, err = c.check(); err != nil {
return errors.Wrap(err, "failed validating chunk")
// TODO: Create ABORT
a.log.Errorf("[ %s ] failed validating chunk: %s ", a.name, err)
return nil
}

switch c := c.(type) {
Expand All @@ -1979,7 +1981,7 @@ func (a *Association) handleChunk(p *packet, c chunk) error {
for _, e := range c.errorCauses {
errStr += fmt.Sprintf("(%s)", e)
}
a.log.Debugf("[%s] Abort chunk, with following errors: %s", a.name, errStr)
return fmt.Errorf("[%s] Abort chunk, with following errors: %s", a.name, errStr)

case *chunkError:
var errStr string
Expand Down Expand Up @@ -2013,8 +2015,10 @@ func (a *Association) handleChunk(p *packet, c chunk) error {
err = errors.Errorf("unhandled chunk type")
}

// Log and return, the only condition that is fatal is a ABORT chunk
if err != nil {
return err
a.log.Errorf("Failed to handle chunk: %v", err)
return nil
}

if len(packets) > 0 {
Expand Down

0 comments on commit 807f7b9

Please sign in to comment.