mirror of
https://github.com/rtr7/router7.git
synced 2024-05-06 15:54:52 +00:00
Working radvd
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
// Binary dhcp4 obtains a DHCPv4 lease, persists its contents to
|
||||
// Binary dhcp4 obtains a DHCPv4 lease, persists it to
|
||||
// /perm/dhcp4/wire/lease.json and notifies netconfigd.
|
||||
package main
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Binary dhcp6 obtains a DHCPv6 lease, persists its contents to
|
||||
// Binary dhcp6 obtains a DHCPv6 lease, persists it to
|
||||
// /perm/dhcp6/wire/lease.json and notifies netconfigd.
|
||||
package main
|
||||
|
||||
|
@ -21,12 +21,21 @@ func logic() error {
|
||||
ch := make(chan os.Signal, 1)
|
||||
signal.Notify(ch, syscall.SIGUSR1)
|
||||
for {
|
||||
if err := netconfig.Apply("uplink0", "/perm/"); err != nil {
|
||||
err := netconfig.Apply("uplink0", "/perm/")
|
||||
// Notify gokrazy about new addresses (netconfig.Apply might have
|
||||
// modified state before returning an error) so that listeners can be
|
||||
// updated.
|
||||
p, _ := os.FindProcess(1)
|
||||
if err := p.Signal(syscall.SIGHUP); err != nil {
|
||||
log.Printf("kill -HUP 1: %v", err)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if *linger {
|
||||
<-ch
|
||||
if !*linger {
|
||||
break
|
||||
}
|
||||
<-ch
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -114,7 +114,7 @@ func TestNetconfig(t *testing.T) {
|
||||
if !addrRe.MatchString(string(addrs)) {
|
||||
t.Fatalf("regexp %s does not match %s", addrRe, string(addrs))
|
||||
}
|
||||
addr6Re := regexp.MustCompile(`(?m)^\s*inet6 2a02:168:4a00::1/48 scope global\s*$`)
|
||||
addr6Re := regexp.MustCompile(`(?m)^\s*inet6 2a02:168:4a00::1/64 scope global\s*$`)
|
||||
if !addr6Re.MatchString(string(addrs)) {
|
||||
t.Fatalf("regexp %s does not match %s", addr6Re, string(addrs))
|
||||
}
|
||||
|
@ -6,11 +6,9 @@ import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/vishvananda/netlink"
|
||||
"golang.org/x/sys/unix"
|
||||
@ -123,6 +121,10 @@ func applyDhcp6(iface, dir string) error {
|
||||
// pick the first address of the prefix, e.g. address 2a02:168:4a00::1
|
||||
// for prefix 2a02:168:4a00::/48
|
||||
prefix.IP[len(prefix.IP)-1] = 1
|
||||
// Use the first /64 subnet within larger prefixes
|
||||
if ones, bits := prefix.Mask.Size(); ones < 64 {
|
||||
prefix.Mask = net.CIDRMask(64, bits)
|
||||
}
|
||||
addr, err := netlink.ParseAddr(prefix.String())
|
||||
if err != nil {
|
||||
return err
|
||||
@ -220,12 +222,23 @@ func applyFirewall() error {
|
||||
|
||||
func applySysctl() error {
|
||||
if err := ioutil.WriteFile("/proc/sys/net/ipv4/ip_forward", []byte("1"), 0644); err != nil {
|
||||
return err
|
||||
return fmt.Errorf("sysctl(net.ipv4.ip_forward=1): %v", err)
|
||||
}
|
||||
|
||||
if err := ioutil.WriteFile("/proc/sys/net/ipv6/conf/all/forwarding", []byte("1"), 0644); err != nil {
|
||||
return fmt.Errorf("sysctl(net.ipv6.conf.all.forwarding=1): %v", err)
|
||||
}
|
||||
|
||||
if err := ioutil.WriteFile("/proc/sys/net/ipv6/conf/uplink0/accept_ra", []byte("2"), 0644); err != nil {
|
||||
return fmt.Errorf("sysctl(net.ipv6.conf.uplink0.accept_ra=2): %v", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func Apply(iface, dir string) error {
|
||||
|
||||
// TODO: split into two parts: delay the up until later
|
||||
if err := applyInterfaces(dir); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -246,11 +259,5 @@ func Apply(iface, dir string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// Notify gokrazy init of new addresses
|
||||
p, _ := os.FindProcess(1)
|
||||
if err := p.Signal(syscall.SIGHUP); err != nil {
|
||||
log.Printf("send SIGHUP to init: %v", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user