mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-05 16:57:51 +08:00
packet sniffer changes
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -150,25 +149,25 @@ func startGoRoutines(wg *sync.WaitGroup) context.CancelFunc {
|
||||
|
||||
go func(networks []string) {
|
||||
|
||||
for _, network := range networks {
|
||||
logger.Log(0, "Collecting interface and peers info to configure proxy...")
|
||||
cfg := config.ClientConfig{}
|
||||
cfg.Network = network
|
||||
cfg.ReadConfig()
|
||||
node, err := GetNodeInfo(&cfg)
|
||||
if err != nil {
|
||||
log.Println("Failed to get node info: ", err)
|
||||
continue
|
||||
}
|
||||
ProxyMgmChan <- &manager.ManagerAction{
|
||||
Action: manager.AddInterface,
|
||||
Payload: manager.ManagerPayload{
|
||||
InterfaceName: node.Node.Interface,
|
||||
Peers: node.Peers,
|
||||
},
|
||||
}
|
||||
// for _, network := range networks {
|
||||
// logger.Log(0, "Collecting interface and peers info to configure proxy...")
|
||||
// cfg := config.ClientConfig{}
|
||||
// cfg.Network = network
|
||||
// cfg.ReadConfig()
|
||||
// node, err := GetNodeInfo(&cfg)
|
||||
// if err != nil {
|
||||
// log.Println("Failed to get node info: ", err)
|
||||
// continue
|
||||
// }
|
||||
// ProxyMgmChan <- &manager.ManagerAction{
|
||||
// Action: manager.AddInterface,
|
||||
// Payload: manager.ManagerPayload{
|
||||
// InterfaceName: node.Node.Interface,
|
||||
// Peers: node.Peers,
|
||||
// },
|
||||
// }
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
}(networks)
|
||||
return cancel
|
||||
|
@@ -226,7 +226,7 @@ func (m *ManagerAction) AddInterfaceToProxy() error {
|
||||
|
||||
for _, peerI := range m.Payload.Peers {
|
||||
peerConf := m.Payload.PeerMap[peerI.PublicKey.String()]
|
||||
if peerI.Endpoint == nil && (!peerConf.IsAttachedExtClient || !peerConf.IsExtClient) {
|
||||
if peerI.Endpoint == nil && !(peerConf.IsAttachedExtClient || peerConf.IsExtClient) {
|
||||
log.Println("Endpoint nil for peer: ", peerI.PublicKey.String())
|
||||
continue
|
||||
}
|
||||
|
@@ -42,17 +42,19 @@ func ExtractInfo(buffer []byte, n int) (int, string, string) {
|
||||
}
|
||||
|
||||
func StartSniffer(ifaceName string, extClient string) {
|
||||
log.Println("Starting Packet Sniffer for iface: ", ifaceName)
|
||||
var (
|
||||
snapshotLen int32 = 1024
|
||||
promiscuous bool = false
|
||||
err error
|
||||
timeout time.Duration = 30 * time.Second
|
||||
timeout time.Duration = 1 * time.Microsecond
|
||||
handle *pcap.Handle
|
||||
)
|
||||
// Open device
|
||||
handle, err = pcap.OpenLive(ifaceName, snapshotLen, promiscuous, timeout)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
log.Println("failed to start sniffer for iface: ", ifaceName, err)
|
||||
return
|
||||
}
|
||||
defer handle.Close()
|
||||
|
||||
|
@@ -60,13 +60,13 @@ func (p *Proxy) ProxyToRemote() {
|
||||
}
|
||||
peers := common.WgIFaceMap[p.Config.WgInterface.Name]
|
||||
if peerI, ok := peers[p.Config.RemoteKey]; ok {
|
||||
//var srcPeerKeyHash, dstPeerKeyHash string
|
||||
buf, n, _, _ = packet.ProcessPacketBeforeSending(buf, n, peerI.Config.LocalKey, peerI.Config.Key)
|
||||
var srcPeerKeyHash, dstPeerKeyHash string
|
||||
buf, n, srcPeerKeyHash, dstPeerKeyHash = packet.ProcessPacketBeforeSending(buf, n, peerI.Config.LocalKey, peerI.Config.Key)
|
||||
if err != nil {
|
||||
log.Println("failed to process pkt before sending: ", err)
|
||||
}
|
||||
// log.Printf("PROXING TO REMOTE!!!---> %s >>>>> %s [[ SrcPeerHash: %s, DstPeerHash: %s ]]\n",
|
||||
// server.NmProxyServer.Server.LocalAddr().String(), p.RemoteConn.String(), srcPeerKeyHash, dstPeerKeyHash)
|
||||
log.Printf("PROXING TO REMOTE!!!---> %s >>>>> %s [[ SrcPeerHash: %s, DstPeerHash: %s ]]\n",
|
||||
server.NmProxyServer.Server.LocalAddr().String(), p.RemoteConn.String(), srcPeerKeyHash, dstPeerKeyHash)
|
||||
} else {
|
||||
log.Printf("Peer: %s not found in config\n", p.Config.RemoteKey)
|
||||
p.Cancel()
|
||||
|
@@ -2,6 +2,7 @@ package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"time"
|
||||
@@ -113,9 +114,9 @@ func (p *ProxyServer) Listen(ctx context.Context) {
|
||||
if peerInfo, ok := common.PeerKeyHashMap[srcPeerKeyHash]; ok {
|
||||
if peers, ok := common.WgIFaceMap[peerInfo.Interface]; ok {
|
||||
if peerI, ok := peers[peerInfo.PeerKey]; ok {
|
||||
// log.Printf("PROXING TO LOCAL!!!---> %s <<<< %s <<<<<<<< %s [[ RECV PKT [SRCKEYHASH: %s], [DSTKEYHASH: %s], SourceIP: [%s] ]]\n",
|
||||
// peerI.Proxy.LocalConn.RemoteAddr(), peerI.Proxy.LocalConn.LocalAddr(),
|
||||
// fmt.Sprintf("%s:%d", source.IP.String(), source.Port), srcPeerKeyHash, dstPeerKeyHash, source.IP.String())
|
||||
log.Printf("PROXING TO LOCAL!!!---> %s <<<< %s <<<<<<<< %s [[ RECV PKT [SRCKEYHASH: %s], [DSTKEYHASH: %s], SourceIP: [%s] ]]\n",
|
||||
peerI.Proxy.LocalConn.RemoteAddr(), peerI.Proxy.LocalConn.LocalAddr(),
|
||||
fmt.Sprintf("%s:%d", source.IP.String(), source.Port), srcPeerKeyHash, dstPeerKeyHash, source.IP.String())
|
||||
_, err = peerI.Proxy.LocalConn.Write(buffer[:n])
|
||||
if err != nil {
|
||||
log.Println("Failed to proxy to Wg local interface: ", err)
|
||||
|
Reference in New Issue
Block a user