fix dns bug, fix cidr bug

This commit is contained in:
p_caiwfeng
2021-11-17 19:45:01 +08:00
parent dfc7058ac9
commit af33818ac0
5 changed files with 17 additions and 15 deletions

View File

@@ -17,11 +17,8 @@ import (
"golang.org/x/net/ipv6"
)
type key [16]byte
func ipToTunRouteKey(ip net.IP) (key key) {
copy(key[:], ip.To16())
return
func ipToTunRouteKey(ip net.IP) string {
return ip.To16().String()
}
type tunHandler struct {
@@ -253,11 +250,11 @@ func (h *tunHandler) transportTun(tun net.Conn, conn net.PacketConn, raddr net.A
return err
}
rkey := ipToTunRouteKey(src)
if actual, loaded := h.routes.LoadOrStore(rkey, addr); loaded {
routeKey := ipToTunRouteKey(src)
if actual, loaded := h.routes.LoadOrStore(routeKey, addr); loaded {
if actual.(net.Addr).String() != addr.String() {
log.Debugf("[tun] update route: %s -> %s (old %s)", src, addr, actual.(net.Addr))
h.routes.Store(rkey, addr)
h.routes.Store(routeKey, addr)
}
} else {
log.Debugf("[tun] new route: %s -> %s", src, addr)

View File

@@ -26,8 +26,8 @@ func GetDNSServiceIPFromPod(clientset *kubernetes.Clientset, restclient *rest.RE
for i := range ipp {
resolvConf.Servers[i] = ipp[i]
}
return resolvConf, nil
}
return resolvConf, nil
} else {
return nil, err
}

View File

@@ -82,7 +82,7 @@ func (c *ConnectOptions) createRemoteInboundPod() {
tunIp.IP.String(),
c.routerIP,
virtualShadowIp.String(),
strings.Join(list, ","),
trafficManager.String(),
)
} else {
err = CreateInboundPod(
@@ -93,7 +93,7 @@ func (c *ConnectOptions) createRemoteInboundPod() {
tunIp.IP.String(),
c.routerIP,
virtualShadowIp.String(),
strings.Join(list, ","),
trafficManager.String(),
)
}
if err != nil {

View File

@@ -352,6 +352,8 @@ func getEnvoyConfig(port uint32, localAddress string) string {
})
withHeader := envoyresource.MakeCluster("", "service_debug_withHeader")
withHeader.ClusterDiscoveryType = &v22.Cluster_Type{Type: v22.Cluster_STATIC}
withHeader.EdsClusterConfig = nil
withHeader.LoadAssignment = &v22.ClusterLoadAssignment{
ClusterName: "service_debug_withoutHeader",
Endpoints: []*endpoint.LocalityLbEndpoints{
@@ -372,6 +374,8 @@ func getEnvoyConfig(port uint32, localAddress string) string {
Policy: nil,
}
withoutHeader := envoyresource.MakeCluster("", "service_debug_withoutHeader")
withoutHeader.ClusterDiscoveryType = &v22.Cluster_Type{Type: v22.Cluster_STATIC}
withoutHeader.EdsClusterConfig = nil
withoutHeader.LoadAssignment = &v22.ClusterLoadAssignment{
ClusterName: "service_debug_withoutHeader",
Endpoints: []*endpoint.LocalityLbEndpoints{
@@ -397,7 +401,7 @@ func getEnvoyConfig(port uint32, localAddress string) string {
Clusters: []*v22.Cluster{withHeader, withoutHeader},
},
}
marshal, _ := json.Marshal(&resources)
marshal, _ := json.Marshal(resources)
toYAML, _ := yaml.JSONToYAML(marshal)
return string(toYAML)
}

View File

@@ -277,9 +277,10 @@ func server() {
}
func TestParseEnvoy(t *testing.T) {
port := uint32(0)
localAddress := ""
getEnvoyConfig(port, localAddress)
port := uint32(8080)
localAddress := "223.254.254.2"
config := getEnvoyConfig(port, localAddress)
fmt.Println(config)
}
func init() {