Skip to content

Commit

Permalink
refactor: unify loopback handling
Browse files Browse the repository at this point in the history
it does not really make sense to handle the loopback interface any
different than eth, this was a leftover from before introducing a known
local port.
  • Loading branch information
ctrox committed Jan 11, 2024
1 parent 91c67d7 commit 6016e88
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 14 deletions.
3 changes: 1 addition & 2 deletions activator/activator.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,7 @@ func (s *Server) handleConection(ctx context.Context, conn net.Conn, port uint16
}

if err := s.removeConnection(uint16(tcpAddr.Port)); err != nil {
log.G(ctx).Errorf("error removing connection: %s", err)
return
log.G(ctx).Warnf("error removing connection: %s", err)
}

log.G(ctx).Println("connection closed", conn.RemoteAddr().String())
Expand Down
5 changes: 0 additions & 5 deletions activator/bpf.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,6 @@ func initBPF(ifaces ...string) (*bpfObjects, func(), error) {
}
filters = append(filters, &ingress)

// for loopback we don't need an egress filter
if devID.Index == 1 {
continue
}

if err := netlink.FilterReplace(&egress); err != nil {
return nil, nil, fmt.Errorf("failed to replace tc filter: %w", err)
}
Expand Down
Binary file modified activator/bpf_bpfeb.o
Binary file not shown.
Binary file modified activator/bpf_bpfel.o
Binary file not shown.
9 changes: 2 additions & 7 deletions activator/redirector.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,11 @@ static __always_inline int parse_and_redirect(struct __sk_buff *ctx, bool ingres
if (ip->protocol == IPPROTO_TCP) {
struct tcphdr *tcp = (void*)ip + sizeof(*ip);
if ((void*)tcp + sizeof(*tcp) <= data_end) {
if (ctx->ifindex == 1) {
ingress_redirect(tcp);
return egress_redirect(tcp);
}

if (ingress) {
return ingress_redirect(tcp);
} else {
return egress_redirect(tcp);
}

return egress_redirect(tcp);
}
}
}
Expand Down

0 comments on commit 6016e88

Please sign in to comment.