Skip to content

Commit

Permalink
Rename package from radv to ra
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
YutaroHayakawa committed May 5, 2024
1 parent 7697160 commit 1e2add4
Show file tree
Hide file tree
Showing 19 changed files with 62 additions and 58 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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:

Expand 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# go-radv
# go-ra
Pure Go IPv6 Router Advertisement daemon
6 changes: 3 additions & 3 deletions cmd/goradv/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions cmd/goradvd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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())
Expand Down
8 changes: 4 additions & 4 deletions cmd/internal/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"fmt"
"net/http"

"github.com/YutaroHayakawa/go-radv"
"github.com/YutaroHayakawa/go-ra"
)

type Client struct {
Expand All @@ -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
Expand Down Expand Up @@ -60,15 +60,15 @@ 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
}
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)
}
Expand Down
10 changes: 5 additions & 5 deletions cmd/internal/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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())
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package radv
package ra

import (
"encoding/json"
Expand Down
4 changes: 2 additions & 2 deletions config_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package radv
package ra

import (
"bytes"
Expand All @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions daemon.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package radv
package ra

import (
"context"
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion daemon_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package radv
package ra

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion fake_socket.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package radv
package ra

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/YutaroHayakawa/go-radv
module github.com/YutaroHayakawa/go-ra

go 1.22.0

Expand Down
28 changes: 14 additions & 14 deletions integration_tests/gobgp_unnumbered_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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.")
Expand Down
4 changes: 2 additions & 2 deletions integration_tests/shared_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
)
22 changes: 11 additions & 11 deletions integration_tests/solicited_ra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand All @@ -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)
Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion ra_sender.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package radv
package ra

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion socket.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package radv
package ra

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion status.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package radv
package ra

// Status is the status of the Daemon
type Status struct {
Expand Down
2 changes: 1 addition & 1 deletion zz_generated_deepcopy.go
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down

0 comments on commit 1e2add4

Please sign in to comment.