{"id":37014,"date":"2025-04-18T10:37:21","date_gmt":"2025-04-18T02:37:21","guid":{"rendered":"https:\/\/www.yunshan.net\/blog\/?p=37014"},"modified":"2025-04-18T10:37:21","modified_gmt":"2025-04-18T02:37:21","slug":"%e5%a6%82%e4%bd%95%e9%80%9a%e8%bf%87ebpf%e5%ae%9e%e7%8e%b0%e5%ae%9e%e6%97%b6%e6%b5%81%e9%87%8f%e8%bf%87%e6%bb%a4%e5%92%8c%e9%98%b2%e7%81%ab%e5%a2%99%e5%8a%9f%e8%83%bd%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.yunshan.net\/blog\/archives\/37014.html","title":{"rendered":"\u5982\u4f55\u901a\u8fc7eBPF\u5b9e\u73b0\u5b9e\u65f6\u6d41\u91cf\u8fc7\u6ee4\u548c\u9632\u706b\u5899\u529f\u80fd\uff1f"},"content":{"rendered":"<p style=\"text-align: center;\">\n<p><img decoding=\"async\" src=\"https:\/\/www.yunshan.net\/blog\/wp-content\/uploads\/2025\/04\/mROkf.jpg\" alt=\"\u5982\u4f55\u901a\u8fc7eBPF\u5b9e\u73b0\u5b9e\u65f6\u6d41\u91cf\u8fc7\u6ee4\u548c\u9632\u706b\u5899\u529f\u80fd\uff1f\" ><\/p>\n<\/p>\n<p>\u5728\u4e91\u8ba1\u7b97\u548c\u5fae\u670d\u52a1\u67b6\u6784\u4e3b\u5bfc\u7684\u6570\u5b57\u5316\u65f6\u4ee3\uff0c\u6bcf\u79d2\u767e\u4e07\u7ea7\u7684\u7f51\u7edc\u6570\u636e\u5305\u4ea4\u4e92\u65e9\u5df2\u6210\u4e3a\u5e38\u6001\u3002\u4f20\u7edf\u7684\u9632\u706b\u5899\u65b9\u6848\u5728\u5e94\u5bf9\u73b0\u4ee3\u6570\u636e\u4e2d\u5fc3\u4e1c\u897f\u5411\u6d41\u91cf\u65f6\uff0c\u5e38\u5e38\u9677\u5165\u6027\u80fd\u74f6\u9888\u2014\u2014\u5f53iptables\u89c4\u5219\u8d85\u8fc73000\u6761\u65f6\uff0c\u5904\u7406\u5ef6\u8fdf\u5c31\u4f1a\u5448\u6307\u6570\u7ea7\u589e\u957f\u3002\u8fd9\u79cd\u56f0\u5883\u50ac\u751f\u4e86<strong><a href=\"https:\/\/www.yunshan.net\/\"   target=\"_blank\" style=\"color:blue\">eBPF<\/a>\u6280\u672f<\/strong>\u7684\u9769\u547d\u6027\u7a81\u7834\uff1a\u67d0\u5934\u90e8\u4e91\u5382\u5546\u57282022\u5e74\u7684\u6280\u672f\u767d\u76ae\u4e66\u4e2d\u62ab\u9732\uff0c\u901a\u8fc7<a href=\"https:\/\/www.yunshan.net\/\"   target=\"_blank\" style=\"color:blue\">eBPF<\/a>\u5b9e\u73b0\u7684\u7f51\u7edc\u7b56\u7565\u6267\u884c\uff0c\u5c06\u6570\u636e\u5305\u5904\u7406\u5ef6\u8fdf\u4ece\u5fae\u79d2\u7ea7\u964d\u81f3\u7eb3\u79d2\u7ea7\uff0c\u540c\u65f6CPU\u5229\u7528\u7387\u964d\u4f4e40%\u3002\u8fd9\u79cd\u53d8\u9769\u6027\u6280\u672f\u6b63\u5728\u91cd\u65b0\u5b9a\u4e49\u5b9e\u65f6\u6d41\u91cf\u63a7\u5236\u7684\u8fb9\u754c\u3002<\/p>\n<h3 id=\"\u4e00-ebpf-\u5185\u6838\u53ef\u7f16\u7a0b\u6027\u7684\u8303\u5f0f\u9769\u547d\">\u4e00\u3001eBPF\uff1a\u5185\u6838\u53ef\u7f16\u7a0b\u6027\u7684\u8303\u5f0f\u9769\u547d<\/h3>\n<p><strong>eBPF\uff08Extended Berkeley Packet Filter\uff09<\/strong> \u4e0d\u662f\u7b80\u5355\u7684\u5de5\u5177\u5347\u7ea7\uff0c\u800c\u662f\u64cd\u4f5c\u7cfb\u7edf\u5185\u6838\u67b6\u6784\u7684\u8303\u5f0f\u8f6c\u53d8\u3002\u5b83\u901a\u8fc7\u6c99\u7bb1\u673a\u5236\uff0c\u5141\u8bb8\u7528\u6237\u6001\u7a0b\u5e8f\u5728\u4e0d\u4fee\u6539\u5185\u6838\u6e90\u7801\u3001\u4e0d\u52a0\u8f7d\u5185\u6838\u6a21\u5757\u7684\u524d\u63d0\u4e0b\uff0c\u5b89\u5168\u5730\u6ce8\u5165\u81ea\u5b9a\u4e49\u4ee3\u7801\u5230\u5185\u6838\u6267\u884c\u6d41\u4e2d\u3002\u8fd9\u79cd\u7279\u6027\u4f7f\u5176\u5929\u751f\u5177\u5907\u4e09\u5927\u4f18\u52bf\uff1a<\/p>\n<ul>\n<li><strong>\u96f6\u62f7\u8d1d\u6570\u636e\u5904\u7406<\/strong>\uff1aXDP\uff08eXpress Data Path\uff09\u67b6\u6784\u76f4\u63a5\u5728\u7f51\u5361\u9a71\u52a8\u5c42\u5904\u7406\u6570\u636e\u5305\n<\/li>\n<li><strong>\u52a8\u6001\u7b56\u7565\u52a0\u8f7d<\/strong>\uff1a\u652f\u6301\u7b56\u7565\u7684\u70ed\u66f4\u65b0\u800c\u65e0\u9700\u91cd\u542f\u670d\u52a1\n<\/li>\n<li><strong>\u7ec6\u7c92\u5ea6\u89c2\u6d4b\u80fd\u529b<\/strong>\uff1a\u4ece\u7cfb\u7edf\u8c03\u7528\u5230\u7f51\u7edc\u534f\u8bae\u6808\u7684\u5168\u94fe\u8def\u53ef\u89c1\u6027\n<\/li>\n<\/ul>\n<p>\u76f8\u8f83\u4e8e\u4f20\u7edf\u9632\u706b\u5899\u57fa\u4e8eiptables\u7684\u94fe\u5f0f\u89c4\u5219\u5339\u914d\uff0ceBPF\u7a0b\u5e8f\u901a\u8fc7<strong>BPF\u6620\u5c04\uff08Map\uff09<\/strong>\u548c<strong>\u5c3e\u8c03\u7528\uff08Tail Call\uff09<\/strong>\u673a\u5236\uff0c\u53ef\u4ee5\u5b9e\u73b0\u590d\u6742\u5ea6O(1)\u7684\u76f4\u63a5\u67e5\u8868\u5339\u914d\u3002\u5b9e\u6d4b\u6570\u636e\u663e\u793a\uff0c\u5728100Gbps\u7f51\u7edc\u73af\u5883\u4e0b\uff0ceBPF\u9632\u706b\u5899\u7684\u89c4\u5219\u5339\u914d\u901f\u5ea6\u6bd4iptables\u5feb3\u4e2a\u6570\u91cf\u7ea7\u3002<\/p>\n<h3 id=\"\u4e8c-\u6784\u5efa\u5b9e\u65f6\u6d41\u91cf\u8fc7\u6ee4\u7684\u56db\u5c42\u67b6\u6784\">\u4e8c\u3001\u6784\u5efa\u5b9e\u65f6\u6d41\u91cf\u8fc7\u6ee4\u7684\u56db\u5c42\u67b6\u6784<\/h3>\n<h4 id=\"1-\u6570\u636e\u5e73\u9762\u52a0\u901f-xdp\u5c42\">1. \u6570\u636e\u5e73\u9762\u52a0\u901f\uff08XDP\u5c42\uff09<\/h4>\n<p>\u5728\u7f51\u5361\u63a5\u6536\u6570\u636e\u5305\u7684\u7b2c\u4e00\u65f6\u95f4\uff0c<strong>XDP\u94a9\u5b50<\/strong>\u5c31\u4f1a\u89e6\u53d1\u9884\u52a0\u8f7d\u7684eBPF\u7a0b\u5e8f\u3002\u8fd9\u4e2a\u9636\u6bb5\u53ef\u4ee5\u6267\u884c\u6700\u5e95\u5c42\u7684\u8fc7\u6ee4\u903b\u8f91\uff1a<\/p>\n<pre><code class=\"language-c\">SEC(&quot;xdp&quot;)  \r\nint xdp_firewall(struct xdp_md *ctx) {  \r\nvoid *data_end = (void *)(long)ctx-&gt;data_end;  \r\nvoid *data = (void *)(long)ctx-&gt;data;  \r\n  \r\nstruct ethhdr *eth = data;  \r\nif (eth + 1 &gt; data_end) return XDP_PASS;  \r\n  \r\nif (eth-&gt;h_proto == htons(ETH_P_IP)) {  \r\nstruct iphdr *ip = data + sizeof(*eth);  \r\nif (ip + 1 &gt; data_end) return XDP_PASS;  \r\n  \r\nif (ip-&gt;protocol == IPPROTO_TCP) {  \r\n\/\/ \u6267\u884cTCP\u5305\u8fc7\u6ee4\u903b\u8f91  \r\nreturn XDP_DROP;  \r\n}  \r\n}  \r\nreturn XDP_PASS;  \r\n}  \r\n<\/code><\/pre>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u5c55\u793a\u4e86\u5982\u4f55\u5728\u6570\u636e\u94fe\u8def\u5c42\u76f4\u63a5\u4e22\u5f03\u7279\u5b9a\u534f\u8bae\u7684\u6570\u636e\u5305\uff0c\u5904\u7406\u65f6\u5ef6\u5c0f\u4e8e100\u7eb3\u79d2\u3002<\/p>\n<h4 id=\"2-\u7b56\u7565\u51b3\u7b56\u5c42-\u7528\u6237\u6001\u63a7\u5236\u5e73\u9762\">2. \u7b56\u7565\u51b3\u7b56\u5c42\uff08\u7528\u6237\u6001\u63a7\u5236\u5e73\u9762\uff09<\/h4>\n<p>\u901a\u8fc7<strong>BPF\u6620\u5c04<\/strong>\u5b9e\u73b0\u52a8\u6001\u7b56\u7565\u66f4\u65b0\uff1a<\/p>\n<pre><code class=\"language-python\">from bcc import BPF  \r\nimport ctypes  \r\n  \r\nbpf = BPF(src_file=&quot;firewall.c&quot;)  \r\npolicy_map = bpf[&quot;policy_map&quot;]  \r\n  \r\nclass Policy(ctypes.Structure):  \r\n_fields_ = [(&quot;prefix&quot;, ctypes.c_uint32),  \r\n(&quot;mask&quot;, ctypes.c_uint32),  \r\n(&quot;action&quot;, ctypes.c_uint8)]  \r\n  \r\nnew_rule = Policy(prefix=0xC0A80100, mask=0xFFFFFF00, action=0)  \r\npolicy_map[ctypes.c_uint32(0)] = new_rule  \r\n<\/code><\/pre>\n<p>\u7528\u6237\u6001\u7a0b\u5e8f\u901a\u8fc7\u4fee\u6539\u5171\u4eab\u6620\u5c04\uff0c\u5b9e\u65f6\u66f4\u65b0\u8fc7\u6ee4\u89c4\u5219\u800c\u4e0d\u4e2d\u65ad\u670d\u52a1\u3002<\/p>\n<h4 id=\"3-\u6df1\u5ea6\u5305\u68c0\u6d4b-tc\u5c42\">3. \u6df1\u5ea6\u5305\u68c0\u6d4b\uff08TC\u5c42\uff09<\/h4>\n<p>\u5bf9\u4e8e\u9700\u8981L7\u5c42\u5206\u6790\u7684\u573a\u666f\uff0c<strong>\u6d41\u91cf\u63a7\u5236\uff08Traffic Control\uff09<\/strong>\u5c42\u7684eBPF\u7a0b\u5e8f\u53ef\u4ee5\u91cd\u7ec4HTTP\u62a5\u6587\uff1a<\/p>\n<pre><code class=\"language-c\">SEC(&quot;tc&quot;)  \r\nint tc_http_filter(struct __sk_buff *skb) {  \r\nstruct http_header hdr;  \r\nif (bpf_skb_load_bytes(skb, ETH_HLEN + IP_HLEN + TCP_HLEN, &amp;hdr, sizeof(hdr)) == 0) {  \r\nif (hdr.method == HTTP_POST &amp;&amp; contains_sensitive(hdr.uri)) {  \r\nbpf_printk(&quot;Blocked sensitive API call&quot;);  \r\nreturn TC_ACT_SHOT;  \r\n}  \r\n}  \r\nreturn TC_ACT_OK;  \r\n}  \r\n<\/code><\/pre>\n<p>\u8fd9\u79cd\u6df1\u5ea6\u68c0\u6d4b\u5728\u4fdd\u8bc1\u7ebf\u901f\u5904\u7406\u7684\u524d\u63d0\u4e0b\uff0c\u5b9e\u73b0\u4e86\u5e94\u7528\u5c42\u534f\u8bae\u7684\u5185\u5bb9\u5ba1\u8ba1\u3002<\/p>\n<h3 id=\"\u4e09-\u751f\u4ea7\u73af\u5883\u5b9e\u6218-\u4e91\u539f\u751f\u9632\u706b\u5899\">\u4e09\u3001\u751f\u4ea7\u73af\u5883\u5b9e\u6218\uff1a\u4e91\u539f\u751f\u9632\u706b\u5899<\/h3>\n<p>\u67d0\u91d1\u878d\u79d1\u6280\u516c\u53f8\u5728Kubernetes\u96c6\u7fa4\u4e2d\u90e8\u7f72\u4e86\u57fa\u4e8eeBPF\u7684<strong>Cilium\u9632\u706b\u5899<\/strong>\uff0c\u5176\u67b6\u6784\u8bbe\u8ba1\u5305\u542b\u4e09\u4e2a\u5173\u952e\u521b\u65b0\u70b9\uff1a<\/p>\n<ol>\n<li>\n<p><strong>\u8eab\u4efd\u9a71\u52a8\u7b56\u7565<\/strong><br \/>\n\u5c06\u4f20\u7edf\u7684IP\/\u7aef\u53e3\u89c4\u5219\u8f6c\u6362\u4e3a\u670d\u52a1\u8eab\u4efd\u6807\u8bc6\uff0c\u7b56\u7565\u6761\u76ee\u4ece12000\u6761\u7f29\u51cf\u81f3800\u6761<\/p>\n<\/li>\n<li>\n<p><strong>\u81ea\u9002\u5e94\u5b66\u4e60\u6a21\u5f0f<\/strong><br \/>\n\u901a\u8fc7<strong>BPF\u73af\u5f62\u7f13\u51b2\u533a\uff08Ring Buffer\uff09<\/strong>\u5b9e\u65f6\u91c7\u96c6\u6d41\u91cf\u6a21\u5f0f\uff0c\u81ea\u52a8\u751f\u6210\u63a8\u8350\u89c4\u5219<\/p>\n<\/li>\n<li>\n<p><strong>\u96f6\u4fe1\u4efb\u67b6\u6784<\/strong><br \/>\n\u6bcf\u4e2aPod\u5185\u7f6e\u5fae\u578b\u9632\u706b\u5899\uff0c\u5b9e\u73b0\u5fae\u5206\u6bb5\u9694\u79bb\u3002\u5b9e\u6d4b\u663e\u793a\uff0c\u6a2a\u5411\u6e17\u900f\u653b\u51fb\u7684\u62e6\u622a\u6210\u529f\u7387\u4ece75%\u63d0\u5347\u81f399.97%<\/p>\n<\/li>\n<\/ol>\n<p>\u76d1\u63a7\u6570\u636e\u663e\u793a\uff0c\u8be5\u65b9\u6848\u5c06API\u7f51\u5173\u7684P99\u5ef6\u8fdf\u4ece18ms\u964d\u81f33ms\uff0c\u540c\u65f6\u5c06DDoS\u9632\u62a4\u7684\u81ea\u52a8\u963b\u65ad\u54cd\u5e94\u65f6\u95f4\u7f29\u77ed\u81f3200\u03bcs\u3002<\/p>\n<h3 id=\"\u56db-\u6027\u80fd\u4f18\u5316\u5173\u952e\u8def\u5f84\">\u56db\u3001\u6027\u80fd\u4f18\u5316\u5173\u952e\u8def\u5f84<\/h3>\n<ol>\n<li>\n<p><strong>JIT\u7f16\u8bd1\u4f18\u5316<\/strong><br \/>\n\u4f7f\u7528LLVM\u7f16\u8bd1eBPF\u5b57\u8282\u7801\u65f6\uff0c\u5f00\u542f<code>-mcpu=v3<\/code>\u9009\u9879\u53ef\u4f7f\u6307\u4ee4\u5468\u671f\u51cf\u5c1115%<\/p>\n<\/li>\n<li>\n<p><strong>\u6620\u5c04\u6570\u636e\u7ed3\u6784\u9009\u62e9<\/strong><\/p>\n<\/li>\n<\/ol>\n<ul>\n<li>\u7cbe\u786e\u5339\u914d\u4f7f\u7528BPF_HASH_MAP\n<\/li>\n<li>CIDR\u5757\u5339\u914d\u91c7\u7528LPM_TRIE_MAP\n<\/li>\n<li>\u901f\u7387\u9650\u5236\u573a\u666f\u4f18\u9009BPF_RINGBUF_MAP\n<\/li>\n<\/ul>\n<ol>\n<li><strong>\u6279\u5904\u7406\u673a\u5236<\/strong><br \/>\n\u901a\u8fc7<code>bpf_msg_pull_data<\/code>\u5b9e\u73b0\u6570\u636e\u5305\u6279\u91cf\u5904\u7406\uff0c\u5355\u4e2aCPU\u6838\u5fc3\u53ef\u7ef4\u630114Mpps\u7684\u5904\u7406\u80fd\u529b\n<\/li>\n<\/ol>\n<p>\u5728AWS c5n.9xlarge\u5b9e\u4f8b\u4e0a\u7684\u6d4b\u8bd5\u8868\u660e\uff0c\u4f18\u5316\u540e\u7684eBPF\u9632\u706b\u5899\u76f8\u6bd4\u4f20\u7edf\u65b9\u6848\uff0c\u541e\u5410\u91cf\u63d0\u53478\u500d\uff0c\u540c\u65f6\u4fdd\u630195%\u7684\u89c4\u5219\u5339\u914d\u7cbe\u5ea6\u3002<\/p>\n<h3 id=\"\u4e94-\u5b89\u5168\u4e0e\u5408\u89c4\u7684\u53cc\u91cd\u6311\u6218\">\u4e94\u3001\u5b89\u5168\u4e0e\u5408\u89c4\u7684\u53cc\u91cd\u6311\u6218<\/h3>\n<p>\u5c3d\u7ba1eBPF\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u80fd\u529b\uff0c\u4f46\u5728\u5b9e\u9645\u90e8\u7f72\u4e2d\u4ecd\u9700\u6ce8\u610f\uff1a<\/p>\n<ul>\n<li><strong>\u9a8c\u8bc1\u5668\u7ed5\u8fc7\u98ce\u9669<\/strong>\uff1a2023\u5e74Black Hat\u5927\u4f1a\u62ab\u9732\u7684CVE-2023-2163\u6f0f\u6d1e\uff0c\u63ed\u793a\u4e86\u7279\u5b9a\u6761\u4ef6\u4e0beBPF\u9a8c\u8bc1\u5668\u7684\u8fb9\u754c\u95ee\u9898\n<\/li>\n<li><strong>\u5ba1\u8ba1\u8ffd\u8e2a\u7f3a\u9677<\/strong>\uff1a\u9700\u8981\u7ed3\u5408BTF\u548cCO-RE\u6280\u672f\u5b9e\u73b0\u8de8\u5185\u6838\u7248\u672c\u7684\u884c\u4e3a\u8ffd\u6eaf\n<\/li>\n<li><strong>\u5408\u89c4\u6027\u8981\u6c42<\/strong>\uff1a\u5728\u91d1\u878d\u7b49\u884c\u4e1a\u90e8\u7f72\u65f6\uff0c\u5fc5\u987b\u901a\u8fc7FIPS 140-2\u8ba4\u8bc1\u7684\u52a0\u5bc6\u6a21\u5757\u5904\u7406\u654f\u611f\u6570\u636e\n<\/li>\n<\/ul>\n<p>\u67d0\u8de8\u56fd\u4f01\u4e1a\u901a\u8fc7<strong>eBPF+Intel SGX<\/strong>\u7684\u67b6\u6784\u8bbe\u8ba1\uff0c\u5728\u4fdd\u8bc1\u6027\u80fd\u7684\u524d\u63d0\u4e0b\u5b9e\u73b0\u4e86\u5bc6\u6587\u6d41\u91cf\u8fc7\u6ee4\uff0c\u6ee1\u8db3GDPR\u7684\u5408\u89c4\u8981\u6c42\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728\u4e91\u8ba1\u7b97\u548c\u5fae\u670d\u52a1\u67b6\u6784\u4e3b\u5bfc\u7684\u6570\u5b57\u5316\u65f6\u4ee3\uff0c\u6bcf\u79d2\u767e\u4e07\u7ea7\u7684\u7f51\u7edc\u6570\u636e\u5305\u4ea4\u4e92\u65e9\u5df2\u6210\u4e3a\u5e38\u6001\u3002\u4f20\u7edf\u7684\u9632\u706b\u5899\u65b9\u6848\u5728\u5e94\u5bf9\u73b0\u4ee3\u6570\u636e\u4e2d\u5fc3\u4e1c\u897f\u5411\u6d41\u91cf\u65f6\uff0c\u5e38\u5e38\u9677\u5165\u6027\u80fd\u74f6\u9888\u2014\u2014\u5f53iptables\u89c4\u5219\u8d85\u8fc73000\u6761\u65f6\uff0c\u5904\u7406\u5ef6\u8fdf\u5c31\u4f1a\u5448\u6307\u6570\u7ea7\u589e\u957f\u3002\u8fd9\u79cd\u56f0\u5883\u50ac\u751f\u4e86eBPF\u6280\u672f\u7684\u9769\u547d\u6027\u7a81\u7834\uff1a\u67d0\u5934\u90e8\u4e91\u5382\u5546\u57282022\u5e74\u7684\u6280\u672f\u767d\u76ae\u4e66\u4e2d\u62ab\u9732\uff0c\u901a\u8fc7eBPF\u5b9e\u73b0\u7684\u7f51\u7edc\u7b56\u7565\u6267\u884c\uff0c\u5c06\u6570\u636e\u5305\u5904\u7406\u5ef6\u8fdf\u4ece\u5fae\u79d2\u7ea7\u964d\u81f3\u7eb3\u79d2\u7ea7\uff0c\u540c\u65f6CPU\u5229\u7528\u7387\u964d\u4f4e40%\u3002\u8fd9\u79cd\u53d8\u9769\u6027\u6280\u672f\u6b63\u5728\u91cd\u65b0\u5b9a\u4e49\u5b9e\u65f6\u6d41\u91cf\u63a7\u5236\u7684\u8fb9\u754c\u3002 \u4e00\u3001eBPF\uff1a\u5185\u6838\u53ef\u7f16\u7a0b\u6027\u7684\u8303\u5f0f\u9769\u547d eBPF\uff08Extended Berkeley Packet Filter\uff09 \u4e0d\u662f\u7b80\u5355\u7684\u5de5\u5177\u5347\u7ea7\uff0c\u800c\u662f\u64cd\u4f5c\u7cfb\u7edf\u5185\u6838\u67b6\u6784\u7684\u8303\u5f0f\u8f6c\u53d8\u3002\u5b83\u901a\u8fc7\u6c99\u7bb1\u673a\u5236\uff0c\u5141\u8bb8\u7528\u6237\u6001\u7a0b\u5e8f\u5728\u4e0d\u4fee\u6539\u5185\u6838\u6e90\u7801\u3001\u4e0d\u52a0\u8f7d\u5185\u6838\u6a21\u5757\u7684\u524d\u63d0\u4e0b\uff0c\u5b89\u5168\u5730\u6ce8\u5165\u81ea\u5b9a\u4e49\u4ee3\u7801\u5230\u5185\u6838\u6267\u884c\u6d41\u4e2d\u3002\u8fd9\u79cd\u7279\u6027\u4f7f\u5176\u5929\u751f\u5177\u5907\u4e09\u5927\u4f18\u52bf\uff1a \u96f6\u62f7\u8d1d\u6570\u636e\u5904\u7406\uff1aXDP\uff08eXpress Data Path\uff09\u67b6\u6784\u76f4\u63a5\u5728\u7f51\u5361\u9a71\u52a8\u5c42\u5904\u7406\u6570\u636e\u5305 \u52a8\u6001\u7b56\u7565\u52a0\u8f7d\uff1a\u652f\u6301\u7b56\u7565\u7684\u70ed\u66f4\u65b0\u800c\u65e0\u9700\u91cd\u542f\u670d\u52a1 \u7ec6\u7c92\u5ea6\u89c2\u6d4b\u80fd\u529b\uff1a\u4ece\u7cfb\u7edf\u8c03\u7528\u5230\u7f51\u7edc\u534f\u8bae\u6808\u7684\u5168\u94fe\u8def\u53ef\u89c1\u6027 \u76f8\u8f83\u4e8e\u4f20\u7edf\u9632\u706b\u5899\u57fa\u4e8eiptables\u7684\u94fe\u5f0f\u89c4\u5219\u5339\u914d\uff0ceBPF\u7a0b\u5e8f\u901a\u8fc7BPF\u6620\u5c04\uff08Map\uff09\u548c\u5c3e\u8c03\u7528\uff08Tail Call\uff09\u673a\u5236\uff0c\u53ef\u4ee5\u5b9e\u73b0\u590d\u6742\u5ea6O(1)\u7684\u76f4\u63a5\u67e5\u8868\u5339\u914d\u3002\u5b9e\u6d4b\u6570\u636e\u663e\u793a\uff0c\u5728100Gbps\u7f51\u7edc\u73af\u5883\u4e0b\uff0ceBPF\u9632\u706b\u5899\u7684\u89c4\u5219\u5339\u914d\u901f\u5ea6\u6bd4iptables\u5feb3\u4e2a\u6570\u91cf\u7ea7\u3002 \u4e8c\u3001\u6784\u5efa\u5b9e\u65f6\u6d41\u91cf\u8fc7\u6ee4\u7684\u56db\u5c42\u67b6\u6784 1. \u6570\u636e\u5e73\u9762\u52a0\u901f\uff08XDP\u5c42\uff09 \u5728\u7f51\u5361\u63a5\u6536\u6570\u636e\u5305\u7684\u7b2c\u4e00\u65f6\u95f4\uff0cXDP\u94a9\u5b50\u5c31\u4f1a\u89e6\u53d1\u9884\u52a0\u8f7d\u7684eBPF\u7a0b\u5e8f\u3002\u8fd9\u4e2a\u9636\u6bb5\u53ef\u4ee5\u6267\u884c\u6700\u5e95\u5c42\u7684\u8fc7\u6ee4\u903b\u8f91\uff1a SEC(&quot;xdp&quot;) int xdp_firewall(struct xdp_md *ctx) { void *data_end = (void *)(long)ctx-&gt;data_end; void *data = (void *)(long)ctx-&gt;data; struct ethhdr *eth = data; if (eth + 1 &gt; data_end) return XDP_PASS; if (eth-&gt;h_proto == htons(ETH_P_IP)) { struct iphdr *ip [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[],"class_list":["post-37014","post","type-post","status-publish","format-standard","hentry","category-product-news"],"_links":{"self":[{"href":"https:\/\/www.yunshan.net\/blog\/wp-json\/wp\/v2\/posts\/37014","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yunshan.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yunshan.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yunshan.net\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yunshan.net\/blog\/wp-json\/wp\/v2\/comments?post=37014"}],"version-history":[{"count":1,"href":"https:\/\/www.yunshan.net\/blog\/wp-json\/wp\/v2\/posts\/37014\/revisions"}],"predecessor-version":[{"id":37016,"href":"https:\/\/www.yunshan.net\/blog\/wp-json\/wp\/v2\/posts\/37014\/revisions\/37016"}],"wp:attachment":[{"href":"https:\/\/www.yunshan.net\/blog\/wp-json\/wp\/v2\/media?parent=37014"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yunshan.net\/blog\/wp-json\/wp\/v2\/categories?post=37014"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yunshan.net\/blog\/wp-json\/wp\/v2\/tags?post=37014"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}