Skip to content

Commit

Permalink
rules::llmnr: Allow interface filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
bastelfreak committed Dec 31, 2023
1 parent 9685362 commit 1ef7d5c
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
9 changes: 9 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,7 @@ The following parameters are available in the `nftables::rules::llmnr` class:

* [`ipv4`](#-nftables--rules--llmnr--ipv4)
* [`ipv6`](#-nftables--rules--llmnr--ipv6)
* [`iifname`](#-nftables--rules--llmnr--iifname)

##### <a name="-nftables--rules--llmnr--ipv4"></a>`ipv4`

Expand All @@ -769,6 +770,14 @@ Allow LLMNR over IPv6

Default value: `true`

##### <a name="-nftables--rules--llmnr--iifname"></a>`iifname`

Data type: `Array[String[1]]`

optional list of incoming interfaces to filter on

Default value: `[]`

### <a name="nftables--rules--mdns"></a>`nftables::rules::mdns`

allow incoming multicast DNS
Expand Down
14 changes: 12 additions & 2 deletions manifests/rules/llmnr.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,31 @@
#
# @param ipv4 Allow LLMNR over IPv4
# @param ipv6 Allow LLMNR over IPv6
# @param iifname optional list of incoming interfaces to filter on
#
# @author Tim Meusel <[email protected]>
#
# @see https://datatracker.ietf.org/doc/html/rfc4795
#
class nftables::rules::llmnr (
Boolean $ipv4 = true,
Boolean $ipv6 = true,
Array[String[1]] $iifname = [],
) {
if empty($iifname) {
$_iifname = ''
} else {
$iifdata = $iifname.map |String[1] $interface| { "\"${interface}\"" }.join(', ')
$_iifname = "iifname { ${iifdata} } "
}
if $ipv4 {
nftables::rule { 'default_in-llmnr_v4':
content => 'ip daddr 224.0.0.252 udp dport 5355 accept comment "allow LLMNR"',
content => "${_iifname}ip daddr 224.0.0.252 udp dport 5355 accept comment \"allow LLMNR\"",
}
}
if $ipv6 {
nftables::rule { 'default_in-llmnr_v6':
content => 'ip6 daddr ff02::1:3 udp dport 5355 accept comment "allow LLMNR"',
content => "${_iifname}ip6 daddr ff02::1:3 udp dport 5355 accept comment \"allow LLMNR\"",
}
}
}
31 changes: 31 additions & 0 deletions spec/classes/rules/llmnr_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

require 'spec_helper'

describe 'nftables::rules::llmnr' do
on_supported_os.each do |os, os_facts|
context "on #{os}" do
let :facts do
os_facts
end

context 'default options' do
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_nftables__rule('default_in-llmnr_v4').with_content('ip daddr 224.0.0.252 udp dport 5355 accept comment "allow LLMNR"') }
it { is_expected.to contain_nftables__rule('default_in-llmnr_v6').with_content('ip6 daddr ff02::1:3 udp dport 5355 accept comment "allow LLMNR"') }
end

context 'with input interfaces set' do
let :params do
{
iifname: %w[docker0 eth0],
}
end

it { is_expected.to compile }
it { is_expected.to contain_nftables__rule('default_in-llmnr_v4').with_content('iifname { "docker0", "eth0" } ip daddr 224.0.0.252 udp dport 5355 accept comment "allow LLMNR"') }
it { is_expected.to contain_nftables__rule('default_in-llmnr_v6').with_content('iifname { "docker0", "eth0" } ip6 daddr ff02::1:3 udp dport 5355 accept comment "allow LLMNR"') }
end
end
end
end

0 comments on commit 1ef7d5c

Please sign in to comment.