Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add command brctl #2971

Merged
merged 34 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
5f3ae47
add addbr, delbr
leongross Feb 21, 2024
47f1803
update args
leongross Feb 23, 2024
d2413d2
add preliminary show implementation
leongross Feb 23, 2024
e0f1e73
add prelim showmacs (parsing partially incorrect)
leongross Feb 23, 2024
cac7809
add subcommands
leongross Mar 1, 2024
21d5ef1
add subcommands
leongross Mar 1, 2024
a093b39
extend usage, add cmd to template 'embedded'
leongross Mar 5, 2024
063929c
refctor brctl into pkg and cmd component
leongross Mar 5, 2024
e1909f6
add unit tests for jiffies, update jiffies
leongross Mar 5, 2024
2b1cd79
prelim: add qemu integration test for Addbr Delbr
leongross Mar 6, 2024
6b581fc
remove unused command 'Setgcint', refactor consts, rename helper came…
leongross Apr 26, 2024
9111830
add tests
leongross Apr 26, 2024
f332386
mod tidy
leongross Apr 26, 2024
90dc4b9
remove command description comment
leongross Apr 30, 2024
c0a824d
add interface parsing for bridges
leongross May 3, 2024
2a0b36f
update tests
leongross May 14, 2024
7ede78a
make unix.Timval bitsize agnostic
leongross May 15, 2024
195689a
add vmtest config with kernel that has bridge support, simplify jiffy
leongross May 15, 2024
9ffa6a9
Copium for CI
ChriMarMe Jun 6, 2024
92358e2
add documentation for brctl
leongross Jun 7, 2024
32a15b3
remove old ioctl, update sysfs access
leongross Jun 11, 2024
df805e0
remove me: custom vmtest.yaml for amd64
leongross Jun 11, 2024
f6f77ff
update tests
leongross Jun 11, 2024
762d66b
Update kernel image hashes for the CI
ChriMarMe Jun 12, 2024
219ecca
Try to fix TestSetportprio & TestHairpin
ChriMarMe Jun 12, 2024
2be5117
Add tests for cmds/core/brctl
ChriMarMe Jun 13, 2024
a903b7f
Fix some tests
ChriMarMe Jun 13, 2024
a7dd3e7
Make sure tests of pkg/brctl are skipped if not in VM
ChriMarMe Jun 13, 2024
a56ec9a
Complete implementation of pkg/brctl/TestIfDelif
ChriMarMe Jun 13, 2024
37081d1
Remove unused code in util.go
ChriMarMe Jun 13, 2024
297b91e
Implemenet general review feedback
ChriMarMe Jun 13, 2024
6583c81
Add comments to functions and correct some functions parameter names.
ChriMarMe Jun 14, 2024
77b9dac
rename variables go idiomatically
leongross Jun 14, 2024
96a31b5
Merge branch 'main' into cmds/brctl
10000TB Jun 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .vmtest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@ amd64:
qemu: "/zqemu"

VMTEST_KERNEL:
container: "ghcr.io/u-root/u-root/test-kernel-amd64@sha256:10ea580ef29468f6d6f4674279586d37e118b145564fd1e99b708370262961a4"
container: "ghcr.io/u-root/u-root/test-kernel-amd64@sha256:f2e059a15c78754db1f4b13e218e671188b301e00d89ae5dd7c90852b93051fa"
template: "{{.bzImage}}"
files:
bzImage: "/bzImage"

UROOT_MULTIBOOT_TEST_KERNEL_DIR:
container: "ghcr.io/u-root/u-root/test-multiboot-test-kernel-amd64@sha256:0fba729eddd76a50f5cfdfdabc4389d6a6902486b1190d354813ae953cc94b52"
container: "ghcr.io/u-root/u-root/test-multiboot-test-kernel-amd64@sha256:0385b76e46f707ec2cd37942605d414f25fdea20be69ef942a24c447332ed2f4"
template: "{{.mbdir}}"
directories:
mbdir: "/mb"

UROOT_TEST_UEFIPAYLOAD:
container: "ghcr.io/u-root/u-root/test-uefipayload-amd64@sha256:4a9a47cdce32fb6dd7610f6de9f55d64b5dc380cf95bc23561696bb48e34622a"
container: "ghcr.io/u-root/u-root/test-uefipayload-amd64@sha256:1bd2eba74930d863ff76a3cf1889ecda8d5bf569c795d3bc7a9d79d5580d7972"
template: "{{.payload}}"
files:
payload: "/UEFIPAYLOAD.fd"
Expand All @@ -31,7 +31,7 @@ arm:
qemu: "/zqemu"

VMTEST_KERNEL:
container: "ghcr.io/u-root/u-root/test-kernel-arm@sha256:d185d93812738b2869f4835d5a209fcf25ffdea4fd6601fcd206dfad67c9bced"
container: "ghcr.io/u-root/u-root/test-kernel-arm@sha256:89f168f0da14f69c69ba3427b7c553ffa5e66d1e9f5f7f8f46ac09d1d776a602"
template: "{{.zImage}}"
files:
zImage: "/zImage"
Expand All @@ -44,7 +44,7 @@ arm64:
qemu: "/zqemu"

