Programmable Flow Protection (Beta)·续3
netshort— The 16-bit value in network byte order.
Returns: The value in host byte order.
htons
Converts a 16-bit integer from host byte order to network byte order.
uint16_t htons(uint16_t hostshort);
Arguments:
hostshort— The 16-bit value in host byte order.
Returns: The value in network byte order.
ntohl
Converts a 32-bit integer from network byte order to host byte order.
uint32_t ntohl(uint32_t netlong);
Arguments:
netlong— The 32-bit value in network byte order.
Returns: The value in host byte order.
htonl
Converts a 32-bit integer from host byte order to network byte order.
uint32_t htonl(uint32_t hostlong);
Arguments:
hostlong— The 32-bit value in host byte order.
Returns: The value in network byte order.
ntohll
Converts a 64-bit integer from network byte order to host byte order.
uint64_t ntohll(uint64_t netlonglong);
Arguments:
netlonglong— The 64-bit value in network byte order.
Returns: The value in host byte order.
htonll
Converts a 64-bit integer from host byte order to network byte order.
uint64_t htonll(uint64_t hostlonglong);
Arguments:
hostlonglong— The 64-bit value in host byte order.
Returns: The value in network byte order.
Structures
cf_ebpf_generic_ctx
The generic context structure passed into the BPF program.
struct cf_ebpf_generic_ctx {
/* Pointer to the beginning of the context data. */
uint64_t data;
/* Pointer to the end of the context data. */
uint64_t data_end;
/* Space for the program to store metadata. */
uint64_t meta_data;
};
cf_ebpf_packet_data
Contains the raw packet data passed into the BPF program.
struct cf_ebpf_packet_data {
/* Total length of the packet. */
size_t total_packet_length;
/* Size of the IP header. Supports IPv4 (including options) and IPv6. */
size_t ip_header_length;
/* Bytes of the packet, starting with the IP header. */
uint8_t packet_buffer[1500];
};
cf_ebpf_parsed_headers
Contains pointers to parsed IP and UDP headers. Populated by calling parse_packet_data.
struct cf_ebpf_parsed_headers {
/* Pointer to the parsed IPv4 header, if present (otherwise null). */
struct iphdr *ipv4;
/* Pointer to the parsed IPv6 header, if present (otherwise null). */
struct ipv6hdr *ipv6;
/* Pointer to the parsed UDP header. */
struct udphdr *udp;
/* Raw pointer to the last valid byte of the packet context data. */
uint8_t *data_end;
};
iphdr
IPv4 header structure. Source: Linux kernel ↗︎.
struct iphdr {
#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
uint8_t version:4,
ihl:4;
#else
uint8_t ihl:4,
version:4;
#endif
uint8_t tos;
uint16_t tot_len;
uint16_t id;
uint16_t frag_off;
uint8_t ttl;
uint8_t protocol;
uint16_t check;
uint32_t saddr;
uint32_t daddr;
};
ipv6hdr
IPv6 header structure. Source: Linux kernel ↗︎.
struct ipv6hdr {
#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
uint8_t version:4,
priority:4;
#else
uint8_t priority:4,
version:4;
#endif
uint8_t flow_lbl[3];
uint16_t payload_len;
uint8_t nexthdr;
uint8_t hop_limit;
uint8_t saddr[16];
uint8_t daddr[16];
};
udphdr
UDP header structure. Source: Linux kernel ↗︎.
struct udphdr {
uint16_t source;
uint16_t dest;
uint16_t len;
uint16_t check;
};
Program endpoints
Upload a program
To upload a program, navigate to Networking > L3/4 DDoS protection > Advanced Protection in the Cloudflare dashboard. Then select the tab titled Programmable Flow Protection.
Under Programs, click the button "Upload new program." This will prompt you to select a file to upload with your C source code.
The Cloudflare API will receive the source code in the C file, compile it into BPF bytecode, and run the verifier against it.
If compilation or verification fails, the API will return a detailed error message.
If compilation and verification succeeds, Cloudflare will store the source code and object file to the account and return the program ID.
Update a program
During the development process, you may find it useful to update the same program (identified by the same program ID) instead of repeatedly creating new programs as new resources.
To update the program, select the three dots next to your program. Then, select Overwrite. This will prompt you to choose a file to upload as your C source code.
Each update creates a new program version. The response's version field identifies the current version.
Rules remain pinned to their existing program_version when you update a program. To use the updated program, update each rule with the new program_version through the API.
Note
It is possible to update a program that is currently in use by one or more rules. When doing so, you will be warned that the program is currently active. Existing rules continue to use their pinned program version. If the updated program does not compile or cannot be verified, existing rules continue to use the previous successful version.
View all programs
To view all uploaded programs and their success statuses, view the table under the section entitled Programs.
A link icon next to the program name indicates that the program is currently in use in an active rule and may not be deleted.
Delete a program
To delete a program, select the three dots next to the program that you wish to delete. Then, select Delete.
Note that you will not be able to delete a program that is referenced in an active Rule.
Note that programs that have a "failed" status (meaning they failed to compile or pass verification) will be automatically and permanently deleted after 30 days of inactivity.
Rules
Only one rule executes per packet. If your account has multiple rules configured, the rule with the most specific scope executes. For example, a rule scoped to a specific colo takes precedence over a rule scoped to a region, which takes precedence over a global rule. This is why you cannot create more than one global rule.
List all rules
To view rules and their associated rule IDs, go to Networking > L3/4 DDoS protection > Advanced Protection in the Cloudflare dashboard. Then, select Programmable Flow Protection.
Create a rule
To create a rule, go to Networking > L3/4 DDoS protection > Advanced Protection in the Cloudflare dashboard. Then, select Programmable Flow Protection.
Under Rules, select Create rule. Fill out the corresponding fields of your new rule. You will be prompted to select a program, mode, and scope for the rule.
Update a rule
To update an existing rule, navigate to the Rules section. Click the three dots next to the rule and select Edit.
You will be prompted to edit the mode and scope of the rule. You may not edit the program of the rule because that is an unsafe rollout pattern.
Delete a rule
To delete an existing rule, navigate to the Rules section. Click the three dots next to the rule and select Delete.
Debug Packet CAPture (PCAP)
This API endpoint debugs a program by intaking:
- A local path to the input PCAP file provided as requested data in binary format. The input PCAP file has a maximum size limit of 5 MB and will be rejected if it is too large.
- The program ID provided in the request path.
- An optional query parameter
ip_offset=<value>to specify IP offset. This is the number of bytes that the IP header is offset by in each packet of the input PCAP file. If the ip offset query parameter is omitted, the API will make an educated guess on the correct offset value. For example, if the PCAP file captures Ethernet packets, the detected IP offset value would be 14. This endpoint assumes that all packets in a PCAP have the same IP offset value and will otherwise parse packets incorrectly.
This endpoint runs the referenced BPF program against the input PCAP and outputs a new annotated PCAP file. The output PCAP file will contain the exact same packets as the input PCAP file, and will also include the program verdict annotated in the Packet Comment section of each packet.
Requestbash
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/magic/programmable_flow_protection/configs/programs/$PROGRAM_ID/pcap" \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--header "Content-Type: application/vnd.tcpdump.pcap" \
--data-binary "@<PATH_TO_INPUT_PCAP_FILE>" \
--output output.pcap
The Packet Comment annotation may contain:
- Program return value:
CF_EBPF_PASSorCF_EBPF_DROP Ignored: if the incoming packet is not UDPAnalytics tag: the custom network analytics tag set by the program on this packet, if any
The output PCAP file may also contain:
Challenge packet: a challenge packet emitted from the program back to the client, if any
Safe program and rule deployment best practices
You will want to safely deploy and test programs without impacting existing production traffic. An initial deployment approach could be to set a global scoped rule to disabled and set a colo or region level scoped rule to monitoring with a filter expression only acting on some subset of IP traffic.
Each Cloudflare region or colo will apply the most granular rule. So, in the scenario described above, the colos or regions specified in the monitoring rule will execute the developer program in monitoring mode, while every other Cloudflare location will not execute the program at all. The monitoring rule would only execute on traffic that matches the filter expression.
Then, after verifying the correct behavior with Network Analytics, you can update and expand the monitoring rule's scope and filter expression. Eventually, you can delete the disabled and monitoring rules and apply a global enabled rule.
Using the Expression field to limit programs to a subset of IPs or prefixes and the Mode field to dictate whether a program actually drops packets ensures a program's safety and granularity upon rollout.
Network Analytics
Traffic flowing through Programmable Flow Protection can be found in the Network Analytics dashboard.
In the Network Analytics dashboard, select the Programmable Flow Protection tab to filter traffic based on this feature. You can filter traffic by program ID, custom network analytics tags, actions, IPs, and ports. By default, packets are sampled at a rate of 1/10,000.
Was this helpful?
YesNo
On this page
{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/ddos-protection/advanced-ddos-systems/overview/programmable-flow-protection/#page","headline":"Programmable Flow Protection (Beta)","description":"Create custom flow-based rules to detect and mitigate volumetric DDoS attacks.","url":"https://developers.cloudflare.com/ddos-protection/advanced-ddos-systems/overview/programmable-flow-protection/","inLanguage":"en","image":"https://developers.cloudflare.com/ddos-protection/advanced-ddos-systems/overview/programmable-flow-protection/og.png?v=507a10264f2d42b8","dateModified":"2026-10-21","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"},"keywords":["UDP"]}
description: Troubleshoot common issues with Advanced TCP Protection, including mode transitions, false positives, allowlist behavior, and false negatives. title: Troubleshooting Advanced TCP Protection image: https://developers.cloudflare.com/ddos-protection/advanced-ddos-systems/troubleshooting/og.png?v=f87ee69fb47bd442
Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/ddos-protection/llms.txt
Use this file to discover all available pages before exploring further.
Docs