Skip to content

Commit

Permalink
feat(frr): implement ExitPrivileged mode
Browse files Browse the repository at this point in the history
Signed-off-by: Boris Glimcher <[email protected]>
  • Loading branch information
glimchb committed Oct 16, 2023
1 parent 15b7489 commit 6833728
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 46 deletions.
18 changes: 14 additions & 4 deletions pkg/utils/frr.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ type Frr interface {
FrrZebraCmd(ctx context.Context, command string) (string, error)
FrrBgpCmd(ctx context.Context, command string) (string, error)
Password(conn *telnet.Conn, delim string) error
Privileged(conn *telnet.Conn) error
EnterPrivileged(conn *telnet.Conn) error
ExitPrivileged(conn *telnet.Conn) error
}

// FrrWrapper wrapper for Frr package
Expand Down Expand Up @@ -82,15 +83,24 @@ func (n *FrrWrapper) Password(conn *telnet.Conn, delim string) error {
return conn.SkipUntil(delim)
}

// Privileged turns on privileged mode command
func (n *FrrWrapper) Privileged(conn *telnet.Conn) error {
// EnterPrivileged turns on privileged mode command
func (n *FrrWrapper) EnterPrivileged(conn *telnet.Conn) error {
_, err := conn.Write([]byte("enable\n"))
if err != nil {
return err
}
return n.Password(conn, "#")
}

// ExitPrivileged turns off privileged mode command
func (n *FrrWrapper) ExitPrivileged(conn *telnet.Conn) error {
_, err := conn.Write([]byte("disable\n"))
if err != nil {
return err
}
return conn.SkipUntil(">")
}

// FrrZebraCmd connects to Zebra telnet with password and runs command
func (n *FrrWrapper) FrrZebraCmd(ctx context.Context, command string) (string, error) {
// ports defined here https://docs.frrouting.org/en/latest/setup.html#services
Expand Down Expand Up @@ -136,7 +146,7 @@ func (n *FrrWrapper) TelnetDialAndCommunicate(ctx context.Context, command strin
return "", err
}

err = n.Privileged(conn)
err = n.EnterPrivileged(conn)
if err != nil {
return "", err
}
Expand Down
126 changes: 84 additions & 42 deletions pkg/utils/mocks/Frr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6833728

Please sign in to comment.