Skip to content

Commit

Permalink
Add custom Sockopt support (XTLS#3517)
Browse files Browse the repository at this point in the history
* Add custom sockopt

* Add custom level

* Change field

* Sth left
  • Loading branch information
Fangliding authored Jul 9, 2024
1 parent ce637c0 commit 308f0c6
Show file tree
Hide file tree
Showing 4 changed files with 321 additions and 135 deletions.
53 changes: 37 additions & 16 deletions infra/conf/transport_internet.go
Original file line number Diff line number Diff line change
Expand Up @@ -685,23 +685,31 @@ func (p TransportProtocol) Build() (string, error) {
}
}

type CustomSockoptConfig struct {
Level string `json:"level"`
Opt string `json:"opt"`
Value string `json:"value"`
Type string `json:"type"`
}

type SocketConfig struct {
Mark int32 `json:"mark"`
TFO interface{} `json:"tcpFastOpen"`
TProxy string `json:"tproxy"`
AcceptProxyProtocol bool `json:"acceptProxyProtocol"`
DomainStrategy string `json:"domainStrategy"`
DialerProxy string `json:"dialerProxy"`
TCPKeepAliveInterval int32 `json:"tcpKeepAliveInterval"`
TCPKeepAliveIdle int32 `json:"tcpKeepAliveIdle"`
TCPCongestion string `json:"tcpCongestion"`
TCPWindowClamp int32 `json:"tcpWindowClamp"`
TCPMaxSeg int32 `json:"tcpMaxSeg"`
TcpNoDelay bool `json:"tcpNoDelay"`
TCPUserTimeout int32 `json:"tcpUserTimeout"`
V6only bool `json:"v6only"`
Interface string `json:"interface"`
TcpMptcp bool `json:"tcpMptcp"`
Mark int32 `json:"mark"`
TFO interface{} `json:"tcpFastOpen"`
TProxy string `json:"tproxy"`
AcceptProxyProtocol bool `json:"acceptProxyProtocol"`
DomainStrategy string `json:"domainStrategy"`
DialerProxy string `json:"dialerProxy"`
TCPKeepAliveInterval int32 `json:"tcpKeepAliveInterval"`
TCPKeepAliveIdle int32 `json:"tcpKeepAliveIdle"`
TCPCongestion string `json:"tcpCongestion"`
TCPWindowClamp int32 `json:"tcpWindowClamp"`
TCPMaxSeg int32 `json:"tcpMaxSeg"`
TcpNoDelay bool `json:"tcpNoDelay"`
TCPUserTimeout int32 `json:"tcpUserTimeout"`
V6only bool `json:"v6only"`
Interface string `json:"interface"`
TcpMptcp bool `json:"tcpMptcp"`
CustomSockopt []*CustomSockoptConfig `json:"customSockopt"`
}

// Build implements Buildable.
Expand Down Expand Up @@ -759,6 +767,18 @@ func (c *SocketConfig) Build() (*internet.SocketConfig, error) {
return nil, errors.New("unsupported domain strategy: ", c.DomainStrategy)
}

var customSockopts []*internet.CustomSockopt

for _, copt := range c.CustomSockopt {
customSockopt := &internet.CustomSockopt{
Level: copt.Level,
Opt: copt.Opt,
Value: copt.Value,
Type: copt.Type,
}
customSockopts = append(customSockopts, customSockopt)
}

return &internet.SocketConfig{
Mark: c.Mark,
Tfo: tfo,
Expand All @@ -776,6 +796,7 @@ func (c *SocketConfig) Build() (*internet.SocketConfig, error) {
V6Only: c.V6only,
Interface: c.Interface,
TcpMptcp: c.TcpMptcp,
CustomSockopt: customSockopts,
}, nil
}

Expand Down
Loading

0 comments on commit 308f0c6

Please sign in to comment.