mirror of
https://github.com/xjasonlyu/tun2socks.git
synced 2024-12-30 02:37:01 +00:00
Feature: add support for multicast (#245)
* add support for multicast (#243) * adjust setup --------- Co-authored-by: xjasonlyu <xjasonlyu@gmail.com>
This commit is contained in:
@@ -193,6 +193,11 @@ func netstack(k *Key) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
var multicastGroups []net.IP
|
||||
if multicastGroups, err = parseMulticastGroups(k.MulticastGroups); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var opts []option.Option
|
||||
if k.TCPModerateReceiveBuffer {
|
||||
opts = append(opts, option.WithTCPModerateReceiveBuffer(true))
|
||||
@@ -217,6 +222,7 @@ func netstack(k *Key) (err error) {
|
||||
if _defaultStack, err = core.CreateStack(&core.Config{
|
||||
LinkEndpoint: _defaultDevice,
|
||||
TransportHandler: &mirror.Tunnel{},
|
||||
MulticastGroups: multicastGroups,
|
||||
Options: opts,
|
||||
}); err != nil {
|
||||
return
|
||||
|
||||
@@ -13,6 +13,7 @@ type Key struct {
|
||||
TCPModerateReceiveBuffer bool `yaml:"tcp-moderate-receive-buffer"`
|
||||
TCPSendBufferSize string `yaml:"tcp-send-buffer-size"`
|
||||
TCPReceiveBufferSize string `yaml:"tcp-receive-buffer-size"`
|
||||
MulticastGroups string `yaml:"multicast-groups"`
|
||||
TUNPreUp string `yaml:"tun-pre-up"`
|
||||
TUNPostUp string `yaml:"tun-post-up"`
|
||||
UDPTimeout time.Duration `yaml:"udp-timeout"`
|
||||
|
||||
@@ -150,3 +150,21 @@ func parseShadowsocks(u *url.URL) (address, method, password, obfsMode, obfsHost
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func parseMulticastGroups(s string) (multicastGroups []net.IP, _ error) {
|
||||
ipStrings := strings.Split(s, ",")
|
||||
for _, ipString := range ipStrings {
|
||||
if strings.TrimSpace(ipString) == "" {
|
||||
continue
|
||||
}
|
||||
ip := net.ParseIP(ipString)
|
||||
if ip == nil {
|
||||
return nil, fmt.Errorf("invalid IP format: %s", ipString)
|
||||
}
|
||||
if !ip.IsMulticast() {
|
||||
return nil, fmt.Errorf("invalid multicast IP address: %s", ipString)
|
||||
}
|
||||
multicastGroups = append(multicastGroups, ip)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user