Skip to content

Commit

Permalink
fix: bad behaviour of must_direct
Browse files Browse the repository at this point in the history
  • Loading branch information
mzz2017 committed Mar 13, 2023
1 parent 570a04a commit 207c343
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions control/kern/tproxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -971,14 +971,6 @@ routing(const __u32 flag[6], const void *l4hdr, const __be32 saddr[4],
return ret;
};

// Modify DNS upstream for routing.
if (h_dport == 53 && _l4proto_type == L4ProtoType_UDP) {
__u32 *control_plane_dns_routing =
bpf_map_lookup_elem(&param_map, &control_plane_dns_routing_key);
if (control_plane_dns_routing && *control_plane_dns_routing) {
return OUTBOUND_CONTROL_PLANE_ROUTING;
}
}
lpm_key_instance.trie_key.prefixlen = IPV6_BYTE_LENGTH * 8;
__builtin_memcpy(lpm_key_instance.data, daddr, IPV6_BYTE_LENGTH);
key = MatchType_IpSet;
Expand Down Expand Up @@ -1134,6 +1126,17 @@ routing(const __u32 flag[6], const void *l4hdr, const __be32 saddr[4],
bpf_printk("MATCHED: match_set->type: %u, match_set->not: %d",
match_set->type, match_set->not );
#endif

// DNS requests should routed by control plane if outbound is not
// must_direct.
if (match_set->outbound != OUTBOUND_MUST_DIRECT && h_dport == 53 &&
_l4proto_type == L4ProtoType_UDP) {
__u32 *control_plane_dns_routing =
bpf_map_lookup_elem(&param_map, &control_plane_dns_routing_key);
if (control_plane_dns_routing && *control_plane_dns_routing) {
return OUTBOUND_CONTROL_PLANE_ROUTING | (match_set->mark << 8);
}
}
return match_set->outbound | (match_set->mark << 8);
}
bad_rule = false;
Expand Down

0 comments on commit 207c343

Please sign in to comment.