Skip to content

Fix the IP address retrieval error#2051

Merged
yu199195 merged 5 commits into
apache:masterfrom
p8rtop:master
Sep 10, 2021
Merged

Fix the IP address retrieval error#2051
yu199195 merged 5 commits into
apache:masterfrom
p8rtop:master

Conversation

@p8rtop

@p8rtop p8rtop commented Sep 10, 2021

Copy link
Copy Markdown
Contributor

// Describe your PR here; eg. Fixes #issueNo

Make sure that:

-------------------------------------------test code----------------------------------------------------------
The original code:

if (!ip.isLoopbackAddress()){
System.out.print(ip.getHostAddress());
System.out.print("-------");
System.out.print(netInterface.getDisplayName());
System.out.print("-------");
System.out.print(netInterface.getName());
System.out.println();
}

fe80:0:0:0:3507:b35:d4e4:ebf3%eth2-------Bluetooth Device (Personal Area Network)-------eth2
fe80:0:0:0:7881:df0f:e380:188b%wlan2-------Microsoft Wi-Fi Direct Virtual Adapter-------wlan2
172.23.39.81-------Intel(R) Ethernet Connection (3) I218-LM-------eth3
fe80:0:0:0:58b0:4f02:d55e:4f32%eth3-------Intel(R) Ethernet Connection (3) I218-LM-------eth3
fe80:0:0:0:8010:123e:b12b:1e57%wlan3-------Intel(R) Dual Band Wireless-AC 7265-------wlan3
192.168.137.1-------Microsoft Wi-Fi Direct Virtual Adapter #2-------wlan4
fe80:0:0:0:e495:d3f:9590:e7d7%wlan4-------Microsoft Wi-Fi Direct Virtual Adapter #2-------wlan4
192.168.16.1-------Hyper-V Virtual Ethernet Adapter-------eth22
fe80:0:0:0:9d08:73ac:5e28:4f53%eth22-------Hyper-V Virtual Ethernet Adapter-------eth22
------------------------------------------test code-----------------------------------------------------------

These are the network cards for my laptop. The shenyu utility class only gets IP 192.168.16.1, but my real IP is 172.23.39.81.

I had fix the IP address retrieval error.

Use the new rule:

example: eth3 172.23.39.81 | eth22 192.168.16.1 | wlan4 192.168.137.1

I will spit as "name namePostfix ipv4Postfix"
"eth 3 81", "eth 22 1", "wlan 4 1"

then, sort the list:
first rule: name (other name<"enp"<"eth"<"bond")
second rule: namePostfix ( 3[eth] > 22[eth] > 4[wlan])
third rule : ipv4Postfix ( 81[172.23.39.81] > 1[192.168.16.1] > 1[192.168.137.1] )

then, keep old filter (ipv4).

  • [ √ ] You have read the contribution guidelines.
  • [ √ ] You submit test cases (unit or integration tests) that back your changes.
  • [ √ ] Your local test passed mvn clean install -Dmaven.javadoc.skip=true.

Comment thread shenyu-common/src/main/java/org/apache/shenyu/common/utils/IpUtils.java Outdated
Comment thread shenyu-common/src/main/java/org/apache/shenyu/common/utils/IpUtils.java Outdated
Comment thread shenyu-common/src/main/java/org/apache/shenyu/common/utils/IpUtils.java Outdated
@p8rtop p8rtop closed this Sep 10, 2021
@p8rtop p8rtop reopened this Sep 10, 2021
@p8rtop p8rtop closed this Sep 10, 2021
@p8rtop p8rtop reopened this Sep 10, 2021
@tydhot

tydhot commented Sep 10, 2021

Copy link
Copy Markdown
Member

why not add some test about the util either? I think it can help us review too.

Comment thread shenyu-common/src/main/java/org/apache/shenyu/common/utils/IpUtils.java Outdated
Comment thread shenyu-common/src/main/java/org/apache/shenyu/common/utils/IpUtils.java Outdated
Comment thread shenyu-common/src/main/java/org/apache/shenyu/common/utils/IpUtils.java Outdated
@yu199195

Copy link
Copy Markdown
Member

pls add finnal to all Method parameters

@codecov-commenter

codecov-commenter commented Sep 10, 2021

Copy link
Copy Markdown

Codecov Report

Merging #2051 (e23a7fc) into master (afe0d83) will decrease coverage by 1.52%.
The diff coverage is 62.22%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #2051      +/-   ##
============================================
- Coverage     62.18%   60.66%   -1.53%     
- Complexity     4012     4031      +19     
============================================
  Files           594      606      +12     
  Lines         17408    17833     +425     
  Branches       1665     1704      +39     
============================================
- Hits          10826    10819       -7     
- Misses         5721     6133     +412     
- Partials        861      881      +20     
Impacted Files Coverage Δ
...n/java/org/apache/shenyu/common/utils/IpUtils.java 65.00% <62.22%> (-3.75%) ⬇️
...ache/shenyu/admin/exception/ExceptionHandlers.java 5.55% <0.00%> (-94.45%) ⬇️
...shenyu/admin/service/impl/MetaDataServiceImpl.java 5.15% <0.00%> (-90.73%) ⬇️
...u/admin/listener/websocket/WebsocketCollector.java 7.69% <0.00%> (-69.24%) ⬇️
...nyu/plugin/grpc/proto/CompositeStreamObserver.java 38.46% <0.00%> (-61.54%) ⬇️
...henyu/admin/service/impl/UpstreamCheckService.java 26.82% <0.00%> (-56.92%) ⬇️
...rg/apache/shenyu/common/utils/CollectionUtils.java 33.33% <0.00%> (-33.34%) ⬇️
...in/alibaba/dubbo/cache/ApplicationConfigCache.java 45.54% <0.00%> (-32.68%) ⬇️
...gin/apache/dubbo/cache/ApplicationConfigCache.java 47.52% <0.00%> (-27.73%) ⬇️
...ache/shenyu/plugin/grpc/cache/GrpcClientCache.java 76.47% <0.00%> (-17.65%) ⬇️
... and 73 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update afe0d83...e23a7fc. Read the comment docs.

@yu199195 yu199195 added this to the 2.4.1 milestone Sep 10, 2021
@yu199195 yu199195 merged commit 53704ef into apache:master Sep 10, 2021
@yu199195

Copy link
Copy Markdown
Member

@xiaheshun welcome to join apache shenyu controbutor 。 you can add my wechat: xixy199195

@yu199195 yu199195 linked an issue Sep 15, 2021 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add ipUtils to get real ip

4 participants