mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Add packet filter parameter validation to prevent ubridge errors
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
This commit is contained in:
3 files changed
+363
No files matched your search
@@ -23,6 +23,7 @@ import html
|
||||
from .controller_error import ControllerError, ControllerNotFoundError
|
||||
from gns3server.agent.web_wireshark.manager import WebWiresharkManager
|
||||
from gns3server.config import Config
|
||||
from gns3server.utils.packet_filter_validation import validate_all_filters, FilterValidationError
|
||||
|
||||
import logging
|
||||
|
||||
@@ -161,6 +162,12 @@ class Link:
|
||||
if len(values) != 0 and values[0] != 0 and values[0] != "":
|
||||
new_filters[filter] = values
|
||||
|
||||
# Validate filter parameters before applying
|
||||
try:
|
||||
validate_all_filters(new_filters)
|
||||
except FilterValidationError as e:
|
||||
raise ControllerError(f"Invalid packet filter parameters: {str(e)}")
|
||||
|
||||
if new_filters != self.filters:
|
||||
self._filters = new_filters
|
||||
if self._created:
|
||||
|
||||
Reference in new issue
Block a user