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

allow to specify source LLA's address #27

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ type rawInterface struct {
DNSSL []rawDNSSL `toml:"dnssl"`
MTU int `toml:"mtu"`
SourceLLA *bool `toml:"source_lla"`
LLA_Address string `toml:"lla_address"`
CaptivePortal string `toml:"captive_portal"`
}

Expand Down
14 changes: 13 additions & 1 deletion internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package config_test

import (
"net"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -88,6 +89,14 @@ func TestParse(t *testing.T) {
default_lifetime = "yes"
`,
},
{
name: "bad LLA address",
s: `
[[interfaces]]
name = "eth0"
lla_address = "yes"
`,
},
{
name: "bad debug address",
s: `
Expand Down Expand Up @@ -162,6 +171,7 @@ func TestParse(t *testing.T) {
reachable_time = "30s"
retransmit_timer = "5s"
source_lla = true
lla_address = "de:ad:be:ef:de:ad"
captive_portal = ""
preference = "low"

Expand Down Expand Up @@ -254,7 +264,9 @@ func TestParse(t *testing.T) {
Auto: true,
Lifetime: 8 * time.Second,
},
&plugin.LLA{},
&plugin.LLA{
Addr: net.HardwareAddr{0xde, 0xad, 0xbe, 0xef, 0xde, 0xad},
},
},
},
{
Expand Down
14 changes: 13 additions & 1 deletion internal/config/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package config
import (
"errors"
"fmt"
"net"
"sort"
"time"

Expand Down Expand Up @@ -108,7 +109,18 @@ func parsePlugins(ifi rawInterface, maxInterval time.Duration, epoch time.Time)

// Always set unless explicitly false.
if ifi.SourceLLA == nil || *ifi.SourceLLA {
plugins = append(plugins, &plugin.LLA{})
p := &plugin.LLA{}
// if LLA_Address is set, explicitly use that address instead of the
// interface's actual address.
if ifi.LLA_Address != "" {
var err error
p.Addr, err = net.ParseMAC(ifi.LLA_Address)
if err != nil {
return nil, fmt.Errorf("failed to parse LLA_Address: %v", err)
}
}

plugins = append(plugins, p)
}

// Only set when key is not empty.
Expand Down
9 changes: 7 additions & 2 deletions internal/config/reference.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,13 @@ default_lifetime = "auto"
mtu = 0

# AdvSourceLLAddress: attaches a NDP source link-layer address option to the
# router advertisement. Defaults to true when omitted.
source_lla = true
# router advertisement. Specify router MAC address or set to auto to use MAC
# address of current interface. Defaults to auto when omitted.
source_lla = "auto"

# AdvSourceLLAddress: override the interface's link-layer address with specified MAC
# Useful when sending out router advertisements on behalf of another router.
lla_address = ""

# Attaches a NDP captive portal option to the router advertisement. Only set
# when a URI value is present and not an empty string.
Expand Down