summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorIWASE Yusuke <iwase.yusuke0@gmail.com>2018-01-12 14:18:00 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2018-01-24 08:18:50 +0900
commit549b7037381ec51d0c5b9a0abbe8f73000fda70c (patch)
tree40ed8a74f1b75990071b79e363e331887e7db51e
parentb391322bcbf56d623ca0a6b667c026b92f1e9e4d (diff)
*: Use strconv.ParseUint instead of strconv.Atoi()
For the 32-bit platform compatibility. Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
-rw-r--r--api/grpc_server.go12
-rw-r--r--client/client.go4
-rw-r--r--config/util.go14
-rw-r--r--gobgp/cmd/bmp.go7
-rw-r--r--gobgp/cmd/common.go4
-rw-r--r--gobgp/cmd/global.go56
-rw-r--r--gobgp/cmd/mrt.go6
-rw-r--r--gobgp/cmd/neighbor.go13
-rw-r--r--gobgp/cmd/policy.go9
-rw-r--r--gobgp/cmd/vrf.go12
-rw-r--r--server/fsm.go18
-rw-r--r--server/rpki.go9
-rw-r--r--server/zclient.go12
-rw-r--r--table/policy.go16
-rw-r--r--table/policy_test.go11
15 files changed, 110 insertions, 93 deletions
diff --git a/api/grpc_server.go b/api/grpc_server.go
index d43a0a8b..67ff7722 100644
--- a/api/grpc_server.go
+++ b/api/grpc_server.go
@@ -1489,8 +1489,8 @@ func (s *Server) GetDefinedSet(ctx context.Context, arg *GetDefinedSetRequest) (
for _, p := range cs.PrefixList {
exp := regexp.MustCompile("(\\d+)\\.\\.(\\d+)")
elems := exp.FindStringSubmatch(p.MasklengthRange)
- min, _ := strconv.Atoi(elems[1])
- max, _ := strconv.Atoi(elems[2])
+ min, _ := strconv.ParseUint(elems[1], 10, 32)
+ max, _ := strconv.ParseUint(elems[2], 10, 32)
l = append(l, &Prefix{IpPrefix: p.IpPrefix, MaskLengthMin: uint32(min), MaskLengthMax: uint32(max)})
}
@@ -1664,12 +1664,12 @@ func toStatementApi(s *config.Statement) *Statement {
case "+", "-":
action = MedActionType_MED_MOD
}
- value, err := strconv.Atoi(matches[1] + matches[2])
+ value, err := strconv.ParseInt(matches[1]+matches[2], 10, 64)
if err != nil {
return nil
}
return &MedAction{
- Value: int64(value),
+ Value: value,
Type: action,
}
}(),
@@ -1677,10 +1677,10 @@ func toStatementApi(s *config.Statement) *Statement {
if len(s.Actions.BgpActions.SetAsPathPrepend.As) == 0 {
return nil
}
- asn := 0
+ var asn uint64
useleft := false
if s.Actions.BgpActions.SetAsPathPrepend.As != "last-as" {
- asn, _ = strconv.Atoi(s.Actions.BgpActions.SetAsPathPrepend.As)
+ asn, _ = strconv.ParseUint(s.Actions.BgpActions.SetAsPathPrepend.As, 10, 32)
} else {
useleft = true
}
diff --git a/client/client.go b/client/client.go
index 50d55319..4cd22526 100644
--- a/client/client.go
+++ b/client/client.go
@@ -818,7 +818,9 @@ func (cli *Client) GetRPKI() ([]*config.RpkiServer, error) {
}
servers := make([]*config.RpkiServer, 0, len(rsp.Servers))
for _, s := range rsp.Servers {
- port, err := strconv.Atoi(s.Conf.RemotePort)
+ // Note: RpkiServerConfig.Port is uint32 type, but the TCP/UDP port is
+ // 16-bit length.
+ port, err := strconv.ParseUint(s.Conf.RemotePort, 10, 16)
if err != nil {
return nil, err
}
diff --git a/config/util.go b/config/util.go
index ce49ff63..aa393f14 100644
--- a/config/util.go
+++ b/config/util.go
@@ -247,25 +247,25 @@ func ParseMaskLength(prefix, mask string) (int, int, error) {
return 0, 0, fmt.Errorf("invalid mask length range: %s", mask)
}
// we've already checked the range is sane by regexp
- min, _ := strconv.Atoi(elems[1])
- max, _ := strconv.Atoi(elems[2])
+ min, _ := strconv.ParseUint(elems[1], 10, 8)
+ max, _ := strconv.ParseUint(elems[2], 10, 8)
if min > max {
return 0, 0, fmt.Errorf("invalid mask length range: %s", mask)
}
if ipv4 := ipNet.IP.To4(); ipv4 != nil {
- f := func(i int) bool {
- return i >= 0 && i <= 32
+ f := func(i uint64) bool {
+ return i <= 32
}
if !f(min) || !f(max) {
return 0, 0, fmt.Errorf("ipv4 mask length range outside scope :%s", mask)
}
} else {
- f := func(i int) bool {
- return i >= 0 && i <= 128
+ f := func(i uint64) bool {
+ return i <= 128
}
if !f(min) || !f(max) {
return 0, 0, fmt.Errorf("ipv6 mask length range outside scope :%s", mask)
}
}
- return min, max, nil
+ return int(min), int(max), nil
}
diff --git a/gobgp/cmd/bmp.go b/gobgp/cmd/bmp.go
index 78fff114..f06268a1 100644
--- a/gobgp/cmd/bmp.go
+++ b/gobgp/cmd/bmp.go
@@ -20,9 +20,10 @@ import (
"net"
"strconv"
+ "github.com/spf13/cobra"
+
"github.com/osrg/gobgp/config"
"github.com/osrg/gobgp/packet/bmp"
- "github.com/spf13/cobra"
)
func modBmpServer(cmdType string, args []string) error {
@@ -40,7 +41,9 @@ func modBmpServer(cmdType string, args []string) error {
address = args[0]
} else {
address = host
- pn, _ := strconv.Atoi(p)
+ // Note: BmpServerConfig.Port is uint32 type, but the TCP/UDP port is
+ // 16-bit length.
+ pn, _ := strconv.ParseUint(p, 10, 16)
port = uint32(pn)
}
diff --git a/gobgp/cmd/common.go b/gobgp/cmd/common.go
index 65a19a87..9c3f1732 100644
--- a/gobgp/cmd/common.go
+++ b/gobgp/cmd/common.go
@@ -112,8 +112,8 @@ var mrtOpts struct {
OutputDir string
FileFormat string
Filename string `long:"filename" description:"MRT file name"`
- RecordCount int `long:"count" description:"Number of records to inject"`
- RecordSkip int `long:"skip" description:"Number of records to skip before injecting"`
+ RecordCount int64 `long:"count" description:"Number of records to inject"`
+ RecordSkip int64 `long:"skip" description:"Number of records to skip before injecting"`
QueueSize int `long:"batch-size" description:"Maximum number of updates to keep queued"`
Best bool `long:"only-best" description:"only keep best path routes"`
SkipV4 bool `long:"no-ipv4" description:"Skip importing IPv4 routes"`
diff --git a/gobgp/cmd/global.go b/gobgp/cmd/global.go
index 45ee5614..fd36bceb 100644
--- a/gobgp/cmd/global.go
+++ b/gobgp/cmd/global.go
@@ -92,7 +92,7 @@ func rateLimitParser(args []string) ([]bgp.ExtendedCommunityInterface, error) {
return nil, fmt.Errorf("invalid rate-limit")
}
var rate float32
- var as int
+ var as uint64
if elems[2] == ExtCommNameMap[RATE] {
f, err := strconv.ParseFloat(elems[3]+elems[4], 32)
if err != nil {
@@ -102,7 +102,7 @@ func rateLimitParser(args []string) ([]bgp.ExtendedCommunityInterface, error) {
}
if elems[7] != "" {
var err error
- as, err = strconv.Atoi(elems[7])
+ as, err = strconv.ParseUint(elems[7], 10, 16)
if err != nil {
return nil, err
}
@@ -139,7 +139,7 @@ func markParser(args []string) ([]bgp.ExtendedCommunityInterface, error) {
if len(args) < 2 || args[0] != ExtCommNameMap[MARK] {
return nil, fmt.Errorf("invalid mark")
}
- dscp, err := strconv.Atoi(args[1])
+ dscp, err := strconv.ParseUint(args[1], 10, 8)
if err != nil {
return nil, fmt.Errorf("invalid mark")
}
@@ -216,7 +216,7 @@ func esiLabelParser(args []string) ([]bgp.ExtendedCommunityInterface, error) {
if len(args) < 2 || args[0] != ExtCommNameMap[ESI_LABEL] {
return nil, fmt.Errorf("invalid esi-label")
}
- label, err := strconv.Atoi(args[1])
+ label, err := strconv.ParseUint(args[1], 10, 32)
if err != nil {
return nil, err
}
@@ -418,13 +418,13 @@ func ParseEvpnEthernetAutoDiscoveryArgs(args []string) (bgp.AddrPrefixInterface,
return nil, nil, err
}
- e, err := strconv.Atoi(m["etag"][0])
+ e, err := strconv.ParseUint(m["etag"][0], 10, 32)
if err != nil {
return nil, nil, err
}
etag := uint32(e)
- l, err := strconv.Atoi(m["label"][0])
+ l, err := strconv.ParseUint(m["label"][0], 10, 32)
if err != nil {
return nil, nil, err
}
@@ -518,14 +518,14 @@ func ParseEvpnMacAdvArgs(args []string) (bgp.AddrPrefixInterface, []string, erro
return nil, nil, err
}
- eTag, err := strconv.Atoi(eTagStr)
+ eTag, err := strconv.ParseUint(eTagStr, 10, 32)
if err != nil {
return nil, nil, fmt.Errorf("invalid etag: %s: %s", eTagStr, err)
}
var labels []uint32
for _, l := range strings.SplitN(labelStr, ",", 2) {
- label, err := strconv.Atoi(l)
+ label, err := strconv.ParseUint(l, 10, 32)
if err != nil {
return nil, nil, fmt.Errorf("invalid label: %s: %s", labelStr, err)
}
@@ -604,7 +604,7 @@ func ParseEvpnMulticastArgs(args []string) (bgp.AddrPrefixInterface, []string, e
ipLen = net.IPv6len * 8
}
- eTag, err := strconv.Atoi(eTagStr)
+ eTag, err := strconv.ParseUint(eTagStr, 10, 32)
if err != nil {
return nil, nil, fmt.Errorf("invalid etag: %s: %s", eTagStr, err)
}
@@ -727,7 +727,7 @@ func ParseEvpnIPPrefixArgs(args []string) (bgp.AddrPrefixInterface, []string, er
return nil, nil, err
}
- e, err := strconv.Atoi(m["etag"][0])
+ e, err := strconv.ParseUint(m["etag"][0], 10, 32)
if err != nil {
return nil, nil, fmt.Errorf("invalid etag: %s: %s", m["etag"][0], err)
}
@@ -735,7 +735,7 @@ func ParseEvpnIPPrefixArgs(args []string) (bgp.AddrPrefixInterface, []string, er
var label uint32
if len(m["label"]) > 0 {
- e, err := strconv.Atoi(m["label"][0])
+ e, err := strconv.ParseUint(m["label"][0], 10, 32)
if err != nil {
return nil, nil, fmt.Errorf("invalid label: %s: %s", m["label"][0], err)
}
@@ -810,17 +810,17 @@ func extractOrigin(args []string) ([]string, bgp.PathAttributeInterface, error)
func toAs4Value(s string) (uint32, error) {
if strings.Contains(s, ".") {
v := strings.Split(s, ".")
- upper, err := strconv.Atoi(v[0])
+ upper, err := strconv.ParseUint(v[0], 10, 16)
if err != nil {
return 0, nil
}
- lower, err := strconv.Atoi(v[1])
+ lower, err := strconv.ParseUint(v[1], 10, 16)
if err != nil {
return 0, nil
}
- return uint32(upper)<<16 + uint32(lower), nil
+ return uint32(upper<<16 | lower), nil
}
- i, err := strconv.Atoi(s)
+ i, err := strconv.ParseUint(s, 10, 32)
if err != nil {
return 0, err
}
@@ -898,7 +898,7 @@ func extractNexthop(rf bgp.RouteFamily, args []string) ([]string, string, error)
func extractLocalPref(args []string) ([]string, bgp.PathAttributeInterface, error) {
for idx, arg := range args {
if arg == "local-pref" && len(args) > (idx+1) {
- metric, err := strconv.Atoi(args[idx+1])
+ metric, err := strconv.ParseUint(args[idx+1], 10, 32)
if err != nil {
return nil, nil, err
}
@@ -912,12 +912,12 @@ func extractLocalPref(args []string) ([]string, bgp.PathAttributeInterface, erro
func extractMed(args []string) ([]string, bgp.PathAttributeInterface, error) {
for idx, arg := range args {
if arg == "med" && len(args) > (idx+1) {
- metric, err := strconv.Atoi(args[idx+1])
+ med, err := strconv.ParseUint(args[idx+1], 10, 32)
if err != nil {
return nil, nil, err
}
args = append(args[:idx], args[idx+2:]...)
- return args, bgp.NewPathAttributeMultiExitDisc(uint32(metric)), nil
+ return args, bgp.NewPathAttributeMultiExitDisc(uint32(med)), nil
}
}
return args, nil, nil
@@ -970,7 +970,7 @@ func extractAigp(args []string) ([]string, bgp.PathAttributeInterface, error) {
typ := args[idx+1]
switch typ {
case "metric":
- metric, err := strconv.Atoi(args[idx+2])
+ metric, err := strconv.ParseUint(args[idx+2], 10, 64)
if err != nil {
return nil, nil, err
}
@@ -1077,11 +1077,11 @@ func ParsePath(rf bgp.RouteFamily, args []string) (*table.Path, error) {
}
if len(args) > 2 && args[1] == "identifier" {
- if id, err := strconv.Atoi(args[2]); err != nil {
+ id, err := strconv.ParseUint(args[2], 10, 32)
+ if err != nil {
return nil, fmt.Errorf("invalid format")
- } else {
- nlri.SetPathIdentifier(uint32(id))
}
+ nlri.SetPathIdentifier(uint32(id))
extcomms = args[3:]
} else {
extcomms = args[1:]
@@ -1094,8 +1094,8 @@ func ParsePath(rf bgp.RouteFamily, args []string) (*table.Path, error) {
ip, nw, _ := net.ParseCIDR(args[0])
ones, _ := nw.Mask.Size()
- label := 0
- if label, err = strconv.Atoi(args[2]); err != nil {
+ label, err := strconv.ParseUint(args[2], 10, 32)
+ if err != nil {
return nil, fmt.Errorf("invalid format")
}
mpls := bgp.NewMPLSLabelStack(uint32(label))
@@ -1397,7 +1397,7 @@ func modGlobalConfig(args []string) error {
if len(m["as"]) != 1 || len(m["router-id"]) != 1 {
return fmt.Errorf("usage: gobgp global as <VALUE> router-id <VALUE> [use-multipath] [listen-port <VALUE>] [listen-addresses <VALUE>...]")
}
- asn, err := strconv.Atoi(m["as"][0])
+ asn, err := strconv.ParseUint(m["as"][0], 10, 32)
if err != nil {
return err
}
@@ -1405,9 +1405,11 @@ func modGlobalConfig(args []string) error {
if id.To4() == nil {
return fmt.Errorf("invalid router-id format")
}
- var port int
+ var port int64
if len(m["listen-port"]) > 0 {
- port, err = strconv.Atoi(m["listen-port"][0])
+ // Note: GlobalConfig.Port is uint32 type, but the TCP/UDP port is
+ // 16-bit length.
+ port, err = strconv.ParseInt(m["listen-port"][0], 10, 16)
if err != nil {
return err
}
diff --git a/gobgp/cmd/mrt.go b/gobgp/cmd/mrt.go
index 336b9616..844cf66c 100644
--- a/gobgp/cmd/mrt.go
+++ b/gobgp/cmd/mrt.go
@@ -40,7 +40,7 @@ func injectMrt() error {
fmt.Println("You should probably specify either --no-ipv4 or --no-ipv6 when overwriting nexthop, unless your dump contains only one type of routes")
}
- idx := 0
+ var idx int64
if mrtOpts.QueueSize < 1 {
return fmt.Errorf("Specified queue size is smaller than 1, refusing to run with unbounded memory usage")
}
@@ -195,12 +195,12 @@ func NewMrtCmd() *cobra.Command {
mrtOpts.Filename = args[0]
if len(args) > 1 {
var err error
- mrtOpts.RecordCount, err = strconv.Atoi(args[1])
+ mrtOpts.RecordCount, err = strconv.ParseInt(args[1], 10, 64)
if err != nil {
exitWithError(fmt.Errorf("invalid count value: %s", args[1]))
}
if len(args) > 2 {
- mrtOpts.RecordSkip, err = strconv.Atoi(args[2])
+ mrtOpts.RecordSkip, err = strconv.ParseInt(args[2], 10, 64)
if err != nil {
exitWithError(fmt.Errorf("invalid skip value: %s", args[2]))
}
diff --git a/gobgp/cmd/neighbor.go b/gobgp/cmd/neighbor.go
index 2f0f21a4..4a081035 100644
--- a/gobgp/cmd/neighbor.go
+++ b/gobgp/cmd/neighbor.go
@@ -989,10 +989,10 @@ func modNeighbor(cmdType string, args []string) error {
}
}
- getConf := func(asn int) (*config.Neighbor, error) {
+ getConf := func(asn uint32) (*config.Neighbor, error) {
peer := &config.Neighbor{
Config: config.NeighborConfig{
- PeerAs: uint32(asn),
+ PeerAs: asn,
},
}
if unnumbered {
@@ -1032,7 +1032,7 @@ func modNeighbor(cmdType string, args []string) error {
}
}
if option, ok := m["allow-own-as"]; ok {
- as, err := strconv.Atoi(option[0])
+ as, err := strconv.ParseUint(option[0], 10, 8)
if err != nil {
return nil, err
}
@@ -1054,16 +1054,15 @@ func modNeighbor(cmdType string, args []string) error {
return peer, nil
}
- var as int
+ var as uint64
if len(m["as"]) > 0 {
var err error
- as, err = strconv.Atoi(m["as"][0])
- if err != nil {
+ if as, err = strconv.ParseUint(m["as"][0], 10, 32); err != nil {
return err
}
}
- n, err := getConf(as)
+ n, err := getConf(uint32(as))
if err != nil {
return err
}
diff --git a/gobgp/cmd/policy.go b/gobgp/cmd/policy.go
index 0edde4c5..18674f0f 100644
--- a/gobgp/cmd/policy.go
+++ b/gobgp/cmd/policy.go
@@ -25,9 +25,10 @@ import (
"strconv"
"strings"
+ "github.com/spf13/cobra"
+
"github.com/osrg/gobgp/config"
"github.com/osrg/gobgp/table"
- "github.com/spf13/cobra"
)
func formatDefinedSet(head bool, typ string, indent int, list []table.DefinedSet) string {
@@ -592,7 +593,7 @@ func modCondition(name, op string, args []string) error {
if len(args) < 2 {
return fmt.Errorf("%s as-path-length <length> { eq | ge | le }", usage)
}
- length, err := strconv.Atoi(args[0])
+ length, err := strconv.ParseUint(args[0], 10, 32)
if err != nil {
return err
}
@@ -721,7 +722,7 @@ func modAction(name, op string, args []string) error {
if len(args) < 2 {
return fmt.Errorf("%s med { add | sub | set } <value>", usage)
}
- med, err := strconv.Atoi(args[1])
+ med, err := strconv.ParseUint(args[1], 10, 32)
if err != nil {
return err
}
@@ -749,7 +750,7 @@ func modAction(name, op string, args []string) error {
return fmt.Errorf("%s as-prepend { <asn> | last-as } <repeat-value>", usage)
}
stmt.Actions.BgpActions.SetAsPathPrepend.As = args[0]
- repeat, err := strconv.Atoi(args[1])
+ repeat, err := strconv.ParseUint(args[1], 10, 8)
if err != nil {
return err
}
diff --git a/gobgp/cmd/vrf.go b/gobgp/cmd/vrf.go
index 356f6881..5aebf903 100644
--- a/gobgp/cmd/vrf.go
+++ b/gobgp/cmd/vrf.go
@@ -18,11 +18,13 @@ package cmd
import (
"encoding/json"
"fmt"
- "github.com/osrg/gobgp/packet/bgp"
- "github.com/spf13/cobra"
"sort"
"strconv"
"strings"
+
+ "github.com/spf13/cobra"
+
+ "github.com/osrg/gobgp/packet/bgp"
)
func getVrfs() (vrfs, error) {
@@ -125,14 +127,14 @@ func modVrf(typ string, args []string) error {
return fmt.Errorf("Usage: gobgp vrf add <vrf name> rd <rd> rt { import | export | both } <rt>...")
}
}
- vrfId := 0
+ var id uint64
if len(a["id"]) > 0 {
- vrfId, err = strconv.Atoi(a["id"][0])
+ id, err = strconv.ParseUint(a["id"][0], 10, 32)
if err != nil {
return err
}
}
- err = client.AddVRF(name, vrfId, rd, importRt, exportRt)
+ err = client.AddVRF(name, int(id), rd, importRt, exportRt)
case CMD_DEL:
if len(args) != 1 {
return fmt.Errorf("Usage: gobgp vrf del <vrf name>")
diff --git a/server/fsm.go b/server/fsm.go
index c3c2910e..9db3a552 100644
--- a/server/fsm.go
+++ b/server/fsm.go
@@ -17,19 +17,21 @@ package server
import (
"fmt"
- "github.com/eapache/channels"
- "github.com/osrg/gobgp/config"
- "github.com/osrg/gobgp/packet/bgp"
- "github.com/osrg/gobgp/packet/bmp"
- "github.com/osrg/gobgp/table"
- log "github.com/sirupsen/logrus"
- "gopkg.in/tomb.v2"
"io"
"math/rand"
"net"
"strconv"
"strings"
"time"
+
+ "github.com/eapache/channels"
+ log "github.com/sirupsen/logrus"
+ "gopkg.in/tomb.v2"
+
+ "github.com/osrg/gobgp/config"
+ "github.com/osrg/gobgp/packet/bgp"
+ "github.com/osrg/gobgp/packet/bmp"
+ "github.com/osrg/gobgp/table"
)
type FsmStateReason string
@@ -272,7 +274,7 @@ func hostport(addr net.Addr) (string, uint16) {
if err != nil {
return "", 0
}
- p, _ := strconv.Atoi(port)
+ p, _ := strconv.ParseUint(port, 10, 16)
return host, uint16(p)
}
return "", 0
diff --git a/server/rpki.go b/server/rpki.go
index b6aec254..8f286930 100644
--- a/server/rpki.go
+++ b/server/rpki.go
@@ -25,12 +25,13 @@ import (
"time"
"github.com/armon/go-radix"
+ log "github.com/sirupsen/logrus"
+ "golang.org/x/net/context"
+
"github.com/osrg/gobgp/config"
"github.com/osrg/gobgp/packet/bgp"
"github.com/osrg/gobgp/packet/rtr"
"github.com/osrg/gobgp/table"
- log "github.com/sirupsen/logrus"
- "golang.org/x/net/context"
)
const (
@@ -453,7 +454,9 @@ func (c *roaManager) GetServers() []*config.RpkiServer {
l = append(l, &config.RpkiServer{
Config: config.RpkiServerConfig{
Address: addr,
- Port: func() uint32 { p, _ := strconv.Atoi(port); return uint32(p) }(),
+ // Note: RpkiServerConfig.Port is uint32 type, but the TCP/UDP
+ // port is 16-bit length.
+ Port: func() uint32 { p, _ := strconv.ParseUint(port, 10, 16); return uint32(p) }(),
},
State: client.state,
})
diff --git a/server/zclient.go b/server/zclient.go
index 46cab1a1..2e2c0187 100644
--- a/server/zclient.go
+++ b/server/zclient.go
@@ -17,15 +17,17 @@ package server
import (
"fmt"
- "github.com/osrg/gobgp/packet/bgp"
- "github.com/osrg/gobgp/table"
- "github.com/osrg/gobgp/zebra"
- log "github.com/sirupsen/logrus"
"net"
"strconv"
"strings"
"syscall"
"time"
+
+ log "github.com/sirupsen/logrus"
+
+ "github.com/osrg/gobgp/packet/bgp"
+ "github.com/osrg/gobgp/table"
+ "github.com/osrg/gobgp/zebra"
)
type pathList []*table.Path
@@ -249,7 +251,7 @@ func newIPRouteBody(dst pathList) (body *zebra.IPRouteBody, isWithdraw bool) {
return nil, false
}
msgFlags := zebra.MESSAGE_NEXTHOP
- plen, _ := strconv.Atoi(l[1])
+ plen, _ := strconv.ParseUint(l[1], 10, 8)
med, err := path.GetMed()
if err == nil {
msgFlags |= zebra.MESSAGE_METRIC
diff --git a/table/policy.go b/table/policy.go
index e1b7d690..a7d02b06 100644
--- a/table/policy.go
+++ b/table/policy.go
@@ -337,8 +337,8 @@ func NewPrefix(c config.Prefix) (*Prefix, error) {
return nil, fmt.Errorf("mask length range format is invalid")
}
// we've already checked the range is sane by regexp
- min, _ := strconv.Atoi(elems[1])
- max, _ := strconv.Atoi(elems[2])
+ min, _ := strconv.ParseUint(elems[1], 10, 8)
+ max, _ := strconv.ParseUint(elems[2], 10, 8)
p.MasklengthRangeMin = uint8(min)
p.MasklengthRangeMax = uint8(max)
}
@@ -716,25 +716,25 @@ func NewSingleAsPathMatch(arg string) *singleAsPathMatch {
onlyRe := regexp.MustCompile("^\\^([0-9]+)\\$$")
switch {
case leftMostRe.MatchString(arg):
- asn, _ := strconv.Atoi(leftMostRe.FindStringSubmatch(arg)[1])
+ asn, _ := strconv.ParseUint(leftMostRe.FindStringSubmatch(arg)[1], 10, 32)
return &singleAsPathMatch{
asn: uint32(asn),
mode: LEFT_MOST,
}
case originRe.MatchString(arg):
- asn, _ := strconv.Atoi(originRe.FindStringSubmatch(arg)[1])
+ asn, _ := strconv.ParseUint(originRe.FindStringSubmatch(arg)[1], 10, 32)
return &singleAsPathMatch{
asn: uint32(asn),
mode: ORIGIN,
}
case includeRe.MatchString(arg):
- asn, _ := strconv.Atoi(includeRe.FindStringSubmatch(arg)[1])
+ asn, _ := strconv.ParseUint(includeRe.FindStringSubmatch(arg)[1], 10, 32)
return &singleAsPathMatch{
asn: uint32(asn),
mode: INCLUDE,
}
case onlyRe.MatchString(arg):
- asn, _ := strconv.Atoi(onlyRe.FindStringSubmatch(arg)[1])
+ asn, _ := strconv.ParseUint(onlyRe.FindStringSubmatch(arg)[1], 10, 32)
return &singleAsPathMatch{
asn: uint32(asn),
mode: ONLY,
@@ -985,8 +985,8 @@ func ParseCommunity(arg string) (uint32, error) {
exp := regexp.MustCompile("(\\d+):(\\d+)")
elems := exp.FindStringSubmatch(arg)
if len(elems) == 3 {
- fst, _ := strconv.Atoi(elems[1])
- snd, _ := strconv.Atoi(elems[2])
+ fst, _ := strconv.ParseUint(elems[1], 10, 16)
+ snd, _ := strconv.ParseUint(elems[2], 10, 16)
return uint32(fst<<16 | snd), nil
}
for i, v := range bgp.WellKnownCommunityNameMap {
diff --git a/table/policy_test.go b/table/policy_test.go
index c55eb1c8..cf02b095 100644
--- a/table/policy_test.go
+++ b/table/policy_test.go
@@ -24,10 +24,11 @@ import (
"testing"
"time"
- "github.com/osrg/gobgp/config"
- "github.com/osrg/gobgp/packet/bgp"
log "github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
+
+ "github.com/osrg/gobgp/config"
+ "github.com/osrg/gobgp/packet/bgp"
)
func TestPrefixCalcurateNoRange(t *testing.T) {
@@ -2800,9 +2801,9 @@ func createNeighborSet(name string, addr string) config.NeighborSet {
func createAs4Value(s string) uint32 {
v := strings.Split(s, ".")
- upper, _ := strconv.Atoi(v[0])
- lower, _ := strconv.Atoi(v[1])
- return uint32(upper)<<16 + uint32(lower)
+ upper, _ := strconv.ParseUint(v[0], 10, 16)
+ lower, _ := strconv.ParseUint(v[1], 10, 16)
+ return uint32(upper<<16 | lower)
}
func TestPrefixSetOperation(t *testing.T) {