Skip to content

Commit

Permalink
Fix action type
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed Mar 24, 2023
1 parent f0c27d0 commit ca53ccf
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 22 deletions.
4 changes: 2 additions & 2 deletions gvisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
31 changes: 17 additions & 14 deletions route.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,37 @@ import (
type ActionType = uint8

const (
ActionTypeReturn ActionType = iota
ActionTypeReject
ActionTypeUnknown ActionType = iota
ActionTypeReturn
ActionTypeBlock
ActionTypeDirect
)

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:
return 0, E.New("unknown action: ", action)
}
}

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)
}
}

Expand Down Expand Up @@ -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
}

Expand Down
12 changes: 6 additions & 6 deletions system.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit ca53ccf

Please sign in to comment.