NetXFW provides a complete RESTful API for managing and controlling firewall rules. The API service runs at http://localhost:11811 by default.
Most API endpoints require authentication. Use Bearer Token for authentication:
Authorization: Bearer <token>
GET /healthz
Response Example:
{
"status": "ok"
}
GET /health
Response Example:
{
"status": "healthy",
"version": "1.0.0",
"uptime": "24h"
}
GET /health/maps
GET /health/map?name=<map_name>
GET /version
Response Example:
{
"version": "1.0.0",
"commit": "abc123",
"build_date": "2024-01-01"
}
GET /api/stats
Response Example:
{
"packets": {
"total": 1234567,
"passed": 1234000,
"dropped": 567
},
"drop_reasons": {
"blacklist": 300,
"rate_limit": 150,
"port_blocked": 117
},
"maps": {
"blacklist_count": 1234,
"whitelist_count": 56,
"conntrack_count": 1500
}
}
GET /api/rules
Response Example:
{
"rules": [
{
"ip": "192.168.1.100",
"port": 80,
"action": "allow"
}
]
}
POST /api/rules
Request Body:
{
"ip": "192.168.1.100",
"port": 80,
"action": "allow"
}
DELETE /api/rules
Request Body:
{
"ip": "192.168.1.100",
"port": 80
}
GET /api/config
PUT /api/config
Request Body:
{
"base": {
"default_deny": true
}
}
GET /api/sync
POST /api/sync
Request Body:
{
"action": "to_map"
}
GET /api/conntrack
Query Parameters:
limit: Maximum number of entries (default: 100)offset: Pagination offsetprotocol: Protocol filter (tcp/udp/icmp)Response Example:
{
"connections": [
{
"src_ip": "192.168.1.100",
"dst_ip": "8.8.8.8",
"src_port": 12345,
"dst_port": 53,
"protocol": "udp",
"last_seen": "2024-01-01T00:00:00Z"
}
],
"total": 1500
}
GET /api/perf
GET /api/perf/latency
GET /api/perf/cache
GET /api/perf/traffic
POST /api/perf/reset
GET /api/v1/metrics
GET /api/v1/metrics/traffic
GET /api/v1/metrics/conntrack
GET /api/v1/metrics/maps
GET /api/v1/metrics/ratelimit
GET /api/v1/metrics/protocols
GET /metrics
The API uses standard HTTP status codes:
| Status Code | Description |
|---|---|
200 OK |
Request successful |
201 Created |
Resource created |
400 Bad Request |
Invalid request format |
401 Unauthorized |
Unauthorized |
404 Not Found |
Resource not found |
500 Internal Server Error |
Internal server error |
Error Response Format:
{
"error": "Invalid IP address format",
"code": "INVALID_IP"
}
curl -X POST http://localhost:11811/api/rules \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_TOKEN" \
-d '{
"ip": "192.168.1.100",
"port": 80,
"action": "allow"
}'
curl -X GET http://localhost:11811/api/stats \
-H "Authorization: Bearer YOUR_TOKEN"
curl -X GET "http://localhost:11811/api/conntrack?limit=50&protocol=tcp" \
-H "Authorization: Bearer YOUR_TOKEN"
curl -X GET http://localhost:11811/healthz
When enable_pprof: true is set in the configuration, the following endpoints are available:
GET /debug/pprof/ # pprof index
GET /debug/pprof/cmdline # Command line
GET /debug/pprof/profile # CPU profile
GET /debug/pprof/symbol # Symbol table
GET /debug/pprof/trace # Execution trace