fib update
This commit is contained in:
parent
095fb9243f
commit
2d381d2a85
2
main.go
2
main.go
@ -9,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
func callback(r *ripv2.Routes) {
|
||||
rtable.Add(r)
|
||||
rtable.Pass(r)
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
@ -15,7 +15,7 @@ type Routes struct {
|
||||
|
||||
type Route struct {
|
||||
Addr net.IP
|
||||
FIB bool
|
||||
FIB FIB
|
||||
Subnet net.IPMask
|
||||
Nexthop net.IP
|
||||
Metric uint32
|
||||
|
@ -10,9 +10,9 @@ func (r *Routes) Timer() {
|
||||
for {
|
||||
<-t.C
|
||||
r.Lock()
|
||||
for k, route := range r.Routes {
|
||||
for _, route := range r.Routes {
|
||||
if time.Since(route.TTL) >= time.Minute*2 {
|
||||
delete(r.Routes, k)
|
||||
route.FIB = DELETE
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package ripv2
|
||||
|
||||
type Command uint8
|
||||
type FIB uint8
|
||||
type Version uint8
|
||||
|
||||
const (
|
||||
@ -9,6 +10,12 @@ const (
|
||||
RESPONSE
|
||||
)
|
||||
|
||||
const (
|
||||
NEW FIB = iota
|
||||
TABLE
|
||||
DELETE
|
||||
)
|
||||
|
||||
const (
|
||||
RIPv1 Version = iota + 1
|
||||
RIPv2
|
||||
|
@ -3,17 +3,24 @@ package rtable
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"os/exec"
|
||||
|
||||
"github.com/crip/ripv2"
|
||||
)
|
||||
|
||||
func Add(r *ripv2.Routes) {
|
||||
func Pass(r *ripv2.Routes) {
|
||||
r.Lock()
|
||||
for _, r := range r.Routes {
|
||||
if !r.FIB {
|
||||
command(ADD, &r)
|
||||
r.FIB = true
|
||||
for k, route := range r.Routes {
|
||||
switch route.FIB {
|
||||
case ripv2.NEW:
|
||||
command(ADD, &route)
|
||||
route.FIB = ripv2.TABLE
|
||||
case ripv2.DELETE:
|
||||
command(REMOVE, &route)
|
||||
delete(r.Routes, k)
|
||||
default:
|
||||
log.Println("unknown FIB type")
|
||||
}
|
||||
}
|
||||
r.Unlock()
|
||||
@ -29,9 +36,3 @@ func command(command COMMAND, r *ripv2.Route) error {
|
||||
}
|
||||
return cmd.Run()
|
||||
}
|
||||
|
||||
func Remove(r *ripv2.Routes) {
|
||||
for _, r := range r.Routes {
|
||||
command(REMOVE, &r)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user