PageRenderTime 52ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/firewall/lib/puppet/provider/firewall/ip6tables.rb

https://gitlab.com/jkday/bootstrap
Ruby | 183 lines | 157 code | 15 blank | 11 comment | 10 complexity | 8fbf54c6d3a3d0cebe5c50d2309d77de MD5 | raw file
Possible License(s): Apache-2.0, BSD-2-Clause
  1. Puppet::Type.type(:firewall).provide :ip6tables, :parent => :iptables, :source => :ip6tables do
  2. @doc = "Ip6tables type provider"
  3. has_feature :iptables
  4. has_feature :connection_limiting
  5. has_feature :hop_limiting
  6. has_feature :rate_limiting
  7. has_feature :recent_limiting
  8. has_feature :snat
  9. has_feature :dnat
  10. has_feature :interface_match
  11. has_feature :icmp_match
  12. has_feature :owner
  13. has_feature :state_match
  14. has_feature :reject_type
  15. has_feature :log_level
  16. has_feature :log_prefix
  17. has_feature :mark
  18. has_feature :tcp_flags
  19. has_feature :pkttype
  20. has_feature :ishasmorefrags
  21. has_feature :islastfrag
  22. has_feature :isfirstfrag
  23. has_feature :socket
  24. has_feature :address_type
  25. has_feature :iprange
  26. has_feature :ipsec_dir
  27. has_feature :ipsec_policy
  28. has_feature :mask
  29. has_feature :ipset
  30. optional_commands({
  31. :ip6tables => 'ip6tables',
  32. :ip6tables_save => 'ip6tables-save',
  33. })
  34. confine :kernel => :linux
  35. ip6tables_version = Facter.fact('ip6tables_version').value
  36. if (ip6tables_version and Puppet::Util::Package.versioncmp(ip6tables_version, '1.4.1') < 0)
  37. mark_flag = '--set-mark'
  38. else
  39. mark_flag = '--set-xmark'
  40. end
  41. def initialize(*args)
  42. ip6tables_version = Facter.value('ip6tables_version')
  43. if ip6tables_version and ip6tables_version.match /1\.3\.\d/
  44. raise ArgumentError, 'The ip6tables provider is not supported on version 1.3 of iptables'
  45. else
  46. super
  47. end
  48. end
  49. def self.iptables(*args)
  50. ip6tables(*args)
  51. end
  52. def self.iptables_save(*args)
  53. ip6tables_save(*args)
  54. end
  55. @protocol = "IPv6"
  56. @resource_map = {
  57. :burst => "--limit-burst",
  58. :connlimit_above => "-m connlimit --connlimit-above",
  59. :connlimit_mask => "--connlimit-mask",
  60. :connmark => "-m connmark --mark",
  61. :ctstate => "-m conntrack --ctstate",
  62. :destination => "-d",
  63. :dport => ["-m multiport --dports", "--dport"],
  64. :dst_range => '-m iprange --dst-range',
  65. :dst_type => "-m addrtype --dst-type",
  66. :gid => "-m owner --gid-owner",
  67. :hop_limit => "-m hl --hl-eq",
  68. :icmp => "-m icmp6 --icmpv6-type",
  69. :iniface => "-i",
  70. :ipsec_dir => "-m policy --dir",
  71. :ipsec_policy => "--pol",
  72. :ipset => "-m set --match-set",
  73. :isfirstfrag => "-m frag --fragid 0 --fragfirst",
  74. :ishasmorefrags => "-m frag --fragid 0 --fragmore",
  75. :islastfrag => "-m frag --fragid 0 --fraglast",
  76. :jump => "-j",
  77. :limit => "-m limit --limit",
  78. :log_level => "--log-level",
  79. :log_prefix => "--log-prefix",
  80. :mask => "--mask",
  81. :name => "-m comment --comment",
  82. :mac_source => ["-m mac --mac-source", "--mac-source"],
  83. :outiface => "-o",
  84. :pkttype => "-m pkttype --pkt-type",
  85. :port => '-m multiport --ports',
  86. :proto => "-p",
  87. :rdest => "--rdest",
  88. :reap => "--reap",
  89. :recent => "-m recent",
  90. :reject => "--reject-with",
  91. :rhitcount => "--hitcount",
  92. :rname => "--name",
  93. :rseconds => "--seconds",
  94. :rsource => "--rsource",
  95. :rttl => "--rttl",
  96. :set_mark => mark_flag,
  97. :socket => "-m socket",
  98. :source => "-s",
  99. :sport => ["-m multiport --sports", "--sport"],
  100. :src_range => '-m iprange --src-range',
  101. :src_type => "-m addrtype --src-type",
  102. :stat_every => '--every',
  103. :stat_mode => "-m statistic --mode",
  104. :stat_packet => '--packet',
  105. :stat_probability => '--probability',
  106. :state => "-m state --state",
  107. :table => "-t",
  108. :tcp_flags => "-m tcp --tcp-flags",
  109. :todest => "--to-destination",
  110. :toports => "--to-ports",
  111. :tosource => "--to-source",
  112. :uid => "-m owner --uid-owner",
  113. :physdev_in => "-m physdev --physdev-in",
  114. :physdev_out => "-m physdev --physdev-out",
  115. }
  116. # These are known booleans that do not take a value, but we want to munge
  117. # to true if they exist.
  118. @known_booleans = [
  119. :ishasmorefrags,
  120. :islastfrag,
  121. :isfirstfrag,
  122. :rsource,
  123. :rdest,
  124. :reap,
  125. :rttl,
  126. :socket
  127. ]
  128. # Create property methods dynamically
  129. (@resource_map.keys << :chain << :table << :action).each do |property|
  130. if @known_booleans.include?(property) then
  131. # The boolean properties default to '' which should be read as false
  132. define_method "#{property}" do
  133. @property_hash[property] = :false if @property_hash[property] == nil
  134. @property_hash[property.to_sym]
  135. end
  136. else
  137. define_method "#{property}" do
  138. @property_hash[property.to_sym]
  139. end
  140. end
  141. if property == :chain
  142. define_method "#{property}=" do |value|
  143. if @property_hash[:chain] != value
  144. raise ArgumentError, "Modifying the chain for existing rules is not supported."
  145. end
  146. end
  147. else
  148. define_method "#{property}=" do |value|
  149. @property_hash[:needs_change] = true
  150. end
  151. end
  152. end
  153. # This is the order of resources as they appear in iptables-save output,
  154. # we need it to properly parse and apply rules, if the order of resource
  155. # changes between puppet runs, the changed rules will be re-applied again.
  156. # This order can be determined by going through iptables source code or just tweaking and trying manually
  157. # (Note: on my CentOS 6.4 ip6tables-save returns -m frag on the place
  158. # I put it when calling the command. So compability with manual changes
  159. # not provided with current parser [georg.koester])
  160. @resource_list = [:table, :source, :destination, :iniface, :outiface, :physdev_in,
  161. :physdev_out, :proto, :ishasmorefrags, :islastfrag, :isfirstfrag, :src_range, :dst_range,
  162. :tcp_flags, :gid, :uid, :mac_source, :sport, :dport, :port, :dst_type,
  163. :src_type, :socket, :pkttype, :name, :ipsec_dir, :ipsec_policy, :state,
  164. :ctstate, :icmp, :hop_limit, :limit, :burst, :recent, :rseconds, :reap,
  165. :rhitcount, :rttl, :rname, :mask, :rsource, :rdest, :ipset, :jump, :todest,
  166. :tosource, :toports, :log_level, :log_prefix, :reject, :set_mark,
  167. :connlimit_above, :connlimit_mask, :connmark]
  168. end