Module: Mt::Wall::Model

Defined in:
lib/mt/wall/model/rule.rb,
lib/mt/wall/model/group.rb,
lib/mt/wall/model/device.rb,
lib/mt/wall/model/policy.rb,
lib/mt/wall/model/service.rb,
lib/mt/wall/model/nat_rule.rb,
lib/mt/wall/model/filter_rule.rb,
lib/mt/wall/model/address_object.rb

Defined Under Namespace

Classes: AddressObject, Device, FilterRule, Group, NatRule, Policy, Rule, Service

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#addressesObject (readonly)

IPv4/IPv6 addresses, CIDR subnets or IP ranges



28
29
30
31
32
# File 'lib/mt/wall/model/address_object.rb', line 28

AddressObject = Data.define(:name, :addresses, :comment) do
  def initialize(name:, addresses: [], comment: nil)
    super(name: name, addresses: Array(addresses), comment: comment)
  end
end

#commentObject (readonly)

optional human-readable note



42
43
44
45
46
47
# File 'lib/mt/wall/model/rule.rb', line 42

Rule = Data.define(:source, :destination, :service, :action, :comment, :log, :log_prefix, :disabled) do
  def initialize(source:, destination:, action:, service: nil, comment: nil,
                 log: false, log_prefix: nil, disabled: false)
    super
  end
end

#destinationObject (readonly)

name of the destination object/group



42
43
44
45
46
47
# File 'lib/mt/wall/model/rule.rb', line 42

Rule = Data.define(:source, :destination, :service, :action, :comment, :log, :log_prefix, :disabled) do
  def initialize(source:, destination:, action:, service: nil, comment: nil,
                 log: false, log_prefix: nil, disabled: false)
    super
  end
end

#filter_rulesObject (readonly)

the box’s own input/output/forward rules



43
44
45
46
47
48
49
50
51
# File 'lib/mt/wall/model/device.rb', line 43

Device = Data.define(:name, :host, :transport, :policies, :filter_rules, :nat_rules,
                     :management, :options) do
  def initialize(name:, host:, transport: :rest_api, policies: [], filter_rules: [],
                 nat_rules: [], management: [], options: {})
    super(name: name, host: host, transport: transport,
          policies: Array(policies), filter_rules: Array(filter_rules),
          nat_rules: Array(nat_rules), management: Array(management), options: options)
  end
end

#hostObject (readonly)

hostname / IP of the router



43
44
45
46
47
48
49
50
51
# File 'lib/mt/wall/model/device.rb', line 43

Device = Data.define(:name, :host, :transport, :policies, :filter_rules, :nat_rules,
                     :management, :options) do
  def initialize(name:, host:, transport: :rest_api, policies: [], filter_rules: [],
                 nat_rules: [], management: [], options: {})
    super(name: name, host: host, transport: transport,
          policies: Array(policies), filter_rules: Array(filter_rules),
          nat_rules: Array(nat_rules), management: Array(management), options: options)
  end
end

#log_prefixObject (readonly)

optional log-prefix label



42
43
44
45
46
47
# File 'lib/mt/wall/model/rule.rb', line 42

Rule = Data.define(:source, :destination, :service, :action, :comment, :log, :log_prefix, :disabled) do
  def initialize(source:, destination:, action:, service: nil, comment: nil,
                 log: false, log_prefix: nil, disabled: false)
    super
  end
end

#managementObject (readonly)

explicit mgmt-protect specs { src:, service:, port: }



43
44
45
46
47
48
49
50
51
# File 'lib/mt/wall/model/device.rb', line 43

Device = Data.define(:name, :host, :transport, :policies, :filter_rules, :nat_rules,
                     :management, :options) do
  def initialize(name:, host:, transport: :rest_api, policies: [], filter_rules: [],
                 nat_rules: [], management: [], options: {})
    super(name: name, host: host, transport: transport,
          policies: Array(policies), filter_rules: Array(filter_rules),
          nat_rules: Array(nat_rules), management: Array(management), options: options)
  end
end

#membersObject (readonly)

names of objects and/or groups



20
21
22
23
24
# File 'lib/mt/wall/model/group.rb', line 20

Group = Data.define(:name, :members, :comment) do # rubocop:disable Lint/DataDefineOverride
  def initialize(name:, members: [], comment: nil)
    super(name: name, members: Array(members), comment: comment)
  end
end

