Skip to content

Commit

Permalink
bpf: Don't call lb{4,6}_extract_key() unless needed
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Chaignon <paul@cilium.io>
  • Loading branch information
pchaigno committed Mar 23, 2020
1 parent 5fd2c05 commit 00ce234
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions bpf/bpf_lxc.c
Expand Up @@ -60,7 +60,6 @@ static __always_inline int ipv6_l3_from_lxc(struct __ctx_buff *ctx,
#endif
int ret, verdict, l4_off, hdrlen;
struct csum_offset csum_off = {};
struct lb6_key key = {};
struct ct_state ct_state_new = {};
struct ct_state ct_state = {};
void *data, *data_end;
Expand All @@ -84,14 +83,6 @@ static __always_inline int ipv6_l3_from_lxc(struct __ctx_buff *ctx,

l4_off = l3_off + hdrlen;

ret = lb6_extract_key(ctx, tuple, l4_off, &key, &csum_off, CT_EGRESS);
if (IS_ERR(ret)) {
if (ret == DROP_UNKNOWN_L4)
goto skip_service_lookup;
else
return ret;
}

/*
* Check if the destination address is among the address that should be
* load balanced. This operation is performed before we go through the
Expand All @@ -103,6 +94,15 @@ static __always_inline int ipv6_l3_from_lxc(struct __ctx_buff *ctx,
# if !defined(ENABLE_HOST_SERVICES_FULL) || defined(ENABLE_EXTERNAL_IP)
{
struct lb6_service *svc;
struct lb6_key key = {};

ret = lb6_extract_key(ctx, tuple, l4_off, &key, &csum_off, CT_EGRESS);
if (IS_ERR(ret)) {
if (ret == DROP_UNKNOWN_L4)
goto skip_service_lookup;
else
return ret;
}

if ((svc = lb6_lookup_service(ctx, &key)) != NULL) {
ret = lb6_local(get_ct_map6(tuple), ctx, l3_off, l4_off,
Expand All @@ -112,10 +112,11 @@ static __always_inline int ipv6_l3_from_lxc(struct __ctx_buff *ctx,
hairpin_flow |= ct_state_new.loopback;
}
}

skip_service_lookup:
# endif /* !ENABLE_HOST_SERVICES_FULL || ENABLE_EXTERNAL_IP*/
#endif /* ENABLE_SERVICES */

skip_service_lookup:
/* The verifier wants to see this assignment here in case the above goto
* skip_service_lookup is hit. However, in the case the packet
* is _not_ TCP or UDP we should not be using proxy logic anyways. For
Expand Down Expand Up @@ -417,7 +418,6 @@ static __always_inline int handle_ipv4_from_lxc(struct __ctx_buff *ctx,
struct iphdr *ip4;
int ret, verdict, l3_off = ETH_HLEN, l4_off;
struct csum_offset csum_off = {};
struct lb4_key key = {};
struct ct_state ct_state_new = {};
struct ct_state ct_state = {};
__be32 orig_dip;
Expand All @@ -441,18 +441,20 @@ static __always_inline int handle_ipv4_from_lxc(struct __ctx_buff *ctx,

l4_off = l3_off + ipv4_hdrlen(ip4);

ret = lb4_extract_key(ctx, &tuple, l4_off, &key, &csum_off, CT_EGRESS);
if (IS_ERR(ret)) {
if (ret == DROP_UNKNOWN_L4)
goto skip_service_lookup;
else
return ret;
}

#ifdef ENABLE_SERVICES
# if !defined(ENABLE_HOST_SERVICES_FULL) || defined(ENABLE_EXTERNAL_IP)
{
struct lb4_service *svc;
struct lb4_key key = {};

ret = lb4_extract_key(ctx, &tuple, l4_off, &key, &csum_off,
CT_EGRESS);
if (IS_ERR(ret)) {
if (ret == DROP_UNKNOWN_L4)
goto skip_service_lookup;
else
return ret;
}

if ((svc = lb4_lookup_service(ctx, &key)) != NULL) {
ret = lb4_local(get_ct_map4(&tuple), ctx, l3_off, l4_off, &csum_off,
Expand All @@ -462,10 +464,11 @@ static __always_inline int handle_ipv4_from_lxc(struct __ctx_buff *ctx,
hairpin_flow |= ct_state_new.loopback;
}
}

skip_service_lookup:
# endif /* !ENABLE_HOST_SERVICES_FULL || ENABLE_EXTERNAL_IP */
#endif /* ENABLE_SERVICES */

skip_service_lookup:
/* The verifier wants to see this assignment here in case the above goto
* skip_service_lookup is hit. However, in the case the packet
* is _not_ TCP or UDP we should not be using proxy logic anyways. For
Expand Down

0 comments on commit 00ce234

Please sign in to comment.