forked from slackhq/nebula
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support startup without a tun device (slackhq#269)
This commit adds support for Nebula to be started without creating a tun device. A node started in this mode still has a full "control plane", but no effective "data plane". Its use is suited to a lighthouse that has no need to partake in the mesh VPN. Consequently, creation of the tun device is the only reason nebula neesd to be started with elevated privileged, so this example lighthouse can also be run as a non-root user.
- Loading branch information
1 parent
7b3f23d
commit 9b8b3c4
Showing
3 changed files
with
82 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
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) 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() | ||
} |