Skip to content

Commit

Permalink
[Bugfix] Parse the routingTableID correctly (#889)
Browse files Browse the repository at this point in the history
* Parse the routingTableID correctly [rtnetlink.h](https://github.com/torvalds/linux/blob/55027e689933ba2e64f3d245fb1ff185b3e7fc81/include/uapi/linux/rtnetlink.h\#L354C15-L354C25) says RT_TABLE_MAX=0xFFFFFFFF

Signed-off-by: Marcel Fest <marcel.fest@telekom.de>

* Better error handling for int check

Signed-off-by: Marcel Fest <marcel.fest@telekom.de>

* Better error message + typo fix

Signed-off-by: Marcel Fest <marcel.fest@telekom.de>

* Use MaxInt instead of MaxUint

Signed-off-by: Marcel Fest <marcel.fest@telekom.de>

---------

Signed-off-by: Marcel Fest <marcel.fest@telekom.de>
  • Loading branch information
Cellebyte committed Jun 26, 2024
1 parent 9abce4a commit 59951cb
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions pkg/kubevip/config_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package kubevip

import (
"encoding/json"
"fmt"
"math"
"math/bits"
"os"
"strconv"

Expand Down Expand Up @@ -316,11 +319,18 @@ func ParseEnvironment(c *Config) error {
// Routing Table ID
env = os.Getenv(vipRoutingTableID)
if env != "" {
i, err := strconv.ParseInt(env, 10, 32)
i, err := strconv.ParseInt(env, 10, 64)
if err != nil {
return err
}
c.RoutingTableID = int(i)
if i >= 0 && i <= math.MaxInt {
c.RoutingTableID = int(i)
return nil
} else if i < 0 {
return fmt.Errorf("no support of negative [%d] in env var %q", i, vipRoutingTableID)
}
// +1 for the signing bit as it is 0 for positive integers
return fmt.Errorf("no support for int64, system natively supports [int%d]", bits.OnesCount(math.MaxInt)+1)
}

// Routing Table Type
Expand Down

0 comments on commit 59951cb

Please sign in to comment.