|
|
@ -3,6 +3,8 @@ package main
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
"net"
|
|
|
|
"os"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
|
|
envChecks "git.ruekov.eu/ruakij/routingtabletowg/lib/environmentchecks"
|
|
|
|
envChecks "git.ruekov.eu/ruakij/routingtabletowg/lib/environmentchecks"
|
|
|
|
ip2Map "git.ruekov.eu/ruakij/routingtabletowg/lib/iproute2mapping"
|
|
|
|
ip2Map "git.ruekov.eu/ruakij/routingtabletowg/lib/iproute2mapping"
|
|
|
@ -24,6 +26,8 @@ var envDefaults = map[string]string{
|
|
|
|
|
|
|
|
|
|
|
|
"FILTER_PROTOCOL": "-1",
|
|
|
|
"FILTER_PROTOCOL": "-1",
|
|
|
|
"FILTER_TABLE": "-1",
|
|
|
|
"FILTER_TABLE": "-1",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"PERIODIC_SYNC": "-1",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
func main() {
|
|
|
@ -55,6 +59,12 @@ func main() {
|
|
|
|
logger.Error.Fatalf("Couldn't read FILTER_TABLE '%s': %s", filterTableStr, err)
|
|
|
|
logger.Error.Fatalf("Couldn't read FILTER_TABLE '%s': %s", filterTableStr, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
periodicSyncStr := os.Getenv("PERIODIC_SYNC")
|
|
|
|
|
|
|
|
periodicSync, err := strconv.Atoi(periodicSyncStr)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
logger.Error.Fatalf("Couldn't read PERIODIC_SYNC '%s': %s", periodicSyncStr, err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Create filter
|
|
|
|
// Create filter
|
|
|
|
filterOptions := FilterOptions{
|
|
|
|
filterOptions := FilterOptions{
|
|
|
|
Table: filterTable,
|
|
|
|
Table: filterTable,
|
|
|
@ -93,6 +103,33 @@ func main() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
logger.Info.Printf("Initially setting all current routes")
|
|
|
|
logger.Info.Printf("Initially setting all current routes")
|
|
|
|
|
|
|
|
syncCurrentRoutesToHandler(routeSubChan, routeList)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(periodicSync > 0){
|
|
|
|
|
|
|
|
go runPeriodicSync(periodicSync, link, routeSubChan)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
select {}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func runPeriodicSync(seconds int, link netlink.Link, routeSubChan chan netlink.RouteUpdate){
|
|
|
|
|
|
|
|
interval := time.Duration(seconds) * time.Second
|
|
|
|
|
|
|
|
for {
|
|
|
|
|
|
|
|
time.Sleep(interval)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Get routing-table entries from device
|
|
|
|
|
|
|
|
routeList, err := netlink.RouteList(link, netlink.FAMILY_ALL)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
logger.Error.Fatalf("Couldn't get route-entries: %s", err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
logger.Info.Printf("Periodically syncing all routes")
|
|
|
|
|
|
|
|
syncCurrentRoutesToHandler(routeSubChan, routeList)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func syncCurrentRoutesToHandler(routeSubChan chan netlink.RouteUpdate, routeList []netlink.Route){
|
|
|
|
|
|
|
|
|
|
|
|
for _, route := range routeList {
|
|
|
|
for _, route := range routeList {
|
|
|
|
// Ignore routes with empty gateway
|
|
|
|
// Ignore routes with empty gateway
|
|
|
|
if(route.Gw == nil){
|
|
|
|
if(route.Gw == nil){
|
|
|
@ -105,8 +142,6 @@ func main() {
|
|
|
|
Route: route,
|
|
|
|
Route: route,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
select {}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var routeUpdateTypeMapFromId = map[uint16]string{
|
|
|
|
var routeUpdateTypeMapFromId = map[uint16]string{
|
|
|
|