{"id":25593946,"url":"https://github.com/packet-batch/tech-afxdp","last_synced_at":"2026-02-16T04:01:46.357Z","repository":{"id":278594179,"uuid":"934766861","full_name":"Packet-Batch/tech-afxdp","owner":"Packet-Batch","description":"A small C API that interacts with AF_XDP sockets. Will be used with upcoming Packet Batch revamp and a work-in-progress!","archived":false,"fork":false,"pushed_at":"2025-03-13T21:36:33.000Z","size":14,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-12T23:44:00.577Z","etag":null,"topics":["af-xdp","afxdp","api","bpf","c","ebpf","makefile","shared","shared-library","small","xdp"],"latest_commit_sha":null,"homepage":"https://deaconn.net/","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Packet-Batch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-02-18T11:21:09.000Z","updated_at":"2025-03-13T21:36:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"c03bfe11-f680-43b5-9b8e-dd172899f044","html_url":"https://github.com/Packet-Batch/tech-afxdp","commit_stats":null,"previous_names":["packet-batch/tech-afxdp"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Packet-Batch/tech-afxdp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Packet-Batch%2Ftech-afxdp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Packet-Batch%2Ftech-afxdp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Packet-Batch%2Ftech-afxdp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Packet-Batch%2Ftech-afxdp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Packet-Batch","download_url":"https://codeload.github.com/Packet-Batch/tech-afxdp/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Packet-Batch%2Ftech-afxdp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29499803,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-16T03:57:51.541Z","status":"ssl_error","status_checked_at":"2026-02-16T03:55:59.854Z","response_time":115,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["af-xdp","afxdp","api","bpf","c","ebpf","makefile","shared","shared-library","small","xdp"],"created_at":"2025-02-21T10:22:27.415Z","updated_at":"2026-02-16T04:01:46.343Z","avatar_url":"https://github.com/Packet-Batch.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"A small C API for interacting with [AF_XDP sockets](https://docs.kernel.org/networking/af_xdp.html) on Linux which includes setting up sockets, sending packets on sockets, and cleaning up sockets. While this may be used separately, this was primarily made for an upcoming revamp for [Packet Batch](https://github.com/Packet-Batch).\n\n**NOTE** - This is experimental and a **work-in-progress**!\n\n## How It Works\nWhen building, a shared library (`libpbafxdp.so`) is created which is then installed to the `/usr/lib` directory.\n\nThere is also an [`api.h`](./include/api.h) header file that may be installed to `/usr/include/pb/afxdp/api.h` which should be included by programs that want to utilize this small API.\n\nIf you want to interact with the API, you'll want to make sure `/usr/include` is included when building your C source code (via `-I /usr/include`) and you'll want to also pass the linker flags `-lxdp -lbpf -lpbafxdp`. Afterwards, you can do something like the following.\n\n```C\n#include \u003cpb/afxdp/api.h\u003e\n\n#include \u003clinux/bpf.h\u003e\n#include \u003cxdp/xsk.h\u003e\n\n#define INTERFACE \"eth0\"\n\nint main() {\n    int ret;\n\n    if ((ret = Setup(INTERFACE, 0, 0, 0, 0, 0, 1)) != 0) {\n        fprintf(stderr, \"[ERR] Failed to setup AF_XDP socket on %s: %d\\n\", INTERFACE, ret);\n\n        return ret;\n    }\n\n    printf(\"Sockets setup successfully!\\n\");\n\n    if ((ret = Cleanup(1)) != 0) {\n        fprintf(stderr, \"[ERR] Failed to cleanup AF_XDP socket on %s: %d\\n\", INTERFACE, ret);\n\n        return ret;\n    }\n\n    printf(\"Sockets cleaned up successfully!\\n\");\n\n    return 0;\n}\n```\n\nTake a look at test programs from the [`tests/`](./tests/) directory for more information.\n\n## Building \u0026 Installing\nBefore building this project, make sure to build and install [`xdp-tools`](https://github.com/xdp-project/xdp-tools) onto your server's system. When creating programs using this API, you will need to link `xdp-tools` via the `-lxdp -lbpf` linker flags.\n\nAfterwards, use `make` to build the shared library and `make install` (as root or via `sudo`) to install the shared library and API header file onto your system.\n\n```bash\n# Clone repository (include sub-modules).\ngit clone --recursive https://github.com/Packet-Batch/tech-afxdp.git\n\n# Change to repository.\ncd tech-afxdp/\n\n# Build shared library.\nmake\n\n# Install shared library and API header.\nsudo make install\n```\n\n## API Usage\nThe following functions are exposed by the API.\n\n```C\n/**\n * Sets up AF_XDP sockets.\n * \n * @param dev The interface to bind the AF_XDP sockets to.\n * @param queueId The TX queue ID to use.\n * @param needWakeup If 1, sets the need wakeup flag on the sockets.\n * @param sharedUmem If 1, uses a shared umem allocated between all sockets.\n * @param forceSkb If 1, forces SKB mode (slower, but useful for debugging).\n * @param zeroCopy If 1, will set the zero-copy flag.\n * @param threads The amount of sockets and threads to create.\n * \n * @return 0 on success or other value on error.\n */\nextern int Setup(const char *dev, int queueId, int needWakeup, int sharedUmem, int forceSkb, int zeroCopy, int threads);\n\n/**\n * Cleans up AF_XDP sockets.\n * \n * @param threads The amount of sockets and threads that were created in Setup().\n * \n * @return 0 on success or other value on error.\n */\nextern int Cleanup(int threads);\n\n/**\n * Sends a packet on an AF_XDP socket (at index).\n * \n * @param pkt The packet buffer.\n * @param length The packet's full length (includes ethernet header, layer 3/4 headers, and payload).\n * @param threadIdx The socket index to send on.\n * @param batchSize The batch size.\n * \n * @return 0 on success or other value on error.\n */\nextern int SendPacket(void *pkt, int length, int threadIdx, int batchSize);\n```\n\nTake a look at test programs from the [`tests/`](./tests/) directory for more information.\n\n## Tests\n* [`tcp_syn_test.c`](./tests/tcp_syn_test.c) - Sends a single TCP SYN packet on an AF_XDP socket (no checksum calculated).\n\n## Notes\n### Do I Need To Set The `LD_LIBRARY_PATH` Environmental Variable?\nYou should **not** need to set your `LD_LIBRARY_PATH` environmental variable if you installed the shared library to `/usr/lib` since that directory is usually included when searching for linked libraries by default.\n\nIf you have issues, you could try setting it specifically via `export LD_LIBRARY_PATH=/usr/lib`.\n\n## Credits\n* [Christian Deacon](https://github.com/gamemann)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpacket-batch%2Ftech-afxdp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpacket-batch%2Ftech-afxdp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpacket-batch%2Ftech-afxdp/lists"}