@@ -168,7 +168,8 @@ type Combined struct {
168
168
enableLocalTraffic bool
169
169
// list with the existing OS interfaces when VPN was connected.
170
170
// This is used at network changes to know when a new interface was inserted
171
- interfaces mapset.Set [string ]
171
+ interfaces mapset.Set [string ]
172
+ isFilesharePermitted bool
172
173
}
173
174
174
175
// NewCombined returns a ready made version of
@@ -1509,6 +1510,11 @@ func (netw *Combined) AllowFileshare(uniqueAddress meshnet.UniqueAddress) error
1509
1510
}
1510
1511
1511
1512
func (netw * Combined ) allowFileshare (publicKey string , address netip.Addr ) error {
1513
+ if ! netw .isFilesharePermitted {
1514
+ log .Println (internal .WarningPrefix , "fileshare is not permitted, can't add allow rules" )
1515
+ return nil
1516
+ }
1517
+
1512
1518
ruleName := publicKey + "-allow-fileshare-rule-" + address .String ()
1513
1519
rules := []firewall.Rule {{
1514
1520
Name : ruleName ,
@@ -1537,6 +1543,27 @@ func (netw *Combined) allowFileshare(publicKey string, address netip.Addr) error
1537
1543
return nil
1538
1544
}
1539
1545
1546
+ func (netw * Combined ) PermitFileshare () error {
1547
+ netw .mu .Lock ()
1548
+ defer netw .mu .Unlock ()
1549
+ if netw .isFilesharePermitted {
1550
+ return nil
1551
+ }
1552
+ netw .isFilesharePermitted = true
1553
+ return netw .allowFileshareAll ()
1554
+ }
1555
+
1556
+ func (netw * Combined ) allowFileshareAll () error {
1557
+ var allErrors []error
1558
+ for _ , peer := range netw .cfg .Peers {
1559
+ if peer .DoIAllowFileshare {
1560
+ err := netw .allowFileshare (peer .PublicKey , peer .Address )
1561
+ allErrors = append (allErrors , err )
1562
+ }
1563
+ }
1564
+ return errors .Join (allErrors ... )
1565
+ }
1566
+
1540
1567
func (netw * Combined ) undenyDNS () error {
1541
1568
ruleName := "deny-private-dns"
1542
1569
@@ -1608,7 +1635,15 @@ func (netw *Combined) blockIncoming(uniqueAddress meshnet.UniqueAddress) error {
1608
1635
func (netw * Combined ) BlockFileshare (uniqueAddress meshnet.UniqueAddress ) error {
1609
1636
netw .mu .Lock ()
1610
1637
defer netw .mu .Unlock ()
1611
- ruleName := uniqueAddress .UID + "-allow-fileshare-rule-" + uniqueAddress .Address .String ()
1638
+ return netw .blockFileshare (uniqueAddress .UID , uniqueAddress .Address )
1639
+ }
1640
+
1641
+ func (netw * Combined ) blockFileshare (publicKey string , address netip.Addr ) error {
1642
+ if ! netw .isFilesharePermitted {
1643
+ log .Println (internal .WarningPrefix , "fileshare is already forbidden" )
1644
+ return nil
1645
+ }
1646
+ ruleName := publicKey + "-allow-fileshare-rule-" + address .String ()
1612
1647
return netw .removeRule (ruleName )
1613
1648
}
1614
1649
@@ -1627,6 +1662,25 @@ func (netw *Combined) removeRule(ruleName string) error {
1627
1662
return nil
1628
1663
}
1629
1664
1665
+ func (netw * Combined ) ForbidFileshare () error {
1666
+ netw .mu .Lock ()
1667
+ defer netw .mu .Unlock ()
1668
+ if ! netw .isFilesharePermitted {
1669
+ return nil
1670
+ }
1671
+ defer func () { netw .isFilesharePermitted = false }()
1672
+ return netw .blockFileshareAll ()
1673
+ }
1674
+
1675
+ func (netw * Combined ) blockFileshareAll () error {
1676
+ var allErrors []error
1677
+ for _ , peer := range netw .cfg .Peers {
1678
+ err := netw .blockFileshare (peer .PublicKey , peer .Address )
1679
+ allErrors = append (allErrors , err )
1680
+ }
1681
+ return errors .Join (allErrors ... )
1682
+ }
1683
+
1630
1684
func getHostsFromConfig (peers mesh.MachinePeers ) dns.Hosts {
1631
1685
hosts := make (dns.Hosts , 0 , len (peers ))
1632
1686
for _ , peer := range peers {
0 commit comments