• Alexei Starovoitov's avatar
    selftests/bpf: Add skb_pkt_end test · 9cc873e8
    Alexei Starovoitov authored
    Add a test that currently makes LLVM generate assembly code:
    
    $ llvm-objdump -S skb_pkt_end.o
    0000000000000000 <main_prog>:
    ; 	if (skb_shorter(skb, ETH_IPV4_TCP_SIZE))
           0:	61 12 50 00 00 00 00 00	r2 = *(u32 *)(r1 + 80)
           1:	61 14 4c 00 00 00 00 00	r4 = *(u32 *)(r1 + 76)
           2:	bf 43 00 00 00 00 00 00	r3 = r4
           3:	07 03 00 00 36 00 00 00	r3 += 54
           4:	b7 01 00 00 00 00 00 00	r1 = 0
           5:	2d 23 02 00 00 00 00 00	if r3 > r2 goto +2 <LBB0_2>
           6:	07 04 00 00 0e 00 00 00	r4 += 14
    ; 	if (skb_shorter(skb, ETH_IPV4_TCP_SIZE))
           7:	bf 41 00 00 00 00 00 00	r1 = r4
    0000000000000040 <LBB0_2>:
           8:	b4 00 00 00 ff ff ff ff	w0 = -1
    ; 	if (!(ip = get_iphdr(skb)))
           9:	2d 23 05 00 00 00 00 00	if r3 > r2 goto +5 <LBB0_6>
    ; 	proto = ip->protocol;
          10:	71 12 09 00 00 00 00 00	r2 = *(u8 *)(r1 + 9)
    ; 	if (proto != IPPROTO_TCP)
          11:	56 02 03 00 06 00 00 00	if w2 != 6 goto +3 <LBB0_6>
    ; 	if (tcp->dest != 0)
          12:	69 12 16 00 00 00 00 00	r2 = *(u16 *)(r1 + 22)
          13:	56 02 01 00 00 00 00 00	if w2 != 0 goto +1 <LBB0_6>
    ; 	return tcp->urg_ptr;
          14:	69 10 26 00 00 00 00 00	r0 = *(u16 *)(r1 + 38)
    0000000000000078 <LBB0_6>:
    ; }
          15:	95 00 00 00 00 00 00 00	exit
    Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
    Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
    Acked-by: default avatarJohn Fastabend <john.fastabend@gmail.com>
    Link: https://lore.kernel.org/bpf/20201111031213.25109-3-alexei.starovoitov@gmail.com
    9cc873e8
skb_pkt_end.c 1016 Bytes