LimitMatch¶
Example:
>>> from linuxnet.iptables import LimitMatch
>>> m = LimitMatch()
>>> m.limit().equals(LimitMatch.Rate(1)).burst().equals(10)
<linuxnet.iptables.matches.limitmatch.LimitMatch object at 0x7f4191c70208>
>>> m.to_iptables_args()
['-m', 'limit', '--limit', '1/sec', '--limit-burst', '10']
>>> m = LimitMatch()
>>> Rate = LimitMatch.Rate
>>> m.limit().equals(Rate(3, Rate.PER_MINUTE))
<linuxnet.iptables.matches.limitmatch.LimitMatch object at 0x7f4191c704e0>
>>> m.to_iptables_args()
['-m', 'limit', '--limit', '3/min']
- class LimitMatch[source]¶
Match against a rate limit with a maximum burst
- class Rate(rate: int, interval: Optional[str] = None)¶
Used to express rates
- Parameters:
rate – (integer) rate value
interval – optional (string) time interval (defaults to PER_SEC)
Possible interval values are:
- PER_DAY = 'day'¶
day interval
- PER_HOUR = 'hour'¶
hour interval
- PER_MIN = 'min'¶
minute interval
- PER_MINUTE = 'minute'¶
minute interval (normalized to ‘min’)
- PER_SEC = 'sec'¶
second interval
- PER_SECOND = 'second'¶
second interval (normalized to ‘sec’)
- get_interval() str¶
Returns the rate interval
- get_rate() int¶
Returns the rate value
- get_criteria() Iterable[Criterion][source]¶
Returns the limit match criteria: rate-limit, burst Note that the burst criterion will be
Noneif the rate-limit criterion has not been set.
- limit() RateLimitCriterion[source]¶
Compare with the rate limit
- burst() BurstCriterion[source]¶
Compare with the burst limit
RateLimitCriterion¶
- class RateLimitCriterion(match: Match)[source]¶
Compare with a rate limit
The comparison value is a
LimitMatch.Rateobject- not_equals(*args, **kwargs)[source]¶
This
Criterionmethod is not supported because the limit match does not support ‘!’
- any() Match¶
Match any value.
This method is used when creating a
Criterionin order to search an existing chain for rules that try to match against certain packet properties (e.g. input interface) without being particular about the specific property value (e.g.eth0).
- compare(is_equal: bool, *args, **kwargs) Match¶
Alternative method used for comparisons. It invokes
equals()(ornot_equals()) withargsandkwargsifis_equalisTrue(orFalse).
- is_positive() bool¶
Returns the ‘polarity’ of the criterion:
Trueforequals()orFalsefornot_equals()Raises
IptablesErrorif the criterion is not set
- is_set() bool¶
Returns
Trueif the criterion has been set
BurstCriterion¶
- class BurstCriterion(match: Match)[source]¶
Compare with the burst limit
The comparison value is an integer
- not_equals(*args, **kwargs)[source]¶
This
Criterionmethod is not supported because the limit match does not support ‘!’
- any() Match¶
Match any value.
This method is used when creating a
Criterionin order to search an existing chain for rules that try to match against certain packet properties (e.g. input interface) without being particular about the specific property value (e.g.eth0).
- compare(is_equal: bool, *args, **kwargs) Match¶
Alternative method used for comparisons. It invokes
equals()(ornot_equals()) withargsandkwargsifis_equalisTrue(orFalse).
- get_iptables_option() str¶
Returns the iptables(8) option
- get_value() Any¶
Returns the criterion value
- is_positive() bool¶
Returns the ‘polarity’ of the criterion:
Trueforequals()orFalsefornot_equals()Raises
IptablesErrorif the criterion is not set
- is_set() bool¶
Returns
Trueif the criterion has been set