Skip to content

Commit

Permalink
Update for tunnel api change. Add agent unroute command.
Browse files Browse the repository at this point in the history
  • Loading branch information
plorenz committed May 25, 2023
1 parent 92e0e6b commit b687e42
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 6 deletions.
1 change: 1 addition & 0 deletions ziti/cmd/agentcli/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func NewAgentCmd(p common.OptionsProvider) *cobra.Command {
agentCmd.AddCommand(routerCmd)

routerCmd.AddCommand(NewRouteCmd(p))
routerCmd.AddCommand(NewUnrouteCmd(p))
routerCmd.AddCommand(NewSimpleAgentCustomCmd("dump-api-sessions", AgentAppRouter, debugops.DumpApiSessions, p))
routerCmd.AddCommand(NewSimpleChAgentCustomCmd("dump-routes", AgentAppRouter, int32(mgmt_pb.ContentType_RouterDebugDumpForwarderTablesRequestType), p))
routerCmd.AddCommand(NewSimpleChAgentCustomCmd("dump-links", AgentAppRouter, int32(mgmt_pb.ContentType_RouterDebugDumpLinksRequestType), p))
Expand Down
2 changes: 1 addition & 1 deletion ziti/cmd/agentcli/agent_router_add_route.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func NewRouteCmd(p common.OptionsProvider) *cobra.Command {
}

cmd := &cobra.Command{
Args: cobra.RangeArgs(3, 4),
Args: cobra.ExactArgs(4),
Use: "route <controller id> <circuit id> <source-address> <destination-address>",
RunE: func(cmd *cobra.Command, args []string) error {
action.Cmd = cmd
Expand Down
88 changes: 88 additions & 0 deletions ziti/cmd/agentcli/agent_router_unroute.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
Copyright NetFoundry Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package agentcli

import (
"fmt"
"github.com/openziti/channel/v2"
"github.com/openziti/fabric/pb/ctrl_pb"
"github.com/openziti/fabric/pb/mgmt_pb"
"github.com/openziti/fabric/router"
"github.com/openziti/ziti/ziti/cmd/common"
"github.com/spf13/cobra"
"google.golang.org/protobuf/proto"
)

type AgentUnrouteAction struct {
AgentOptions
}

func NewUnrouteCmd(p common.OptionsProvider) *cobra.Command {
action := &AgentUnrouteAction{
AgentOptions: AgentOptions{
CommonOptions: p(),
},
}

cmd := &cobra.Command{
Args: cobra.ExactArgs(1),
Use: "unroute <circuit id>",
RunE: func(cmd *cobra.Command, args []string) error {
action.Cmd = cmd
action.Args = args
return action.MakeChannelRequest(router.AgentAppId, action.makeRequest)
},
}

action.AddAgentOptions(cmd)

return cmd
}

func (self *AgentUnrouteAction) makeRequest(ch channel.Channel) error {
route := &ctrl_pb.Unroute{
CircuitId: self.Args[0],
Now: true,
}

buf, err := proto.Marshal(route)
if err != nil {
return err
}

msg := channel.NewMessage(int32(mgmt_pb.ContentType_RouterDebugUnrouteRequestType), buf)
reply, err := msg.WithTimeout(self.timeout).SendForReply(ch)
if err != nil {
return err
}

if reply.ContentType == channel.ContentTypeResultType {
result := channel.UnmarshalResult(reply)
if result.Success {
if len(result.Message) > 0 {
fmt.Printf("success: %v\n", result.Message)
} else {
fmt.Println("success")
}
} else {
fmt.Printf("error: %v\n", result.Message)
}
} else {
fmt.Printf("unexpected response type %v\n", reply.ContentType)
}
return nil
}
5 changes: 2 additions & 3 deletions ziti/cmd/demo/zcat.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,8 @@ func (self *zcatAction) run(_ *cobra.Command, args []string) {
addr = addr[atIdx+1:]
}

zitiContext, err := ziti.NewContext(zitiConfig)

if err != nil {
zitiContext, ctxErr := ziti.NewContext(zitiConfig)
if ctxErr != nil {
pfxlog.Logger().WithError(err).Fatal("could not create sdk context from config")
}

Expand Down
2 changes: 1 addition & 1 deletion ziti/tunnel/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func run(cmd *cobra.Command, args []string) {
_ = cmd.Flag("identity").Value.Set(args[0])
}

tProxyInterceptor, err = tproxy.New("")
tProxyInterceptor, err = tproxy.New(tproxy.Config{})
if err != nil {
log.Infof("tproxy initialization failed: %v", err)
} else {
Expand Down
2 changes: 1 addition & 1 deletion ziti/tunnel/tproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func runTProxy(cmd *cobra.Command, _ []string) error {
return err
}

interceptor, err = tproxy.New(lanIf)
interceptor, err = tproxy.New(tproxy.Config{LanIf: lanIf})
if err != nil {
return fmt.Errorf("failed to initialize tproxy interceptor: %v", err)
}
Expand Down

0 comments on commit b687e42

Please sign in to comment.