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

Add ability to inject gzip/bzip2 compressed MRT files #2815

Closed
wants to merge 3 commits into from
Closed
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
24 changes: 20 additions & 4 deletions cmd/gobgp/mrt.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@
package main

import (
"compress/bzip2"
"compress/gzip"
"fmt"
"io"
"os"
"strconv"
"strings"
"time"

"github.com/spf13/cobra"
Expand All @@ -31,12 +34,25 @@ import (
)

func injectMrt() error {

file, err := os.Open(mrtOpts.Filename)
var reader io.Reader
fileReader, err := os.Open(mrtOpts.Filename)
if err != nil {
return fmt.Errorf("failed to open file: %s", err)
}

if strings.HasSuffix(mrtOpts.Filename, ".gz") {
gzReader, err := gzip.NewReader(fileReader)
if err != nil {
return fmt.Errorf("failed to open gzip file: %s", err)
}
reader = gzReader
} else if strings.HasSuffix(mrtOpts.Filename, ".bz2") {
bz2Reader := bzip2.NewReader(fileReader)
reader = bz2Reader
} else {
reader = fileReader
}

if mrtOpts.NextHop != nil && !mrtOpts.SkipV4 && !mrtOpts.SkipV6 {
fmt.Println("You should probably specify either --no-ipv4 or --no-ipv6 when overwriting nexthop, unless your dump contains only one type of routes")
}
Expand All @@ -52,7 +68,7 @@ func injectMrt() error {
var peers []*mrt.Peer
for {
buf := make([]byte, mrt.MRT_COMMON_HEADER_LEN)
_, err := file.Read(buf)
_, err := io.ReadFull(reader, buf)
if err == io.EOF {
break
} else if err != nil {
Expand All @@ -66,7 +82,7 @@ func injectMrt() error {
}

buf = make([]byte, h.Len)
_, err = file.Read(buf)
_, err = io.ReadFull(reader, buf)
if err != nil {
exitWithError(fmt.Errorf("failed to read"))
}
Expand Down
1 change: 1 addition & 0 deletions tools/spell-check/dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ flowspec
gobgp
gobgpd
grpc
gzip
ibgp
ipproto
isis
Expand Down
Loading