From 5313e2e0d81a1543f6682aa96409498cf5fdcbe8 Mon Sep 17 00:00:00 2001 From: hwipl <33433250+hwipl@users.noreply.github.com> Date: Wed, 7 Aug 2024 11:01:35 +0200 Subject: [PATCH] Add variables in Split Routing to log entries Signed-off-by: hwipl <33433250+hwipl@users.noreply.github.com> --- internal/splitrt/filter.go | 24 ++++++++++++------ internal/splitrt/route.go | 50 ++++++++++++++++++++++++++------------ 2 files changed, 50 insertions(+), 24 deletions(-) diff --git a/internal/splitrt/filter.go b/internal/splitrt/filter.go index 6e59411..92344c7 100644 --- a/internal/splitrt/filter.go +++ b/internal/splitrt/filter.go @@ -106,6 +106,7 @@ table inet oc-daemon-routing { rules := r.Replace(routeRules) if stdout, stderr, err := execs.RunNft(ctx, rules); err != nil { log.WithError(err).WithFields(log.Fields{ + "fwMark": fwMark, "stdout": string(stdout), "stderr": string(stderr), }).Error("SplitRouting error setting routing rules") @@ -138,8 +139,11 @@ func addLocalAddresses(ctx context.Context, device, family string, addresses []* if stdout, stderr, err := execs.RunNft(ctx, nftconf); err != nil { log.WithError(err).WithFields(log.Fields{ - "stdout": string(stdout), - "stderr": string(stderr), + "device": device, + "family": family, + "addresses": addresses, + "stdout": string(stdout), + "stderr": string(stderr), }).Error("SplitRouting error adding local addresses") } } @@ -172,8 +176,10 @@ func rejectIPVersion(ctx context.Context, device, version string) { if stdout, stderr, err := execs.RunNft(ctx, nftconf); err != nil { log.WithError(err).WithFields(log.Fields{ - "stdout": string(stdout), - "stderr": string(stderr), + "device": device, + "version": version, + "stdout": string(stdout), + "stderr": string(stderr), }).Error("SplitRouting error setting ip version reject rules") } } @@ -203,8 +209,9 @@ func addExclude(ctx context.Context, address *netip.Prefix) { set, address) if stdout, stderr, err := execs.RunNft(ctx, nftconf); err != nil { log.WithError(err).WithFields(log.Fields{ - "stdout": string(stdout), - "stderr": string(stderr), + "address": address, + "stdout": string(stdout), + "stderr": string(stderr), }).Error("SplitRouting error adding exclude") } } @@ -230,8 +237,9 @@ func setExcludes(ctx context.Context, addresses []*netip.Prefix) { // run command if stdout, stderr, err := execs.RunNft(ctx, nftconf); err != nil { log.WithError(err).WithFields(log.Fields{ - "stdout": string(stdout), - "stderr": string(stderr), + "addresses": addresses, + "stdout": string(stdout), + "stderr": string(stderr), }).Error("SplitRouting error setting excludes") } } diff --git a/internal/splitrt/route.go b/internal/splitrt/route.go index e32342f..464764a 100644 --- a/internal/splitrt/route.go +++ b/internal/splitrt/route.go @@ -13,8 +13,10 @@ func addDefaultRouteIPv4(ctx context.Context, device, rtTable, rulePrio1, fwMark if stdout, stderr, err := execs.RunIP4Route(ctx, "add", "0.0.0.0/0", "dev", device, "table", rtTable); err != nil { log.WithError(err).WithFields(log.Fields{ - "stdout": string(stdout), - "stderr": string(stderr), + "device": device, + "rtTable": rtTable, + "stdout": string(stdout), + "stderr": string(stderr), }).Error("SplitRouting error setting ipv4 default route") } @@ -22,15 +24,20 @@ func addDefaultRouteIPv4(ctx context.Context, device, rtTable, rulePrio1, fwMark if stdout, stderr, err := execs.RunIP4Rule(ctx, "add", "iif", device, "table", "main", "pref", rulePrio1); err != nil { log.WithError(err).WithFields(log.Fields{ - "stdout": string(stdout), - "stderr": string(stderr), + "device": device, + "rulePrio1": rulePrio1, + "stdout": string(stdout), + "stderr": string(stderr), }).Error("SplitRouting error setting ipv4 routing rule 1") } if stdout, stderr, err := execs.RunIP4Rule(ctx, "add", "not", "fwmark", fwMark, "table", rtTable, "pref", rulePrio2); err != nil { log.WithError(err).WithFields(log.Fields{ - "stdout": string(stdout), - "stderr": string(stderr), + "fwMark": fwMark, + "rtTable": rtTable, + "rulePrio2": rulePrio2, + "stdout": string(stdout), + "stderr": string(stderr), }).Error("SplitRouting error setting ipv4 routing rule 2") } @@ -50,8 +57,10 @@ func addDefaultRouteIPv6(ctx context.Context, device, rtTable, rulePrio1, fwMark if stdout, stderr, err := execs.RunIP6Route(ctx, "add", "::/0", "dev", device, "table", rtTable); err != nil { log.WithError(err).WithFields(log.Fields{ - "stdout": string(stdout), - "stderr": string(stderr), + "device": device, + "rtTable": rtTable, + "stdout": string(stdout), + "stderr": string(stderr), }).Error("SplitRouting error setting ipv6 default route") } @@ -59,15 +68,20 @@ func addDefaultRouteIPv6(ctx context.Context, device, rtTable, rulePrio1, fwMark if stdout, stderr, err := execs.RunIP6Rule(ctx, "add", "iif", device, "table", "main", "pref", rulePrio1); err != nil { log.WithError(err).WithFields(log.Fields{ - "stdout": string(stdout), - "stderr": string(stderr), + "device": device, + "rulePrio1": rulePrio1, + "stdout": string(stdout), + "stderr": string(stderr), }).Error("SplitRouting error setting ipv6 routing rule 1") } if stdout, stderr, err := execs.RunIP6Rule(ctx, "add", "not", "fwmark", fwMark, "table", rtTable, "pref", rulePrio2); err != nil { log.WithError(err).WithFields(log.Fields{ - "stdout": string(stdout), - "stderr": string(stderr), + "fwMark": fwMark, + "rtTable": rtTable, + "rulePrio2": rulePrio2, + "stdout": string(stdout), + "stderr": string(stderr), }).Error("SplitRouting error setting ipv6 routing rule 2") } } @@ -77,13 +91,15 @@ func deleteDefaultRouteIPv4(ctx context.Context, device, rtTable string) { // delete routing rules if stdout, stderr, err := execs.RunIP4Rule(ctx, "delete", "table", rtTable); err != nil { log.WithError(err).WithFields(log.Fields{ - "stdout": string(stdout), - "stderr": string(stderr), + "rtTable": rtTable, + "stdout": string(stdout), + "stderr": string(stderr), }).Error("SplitRouting error deleting ipv4 routing rule 2") } if stdout, stderr, err := execs.RunIP4Rule(ctx, "delete", "iif", device, "table", "main"); err != nil { log.WithError(err).WithFields(log.Fields{ + "device": device, "stdout": string(stdout), "stderr": string(stderr), }).Error("SplitRouting error deleting ipv4 routing rule 1") @@ -95,13 +111,15 @@ func deleteDefaultRouteIPv6(ctx context.Context, device, rtTable string) { // delete routing rules if stdout, stderr, err := execs.RunIP6Rule(ctx, "delete", "table", rtTable); err != nil { log.WithError(err).WithFields(log.Fields{ - "stdout": string(stdout), - "stderr": string(stderr), + "rtTable": rtTable, + "stdout": string(stdout), + "stderr": string(stderr), }).Error("SplitRouting error deleting ipv6 routing rule 2") } if stdout, stderr, err := execs.RunIP6Rule(ctx, "delete", "iif", device, "table", "main"); err != nil { log.WithError(err).WithFields(log.Fields{ + "device": device, "stdout": string(stdout), "stderr": string(stderr), }).Error("SplitRouting error deleting ipv6 routing rule 1")