Fix action type
This commit is contained in:
parent
f0c27d037c
commit
ca53ccf346
3 changed files with 25 additions and 22 deletions
|
|
@ -175,7 +175,7 @@ func (t *GVisor) Start() error {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
switch actionType := action.(type) {
|
switch actionType := action.(type) {
|
||||||
case *ActionReject:
|
case *ActionBlock:
|
||||||
// TODO: send icmp unreachable
|
// TODO: send icmp unreachable
|
||||||
return true
|
return true
|
||||||
case *ActionDirect:
|
case *ActionDirect:
|
||||||
|
|
@ -238,7 +238,7 @@ func (t *GVisor) Start() error {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
switch actionType := action.(type) {
|
switch actionType := action.(type) {
|
||||||
case *ActionReject:
|
case *ActionBlock:
|
||||||
// TODO: send icmp unreachable
|
// TODO: send icmp unreachable
|
||||||
return true
|
return true
|
||||||
case *ActionDirect:
|
case *ActionDirect:
|
||||||
|
|
|
||||||
31
route.go
31
route.go
|
|
@ -9,8 +9,9 @@ import (
|
||||||
type ActionType = uint8
|
type ActionType = uint8
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ActionTypeReturn ActionType = iota
|
ActionTypeUnknown ActionType = iota
|
||||||
ActionTypeReject
|
ActionTypeReturn
|
||||||
|
ActionTypeBlock
|
||||||
ActionTypeDirect
|
ActionTypeDirect
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -18,8 +19,8 @@ func ParseActionType(action string) (ActionType, error) {
|
||||||
switch action {
|
switch action {
|
||||||
case "return":
|
case "return":
|
||||||
return ActionTypeReturn, nil
|
return ActionTypeReturn, nil
|
||||||
case "reject":
|
case "block":
|
||||||
return ActionTypeReject, nil
|
return ActionTypeBlock, nil
|
||||||
case "direct":
|
case "direct":
|
||||||
return ActionTypeDirect, nil
|
return ActionTypeDirect, nil
|
||||||
default:
|
default:
|
||||||
|
|
@ -27,16 +28,18 @@ func ParseActionType(action string) (ActionType, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ActionTypeName(actionType ActionType) string {
|
func ActionTypeName(actionType ActionType) (string, error) {
|
||||||
switch actionType {
|
switch actionType {
|
||||||
|
case ActionTypeUnknown:
|
||||||
|
return "", nil
|
||||||
case ActionTypeReturn:
|
case ActionTypeReturn:
|
||||||
return "return"
|
return "return", nil
|
||||||
case ActionTypeReject:
|
case ActionTypeBlock:
|
||||||
return "reject"
|
return "block", nil
|
||||||
case ActionTypeDirect:
|
case ActionTypeDirect:
|
||||||
return "direct"
|
return "direct", nil
|
||||||
default:
|
default:
|
||||||
return "unknown"
|
return "", E.New("unknown action: ", actionType)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -70,13 +73,13 @@ func (r *ActionReturn) Timeout() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
type ActionReject struct{}
|
type ActionBlock struct{}
|
||||||
|
|
||||||
func (r *ActionReject) ActionType() ActionType {
|
func (r *ActionBlock) ActionType() ActionType {
|
||||||
return ActionTypeReject
|
return ActionTypeBlock
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *ActionReject) Timeout() bool {
|
func (r *ActionBlock) Timeout() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
12
system.go
12
system.go
|
|
@ -257,7 +257,7 @@ func (s *System) processIPv4TCP(packet clashtcpip.IPv4Packet, header clashtcpip.
|
||||||
return s.router.RouteConnection(session, &systemTCPDirectPacketWriter4{s.tun, source})
|
return s.router.RouteConnection(session, &systemTCPDirectPacketWriter4{s.tun, source})
|
||||||
})
|
})
|
||||||
switch actionType := action.(type) {
|
switch actionType := action.(type) {
|
||||||
case *ActionReject:
|
case *ActionBlock:
|
||||||
// TODO: send ICMP unreachable
|
// TODO: send ICMP unreachable
|
||||||
return nil
|
return nil
|
||||||
case *ActionDirect:
|
case *ActionDirect:
|
||||||
|
|
@ -298,7 +298,7 @@ func (s *System) processIPv6TCP(packet clashtcpip.IPv6Packet, header clashtcpip.
|
||||||
return s.router.RouteConnection(session, &systemTCPDirectPacketWriter6{s.tun, source})
|
return s.router.RouteConnection(session, &systemTCPDirectPacketWriter6{s.tun, source})
|
||||||
})
|
})
|
||||||
switch actionType := action.(type) {
|
switch actionType := action.(type) {
|
||||||
case *ActionReject:
|
case *ActionBlock:
|
||||||
// TODO: send RST
|
// TODO: send RST
|
||||||
return nil
|
return nil
|
||||||
case *ActionDirect:
|
case *ActionDirect:
|
||||||
|
|
@ -336,7 +336,7 @@ func (s *System) processIPv4UDP(packet clashtcpip.IPv4Packet, header clashtcpip.
|
||||||
return s.router.RouteConnection(routeSession, &systemUDPDirectPacketWriter4{s.tun, source})
|
return s.router.RouteConnection(routeSession, &systemUDPDirectPacketWriter4{s.tun, source})
|
||||||
})
|
})
|
||||||
switch actionType := action.(type) {
|
switch actionType := action.(type) {
|
||||||
case *ActionReject:
|
case *ActionBlock:
|
||||||
// TODO: send icmp unreachable
|
// TODO: send icmp unreachable
|
||||||
return nil
|
return nil
|
||||||
case *ActionDirect:
|
case *ActionDirect:
|
||||||
|
|
@ -374,7 +374,7 @@ func (s *System) processIPv6UDP(packet clashtcpip.IPv6Packet, header clashtcpip.
|
||||||
return s.router.RouteConnection(routeSession, &systemUDPDirectPacketWriter6{s.tun, source})
|
return s.router.RouteConnection(routeSession, &systemUDPDirectPacketWriter6{s.tun, source})
|
||||||
})
|
})
|
||||||
switch actionType := action.(type) {
|
switch actionType := action.(type) {
|
||||||
case *ActionReject:
|
case *ActionBlock:
|
||||||
// TODO: send icmp unreachable
|
// TODO: send icmp unreachable
|
||||||
return nil
|
return nil
|
||||||
case *ActionDirect:
|
case *ActionDirect:
|
||||||
|
|
@ -407,7 +407,7 @@ func (s *System) processIPv4ICMP(packet clashtcpip.IPv4Packet, header clashtcpip
|
||||||
return s.router.RouteConnection(routeSession, &systemICMPDirectPacketWriter4{s.tun, packet.SourceIP()})
|
return s.router.RouteConnection(routeSession, &systemICMPDirectPacketWriter4{s.tun, packet.SourceIP()})
|
||||||
})
|
})
|
||||||
switch actionType := action.(type) {
|
switch actionType := action.(type) {
|
||||||
case *ActionReject:
|
case *ActionBlock:
|
||||||
// TODO: send icmp unreachable
|
// TODO: send icmp unreachable
|
||||||
return nil
|
return nil
|
||||||
case *ActionDirect:
|
case *ActionDirect:
|
||||||
|
|
@ -435,7 +435,7 @@ func (s *System) processIPv6ICMP(packet clashtcpip.IPv6Packet, header clashtcpip
|
||||||
return s.router.RouteConnection(routeSession, &systemICMPDirectPacketWriter6{s.tun, packet.SourceIP()})
|
return s.router.RouteConnection(routeSession, &systemICMPDirectPacketWriter6{s.tun, packet.SourceIP()})
|
||||||
})
|
})
|
||||||
switch actionType := action.(type) {
|
switch actionType := action.(type) {
|
||||||
case *ActionReject:
|
case *ActionBlock:
|
||||||
// TODO: send icmp unreachable
|
// TODO: send icmp unreachable
|
||||||
return nil
|
return nil
|
||||||
case *ActionDirect:
|
case *ActionDirect:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue