mirror of
https://github.com/tickstep/aliyunpan.git
synced 2025-01-23 22:42:15 +08:00
set local address binding match prefer ip type
This commit is contained in:
parent
54dd4e766b
commit
e9ae974017
@ -210,7 +210,7 @@ func (c *PanConfig) init() error {
|
||||
|
||||
// 设置本地网卡地址
|
||||
if c.LocalAddrs != "" {
|
||||
ips := ParseLocalAddress(c.LocalAddrs)
|
||||
ips := ParseLocalAddress(c.LocalAddrs, strings.ToLower(c.PreferIPType))
|
||||
if len(ips) > 0 {
|
||||
logger.Verboseln("bind local address list: ", ips)
|
||||
requester.SetLocalTCPAddrList(ips...)
|
||||
|
@ -33,7 +33,7 @@ func (c *PanConfig) SetProxy(proxy string) {
|
||||
// SetLocalAddrs 设置localAddrs
|
||||
func (c *PanConfig) SetLocalAddrs(localAddrs string) {
|
||||
c.LocalAddrs = localAddrs
|
||||
ips := ParseLocalAddress(localAddrs)
|
||||
ips := ParseLocalAddress(localAddrs, strings.ToLower(c.PreferIPType))
|
||||
if len(ips) > 0 {
|
||||
requester.SetLocalTCPAddrList(ips...)
|
||||
}
|
||||
|
@ -139,7 +139,7 @@ func RandomDeviceId() string {
|
||||
}
|
||||
|
||||
// ParseLocalAddress 解析网络接口配置为对应的本地IP地址
|
||||
func ParseLocalAddress(localAddrs string) []string {
|
||||
func ParseLocalAddress(localAddrs string, filterIpType string) []string {
|
||||
allLocalAddress, _ := nets.GetLocalNetInterfaceAddress()
|
||||
localAddrNames := strings.Split(localAddrs, ",")
|
||||
ips := []string{}
|
||||
@ -151,10 +151,22 @@ func ParseLocalAddress(localAddrs string) []string {
|
||||
// maybe local interface name
|
||||
if localAddr := allLocalAddress.GetByName(addr); localAddr != nil {
|
||||
if localAddr.IPv4 != "" {
|
||||
if filterIpType == "any" || filterIpType == "" { // 不限制
|
||||
ips = append(ips, localAddr.IPv4)
|
||||
} else {
|
||||
if filterIpType == "ipv4" {
|
||||
ips = append(ips, localAddr.IPv4)
|
||||
}
|
||||
}
|
||||
}
|
||||
if localAddr.IPv6 != "" {
|
||||
if filterIpType == "any" || filterIpType == "" { // 不限制
|
||||
ips = append(ips, localAddr.IPv6)
|
||||
} else {
|
||||
if filterIpType == "ipv6" {
|
||||
ips = append(ips, localAddr.IPv6)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user