Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpf: lb: have __lb*_rev_nat() take the source port from CT tuple #31364

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 7 additions & 8 deletions bpf/lib/lb.h
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ bool lb6_svc_is_l7loadbalancer(const struct lb6_service *svc __maybe_unused)
}

static __always_inline int reverse_map_l4_port(struct __ctx_buff *ctx, __u8 nexthdr,
__be16 port, int l4_off,
__be16 old_port, __be16 port, int l4_off,
struct csum_offset *csum_off)
{
switch (nexthdr) {
Expand All @@ -381,13 +381,8 @@ static __always_inline int reverse_map_l4_port(struct __ctx_buff *ctx, __u8 next
case IPPROTO_SCTP:
#endif /* ENABLE_SCTP */
if (port) {
__be16 old_port;
int ret;

/* Port offsets for UDP and TCP are the same */
if (l4_load_port(ctx, l4_off + TCP_SPORT_OFF, &old_port) < 0)
julianwiedmann marked this conversation as resolved.
Show resolved Hide resolved
return DROP_INVALID;

if (port != old_port) {
#ifdef ENABLE_SCTP
/* This will change the SCTP checksum, which we cannot fix right now.
Expand Down Expand Up @@ -455,7 +450,8 @@ static __always_inline int __lb6_rev_nat(struct __ctx_buff *ctx, int l4_off,
csum_l4_offset_and_flags(tuple->nexthdr, &csum_off);

if (nat->port) {
ret = reverse_map_l4_port(ctx, tuple->nexthdr, nat->port, l4_off, &csum_off);
ret = reverse_map_l4_port(ctx, tuple->nexthdr, tuple->dport,
nat->port, l4_off, &csum_off);
if (IS_ERR(ret))
return ret;
}
Expand Down Expand Up @@ -1075,7 +1071,10 @@ static __always_inline int __lb4_rev_nat(struct __ctx_buff *ctx, int l3_off, int
csum_l4_offset_and_flags(tuple->nexthdr, &csum_off);

if (nat->port) {
ret = reverse_map_l4_port(ctx, tuple->nexthdr,
/* We expect to only handle replies. Thus the extracted CT tuple
* will have the packet's source port in .dport.
*/
ret = reverse_map_l4_port(ctx, tuple->nexthdr, tuple->dport,
nat->port, l4_off, &csum_off);
if (IS_ERR(ret))
return ret;
Expand Down