Skip to content

Commit

Permalink
AC: add PASS_KNOCKIP_WITH_RANGE mode, which also includes a range of …
Browse files Browse the repository at this point in the history
…IP addresses derived from target address. Default behavior is just including the knock IP.
  • Loading branch information
craftleon committed Dec 23, 2024
1 parent 51d8117 commit d8245bc
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions ac/msghandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
// IP pass mode
const (
PASS_KNOCK_IP = iota
PASS_KNOCKIP_WITH_RANGE
PASS_PRE_ACCESS_IP
)

Expand Down Expand Up @@ -126,9 +127,14 @@ func (a *UdpAC) HandleAccessControl(au *common.AgentUser, srcAddrs []*common.Net
}
}

switch a.IpPassMode() {
ipPassMode := a.IpPassMode()
switch ipPassMode {
// pass the knock ip immediately
case PASS_KNOCKIP_WITH_RANGE:
fallthrough
case PASS_KNOCK_IP:
fallthrough
default:
for _, srcAddr := range srcAddrs {
var ipType utils.IPTYPE
var ipNet *net.IPNet
Expand Down Expand Up @@ -192,8 +198,8 @@ func (a *UdpAC) HandleAccessControl(au *common.AgentUser, srcAddrs []*common.Net
}
}

// add tempset
if ipNet != nil {
// add tempset for the adjacent 128 (25bit netmask ipv4, 121bit netmask ipv6) addresses derived from the target IP address
if ipPassMode == PASS_KNOCKIP_WITH_RANGE && ipNet != nil {
netStr := ipNet.String()
if len(dstAddr.Protocol) == 0 || dstAddr.Protocol == "tcp" || dstAddr.Protocol == "any" {
netHashStr := fmt.Sprintf("%s,%d", netStr, dstAddr.Port)
Expand Down Expand Up @@ -221,8 +227,6 @@ func (a *UdpAC) HandleAccessControl(au *common.AgentUser, srcAddrs []*common.Net

// return temporary listened port(s) and nhp access token, then pass the real ip when agent sends access message
case PASS_PRE_ACCESS_IP:
fallthrough
default:
// ac open a temporary tcp or udp port for access
dstIp := net.ParseIP(dstAddrs[0].Ip)
if dstIp == nil {
Expand Down

0 comments on commit d8245bc

Please sign in to comment.