diff --git a/gvisor.go b/gvisor.go index 972302a..81e8efd 100644 --- a/gvisor.go +++ b/gvisor.go @@ -175,7 +175,7 @@ func (t *GVisor) Start() error { } }) switch actionType := action.(type) { - case *ActionReject: + case *ActionBlock: // TODO: send icmp unreachable return true case *ActionDirect: @@ -238,7 +238,7 @@ func (t *GVisor) Start() error { } }) switch actionType := action.(type) { - case *ActionReject: + case *ActionBlock: // TODO: send icmp unreachable return true case *ActionDirect: diff --git a/route.go b/route.go index 91c91a5..0ebf267 100644 --- a/route.go +++ b/route.go @@ -9,8 +9,9 @@ import ( type ActionType = uint8 const ( - ActionTypeReturn ActionType = iota - ActionTypeReject + ActionTypeUnknown ActionType = iota + ActionTypeReturn + ActionTypeBlock ActionTypeDirect ) @@ -18,8 +19,8 @@ func ParseActionType(action string) (ActionType, error) { switch action { case "return": return ActionTypeReturn, nil - case "reject": - return ActionTypeReject, nil + case "block": + return ActionTypeBlock, nil case "direct": return ActionTypeDirect, nil default: @@ -27,16 +28,18 @@ func ParseActionType(action string) (ActionType, error) { } } -func ActionTypeName(actionType ActionType) string { +func ActionTypeName(actionType ActionType) (string, error) { switch actionType { + case ActionTypeUnknown: + return "", nil case ActionTypeReturn: - return "return" - case ActionTypeReject: - return "reject" + return "return", nil + case ActionTypeBlock: + return "block", nil case ActionTypeDirect: - return "direct" + return "direct", nil default: - return "unknown" + return "", E.New("unknown action: ", actionType) } } @@ -70,13 +73,13 @@ func (r *ActionReturn) Timeout() bool { return false } -type ActionReject struct{} +type ActionBlock struct{} -func (r *ActionReject) ActionType() ActionType { - return ActionTypeReject +func (r *ActionBlock) ActionType() ActionType { + return ActionTypeBlock } -func (r *ActionReject) Timeout() bool { +func (r *ActionBlock) Timeout() bool { return false } diff --git a/system.go b/system.go index e3e77eb..a5359d5 100644 --- a/system.go +++ b/system.go @@ -257,7 +257,7 @@ func (s *System) processIPv4TCP(packet clashtcpip.IPv4Packet, header clashtcpip. return s.router.RouteConnection(session, &systemTCPDirectPacketWriter4{s.tun, source}) }) switch actionType := action.(type) { - case *ActionReject: + case *ActionBlock: // TODO: send ICMP unreachable return nil case *ActionDirect: @@ -298,7 +298,7 @@ func (s *System) processIPv6TCP(packet clashtcpip.IPv6Packet, header clashtcpip. return s.router.RouteConnection(session, &systemTCPDirectPacketWriter6{s.tun, source}) }) switch actionType := action.(type) { - case *ActionReject: + case *ActionBlock: // TODO: send RST return nil case *ActionDirect: @@ -336,7 +336,7 @@ func (s *System) processIPv4UDP(packet clashtcpip.IPv4Packet, header clashtcpip. return s.router.RouteConnection(routeSession, &systemUDPDirectPacketWriter4{s.tun, source}) }) switch actionType := action.(type) { - case *ActionReject: + case *ActionBlock: // TODO: send icmp unreachable return nil case *ActionDirect: @@ -374,7 +374,7 @@ func (s *System) processIPv6UDP(packet clashtcpip.IPv6Packet, header clashtcpip. return s.router.RouteConnection(routeSession, &systemUDPDirectPacketWriter6{s.tun, source}) }) switch actionType := action.(type) { - case *ActionReject: + case *ActionBlock: // TODO: send icmp unreachable return nil 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()}) }) switch actionType := action.(type) { - case *ActionReject: + case *ActionBlock: // TODO: send icmp unreachable return nil 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()}) }) switch actionType := action.(type) { - case *ActionReject: + case *ActionBlock: // TODO: send icmp unreachable return nil case *ActionDirect: