mirror of
https://github.com/slackhq/nebula.git
synced 2026-02-16 01:34:22 +01:00
skeleton to handle other tunless packets
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
|||||||
|
|
||||||
"github.com/rcrowley/go-metrics"
|
"github.com/rcrowley/go-metrics"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
"github.com/slackhq/nebula/firewall"
|
||||||
"github.com/slackhq/nebula/iputil"
|
"github.com/slackhq/nebula/iputil"
|
||||||
"github.com/slackhq/nebula/routing"
|
"github.com/slackhq/nebula/routing"
|
||||||
)
|
)
|
||||||
@@ -87,21 +88,45 @@ func (t *disabledTun) handleICMPEchoRequest(b []byte) bool {
|
|||||||
default:
|
default:
|
||||||
t.l.Debugf("tun_disabled: dropped ICMP Echo Reply response")
|
t.l.Debugf("tun_disabled: dropped ICMP Echo Reply response")
|
||||||
}
|
}
|
||||||
|
if t.l.Level >= logrus.DebugLevel {
|
||||||
|
t.l.WithField("raw", prettyPacket(b)).Debugf("Disabled tun responded to ICMP Echo Request")
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *disabledTun) handleOtherPackets(b []byte) error {
|
||||||
|
fp := &firewall.Packet{}
|
||||||
|
err := firewall.NewPacket(b, true, fp)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
out := make([]byte, len(b)) //todo do something!
|
||||||
|
|
||||||
|
// attempt to write it, but don't block
|
||||||
|
select {
|
||||||
|
case t.read <- out:
|
||||||
|
default:
|
||||||
|
t.l.Debugf("tun_disabled: dropped reply")
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
func (t *disabledTun) Write(b []byte) (int, error) {
|
func (t *disabledTun) Write(b []byte) (int, error) {
|
||||||
t.rx.Inc(1)
|
t.rx.Inc(1)
|
||||||
|
|
||||||
// Check for ICMP Echo Request before spending time doing the full parsing
|
|
||||||
if t.handleICMPEchoRequest(b) {
|
if t.handleICMPEchoRequest(b) {
|
||||||
if t.l.Level >= logrus.DebugLevel {
|
return len(b), nil
|
||||||
t.l.WithField("raw", prettyPacket(b)).Debugf("Disabled tun responded to ICMP Echo Request")
|
|
||||||
}
|
}
|
||||||
} else if t.l.Level >= logrus.DebugLevel {
|
if err := t.handleOtherPackets(b); err != nil {
|
||||||
|
if t.l.Level >= logrus.DebugLevel {
|
||||||
|
t.l.WithField("raw", prettyPacket(b)).WithError(err).Debugf("Disabled tun failed to respond")
|
||||||
|
}
|
||||||
|
return len(b), nil
|
||||||
|
}
|
||||||
|
if t.l.Level >= logrus.DebugLevel {
|
||||||
t.l.WithField("raw", prettyPacket(b)).Debugf("Disabled tun received unexpected payload")
|
t.l.WithField("raw", prettyPacket(b)).Debugf("Disabled tun received unexpected payload")
|
||||||
}
|
}
|
||||||
|
|
||||||
return len(b), nil
|
return len(b), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user