Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / manifests / set.pp @ 6ee35b94

Historique | Voir | Annoter | Télécharger (2,95 ko)

1 13f4e4c6 Steve Traylen
# @summary  manage a named set
2
#
3
# @example simple set
4
#  nftables::set{'my_set':
5
#    type       => 'ipv4_addr',
6
#    flags      => ['interval'],
7
#    elements   => ['192.168.0.1/24', '10.0.0.2'],
8
#    auto_merge => true,
9
#  }
10
#
11
# @param ensure should the set be created.
12
# @param setname name of set, equal to to title.
13
# @param order concat ordering.
14
# @param type type of set.
15 c94658e1 Nacho Barrientos
# @param table table or array of tables to add the set to.
16 13f4e4c6 Steve Traylen
# @param flags specify flags for set
17
# @param timeout timeout in seconds
18
# @param gc_interval garbage collection interval.
19
# @param elements initialize the set with some elements in it.
20 c868cae3 Tim Meusel
# @param size limits the maximum number of elements of the set.
21 13f4e4c6 Steve Traylen
# @param policy determines set selection policy.
22 2732318a Tames McTigue
# @param auto_merge automatically merge adjacent/overlapping set elements (only valid for interval sets)
23 13f4e4c6 Steve Traylen
# @param content specify content of set.
24
# @param source specify source of set.
25 11bf7237 Steve Traylen
define nftables::set (
26 31b17627 Steve Traylen
  Enum['present','absent'] $ensure = 'present',
27
  Pattern[/^[-a-zA-Z0-9_]+$/] $setname = $title,
28
  Pattern[/^\d\d$/] $order = '10',
29
  Optional[Enum['ipv4_addr', 'ipv6_addr', 'ether_addr', 'inet_proto', 'inet_service', 'mark']] $type = undef,
30 c94658e1 Nacho Barrientos
  Variant[String, Array[String, 1]] $table = 'inet-filter',
31 31b17627 Steve Traylen
  Array[Enum['constant', 'dynamic', 'interval', 'timeout'], 0, 4] $flags = [],
32
  Optional[Integer] $timeout = undef,
33
  Optional[Integer] $gc_interval = undef,
34
  Optional[Array[String]] $elements = undef,
35
  Optional[Integer] $size = undef,
36
  Optional[Enum['performance', 'memory']] $policy = undef,
37
  Boolean $auto_merge = false,
38
  Optional[String] $content = undef,
39
  Optional[Variant[String,Array[String,1]]] $source = undef,
40 11bf7237 Steve Traylen
) {
41 20b96360 Nacho Barrientos
  if $size and $elements {
42
    if length($elements) > $size {
43
      fail("Max size of set ${setname} of ${size} is not being respected")
44
    }
45
  }
46
47 c94658e1 Nacho Barrientos
  $_tables = Array($table, true)
48 20b96360 Nacho Barrientos
49 c94658e1 Nacho Barrientos
  if $ensure == 'present' {
50
    $_tables.each |Integer $index, String $_table| {
51
      concat::fragment {
52
        "nftables-${_table}-set-${setname}":
53
          order  => $order,
54
          target => "nftables-${_table}",
55 9f0498e3 Nacho Barrientos
      }
56 c94658e1 Nacho Barrientos
57
      if $content {
58
        Concat::Fragment["nftables-${_table}-set-${setname}"] {
59
          content => "  ${content}",
60
        }
61
      } elsif $source {
62
        Concat::Fragment["nftables-${_table}-set-${setname}"] {
63
          source => $source,
64
        }
65
      } else {
66
        if $type == undef {
67
          fail('The way the resource is configured must have a type set')
68
        }
69
        Concat::Fragment["nftables-${_table}-set-${setname}"] {
70
          content => epp('nftables/set.epp',
71
            {
72
              'name'        => $setname,
73
              'type'        => $type,
74
              'flags'       => $flags,
75
              'timeout'     => $timeout,
76
              'gc_interval' => $gc_interval,
77
              'elements'    => $elements,
78
              'size'        => $size,
79
              'policy'      => $policy,
80
              'auto_merge'  => $auto_merge,
81
            }
82
          )
83
        }
84 20b96360 Nacho Barrientos
      }
85
    }
86
  }
87
}