mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-10-27 13:37:09 +00:00
Sockopt: Fix indentation of the CustomSockopt block
https://github.com/XTLS/Xray-core/issues/6564#issuecomment-5150960771 Closes https://github.com/XTLS/Xray-core/issues/6564
This commit is contained in:
@@ -169,41 +169,42 @@ func applyInboundSocketOptions(network string, fd uintptr, config *SocketConfig)
|
|||||||
return errors.New("failed to set TCP_MAXSEG", err)
|
return errors.New("failed to set TCP_MAXSEG", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(config.CustomSockopt) > 0 {
|
}
|
||||||
for _, custom := range config.CustomSockopt {
|
|
||||||
if custom.System != "" && custom.System != runtime.GOOS {
|
if len(config.CustomSockopt) > 0 {
|
||||||
errors.LogDebug(context.Background(), "CustomSockopt system not match: ", "want ", custom.System, " got ", runtime.GOOS)
|
for _, custom := range config.CustomSockopt {
|
||||||
continue
|
if custom.System != "" && custom.System != runtime.GOOS {
|
||||||
|
errors.LogDebug(context.Background(), "CustomSockopt system not match: ", "want ", custom.System, " got ", runtime.GOOS)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// Skip unwanted network type
|
||||||
|
// network might be tcp4 or tcp6
|
||||||
|
// use HasPrefix so that "tcp" can match tcp4/6 with "tcp" if user want to control all tcp (udp is also the same)
|
||||||
|
// if it is empty, strings.HasPrefix will always return true to make it apply for all networks
|
||||||
|
if !strings.HasPrefix(network, custom.Network) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
level := 0x6 // default TCP
|
||||||
|
var opt int
|
||||||
|
if len(custom.Opt) == 0 {
|
||||||
|
return errors.New("No opt!")
|
||||||
|
} else {
|
||||||
|
opt, _ = strconv.Atoi(custom.Opt)
|
||||||
|
}
|
||||||
|
if custom.Level != "" {
|
||||||
|
level, _ = strconv.Atoi(custom.Level)
|
||||||
|
}
|
||||||
|
if custom.Type == "int" {
|
||||||
|
value, _ := strconv.Atoi(custom.Value)
|
||||||
|
if err := syscall.SetsockoptInt(int(fd), level, opt, value); err != nil {
|
||||||
|
return errors.New("failed to set CustomSockoptInt", opt, value, err)
|
||||||
}
|
}
|
||||||
// Skip unwanted network type
|
} else if custom.Type == "str" {
|
||||||
// network might be tcp4 or tcp6
|
if err := syscall.SetsockoptString(int(fd), level, opt, custom.Value); err != nil {
|
||||||
// use HasPrefix so that "tcp" can match tcp4/6 with "tcp" if user want to control all tcp (udp is also the same)
|
return errors.New("failed to set CustomSockoptString", opt, custom.Value, err)
|
||||||
// if it is empty, strings.HasPrefix will always return true to make it apply for all networks
|
|
||||||
if !strings.HasPrefix(network, custom.Network) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
level := 0x6 // default TCP
|
|
||||||
var opt int
|
|
||||||
if len(custom.Opt) == 0 {
|
|
||||||
return errors.New("No opt!")
|
|
||||||
} else {
|
|
||||||
opt, _ = strconv.Atoi(custom.Opt)
|
|
||||||
}
|
|
||||||
if custom.Level != "" {
|
|
||||||
level, _ = strconv.Atoi(custom.Level)
|
|
||||||
}
|
|
||||||
if custom.Type == "int" {
|
|
||||||
value, _ := strconv.Atoi(custom.Value)
|
|
||||||
if err := syscall.SetsockoptInt(int(fd), level, opt, value); err != nil {
|
|
||||||
return errors.New("failed to set CustomSockoptInt", opt, value, err)
|
|
||||||
}
|
|
||||||
} else if custom.Type == "str" {
|
|
||||||
if err := syscall.SetsockoptString(int(fd), level, opt, custom.Value); err != nil {
|
|
||||||
return errors.New("failed to set CustomSockoptString", opt, custom.Value, err)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return errors.New("unknown CustomSockopt type:", custom.Type)
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return errors.New("unknown CustomSockopt type:", custom.Type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user