Defined Type: interface::rule

Defined in:
modules/interface/manifests/rule.pp

Summary

defines a routing policy rule

Overview

SPDX-License-Identifier: Apache-2.0

Parameters:

  • interface (String[1])

    interface to attach this rule to

  • from (Stdlib::IP::Address)

    match traffic coming from this address

  • table (Optional[String[1]]) (defaults to: undef)

    use this table for traffic that matches the conditions

  • ensure (Wmflib::Ensure) (defaults to: 'present')

    ensure



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'modules/interface/manifests/rule.pp', line 7

define interface::rule (
    String[1]           $interface,
    Stdlib::IP::Address $from,
    Wmflib::Ensure      $ensure = 'present',
    Optional[String[1]] $table  = undef,
) {
    if $from =~ Stdlib::IP::Address::Nosubnet {
        $from_cidr = $from ? {
            Stdlib::IP::Address::V4 => "${from}/32",
            Stdlib::IP::Address::V6 => "${from}/128",
        }
    } else {
        $from_cidr = $from
    }
    $from_cmd = " from ${$from_cidr}"

    $table_cmd = $table.then |$t| { " table ${t}" }
    $table_require = $table.then |$t| { Interface::Routing_table[$t] }

    $command = "ip rule add${from_cmd}${table_cmd}"

    interface::post_up_command { $title:
        ensure    => $ensure,
        command   => $command,
        interface => $interface,
        require   => $table_require,
    }
}