mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-09-15 21:00:27 +00:00
refactor: New tun udpnat
This commit is contained in:
@@ -87,6 +87,48 @@ type ListenOptions struct {
|
||||
InboundOptions
|
||||
}
|
||||
|
||||
type UDPNATBehavior uint8
|
||||
|
||||
const (
|
||||
UDPNATBehaviorEndpointIndependent UDPNATBehavior = iota
|
||||
UDPNATBehaviorAddressDependent
|
||||
UDPNATBehaviorAddressAndPortDependent
|
||||
)
|
||||
|
||||
func (b UDPNATBehavior) MarshalJSON() ([]byte, error) {
|
||||
var value string
|
||||
switch b {
|
||||
case UDPNATBehaviorEndpointIndependent:
|
||||
value = "endpoint_independent"
|
||||
case UDPNATBehaviorAddressDependent:
|
||||
value = "address_dependent"
|
||||
case UDPNATBehaviorAddressAndPortDependent:
|
||||
value = "address_and_port_dependent"
|
||||
default:
|
||||
return nil, E.New("unknown UDP NAT behavior: ", uint8(b))
|
||||
}
|
||||
return json.Marshal(value)
|
||||
}
|
||||
|
||||
func (b *UDPNATBehavior) UnmarshalJSON(data []byte) error {
|
||||
var value string
|
||||
err := json.Unmarshal(data, &value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
switch value {
|
||||
case "", "endpoint_independent":
|
||||
*b = UDPNATBehaviorEndpointIndependent
|
||||
case "address_dependent":
|
||||
*b = UDPNATBehaviorAddressDependent
|
||||
case "address_and_port_dependent":
|
||||
*b = UDPNATBehaviorAddressAndPortDependent
|
||||
default:
|
||||
return E.New("unknown UDP NAT behavior: ", value)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type UDPTimeoutCompat badoption.Duration
|
||||
|
||||
func (c UDPTimeoutCompat) MarshalJSON() ([]byte, error) {
|
||||
|
||||
+4
-1
@@ -6,5 +6,8 @@ type RedirectInboundOptions struct {
|
||||
|
||||
type TProxyInboundOptions struct {
|
||||
ListenOptions
|
||||
Network NetworkList `json:"network,omitempty"`
|
||||
Network NetworkList `json:"network,omitempty"`
|
||||
UDPMapping UDPNATBehavior `json:"udp_mapping,omitempty"`
|
||||
UDPFiltering UDPNATBehavior `json:"udp_filtering,omitempty"`
|
||||
UDPNATMax uint32 `json:"udp_nat_max,omitempty"`
|
||||
}
|
||||
|
||||
@@ -45,6 +45,9 @@ type TunInboundOptions struct {
|
||||
IncludeMACAddress badoption.Listable[string] `json:"include_mac_address,omitempty"`
|
||||
ExcludeMACAddress badoption.Listable[string] `json:"exclude_mac_address,omitempty"`
|
||||
UDPTimeout UDPTimeoutCompat `json:"udp_timeout,omitempty"`
|
||||
UDPMapping UDPNATBehavior `json:"udp_mapping,omitempty"`
|
||||
UDPFiltering UDPNATBehavior `json:"udp_filtering,omitempty"`
|
||||
UDPNATMax uint32 `json:"udp_nat_max,omitempty"`
|
||||
Stack string `json:"stack,omitempty"`
|
||||
Platform *TunPlatformOptions `json:"platform,omitempty"`
|
||||
InboundOptions
|
||||
|
||||
+12
-9
@@ -7,15 +7,18 @@ import (
|
||||
)
|
||||
|
||||
type WireGuardEndpointOptions struct {
|
||||
System bool `json:"system,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
MTU uint32 `json:"mtu,omitempty"`
|
||||
Address badoption.Listable[netip.Prefix] `json:"address"`
|
||||
PrivateKey string `json:"private_key"`
|
||||
ListenPort uint16 `json:"listen_port,omitempty"`
|
||||
Peers []WireGuardPeer `json:"peers,omitempty"`
|
||||
UDPTimeout badoption.Duration `json:"udp_timeout,omitempty"`
|
||||
Workers int `json:"workers,omitempty"`
|
||||
System bool `json:"system,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
MTU uint32 `json:"mtu,omitempty"`
|
||||
Address badoption.Listable[netip.Prefix] `json:"address"`
|
||||
PrivateKey string `json:"private_key"`
|
||||
ListenPort uint16 `json:"listen_port,omitempty"`
|
||||
Peers []WireGuardPeer `json:"peers,omitempty"`
|
||||
UDPTimeout badoption.Duration `json:"udp_timeout,omitempty"`
|
||||
UDPMapping UDPNATBehavior `json:"udp_mapping,omitempty"`
|
||||
UDPFiltering UDPNATBehavior `json:"udp_filtering,omitempty"`
|
||||
UDPNATMax uint32 `json:"udp_nat_max,omitempty"`
|
||||
Workers int `json:"workers,omitempty"`
|
||||
DialerOptions
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user