Skip to content

Commit

Permalink
fix: mark linux exclusive sources with build tags (#4707)
Browse files Browse the repository at this point in the history
[github.com/gopacket/gopacket/afpacket](https://pkg.go.dev/github.com/gopacket/gopacket@v1.3.1/afpacket)
works with [Linux
only](https://github.com/gopacket/gopacket/blob/de38b3ed5f55a68c3e7cdf34809dac42bf41d22a/afpacket/afpacket.go#L7),
hence marking all sources that depend on it improves DX for other
platforms such as macOS.
  • Loading branch information
romshark authored Feb 20, 2025
1 parent 896d790 commit 4f935c8
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 48 deletions.
42 changes: 29 additions & 13 deletions acceptance/router_benchmark/brload/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,35 @@ go_library(
],
importpath = "github.com/scionproto/scion/acceptance/router_benchmark/brload",
visibility = ["//visibility:private"],
deps = [
"//acceptance/router_benchmark/cases:go_default_library",
"//pkg/log:go_default_library",
"//pkg/private/serrors:go_default_library",
"//pkg/scrypto:go_default_library",
"//pkg/slayers:go_default_library",
"//private/keyconf:go_default_library",
"@com_github_gopacket_gopacket//:go_default_library",
"@com_github_gopacket_gopacket//afpacket:go_default_library",
"@com_github_gopacket_gopacket//layers:go_default_library",
"@com_github_spf13_cobra//:go_default_library",
"@org_golang_x_sys//unix:go_default_library",
],
deps = select({
"@io_bazel_rules_go//go/platform:android": [
"//acceptance/router_benchmark/cases:go_default_library",
"//pkg/log:go_default_library",
"//pkg/private/serrors:go_default_library",
"//pkg/scrypto:go_default_library",
"//pkg/slayers:go_default_library",
"//private/keyconf:go_default_library",
"@com_github_gopacket_gopacket//:go_default_library",
"@com_github_gopacket_gopacket//afpacket:go_default_library",
"@com_github_gopacket_gopacket//layers:go_default_library",
"@com_github_spf13_cobra//:go_default_library",
"@org_golang_x_sys//unix:go_default_library",
],
"@io_bazel_rules_go//go/platform:linux": [
"//acceptance/router_benchmark/cases:go_default_library",
"//pkg/log:go_default_library",
"//pkg/private/serrors:go_default_library",
"//pkg/scrypto:go_default_library",
"//pkg/slayers:go_default_library",
"//private/keyconf:go_default_library",
"@com_github_gopacket_gopacket//:go_default_library",
"@com_github_gopacket_gopacket//afpacket:go_default_library",
"@com_github_gopacket_gopacket//layers:go_default_library",
"@com_github_spf13_cobra//:go_default_library",
"@org_golang_x_sys//unix:go_default_library",
],
"//conditions:default": [],
}),
)

scion_go_binary(
Expand Down
4 changes: 3 additions & 1 deletion acceptance/router_benchmark/brload/main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 SCION Association
// Copyright 2025 SCION Association
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build linux

package main

import (
Expand Down
4 changes: 3 additions & 1 deletion acceptance/router_benchmark/brload/mmsg.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 SCION Association
// Copyright 2025 SCION Association
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build linux

package main

import (
Expand Down
30 changes: 21 additions & 9 deletions tools/braccept/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,27 @@ go_library(
srcs = ["main.go"],
importpath = "github.com/scionproto/scion/tools/braccept",
visibility = ["//visibility:private"],
deps = [
"//pkg/log:go_default_library",
"//pkg/scrypto:go_default_library",
"//pkg/slayers:go_default_library",
"//private/keyconf:go_default_library",
"//tools/braccept/cases:go_default_library",
"//tools/braccept/runner:go_default_library",
"@com_github_gopacket_gopacket//layers:go_default_library",
],
deps = select({
"@io_bazel_rules_go//go/platform:android": [
"//pkg/log:go_default_library",
"//pkg/scrypto:go_default_library",
"//pkg/slayers:go_default_library",
"//private/keyconf:go_default_library",
"//tools/braccept/cases:go_default_library",
"//tools/braccept/runner:go_default_library",
"@com_github_gopacket_gopacket//layers:go_default_library",
],
"@io_bazel_rules_go//go/platform:linux": [
"//pkg/log:go_default_library",
"//pkg/scrypto:go_default_library",
"//pkg/slayers:go_default_library",
"//private/keyconf:go_default_library",
"//tools/braccept/cases:go_default_library",
"//tools/braccept/runner:go_default_library",
"@com_github_gopacket_gopacket//layers:go_default_library",
],
"//conditions:default": [],
}),
)

scion_go_binary(
Expand Down
3 changes: 3 additions & 0 deletions tools/braccept/main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright 2020 Anapaya Systems
// Copyright 2025 SCION Association
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -12,6 +13,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build linux

package main

import (
Expand Down
23 changes: 17 additions & 6 deletions tools/braccept/runner/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,32 @@ go_library(
srcs = [
"compare.go",
"print.go",
"run.go",
"run_linux.go",
"runner.go",
],
importpath = "github.com/scionproto/scion/tools/braccept/runner",
visibility = ["//visibility:public"],
deps = [
"//pkg/log:go_default_library",
"//pkg/private/common:go_default_library",
"//pkg/private/serrors:go_default_library",
"@com_github_gopacket_gopacket//:go_default_library",
"@com_github_gopacket_gopacket//afpacket:go_default_library",
"@com_github_gopacket_gopacket//layers:go_default_library",
"@com_github_gopacket_gopacket//pcapgo:go_default_library",
"@com_github_mattn_go_isatty//:go_default_library",
"@com_github_sergi_go_diff//diffmatchpatch:go_default_library",
],
] + select({
"@io_bazel_rules_go//go/platform:android": [
"//pkg/log:go_default_library",
"//pkg/private/common:go_default_library",
"@com_github_gopacket_gopacket//afpacket:go_default_library",
"@com_github_gopacket_gopacket//pcapgo:go_default_library",
],
"@io_bazel_rules_go//go/platform:linux": [
"//pkg/log:go_default_library",
"//pkg/private/common:go_default_library",
"@com_github_gopacket_gopacket//afpacket:go_default_library",
"@com_github_gopacket_gopacket//pcapgo:go_default_library",
],
"//conditions:default": [],
}),
)

go_test(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright 2020 Anapaya Systems
// Copyright 2025 SCION Association
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -12,6 +13,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build linux

package runner

import (
Expand Down Expand Up @@ -106,7 +109,6 @@ type ExpectedPacket struct {
// the expected packet and no other packet is received nil is returned.
// Otherwise details of what went wrong are returned in the error.
func (c *RunConfig) ExpectPacket(pkt ExpectedPacket, normalizeFn NormalizePacketFn) error {

timerCh := time.After(pkt.Timeout)
c.packetChans[len(c.deviceNames)] = reflect.SelectCase{
Dir: reflect.SelectRecv,
Expand Down Expand Up @@ -170,21 +172,6 @@ func (c *RunConfig) Close() {
c.handles = nil
}

type NormalizePacketFn func(gopacket.Packet)

// Case represents a border router test case.
type Case struct {
Name string
WriteTo, ReadFrom string
Input, Want []byte
StoreDir string
IgnoreNonMatching bool
// NormalizePacket is a function that will be called both on actual and
// expected packet. It can modify the packet fields so that unpredictable
// values are zeroed out and the packets match.
NormalizePacket NormalizePacketFn
}

// Run executes a test case. It writes input pkt to interface `WriteTo` and
// listens for want pkt in interface `ReadFrom`. It stores all the packets
// in the artifact directory for further debug.
Expand Down Expand Up @@ -224,7 +211,6 @@ func (t *Case) Run(cfg *RunConfig) error {
}
return serrors.Wrap("Errors were found", err,
"Packets are stored in", t.StoreDir)

}

type packetStorer struct {
Expand All @@ -238,7 +224,7 @@ func (s *packetStorer) storePkt(fileName string, packet gopacket.Packet) {
return
}
filename := filepath.Join(s.StoreDir, fileName+".pcap")
f, err := os.OpenFile(filename, os.O_CREATE|os.O_WRONLY, 0600)
f, err := os.OpenFile(filename, os.O_CREATE|os.O_WRONLY, 0o600)
if err != nil {
log.Error(s.TestName, "err", err)
return
Expand Down
33 changes: 33 additions & 0 deletions tools/braccept/runner/runner.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2020 Anapaya Systems
// Copyright 2025 SCION Association
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package runner

import "github.com/gopacket/gopacket"

type NormalizePacketFn func(gopacket.Packet)

// Case represents a border router test case.
type Case struct {
Name string
WriteTo, ReadFrom string
Input, Want []byte
StoreDir string
IgnoreNonMatching bool
// NormalizePacket is a function that will be called both on actual and
// expected packet. It can modify the packet fields so that unpredictable
// values are zeroed out and the packets match.
NormalizePacket NormalizePacketFn
}

0 comments on commit 4f935c8

Please sign in to comment.