Skip to content

Commit 42ed906

Browse files
committed
nettrace: fix compile error on arm64
Signed-off-by: Menglong Dong <imagedong@tencent.com>
1 parent 0dc16c1 commit 42ed906

3 files changed

Lines changed: 30 additions & 14 deletions

File tree

shared/bpf/skb_parse.h

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,19 @@ static try_inline int probe_parse_ip(void *ip, parse_ctx_t *ctx)
323323
return -1;
324324
}
325325

326+
static __always_inline u8 sk_get_protocol(struct sock *sk)
327+
{
328+
u32 flags = _(((u32 *)(&sk->__sk_flags_offset))[0]);
329+
u8 l4_proto;
330+
331+
#ifdef CONFIG_CPU_BIG_ENDIAN
332+
l4_proto = (flags << 8) >> 24;
333+
#else
334+
l4_proto = (flags << 16) >> 24;
335+
#endif
336+
return l4_proto;
337+
}
338+
326339
static try_inline int __probe_parse_sk(parse_ctx_t *ctx)
327340
{
328341
struct inet_connection_sock *icsk;
@@ -354,15 +367,17 @@ static try_inline int __probe_parse_sk(parse_ctx_t *ctx)
354367
if (FILTER_CHECK(ctx, l3_proto, l3_proto))
355368
goto err;
356369

370+
#ifdef COMPAT_MODE
357371
#ifdef BPF_FEAT_SK_PRPTOCOL_LEGACY
358-
u32 flags = _(((u32 *)(&sk->__sk_flags_offset))[0]);
359-
#ifdef CONFIG_CPU_BIG_ENDIAN
360-
l4_proto = (flags << 8) >> 24;
372+
l4_proto = sk_get_protocol(sk);
361373
#else
362-
l4_proto = (flags << 16) >> 24;
374+
l4_proto = _C(sk, sk_protocol);
363375
#endif
364376
#else
365-
l4_proto = _C(sk, sk_protocol);
377+
if (bpf_core_field_size(sk->sk_protocol) == 2)
378+
l4_proto = _C(sk, sk_protocol);
379+
else
380+
l4_proto = sk_get_protocol(sk);
366381
#endif
367382

368383
if (l4_proto == IPPROTO_IP)

shared/bpf/vmlinux_arm64.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8018,16 +8018,16 @@ struct sock {
80188018
unsigned int sk_gso_max_size;
80198019
gfp_t sk_allocation;
80208020
__u32 sk_txhash;
8021-
unsigned int __sk_flags_offset[0];
8022-
unsigned int sk_padding: 1;
8023-
unsigned int sk_kern_sock: 1;
8024-
unsigned int sk_no_check_tx: 1;
8025-
unsigned int sk_no_check_rx: 1;
8026-
unsigned int sk_userlocks: 4;
8027-
unsigned int sk_protocol: 8;
8028-
unsigned int sk_type: 16;
8029-
u16 sk_gso_max_segs;
8021+
unsigned int __sk_flags_offset[0];
8022+
u8 sk_padding: 1;
8023+
u8 sk_kern_sock: 1;
8024+
u8 sk_no_check_tx: 1;
8025+
u8 sk_no_check_rx: 1;
8026+
u8 sk_userlocks: 4;
80308027
u8 sk_pacing_shift;
8028+
u16 sk_type;
8029+
u16 sk_protocol;
8030+
u16 sk_gso_max_segs;
80318031
long unsigned int sk_lingertime;
80328032
struct proto *sk_prot_creator;
80338033
rwlock_t sk_callback_lock;

shared/bpf/vmlinux_x86.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8733,6 +8733,7 @@ struct sock {
87338733
unsigned int sk_gso_max_size;
87348734
gfp_t sk_allocation;
87358735
__u32 sk_txhash;
8736+
unsigned int __sk_flags_offset[0];
87368737
u8 sk_padding: 1;
87378738
u8 sk_kern_sock: 1;
87388739
u8 sk_no_check_tx: 1;

0 commit comments

Comments
 (0)