/* Copyright (c) 2017 Facebook * * This program is free software; you can redistribute it and/or * modify it under the terms of version 2 of the GNU General Public * License as published by the Free Software Foundation.
*/
/* This program shows clang/llvm is able to generate code pattern * like: * _tcp_send_active_reset: * 0: bf 16 00 00 00 00 00 00 r6 = r1 * ...... * 335: b7 01 00 00 0f 00 00 00 r1 = 15 * 336: 05 00 48 00 00 00 00 00 goto 72 * * LBB0_3: * 337: b7 01 00 00 01 00 00 00 r1 = 1 * 338: 63 1a d0 ff 00 00 00 00 *(u32 *)(r10 - 48) = r1 * 408: b7 01 00 00 03 00 00 00 r1 = 3 * * LBB0_4: * 409: 71 a2 fe ff 00 00 00 00 r2 = *(u8 *)(r10 - 2) * 410: bf a7 00 00 00 00 00 00 r7 = r10 * 411: 07 07 00 00 b8 ff ff ff r7 += -72 * 412: bf 73 00 00 00 00 00 00 r3 = r7 * 413: 0f 13 00 00 00 00 00 00 r3 += r1 * 414: 73 23 2d 00 00 00 00 00 *(u8 *)(r3 + 45) = r2 * * From the above code snippet, the code generated by the compiler * is reasonable. The "r1" is assigned to different values in basic * blocks "_tcp_send_active_reset" and "LBB0_3", and used in "LBB0_4". * The verifier should be able to handle such code patterns.
*/ #include <string.h> #include <linux/bpf.h> #include <linux/ipv6.h> #include <linux/version.h> #include <sys/socket.h> #include <bpf/bpf_helpers.h>
/* This test case needs "sock" and "pt_regs" data structure. * Recursively, "sock" needs "sock_common" and "inet_sock". * However, this is a unit test case only for * verifier purpose without bpf program execution. * We can safely mock much simpler data structures, basically * only taking the necessary fields from kernel headers.
*/ typedef __u32 __bitwise __portpair; typedef __u64 __bitwise __addrpair;
/* Define various data structures for state recording. * Some fields are not used due to test simplification.
*/ enum tcp_estats_addrtype {
TCP_ESTATS_ADDRTYPE_IPV4 = 1,
TCP_ESTATS_ADDRTYPE_IPV6 = 2
};
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.