allow router to be started w/o capture/inject interface
useful for testing of the control plane
This commit is contained in:
1 parent
e33d2eaf8e
commit
e97a3f88aa
2 files changed
+25
-15
No files matched your search
+16
-7
@@ -73,17 +73,24 @@ func NewRouter(iface *net.Interface, name PeerName, nickName string, password []
|
|||||||
|
|
||||||
func (router *Router) Start() {
|
func (router *Router) Start() {
|
||||||
// we need two pcap handles since they aren't thread-safe
|
// we need two pcap handles since they aren't thread-safe
|
||||||
pio, err := NewPcapIO(router.Iface.Name, router.BufSz)
|
var pio PacketSourceSink
|
||||||
checkFatal(err)
|
var po PacketSink
|
||||||
po, err := NewPcapO(router.Iface.Name)
|
var err error
|
||||||
checkFatal(err)
|
if router.Iface != nil {
|
||||||
|
pio, err = NewPcapIO(router.Iface.Name, router.BufSz)
|
||||||
|
checkFatal(err)
|
||||||
|
po, err = NewPcapO(router.Iface.Name)
|
||||||
|
checkFatal(err)
|
||||||
|
}
|
||||||
router.Ourself.Start()
|
router.Ourself.Start()
|
||||||
router.Macs.Start()
|
router.Macs.Start()
|
||||||
router.Routes.Start()
|
router.Routes.Start()
|
||||||
router.ConnectionMaker.Start()
|
router.ConnectionMaker.Start()
|
||||||
router.UDPListener = router.listenUDP(Port, po)
|
router.UDPListener = router.listenUDP(Port, po)
|
||||||
router.listenTCP(Port)
|
router.listenTCP(Port)
|
||||||
router.sniff(pio)
|
if pio != nil {
|
||||||
|
router.sniff(pio)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (router *Router) UsingPassword() bool {
|
func (router *Router) UsingPassword() bool {
|
||||||
@@ -310,8 +317,10 @@ func (router *Router) handleUDPPacketFunc(dec *EthernetDecoder, sender *net.UDPA
|
|||||||
if router.Macs.Enter(srcMac, srcPeer) {
|
if router.Macs.Enter(srcMac, srcPeer) {
|
||||||
log.Println("Discovered remote MAC", srcMac, "at", srcPeer.FullName())
|
log.Println("Discovered remote MAC", srcMac, "at", srcPeer.FullName())
|
||||||
}
|
}
|
||||||
router.LogFrame("Injecting", frame, &dec.eth)
|
if po != nil {
|
||||||
checkWarn(po.WritePacket(frame))
|
router.LogFrame("Injecting", frame, &dec.eth)
|
||||||
|
checkWarn(po.WritePacket(frame))
|
||||||
|
}
|
||||||
|
|
||||||
dstPeer, found = router.Macs.Lookup(dstMac)
|
dstPeer, found = router.Macs.Lookup(dstMac)
|
||||||
if !found || dstPeer != router.Ourself.Peer {
|
if !found || dstPeer != router.Ourself.Peer {
|
||||||
|
|||||||
+9
-8
@@ -49,7 +49,7 @@ func main() {
|
|||||||
)
|
)
|
||||||
|
|
||||||
flag.BoolVar(&justVersion, "version", false, "print version and exit")
|
flag.BoolVar(&justVersion, "version", false, "print version and exit")
|
||||||
flag.StringVar(&ifaceName, "iface", "", "name of interface to read from")
|
flag.StringVar(&ifaceName, "iface", "", "name of interface to capture/inject from (disabled if left blank)")
|
||||||
flag.StringVar(&routerName, "name", "", "name of router (defaults to MAC)")
|
flag.StringVar(&routerName, "name", "", "name of router (defaults to MAC)")
|
||||||
flag.StringVar(&nickName, "nickname", "", "nickname of peer (defaults to hostname)")
|
flag.StringVar(&nickName, "nickname", "", "nickname of peer (defaults to hostname)")
|
||||||
flag.StringVar(&password, "password", "", "network password")
|
flag.StringVar(&password, "password", "", "network password")
|
||||||
@@ -77,13 +77,14 @@ func main() {
|
|||||||
log.Println("Command line options:", options)
|
log.Println("Command line options:", options)
|
||||||
log.Println("Command line peers:", peers)
|
log.Println("Command line peers:", peers)
|
||||||
|
|
||||||
if ifaceName == "" {
|
var err error
|
||||||
fmt.Println("Missing required parameter 'iface'")
|
|
||||||
os.Exit(1)
|
var iface *net.Interface
|
||||||
}
|
if ifaceName != "" {
|
||||||
iface, err := weavenet.EnsureInterface(ifaceName, wait)
|
iface, err = weavenet.EnsureInterface(ifaceName, wait)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if routerName == "" {
|
if routerName == "" {
|
||||||
|
|||||||
Reference in new issue
Block a user