
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/">
    <channel>
        <title><![CDATA[ The Cloudflare Blog ]]></title>
        <description><![CDATA[ Get the latest news on how products at Cloudflare are built, technologies used, and join the teams helping to build a better Internet. ]]></description>
        <link>https://blog.cloudflare.com</link>
        <atom:link href="https://blog.cloudflare.com/" rel="self" type="application/rss+xml"/>
        <language>en-us</language>
        <image>
            <url>https://blog.cloudflare.com/favicon.png</url>
            <title>The Cloudflare Blog</title>
            <link>https://blog.cloudflare.com</link>
        </image>
        <lastBuildDate>Tue, 07 Apr 2026 05:03:48 GMT</lastBuildDate>
        <item>
            <title><![CDATA[Network flow monitoring is GA, providing end-to-end traffic visibility]]></title>
            <link>https://blog.cloudflare.com/network-flow-monitoring-generally-available/</link>
            <pubDate>Wed, 18 Oct 2023 13:00:53 GMT</pubDate>
            <description><![CDATA[ Network engineers often need better visibility into their network’s traffic when analyzing DDoS attacks or troubleshooting other traffic anomalies. To solve this problem, Cloudflare offers a network flow monitoring product that gives customers end-to-end traffic visibility across their network. ]]></description>
            <content:encoded><![CDATA[ <p></p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/4EZamNYbSPCC1yBqXXwaZR/d3e36168073dcc8f08b715ab7d4bbe5e/image4-4.png" />
            
            </figure><p>Network engineers often find they need better visibility into their network’s traffic and operations while analyzing DDoS attacks or troubleshooting other traffic anomalies. These engineers typically have some high level metrics about their network traffic, but they struggle to collect essential information on the specific traffic flows that would clarify the issue. To solve this problem, Cloudflare has been piloting a <a href="https://www.cloudflare.com/network-services/solutions/network-monitoring-tools/">cloud network flow monitoring product</a> called <a href="https://www.cloudflare.com/network-services/products/magic-network-monitoring/">Magic Network Monitoring</a> that gives customers end-to-end visibility into all traffic across their network.</p><p>Today, Cloudflare is excited to announce that Magic Network Monitoring (previously called <a href="/flow-based-monitoring-for-magic-transit/">Flow Based Monitoring</a>) is now generally available to all enterprise customers. Over the last year, the Cloudflare engineering team has significantly improved Magic Network Monitoring; we’re excited to offer a network services product that will help our customers identify threats faster, reduce vulnerabilities, and <a href="https://www.cloudflare.com/network-services/solutions/enterprise-network-security/">make their network more secure</a>.</p><p>Magic Network Monitoring is automatically enabled for all Magic Transit and Magic WAN enterprise customers. The product is located at the account level of the Cloudflare dashboard and can be opened by navigating to “Analytics &amp; Logs &gt; Magic Monitoring”. The onboarding process for Magic Network Monitoring is self-serve, and all enterprise customers with access can begin configuring the product today.</p><p>Any enterprise customers without Magic Transit or Magic WAN that are interested in testing Magic Network Monitoring can receive access to the free version (with some <a href="https://developers.cloudflare.com/magic-network-monitoring/magic-network-monitoring-free/">limitations</a> on traffic volume) by submitting a request to their Cloudflare account team or filling out this form to <a href="https://cloudflare.com/network-services/products/magic-network-monitoring/">talk with an expert</a>.</p>
    <div>
      <h3>What is Magic Network Monitoring?</h3>
      <a href="#what-is-magic-network-monitoring">
        
      </a>
    </div>
    <p>Magic Network Monitoring is a cloud network flow monitor. <a href="https://en.wikipedia.org/wiki/Traffic_flow_(computer_networking)">Network traffic flow</a> refers to any stream of packets between one source and one destination with the same Internet protocol and set of ports. Customers can send network flow reports from their routers (or any other network flow generator) to a publicly available endpoint on <a href="https://www.cloudflare.com/learning/cdn/glossary/anycast-network/">Cloudflare’s anycast network</a>, even if the traffic didn’t originally pass through Cloudflare’s network. Cloudflare analyzes the network flow data, then provides customers visibility into key network traffic metrics via an analytics dashboard. These metrics include: traffic volume (in bits or packets) over time, source IPs, destination IPs, ports, traffic protocols, and router IPs. Customers can also configure alerts to identify <a href="https://www.cloudflare.com/learning/ddos/what-is-a-ddos-attack/">DDoS attacks</a> and any other abnormal traffic volume activities.</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/3CrObnYrLzKlSOjSUS8dH6/c59b39388b98ba4e7492121d5db3bacf/1-1.png" />
            
            </figure><p>Send flow data from your network to Cloudflare for analysis</p>
    <div>
      <h3>Enterprise DDoS attack type detection</h3>
      <a href="#enterprise-ddos-attack-type-detection">
        
      </a>
    </div>
    <p><a href="https://developers.cloudflare.com/magic-transit/on-demand/">Magic Transit On Demand</a> (MTOD) customers will experience significant traffic visibility benefits when using Magic Network Monitoring. <a href="https://www.cloudflare.com/network-services/products/magic-transit/">Magic Transit</a> is a <a href="https://www.cloudflare.com/network-security/">network security solution</a> that offers DDoS protection and traffic acceleration from every Cloudflare data center for on-premise, cloud-hosted, and hybrid networks. Magic Transit On Demand customers can activate Magic Transit for protection when a DDoS attack is detected.</p><p>In general, we noticed that some MTOD customers lacked the network visibility tools to quickly identify DDoS attacks and take the appropriate mitigation action. Now, MTOD customers can use Magic Network Monitoring to analyze their network data and receive an alert if a DDoS attack is detected.</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/6HcgWfT995D5YTtTjI7t0x/8f5265dc6c920df9aa4de7db814bfc71/2-1.png" />
            
            </figure><p>Cloudflare detects a DDoS attack from the customer’s network flow data</p><p>Once a DDoS attack is detected, Magic Network Monitoring customers can choose to either manually or automatically enable Magic Transit to mitigate any DDoS attacks.</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/5FlxXObNPK0L8lx2sN0S6S/8a47e805c9ec45f41c1f9d3bf6d84a33/3-1.png" />
            
            </figure><p>Activate Magic Transit for DDoS protection</p>
    <div>
      <h3>Enterprise network monitoring</h3>
      <a href="#enterprise-network-monitoring">
        
      </a>
    </div>
    <p>Cloudflare’s Magic WAN and Cloudflare One customers can also benefit from using Magic Network Monitoring. Today, these customers have excellent visibility into the traffic they send through Cloudflare’s network, but sometimes they may lack visibility into traffic that isn’t sent through Cloudflare. This can include traffic that remains on a local network, or network traffic sent in between cloud environments. Magic WAN and Cloudflare One customers can add Magic Network Monitoring into their suite of product solutions to establish end-to-end network visibility across all traffic on their network.</p>
    <div>
      <h3>A deep dive into network flow and network traffic sampling</h3>
      <a href="#a-deep-dive-into-network-flow-and-network-traffic-sampling">
        
      </a>
    </div>
    <p>Magic Network Monitoring gives customers better visibility into their network traffic by ingesting and analyzing network flow data.</p><p>The process starts when a router (or other network flow generation device) collects <a href="https://en.wikipedia.org/wiki/Sampling_(statistics)">statistical samples</a> of inbound and / or outbound packet data. These samples are collected by examining 1 in every X packets, where X is the sampling rate configured on the router. Typical sampling rates range from 1 in every 1,000 to 1 in every 4,000 packets. The ideal sampling rate depends on the traffic volume, traffic diversity, and the compute / memory power of your router’s hardware. You can read more about the <a href="https://developers.cloudflare.com/magic-network-monitoring/routers/recommended-sampling-rate/">recommended network flow sampling rate</a> in Cloudflare’s MNM Developer Docs.</p><p>The sampled data is packaged into one of two industry standard formats for network flow data: NetFlow or sFlow. In NetFlow, the sampled packet data is grouped by different packet characteristics such as source / destination IP, port, and protocol. Each group of sampled packet data also includes a traffic volume estimate. In sFlow, the entire packet header is selected as the representative sample, and there isn’t any data summarization. As a result, sFlow is a richer data format and includes more details about network traffic than NetFlow data. Once either the NetFlow or sFlow data samples are collected, they’re sent to Magic Network Monitoring for analysis and alerting.</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/2XoUWHVTlsaVD6wYjekYm6/951cff39344b3912444f239618af64c6/4-1.png" />
            
            </figure>
    <div>
      <h3>Why simple random sampling didn’t work for Magic Network Monitoring</h3>
      <a href="#why-simple-random-sampling-didnt-work-for-magic-network-monitoring">
        
      </a>
    </div>
    <p>Magic Network Monitoring has come a long way from its early access release one year ago. In particular, the Cloudflare engineering team invested significant time in improving the accuracy of the traffic volume estimations in MNM. In the early access version of Magic Network Monitoring, customers were unexpectedly reporting that their network traffic volume estimates were too high and didn’t match the expected value.</p><p>Magic Network Monitoring performs its own sampling of the NetFlow or sFlow data it receives, so it can effectively scale and manage the data ingested across Cloudflare’s global network. Increasing the accuracy of the traffic volume estimations was more difficult than expected, as the NetFlow or sFlow data parsed by MNM is already built on sampled packet data. This introduces multiple distinct layers of data sampling in the product’s analytics.</p><p>The first version of Magic Network Monitoring used <a href="https://en.wikipedia.org/wiki/Simple_random_sample">random sampling</a> where a random subset of network flow data with the same timestamp was selected to represent the traffic volume at that point in time. A characteristic of network flow data is that some samples are more significant than others and represent a greater volume of network traffic. In order to account for this significance, we can associate a <a href="https://en.wikipedia.org/wiki/Weighting">weight</a> with each sample based on the traffic volume it represents. Network flow data weights are always positive numbers, and they follow a <a href="https://en.wikipedia.org/wiki/Long_tail">long tail distribution</a>. These data characteristics caused MNM’s random sampling to incorrectly estimate the traffic volume of a customer’s network. Customers would see false spikes in their traffic volume analytics when an outlying data sample from the long tail was randomly selected to be the representative of all traffic at that point in time.</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/2Tje0Xn9GucCoNamBEyvVE/0d097130617a1c6584efa8679f91c87a/5-1.png" />
            
            </figure>
    <div>
      <h3>Increasing accuracy with VarOpt reservoir sampling</h3>
      <a href="#increasing-accuracy-with-varopt-reservoir-sampling">
        
      </a>
    </div>
    <p>To solve this problem, the Cloudflare engineering team implemented an alternative <a href="https://en.wikipedia.org/wiki/Reservoir_sampling">reservoir sampling</a> technique called <a href="https://arxiv.org/pdf/0803.0473.pdf">VarOpt</a>. VarOpt is designed to collect samples from a stream of data when the length of the data stream is unknown (a perfect application for analyzing incoming network flow data). In the MNM implementation of VarOpt, we start with an empty reservoir of a fixed size that is filled with samples of network flow data. When the reservoir is full, and there is still new incoming network flow data, an old sample is randomly discarded from the reservoir and replaced with a new one.</p><p>After a certain number of samples have been observed, we calculate the traffic volume across all weighted samples in the reservoir, and that is the estimated traffic volume of a customer’s network flow at that point in time. Finally, the reservoir is emptied, and the VarOpt loop is restarted by filling the reservoir with the next set of the latest network flow samples.</p><p>The new VarOpt sampling method significantly increased the accuracy of the traffic volume estimations in Magic Network Monitoring, and solved our customer’s problems. These sampling improvements paved the way for general availability, and we’re excited to make accurate network flow analytics available to everyone.</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/2NYGpyTodAgtP9K8KycjGZ/fa5e290cdf3286c7efcbbe53954e1540/6-1.png" />
            
            </figure>
    <div>
      <h3>Developer Docs and Discord Community</h3>
      <a href="#developer-docs-and-discord-community">
        
      </a>
    </div>
    <p>There are detailed <a href="https://developers.cloudflare.com/magic-network-monitoring/">Developer Docs for Magic Network Monitoring</a> that explain the product’s features and outlines a step-by-step configuration guide for new customers. As you’re working through the Magic Network Monitoring documentation, please feel free to provide feedback by clicking the “Give Feedback” button in the top right corner of the Developer Docs.</p><p>We’ve also created a channel in Cloudflare’s Discord community built around debugging configuration problems, testing new features, and providing product feedback. You can follow this link to join the <a href="https://discord.gg/cloudflaredev">Cloudflare Discord server</a>.</p>
    <div>
      <h3>Free version</h3>
      <a href="#free-version">
        
      </a>
    </div>
    <p>A <a href="https://developers.cloudflare.com/magic-network-monitoring/magic-network-monitoring-free/">free version of Magic Network Monitoring</a> is available to all Enterprise customers on request to their Cloudflare account team. The free version is designed to enable Enterprise customers to quickly test and evaluate Magic Network Monitoring before purchasing Magic Transit, Magic WAN, or Cloudflare One. Enterprise customers can fully configure Magic Network Monitoring themselves by following the <a href="https://developers.cloudflare.com/magic-network-monitoring/get-started/">step-by-step onboarding guide</a> in the product’s documentation. The free version has some <a href="https://developers.cloudflare.com/magic-network-monitoring/magic-network-monitoring-free/">limitations</a> on the quantity of traffic that can be processed which are further outlined in the product’s documentation.</p><p>The free version of Magic Network Monitoring is also available to all Free, Pro, and Business plan Cloudflare customers via a closed beta. Anyone can request access to the free version by <a href="https://developers.cloudflare.com/magic-network-monitoring/magic-network-monitoring-free/">reading the free version documentation</a> and <a href="https://forms.gle/z93ghpydpKdAFZ7P9">filling out this form</a>. Priority access is granted to anyone that joins <a href="https://discord.com/invite/cloudflaredev">Cloudflare’s Discord server</a> and sends a message in the Magic Network Monitoring Discord channel.</p>
    <div>
      <h3>Next steps that you can take today</h3>
      <a href="#next-steps-that-you-can-take-today">
        
      </a>
    </div>
    <p>Magic Network Monitoring is generally available, and all Magic Transit and Magic WAN customers have been automatically granted access to the product today. You can navigate to the product by going to the account level of the Cloudflare dashboard, then selecting “Analytics &amp; Logs &gt; Magic Monitoring”.</p><p>If you’re an enterprise customer without Magic Transit or Magic WAN, and you want to use Magic Network Monitoring to improve your traffic visibility, you can <a href="https://cloudflare.com/network-services/products/magic-network-monitoring/">talk with an MNM expert today</a>.</p><p>If you’re interested in using Magic Transit and Magic Network Monitoring for DDoS protection, you can <a href="https://www.cloudflare.com/network-services/products/magic-transit/">request a demo of Magic Transit</a>. If you want to use Magic WAN and Magic Network Monitoring together to establish end-to-end network traffic visibility, you can <a href="https://www.cloudflare.com/network-services/products/magic-wan/">talk with a Magic WAN expert</a>.</p> ]]></content:encoded>
            <category><![CDATA[Magic Network Monitoring]]></category>
            <category><![CDATA[Network Services]]></category>
            <category><![CDATA[Magic Transit]]></category>
            <category><![CDATA[Magic WAN]]></category>
            <category><![CDATA[Product News]]></category>
            <guid isPermaLink="false">5Q496AB243DF9bETeys1Pq</guid>
            <dc:creator>Chris Draper</dc:creator>
            <dc:creator>Chris J Arges</dc:creator>
            <dc:creator>Ana Oliveira</dc:creator>
            <dc:creator>João Santos</dc:creator>
            <dc:creator>Luís Franco</dc:creator>
            <dc:creator>Nadin El-Yabroudi</dc:creator>
            <dc:creator>Dan Geraghty</dc:creator>
        </item>
        <item>
            <title><![CDATA[How We Used eBPF to Build Programmable Packet Filtering in Magic Firewall]]></title>
            <link>https://blog.cloudflare.com/programmable-packet-filtering-with-magic-firewall/</link>
            <pubDate>Mon, 06 Dec 2021 13:59:53 GMT</pubDate>
            <description><![CDATA[ By combining the power of eBPF and Nftables, Magic Firewall can mitigate sophisticated attacks on infrastructure by enforcing a positive security model. ]]></description>
            <content:encoded><![CDATA[ <p></p><p>Cloudflare actively protects services from sophisticated attacks day after day. For users of Magic Transit, <a href="https://www.cloudflare.com/ddos/">DDoS protection</a> detects and drops attacks, while <a href="https://www.cloudflare.com/magic-firewall/">Magic Firewall</a> allows custom packet-level rules, enabling customers to deprecate hardware firewall appliances and block malicious traffic at Cloudflare’s network. The types of attacks and sophistication of attacks continue to evolve, as recent DDoS and reflection <a href="/attacks-on-voip-providers/">attacks</a> <a href="/update-on-voip-attacks/">against</a> VoIP services targeting protocols such as <a href="https://en.wikipedia.org/wiki/Session_Initiation_Protocol">Session Initiation Protocol</a> (SIP) have shown. Fighting these attacks requires pushing the limits of packet filtering beyond what traditional firewalls are capable of. We did this by taking best of class technologies and combining them in new ways to turn Magic Firewall into a blazing fast, fully programmable firewall that can stand up to even the most sophisticated of attacks.</p>
    <div>
      <h3>Magical Walls of Fire</h3>
      <a href="#magical-walls-of-fire">
        
      </a>
    </div>
    <p><a href="/introducing-magic-firewall/">Magic Firewall</a> is a distributed stateless packet firewall built on Linux nftables. It runs on every server, in every Cloudflare data center around the world. To provide isolation and flexibility, each customer’s nftables rules are configured within their own Linux network namespace.</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/7IjaJVGQWr5ssJPteOj4DR/2a0a310c33b86840a752386253f555b9/image1-20.png" />
            
            </figure><p>This diagram shows the life of an example packet when using <a href="/magic-transit-network-functions/">Magic Transit</a>, which has Magic Firewall built in. First, packets go into the server and DDoS protections are applied, which drops attacks as early as possible. Next, the packet is routed into a customer-specific network namespace, which applies the nftables rules to the packets. After this, packets are routed back to the origin via a GRE tunnel. Magic Firewall users can construct firewall statements from a <a href="https://developers.cloudflare.com/magic-firewall">single API</a>, using a flexible <a href="https://github.com/cloudflare/wirefilter">Wirefilter syntax</a>. In addition, rules can be configured via the Cloudflare dashboard, using friendly UI drag and drop elements.</p><p>Magic Firewall provides a very powerful syntax for matching on various packet parameters, but it is also limited to the matches provided by nftables. While this is more than sufficient for many use cases, it does not provide enough flexibility to implement the advanced packet parsing and content matching we want. We needed more power.</p>
    <div>
      <h3>Hello eBPF, meet Nftables!</h3>
      <a href="#hello-ebpf-meet-nftables">
        
      </a>
    </div>
    <p>When looking to add more power to your Linux networking needs, Extended Berkeley Packet Filter (<a href="https://ebpf.io/">eBPF</a>) is a natural choice. With eBPF, you can insert packet processing programs that execute <i>in the kernel</i>, giving you the flexibility of familiar programming paradigms with the speed of in-kernel execution. Cloudflare <a href="/tag/ebpf/">loves eBPF</a> and this technology has been transformative in enabling many of our products. Naturally, we wanted to find a way to use eBPF to extend our use of nftables in Magic Firewall. This means being able to match, using an eBPF program within a table and chain as a rule. By doing this we can have our cake and eat it too, by keeping our existing infrastructure and code, and extending it further.</p><p>If nftables could leverage eBPF natively, this story would be much shorter; alas, we had to continue our quest. To get us started in our search, we know that iptables integrates with eBPF. For example, one can use iptables and a pinned eBPF program for dropping packets with the following command:</p>
            <pre><code>iptables -A INPUT -m bpf --object-pinned /sys/fs/bpf/match -j DROP</code></pre>
            <p>This clue helped to put us on the right path. Iptables uses the <a href="https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/net/netfilter/xt_bpf.c#n60">xt_bpf</a> extension to match on an eBPF program. This extension uses the BPF_PROG_TYPE_SOCKET_FILTER eBPF program type, which allows us to load the packet information from the socket buffer and return a value based on our code.</p><p>Since we know iptables can use eBPF, why not just use that? Magic Firewall currently leverages nftables, which is a great choice for our use case due to its flexibility in syntax and programmable interface. Thus, we need to find a way to use the xt_bpf extension with nftables.</p>
            <figure>
            
            <img src="https://cf-assets.www.cloudflare.com/zkvhlag99gkb/4EnxwNmNsjU68l44Mf0M3J/8d5f3b9cfc9f74f1d398c2955925e0c0/image2-13.png" />
            
            </figure><p>This <a href="https://developers.redhat.com/blog/2020/08/18/iptables-the-two-variants-and-their-relationship-with-nftables#using_iptables_nft">diagram</a> helps explain the relationship between iptables, nftables and the kernel. The nftables API can be used by both the iptables and nft userspace programs, and can configure both xtables matches (including xt_bpf) and normal nftables matches.</p><p>This means that given the right API calls (netlink/netfilter messages), we can embed an xt_bpf match within an nftables rule. In order to do this, we need to understand which netfilter messages we need to send. By using tools such as strace, Wireshark, and especially using the <a href="https://github.com/torvalds/linux/blob/master/net/netfilter/xt_bpf.c">source</a> we were able to construct a message that could append an eBPF rule given a table and chain.</p>
            <pre><code>NFTA_RULE_TABLE table
NFTA_RULE_CHAIN chain
NFTA_RULE_EXPRESSIONS | NFTA_MATCH_NAME
	NFTA_LIST_ELEM | NLA_F_NESTED
	NFTA_EXPR_NAME "match"
		NLA_F_NESTED | NFTA_EXPR_DATA
		NFTA_MATCH_NAME "bpf"
		NFTA_MATCH_REV 1
		NFTA_MATCH_INFO ebpf_bytes	</code></pre>
            <p>The structure of the netlink/netfilter message to add an eBPF match should look like the above example. Of course, this message needs to be properly embedded and include a conditional step, such as a verdict, when there is a match. The next step was decoding the format of <code>ebpf_bytes</code> as shown in the example below.</p>
            <pre><code> struct xt_bpf_info_v1 {
	__u16 mode;
	__u16 bpf_program_num_elem;
	__s32 fd;
	union {
		struct sock_filter bpf_program[XT_BPF_MAX_NUM_INSTR];
		char path[XT_BPF_PATH_MAX];
	};
};</code></pre>
            <p>The bytes format can be found in the kernel header definition of <a href="https://git.netfilter.org/iptables/tree/include/linux/netfilter/xt_bpf.h#n27">struct xt_bpf_info_v1</a>. The code example above shows the relevant parts of the structure.</p><p>The xt_bpf module supports both raw bytecodes, as well as a path to a pinned ebpf program. The later mode is the technique we used to combine the ebpf program with nftables.</p><p>With this information we were able to write code that could create netlink messages and properly serialize any relevant data fields. This approach was just the first step, we are also looking into incorporating this into proper tooling instead of sending custom netfilter messages.</p>
    <div>
      <h3>Just Add eBPF</h3>
      <a href="#just-add-ebpf">
        
      </a>
    </div>
    <p>Now we needed to construct an eBPF program and load it into an existing nftables table and chain. Starting to use eBPF can be a bit daunting. Which program type do we want to use? How do we compile and load our eBPF program? We started this process by doing some exploration and research.</p><p>First we constructed an example program to try it out.</p>
            <pre><code>SEC("socket")
int filter(struct __sk_buff *skb) {
  /* get header */
  struct iphdr iph;
  if (bpf_skb_load_bytes(skb, 0, &amp;iph, sizeof(iph))) {
    return BPF_DROP;
  }

  /* read last 5 bytes in payload of udp */
  __u16 pkt_len = bswap_16(iph.tot_len);
  char data[5];
  if (bpf_skb_load_bytes(skb, pkt_len - sizeof(data), &amp;data, sizeof(data))) {
    return BPF_DROP;
  }

  /* only packets with the magic word at the end of the payload are allowed */
  const char SECRET_TOKEN[5] = "xyzzy";
  for (int i = 0; i &lt; sizeof(SECRET_TOKEN); i++) {
    if (SECRET_TOKEN[i] != data[i]) {
      return BPF_DROP;
    }
  }

  return BPF_OK;
}</code></pre>
            <p>The excerpt mentioned is an example of an eBPF program that only accepts packets that have a magic string at the end of the payload. This requires checking the total length of the packet to find where to start the search. For clarity, this example omits error checking and headers.</p><p>Once we had a program, the next step was integrating it into our tooling. We tried a few technologies to load the program, like BCC, libbpf, and we even created a custom loader. Ultimately, we ended up using <a href="https://github.com/cilium/ebpf/">cilium’s ebpf library</a>, since we are using Golang for our control-plane program and the library makes it easy to generate, embed and load eBPF programs.</p>
            <pre><code># nft list ruleset
table ip mfw {
	chain input {
		#match bpf pinned /sys/fs/bpf/mfw/match drop
	}
}</code></pre>
            <p>Once the program is compiled and pinned, we can add matches into nftables using netlink commands. Listing the ruleset shows the match is present. This is incredible! We are now able to deploy custom C programs to provide advanced matching inside a Magic Firewall ruleset!</p>
    <div>
      <h3>More Magic</h3>
      <a href="#more-magic">
        
      </a>
    </div>
    <p>With the addition of eBPF to our toolkit, Magic Firewall is an even more flexible and powerful way to protect your network from bad actors. We are now able to look deeper into packets and implement more complex matching logic than nftables alone could provide. Since our firewall is running as software on all Cloudflare servers, we can quickly iterate and update features.</p><p>One outcome of this project is SIP protection, which is currently in beta. That’s only the beginning. We are currently exploring using eBPF for protocol validations, advanced field matching, looking into payloads, and supporting even larger sets of IP lists.</p><p>We welcome your help here, too! If you have other use cases and ideas, please talk to your account team. If you find this technology interesting, come <a href="https://www.cloudflare.com/careers/">join our team</a>!</p> ]]></content:encoded>
            <category><![CDATA[CIO Week]]></category>
            <category><![CDATA[Magic Firewall]]></category>
            <category><![CDATA[Magic Transit]]></category>
            <category><![CDATA[Security]]></category>
            <category><![CDATA[VoIP]]></category>
            <category><![CDATA[eBPF]]></category>
            <guid isPermaLink="false">1RUM6TLPNlUYMBqyfPL81y</guid>
            <dc:creator>Chris J Arges</dc:creator>
        </item>
    </channel>
</rss>