From 4a6e13f43c34b7ee86478497b46f9300a25bd605 Mon Sep 17 00:00:00 2001 From: Gian Lorenzo Meocci Date: Wed, 21 Aug 2024 11:49:06 +0200 Subject: [PATCH 1/2] Fix regex reply code and support partial config in the new --- gobirdc.go | 16 +++++++++++++--- socket/socket.go | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/gobirdc.go b/gobirdc.go index 54034eb..f6ea86f 100644 --- a/gobirdc.go +++ b/gobirdc.go @@ -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), } } diff --git a/socket/socket.go b/socket/socket.go index db44a1e..fe4040b 100644 --- a/socket/socket.go +++ b/socket/socket.go @@ -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 From 0611ed7c46b6bfbaf0ce2ad0ae2ee96fcc4e7c6a Mon Sep 17 00:00:00 2001 From: Gian Lorenzo Meocci Date: Thu, 22 Aug 2024 21:34:28 +0200 Subject: [PATCH 2/2] revert socket.go --- socket/socket.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/socket/socket.go b/socket/socket.go index fe4040b..db44a1e 100644 --- a/socket/socket.go +++ b/socket/socket.go @@ -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)^([0189][0-9]{3})`) + replyCodeExpr = regexp.MustCompile(`(?m)^([089][0-9]{3})`) } // BirdSocket represents a socket connection to bird daemon