U32IPFilter¶
The U32IPFilter uses the packet contents to classify a packet.
Matching is done using selector classes.
The following selector classes are available:
IPSubnetSelector: match based onIPsubnetIPPortSelector: match based on portIPProtocolSelector: match based on protocolNumberSelector: match based on packet contents at specified offsetIPHeaderLength: match based onIPheader lengthIPDatagramLimit: match based on datagram sizeTcpAck: match based on presence ofTCPACK
The class U32FilterHandle describes the U32 filter handle.
- class U32IPFilter(*, prio: Optional[int] = None, dest_class_handle: Optional[Handle] = None, filter_handle: Optional[U32FilterHandle] = None, filter_name: Optional[str] = None, selectors: Optional[List[U32Selector]] = None, hit_count=0, success_count=0)[source]¶
This class is used for
U32filters when the ethernet frames carry IP datagrams. It uses an arbitrary number of selectors for matching against the packet fields.- Parameters:
prio – filter priority
dest_class_handle – if there is a match, traffic will be directed to the
QClasswith thisHandlefilter_handle – handle of this filter
filter_name – name for this filter
selectors – list of
U32Selectorobjects specifying the matching criteria
- property hit_count: int¶
Returns hit count
- property success_count: int¶
Returns success count
- get_match_name() Optional[str][source]¶
Returns a string with the name that describes the traffic matched by the filter.
- get_filter_handle() U32FilterHandle[source]¶
Returns the filter handle
- set_filter_handle(filter_handle: U32FilterHandle)[source]¶
Set the filter handle.
Raises
TcErrorif the filter is instantiated.
- has_selector(selector: U32Selector) bool[source]¶
Returns
Trueif a selector matchingselectoris included in this filter (U32Selectorobjects support equality comparisons)
- add_action(action: TrafficAction) None¶
Add a filter action.
Raises
TcErrorif the filter is instantiated.
- get_actions() List[TrafficAction]¶
Returns the action list for this filter
- get_dest_handle() Optional[Handle]¶
Returns the
Handleof theQClasswhere this filter will send traffic
- get_filter_name() Optional[str]¶
Returns the filter name
- get_filter_type() str¶
Returns the filter type
- get_prio() int¶
Returns the filter priority
- is_instantiated() bool¶
Returns
Trueif the filter is in the kernel
- set_dest_handle(handle: Handle)¶
Sets the handle of the class where this filter will send traffic.
Raises
TcErrorif the filter is instantiated.
- set_filter_name(filter_name: str)¶
Set the filter name
- class U32FilterHandle(htid: int, *, bucket: Optional[int] = 0, nodeid: Optional[int] = 0)[source]¶
U32 filter handle.
- Parameters:
htid – hash table id (12-bit integer)
bucket – bucket value (8-bit integer)
nodeid – 12-bit integer
- property htid: int¶
Hash table id
- property bucket: int¶
Bucket value (aka hash value)
- property nodeid: int¶
Nodeid value
- classmethod create_from_string(handle_str: str) U32FilterHandle[source]¶
Create a
U32FilterHandleobject from a string- Parameters:
handle_str – string containing handle with the expected syntax
<num>:[<num>][:<num>]; the number strings are interpreted as hexadecimal numbers
Raises a
ValueErrorifhandle_stris malformed
IPSubnetSelector¶
- class IPSubnetSelector(direction: str, ipv4_network: IPv4Network)[source]¶
A
U32selector that identifies a subnet- Parameters:
direction – should be either
srcordstipv4_network – match against this subnet
- static any_source_ip() IPSubnetSelector[source]¶
Returns an
IPSubnetSelectorthat matches any source IP address
- static any_dest_ip() IPSubnetSelector[source]¶
Returns an
IPSubnetSelectorthat matches any destination IP address
- set_success_count(count: int) None¶
Set the success count
- property success_count: int¶
Returns success count
IPPortSelector¶
- class IPPortSelector(direction: str, port: int)[source]¶
A
U32selector that identifies a TCP/UDP port- Precondition:
The protocol should be TCP or UDP.
- Parameters:
direction – should be either
srcordstport – match against this port number
- tc_creation_args() List[str][source]¶
Returns a list of strings suitable to be used as arguments to the tc(8) command.
- set_success_count(count: int) None¶
Set the success count
- property success_count: int¶
Returns success count
IPProtocolSelector¶
- class IPProtocolSelector(protonum: int)[source]¶
A
U32selector that identifies a protocol by number- Parameters:
protonum – protocol number
- tc_creation_args() List[str][source]¶
Returns a list of strings suitable to be used as arguments to the tc(8) command.
- set_success_count(count: int) None¶
Set the success count
- property success_count: int¶
Returns success count
NumberSelector¶
- class NumberSelector(width: str, number: int, mask: int, offset: int)[source]¶
A
U32selector that matches a number at a specific offset in the packet.- Parameters:
width – one of
u8,u16,u32number – compare packet contents against this number
mask – apply this mask to the number and the packet contents before comparing
offset – offset inside the packet, always in bytes, regardless of width
- tc_creation_args() List[str][source]¶
Returns a list of strings suitable to be used as arguments to the tc(8) command.
- get_name() Optional[str]¶
Returns an (optional) selector name.
- set_success_count(count: int) None¶
Set the success count
- property success_count: int¶
Returns success count
IPHeaderLength¶
- class IPHeaderLength(header_length: int)[source]¶
Bases:
NumberSelectorThis is a convenience
U32selector that matches against a specific IP header length- Parameters:
header_length – compare packet header length against this number;
header_lengthmust be a multiple of 4
- get_mask() int¶
Return the mask
- get_number() int¶
Return the comparison value
- get_offset() int¶
Return the offset
- set_success_count(count: int) None¶
Set the success count
- property success_count: int¶
Returns success count
- tc_creation_args() List[str]¶
Returns a list of strings suitable to be used as arguments to the tc(8) command.
IPDatagramLimit¶
- class IPDatagramLimit(limit: int)[source]¶
Bases:
NumberSelectorThis is a convenience
U32selector that matches if the IP datagram size is less that a specific limit; the limit must be a power of 2.- Parameters:
limit – compare against this limit
- get_mask() int¶
Return the mask
- get_number() int¶
Return the comparison value
- get_offset() int¶
Return the offset
- set_success_count(count: int) None¶
Set the success count
- property success_count: int¶
Returns success count
- tc_creation_args() List[str]¶
Returns a list of strings suitable to be used as arguments to the tc(8) command.
TcpAck¶
- class TcpAck[source]¶
Bases:
NumberSelectorThis is a convenience
U32selector that matches theTCP ACKbit. Preconditions:no IP options
no IP fragmentation
__init__()expects no parameters.- get_mask() int¶
Return the mask
- get_number() int¶
Return the comparison value
- get_offset() int¶
Return the offset
- set_success_count(count: int) None¶
Set the success count
- property success_count: int¶
Returns success count
- tc_creation_args() List[str]¶
Returns a list of strings suitable to be used as arguments to the tc(8) command.