Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
defo89 committed Apr 12, 2024
1 parent 3103ab8 commit 58fd93c
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.21 AS builder
FROM golang:1.22 AS builder

WORKDIR /go/src/github.com/sapcc/go-pmtud
ADD go.mod go.sum ./
Expand Down
2 changes: 2 additions & 0 deletions Makefile.maker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ golangciLint:
createConfig: true
errcheckExcludes:
- netlink.RouteGet
- viper.BindPFlags
- rand.Seed

githubWorkflow:
ci:
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/handler"

//"sigs.k8s.io/controller-runtime/pkg/log"
// "sigs.k8s.io/controller-runtime/pkg/log"
"strconv"

"sigs.k8s.io/controller-runtime/pkg/log/zap"
Expand All @@ -46,7 +46,7 @@ func init() {
rootCmd.PersistentFlags().StringSliceVar(&cfg.InterfaceNames, "iface_names", nil, "Replication interface names to work on")
rootCmd.PersistentFlags().StringVar(&cfg.NodeName, "nodename", "", "Node hostname")
rootCmd.PersistentFlags().IntVar(&cfg.InterfaceMtu, "iface_mtu", 1500, "MTU size that replication interface should have")
//rootCmd.PersistentFlags().StringSliceVar(&cfg.Peers, "peers", nil, "Resend ICMP frag-needed packets to this peer list (comma separated)")
// rootCmd.PersistentFlags().StringSliceVar(&cfg.Peers, "peers", nil, "Resend ICMP frag-needed packets to this peer list (comma separated)")
rootCmd.PersistentFlags().IntVar(&cfg.MetricsPort, "metrics_port", 30040, "Port for Prometheus metrics")
rootCmd.PersistentFlags().IntVar(&cfg.HealthPort, "health_port", 30041, "Port for healthz")
rootCmd.PersistentFlags().Uint16Var(&cfg.NfGroup, "nflog_group", 33, "NFLOG group")
Expand Down
12 changes: 6 additions & 6 deletions internal/nflog/pmtud.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (
"golang.org/x/net/ipv4"
)

const nf_bufsize = 2 * 1024 * 1024
const read_bufsize = 2 * 1024 * 1024
const nfBufsize = 2 * 1024 * 1024
const readBufsize = 2 * 1024 * 1024

var wg = sync.WaitGroup{}

Check failure on line 24 in internal/nflog/pmtud.go

View workflow job for this annotation

GitHub Actions / Build & Lint

var `wg` is unused (unused)

Expand All @@ -36,18 +36,18 @@ func (nfc *Controller) Start(startCtx context.Context) error {
ctx, cancel := context.WithCancel(startCtx)

nodeIface := cfg.ReplicationInterface
//ensure counters are reported
// ensure counters are reported
metrics.RecvPackets.WithLabelValues(cfg.NodeName, "").Add(0)
metrics.Error.WithLabelValues(cfg.NodeName).Add(0)

//TODO: make this a better logger
// TODO: make this a better logger
nflogger := golog.New(os.Stdout, "nflog:", golog.Ldate|golog.Ltime|golog.Lshortfile)
nfConfig := nflog.Config{
Group: cfg.NfGroup,
Copymode: nflog.CopyPacket,
ReadTimeout: 100 * time.Millisecond,
Logger: nflogger,
Bufsize: nf_bufsize,
Bufsize: nfBufsize,
}
log.Info("Operating with", "buffersize", nfConfig.Bufsize)
nf, err := nflog.Open(&nfConfig)
Expand All @@ -58,7 +58,7 @@ func (nfc *Controller) Start(startCtx context.Context) error {
return err
}
defer nf.Close()
err = nf.Con.SetReadBuffer(read_bufsize)
err = nf.Con.SetReadBuffer(readBufsize)
if err != nil {
metrics.Error.WithLabelValues(cfg.NodeName).Inc()
log.Error(err, "error setting read buffer")
Expand Down
2 changes: 1 addition & 1 deletion internal/util/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

// CalcSrcDst counts inner packet IPv4 IPs with bytes due to missing ICMP 3/4 parsing library
func CalcSrcDst(b []byte) (srcIP net.IP, dstIP net.IP, err error) {
func CalcSrcDst(b []byte) (srcIP, dstIP net.IP, err error) {
src := b[40:44]
dst := b[44:48]

Expand Down
15 changes: 10 additions & 5 deletions internal/util/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package util

import (
"fmt"
"net"
"strings"

"github.com/go-logr/logr"

Check failure on line 8 in internal/util/interface.go

View workflow job for this annotation

GitHub Actions / Build & Lint

File is not `goimports`-ed with -local github.com/sapcc/go-pmtud (goimports)
"github.com/sapcc/go-pmtud/internal/config"
"github.com/sapcc/go-pmtud/internal/metrics"
"github.com/vishvananda/netlink"
"net"
"strings"
)

func GetReplicationInterface(cfg *config.Config, log logr.Logger) error {
Expand Down Expand Up @@ -36,7 +37,11 @@ func GetReplicationInterface(cfg *config.Config, log logr.Logger) error {
// GetDefaultInterface gets the interface with the default route
func GetDefaultInterface(cfg *config.Config, log logr.Logger) error {
// Internet is where 8.8.8.8 lives :)
defaultRoute, _, _ := net.ParseCIDR("8.8.8.8/32")
defaultRoute, _, err := net.ParseCIDR("8.8.8.8/32")
if err != nil {
log.Error(err, "could not parse cidr")
return err
}
route, err := netlink.RouteGet(defaultRoute)
if err != nil {
log.Error(err, "could not get default route")
Expand All @@ -58,7 +63,7 @@ func GetDefaultInterface(cfg *config.Config, log logr.Logger) error {
return nil
}

func GetInterfaceIp(name string, log logr.Logger) (string, error) {
func GetInterfaceIP(name string, log logr.Logger) (string, error) {
interFace, err := net.InterfaceByName(name)
if err != nil {
log.Error(err, "error listing interfaces")
Expand All @@ -77,7 +82,7 @@ func GetInterfaceIp(name string, log logr.Logger) (string, error) {
case *net.IPAddr:
ip = v.IP
default:
//???
// ???
}
if ip == nil || ip.IsLoopback() {
continue
Expand Down

0 comments on commit 58fd93c

Please sign in to comment.