#nameObject (readonly)

unique object name / address-list name



20
21
22
23
24
# File 'lib/mt/wall/model/group.rb', line 20

Group = Data.define(:name, :members, :comment) do # rubocop:disable Lint/DataDefineOverride
  def initialize(name:, members: [], comment: nil)
    super(name: name, members: Array(members), comment: comment)
  end
end

#nat_rulesObject (readonly)

the box’s own srcnat/dstnat rules (IPv4-only, v1)



43
44
45
46
47
48
49
50
51
# File 'lib/mt/wall/model/device.rb', line 43

Device = Data.define(:name, :host, :transport, :policies, :filter_rules, :nat_rules,
                     :management, :options) do
  def initialize(name:, host:, transport: :rest_api, policies: [], filter_rules: [],
                 nat_rules: [], management: [], options: {})
    super(name: name, host: host, transport: transport,
          policies: Array(policies), filter_rules: Array(filter_rules),
          nat_rules: Array(nat_rules), management: Array(management), options: options)
  end
end

#policiesObject (readonly)

per-device chain-default overrides



43
44
45
46
47
48
49
50
51
# File 'lib/mt/wall/model/device.rb', line 43

Device = Data.define(:name, :host, :transport, :policies, :filter_rules, :nat_rules,
                     :management, :options) do
  def initialize(name:, host:, transport: :rest_api, policies: [], filter_rules: [],
                 nat_rules: [], management: [], options: {})
    super(name: name, host: host, transport: transport,
          policies: Array(policies), filter_rules: Array(filter_rules),
          nat_rules: Array(nat_rules), management: Array(management), options: options)
  end
end

#portsObject (readonly)

destination ports / ranges (empty = portless)



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/mt/wall/model/service.rb', line 25

Service = Data.define(:name, :protocols, :ports) do
  def initialize(name:, protocol: nil, protocols: nil, ports: [])
    list = protocols || protocol
    # A Range is a single port-spec value — wrap it so Array() does not
    # explode it into discrete integers (we want `dst-port=8000-8100`).
    port_list = ports.is_a?(Range) ? [ports] : Array(ports)
    super(name: name, protocols: Array(list), ports: port_list)
  end

  # Backward-compatible single-protocol reader: the first declared protocol.
  # @return [Symbol, nil]
  def protocol
    protocols.first
  end
end

#protocolsObject (readonly)

one or more protocols (:tcp, :udp, …)



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/mt/wall/model/service.rb', line 25

Service = Data.define(:name, :protocols, :ports) do
  def initialize(name:, protocol: nil, protocols: nil, ports: [])
    list = protocols || protocol
    # A Range is a single port-spec value — wrap it so Array() does not
    # explode it into discrete integers (we want `dst-port=8000-8100`).
    port_list = ports.is_a?(Range) ? [ports] : Array(ports)
    super(name: name, protocols: Array(list), ports: port_list)
  end

  # Backward-compatible single-protocol reader: the first declared protocol.
  # @return [Symbol, nil]
  def protocol
    protocols.first
  end
end

#serviceObject (readonly)

name of a Service, or nil for any



42
43
44
45
46
47
# File 'lib/mt/wall/model/rule.rb', line 42

Rule = Data.define(:source, :destination, :service, :action, :comment, :log, :log_prefix, :disabled) do
  def initialize(source:, destination:, action:, service: nil, comment: nil,
                 log: false, log_prefix: nil, disabled: false)
    super
  end
end

#sourceObject (readonly)

name of the source object/group



42
43
44
45
46
47
# File 'lib/mt/wall/model/rule.rb', line 42

Rule = Data.define(:source, :destination, :service, :action, :comment, :log, :log_prefix, :disabled) do
  def initialize(source:, destination:, action:, service: nil, comment: nil,
                 log: false, log_prefix: nil, disabled: false)
    super
  end
end

#to_addressesObject (readonly)

IPv4 translation target address(es)



41
42
43
44
45
46
# File 'lib/mt/wall/model/nat_rule.rb', line 41

NatRule = Data.define(:chain, :action, :match, :to_addresses, :to_ports, :comment) do
  def initialize(chain:, action:, match: {}, to_addresses: [], to_ports: nil, comment: nil)
    super(chain: chain, action: action, match: match,
          to_addresses: Array(to_addresses), to_ports: to_ports, comment: comment)
  end
end

#to_portsObject (readonly)

