Smart Home firewall
Profile-based Smart Home firewall
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
protocols.Protocol.Protocol Class Reference
Inheritance diagram for protocols.Protocol.Protocol:
Inheritance graph
[legend]

Public Member Functions

None __init__ (self, dict protocol_data, dict device)
 
Protocol init_protocol (c, str protocol_name, dict protocol_data, dict device)
 
str format_list (self, list l, func=lambda x:x)
 
None add_field (self, str field, dict template_rules, bool is_backward=False, func=lambda x:x, backward_func=lambda x:x)
 
dict parse (self, bool is_backward=False, str initiator="src")
 

Static Public Member Functions

Union[str, int] convert_value (str value)
 

Public Attributes

 protocol_data
 
 device
 
 rules
 

Detailed Description

Generic protocol, inherited by all concrete protocols.

Constructor & Destructor Documentation

◆ __init__()

None protocols.Protocol.Protocol.__init__ (   self,
dict  protocol_data,
dict  device 
)
Generic protocol constructor.

:param protocol_data: Dictionary containing the protocol data.
:param device: Dictionary containing the device metadata.

Member Function Documentation

◆ add_field()

None protocols.Protocol.Protocol.add_field (   self,
str  field,
dict  template_rules,
bool   is_backward = False,
  func = lambda x: x,
  backward_func = lambda x: x 
)
Add a new nftables rule to the nftables rules accumulator.

:param field: Field to add the rule for.
:param template_rules: Dictionary containing the protocol-specific rules to add.
:param is_backward (optional): Whether the field to add is for a backward rule.
                               Optional, default is `False`.
:param func (optional): Function to apply to the field value before writing it.
                        Optional, default is the identity function.
:param backward_func (optional): a to apply to the field value in the case of a backwards rule.
                                 Will be applied after the forward function.
                                 Optional, default is the identity function.
Args:
    field (str): Field to add the rule for.
    rules (dict): Dictionary containing the protocol-specific rules to add.
    is_backward (bool): Whether the field to add is for a backward rule.
                        Optional, default is `False`.
    func (lambda): Function to apply to the field value before writing it.
                   Optional, default is the identity function.
    backward_func (lambda): a to apply to the field value in the case of a backwards rule.
                   Will be applied after the forward function.
                   Optional, default is the identity function.

Reimplemented in protocols.Custom.Custom.

◆ convert_value()

Union[str, int] protocols.Protocol.Protocol.convert_value ( str  value)
static
Convert a string value to an int if possible.

:param value: Value to convert.
:return: Converted value as int if possible, or the original string value otherwise.

◆ format_list()

str protocols.Protocol.Protocol.format_list (   self,
list  l,
  func = lambda x: x 
)
Format a list of values.

:param l: List of values.
:param func: Function to apply to each value.
             Optional, default is the identity function.
:return: Formatted list.

◆ init_protocol()

Protocol protocols.Protocol.Protocol.init_protocol (   c,
str  protocol_name,
dict  protocol_data,
dict  device 
)
Factory method for a specific protocol.

:param protocol_name: Name of the protocol.
:param protocol_data: Dictionary containing the protocol data.
:param device: Dictionary containing the device metadata.

◆ parse()

dict protocols.Protocol.Protocol.parse (   self,
bool   is_backward = False,
str   initiator = "src" 
)
Default parsing method.
Must be updated in the children class.

:param is_backward (optional): Whether the protocol must be parsed for a backward rule.
                               Optional, default is `False`.
:param initiator (optional): Connection initiator (src or dst).
                            Optional, default is "src".
:return: Dictionary containing the (forward and backward) nftables and nfqueue rules for this policy.

Reimplemented in protocols.ssdp.ssdp, protocols.igmp.igmp, protocols.icmpv6.icmpv6, protocols.icmp.icmp, protocols.http.http, protocols.dns.dns, protocols.dhcp.dhcp, protocols.coap.coap, protocols.arp.arp, protocols.Transport.Transport, and protocols.ip.ip.


The documentation for this class was generated from the following file: