mirror of
https://github.com/gravitl/netmaker.git
synced 2025-11-01 12:42:42 +08:00
forward unknown pkts to all interfaces
This commit is contained in:
@@ -104,6 +104,7 @@ func GetPeersForProxy(node *models.Node, onlyPeers bool) (manager.ManagerPayload
|
||||
peerConfMap[peer.PublicKey] = manager.PeerConf{
|
||||
IsRelayed: true,
|
||||
RelayedTo: relayTo,
|
||||
Address: peer.PrimaryAddress(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ var WgIFaceMap = make(map[string]map[string]*Conn)
|
||||
|
||||
var PeerKeyHashMap = make(map[string]RemotePeer)
|
||||
|
||||
var WgIfaceKeyMap = make(map[string]struct{})
|
||||
var WgIfaceKeyMap = make(map[string]RemotePeer)
|
||||
|
||||
var RelayPeerMap = make(map[string]map[string]RemotePeer)
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/gravitl/netmaker/nm-proxy/common"
|
||||
"github.com/gravitl/netmaker/nm-proxy/packet"
|
||||
peerpkg "github.com/gravitl/netmaker/nm-proxy/peer"
|
||||
"github.com/gravitl/netmaker/nm-proxy/proxy"
|
||||
"github.com/gravitl/netmaker/nm-proxy/wg"
|
||||
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
||||
)
|
||||
@@ -225,7 +226,16 @@ func (m *ManagerAction) AddInterfaceToProxy() error {
|
||||
return err
|
||||
}
|
||||
log.Printf("wg: %+v\n", wgInterface)
|
||||
|
||||
wgListenAddr, err := proxy.GetInterfaceListenAddr(wgInterface.Port)
|
||||
if err != nil {
|
||||
log.Println("failed to get wg listen addr: ", err)
|
||||
return err
|
||||
}
|
||||
common.WgIfaceKeyMap[fmt.Sprintf("%x", md5.Sum([]byte(wgInterface.Device.PublicKey.String())))] = common.RemotePeer{
|
||||
PeerKey: wgInterface.Device.PublicKey.String(),
|
||||
Interface: wgInterface.Name,
|
||||
Endpoint: wgListenAddr,
|
||||
}
|
||||
for _, peerI := range m.Payload.Peers {
|
||||
peerConf := m.Payload.PeerMap[peerI.PublicKey.String()]
|
||||
if peerI.Endpoint == nil && !(peerConf.IsAttachedExtClient || peerConf.IsExtClient) {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package peer
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
@@ -105,6 +104,6 @@ func AddNewPeer(wgInterface *wg.WGIface, peer *wgtypes.PeerConfig,
|
||||
common.WgIFaceMap[wgInterface.Name] = make(map[string]*common.Conn)
|
||||
common.WgIFaceMap[wgInterface.Name][peer.PublicKey.String()] = &peerConn
|
||||
}
|
||||
common.WgIfaceKeyMap[fmt.Sprintf("%x", md5.Sum([]byte(wgInterface.Device.PublicKey.String())))] = struct{}{}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -125,10 +125,23 @@ func (p *ProxyServer) Listen(ctx context.Context) {
|
||||
|
||||
}
|
||||
}
|
||||
continue
|
||||
|
||||
}
|
||||
// forward to all interfaces
|
||||
for _, ifaceCfg := range common.WgIfaceKeyMap {
|
||||
log.Println("###--------> Forwarding Unknown PKT to ", ifaceCfg.Interface)
|
||||
conn, err := net.DialUDP("udp", source, ifaceCfg.Endpoint)
|
||||
if err == nil {
|
||||
_, err := conn.Write(buffer[:n])
|
||||
if err != nil {
|
||||
log.Println("Failed to forward the unknown pkt to ifcace: ", ifaceCfg.Interface, err)
|
||||
}
|
||||
conn.Close()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user