From 1e2add4db713f647ca6647e2628019dfab2e2e7b Mon Sep 17 00:00:00 2001 From: Yutaro Hayakawa Date: Mon, 6 May 2024 00:40:02 +0900 Subject: [PATCH] Rename package from radv to ra radv was taken from radvd, but it's hard to pronounce. We haven't released any version, so take this chance to rename it. The package name is "ra" and the repo name will be renamed to go-ra. Signed-off-by: Yutaro Hayakawa --- Makefile | 6 ++++- README.md | 2 +- cmd/goradv/main.go | 6 ++--- cmd/goradvd/main.go | 10 ++++---- cmd/internal/client.go | 8 +++---- cmd/internal/server.go | 10 ++++---- config.go | 2 +- config_test.go | 4 ++-- daemon.go | 4 ++-- daemon_test.go | 2 +- fake_socket.go | 2 +- go.mod | 2 +- integration_tests/gobgp_unnumbered_test.go | 28 +++++++++++----------- integration_tests/shared_resources.go | 4 ++-- integration_tests/solicited_ra_test.go | 22 ++++++++--------- ra_sender.go | 2 +- socket.go | 2 +- status.go | 2 +- zz_generated_deepcopy.go | 2 +- 19 files changed, 62 insertions(+), 58 deletions(-) diff --git a/Makefile b/Makefile index 98253bd..cfd2bed 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ MAKEFLAGS += --silent -DEEPCOPY_OPTS=-type Config -type InterfaceConfig -type InterfaceStatus +DEEPCOPY_OPTS=-type Config -type Status -type InterfaceConfig -type InterfaceStatus all: @@ -13,3 +13,7 @@ deepcopy: check-deepcopy: deep-copy -pointer-receiver $(DEEPCOPY_OPTS) -o zz_generated_deepcopy.go . git diff --exit-code zz_generated_deepcopy.go || echo "deepcopy is not up to date. Please commit the changes."; git diff zz_generated_deepcopy.go + +coverage: + go test -cover -coverprofile=coverage.out -v + go tool cover -html=coverage.out -o coverage.html diff --git a/README.md b/README.md index a6abac8..f2f7785 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ -# go-radv +# go-ra Pure Go IPv6 Router Advertisement daemon diff --git a/cmd/goradv/main.go b/cmd/goradv/main.go index 595e963..fae9994 100644 --- a/cmd/goradv/main.go +++ b/cmd/goradv/main.go @@ -8,8 +8,8 @@ import ( "text/tabwriter" "time" - "github.com/YutaroHayakawa/go-radv" - "github.com/YutaroHayakawa/go-radv/cmd/internal" + "github.com/YutaroHayakawa/go-ra" + "github.com/YutaroHayakawa/go-ra/cmd/internal" "gopkg.in/yaml.v3" ) @@ -62,7 +62,7 @@ func reload(client *internal.Client, config string) { os.Exit(1) } - c, err := radv.ParseConfigYAMLFile(config) + c, err := ra.ParseConfigYAMLFile(config) if err != nil { fmt.Printf("Failed to parse the configuration file: %s\n", err.Error()) os.Exit(1) diff --git a/cmd/goradvd/main.go b/cmd/goradvd/main.go index 2a0125a..6ac1284 100644 --- a/cmd/goradvd/main.go +++ b/cmd/goradvd/main.go @@ -6,8 +6,8 @@ import ( "log/slog" "os/signal" - "github.com/YutaroHayakawa/go-radv" - "github.com/YutaroHayakawa/go-radv/cmd/internal" + "github.com/YutaroHayakawa/go-ra" + "github.com/YutaroHayakawa/go-ra/cmd/internal" "golang.org/x/sys/unix" ) @@ -22,15 +22,15 @@ func main() { return } - config, err := radv.ParseConfigYAMLFile(*configFile) + config, err := ra.ParseConfigYAMLFile(*configFile) if err != nil { slog.Error("Failed to parse config file. Aborting.", "error", err.Error()) return } - daemon, err := radv.NewDaemon( + daemon, err := ra.NewDaemon( config, - radv.WithLogger(slog.With("component", "daemon")), + ra.WithLogger(slog.With("component", "daemon")), ) if err != nil { slog.Error("Failed to create daemon. Aborting.", "error", err.Error()) diff --git a/cmd/internal/client.go b/cmd/internal/client.go index fb8cb4a..e4aceba 100644 --- a/cmd/internal/client.go +++ b/cmd/internal/client.go @@ -6,7 +6,7 @@ import ( "fmt" "net/http" - "github.com/YutaroHayakawa/go-radv" + "github.com/YutaroHayakawa/go-ra" ) type Client struct { @@ -21,7 +21,7 @@ func NewClient(host string) *Client { } } -func (c *Client) Reload(config *radv.Config) error { +func (c *Client) Reload(config *ra.Config) error { data, err := json.Marshal(config) if err != nil { return err @@ -60,7 +60,7 @@ func (c *Client) Reload(config *radv.Config) error { return &e } -func (c *Client) Status() (*radv.Status, error) { +func (c *Client) Status() (*ra.Status, error) { res, err := c.Get("http://" + c.host + "/status") if err != nil { return nil, err @@ -68,7 +68,7 @@ func (c *Client) Status() (*radv.Status, error) { defer res.Body.Close() if res.StatusCode == http.StatusOK { - var status radv.Status + var status ra.Status if err := json.NewDecoder(res.Body).Decode(&status); err != nil { return nil, fmt.Errorf("failed to decode status response: %s", err) } diff --git a/cmd/internal/server.go b/cmd/internal/server.go index 8f06114..c435f41 100644 --- a/cmd/internal/server.go +++ b/cmd/internal/server.go @@ -6,16 +6,16 @@ import ( "log/slog" "net/http" - "github.com/YutaroHayakawa/go-radv" + "github.com/YutaroHayakawa/go-ra" ) type Server struct { http.Server - daemon *radv.Daemon + daemon *ra.Daemon logger *slog.Logger } -func NewServer(host string, daemon *radv.Daemon, logger *slog.Logger) *Server { +func NewServer(host string, daemon *ra.Daemon, logger *slog.Logger) *Server { srv := &Server{ daemon: daemon, logger: logger, @@ -56,7 +56,7 @@ func (s *Server) handleReload(w http.ResponseWriter, r *http.Request) { return } - config, err := radv.ParseConfigJSON(r.Body) + config, err := ra.ParseConfigJSON(r.Body) if err != nil { if errors.Is(err, &json.SyntaxError{}) { s.writeError(w, http.StatusBadRequest, "JSONSyntaxError", err.Error()) @@ -69,7 +69,7 @@ func (s *Server) handleReload(w http.ResponseWriter, r *http.Request) { } if err := s.daemon.Reload(r.Context(), config); err != nil { - var verrs radv.ValidationErrors + var verrs ra.ValidationErrors if errors.As(err, &verrs) { s.writeError(w, http.StatusBadRequest, "ValidationError", verrs.Error()) return diff --git a/config.go b/config.go index b19c58a..81e3729 100644 --- a/config.go +++ b/config.go @@ -1,4 +1,4 @@ -package radv +package ra import ( "encoding/json" diff --git a/config_test.go b/config_test.go index d27fc04..3904950 100644 --- a/config_test.go +++ b/config_test.go @@ -1,4 +1,4 @@ -package radv +package ra import ( "bytes" @@ -19,7 +19,7 @@ interfaces: ` t.Run("ParseConfigYAMLFile", func(t *testing.T) { - f, err := os.CreateTemp(".", "radv-test") + f, err := os.CreateTemp(".", "ra-test") require.NoError(t, err) defer os.Remove(f.Name()) _, err = f.Write([]byte(yamlConf)) diff --git a/daemon.go b/daemon.go index f2fc95c..6e934d4 100644 --- a/daemon.go +++ b/daemon.go @@ -1,4 +1,4 @@ -package radv +package ra import ( "context" @@ -8,7 +8,7 @@ import ( "time" ) -// Daemon is the main struct for the radv daemon +// Daemon is the main struct for the ra daemon type Daemon struct { initialConfig *Config reloadCh chan *Config diff --git a/daemon_test.go b/daemon_test.go index 42bd685..a09046f 100644 --- a/daemon_test.go +++ b/daemon_test.go @@ -1,4 +1,4 @@ -package radv +package ra import ( "context" diff --git a/fake_socket.go b/fake_socket.go index 1c4806b..12ad4e9 100644 --- a/fake_socket.go +++ b/fake_socket.go @@ -1,4 +1,4 @@ -package radv +package ra import ( "context" diff --git a/go.mod b/go.mod index a6764be..6d8776b 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/YutaroHayakawa/go-radv +module github.com/YutaroHayakawa/go-ra go 1.22.0 diff --git a/integration_tests/gobgp_unnumbered_test.go b/integration_tests/gobgp_unnumbered_test.go index d4d47ae..488be2c 100644 --- a/integration_tests/gobgp_unnumbered_test.go +++ b/integration_tests/gobgp_unnumbered_test.go @@ -5,7 +5,7 @@ import ( "testing" "time" - "github.com/YutaroHayakawa/go-radv" + "github.com/YutaroHayakawa/go-ra" "github.com/lorenzosaino/go-sysctl" apipb "github.com/osrg/gobgp/v3/api" @@ -67,13 +67,13 @@ func TestGoBGPUnnumbered(t *testing.T) { err = sysctlClient.Set("net.ipv6.conf."+veth1Name+".accept_ra", "2") require.NoError(t, err) - t.Log("Sysctl set. Starting radvd.") + t.Log("Sysctl set. Starting rad.") ctx := context.Background() - // Start radvd - radvd0, err := radv.NewDaemon(&radv.Config{ - Interfaces: []*radv.InterfaceConfig{ + // Start rad + rad0, err := ra.NewDaemon(&ra.Config{ + Interfaces: []*ra.InterfaceConfig{ { Name: veth0Name, RAIntervalMilliseconds: 1000, @@ -82,8 +82,8 @@ func TestGoBGPUnnumbered(t *testing.T) { }) require.NoError(t, err) - radvd1, err := radv.NewDaemon(&radv.Config{ - Interfaces: []*radv.InterfaceConfig{ + rad1, err := ra.NewDaemon(&ra.Config{ + Interfaces: []*ra.InterfaceConfig{ { Name: veth1Name, RAIntervalMilliseconds: 1000, @@ -92,18 +92,18 @@ func TestGoBGPUnnumbered(t *testing.T) { }) require.NoError(t, err) - go radvd0.Run(ctx) - go radvd1.Run(ctx) + go rad0.Run(ctx) + go rad1.Run(ctx) - t.Log("Started radvd. Waiting for RAs to be sent.") + t.Log("Started rad. Waiting for RAs to be sent.") // Wait at least for 2 RAs to be sent require.Eventually(t, func() bool { - status0 := radvd0.Status() - status1 := radvd1.Status() + status0 := rad0.Status() + status1 := rad1.Status() return status0 != nil && status1 != nil && - status0.Interfaces[0].State == radv.Running && - status1.Interfaces[0].State == radv.Running + status0.Interfaces[0].State == ra.Running && + status1.Interfaces[0].State == ra.Running }, time.Second*10, time.Millisecond*500) t.Log("RAs are being sent. Starting BGP.") diff --git a/integration_tests/shared_resources.go b/integration_tests/shared_resources.go index 13e7da1..147971b 100644 --- a/integration_tests/shared_resources.go +++ b/integration_tests/shared_resources.go @@ -4,8 +4,8 @@ package integration_tests // integration tests that may run concurrently. var ( // Assigned to the TestGoBGPUnnumbered - vethPair0 = []string{"go-radv0", "go-radv1"} + vethPair0 = []string{"go-ra0", "go-ra1"} // Assigned to the TestSolictedRA - vethPair1 = []string{"go-radv2", "go-radv3"} + vethPair1 = []string{"go-ra2", "go-ra3"} ) diff --git a/integration_tests/solicited_ra_test.go b/integration_tests/solicited_ra_test.go index 6c22d11..0f99dce 100644 --- a/integration_tests/solicited_ra_test.go +++ b/integration_tests/solicited_ra_test.go @@ -5,7 +5,7 @@ import ( "testing" "time" - "github.com/YutaroHayakawa/go-radv" + "github.com/YutaroHayakawa/go-ra" "github.com/lorenzosaino/go-sysctl" "github.com/osrg/gobgp/v3/pkg/config/oc" "github.com/stretchr/testify/require" @@ -64,14 +64,14 @@ func TestSolicitedRA(t *testing.T) { err = netlink.LinkSetUp(link1) require.NoError(t, err) - // Start radvd - t.Log("Starting radvd") + // Start rad + t.Log("Starting rad") ctx := context.Background() - // Start radvd on veth0 - radvd0, err := radv.NewDaemon(&radv.Config{ - Interfaces: []*radv.InterfaceConfig{ + // Start rad on veth0 + rad0, err := ra.NewDaemon(&ra.Config{ + Interfaces: []*ra.InterfaceConfig{ { Name: veth0Name, // Set this to super long to avoid sending unsolicited RAs. @@ -81,15 +81,15 @@ func TestSolicitedRA(t *testing.T) { }) require.NoError(t, err) - go radvd0.Run(ctx) + go rad0.Run(ctx) // Wait until the RA sender is ready require.Eventually(t, func() bool { - status := radvd0.Status() - return status.Interfaces[0].State == radv.Running + status := rad0.Status() + return status.Interfaces[0].State == ra.Running }, time.Second*10, 100*time.Millisecond) - t.Logf("radvd is ready. Down -> Up %s to send RS", veth1Name) + t.Logf("rad is ready. Down -> Up %s to send RS", veth1Name) // Down and up the link to trigger an RS err = netlink.LinkSetDown(link1) @@ -101,7 +101,7 @@ func TestSolicitedRA(t *testing.T) { // Ensure the neighbor entry is created require.Eventually(t, func() bool { _, err := oc.GetIPv6LinkLocalNeighborAddress(veth1Name) - status := radvd0.Status() + status := rad0.Status() return err == nil && status.Interfaces[0].TxSolicitedRA > 0 }, time.Second*10, 100*time.Millisecond) diff --git a/ra_sender.go b/ra_sender.go index b5a31c2..358a09e 100644 --- a/ra_sender.go +++ b/ra_sender.go @@ -1,4 +1,4 @@ -package radv +package ra import ( "context" diff --git a/socket.go b/socket.go index f3cae49..37a3e7d 100644 --- a/socket.go +++ b/socket.go @@ -1,4 +1,4 @@ -package radv +package ra import ( "context" diff --git a/status.go b/status.go index 09fdd0a..add407d 100644 --- a/status.go +++ b/status.go @@ -1,4 +1,4 @@ -package radv +package ra // Status is the status of the Daemon type Status struct { diff --git a/zz_generated_deepcopy.go b/zz_generated_deepcopy.go index 11df720..55f2d38 100644 --- a/zz_generated_deepcopy.go +++ b/zz_generated_deepcopy.go @@ -1,6 +1,6 @@ // generated by deep-copy -pointer-receiver -type Config -type Status -type InterfaceConfig -type InterfaceStatus -o zz_generated_deepcopy.go .; DO NOT EDIT. -package radv +package ra // DeepCopy generates a deep copy of *Config func (o *Config) DeepCopy() *Config {