#ifndef __ASSEMBLY__ #ifndef __KERNEL__ #ifndef __EXPORTED_HEADERS__ #warning "Attempt to use kernel headers from user space, see http://kernelnewbies.org/KernelHeaders" #endif /* __EXPORTED_HEADERS__ */ #endif
$ cd bpf-test $ make ... LLVM ERROR: 'helper_test_init' label emitted multiple times to assembly file Makefile:69: recipe for target 'test_bpf_helper_init_kern.o' failed ...
root@ubuntu:~/bpftest/linux-blog-sample-code/bpf-test# make test make -C bpf test make[1]: Entering directory '/root/bpftest/linux-blog-sample-code/bpf-test/bpf' make[1]: 'test' is up to date. make[1]: Leaving directory '/root/bpftest/linux-blog-sample-code/bpf-test/bpf' make -C user test make[1]: Entering directory '/root/bpftest/linux-blog-sample-code/bpf-test/user' bash test_bpf_helper_run.sh before setup 0 maps not supported in current map section! Error fixing up map structure, incompatible struct bpf_elf_map used? Error fetching ELF ancillary data! Unable to load program setup ok could not find map bpf_helper_test_map: No such file or directory Makefile:63: recipe for target 'test' failed make[1]: *** [test] Error 1 make[1]: Leaving directory '/root/bpftest/linux-blog-sample-code/bpf-test/user' Makefile:69: recipe for target 'test-user' failed make: *** [test-user] Error 2
大致是说在bpf程序中找不到map。
测试命令执行的是以下命令
1 2 3
tc filter add dev veth1 ingress bpf da \ obj ../bpf/test_bpf_helper_init_kern.o \ sec helper_test_init
static int bpf_fetch_maps_end(struct bpf_elf_ctx *ctx) { struct bpf_elf_map fixup[ARRAY_SIZE(ctx->maps)] = {}; int i, sym_num = bpf_map_num_sym(ctx); __u8 *buff;
if (sym_num == 0 || sym_num > ARRAY_SIZE(ctx->maps)) { fprintf(stderr, "%u maps not supported in current map section!\n", sym_num); ... static int bpf_map_num_sym(struct bpf_elf_ctx *ctx) { int i, num = 0; GElf_Sym sym;
for (i = 0; i < ctx->sym_num; i++) { int type;
if (gelf_getsym(ctx->sym_tab, i, &sym) != &sym) continue;
type = GELF_ST_TYPE(sym.st_info); if (GELF_ST_BIND(sym.st_info) != STB_GLOBAL || (type != STT_NOTYPE && type != STT_OBJECT) || sym.st_shndx != ctx->sec_maps) continue; num++; }
一种调试文件格式,用于支持源码级调试功能。它通过树结构描述一个程序,每个节点有子节点或兄弟节点。节点可以表示类型、变量、或函数。 dwarf使用一系列的DIE(debugging information entries)表示源程序。每个DIE包含一个tag标签标识和一系列属性。每个或多个DIE组成一组标识程序中某个实体,或是程序或者变量等等。
def createKeyPair(type, bits): """ Create a public/private key pair. Arguments: type - Key type, must be one of TYPE_RSA and TYPE_DSA bits - Number of bits to use in the key Returns: The public/private key pair in a PKey object """ pkey = crypto.PKey() pkey.generate_key(type, bits) return pkey
def createCertRequest(pkey, digest="md5", **name): """ Create a certificate request. Arguments: pkey - The key to associate with the request digest - Digestion method to use for signing, default is md5 **name - The name of the subject of the request, possible arguments are: C - Country name ST - State or province name L - Locality name O - Organization name OU - Organizational unit name CN - Common name emailAddress - E-mail address Returns: The certificate request in an X509Req object """ req = crypto.X509Req() subj = req.get_subject()
for (key,value) in name.items(): setattr(subj, key, value)
def createCertificate(req, (issuerCert, issuerKey), serial, (notBefore, notAfter), digest="md5"): """ Generate a certificate given a certificate request. Arguments: req - Certificate reqeust to use issuerCert - The certificate of the issuer issuerKey - The private key of the issuer serial - Serial number for the certificate notBefore - Timestamp (relative to now) when the certificate starts being valid notAfter - Timestamp (relative to now) when the certificate stops being valid digest - Digest method to use for signing, default is md5 Returns: The signed certificate in an X509 object """ cert = crypto.X509() cert.set_serial_number(serial) cert.gmtime_adj_notBefore(notBefore) cert.gmtime_adj_notAfter(notAfter) cert.set_issuer(issuerCert.get_subject()) cert.set_subject(req.get_subject()) cert.set_pubkey(req.get_pubkey()) cert.sign(issuerKey, digest) return cert