diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 3f814cd..8fb9d4c 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -11,55 +11,60 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Set up Go - uses: actions/setup-go@v2 + uses: actions/setup-go@v6 with: - go-version: 1.17 + go-version: 1.25 - - name: OVS setup + - name: Set up OVS run: | sudo apt-get update sudo apt install openvswitch-switch sudo ovs-vsctl add-br ovsbr0 - - - name: Check and test - run: | - export GOPATH=/home/runner/work - export PATH=$PATH:$GOPATH/bin - mkdir $GOPATH/src $GOPATH/pkg $GOPATH/bin - go install honnef.co/go/tools/cmd/staticcheck@2020.2.1 - NEW=$GOPATH/src/github.com/digitalocean/go-openvswitch - mkdir -p $NEW - cp -r ./* $NEW - cd $NEW - go mod download - go get golang.org/x/lint/golint - go get -d ./... + + - uses: actions/checkout@v5 + + - name: License check + run: | echo "=========START LICENSE CHECK============" ./scripts/licensecheck.sh - echo "=========START BUILD============" - go build -v -tags=gofuzz ./... - echo "=========START VET============" + + - name: Download deps + run: go mod download + + - name: Lint + run: | + # install tools + go install honnef.co/go/tools/cmd/staticcheck@latest + go install golang.org/x/lint/golint@latest + go install github.com/mgechev/revive@latest + go vet ./... - echo "=========START GO FMT CHECK============" - ./scripts/gofmt.sh - echo "=========START GO LINT CHECK============" - ./scripts/golint.sh - echo "=========START STATICCHECK============" + + GOFMT=$(gofmt -l .) + if [[ -n $GOFMT ]]; then + echo -e "Files that are not gofmt'd:\n" + echo "$GOFMT" + exit 1 + fi + + revive ./... + staticcheck ./... - echo "=========START LINT============" - golint -set_exit_status ./cmd/... ./internal/... + + - name: Run Gosec Security Scanner + uses: securego/gosec@master + with: + args: -exclude=G115 ./... + + - name: Build + run: go build -v ./... + + - name: Test + run: | echo "=========START TESTS IN OVS============" go test -v -race -short ./ovs/ echo "=========START TESTS IN OVSDB============" - go test -v -race ./ovsdb/ - go test -c -race ./ovsdb + sudo go test -v -race ./ovsdb/ echo "=========START TESTS IN OVSNL============" go test -v -race ./ovsnl/ - echo "=========START OVSDB.TEST============" - sudo ./ovsdb.test -test.v - echo "=========START SECURITY SCANNING============" - go install github.com/praetorian-inc/gokart@latest - gokart scan diff --git a/go.mod b/go.mod index 8e622eb..0070099 100644 --- a/go.mod +++ b/go.mod @@ -1,10 +1,16 @@ module github.com/digitalocean/go-openvswitch -go 1.16 +go 1.25 require ( - github.com/google/go-cmp v0.5.6 - github.com/mdlayher/genetlink v1.0.0 - github.com/mdlayher/netlink v1.4.1 - golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf + github.com/google/go-cmp v0.7.0 + github.com/mdlayher/genetlink v1.3.2 + github.com/mdlayher/netlink v1.8.0 + golang.org/x/sys v0.37.0 +) + +require ( + github.com/mdlayher/socket v0.5.1 // indirect + golang.org/x/net v0.45.0 // indirect + golang.org/x/sync v0.3.0 // indirect ) diff --git a/go.sum b/go.sum index c2c7155..138a534 100644 --- a/go.sum +++ b/go.sum @@ -1,86 +1,14 @@ -github.com/cilium/ebpf v0.5.0/go.mod h1:4tRaxcgiL706VnOzHOdBlY8IEAIdxINsQBcU4xJJXRs= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/frankban/quicktest v1.11.3/go.mod h1:wRf/ReqHper53s+kmmSZizM8NamnL3IM0I9ntUbOk+k= -github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= -github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= -github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= -github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/josharian/native v0.0.0-20200817173448-b6b71def0850 h1:uhL5Gw7BINiiPAo24A2sxkcDI0Jt/sqp1v5xQCniEFA= -github.com/josharian/native v0.0.0-20200817173448-b6b71def0850/go.mod h1:7X/raswPFr05uY3HiLlYeyQntB6OO7E/d2Cu7qoaN2w= -github.com/jsimonetti/rtnetlink v0.0.0-20190606172950-9527aa82566a/go.mod h1:Oz+70psSo5OFh8DBl0Zv2ACw7Esh6pPUphlvZG9x7uw= -github.com/jsimonetti/rtnetlink v0.0.0-20200117123717-f846d4f6c1f4/go.mod h1:WGuG/smIU4J/54PblvSbh+xvCZmpJnFgr3ds6Z55XMQ= -github.com/jsimonetti/rtnetlink v0.0.0-20201009170750-9c6f07d100c1/go.mod h1:hqoO/u39cqLeBLebZ8fWdE96O7FxrAsRYhnVOdgHxok= -github.com/jsimonetti/rtnetlink v0.0.0-20201216134343-bde56ed16391/go.mod h1:cR77jAZG3Y3bsb8hF6fHJbFoyFukLFOkQ98S0pQz3xw= -github.com/jsimonetti/rtnetlink v0.0.0-20201220180245-69540ac93943/go.mod h1:z4c53zj6Eex712ROyh8WI0ihysb5j2ROyV42iNogmAs= -github.com/jsimonetti/rtnetlink v0.0.0-20210122163228-8d122574c736/go.mod h1:ZXpIyOK59ZnN7J0BV99cZUPmsqDRZ3eq5X+st7u/oSA= -github.com/jsimonetti/rtnetlink v0.0.0-20210212075122-66c871082f2b/go.mod h1:8w9Rh8m+aHZIG69YPGGem1i5VzoyRC8nw2kA8B+ik5U= -github.com/jsimonetti/rtnetlink v0.0.0-20210525051524-4cc836578190 h1:iycCSDo8EKVueI9sfVBBJmtNn9DnXV/K1YWwEJO+uOs= -github.com/jsimonetti/rtnetlink v0.0.0-20210525051524-4cc836578190/go.mod h1:NmKSdU4VGSiv1bMsdqNALI4RSvvjtz65tTMCnD05qLo= -github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= -github.com/mdlayher/ethtool v0.0.0-20210210192532-2b88debcdd43 h1:WgyLFv10Ov49JAQI/ZLUkCZ7VJS3r74hwFIGXJsgZlY= -github.com/mdlayher/ethtool v0.0.0-20210210192532-2b88debcdd43/go.mod h1:+t7E0lkKfbBsebllff1xdTmyJt8lH37niI6kwFk9OTo= -github.com/mdlayher/genetlink v1.0.0 h1:OoHN1OdyEIkScEmRgxLEe2M9U8ClMytqA5niynLtfj0= -github.com/mdlayher/genetlink v1.0.0/go.mod h1:0rJ0h4itni50A86M2kHcgS85ttZazNt7a8H2a2cw0Gc= -github.com/mdlayher/netlink v0.0.0-20190409211403-11939a169225/go.mod h1:eQB3mZE4aiYnlUsyGGCOpPETfdQq4Jhsgf1fk3cwQaA= -github.com/mdlayher/netlink v1.0.0/go.mod h1:KxeJAFOFLG6AjpyDkQ/iIhxygIUKD+vcwqcnu43w/+M= -github.com/mdlayher/netlink v1.1.0/go.mod h1:H4WCitaheIsdF9yOYu8CFmCgQthAPIWZmcKp9uZHgmY= -github.com/mdlayher/netlink v1.1.1/go.mod h1:WTYpFb/WTvlRJAyKhZL5/uy69TDDpHHu2VZmb2XgV7o= -github.com/mdlayher/netlink v1.2.0/go.mod h1:kwVW1io0AZy9A1E2YYgaD4Cj+C+GPkU6klXCMzIJ9p8= -github.com/mdlayher/netlink v1.2.1/go.mod h1:bacnNlfhqHqqLo4WsYeXSqfyXkInQ9JneWI68v1KwSU= -github.com/mdlayher/netlink v1.2.2-0.20210123213345-5cc92139ae3e/go.mod h1:bacnNlfhqHqqLo4WsYeXSqfyXkInQ9JneWI68v1KwSU= -github.com/mdlayher/netlink v1.3.0/go.mod h1:xK/BssKuwcRXHrtN04UBkwQ6dY9VviGGuriDdoPSWys= -github.com/mdlayher/netlink v1.4.0/go.mod h1:dRJi5IABcZpBD2A3D0Mv/AiX8I9uDEu5oGkAVrekmf8= -github.com/mdlayher/netlink v1.4.1 h1:I154BCU+mKlIf7BgcAJB2r7QjveNPty6uNY1g9ChVfI= -github.com/mdlayher/netlink v1.4.1/go.mod h1:e4/KuJ+s8UhfUpO9z00/fDZZmhSrs+oxyqAS9cNgn6Q= -github.com/mdlayher/socket v0.0.0-20210307095302-262dc9984e00 h1:qEtkL8n1DAHpi5/AOgAckwGQUlMe4+jhL/GMt+GKIks= -github.com/mdlayher/socket v0.0.0-20210307095302-262dc9984e00/go.mod h1:GAFlyu4/XV68LkQKYzKhIo/WW7j3Zi0YRAz/BOoanUc= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20191007182048-72f939374954/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20201010224723-4f7140c49acb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20201216054612-986b41b23924/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20210525063256-abc453219eb5 h1:wjuX4b5yYQnEQHzd+CBcrcC6OVR2J1CN6mUy0oSxIPo= -golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190411185658-b44545bcd369/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201009025420-dfb3f7c4e634/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201118182958-a01c418693c7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201218084310-7d0127a74742/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210110051926-789bb1bd4061/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210123111255-9b0068b26619/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210216163648-f7da38b97c65/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210305230114-8fe3ee5dd75b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210525143221-35b2ab0089ea/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf h1:2ucpDCmfkl8Bd/FsLtiD653Wf96cW37s+iGx93zsu4k= -golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= +github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= +github.com/mdlayher/genetlink v1.3.2 h1:KdrNKe+CTu+IbZnm/GVUMXSqBBLqcGpRDa0xkQy56gw= +github.com/mdlayher/genetlink v1.3.2/go.mod h1:tcC3pkCrPUGIKKsCsp0B3AdaaKuHtaxoJRz3cc+528o= +github.com/mdlayher/netlink v1.8.0 h1:e7XNIYJKD7hUct3Px04RuIGJbBxy1/c4nX7D5YyvvlM= +github.com/mdlayher/netlink v1.8.0/go.mod h1:UhgKXUlDQhzb09DrCl2GuRNEglHmhYoWAHid9HK3594= +github.com/mdlayher/socket v0.5.1 h1:VZaqt6RkGkt2OE9l3GcC6nZkqD3xKeQLyfleW/uBcos= +github.com/mdlayher/socket v0.5.1/go.mod h1:TjPLHI1UgwEv5J1B5q0zTZq12A/6H7nKmtTanQE37IQ= +golang.org/x/net v0.45.0 h1:RLBg5JKixCy82FtLJpeNlVM0nrSqpCRYzVU1n8kj0tM= +golang.org/x/net v0.45.0/go.mod h1:ECOoLqd5U3Lhyeyo/QDCEVQ4sNgYsqvCZ722XogGieY= +golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= +golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= +golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ= +golang.org/x/sys v0.37.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= diff --git a/ovs/action.go b/ovs/action.go index cee8ba8..9e5366a 100644 --- a/ovs/action.go +++ b/ovs/action.go @@ -456,7 +456,7 @@ func (a *outputFieldAction) GoString() string { // applies multipath link selection `algorithm` (with parameter `arg`) // to choose one of `n_links` output links numbered 0 through n_links // minus 1, and stores the link into `dst`, which must be a field or -// subfield in the syntax described under ``Field Specifications’’ +// subfield in the syntax described under “Field Specifications’’ // above. // https://www.openvswitch.org/support/dist-docs/ovs-actions.7.txt func Multipath(fields string, basis int, algorithm string, nlinks int, arg int, dst string) Action { diff --git a/ovs/client.go b/ovs/client.go index 0dafe5b..2bc7a21 100644 --- a/ovs/client.go +++ b/ovs/client.go @@ -18,7 +18,6 @@ import ( "bytes" "fmt" "io" - "io/ioutil" "log" "os/exec" "strings" @@ -145,7 +144,7 @@ func shellPipe(stdin io.Reader, cmd string, args ...string) ([]byte, error) { } mr := io.MultiReader(stdout, stderr) - b, err := ioutil.ReadAll(mr) + b, err := io.ReadAll(mr) if err != nil { return nil, err } diff --git a/ovs/datapath_test.go b/ovs/datapath_test.go index 8cc88ba..e3d84c9 100644 --- a/ovs/datapath_test.go +++ b/ovs/datapath_test.go @@ -265,7 +265,7 @@ func TestGetCTLimits(t *testing.T) { } case handleError: if err != nil && err.Error() != tt.err { - t.Errorf(err.Error()) + t.Error(err.Error()) } default: t.Log("pass") @@ -346,7 +346,7 @@ func TestGetCTLimitsWithBinary(t *testing.T) { } case handleError: if err != nil && err.Error() != tt.err { - t.Errorf(err.Error()) + t.Error(err.Error()) } default: @@ -426,7 +426,7 @@ func TestCtSetLimitsArgsToString(t *testing.T) { got, err := ctSetLimitsArgsToString(tt.zone) if err != nil { if err.Error() != tt.err { - t.Errorf(err.Error()) + t.Error(err.Error()) } } if got != tt.want1 && got != tt.want2 { diff --git a/ovs/matchparser.go b/ovs/matchparser.go index a15f104..3d9f5f1 100644 --- a/ovs/matchparser.go +++ b/ovs/matchparser.go @@ -116,23 +116,23 @@ func parseMatch(key string, value string) (Match, error) { } // parseClampInt calls strconv.Atoi on s, and then ensures that s is less than -// or equal to the integer specified by max. -func parseClampInt(s string, max int) (int, error) { +// or equal to the integer specified by upper. +func parseClampInt(s string, upper int) (int, error) { t, err := strconv.Atoi(s) if err != nil { return 0, err } - if t > max { - return 0, fmt.Errorf("integer %d too large; %d > %d", t, t, max) + if t > upper { + return 0, fmt.Errorf("integer %d too large; %d > %d", t, t, upper) } return t, nil } // parseIntMatch parses an integer Match value from the input key and value, -// with a maximum possible value of max. -func parseIntMatch(key string, value string, max int) (Match, error) { - t, err := parseClampInt(value, max) +// with a maximum possible value of upper. +func parseIntMatch(key string, value string, upper int) (Match, error) { + t, err := parseClampInt(value, upper) if err != nil { return nil, err } @@ -176,8 +176,8 @@ func parseIntMatch(key string, value string, max int) (Match, error) { } // parsePort parses a port or port/mask Match value from the input key and value, -// with a maximum possible value of max. -func parsePort(key string, value string, max int) (Match, error) { +// with a maximum possible value of upper. +func parsePort(key string, value string, upper int) (Match, error) { var values []uint64 //Split the string @@ -186,7 +186,7 @@ func parsePort(key string, value string, max int) (Match, error) { //If input is just port switch len(ss) { case 1: - val, err := parseClampInt(value, max) + val, err := parseClampInt(value, upper) if err != nil { return nil, err } @@ -200,8 +200,8 @@ func parsePort(key string, value string, max int) (Match, error) { return nil, err } // Return error if val > 65536 (uint16) - if val > uint64(max) { - return nil, fmt.Errorf("integer %d too large; %d > %d", val, val, max) + if val > uint64(upper) { + return nil, fmt.Errorf("integer %d too large; %d > %d", val, val, upper) } values = append(values, val) diff --git a/ovs/portstats.go b/ovs/portstats.go index 36c5398..7803703 100644 --- a/ovs/portstats.go +++ b/ovs/portstats.go @@ -64,8 +64,9 @@ type PortStatsTransmit struct { // UnmarshalText unmarshals a PortStats from textual form as output by // 'ovs-ofctl dump-ports': -// port 1: rx pkts=0, bytes=0, drop=0, errs=0, frame=0, over=0, crc=0 -// tx pkts=0, bytes=0, drop=0, errs=0, coll=0 +// +// port 1: rx pkts=0, bytes=0, drop=0, errs=0, frame=0, over=0, crc=0 +// tx pkts=0, bytes=0, drop=0, errs=0, coll=0 func (p *PortStats) UnmarshalText(b []byte) error { // Make a copy per documentation for encoding.TextUnmarshaler. s := string(b) diff --git a/ovs/table.go b/ovs/table.go index c77d3d5..20693be 100644 --- a/ovs/table.go +++ b/ovs/table.go @@ -39,8 +39,9 @@ type Table struct { // UnmarshalText unmarshals a Table from textual form as output by // 'ovs-ofctl dump-tables': -// 0: classifier: wild=0x3fffff, max=1000000, active=0 -// lookup=0, matched=0 +// +// 0: classifier: wild=0x3fffff, max=1000000, active=0 +// lookup=0, matched=0 func (t *Table) UnmarshalText(b []byte) error { // Make a copy per documentation for encoding.TextUnmarshaler. s := string(b) diff --git a/ovsdb/internal/jsonrpc/testconn.go b/ovsdb/internal/jsonrpc/testconn.go index f054aad..bbf0af4 100644 --- a/ovsdb/internal/jsonrpc/testconn.go +++ b/ovsdb/internal/jsonrpc/testconn.go @@ -51,7 +51,7 @@ func TestConn(t *testing.T, fn TestFunc) (*Conn, chan<- *Response, func()) { func TestNetConn(t *testing.T, fn TestFunc) (net.Conn, chan<- *Response, func()) { t.Helper() - l, err := net.Listen("tcp", ":0") + l, err := net.Listen("tcp", ":0") // #nosec G102 if err != nil { t.Fatalf("failed to listen: %v", err) } diff --git a/ovsnl/client.go b/ovsnl/client.go index 204af0e..4e522bc 100644 --- a/ovsnl/client.go +++ b/ovsnl/client.go @@ -119,7 +119,7 @@ func (c *Client) initFamily(f genetlink.Family) error { // headerBytes converts an ovsh.Header into a byte slice. func headerBytes(h ovsh.Header) []byte { - b := *(*[sizeofHeader]byte)(unsafe.Pointer(&h)) + b := *(*[sizeofHeader]byte)(unsafe.Pointer(&h)) // #nosec G103 return b[:] } @@ -130,6 +130,6 @@ func parseHeader(b []byte) (ovsh.Header, error) { return ovsh.Header{}, fmt.Errorf("not enough data for OVS message header: %d bytes", l) } - h := *(*ovsh.Header)(unsafe.Pointer(&b[:sizeofHeader][0])) + h := *(*ovsh.Header)(unsafe.Pointer(&b[:sizeofHeader][0])) // #nosec G103 return h, nil } diff --git a/ovsnl/client_linux_integration_test.go b/ovsnl/client_linux_integration_test.go index 46d43d1..724fa6f 100644 --- a/ovsnl/client_linux_integration_test.go +++ b/ovsnl/client_linux_integration_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -//+build linux +//go:build linux package ovsnl_test diff --git a/ovsnl/client_linux_test.go b/ovsnl/client_linux_test.go index 8384532..d09239d 100644 --- a/ovsnl/client_linux_test.go +++ b/ovsnl/client_linux_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -//+build linux +//go:build linux package ovsnl diff --git a/ovsnl/datapath.go b/ovsnl/datapath.go index 6751cde..2f4921a 100644 --- a/ovsnl/datapath.go +++ b/ovsnl/datapath.go @@ -173,7 +173,7 @@ func parseDPStats(b []byte) (DatapathStats, error) { return DatapathStats{}, fmt.Errorf("unexpected datapath stats structure size, want %d, got %d", want, got) } - s := *(*ovsh.DPStats)(unsafe.Pointer(&b[0])) + s := *(*ovsh.DPStats)(unsafe.Pointer(&b[0])) // #nosec G103 return DatapathStats{ Hit: s.Hit, Missed: s.Missed, @@ -190,7 +190,7 @@ func parseDPMegaflowStats(b []byte) (DatapathMegaflowStats, error) { return DatapathMegaflowStats{}, fmt.Errorf("unexpected datapath megaflow stats structure size, want %d, got %d", want, got) } - s := *(*ovsh.DPMegaflowStats)(unsafe.Pointer(&b[0])) + s := *(*ovsh.DPMegaflowStats)(unsafe.Pointer(&b[0])) // #nosec G103 return DatapathMegaflowStats{ MaskHits: s.Mask_hit, diff --git a/ovsnl/datapath_linux_test.go b/ovsnl/datapath_linux_test.go index f533314..c40b145 100644 --- a/ovsnl/datapath_linux_test.go +++ b/ovsnl/datapath_linux_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -//+build linux +//go:build linux package ovsnl @@ -186,7 +186,7 @@ func mustMarshalDatapath(dp Datapath) []byte { Flows: dp.Stats.Flows, } - sb := *(*[sizeofDPStats]byte)(unsafe.Pointer(&s)) + sb := *(*[sizeofDPStats]byte)(unsafe.Pointer(&s)) // #nosec G103 ms := ovsh.DPMegaflowStats{ Mask_hit: dp.MegaflowStats.MaskHits, @@ -194,7 +194,7 @@ func mustMarshalDatapath(dp Datapath) []byte { // Pad already set to zero. } - msb := *(*[sizeofDPMegaflowStats]byte)(unsafe.Pointer(&ms)) + msb := *(*[sizeofDPMegaflowStats]byte)(unsafe.Pointer(&ms)) // #nosec G103 ab := mustMarshalAttributes([]netlink.Attribute{ { diff --git a/ovsnl/internal/ovsh/types.go b/ovsnl/internal/ovsh/types.go index 12bcda3..e3843cf 100644 --- a/ovsnl/internal/ovsh/types.go +++ b/ovsnl/internal/ovsh/types.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -//+build ignore +//go:build ignore package ovsh diff --git a/revive.toml b/revive.toml new file mode 100644 index 0000000..4aff122 --- /dev/null +++ b/revive.toml @@ -0,0 +1,31 @@ +ignoreGeneratedHeader = true +severity = "warning" +confidence = 0.8 +errorCode = 1 +warningCode = 1 +exclude = ["ovsnl/internal/ovsh"] + +[rule.blank-imports] +[rule.context-as-argument] +[rule.context-keys-type] +[rule.dot-imports] +[rule.error-return] +[rule.error-strings] +[rule.error-naming] +[rule.exported] +[rule.increment-decrement] +[rule.var-naming] +[rule.var-declaration] +[rule.package-comments] +[rule.range] +[rule.receiver-naming] +[rule.time-naming] +[rule.unexported-return] +[rule.indent-error-flow] +[rule.errorf] +[rule.empty-block] +[rule.superfluous-else] +[rule.unused-parameter] + Disabled = true +[rule.unreachable-code] +[rule.redefines-builtin-id] diff --git a/scripts/gofmt.sh b/scripts/gofmt.sh deleted file mode 100755 index f0db877..0000000 --- a/scripts/gofmt.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -# Verify that all files are correctly gofmt'd, with the exception of -# generated code. -EXIT=0 -GOFMT=$(go fmt ./... | grep -v -E "ovsnl.*test|ovsnl/internal/ovsh" ) - -if [[ ! -z $GOFMT ]]; then - echo -e "Files that are not gofmt'd:\n" - echo "$GOFMT" - EXIT=1 -fi - -exit $EXIT diff --git a/scripts/golint.sh b/scripts/golint.sh deleted file mode 100755 index 51eb631..0000000 --- a/scripts/golint.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -# Verify that all files are correctly golint'd, with the exception of -# generated code. -EXIT=0 -GOLINT=$(golint ./... | grep -v -E "ovsnl.*test|ovsnl/internal/ovsh") - -if [[ ! -z $GOLINT ]]; then - echo "$GOLINT" - EXIT=1 -fi - -exit $EXIT