{"id":308320,"date":"2020-08-11T15:00:31","date_gmt":"2020-08-11T15:00:31","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=308320"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=308320","title":{"rendered":"BPF \u0434\u043b\u044f \u0441\u0430\u043c\u044b\u0445 \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u0445, \u0447\u0430\u0441\u0442\u044c \u043f\u0435\u0440\u0432\u0430\u044f: extended BPF"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/514736\/\">\n<p>\u0412 \u043d\u0430\u0447\u0430\u043b\u0435 \u0431\u044b\u043b\u0430 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u044f \u0438 \u043d\u0430\u0437\u044b\u0432\u0430\u043b\u0430\u0441\u044c \u043e\u043d\u0430 BPF. \u041c\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438 \u043d\u0430 \u043d\u0435\u0435 \u0432 <a href=\"https:\/\/habr.com\/ru\/post\/493880\/\">\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439<\/a>, \u0432\u0435\u0442\u0445\u043e\u0437\u0430\u0432\u0435\u0442\u043d\u043e\u0439, \u0441\u0442\u0430\u0442\u044c\u0435 \u044d\u0442\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430. \u0412 2013 \u0433\u043e\u0434\u0443 \u0443\u0441\u0438\u043b\u0438\u044f\u043c\u0438 \u0410\u043b\u0435\u043a\u0441\u0435\u044f \u0421\u0442\u0430\u0440\u043e\u0432\u043e\u0439\u0442\u043e\u0432\u0430 (Alexei Starovoitov) \u0438 \u0414\u0430\u043d\u0438\u044d\u043b\u044f \u0411\u043e\u0440\u043a\u043c\u0430\u043d\u0430 (Daniel Borkman) \u0431\u044b\u043b\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u0430 \u0438 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0430 \u0432 \u044f\u0434\u0440\u043e Linux \u0435\u0435 \u0443\u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f, \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u043f\u043e\u0434 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 64-\u0431\u0438\u0442\u043d\u044b\u0435 \u043c\u0430\u0448\u0438\u043d\u044b. \u042d\u0442\u0430 \u043d\u043e\u0432\u0430\u044f \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u044f \u043d\u0435\u0434\u043e\u043b\u0433\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043d\u043e\u0441\u0438\u043b\u0430 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 Internal BPF, \u0437\u0430\u0442\u0435\u043c \u0431\u044b\u043b\u0430 \u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0430 \u0432 Extended BPF, \u0430 \u0442\u0435\u043f\u0435\u0440\u044c, \u043f\u043e \u043f\u0440\u043e\u0448\u0435\u0441\u0442\u0432\u0438\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043b\u0435\u0442, \u0432\u0441\u0435 \u0435\u0435 \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u043f\u0440\u043e\u0441\u0442\u043e BPF.<\/p>\n<p>  <\/p>\n<p>\u0413\u0440\u0443\u0431\u043e \u0433\u043e\u0432\u043e\u0440\u044f, BPF \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u0434, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c, \u0432 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435 \u044f\u0434\u0440\u0430 Linux \u0438 \u043d\u043e\u0432\u0430\u044f \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u043e\u043a\u0430\u0437\u0430\u043b\u0430\u0441\u044c \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0443\u0434\u0430\u0447\u043d\u043e\u0439, \u0447\u0442\u043e \u043d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0435\u0449\u0435 \u0441 \u0434\u0435\u0441\u044f\u0442\u043e\u043a \u0441\u0442\u0430\u0442\u0435\u0439, \u0447\u0442\u043e\u0431\u044b \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0432\u0441\u0435 \u0435\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f. (<s>\u0415\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0441 \u0447\u0435\u043c \u043d\u0435 \u0441\u043f\u0440\u0430\u0432\u0438\u043b\u0438\u0441\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438, \u043a\u0430\u043a \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u0438\u0434\u0435\u0442\u044c \u043d\u0430 \u043a\u043f\u0434\u0432 \u043d\u0438\u0436\u0435, \u044d\u0442\u043e \u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435\u043c \u043f\u0440\u0438\u043b\u0438\u0447\u043d\u043e\u0433\u043e \u043b\u043e\u0433\u043e\u0442\u0438\u043f\u0430.<\/s>)<\/p>\n<p>  <\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0439 \u043c\u0430\u0448\u0438\u043d\u044b BPF, \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u044f\u0434\u0440\u0430 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 BPF, \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043a\u0440\u0430\u0442\u043a\u0438\u0439, \u043e\u0447\u0435\u043d\u044c \u043a\u0440\u0430\u0442\u043a\u0438\u0439, \u043e\u0431\u0437\u043e\u0440 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439, \u0442.\u0435. \u0432\u0441\u0451 \u0442\u043e, \u0447\u0442\u043e \u043d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u0434\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u0433\u043b\u0443\u0431\u043e\u043a\u043e\u0433\u043e \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0439 BPF.<br \/>  <a href=\"https:\/\/habr.com\/ru\/post\/514736\/\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/eb\/cx\/cq\/ebcxcqjpcedlop51jeh-bvbhyfy.png\"><\/a><\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<h2>\u041a\u0440\u0430\u0442\u043a\u043e\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435 \u0441\u0442\u0430\u0442\u044c\u0438<\/h2>\n<p>  <\/p>\n<p><a href=\"https:\/\/habr.com\/ru\/post\/514736#introduction-to-bpf\">\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0432 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443 BPF.<\/a> \u0412\u043d\u0430\u0447\u0430\u043b\u0435 \u043c\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443 BPF \u0441 \u0432\u044b\u0441\u043e\u0442\u044b \u043f\u0442\u0438\u0447\u044c\u0435\u0433\u043e \u043f\u043e\u043b\u0435\u0442\u0430 \u0438 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0438\u043c \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b.<\/p>\n<p>  <\/p>\n<p><a href=\"#bpf-virtual-machine\">\u0420\u0435\u0433\u0438\u0441\u0442\u0440\u044b \u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u043a\u043e\u043c\u0430\u043d\u0434 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0439 \u043c\u0430\u0448\u0438\u043d\u044b BPF.<\/a> \u0423\u0436\u0435 \u0438\u043c\u0435\u044f \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e\u0431 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0435 \u0432 \u0446\u0435\u043b\u043e\u043c, \u043c\u044b \u043e\u043f\u0438\u0448\u0435\u043c \u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0439 \u043c\u0430\u0448\u0438\u043d\u044b BPF.<\/p>\n<p>  <\/p>\n<p><a href=\"#objects-lifetime\">\u0416\u0438\u0437\u043d\u0435\u043d\u043d\u044b\u0439 \u0446\u0438\u043a\u043b \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 BPF, \u0444\u0430\u0439\u043b\u043e\u0432\u0430\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0430 bpffs.<\/a> \u0412 \u044d\u0442\u043e\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u043c\u044b \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u0438\u0441\u0442\u0430\u043b\u044c\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u044b\u0439 \u0446\u0438\u043a\u043b \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 BPF \u2014 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c \u0438 \u043c\u0430\u043f\u043e\u0432.<\/p>\n<p>  <\/p>\n<p><a href=\"#bpf-syscall\">\u0423\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 bpf.<\/a> \u0418\u043c\u0435\u044f \u0443\u0436\u0435 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u043c\u044b, \u043d\u0430\u043a\u043e\u043d\u0435\u0446, \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0442\u043e, \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438 \u0438\u0437 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 \u2014 <code>bpf(2)<\/code>.<\/p>\n<p>  <\/p>\n<p><a href=\"#hello-libbpf\"><code>\u041f\u0438\u0448\u0435\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b BPF \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e libbpf<\/code>.<\/a> \u041f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u043c\u043e\u0436\u043d\u043e. \u041d\u043e \u0441\u043b\u043e\u0436\u043d\u043e. \u0414\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u0440\u0435\u0430\u043b\u0438\u0441\u0442\u0438\u0447\u043d\u043e\u0433\u043e \u0441\u0446\u0435\u043d\u0430\u0440\u0438\u044f \u044f\u0434\u0435\u0440\u043d\u044b\u043c\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0430\u043c\u0438 \u0431\u044b\u043b\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 <code>libbpf<\/code>. \u041c\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0438\u0439 \u0441\u043a\u0435\u043b\u0435\u0442 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f BPF, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445.<\/p>\n<p>  <\/p>\n<p><a href=\"#kernel-helpers\">Kernel Helpers.<\/a> \u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0443\u0437\u043d\u0430\u0435\u043c \u043a\u0430\u043a \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b BPF \u043c\u043e\u0433\u0443\u0442 \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u043a \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c-\u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a\u0430\u043c \u044f\u0434\u0440\u0430 \u2014\u00a0\u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0443, \u043a\u043e\u0442\u043e\u0440\u044b\u0439, \u043d\u0430\u0440\u044f\u0434\u0443 \u0441 \u043c\u0430\u043f\u0430\u043c\u0438, \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0438\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043d\u043e\u0432\u043e\u0433\u043e BPF \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u043c.<\/p>\n<p>  <\/p>\n<p><a href=\"#maps-from-progs\">\u0414\u043e\u0441\u0442\u0443\u043f \u043a maps \u0438\u0437 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c BPF.<\/a> \u041a \u044d\u0442\u043e\u043c\u0443 \u043c\u043e\u043c\u0435\u043d\u0442\u0443 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0437\u043d\u0430\u0442\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c \u043a\u0430\u043a \u0438\u043c\u0435\u043d\u043d\u043e \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0435 \u043c\u0430\u043f\u044b. \u0418 \u0434\u0430\u0436\u0435 \u043e\u0434\u043d\u0438\u043c \u0433\u043b\u0430\u0437\u043a\u043e\u043c \u0437\u0430\u0433\u043b\u044f\u043d\u0435\u043c \u0432 \u0432\u0435\u043b\u0438\u043a\u0438\u0439 \u0438 \u043c\u043e\u0433\u0443\u0447\u0438\u0439 verifier.<\/p>\n<p>  <\/p>\n<p><a href=\"#tools\">\u0421\u0440\u0435\u0434\u0441\u0442\u0432\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438.<\/a> \u0421\u043f\u0440\u0430\u0432\u043e\u0447\u043d\u044b\u0439 \u0440\u0430\u0437\u0434\u0435\u043b \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u0442\u0440\u0435\u0431\u0443\u0435\u043c\u044b\u0435 \u0443\u0442\u0438\u043b\u0438\u0442\u044b \u0438 \u044f\u0434\u0440\u043e \u0434\u043b\u044f \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u0432.<\/p>\n<p>  <\/p>\n<p><a href=\"#this-is-the-end\">\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435.<\/a> \u0412 \u043a\u043e\u043d\u0446\u0435 \u0441\u0442\u0430\u0442\u044c\u0438 \u0442\u0435, \u043a\u0442\u043e \u0434\u043e\u0442\u0443\u0434\u0430 \u0434\u043e\u0447\u0438\u0442\u0430\u0435\u0442, \u043d\u0430\u0439\u0434\u0443\u0442 \u043c\u043e\u0442\u0438\u0432\u0438\u0440\u0443\u044e\u0449\u0438\u0435 \u0441\u043b\u043e\u0432\u0430 \u0438 \u043a\u0440\u0430\u0442\u043a\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0441\u0442\u0430\u0442\u044c\u044f\u0445. \u041c\u044b \u0442\u0430\u043a\u0436\u0435 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0438\u043c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0441\u0441\u044b\u043b\u043e\u043a \u0434\u043b\u044f \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0442\u0435\u0445, \u0443 \u043a\u043e\u0433\u043e \u043d\u0435\u0442 \u0436\u0435\u043b\u0430\u043d\u0438\u044f \u0438\u043b\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0436\u0434\u0430\u0442\u044c \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<h2 id=\"introduction-to-bpf\">\u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0432 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443 BPF<\/h2>\n<p>  <\/p>\n<p>\u041f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c \u043a\u0430\u043a \u043d\u0430\u0447\u0430\u0442\u044c \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443 BPF \u043c\u044b \u0432 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0440\u0430\u0437 (\u043e\u0439 \u043b\u0438) \u0441\u043e\u0448\u043b\u0435\u043c\u0441\u044f \u043d\u0430 <a href=\"https:\/\/habr.com\/ru\/post\/493880\/\">\u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 BPF<\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u044b\u043b \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d \u043a\u0430\u043a \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u0435 RISC \u043c\u0430\u0448\u0438\u043d \u0438 \u0440\u0435\u0448\u0430\u043b \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0439 \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u043f\u0430\u043a\u0435\u0442\u043e\u0432. \u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0430\u0441\u044c \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0443\u0434\u0430\u0447\u043d\u043e\u0439, \u0447\u0442\u043e, \u0440\u043e\u0434\u0438\u0432\u0448\u0438\u0441\u044c \u0432 \u043b\u0438\u0445\u0438\u0435 \u0434\u0435\u0432\u044f\u043d\u043e\u0441\u0442\u044b\u0435 \u0432 Berkeley UNIX, \u043e\u043d\u0430 \u0431\u044b\u043b\u0430 \u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0441\u0438\u0441\u0442\u0435\u043c, \u0434\u043e\u0436\u0438\u043b\u0430 \u0434\u043e \u0431\u0435\u0437\u0443\u043c\u043d\u044b\u0445 \u0434\u0432\u0430\u0434\u0446\u0430\u0442\u044b\u0445 \u0438 \u0434\u043e \u0441\u0438\u0445 \u043f\u043e\u0440 \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u043d\u043e\u0432\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<p>\u041d\u043e\u0432\u044b\u0439 BPF \u0431\u044b\u043b \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d \u043a\u0430\u043a \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u043f\u043e\u0432\u0441\u0435\u043c\u0435\u0441\u0442\u043d\u043e\u0435 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0435\u043d\u0438\u0435 64-\u0431\u0438\u0442\u043d\u044b\u0445 \u043c\u0430\u0448\u0438\u043d, \u043e\u0431\u043b\u0430\u0447\u043d\u044b\u0445 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u0438 \u0432\u043e\u0437\u0440\u043e\u0441\u0448\u0438\u0445 \u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u0435\u0439 \u0432 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430\u0445 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f SDN (<b>S<\/b>oftware-<b>d<\/b>efined <b>n<\/b>etworking). \u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u0439 \u0441\u0435\u0442\u0435\u0432\u044b\u043c\u0438 \u0438\u043d\u0436\u0435\u043d\u0435\u0440\u0430\u043c\u0438 \u044f\u0434\u0440\u0430 \u043a\u0430\u043a \u0443\u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u0437\u0430\u043c\u0435\u043d\u0430 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e BPF, \u043d\u043e\u0432\u044b\u0439 BPF \u0431\u0443\u043a\u0432\u0430\u043b\u044c\u043d\u043e \u0447\u0435\u0440\u0435\u0437 \u043f\u043e\u043b\u0433\u043e\u0434\u0430 \u043d\u0430\u0448\u0435\u043b \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 \u043d\u0435\u043b\u0435\u0433\u043a\u043e\u043c \u0434\u0435\u043b\u0435 \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u043a\u0438 Linux \u0441\u0438\u0441\u0442\u0435\u043c, \u0430 \u0441\u0435\u0439\u0447\u0430\u0441, \u0447\u0435\u0440\u0435\u0437 \u0448\u0435\u0441\u0442\u044c \u043b\u0435\u0442 \u043f\u043e\u0441\u043b\u0435 \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u044f, \u043d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0446\u0435\u043b\u0430\u044f, \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f, \u0441\u0442\u0430\u0442\u044c\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0438\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0435 \u0442\u0438\u043f\u044b \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c.<\/p>\n<p>  <\/p>\n<h3>\u0412\u0435\u0421\u0451\u041b\u044b\u0415 \u041a\u0430\u0420\u0442\u0418\u043d\u041a\u0438<\/h3>\n<p>  <\/p>\n<p>\u0412 \u0441\u0432\u043e\u0435\u0439 \u043e\u0441\u043d\u043e\u0432\u0435 BPF \u2014 \u044d\u0442\u043e \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u0430\u044f \u043c\u0430\u0448\u0438\u043d\u0430-\u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u0430, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0430\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u00ab\u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0439\u00bb \u043a\u043e\u0434 \u0432 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435 \u044f\u0434\u0440\u0430 \u0431\u0435\u0437 \u0443\u0449\u0435\u0440\u0431\u0430 \u0434\u043b\u044f \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u0438. \u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b BPF \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u0432 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u044e\u0442\u0441\u044f \u0432 \u044f\u0434\u0440\u043e \u0438 \u043f\u043e\u0434\u0441\u043e\u0435\u0434\u0438\u043d\u044f\u044e\u0442\u0441\u044f \u043a \u043a\u0430\u043a\u043e\u043c\u0443-\u043d\u0438\u0431\u0443\u0434\u044c \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0443 \u0441\u043e\u0431\u044b\u0442\u0438\u0439. \u0421\u043e\u0431\u044b\u0442\u0438\u0435\u043c \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043e\u0441\u0442\u0430\u0432\u043a\u0430 \u043f\u0430\u043a\u0435\u0442\u0430 \u043d\u0430 \u0441\u0435\u0442\u0435\u0432\u043e\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u0437\u0430\u043f\u0443\u0441\u043a \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u044f\u0434\u0440\u0430, \u0438 \u0442.\u043f. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0430\u043a\u0435\u0442\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 BPF \u0431\u0443\u0434\u0443\u0442 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0434\u0430\u043d\u043d\u044b\u0435 \u0438 \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0430\u043a\u0435\u0442\u0430 (\u043d\u0430 \u0447\u0442\u0435\u043d\u0438\u0435 \u0438, \u043c\u043e\u0436\u0435\u0442, \u043d\u0430 \u0437\u0430\u043f\u0438\u0441\u044c, \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u0438\u043f\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b), \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u044f\u0434\u0440\u0430 \u2014 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u0432\u043a\u043b\u044e\u0447\u0430\u044f \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u043d\u0430 \u043f\u0430\u043c\u044f\u0442\u044c \u044f\u0434\u0440\u0430, \u0438 \u0442.\u043f.<\/p>\n<p>  <\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u044d\u0442\u043e\u0442 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435. \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0435\u043c \u043f\u0440\u043e \u043f\u0435\u0440\u0432\u043e\u0435 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e BPF, \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043f\u0438\u0441\u0430\u043b\u0438\u0441\u044c \u043d\u0430 \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440\u0435. \u0412 \u043d\u043e\u0432\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u0431\u044b\u043b\u0430 \u0434\u043e\u043f\u043e\u043b\u043d\u0435\u043d\u0430 \u0442\u0430\u043a, \u0447\u0442\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0441\u0442\u0430\u043b\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0430 \u044f\u0437\u044b\u043a\u0430\u0445 \u0432\u044b\u0441\u043e\u043a\u043e\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f, \u0432 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u043d\u0430 C. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0431\u044b\u043b \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d \u0431\u0430\u043a\u0435\u043d\u0434 \u0434\u043b\u044f llvm, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0439 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0431\u0430\u0439\u0442-\u043a\u043e\u0434 \u0434\u043b\u044f \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b BPF.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/0p\/x2\/95\/0px295mnsbzwd9pmkqbtswwk-nc.png\">  <\/p>\n<p>  <\/p>\n<p>\u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 BPF \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u043b\u0430\u0441\u044c, \u0432 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u043d\u0430 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043c\u0430\u0448\u0438\u043d\u0430\u0445. \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435, \u0431\u0430\u0439\u0442-\u043a\u043e\u0434 BPF, \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0432 \u044f\u0434\u0440\u043e \u0442\u0440\u0430\u043d\u0441\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432 \u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u043f\u043e\u0434 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c JIT compiler (<b>J<\/b>ust <b>I<\/b>n <b>T<\/b>ime). \u0414\u0430\u043b\u0435\u0435, \u0435\u0441\u043b\u0438 \u0432\u044b \u043f\u043e\u043c\u043d\u0438\u0442\u0435, \u0432 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u043c BPF \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u043b\u0430\u0441\u044c \u0432 \u044f\u0434\u0440\u043e \u0438 \u043f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u044f\u043b\u0430\u0441\u044c \u043a \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0443 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0430\u0442\u043e\u043c\u0430\u0440\u043d\u043e \u2014 \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430. \u0412 \u043d\u043e\u0432\u043e\u0439 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0435 \u044d\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 \u0434\u0432\u0430 \u044d\u0442\u0430\u043f\u0430 \u2014 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043a\u043e\u0434 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442\u0441\u044f \u0432 \u044f\u0434\u0440\u043e \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 <code>bpf(2)<\/code>, \u0430 \u0437\u0430\u0442\u0435\u043c, \u043f\u043e\u0437\u0434\u043d\u0435\u0435, \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u043e\u0432, \u0440\u0430\u0437\u043d\u044b\u0445 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u0438\u043f\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043f\u043e\u0434\u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0435\u0442\u0441\u044f (attaches) \u043a \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0443 \u0441\u043e\u0431\u044b\u0442\u0438\u0439.<\/p>\n<p>  <\/p>\n<p>\u0422\u0443\u0442 \u0443 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044f \u043c\u043e\u0436\u0435\u0442 \u0432\u043e\u0437\u043d\u0438\u043a\u043d\u0443\u0442\u044c \u0432\u043e\u043f\u0440\u043e\u0441: \u0430 \u0447\u0442\u043e, \u0442\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e? \u041a\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0442\u0430\u043a\u043e\u0433\u043e \u043a\u043e\u0434\u0430? \u0411\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043d\u0430\u043c \u044d\u0442\u0430\u043f\u043e\u043c \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c BPF \u043f\u043e\u0434 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c \u0432\u0435\u0440\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 (\u043f\u043e-\u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u0438 \u044d\u0442\u043e\u0442 \u044d\u0442\u0430\u043f \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f verifier \u0438 \u044f \u0434\u0430\u043b\u044c\u0448\u0435 \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0430\u043d\u0433\u043b\u0438\u0439\u0441\u043a\u043e\u0435 \u0441\u043b\u043e\u0432\u043e):<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/l8\/il\/pk\/l8ilpkcnogyoaf73qwsljfvevjo.png\">  <\/p>\n<p>  <\/p>\n<p>Verifier \u2014 \u044d\u0442\u043e \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0430\u043d\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043d\u0435 \u043d\u0430\u0440\u0443\u0448\u0438\u0442 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0445\u043e\u0434 \u0440\u0430\u0431\u043e\u0442\u044b \u044f\u0434\u0440\u0430. \u042d\u0442\u043e, \u043a\u0441\u0442\u0430\u0442\u0438, \u043d\u0435 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0432\u043c\u0435\u0448\u0430\u0442\u044c\u0441\u044f \u0432 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u2014 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b BPF, \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u0438\u043f\u0430, \u043c\u043e\u0433\u0443\u0442 \u0447\u0438\u0442\u0430\u0442\u044c \u0438 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0443\u0447\u0430\u0441\u0442\u043a\u0438 \u043f\u0430\u043c\u044f\u0442\u0438 \u044f\u0434\u0440\u0430, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u043e\u0431\u0440\u0435\u0437\u0430\u0442\u044c, \u0434\u043e\u043f\u043e\u043b\u043d\u044f\u0442\u044c, \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0438 \u0434\u0430\u0436\u0435 \u043f\u0435\u0440\u0435\u0441\u044b\u043b\u0430\u0442\u044c \u0441\u0435\u0442\u0435\u0432\u044b\u0435 \u043f\u0430\u043a\u0435\u0442\u044b. Verifier \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u043e\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b BPF \u044f\u0434\u0440\u043e \u043d\u0435 \u0441\u0432\u0430\u043b\u0438\u0442\u0441\u044f \u0438 \u0447\u0442\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430, \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043f\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u0430\u043c \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u043d\u0430 \u0437\u0430\u043f\u0438\u0441\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0441\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u043f\u0430\u043a\u0435\u0442\u0430, \u043d\u0435 \u0441\u043c\u043e\u0436\u0435\u0442 \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0430\u043c\u044f\u0442\u044c \u044f\u0434\u0440\u0430 \u0432\u043d\u0435 \u043f\u0430\u043a\u0435\u0442\u0430. \u0427\u0443\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043c\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 verifier \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435, \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043f\u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u043c\u0441\u044f \u0441\u043e \u0432\u0441\u0435\u043c\u0438 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c\u0438 BPF.<\/p>\n<p>  <\/p>\n<p>\u0418\u0442\u0430\u043a, \u0447\u0442\u043e \u043c\u044b \u0443\u0437\u043d\u0430\u043b\u0438 \u043a \u044d\u0442\u043e\u043c\u0443 \u043c\u043e\u043c\u0435\u043d\u0442\u0443? \u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043f\u0438\u0448\u0435\u0442 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 C, \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442 \u0435\u0435 \u0432 \u044f\u0434\u0440\u043e \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 <code>bpf(2)<\/code>, \u0433\u0434\u0435 \u043e\u043d\u0430 \u043f\u0440\u043e\u0445\u043e\u0434\u0438\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043d\u0430 verifier \u0438 \u0442\u0440\u0430\u043d\u0441\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432 \u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u0431\u0430\u0439\u0442\u043a\u043e\u0434. \u0417\u0430\u0442\u0435\u043c \u0442\u043e\u0442 \u0436\u0435 \u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043f\u043e\u0434\u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0435\u0442 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u043a \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0443 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0438 \u043e\u043d\u0430 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f. \u0420\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0438 \u043f\u043e\u0434\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u043d\u0443\u0436\u043d\u043e \u043f\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c \u043f\u0440\u0438\u0447\u0438\u043d\u0430\u043c. \u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u0437\u0430\u043f\u0443\u0441\u043a verifier \u2014 \u044d\u0442\u043e \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043e\u0440\u043e\u0433\u043e \u0438, \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u044f \u043e\u0434\u043d\u0443 \u0438 \u0442\u0443 \u0436\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437, \u043c\u044b \u0442\u0440\u0430\u0442\u0438\u043c \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u043d\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0432\u043f\u0443\u0441\u0442\u0443\u044e. \u0412\u043e-\u0432\u0442\u043e\u0440\u044b\u0445, \u0442\u043e, \u043a\u0430\u043a \u0438\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u0434\u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430, \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0435\u0435 \u0442\u0438\u043f\u0430 \u0438 \u043e\u0434\u0438\u043d \u00ab\u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u0439\u00bb \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u043d\u044b\u0439 \u0433\u043e\u0434 \u043d\u0430\u0437\u0430\u0434 \u043c\u043e\u0436\u0435\u0442 \u043d\u0435 \u043f\u043e\u0434\u043e\u0439\u0442\u0438 \u0434\u043b\u044f \u043d\u043e\u0432\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c. (\u0425\u043e\u0442\u044f \u0441\u0435\u0439\u0447\u0430\u0441, \u043a\u043e\u0433\u0434\u0430 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0431\u043e\u043b\u0435\u0435 \u0437\u0440\u0435\u043b\u043e\u0439, \u0435\u0441\u0442\u044c \u0438\u0434\u0435\u044f \u0443\u043d\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 <code>libbpf<\/code>.)<\/p>\n<p>  <\/p>\n<p>\u0412\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044c \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u043c\u044b \u0435\u0449\u0435 \u043d\u0435 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0438 \u0441 \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0430\u043c\u0438. \u0418 \u043f\u0440\u0430\u0432\u0434\u0430, \u0432\u0441\u0435 \u0441\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0435 \u0432\u044b\u0448\u0435 \u043d\u0435 \u043e\u0431\u044a\u044f\u0441\u043d\u044f\u0435\u0442, \u0447\u0435\u043c BPF \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0438\u0430\u043b\u044c\u043d\u043e \u043c\u0435\u043d\u044f\u0435\u0442 \u043a\u0430\u0440\u0442\u0438\u043d\u0443 \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u043c BPF. \u0414\u0432\u0430 \u043d\u043e\u0432\u0448\u0435\u0441\u0442\u0432\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u044e\u0442 \u0433\u0440\u0430\u043d\u0438\u0446\u044b \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043c\u043e\u0441\u0442\u0438 \u2014 \u044d\u0442\u043e \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u043c\u0443\u044e \u043f\u0430\u043c\u044f\u0442\u044c \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438-\u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a\u0438 \u044f\u0434\u0440\u0430 (kernel helpers). \u0412 BPF \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u043c\u0430\u044f \u043f\u0430\u043c\u044f\u0442\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u0430 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0445 maps \u2014 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u043c\u044b\u0445 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u043c API. \u0422\u0430\u043a\u043e\u0435 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043e\u043d\u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438, \u043d\u0430\u0432\u0435\u0440\u043d\u043e\u0435, \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u043f\u0435\u0440\u0432\u044b\u043c \u043f\u043e\u044f\u0432\u0438\u0432\u0448\u0438\u043c\u0441\u044f \u0442\u0438\u043f\u043e\u043c map \u0431\u044b\u043b\u0430 \u0445\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u0430. \u0414\u0430\u043b\u044c\u0448\u0435 \u043f\u043e\u044f\u0432\u0438\u043b\u0438\u0441\u044c \u043c\u0430\u0441\u0441\u0438\u0432\u044b, \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0435 (per-CPU) \u0445\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0438 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u044b, \u0434\u0435\u0440\u0435\u0432\u044c\u044f \u043f\u043e\u0438\u0441\u043a\u0430, \u043c\u0430\u043f\u044b, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u043d\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b BPF \u0438 \u043c\u043d\u043e\u0433\u043e\u0435 \u0434\u0440\u0443\u0433\u043e\u0435. \u041d\u0430\u043c \u0441\u0435\u0439\u0447\u0430\u0441 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0435\u043d \u0442\u043e\u0442 \u0444\u0430\u043a\u0442, \u0447\u0442\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b BPF \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u0432\u044b\u0437\u043e\u0432\u0430\u043c\u0438 \u0438 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0442\u044c \u0435\u0433\u043e \u0441 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430\u043c\u0438 \u0438 \u0441 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.<\/p>\n<p>  <\/p>\n<p>\u0414\u043e\u0441\u0442\u0443\u043f \u043a maps \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u0437 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0445 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 <code>bpf(2)<\/code>, \u0430 \u0438\u0437 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c BPF, \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0445 \u0432 \u044f\u0434\u0440\u0435 \u2014 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0439-\u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a\u043e\u0432. \u0411\u043e\u043b\u0435\u0435 \u0442\u043e\u0433\u043e, helpers \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043c\u0430\u043f\u0430\u043c\u0438, \u043d\u043e \u0438 \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0434\u0440\u0443\u0433\u0438\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u043c \u044f\u0434\u0440\u0430. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b BPF \u043c\u043e\u0433\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u0438-\u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a\u0438 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u043a\u0435\u0442\u043e\u0432 \u043d\u0430 \u0434\u0440\u0443\u0433\u0438\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b, \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u043f\u043e\u0434\u0441\u0438\u0441\u0442\u0435\u043c\u044b perf, \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430\u043c \u044f\u0434\u0440\u0430 \u0438 \u0442.\u043f.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/1w\/jo\/sq\/1wjosqevjc0ghneknvv56jdc4fo.png\">  <\/p>\n<p>  <\/p>\n<p>\u0418\u0442\u043e\u0433\u043e, BPF \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0439, \u0442.\u0435., \u043f\u0440\u043e\u0448\u0435\u0434\u0448\u0438\u0439 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043d\u0430 verifier, \u043a\u043e\u0434 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e \u044f\u0434\u0440\u0430. \u042d\u0442\u043e\u0442 \u043a\u043e\u0434 \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435 \u043c\u0435\u0436\u0434\u0443 \u0432\u044b\u0437\u043e\u0432\u0430\u043c\u0438 \u0438 \u043e\u0431\u043c\u0435\u043d\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0441 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0438\u043c\u0435\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u043d\u044b\u043c \u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u0442\u0438\u043f\u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c \u043f\u043e\u0434\u0441\u0438\u0441\u0442\u0435\u043c\u0430\u043c \u044f\u0434\u0440\u0430.<\/p>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u0443\u0436\u0435 \u043f\u043e\u0445\u043e\u0436\u0435 \u043d\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0435 \u043c\u043e\u0434\u0443\u043b\u044f\u043c\u0438 \u044f\u0434\u0440\u0430, \u043f\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044e \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u0443 BPF \u0435\u0441\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u0430 (\u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0442\u044c \u043c\u043e\u0436\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0445\u043e\u0436\u0438\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u043a\u0443 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u2014 \u043d\u0430 BPF \u043d\u0435\u043b\u044c\u0437\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0439 \u0434\u0440\u0430\u0439\u0432\u0435\u0440). \u041c\u043e\u0436\u043d\u043e \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u043d\u0438\u0437\u043a\u0438\u0439 \u043f\u043e\u0440\u043e\u0433 \u0432\u0445\u043e\u0434\u0430 (\u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0443\u0442\u0438\u043b\u0438\u0442\u044b, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0435 BPF \u043d\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u044e\u0442 \u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u043d\u0430\u0432\u044b\u043a\u043e\u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u044f\u0434\u0440\u0430, \u0434\u0430 \u0438 \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0430\u0432\u044b\u043a\u043e\u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f), \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0441\u0442\u044c \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f (\u043f\u043e\u0434\u043d\u0438\u043c\u0438\u0442\u0435 \u0440\u0443\u043a\u0443 \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445 \u0442\u0435, \u043a\u0442\u043e \u043d\u0435 \u043b\u043e\u043c\u0430\u043b \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u043f\u0440\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0438 \u0438\u043b\u0438 \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u043c\u043e\u0434\u0443\u043b\u0435\u0439), \u0430\u0442\u043e\u043c\u0430\u0440\u043d\u043e\u0441\u0442\u044c \u2014 \u043f\u0440\u0438 \u043f\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0435 \u043c\u043e\u0434\u0443\u043b\u0435\u0439 \u0435\u0441\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u044f, \u0430 \u043f\u043e\u0434\u0441\u0438\u0441\u0442\u0435\u043c\u0430 BPF \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442, \u0447\u0442\u043e \u043d\u0438 \u043e\u0434\u043d\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u043f\u0443\u0449\u0435\u043d\u043e (\u0441\u043f\u0440\u0430\u0432\u0435\u0434\u043b\u0438\u0432\u043e\u0441\u0442\u0438 \u0440\u0430\u0434\u0438, \u044d\u0442\u043e \u0432\u0435\u0440\u043d\u043e \u043d\u0435 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0442\u0438\u043f\u043e\u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c BPF).<\/p>\n<p>  <\/p>\n<p>\u041d\u0430\u043b\u0438\u0447\u0438\u0435 \u0442\u0430\u043a\u0438\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439 \u0438 \u0434\u0435\u043b\u0430\u0435\u0442 BPF \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u043c \u0434\u043b\u044f \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f \u044f\u0434\u0440\u0430, \u0447\u0442\u043e \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0436\u0434\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435: \u0432\u0441\u0435 \u043d\u043e\u0432\u044b\u0435 \u0438 \u043d\u043e\u0432\u044b\u0435 \u0442\u0438\u043f\u044b \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432 BPF, \u0432\u0441\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 \u043a\u0440\u0443\u043f\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 BPF \u043d\u0430 \u0431\u043e\u0435\u0432\u044b\u0445 \u0441\u0435\u0440\u0432\u0435\u0440\u0430\u0445 24&#215;7, \u0432\u0441\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 \u0441\u0442\u0430\u0440\u0442\u0430\u043f\u043e\u0432 \u0441\u0442\u0440\u043e\u044f\u0442 \u0441\u0432\u043e\u0439 \u0431\u0438\u0437\u043d\u0435\u0441 \u043d\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u044f\u0445, \u0432 \u043e\u0441\u043d\u043e\u0432\u0435 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043b\u0435\u0436\u0438\u0442 BPF. BPF \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432\u0435\u0437\u0434\u0435: \u0432 \u0437\u0430\u0449\u0438\u0442\u0435 \u043e\u0442 DDoS \u0430\u0442\u0430\u043a, \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 SDN (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u0435\u0442\u0435\u0439 \u0434\u043b\u044f kubernetes), \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0433\u043e \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430 \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u043a\u0438 \u0441\u0438\u0441\u0442\u0435\u043c \u0438 \u0441\u0431\u043e\u0440\u0449\u0438\u043a\u0430 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438, \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u0432\u0442\u043e\u0440\u0436\u0435\u043d\u0438\u044f \u0438 \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0430\u0445-\u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u0430\u0445 \u0438 \u0442.\u043f.<\/p>\n<p>  <\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430 \u044d\u0442\u043e\u043c \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043c \u043e\u0431\u0437\u043e\u0440\u043d\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u0441\u0442\u0430\u0442\u044c\u0438 \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u0443\u044e \u043c\u0430\u0448\u0438\u043d\u0443 \u0438 \u043d\u0430 \u044d\u043a\u043e\u0441\u0438\u0441\u0442\u0435\u043c\u0443 BPF \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e.<\/p>\n<p>  <\/p>\n<h3>\u041e\u0442\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0435: \u0443\u0442\u0438\u043b\u0438\u0442\u044b<\/h3>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0438\u043c\u0435\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0438\u0437 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0440\u0430\u0437\u0434\u0435\u043b\u043e\u0432, \u0432\u0430\u043c \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0443\u0442\u0438\u043b\u0438\u0442, \u043c\u0438\u043d\u0438\u043c\u0443\u043c <code>llvm<\/code>\/<code>clang<\/code> \u0441 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u043e\u0439 bpf \u0438 <code>bpftool<\/code>. \u0412 \u0440\u0430\u0437\u0434\u0435\u043b\u0435 <a href=\"#tools\">\u0421\u0440\u0435\u0434\u0441\u0442\u0432\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438<\/a> \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u043f\u043e \u0441\u0431\u043e\u0440\u043a\u0435 \u0443\u0442\u0438\u043b\u0438\u0442, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0441\u0432\u043e\u0435\u0433\u043e \u044f\u0434\u0440\u0430. \u042d\u0442\u043e\u0442 \u0440\u0430\u0437\u0434\u0435\u043b \u043f\u043e\u043c\u0435\u0449\u0435\u043d \u043d\u0438\u0436\u0435, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043d\u0430\u0440\u0443\u0448\u0430\u0442\u044c \u0441\u0442\u0440\u043e\u0439\u043d\u043e\u0441\u0442\u044c \u043d\u0430\u0448\u0435\u0433\u043e \u0438\u0437\u043b\u043e\u0436\u0435\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<h3 id=\"bpf-virtual-machine\">\u0420\u0435\u0433\u0438\u0441\u0442\u0440\u044b \u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u043a\u043e\u043c\u0430\u043d\u0434 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0439 \u043c\u0430\u0448\u0438\u043d\u044b BPF<\/h3>\n<p>  <\/p>\n<p>\u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u043a\u043e\u043c\u0430\u043d\u0434 BPF \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u043b\u0430\u0441\u044c \u0441 \u0443\u0447\u0435\u0442\u043e\u043c \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0431\u0443\u0434\u0443\u0442 \u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 C \u0438 \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0432 \u044f\u0434\u0440\u043e \u0442\u0440\u0430\u043d\u0441\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u043a\u043e\u0434. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u043e\u0432 \u0438 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043a\u043e\u043c\u0430\u043d\u0434 \u0432\u044b\u0431\u0438\u0440\u0430\u043b\u043e\u0441\u044c \u0441 \u043e\u0433\u043b\u044f\u0434\u043a\u043e\u0439 \u043d\u0430 \u043f\u0435\u0440\u0435\u0441\u0435\u0447\u0435\u043d\u0438\u0435, \u0432 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u0441\u043c\u044b\u0441\u043b\u0435, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u043c\u0430\u0448\u0438\u043d. \u041a\u0440\u043e\u043c\u0435 \u044d\u0442\u043e\u0433\u043e, \u043d\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u043d\u0430\u043b\u0430\u0433\u0430\u043b\u0438\u0441\u044c \u0440\u0430\u0437\u043d\u043e\u0433\u043e \u0440\u043e\u0434\u0430 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043e \u043d\u0435\u0434\u0430\u0432\u043d\u0435\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043d\u0435 \u0431\u044b\u043b\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043f\u0438\u0441\u0430\u0442\u044c \u0446\u0438\u043a\u043b\u044b \u0438 \u043f\u043e\u0434\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u0430 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439 \u0431\u044b\u043b\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043e 4096 (\u0441\u0435\u0439\u0447\u0430\u0441 \u043f\u0440\u0438\u0432\u0438\u043b\u0435\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430\u043c \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0434\u043e \u043c\u0438\u043b\u043b\u0438\u043e\u043d\u0430 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439).<\/p>\n<p>  <\/p>\n<p>\u0412 BPF \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u043e\u0434\u0438\u043d\u043d\u0430\u0434\u0446\u0430\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e 64-\u0431\u0438\u0442\u043d\u044b\u0445 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u043e\u0432 <code>r0<\/code>\u2014<code>r10<\/code> \u0438 \u0441\u0447\u0451\u0442\u0447\u0438\u043a \u043a\u043e\u043c\u0430\u043d\u0434 (program counter). \u0420\u0435\u0433\u0438\u0441\u0442\u0440 <code>r10<\/code> \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0441\u0442\u0435\u043a (frame pointer) \u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0447\u0442\u0435\u043d\u0438\u044f. \u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430\u043c \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u0441\u0442\u0435\u043a \u0432 512 \u0431\u0430\u0439\u0442 \u0438 \u043d\u0435\u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u043c\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 \u0432\u0438\u0434\u0435 maps.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430\u043c BPF \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u0435\u0442\u0441\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u0438\u043f\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u043d\u0430\u0431\u043e\u0440 \u0444\u0443\u043d\u043a\u0446\u0438\u0439-\u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a\u043e\u0432 (kernel helpers) \u0438, \u0441 \u043d\u0435\u0434\u0430\u0432\u043d\u0438\u0445 \u043f\u043e\u0440, \u0438 \u043e\u0431\u044b\u0447\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u041a\u0430\u0436\u0434\u0430\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0434\u043e \u043f\u044f\u0442\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0445 \u0432 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0445 <code>r1<\/code>\u2014<code>r5<\/code>, \u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u0432 <code>r0<\/code>. \u0413\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u043f\u043e\u0441\u043b\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0430 \u0438\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u043e\u0432 <code>r6<\/code>\u2014<code>r9<\/code> \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u0441\u044f.<\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0439 \u0442\u0440\u0430\u043d\u0441\u043b\u044f\u0446\u0438\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u044b <code>r0<\/code>\u2014<code>r11<\/code> \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043c\u044b\u0445 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440 \u043e\u0434\u043d\u043e\u0437\u043d\u0430\u0447\u043d\u043e \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u044e\u0442\u0441\u044f \u043d\u0430 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0438\u0435 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u044b \u0441 \u0443\u0447\u0435\u0442\u043e\u043c \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0435\u0439 ABI \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f <code>x86_64<\/code> \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u044b <code>r1<\/code>\u2014<code>r5<\/code>, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0435\u0441\u044f \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u044e\u0442\u0441\u044f \u043d\u0430 <code>rdi<\/code>, <code>rsi<\/code>, <code>rdx<\/code>, <code>rcx<\/code>, <code>r8<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0430 <code>x86_64<\/code>. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u0434 \u0441\u043b\u0435\u0432\u0430 \u0442\u0440\u0430\u043d\u0441\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432 \u043a\u043e\u0434 \u0441\u043f\u0440\u0430\u0432\u0430 \u0432\u043e\u0442 \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">1:  (b7) r1 = 1                    mov    $0x1,%rdi 2:  (b7) r2 = 2                    mov    $0x2,%rsi 3:  (b7) r3 = 3                    mov    $0x3,%rdx 4:  (b7) r4 = 4                    mov    $0x4,%rcx 5:  (b7) r5 = 5                    mov    $0x5,%r8 6:  (85) call pc+1                 callq  0x0000000000001ee8<\/code><\/pre>\n<p>  <\/p>\n<p>\u0420\u0435\u0433\u0438\u0441\u0442\u0440 <code>r0<\/code> \u0442\u0430\u043a\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u0430 \u0432 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0435 <code>r1<\/code> \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u2014 \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u0438\u043f\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 <a href=\"https:\/\/github.com\/torvalds\/linux\/blob\/v5.7-rc3\/include\/uapi\/linux\/bpf.h#L3482\" rel=\"nofollow\"><code>struct xdp_md<\/code><\/a> (\u0434\u043b\u044f XDP) \u0438\u043b\u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 <a href=\"https:\/\/github.com\/torvalds\/linux\/blob\/v5.7-rc3\/include\/uapi\/linux\/bpf.h#L3292\" rel=\"nofollow\"><code>struct __sk_buff<\/code><\/a> (\u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u0441\u0435\u0442\u0435\u0432\u044b\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c) \u0438\u043b\u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 <a href=\"https:\/\/github.com\/torvalds\/linux\/blob\/v5.7-rc3\/arch\/x86\/include\/uapi\/asm\/ptrace.h\" rel=\"nofollow\"><code>struct pt_regs<\/code><\/a> (\u0434\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 tracing \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c) \u0438 \u0442.\u043f.<\/p>\n<p>  <\/p>\n<p>\u0418\u0442\u0430\u043a, \u0443 \u043d\u0430\u0441 \u0431\u044b\u043b \u043d\u0430\u0431\u043e\u0440 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u043e\u0432, kernel helpers, \u0441\u0442\u0435\u043a, \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0438 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u043c\u0430\u044f \u043f\u0430\u043c\u044f\u0442\u044c \u0432 \u0432\u0438\u0434\u0435 maps. <s>\u041d\u0435 \u0442\u043e, \u0447\u0442\u043e\u0431\u044b \u0432\u0441\u0451 \u044d\u0442\u043e \u0431\u044b\u043b\u043e \u043a\u0430\u0442\u0435\u0433\u043e\u0440\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0432 \u043f\u043e\u0435\u0437\u0434\u043a\u0435, \u043d\u043e&#8230;<\/s><\/p>\n<p>  <\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u043c \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0438 \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0435\u043c \u043f\u0440\u043e \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u043a\u043e\u043c\u0430\u043d\u0434 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u044d\u0442\u0438\u043c\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438. \u0412\u0441\u0435 (<a href=\"#x16\">\u043f\u043e\u0447\u0442\u0438 \u0432\u0441\u0435<\/a>) \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 BPF \u0438\u043c\u0435\u044e\u0442 \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 64-\u0431\u0438\u0442\u043d\u044b\u0439 \u0440\u0430\u0437\u043c\u0435\u0440. \u0415\u0441\u043b\u0438 \u0432\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u043d\u0430 \u043e\u0434\u043d\u0443 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e \u043d\u0430 64-\u0431\u0438\u0442\u043d\u043e\u0439 Big Endian \u043c\u0430\u0448\u0438\u043d\u0435, \u0442\u043e \u0432\u044b \u0443\u0432\u0438\u0434\u0438\u0442\u0435<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/ea\/wj\/pn\/eawjpniwfui7mpowjoa6nd6uths.png\">  <\/p>\n<p>  <\/p>\n<p>\u0417\u0434\u0435\u0441\u044c <code>Code<\/code> \u2014 \u044d\u0442\u043e \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u043a\u0430 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438, <code>Dst<\/code>\/<code>Src<\/code> \u2014\u00a0\u044d\u0442\u043e \u043a\u043e\u0434\u0438\u0440\u043e\u0432\u043a\u0438 \u043f\u0440\u0438\u0435\u043c\u043d\u0438\u043a\u0430 \u0438 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, <code>Off<\/code> \u2014 16-\u0431\u0438\u0442\u043d\u044b\u0439 \u0437\u043d\u0430\u043a\u043e\u0432\u044b\u0439 \u043e\u0442\u0441\u0442\u0443\u043f, \u0430 <code>Imm<\/code> \u2014 \u044d\u0442\u043e 32-\u0431\u0438\u0442\u043d\u043e\u0435 \u0437\u043d\u0430\u043a\u043e\u0432\u043e\u0435 \u0446\u0435\u043b\u043e\u0435 \u0447\u0438\u0441\u043b\u043e, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u043e\u0435 \u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043a\u043e\u043c\u0430\u043d\u0434\u0430\u0445 (\u0430\u043d\u0430\u043b\u043e\u0433 \u043a\u043e\u043d\u0441\u0442\u0430\u043d\u0442\u044b K \u0438\u0437 cBPF). \u041a\u043e\u0434\u0438\u0440\u043e\u0432\u043a\u0430 <code>Code<\/code> \u0438\u043c\u0435\u0435\u0442 \u043e\u0434\u0438\u043d \u0438\u0437 \u0434\u0432\u0443\u0445 \u0432\u0438\u0434\u043e\u0432:<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/_3\/fc\/cl\/_3fccl4c0qb2v90wodmua08s2ps.png\">  <\/p>\n<p>  <\/p>\n<p>\u041a\u043b\u0430\u0441\u0441\u044b \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439 0, 1, 2, 3 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043f\u0430\u043c\u044f\u0442\u044c\u044e. \u041e\u043d\u0438 <a href=\"https:\/\/github.com\/torvalds\/linux\/blob\/v5.7-rc3\/include\/uapi\/linux\/bpf_common.h#L7-L10\" rel=\"nofollow\">\u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f<\/a>, <code>BPF_LD<\/code>, <code>BPF_LDX<\/code>, <code>BPF_ST<\/code>, <code>BPF_STX<\/code>, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e. \u041a\u043b\u0430\u0441\u0441\u044b 4, 7 (<code>BPF_ALU<\/code>, <code>BPF_ALU64<\/code>) \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u043d\u0430\u0431\u043e\u0440 ALU \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439. \u041a\u043b\u0430\u0441\u0441\u044b 5, 6 (<code>BPF_JMP<\/code>, <code>BPF_JMP32<\/code>) \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u044e\u0442 \u0432 \u0441\u0435\u0431\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0430.<\/p>\n<p>  <\/p>\n<p>\u0414\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0438\u0439 \u043f\u043b\u0430\u043d \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u043a\u043e\u043c\u0430\u043d\u0434 BPF \u0442\u0430\u043a\u043e\u0439: \u0432\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0434\u043e\u0442\u043e\u0448\u043d\u043e \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u044f\u0442\u044c \u0432\u0441\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u0438 \u0438\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b, \u043c\u044b \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u043f\u0430\u0440\u0443 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0432 \u044d\u0442\u043e\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u0438 \u0438\u0437 \u043d\u0438\u0445 \u0441\u0442\u0430\u043d\u0435\u0442 \u044f\u0441\u043d\u043e, \u043a\u0430\u043a \u0443\u0441\u0442\u0440\u043e\u0435\u043d\u044b \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0438 \u043a\u0430\u043a \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u0434\u0438\u0437\u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043b\u044e\u0431\u043e\u0439 \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u0434\u043b\u044f BPF. \u0414\u043b\u044f \u0437\u0430\u043a\u0440\u0435\u043f\u043b\u0435\u043d\u0438\u044f \u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b\u0430 \u0434\u0430\u043b\u044c\u0448\u0435 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0435\u0449\u0435 \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u043c\u0441\u044f \u0441 \u0438\u043d\u0434\u0438\u0432\u0438\u0434\u0443\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f\u043c\u0438 \u0432 \u0440\u0430\u0437\u0434\u0435\u043b\u0430\u0445 \u043f\u0440\u043e Verifier, JIT \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440, \u0442\u0440\u0430\u043d\u0441\u043b\u044f\u0446\u0438\u044e \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e BPF, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u0438 \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u0438 maps, \u0432\u044b\u0437\u043e\u0432\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0438 \u0442.\u043f.<\/p>\n<p>  <\/p>\n<p>\u041a\u043e\u0433\u0434\u0430 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u043e\u0431 \u0438\u043d\u0434\u0438\u0432\u0438\u0434\u0443\u0430\u043b\u044c\u043d\u044b\u0445 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f\u0445, \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0441\u0441\u044b\u043b\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0444\u0430\u0439\u043b\u044b \u044f\u0434\u0440\u0430 <a href=\"https:\/\/github.com\/torvalds\/linux\/blob\/v5.7-rc3\/include\/uapi\/linux\/bpf.h\" rel=\"nofollow\"><code>bpf.h<\/code><\/a> \u0438 <a href=\"https:\/\/github.com\/torvalds\/linux\/blob\/v5.7-rc3\/include\/uapi\/linux\/bpf_common.h\" rel=\"nofollow\"><code>bpf_common.h<\/code><\/a>, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0435 \u043a\u043e\u0434\u044b \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439 BPF. \u041f\u0440\u0438 \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e\u043c \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u0438 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b \u0438\/\u0438\u043b\u0438 \u0440\u0430\u0437\u0431\u043e\u0440\u0435 \u0431\u0438\u043d\u0430\u0440\u043d\u0438\u043a\u043e\u0432, \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u043a\u0443 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0439\u0442\u0438 \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445, \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u0438, \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430\u0445: <a href=\"https:\/\/github.com\/iovisor\/bpf-docs\/blob\/master\/eBPF.md\" rel=\"nofollow\">Unofficial eBPF spec<\/a>, <a href=\"https:\/\/docs.cilium.io\/en\/latest\/bpf\/#instruction-set\" rel=\"nofollow\">BPF and XDP Reference Guide, Instruction Set<\/a>, <a href=\"https:\/\/git.kernel.org\/pub\/scm\/linux\/kernel\/git\/bpf\/bpf-next.git\/tree\/Documentation\/networking\/filter.txt\" rel=\"nofollow\">Documentation\/networking\/filter.txt<\/a> \u0438, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0445 \u043a\u043e\u0434\u0430\u0445 Linux \u2014 verifier, JIT, \u0438\u043d\u0442\u0435\u0440\u043f\u0440\u0435\u0442\u0430\u0442\u043e\u0440 BPF.<\/p>\n<p>  <\/p>\n<h4>\u041f\u0440\u0438\u043c\u0435\u0440: \u0434\u0438\u0437\u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0438\u0440\u0443\u0435\u043c BPF \u0432 \u0443\u043c\u0435<\/h4>\n<p>  <\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043c\u044b \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 <code>readelf-example.c<\/code> \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043f\u043e\u043b\u0443\u0447\u0438\u0432\u0448\u0438\u0439\u0441\u044f \u0431\u0438\u043d\u0430\u0440\u043d\u0438\u043a. \u041c\u044b \u0440\u0430\u0441\u043a\u0440\u043e\u0435\u043c \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 <code>readelf-example.c<\/code> \u043d\u0438\u0436\u0435, \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u0435\u0433\u043e \u043b\u043e\u0433\u0438\u043a\u0443 \u0438\u0437 \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0445 \u043a\u043e\u0434\u043e\u0432:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ clang -target bpf -c readelf-example.c -o readelf-example.o -O2 $ llvm-readelf -x .text readelf-example.o Hex dump of section '.text': 0x00000000 b7000000 01000000 15010100 00000000 ................ 0x00000010 b7000000 02000000 95000000 00000000 ................<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0435\u0440\u0432\u044b\u0439 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u0432 \u0432\u044b\u0432\u043e\u0434\u0435 <code>readelf<\/code> \u2014 \u044d\u0442\u043e \u043e\u0442\u0441\u0442\u0443\u043f \u0438 \u043d\u0430\u0448\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430, \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u0447\u0435\u0442\u044b\u0440\u0435\u0445 \u043a\u043e\u043c\u0430\u043d\u0434:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">Code Dst Src Off  Imm b7   0   0   0000 01000000 15   0   1   0100 00000000 b7   0   0   0000 02000000 95   0   0   0000 00000000<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u043e\u0434\u044b \u043a\u043e\u043c\u0430\u043d\u0434 \u0440\u0430\u0432\u043d\u044b <code>b7<\/code>, <code>15<\/code>, <code>b7<\/code> \u0438 <code>95<\/code>. \u0412\u0441\u043f\u043e\u043c\u043d\u0438\u043c, \u0447\u0442\u043e \u0442\u0440\u0438 \u043c\u043b\u0430\u0434\u0448\u0438\u0435 \u0431\u0438\u0442\u0430 \u2014 \u044d\u0442\u043e \u043a\u043b\u0430\u0441\u0441 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0447\u0435\u0442\u0432\u0435\u0440\u0442\u044b\u0439 \u0431\u0438\u0442 \u0443 \u0432\u0441\u0435\u0445 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439 \u043f\u0443\u0441\u0442\u043e\u0439, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043a\u043b\u0430\u0441\u0441\u044b \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439 \u0440\u0430\u0432\u043d\u044b, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, 7, 5, 7, 5. \u041a\u043b\u0430\u0441\u0441 7 \u2014 \u044d\u0442\u043e <code>BPF_ALU64<\/code>, \u0430 5 \u2014 \u044d\u0442\u043e <code>BPF_JMP<\/code>. \u0414\u043b\u044f \u043e\u0431\u043e\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0444\u043e\u0440\u043c\u0430\u0442 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u0439 (\u0441\u043c. \u0432\u044b\u0448\u0435) \u0438 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0430\u0448\u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0442\u0430\u043a (\u0437\u0430\u043e\u0434\u043d\u043e \u043f\u0435\u0440\u0435\u043f\u0438\u0448\u0435\u043c \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0441\u0442\u043e\u043b\u0431\u0446\u044b \u0432 \u0447\u0435\u043b\u043e\u0432\u0435\u0447\u0435\u0441\u043a\u043e\u043c \u0432\u0438\u0434\u0435):<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">Op S  Class   Dst Src Off  Imm b  0  ALU64   0   0   0    1 1  0  JMP     0   1   1    0 b  0  ALU64   0   0   0    2 9  0  JMP     0   0   0    0<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u043f\u0435\u0440\u0430\u0446\u0438\u044f <code>b<\/code> \u043a\u043b\u0430\u0441\u0441\u0430 <code>ALU64<\/code> \u2014 \u044d\u0442\u043e <a href=\"https:\/\/github.com\/torvalds\/linux\/blob\/v5.7-rc3\/include\/uapi\/linux\/bpf.h#L25\" rel=\"nofollow\">BPF_MOV<\/a>. \u041e\u043d\u0430 \u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0443-\u043f\u0440\u0438\u0435\u043c\u043d\u0438\u043a\u0443. \u0415\u0441\u043b\u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d \u0431\u0438\u0442 <code>s<\/code> (source), \u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0431\u0435\u0440\u0435\u0442\u0441\u044f \u0438\u0437 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430-\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430, \u0430 \u0435\u0441\u043b\u0438, \u043a\u0430\u043a \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043e\u043d \u043d\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d, \u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0431\u0435\u0440\u0435\u0442\u0441\u044f \u0438\u0437 \u043f\u043e\u043b\u044f <code>Imm<\/code>. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0432 \u043f\u0435\u0440\u0432\u043e\u0439 \u0438 \u0442\u0440\u0435\u0442\u044c\u0435\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f\u0445 \u043c\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e <code>r0 = Imm<\/code>. \u0414\u0430\u043b\u0435\u0435, \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f 1 \u043a\u043b\u0430\u0441\u0441\u0430 JMP \u2014 \u044d\u0442\u043e <a href=\"https:\/\/github.com\/torvalds\/linux\/blob\/v5.7-rc3\/include\/uapi\/linux\/bpf_common.h#L45\" rel=\"nofollow\">BPF_JEQ<\/a> (jump if equal). \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0442\u0430\u043a \u043a\u0430\u043a \u0431\u0438\u0442 <code>S<\/code> \u0440\u0430\u0432\u0435\u043d \u043d\u0443\u043b\u044e, \u043e\u043d\u0430 \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430-\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430 \u0441 \u043f\u043e\u043b\u0435\u043c <code>Imm<\/code>. \u0415\u0441\u043b\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442, \u0442\u043e \u043f\u0435\u0440\u0435\u0445\u043e\u0434 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043d\u0430 <code>PC + Off<\/code>, \u0433\u0434\u0435 <code>PC<\/code>, \u043a\u0430\u043a \u0432\u043e\u0434\u0438\u0442\u0441\u044f, \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0430\u0434\u0440\u0435\u0441 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438. \u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044f 9 \u043a\u043b\u0430\u0441\u0441\u0430 JMP \u2014 \u044d\u0442\u043e <a href=\"https:\/\/github.com\/torvalds\/linux\/blob\/v5.7-rc3\/include\/uapi\/linux\/bpf.h#L44\" rel=\"nofollow\"><code>BPF_EXIT<\/code><\/a>. \u042d\u0442\u0430 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044f \u044f\u0434\u0440\u0443 <code>r0<\/code>. \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u043d\u043e\u0432\u044b\u0439 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u043a \u043d\u0430\u0448\u0435\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">Op    S  Class   Dst Src Off  Imm    Disassm MOV   0  ALU64   0   0   0    1      r0 = 1 JEQ   0  JMP     0   1   1    0      if (r1 == 0) goto pc+1 MOV   0  ALU64   0   0   0    2      r0 = 2 EXIT  0  JMP     0   0   0    0      exit<\/code><\/pre>\n<p>  <\/p>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u044d\u0442\u043e \u0432 \u0431\u043e\u043b\u0435\u0435 \u0443\u0434\u043e\u0431\u043d\u043e\u043c \u0432\u0438\u0434\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">     r0 = 1      if (r1 == 0) goto END      r0 = 2 END:      exit<\/code><\/pre>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u043c\u044b \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u043c, \u0447\u0442\u043e \u0432 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0435 <code>r1<\/code> \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u043e\u0442 \u044f\u0434\u0440\u0430, \u0430 \u0432 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0435 <code>r0<\/code> \u0432 \u044f\u0434\u0440\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0443\u0432\u0438\u0434\u0435\u0442\u044c, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0440\u0430\u0432\u0435\u043d \u043d\u0443\u043b\u044e, \u0442\u043e \u043c\u044b \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c 1, \u0430 \u0432 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u2014 2. \u041f\u0440\u043e\u0432\u0435\u0440\u0438\u043c, \u0447\u0442\u043e \u043c\u044b \u043f\u0440\u0430\u0432\u044b, \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0432 \u043d\u0430 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ cat readelf-example.c int foo(void *ctx) {         return ctx ? 2 : 1; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u0430, \u044d\u0442\u043e \u0431\u0435\u0441\u0441\u043c\u044b\u0441\u043b\u0435\u043d\u043d\u0430\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430, \u043d\u043e \u0437\u0430\u0442\u043e \u043e\u043d\u0430 \u0442\u0440\u0430\u043d\u0441\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432\u0441\u0435\u0433\u043e \u0432 \u0447\u0435\u0442\u044b\u0440\u0435 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438.<\/p>\n<p>  <\/p>\n<h4 id=\"x16\">\u041f\u0440\u0438\u043c\u0435\u0440-\u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435: 16-\u0431\u0430\u0439\u0442\u043d\u0430\u044f \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f<\/h4>\n<p>  <\/p>\n<p>\u0420\u0430\u043d\u0435\u0435 \u043c\u044b \u0443\u043f\u043e\u043c\u044f\u043d\u0443\u043b\u0438, \u0447\u0442\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0442 \u0431\u043e\u043b\u044c\u0448\u0435, \u0447\u0435\u043c 64 \u0431\u0438\u0442\u0430. \u042d\u0442\u043e \u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 <code>lddw<\/code> (Code = <code>0x18<\/code> = <a href=\"https:\/\/github.com\/torvalds\/linux\/blob\/v5.7-rc3\/include\/uapi\/linux\/bpf_common.h#L7\" rel=\"nofollow\"><code>BPF_LD<\/code><\/a> | <a href=\"https:\/\/github.com\/torvalds\/linux\/blob\/v5.7-rc3\/include\/uapi\/linux\/bpf.h#L21\" rel=\"nofollow\"><code>BPF_DW<\/code><\/a> | <a href=\"https:\/\/github.com\/torvalds\/linux\/blob\/v5.7-rc3\/include\/uapi\/linux\/bpf_common.h#L23\" rel=\"nofollow\"><code>BPF_IMM<\/code><\/a>) \u2014 \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0432 \u0440\u0435\u0433\u0438\u0441\u0442\u0440 \u0434\u0432\u043e\u0439\u043d\u043e\u0435 \u0441\u043b\u043e\u0432\u043e \u0438\u0437 \u043f\u043e\u043b\u0435\u0439 <code>Imm<\/code>. \u0414\u0435\u043b\u043e \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e <code>Imm<\/code> \u0438\u043c\u0435\u0435\u0442 \u0440\u0430\u0437\u043c\u0435\u0440 32, \u0430 \u0434\u0432\u043e\u0439\u043d\u043e\u0435 \u0441\u043b\u043e\u0432\u043e \u2014 64 \u0431\u0438\u0442\u0430, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0432 \u0440\u0435\u0433\u0438\u0441\u0442\u0440 64-\u0431\u0438\u0442\u043d\u043e\u0435 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u043e\u0434\u043d\u043e\u0439 64-\u0431\u0438\u0442\u043d\u043e\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u0441\u044f. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0434\u0432\u0435 \u0441\u043e\u0441\u0435\u0434\u043d\u0438\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0432\u0442\u043e\u0440\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 64-\u0431\u0438\u0442\u043d\u043e\u0433\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u043f\u043e\u043b\u0435 <code>Imm<\/code>. \u041f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ cat x64.c long foo(void *ctx) {         return 0x11223344aabbccdd; } $ clang -target bpf -c x64.c -o x64.o -O2 $ llvm-readelf -x .text x64.o Hex dump of section '.text': 0x00000000 18000000 ddccbbaa 00000000 44332211 ............D3&quot;. 0x00000010 95000000 00000000                   ........<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u0431\u0438\u043d\u0430\u0440\u043d\u043e\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 \u0432\u0441\u0435\u0433\u043e \u0434\u0432\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">Binary                                 Disassm 18000000 ddccbbaa 00000000 44332211    r0 = Imm[0]|Imm[1] 95000000 00000000                      exit<\/code><\/pre>\n<p>  <\/p>\n<p>\u041c\u044b \u0435\u0449\u0435 \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u043c\u0441\u044f \u0441 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0435\u0439 <code>lddw<\/code>, \u043a\u043e\u0433\u0434\u0430 \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u0440\u0435\u043b\u043e\u043a\u0430\u0446\u0438\u044f\u0445 \u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 maps.<\/p>\n<p>  <\/p>\n<h4>\u041f\u0440\u0438\u043c\u0435\u0440: \u0434\u0438\u0437\u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0438\u0440\u0443\u0435\u043c BPF \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u043c\u0438 \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430\u043c\u0438<\/h4>\n<p>  <\/p>\n<p>\u0418\u0442\u0430\u043a, \u043c\u044b \u043d\u0430\u0443\u0447\u0438\u043b\u0438\u0441\u044c \u0447\u0438\u0442\u0430\u0442\u044c \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0435 \u043a\u043e\u0434\u044b BPF \u0438 \u0433\u043e\u0442\u043e\u0432\u044b \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c \u043b\u044e\u0431\u0443\u044e \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e, \u0435\u0441\u043b\u0438 \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f. \u041e\u0434\u043d\u0430\u043a\u043e, \u0441\u0442\u043e\u0438\u0442 \u0441\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u0443\u0434\u043e\u0431\u043d\u0435\u0435 \u0438 \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u0434\u0438\u0437\u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0445 \u0441\u0440\u0435\u0434\u0441\u0442\u0432, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ llvm-objdump -d x64.o  Disassembly of section .text:  0000000000000000 &lt;foo&gt;:  0: 18 00 00 00 dd cc bb aa 00 00 00 00 44 33 22 11 r0 = 1234605617868164317 ll  2: 95 00 00 00 00 00 00 00 exit<\/code><\/pre>\n<p>  <\/p>\n<h3 id=\"objects-lifetime\">\u0416\u0438\u0437\u043d\u0435\u043d\u043d\u044b\u0439 \u0446\u0438\u043a\u043b \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 BPF, \u0444\u0430\u0439\u043b\u043e\u0432\u0430\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0430 bpffs<\/h3>\n<p>  <\/p>\n<p>(\u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0441\u0442\u0438, \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c\u044b\u0435 \u0432 \u044d\u0442\u043e\u043c \u043f\u043e\u0434\u0440\u0430\u0437\u0434\u0435\u043b\u0435, \u044f \u0432\u043f\u0435\u0440\u0432\u044b\u0435 \u0443\u0437\u043d\u0430\u043b \u0438\u0437 <a href=\"https:\/\/facebookmicrosites.github.io\/bpf\/blog\/2018\/08\/31\/object-lifetime.html\" rel=\"nofollow\">\u043f\u043e\u0441\u0442\u0430<\/a> Alexei Starovoitov \u0432 <a href=\"https:\/\/facebookmicrosites.github.io\/bpf\/blog\/\" rel=\"nofollow\">BPF Blog<\/a>.)<\/p>\n<p>  <\/p>\n<p>\u041e\u0431\u044a\u0435\u043a\u0442\u044b BPF \u2014 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0438 \u043c\u0430\u043f\u044b \u2014 \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u0438\u0437 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043a\u043e\u043c\u0430\u043d\u0434 <code>BPF_PROG_LOAD<\/code> \u0438 <code>BPF_MAP_CREATE<\/code> \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 <code>bpf(2)<\/code>, \u043c\u044b \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043f\u0440\u043e \u0442\u043e \u043a\u0430\u043a \u0438\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u044f\u0434\u0440\u0430 \u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0439 \u0438\u0437 \u043d\u0438\u0445 <code>refcount<\/code> (\u0441\u0447\u0435\u0442\u0447\u0438\u043a \u0441\u0441\u044b\u043b\u043e\u043a) \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0440\u0430\u0432\u043d\u044b\u043c \u0435\u0434\u0438\u043d\u0438\u0446\u0435, \u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0444\u0430\u0439\u043b\u043e\u0432\u044b\u0439 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442. \u041f\u043e\u0441\u043b\u0435 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u044f \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u0430 <code>refcount<\/code> \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0443\u043c\u0435\u043d\u044c\u0448\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0435\u0434\u0438\u043d\u0438\u0446\u0443, \u0438 \u043f\u0440\u0438 \u0434\u043e\u0441\u0442\u0438\u0436\u0435\u043d\u0438\u0438 \u0438\u043c \u043d\u0443\u043b\u044f \u043e\u0431\u044a\u0435\u043a\u0442 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0430\u0435\u0442\u0441\u044f.<\/p>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043c\u0430\u043f\u044b, \u0442\u043e <code>refcount<\/code> \u044d\u0442\u0438\u0445 \u043c\u0430\u043f\u043e\u0432 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0435\u0434\u0438\u043d\u0438\u0446\u0443 \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u0442.\u0435. \u0438\u0445 \u0444\u0430\u0439\u043b\u043e\u0432\u044b\u0435 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u044b \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043a\u0440\u044b\u0442\u044c \u0438\u0437 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0438 \u043f\u0440\u0438 \u044d\u0442\u043e\u043c <code>refcount<\/code> \u043d\u0435 \u0441\u0442\u0430\u043d\u0435\u0442 \u043d\u0443\u043b\u0435\u043c:<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/2d\/6t\/iv\/2d6tivzhrp7bb9-z0ttjm4i4cn4.png\">  <\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0439 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u043c\u044b \u043e\u0431\u044b\u0447\u043d\u043e \u043f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0435\u043c \u0435\u0435 \u043a \u043a\u0430\u043a\u043e\u043c\u0443-\u043d\u0438\u0431\u0443\u0434\u044c \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u0443 \u0441\u043e\u0431\u044b\u0442\u0438\u0439. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u0441\u0430\u0434\u0438\u0442\u044c \u0435\u0435 \u043d\u0430 \u0441\u0435\u0442\u0435\u0432\u043e\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0445 \u043f\u0430\u043a\u0435\u0442\u043e\u0432 \u0438\u043b\u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0435\u0435 \u043a \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c <code>tracepoint<\/code> \u0432 \u044f\u0434\u0440\u0435. \u0412 \u044d\u0442\u043e\u0442 \u043c\u043e\u043c\u0435\u043d\u0442 \u0441\u0447\u0435\u0442\u0447\u0438\u043a \u0441\u0441\u044b\u043b\u043e\u043a \u0442\u043e\u0436\u0435 \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442\u0441\u044f \u043d\u0430 \u0435\u0434\u0438\u043d\u0438\u0446\u0443 \u0438 \u043c\u044b \u0441\u043c\u043e\u0436\u0435\u043c \u0437\u0430\u043a\u0440\u044b\u0442\u044c \u0444\u0430\u0439\u043b\u043e\u0432\u044b\u0439 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440 \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435-\u0437\u0430\u0433\u0440\u0443\u0437\u0447\u0438\u043a\u0435.<\/p>\n<p>  <\/p>\n<p>\u0427\u0442\u043e \u0441\u043b\u0443\u0447\u0438\u0442\u0441\u044f \u0435\u0441\u043b\u0438 \u043c\u044b \u0442\u0435\u043f\u0435\u0440\u044c \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043c \u0440\u0430\u0431\u043e\u0442\u0443 \u0437\u0430\u0433\u0440\u0443\u0437\u0447\u0438\u043a\u0430? \u042d\u0442\u043e \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0442\u0438\u043f\u0430 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 (hook). \u0412\u0441\u0435 \u0441\u0435\u0442\u0435\u0432\u044b\u0435 \u0445\u0443\u043a\u0438 \u0431\u0443\u0434\u0443\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u0447\u0438\u043a\u0430, \u044d\u0442\u043e, \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0435, \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0435 \u0445\u0443\u043a\u0438. \u0410, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u043a\u0438 \u0431\u0443\u0434\u0443\u0442 \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0435\u043d\u044b \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430, \u0441\u043e\u0437\u0434\u0430\u0432\u0448\u0435\u0433\u043e \u0438\u0445 (\u0438 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u043c\u0438, \u043e\u0442 \u00ablocal to the process\u00bb). \u0422\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438, \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u0445\u0443\u043a\u0438 \u0432\u0441\u0435\u0433\u0434\u0430 \u0438\u043c\u0435\u044e\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u0444\u0430\u0439\u043b\u043e\u0432\u044b\u0439 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440 \u0432 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0441 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0435\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430, \u0430 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0435 \u2014\u00a0\u043d\u0435\u0442. \u041d\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0440\u0438\u0441\u0443\u043d\u043a\u0435 \u044f \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043a\u0440\u0430\u0441\u043d\u044b\u0445 \u043a\u0440\u0435\u0441\u0442\u0438\u043a\u043e\u0432 \u0441\u0442\u0430\u0440\u0430\u044e\u0441\u044c \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u043a\u0430\u043a \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b-\u0437\u0430\u0433\u0440\u0443\u0437\u0447\u0438\u043a\u0430 \u0432\u043b\u0438\u044f\u0435\u0442 \u043d\u0430 \u0432\u0440\u0435\u043c\u044f \u0436\u0438\u0437\u043d\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u0438 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0445 \u0445\u0443\u043a\u043e\u0432.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/vk\/hd\/oa\/vkhdoalgmwvdj0kewke11pov_xu.png\">  <\/p>\n<p>  <\/p>\n<p>\u0417\u0430\u0447\u0435\u043c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043d\u0430 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u0438 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0435 \u0445\u0443\u043a\u0438? \u0417\u0430\u043f\u0443\u0441\u043a \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u0441\u0435\u0442\u0435\u0432\u044b\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c \u0438\u043c\u0435\u0435\u0442 \u0441\u043c\u044b\u0441\u043b \u0438 \u0431\u0435\u0437 userspace, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435 \u0437\u0430\u0449\u0438\u0442\u0443 \u043e\u0442 DDoS \u2014 \u0437\u0430\u0433\u0440\u0443\u0437\u0447\u0438\u043a \u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u043f\u0440\u0430\u0432\u0438\u043b\u0430 \u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u0442 BPF \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u043a \u0441\u0435\u0442\u0435\u0432\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0443, \u043f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u0437\u0430\u0433\u0440\u0443\u0437\u0447\u0438\u043a \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0439\u0442\u0438 \u0438 \u0443\u0431\u0438\u0442\u044c\u0441\u044f. \u0421 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435 \u0441\u0435\u0431\u0435 \u043e\u0442\u043b\u0430\u0434\u043e\u0447\u043d\u0443\u044e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u043a\u0438, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0432\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u043b\u0438 \u043d\u0430 \u043a\u043e\u043b\u0435\u043d\u043a\u0435 \u0437\u0430 \u0434\u0435\u0441\u044f\u0442\u044c \u043c\u0438\u043d\u0443\u0442 \u2014\u00a0\u043f\u043e\u0441\u043b\u0435 \u0435\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0432\u0430\u043c \u0431\u044b \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c, \u0447\u0442\u043e\u0431\u044b \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u043d\u0435 \u043e\u0441\u0442\u0430\u0432\u0430\u043b\u043e\u0441\u044c \u043c\u0443\u0441\u043e\u0440\u0430, \u0438 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u0445\u0443\u043a\u0438 \u044d\u0442\u043e \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u044e\u0442.<\/p>\n<p>  <\/p>\n<p>\u0421 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435, \u0447\u0442\u043e \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u043e\u0434\u0441\u043e\u0435\u0434\u0438\u043d\u0438\u0442\u044c\u0441\u044f \u043a tracepoint \u0432 \u044f\u0434\u0440\u0435 \u0438 \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443 \u0432 \u0442\u0435\u0447\u0435\u043d\u0438\u0435 \u043c\u043d\u043e\u0433\u0438\u0445 \u043b\u0435\u0442. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u0430\u043c \u0431\u044b \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u043a \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0435 \u0432\u0440\u0435\u043c\u044f \u043e\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u0438. \u0422\u0430\u043a\u0443\u044e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0444\u0430\u0439\u043b\u043e\u0432\u0430\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0430 bpf. \u042d\u0442\u043e \u043f\u0441\u0435\u0432\u0434\u043e-\u0444\u0430\u0439\u043b\u043e\u0432\u0430\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0430, \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0430\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043f\u0430\u043c\u044f\u0442\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0444\u0430\u0439\u043b\u044b, \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u044b BPF \u0438, \u0442\u0435\u043c \u0441\u0430\u043c\u044b\u043c, \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u044e\u0449\u0438\u0435 <code>refcount<\/code> \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432. \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0437\u0430\u0433\u0440\u0443\u0437\u0447\u0438\u043a \u043c\u043e\u0436\u0435\u0442 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443, \u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043e\u0441\u0442\u0430\u043d\u0443\u0442\u0441\u044f \u0436\u0438\u0432\u044b.<\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/qc\/5o\/h0\/qc5oh0vxhkoah5-bzlr-chgz_qk.png\">  <\/p>\n<p>  <\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0444\u0430\u0439\u043b\u043e\u0432 \u0432 bpffs, \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0438\u0445\u0441\u044f \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u044b BPF \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u00ab\u0437\u0430\u043a\u0440\u0435\u043f\u043b\u0435\u043d\u0438\u0435\u00bb (\u00abpin\u00bb, \u043a\u0430\u043a \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0444\u0440\u0430\u0437\u0435: \u00abprocess can pin a BPF program or map\u00bb). \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0444\u0430\u0439\u043b\u043e\u0432\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0434\u043b\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 BPF \u0438\u043c\u0435\u0435\u0442 \u0441\u043c\u044b\u0441\u043b \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u043f\u0440\u043e\u0434\u043b\u0435\u043d\u0438\u044f \u0436\u0438\u0437\u043d\u0438 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u043d\u043e \u0438 \u0434\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u2014 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044f\u0441\u044c \u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443 \u0441 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043e\u0439 \u0434\u043b\u044f \u0437\u0430\u0449\u0438\u0442\u044b \u043e\u0442 DDoS, \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0438\u043c\u0435\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u043e\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u044c \u0438 \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443.<\/p>\n<p>  <\/p>\n<p>\u0424\u0430\u0439\u043b\u043e\u0432\u0430\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0430 BPF \u043e\u0431\u044b\u0447\u043d\u043e \u043c\u043e\u043d\u0442\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432 <code>\/sys\/fs\/bpf<\/code>, \u043d\u043e \u0435\u0435 \u043c\u043e\u0436\u043d\u043e \u0441\u043c\u043e\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ mkdir bpf-mountpoint $ sudo mount -t bpf none bpf-mountpoint<\/code><\/pre>\n<p>  <\/p>\n<p>\u0418\u043c\u0435\u043d\u0430 \u0432 \u0444\u0430\u0439\u043b\u043e\u0432\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u044b <code>BPF_OBJ_PIN<\/code> \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 BPF. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0438\u043b\u043b\u044e\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u043a\u0430\u043a\u0443\u044e-\u043d\u0438\u0431\u0443\u0434\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443, \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u043c, \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u043c \u0438 \u0437\u0430\u043a\u0440\u0435\u043f\u0438\u043c \u0435\u0435 \u0432 <code>bpffs<\/code>. \u041d\u0430\u0448\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u0442 \u043d\u0438\u0447\u0435\u0433\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0433\u043e, \u043c\u044b \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u043c \u0435\u0435 \u043a\u043e\u0434 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0432\u044b \u043c\u043e\u0433\u043b\u0438 \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0441\u0442\u0438 \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ cat test.c __attribute__((section(&quot;xdp&quot;), used)) int test(void *ctx) {         return 0; }  char _license[] __attribute__((section(&quot;license&quot;), used)) = &quot;GPL&quot;;<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u043c \u044d\u0442\u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0438 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u0443\u044e \u043a\u043e\u043f\u0438\u044e \u0444\u0430\u0439\u043b\u043e\u0432\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u044b <code>bpffs<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ clang -target bpf -c test.c -o test.o $ mkdir bpf-mountpoint $ sudo mount -t bpf none bpf-mountpoint<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u043c \u043d\u0430\u0448\u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0443\u0442\u0438\u043b\u0438\u0442\u044b <code>bpftool<\/code> \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0441\u043e\u043f\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0435 \u0432\u044b\u0437\u043e\u0432\u044b <code>bpf(2)<\/code> (\u0438\u0437 \u0432\u044b\u0432\u043e\u0434\u0430 strace \u0443\u0434\u0430\u043b\u0435\u043d\u044b \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0435 \u043e\u0442\u043d\u043e\u0441\u044f\u0449\u0438\u0435\u0441\u044f \u043a \u0434\u0435\u043b\u0443 \u0441\u0442\u0440\u043e\u043a\u0438):<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ sudo strace -e bpf bpftool prog load .\/test.o bpf-mountpoint\/test bpf(BPF_PROG_LOAD, {prog_type=BPF_PROG_TYPE_XDP, prog_name=&quot;test&quot;, ...}, 120) = 3 bpf(BPF_OBJ_PIN, {pathname=&quot;bpf-mountpoint\/test&quot;, bpf_fd=3}, 120) = 0<\/code><\/pre>\n<p>  <\/p>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u043b\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 <code>BPF_PROG_LOAD<\/code>, \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u043e\u0442 \u044f\u0434\u0440\u0430 \u0444\u0430\u0439\u043b\u043e\u0432\u044b\u0439 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440 <code>3<\/code> \u0438 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u044b <code>BPF_OBJ_PIN<\/code> \u0437\u0430\u043a\u0440\u0435\u043f\u0438\u043b\u0438 \u044d\u0442\u043e\u0442 \u0444\u0430\u0439\u043b\u043e\u0432\u044b\u0439 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440 \u0432 \u0432\u0438\u0434\u0435 \u0444\u0430\u0439\u043b\u0430 <code>&quot;bpf-mountpoint\/test&quot;<\/code>. \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430-\u0437\u0430\u0433\u0440\u0443\u0437\u0447\u0438\u043a <code>bpftool<\/code> \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0430 \u0440\u0430\u0431\u043e\u0442\u0443, \u043d\u043e \u043d\u0430\u0448\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043e\u0441\u0442\u0430\u043b\u0430\u0441\u044c \u0432 \u044f\u0434\u0440\u0435, \u0445\u043e\u0442\u044f \u043c\u044b \u0438 \u043d\u0435 \u043f\u0440\u0438\u043a\u0440\u0435\u043f\u043b\u044f\u043b\u0438 \u0435\u0435 \u043d\u0438 \u043a \u043a\u0430\u043a\u043e\u043c\u0443 \u0441\u0435\u0442\u0435\u0432\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0443:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ sudo bpftool prog | tail -3 783: xdp  name test  tag 5c8ba0cf164cb46c  gpl         loaded_at 2020-05-05T13:27:08+0000  uid 0         xlated 24B  jited 41B  memlock 4096B<\/code><\/pre>\n<p>  <\/p>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u0444\u0430\u0439\u043b\u043e\u0432\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u043e\u0431\u044b\u0447\u043d\u044b\u043c <code>unlink(2)<\/code> \u0438 \u043f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0430\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0431\u0443\u0434\u0435\u0442 \u0443\u0434\u0430\u043b\u0435\u043d\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ sudo rm .\/bpf-mountpoint\/test $ sudo bpftool prog show id 783 Error: get by id (783): No such file or directory<\/code><\/pre>\n<p>  <\/p>\n<h4>\u0423\u0434\u0430\u043b\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432<\/h4>\n<p>  <\/p>\n<p>\u0413\u043e\u0432\u043e\u0440\u044f \u043e\u0431 \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u0442\u043e\u0447\u043d\u0438\u0442\u044c, \u0447\u0442\u043e \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043c\u044b \u043e\u0442\u043a\u043b\u044e\u0447\u0438\u043b\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u043e\u0442 \u0445\u0443\u043a\u0430 (\u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u0441\u043e\u0431\u044b\u0442\u0438\u0439), \u043d\u0438 \u043e\u0434\u043d\u043e \u043d\u043e\u0432\u043e\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u043d\u0435 \u043f\u043e\u0432\u043b\u0435\u0447\u0435\u0442 \u0435\u0435 \u0437\u0430\u043f\u0443\u0441\u043a, \u043e\u0434\u043d\u0430\u043a\u043e, \u0432\u0441\u0435 \u0442\u0435\u043a\u0443\u0449\u0438\u0435 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u044b \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0431\u0443\u0434\u0443\u0442 \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u044b \u0432 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435.<\/p>\n<p>  <\/p>\n<p>\u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u0438\u0434\u044b BPF \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043f\u043e\u0434\u043c\u0435\u043d\u044f\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u043d\u0430 \u043b\u0435\u0442\u0443, \u0442.\u0435. \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0430\u0442\u043e\u043c\u0430\u0440\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 <code>replace = detach old program, attach new program<\/code>. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u0432\u0441\u0435 \u0430\u043a\u0442\u0438\u0432\u043d\u044b\u0435 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u044b \u0441\u0442\u0430\u0440\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0437\u0430\u043a\u043e\u043d\u0447\u0430\u0442 \u0441\u0432\u043e\u044e \u0440\u0430\u0431\u043e\u0442\u0443, \u0430 \u043d\u043e\u0432\u044b\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u0431\u0443\u0434\u0443\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0443\u0436\u0435 \u0438\u0437 \u043d\u043e\u0432\u043e\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u0438 \u00ab\u0430\u0442\u043e\u043c\u0430\u0440\u043d\u043e\u0441\u0442\u044c\u00bb \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u0437\u0434\u0435\u0441\u044c, \u0447\u0442\u043e \u043d\u0438 \u043e\u0434\u043d\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u043f\u0443\u0449\u0435\u043d\u043e.<\/p>\n<p>  <\/p>\n<h4>\u041f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c \u043a \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430\u043c \u0441\u043e\u0431\u044b\u0442\u0438\u0439<\/h4>\n<p>  <\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u043f\u043e\u0434\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c \u043a \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430\u043c \u0441\u043e\u0431\u044b\u0442\u0438\u0439, \u0442\u0430\u043a \u043a\u0430\u043a \u044d\u0442\u043e \u0438\u043c\u0435\u0435\u0442 \u0441\u043c\u044b\u0441\u043b \u0438\u0437\u0443\u0447\u0430\u0442\u044c \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b. \u0421\u043c. <a href=\"#helpers-with-args\">\u043f\u0440\u0438\u043c\u0435\u0440<\/a> \u043d\u0438\u0436\u0435, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043c\u044b \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u043a\u0430\u043a \u043f\u043e\u0434\u0441\u043e\u0435\u0434\u0438\u043d\u044f\u044e\u0442\u0441\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0442\u0438\u043f\u0430 XDP.<\/p>\n<p>  <\/p>\n<h3 id=\"bpf-syscall\">\u0423\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 bpf<\/h3>\n<p>  <\/p>\n<h4 id=\"bpf-programs\">\u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b BPF<\/h4>\n<p>  <\/p>\n<p>\u0412\u0441\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b BPF \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0438\u0437 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 <code>bpf<\/code>, \u0438\u043c\u0435\u044e\u0449\u0435\u0433\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">#include &lt;linux\/bpf.h&gt;  int bpf(int cmd, union bpf_attr *attr, unsigned int size);<\/code><\/pre>\n<p>  <\/p>\n<p>\u0417\u0434\u0435\u0441\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u0430 <code>cmd<\/code> \u2014 \u044d\u0442\u043e \u043e\u0434\u043d\u043e \u0438\u0437 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0442\u0438\u043f\u0430 <a href=\"https:\/\/github.com\/torvalds\/linux\/blob\/v5.8-rc7\/include\/uapi\/linux\/bpf.h#L85\" rel=\"nofollow\"><code>enum bpf_cmd<\/code><\/a>, <code>attr<\/code> \u2014\u00a0\u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0434\u043b\u044f \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0438 <code>size<\/code> \u2014 \u0440\u0430\u0437\u043c\u0435\u0440 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043f\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044e, \u0442.\u0435. \u043e\u0431\u044b\u0447\u043d\u043e \u044d\u0442\u043e <code>sizeof(*attr)<\/code>. \u0412 \u044f\u0434\u0440\u0435 5.8 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 <code>bpf<\/code> \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 34 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043a\u043e\u043c\u0430\u043d\u0434\u044b, \u0430 <a href=\"https:\/\/github.com\/torvalds\/linux\/blob\/v5.8-rc7\/include\/uapi\/linux\/bpf.h#L431-L630\" rel=\"nofollow\">\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435<\/a> <code>union bpf_attr<\/code> \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 200 \u0441\u0442\u0440\u043e\u0447\u0435\u043a. \u041d\u043e \u043d\u0430\u0441 \u043d\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u044d\u0442\u043e \u043f\u0443\u0433\u0430\u0442\u044c, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f \u0441 \u043a\u043e\u043c\u0430\u043d\u0434\u0430\u043c\u0438 \u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438 \u043d\u0430 \u043f\u0440\u043e\u0442\u044f\u0436\u0435\u043d\u0438\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u0441\u0442\u0430\u0442\u0435\u0439.<\/p>\n<p>  <\/p>\n<p>\u041d\u0430\u0447\u043d\u0435\u043c \u043c\u044b \u0441 \u043a\u043e\u043c\u0430\u043d\u0434\u044b <code>BPF_PROG_LOAD<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b BPF \u2014 \u0431\u0435\u0440\u0435\u0442 \u043d\u0430\u0431\u043e\u0440 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439 BPF \u0438 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442 \u0435\u0433\u043e \u0432 \u044f\u0434\u0440\u043e. \u0412 \u043c\u043e\u043c\u0435\u043d\u0442 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f verifier, \u0430 \u043f\u043e\u0442\u043e\u043c JIT compiler \u0438, \u043f\u043e\u0441\u043b\u0435 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0433\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f, \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0444\u0430\u0439\u043b\u043e\u0432\u044b\u0439 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b. \u041c\u044b \u0432\u0438\u0434\u0435\u043b\u0438 \u0447\u0442\u043e \u0441 \u043d\u0438\u043c \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0434\u0430\u043b\u044c\u0448\u0435 \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435 <a href=\"#objects-lifetime\">\u043f\u0440\u043e \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u044b\u0439 \u0446\u0438\u043a\u043b \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 BPF<\/a>.<\/p>\n<p>  <\/p>\n<p>\u0421\u0435\u0439\u0447\u0430\u0441 \u043c\u044b \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0443\u044e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 BPF, \u043d\u043e \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0440\u0435\u0448\u0438\u0442\u044c, \u0447\u0442\u043e \u0438\u043c\u0435\u043d\u043d\u043e \u0437\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u2014\u00a0\u043d\u0430\u043c \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0432\u044b\u0431\u0440\u0430\u0442\u044c <a href=\"https:\/\/github.com\/torvalds\/linux\/blob\/v5.8-rc7\/include\/uapi\/linux\/bpf.h#L161\" rel=\"nofollow\">\u0442\u0438\u043f<\/a> \u0438 \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u044d\u0442\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u043e\u0439\u0434\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043d\u0430 verifier. \u041e\u0434\u043d\u0430\u043a\u043e, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441, \u0432\u043e\u0442 \u0433\u043e\u0442\u043e\u0432\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435: \u043c\u044b \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0442\u0438\u043f\u0430 <code>BPF_PROG_TYPE_XDP<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>XDP_PASS<\/code> (\u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0432\u0441\u0435 \u043f\u0430\u043a\u0435\u0442\u044b). \u041d\u0430 \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440\u0435 BPF \u044d\u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">r0 = 2 exit<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u043c\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043b\u0438\u0441\u044c \u0441 \u0442\u0435\u043c, <em>\u0447\u0442\u043e<\/em> \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043a\u0430\u043a \u043c\u044b \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0435\u043c:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">#define _GNU_SOURCE #include &lt;string.h&gt; #include &lt;unistd.h&gt; #include &lt;sys\/syscall.h&gt; #include &lt;linux\/bpf.h&gt;  static inline __u64 ptr_to_u64(const void *ptr) {         return (__u64) (unsigned long) ptr; }  int main(void) {     struct bpf_insn insns[] = {         {             .code = BPF_ALU64 | BPF_MOV | BPF_K,             .dst_reg = BPF_REG_0,             .imm = XDP_PASS         },         {             .code = BPF_JMP | BPF_EXIT         },     };      union bpf_attr attr = {         .prog_type = BPF_PROG_TYPE_XDP,         .insns     = ptr_to_u64(insns),         .insn_cnt  = sizeof(insns)\/sizeof(insns[0]),         .license   = ptr_to_u64(&quot;GPL&quot;),     };      strncpy(attr.prog_name, &quot;woo&quot;, sizeof(attr.prog_name));     syscall(__NR_bpf, BPF_PROG_LOAD, &amp;attr, sizeof(attr));      for ( ;; )         pause(); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442\u0441\u044f \u0441 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043c\u0430\u0441\u0441\u0438\u0432\u0430 <code>insns<\/code> \u2014 \u043d\u0430\u0448\u0435\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b BPF \u0432 \u043c\u0430\u0448\u0438\u043d\u043d\u044b\u0445 \u043a\u043e\u0434\u0430\u0445. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u043a\u0430\u0436\u0434\u0430\u044f \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b BPF \u0443\u043f\u0430\u043a\u043e\u0432\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 <a href=\"https:\/\/github.com\/torvalds\/linux\/blob\/v5.8-rc7\/include\/uapi\/linux\/bpf.h#L65-L71\" rel=\"nofollow\"><code>bpf_insn<\/code><\/a>. \u041f\u0435\u0440\u0432\u044b\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442 <code>insns<\/code> \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 <code>r0 = 2<\/code>, \u0432\u0442\u043e\u0440\u043e\u0439 \u2014\u00a0<code>exit<\/code>.<\/p>\n<p>  <\/p>\n<p><em>\u041e\u0442\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0435.<\/em> \u0412 \u044f\u0434\u0440\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b \u0431\u043e\u043b\u0435\u0435 \u0443\u0434\u043e\u0431\u043d\u044b\u0435 \u043c\u0430\u043a\u0440\u043e\u0441\u044b \u0434\u043b\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043c\u0430\u0448\u0438\u043d\u043d\u044b\u0445 \u043a\u043e\u0434\u043e\u0432, \u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u044f\u0434\u0435\u0440\u043d\u044b\u0439 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u0447\u043d\u044b\u0439 \u0444\u0430\u0439\u043b <code>tools\/include\/linux\/filter.h<\/code> \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">struct bpf_insn insns[] = {     BPF_MOV64_IMM(BPF_REG_0, XDP_PASS),     BPF_EXIT_INSN() };<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u043e \u0442\u0430\u043a \u043a\u0430\u043a \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c BPF \u0432 \u043c\u0430\u0448\u0438\u043d\u043d\u044b\u0445 \u043a\u043e\u0434\u0430\u0445 \u043d\u0443\u0436\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0442\u0435\u0441\u0442\u043e\u0432 \u0432 \u044f\u0434\u0440\u0435 \u0438 \u0441\u0442\u0430\u0442\u0435\u0439 \u043f\u0440\u043e BPF, \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u044d\u0442\u0438\u0445 \u043c\u0430\u043a\u0440\u043e\u0441\u043e\u0432 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043d\u0435 \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0435\u0442 \u0436\u0438\u0437\u043d\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430.<\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b BPF \u043c\u044b \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u0435\u0435 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0435 \u0432 \u044f\u0434\u0440\u043e. \u041d\u0430\u0448 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u0438\u0441\u0442\u0441\u043a\u0438\u0439 \u043d\u0430\u0431\u043e\u0440 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 <code>attr<\/code> \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0432 \u0441\u0435\u0431\u044f \u0442\u0438\u043f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u043d\u0430\u0431\u043e\u0440 \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439, \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u043b\u0438\u0446\u0435\u043d\u0437\u0438\u044e, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0438\u043c\u044f <code>&quot;woo&quot;<\/code>, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0439\u0442\u0438 \u043d\u0430\u0448\u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u043f\u043e\u0441\u043b\u0435 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438. \u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430, \u043a\u0430\u043a \u0438 \u0431\u044b\u043b\u043e \u043e\u0431\u0435\u0449\u0430\u043d\u043e, \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442\u0441\u044f \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 <code>bpf<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0412 \u043a\u043e\u043d\u0446\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u043c\u044b \u043f\u043e\u043f\u0430\u0434\u0430\u0435\u043c \u0432 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0446\u0438\u043a\u043b, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u043c\u0438\u0442\u0438\u0440\u0443\u0435\u0442 \u043f\u043e\u043b\u0435\u0437\u043d\u0443\u044e \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0443. \u0411\u0435\u0437 \u043d\u0435\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0431\u0443\u0434\u0435\u0442 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d\u0430 \u044f\u0434\u0440\u043e\u043c \u043f\u0440\u0438 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0438 \u0444\u0430\u0439\u043b\u043e\u0432\u043e\u0433\u043e \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0438\u043b \u043d\u0430\u043c \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 <code>bpf<\/code>, \u0438 \u043c\u044b \u043d\u0435 \u0443\u0432\u0438\u0434\u0438\u043c \u0435\u0435 \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0435.<\/p>\n<p>  <\/p>\n<p>\u041d\u0443 \u0447\u0442\u043e \u0436\u0435, \u043c\u044b \u0433\u043e\u0442\u043e\u0432\u044b \u043a \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e. \u0421\u043e\u0431\u0435\u0440\u0435\u043c \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u043f\u043e\u0434 <code>strace<\/code>, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0447\u0442\u043e \u0432\u0441\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043a\u0430\u043a \u043d\u0430\u0434\u043e:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ clang -g -O2 simple-prog.c -o simple-prog  $ sudo strace .\/simple-prog execve(&quot;.\/simple-prog&quot;, [&quot;.\/simple-prog&quot;], 0x7ffc7b553480 \/* 13 vars *\/) = 0 ... bpf(BPF_PROG_LOAD, {prog_type=BPF_PROG_TYPE_XDP, insn_cnt=2, insns=0x7ffe03c4ed50, license=&quot;GPL&quot;, log_level=0, log_size=0, log_buf=NULL, kern_version=KERNEL_V ERSION(0, 0, 0), prog_flags=0, prog_name=&quot;woo&quot;, prog_ifindex=0, expected_attach_type=BPF_CGROUP_INET_INGRESS}, 72) = 3 pause(<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u0441\u0435 \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435, <code>bpf(2)<\/code> \u0432\u0435\u0440\u043d\u0443\u043b \u043d\u0430\u043c \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440 3 \u0438 \u043c\u044b \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u043b\u0438\u0441\u044c \u0432 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0446\u0438\u043a\u043b \u0441 <code>pause()<\/code>. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043d\u0430\u0439\u0442\u0438 \u043d\u0430\u0448\u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0435. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u043f\u043e\u0439\u0434\u0435\u043c \u0432 \u0434\u0440\u0443\u0433\u043e\u0439 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0443\u0442\u0438\u043b\u0438\u0442\u0443 <code>bpftool<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\"># bpftool prog | grep -A3 woo 390: xdp  name woo  tag 3b185187f1855c4c  gpl         loaded_at 2020-08-31T24:66:44+0000  uid 0         xlated 16B  jited 40B  memlock 4096B         pids simple-prog(10381)<\/code><\/pre>\n<p>  <\/p>\n<p>\u041c\u044b \u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u0430\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 <code>woo<\/code> \u0447\u0435\u0439 \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0439 ID \u0440\u0430\u0432\u0435\u043d 390, \u0438 \u0447\u0442\u043e \u0432 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 <code>simple-prog<\/code> \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0439 \u0444\u0430\u0439\u043b\u043e\u0432\u044b\u0439 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u043d\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 (\u0438 \u0435\u0441\u043b\u0438 <code>simple-prog<\/code> \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442 \u0440\u0430\u0431\u043e\u0442\u0443, \u0442\u043e <code>woo<\/code> \u0438\u0441\u0447\u0435\u0437\u043d\u0435\u0442). \u041a\u0430\u043a \u0438 \u043e\u0436\u0438\u0434\u0430\u043b\u043e\u0441\u044c, \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 <code>woo<\/code> \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 16 \u0431\u0430\u0439\u0442 \u2014\u00a0\u0434\u0432\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u2014 \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0445 \u043a\u043e\u0434\u043e\u0432 \u0432 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0435 BPF, \u043d\u043e \u0432 \u043d\u0430\u0442\u0438\u0432\u043d\u043e\u043c \u0432\u0438\u0434\u0435 (x86_64) \u2014\u00a0\u044d\u0442\u043e \u0443\u0436\u0435 40 \u0431\u0430\u0439\u0442. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043d\u0430\u0448\u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0432 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u043c \u0432\u0438\u0434\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\"># bpftool prog dump xlated id 390    0: (b7) r0 = 2    1: (95) exit<\/code><\/pre>\n<p>  <\/p>\n<p>\u0431\u0435\u0437 \u0441\u044e\u0440\u043f\u0440\u0438\u0437\u043e\u0432. \u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043a\u043e\u0434, \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 JIT \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\"># bpftool prog dump jited id 390 bpf_prog_3b185187f1855c4c_woo:    0:   nopl   0x0(%rax,%rax,1)    5:   push   %rbp    6:   mov    %rsp,%rbp    9:   sub    $0x0,%rsp   10:   push   %rbx   11:   push   %r13   13:   push   %r14   15:   push   %r15   17:   pushq  $0x0   19:   mov    $0x2,%eax   1e:   pop    %rbx   1f:   pop    %r15   21:   pop    %r14   23:   pop    %r13   25:   pop    %rbx   26:   leaveq   27:   retq<\/code><\/pre>\n<p>  <\/p>\n<p>\u043d\u0435 \u043e\u0447\u0435\u043d\u044c-\u0442\u043e \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e \u0434\u043b\u044f <code>exit(2)<\/code>, \u043d\u043e \u0441\u043f\u0440\u0430\u0432\u0435\u0434\u043b\u0438\u0432\u043e\u0441\u0442\u0438 \u0440\u0430\u0434\u0438, \u043d\u0430\u0448\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0443\u0436 \u043f\u0440\u043e\u0441\u0442\u0430, \u0430 \u0434\u043b\u044f \u043d\u0435\u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c \u043f\u0440\u043e\u043b\u043e\u0433 \u0438 \u044d\u043f\u0438\u043b\u043e\u0433, \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0435 JIT \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u043d\u0443\u0436\u043d\u044b.<\/p>\n<p>  <\/p>\n<h4>Maps<\/h4>\n<p>  <\/p>\n<p>\u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b BPF \u043c\u043e\u0433\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043e\u0431\u043b\u0430\u0441\u0442\u0438 \u043f\u0430\u043c\u044f\u0442\u0438, \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0435 \u043a\u0430\u043a \u0434\u0440\u0443\u0433\u0438\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430\u043c BPF, \u0442\u0430\u043a \u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430\u043c \u0438\u0437 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u042d\u0442\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f maps \u0438 \u0432 \u044d\u0442\u043e\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u043c\u044b \u043f\u043e\u043a\u0430\u0436\u0435\u043c \u043a\u0430\u043a \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0438\u043c\u0438 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 <code>bpf<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0421\u0440\u0430\u0437\u0443 \u0441\u043a\u0430\u0436\u0435\u043c, \u0447\u0442\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 maps \u043d\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043e\u0441\u0442\u0443\u043f\u043e\u043c \u043a \u043e\u0431\u0449\u0435\u0439 \u043f\u0430\u043c\u044f\u0442\u0438. \u0421\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u043c\u0430\u043f\u044b \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u043d\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b BPF \u0438\u043b\u0438 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u043d\u0430 \u0441\u0435\u0442\u0435\u0432\u044b\u0435 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b, \u043c\u0430\u043f\u044b \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 perf events \u0438 \u0442.\u043f. \u0417\u0434\u0435\u0441\u044c \u043c\u044b \u043e \u043d\u0438\u0445 \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u043d\u0435 \u0431\u0443\u0434\u0435\u043c, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u0443\u0442\u0430\u0442\u044c \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u044f. \u041a\u0440\u043e\u043c\u0435 \u044d\u0442\u043e\u0433\u043e, \u043c\u044b \u0438\u0433\u043d\u043e\u0440\u0438\u0440\u0443\u0435\u043c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438, \u0442\u0430\u043a \u043a\u0430\u043a \u044d\u0442\u043e \u043d\u0435 \u0432\u0430\u0436\u043d\u043e \u0434\u043b\u044f \u043d\u0430\u0448\u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432. \u041f\u043e\u043b\u043d\u044b\u0439 \u0441\u043f\u0438\u0441\u043e\u043a \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432 \u043c\u0430\u043f\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0432 <a href=\"https:\/\/github.com\/torvalds\/linux\/blob\/v5.8-rc7\/include\/uapi\/linux\/bpf.h#L122\" rel=\"nofollow\"><code>&lt;linux\/bpf.h&gt;<\/code><\/a>, \u0430 \u0432 \u044d\u0442\u043e\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u043c\u044b \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u0438\u0441\u0442\u043e\u0440\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0435\u0440\u0432\u044b\u0439 \u0442\u0438\u043f, \u0445\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u0443 <code>BPF_MAP_TYPE_HASH<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0435 \u0445\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u0443, \u0441\u043a\u0430\u0436\u0435\u043c, \u0432 C++, \u0432\u044b \u0441\u043a\u0430\u0436\u0435\u0442\u0435 <code>unordered_map&lt;int,long&gt; woo<\/code>, \u0447\u0442\u043e \u043f\u043e-\u0440\u0443\u0441\u0441\u043a\u0438 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u00ab\u043c\u043d\u0435 \u043d\u0443\u0436\u043d\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 <code>woo<\/code> \u043d\u0435\u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u043e\u0433\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430, \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043a\u043b\u044e\u0447\u0438 \u0438\u043c\u0435\u044e\u0442 \u0442\u0438\u043f <code>int<\/code>, \u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u2014 \u0442\u0438\u043f <code>long<\/code>\u00bb. \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0445\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u0443 BPF \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435, \u0441 \u043f\u043e\u043f\u0440\u0430\u0432\u043a\u043e\u0439 \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u043d\u0430\u043c \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0430 \u0432\u043c\u0435\u0441\u0442\u043e \u0442\u0438\u043f\u043e\u0432 \u043a\u043b\u044e\u0447\u0435\u0439 \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u0438\u0445 \u0440\u0430\u0437\u043c\u0435\u0440\u044b \u0432 \u0431\u0430\u0439\u0442\u0430\u0445. \u0414\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043c\u0430\u043f\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u0430 <code>BPF_MAP_CREATE<\/code> \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 <code>bpf<\/code>. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0431\u043e\u043b\u0435\u0435-\u043c\u0435\u043d\u0435\u0435 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0443\u044e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043e\u0437\u0434\u0430\u0435\u0442 map. \u041f\u043e\u0441\u043b\u0435 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u044e\u0449\u0435\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b BPF, \u044d\u0442\u0430 \u0434\u043e\u043b\u0436\u043d\u0430 \u0432\u0430\u043c \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c\u0441\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0439:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ cat simple-map.c #define _GNU_SOURCE #include &lt;string.h&gt; #include &lt;unistd.h&gt; #include &lt;sys\/syscall.h&gt; #include &lt;linux\/bpf.h&gt;  int main(void) {     union bpf_attr attr = {         .map_type = BPF_MAP_TYPE_HASH,         .key_size = sizeof(int),         .value_size = sizeof(int),         .max_entries = 4,     };     strncpy(attr.map_name, &quot;woo&quot;, sizeof(attr.map_name));     syscall(__NR_bpf, BPF_MAP_CREATE, &amp;attr, sizeof(attr));      for ( ;; )         pause(); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u043d\u0430\u0431\u043e\u0440 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 <code>attr<\/code>, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0433\u043e\u0432\u043e\u0440\u0438\u043c \u00ab\u043c\u043d\u0435 \u043d\u0443\u0436\u043d\u0430 \u0445\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0441 \u043a\u043b\u044e\u0447\u0430\u043c\u0438 \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 <code>sizeof(int)<\/code>, \u0432 \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u044f \u043c\u043e\u0433\u0443 \u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c \u0447\u0435\u0442\u044b\u0440\u0435 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u00bb. \u041f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 BPF \u043c\u0430\u043f\u043e\u0432 \u043c\u043e\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a \u0438 \u0432 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0441 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043e\u0439, \u043c\u044b \u0443\u043a\u0430\u0437\u0430\u043b\u0438 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043a\u0430\u043a <code>&quot;woo&quot;<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0421\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u043c \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ clang -g -O2 simple-map.c -o simple-map $ sudo strace .\/simple-map execve(&quot;.\/simple-map&quot;, [&quot;.\/simple-map&quot;], 0x7ffd40a27070 \/* 14 vars *\/) = 0 ... bpf(BPF_MAP_CREATE, {map_type=BPF_MAP_TYPE_HASH, key_size=4, value_size=4, max_entries=4, map_name=&quot;woo&quot;, ...}, 72) = 3 pause(<\/code><\/pre>\n<p>  <\/p>\n<p>\u0417\u0434\u0435\u0441\u044c \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 <code>bpf(2)<\/code> \u0432\u0435\u0440\u043d\u0443\u043b \u043d\u0430\u043c \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440 \u043c\u0430\u043f\u0430 \u043d\u043e\u043c\u0435\u0440 <code>3<\/code> \u0438 \u0434\u0430\u043b\u044c\u0448\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430, \u043a\u0430\u043a \u0438 \u043e\u0436\u0438\u0434\u0430\u043b\u043e\u0441\u044c, \u0436\u0434\u0435\u0442 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0438\u0445 \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u0439 \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u043c \u0432\u044b\u0437\u043e\u0432\u0435 <code>pause(2)<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u043c \u043d\u0430\u0448\u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0432 background \u0438\u043b\u0438 \u043e\u0442\u043a\u0440\u043e\u0435\u043c \u0434\u0440\u0443\u0433\u043e\u0439 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043d\u0430\u0448 \u043e\u0431\u044a\u0435\u043a\u0442 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0443\u0442\u0438\u043b\u0438\u0442\u044b <code>bpftool<\/code> (\u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043e\u0442\u043b\u0438\u0447\u0438\u0442\u044c \u043d\u0430\u0448 map \u043e\u0442 \u0434\u0440\u0443\u0433\u0438\u0445 \u043f\u043e \u0435\u0433\u043e \u0438\u043c\u0435\u043d\u0438):<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ sudo bpftool map ... 114: hash  name woo  flags 0x0         key 4B  value 4B  max_entries 4  memlock 4096B ...<\/code><\/pre>\n<p>  <\/p>\n<p>\u0427\u0438\u0441\u043b\u043e 114 \u2014 \u044d\u0442\u043e \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u044b\u0439 ID \u043d\u0430\u0448\u0435\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430. \u041b\u044e\u0431\u0430\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u043c\u043e\u0436\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 ID, \u0447\u0442\u043e\u0431\u044b \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 map \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u044b <code>BPF_MAP_GET_FD_BY_ID<\/code> \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 <code>bpf<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u0438\u0433\u0440\u0430\u0442\u044c\u0441\u044f \u0441 \u043d\u0430\u0448\u0435\u0439 \u0445\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0435\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ sudo bpftool map dump id 114 Found 0 elements<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0443\u0441\u0442\u043e. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043b\u043e\u0436\u0438\u043c \u0432 \u043d\u0435\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>hash[1] = 1<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ sudo bpftool map update id 114 key 1 0 0 0 value 1 0 0 0<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0435\u0449\u0435 \u0440\u0430\u0437:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ sudo bpftool map dump id 114 key: 01 00 00 00  value: 01 00 00 00 Found 1 element<\/code><\/pre>\n<p>  <\/p>\n<p>\u0423\u0440\u0430! \u0423 \u043d\u0430\u0441 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043e\u0434\u0438\u043d \u044d\u043b\u0435\u043c\u0435\u043d\u0442. \u0417\u0430\u043c\u0435\u0442\u044c\u0442\u0435, \u0447\u0442\u043e \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u043c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u0431\u0430\u0439\u0442\u043e\u0432, \u0442\u0430\u043a \u043a\u0430\u043a <code>bptftool<\/code> \u043d\u0435 \u0437\u043d\u0430\u0435\u0442 \u043a\u0430\u043a\u043e\u0439 \u0442\u0438\u043f \u0438\u043c\u0435\u044e\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u0445\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u0435. (\u0415\u0439 \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u044d\u0442\u043e \u0437\u043d\u0430\u043d\u0438\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f BTF, \u043d\u043e \u043e\u0431 \u044d\u0442\u043e\u043c \u043d\u0435 \u0441\u0435\u0439\u0447\u0430\u0441.)<\/p>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u0438\u043c\u0435\u043d\u043d\u043e bpftool \u0447\u0438\u0442\u0430\u0435\u0442 \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b? \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0437\u0430\u0433\u043b\u044f\u043d\u0435\u043c \u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ sudo strace -e bpf bpftool map dump id 114 bpf(BPF_MAP_GET_FD_BY_ID, {map_id=114, next_id=0, open_flags=0}, 120) = 3 bpf(BPF_MAP_GET_NEXT_KEY, {map_fd=3, key=NULL, next_key=0x55856ab65280}, 120) = 0 bpf(BPF_MAP_LOOKUP_ELEM, {map_fd=3, key=0x55856ab65280, value=0x55856ab652a0}, 120) = 0 key: 01 00 00 00  value: 01 00 00 00 bpf(BPF_MAP_GET_NEXT_KEY, {map_fd=3, key=0x55856ab65280, next_key=0x55856ab65280}, 120) = -1 ENOENT<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u043e\u0442\u043a\u0440\u044b\u043b\u0438 \u043c\u0430\u043f \u043f\u043e \u0435\u0433\u043e \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u043c\u0443 ID \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u044b <code>BPF_MAP_GET_FD_BY_ID<\/code> \u0438 <code>bpf(2)<\/code> \u0432\u0435\u0440\u043d\u0443\u043b \u043d\u0430\u043c \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440 3. \u0414\u0430\u043b\u044c\u0448\u0435 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u044b <code>BPF_MAP_GET_NEXT_KEY<\/code> \u043c\u044b \u043d\u0430\u0448\u043b\u0438 \u043f\u0435\u0440\u0432\u044b\u0439 \u043a\u043b\u044e\u0447 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435, \u043f\u0435\u0440\u0435\u0434\u0430\u0432 <code>NULL<\/code> \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f \u043d\u0430 \u00ab\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0439\u00bb \u043a\u043b\u044e\u0447. \u041f\u0440\u0438 \u043d\u0430\u043b\u0438\u0447\u0438\u0438 \u043a\u043b\u044e\u0447\u0430 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c <code>BPF_MAP_LOOKUP_ELEM<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c <code>value<\/code>. \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0448\u0430\u0433 \u2014 \u043c\u044b \u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u043d\u0430\u0439\u0442\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u044d\u043b\u0435\u043c\u0435\u043d\u0442, \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u044f \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043a\u043b\u044e\u0447, \u043d\u043e \u043d\u0430\u0448\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u044d\u043b\u0435\u043c\u0435\u043d\u0442 \u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u0430 <code>BPF_MAP_GET_NEXT_KEY<\/code> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 <code>ENOENT<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0425\u043e\u0440\u043e\u0448\u043e, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u043c\u0435\u043d\u044f\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u043a\u043b\u044e\u0447\u0443 1, \u0441\u043a\u0430\u0436\u0435\u043c, \u043d\u0430\u0448\u0430 \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0430 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u0442\u044c <code>hash[1] = 2<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ sudo strace -e bpf bpftool map update id 114 key 1 0 0 0 value 2 0 0 0 bpf(BPF_MAP_GET_FD_BY_ID, {map_id=114, next_id=0, open_flags=0}, 120) = 3 bpf(BPF_MAP_UPDATE_ELEM, {map_fd=3, key=0x55dcd72be260, value=0x55dcd72be280, flags=BPF_ANY}, 120) = 0<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u0438 \u043e\u0436\u0438\u0434\u0430\u043b\u043e\u0441\u044c, \u044d\u0442\u043e \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e: \u043a\u043e\u043c\u0430\u043d\u0434\u0430 <code>BPF_MAP_GET_FD_BY_ID<\/code> \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u043d\u0430\u0448 \u043c\u0430\u043f \u043f\u043e ID, \u0430 \u043a\u043e\u043c\u0430\u043d\u0434\u0430 <code>BPF_MAP_UPDATE_ELEM<\/code> \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u044d\u043b\u0435\u043c\u0435\u043d\u0442.<\/p>\n<p>  <\/p>\n<p>\u0418\u0442\u043e\u0433\u043e, \u043f\u043e\u0441\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0445\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0438\u0437 \u043e\u0434\u043d\u043e\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0447\u0438\u0442\u0430\u0442\u044c \u0438 \u043f\u0438\u0441\u0430\u0442\u044c \u0435\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0438\u0437 \u0434\u0440\u0443\u0433\u043e\u0439. \u0417\u0430\u043c\u0435\u0442\u044c\u0442\u0435, \u0447\u0442\u043e \u0435\u0441\u043b\u0438 \u043c\u044b \u0441\u043c\u043e\u0433\u043b\u0438 \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0438\u0437 \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438, \u0442\u043e \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0438 \u043b\u044e\u0431\u0430\u044f \u0434\u0440\u0443\u0433\u0430\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0435. \u041a\u0440\u043e\u043c\u0435 \u043a\u043e\u043c\u0430\u043d\u0434, \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0445 \u0432\u044b\u0448\u0435, \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043c\u0430\u043f\u0430\u043c\u0438 \u0438\u0437 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b <a href=\"https:\/\/github.com\/torvalds\/linux\/blob\/v5.8-rc7\/include\/uapi\/linux\/bpf.h#L85\" rel=\"nofollow\">\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435<\/a>:<\/p>\n<p>  <\/p>\n<ul>\n<li><code>BPF_MAP_LOOKUP_ELEM<\/code>: \u043d\u0430\u0439\u0442\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u043a\u043b\u044e\u0447\u0443<\/li>\n<li><code>BPF_MAP_UPDATE_ELEM<\/code>: \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c\/\u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435<\/li>\n<li><code>BPF_MAP_DELETE_ELEM<\/code>: \u0443\u0434\u0430\u043b\u0438\u0442\u044c \u043a\u043b\u044e\u0447<\/li>\n<li><code>BPF_MAP_GET_NEXT_KEY<\/code>: \u043d\u0430\u0439\u0442\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 (\u0438\u043b\u0438 \u043f\u0435\u0440\u0432\u044b\u0439) \u043a\u043b\u044e\u0447<\/li>\n<li><code>BPF_MAP_GET_NEXT_ID<\/code>: \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0440\u043e\u0439\u0442\u0438\u0441\u044c \u043f\u043e \u0432\u0441\u0435\u043c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c \u043c\u0430\u043f\u0430\u043c, \u0442\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 <code>bpftool map<\/code><\/li>\n<li><code>BPF_MAP_GET_FD_BY_ID<\/code>: \u043e\u0442\u043a\u0440\u044b\u0442\u044c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043c\u0430\u043f \u043f\u043e \u0435\u0433\u043e \u0433\u043b\u043e\u0431\u0430\u043b\u044c\u043d\u043e\u043c\u0443 ID<\/li>\n<li><code>BPF_MAP_LOOKUP_AND_DELETE_ELEM<\/code>: \u0430\u0442\u043e\u043c\u0430\u0440\u043d\u043e \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0438 \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0441\u0442\u0430\u0440\u043e\u0435<\/li>\n<li><code>BPF_MAP_FREEZE<\/code>: \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043c\u0430\u043f \u043d\u0435\u0438\u0437\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u043c \u0438\u0437 userspace (\u044d\u0442\u0443 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u044e \u043d\u0435\u043b\u044c\u0437\u044f \u043e\u0442\u043c\u0435\u043d\u0438\u0442\u044c)<\/li>\n<li><code>BPF_MAP_LOOKUP_BATCH<\/code>, <code>BPF_MAP_LOOKUP_AND_DELETE_BATCH<\/code>, <code>BPF_MAP_UPDATE_BATCH<\/code>, <code>BPF_MAP_DELETE_BATCH<\/code>: \u043c\u0430\u0441\u0441\u043e\u0432\u044b\u0435 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>BPF_MAP_LOOKUP_AND_DELETE_BATCH<\/code> \u2014\u00a0\u044d\u0442\u043e \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043d\u0430\u0434\u0435\u0436\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u0442\u044c \u0438 \u043e\u0431\u043d\u0443\u043b\u0438\u0442\u044c \u0432\u0441\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437 \u043c\u0430\u043f\u0430<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u041d\u0435 \u0432\u0441\u0435 \u0438\u0437 \u044d\u0442\u0438\u0445 \u043a\u043e\u043c\u0430\u043d\u0434 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0442\u0438\u043f\u043e\u0432 \u043c\u0430\u043f\u043e\u0432, \u043d\u043e \u0432\u043e\u043e\u0431\u0449\u0435 \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u0442\u0438\u043f\u0430\u043c\u0438 maps \u0438\u0437 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u043e\u0447\u043d\u043e \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a \u0438 \u0440\u0430\u0431\u043e\u0442\u0430 \u0441 \u0445\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u0430\u043c\u0438.<\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u043f\u043e\u0440\u044f\u0434\u043a\u0430, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u043c \u043d\u0430\u0448\u0438 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u044b \u0441 \u0445\u044d\u0448-\u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439. \u041f\u043e\u043c\u043d\u0438\u0442\u0435, \u0447\u0442\u043e \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u0443, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c\u0441\u044f \u0434\u043e \u0447\u0435\u0442\u044b\u0440\u0435\u0445 \u043a\u043b\u044e\u0447\u0435\u0439? \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0435\u0449\u0435 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ sudo bpftool map update id 114 key 2 0 0 0 value 1 0 0 0 $ sudo bpftool map update id 114 key 3 0 0 0 value 1 0 0 0 $ sudo bpftool map update id 114 key 4 0 0 0 value 1 0 0 0<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u043a\u0430 \u0432\u0441\u0435 \u0445\u043e\u0440\u043e\u0448\u043e:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ sudo bpftool map dump id 114 key: 01 00 00 00  value: 01 00 00 00 key: 02 00 00 00  value: 01 00 00 00 key: 04 00 00 00  value: 01 00 00 00 key: 03 00 00 00  value: 01 00 00 00 Found 4 elements<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0435\u0449\u0435 \u043e\u0434\u0438\u043d:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ sudo bpftool map update id 114 key 5 0 0 0 value 1 0 0 0 Error: update failed: Argument list too long<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u0438 \u043e\u0436\u0438\u0434\u0430\u043b\u043e\u0441\u044c, \u0443 \u043d\u0430\u0441 \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c. \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043e\u0448\u0438\u0431\u043a\u0443 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ sudo strace -e bpf bpftool map update id 114 key 5 0 0 0 value 1 0 0 0 bpf(BPF_MAP_GET_FD_BY_ID, {map_id=114, next_id=0, open_flags=0}, 120) = 3 bpf(BPF_OBJ_GET_INFO_BY_FD, {info={bpf_fd=3, info_len=80, info=0x7ffe6c626da0}}, 120) = 0 bpf(BPF_MAP_UPDATE_ELEM, {map_fd=3, key=0x56049ded5260, value=0x56049ded5280, flags=BPF_ANY}, 120) = -1 E2BIG (Argument list too long) Error: update failed: Argument list too long +++ exited with 255 +++<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u0441\u0435 \u0432 \u043f\u043e\u0440\u044f\u0434\u043a\u0435: \u043a\u0430\u043a \u0438 \u043e\u0436\u0438\u0434\u0430\u043b\u043e\u0441\u044c, \u043a\u043e\u043c\u0430\u043d\u0434\u0430 <code>BPF_MAP_UPDATE_ELEM<\/code> \u043f\u044b\u0442\u0430\u0435\u0442\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0439, \u043f\u044f\u0442\u044b\u0439, \u043a\u043b\u044e\u0447, \u043d\u043e \u043f\u0430\u0434\u0430\u0435\u0442 \u0441 <code>E2BIG<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0418\u0442\u0430\u043a, \u043c\u044b \u0443\u043c\u0435\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0438 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b BPF, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043c\u0430\u043f\u0430\u043c\u0438 \u0438\u0437 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u0422\u0435\u043f\u0435\u0440\u044c \u043b\u043e\u0433\u0438\u0447\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430 \u0442\u043e, \u043a\u0430\u043a \u0436\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0430\u043f\u044b \u0438\u0437 \u0441\u0430\u043c\u0438\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c BPF. \u041c\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e\u0431 \u044d\u0442\u043e\u043c, \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 \u0442\u0440\u0443\u0434\u043d\u043e-\u0447\u0438\u0442\u0430\u0435\u043c\u044b\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c \u0432 \u043c\u0430\u0448\u0438\u043d\u043d\u044b\u0445 \u043a\u043e\u0434\u0430\u0445-\u043c\u0430\u043a\u0440\u043e\u0441\u0430\u0445, \u043d\u043e \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043f\u0440\u0438\u0448\u043b\u0430 \u043f\u043e\u0440\u0430 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c, \u043a\u0430\u043a \u043f\u0438\u0448\u0443\u0442\u0441\u044f \u0438 \u043e\u0431\u0441\u043b\u0443\u0436\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b BPF \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u2014\u00a0\u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 <code>libbpf<\/code>.<\/p>\n<p>  <\/p>\n<p>(\u0414\u043b\u044f \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u0435\u0439, \u043d\u0435\u0434\u043e\u0432\u043e\u043b\u044c\u043d\u044b\u0445 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435\u043c \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430: \u043c\u044b \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0435 \u043c\u0430\u043f\u044b \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438-\u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a\u0438, \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 <code>libbpf<\/code> \u0438 \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0435\u043c, \u0447\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439. \u0414\u043b\u044f \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u0435\u0439, \u043d\u0435\u0434\u043e\u0432\u043e\u043b\u044c\u043d\u044b\u0445 <em>\u043e\u0447\u0435\u043d\u044c \u0441\u0438\u043b\u044c\u043d\u043e<\/em>, \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 <a href=\"#nolibbpf\">\u043f\u0440\u0438\u043c\u0435\u0440<\/a> \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u043c \u043c\u0435\u0441\u0442\u0435 \u0441\u0442\u0430\u0442\u044c\u0438.)<\/p>\n<p>  <\/p>\n<h3 id=\"hello-libbpf\">\u041f\u0438\u0448\u0435\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b BPF \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e libbpf<\/h3>\n<p>  <\/p>\n<p>\u041f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b BPF \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043c\u0430\u0448\u0438\u043d\u043d\u044b\u0445 \u043a\u043e\u0434\u043e\u0432 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0435\u0440\u0432\u043e\u0435 \u0432\u0440\u0435\u043c\u044f, \u0430 \u043f\u043e\u0442\u043e\u043c \u043d\u0430\u0441\u0442\u0443\u043f\u0430\u0435\u0442 \u043f\u0440\u0435\u0441\u044b\u0449\u0435\u043d\u0438\u0435. \u0412 \u044d\u0442\u043e\u0442 \u043c\u043e\u043c\u0435\u043d\u0442 \u043d\u0443\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0441\u0432\u043e\u0439 \u0432\u0437\u043e\u0440 \u043d\u0430 <code>llvm<\/code>, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0435\u0441\u0442\u044c \u0431\u0430\u043a\u0435\u043d\u0434 \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043a\u043e\u0434\u0430 \u0434\u043b\u044f \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b BPF, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043d\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 <code>libbpf<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0438\u0441\u0430\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0443\u044e \u0447\u0430\u0441\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 BPF \u0438 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u043a\u043e\u0434 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c BPF, \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 <code>llvm<\/code>\/<code>clang<\/code>.<\/p>\n<p>  <\/p>\n<p>\u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435, \u043a\u0430\u043a \u043c\u044b \u0443\u0432\u0438\u0434\u0438\u043c \u0432 \u044d\u0442\u043e\u0439 \u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0441\u0442\u0430\u0442\u044c\u044f\u0445, <code>libbpf<\/code> \u0434\u0435\u043b\u0430\u0435\u0442 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0431\u043e\u0442\u044b \u0438 \u0431\u0435\u0437 \u043d\u0435\u0435 (\u0438\u043b\u0438 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u044b\u0445 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u2014 <code>iproute2<\/code>, <code>libbcc<\/code>, <code>libbpf-go<\/code>, \u0438 \u0442.\u043f.) \u0436\u0438\u0442\u044c \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e. \u041e\u0434\u043d\u043e\u0439 \u0438\u0437 killer-\u0444\u0438\u0447 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 <code>libbpf<\/code> \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f BPF CO-RE (Compile Once, Run Everywhere) \u2014\u00a0\u043f\u0440\u043e\u0435\u043a\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b BPF, \u043f\u0435\u0440\u0435\u043d\u043e\u0441\u0438\u043c\u044b\u0435 \u0441 \u043e\u0434\u043d\u043e\u0433\u043e \u044f\u0434\u0440\u0430 \u043d\u0430 \u0434\u0440\u0443\u0433\u043e\u0435, \u0441 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 API (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u0433\u0434\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u044f\u0434\u0440\u0430 \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043e\u0442 \u0432\u0435\u0440\u0441\u0438\u0438 \u043a \u0432\u0435\u0440\u0441\u0438\u0438). \u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0438\u043c\u0435\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 CO-RE, \u0432\u0430\u0448\u0435 \u044f\u0434\u0440\u043e \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043e \u0441 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u043e\u0439 BTF (\u043a\u0430\u043a \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043c\u044b \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0432 \u0440\u0430\u0437\u0434\u0435\u043b\u0435 <a href=\"#tools\">\u0421\u0440\u0435\u0434\u0441\u0442\u0432\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438<\/a>. \u041f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0441\u043e\u0431\u0440\u0430\u043d\u043e \u043b\u0438 \u0432\u0430\u0448\u0435 \u044f\u0434\u0440\u043e \u0441 BTF \u0438\u043b\u0438 \u043d\u0435\u0442, \u043c\u043e\u0436\u043d\u043e \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e \u2014 \u043f\u043e \u043d\u0430\u043b\u0438\u0447\u0438\u044e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0444\u0430\u0439\u043b\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ ls -lh \/sys\/kernel\/btf\/vmlinux -r--r--r-- 1 root root 2.6M Jul 29 15:30 \/sys\/kernel\/btf\/vmlinux<\/code><\/pre>\n<p>  <\/p>\n<p>\u042d\u0442\u043e\u0442 \u0444\u0430\u0439\u043b \u0445\u0440\u0430\u043d\u0438\u0442 \u0432 \u0441\u0435\u0431\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e\u0431\u043e \u0432\u0441\u0435\u0445 \u0442\u0438\u043f\u0430\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0445 \u0432 \u044f\u0434\u0440\u0435 \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432\u043e \u0432\u0441\u0435\u0445 \u043d\u0430\u0448\u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0445 <code>libbpf<\/code>. \u041c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u0433\u043e\u0432\u043e\u0440\u0438\u0442\u044c \u043f\u0440\u043e CO-RE \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435, \u0430 \u0432 \u044d\u0442\u043e\u0439 \u2014\u00a0\u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u0441\u0442\u0440\u043e\u0439\u0442\u0435 \u0441\u0435\u0431\u0435 \u044f\u0434\u0440\u043e \u0441 <code>CONFIG_DEBUG_INFO_BTF<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 <code>libbpf<\/code> \u0436\u0438\u0432\u0435\u0442 \u043f\u0440\u044f\u043c\u043e \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 <code>tools\/lib\/bpf<\/code> \u044f\u0434\u0440\u0430 \u0438 \u0435\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0432\u0435\u0434\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u0441\u043f\u0438\u0441\u043e\u043a \u0440\u0430\u0441\u0441\u044b\u043b\u043a\u0438 <code>bpf@vger.kernel.org<\/code>. \u041e\u0434\u043d\u0430\u043a\u043e \u0434\u043b\u044f \u043d\u0443\u0436\u0434 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439, \u0436\u0438\u0432\u0443\u0449\u0438\u0445 \u0437\u0430 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u043c\u0438 \u044f\u0434\u0440\u0430, \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 <a href=\"https:\/\/github.com\/libbpf\/libbpf\" rel=\"nofollow\">https:\/\/github.com\/libbpf\/libbpf<\/a> \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u044f\u0434\u0435\u0440\u043d\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0437\u0435\u0440\u043a\u0430\u043b\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043d\u0430 \u0447\u0442\u0435\u043d\u0438\u0435 \u0431\u043e\u043b\u0435\u0435-\u043c\u0435\u043d\u0435\u0435 \u043a\u0430\u043a \u0435\u0441\u0442\u044c.<\/p>\n<p>  <\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u043c\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0442\u043e, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0440\u043e\u0435\u043a\u0442, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0439 <code>libbpf<\/code>, \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e (\u0431\u043e\u043b\u0435\u0435-\u043c\u0435\u043d\u0435\u0435 \u0431\u0435\u0441\u0441\u043c\u044b\u0441\u043b\u0435\u043d\u043d\u044b\u0445) \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0445 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c \u0438 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u043a\u0430\u043a \u0432\u0441\u0435 \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043d\u0430\u043c \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0440\u0430\u0437\u0434\u0435\u043b\u0430\u0445 \u043f\u0440\u043e\u0449\u0435 \u043e\u0431\u044a\u044f\u0441\u043d\u0438\u0442\u044c, \u043a\u0430\u043a \u0438\u043c\u0435\u043d\u043d\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b BPF \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0443\u044e\u0442 \u0441 maps, kernel helpers, BTF, \u0438 \u0442.\u043f.<\/p>\n<p>  <\/p>\n<p>\u041e\u0431\u044b\u0447\u043d\u043e \u043f\u0440\u043e\u0435\u043a\u0442\u044b, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u0435 <code>libbpf<\/code> \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0442 \u0433\u0438\u0442\u0445\u0430\u0431\u043e\u0432\u0441\u043a\u0438\u0439 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0439 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 git submodule, \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u044d\u0442\u043e \u0438 \u043c\u044b:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ mkdir \/tmp\/libbpf-example $ cd \/tmp\/libbpf-example\/ $ git init-db Initialized empty Git repository in \/tmp\/libbpf-example\/.git\/ $ git submodule add https:\/\/github.com\/libbpf\/libbpf.git Cloning into '\/tmp\/libbpf-example\/libbpf'... remote: Enumerating objects: 200, done. remote: Counting objects: 100% (200\/200), done. remote: Compressing objects: 100% (103\/103), done. remote: Total 3354 (delta 101), reused 118 (delta 79), pack-reused 3154 Receiving objects: 100% (3354\/3354), 2.05 MiB | 10.22 MiB\/s, done. Resolving deltas: 100% (2176\/2176), done.<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u043e\u0431\u0438\u0440\u0430\u0435\u0442\u0441\u044f <code>libbpf<\/code> \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ cd libbpf\/src $ mkdir build $ OBJDIR=build DESTDIR=root make -s install $ find root root root\/usr root\/usr\/include root\/usr\/include\/bpf root\/usr\/include\/bpf\/bpf_tracing.h root\/usr\/include\/bpf\/xsk.h root\/usr\/include\/bpf\/libbpf_common.h root\/usr\/include\/bpf\/bpf_endian.h root\/usr\/include\/bpf\/bpf_helpers.h root\/usr\/include\/bpf\/btf.h root\/usr\/include\/bpf\/bpf_helper_defs.h root\/usr\/include\/bpf\/bpf.h root\/usr\/include\/bpf\/libbpf_util.h root\/usr\/include\/bpf\/libbpf.h root\/usr\/include\/bpf\/bpf_core_read.h root\/usr\/lib64 root\/usr\/lib64\/libbpf.so.0.1.0 root\/usr\/lib64\/libbpf.so.0 root\/usr\/lib64\/libbpf.a root\/usr\/lib64\/libbpf.so root\/usr\/lib64\/pkgconfig root\/usr\/lib64\/pkgconfig\/libbpf.pc<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u0430\u0448 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0438\u0439 \u043f\u043b\u0430\u043d \u0432 \u044d\u0442\u043e\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c: \u043c\u044b \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 BPF \u0442\u0438\u043f\u0430 <code>BPF_PROG_TYPE_XDP<\/code>, \u0442\u0443 \u0436\u0435 \u0441\u0430\u043c\u0443\u044e, \u0447\u0442\u043e \u0438 \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435, \u043d\u043e \u043d\u0430 C, \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u043c \u0435\u0435 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 <code>clang<\/code>, \u0438 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443-\u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0435\u0435 \u0432 \u044f\u0434\u0440\u043e. \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0440\u0430\u0437\u0434\u0435\u043b\u0430\u0445 \u043c\u044b \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043a\u0430\u043a \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b BPF, \u0442\u0430\u043a \u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b-\u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a\u0430.<\/p>\n<p>  <\/p>\n<h4>\u041f\u0440\u0438\u043c\u0435\u0440: \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 libbpf<\/h4>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0444\u0430\u0439\u043b <code>\/sys\/kernel\/btf\/vmlinux<\/code>, \u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0433\u043e\u0432\u043e\u0440\u0438\u043b\u043e\u0441\u044c \u0432\u044b\u0448\u0435, \u0438 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0435\u0433\u043e \u044d\u043a\u0432\u0438\u0432\u0430\u043b\u0435\u043d\u0442 \u0432 \u0432\u0438\u0434\u0435 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u0447\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ bpftool btf dump file \/sys\/kernel\/btf\/vmlinux format c &gt; vmlinux.h<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0444\u0430\u0439\u043b\u0435 \u0431\u0443\u0434\u0443\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u0441\u044f \u0432\u0441\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u0438\u043c\u0435\u044e\u0449\u0438\u0435\u0441\u044f \u0432 \u043d\u0430\u0448\u0435\u043c \u044f\u0434\u0440\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u043e\u0442 \u0442\u0430\u043a \u0432 \u044f\u0434\u0440\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a IPv4:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ grep -A 12 'struct iphdr {' vmlinux.h struct iphdr {     __u8 ihl: 4;     __u8 version: 4;     __u8 tos;     __be16 tot_len;     __be16 id;     __be16 frag_off;     __u8 ttl;     __u8 protocol;     __sum16 check;     __be32 saddr;     __be32 daddr; };<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043d\u0430\u0448\u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 BPF \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 C:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ cat xdp-simple.bpf.c #include &quot;vmlinux.h&quot; #include &lt;bpf\/bpf_helpers.h&gt;  SEC(&quot;xdp\/simple&quot;) int simple(void *ctx) {         return XDP_PASS; }  char LICENSE[] SEC(&quot;license&quot;) = &quot;GPL&quot;;<\/code><\/pre>\n<p>  <\/p>\n<p>\u0425\u043e\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0443 \u043d\u0430\u0441 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0430\u0441\u044c \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u0430\u044f, \u043d\u043e \u0432\u0441\u0435 \u0436\u0435 \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u043d\u0430 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0434\u0435\u0442\u0430\u043b\u0435\u0439. \u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u043f\u0435\u0440\u0432\u044b\u043c \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u0447\u043d\u044b\u043c \u0444\u0430\u0439\u043b\u043e\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <code>vmlinux.h<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0442\u043e \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 <code>bpftool btf dump<\/code> \u2014\u00a0\u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u043f\u0430\u043a\u0435\u0442 kernel-headers, \u0447\u0442\u043e\u0431\u044b \u0443\u0437\u043d\u0430\u0442\u044c, \u043a\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u044f\u0434\u0440\u0430. \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u0447\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u043a \u043d\u0430\u043c \u0438\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 <code>libbpf<\/code>. \u0421\u0435\u0439\u0447\u0430\u0441 \u043e\u043d \u043d\u0430\u043c \u043d\u0443\u0436\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043b\u0441\u044f \u043c\u0430\u043a\u0440\u043e\u0441 <code>SEC<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u0438\u043c\u0432\u043e\u043b \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e \u0441\u0435\u043a\u0446\u0438\u044e \u043e\u0431\u044a\u0435\u043a\u0442\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 ELF. \u041d\u0430\u0448\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f \u0432 \u0441\u0435\u043a\u0446\u0438\u0438 <code>xdp\/simple<\/code>, \u0433\u0434\u0435 \u043f\u0435\u0440\u0435\u0434 \u0441\u043b\u044d\u0448\u0435\u043c \u043c\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0442\u0438\u043f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b BPF \u2014\u00a0\u044d\u0442\u043e \u0441\u043e\u0433\u043b\u0430\u0448\u0435\u043d\u0438\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u043e\u0435 \u0432 <code>libbpf<\/code>, \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u0441\u0435\u043a\u0446\u0438\u0438 \u043e\u043d\u0430 \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u0438\u0442 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u0442\u0438\u043f \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 <code>bpf(2)<\/code>. \u0421\u0430\u043c\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 BPF \u043d\u0430 <code>C<\/code> \u2014\u00a0\u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u0438 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u0447\u043a\u0438 <code>return XDP_PASS<\/code>. \u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0430\u044f \u0441\u0435\u043a\u0446\u0438\u044f <code>&quot;license&quot;<\/code> \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043b\u0438\u0446\u0435\u043d\u0437\u0438\u0438.<\/p>\n<p>  <\/p>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0448\u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 llvm\/clang, \u0432\u0435\u0440\u0441\u0438\u0438 &gt;= 10.0.0, \u0430 \u043b\u0443\u0447\u0448\u0435 \u2014\u00a0\u0431\u043e\u043b\u044c\u0448\u0435 (\u0441\u043c. \u0440\u0430\u0437\u0434\u0435\u043b <a href=\"#tools\">\u0421\u0440\u0435\u0434\u0441\u0442\u0432\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438<\/a>):<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ clang --version clang version 11.0.0 (https:\/\/github.com\/llvm\/llvm-project.git afc287e0abec710398465ee1f86237513f2b5091) ...  $ clang -O2 -g -c -target bpf -I libbpf\/src\/root\/usr\/include xdp-simple.bpf.c -o xdp-simple.bpf.o<\/code><\/pre>\n<p>  <\/p>\n<p>\u0418\u0437 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0445 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0435\u0439: \u043c\u044b \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0446\u0435\u043b\u0435\u0432\u0443\u044e \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443 <code>-target bpf<\/code> \u0438 \u043f\u0443\u0442\u044c \u043a \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430\u043c <code>libbpf<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u043d\u0435\u0434\u0430\u0432\u043d\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b\u0438. \u0422\u0430\u043a\u0436\u0435, \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u043e <code>-O2<\/code>, \u0431\u0435\u0437 \u044d\u0442\u043e\u0439 \u043e\u043f\u0446\u0438\u0438 \u0432\u0430\u0441 \u043c\u043e\u0433\u0443\u0442 \u043e\u0436\u0438\u0434\u0430\u0442\u044c \u0441\u044e\u0440\u043f\u0440\u0438\u0437\u044b \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c. \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043d\u0430\u0448 \u043a\u043e\u0434, \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u043b\u0438 \u0443 \u043d\u0430\u0441 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u0445\u043e\u0442\u0435\u043b\u0438?<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ llvm-objdump --section=xdp\/simple --no-show-raw-insn -D xdp-simple.bpf.o  xdp-simple.bpf.o:       file format elf64-bpf  Disassembly of section xdp\/simple:  0000000000000000 &lt;simple&gt;:        0:       r0 = 2        1:       exit<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u0430, \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c! \u0422\u0435\u043f\u0435\u0440\u044c, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u0441 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043e\u0439, \u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u0443\u0434\u0435\u0442 \u0435\u0433\u043e \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0432 \u044f\u0434\u0440\u043e. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 <code>libbpf<\/code> \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u0442 \u043d\u0430\u043c \u0434\u0432\u0430 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u2014\u00a0\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u043e\u0435 API \u0438\u043b\u0438 \u0431\u043e\u043b\u0435\u0435 \u0432\u044b\u0441\u043e\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u043e\u0435 API. \u041c\u044b \u043f\u043e\u0439\u0434\u0435\u043c \u0432\u0442\u043e\u0440\u044b\u043c \u043f\u0443\u0442\u0435\u043c, \u0442\u0430\u043a \u043a\u0430\u043a \u043d\u0430\u043c \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u043d\u0430\u0443\u0447\u0438\u0442\u044c\u0441\u044f \u043f\u0438\u0441\u0430\u0442\u044c, \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0438 \u043f\u043e\u0434\u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b BPF \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0443\u0441\u0438\u043b\u0438\u044f\u043c\u0438 \u0434\u043b\u044f \u0438\u0445 \u043f\u043e\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u00ab\u0441\u043a\u0435\u043b\u0435\u0442\u00bb \u043d\u0430\u0448\u0435\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0438\u0437 \u0435\u0435 \u0431\u0438\u043d\u0430\u0440\u043d\u0438\u043a\u0430 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0432\u0441\u0435 \u0442\u043e\u0439 \u0436\u0435 \u0443\u0442\u0438\u043b\u0438\u0442\u044b <code>bpftool<\/code> \u2014\u00a0\u0448\u0432\u0435\u0439\u0446\u0430\u0440\u0441\u043a\u043e\u0433\u043e \u043d\u043e\u0436\u0430 \u043c\u0438\u0440\u0430 BPF (\u0447\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c \u0438 \u0431\u0443\u043a\u0432\u0430\u043b\u044c\u043d\u043e, \u0442\u0430\u043a \u043a\u0430\u043a Daniel Borkman \u2014 \u043e\u0434\u0438\u043d \u0438\u0437 \u0441\u043e\u0437\u0434\u0430\u0442\u0435\u043b\u0435\u0439 \u0438 \u043c\u0430\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u043e\u0432 BPF \u2014\u00a0\u0448\u0432\u0435\u0439\u0446\u0430\u0440\u0435\u0446):<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ bpftool gen skeleton xdp-simple.bpf.o &gt; xdp-simple.skel.h<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u0444\u0430\u0439\u043b\u0435 <code>xdp-simple.skel.h<\/code> \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0439 \u043a\u043e\u0434 \u043d\u0430\u0448\u0435\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u2014\u00a0\u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438, \u043f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f, \u0443\u0434\u0430\u043b\u0435\u043d\u0438\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430. \u0412 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043a\u0430\u043a overkill, \u043d\u043e \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0438 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435, \u043a\u043e\u0433\u0434\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c BPF \u0438 \u043c\u0430\u043f\u043e\u0432 \u0438 \u0434\u043b\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u044d\u0442\u043e\u0433\u043e \u0433\u0438\u0433\u0430\u043d\u0442\u0441\u043a\u043e\u0433\u043e ELF \u043d\u0430\u043c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043b\u0438\u0448\u044c \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u043a\u0435\u043b\u0435\u0442 \u0438 \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u043e\u0434\u043d\u0443-\u0434\u0432\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0438\u0437 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043a \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043c\u044b \u0441\u0435\u0439\u0447\u0430\u0441 \u0438 \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c.<\/p>\n<p>  <\/p>\n<p>\u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0433\u043e\u0432\u043e\u0440\u044f, \u043d\u0430\u0448\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430-\u0437\u0430\u0433\u0440\u0443\u0437\u0447\u0438\u043a \u2014\u00a0\u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u0430\u044f:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">#include &lt;err.h&gt; #include &lt;unistd.h&gt; #include &quot;xdp-simple.skel.h&quot;  int main(int argc, char **argv) {     struct xdp_simple_bpf *obj;      obj = xdp_simple_bpf__open_and_load();     if (!obj)         err(1, &quot;failed to open and\/or load BPF object\\n&quot;);      pause();      xdp_simple_bpf__destroy(obj); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0417\u0434\u0435\u0441\u044c <code>struct xdp_simple_bpf<\/code> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u0444\u0430\u0439\u043b\u0435 <code>xdp-simple.skel.h<\/code> \u0438 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u043d\u0430\u0448 \u043e\u0431\u044a\u0435\u043a\u0442\u043d\u044b\u0439 \u0444\u0430\u0439\u043b:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">struct xdp_simple_bpf {     struct bpf_object_skeleton *skeleton;     struct bpf_object *obj;     struct {         struct bpf_program *simple;     } progs;     struct {         struct bpf_link *simple;     } links; };<\/code><\/pre>\n<p>  <\/p>\n<p>\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c \u0442\u0443\u0442 \u0441\u043b\u0435\u0434\u044b \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0433\u043e API: \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 <code>struct bpf_program *simple<\/code> \u0438 <code>struct bpf_link *simple<\/code>. \u041f\u0435\u0440\u0432\u0430\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e \u043d\u0430\u0448\u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443, \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u0443\u044e \u0432 \u0441\u0435\u043a\u0446\u0438\u0438 <code>xdp\/simple<\/code>, \u0430 \u0432\u0442\u043e\u0440\u0430\u044f \u2014\u00a0\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0442\u043e, \u043a\u0430\u043a \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043f\u043e\u0434\u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0435\u0442\u0441\u044f \u043a \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0443 \u0441\u043e\u0431\u044b\u0442\u0438\u0439.<\/p>\n<p>  <\/p>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>xdp_simple_bpf__open_and_load<\/code>, \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442 ELF, \u043f\u0430\u0440\u0441\u0438\u0442 \u0435\u0433\u043e, \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0432\u0441\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0438 \u043f\u043e\u0434\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b (\u043a\u0440\u043e\u043c\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0432 ELF \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u0441\u0435\u043a\u0446\u0438\u0438 \u2014\u00a0data, readonly data, \u043e\u0442\u043b\u0430\u0434\u043e\u0447\u043d\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f, \u043b\u0438\u0446\u0435\u043d\u0437\u0438\u044f \u0438 \u0442.\u043f.), \u0430 \u043f\u043e\u0442\u043e\u043c \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442 \u0432 \u044f\u0434\u0440\u043e \u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u043e\u043c \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 <code>bpf<\/code>, \u0447\u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0432 \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ clang -O2 -I .\/libbpf\/src\/root\/usr\/include\/ xdp-simple.c -o xdp-simple .\/libbpf\/src\/root\/usr\/lib64\/libbpf.a -lelf -lz  $ sudo strace -e bpf .\/xdp-simple ... bpf(BPF_BTF_LOAD, 0x7ffdb8fd9670, 120)  = 3 bpf(BPF_PROG_LOAD, {prog_type=BPF_PROG_TYPE_XDP, insn_cnt=2, insns=0xdfd580, license=&quot;GPL&quot;, log_level=0, log_size=0, log_buf=NULL, kern_version=KERNEL_VERSION(5, 8, 0), prog_flags=0, prog_name=&quot;simple&quot;, prog_ifindex=0, expected_attach_type=0x25 \/* BPF_??? *\/, ...}, 120) = 4<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043d\u0430\u0448\u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 <code>bpftool<\/code>. \u041d\u0430\u0439\u0434\u0435\u043c \u0435\u0435 ID:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\"># bpftool p | grep -A4 simple 463: xdp  name simple  tag 3b185187f1855c4c  gpl         loaded_at 2020-08-01T01:59:49+0000  uid 0         xlated 16B  jited 40B  memlock 4096B         btf_id 185         pids xdp-simple(16498)<\/code><\/pre>\n<p>  <\/p>\n<p>\u0438 \u0441\u0434\u0430\u043c\u043f\u0438\u043c (\u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u043e\u043a\u0440\u0430\u0449\u0435\u043d\u043d\u044b\u0439 \u0432\u0438\u0434 \u043a\u043e\u043c\u0430\u043d\u0434\u044b <code>bpftool prog dump xlated<\/code>):<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\"># bpftool p d x id 463 int simple(void *ctx): ; return XDP_PASS;    0: (b7) r0 = 2    1: (95) exit<\/code><\/pre>\n<p>  <\/p>\n<p>\u0427\u0442\u043e-\u0442\u043e \u043d\u043e\u0432\u043e\u0435! \u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043d\u0430\u043f\u0435\u0447\u0430\u0442\u0430\u043b\u0430 \u043a\u0443\u0441\u043a\u0438 \u043d\u0430\u0448\u0435\u0433\u043e \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 C. \u042d\u0442\u043e \u0431\u044b\u043b\u043e \u043f\u0440\u043e\u0434\u0435\u043b\u0430\u043d\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 <code>libbpf<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0430\u0448\u043b\u0430 \u043e\u0442\u043b\u0430\u0434\u043e\u0447\u043d\u0443\u044e \u0441\u0435\u043a\u0446\u0438\u044e \u0432 \u0431\u0438\u043d\u0430\u0440\u043d\u0438\u043a\u0435, \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043b\u0430 \u0435\u0435 \u0432 \u043e\u0431\u044a\u0435\u043a\u0442 BTF, \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u043b\u0430 \u0435\u0433\u043e \u0432 \u044f\u0434\u0440\u043e \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 <code>BPF_BTF_LOAD<\/code>, \u0430 \u043f\u043e\u0442\u043e\u043c \u0443\u043a\u0430\u0437\u0430\u043b\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u0444\u0430\u0439\u043b\u043e\u0432\u044b\u0439 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440 \u043f\u0440\u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 <code>BPG_PROG_LOAD<\/code>.<\/p>\n<p>  <\/p>\n<h3 id=\"kernel-helpers\">Kernel Helpers<\/h3>\n<p>  <\/p>\n<p>\u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b BPF \u043c\u043e\u0433\u0443\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u00ab\u0432\u043d\u0435\u0448\u043d\u0438\u0435\u00bb \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u2014\u00a0kernel helpers. \u042d\u0442\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438-\u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a\u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430\u043c BPF \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430\u043c \u044f\u0434\u0440\u0430, \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c maps, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043e\u0431\u0449\u0430\u0442\u044c\u0441\u044f \u0441 \u00ab\u0440\u0435\u0430\u043b\u044c\u043d\u044b\u043c \u043c\u0438\u0440\u043e\u043c\u00bb \u2014\u00a0\u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c perf events, \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043e\u0431\u043e\u0440\u0443\u0434\u043e\u0432\u0430\u043d\u0438\u0435\u043c (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0435\u0440\u0435\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043f\u0430\u043a\u0435\u0442\u044b) \u0438 \u0442.\u043f.<\/p>\n<p>  <\/p>\n<h4>\u041f\u0440\u0438\u043c\u0435\u0440: bpf_get_smp_processor_id<\/h4>\n<p>  <\/p>\n<p>\u0412 \u0440\u0430\u043c\u043a\u0430\u0445 \u043f\u0430\u0440\u0430\u0434\u0438\u0433\u043c\u044b \u00ab\u0443\u0447\u0438\u043c\u0441\u044f \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u0445\u00bb, \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043e\u0434\u043d\u0443 \u0438\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u0439-\u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a\u043e\u0432, <code>bpf_get_smp_processor_id()<\/code>, <a href=\"https:\/\/github.com\/torvalds\/linux\/blob\/v5.8-rc7\/kernel\/bpf\/helpers.c#L124\" rel=\"nofollow\">\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u0443\u044e<\/a> \u0432 \u0444\u0430\u0439\u043b\u0435 <code>kernel\/bpf\/helpers.c<\/code>. \u041e\u043d\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043d\u043e\u043c\u0435\u0440 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0432\u044b\u0437\u0432\u0430\u0432\u0448\u0430\u044f \u0435\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 BPF. \u041d\u043e \u043d\u0430\u0441 \u043d\u0435 \u0442\u0430\u043a \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442 \u0435\u0435 \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u043a\u0430, \u043a\u0430\u043a \u0442\u043e, \u0447\u0442\u043e \u0435\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u043e\u0434\u043d\u0443 \u0441\u0442\u0440\u043e\u0447\u043a\u0443:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">BPF_CALL_0(bpf_get_smp_processor_id) {     return smp_processor_id(); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439-\u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a\u043e\u0432 BPF \u043f\u043e\u0445\u043e\u0436\u0438 \u043d\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 Linux. \u0417\u0434\u0435\u0441\u044c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043d\u0435 \u0438\u043c\u0435\u044e\u0449\u0430\u044f \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432. (\u0424\u0443\u043d\u043a\u0446\u0438\u044f, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0430\u044f, \u0441\u043a\u0430\u0436\u0435\u043c, \u0442\u0440\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043c\u0430\u043a\u0440\u043e\u0441\u0430 <code>BPF_CALL_3<\/code>. \u041c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0440\u0430\u0432\u043d\u043e \u043f\u044f\u0442\u0438.) \u041e\u0434\u043d\u0430\u043a\u043e, \u044d\u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0435\u0440\u0432\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f. \u0412\u0442\u043e\u0440\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0442\u0438\u043f\u0430 <code>struct bpf_func_proto<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438-\u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a\u0430, \u043f\u043e\u043d\u044f\u0442\u043d\u043e\u0435 verifier:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">const struct bpf_func_proto bpf_get_smp_processor_id_proto = {     .func     = bpf_get_smp_processor_id,     .gpl_only = false,     .ret_type = RET_INTEGER, };<\/code><\/pre>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439-\u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a\u043e\u0432<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b BPF \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u043c\u043e\u0433\u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043e\u043d\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0437\u0430\u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0435\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f \u0442\u0438\u043f\u0430 <code>BPF_PROG_TYPE_XDP<\/code> \u0432 \u044f\u0434\u0440\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>xdp_func_proto<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e ID \u0444\u0443\u043d\u043a\u0446\u0438\u0438-\u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442, \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043b\u0438 XDP \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0438\u043b\u0438 \u043d\u0435\u0442. \u041d\u0430\u0448\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043e\u043d\u0430 <a href=\"https:\/\/github.com\/torvalds\/linux\/blob\/v5.8-rc7\/net\/core\/filter.c#L6423\" rel=\"nofollow\">\u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442<\/a>:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">static const struct bpf_func_proto * xdp_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) {     switch (func_id) {     ...     case BPF_FUNC_get_smp_processor_id:         return &amp;bpf_get_smp_processor_id_proto;     ...     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u043e\u0432\u044b\u0435 \u0442\u0438\u043f\u044b \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c BPF \u00ab\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f\u00bb \u0432 \u0444\u0430\u0439\u043b\u0435 <a href=\"https:\/\/github.com\/torvalds\/linux\/blob\/v5.8-rc7\/include\/linux\/bpf_types.h\" rel=\"nofollow\"><code>include\/linux\/bpf_types.h<\/code><\/a> \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043c\u0430\u043a\u0440\u043e\u0441\u0430 <code>BPF_PROG_TYPE<\/code>. \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u0432\u0437\u044f\u0442\u043e \u0432 \u043a\u0430\u0432\u044b\u0447\u043a\u0438, \u0442\u0430\u043a \u043a\u0430\u043a \u044d\u0442\u043e \u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435, \u0430 \u0432 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u0445 \u044f\u0437\u044b\u043a\u0430 C \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0446\u0435\u043b\u043e\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u0430 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u043c\u0435\u0441\u0442\u0430\u0445. \u0412 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u0432 \u0444\u0430\u0439\u043b\u0435 <code>kernel\/bpf\/verifier.c<\/code> \u0432\u0441\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 <code>bpf_types.h<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f, \u0447\u0442\u043e\u0431\u044b \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440 <code>bpf_verifier_ops[]<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">static const struct bpf_verifier_ops *const bpf_verifier_ops[] = { #define BPF_PROG_TYPE(_id, _name, prog_ctx_type, kern_ctx_type) \\     [_id] = &amp; _name ## _verifier_ops, #include &lt;linux\/bpf_types.h&gt; #undef BPF_PROG_TYPE };<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u043e \u0435\u0441\u0442\u044c, \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c BPF \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u0442\u0438\u043f\u0430 <code>struct bpf_verifier_ops<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c <code>_name ## _verifier_ops<\/code>, \u0442.\u0435., <code>xdp_verifier_ops<\/code> \u0434\u043b\u044f <code>xdp<\/code>. \u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 <code>xdp_verifier_ops<\/code> <a href=\"https:\/\/github.com\/torvalds\/linux\/blob\/v5.8-rc7\/net\/core\/filter.c#L8761\" rel=\"nofollow\">\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f<\/a> \u0432 \u0444\u0430\u0439\u043b\u0435 <code>net\/core\/filter.c<\/code> \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">const struct bpf_verifier_ops xdp_verifier_ops = {     .get_func_proto     = xdp_func_proto,     .is_valid_access    = xdp_is_valid_access,     .convert_ctx_access = xdp_convert_ctx_access,     .gen_prologue       = bpf_noop_prologue, };<\/code><\/pre>\n<p>  <\/p>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0438 \u0432\u0438\u0434\u0438\u043c \u043d\u0430\u0448\u0443 \u0437\u043d\u0430\u043a\u043e\u043c\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>xdp_func_proto<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c\u0441\u044f verifier \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437, \u043a\u0430\u043a \u043e\u043d \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u0442 \u0432\u044b\u0437\u043e\u0432 <em>\u043a\u0430\u043a\u043e\u0439-\u0442\u043e<\/em> \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b BPF, \u0441\u043c. <a href=\"https:\/\/github.com\/torvalds\/linux\/blob\/v5.8-rc7\/kernel\/bpf\/verifier.c#L4611-L4617\" rel=\"nofollow\"><code>verifier.c<\/code><\/a>.<\/p>\n<\/div><\/div>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0442\u043e, \u043a\u0430\u043a \u0433\u0438\u043f\u043e\u0442\u0435\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 BPF \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>bpf_get_smp_processor_id<\/code>. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u043f\u0438\u0448\u0435\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0438\u0437 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u0440\u0430\u0437\u0434\u0435\u043b\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">#include &quot;vmlinux.h&quot; #include &lt;bpf\/bpf_helpers.h&gt;  SEC(&quot;xdp\/simple&quot;) int simple(void *ctx) {     if (bpf_get_smp_processor_id() != 0)         return XDP_DROP;     return XDP_PASS; }  char LICENSE[] SEC(&quot;license&quot;) = &quot;GPL&quot;;<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u0438\u043c\u0432\u043e\u043b <code>bpf_get_smp_processor_id<\/code> <a href=\"https:\/\/github.com\/libbpf\/libbpf\/blob\/master\/src\/bpf_helper_defs.h\" rel=\"nofollow\">\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f<\/a> \u0432 <code>&lt;bpf\/bpf_helper_defs.h&gt;<\/code> \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 <code>libbpf<\/code> \u043a\u0430\u043a<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">static u32 (*bpf_get_smp_processor_id)(void) = (void *) 8;<\/code><\/pre>\n<p>  <\/p>\n<p>\u0442\u043e \u0435\u0441\u0442\u044c, <code>bpf_get_smp_processor_id<\/code> \u2014 \u044d\u0442\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0440\u0430\u0432\u043d\u043e 8, \u0433\u0434\u0435 8 \u2014\u00a0\u044d\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>BPF_FUNC_get_smp_processor_id<\/code> \u0442\u0438\u043f\u0430 <code>enum bpf_fun_id<\/code>, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043d\u0430\u0441 \u0432 \u0444\u0430\u0439\u043b\u0435 <code>vmlinux.h<\/code> (\u0444\u0430\u0439\u043b <code>bpf_helper_defs.h<\/code> \u0432 \u044f\u0434\u0440\u0435 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0441\u043a\u0440\u0438\u043f\u0442\u043e\u043c, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u00ab\u043c\u0430\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0435\u00bb \u0447\u0438\u0441\u043b\u0430 \u2014\u00a0\u044d\u0442\u043e ok). \u042d\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043d\u0435 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0442\u0438\u043f\u0430 <code>__u32<\/code>. \u041a\u043e\u0433\u0434\u0430 \u043c\u044b \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0435\u0435 \u0432 \u043d\u0430\u0448\u0435\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435, <code>clang<\/code> \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e <code>BPF_CALL<\/code> \u00ab\u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0433\u043e \u0432\u0438\u0434\u0430\u00bb. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0441\u0435\u043a\u0446\u0438\u044e <code>xdp\/simple<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ clang -O2 -g -c -target bpf -I libbpf\/src\/root\/usr\/include xdp-simple.bpf.c -o xdp-simple.bpf.o $ llvm-objdump -D --section=xdp\/simple xdp-simple.bpf.o  xdp-simple.bpf.o:       file format elf64-bpf  Disassembly of section xdp\/simple:  0000000000000000 &lt;simple&gt;:        0:       85 00 00 00 08 00 00 00 call 8        1:       bf 01 00 00 00 00 00 00 r1 = r0        2:       67 01 00 00 20 00 00 00 r1 &lt;&lt;= 32        3:       77 01 00 00 20 00 00 00 r1 &gt;&gt;= 32        4:       b7 00 00 00 02 00 00 00 r0 = 2        5:       15 01 01 00 00 00 00 00 if r1 == 0 goto +1 &lt;LBB0_2&gt;        6:       b7 00 00 00 01 00 00 00 r0 = 1  0000000000000038 &lt;LBB0_2&gt;:        7:       95 00 00 00 00 00 00 00 exit<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u0436\u0435 \u0441\u0442\u0440\u043e\u0447\u043a\u0435 \u043c\u044b \u0432\u0438\u0434\u0438\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e <code>call<\/code>, \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 <code>IMM<\/code> \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0440\u0430\u0432\u0435\u043d 8, \u0430 <code>SRC_REG<\/code> \u2014 \u043d\u0443\u043b\u044e. \u041f\u043e ABI-\u0441\u043e\u0433\u043b\u0430\u0448\u0435\u043d\u0438\u044e, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u043e\u043c\u0443 verifier, \u044d\u0442\u043e \u0438 \u0435\u0441\u0442\u044c \u0432\u044b\u0437\u043e\u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u0438-\u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a\u0430 \u043f\u043e\u0434 \u043d\u043e\u043c\u0435\u0440\u043e\u043c \u0432\u043e\u0441\u0435\u043c\u044c. \u041f\u043e\u0441\u043b\u0435 \u0435\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043b\u043e\u0433\u0438\u043a\u0430 \u043f\u0440\u043e\u0441\u0442\u0430\u044f. \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0438\u0437 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430 <code>r0<\/code> \u043a\u043e\u043f\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432 <code>r1<\/code> \u0438 \u043d\u0430 \u0441\u0442\u0440\u043e\u0447\u043a\u0430\u0445 2,3 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043a \u0442\u0438\u043f\u0443 <code>u32<\/code> \u2014 \u0432\u0435\u0440\u0445\u043d\u0438\u0435 32 \u0431\u0438\u0442\u0430 \u043e\u0431\u043d\u0443\u043b\u044f\u044e\u0442\u0441\u044f. \u041d\u0430 \u0441\u0442\u0440\u043e\u0447\u043a\u0430\u0445 4,5,6,7 \u043c\u044b \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c 2 (<code>XDP_PASS<\/code>) \u0438\u043b\u0438 1 (<code>XDP_DROP<\/code>) \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u043e\u0433\u043e, \u0432\u0435\u0440\u043d\u0443\u043b\u0430 \u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f-\u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a \u0441\u043e \u0441\u0442\u0440\u043e\u0447\u043a\u0438 0 \u043d\u0443\u043b\u0435\u0432\u043e\u0435 \u0438\u043b\u0438 \u043d\u0435\u043d\u0443\u043b\u0435\u0432\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435.<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u0438\u043c \u0441\u0435\u0431\u044f: \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0432\u044b\u0432\u043e\u0434 <code>bpftool prog dump xlated<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ bpftool gen skeleton xdp-simple.bpf.o &gt; xdp-simple.skel.h $ clang -O2 -g -I .\/libbpf\/src\/root\/usr\/include\/ -o xdp-simple xdp-simple.c .\/libbpf\/src\/root\/usr\/lib64\/libbpf.a -lelf -lz $ sudo .\/xdp-simple &amp; [2] 10914  $ sudo bpftool p | grep simple 523: xdp  name simple  tag 44c38a10c657e1b0  gpl         pids xdp-simple(10915)  $ sudo bpftool p d x id 523 int simple(void *ctx): ; if (bpf_get_smp_processor_id() != 0)    0: (85) call bpf_get_smp_processor_id#114128    1: (bf) r1 = r0    2: (67) r1 &lt;&lt;= 32    3: (77) r1 &gt;&gt;= 32    4: (b7) r0 = 2 ; }    5: (15) if r1 == 0x0 goto pc+1    6: (b7) r0 = 1    7: (95) exit<\/code><\/pre>\n<p>  <\/p>\n<p>\u0425\u043e\u0440\u043e\u0448\u043e, verifier \u043d\u0430\u0448\u0435\u043b \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 kernel-helper.<\/p>\n<p>  <\/p>\n<h4 id=\"helpers-with-args\">\u041f\u0440\u0438\u043c\u0435\u0440: \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0438, \u043d\u0430\u043a\u043e\u043d\u0435\u0446, \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443!<\/h4>\n<p>  <\/p>\n<p>\u0412\u0441\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438-\u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a\u0438 \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0438\u043c\u0435\u044e\u0442 \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">u64 fn(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5)<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c-\u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a\u0430\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u044e\u0442\u0441\u044f \u0432 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0445 <code>r1<\/code>\u2014<code>r5<\/code>, \u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0435 <code>r0<\/code>. \u0424\u0443\u043d\u043a\u0446\u0438\u0439, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0438\u0445 \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u044f\u0442\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u2014\u00a0\u043d\u0435\u0442 \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u0438\u0445 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c \u043d\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f.<\/p>\n<p>  <\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043d\u043e\u0432\u044b\u0439 kernel helper \u0438 \u0442\u043e \u043a\u0430\u043a BPF \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b. \u041f\u0435\u0440\u0435\u043f\u0438\u0448\u0435\u043c <code>xdp-simple.bpf.c<\/code> \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c (\u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u0438\u0441\u044c):<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">SEC(&quot;xdp\/simple&quot;) int simple(void *ctx) {     bpf_printk(&quot;running on CPU%u\\n&quot;, bpf_get_smp_processor_id());     return XDP_PASS; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u0430\u0448\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043f\u0435\u0447\u0430\u0442\u0430\u0435\u0442 \u043d\u043e\u043c\u0435\u0440 CPU, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043e\u043d\u0430 \u0437\u0430\u043f\u0443\u0449\u0435\u043d\u0430. \u0421\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u043c \u0435\u0435 \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043a\u043e\u0434:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ llvm-objdump -D --section=xdp\/simple --no-show-raw-insn xdp-simple.bpf.o  0000000000000000 &lt;simple&gt;:        0:       r1 = 10        1:       *(u16 *)(r10 - 8) = r1        2:       r1 = 8441246879787806319 ll        4:       *(u64 *)(r10 - 16) = r1        5:       r1 = 2334956330918245746 ll        7:       *(u64 *)(r10 - 24) = r1        8:       call 8        9:       r1 = r10       10:       r1 += -24       11:       r2 = 18       12:       r3 = r0       13:       call 6       14:       r0 = 2       15:       exit<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u0441\u0442\u0440\u043e\u043a\u0430\u0445 0-7 \u043c\u044b \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u043d\u0430 \u0441\u0442\u0435\u043a \u0441\u0442\u0440\u043e\u043a\u0443 <code>running on CPU%u\\n<\/code>, \u0430 \u0437\u0430\u0442\u0435\u043c \u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0435 8 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0437\u043d\u0430\u043a\u043e\u043c\u044b\u0439 \u043d\u0430\u043c <code>bpf_get_smp_processor_id<\/code>. \u0412 \u0441\u0442\u0440\u043e\u043a\u0430\u0445 9-12 \u043c\u044b \u043f\u043e\u0434\u0433\u043e\u0442\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u044b \u0445\u0435\u043b\u043f\u0435\u0440\u0430 <code>bpf_printk<\/code> \u2014 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u044b <code>r1<\/code>, <code>r2<\/code>, <code>r3<\/code>. \u041f\u043e\u0447\u0435\u043c\u0443 \u0438\u0445 \u0442\u0440\u0438, \u0430 \u043d\u0435 \u0434\u0432\u0430? \u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e <code>bpf_printk<\/code> \u2014\u00a0<a href=\"https:\/\/github.com\/torvalds\/linux\/blob\/v5.8-rc7\/tools\/lib\/bpf\/bpf_helpers.h#L18\" rel=\"nofollow\">\u044d\u0442\u043e \u043c\u0430\u043a\u0440\u043e\u0441-\u043e\u0431\u0435\u0440\u0442\u043a\u0430<\/a> \u0432\u043e\u043a\u0440\u0443\u0433 \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u0433\u043e \u0445\u0435\u043b\u043f\u0435\u0440\u0430 <code>bpf_trace_printk<\/code>, \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0440 \u0444\u043e\u0440\u043c\u0430\u0442\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438.<\/p>\n<p>  <\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0442\u0435\u043f\u0435\u0440\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043f\u0430\u0440\u0443 \u0441\u0442\u0440\u043e\u0447\u0435\u043a \u043a <code>xdp-simple.c<\/code>, \u0447\u0442\u043e\u0431\u044b \u043d\u0430\u0448\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043f\u043e\u0434\u0441\u043e\u0435\u0434\u0438\u043d\u044f\u043b\u0430\u0441\u044c \u043a \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0443 <code>lo<\/code> \u0438 \u043f\u043e-\u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0435\u043c\u0443 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u043b\u0430\u0441\u044c!<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ cat xdp-simple.c #include &lt;linux\/if_link.h&gt; #include &lt;err.h&gt; #include &lt;unistd.h&gt; #include &quot;xdp-simple.skel.h&quot;  int main(int argc, char **argv) {     __u32 flags = XDP_FLAGS_SKB_MODE;     struct xdp_simple_bpf *obj;      obj = xdp_simple_bpf__open_and_load();     if (!obj)         err(1, &quot;failed to open and\/or load BPF object\\n&quot;);      bpf_set_link_xdp_fd(1, -1, flags);     bpf_set_link_xdp_fd(1, bpf_program__fd(obj-&gt;progs.simple), flags);  cleanup:     xdp_simple_bpf__destroy(obj); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>bpf_set_link_xdp_fd<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0434\u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0435\u0442 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b BPF \u0442\u0438\u043f\u0430 XDP \u043a \u0441\u0435\u0442\u0435\u0432\u044b\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430\u043c. \u041c\u044b \u0437\u0430\u0445\u0430\u0440\u0434\u043a\u043e\u0434\u0438\u043b\u0438 \u043d\u043e\u043c\u0435\u0440 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 <code>lo<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u0441\u0435\u0433\u0434\u0430 \u0440\u0430\u0432\u0435\u043d 1. \u041c\u044b \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0434\u0432\u0430 \u0440\u0430\u0437\u0430, \u0447\u0442\u043e\u0431\u044b \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u0442\u0441\u043e\u0435\u0434\u0438\u043d\u0438\u0442\u044c \u0441\u0442\u0430\u0440\u0443\u044e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443, \u0435\u0441\u043b\u0438 \u043e\u043d\u0430 \u0431\u044b\u043b\u0430 \u043f\u0440\u0438\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0430. \u0417\u0430\u043c\u0435\u0442\u044c\u0442\u0435, \u0447\u0442\u043e \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043c \u043d\u0435 \u043d\u0443\u0436\u0435\u043d \u0432\u044b\u0437\u043e\u0432 <code>pause<\/code> \u0438\u043b\u0438 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0446\u0438\u043a\u043b: \u043d\u0430\u0448\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430-\u0437\u0430\u0433\u0440\u0443\u0437\u0447\u0438\u043a \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442 \u0440\u0430\u0431\u043e\u0442\u0443, \u043d\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 BPF \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d\u0430, \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u043d\u0430 \u043f\u043e\u0434\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0430 \u043a \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0443 \u0441\u043e\u0431\u044b\u0442\u0438\u0439. \u041f\u043e\u0441\u043b\u0435 \u0443\u0441\u043f\u0435\u0448\u043d\u043e\u0439 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0438 \u043f\u043e\u0434\u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f, \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u0435\u0442\u0435\u0432\u043e\u0433\u043e \u043f\u0430\u043a\u0435\u0442\u0430, \u043f\u0440\u0438\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u043d\u0430 <code>lo<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0417\u0430\u0433\u0440\u0443\u0437\u0438\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 <code>lo<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ sudo .\/xdp-simple $ sudo bpftool p | grep simple 669: xdp  name simple  tag 4fca62e77ccb43d6  gpl $ ip l show dev lo 1: lo: &lt;LOOPBACK,UP,LOWER_UP&gt; mtu 65536 xdpgeneric qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000     link\/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00     prog\/xdp id 669<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u044b \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u043b\u0438 \u0438\u043c\u0435\u0435\u0442 ID 669 \u0438 \u0442\u043e\u0442 \u0436\u0435 ID \u043c\u044b \u0432\u0438\u0434\u0438\u043c \u043d\u0430 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0435 <code>lo<\/code>. \u041f\u043e\u0448\u043b\u0435\u043c \u043f\u0430\u0440\u0443 \u043f\u0430\u043a\u0435\u0442\u043e\u0432 \u043d\u0430 <code>127.0.0.1<\/code> (request + reply):<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ ping -c1 localhost<\/code><\/pre>\n<p>  <\/p>\n<p>\u0438 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u043e\u0442\u043b\u0430\u0434\u043e\u0447\u043d\u043e\u0433\u043e \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 <code>\/sys\/kernel\/debug\/tracing\/trace_pipe<\/code>, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 <code>bpf_printk<\/code> \u043f\u0438\u0448\u0435\u0442 \u0441\u0432\u043e\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\"># cat \/sys\/kernel\/debug\/tracing\/trace_pipe ping-13937 [000] d.s1 442015.377014: bpf_trace_printk: running on CPU0 ping-13937 [000] d.s1 442015.377027: bpf_trace_printk: running on CPU0<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u0432\u0430 \u043f\u0430\u043a\u0435\u0442\u0430 \u0431\u044b\u043b\u0438 \u0437\u0430\u043c\u0435\u0447\u0435\u043d\u044b \u043d\u0430 <code>lo<\/code> \u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u044b \u043d\u0430 CPU0 \u2014\u00a0\u043d\u0430\u0448\u0430 \u043f\u0435\u0440\u0432\u0430\u044f \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u0430\u044f \u0431\u0435\u0441\u0441\u043c\u044b\u0441\u043b\u0435\u043d\u043d\u0430\u044f \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 BPF \u043e\u0442\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0430!<\/p>\n<p>  <\/p>\n<p>\u0421\u0442\u043e\u0438\u0442 \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e <code>bpf_printk<\/code> \u043d\u0435 \u0434\u0430\u0440\u043e\u043c \u043f\u0438\u0448\u0435\u0442 \u0432 \u043e\u0442\u043b\u0430\u0434\u043e\u0447\u043d\u044b\u0439 \u0444\u0430\u0439\u043b: \u044d\u0442\u043e \u043d\u0435 \u0441\u0430\u043c\u044b\u0439 \u0443\u0434\u0430\u0447\u043d\u044b\u0439 \u0445\u0435\u043b\u043f\u0435\u0440 \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0432 production, \u043d\u043e \u043d\u0430\u0448\u0430 \u0446\u0435\u043b\u044c \u0431\u044b\u043b\u0430 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c \u0447\u0442\u043e-\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0435.<\/p>\n<p>  <\/p>\n<h3 id=\"maps-from-progs\">\u0414\u043e\u0441\u0442\u0443\u043f \u043a maps \u0438\u0437 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c BPF<\/h3>\n<p>  <\/p>\n<h4>\u041f\u0440\u0438\u043c\u0435\u0440: \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043c\u0430\u043f \u0438\u0437 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b BPF<\/h4>\n<p>  <\/p>\n<p>\u0412 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0440\u0430\u0437\u0434\u0435\u043b\u0430\u0445 \u043c\u044b \u043d\u0430\u0443\u0447\u0438\u043b\u0438\u0441\u044c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0430\u043f\u044b \u0438\u0437 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0430 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u044f\u0434\u0435\u0440\u043d\u0443\u044e \u0447\u0430\u0441\u0442\u044c. \u041d\u0430\u0447\u043d\u0435\u043c, \u043a\u0430\u043a \u0432\u043e\u0434\u0438\u0442\u0441\u044f, \u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u0430. \u041f\u0435\u0440\u0435\u043f\u0438\u0448\u0435\u043c \u043d\u0430\u0448\u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 <code>xdp-simple.bpf.c<\/code> \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">#include &quot;vmlinux.h&quot; #include &lt;bpf\/bpf_helpers.h&gt;  struct {     __uint(type, BPF_MAP_TYPE_ARRAY);     __uint(max_entries, 8);     __type(key, u32);     __type(value, u64); } woo SEC(&quot;.maps&quot;);  SEC(&quot;xdp\/simple&quot;) int simple(void *ctx) {     u32 key = bpf_get_smp_processor_id();     u32 *val;      val = bpf_map_lookup_elem(&amp;woo, &amp;key);     if (!val)         return XDP_ABORTED;      *val += 1;      return XDP_PASS; }  char LICENSE[] SEC(&quot;license&quot;) = &quot;GPL&quot;;<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412 \u043d\u0430\u0447\u0430\u043b\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043c\u0430\u043f\u0430 <code>woo<\/code>: \u044d\u0442\u043e \u043c\u0430\u0441\u0441\u0438\u0432 \u0438\u0437 8 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0445\u0440\u0430\u043d\u044f\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u0430 <code>u64<\/code> (\u043d\u0430 C \u043c\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043b\u0438 \u0431\u044b \u0442\u0430\u043a\u043e\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 \u043a\u0430\u043a <code>u64 woo[8]<\/code>). \u0412 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 <code>&quot;xdp\/simple&quot;<\/code> \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043d\u043e\u043c\u0435\u0440 \u0442\u0435\u043a\u0443\u0449\u0435\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0440\u0430 \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e <code>key<\/code> \u0438 \u0437\u0430\u0442\u0435\u043c \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438-\u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a\u0430 <code>bpf_map_lookup_element<\/code> \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u043c\u0430\u0441\u0441\u0438\u0432\u0435, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u043c \u043d\u0430 \u0435\u0434\u0438\u043d\u0438\u0446\u0443. \u0412 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0435 \u043d\u0430 \u0440\u0443\u0441\u0441\u043a\u0438\u0439: \u043c\u044b \u043f\u043e\u0434\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443 \u0442\u043e\u0433\u043e, \u043d\u0430 \u043a\u0430\u043a\u043e\u043c CPU \u0431\u044b\u043b\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u044b \u0432\u0445\u043e\u0434\u044f\u0449\u0438\u0435 \u043f\u0430\u043a\u0435\u0442\u044b. \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ clang -O2 -g -c -target bpf -I libbpf\/src\/root\/usr\/include xdp-simple.bpf.c -o xdp-simple.bpf.o $ bpftool gen skeleton xdp-simple.bpf.o &gt; xdp-simple.skel.h $ clang -O2 -g -I .\/libbpf\/src\/root\/usr\/include\/ -o xdp-simple xdp-simple.c .\/libbpf\/src\/root\/usr\/lib64\/libbpf.a -lelf -lz $ sudo .\/xdp-simple<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0440\u043e\u0432\u0435\u0440\u0438\u043c, \u0447\u0442\u043e \u043e\u043d\u0430 \u043f\u043e\u0434\u0446\u0435\u043f\u0438\u043b\u0430\u0441\u044c \u043a <code>lo<\/code> \u0438 \u043f\u043e\u0448\u043b\u0435\u043c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0430\u043a\u0435\u0442\u043e\u0432:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ ip l show dev lo 1: lo: &lt;LOOPBACK,UP,LOWER_UP&gt; mtu 65536 xdpgeneric qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000     link\/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00     prog\/xdp id 108  $ for s in `seq 234`; do sudo ping -f -c 100 127.0.0.1 &gt;\/dev\/null 2&gt;&amp;1; done<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ sudo bpftool map dump name woo [     { &quot;key&quot;: 0, &quot;value&quot;: 0 },     { &quot;key&quot;: 1, &quot;value&quot;: 400 },     { &quot;key&quot;: 2, &quot;value&quot;: 0 },     { &quot;key&quot;: 3, &quot;value&quot;: 0 },     { &quot;key&quot;: 4, &quot;value&quot;: 0 },     { &quot;key&quot;: 5, &quot;value&quot;: 0 },     { &quot;key&quot;: 6, &quot;value&quot;: 0 },     { &quot;key&quot;: 7, &quot;value&quot;: 46400 } ]<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u0447\u0442\u0438 \u0432\u0441\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u044b \u0431\u044b\u043b\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u044b \u043d\u0430 CPU7. \u041d\u0430\u043c \u044d\u0442\u043e \u043d\u0435 \u0432\u0430\u0436\u043d\u043e, \u0433\u043b\u0430\u0432\u043d\u043e\u0435, \u0447\u0442\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0438 \u043c\u044b \u043f\u043e\u043d\u044f\u043b\u0438 \u043a\u0430\u043a \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043c\u0430\u043f\u0430\u043c \u0438\u0437 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c BPF \u2014 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 <a href=\"https:\/\/github.com\/torvalds\/linux\/blob\/v5.8-rc7\/include\/uapi\/linux\/bpf.h#L632\" rel=\"nofollow\"><code>\u0445\u0435\u043b\u043f\u0435\u0440\u043e\u0432 bpf_mp_*<\/code><\/a>.<\/p>\n<p>  <\/p>\n<h4>\u041c\u0438\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c<\/h4>\n<p>  <\/p>\n<p>\u0418\u0442\u0430\u043a, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u0438\u0437 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b BPF \u043a \u043c\u0430\u043f\u0443 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0432\u0438\u0434\u0430<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">val = bpf_map_lookup_elem(&amp;woo, &amp;key);<\/code><\/pre>\n<p>  <\/p>\n<p>\u0433\u0434\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044f-\u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043a\u0430\u043a<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">void *bpf_map_lookup_elem(struct bpf_map *map, const void *key)<\/code><\/pre>\n<p>  <\/p>\n<p>\u043d\u043e \u043c\u044b \u0436\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c <code>&amp;woo<\/code> \u043d\u0430 \u0431\u0435\u0437\u044b\u043c\u044f\u043d\u043d\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 <code>struct { ... }<\/code>&#8230;<\/p>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u043c\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u0442\u043e \u0443\u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>&amp;woo<\/code> \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043d\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043e (\u0441\u0442\u0440\u043e\u0447\u043a\u0430 4):<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">llvm-objdump -D --section xdp\/simple xdp-simple.bpf.o  xdp-simple.bpf.o:       file format elf64-bpf  Disassembly of section xdp\/simple:  0000000000000000 &lt;simple&gt;:        0:       85 00 00 00 08 00 00 00 call 8        1:       63 0a fc ff 00 00 00 00 *(u32 *)(r10 - 4) = r0        2:       bf a2 00 00 00 00 00 00 r2 = r10        3:       07 02 00 00 fc ff ff ff r2 += -4        4:       18 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 r1 = 0 ll        6:       85 00 00 00 01 00 00 00 call 1 ...<\/code><\/pre>\n<p>  <\/p>\n<p>\u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f \u0432 \u0440\u0435\u043b\u043e\u043a\u0430\u0446\u0438\u044f\u0445:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ llvm-readelf -r xdp-simple.bpf.o | head -4  Relocation section '.relxdp\/simple' at offset 0xe18 contains 1 entries:     Offset             Info             Type               Symbol's Value  Symbol's Name 0000000000000020  0000002700000001 R_BPF_64_64            0000000000000000 woo<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u043e \u0435\u0441\u043b\u0438 \u043c\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0443\u0436\u0435 \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u0443\u044e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443, \u0442\u043e \u0443\u0432\u0438\u0434\u0438\u043c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 map (\u0441\u0442\u0440\u043e\u043a\u0430 4):<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ sudo bpftool prog dump x name simple int simple(void *ctx):    0: (85) call bpf_get_smp_processor_id#114128    1: (63) *(u32 *)(r10 -4) = r0    2: (bf) r2 = r10    3: (07) r2 += -4    4: (18) r1 = map[id:64] ...<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432\u044b\u0432\u043e\u0434, \u0447\u0442\u043e \u0432 \u043c\u043e\u043c\u0435\u043d\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043d\u0430\u0448\u0435\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b-\u0437\u0430\u0433\u0440\u0443\u0437\u0447\u0438\u043a\u0430 \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 <code>&amp;woo<\/code> \u0431\u044b\u043b\u0430 \u043d\u0430 \u0447\u0442\u043e-\u0442\u043e \u0437\u0430\u043c\u0435\u043d\u0435\u043d\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 <code>libbpf<\/code>. \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043c\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0432\u044b\u0432\u043e\u0434 <code>strace<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ sudo strace -e bpf .\/xdp-simple ... bpf(BPF_MAP_CREATE, {map_type=BPF_MAP_TYPE_ARRAY, key_size=4, value_size=8, max_entries=8, map_name=&quot;woo&quot;, ...}, 120) = 4 bpf(BPF_PROG_LOAD, {prog_type=BPF_PROG_TYPE_XDP, prog_name=&quot;simple&quot;, ...}, 120) = 5<\/code><\/pre>\n<p>  <\/p>\n<p>\u041c\u044b \u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e <code>libbpf<\/code> \u0441\u043e\u0437\u0434\u0430\u043b\u0430 \u043c\u0430\u043f <code>woo<\/code> \u0438 \u043f\u043e\u0442\u043e\u043c \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u043b\u0430 \u043d\u0430\u0448\u0443 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 <code>simple<\/code>. \u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u0438\u0441\u0442\u0430\u043b\u044c\u043d\u043e \u043d\u0430 \u0442\u043e, \u043a\u0430\u043a \u043c\u044b \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c <code>xdp_simple_bpf__open_and_load<\/code> \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 <code>xdp-simple.skel.h<\/code><\/li>\n<li>\u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 <code>xdp_simple_bpf__load<\/code> \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 <code>xdp-simple.skel.h<\/code><\/li>\n<li>\u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 <code>bpf_object__load_skeleton<\/code> \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 <code>libbpf\/src\/libbpf.c<\/code><\/li>\n<li>\u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 <code>bpf_object__load_xattr<\/code> \u0438\u0437 <code>libbpf\/src\/libbpf.c<\/code><\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u0440\u043e\u043c\u0435 \u0432\u0441\u0435\u0433\u043e \u043f\u0440\u043e\u0447\u0435\u0433\u043e, \u0432\u044b\u0437\u043e\u0432\u0435\u0442 <code>bpf_object__create_maps<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0438\u043b\u0438 \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 maps, \u043f\u0440\u0435\u0432\u0440\u0430\u0449\u0430\u044f \u0438\u0445 \u0432 \u0444\u0430\u0439\u043b\u043e\u0432\u044b\u0435 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u044b. (\u042d\u0442\u043e \u0442\u043e \u043c\u0435\u0441\u0442\u043e, \u0433\u0434\u0435 \u043c\u044b \u0432\u0438\u0434\u0438\u043c <code>BPF_MAP_CREATE<\/code> \u0432 \u0432\u044b\u0432\u043e\u0434\u0435 <code>strace<\/code>.) \u0414\u0430\u043b\u044c\u0448\u0435 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f <code>bpf_object__relocate<\/code> \u0438 \u0438\u043c\u0435\u043d\u043d\u043e \u043e\u043d\u0430 \u043d\u0430\u0441 \u0438 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u0443\u0435\u0442, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u043f\u043e\u043c\u043d\u0438\u043c, \u0447\u0442\u043e \u043c\u044b \u0432\u0438\u0434\u0435\u043b\u0438 <code>woo<\/code> \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0440\u0435\u043b\u043e\u043a\u0430\u0446\u0438\u0439. \u0418\u0441\u0441\u043b\u0435\u0434\u0443\u044f \u0435\u0435, \u043c\u044b, \u0432 \u043a\u043e\u043d\u0446\u0435-\u043a\u043e\u043d\u0446\u043e\u0432 \u043f\u043e\u043f\u0430\u0434\u0430\u0435\u043c \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>bpf_program__relocate<\/code>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438 <a href=\"https:\/\/github.com\/torvalds\/linux\/blob\/v5.7-rc3\/tools\/lib\/bpf\/libbpf.c#L4749\" rel=\"nofollow\">\u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u0440\u0435\u043b\u043e\u043a\u0430\u0446\u0438\u044f\u043c\u0438 \u043c\u0430\u043f\u043e\u0432<\/a>:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">case RELO_LD64:     insn[0].src_reg = BPF_PSEUDO_MAP_FD;     insn[0].imm = obj-&gt;maps[relo-&gt;map_idx].fd;     break;<\/code><\/pre>\n<p>  <\/p>\n<p>\u0418\u0442\u0430\u043a, \u043c\u044b \u0431\u0435\u0440\u0435\u043c \u043d\u0430\u0448\u0443 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">18 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 r1 = 0 ll<\/code><\/pre>\n<p>  <\/p>\n<p>\u0438 \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u043c \u0432 \u043d\u0435\u0439 \u0440\u0435\u0433\u0438\u0441\u0442\u0440-\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u043d\u0430 <code>BPF_PSEUDO_MAP_FD<\/code>, \u0430 \u043f\u0435\u0440\u0432\u044b\u0439 IMM \u043d\u0430 \u0444\u0430\u0439\u043b\u043e\u0432\u044b\u0439 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440 \u043d\u0430\u0448\u0435\u0433\u043e \u043c\u0430\u043f\u0430 \u0438, \u0435\u0441\u043b\u0438 \u043e\u043d \u0440\u0430\u0432\u0435\u043d, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>0xdeadbeef<\/code>, \u0442\u043e \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">18 11 00 00 ef eb ad de 00 00 00 00 00 00 00 00 r1 = 0 ll<\/code><\/pre>\n<p>  <\/p>\n<p>\u0418\u043c\u0435\u043d\u043d\u043e \u0442\u0430\u043a \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u043c\u0430\u043f\u0430\u0445 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u0432 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u0443\u044e \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u0443\u044e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 BPF. \u041f\u0440\u0438 \u044d\u0442\u043e\u043c \u043c\u0430\u043f \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u043d \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 <code>BPF_MAP_CREATE<\/code>, \u0442\u0430\u043a \u0438 \u043e\u0442\u043a\u0440\u044b\u0442 \u043f\u043e ID \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 <code>BPF_MAP_GET_FD_BY_ID<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0418\u0442\u043e\u0433\u043e, \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 <code>libbpf<\/code> \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 \u0434\u043b\u044f \u0441\u0441\u044b\u043b\u043e\u043a \u043d\u0430 \u043c\u0430\u043f\u044b \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0440\u0435\u043b\u043e\u043a\u0430\u0446\u0438\u0438<\/li>\n<li><code>libbpf<\/code> \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442\u043d\u0438\u043a ELF, \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u0432\u0441\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435 \u043c\u0430\u043f\u044b \u0438 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0434\u043b\u044f \u043d\u0438\u0445 \u0444\u0430\u0439\u043b\u043e\u0432\u044b\u0435 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u044b<\/li>\n<li>\u0444\u0430\u0439\u043b\u043e\u0432\u044b\u0435 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u044b \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u044e\u0442\u0441\u044f \u0432 \u044f\u0434\u0440\u043e \u043a\u0430\u043a \u0447\u0430\u0441\u0442\u044c \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 <code>LD64<\/code><\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u0432\u044b \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u0442\u0435, \u044d\u0442\u043e \u0435\u0449\u0435 \u043d\u0435 \u0432\u0441\u0435, \u0438 \u043d\u0430\u043c \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0437\u0430\u0433\u043b\u044f\u043d\u0443\u0442\u044c \u0432 \u044f\u0434\u0440\u043e. \u041a \u0441\u0447\u0430\u0441\u0442\u044c\u044e, \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0437\u0430\u0446\u0435\u043f\u043a\u0430 \u2014\u00a0\u043c\u044b \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u043b\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 <code>BPF_PSEUDO_MAP_FD<\/code> \u0432 \u0440\u0435\u0433\u0438\u0441\u0442\u0440-\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a \u0438 \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u0433\u0440\u0435\u043f\u0430\u0442\u044c \u0435\u0433\u043e, \u0447\u0442\u043e \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u0442 \u043d\u0430\u0441 \u0432 \u0441\u0432\u044f\u0442\u0430\u044f \u0432\u0441\u0435\u0445 \u0441\u0432\u044f\u0442\u044b\u0445 \u2014 <code>kernel\/bpf\/verifier.c<\/code>, \u0433\u0434\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0441 \u0445\u0430\u0440\u0430\u043a\u0442\u0435\u0440\u043d\u044b\u043c \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u0442 \u0444\u0430\u0439\u043b\u043e\u0432\u044b\u0439 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440 \u043d\u0430 \u0430\u0434\u0440\u0435\u0441 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0442\u0438\u043f\u0430 <code>struct bpf_map<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">static int replace_map_fd_with_map_ptr(struct bpf_verifier_env *env) {     ...      f = fdget(insn[0].imm);     map = __bpf_map_get(f);     if (insn-&gt;src_reg == BPF_PSEUDO_MAP_FD) {         addr = (unsigned long)map;     }     insn[0].imm = (u32)addr;     insn[1].imm = addr &gt;&gt; 32;<\/code><\/pre>\n<p>  <\/p>\n<p>(\u043f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 <a href=\"https:\/\/github.com\/torvalds\/linux\/blob\/v5.8-rc7\/kernel\/bpf\/verifier.c#L9086-L9131\" rel=\"nofollow\">\u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435<\/a>). \u0422\u0430\u043a \u0447\u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043d\u0430\u0448 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b verifier \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0435\u0442 \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0441\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u0430\u043f\u0430 \u0438 \u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0430\u0434\u0440\u0435\u0441 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b <code>struct bpf_map<\/code><\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u041f\u0440\u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0435 \u0431\u0438\u043d\u0430\u0440\u043d\u0438\u043a\u0430 ELF \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 <code>libbpf<\/code> \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0435\u0449\u0435 \u043c\u043d\u043e\u0433\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0439, \u043d\u043e \u043c\u044b \u043e\u0431\u0441\u0443\u0434\u0438\u043c \u044d\u0442\u043e \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u0434\u0440\u0443\u0433\u0438\u0445 \u0441\u0442\u0430\u0442\u0435\u0439.<\/p>\n<p>  <\/p>\n<h4 id=\"nolibbpf\">\u0417\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0438 \u043c\u0430\u043f\u044b \u0431\u0435\u0437 libbpf<\/h4>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u0438 \u043e\u0431\u0435\u0449\u0430\u043b\u043e\u0441\u044c, \u0432\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0445\u043e\u0442\u044f\u0442 \u0437\u043d\u0430\u0442\u044c, \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0443\u044e \u043c\u0430\u043f\u044b, \u0431\u0435\u0437 \u043f\u043e\u043c\u043e\u0449\u0438 <code>libbpf<\/code>. \u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043b\u0435\u0437\u043d\u043e, \u043a\u043e\u0433\u0434\u0430 \u0432\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442\u0435 \u0432 \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0438, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043d\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438, \u0438\u043b\u0438 \u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0442\u0435 \u043a\u0430\u0436\u0434\u044b\u0439 \u0431\u0438\u0442, \u0438\u043b\u0438 \u043f\u0438\u0448\u0435\u0442\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u0442\u0438\u043f\u0430 <a href=\"https:\/\/github.com\/iovisor\/ply\" rel=\"nofollow\"><code>ply<\/code><\/a>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0439 \u043a\u043e\u0434 BPF \u043d\u0430\u043b\u0435\u0442\u0443.<\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0431\u044b\u043b\u043e \u043f\u0440\u043e\u0449\u0435 \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u0437\u0430 \u043b\u043e\u0433\u0438\u043a\u043e\u0439, \u043c\u044b \u0434\u043b\u044f \u044d\u0442\u0438\u0445 \u0446\u0435\u043b\u0435\u0439 \u043f\u0435\u0440\u0435\u043f\u0438\u0448\u0435\u043c \u043d\u0430\u0448 \u043f\u0440\u0438\u043c\u0435\u0440 <code>xdp-simple<\/code>. \u041f\u043e\u043b\u043d\u044b\u0439 \u0438 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c\u043e\u0439 \u0432 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0439\u0442\u0438 \u0432 \u044d\u0442\u043e\u043c <a href=\"https:\/\/gist.github.com\/aspsk\/fc145db380aee3c2cd503c36c63b555e\" rel=\"nofollow\">gist<\/a>.<\/p>\n<p>  <\/p>\n<p>\u041b\u043e\u0433\u0438\u043a\u0430 \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043c\u0430\u043f \u0442\u0438\u043f\u0430 <code>BPF_MAP_TYPE_ARRAY<\/code> \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043a\u043e\u043c\u0430\u043d\u0434\u044b <code>BPF_MAP_CREATE<\/code>,<\/li>\n<li>\u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0443\u044e \u044d\u0442\u043e\u0442 \u043c\u0430\u043f,<\/li>\n<li>\u043f\u043e\u0434\u0441\u043e\u0435\u0434\u0438\u043d\u0438\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443 \u043a \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0443 <code>lo<\/code>,<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0447\u0442\u043e \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043d\u0430 \u0447\u0435\u043b\u043e\u0432\u0435\u0447\u0435\u0441\u043a\u0438\u0439 \u043a\u0430\u043a<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">int main(void) {     int map_fd, prog_fd;      map_fd = map_create();     if (map_fd &lt; 0)         err(1, &quot;bpf: BPF_MAP_CREATE&quot;);      prog_fd = prog_load(map_fd);     if (prog_fd &lt; 0)         err(1, &quot;bpf: BPF_PROG_LOAD&quot;);      xdp_attach(1, prog_fd); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0417\u0434\u0435\u0441\u044c <code>map_create<\/code> \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043c\u0430\u043f \u0442\u043e\u0447\u043d\u043e \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a \u043c\u044b \u0434\u0435\u043b\u0430\u043b\u0438 \u044d\u0442\u043e \u0432 \u043f\u0435\u0440\u0432\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u0440\u043e \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u044b\u0439 \u0432\u044b\u0437\u043e\u0432 <code>bpf<\/code> \u2014 \u00ab\u044f\u0434\u0440\u043e, \u043f\u043e\u0436\u0430\u043b\u0443\u0439\u0441\u0442\u0430, \u0441\u0434\u0435\u043b\u0430\u0439 \u043c\u043d\u0435 \u043d\u043e\u0432\u044b\u0439 \u043c\u0430\u043f \u0432 \u0432\u0438\u0434\u0435\u00a0\u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0438\u0437 8 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0442\u0438\u043f\u0430 <code>__u64<\/code> \u0438 \u0432\u0435\u0440\u043d\u0438 \u043c\u043d\u0435 \u0444\u0430\u0439\u043b\u043e\u0432\u044b\u0439 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u00bb:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">static int map_create() {     union bpf_attr attr;      memset(&amp;attr, 0, sizeof(attr));     attr.map_type = BPF_MAP_TYPE_ARRAY,     attr.key_size = sizeof(__u32),     attr.value_size = sizeof(__u64),     attr.max_entries = 8,     strncpy(attr.map_name, &quot;woo&quot;, sizeof(attr.map_name));     return syscall(__NR_bpf, BPF_MAP_CREATE, &amp;attr, sizeof(attr)); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0442\u043e\u0436\u0435 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0441\u0442\u043e:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">static int prog_load(int map_fd) {     union bpf_attr attr;     struct bpf_insn insns[] = {         ...     };      memset(&amp;attr, 0, sizeof(attr));     attr.prog_type = BPF_PROG_TYPE_XDP;     attr.insns     = ptr_to_u64(insns);     attr.insn_cnt  = sizeof(insns)\/sizeof(insns[0]);     attr.license   = ptr_to_u64(&quot;GPL&quot;);     strncpy(attr.prog_name, &quot;woo&quot;, sizeof(attr.prog_name));     return syscall(__NR_bpf, BPF_PROG_LOAD, &amp;attr, sizeof(attr)); }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u043b\u043e\u0436\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c <code>prog_load<\/code> \u2014 \u044d\u0442\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043d\u0430\u0448\u0435\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b BPF \u0432 \u0432\u0438\u0434\u0435 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440 <code>struct bpf_insn insns[]<\/code>. \u041d\u043e \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043d\u0430 C, \u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0441\u0445\u0438\u0442\u0440\u0438\u0442\u044c:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ llvm-objdump -D --section xdp\/simple xdp-simple.bpf.o  0000000000000000 &lt;simple&gt;:        0:       85 00 00 00 08 00 00 00 call 8        1:       63 0a fc ff 00 00 00 00 *(u32 *)(r10 - 4) = r0        2:       bf a2 00 00 00 00 00 00 r2 = r10        3:       07 02 00 00 fc ff ff ff r2 += -4        4:       18 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 r1 = 0 ll        6:       85 00 00 00 01 00 00 00 call 1        7:       b7 01 00 00 00 00 00 00 r1 = 0        8:       15 00 04 00 00 00 00 00 if r0 == 0 goto +4 &lt;LBB0_2&gt;        9:       61 01 00 00 00 00 00 00 r1 = *(u32 *)(r0 + 0)       10:       07 01 00 00 01 00 00 00 r1 += 1       11:       63 10 00 00 00 00 00 00 *(u32 *)(r0 + 0) = r1       12:       b7 01 00 00 02 00 00 00 r1 = 2  0000000000000068 &lt;LBB0_2&gt;:       13:       bf 10 00 00 00 00 00 00 r0 = r1       14:       95 00 00 00 00 00 00 00 exit<\/code><\/pre>\n<p>  <\/p>\n<p>\u0418\u0442\u043e\u0433\u043e, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c 14 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439 \u0432 \u0432\u0438\u0434\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440 \u0442\u0438\u043f\u0430 <code>struct bpf_insn<\/code> (<em>\u0441\u043e\u0432\u0435\u0442:<\/em> \u0432\u043e\u0437\u044c\u043c\u0438\u0442\u0435 \u0434\u0430\u043c\u043f \u0441\u0432\u0435\u0440\u0445\u0443, \u043f\u0435\u0440\u0435\u0447\u0438\u0442\u0430\u0439\u0442\u0435 \u0440\u0430\u0437\u0434\u0435\u043b \u043f\u0440\u043e \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438, \u043e\u0442\u043a\u0440\u043e\u0439\u0442\u0435 <a href=\"https:\/\/github.com\/torvalds\/linux\/blob\/v5.7-rc3\/include\/uapi\/linux\/bpf.h#L17-L71\" rel=\"nofollow\"><code>linux\/bpf.h<\/code><\/a> \u0438 <a href=\"https:\/\/github.com\/torvalds\/linux\/blob\/v5.8-rc7\/include\/uapi\/linux\/bpf_common.h\" rel=\"nofollow\"><code>linux\/bpf_common.h<\/code><\/a> \u0438 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0439\u0442\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c <code>struct bpf_insn insns[]<\/code> \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e):<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">struct bpf_insn insns[] = {     \/* 85 00 00 00 08 00 00 00 call 8 *\/     {         .code = BPF_JMP | BPF_CALL,         .imm = 8,     },      \/* 63 0a fc ff 00 00 00 00 *(u32 *)(r10 - 4) = r0 *\/     {         .code = BPF_MEM | BPF_STX,         .off = -4,         .src_reg = BPF_REG_0,         .dst_reg = BPF_REG_10,     },      \/* bf a2 00 00 00 00 00 00 r2 = r10 *\/     {         .code = BPF_ALU64 | BPF_MOV | BPF_X,         .src_reg = BPF_REG_10,         .dst_reg = BPF_REG_2,     },      \/* 07 02 00 00 fc ff ff ff r2 += -4 *\/     {         .code = BPF_ALU64 | BPF_ADD | BPF_K,         .dst_reg = BPF_REG_2,         .imm = -4,     },      \/* 18 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 r1 = 0 ll *\/     {         .code = BPF_LD | BPF_DW | BPF_IMM,         .src_reg = BPF_PSEUDO_MAP_FD,         .dst_reg = BPF_REG_1,         .imm = map_fd,     },     { }, \/* placeholder *\/      \/* 85 00 00 00 01 00 00 00 call 1 *\/     {         .code = BPF_JMP | BPF_CALL,         .imm = 1,     },      \/* b7 01 00 00 00 00 00 00 r1 = 0 *\/     {         .code = BPF_ALU64 | BPF_MOV | BPF_K,         .dst_reg = BPF_REG_1,         .imm = 0,     },      \/* 15 00 04 00 00 00 00 00 if r0 == 0 goto +4 &lt;LBB0_2&gt; *\/     {         .code = BPF_JMP | BPF_JEQ | BPF_K,         .off = 4,         .src_reg = BPF_REG_0,         .imm = 0,     },      \/* 61 01 00 00 00 00 00 00 r1 = *(u32 *)(r0 + 0) *\/     {         .code = BPF_MEM | BPF_LDX,         .off = 0,         .src_reg = BPF_REG_0,         .dst_reg = BPF_REG_1,     },      \/* 07 01 00 00 01 00 00 00 r1 += 1 *\/     {         .code = BPF_ALU64 | BPF_ADD | BPF_K,         .dst_reg = BPF_REG_1,         .imm = 1,     },      \/* 63 10 00 00 00 00 00 00 *(u32 *)(r0 + 0) = r1 *\/     {         .code = BPF_MEM | BPF_STX,         .src_reg = BPF_REG_1,         .dst_reg = BPF_REG_0,     },      \/* b7 01 00 00 02 00 00 00 r1 = 2 *\/     {         .code = BPF_ALU64 | BPF_MOV | BPF_K,         .dst_reg = BPF_REG_1,         .imm = 2,     },      \/* &lt;LBB0_2&gt;: bf 10 00 00 00 00 00 00 r0 = r1 *\/     {         .code = BPF_ALU64 | BPF_MOV | BPF_X,         .src_reg = BPF_REG_1,         .dst_reg = BPF_REG_0,     },      \/* 95 00 00 00 00 00 00 00 exit *\/     {         .code = BPF_JMP | BPF_EXIT     }, };<\/code><\/pre>\n<p>  <\/p>\n<p>\u0423\u043f\u0440\u0430\u0436\u043d\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0442\u0435\u0445, \u043a\u0442\u043e \u043d\u0435 \u0441\u0442\u0430\u043b \u043f\u0438\u0441\u0430\u0442\u044c \u044d\u0442\u043e \u0441\u0430\u043c \u2014\u00a0\u043d\u0430\u0439\u0434\u0438\u0442\u0435 <code>map_fd<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0412 \u043d\u0430\u0448\u0435\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 \u043e\u0441\u0442\u0430\u043b\u0430\u0441\u044c \u0435\u0449\u0435 \u043e\u0434\u043d\u0430 \u043d\u0435\u0440\u0430\u0441\u043a\u0440\u044b\u0442\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u2014 <code>xdp_attach<\/code>. \u041a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0442\u0438\u043f\u0430 XDP \u043d\u0435\u043b\u044c\u0437\u044f \u043f\u043e\u0434\u0441\u043e\u0435\u0434\u0438\u043d\u0438\u0442\u044c \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 <code>bpf<\/code>. \u041b\u044e\u0434\u0438, \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0432\u0448\u0438\u0435 BPF \u0438 XDP \u0431\u044b\u043b\u0438 \u0438\u0437 \u0441\u0435\u0442\u0435\u0432\u043e\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u0430 Linux, \u0430 \u0437\u043d\u0430\u0447\u0438\u0442, \u043e\u043d\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u0441\u0430\u043c\u044b\u0439 \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u044b\u0439 \u0434\u043b\u044f \u043d\u0438\u0445 (\u043d\u043e \u043d\u0435 \u0434\u043b\u044f <em>\u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u044b\u0445<\/em> \u043b\u044e\u0434\u0435\u0439) \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 \u044f\u0434\u0440\u043e\u043c: <a href=\"https:\/\/man7.org\/linux\/man-pages\/man7\/rtnetlink.7.html\" rel=\"nofollow\">netlink sockets<\/a>, \u0441\u043c. \u0442\u0430\u043a\u0436\u0435 <a href=\"https:\/\/tools.ietf.org\/html\/rfc3549\" rel=\"nofollow\">RFC3549<\/a>. \u0421\u0430\u043c\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 <code>xdp_attach<\/code> \u2014 \u044d\u0442\u043e \u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u0434\u0430 \u0438\u0437 <code>libbpf<\/code>, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e, \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 <a href=\"https:\/\/github.com\/libbpf\/libbpf\/blob\/master\/src\/netlink.c\" rel=\"nofollow\"><code>netlink.c<\/code><\/a>, \u0447\u0442\u043e \u043c\u044b \u0438 \u043f\u0440\u043e\u0434\u0435\u043b\u0430\u043b\u0438, \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0443\u043a\u043e\u0440\u043e\u0442\u0438\u0432 \u0435\u0433\u043e:<\/p>\n<p>  <\/p>\n<div class=\"spoiler\" role=\"button\" tabindex=\"0\">                         <b class=\"spoiler_title\">\u0414\u043e\u0431\u0440\u043e \u043f\u043e\u0436\u0430\u043b\u043e\u0432\u0430\u0442\u044c \u0432 \u043c\u0438\u0440 netlink \u0441\u043e\u043a\u0435\u0442\u043e\u0432<\/b>                         <\/p>\n<div class=\"spoiler_text\">\n<p>\u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u043c netlink \u0441\u043e\u043a\u0435\u0442 \u0442\u0438\u043f\u0430 <code>NETLINK_ROUTE<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">int netlink_open(__u32 *nl_pid) {     struct sockaddr_nl sa;     socklen_t addrlen;     int one = 1, ret;     int sock;      memset(&amp;sa, 0, sizeof(sa));     sa.nl_family = AF_NETLINK;      sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);     if (sock &lt; 0)         err(1, &quot;socket&quot;);      if (setsockopt(sock, SOL_NETLINK, NETLINK_EXT_ACK, &amp;one, sizeof(one)) &lt; 0)         warnx(&quot;netlink error reporting not supported&quot;);      if (bind(sock, (struct sockaddr *)&amp;sa, sizeof(sa)) &lt; 0)         err(1, &quot;bind&quot;);      addrlen = sizeof(sa);     if (getsockname(sock, (struct sockaddr *)&amp;sa, &amp;addrlen) &lt; 0)         err(1, &quot;getsockname&quot;);      *nl_pid = sa.nl_pid;     return sock; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0427\u0438\u0442\u0430\u0435\u043c \u0438\u0437 \u0442\u0430\u043a\u043e\u0433\u043e \u0441\u043e\u043a\u0435\u0442\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">static int bpf_netlink_recv(int sock, __u32 nl_pid, int seq) {     bool multipart = true;     struct nlmsgerr *errm;     struct nlmsghdr *nh;     char buf[4096];     int len, ret;      while (multipart) {         multipart = false;         len = recv(sock, buf, sizeof(buf), 0);         if (len &lt; 0)             err(1, &quot;recv&quot;);          if (len == 0)             break;          for (nh = (struct nlmsghdr *)buf; NLMSG_OK(nh, len);                 nh = NLMSG_NEXT(nh, len)) {             if (nh-&gt;nlmsg_pid != nl_pid)                 errx(1, &quot;wrong pid&quot;);             if (nh-&gt;nlmsg_seq != seq)                 errx(1, &quot;INVSEQ&quot;);             if (nh-&gt;nlmsg_flags &amp; NLM_F_MULTI)                 multipart = true;             switch (nh-&gt;nlmsg_type) {                 case NLMSG_ERROR:                     errm = (struct nlmsgerr *)NLMSG_DATA(nh);                     if (!errm-&gt;error)                         continue;                     ret = errm-&gt;error;                     \/\/ libbpf_nla_dump_errormsg(nh); too many code to copy...                     goto done;                 case NLMSG_DONE:                     return 0;                 default:                     break;             }         }     }     ret = 0; done:     return ret; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u0432\u043e\u0442 \u043d\u0430\u0448\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u0441\u043e\u043a\u0435\u0442 \u0438 \u043f\u043e\u0441\u044b\u043b\u0430\u0435\u0442 \u0432 \u043d\u0435\u0433\u043e \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0435\u0435 \u0444\u0430\u0439\u043b\u043e\u0432\u044b\u0439 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">static int xdp_attach(int ifindex, int prog_fd) {     int sock, seq = 0, ret;     struct nlattr *nla, *nla_xdp;     struct {         struct nlmsghdr  nh;         struct ifinfomsg ifinfo;         char             attrbuf[64];     } req;     __u32 nl_pid = 0;      sock = netlink_open(&amp;nl_pid);     if (sock &lt; 0)         return sock;      memset(&amp;req, 0, sizeof(req));     req.nh.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));     req.nh.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;     req.nh.nlmsg_type = RTM_SETLINK;     req.nh.nlmsg_pid = 0;     req.nh.nlmsg_seq = ++seq;     req.ifinfo.ifi_family = AF_UNSPEC;     req.ifinfo.ifi_index = ifindex;      \/* started nested attribute for XDP *\/     nla = (struct nlattr *)(((char *)&amp;req)             + NLMSG_ALIGN(req.nh.nlmsg_len));     nla-&gt;nla_type = NLA_F_NESTED | IFLA_XDP;     nla-&gt;nla_len = NLA_HDRLEN;      \/* add XDP fd *\/     nla_xdp = (struct nlattr *)((char *)nla + nla-&gt;nla_len);     nla_xdp-&gt;nla_type = IFLA_XDP_FD;     nla_xdp-&gt;nla_len = NLA_HDRLEN + sizeof(int);     memcpy((char *)nla_xdp + NLA_HDRLEN, &amp;prog_fd, sizeof(prog_fd));     nla-&gt;nla_len += nla_xdp-&gt;nla_len;      \/* if user passed in any flags, add those too *\/     __u32 flags = XDP_FLAGS_SKB_MODE;     nla_xdp = (struct nlattr *)((char *)nla + nla-&gt;nla_len);     nla_xdp-&gt;nla_type = IFLA_XDP_FLAGS;     nla_xdp-&gt;nla_len = NLA_HDRLEN + sizeof(flags);     memcpy((char *)nla_xdp + NLA_HDRLEN, &amp;flags, sizeof(flags));     nla-&gt;nla_len += nla_xdp-&gt;nla_len;      req.nh.nlmsg_len += NLA_ALIGN(nla-&gt;nla_len);      if (send(sock, &amp;req, req.nh.nlmsg_len, 0) &lt; 0)         err(1, &quot;send&quot;);     ret = bpf_netlink_recv(sock, nl_pid, seq);  cleanup:     close(sock);     return ret; }<\/code><\/pre>\n<\/div><\/div>\n<p>  <\/p>\n<p>\u0418\u0442\u0430\u043a, \u0432\u0441\u0435 \u0433\u043e\u0442\u043e\u0432\u043e \u043a \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044e:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ cc nolibbpf.c -o nolibbpf $ sudo strace -e bpf .\/nolibbpf bpf(BPF_MAP_CREATE, {map_type=BPF_MAP_TYPE_ARRAY, map_name=&quot;woo&quot;, ...}, 72) = 3 bpf(BPF_PROG_LOAD, {prog_type=BPF_PROG_TYPE_XDP, insn_cnt=15, prog_name=&quot;woo&quot;, ...}, 72) = 4 +++ exited with 0 +++<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043f\u043e\u0434\u0441\u043e\u0435\u0434\u0438\u043d\u0438\u043b\u0430\u0441\u044c \u043b\u0438 \u043d\u0430\u0448\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u043a <code>lo<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ ip l show dev lo 1: lo: &lt;LOOPBACK,UP,LOWER_UP&gt; mtu 65536 xdpgeneric qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000     link\/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00     prog\/xdp id 160<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u0448\u043b\u0435\u043c \u043f\u0438\u043d\u0433\u0438 \u0438 \u043f\u043e\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 map:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ for s in `seq 234`; do sudo ping -f -c 100 127.0.0.1 &gt;\/dev\/null 2&gt;&amp;1; done $ sudo bpftool m dump name woo key: 00 00 00 00  value: 90 01 00 00 00 00 00 00 key: 01 00 00 00  value: 00 00 00 00 00 00 00 00 key: 02 00 00 00  value: 00 00 00 00 00 00 00 00 key: 03 00 00 00  value: 00 00 00 00 00 00 00 00 key: 04 00 00 00  value: 00 00 00 00 00 00 00 00 key: 05 00 00 00  value: 00 00 00 00 00 00 00 00 key: 06 00 00 00  value: 40 b5 00 00 00 00 00 00 key: 07 00 00 00  value: 00 00 00 00 00 00 00 00 Found 8 elements<\/code><\/pre>\n<p>  <\/p>\n<p>\u0423\u0440\u0430, \u0432\u0441\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442. \u0417\u0430\u043c\u0435\u0442\u044c\u0442\u0435, \u043a\u0441\u0442\u0430\u0442\u0438, \u0447\u0442\u043e \u043d\u0430\u0448 map \u043e\u043f\u044f\u0442\u044c \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442\u0441\u044f \u0432 \u0432\u0438\u0434\u0435 \u0431\u0430\u0439\u0442\u0438\u043a\u043e\u0432. \u042d\u0442\u043e \u043f\u0440\u043e\u0438\u0445\u043e\u0434\u0438\u0442 \u0438\u0437-\u0437\u0430 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e, \u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 <code>libbpf<\/code> \u043c\u044b \u043d\u0435 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u043b\u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0442\u0438\u043f\u0430\u0445 (BTF). \u041d\u043e \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e\u0431 \u044d\u0442\u043e\u043c \u043c\u044b \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u0432 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0440\u0430\u0437.<\/p>\n<p>  <\/p>\n<h2 id=\"tools\">\u0421\u0440\u0435\u0434\u0441\u0442\u0432\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438<\/h2>\n<p>  <\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0435 \u043c\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430\u043b\u044c\u043d\u044b\u0439 \u043d\u0430\u0431\u043e\u0440 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430 BPF.<\/p>\n<p>  <\/p>\n<p>\u0412\u043e\u043e\u0431\u0449\u0435 \u0433\u043e\u0432\u043e\u0440\u044f, \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c BPF \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u043d\u0438\u0447\u0435\u0433\u043e \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0433\u043e \u2014\u00a0BPF \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043d\u0430 \u043b\u044e\u0431\u043e\u043c \u043f\u0440\u0438\u043b\u0438\u0447\u043d\u043e\u043c \u0434\u0438\u0441\u0442\u0440\u0438\u0431\u0443\u0442\u0438\u0432\u043d\u043e\u043c \u044f\u0434\u0440\u0435, \u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u044e\u0442\u0441\u044f \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 <code>clang<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0438\u0437 \u043f\u0430\u043a\u0435\u0442\u0430. \u041e\u0434\u043d\u0430\u043a\u043e, \u0438\u0437-\u0437\u0430 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e BPF \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438, \u044f\u0434\u0440\u043e \u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u043f\u043e\u0441\u0442\u043e\u044f\u043d\u043d\u043e \u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f, \u0435\u0441\u043b\u0438 \u0432\u044b \u043d\u0435 \u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b BPF \u0434\u0435\u0434\u043e\u0432\u0441\u043a\u0438\u043c\u0438 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 \u0438\u0437 2019-\u0445, \u0442\u043e \u0432\u0430\u043c \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0441\u043e\u0431\u0440\u0430\u0442\u044c<\/p>\n<p>  <\/p>\n<ul>\n<li><code>llvm<\/code>\/<code>clang<\/code><\/li>\n<li><code>pahole<\/code><\/li>\n<li>\u0441\u0432\u043e\u0435 \u044f\u0434\u0440\u043e<\/li>\n<li><code>bpftool<\/code><\/li>\n<\/ul>\n<p>  <\/p>\n<p>(\u0414\u043b\u044f \u0441\u043f\u0440\u0430\u0432\u043a\u0438: \u044d\u0442\u043e\u0442 \u0440\u0430\u0437\u0434\u0435\u043b \u0438 \u0432\u0441\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u043b\u0438\u0441\u044c \u043d\u0430 Debian 10.)<\/p>\n<p>  <\/p>\n<h4>llvm\/clang<\/h4>\n<p>  <\/p>\n<p>BPF \u0434\u0440\u0443\u0436\u0438\u0442 \u0441 LLVM \u0438, \u0445\u043e\u0442\u044f \u0441 \u043d\u0435\u0434\u0430\u0432\u043d\u0438\u0445 \u043f\u043e\u0440 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0434\u043b\u044f BPF \u043c\u043e\u0436\u043d\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 gcc, \u0432\u0441\u044f \u0442\u0435\u043a\u0443\u0449\u0430\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0432\u0435\u0434\u0435\u0442\u0441\u044f \u0434\u043b\u044f LLVM. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u0435\u0440\u0432\u044b\u043c \u0434\u0435\u043b\u043e\u043c \u043c\u044b \u0441\u043e\u0431\u0435\u0440\u0435\u043c \u0442\u0435\u043a\u0443\u0449\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e <code>clang<\/code> \u0438\u0437 git:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ sudo apt install ninja-build $ git clone --depth 1 https:\/\/github.com\/llvm\/llvm-project.git $ mkdir -p llvm-project\/llvm\/build\/install $ cd llvm-project\/llvm\/build $ cmake .. -G &quot;Ninja&quot; -DLLVM_TARGETS_TO_BUILD=&quot;BPF;X86&quot; \\                       -DLLVM_ENABLE_PROJECTS=&quot;clang&quot; \\                       -DBUILD_SHARED_LIBS=OFF \\                       -DCMAKE_BUILD_TYPE=Release \\                       -DLLVM_BUILD_RUNTIME=OFF $ time ninja ... \u043c\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0441\u043f\u0443\u0441\u0442\u044f $<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043b\u0438 \u0432\u0441\u0435 \u0441\u043e\u0431\u0440\u0430\u043b\u043e\u0441\u044c:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ .\/bin\/llc --version LLVM (http:\/\/llvm.org\/):   LLVM version 11.0.0git   Optimized build.   Default target: x86_64-unknown-linux-gnu   Host CPU: znver1    Registered Targets:     bpf    - BPF (host endian)     bpfeb  - BPF (big endian)     bpfel  - BPF (little endian)     x86    - 32-bit X86: Pentium-Pro and above     x86-64 - 64-bit X86: EM64T and AMD64<\/code><\/pre>\n<p>  <\/p>\n<p>(\u0418\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f \u043f\u043e \u0441\u0431\u043e\u0440\u043a\u0435 <code>clang<\/code> \u0432\u0437\u044f\u0442\u0430 \u043c\u043d\u043e\u0439 \u0438\u0437 <a href=\"https:\/\/www.kernel.org\/doc\/html\/latest\/bpf\/bpf_devel_QA.html#llvm\" rel=\"nofollow\">bpf_devel_QA<\/a>.)<\/p>\n<p>  <\/p>\n<p>\u041c\u044b \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0442\u043e \u0441\u043e\u0431\u0440\u0430\u043d\u043d\u044b\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u0430 \u0432\u043c\u0435\u0441\u0442\u043e \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0438\u0445 \u0432 <code>PATH<\/code>, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">export PATH=&quot;`pwd`\/bin:$PATH&quot;<\/code><\/pre>\n<p>  <\/p>\n<p>(\u042d\u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432 <code>.bashrc<\/code> \u0438\u043b\u0438 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0444\u0430\u0439\u043b. \u041b\u0438\u0447\u043d\u043e \u044f \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e \u0442\u0430\u043a\u0438\u0435 \u0432\u0435\u0449\u0438 \u0432 <code>~\/bin\/activate-llvm.sh<\/code> \u0438 \u043a\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u044e <code>. activate-llvm.sh<\/code>.)<\/p>\n<p>  <\/p>\n<h4>Pahole \u0438 BTF<\/h4>\n<p>  <\/p>\n<p>\u0423\u0442\u0438\u043b\u0438\u0442\u0430 <code>pahole<\/code> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u0441\u0431\u043e\u0440\u043a\u0435 \u044f\u0434\u0440\u0430 \u0434\u043b\u044f \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043e\u0442\u043b\u0430\u0434\u043e\u0447\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 BTF. \u041c\u044b \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0434\u0435\u0442\u0430\u043b\u044f\u0445 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0438 BTF, \u043a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e \u0444\u0430\u043a\u0442\u0430, \u0447\u0442\u043e \u044d\u0442\u043e \u0443\u0434\u043e\u0431\u043d\u043e \u0438 \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c. \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u0435\u0441\u043b\u0438 \u0432\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442\u0435\u0441\u044c \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c \u0441\u0432\u043e\u0435 \u044f\u0434\u0440\u043e, \u0441\u043e\u0431\u0435\u0440\u0438\u0442\u0435 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 <code>pahole<\/code> (\u0431\u0435\u0437 <code>pahole<\/code> \u0432\u044b \u043d\u0435 \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u044f\u0434\u0440\u043e \u0441 \u043e\u043f\u0446\u0438\u0435\u0439 <code>CONFIG_DEBUG_INFO_BTF<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ git clone https:\/\/git.kernel.org\/pub\/scm\/devel\/pahole\/pahole.git $ cd pahole\/ $ sudo apt install cmake $ mkdir build $ cd build\/ $ cmake -D__LIB=lib .. $ make $ sudo make install $ which pahole \/usr\/local\/bin\/pahole<\/code><\/pre>\n<p>  <\/p>\n<h4>\u042f\u0434\u0440\u0430 \u0434\u043b\u044f \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u0432 \u0441 BPF<\/h4>\n<p>  <\/p>\n<p>\u041f\u0440\u0438 \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439 BPF \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u0441\u0432\u043e\u0435 \u044f\u0434\u0440\u043e. \u042d\u0442\u043e, \u0432\u043e\u043e\u0431\u0449\u0435 \u0433\u043e\u0432\u043e\u0440\u044f, \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u0442\u0430\u043a \u043a\u0430\u043a \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c \u0438 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b BPF \u0438 \u043d\u0430 \u0434\u0438\u0441\u0442\u0440\u0438\u0431\u0443\u0442\u0438\u0432\u043d\u043e\u043c \u044f\u0434\u0440\u0435, \u043e\u0434\u043d\u0430\u043a\u043e, \u043d\u0430\u043b\u0438\u0447\u0438\u0435 \u0441\u0432\u043e\u0435\u0433\u043e \u044f\u0434\u0440\u0430 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u0430\u043c\u044b\u0435 \u043d\u043e\u0432\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 BPF, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u043a\u0430\u0436\u0443\u0442\u0441\u044f \u0432 \u0432\u0430\u0448\u0435\u043c \u0434\u0438\u0441\u0442\u0440\u0438\u0431\u0443\u0442\u0438\u0432\u0435 \u0432 \u043b\u0443\u0447\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0447\u0435\u0440\u0435\u0437 \u043c\u0435\u0441\u044f\u0446\u044b \u0438\u043b\u0438, \u043a\u0430\u043a \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u0441 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043e\u0442\u043b\u0430\u0434\u043e\u0447\u043d\u044b\u043c\u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u0430\u043c\u0438, \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0435 \u0431\u0443\u0434\u0443\u0442 \u043e\u043f\u0430\u043a\u0435\u0447\u0435\u043d\u044b \u0432 \u043e\u0431\u043e\u0437\u0440\u0438\u043c\u043e\u043c \u0431\u0443\u0434\u0443\u0449\u0435\u043c. \u0422\u0430\u043a\u0436\u0435 \u0441\u0432\u043e\u0435 \u044f\u0434\u0440\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 <s>\u043f\u043e\u0447\u0443\u0432\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441\u0435\u0431\u044f \u0432\u0430\u0436\u043d\u044b\u043c<\/s> \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441 \u043a\u043e\u0434\u043e\u043c.<\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u044f\u0434\u0440\u043e \u0432\u0430\u043c \u043d\u0443\u0436\u043d\u043e, \u0432\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u0441\u0430\u043c\u043e \u044f\u0434\u0440\u043e, \u0430 \u0432\u043e-\u0432\u0442\u043e\u0440\u044b\u0445, \u0444\u0430\u0439\u043b \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u044f\u0434\u0440\u0430. \u0414\u043b\u044f \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u043e\u0432 \u0441 BPF \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u044b\u0447\u043d\u043e\u0435 <a href=\"https:\/\/github.com\/torvalds\/linux.git\" rel=\"nofollow\">\u0432\u0430\u043d\u0438\u043b\u044c\u043d\u043e\u0435<\/a> \u044f\u0434\u0440\u043e \u0438\u043b\u0438 \u043e\u0434\u043d\u043e \u0438\u0437 \u0434\u0435\u0432\u0435\u043b\u043e\u043f\u0435\u0440\u0441\u043a\u0438\u0445 \u044f\u0434\u0435\u0440. \u0418\u0441\u0442\u043e\u0440\u0438\u0447\u0435\u0441\u043a\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0430 BPF \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 \u0440\u0430\u043c\u043a\u0430\u0445 \u0441\u0435\u0442\u0435\u0432\u043e\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u0430 Linux \u0438 \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432\u0441\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0440\u0430\u043d\u043e \u0438\u043b\u0438 \u043f\u043e\u0437\u0434\u043d\u043e \u043f\u0440\u043e\u0445\u043e\u0434\u044f\u0442 \u0447\u0435\u0440\u0435\u0437 \u0414\u044d\u0432\u0438\u0434\u0430 \u041c\u0438\u043b\u043b\u0435\u0440\u0430 (David Miller) \u2014 \u043c\u0430\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u0430 \u0441\u0435\u0442\u0435\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 Linux. \u0412 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0441\u0432\u043e\u0435\u0439 \u043f\u0440\u0438\u0440\u043e\u0434\u044b \u2014 \u043f\u0440\u0430\u0432\u043a\u0430 \u0438\u043b\u0438 \u043d\u043e\u0432\u044b\u0435 \u0444\u0438\u0447\u0438 \u2014 \u0441\u0435\u0442\u0435\u0432\u044b\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u043f\u043e\u043f\u0430\u0434\u0430\u044e\u0442 \u0432 \u043e\u0434\u043d\u043e \u0438\u0437 \u0434\u0432\u0443\u0445 \u044f\u0434\u0435\u0440 \u2014 <a href=\"https:\/\/git.kernel.org\/pub\/scm\/linux\/kernel\/git\/netdev\/net.git\" rel=\"nofollow\"><code>net<\/code><\/a> \u0438\u043b\u0438 <a href=\"https:\/\/git.kernel.org\/pub\/scm\/linux\/kernel\/git\/netdev\/net-next.git\" rel=\"nofollow\"><code>net-next<\/code><\/a>. \u0418\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0434\u043b\u044f BPF \u0442\u0430\u043a\u0438\u043c \u0436\u0435 \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0442\u0441\u044f \u043c\u0435\u0436\u0434\u0443 <a href=\"https:\/\/git.kernel.org\/pub\/scm\/linux\/kernel\/git\/bpf\/bpf.git\/\" rel=\"nofollow\"><code>bpf<\/code><\/a> \u0438 <a href=\"https:\/\/git.kernel.org\/pub\/scm\/linux\/kernel\/git\/bpf\/bpf-next.git\/\" rel=\"nofollow\"><code>bpf-next<\/code><\/a>, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0442\u043e\u043c \u043f\u0443\u043b\u044f\u0442\u0441\u044f \u0432 net \u0438 net-next, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0441\u043c. \u0432 <a href=\"https:\/\/www.kernel.org\/doc\/html\/latest\/bpf\/bpf_devel_QA.html#llvm\" rel=\"nofollow\">bpf_devel_QA<\/a> \u0438 <a href=\"https:\/\/www.kernel.org\/doc\/html\/latest\/networking\/netdev-FAQ.html\" rel=\"nofollow\">netdev-FAQ<\/a>. \u0422\u0430\u043a \u0447\u0442\u043e \u0432\u044b\u0431\u0438\u0440\u0430\u0439\u0442\u0435 \u044f\u0434\u0440\u043e \u0438\u0441\u0445\u043e\u0434\u044f \u0438\u0437 \u0432\u0430\u0448\u0435\u0433\u043e \u0432\u043a\u0443\u0441\u0430 \u0438 \u043f\u043e\u0442\u0440\u0435\u0431\u043d\u043e\u0441\u0442\u0435\u0439 \u0432 \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0441\u0438\u0441\u0442\u0435\u043c\u044b, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0432\u044b \u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0435\u0442\u0435 (<code>*-next<\/code> \u044f\u0434\u0440\u0430 \u0441\u0430\u043c\u044b\u0435 \u043d\u0435\u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u044b\u0435 \u0438\u0437 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0445).<\/p>\n<p>  <\/p>\n<p>\u0412 \u0440\u0430\u043c\u043a\u0438 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u043d\u0435 \u0432\u0445\u043e\u0434\u0438\u0442 \u0440\u0430\u0441\u0441\u043a\u0430\u0437 \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0441 \u0444\u0430\u0439\u043b\u0430\u043c\u0438 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u044f\u0434\u0440\u0430 \u2014 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0432\u044b \u043b\u0438\u0431\u043e \u0443\u0436\u0435 \u0443\u043c\u0435\u0435\u0442\u0435 \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c, \u043b\u0438\u0431\u043e <a href=\"https:\/\/kernelnewbies.org\/KernelBuild\" rel=\"nofollow\">\u0433\u043e\u0442\u043e\u0432\u044b \u043d\u0430\u0443\u0447\u0438\u0442\u044c\u0441\u044f<\/a> \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e. \u041e\u0434\u043d\u0430\u043a\u043e, \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0439 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c, \u0431\u043e\u043b\u0435\u0435-\u043c\u0435\u043d\u0435\u0435, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u0443 \u0432\u0430\u0441 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0430\u0441\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0430\u044f \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u0441 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u043e\u0439 BPF.<\/p>\n<p>  <\/p>\n<p>\u0421\u043a\u0430\u0447\u0430\u0442\u044c \u043e\u0434\u043d\u043e \u0438\u0437 \u0432\u044b\u0448\u0435\u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u044b\u0445 \u044f\u0434\u0435\u0440:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ git clone git:\/\/git.kernel.org\/pub\/scm\/linux\/kernel\/git\/bpf\/bpf-next.git $ cd bpf-next<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u043e\u0431\u0440\u0430\u0442\u044c \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0438\u0439 \u043a\u043e\u043d\u0444\u0438\u0433 \u044f\u0434\u0440\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ cp \/boot\/config-`uname -r` .config $ make localmodconfig<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043e\u043f\u0446\u0438\u0438 BPF \u0432 \u0444\u0430\u0439\u043b\u0435 <code>.config<\/code> \u043f\u043e \u0441\u0432\u043e\u0435\u043c\u0443 \u0432\u044b\u0431\u043e\u0440\u0443 (\u0441\u043a\u043e\u0440\u0435\u0435 \u0432\u0441\u0435\u0433\u043e, \u0441\u0430\u043c <code>CONFIG_BPF<\/code> \u0443\u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u043a\u043b\u044e\u0447\u0435\u043d, \u0442\u0430\u043a \u043a\u0430\u043a \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 systemd). \u0412\u043e\u0442 \u0441\u043f\u0438\u0441\u043e\u043a \u043e\u043f\u0446\u0438\u0439 \u0438\u0437 \u044f\u0434\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u043e\u0441\u044c \u0434\u043b\u044f \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">CONFIG_CGROUP_BPF=y CONFIG_BPF=y CONFIG_BPF_LSM=y CONFIG_BPF_SYSCALL=y CONFIG_ARCH_WANT_DEFAULT_BPF_JIT=y CONFIG_BPF_JIT_ALWAYS_ON=y CONFIG_BPF_JIT_DEFAULT_ON=y CONFIG_IPV6_SEG6_BPF=y # CONFIG_NETFILTER_XT_MATCH_BPF is not set # CONFIG_BPFILTER is not set CONFIG_NET_CLS_BPF=y CONFIG_NET_ACT_BPF=y CONFIG_BPF_JIT=y CONFIG_BPF_STREAM_PARSER=y CONFIG_LWTUNNEL_BPF=y CONFIG_HAVE_EBPF_JIT=y CONFIG_BPF_EVENTS=y CONFIG_BPF_KPROBE_OVERRIDE=y CONFIG_DEBUG_INFO_BTF=y<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u0430\u043b\u044c\u0448\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043b\u0435\u0433\u043a\u043e \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c \u043c\u043e\u0434\u0443\u043b\u0438 \u0438 \u044f\u0434\u0440\u043e (\u043a\u0441\u0442\u0430\u0442\u0438, \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0431\u0440\u0430\u0442\u044c \u044f\u0434\u0440\u043e \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0442\u043e \u0441\u043e\u0431\u0440\u0430\u043d\u043d\u043e\u0433\u043e <code>clang<\/code>, \u0434\u043e\u0431\u0430\u0432\u0438\u0432 <code>CC=clang<\/code>):<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ make -s -j $(getconf _NPROCESSORS_ONLN) $ sudo make modules_install $ sudo make install<\/code><\/pre>\n<p>  <\/p>\n<p>\u0438 \u043f\u0435\u0440\u0435\u0437\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c\u0441\u044f \u0441 \u043d\u043e\u0432\u044b\u043c \u044f\u0434\u0440\u043e\u043c (\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e <code>kexec<\/code> \u0438\u0437 \u043f\u0430\u043a\u0435\u0442\u0430 <code>kexec-tools<\/code>):<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">v=5.8.0-rc6+ # \u0435\u0441\u043b\u0438 \u0432\u044b \u043f\u0435\u0440\u0435\u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442\u0435 \u0442\u0435\u043a\u0443\u0449\u0435\u0435 \u044f\u0434\u0440\u043e, \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c v=`uname -r` sudo kexec -l -t bzImage \/boot\/vmlinuz-$v --initrd=\/boot\/initrd.img-$v --reuse-cmdline &amp;&amp; sudo kexec -e<\/code><\/pre>\n<p>  <\/p>\n<h4>bpftool<\/h4>\n<p>  <\/p>\n<p>\u041d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u043e\u0439 \u0443\u0442\u0438\u043b\u0438\u0442\u043e\u0439 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 \u0431\u0443\u0434\u0435\u0442 \u0443\u0442\u0438\u043b\u0438\u0442\u0430 <code>bpftool<\/code>, \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u0430\u044f \u0432 \u0441\u043e\u0441\u0442\u0430\u0432\u0435 \u044f\u0434\u0440\u0430 Linux. \u041e\u043d\u0430 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0430 \u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u043c\u0438 BPF \u0434\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 BPF \u0438 \u0441 \u0435\u0435 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u043e\u0436\u043d\u043e \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c\u0441\u044f \u0441\u043e \u0432\u0441\u0435\u043c\u0438 \u0442\u0438\u043f\u0430\u043c\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 BPF \u2014 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b, \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0438 \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c maps, \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u0436\u0438\u0437\u043d\u0435\u0434\u0435\u044f\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u044d\u043a\u043e\u0441\u0438\u0441\u0442\u0435\u043c\u044b BPF, \u0438 \u0442.\u043f. \u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e \u0432 \u0432\u0438\u0434\u0435 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u043e\u0432 \u043a man pages \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 <a href=\"https:\/\/github.com\/torvalds\/linux\/tree\/master\/tools\/bpf\/bpftool\/Documentation\" rel=\"nofollow\">\u0432 \u044f\u0434\u0440\u0435<\/a> \u0438\u043b\u0438, \u0443\u0436\u0435 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e, <a href=\"https:\/\/www.mankier.com\/8\/bpftool\" rel=\"nofollow\">\u0432 \u0441\u0435\u0442\u0438<\/a>.<\/p>\n<p>  <\/p>\n<p>\u041d\u0430 \u043c\u043e\u043c\u0435\u043d\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u0441\u0442\u0430\u0442\u044c\u0438 <code>bpftool<\/code> \u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u0433\u043e\u0442\u043e\u0432\u043e\u043c \u0432\u0438\u0434\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f RHEL, Fedora \u0438 Ubuntu (\u0441\u043c., \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <a href=\"https:\/\/bugs.debian.org\/cgi-bin\/bugreport.cgi?bug=896165\" rel=\"nofollow\">\u044d\u0442\u043e\u0442 \u0442\u0440\u0435\u0434<\/a>, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0435\u043e\u043a\u043e\u043d\u0447\u0435\u043d\u043d\u0430\u044f \u0438\u0441\u0442\u043e\u0440\u0438\u044f \u043e\u043f\u0430\u043a\u0435\u0447\u0438\u0432\u0430\u043d\u0438\u044f <code>bpftool<\/code> \u0432 Debian). \u041d\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u0443\u0436\u0435 \u0441\u043e\u0431\u0440\u0430\u043b\u0438 \u0441\u0432\u043e\u0435 \u044f\u0434\u0440\u043e, \u0442\u043e \u0441\u043e\u0431\u0440\u0430\u0442\u044c <code>bpftool<\/code> \u043f\u0440\u043e\u0449\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ cd ${linux}\/tools\/bpf\/bpftool # ... \u043f\u0440\u043e\u043f\u0438\u0448\u0438\u0442\u0435 \u043f\u0443\u0442\u0438 \u043a \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u043c\u0443 clang, \u043a\u0430\u043a \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u043d\u043e \u0432\u044b\u0448\u0435 $ make -s  Auto-detecting system features: ...                        libbfd: [ on  ] ...        disassembler-four-args: [ on  ] ...                          zlib: [ on  ] ...                        libcap: [ on  ] ...               clang-bpf-co-re: [ on  ]  Auto-detecting system features: ...                        libelf: [ on  ] ...                          zlib: [ on  ] ...                           bpf: [ on  ]  $<\/code><\/pre>\n<p>  <\/p>\n<p>(\u0437\u0434\u0435\u0441\u044c <code>${linux}<\/code> \u2014 \u044d\u0442\u043e \u0432\u0430\u0448\u0430 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u044f \u0441 \u044f\u0434\u0440\u043e\u043c.) \u041f\u043e\u0441\u043b\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u044d\u0442\u0438\u0445 \u043a\u043e\u043c\u0430\u043d\u0434 <code>bpftool<\/code> \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0431\u0440\u0430\u043d\u0430 \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 <code>${linux}\/tools\/bpf\/bpftool<\/code> \u0438 \u0435\u0435 \u043c\u043e\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u043f\u0443\u0442\u044c (\u043f\u0440\u0435\u0436\u0434\u0435 \u0432\u0441\u0435\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e <code>root<\/code>) \u0438\u043b\u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432 <code>\/usr\/local\/sbin<\/code>.<\/p>\n<p>  <\/p>\n<p>\u0421\u043e\u0431\u0438\u0440\u0430\u0442\u044c <code>bpftool<\/code> \u043b\u0443\u0447\u0448\u0435 \u0432\u0441\u0435\u0433\u043e \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e <code>clang<\/code>, \u0441\u043e\u0431\u0440\u0430\u043d\u043d\u043e\u0433\u043e, \u043a\u0430\u043a \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u043d\u043e \u0432\u044b\u0448\u0435, \u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043b\u0438 \u043e\u043d\u0430 \u0441\u043e\u0431\u0440\u0430\u043b\u0430\u0441\u044c \u2014 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043e\u043c\u0430\u043d\u0434\u044b<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ sudo bpftool feature probe kernel Scanning system configuration... bpf() syscall for unprivileged users is enabled JIT compiler is enabled JIT compiler hardening is disabled JIT compiler kallsyms exports are enabled for root ...<\/code><\/pre>\n<p>  <\/p>\n<p>\u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u043a\u0430\u0436\u0435\u0442, \u043a\u0430\u043a\u0438\u0435 \u0444\u0438\u0447\u0438 BPF \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u044b \u0443 \u0432\u0430\u0441 \u0432 \u044f\u0434\u0440\u0435.<\/p>\n<p>  <\/p>\n<p>\u041a\u0441\u0442\u0430\u0442\u0438, \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0443\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043a\u0430\u043a<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\"># bpftool f p k<\/code><\/pre>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u043f\u043e \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0438 \u0441 \u0443\u0442\u0438\u043b\u0438\u0442\u0430\u043c\u0438 \u0438\u0437 \u043f\u0430\u043a\u0435\u0442\u0430 <code>iproute2<\/code>, \u0433\u0434\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u043a\u0430\u0437\u0430\u0442\u044c <code>ip a s eth0<\/code> \u0432\u043c\u0435\u0441\u0442\u043e <code>ip addr show dev eth0<\/code>.<\/p>\n<p>  <\/p>\n<h2 id=\"this-is-the-end\">\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>  <\/p>\n<p>BPF \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 <s>\u043f\u043e\u0434\u043a\u043e\u0432\u0430\u0442\u044c \u0431\u043b\u043e\u0445\u0443<\/s> \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e \u0438\u0437\u043c\u0435\u0440\u044f\u0442\u044c \u0438 \u043d\u0430\u043b\u0435\u0442\u0443 \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u044f\u0434\u0440\u0430. \u0421\u0438\u0441\u0442\u0435\u043c\u0430 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0430\u0441\u044c \u043e\u0447\u0435\u043d\u044c \u0443\u0434\u0430\u0447\u043d\u043e\u0439, \u0432 \u043b\u0443\u0447\u0448\u0438\u0445 \u0442\u0440\u0430\u0434\u0438\u0446\u0438\u044f\u0445 UNIX: \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0439 (\u043f\u0435\u0440\u0435)\u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044f\u0434\u0440\u043e, \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u043b \u043e\u0433\u0440\u043e\u043c\u043d\u043e\u043c\u0443 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0443 \u043b\u044e\u0434\u0435\u0439 \u0438 \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u0439 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u0418, \u0445\u043e\u0442\u044f \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u044b, \u0442\u0430\u043a \u0436\u0435 \u043a\u0430\u043a \u0438 \u0440\u0430\u0437\u0432\u0438\u0442\u0438\u0435 \u0441\u0430\u043c\u043e\u0439 \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b BPF, \u0435\u0449\u0435 \u0434\u0430\u043b\u0435\u043a\u043e \u043d\u0435 \u0437\u0430\u043a\u043e\u043d\u0447\u0435\u043d\u044b, \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u0443\u0436\u0435 \u0438\u043c\u0435\u0435\u0442 \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u043e\u0435 ABI, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0435\u0435 \u0432\u044b\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0442\u044c \u043d\u0430\u0434\u0435\u0436\u043d\u0443\u044e, \u0430 \u0433\u043b\u0430\u0432\u043d\u043e\u0435, \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u0443\u044e \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0443.<\/p>\n<p>  <\/p>\n<p>\u0425\u043e\u0447\u0435\u0442\u0441\u044f \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u043f\u043e \u043c\u043e\u0435\u043c\u0443 \u043c\u043d\u0435\u043d\u0438\u044e \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u044f \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0430\u0441\u044c \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u043e\u0439 \u043e\u0442\u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u0441 \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u0432 \u043d\u0435\u0435 \u043c\u043e\u0436\u043d\u043e <em>\u0438\u0433\u0440\u0430\u0442\u044c<\/em> (\u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443 \u043c\u0430\u0448\u0438\u043d\u044b \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u044c \u0431\u043e\u043b\u0435\u0435-\u043c\u0435\u043d\u0435\u0435 \u0437\u0430 \u043e\u0434\u0438\u043d \u0432\u0435\u0447\u0435\u0440), \u0430 \u0441 \u0434\u0440\u0443\u0433\u043e\u0439 \u2014\u00a0\u0440\u0435\u0448\u0430\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0438, \u043d\u0435 \u0440\u0435\u0448\u0430\u0435\u043c\u044b\u0435 (\u043a\u0440\u0430\u0441\u0438\u0432\u043e) \u0434\u043e \u0435\u0435 \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u044f. \u0414\u0432\u0435 \u044d\u0442\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u044b \u0432\u043c\u0435\u0441\u0442\u0435 \u0437\u0430\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u043b\u044e\u0434\u0435\u0439 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438 \u043c\u0435\u0447\u0442\u0430\u0442\u044c, \u0447\u0442\u043e \u0438 \u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u043f\u043e\u044f\u0432\u043b\u0435\u043d\u0438\u044e \u0432\u0441\u0435 \u043d\u043e\u0432\u044b\u0445 \u0438 \u043d\u043e\u0432\u044b\u0445 \u0438\u043d\u043d\u043e\u0432\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439.<\/p>\n<p>  <\/p>\n<p>\u0414\u0430\u043d\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f, \u0445\u043e\u0442\u044c \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0430\u0441\u044c \u043d\u0435 \u043e\u0441\u043e\u0431\u043e \u043a\u043e\u0440\u043e\u0442\u043a\u043e\u0439, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u0432\u0435\u0434\u0435\u043d\u0438\u0435\u043c \u0432 \u043c\u0438\u0440 BPF \u0438 \u043d\u0435 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u00ab\u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u044b\u0435\u00bb \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u0438 \u0432\u0430\u0436\u043d\u044b\u0435 \u0447\u0430\u0441\u0442\u0438 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b. \u0414\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0438\u0439 \u043f\u043b\u0430\u043d, \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e, \u0442\u0430\u043a\u043e\u0439: \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0437\u043e\u0440\u043e\u043c \u0442\u0438\u043f\u043e\u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c BPF (\u0432 \u044f\u0434\u0440\u0435 5.8 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f 30 \u0442\u0438\u043f\u043e\u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c), \u0437\u0430\u0442\u0435\u043c \u043c\u044b, \u043d\u0430\u043a\u043e\u043d\u0435\u0446, \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0442\u043e, \u043a\u0430\u043a \u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0438\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u043d\u0430 BPF \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c \u0434\u043b\u044f \u0442\u0440\u0430\u0441\u0441\u0438\u0440\u043e\u0432\u043a\u0438 \u044f\u0434\u0440\u0430, \u0437\u0430\u0442\u0435\u043c \u043f\u0440\u0438\u0434\u0435\u0442 \u0432\u0440\u0435\u043c\u044f \u0434\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u0443\u0433\u043b\u0443\u0431\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u043a\u0443\u0440\u0441\u0430 \u043f\u043e \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0435 BPF, \u0430 \u0437\u0430\u0442\u0435\u043c \u2014 \u0434\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u0441\u0435\u0442\u0435\u0432\u044b\u0445 \u0438 security \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 BPF.<\/p>\n<p>  <\/p>\n<h2>\u041f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0435 \u0441\u0442\u0430\u0442\u044c\u0438 \u044d\u0442\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430<\/h2>\n<p>  <\/p>\n<ol>\n<li><a href=\"https:\/\/habr.com\/ru\/post\/493880\/\">BPF \u0434\u043b\u044f \u0441\u0430\u043c\u044b\u0445 \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u0445, \u0447\u0430\u0441\u0442\u044c \u043d\u0443\u043b\u0435\u0432\u0430\u044f: classic BPF<\/a><\/li>\n<\/ol>\n<p>  <\/p>\n<h2>\u0421\u044b\u043b\u043a\u0438<\/h2>\n<p>  <\/p>\n<ol>\n<li>\n<p><a href=\"https:\/\/docs.cilium.io\/en\/latest\/bpf\" rel=\"nofollow\">BPF and XDP Reference Guide<\/a> \u2014 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f \u043f\u043e BPF \u043e\u0442 cilium, \u0430 \u0442\u043e\u0447\u043d\u0435\u0435 \u043e\u0442 Daniel Borkman, \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0437 \u0441\u043e\u0437\u0434\u0430\u0442\u0435\u043b\u0435\u0439 \u0438 \u043c\u0430\u043d\u0442\u0435\u0439\u043d\u0435\u0440\u043e\u0432 BPF. \u042d\u0442\u043e \u043e\u0434\u043d\u043e \u0438\u0437 \u043f\u0435\u0440\u0432\u044b\u0445 \u0441\u0435\u0440\u044c\u0435\u0437\u043d\u044b\u0445 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043e\u0442\u043b\u0438\u0447\u043d\u043e \u043e\u0442 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u0442\u0435\u043c, \u0447\u0442\u043e Daniel \u0442\u043e\u0447\u043d\u043e \u0437\u043d\u0430\u0435\u0442 \u043e \u0447\u0435\u043c \u043f\u0438\u0448\u0435\u0442 \u0438 \u043b\u044f\u043f\u043e\u0432 \u0442\u0430\u043c \u043d\u0435 \u043d\u0430\u0431\u043b\u044e\u0434\u0430\u0435\u0442\u0441\u044f. \u0412 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u0432 \u044d\u0442\u043e\u043c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0435 \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430\u043c\u0438 BPF \u0442\u0438\u043f\u043e\u0432 XDP \u0438 TC \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u043e\u0439 \u0443\u0442\u0438\u043b\u0438\u0442\u044b <code>ip<\/code> \u0438\u0437 \u043f\u0430\u043a\u0435\u0442\u0430 <code>iproute2<\/code>.<\/p>\n<p>  <\/li>\n<li>\n<p><a href=\"https:\/\/git.kernel.org\/pub\/scm\/linux\/kernel\/git\/bpf\/bpf-next.git\/tree\/Documentation\/networking\/filter.txt\" rel=\"nofollow\">Documentation\/networking\/filter.txt<\/a> \u2014 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u0441 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0435\u0439 \u043f\u043e \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u043c\u0443, \u0430 \u0437\u0430\u0442\u0435\u043c \u0438 \u043f\u043e extended BPF. \u041f\u043e\u043b\u0435\u0437\u043d\u043e \u0447\u0438\u0442\u0430\u0442\u044c, \u0435\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u043f\u043e\u043a\u043e\u043f\u0430\u0442\u044c\u0441\u044f \u0432 \u0430\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440\u0435 \u0438 \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0434\u0435\u0442\u0430\u043b\u044f\u0445 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b.<\/p>\n<p>  <\/li>\n<li>\n<p><a href=\"https:\/\/facebookmicrosites.github.io\/bpf\/\" rel=\"nofollow\">\u0411\u043b\u043e\u0433 \u043f\u0440\u043e BPF \u043e\u0442 facebook<\/a>. \u041e\u0431\u043d\u043e\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0440\u0435\u0434\u043a\u043e, \u043d\u043e \u043c\u0435\u0442\u043a\u043e, \u0442\u0430\u043a \u043a\u0430\u043a \u043f\u0438\u0448\u0443\u0442 \u0442\u0443\u0434\u0430 Alexei Starovoitov (\u0430\u0432\u0442\u043e\u0440 eBPF) \u0438 Andrii Nakryiko \u2014 (\u043c\u0430\u043d\u0442\u0435\u0439\u043d\u0435\u0440 <code>libbpf<\/code>).<\/p>\n<p>  <\/li>\n<li>\n<p><a href=\"https:\/\/twitter.com\/qeole\/status\/1101450782841466880\" rel=\"nofollow\">\u0421\u0435\u043a\u0440\u0435\u0442\u044b bpftool<\/a>. \u0417\u0430\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 twitter-\u0442\u0440\u0435\u0434 \u043e\u0442 Quentin Monnet \u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 \u0438 \u0441\u0435\u043a\u0440\u0435\u0442\u0430\u043c\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f bpftool.<\/p>\n<p>  <\/li>\n<li>\n<p><a href=\"https:\/\/qmonnet.github.io\/whirl-offload\/2016\/09\/01\/dive-into-bpf\/\" rel=\"nofollow\">Dive into BPF: a list of reading material<\/a>. \u0413\u0438\u0433\u0430\u043d\u0442\u0441\u043a\u0438\u0439 (\u0438 \u0434\u043e \u0441\u0438\u0445 \u043f\u043e\u0440 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043c\u044b\u0439) \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u0441\u044b\u043b\u043e\u043a \u043d\u0430 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e \u043f\u043e BPF \u043e\u0442 Quentin Monnet.<\/p>\n<p>  <\/li>\n<\/ol>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/514736\/\"> https:\/\/habr.com\/ru\/post\/514736\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/514736\/\">\n<p>\u0412 \u043d\u0430\u0447\u0430\u043b\u0435 \u0431\u044b\u043b\u0430 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u044f \u0438 \u043d\u0430\u0437\u044b\u0432\u0430\u043b\u0430\u0441\u044c \u043e\u043d\u0430 BPF. \u041c\u044b \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438 \u043d\u0430 \u043d\u0435\u0435 \u0432 <a href=\"https:\/\/habr.com\/ru\/post\/493880\/\">\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439<\/a>, \u0432\u0435\u0442\u0445\u043e\u0437\u0430\u0432\u0435\u0442\u043d\u043e\u0439, \u0441\u0442\u0430\u0442\u044c\u0435 \u044d\u0442\u043e\u0433\u043e \u0446\u0438\u043a\u043b\u0430. \u0412 2013 \u0433\u043e\u0434\u0443 \u0443\u0441\u0438\u043b\u0438\u044f\u043c\u0438 \u0410\u043b\u0435\u043a\u0441\u0435\u044f \u0421\u0442\u0430\u0440\u043e\u0432\u043e\u0439\u0442\u043e\u0432\u0430 (Alexei Starovoitov) \u0438 \u0414\u0430\u043d\u0438\u044d\u043b\u044f \u0411\u043e\u0440\u043a\u043c\u0430\u043d\u0430 (Daniel Borkman) \u0431\u044b\u043b\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u0430 \u0438 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0430 \u0432 \u044f\u0434\u0440\u043e Linux \u0435\u0435 \u0443\u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u0441\u0442\u0432\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f, \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u043f\u043e\u0434 \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 64-\u0431\u0438\u0442\u043d\u044b\u0435 \u043c\u0430\u0448\u0438\u043d\u044b. \u042d\u0442\u0430 \u043d\u043e\u0432\u0430\u044f \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u044f \u043d\u0435\u0434\u043e\u043b\u0433\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043d\u043e\u0441\u0438\u043b\u0430 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 Internal BPF, \u0437\u0430\u0442\u0435\u043c \u0431\u044b\u043b\u0430 \u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0430 \u0432 Extended BPF, \u0430 \u0442\u0435\u043f\u0435\u0440\u044c, \u043f\u043e \u043f\u0440\u043e\u0448\u0435\u0441\u0442\u0432\u0438\u0438 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043b\u0435\u0442, \u0432\u0441\u0435 \u0435\u0435 \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u043f\u0440\u043e\u0441\u0442\u043e BPF.<\/p>\n<p>  <\/p>\n<p>\u0413\u0440\u0443\u0431\u043e \u0433\u043e\u0432\u043e\u0440\u044f, BPF \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u0434, \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c, \u0432 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435 \u044f\u0434\u0440\u0430 Linux \u0438 \u043d\u043e\u0432\u0430\u044f \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u043e\u043a\u0430\u0437\u0430\u043b\u0430\u0441\u044c \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0443\u0434\u0430\u0447\u043d\u043e\u0439, \u0447\u0442\u043e \u043d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0435\u0449\u0435 \u0441 \u0434\u0435\u0441\u044f\u0442\u043e\u043a \u0441\u0442\u0430\u0442\u0435\u0439, \u0447\u0442\u043e\u0431\u044b \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0432\u0441\u0435 \u0435\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u044f. (<s>\u0415\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0441 \u0447\u0435\u043c \u043d\u0435 \u0441\u043f\u0440\u0430\u0432\u0438\u043b\u0438\u0441\u044c \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438, \u043a\u0430\u043a \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0432\u0438\u0434\u0435\u0442\u044c \u043d\u0430 \u043a\u043f\u0434\u0432 \u043d\u0438\u0436\u0435, \u044d\u0442\u043e \u0441 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435\u043c \u043f\u0440\u0438\u043b\u0438\u0447\u043d\u043e\u0433\u043e \u043b\u043e\u0433\u043e\u0442\u0438\u043f\u0430.<\/s>)<\/p>\n<p>  <\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0439 \u043c\u0430\u0448\u0438\u043d\u044b BPF, \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b \u044f\u0434\u0440\u0430 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 BPF, \u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043a\u0440\u0430\u0442\u043a\u0438\u0439, \u043e\u0447\u0435\u043d\u044c \u043a\u0440\u0430\u0442\u043a\u0438\u0439, \u043e\u0431\u0437\u043e\u0440 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439, \u0442.\u0435. \u0432\u0441\u0451 \u0442\u043e, \u0447\u0442\u043e \u043d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c \u0434\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u0433\u043b\u0443\u0431\u043e\u043a\u043e\u0433\u043e \u0438\u0437\u0443\u0447\u0435\u043d\u0438\u044f \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0439 BPF.<br \/>  <a href=\"https:\/\/habr.com\/ru\/post\/514736\/\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/eb\/cx\/cq\/ebcxcqjpcedlop51jeh-bvbhyfy.png\"><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-308320","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/308320","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=308320"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/308320\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=308320"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=308320"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=308320"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}