translation target port(s)



41
42
43
44
45
46
# File 'lib/mt/wall/model/nat_rule.rb', line 41

NatRule = Data.define(:chain, :action, :match, :to_addresses, :to_ports, :comment) do
  def initialize(chain:, action:, match: {}, to_addresses: [], to_ports: nil, comment: nil)
    super(chain: chain, action: action, match: match,
          to_addresses: Array(to_addresses), to_ports: to_ports, comment: comment)
  end
end

Instance Method Details

#action=(value) ⇒ Object

:accept, :drop or :reject



42
43
44
45
46
47
# File 'lib/mt/wall/model/rule.rb', line 42

Rule = Data.define(:source, :destination, :service, :action, :comment, :log, :log_prefix, :disabled) do
  def initialize(source:, destination:, action:, service: nil, comment: nil,
                 log: false, log_prefix: nil, disabled: false)
    super
  end
end

#chain=(value) ⇒ Object

:input, :output or :forward



20
21
22
23
24
# File 'lib/mt/wall/model/policy.rb', line 20

Policy = Data.define(:chain, :action, :comment, :log, :log_prefix, :disabled) do
  def initialize(chain:, action:, comment: nil, log: false, log_prefix: nil, disabled: false)
    super
  end
end

#disabled=(value) ⇒ Object

keep the rule but inactive (disabled=yes)



42
43
44
45
46
47
# File 'lib/mt/wall/model/rule.rb', line 42

Rule = Data.define(:source, :destination, :service, :action, :comment, :log, :log_prefix, :disabled) do
  def initialize(source:, destination:, action:, service: nil, comment: nil,
                 log: false, log_prefix: nil, disabled: false)
    super
  end
end

#family=(value) ⇒ Object

:ip4, :ip6 or nil (both families)



58
59
60
61
62
63
# File 'lib/mt/wall/model/filter_rule.rb', line 58

FilterRule = Data.define(:chain, :action, :match, :family, :comment, :log, :log_prefix, :disabled) do
  def initialize(chain:, action:, match: {}, family: nil, comment: nil,
                 log: false, log_prefix: nil, disabled: false)
    super
  end
end

#log=(value) ⇒ Object

log matched packets (RouterOS log=yes)



42
43
44
45
46
47
# File 'lib/mt/wall/model/rule.rb', line 42

Rule = Data.define(:source, :destination, :service, :action, :comment, :log, :log_prefix, :disabled) do
  def initialize(source:, destination:, action:, service: nil, comment: nil,
                 log: false, log_prefix: nil, disabled: false)
    super
  end
end

#match=(value) ⇒ Object

native match conditions (see above)



41
42
43
44
45
46
# File 'lib/mt/wall/model/nat_rule.rb', line 41

NatRule = Data.define(:chain, :action, :match, :to_addresses, :to_ports, :comment) do
  def initialize(chain:, action:, match: {}, to_addresses: [], to_ports: nil, comment: nil)
    super(chain: chain, action: action, match: match,
          to_addresses: Array(to_addresses), to_ports: to_ports, comment: comment)
  end
end

#options=(value) ⇒ Object

non-secret transport options (port, verify_tls, …)



43
44
45
46
47
48
49
50
51
# File 'lib/mt/wall/model/device.rb', line 43

Device = Data.define(:name, :host, :transport, :policies, :filter_rules, :nat_rules,
                     :management, :options) do
  def initialize(name:, host:, transport: :rest_api, policies: [], filter_rules: [],
                 nat_rules: [], management: [], options: {})
    super(name: name, host: host, transport: transport,
          policies: Array(policies), filter_rules: Array(filter_rules),
          nat_rules: Array(nat_rules), management: Array(management), options: options)
  end
end

#transport=(value) ⇒ Object

transport adapter key (e.g. :rest_api, :rsc)



43
44
45
46
47
48
49
50
51
# File 'lib/mt/wall/model/device.rb', line 43

Device = Data.define(:name, :host, :transport, :policies, :filter_rules, :nat_rules,
                     :management, :options) do
  def initialize(name:, host:, transport: :rest_api, policies: [], filter_rules: [],
                 nat_rules: [], management: [], options: {})
    super(name: name, host: host, transport: transport,
          policies: Array(policies), filter_rules: Array(filter_rules),
          nat_rules: Array(nat_rules), management: Array(management), options: options)
  end
end