class Havox::RuleSanitizer

Constants

SELF_VLAN_REGEX
SET_VLAN_ID_REGEX
VLAN_MATCH_REGEX

Attributes

sanitized_rules[R]

Public Class Methods

new(raw_rules) click to toggle source
# File lib/havox/classes/rule_sanitizer.rb, line 9
def initialize(raw_rules)
  @raw_rules = raw_rules
  @setted_vlan_ids = []
  @sanitized_rules = []
  scan_setted_vlan_ids
  sanitize
end

Private Instance Methods

sanitize() click to toggle source

Main method which iterates over all the rules and cleans them.

# File lib/havox/classes/rule_sanitizer.rb, line 20
def sanitize
  @raw_rules.each do |raw_rule|
    mod_raw_rule = raw_rule.gsub(SELF_VLAN_REGEX, '')
    @sanitized_rules << mod_raw_rule if valid_vlan?(mod_raw_rule)
  end
end
scan_setted_vlan_ids() click to toggle source

Determines all VLAN IDs defined by the SetField action.

# File lib/havox/classes/rule_sanitizer.rb, line 28
def scan_setted_vlan_ids
  @raw_rules.each do |raw_rule|
    match_data = raw_rule.match(SET_VLAN_ID_REGEX)
    @setted_vlan_ids << match_data[:vlan_id] unless match_data.nil?
  end
end
valid_vlan?(raw_rule) click to toggle source

The rule is valid if it does not have matches like 'vlanId = x' or, in case it has, if 'x' is set by the SetField action.

# File lib/havox/classes/rule_sanitizer.rb, line 37
def valid_vlan?(raw_rule)
  match_data = raw_rule.match(VLAN_MATCH_REGEX)
  match_data.nil? || @setted_vlan_ids.include?(match_data[:vlan_id])
end