-
Notifications
You must be signed in to change notification settings - Fork 0
<fix>[core]: register IPv6 prefer config #4146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feature-5.5.28-IPv6-management-network
Are you sure you want to change the base?
Changes from all commits
b13e299
04d65fc
e50ef99
93cce8b
9893728
3dc8bcd
81ed0a1
4ca12c4
a31cf9c
123bd2b
d84840d
e40f7f8
2b2d2fb
5579167
9c58c88
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -83,7 +83,6 @@ public class Platform { | |
| private static MessageSource messageSource; | ||
| private static String encryptionKey = EncryptRSA.generateKeyString("ZStack open source"); | ||
| private static final String MANAGEMENT_SERVER_IP_PROPERTY = "management.server.ip"; | ||
| private static final String MANAGEMENT_SERVER_PREFER_IPV6_PROPERTY = "management.server.prefer.ipv6"; | ||
| private static final String ZSTACK_MANAGEMENT_SERVER_IP_ENV = "ZSTACK_MANAGEMENT_SERVER_IP"; | ||
| private static final String IPV4_ADDRESS_COMMAND = "ip -4 add"; | ||
| private static final String IPV6_ADDRESS_COMMAND = "ip -6 addr"; | ||
|
|
@@ -994,7 +993,7 @@ private static String getManagementServerIpInternal() { | |
| for (NetworkInterface iface : Collections.list(nets)) { | ||
| String name = iface.getName(); | ||
| if (defaultLine.contains(name)) { | ||
| ip = selectManagementServerIp(Collections.list(iface.getInetAddresses()), isManagementServerPreferIpv6()); | ||
| ip = selectManagementServerIp(Collections.list(iface.getInetAddresses())); | ||
| } | ||
| } | ||
| } catch (SocketException e) { | ||
|
|
@@ -1070,7 +1069,74 @@ public static List<String> getManagementServerIps() { | |
| return new ArrayList<>(ips); | ||
| } | ||
|
|
||
| public static String selectManagementServerIp(Collection<InetAddress> addresses, boolean preferIpv6) { | ||
| public static List<String> getManagementServerIpsWithLocalFallback() { | ||
| LinkedHashSet<String> ips = new LinkedHashSet<>(getManagementServerIps()); | ||
| ips.addAll(getLocalNonLoopbackIps()); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment from shixin.ruan: 有效,已按最小范围修复。缺陷类型:API 语义/多网卡回调候选扩大。根因是 getManagementServerIps() 被扩展为包含所有本机非回环地址,确实会破坏旧 API 的“管理地址列表”契约。修改:9c58c88c32 中恢复 getManagementServerIps() 只返回 management.server.ip / ip4 / ip6;新增 getManagementServerIpsWithLocalFallback(),仅在 ApplianceVmFacadeImpl bootstrap 且后续会按 vRouter management CIDR 过滤的路径使用。VirtualRouterManagerImpl 仍优先使用 Platform.getRouteSourceIp(agentIp),fallback 回窄化后的管理地址列表。验证:mvn -pl utils -DskipTests install;mvn -pl utils,header,core,plugin/applianceVm,plugin/virtualRouterProvider -DskipTests compile;zstack/test 下 mvn -DskipTests test-compile 均通过。剩余风险:本次不引入按网卡名选择管理口的新策略,只收窄旧 API 语义并保留 bootstrap CIDR 过滤 fallback。 |
||
| ips.remove(null); | ||
| return new ArrayList<>(ips); | ||
| } | ||
|
|
||
| private static List<String> getLocalNonLoopbackIps() { | ||
| List<String> ips = new ArrayList<>(); | ||
| try { | ||
| Enumeration<NetworkInterface> nets = NetworkInterface.getNetworkInterfaces(); | ||
| for (NetworkInterface iface : Collections.list(nets)) { | ||
| if (!iface.isUp()) { | ||
| continue; | ||
| } | ||
| for (InetAddress address : Collections.list(iface.getInetAddresses())) { | ||
| if (address.isLoopbackAddress() || address.isLinkLocalAddress()) { | ||
| continue; | ||
| } | ||
| ips.add(normalizeManagementIp(address.getHostAddress())); | ||
| } | ||
| } | ||
| } catch (SocketException e) { | ||
| logger.warn("failed to list local non-loopback IPs", e); | ||
| } | ||
| return ips; | ||
| } | ||
|
|
||
| public static String getRouteSourceIp(String remoteIp) { | ||
| if (StringUtils.isBlank(remoteIp)) { | ||
| return null; | ||
| } | ||
|
|
||
| remoteIp = normalizeManagementIp(remoteIp); | ||
| String family; | ||
| if (IPv6NetworkUtils.isIpv6Address(remoteIp)) { | ||
| family = "-6"; | ||
| } else if (NetworkUtils.isIpv4Address(remoteIp)) { | ||
| family = "-4"; | ||
| } else { | ||
| return null; | ||
| } | ||
|
|
||
| Linux.ShellResult ret = Linux.shell(String.format("/sbin/ip %s route get %s", family, remoteIp)); | ||
| if (ret.getExitCode() != 0) { | ||
| logger.warn(String.format("failed to get route source IP for remote[%s], stdout[%s], stderr[%s]", | ||
| remoteIp, ret.getStdout(), ret.getStderr())); | ||
| return null; | ||
| } | ||
|
|
||
| String[] tokens = ret.getStdout().trim().split("\\s+"); | ||
| for (int i = 0; i < tokens.length - 1; i++) { | ||
| if (!"src".equals(tokens[i])) { | ||
| continue; | ||
| } | ||
| String sourceIp = normalizeManagementIp(tokens[i + 1]); | ||
| if (IPv6NetworkUtils.isIpv6Address(remoteIp) && IPv6NetworkUtils.isIpv6Address(sourceIp)) { | ||
| return sourceIp; | ||
| } | ||
| if (NetworkUtils.isIpv4Address(remoteIp) && NetworkUtils.isIpv4Address(sourceIp)) { | ||
| return sourceIp; | ||
| } | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
| public static String selectManagementServerIp(Collection<InetAddress> addresses) { | ||
| String ipv4 = null; | ||
| String ipv6 = null; | ||
|
|
||
|
|
@@ -1087,22 +1153,9 @@ public static String selectManagementServerIp(Collection<InetAddress> addresses, | |
| } | ||
| } | ||
|
|
||
| if (preferIpv6 && ipv6 != null) { | ||
| return ipv6; | ||
| } | ||
|
|
||
| return ipv4 != null ? ipv4 : ipv6; | ||
| } | ||
|
|
||
| public static boolean isManagementServerPreferIpv6() { | ||
| String propertyValue = System.getProperty(MANAGEMENT_SERVER_PREFER_IPV6_PROPERTY); | ||
| if (propertyValue != null) { | ||
| return Boolean.parseBoolean(propertyValue); | ||
| } | ||
|
|
||
| return CoreGlobalProperty.MANAGEMENT_SERVER_PREFER_IPV6; | ||
| } | ||
|
|
||
| public static String formatJGroupsInitialHosts(String nodeIp, String peerIp, int port) { | ||
| return String.format(JGROUPS_INITIAL_HOST_FORMAT, | ||
| IPv6NetworkUtils.formatHostForUrl(nodeIp), port, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,27 @@ | ||
| package org.zstack.storage.zbs; | ||
|
|
||
| import org.springframework.web.util.UriComponentsBuilder; | ||
| import org.zstack.utils.network.IPv6NetworkUtils; | ||
|
|
||
| /** | ||
| * @author Xingwei Yu | ||
| * @date 2024/3/27 17:39 | ||
| */ | ||
| public class ZbsAgentUrl { | ||
| public static String primaryStorageUrl(String ip, String path) { | ||
| UriComponentsBuilder ub = UriComponentsBuilder.newInstance(); | ||
| ub.scheme("http"); | ||
| ub.host(ip); | ||
| ub.port(ZbsGlobalProperty.PRIMARY_STORAGE_AGENT_PORT); | ||
| if (!"".equals(ZbsGlobalProperty.PRIMARY_STORAGE_AGENT_URL_ROOT_PATH)) { | ||
| ub.path(ZbsGlobalProperty.PRIMARY_STORAGE_AGENT_URL_ROOT_PATH); | ||
| private static void appendPath(StringBuilder sb, String path) { | ||
| if (path == null || path.isEmpty()) { | ||
| return; | ||
| } | ||
|
|
||
| if (!path.startsWith("/")) { | ||
| sb.append("/"); | ||
| } | ||
| ub.path(path); | ||
| return ub.build().toUriString(); | ||
| sb.append(path); | ||
| } | ||
|
|
||
| public static String primaryStorageUrl(String ip, String path) { | ||
| StringBuilder sb = new StringBuilder(IPv6NetworkUtils.buildHttpUrl(ip, ZbsGlobalProperty.PRIMARY_STORAGE_AGENT_PORT)); | ||
| appendPath(sb, ZbsGlobalProperty.PRIMARY_STORAGE_AGENT_URL_ROOT_PATH); | ||
| appendPath(sb, path); | ||
| return sb.toString(); | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.