mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-08-27 20:40:13 +03:00
This commit implements comprehensive parameter validation for GNS3 packet
filters at the API layer, preventing invalid parameters from reaching
ubridge and causing technical errors.
## Changes
### New Features
- **Add packet filter validation module** (`gns3server/utils/packet_filter_validation.py`)
- Validate parameter ranges for all filter types:
- frequency_drop: -1 to 32767
- packet_loss: 0 to 100%
- delay: 0 to 32767ms (latency + jitter)
- corrupt: 0 to 100%
- **BPF syntax validation** using tshark (method from gns3_copilot)
- Parameter count and type validation
- User-friendly error messages with parameter details
### Integration
- **Integrate validation into Link.update_filters()** (`gns3server/controller/link.py`)
- Validate parameters before applying filters
- Raise ControllerError with clear error messages for invalid input
- Prevent invalid parameters from reaching ubridge
### Testing
- **Add comprehensive test suite** (`tests/utils/test_packet_filter_validation.py`)
- 15 test cases covering all validation scenarios
- Tests for valid/invalid parameters, edge cases, and BPF syntax
- All tests passing
## Benefits
- **Better UX**: Clear, actionable error messages instead of ubridge technical errors
- **Prevents crashes**: Validate parameters at API layer before reaching ubridge
- **Consistent validation**: Centralized validation logic for all filter types
- **BPF safety**: Syntax validation using tshark prevents invalid BPF expressions