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

Feature: Edge gateway automatically obtains public IP #170

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions pkg/networkengine/vpndriver/wireguard/wireguard.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,15 +275,19 @@ func (w *wireguard) createEdgeConnections(desiredEdgeConns map[string]*vpndriver
} else {
remotePort = newConn.RemoteEndpoint.PublicPort
}
var endpoint *net.UDPAddr
if newConn.RemoteEndpoint.PublicIP != "" {
endpoint = &net.UDPAddr{
IP: net.ParseIP(newConn.RemoteEndpoint.PublicIP),
Port: remotePort,
}
}
peerConfigs = append(peerConfigs, wgtypes.PeerConfig{
PublicKey: *newKey,
Remove: false,
UpdateOnly: false,
PresharedKey: &w.psk,
Endpoint: &net.UDPAddr{
IP: net.ParseIP(newConn.RemoteEndpoint.PublicIP),
Port: remotePort,
},
Endpoint: endpoint,

PersistentKeepaliveInterval: &ka,
ReplaceAllowedIPs: true,
Expand Down
22 changes: 8 additions & 14 deletions pkg/tunnelengine/tunnelagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,16 @@ func (c *TunnelHandler) Handler() error {
// try to update public IP if empty.
gw := &gws.Items[i]
if ep := getTunnelActiveEndpoints(gw); ep != nil {
if ep.PublicIP == "" || c.natTraversal && (ep.NATType == "" || ep.PublicPort == 0 && ep.NATType != utils.NATSymmetric) {
if ep.PublicIP == "" {
if err := c.configGatewayPublicIP(gw); err != nil {
klog.ErrorS(err, "error config gateway public ip", "gateway", klog.KObj(gw))
}
if ep.PublicIP == "" {
if err := c.configGatewayPublicIP(gw); err != nil {
// output only error messages, without skipping
klog.ErrorS(err, "error config gateway public ip", "gateway", klog.KObj(gw))
}
if c.natTraversal && (ep.NATType == "" || ep.PublicPort == 0 && ep.NATType != utils.NATSymmetric) {
if err := c.configGatewayStunInfo(gw); err != nil {
klog.ErrorS(err, "error config gateway stun info", "gateway", klog.KObj(gw))
}
}
if c.natTraversal && (ep.NATType == "" || ep.PublicPort == 0 && ep.NATType != utils.NATSymmetric) {
if err := c.configGatewayStunInfo(gw); err != nil {
klog.ErrorS(err, "error config gateway stun info", "gateway", klog.KObj(gw))
}
continue
}
}
if !c.shouldHandleGateway(gw) {
Expand Down Expand Up @@ -212,10 +210,6 @@ func (c *TunnelHandler) shouldHandleGateway(gateway *v1beta1.Gateway) bool {
klog.InfoS("no active endpoint , waiting for sync", "gateway", klog.KObj(gateway))
return false
}
if ep.PublicIP == "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里是不是加下判断,只边缘gateway不强制要求public ip

klog.InfoS("no public IP for gateway, waiting for sync", "gateway", klog.KObj(gateway))
return false
}
if c.natTraversal {
if ep.NATType == "" {
klog.InfoS("no nat type for gateway, waiting for sync", "gateway", klog.KObj(gateway))
Expand Down
Loading