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

fix: cmd-nse-istio-proxy is not working if address has len less or greater than 10 #6

Merged
merged 2 commits into from
May 14, 2022
Merged
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
7 changes: 3 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ require (
github.com/edwarnicke/grpcfd v1.1.2
github.com/kelseyhightower/envconfig v1.4.0
github.com/miekg/dns v1.1.49
github.com/networkservicemesh/api v1.3.2-0.20220512163820-8c875d61945b
github.com/networkservicemesh/sdk v0.5.1-0.20220513003022-4d9bebd00c37
github.com/networkservicemesh/sdk-kernel v0.0.0-20220513094228-e0f2b84203da
github.com/networkservicemesh/sdk-sriov v0.0.0-20220507174402-1f53cfa20170
github.com/networkservicemesh/api v1.3.2-0.20220514193644-73abc067b2ce
github.com/networkservicemesh/sdk v0.5.1-0.20220514195906-4ea3f90ef51e
github.com/networkservicemesh/sdk-kernel v0.0.0-20220514201519-2b7a3d22ee80
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.8.1
github.com/spiffe/go-spiffe/v2 v2.0.0
Expand Down
21 changes: 6 additions & 15 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -172,17 +172,12 @@ github.com/nats-io/nats.go v1.13.1-0.20220308171302-2f2f6968e98d/go.mod h1:BPko4
github.com/nats-io/nkeys v0.3.0/go.mod h1:gvUNGjVcM2IPr5rCsRsC6Wb3Hr2CQAm08dsxtV6A5y4=
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
github.com/nats-io/stan.go v0.10.2/go.mod h1:vo2ax8K2IxaR3JtEMLZRFKIdoK/3o1/PKueapB7ezX0=
github.com/networkservicemesh/api v1.3.0-rc.1.0.20220405210054-fbcde048efa5/go.mod h1:B6meq/SWjWR6bGXZdXPfbOeaBK+T1JayLdtEJQCsXKU=
github.com/networkservicemesh/api v1.3.2-0.20220512163820-8c875d61945b h1:suJRTlWU7/N0gF3FdcN9kCf1MO5Z7CdVSBdb2JTkLhk=
github.com/networkservicemesh/api v1.3.2-0.20220512163820-8c875d61945b/go.mod h1:hOF2844BSstH1311oDMDgqqXS+kdc77htZNPRKl9mf8=
github.com/networkservicemesh/sdk v0.5.1-0.20220507173809-41196bdf49db/go.mod h1:G+NdPbtzcOWx1VljOj+L4kvZPQyYpiwCp84JYs+hGtc=
github.com/networkservicemesh/sdk v0.5.1-0.20220513003022-4d9bebd00c37 h1:1wQY2oelI/porPJb9KREzozx8UOhJ05DumSBPkbVrhY=
github.com/networkservicemesh/sdk v0.5.1-0.20220513003022-4d9bebd00c37/go.mod h1:7Aa9sCLOVzhsbR7LBJ1nSK/YCzd/EO/YK3BbHPB0puw=
github.com/networkservicemesh/sdk-kernel v0.0.0-20220507174054-396e6556b392/go.mod h1:bqow7oO97KM7UJBW3/bb19HQV96XZ2mEb2jBzuJrEkY=
github.com/networkservicemesh/sdk-kernel v0.0.0-20220513094228-e0f2b84203da h1:FLXDVY/XzAGxdsO2Czd+15bzThDO5oOoe0n3r1+/hTg=
github.com/networkservicemesh/sdk-kernel v0.0.0-20220513094228-e0f2b84203da/go.mod h1:qkXN/u/d/8QMBu52j6gaiiAsoaA85m58JTD65dMNGLM=
github.com/networkservicemesh/sdk-sriov v0.0.0-20220507174402-1f53cfa20170 h1:4rM6FZiCsU38AG8a5pKh4SKGC8zlGklNonjraBcndvM=
github.com/networkservicemesh/sdk-sriov v0.0.0-20220507174402-1f53cfa20170/go.mod h1:lFEArhpP3AloaY6JVIDqFP89dPGn1QenBJy5uuxE5Rw=
github.com/networkservicemesh/api v1.3.2-0.20220514193644-73abc067b2ce h1:kpVCSUnoJoIy35F60F6DBuOWY+FZuVwYf3TlptLZP6k=
github.com/networkservicemesh/api v1.3.2-0.20220514193644-73abc067b2ce/go.mod h1:hOF2844BSstH1311oDMDgqqXS+kdc77htZNPRKl9mf8=
github.com/networkservicemesh/sdk v0.5.1-0.20220514195906-4ea3f90ef51e h1:CDM6JS8uYAlKwcY24gI2JioWe81AmLEZLBEvFwXgS3o=
github.com/networkservicemesh/sdk v0.5.1-0.20220514195906-4ea3f90ef51e/go.mod h1:twQwRxXlr01yriIoyGkKK5Rd1hOI0GMbPn+RnBy+i0s=
github.com/networkservicemesh/sdk-kernel v0.0.0-20220514201519-2b7a3d22ee80 h1:YiHNxzKq2N0NvbuVOzeFy9X/2lvSG0Au5M5k78zooWM=
github.com/networkservicemesh/sdk-kernel v0.0.0-20220514201519-2b7a3d22ee80/go.mod h1:COtoHC9b4npq8qObS5MH7sxohCYn3AXXLEeYhicAhzA=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
github.com/olekukonko/tablewriter v0.0.1/go.mod h1:vsDQFd/mU46D+Z4whnwzcISnGGzXWMclvtLoiIKAKIo=
Expand Down Expand Up @@ -238,7 +233,6 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/tatsushid/go-fastping v0.0.0-20160109021039-d7bb493dee3e/go.mod h1:B4+Kq1u5FlULTjFSM707Q6e/cOHFv0z/6QRoxubDIQ8=
github.com/tv42/httpunix v0.0.0-20150427012821-b75d8614f926/go.mod h1:9ESjWnEqriFuLhtthL60Sar/7RFoluCcXsuvEwTV5KM=
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
github.com/vishvananda/netlink v1.1.1-0.20220118170537-d6b03fdeb845/go.mod h1:twkDnbuQxJYemMlGd4JFIcuhgX83tXhKS2B/PRMpOho=
Expand Down Expand Up @@ -312,8 +306,6 @@ golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTk
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
Expand Down Expand Up @@ -401,7 +393,6 @@ golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBn
golang.org/x/tools v0.0.0-20190920225731-5eefd052ad72/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191108193012-7d206e10da11/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
Expand Down
5 changes: 1 addition & 4 deletions internal/pkg/imports/imports_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,22 @@ import (
_ "github.com/miekg/dns"
_ "github.com/networkservicemesh/api/pkg/api/networkservice"
_ "github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/kernel"
_ "github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/noop"
_ "github.com/networkservicemesh/api/pkg/api/registry"
_ "github.com/networkservicemesh/sdk-kernel/pkg/kernel/networkservice/setiptables4nattemplate"
_ "github.com/networkservicemesh/sdk-kernel/pkg/kernel/networkservice/setroutelocalnet"
_ "github.com/networkservicemesh/sdk-sriov/pkg/networkservice/common/token"
_ "github.com/networkservicemesh/sdk-sriov/pkg/tools/tokens"
_ "github.com/networkservicemesh/sdk/pkg/networkservice/chains/endpoint"
_ "github.com/networkservicemesh/sdk/pkg/networkservice/common/authorize"
_ "github.com/networkservicemesh/sdk/pkg/networkservice/common/mechanisms"
_ "github.com/networkservicemesh/sdk/pkg/networkservice/common/mechanisms/kernel"
_ "github.com/networkservicemesh/sdk/pkg/networkservice/common/mechanisms/recvfd"
_ "github.com/networkservicemesh/sdk/pkg/networkservice/common/mechanisms/sendfd"
_ "github.com/networkservicemesh/sdk/pkg/networkservice/common/null"
_ "github.com/networkservicemesh/sdk/pkg/networkservice/common/onidle"
_ "github.com/networkservicemesh/sdk/pkg/networkservice/connectioncontext/dnscontext"
_ "github.com/networkservicemesh/sdk/pkg/networkservice/core/chain"
_ "github.com/networkservicemesh/sdk/pkg/networkservice/ipam/point2pointipam"
_ "github.com/networkservicemesh/sdk/pkg/registry/chains/client"
_ "github.com/networkservicemesh/sdk/pkg/registry/common/sendfd"
_ "github.com/networkservicemesh/sdk/pkg/tools/clientinfo"
_ "github.com/networkservicemesh/sdk/pkg/tools/debug"
_ "github.com/networkservicemesh/sdk/pkg/tools/dnscontext"
_ "github.com/networkservicemesh/sdk/pkg/tools/grpcutils"
Expand Down
38 changes: 10 additions & 28 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,23 @@ import (

"github.com/networkservicemesh/api/pkg/api/networkservice"
kernelmech "github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/kernel"
"github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/noop"
registryapi "github.com/networkservicemesh/api/pkg/api/registry"
"github.com/networkservicemesh/cmd-nse-istio-proxy/internal/pkg/dns"
"github.com/networkservicemesh/sdk-kernel/pkg/kernel/networkservice/setiptables4nattemplate"
"github.com/networkservicemesh/sdk-kernel/pkg/kernel/networkservice/setroutelocalnet"
"github.com/networkservicemesh/sdk-sriov/pkg/networkservice/common/token"
"github.com/networkservicemesh/sdk-sriov/pkg/tools/tokens"
"github.com/networkservicemesh/sdk/pkg/networkservice/chains/endpoint"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/authorize"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/mechanisms"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/mechanisms/kernel"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/mechanisms/recvfd"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/mechanisms/sendfd"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/null"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/onidle"
"github.com/networkservicemesh/sdk/pkg/networkservice/connectioncontext/dnscontext"
"github.com/networkservicemesh/sdk/pkg/networkservice/core/chain"
"github.com/networkservicemesh/sdk/pkg/networkservice/ipam/point2pointipam"
registryclient "github.com/networkservicemesh/sdk/pkg/registry/chains/client"
registrysendfd "github.com/networkservicemesh/sdk/pkg/registry/common/sendfd"
"github.com/networkservicemesh/sdk/pkg/tools/clientinfo"
"github.com/networkservicemesh/sdk/pkg/tools/debug"
dnstools "github.com/networkservicemesh/sdk/pkg/tools/dnscontext"
"github.com/networkservicemesh/sdk/pkg/tools/grpcutils"
Expand Down Expand Up @@ -158,6 +155,8 @@ func main() {
logrus.Fatal("expected CIDR ipv4")
}

clientinfo.AddClientInfo(ctx, config.Labels)

l, err := logrus.ParseLevel(config.LogLevel)
if err != nil {
logrus.Fatalf("invalid log level %s", config.LogLevel)
Expand Down Expand Up @@ -204,7 +203,6 @@ func main() {
// ********************************************************************************
log.FromContext(ctx).Infof("executing phase 4: create network service endpoint")
// ********************************************************************************
tokenServer := getSriovTokenServerChainElement(ctx)
setRulesServer := getSetIPTablesRulesServerChainElement()

config.DNSConfigs = append(config.DNSConfigs, &networkservice.DNSConfig{
Expand All @@ -221,9 +219,7 @@ func main() {
recvfd.NewServer(),
mechanisms.NewServer(map[string]networkservice.NetworkServiceServer{
kernelmech.MECHANISM: kernel.NewServer(),
noop.MECHANISM: null.NewServer(),
}),
tokenServer,
dnscontext.NewServer(config.DNSConfigs...),
setroutelocalnet.NewServer(),
setRulesServer,
Expand Down Expand Up @@ -295,7 +291,7 @@ func main() {
ListenOn: ":53",
}

var dnsProxyErrCh = dnsServer.ListenAndServe(ctx)
var dnsServerErrCh = dnsServer.ListenAndServe(ctx)

// ********************************************************************************
log.FromContext(ctx).Infof("startup completed in %v", time.Since(starttime))
Expand All @@ -306,10 +302,13 @@ func main() {
select {
case <-ctx.Done():
return
case err := <-dnsProxyErrCh:
case err, ok := <-dnsServerErrCh:
if err != nil {
log.FromContext(ctx).Errorf("ProxyRewriteServer: unexpected error: %v", err.Error())
}
if !ok {
return
}
}
}
}
Expand All @@ -333,33 +332,16 @@ func getSetIPTablesRulesServerChainElement() networkservice.NetworkServiceServer
"-A NSM_PREROUTE -j ISTIO_REDIRECT",
"-I PREROUTING 1 -p tcp -i {{ .NsmInterfaceName }} -j NSM_PREROUTE",
"-N NSM_OUTPUT",
"-A NSM_OUTPUT -j DNAT --to-destination {{ slice (index .NsmSrcIPs 0) 0 10 }}",
"-A NSM_OUTPUT -j DNAT --to-destination {{ index .NsmSrcIPs 0 }}",
"-A OUTPUT -p tcp -s 127.0.0.6 -j NSM_OUTPUT",
"-N NSM_POSTROUTING",
"-A NSM_POSTROUTING -j SNAT --to-source {{ slice (index .NsmDstIPs 0) 0 10 }}",
"-A NSM_POSTROUTING -j SNAT --to-source {{ index .NsmDstIPs 0 }}",
"-A POSTROUTING -p tcp -o {{ .NsmInterfaceName }} -j NSM_POSTROUTING",
}

return setiptables4nattemplate.NewServer(defaultRules)
}

func getSriovTokenServerChainElement(ctx context.Context) (tokenServer networkservice.NetworkServiceServer) {
sriovTokens := tokens.FromEnv(os.Environ())
switch len(sriovTokens) {
case 0:
tokenServer = null.NewServer()
case 1:
var tokenKey string
for tokenKey = range sriovTokens {
break
}
tokenServer = token.NewServer(tokenKey)
default:
log.FromContext(ctx).Fatalf("endpoint must be configured with none or only one sriov resource")
}
return
}

func exitOnErr(ctx context.Context, cancel context.CancelFunc, errCh <-chan error) {
// If we already have an error, log it and exit
select {
Expand Down