@@ -35,29 +35,29 @@ import (
3535
3636type VpnServer struct {
3737 // config
38- cfg ServerConfig
38+ cfg ServerConfig
3939 // interface
40- iface * water.Interface
40+ iface * water.Interface
4141 // subnet
42- ipnet * net.IPNet
42+ ipnet * net.IPNet
4343 // IP Pool
44- ippool * VpnIpPool
44+ ippool * VpnIpPool
4545 // client peers, key is the mac address, value is a HopPeer record
4646
4747 // Registered clients
48- clients map [string ]* connection
48+ clients map [string ]* connection
4949
5050 // Register requests
51- register chan * connection
51+ register chan * connection
5252
5353 // Unregister requests
5454 unregister chan * connection
5555
56- outData * Data
56+ outData * Data
5757
58- inData chan * Data
58+ inData chan * Data
5959
60- toIface chan []byte
60+ toIface chan []byte
6161}
6262
6363func NewServer (cfg ServerConfig ) error {
@@ -176,24 +176,40 @@ func (srv *VpnServer) handleInterface() {
176176 break
177177 }
178178 header , _ := ipv4 .ParseHeader (packet [:plen ])
179- logger .Debug ("Sending to remote: " , header )
180-
179+ logger .Debug ("Try sending: " , header )
181180 clientIP := header .Dst .String ()
182181 client , ok := srv .clients [clientIP ]
183182 if ok {
183+ if ! srv .cfg .Interconnection {
184+ if srv .isConnectionBetweenClients (header ) {
185+ logger .Info ("Drop connection betwenn " , header .Src , header .Dst )
186+ continue
187+ }
188+ }
189+
184190 logger .Debug ("Sending to client: " , client .ipAddress )
185191 client .data <- & Data {
186192 ConnectionState : STATE_CONNECTED ,
187193 Payload : packet [:plen ],
188194 }
195+
189196 } else {
190- logger .Error ("Client not found " , clientIP )
197+ logger .Warning ("Client not found " , clientIP )
191198 }
192199
193200 }
194201 }()
195202}
196203
204+ func (srv * VpnServer ) isConnectionBetweenClients (header * ipv4.Header ) bool {
205+
206+ if (header .Src .String () != header .Dst .String () && header .Src .String () != srv .ipnet .IP .String () && srv .ippool .subnet .Contains (header .Dst )) {
207+ return true
208+ }
209+
210+ return false
211+ }
212+
197213func (srv * VpnServer ) cleanUp () {
198214
199215 c := make (chan os.Signal , 1 )
0 commit comments