Compare commits
No commits in common. "36e8aa9b8711ccedf44a8a21f601fa15218c014c" and "f136bcb207316fba076e2c5fe7755fac3ae30a90" have entirely different histories.
36e8aa9b87
...
f136bcb207
@ -2,9 +2,6 @@
|
||||
FROM alpine:3 AS base
|
||||
WORKDIR /app
|
||||
|
||||
# Install necessary packages
|
||||
RUN apk add --no-cache iproute2
|
||||
|
||||
|
||||
# ---- Build ----
|
||||
FROM golang:1.19-alpine AS build
|
||||
|
11
README.md
11
README.md
@ -38,12 +38,11 @@ In case routes clash or cant be added to Wireguard, Warnings will be logged.
|
||||
|
||||
### 1.2.1. Environment
|
||||
|
||||
Variable|Description|Type|Default
|
||||
-|-|-|-
|
||||
`INTERFACE`* | Wireguard-Interface Name | String |
|
||||
`FILTER_PROTOCOL` | Protocol to react on | Number / iproute2-name | All
|
||||
`FILTER_TABLE` | Table to react on | Number / iproute2-name | All
|
||||
`PERIODIC_SYNC` | Reguarly sync the routing-table <br> Useful when the wg-interface is changed/updated without us knowing | Seconds | -1
|
||||
Variable|Description|Default
|
||||
-|-|-
|
||||
`INTERFACE`* | Wireguard-Interface Name |
|
||||
`FILTER_PROTOCOL` | Protocol to react on | All
|
||||
`FILTER_TABLE` | Table to react on | All
|
||||
|
||||
*\* Required*
|
||||
|
||||
|
@ -3,8 +3,6 @@ package main
|
||||
import (
|
||||
"net"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
envChecks "git.ruekov.eu/ruakij/routingtabletowg/lib/environmentchecks"
|
||||
ip2Map "git.ruekov.eu/ruakij/routingtabletowg/lib/iproute2mapping"
|
||||
@ -26,8 +24,6 @@ var envDefaults = map[string]string{
|
||||
|
||||
"FILTER_PROTOCOL": "-1",
|
||||
"FILTER_TABLE": "-1",
|
||||
|
||||
"PERIODIC_SYNC": "-1",
|
||||
}
|
||||
|
||||
func main() {
|
||||
@ -41,11 +37,6 @@ func main() {
|
||||
iface := os.Getenv("INTERFACE")
|
||||
//MANAGE_ALL = os.Getenv("MANAGE_ALL")
|
||||
|
||||
// Check if ip2Map has init-errors
|
||||
for _, err := range ip2Map.Errors {
|
||||
logger.Warn.Printf("iproute2mapping: %s", err)
|
||||
}
|
||||
|
||||
// Parse filter-env-vars
|
||||
filterProtocolStr := os.Getenv("FILTER_PROTOCOL")
|
||||
filterProtocol, err := ip2Map.TryGetId(ip2Map.PROTOCOL, filterProtocolStr)
|
||||
@ -59,12 +50,6 @@ func main() {
|
||||
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
|
||||
filterOptions := FilterOptions{
|
||||
Table: filterTable,
|
||||
@ -103,33 +88,6 @@ func main() {
|
||||
}
|
||||
|
||||
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 {
|
||||
// Ignore routes with empty gateway
|
||||
if(route.Gw == nil){
|
||||
@ -142,6 +100,8 @@ func syncCurrentRoutesToHandler(routeSubChan chan netlink.RouteUpdate, routeList
|
||||
Route: route,
|
||||
}
|
||||
}
|
||||
|
||||
select {}
|
||||
}
|
||||
|
||||
var routeUpdateTypeMapFromId = map[uint16]string{
|
||||
|
@ -32,9 +32,9 @@ func init() {
|
||||
for mapType, filePath := range filePaths{
|
||||
ByName[mapType], ById[mapType], err = readFromFile(filePath)
|
||||
if(err != nil){
|
||||
Errors = append(Errors,
|
||||
fmt.Errorf("failed reading mapping-file '%s': %s", filePath, err),
|
||||
);
|
||||
Errors = []error{
|
||||
fmt.Errorf("failed reading iproute2 mapping-file '%s': %s", filePath, err),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user