{"id":30249193,"url":"https://github.com/zingerlittlebee/tc","last_synced_at":"2025-08-15T08:39:08.440Z","repository":{"id":303789397,"uuid":"1014780157","full_name":"ZingerLittleBee/tc","owner":"ZingerLittleBee","description":"Traffic Control","archived":false,"fork":false,"pushed_at":"2025-07-10T16:30:12.000Z","size":64,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-14T12:57:47.277Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","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/ZingerLittleBee.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-07-06T12:01:32.000Z","updated_at":"2025-07-06T14:38:49.000Z","dependencies_parsed_at":"2025-07-09T12:51:45.196Z","dependency_job_id":"888c490a-46df-4bc5-ba54-7ab1a51f3204","html_url":"https://github.com/ZingerLittleBee/tc","commit_stats":null,"previous_names":["zingerlittlebee/tc"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ZingerLittleBee/tc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZingerLittleBee%2Ftc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZingerLittleBee%2Ftc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZingerLittleBee%2Ftc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZingerLittleBee%2Ftc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ZingerLittleBee","download_url":"https://codeload.github.com/ZingerLittleBee/tc/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZingerLittleBee%2Ftc/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270546174,"owners_count":24604455,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-15T02:00:12.559Z","response_time":110,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2025-08-15T08:39:04.485Z","updated_at":"2025-08-15T08:39:08.426Z","avatar_url":"https://github.com/ZingerLittleBee.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tc - eBPF-based Network Traffic Monitoring Tool\n\n[中文版本](README_zh.md) | English\n\nA high-performance network traffic monitoring tool built with Rust and eBPF technology, capable of real-time monitoring of network traffic for specified IP addresses at the kernel level.\n\n## 🚀 Features\n\n- **High-Performance Monitoring**: Uses XDP (eXpress Data Path) technology to process network packets at the kernel level\n- **Real-time Traffic Statistics**: Monitors inbound and outbound traffic (packet count and bytes) for specified IP addresses\n- **Flexible Configuration**: Configure monitored IP addresses via environment variables\n- **Detailed Logging**: Provides comprehensive traffic statistics and packet processing logs\n- **Cross-Platform Support**: Supports Linux environments, runs on x86_64 and ARM64 architectures\n\n## 📋 System Requirements\n\n- **Operating System**: Linux (kernel version 5.8+, with XDP support)\n- **Permissions**: Requires root privileges to load eBPF programs\n- **Network Interface**: Network interface that supports XDP\n\n## 🛠️ Prerequisites\n\n### Development Environment\n\n1. **Rust Toolchains**: \n   - Stable version: `rustup toolchain install stable`\n   - Nightly version: `rustup toolchain install nightly --component rust-src`\n\n2. **Cross-compilation Support** (if needed):\n   - Add target architecture: `rustup target add ${ARCH}-unknown-linux-musl`\n   - LLVM toolchain: `brew install llvm` (macOS)\n   - C toolchain: [`brew install filosottile/musl-cross/musl-cross`](https://github.com/FiloSottile/homebrew-musl-cross) (macOS)\n\n3. **eBPF Linker**:\n   ```shell\n   cargo install bpf-linker\n   ```\n   \u003e Note: Use `cargo install bpf-linker --no-default-features` on macOS\n\n## 🏗️ Project Architecture\n\n```\ntc/\n├── tc/           # Main program (userspace)\n│   ├── src/\n│   │   ├── main.rs      # Program entry point\n│   │   ├── target_ip.rs # IP address handling\n│   │   └── utils.rs     # Utility functions\n│   └── Cargo.toml\n├── tc-ebpf/      # eBPF program (kernel space)\n│   ├── src/\n│   │   ├── main.rs      # XDP program implementation\n│   │   └── lib.rs       # Library file\n│   └── Cargo.toml\n├── tc-common/    # Shared data structures\n│   ├── src/\n│   │   ├── lib.rs       # Common data structures\n│   │   └── utils.rs     # Utility functions\n│   └── Cargo.toml\n└── Cargo.toml    # Workspace configuration\n```\n\n## ⚙️ Configuration\n\n### Environment Variables\n\nCreate a `.env` file or set environment variables:\n\n```bash\n# Target IP addresses to monitor, separated by commas\nTARGET_IP=192.168.1.100,10.0.0.1,172.16.1.50\n```\n\n### Network Interface\n\nBy default, monitors the `eth0` interface. You can modify it via command line arguments:\n\n```shell\n# Specify network interface\nsudo ./target/release/tc --iface ens18\n```\n\n## 🚀 Build \u0026 Run\n\n### Development Build\n\n```shell\n# Check code\ncargo check\n\n# Build project\ncargo build --release\n\n# Run program (requires root privileges)\ncargo run --release --config 'target.\"cfg(all())\".runner=\"sudo -E\"'\n```\n\n### Manual Execution\n\n```shell\n# Set environment variables\nexport TARGET_IP=192.168.1.100,10.0.0.1\n\n# Run program\nsudo -E ./target/release/tc --iface eth0\n```\n\n### Cross-compilation (on macOS)\n\nCross compilation works on both Intel and Apple Silicon Macs.\n\n```shell\n# Set target architecture\nexport ARCH=x86_64  # or aarch64\n\n# Cross compile\nCC=${ARCH}-linux-musl-gcc cargo build --package tc --release \\\n  --target=${ARCH}-unknown-linux-musl \\\n  --config=target.${ARCH}-unknown-linux-musl.linker=\\\"${ARCH}-linux-musl-gcc\\\"\n```\n\nThe cross-compiled program `target/${ARCH}-unknown-linux-musl/release/tc` can be copied to a Linux server or VM and run there.\n\n## 📊 Usage Examples\n\n### Basic Usage\n\n```shell\n# 1. Set IP addresses to monitor\nexport TARGET_IP=192.168.1.100\n\n# 2. Run monitoring program\nsudo -E ./target/release/tc --iface eth0\n```\n\n### Output Example\n\n```\n[INFO] XDP program loaded and attached to eth0 interface\n[INFO] Starting traffic monitoring for [192.168.1.100]...\n[INFO] Press Ctrl-C to exit\n\n=== Traffic Statistics for 192.168.1.100 ===\nInbound Traffic:\n  Packets: 1247\n  Bytes: 89432 bytes (87.34 KB)\nOutbound Traffic:\n  Packets: 1156\n  Bytes: 156789 bytes (153.11 KB)\nTotal:\n  Packets: 2403\n  Bytes: 246221 bytes (240.45 KB)\n================================\n```\n\n### Monitor Multiple IPs\n\n```shell\n# Monitor multiple IP addresses\nexport TARGET_IP=192.168.1.100,10.0.0.1,172.16.1.50\nsudo -E ./target/release/tc --iface eth0\n```\n\n## 🔧 Technical Details\n\n### eBPF Program\n\n- **Program Type**: XDP (eXpress Data Path)\n- **Packet Processing**: Processes packets at the network driver level\n- **Performance Advantage**: Avoids the overhead of the kernel network stack\n\n### Data Structures\n\n```rust\n// Traffic statistics structure\npub struct TrafficStats {\n    pub inbound_packets: u64,   // Number of inbound packets\n    pub inbound_bytes: u64,     // Inbound bytes\n    pub outbound_packets: u64,  // Number of outbound packets\n    pub outbound_bytes: u64,    // Outbound bytes\n}\n```\n\n### eBPF Maps\n\n- `TARGET_IP`: Stores IP addresses to monitor\n- `TRAFFIC_STATS`: Stores traffic statistics for each IP\n\n## 🐛 Troubleshooting\n\n### Common Issues\n\n1. **Permission Error**: Ensure running with root privileges\n2. **Network Interface Not Supported**: Confirm the network interface supports XDP\n3. **Kernel Version**: Ensure Linux kernel version \u003e= 5.8\n\n### Debug Mode\n\n```shell\n# Enable verbose logging\nRUST_LOG=debug sudo -E ./target/release/tc --iface eth0\n```\n\n### XDP Mode Switching\n\nIf the default XDP mode doesn't work, try modifying the XDP flags in the code:\n\n```rust\n// Change XdpFlags::default() to XdpFlags::SKB_MODE\nprogram.attach(\u0026opt.iface, XdpFlags::SKB_MODE)\n```\n\n## 🤝 Contributing\n\nContributions are welcome! Please follow these steps:\n\n1. Fork the project\n2. Create a feature branch (`git checkout -b feature/amazing-feature`)\n3. Commit your changes (`git commit -m 'Add amazing feature'`)\n4. Push to the branch (`git push origin feature/amazing-feature`)\n5. Create a Pull Request\n\n## 📄 License\n\nWith the exception of eBPF code, tc is distributed under the terms of either the [MIT license](LICENSE-MIT) or the [Apache License](LICENSE-APACHE) (version 2.0), at your option.\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.\n\n### eBPF\n\nAll eBPF code is distributed under either the terms of the [GNU General Public License, Version 2](LICENSE-GPL2) or the [MIT license](LICENSE-MIT), at your option.\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the GPL-2 license, shall be dual licensed as above, without any additional terms or conditions.\n\n---\n\n## 🙏 Acknowledgments\n\nThis project is built on the [Aya](https://github.com/aya-rs/aya) framework. Thanks to the Aya team for providing excellent eBPF development tools. ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzingerlittlebee%2Ftc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzingerlittlebee%2Ftc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzingerlittlebee%2Ftc/lists"}