Skip to content

Commit

Permalink
Remove addExclude() from Split Routing
Browse files Browse the repository at this point in the history
Simplify Split Routing: remove addExclude() and only use setExcludes().

Signed-off-by: hwipl <[email protected]>
  • Loading branch information
hwipl committed Dec 20, 2024
1 parent 854d545 commit 0e634be
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 23 deletions.
20 changes: 0 additions & 20 deletions internal/splitrt/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,26 +195,6 @@ func rejectIPv4(ctx context.Context, device string) {
rejectIPVersion(ctx, device, "ipv4")
}

// addExclude adds exclude address to netfilter.
func addExclude(ctx context.Context, address netip.Prefix) {
log.WithField("address", address).Debug("SplitRouting adding exclude to netfilter")

set := "excludes4"
if address.Addr().Is6() {
set = "excludes6"
}

nftconf := fmt.Sprintf("add element inet oc-daemon-routing %s { %s }",
set, address)
if stdout, stderr, err := execs.RunNft(ctx, nftconf); err != nil {
log.WithError(err).WithFields(log.Fields{
"address": address,
"stdout": string(stdout),
"stderr": string(stderr),
}).Error("SplitRouting error adding exclude")
}
}

// setExcludes resets the excludes to addresses in netfilter.
func setExcludes(ctx context.Context, addresses []netip.Prefix) {
// flush existing entries
Expand Down
2 changes: 1 addition & 1 deletion internal/splitrt/splitrt.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func (s *SplitRouting) handleDNSReport(ctx context.Context, r *dnsproxy.Report)

exclude := netip.PrefixFrom(r.IP, r.IP.BitLen())
if s.excludes.AddDynamic(exclude, r.TTL) {
addExclude(ctx, exclude)
setExcludes(ctx, s.excludes.GetPrefixes())
}
}

Expand Down
9 changes: 7 additions & 2 deletions internal/splitrt/splitrt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,13 @@ func TestSplitRoutingHandleDNSReport(t *testing.T) {
<-report.Done()

want := []string{
"add element inet oc-daemon-routing excludes4 { 192.168.1.1/32 }",
"add element inet oc-daemon-routing excludes6 { 2001::1/128 }",
"flush set inet oc-daemon-routing excludes4\n" +
"flush set inet oc-daemon-routing excludes6\n" +
"add element inet oc-daemon-routing excludes4 { 192.168.1.1/32 }\n",
"flush set inet oc-daemon-routing excludes4\n" +
"flush set inet oc-daemon-routing excludes6\n" +
"add element inet oc-daemon-routing excludes4 { 192.168.1.1/32 }\n" +
"add element inet oc-daemon-routing excludes6 { 2001::1/128 }\n",
}
if !reflect.DeepEqual(got, want) {
t.Errorf("got %v, want %v", got, want)
Expand Down

0 comments on commit 0e634be

Please sign in to comment.