-
Notifications
You must be signed in to change notification settings - Fork 51
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
Feature: Add IPv6 support #34
Open
adjivas
wants to merge
8
commits into
free5gc:main
Choose a base branch
from
adjivas:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+206
−50
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0bbe411
feat: IPv6 support
83a7eae
refactor: rename net_util/net_util into utils/net
c96c634
refactor: add test for the RegisterAddr's utils function
e5708da
refactor: increase version
6ef0236
fix: fmt and error check linters
ca85ce3
refactor: improve test
0f4a4fb
fix: lookUp for BindingIP
43ebdf9
fix: cgi package order
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package net | ||
|
||
import ( | ||
"net" | ||
"net/netip" | ||
|
||
"github.com/free5gc/ausf/internal/logger" | ||
) | ||
|
||
func BindingLookup(bindIP string) string { | ||
ips, err := net.LookupIP(bindIP) | ||
if err != nil { | ||
logger.InitLog.Errorf("Resolve BindingIP hostname %s failed: %+v", bindIP, err) | ||
} | ||
return ips[0].String() | ||
} | ||
|
||
func RegisterAddr(registerIP string) netip.Addr { | ||
ips, err := net.LookupIP(registerIP) | ||
if err != nil { | ||
logger.InitLog.Errorf("Resolve RegisterIP hostname %s failed: %+v", registerIP, err) | ||
} | ||
ip, err := netip.ParseAddr(ips[0].String()) | ||
if err != nil { | ||
logger.InitLog.Errorf("Parse RegisterIP hostname %s failed: %+v", registerIP, err) | ||
} | ||
return ip | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package net | ||
|
||
import ( | ||
"net/netip" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestBindingLookupWithLocalhost(t *testing.T) { | ||
expectedBindIP := "::1" | ||
|
||
bindIP := BindingLookup("localhost") | ||
assert.Equal(t, bindIP, expectedBindIP) | ||
} | ||
|
||
func TestBindingLookupWithIpV4(t *testing.T) { | ||
expectedBindIP := "127.0.0.1" | ||
|
||
bindIP := BindingLookup("127.0.0.1") | ||
assert.Equal(t, bindIP, expectedBindIP) | ||
} | ||
|
||
func TestBindingLookupWithIpV6(t *testing.T) { | ||
expectedBindIP := "2001:db8::1:0:0:1" | ||
|
||
bindIP := BindingLookup("2001:db8::1:0:0:1") | ||
assert.Equal(t, bindIP, expectedBindIP) | ||
} | ||
|
||
func TestRegisterAddrWithLocalhost(t *testing.T) { | ||
expectedAddr, err := netip.ParseAddr("::1") | ||
if err != nil { | ||
t.Errorf("invalid expected IP: %+v", expectedAddr) | ||
} | ||
|
||
addr := RegisterAddr("localhost") | ||
if addr != expectedAddr { | ||
t.Errorf("invalid IP: %+v", addr) | ||
} | ||
assert.Equal(t, addr, expectedAddr) | ||
} | ||
|
||
func TestRegisterAddrWithIpV4(t *testing.T) { | ||
expectedAddr, err := netip.ParseAddr("127.0.0.1") | ||
if err != nil { | ||
t.Errorf("invalid expected IP: %+v", expectedAddr) | ||
} | ||
|
||
addr := RegisterAddr("127.0.0.1") | ||
if addr != expectedAddr { | ||
t.Errorf("invalid IP: %+v", addr) | ||
} | ||
} | ||
|
||
func TestRegisterAddrWithIpV6(t *testing.T) { | ||
expectedAddr, err := netip.ParseAddr("2001:db8::1:0:0:1") | ||
if err != nil { | ||
t.Errorf("invalid expected IP: %+v", expectedAddr) | ||
} | ||
|
||
addr := RegisterAddr("2001:db8::1:0:0:1") | ||
if addr != expectedAddr { | ||
t.Errorf("invalid IP: %+v", addr) | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UDM should register with IPv6 for this code to work.
I think this change can be done in another PR or wait for UDM to have a PR ready.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That a work in progress, I begin to work on the IPv6 support for UDM adjivas/udm#1
I will open this PR to the Free5gc's UDM later