VMTEST_KERNEL:
container: "ghcr.io/u-root/u-root/test-kernel-arm64@sha256:805d64653b654ddf96e307cd3d7e835e5e9b9fd67d1b7e79b73cfa8ea2ce86e4"
container: "ghcr.io/u-root/u-root/test-kernel-arm64@sha256:1ca9bc35409b5cd83fcdb04817ceac034ad437ebeaae34df1172d0a3df6f16f4"
template: "{{.Image}}"
files:
Image: "/Image"
165 changes: 165 additions & 0 deletions cmds/core/brctl/brctl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
// Copyright 2024 the u-root Authors. All rights reserved
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build !tinygo && !plan9
// +build !tinygo,!plan9

package main

import (
"errors"
"fmt"
"io"
"log"
"os"

"github.com/u-root/u-root/pkg/brctl"
)

// cli
const usage = `
Usage: brctl [commands]
commands:

INSTANCES:
brctl addbr <name> creates a new instance of the ethernet bridge
brctl delbr <name> deletes the instance <name> of the ethernet bridge
brctl show show current instance(s) of the ethernet bridge

PORTS:
brctl addif <brname> <ifname> will make the interface <ifname> a port of the bridge <brname>
brctl delif <brname> <ifname> will detach the interface <ifname> from the bridge <brname>
brctl show <brname> will show some information on the bridge and its attached ports

AGEING:
brctl showmacs <brname> shows a list of learned MAC addresses for this bridge
brctl setageingtime <brname> <time> sets the ethernet (MAC) address ageing time, in seconds [OPT]

SPANNING TREE PROTOCOL (IEEE 802.1d):
brctl stp <bridge> <state> controls this bridge instance's participation in the spanning tree protocol.
brctl setbridgeprio <bridge> <priority> sets the bridge's priority to <priority>
brctl setfd <bridge> <time> sets the bridge's 'bridge forward delay' to <time> seconds
brctl sethello <bridge> <time> sets the bridge's 'bridge hello time' to <time> seconds
brctl setmaxage <bridge> <time> sets the bridge's 'maximum message age' to <time> seconds.
brctl setpathcost <bridge> <port> <cost> sets the port cost of the port <port> to <cost>. This is a dimensionless metric
brctl setportprio <bridge> <port> <priority> sets the port <port>'s priority to <priority>
brctl hairpin <bridge> <port> <state> enable/disable hairpin mode on the port <port> of the bridge <bridge>
`

var (
errFewArgs = errors.New("too few args")
errInvalidCmd = errors.New("unknown command")
)

func run(out io.Writer, argv []string) error {
var err error
command := argv[0]
args := argv[1:]

switch command {
case "addbr":
10000TB marked this conversation as resolved.
Show resolved Hide resolved
if len(args) != 1 {
return errFewArgs
}
err = brctl.Addbr(args[0])

case "delbr":
if len(args) != 1 {
return errFewArgs
}
err = brctl.Delbr(args[0])

case "addif":
if len(args) != 2 {
return errFewArgs
}
err = brctl.Addif(args[0], args[1])

case "delif":
if len(args) != 2 {
return errFewArgs
}
err = brctl.Delif(args[0], args[1])

case "show":
err = brctl.Show(out, args...)

case "showmacs":
if len(args) != 1 {
return errFewArgs
}
err = brctl.Showmacs(args[0], out)

case "setageingtime":
if len(args) != 2 {
return errFewArgs
}
err = brctl.Setageingtime(args[0], args[1])

case "stp":
if len(args) != 2 {
return errFewArgs
}
err = brctl.Stp(args[0], args[1])

case "setbridgeprio":
if len(args) != 2 {
return errFewArgs
}
err = brctl.Setbridgeprio(args[0], args[1])

case "setfd":
if len(args) != 2 {
return errFewArgs
}
err = brctl.Setfd(args[0], args[1])

case "sethello":
if len(args) != 2 {
return errFewArgs
}
err = brctl.Sethello(args[0], args[1])

case "setmaxage":
if len(args) != 2 {
return errFewArgs
}
err = brctl.Setmaxage(args[0], args[1])

case "setpathcost":
if len(args) != 3 {
return errFewArgs
}
err = brctl.Setpathcost(args[0], args[1], args[2])

case "setportprio":
if len(args) != 3 {
return errFewArgs
}
err = brctl.Setportprio(args[0], args[1], args[2])

case "hairpin":
if len(args) != 3 {
return errFewArgs
}
err = brctl.Hairpin(args[0], args[1], args[2])

default:
return fmt.Errorf("%w: %s", errInvalidCmd, command)
}

return err
}

func main() {
argv := os.Args

Check warning on line 156 in cmds/core/brctl/brctl.go

View check run for this annotation

Codecov / codecov/patch

cmds/core/brctl/brctl.go#L155-L156

Added lines #L155 - L156 were not covered by tests

if len(argv) < 2 {
log.Fatal(usage)

Check warning on line 159 in cmds/core/brctl/brctl.go

View check run for this annotation

Codecov / codecov/patch

cmds/core/brctl/brctl.go#L158-L159

Added lines #L158 - L159 were not covered by tests
}

if err := run(os.Stdout, argv[1:]); err != nil {
log.Fatalf("brctl: %v", err)

Check warning on line 163 in cmds/core/brctl/brctl.go

View check run for this annotation

Codecov / codecov/patch

cmds/core/brctl/brctl.go#L162-L163

Added lines #L162 - L163 were not covered by tests
}
}
Loading
Loading