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

Expose Replycode in show commands #2

Open
wants to merge 3 commits into
base: master
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
16 changes: 13 additions & 3 deletions gobirdc.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,23 @@ type BirdClientOptions struct {
// SocketBufferSize: 4096,
// }
func New(opts *BirdClientOptions) *BirdClient {
if opts == nil || opts.SocketBufferSize == 0 || opts.Path == "" {
path := "/run/bird/bird.ctl"
socket_buffer_size := 4096

if opts == nil {
return &BirdClient{
s: socket.NewBirdSocket("/run/bird/bird.ctl", 4096),
s: socket.NewBirdSocket(path, socket_buffer_size),
}
}

if opts.Path != "" {
path = opts.Path
}
if opts.SocketBufferSize != 0 {
socket_buffer_size = opts.SocketBufferSize
}

return &BirdClient{
s: socket.NewBirdSocket(opts.Path, opts.SocketBufferSize),
s: socket.NewBirdSocket(path, socket_buffer_size),
}
}
32 changes: 16 additions & 16 deletions show.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package gobirdc

import (
"errors"
"fmt"
"strings"
)

Expand All @@ -19,7 +19,7 @@ func (b *BirdClient) ShowStatus() (resp, replyCode []byte, err error) {
}

if replyCode[0] != '0' {
err = errors.New("got a non-zero reply-code from the server")
err = fmt.Errorf("got a non-zero reply-code (%s) from the server", string(replyCode))
}

return
Expand All @@ -39,7 +39,7 @@ func (b *BirdClient) ShowMemory() (resp, replyCode []byte, err error) {
}

if replyCode[0] != '0' {
err = errors.New("got a non-zero reply-code from the server")
err = fmt.Errorf("got a non-zero reply-code (%s) from the server", string(replyCode))
}

return
Expand All @@ -65,7 +65,7 @@ func (b *BirdClient) ShowProtocols(args ...string) (resp, replyCode []byte, err
}

if replyCode[0] != '0' {
err = errors.New("got a non-zero reply-code from the server")
err = fmt.Errorf("got a non-zero reply-code (%s) from the server", string(replyCode))
}

return
Expand All @@ -92,7 +92,7 @@ func (b *BirdClient) ShowInterfaces(args ...string) (resp, replyCode []byte, err
}

if replyCode[0] != '0' {
err = errors.New("got a non-zero reply-code from the server")
err = fmt.Errorf("got a non-zero reply-code (%s) from the server", string(replyCode))
}

return
Expand All @@ -119,7 +119,7 @@ func (b *BirdClient) ShowRoute(args ...string) (resp, replyCode []byte, err erro
}

if replyCode[0] != '0' {
err = errors.New("got a non-zero reply-code from the server")
err = fmt.Errorf("got a non-zero reply-code (%s) from the server", string(replyCode))
}

return
Expand All @@ -146,7 +146,7 @@ func (b *BirdClient) ShowSymbols(args ...string) (resp, replyCode []byte, err er
}

if replyCode[0] != '0' {
err = errors.New("got a non-zero reply-code from the server")
err = fmt.Errorf("got a non-zero reply-code (%s) from the server", string(replyCode))
}

return
Expand All @@ -173,7 +173,7 @@ func (b *BirdClient) ShowBFDSessions(args ...string) (resp, replyCode []byte, er
}

if replyCode[0] != '0' {
err = errors.New("got a non-zero reply-code from the server")
err = fmt.Errorf("got a non-zero reply-code (%s) from the server", string(replyCode))
}

return
Expand All @@ -200,7 +200,7 @@ func (b *BirdClient) ShowBabelInterfaces(args ...string) (resp, replyCode []byte
}

if replyCode[0] != '0' {
err = errors.New("got a non-zero reply-code from the server")
err = fmt.Errorf("got a non-zero reply-code (%s) from the server", string(replyCode))
}

return
Expand All @@ -227,7 +227,7 @@ func (b *BirdClient) ShowBabelNeighbors(args ...string) (resp, replyCode []byte,
}

if replyCode[0] != '0' {
err = errors.New("got a non-zero reply-code from the server")
err = fmt.Errorf("got a non-zero reply-code (%s) from the server", string(replyCode))
}

return
Expand All @@ -254,7 +254,7 @@ func (b *BirdClient) ShowBabelEntries(args ...string) (resp, replyCode []byte, e
}

if replyCode[0] != '0' {
err = errors.New("got a non-zero reply-code from the server")
err = fmt.Errorf("got a non-zero reply-code (%s) from the server", string(replyCode))
}

return
Expand All @@ -281,7 +281,7 @@ func (b *BirdClient) ShowBabelRoutes(args ...string) (resp, replyCode []byte, er
}

if replyCode[0] != '0' {
err = errors.New("got a non-zero reply-code from the server")
err = fmt.Errorf("got a non-zero reply-code (%s) from the server", string(replyCode))
}

return
Expand All @@ -308,7 +308,7 @@ func (b *BirdClient) ShowOSPF(args ...string) (resp, replyCode []byte, err error
}

if replyCode[0] != '0' {
err = errors.New("got a non-zero reply-code from the server")
err = fmt.Errorf("got a non-zero reply-code (%s) from the server", string(replyCode))
}

return
Expand All @@ -335,7 +335,7 @@ func (b *BirdClient) ShowRIPInterfaces(args ...string) (resp, replyCode []byte,
}

if replyCode[0] != '0' {
err = errors.New("got a non-zero reply-code from the server")
err = fmt.Errorf("got a non-zero reply-code (%s) from the server", string(replyCode))
}

return
Expand All @@ -362,7 +362,7 @@ func (b *BirdClient) ShowRIPNeighbors(args ...string) (resp, replyCode []byte, e
}

if replyCode[0] != '0' {
err = errors.New("got a non-zero reply-code from the server")
err = fmt.Errorf("got a non-zero reply-code (%s) from the server", string(replyCode))
}

return
Expand All @@ -389,7 +389,7 @@ func (b *BirdClient) ShowStatic(args ...string) (resp, replyCode []byte, err err
}

if replyCode[0] != '0' {
err = errors.New("got a non-zero reply-code from the server")
err = fmt.Errorf("got a non-zero reply-code (%s) from the server", string(replyCode))
}

return
Expand Down
2 changes: 1 addition & 1 deletion socket/socket.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var replyCodeExpr *regexp.Regexp

func init() {
// https://gitlab.nic.cz/labs/bird/-/blob/master/doc/reply_codes
replyCodeExpr = regexp.MustCompile(`(?m)^([089][0-9]{3})`)
replyCodeExpr = regexp.MustCompile(`(?m)^([0189][0-9]{3})`)
}

// BirdSocket represents a socket connection to bird daemon
Expand Down