{"id":91402,"date":"2020-08-12T19:42:34","date_gmt":"2020-08-12T17:42:34","guid":{"rendered":"https:\/\/prohoster.info\/blog\/administrirovanie\/bpf-dlya-samyh-malenkih-chast-pervaya-extended-bpf"},"modified":"2020-08-12T19:42:34","modified_gmt":"2020-08-12T17:42:34","slug":"bpf-dlya-samyh-malenkih-chast-pervaya-extended-bpf","status":"publish","type":"post","link":"https:\/\/prohoster.info\/it\/blog\/administrirovanie\/bpf-dlya-samyh-malenkih-chast-pervaya-extended-bpf","title":{"rendered":"BPF per i pi\u00f9 piccoli, parte prima: extended BPF","gt_translate_keys":[{"key":"rendered","format":"text"}]},"content":{"rendered":"<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 <noindex><a rel=\"nofollow\" href=\"https:\/\/habr.com\/ru\/post\/493880\/\">\u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439<\/a><\/noindex>, \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. (\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.)<\/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 \/>\n<noindex><a rel=\"nofollow\" href=\"https:\/\/habr.com\/ru\/post\/514736\/\"><img decoding=\"async\" alt=\"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\" src=\"\/wp-content\/uploads\/2020\/08\/4e1c224cd792b703d6bb0c317b47f908.jpg\" style=\"display:block;margin: 0 auto;\" \/><\/a><\/noindex><\/p>\n<p><noindex><a rel=\"nofollow\" name=\"habracut\"><\/a><\/noindex><\/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><noindex><a rel=\"nofollow\" 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><\/noindex> \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><noindex><a rel=\"nofollow\" 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><\/noindex> \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><noindex><a rel=\"nofollow\" 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><\/noindex> \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><noindex><a rel=\"nofollow\" 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><\/noindex> \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><noindex><a rel=\"nofollow\" 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><\/noindex> \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><noindex><a rel=\"nofollow\" href=\"#kernel-helpers\">Kernel Helpers.<\/a><\/noindex> \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><noindex><a rel=\"nofollow\" href=\"#maps-from-progs\">\u0414\u043e\u0441\u0442\u0443\u043f \u043a maps \u0438\u0437 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c BPF.<\/a><\/noindex> \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><noindex><a rel=\"nofollow\" href=\"#tools\">\u0421\u0440\u0435\u0434\u0441\u0442\u0432\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438.<\/a><\/noindex> \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><noindex><a rel=\"nofollow\" href=\"#this-is-the-end\">\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435.<\/a><\/noindex> \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 <noindex><a rel=\"nofollow\" href=\"https:\/\/habr.com\/ru\/post\/493880\/\">\u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 BPF<\/a><\/noindex>, \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\" alt=\"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\" src=\"\/wp-content\/uploads\/2020\/08\/f7ee4007d64ae38d211417d798d8463b.jpg\" style=\"display:block;margin: 0 auto;\" \/>\n<\/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\" alt=\"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\" src=\"\/wp-content\/uploads\/2020\/08\/6e8e82dfca65c36519f7b01a08e4b46d.jpg\" style=\"display:block;margin: 0 auto;\" \/>\n<\/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\" alt=\"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\" src=\"\/wp-content\/uploads\/2020\/08\/36c5b228f5a5398fff1f6a601a96d553.jpg\" style=\"display:block;margin: 0 auto;\" \/>\n<\/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 <noindex><a rel=\"nofollow\" href=\"#tools\">\u0421\u0440\u0435\u0434\u0441\u0442\u0432\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438<\/a><\/noindex> \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\n2:  (b7) r2 = 2                    mov    $0x2,%rsi\n3:  (b7) r3 = 3                    mov    $0x3,%rdx\n4:  (b7) r4 = 4                    mov    $0x4,%rcx\n5:  (b7) r5 = 5                    mov    $0x5,%r8\n6:  (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 <noindex><a rel=\"nofollow\" href=\"https:\/\/github.com\/torvalds\/linux\/blob\/v5.7-rc3\/include\/uapi\/linux\/bpf.h#L3482\" rel=\"nofollow\"><code>struct xdp_md<\/code><\/a><\/noindex> (\u0434\u043b\u044f XDP) \u0438\u043b\u0438 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 <noindex><a rel=\"nofollow\" href=\"https:\/\/github.com\/torvalds\/linux\/blob\/v5.7-rc3\/include\/uapi\/linux\/bpf.h#L3292\" rel=\"nofollow\"><code>struct __sk_buff<\/code><\/a><\/noindex> (\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 <noindex><a rel=\"nofollow\" 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><\/noindex> (\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. \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;<\/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 (<noindex><a rel=\"nofollow\" href=\"#x16\">\u043f\u043e\u0447\u0442\u0438 \u0432\u0441\u0435<\/a><\/noindex>) \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\" alt=\"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\" src=\"\/wp-content\/uploads\/2020\/08\/b4207428692e790e85fc05d470db4927.jpg\" style=\"display:block;margin: 0 auto;\" \/>\n<\/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\" alt=\"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\" src=\"\/wp-content\/uploads\/2020\/08\/35b3176921b8db48d1a0d8fc246b06bd.jpg\" style=\"display:block;margin: 0 auto;\" \/>\n<\/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 <noindex><a rel=\"nofollow\" 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><\/noindex>, <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 <noindex><a rel=\"nofollow\" href=\"https:\/\/github.com\/torvalds\/linux\/blob\/v5.7-rc3\/include\/uapi\/linux\/bpf.h\" rel=\"nofollow\"><code>bpf.h<\/code><\/a><\/noindex> \u0438 <noindex><a rel=\"nofollow\" href=\"https:\/\/github.com\/torvalds\/linux\/blob\/v5.7-rc3\/include\/uapi\/linux\/bpf_common.h\" rel=\"nofollow\"><code>bpf_common.h<\/code><\/a><\/noindex>, \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: <noindex><a rel=\"nofollow\" href=\"https:\/\/github.com\/iovisor\/bpf-docs\/blob\/master\/eBPF.md\" rel=\"nofollow\">Unofficial eBPF spec<\/a><\/noindex>, <noindex><a rel=\"nofollow\" href=\"https:\/\/docs.cilium.io\/en\/latest\/bpf\/#instruction-set\" rel=\"nofollow\">BPF and XDP Reference Guide, Instruction Set<\/a><\/noindex>, <noindex><a rel=\"nofollow\" 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><\/noindex> \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\n$ llvm-readelf -x .text readelf-example.o\nHex dump of section '.text':\n0x00000000 b7000000 01000000 15010100 00000000 ................\n0x00000010 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\nb7   0   0   0000 01000000\n15   0   1   0100 00000000\nb7   0   0   0000 02000000\n95   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\nb  0  ALU64   0   0   0    1\n1  0  JMP     0   1   1    0\nb  0  ALU64   0   0   0    2\n9  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 <noindex><a rel=\"nofollow\" href=\"https:\/\/github.com\/torvalds\/linux\/blob\/v5.7-rc3\/include\/uapi\/linux\/bpf.h#L25\" rel=\"nofollow\">BPF_MOV<\/a><\/noindex>. \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 <noindex><a rel=\"nofollow\" href=\"https:\/\/github.com\/torvalds\/linux\/blob\/v5.7-rc3\/include\/uapi\/linux\/bpf_common.h#L45\" rel=\"nofollow\">BPF_JEQ<\/a><\/noindex> (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 <noindex><a rel=\"nofollow\" href=\"https:\/\/github.com\/torvalds\/linux\/blob\/v5.7-rc3\/include\/uapi\/linux\/bpf.h#L44\" rel=\"nofollow\"><code>BPF_EXIT<\/code><\/a><\/noindex>. \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\nMOV   0  ALU64   0   0   0    1      r0 = 1\nJEQ   0  JMP     0   1   1    0      if (r1 == 0) goto pc+1\nMOV   0  ALU64   0   0   0    2      r0 = 2\nEXIT  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\n     if (r1 == 0) goto END\n     r0 = 2\nEND:\n     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\nint foo(void *ctx)\n{\n        return ctx ? 2 : 1;\n}<\/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> = <noindex><a rel=\"nofollow\" href=\"https:\/\/github.com\/torvalds\/linux\/blob\/v5.7-rc3\/include\/uapi\/linux\/bpf_common.h#L7\" rel=\"nofollow\"><code>BPF_LD<\/code><\/a><\/noindex> | <noindex><a rel=\"nofollow\" href=\"https:\/\/github.com\/torvalds\/linux\/blob\/v5.7-rc3\/include\/uapi\/linux\/bpf.h#L21\" rel=\"nofollow\"><code>BPF_DW<\/code><\/a><\/noindex> | <noindex><a rel=\"nofollow\" href=\"https:\/\/github.com\/torvalds\/linux\/blob\/v5.7-rc3\/include\/uapi\/linux\/bpf_common.h#L23\" rel=\"nofollow\"><code>BPF_IMM<\/code><\/a><\/noindex>) \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\nlong foo(void *ctx)\n{\n        return 0x11223344aabbccdd;\n}\n$ clang -target bpf -c x64.c -o x64.o -O2\n$ llvm-readelf -x .text x64.o\nHex dump of section '.text':\n0x00000000 18000000 ddccbbaa 00000000 44332211 ............D3&quot;.\n0x00000010 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\n18000000 ddccbbaa 00000000 44332211    r0 = Imm[0]|Imm[1]\n95000000 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\n\nDisassembly of section .text:\n\n0000000000000000 &lt;foo&gt;:\n 0: 18 00 00 00 dd cc bb aa 00 00 00 00 44 33 22 11 r0 = 1234605617868164317 ll\n 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 <noindex><a rel=\"nofollow\" href=\"https:\/\/facebookmicrosites.github.io\/bpf\/blog\/2018\/08\/31\/object-lifetime.html\" rel=\"nofollow\">\u043f\u043e\u0441\u0442\u0430<\/a><\/noindex> Alexei Starovoitov \u0432 <noindex><a rel=\"nofollow\" href=\"https:\/\/facebookmicrosites.github.io\/bpf\/blog\/\" rel=\"nofollow\">BPF Blog<\/a><\/noindex>.)<\/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\" alt=\"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\" src=\"\/wp-content\/uploads\/2020\/08\/5b213cca854f962badef2373ff57648f.jpg\" style=\"display:block;margin: 0 auto;\" \/>\n<\/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\" alt=\"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\" src=\"\/wp-content\/uploads\/2020\/08\/d0de358f99b5d8da923e655f063cc2b3.jpg\" style=\"display:block;margin: 0 auto;\" \/>\n<\/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\" alt=\"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\" src=\"\/wp-content\/uploads\/2020\/08\/f34e8396d0c9cab6a024d07bdd9996bd.jpg\" style=\"display:block;margin: 0 auto;\" \/>\n<\/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\n$ 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\n__attribute__((section(&quot;xdp&quot;), used))\nint test(void *ctx)\n{\n        return 0;\n}\n\nchar _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\n$ mkdir bpf-mountpoint\n$ 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\nbpf(BPF_PROG_LOAD, {prog_type=BPF_PROG_TYPE_XDP, prog_name=&quot;test&quot;, ...}, 120) = 3\nbpf(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\n783: xdp  name test  tag 5c8ba0cf164cb46c  gpl\n        loaded_at 2020-05-05T13:27:08+0000  uid 0\n        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\n$ sudo bpftool prog show id 783\nError: 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. <noindex><a rel=\"nofollow\" href=\"#helpers-with-args\">\u043f\u0440\u0438\u043c\u0435\u0440<\/a><\/noindex> \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;\n\nint 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 <noindex><a rel=\"nofollow\" href=\"https:\/\/github.com\/torvalds\/linux\/blob\/v5.8-rc7\/include\/uapi\/linux\/bpf.h#L85\" rel=\"nofollow\"><code>enum bpf_cmd<\/code><\/a><\/noindex>, <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 <noindex><a rel=\"nofollow\" 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><\/noindex> <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 <noindex><a rel=\"nofollow\" 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><\/noindex>.<\/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 <noindex><a rel=\"nofollow\" href=\"https:\/\/github.com\/torvalds\/linux\/blob\/v5.8-rc7\/include\/uapi\/linux\/bpf.h#L161\" rel=\"nofollow\">\u0442\u0438\u043f<\/a><\/noindex> \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\nexit<\/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\n#include &lt;string.h&gt;\n#include &lt;unistd.h&gt;\n#include &lt;sys\/syscall.h&gt;\n#include &lt;linux\/bpf.h&gt;\n\nstatic inline __u64 ptr_to_u64(const void *ptr)\n{\n        return (__u64) (unsigned long) ptr;\n}\n\nint main(void)\n{\n    struct bpf_insn insns[] = {\n        {\n            .code = BPF_ALU64 | BPF_MOV | BPF_K,\n            .dst_reg = BPF_REG_0,\n            .imm = XDP_PASS\n        },\n        {\n            .code = BPF_JMP | BPF_EXIT\n        },\n    };\n\n    union bpf_attr attr = {\n        .prog_type = BPF_PROG_TYPE_XDP,\n        .insns     = ptr_to_u64(insns),\n        .insn_cnt  = sizeof(insns)\/sizeof(insns[0]),\n        .license   = ptr_to_u64(&quot;GPL&quot;),\n    };\n\n    strncpy(attr.prog_name, &quot;woo&quot;, sizeof(attr.prog_name));\n    syscall(__NR_bpf, BPF_PROG_LOAD, &amp;attr, sizeof(attr));\n\n    for ( ;; )\n        pause();\n}<\/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 <noindex><a rel=\"nofollow\" href=\"https:\/\/github.com\/torvalds\/linux\/blob\/v5.8-rc7\/include\/uapi\/linux\/bpf.h#L65-L71\" rel=\"nofollow\"><code>bpf_insn<\/code><\/a><\/noindex>. \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[] = {\n    BPF_MOV64_IMM(BPF_REG_0, XDP_PASS),\n    BPF_EXIT_INSN()\n};<\/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\n\n$ sudo strace .\/simple-prog\nexecve(&quot;.\/simple-prog&quot;, [&quot;.\/simple-prog&quot;], 0x7ffc7b553480 \/* 13 vars *\/) = 0\n...\nbpf(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\nERSION(0, 0, 0), prog_flags=0, prog_name=&quot;woo&quot;, prog_ifindex=0, expected_attach_type=BPF_CGROUP_INET_INGRESS}, 72) = 3\npause(<\/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\n390: xdp  name woo  tag 3b185187f1855c4c  gpl\n        loaded_at 2020-08-31T24:66:44+0000  uid 0\n        xlated 16B  jited 40B  memlock 4096B\n        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\n   0: (b7) r0 = 2\n   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\nbpf_prog_3b185187f1855c4c_woo:\n   0:   nopl   0x0(%rax,%rax,1)\n   5:   push   %rbp\n   6:   mov    %rsp,%rbp\n   9:   sub    $0x0,%rsp\n  10:   push   %rbx\n  11:   push   %r13\n  13:   push   %r14\n  15:   push   %r15\n  17:   pushq  $0x0\n  19:   mov    $0x2,%eax\n  1e:   pop    %rbx\n  1f:   pop    %r15\n  21:   pop    %r14\n  23:   pop    %r13\n  25:   pop    %rbx\n  26:   leaveq\n  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 <noindex><a rel=\"nofollow\" 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><\/noindex>, \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\n#define _GNU_SOURCE\n#include &lt;string.h&gt;\n#include &lt;unistd.h&gt;\n#include &lt;sys\/syscall.h&gt;\n#include &lt;linux\/bpf.h&gt;\n\nint main(void)\n{\n    union bpf_attr attr = {\n        .map_type = BPF_MAP_TYPE_HASH,\n        .key_size = sizeof(int),\n        .value_size = sizeof(int),\n        .max_entries = 4,\n    };\n    strncpy(attr.map_name, &quot;woo&quot;, sizeof(attr.map_name));\n    syscall(__NR_bpf, BPF_MAP_CREATE, &amp;attr, sizeof(attr));\n\n    for ( ;; )\n        pause();\n}<\/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\n$ sudo strace .\/simple-map\nexecve(&quot;.\/simple-map&quot;, [&quot;.\/simple-map&quot;], 0x7ffd40a27070 \/* 14 vars *\/) = 0\n...\nbpf(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\npause(<\/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\n...\n114: hash  name woo  flags 0x0\n        key 4B  value 4B  max_entries 4  memlock 4096B\n...<\/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\nFound 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\nkey: 01 00 00 00  value: 01 00 00 00\nFound 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\nbpf(BPF_MAP_GET_FD_BY_ID, {map_id=114, next_id=0, open_flags=0}, 120) = 3\nbpf(BPF_MAP_GET_NEXT_KEY, {map_fd=3, key=NULL, next_key=0x55856ab65280}, 120) = 0\nbpf(BPF_MAP_LOOKUP_ELEM, {map_fd=3, key=0x55856ab65280, value=0x55856ab652a0}, 120) = 0\nkey: 01 00 00 00  value: 01 00 00 00\nbpf(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\nbpf(BPF_MAP_GET_FD_BY_ID, {map_id=114, next_id=0, open_flags=0}, 120) = 3\nbpf(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 <noindex><a rel=\"nofollow\" 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><\/noindex>:<\/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\n$ sudo bpftool map update id 114 key 3 0 0 0 value 1 0 0 0\n$ 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\nkey: 01 00 00 00  value: 01 00 00 00\nkey: 02 00 00 00  value: 01 00 00 00\nkey: 04 00 00 00  value: 01 00 00 00\nkey: 03 00 00 00  value: 01 00 00 00\nFound 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\nError: 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\nbpf(BPF_MAP_GET_FD_BY_ID, {map_id=114, next_id=0, open_flags=0}, 120) = 3\nbpf(BPF_OBJ_GET_INFO_BY_FD, {info={bpf_fd=3, info_len=80, info=0x7ffe6c626da0}}, 120) = 0\nbpf(BPF_MAP_UPDATE_ELEM, {map_fd=3, key=0x56049ded5260, value=0x56049ded5280, flags=BPF_ANY}, 120) = -1 E2BIG (Argument list too long)\nError: update failed: Argument list too long\n+++ 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 <noindex><a rel=\"nofollow\" href=\"#nolibbpf\">\u043f\u0440\u0438\u043c\u0435\u0440<\/a><\/noindex> \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 <noindex><a rel=\"nofollow\" href=\"#tools\">\u0421\u0440\u0435\u0434\u0441\u0442\u0432\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438<\/a><\/noindex>. \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\n-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 <noindex><a rel=\"nofollow\" href=\"https:\/\/github.com\/libbpf\/libbpf\" rel=\"nofollow\">https:\/\/github.com\/libbpf\/libbpf<\/a><\/noindex> \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\n$ cd \/tmp\/libbpf-example\/\n$ git init-db\nInitialized empty Git repository in \/tmp\/libbpf-example\/.git\/\n$ git submodule add https:\/\/github.com\/libbpf\/libbpf.git\nCloning into '\/tmp\/libbpf-example\/libbpf'...\nremote: Enumerating objects: 200, done.\nremote: Counting objects: 100% (200\/200), done.\nremote: Compressing objects: 100% (103\/103), done.\nremote: Total 3354 (delta 101), reused 118 (delta 79), pack-reused 3154\nReceiving objects: 100% (3354\/3354), 2.05 MiB | 10.22 MiB\/s, done.\nResolving 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\n$ mkdir build\n$ OBJDIR=build DESTDIR=root make -s install\n$ find root\nroot\nroot\/usr\nroot\/usr\/include\nroot\/usr\/include\/bpf\nroot\/usr\/include\/bpf\/bpf_tracing.h\nroot\/usr\/include\/bpf\/xsk.h\nroot\/usr\/include\/bpf\/libbpf_common.h\nroot\/usr\/include\/bpf\/bpf_endian.h\nroot\/usr\/include\/bpf\/bpf_helpers.h\nroot\/usr\/include\/bpf\/btf.h\nroot\/usr\/include\/bpf\/bpf_helper_defs.h\nroot\/usr\/include\/bpf\/bpf.h\nroot\/usr\/include\/bpf\/libbpf_util.h\nroot\/usr\/include\/bpf\/libbpf.h\nroot\/usr\/include\/bpf\/bpf_core_read.h\nroot\/usr\/lib64\nroot\/usr\/lib64\/libbpf.so.0.1.0\nroot\/usr\/lib64\/libbpf.so.0\nroot\/usr\/lib64\/libbpf.a\nroot\/usr\/lib64\/libbpf.so\nroot\/usr\/lib64\/pkgconfig\nroot\/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\nstruct iphdr {\n    __u8 ihl: 4;\n    __u8 version: 4;\n    __u8 tos;\n    __be16 tot_len;\n    __be16 id;\n    __be16 frag_off;\n    __u8 ttl;\n    __u8 protocol;\n    __sum16 check;\n    __be32 saddr;\n    __be32 daddr;\n};<\/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\n#include &quot;vmlinux.h&quot;\n#include &lt;bpf\/bpf_helpers.h&gt;\n\nSEC(&quot;xdp\/simple&quot;)\nint simple(void *ctx)\n{\n        return XDP_PASS;\n}\n\nchar 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 <noindex><a rel=\"nofollow\" href=\"#tools\">\u0421\u0440\u0435\u0434\u0441\u0442\u0432\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438<\/a><\/noindex>):<\/p>\n<p><\/p>\n<pre><code class=\"plaintext\">$ clang --version\nclang version 11.0.0 (https:\/\/github.com\/llvm\/llvm-project.git afc287e0abec710398465ee1f86237513f2b5091)\n...\n\n$ 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\n\nxdp-simple.bpf.o:       file format elf64-bpf\n\nDisassembly of section xdp\/simple:\n\n0000000000000000 &lt;simple&gt;:\n       0:       r0 = 2\n       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;\n#include &lt;unistd.h&gt;\n#include &quot;xdp-simple.skel.h&quot;\n\nint main(int argc, char **argv)\n{\n    struct xdp_simple_bpf *obj;\n\n    obj = xdp_simple_bpf__open_and_load();\n    if (!obj)\n        err(1, &quot;failed to open and\/or load BPF objectn&quot;);\n\n    pause();\n\n    xdp_simple_bpf__destroy(obj);\n}<\/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 {\n    struct bpf_object_skeleton *skeleton;\n    struct bpf_object *obj;\n    struct {\n        struct bpf_program *simple;\n    } progs;\n    struct {\n        struct bpf_link *simple;\n    } links;\n};<\/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\n\n$ sudo strace -e bpf .\/xdp-simple\n...\nbpf(BPF_BTF_LOAD, 0x7ffdb8fd9670, 120)  = 3\nbpf(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\n463: xdp  name simple  tag 3b185187f1855c4c  gpl\n        loaded_at 2020-08-01T01:59:49+0000  uid 0\n        xlated 16B  jited 40B  memlock 4096B\n        btf_id 185\n        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\nint simple(void *ctx):\n; return XDP_PASS;\n   0: (b7) r0 = 2\n   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>, <noindex><a rel=\"nofollow\" 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><\/noindex> \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)\n{\n    return smp_processor_id();\n}<\/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 = {\n    .func     = bpf_get_smp_processor_id,\n    .gpl_only = false,\n    .ret_type = RET_INTEGER,\n};<\/code><\/pre>\n<p><\/p>\n<p>                        <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<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 <noindex><a rel=\"nofollow\" 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><\/noindex>:<\/p>\n<p><\/p>\n<pre><code class=\"plaintext\">static const struct bpf_func_proto *\nxdp_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)\n{\n    switch (func_id) {\n    ...\n    case BPF_FUNC_get_smp_processor_id:\n        return &amp;bpf_get_smp_processor_id_proto;\n    ...\n    }\n}<\/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 <noindex><a rel=\"nofollow\" 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><\/noindex> \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[] = {\n#define BPF_PROG_TYPE(_id, _name, prog_ctx_type, kern_ctx_type) \n    [_id] = &amp; _name ## _verifier_ops,\n#include &lt;linux\/bpf_types.h&gt;\n#undef BPF_PROG_TYPE\n};<\/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> <noindex><a rel=\"nofollow\" 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><\/noindex> \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 = {\n    .get_func_proto     = xdp_func_proto,\n    .is_valid_access    = xdp_is_valid_access,\n    .convert_ctx_access = xdp_convert_ctx_access,\n    .gen_prologue       = bpf_noop_prologue,\n};<\/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. <noindex><a rel=\"nofollow\" href=\"https:\/\/github.com\/torvalds\/linux\/blob\/v5.8-rc7\/kernel\/bpf\/verifier.c#L4611-L4617\" rel=\"nofollow\"><code>verifier.c<\/code><\/a><\/noindex>.<\/p>\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;\n#include &lt;bpf\/bpf_helpers.h&gt;\n\nSEC(&quot;xdp\/simple&quot;)\nint simple(void *ctx)\n{\n    if (bpf_get_smp_processor_id() != 0)\n        return XDP_DROP;\n    return XDP_PASS;\n}\n\nchar 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> <noindex><a rel=\"nofollow\" 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><\/noindex> \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\n$ llvm-objdump -D --section=xdp\/simple xdp-simple.bpf.o\n\nxdp-simple.bpf.o:       file format elf64-bpf\n\nDisassembly of section xdp\/simple:\n\n0000000000000000 &lt;simple&gt;:\n       0:       85 00 00 00 08 00 00 00 call 8\n       1:       bf 01 00 00 00 00 00 00 r1 = r0\n       2:       67 01 00 00 20 00 00 00 r1 &lt;&lt;= 32\n       3:       77 01 00 00 20 00 00 00 r1 &gt;&gt;= 32\n       4:       b7 00 00 00 02 00 00 00 r0 = 2\n       5:       15 01 01 00 00 00 00 00 if r1 == 0 goto +1 &lt;LBB0_2&gt;\n       6:       b7 00 00 00 01 00 00 00 r0 = 1\n\n0000000000000038 &lt;LBB0_2&gt;:\n       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\n$ clang -O2 -g -I .\/libbpf\/src\/root\/usr\/include\/ -o xdp-simple xdp-simple.c .\/libbpf\/src\/root\/usr\/lib64\/libbpf.a -lelf -lz\n$ sudo .\/xdp-simple &amp;\n[2] 10914\n\n$ sudo bpftool p | grep simple\n523: xdp  name simple  tag 44c38a10c657e1b0  gpl\n        pids xdp-simple(10915)\n\n$ sudo bpftool p d x id 523\nint simple(void *ctx):\n; if (bpf_get_smp_processor_id() != 0)\n   0: (85) call bpf_get_smp_processor_id#114128\n   1: (bf) r1 = r0\n   2: (67) r1 &lt;&lt;= 32\n   3: (77) r1 &gt;&gt;= 32\n   4: (b7) r0 = 2\n; }\n   5: (15) if r1 == 0x0 goto pc+1\n   6: (b7) r0 = 1\n   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;)\nint simple(void *ctx)\n{\n    bpf_printk(&quot;running on CPU%un&quot;, bpf_get_smp_processor_id());\n    return XDP_PASS;\n}<\/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\n\n0000000000000000 &lt;simple&gt;:\n       0:       r1 = 10\n       1:       *(u16 *)(r10 - 8) = r1\n       2:       r1 = 8441246879787806319 ll\n       4:       *(u64 *)(r10 - 16) = r1\n       5:       r1 = 2334956330918245746 ll\n       7:       *(u64 *)(r10 - 24) = r1\n       8:       call 8\n       9:       r1 = r10\n      10:       r1 += -24\n      11:       r2 = 18\n      12:       r3 = r0\n      13:       call 6\n      14:       r0 = 2\n      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%un<\/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<noindex><a rel=\"nofollow\" 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><\/noindex> \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\n#include &lt;linux\/if_link.h&gt;\n#include &lt;err.h&gt;\n#include &lt;unistd.h&gt;\n#include &quot;xdp-simple.skel.h&quot;\n\nint main(int argc, char **argv)\n{\n    __u32 flags = XDP_FLAGS_SKB_MODE;\n    struct xdp_simple_bpf *obj;\n\n    obj = xdp_simple_bpf__open_and_load();\n    if (!obj)\n        err(1, &quot;failed to open and\/or load BPF objectn&quot;);\n\n    bpf_set_link_xdp_fd(1, -1, flags);\n    bpf_set_link_xdp_fd(1, bpf_program__fd(obj-&gt;progs.simple), flags);\n\ncleanup:\n    xdp_simple_bpf__destroy(obj);\n}<\/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\n$ sudo bpftool p | grep simple\n669: xdp  name simple  tag 4fca62e77ccb43d6  gpl\n$ ip l show dev lo\n1: lo: &lt;LOOPBACK,UP,LOWER_UP&gt; mtu 65536 xdpgeneric qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000\n    link\/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00\n    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\nping-13937 [000] d.s1 442015.377014: bpf_trace_printk: running on CPU0\nping-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;\n#include &lt;bpf\/bpf_helpers.h&gt;\n\nstruct {\n    __uint(type, BPF_MAP_TYPE_ARRAY);\n    __uint(max_entries, 8);\n    __type(key, u32);\n    __type(value, u64);\n} woo SEC(&quot;.maps&quot;);\n\nSEC(&quot;xdp\/simple&quot;)\nint simple(void *ctx)\n{\n    u32 key = bpf_get_smp_processor_id();\n    u32 *val;\n\n    val = bpf_map_lookup_elem(&amp;woo, &amp;key);\n    if (!val)\n        return XDP_ABORTED;\n\n    *val += 1;\n\n    return XDP_PASS;\n}\n\nchar 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\n$ bpftool gen skeleton xdp-simple.bpf.o &gt; xdp-simple.skel.h\n$ clang -O2 -g -I .\/libbpf\/src\/root\/usr\/include\/ -o xdp-simple xdp-simple.c .\/libbpf\/src\/root\/usr\/lib64\/libbpf.a -lelf -lz\n$ 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\n1: lo: &lt;LOOPBACK,UP,LOWER_UP&gt; mtu 65536 xdpgeneric qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000\n    link\/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00\n    prog\/xdp id 108\n\n$ 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\n[\n    { &quot;key&quot;: 0, &quot;value&quot;: 0 },\n    { &quot;key&quot;: 1, &quot;value&quot;: 400 },\n    { &quot;key&quot;: 2, &quot;value&quot;: 0 },\n    { &quot;key&quot;: 3, &quot;value&quot;: 0 },\n    { &quot;key&quot;: 4, &quot;value&quot;: 0 },\n    { &quot;key&quot;: 5, &quot;value&quot;: 0 },\n    { &quot;key&quot;: 6, &quot;value&quot;: 0 },\n    { &quot;key&quot;: 7, &quot;value&quot;: 46400 }\n]<\/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 <noindex><a rel=\"nofollow\" 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><\/noindex>.<\/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\n\nxdp-simple.bpf.o:       file format elf64-bpf\n\nDisassembly of section xdp\/simple:\n\n0000000000000000 &lt;simple&gt;:\n       0:       85 00 00 00 08 00 00 00 call 8\n       1:       63 0a fc ff 00 00 00 00 *(u32 *)(r10 - 4) = r0\n       2:       bf a2 00 00 00 00 00 00 r2 = r10\n       3:       07 02 00 00 fc ff ff ff r2 += -4\n       4:       18 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 r1 = 0 ll\n       6:       85 00 00 00 01 00 00 00 call 1\n...<\/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\n\nRelocation section '.relxdp\/simple' at offset 0xe18 contains 1 entries:\n    Offset             Info             Type               Symbol's Value  Symbol's Name\n0000000000000020  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\nint simple(void *ctx):\n   0: (85) call bpf_get_smp_processor_id#114128\n   1: (63) *(u32 *)(r10 -4) = r0\n   2: (bf) r2 = r10\n   3: (07) r2 += -4\n   4: (18) r1 = map[id:64]\n...<\/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\n...\nbpf(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\nbpf(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 <noindex><a rel=\"nofollow\" 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><\/noindex>:<\/p>\n<p><\/p>\n<pre><code class=\"plaintext\">case RELO_LD64:\n    insn[0].src_reg = BPF_PSEUDO_MAP_FD;\n    insn[0].imm = obj-&gt;maps[relo-&gt;map_idx].fd;\n    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) {\n    ...\n\n    f = fdget(insn[0].imm);\n    map = __bpf_map_get(f);\n    if (insn-&gt;src_reg == BPF_PSEUDO_MAP_FD) {\n        addr = (unsigned long)map;\n    }\n    insn[0].imm = (u32)addr;\n    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 <noindex><a rel=\"nofollow\" 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><\/noindex>). \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 <noindex><a rel=\"nofollow\" href=\"https:\/\/github.com\/iovisor\/ply\" rel=\"nofollow\"><code>ply<\/code><\/a><\/noindex>, \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 <noindex><a rel=\"nofollow\" href=\"https:\/\/gist.github.com\/aspsk\/fc145db380aee3c2cd503c36c63b555e\" rel=\"nofollow\">gist<\/a><\/noindex>.<\/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)\n{\n    int map_fd, prog_fd;\n\n    map_fd = map_create();\n    if (map_fd &lt; 0)\n        err(1, &quot;bpf: BPF_MAP_CREATE&quot;);\n\n    prog_fd = prog_load(map_fd);\n    if (prog_fd &lt; 0)\n        err(1, &quot;bpf: BPF_PROG_LOAD&quot;);\n\n    xdp_attach(1, prog_fd);\n}<\/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()\n{\n    union bpf_attr attr;\n\n    memset(&amp;attr, 0, sizeof(attr));\n    attr.map_type = BPF_MAP_TYPE_ARRAY,\n    attr.key_size = sizeof(__u32),\n    attr.value_size = sizeof(__u64),\n    attr.max_entries = 8,\n    strncpy(attr.map_name, &quot;woo&quot;, sizeof(attr.map_name));\n    return syscall(__NR_bpf, BPF_MAP_CREATE, &amp;attr, sizeof(attr));\n}<\/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)\n{\n    union bpf_attr attr;\n    struct bpf_insn insns[] = {\n        ...\n    };\n\n    memset(&amp;attr, 0, sizeof(attr));\n    attr.prog_type = BPF_PROG_TYPE_XDP;\n    attr.insns     = ptr_to_u64(insns);\n    attr.insn_cnt  = sizeof(insns)\/sizeof(insns[0]);\n    attr.license   = ptr_to_u64(&quot;GPL&quot;);\n    strncpy(attr.prog_name, &quot;woo&quot;, sizeof(attr.prog_name));\n    return syscall(__NR_bpf, BPF_PROG_LOAD, &amp;attr, sizeof(attr));\n}<\/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\n\n0000000000000000 &lt;simple&gt;:\n       0:       85 00 00 00 08 00 00 00 call 8\n       1:       63 0a fc ff 00 00 00 00 *(u32 *)(r10 - 4) = r0\n       2:       bf a2 00 00 00 00 00 00 r2 = r10\n       3:       07 02 00 00 fc ff ff ff r2 += -4\n       4:       18 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 r1 = 0 ll\n       6:       85 00 00 00 01 00 00 00 call 1\n       7:       b7 01 00 00 00 00 00 00 r1 = 0\n       8:       15 00 04 00 00 00 00 00 if r0 == 0 goto +4 &lt;LBB0_2&gt;\n       9:       61 01 00 00 00 00 00 00 r1 = *(u32 *)(r0 + 0)\n      10:       07 01 00 00 01 00 00 00 r1 += 1\n      11:       63 10 00 00 00 00 00 00 *(u32 *)(r0 + 0) = r1\n      12:       b7 01 00 00 02 00 00 00 r1 = 2\n\n0000000000000068 &lt;LBB0_2&gt;:\n      13:       bf 10 00 00 00 00 00 00 r0 = r1\n      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 <noindex><a rel=\"nofollow\" 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><\/noindex> \u0438 <noindex><a rel=\"nofollow\" 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><\/noindex> \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[] = {\n    \/* 85 00 00 00 08 00 00 00 call 8 *\/\n    {\n        .code = BPF_JMP | BPF_CALL,\n        .imm = 8,\n    },\n\n    \/* 63 0a fc ff 00 00 00 00 *(u32 *)(r10 - 4) = r0 *\/\n    {\n        .code = BPF_MEM | BPF_STX,\n        .off = -4,\n        .src_reg = BPF_REG_0,\n        .dst_reg = BPF_REG_10,\n    },\n\n    \/* bf a2 00 00 00 00 00 00 r2 = r10 *\/\n    {\n        .code = BPF_ALU64 | BPF_MOV | BPF_X,\n        .src_reg = BPF_REG_10,\n        .dst_reg = BPF_REG_2,\n    },\n\n    \/* 07 02 00 00 fc ff ff ff r2 += -4 *\/\n    {\n        .code = BPF_ALU64 | BPF_ADD | BPF_K,\n        .dst_reg = BPF_REG_2,\n        .imm = -4,\n    },\n\n    \/* 18 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 r1 = 0 ll *\/\n    {\n        .code = BPF_LD | BPF_DW | BPF_IMM,\n        .src_reg = BPF_PSEUDO_MAP_FD,\n        .dst_reg = BPF_REG_1,\n        .imm = map_fd,\n    },\n    { }, \/* placeholder *\/\n\n    \/* 85 00 00 00 01 00 00 00 call 1 *\/\n    {\n        .code = BPF_JMP | BPF_CALL,\n        .imm = 1,\n    },\n\n    \/* b7 01 00 00 00 00 00 00 r1 = 0 *\/\n    {\n        .code = BPF_ALU64 | BPF_MOV | BPF_K,\n        .dst_reg = BPF_REG_1,\n        .imm = 0,\n    },\n\n    \/* 15 00 04 00 00 00 00 00 if r0 == 0 goto +4 &lt;LBB0_2&gt; *\/\n    {\n        .code = BPF_JMP | BPF_JEQ | BPF_K,\n        .off = 4,\n        .src_reg = BPF_REG_0,\n        .imm = 0,\n    },\n\n    \/* 61 01 00 00 00 00 00 00 r1 = *(u32 *)(r0 + 0) *\/\n    {\n        .code = BPF_MEM | BPF_LDX,\n        .off = 0,\n        .src_reg = BPF_REG_0,\n        .dst_reg = BPF_REG_1,\n    },\n\n    \/* 07 01 00 00 01 00 00 00 r1 += 1 *\/\n    {\n        .code = BPF_ALU64 | BPF_ADD | BPF_K,\n        .dst_reg = BPF_REG_1,\n        .imm = 1,\n    },\n\n    \/* 63 10 00 00 00 00 00 00 *(u32 *)(r0 + 0) = r1 *\/\n    {\n        .code = BPF_MEM | BPF_STX,\n        .src_reg = BPF_REG_1,\n        .dst_reg = BPF_REG_0,\n    },\n\n    \/* b7 01 00 00 02 00 00 00 r1 = 2 *\/\n    {\n        .code = BPF_ALU64 | BPF_MOV | BPF_K,\n        .dst_reg = BPF_REG_1,\n        .imm = 2,\n    },\n\n    \/* &lt;LBB0_2&gt;: bf 10 00 00 00 00 00 00 r0 = r1 *\/\n    {\n        .code = BPF_ALU64 | BPF_MOV | BPF_X,\n        .src_reg = BPF_REG_1,\n        .dst_reg = BPF_REG_0,\n    },\n\n    \/* 95 00 00 00 00 00 00 00 exit *\/\n    {\n        .code = BPF_JMP | BPF_EXIT\n    },\n};<\/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: <noindex><a rel=\"nofollow\" href=\"https:\/\/man7.org\/linux\/man-pages\/man7\/rtnetlink.7.html\" rel=\"nofollow\">netlink sockets<\/a><\/noindex>, \u0441\u043c. \u0442\u0430\u043a\u0436\u0435 <noindex><a rel=\"nofollow\" href=\"https:\/\/tools.ietf.org\/html\/rfc3549\" rel=\"nofollow\">RFC3549<\/a><\/noindex>. \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 <noindex><a rel=\"nofollow\" href=\"https:\/\/github.com\/libbpf\/libbpf\/blob\/master\/src\/netlink.c\" rel=\"nofollow\"><code>netlink.c<\/code><\/a><\/noindex>, \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<p>                        <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<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)\n{\n    struct sockaddr_nl sa;\n    socklen_t addrlen;\n    int one = 1, ret;\n    int sock;\n\n    memset(&amp;sa, 0, sizeof(sa));\n    sa.nl_family = AF_NETLINK;\n\n    sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);\n    if (sock &lt; 0)\n        err(1, &quot;socket&quot;);\n\n    if (setsockopt(sock, SOL_NETLINK, NETLINK_EXT_ACK, &amp;one, sizeof(one)) &lt; 0)\n        warnx(&quot;netlink error reporting not supported&quot;);\n\n    if (bind(sock, (struct sockaddr *)&amp;sa, sizeof(sa)) &lt; 0)\n        err(1, &quot;bind&quot;);\n\n    addrlen = sizeof(sa);\n    if (getsockname(sock, (struct sockaddr *)&amp;sa, &amp;addrlen) &lt; 0)\n        err(1, &quot;getsockname&quot;);\n\n    *nl_pid = sa.nl_pid;\n    return sock;\n}<\/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)\n{\n    bool multipart = true;\n    struct nlmsgerr *errm;\n    struct nlmsghdr *nh;\n    char buf[4096];\n    int len, ret;\n\n    while (multipart) {\n        multipart = false;\n        len = recv(sock, buf, sizeof(buf), 0);\n        if (len &lt; 0)\n            err(1, &quot;recv&quot;);\n\n        if (len == 0)\n            break;\n\n        for (nh = (struct nlmsghdr *)buf; NLMSG_OK(nh, len);\n                nh = NLMSG_NEXT(nh, len)) {\n            if (nh-&gt;nlmsg_pid != nl_pid)\n                errx(1, &quot;wrong pid&quot;);\n            if (nh-&gt;nlmsg_seq != seq)\n                errx(1, &quot;INVSEQ&quot;);\n            if (nh-&gt;nlmsg_flags &amp; NLM_F_MULTI)\n                multipart = true;\n            switch (nh-&gt;nlmsg_type) {\n                case NLMSG_ERROR:\n                    errm = (struct nlmsgerr *)NLMSG_DATA(nh);\n                    if (!errm-&gt;error)\n                        continue;\n                    ret = errm-&gt;error;\n                    \/\/ libbpf_nla_dump_errormsg(nh); too many code to copy...\n                    goto done;\n                case NLMSG_DONE:\n                    return 0;\n                default:\n                    break;\n            }\n        }\n    }\n    ret = 0;\ndone:\n    return ret;\n}<\/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)\n{\n    int sock, seq = 0, ret;\n    struct nlattr *nla, *nla_xdp;\n    struct {\n        struct nlmsghdr  nh;\n        struct ifinfomsg ifinfo;\n        char             attrbuf[64];\n    } req;\n    __u32 nl_pid = 0;\n\n    sock = netlink_open(&amp;nl_pid);\n    if (sock &lt; 0)\n        return sock;\n\n    memset(&amp;req, 0, sizeof(req));\n    req.nh.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));\n    req.nh.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;\n    req.nh.nlmsg_type = RTM_SETLINK;\n    req.nh.nlmsg_pid = 0;\n    req.nh.nlmsg_seq = ++seq;\n    req.ifinfo.ifi_family = AF_UNSPEC;\n    req.ifinfo.ifi_index = ifindex;\n\n    \/* started nested attribute for XDP *\/\n    nla = (struct nlattr *)(((char *)&amp;req)\n            + NLMSG_ALIGN(req.nh.nlmsg_len));\n    nla-&gt;nla_type = NLA_F_NESTED | IFLA_XDP;\n    nla-&gt;nla_len = NLA_HDRLEN;\n\n    \/* add XDP fd *\/\n    nla_xdp = (struct nlattr *)((char *)nla + nla-&gt;nla_len);\n    nla_xdp-&gt;nla_type = IFLA_XDP_FD;\n    nla_xdp-&gt;nla_len = NLA_HDRLEN + sizeof(int);\n    memcpy((char *)nla_xdp + NLA_HDRLEN, &amp;prog_fd, sizeof(prog_fd));\n    nla-&gt;nla_len += nla_xdp-&gt;nla_len;\n\n    \/* if user passed in any flags, add those too *\/\n    __u32 flags = XDP_FLAGS_SKB_MODE;\n    nla_xdp = (struct nlattr *)((char *)nla + nla-&gt;nla_len);\n    nla_xdp-&gt;nla_type = IFLA_XDP_FLAGS;\n    nla_xdp-&gt;nla_len = NLA_HDRLEN + sizeof(flags);\n    memcpy((char *)nla_xdp + NLA_HDRLEN, &amp;flags, sizeof(flags));\n    nla-&gt;nla_len += nla_xdp-&gt;nla_len;\n\n    req.nh.nlmsg_len += NLA_ALIGN(nla-&gt;nla_len);\n\n    if (send(sock, &amp;req, req.nh.nlmsg_len, 0) &lt; 0)\n        err(1, &quot;send&quot;);\n    ret = bpf_netlink_recv(sock, nl_pid, seq);\n\ncleanup:\n    close(sock);\n    return ret;\n}<\/code><\/pre>\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\n$ sudo strace -e bpf .\/nolibbpf\nbpf(BPF_MAP_CREATE, {map_type=BPF_MAP_TYPE_ARRAY, map_name=&quot;woo&quot;, ...}, 72) = 3\nbpf(BPF_PROG_LOAD, {prog_type=BPF_PROG_TYPE_XDP, insn_cnt=15, prog_name=&quot;woo&quot;, ...}, 72) = 4\n+++ 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\n1: lo: &lt;LOOPBACK,UP,LOWER_UP&gt; mtu 65536 xdpgeneric qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000\n    link\/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00\n    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\n$ sudo bpftool m dump name woo\nkey: 00 00 00 00  value: 90 01 00 00 00 00 00 00\nkey: 01 00 00 00  value: 00 00 00 00 00 00 00 00\nkey: 02 00 00 00  value: 00 00 00 00 00 00 00 00\nkey: 03 00 00 00  value: 00 00 00 00 00 00 00 00\nkey: 04 00 00 00  value: 00 00 00 00 00 00 00 00\nkey: 05 00 00 00  value: 00 00 00 00 00 00 00 00\nkey: 06 00 00 00  value: 40 b5 00 00 00 00 00 00\nkey: 07 00 00 00  value: 00 00 00 00 00 00 00 00\nFound 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\n$ git clone --depth 1 https:\/\/github.com\/llvm\/llvm-project.git\n$ mkdir -p llvm-project\/llvm\/build\/install\n$ cd llvm-project\/llvm\/build\n$ cmake .. -G &quot;Ninja&quot; -DLLVM_TARGETS_TO_BUILD=&quot;BPF;X86&quot; \n                      -DLLVM_ENABLE_PROJECTS=&quot;clang&quot; \n                      -DBUILD_SHARED_LIBS=OFF \n                      -DCMAKE_BUILD_TYPE=Release \n                      -DLLVM_BUILD_RUNTIME=OFF\n$ time ninja\n... \u043c\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0441\u043f\u0443\u0441\u0442\u044f\n$<\/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\nLLVM (http:\/\/llvm.org\/):\n  LLVM version 11.0.0git\n  Optimized build.\n  Default target: x86_64-unknown-linux-gnu\n  Host CPU: znver1\n\n  Registered Targets:\n    bpf    - BPF (host endian)\n    bpfeb  - BPF (big endian)\n    bpfel  - BPF (little endian)\n    x86    - 32-bit X86: Pentium-Pro and above\n    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 <noindex><a rel=\"nofollow\" href=\"https:\/\/www.kernel.org\/doc\/html\/latest\/bpf\/bpf_devel_QA.html#llvm\" rel=\"nofollow\">bpf_devel_QA<\/a><\/noindex>.)<\/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\n$ cd pahole\/\n$ sudo apt install cmake\n$ mkdir build\n$ cd build\/\n$ cmake -D__LIB=lib ..\n$ make\n$ sudo make install\n$ which pahole\n\/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 \u043f\u043e\u0447\u0443\u0432\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441\u0435\u0431\u044f \u0432\u0430\u0436\u043d\u044b\u043c \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 <noindex><a rel=\"nofollow\" href=\"https:\/\/github.com\/torvalds\/linux.git\" rel=\"nofollow\">\u0432\u0430\u043d\u0438\u043b\u044c\u043d\u043e\u0435<\/a><\/noindex> \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 <noindex><a rel=\"nofollow\" href=\"https:\/\/git.kernel.org\/pub\/scm\/linux\/kernel\/git\/netdev\/net.git\" rel=\"nofollow\"><code>net<\/code><\/a><\/noindex> \u0438\u043b\u0438 <noindex><a rel=\"nofollow\" href=\"https:\/\/git.kernel.org\/pub\/scm\/linux\/kernel\/git\/netdev\/net-next.git\" rel=\"nofollow\"><code>net-next<\/code><\/a><\/noindex>. \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 <noindex><a rel=\"nofollow\" href=\"https:\/\/git.kernel.org\/pub\/scm\/linux\/kernel\/git\/bpf\/bpf.git\/\" rel=\"nofollow\"><code>bpf<\/code><\/a><\/noindex> \u0438 <noindex><a rel=\"nofollow\" href=\"https:\/\/git.kernel.org\/pub\/scm\/linux\/kernel\/git\/bpf\/bpf-next.git\/\" rel=\"nofollow\"><code>bpf-next<\/code><\/a><\/noindex>, \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 <noindex><a rel=\"nofollow\" href=\"https:\/\/www.kernel.org\/doc\/html\/latest\/bpf\/bpf_devel_QA.html#llvm\" rel=\"nofollow\">bpf_devel_QA<\/a><\/noindex> \u0438 <noindex><a rel=\"nofollow\" href=\"https:\/\/www.kernel.org\/doc\/html\/latest\/networking\/netdev-FAQ.html\" rel=\"nofollow\">netdev-FAQ<\/a><\/noindex>. \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 <noindex><a rel=\"nofollow\" href=\"https:\/\/kernelnewbies.org\/KernelBuild\" rel=\"nofollow\">\u0433\u043e\u0442\u043e\u0432\u044b \u043d\u0430\u0443\u0447\u0438\u0442\u044c\u0441\u044f<\/a><\/noindex> \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\n$ 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\n$ 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\nCONFIG_BPF=y\nCONFIG_BPF_LSM=y\nCONFIG_BPF_SYSCALL=y\nCONFIG_ARCH_WANT_DEFAULT_BPF_JIT=y\nCONFIG_BPF_JIT_ALWAYS_ON=y\nCONFIG_BPF_JIT_DEFAULT_ON=y\nCONFIG_IPV6_SEG6_BPF=y\n# CONFIG_NETFILTER_XT_MATCH_BPF is not set\n# CONFIG_BPFILTER is not set\nCONFIG_NET_CLS_BPF=y\nCONFIG_NET_ACT_BPF=y\nCONFIG_BPF_JIT=y\nCONFIG_BPF_STREAM_PARSER=y\nCONFIG_LWTUNNEL_BPF=y\nCONFIG_HAVE_EBPF_JIT=y\nCONFIG_BPF_EVENTS=y\nCONFIG_BPF_KPROBE_OVERRIDE=y\nCONFIG_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)\n$ sudo make modules_install\n$ 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`\nsudo kexec -l -t bzImage \/boot\/vmlinuz-$v --initrd=\/boot\/initrd.img-$v --reuse-cmdline &amp;&amp;\nsudo 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 <noindex><a rel=\"nofollow\" href=\"https:\/\/github.com\/torvalds\/linux\/tree\/master\/tools\/bpf\/bpftool\/Documentation\" rel=\"nofollow\">\u0432 \u044f\u0434\u0440\u0435<\/a><\/noindex> \u0438\u043b\u0438, \u0443\u0436\u0435 \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0443\u044e, <noindex><a rel=\"nofollow\" href=\"https:\/\/www.mankier.com\/8\/bpftool\" rel=\"nofollow\">\u0432 \u0441\u0435\u0442\u0438<\/a><\/noindex>.<\/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, <noindex><a rel=\"nofollow\" href=\"https:\/\/bugs.debian.org\/cgi-bin\/bugreport.cgi?bug=896165\" rel=\"nofollow\">\u044d\u0442\u043e\u0442 \u0442\u0440\u0435\u0434<\/a><\/noindex>, \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\n# ... \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\n$ make -s\n\nAuto-detecting system features:\n...                        libbfd: [ on  ]\n...        disassembler-four-args: [ on  ]\n...                          zlib: [ on  ]\n...                        libcap: [ on  ]\n...               clang-bpf-co-re: [ on  ]\n\nAuto-detecting system features:\n...                        libelf: [ on  ]\n...                          zlib: [ on  ]\n...                           bpf: [ on  ]\n\n$<\/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\nScanning system configuration...\nbpf() syscall for unprivileged users is enabled\nJIT compiler is enabled\nJIT compiler hardening is disabled\nJIT compiler kallsyms exports are enabled for root\n...<\/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 \u043f\u043e\u0434\u043a\u043e\u0432\u0430\u0442\u044c \u0431\u043b\u043e\u0445\u0443 \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><noindex><a rel=\"nofollow\" 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><\/noindex><\/li>\n<\/ol>\n<p><\/p>\n<h2>\u0421\u044b\u043b\u043a\u0438<\/h2>\n<p><\/p>\n<ol>\n<li>\n<p><noindex><a rel=\"nofollow\" href=\"https:\/\/docs.cilium.io\/en\/latest\/bpf\" rel=\"nofollow\">BPF and XDP Reference Guide<\/a><\/noindex> \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>\n<\/li>\n<li>\n<p><noindex><a rel=\"nofollow\" 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><\/noindex> \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>\n<\/li>\n<li>\n<p><noindex><a rel=\"nofollow\" href=\"https:\/\/facebookmicrosites.github.io\/bpf\/\" rel=\"nofollow\">\u0411\u043b\u043e\u0433 \u043f\u0440\u043e BPF \u043e\u0442 facebook<\/a><\/noindex>. \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>\n<\/li>\n<li>\n<p><noindex><a rel=\"nofollow\" href=\"https:\/\/twitter.com\/qeole\/status\/1101450782841466880\" rel=\"nofollow\">\u0421\u0435\u043a\u0440\u0435\u0442\u044b bpftool<\/a><\/noindex>. \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>\n<\/li>\n<li>\n<p><noindex><a rel=\"nofollow\" href=\"https:\/\/qmonnet.github.io\/whirl-offload\/2016\/09\/01\/dive-into-bpf\/\" rel=\"nofollow\">Dive into BPF: a list of reading material<\/a><\/noindex>. \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>\n<\/li>\n<\/ol>\n<p>\u0418\u0441\u0442\u043e\u0447\u043d\u0438\u043a: <a content=\"nofollow\" rel=\"nofollow\" href=\"https:\/\/habr.com\/ru\/post\/514736\/\">habr.com<\/a> <\/p>\n","protected":false,"gt_translate_keys":[{"key":"rendered","format":"html"}]},"excerpt":{"rendered":"<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 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439, \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, [&hellip;]<\/p>\n","protected":false,"gt_translate_keys":[{"key":"rendered","format":"html"}]},"author":1,"featured_media":91403,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[688],"tags":[],"class_list":["post-91402","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-administrirovanie"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.10 - aioseo.com -->\n\t<meta name=\"description\" content=\"\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 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439, \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,\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Yuri Gagarin\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/prohoster.info\/it\/blog\/administrirovanie\/bpf-dlya-samyh-malenkih-chast-pervaya-extended-bpf\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.10\" \/>\n\t\t<meta property=\"og:locale\" content=\"it_IT\" \/>\n\t\t<meta property=\"og:site_name\" content=\"ProHoster | \u041a\u0443\u043f\u0438\u0442\u044c \u043d\u0430\u0434\u0435\u0436\u043d\u044b\u0439 \u0445\u043e\u0441\u0442\u0438\u043d\u0433 \u0434\u043b\u044f \u0441\u0430\u0439\u0442\u043e\u0432 \u0441 \u0437\u0430\u0449\u0438\u0442\u043e\u0439 \u043e\u0442 DDoS, VPS VDS \u0441\u0435\u0440\u0432\u0435\u0440\u044b\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"\ud83e\udd47BPF \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 | ProHoster\" \/>\n\t\t<meta property=\"og:description\" content=\"\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 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439, \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,\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/prohoster.info\/it\/blog\/administrirovanie\/bpf-dlya-samyh-malenkih-chast-pervaya-extended-bpf\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg\" \/>\n\t\t<meta property=\"og:image:width\" content=\"350\" \/>\n\t\t<meta property=\"og:image:height\" content=\"350\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2020-08-12T17:42:34+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2020-08-12T17:42:34+00:00\" \/>\n\t\t<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prohoster\" \/>\n\t\t<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/prohoster\" \/>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"\ud83e\udd47BPF per i pi\u00f9 piccoli, parte prima: extended BPF | ProHoster","description":"All'inizio c'era la tecnologia chiamata BPF. L'abbiamo esaminata nel precedente articolo di questa serie, di tono vetero-testamentario. Nel 2013, grazie agli sforzi di Alexei Starovoitov e Daniel Borkman, fu sviluppata e integrata nel kernel Linux una versione migliorata, ottimizzata per le moderne macchine a 64 bit. Questa nuova tecnologia port\u00f2 per un breve periodo il nome di Internal BPF,","canonical_url":"https:\/\/prohoster.info\/it\/blog\/administrirovanie\/bpf-dlya-samyh-malenkih-chast-pervaya-extended-bpf","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":null,"og:locale":"it_IT","og:site_name":"ProHoster | \u041a\u0443\u043f\u0438\u0442\u044c \u043d\u0430\u0434\u0435\u0436\u043d\u044b\u0439 \u0445\u043e\u0441\u0442\u0438\u043d\u0433 \u0434\u043b\u044f \u0441\u0430\u0439\u0442\u043e\u0432 \u0441 \u0437\u0430\u0449\u0438\u0442\u043e\u0439 \u043e\u0442 DDoS, VPS VDS \u0441\u0435\u0440\u0432\u0435\u0440\u044b","og:type":"article","og:title":"\ud83e\udd47BPF \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 | ProHoster","og:description":"\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 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0439, \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,","og:url":"https:\/\/prohoster.info\/it\/blog\/administrirovanie\/bpf-dlya-samyh-malenkih-chast-pervaya-extended-bpf","og:image":"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg","og:image:secure_url":"https:\/\/prohoster.info\/wp-content\/uploads\/2021\/11\/logo-350.jpg","og:image:width":350,"og:image:height":350,"article:published_time":"2020-08-12T17:42:34+00:00","article:modified_time":"2020-08-12T17:42:34+00:00","article:publisher":"https:\/\/www.facebook.com\/prohoster","article:author":"https:\/\/www.facebook.com\/prohoster"},"aioseo_meta_data":{"post_id":"91402","title":null,"description":null,"keywords":null,"keyphrases":null,"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"","isEnabled":true},"graphs":[]},"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"local_seo":null,"seo_analyzer_scan_date":null,"breadcrumb_settings":null,"limit_modified_date":false,"reviewed_by":null,"ai":null,"created":"2021-02-28 12:28:27","updated":"2022-10-01 09:47:06"},"gt_translate_keys":[{"key":"link","format":"url"}],"_links":{"self":[{"href":"https:\/\/prohoster.info\/it\/wp-json\/wp\/v2\/posts\/91402","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prohoster.info\/it\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prohoster.info\/it\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prohoster.info\/it\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/prohoster.info\/it\/wp-json\/wp\/v2\/comments?post=91402"}],"version-history":[{"count":0,"href":"https:\/\/prohoster.info\/it\/wp-json\/wp\/v2\/posts\/91402\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/prohoster.info\/it\/wp-json\/wp\/v2\/media\/91403"}],"wp:attachment":[{"href":"https:\/\/prohoster.info\/it\/wp-json\/wp\/v2\/media?parent=91402"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prohoster.info\/it\/wp-json\/wp\/v2\/categories?post=91402"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prohoster.info\/it\/wp-json\/wp\/v2\/tags?post=91402"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}