Skip to content

Commit 1c6e50a

Browse files
committed
feat: add IPv6 ipset support, add support for ipset_options
Feature: Add support for IPv6 addresses to ipsets. You can now specify IPv6 addresses when using `ipset` in the `ipset_entries` list when using `hash:ip` or `hash:net`. You can also specify `ipset_options` which are extra key/value pairs of options for the ipset. Reason: Users need to be able to specify IPv6 addresses in `ipset` definitions, and need to be able to specify `ipset_options` for ipsets. Result: Users can specify IPv6 addresses and options in `ipset` definitions. NOTE: You cannot mix IPv4, IPv6, and MAC addresses in the same `ipset_entries` list. This is a limitation of the underlying firewalld implementation. Signed-off-by: Rich Megginson <[email protected]>
1 parent 0513cd1 commit 1c6e50a

13 files changed

+680
-70
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
python-ipaddress
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
python-ipaddress

.sanity-ansible-ignore-2.18.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
plugins/modules/firewall_lib.py validate-modules:missing-gplv3-license
2+
plugins/modules/firewall_lib_facts.py validate-modules:missing-gplv3-license

.sanity-ansible-ignore-2.19.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
plugins/modules/firewall_lib.py validate-modules:missing-gplv3-license
2+
plugins/modules/firewall_lib_facts.py validate-modules:missing-gplv3-license

README.md

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,12 @@ For more information about custom services, see <https://firewalld.org/documenta
381381
Name of the ipset being created, modified, or removed.
382382
Use `source` to add and remove ipsets from a zone
383383

384-
When creating an ipset, you must also specify `ipset_type`,
385-
and optionally `short`, `description`, `ipset_entries`
384+
When creating an ipset, you must also specify `ipset_type`, and optionally
385+
`short`, `description`, `ipset_entries` and `ipset_options`.
386+
387+
**NOTE**: You cannot mix IPv4, IPv6, and MAC addresses in the same
388+
`ipset_entries` list. All addresses must be the same IP type. This is a
389+
limitation of the underlying firewalld implementation.
386390

387391
Defining an ipset with all optional fields:
388392

@@ -398,6 +402,24 @@ firewall:
398402
- 3.3.3.3
399403
- 8.8.8.8
400404
- 127.0.0.1
405+
ipset_options:
406+
maxelem: 1000
407+
state: present
408+
permanent: true
409+
```
410+
411+
Defining an ipset with IPv6 addresses:
412+
413+
```yaml
414+
firewall:
415+
- ipset: customipset
416+
ipset_type: "hash:ip"
417+
short: Custom IPSet
418+
description: set of ip addresses specified in entries
419+
ipset_entries:
420+
- 2001:db8::/32
421+
ipset_options:
422+
maxelem: 1000
401423
state: present
402424
permanent: true
403425
```
@@ -478,6 +500,10 @@ Used with `ipset`
478500
Entries must be compatible with the ipset type of the `ipset`
479501
being created or modified.
480502

503+
**NOTE**: You cannot mix IPv4, IPv6, and MAC addresses in the same
504+
`ipset_entries` list. All addresses must be the same IP type. This is a
505+
limitation of the underlying firewalld implementation.
506+
481507
```yaml
482508
ipset: customipset
483509
ipset_entries:
@@ -486,6 +512,41 @@ ipset_entries:
486512

487513
See `ipset` for more usage information
488514

515+
### ipset_options
516+
517+
A `dict` of key/value pairs of ipset options for the given ipset.
518+
See [firewalld ipset options](https://firewalld.org/documentation/ipset/options.html)
519+
for more information.
520+
521+
You usually do not have to specify the family. The role will default to
522+
`family: inet` if `ipset_entries` contains IPv4 addresses, and will default to
523+
`family: inet6` if `ipset_entries` contains IPv6 addresses
524+
525+
```yaml
526+
ipset_options:
527+
maxelem: 1000
528+
hashsize: 512
529+
```
530+
531+
#### Removing options
532+
533+
**NOTE**: Options cannot be modified or removed if running the role during
534+
a container or image build (e.g. in a `bootc` Containerfile).
535+
536+
If you want to remove an option, set `state: absent`, and set the option value
537+
to `null`:
538+
539+
```yaml
540+
state: absent
541+
ipset_options:
542+
maxelem: null
543+
```
544+
545+
This will remove the `maxelem` option. If you specify a value, then the role
546+
will only remove that option *if it matches the value*. This is useful if you
547+
want to ensure that the value you are removing is the expected value, and has
548+
not be changed outside of the role.
549+
489550
### source_port
490551

491552
Port or port range or a list of them to add or remove source port access to. It

0 commit comments

Comments
 (0)