Skip to content

Commit

Permalink
Merge pull request #115 from telekom-mms/feature/log-variables-in-spl…
Browse files Browse the repository at this point in the history
…itrt

Add variables in Split Routing to log entries
  • Loading branch information
hwipl committed Aug 13, 2024
2 parents f4c16db + 5313e2e commit bc958cc
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 24 deletions.
24 changes: 16 additions & 8 deletions internal/splitrt/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
}
}
Expand Down Expand Up @@ -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")
}
}
Expand Down Expand Up @@ -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")
}
}
Expand All @@ -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")
}
}
Expand Down
50 changes: 34 additions & 16 deletions internal/splitrt/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,31 @@ 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")
}

// set routing rules
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")
}

Expand All @@ -50,24 +57,31 @@ 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")
}

// set routing rules
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")
}
}
Expand All @@ -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")
Expand All @@ -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")
Expand Down

0 comments on commit bc958cc

Please sign in to comment.