mirror of
https://github.com/slackhq/nebula.git
synced 2025-11-10 23:53:58 +01:00
This change is for Linux only. Previously, when running with multiple tun.routines, we would only have one file descriptor. This change instead sets IFF_MULTI_QUEUE and opens a file descriptor for each routine. This allows us to process with multiple threads while preventing out of order packet reception issues. To attempt to distribute the flows across the queues, we try to write to the tun/UDP queue that corresponds with the one we read from. So if we read a packet from tun queue "2", we will write the outgoing encrypted packet to UDP queue "2". Because of the nature of how multi queue works with flows, a given host tunnel will be sticky to a given routine (so if you try to performance benchmark by only using one tunnel between two hosts, you are only going to be using a max of one thread for each direction). Because this system works much better when we can correlate flows between the tun and udp routines, we are deprecating the undocumented "tun.routines" and "listen.routines" parameters and introducing a new "routines" parameter that sets the value for both. If you use the old undocumented parameters, the max of the values will be used and a warning logged. Co-authored-by: Nate Brown <nbrown.us@gmail.com>
79 lines
1.3 KiB
Go
79 lines
1.3 KiB
Go
package nebula
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"net"
|
|
"strings"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
type disabledTun struct {
|
|
block chan struct{}
|
|
cidr *net.IPNet
|
|
logger *log.Logger
|
|
}
|
|
|
|
func newDisabledTun(cidr *net.IPNet, l *log.Logger) *disabledTun {
|
|
return &disabledTun{
|
|
cidr: cidr,
|
|
block: make(chan struct{}),
|
|
logger: l,
|
|
}
|
|
}
|
|
|
|
func (*disabledTun) Activate() error {
|
|
return nil
|
|
}
|
|
|
|
func (t *disabledTun) CidrNet() *net.IPNet {
|
|
return t.cidr
|
|
}
|
|
|
|
func (*disabledTun) DeviceName() string {
|
|
return "disabled"
|
|
}
|
|
|
|
func (t *disabledTun) Read(b []byte) (int, error) {
|
|
<-t.block
|
|
return 0, io.EOF
|
|
}
|
|
|
|
func (t *disabledTun) Write(b []byte) (int, error) {
|
|
t.logger.WithField("raw", prettyPacket(b)).Debugf("Disabled tun received unexpected payload")
|
|
return len(b), nil
|
|
}
|
|
|
|
func (t *disabledTun) WriteRaw(b []byte) error {
|
|
_, err := t.Write(b)
|
|
return err
|
|
}
|
|
|
|
func (t *disabledTun) NewMultiQueueReader() (io.ReadWriteCloser, error) {
|
|
return t, nil
|
|
}
|
|
|
|
func (t *disabledTun) Close() error {
|
|
if t.block != nil {
|
|
close(t.block)
|
|
t.block = nil
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type prettyPacket []byte
|
|
|
|
func (p prettyPacket) String() string {
|
|
var s strings.Builder
|
|
|
|
for i, b := range p {
|
|
if i > 0 && i%8 == 0 {
|
|
s.WriteString(" ")
|
|
}
|
|
s.WriteString(fmt.Sprintf("%02x ", b))
|
|
}
|
|
|
|
return s.String()
|
|
}
|