mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-09-23 01:27:04 +00:00
Sockopt: Fix indentation of the CustomSockopt block for Linux (#6568)
https://github.com/XTLS/Xray-core/pull/6568#issuecomment-5488145252 Fixes https://github.com/XTLS/Xray-core/issues/6564 Fixes https://github.com/XTLS/Xray-core/issues/6602
This commit is contained in:
@@ -10,7 +10,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type CustomSockoptConfig struct {
|
type CustomSockoptConfig struct {
|
||||||
Syetem string `json:"system"`
|
System string `json:"system"`
|
||||||
Network string `json:"network"`
|
Network string `json:"network"`
|
||||||
Level string `json:"level"`
|
Level string `json:"level"`
|
||||||
Opt string `json:"opt"`
|
Opt string `json:"opt"`
|
||||||
@@ -124,7 +124,7 @@ func (c *SocketConfig) Build() (*internet.SocketConfig, error) {
|
|||||||
|
|
||||||
for _, copt := range c.CustomSockopt {
|
for _, copt := range c.CustomSockopt {
|
||||||
customSockopt := &internet.CustomSockopt{
|
customSockopt := &internet.CustomSockopt{
|
||||||
System: copt.Syetem,
|
System: copt.System,
|
||||||
Network: copt.Network,
|
Network: copt.Network,
|
||||||
Level: copt.Level,
|
Level: copt.Level,
|
||||||
Opt: copt.Opt,
|
Opt: copt.Opt,
|
||||||
|
|||||||
@@ -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