-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Independent
source_ip_is_private
and ip_is_private
rules
- Loading branch information
1 parent
889f426
commit 218567b
Showing
10 changed files
with
149 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package route | ||
|
||
import ( | ||
"net/netip" | ||
|
||
"github.com/sagernet/sing-box/adapter" | ||
N "github.com/sagernet/sing/common/network" | ||
) | ||
|
||
var _ RuleItem = (*IPIsPrivateItem)(nil) | ||
|
||
type IPIsPrivateItem struct { | ||
isSource bool | ||
} | ||
|
||
func NewIPIsPrivateItem(isSource bool) *IPIsPrivateItem { | ||
return &IPIsPrivateItem{isSource} | ||
} | ||
|
||
func (r *IPIsPrivateItem) Match(metadata *adapter.InboundContext) bool { | ||
var destination netip.Addr | ||
if r.isSource { | ||
destination = metadata.Source.Addr | ||
} else { | ||
destination = metadata.Destination.Addr | ||
} | ||
if destination.IsValid() && !N.IsPublicAddr(destination) { | ||
return true | ||
} | ||
for _, destinationAddress := range metadata.DestinationAddresses { | ||
if !N.IsPublicAddr(destinationAddress) { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
func (r *IPIsPrivateItem) String() string { | ||
if r.isSource { | ||
return "source_ip_is_private=true" | ||
} else { | ||
return "ip_is_private=true" | ||
} | ||
} |