Skip to content

Commit

Permalink
bpf: Make union v6addr const where possible
Browse files Browse the repository at this point in the history
This is mostly to clarify things for callers, but it will also slightly
simplify a subsequent commit.

Signed-off-by: Paul Chaignon <paul@cilium.io>
  • Loading branch information
pchaigno authored and joamaki committed Jun 8, 2022
1 parent 2d944e9 commit 0ea4341
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 15 deletions.
4 changes: 2 additions & 2 deletions bpf/bpf_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static __always_inline __maybe_unused bool is_v4_loopback(__be32 daddr)
return (daddr & bpf_htonl(0x7f000000)) == bpf_htonl(0x7f000000);
}

static __always_inline __maybe_unused bool is_v6_loopback(union v6addr *daddr)
static __always_inline __maybe_unused bool is_v6_loopback(const union v6addr *daddr)
{
/* Check for ::1/128, RFC4291. */
union v6addr loopback = { .addr[15] = 1, };
Expand Down Expand Up @@ -721,7 +721,7 @@ static __always_inline void ctx_set_v6_address(struct bpf_sock_addr *ctx,
}

static __always_inline __maybe_unused bool
sock6_skip_xlate(struct lb6_service *svc, union v6addr *address)
sock6_skip_xlate(struct lb6_service *svc, const union v6addr *address)
{
if (lb6_to_lb4_service(svc))
return true;
Expand Down
6 changes: 3 additions & 3 deletions bpf/lib/eps.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ __lookup_ip6_endpoint(const union v6addr *ip6)
}

static __always_inline __maybe_unused struct endpoint_info *
lookup_ip6_endpoint(struct ipv6hdr *ip6)
lookup_ip6_endpoint(const struct ipv6hdr *ip6)
{
return __lookup_ip6_endpoint((union v6addr *)&ip6->daddr);
}
Expand Down Expand Up @@ -116,8 +116,8 @@ _Pragma("unroll") \
return NULL; \
}
#ifdef IPCACHE6_PREFIXES
LPM_LOOKUP_FN(lookup_ip6_remote_endpoint, union v6addr *, IPCACHE6_PREFIXES,
IPCACHE_MAP, ipcache_lookup6)
LPM_LOOKUP_FN(lookup_ip6_remote_endpoint, const union v6addr *,
IPCACHE6_PREFIXES, IPCACHE_MAP, ipcache_lookup6)
#endif
#ifdef IPCACHE4_PREFIXES
LPM_LOOKUP_FN(lookup_ip4_remote_endpoint, __be32, IPCACHE4_PREFIXES,
Expand Down
4 changes: 2 additions & 2 deletions bpf/lib/ipv6.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ static __always_inline int ipv6_load_daddr(struct __ctx_buff *ctx, int off,
}

/* Assumes that caller fixes checksum csum_diff() and l4_csum_replace() */
static __always_inline int ipv6_store_daddr(struct __ctx_buff *ctx, __u8 *addr,
int off)
static __always_inline int
ipv6_store_daddr(struct __ctx_buff *ctx, const __u8 *addr, int off)
{
return ctx_store_bytes(ctx, off + offsetof(struct ipv6hdr, daddr), addr, 16, 0);
}
Expand Down
2 changes: 1 addition & 1 deletion bpf/lib/lb.h
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,7 @@ lb6_select_backend_id(struct __ctx_buff *ctx __maybe_unused,
#endif /* LB_SELECTION */

static __always_inline int lb6_xlate(struct __ctx_buff *ctx,
union v6addr *new_dst, __u8 nexthdr,
const union v6addr *new_dst, __u8 nexthdr,
int l3_off, int l4_off,
struct csum_offset *csum_off,
const struct lb6_key *key,
Expand Down
2 changes: 1 addition & 1 deletion bpf/lib/nat.h
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,7 @@ snat_v6_can_skip(const struct ipv6_nat_target *target,
}

static __always_inline __maybe_unused int snat_v6_create_dsr(struct __ctx_buff *ctx,
union v6addr *to_saddr,
const union v6addr *to_saddr,
__be16 to_sport)
{
void *data, *data_end;
Expand Down
8 changes: 4 additions & 4 deletions bpf/lib/nodeport.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ static __always_inline bool nodeport_uses_dsr6(const struct ipv6_ct_tuple *tuple
* then the helper function won't depend the dsr checks.
*/
static __always_inline bool snat_v6_needed(struct __ctx_buff *ctx,
union v6addr *addr)
const union v6addr *addr)
{
void *data, *data_end;
struct ipv6hdr *ip6;
Expand All @@ -203,7 +203,7 @@ static __always_inline bool snat_v6_needed(struct __ctx_buff *ctx,
}

static __always_inline int nodeport_nat_ipv6_fwd(struct __ctx_buff *ctx,
union v6addr *addr)
const union v6addr *addr)
{
struct ipv6_nat_target target = {
.min_port = NODEPORT_PORT_MIN_NAT,
Expand Down Expand Up @@ -253,7 +253,7 @@ static __always_inline void rss_gen_src6(union v6addr *src,

static __always_inline int dsr_set_ipip6(struct __ctx_buff *ctx,
const struct ipv6hdr *ip6,
union v6addr *backend_addr,
const union v6addr *backend_addr,
__be32 l4_hint, int *ohead)
{
__u16 payload_len = bpf_ntohs(ip6->payload_len) + sizeof(*ip6);
Expand Down Expand Up @@ -293,7 +293,7 @@ static __always_inline int dsr_set_ipip6(struct __ctx_buff *ctx,
#elif DSR_ENCAP_MODE == DSR_ENCAP_NONE
static __always_inline int dsr_set_ext6(struct __ctx_buff *ctx,
struct ipv6hdr *ip6,
union v6addr *svc_addr,
const union v6addr *svc_addr,
__be16 svc_port, int *ohead)
{
struct dsr_opt_v6 opt __align_stack_8 = {};
Expand Down
5 changes: 3 additions & 2 deletions bpf/lib/trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,9 @@ send_trace_notify4(struct __ctx_buff *ctx, enum trace_point obs_point,

static __always_inline void
send_trace_notify6(struct __ctx_buff *ctx, enum trace_point obs_point,
__u32 src, __u32 dst, union v6addr *orig_addr, __u16 dst_id,
__u32 ifindex, enum trace_reason reason, __u32 monitor)
__u32 src, __u32 dst, const union v6addr *orig_addr,
__u16 dst_id, __u32 ifindex, enum trace_reason reason,
__u32 monitor)
{
__u64 ctx_len = ctx_full_len(ctx);
__u64 cap_len = min_t(__u64, monitor ? : TRACE_PAYLOAD_LEN,
Expand Down

0 comments on commit 0ea4341

Please sign in to comment.