Skip to content
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

[master] fix ignored interface name matches method #8629

Merged
merged 6 commits into from Sep 8, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -330,7 +330,8 @@ private static boolean ignoreNetworkInterface(NetworkInterface networkInterface)
if(StringUtils.isNotEmpty(ignoredInterfaces)
&&StringUtils.isNotEmpty(networkInterfaceDisplayName=networkInterface.getDisplayName())){
for(String ignoredInterface: ignoredInterfaces.split(",")){
if(networkInterfaceDisplayName.matches(ignoredInterface.trim())){
if(networkInterfaceDisplayName.matches(ignoredInterface.trim())
|| networkInterfaceDisplayName.equals(ignoredInterface.trim())){
return true;
}
}
Expand Down
Expand Up @@ -24,6 +24,7 @@
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.util.regex.Pattern;
import java.net.NetworkInterface;

import static org.apache.dubbo.common.constants.CommonConstants.DUBBO_NETWORK_IGNORED_INTERFACE;
Expand Down Expand Up @@ -352,7 +353,7 @@ public void testIgnoreGivenInterface(){
NetworkInterface networkInterface = NetUtils.findNetworkInterface();
assertNotNull(networkInterface);
// ignore the given network interface's display name
this.setIgnoredInterfaces(networkInterface.getDisplayName());
this.setIgnoredInterfaces(Pattern.quote(networkInterface.getDisplayName()));
NetworkInterface newNetworkInterface = NetUtils.findNetworkInterface();
if(newNetworkInterface!=null){
assertTrue(!networkInterface.getDisplayName().equals(newNetworkInterface.getDisplayName()));
Expand All @@ -373,7 +374,7 @@ public void testIgnoreGivenPrefixInterfaceName(){
// ignore the given prefix network interface's display name
String displayName = networkInterface.getDisplayName();
if(StringUtils.isNotEmpty(displayName)&&displayName.length()>2){
String ignoredInterfaces = displayName.substring(0,1)+".*";
String ignoredInterfaces = Pattern.quote(displayName.substring(0,1)) + ".*";
this.setIgnoredInterfaces(ignoredInterfaces);
NetworkInterface newNetworkInterface = NetUtils.findNetworkInterface();
if(newNetworkInterface!=null){
Expand Down