Sha256: 1a6add4795bd6f87fffbaa0eb8c9956bd5f56af2fabee3441b56d58ef3161396

Contents?: true

Size: 1.49 KB

Versions: 2

Compression:

Stored size: 1.49 KB

Contents

# -*- coding: utf-8 -*-

module Dcmgr
  module VNet
    module Netfilter
    
      class EbtablesRule < Rule
        attr_accessor :table
        attr_accessor :chain
        attr_accessor :rule
        # Should be either :incoming or :outgoing
        attr_accessor :bound
        attr_accessor :protocol
        
        def initialize(table = nil, chain = nil,  protocol = nil, bound = nil, rule = nil)
          super()
          raise ArgumentError, "table does not exist: #{table}" unless EbtablesChain.pre_made.keys.member?(table)
          self.table = table
          self.chain = chain
          self.protocol = protocol
          self.bound = bound
          self.rule = rule
        end
        
        # Override the chain getter to allow us to handle premade chains
        # with symbols instead of all caps strings. ie, :forward instead of "FORWARD"
        def chain
          if EbtablesChain.pre_made[self.table].member?(@chain)
            @chain.to_s.upcase 
          else
            @chain
          end
        end
        
        # Little static method that returns the part of an ebtables rule required for logging arp
        def self.log_arp(prefix)
          "--log-ip --log-arp --log-prefix '#{prefix}'"
        end
        
        # Getter for a hashmap of ebtables protocols
        def self.protocols
          {
            'ip4'  => 'ip4',
            'arp'  => 'arp',
            #'ip6'  => 'ip6',
            #'rarp' => '0x8035',
          }
        end
      end
    
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
wakame-vdc-agents-11.12.0 lib/dcmgr/vnet/netfilter/ebtables_rule.rb
wakame-vdc-dcmgr-11.12.0 lib/dcmgr/vnet/netfilter/ebtables_rule.rb