mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-22 16:41:30 +00:00
Fix bind_address
This commit is contained in:
parent
e859c0a6ef
commit
d481bd7993
|
@ -113,7 +113,10 @@ func NewDefault(router adapter.Router, options option.DialerOptions) *DefaultDia
|
||||||
}
|
}
|
||||||
var bindUDPAddr string
|
var bindUDPAddr string
|
||||||
udpDialer := dialer
|
udpDialer := dialer
|
||||||
bindAddress := netip.Addr(options.BindAddress)
|
var bindAddress netip.Addr
|
||||||
|
if options.BindAddress != nil {
|
||||||
|
bindAddress = options.BindAddress.Build()
|
||||||
|
}
|
||||||
if bindAddress.IsValid() {
|
if bindAddress.IsValid() {
|
||||||
dialer.LocalAddr = &net.TCPAddr{
|
dialer.LocalAddr = &net.TCPAddr{
|
||||||
IP: bindAddress.AsSlice(),
|
IP: bindAddress.AsSlice(),
|
||||||
|
|
|
@ -102,7 +102,7 @@ func (h *Outbound) UnmarshalJSON(bytes []byte) error {
|
||||||
type DialerOptions struct {
|
type DialerOptions struct {
|
||||||
Detour string `json:"detour,omitempty"`
|
Detour string `json:"detour,omitempty"`
|
||||||
BindInterface string `json:"bind_interface,omitempty"`
|
BindInterface string `json:"bind_interface,omitempty"`
|
||||||
BindAddress ListenAddress `json:"bind_address,omitempty"`
|
BindAddress *ListenAddress `json:"bind_address,omitempty"`
|
||||||
ProtectPath string `json:"protect_path,omitempty"`
|
ProtectPath string `json:"protect_path,omitempty"`
|
||||||
RoutingMark int `json:"routing_mark,omitempty"`
|
RoutingMark int `json:"routing_mark,omitempty"`
|
||||||
ReuseAddr bool `json:"reuse_addr,omitempty"`
|
ReuseAddr bool `json:"reuse_addr,omitempty"`
|
||||||
|
|
|
@ -16,7 +16,7 @@ type ListenAddress netip.Addr
|
||||||
func (a ListenAddress) MarshalJSON() ([]byte, error) {
|
func (a ListenAddress) MarshalJSON() ([]byte, error) {
|
||||||
addr := netip.Addr(a)
|
addr := netip.Addr(a)
|
||||||
if !addr.IsValid() {
|
if !addr.IsValid() {
|
||||||
return json.Marshal("")
|
return nil, nil
|
||||||
}
|
}
|
||||||
return json.Marshal(addr.String())
|
return json.Marshal(addr.String())
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,10 @@ func (a *ListenAddress) UnmarshalJSON(content []byte) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a ListenAddress) Build() netip.Addr {
|
||||||
|
return (netip.Addr)(a)
|
||||||
|
}
|
||||||
|
|
||||||
type NetworkList string
|
type NetworkList string
|
||||||
|
|
||||||
func (v *NetworkList) UnmarshalJSON(content []byte) error {
|
func (v *NetworkList) UnmarshalJSON(content []byte) error {
|
||||||
|
|
Loading…
Reference in a new issue