Skip to content

Commit

Permalink
fix staticcheck warnings
Browse files Browse the repository at this point in the history
Signed-off-by: FUJITA Tomonori <[email protected]>
  • Loading branch information
fujita committed Aug 5, 2022
1 parent d8a7ac9 commit f862a96
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 69 deletions.
4 changes: 2 additions & 2 deletions cmd/gobgpd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package main

import (
"fmt"
"io/ioutil"
"io"
"net/http"
_ "net/http/pprof"
"os"
Expand Down Expand Up @@ -101,7 +101,7 @@ func main() {
}

if opts.DisableStdlog {
logger.SetOutput(ioutil.Discard)
logger.SetOutput(io.Discard)
} else {
logger.SetOutput(os.Stdout)
}
Expand Down
10 changes: 6 additions & 4 deletions internal/pkg/table/adj.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,12 @@ func (adj *AdjRib) Update(pathList []*Path) {
}
}

/* The provided pathList is expected to be the real candidate routes after policy evaluation.
For routes that are filtered by policy, there could be a mismatch between display
and actual rib sent to the peer (if softreset out was not run).
Only used to display adj-out because we do not maintain a separate adj-out table
/*
The provided pathList is expected to be the real candidate routes after policy evaluation.
For routes that are filtered by policy, there could be a mismatch between display
and actual rib sent to the peer (if softreset out was not run).
Only used to display adj-out because we do not maintain a separate adj-out table
*/
func (adj *AdjRib) UpdateAdjRibOut(pathList []*Path) {
for _, path := range pathList {
Expand Down
1 change: 0 additions & 1 deletion internal/pkg/table/destination.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,6 @@ func (dest *Destination) Calculate(logger log.Logger, newPath *Path) *Update {
// since not all paths get installed into the table due to bgp policy and
// we can receive withdraws for such paths and withdrawals may not be
// stopped by the same policies.
//
func (dest *Destination) explicitWithdraw(logger log.Logger, withdraw *Path) *Path {
logger.Debug("Removing withdrawals",
log.Fields{
Expand Down
97 changes: 65 additions & 32 deletions internal/pkg/table/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ import (
)

// before:
// as-path : 65000, 4000, 400000, 300000, 40001
//
// as-path : 65000, 4000, 400000, 300000, 40001
//
// expected result:
// as-path : 65000, 4000, 23456, 23456, 40001
// as4-path : 65000, 4000, 400000, 300000, 40001
//
// as-path : 65000, 4000, 23456, 23456, 40001
// as4-path : 65000, 4000, 400000, 300000, 40001
func TestAsPathAs2Trans1(t *testing.T) {
as := []uint32{65000, 4000, 400000, 300000, 40001}
params := []bgp.AsPathParamInterface{bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, as)}
Expand All @@ -54,9 +57,12 @@ func TestAsPathAs2Trans1(t *testing.T) {
}

// before:
// as-path : 65000, 4000, 40000, 30000, 40001
//
// as-path : 65000, 4000, 40000, 30000, 40001
//
// expected result:
// as-path : 65000, 4000, 40000, 30000, 40001
//
// as-path : 65000, 4000, 40000, 30000, 40001
func TestAsPathAs2Trans2(t *testing.T) {
as := []uint32{65000, 4000, 40000, 30000, 40001}
params := []bgp.AsPathParamInterface{bgp.NewAs4PathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, as)}
Expand All @@ -74,10 +80,13 @@ func TestAsPathAs2Trans2(t *testing.T) {
}

// before:
// as-path : 65000, 4000, 23456, 23456, 40001
// as4-path : 400000, 300000, 40001
//
// as-path : 65000, 4000, 23456, 23456, 40001
// as4-path : 400000, 300000, 40001
//
// expected result:
// as-path : 65000, 4000, 400000, 300000, 40001
//
// as-path : 65000, 4000, 400000, 300000, 40001
func TestAsPathAs4Trans1(t *testing.T) {
as := []uint16{65000, 4000, bgp.AS_TRANS, bgp.AS_TRANS, 40001}
params := []bgp.AsPathParamInterface{bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, as)}
Expand All @@ -99,10 +108,13 @@ func TestAsPathAs4Trans1(t *testing.T) {
}

// before:
// as-path : 65000, 4000, {10, 20, 30}, 23456, 23456, 40001
// as4-path : 400000, 300000, 40001
//
// as-path : 65000, 4000, {10, 20, 30}, 23456, 23456, 40001
// as4-path : 400000, 300000, 40001
//
// expected result:
// as-path : 65000, 4000, {10, 20, 30}, 400000, 300000, 40001
//
// as-path : 65000, 4000, {10, 20, 30}, 400000, 300000, 40001
func TestAsPathAs4Trans2(t *testing.T) {
as1 := []uint16{65000, 4000}
param1 := bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, as1)
Expand Down Expand Up @@ -134,10 +146,13 @@ func TestAsPathAs4Trans2(t *testing.T) {
}

// before:
// as-path : 65000, 4000, {10, 20, 30}, 23456, 23456, 40001
// as4-path : 3000, 400000, 300000, 40001
//
// as-path : 65000, 4000, {10, 20, 30}, 23456, 23456, 40001
// as4-path : 3000, 400000, 300000, 40001
//
// expected result:
// as-path : 65000, 4000, 3000, 400000, 300000, 40001
//
// as-path : 65000, 4000, 3000, 400000, 300000, 40001
func TestAsPathAs4Trans3(t *testing.T) {
as1 := []uint16{65000, 4000}
param1 := bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, as1)
Expand Down Expand Up @@ -165,10 +180,13 @@ func TestAsPathAs4Trans3(t *testing.T) {
}

// before:
// as-path : 65000, 4000, 23456, 23456, 40001
// as4-path : 400000, 300000, 40001, {10, 20, 30}
//
// as-path : 65000, 4000, 23456, 23456, 40001
// as4-path : 400000, 300000, 40001, {10, 20, 30}
//
// expected result:
// as-path : 65000, 400000, 300000, 40001, {10, 20, 30}
//
// as-path : 65000, 400000, 300000, 40001, {10, 20, 30}
func TestAsPathAs4Trans4(t *testing.T) {
as := []uint16{65000, 4000, bgp.AS_TRANS, bgp.AS_TRANS, 40001}
params := []bgp.AsPathParamInterface{bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, as)}
Expand Down Expand Up @@ -196,10 +214,13 @@ func TestAsPathAs4Trans4(t *testing.T) {
}

// before:
// as-path : 65000, 4000, 23456, 23456, 40001
// as4-path : {10, 20, 30} 400000, 300000, 40001
//
// as-path : 65000, 4000, 23456, 23456, 40001
// as4-path : {10, 20, 30} 400000, 300000, 40001
//
// expected result:
// as-path : 65000, {10, 20, 30}, 400000, 300000, 40001
//
// as-path : 65000, {10, 20, 30}, 400000, 300000, 40001
func TestAsPathAs4Trans5(t *testing.T) {
as := []uint16{65000, 4000, bgp.AS_TRANS, bgp.AS_TRANS, 40001}
params := []bgp.AsPathParamInterface{bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, as)}
Expand Down Expand Up @@ -228,10 +249,13 @@ func TestAsPathAs4Trans5(t *testing.T) {
}

// before:
// as-path : 65000, 4000, 23456, 23456, 40001
// as4-path : 100000, 65000, 4000, 400000, 300000, 40001
//
// as-path : 65000, 4000, 23456, 23456, 40001
// as4-path : 100000, 65000, 4000, 400000, 300000, 40001
//
// expected result:
// as-path : 65000, 4000, 23456, 23456, 40001
//
// as-path : 65000, 4000, 23456, 23456, 40001
func TestAsPathAs4TransInvalid1(t *testing.T) {
as := []uint16{65000, 4000, bgp.AS_TRANS, bgp.AS_TRANS, 40001}
params := []bgp.AsPathParamInterface{bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, as)}
Expand All @@ -254,10 +278,13 @@ func TestAsPathAs4TransInvalid1(t *testing.T) {
}

// before:
// as-path : 65000, 4000, 23456, 23456, 40001
// as4-path : 300000, 40001
//
// as-path : 65000, 4000, 23456, 23456, 40001
// as4-path : 300000, 40001
//
// expected result:
// as-path : 65000, 4000, 23456, 300000, 40001
//
// as-path : 65000, 4000, 23456, 300000, 40001
func TestAsPathAs4TransInvalid2(t *testing.T) {
as := []uint16{65000, 4000, bgp.AS_TRANS, bgp.AS_TRANS, 40001}
params := []bgp.AsPathParamInterface{bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, as)}
Expand All @@ -280,10 +307,13 @@ func TestAsPathAs4TransInvalid2(t *testing.T) {
}

// before:
// as-path : 65000, 4000, 23456, 23456, 40001
// as4-path : nil
//
// as-path : 65000, 4000, 23456, 23456, 40001
// as4-path : nil
//
// expected result:
// as-path : 65000, 4000, 23456, 23456, 40001
//
// as-path : 65000, 4000, 23456, 23456, 40001
func TestAsPathAs4TransInvalid3(t *testing.T) {
as := []uint16{65000, 4000, bgp.AS_TRANS, bgp.AS_TRANS, 40001}
params := []bgp.AsPathParamInterface{bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, as)}
Expand All @@ -302,10 +332,13 @@ func TestAsPathAs4TransInvalid3(t *testing.T) {
}

// before:
// as-path : 65000, 4000, 23456, 23456, 40001
// as4-path : empty
//
// as-path : 65000, 4000, 23456, 23456, 40001
// as4-path : empty
//
// expected result:
// as-path : 65000, 4000, 23456, 23456, 40001
//
// as-path : 65000, 4000, 23456, 23456, 40001
func TestAsPathAs4TransInvalid4(t *testing.T) {
as := []uint16{65000, 4000, bgp.AS_TRANS, bgp.AS_TRANS, 40001}
params := []bgp.AsPathParamInterface{bgp.NewAsPathParam(bgp.BGP_ASPATH_ATTR_TYPE_SEQ, as)}
Expand Down
35 changes: 18 additions & 17 deletions internal/pkg/table/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,25 +647,26 @@ func (path *Path) GetLabelString() string {
// PrependAsn prepends AS number.
// This function updates the AS_PATH attribute as follows.
// (If the peer is in the confederation member AS,
// replace AS_SEQUENCE in the following sentence with AS_CONFED_SEQUENCE.)
// 1) if the first path segment of the AS_PATH is of type
// AS_SEQUENCE, the local system prepends the specified AS num as
// the last element of the sequence (put it in the left-most
// position with respect to the position of octets in the
// protocol message) the specified number of times.
// If the act of prepending will cause an overflow in the AS_PATH
// segment (i.e., more than 255 ASes),
// it SHOULD prepend a new segment of type AS_SEQUENCE
// and prepend its own AS number to this new segment.
//
// 2) if the first path segment of the AS_PATH is of other than type
// AS_SEQUENCE, the local system prepends a new path segment of type
// AS_SEQUENCE to the AS_PATH, including the specified AS number in
// that segment.
// replace AS_SEQUENCE in the following sentence with AS_CONFED_SEQUENCE.)
// 1) if the first path segment of the AS_PATH is of type
// AS_SEQUENCE, the local system prepends the specified AS num as
// the last element of the sequence (put it in the left-most
// position with respect to the position of octets in the
// protocol message) the specified number of times.
// If the act of prepending will cause an overflow in the AS_PATH
// segment (i.e., more than 255 ASes),
// it SHOULD prepend a new segment of type AS_SEQUENCE
// and prepend its own AS number to this new segment.
//
// 3) if the AS_PATH is empty, the local system creates a path
// segment of type AS_SEQUENCE, places the specified AS number
// into that segment, and places that segment into the AS_PATH.
// 2) if the first path segment of the AS_PATH is of other than type
// AS_SEQUENCE, the local system prepends a new path segment of type
// AS_SEQUENCE to the AS_PATH, including the specified AS number in
// that segment.
//
// 3) if the AS_PATH is empty, the local system creates a path
// segment of type AS_SEQUENCE, places the specified AS number
// into that segment, and places that segment into the AS_PATH.
func (path *Path) PrependAsn(asn uint32, repeat uint8, confed bool) {
var segType uint8
if confed {
Expand Down
19 changes: 14 additions & 5 deletions internal/pkg/zebra/zapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const (
)

// Interface Link Layer Types.
//
//go:generate stringer -type=linkType
type linkType uint32

Expand Down Expand Up @@ -175,6 +176,7 @@ func (t interfaceAddressFlag) String() string {
}

// Address Family IDentifier.
//
//go:generate stringer -type=afi
type afi uint8

Expand All @@ -186,6 +188,7 @@ const (
)

// Safi is Subsequent Address Family IDentifier.
//
//go:generate stringer -type=Safi
type Safi uint8

Expand Down Expand Up @@ -240,6 +243,7 @@ var safiRouteFamilyIPv6Map = map[Safi]bgp.RouteFamily{
}

// APIType is referred in zclient_test.
//
//go:generate stringer -type=APIType
type APIType uint16

Expand Down Expand Up @@ -780,6 +784,7 @@ func (t APIType) addressFamily(version uint8) uint8 {
}

// RouteType is referred in zclient.
//
//go:generate stringer -type=RouteType
type RouteType uint8

Expand Down Expand Up @@ -1178,6 +1183,7 @@ func (f Flag) String(version uint8, software Software) string {
}

// Nexthop Types.
//
//go:generate stringer -type=nexthopType
type nexthopType uint8

Expand Down Expand Up @@ -1248,6 +1254,7 @@ func (t nexthopType) ifNameToIFIndex() nexthopType { // quagga
}

// Nexthop Flags.
//
//go:generate stringer -type=nexthopFlag
type nexthopFlag uint8

Expand Down Expand Up @@ -1279,6 +1286,7 @@ const (
)

// Interface PTM Enable Configuration.
//
//go:generate stringer -type=ptmEnable
type ptmEnable uint8

Expand All @@ -1289,6 +1297,7 @@ const (
)

// PTM Status.
//
//go:generate stringer -type=ptmStatus
type ptmStatus uint8

Expand Down Expand Up @@ -1841,7 +1850,7 @@ type redistributeBody struct {
instance uint16
}

// Ref: zebra_redistribute_add in zebra/redistribute.c of Quagga1.2&FRR3&FRR4&FRR5&FRR6&FRR7.x&FRR8 (ZAPI3&4&5&6)
// Ref: zebra_redistribute_add in zebra/redistribute.c of Quagga1.2&FRR3&FRR4&FRR5&FRR6&FRR7.x&FRR8 (ZAPI3&4&5&6)
func (b *redistributeBody) decodeFromBytes(data []byte, version uint8, software Software) error {
if version < 4 {
b.redist = RouteType(data[0])
Expand All @@ -1853,7 +1862,7 @@ func (b *redistributeBody) decodeFromBytes(data []byte, version uint8, software
return nil
}

// Ref: zebra_redistribute_send in lib/zclient.c of Quagga1.2&FRR3&FRR4&FRR5&FRR6&FRR7.x&FRR8 (ZAPI3&4&5&6)
// Ref: zebra_redistribute_send in lib/zclient.c of Quagga1.2&FRR3&FRR4&FRR5&FRR6&FRR7.x&FRR8 (ZAPI3&4&5&6)
func (b *redistributeBody) serialize(version uint8, software Software) ([]byte, error) {
if version < 4 {
return []byte{uint8(b.redist)}, nil
Expand Down Expand Up @@ -1909,7 +1918,7 @@ type interfaceUpdateBody struct {
linkParam linkParam
}

// Ref: zebra_interface_if_set_value in lib/zclient.c of Quagga1.2&FRR3&FRR4&FRR5&FRR6&FRR7.x&FRR8 (ZAPI3&4&5&6)
// Ref: zebra_interface_if_set_value in lib/zclient.c of Quagga1.2&FRR3&FRR4&FRR5&FRR6&FRR7.x&FRR8 (ZAPI3&4&5&6)
func (b *interfaceUpdateBody) decodeFromBytes(data []byte, version uint8, software Software) error {
if len(data) < interfaceNameSize+33 {
return fmt.Errorf("lack of bytes. need %d but %d", interfaceNameSize+29, len(data))
Expand Down Expand Up @@ -2002,7 +2011,7 @@ type interfaceAddressUpdateBody struct {
destination net.IP
}

// Ref: zebra_interface_address_read in lib/zclient.c of Quagga1.2&FRR3&FRR4&FRR5&FRR6&FRR7.x&FRR8 (ZAPI3&4&5&6)
// Ref: zebra_interface_address_read in lib/zclient.c of Quagga1.2&FRR3&FRR4&FRR5&FRR6&FRR7.x&FRR8 (ZAPI3&4&5&6)
func (b *interfaceAddressUpdateBody) decodeFromBytes(data []byte, version uint8, software Software) error {
b.index = binary.BigEndian.Uint32(data[:4]) //STREAM_GETL(s, ifindex)
b.flags = interfaceAddressFlag(data[4]) //STREAM_GETC(s, ifc_flags)
Expand Down Expand Up @@ -2033,7 +2042,7 @@ type routerIDUpdateBody struct {
afi afi
}

// Ref: zebra_router_id_update_read in lib/zclient.c of Quagga1.2&FRR3&FRR5 (ZAPI3&4&5)
// Ref: zebra_router_id_update_read in lib/zclient.c of Quagga1.2&FRR3&FRR5 (ZAPI3&4&5)
func (b *routerIDUpdateBody) decodeFromBytes(data []byte, version uint8, software Software) error {
family := data[0]

Expand Down
Loading

0 comments on commit f862a96

Please sign in to comment.