mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-04-30 17:38:41 +00:00
Fix: TFO AsIs bug (#452)
This commit is contained in:
parent
a9e11075d1
commit
b63049f404
7 changed files with 133 additions and 36 deletions
|
@ -17,3 +17,14 @@ func isUDPSocket(network string) bool {
|
|||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func (v *SocketConfig) ParseTFOValue() int {
|
||||
if v.Tfo == 0 {
|
||||
return -1
|
||||
}
|
||||
tfo := int(v.Tfo)
|
||||
if tfo < 0 {
|
||||
tfo = 0
|
||||
}
|
||||
return tfo
|
||||
}
|
||||
|
|
|
@ -15,12 +15,12 @@ const (
|
|||
|
||||
func applyOutboundSocketOptions(network string, address string, fd uintptr, config *SocketConfig) error {
|
||||
if isTCPSocket(network) {
|
||||
tfo := config.Tfo
|
||||
tfo := config.ParseTFOValue()
|
||||
if tfo > 0 {
|
||||
tfo = TCP_FASTOPEN_CLIENT
|
||||
}
|
||||
if tfo >= 0 {
|
||||
if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, TCP_FASTOPEN, int(tfo)); err != nil {
|
||||
if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, TCP_FASTOPEN, tfo); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -31,12 +31,12 @@ func applyOutboundSocketOptions(network string, address string, fd uintptr, conf
|
|||
|
||||
func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig) error {
|
||||
if isTCPSocket(network) {
|
||||
tfo := config.Tfo
|
||||
tfo := config.ParseTFOValue()
|
||||
if tfo > 0 {
|
||||
tfo = TCP_FASTOPEN_SERVER
|
||||
}
|
||||
if tfo >= 0 {
|
||||
if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, TCP_FASTOPEN, int(tfo)); err != nil {
|
||||
if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, TCP_FASTOPEN, tfo); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
|
@ -130,7 +130,7 @@ func applyOutboundSocketOptions(network string, address string, fd uintptr, conf
|
|||
}
|
||||
|
||||
if isTCPSocket(network) {
|
||||
tfo := int(config.Tfo)
|
||||
tfo := config.ParseTFOValue()
|
||||
if tfo > 0 {
|
||||
tfo = 1
|
||||
}
|
||||
|
@ -163,9 +163,10 @@ func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig)
|
|||
}
|
||||
}
|
||||
if isTCPSocket(network) {
|
||||
if config.Tfo >= 0 {
|
||||
if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, unix.TCP_FASTOPEN, int(config.Tfo)); err != nil {
|
||||
return newError("failed to set TCP_FASTOPEN=", config.Tfo).Base(err)
|
||||
tfo := config.ParseTFOValue()
|
||||
if tfo >= 0 {
|
||||
if err := syscall.SetsockoptInt(int(fd), syscall.IPPROTO_TCP, unix.TCP_FASTOPEN, tfo); err != nil {
|
||||
return newError("failed to set TCP_FASTOPEN=", tfo).Base(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ func applyOutboundSocketOptions(network string, address string, fd uintptr, conf
|
|||
}
|
||||
|
||||
if isTCPSocket(network) {
|
||||
tfo := int(config.Tfo)
|
||||
tfo := config.ParseTFOValue()
|
||||
if tfo > 0 {
|
||||
tfo = 1
|
||||
}
|
||||
|
@ -75,9 +75,10 @@ func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig)
|
|||
}
|
||||
}
|
||||
if isTCPSocket(network) {
|
||||
if config.Tfo >= 0 {
|
||||
if err := syscall.SetsockoptInt(int(fd), syscall.SOL_TCP, TCP_FASTOPEN, int(config.Tfo)); err != nil {
|
||||
return newError("failed to set TCP_FASTOPEN=", config.Tfo).Base(err)
|
||||
tfo := config.ParseTFOValue()
|
||||
if tfo >= 0 {
|
||||
if err := syscall.SetsockoptInt(int(fd), syscall.SOL_TCP, TCP_FASTOPEN, tfo); err != nil {
|
||||
return newError("failed to set TCP_FASTOPEN=", tfo).Base(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,12 +8,12 @@ const (
|
|||
TCP_FASTOPEN = 15
|
||||
)
|
||||
|
||||
func setTFO(fd syscall.Handle, tfo int32) error {
|
||||
func setTFO(fd syscall.Handle, tfo int) error {
|
||||
if tfo > 0 {
|
||||
tfo = 1
|
||||
}
|
||||
if tfo >= 0 {
|
||||
if err := syscall.SetsockoptInt(fd, syscall.IPPROTO_TCP, TCP_FASTOPEN, int(tfo)); err != nil {
|
||||
if err := syscall.SetsockoptInt(fd, syscall.IPPROTO_TCP, TCP_FASTOPEN, tfo); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ func setTFO(fd syscall.Handle, tfo int32) error {
|
|||
|
||||
func applyOutboundSocketOptions(network string, address string, fd uintptr, config *SocketConfig) error {
|
||||
if isTCPSocket(network) {
|
||||
if err := setTFO(syscall.Handle(fd), config.Tfo); err != nil {
|
||||
if err := setTFO(syscall.Handle(fd), config.ParseTFOValue()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ func applyOutboundSocketOptions(network string, address string, fd uintptr, conf
|
|||
|
||||
func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig) error {
|
||||
if isTCPSocket(network) {
|
||||
if err := setTFO(syscall.Handle(fd), config.Tfo); err != nil {
|
||||
if err := setTFO(syscall.Handle(fd), config.ParseTFOValue()); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue