File: 10-ipset

package info (click to toggle)
iptables-persistent 1.0.23
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 272 kB
  • sloc: sh: 503; makefile: 20
file content (72 lines) | stat: -rwxr-xr-x 1,669 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/sh

# This file is part of netfilter-persistent
# (was iptables-persistent)
# Copyright (C) 2018, gustavo panizzo <gfa@zumbi.com.ar>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation, either version 3
# of the License, or (at your option) any later version.

# This script saves and/or restores ipset(s) to/from a file
# Flush is implemented in another script, as it has to run after
# iptables flush

set -e

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

# Source configuration
if [ -f "/etc/default/netfilter-persistent" ]; then
    . /etc/default/netfilter-persistent
fi

# Create the ipsets and populate them
load_sets ()
{
    #load ipset rules
    if [ ! -f /etc/iptables/ipsets ]; then
        echo "Warning: skipping IPSet (no rules to load)"
    else
        ipset restore -exist < /etc/iptables/ipsets
    fi
}

# Save current contents of the ipsets to file
save_sets ()
{
    if [ ! "${IPSET_SKIP_SAVE}x" = "yesx" ]; then
        touch /etc/iptables/ipsets
        chmod 0640 /etc/iptables/ipsets
        ipset save > /etc/iptables/ipsets
    fi
}

# flush sets
flush_sets ()
{
    :
}


case "$1" in
start|restart|reload|force-reload)
    load_sets
    ;;
save)
    save_sets
    ;;
stop)
    # While it makes sense to stop (delete) ipsets we keep the same
    # semanthics as ip(6)?tables rules
    echo "Automatic flushing disabled, use \"flush\" instead of \"stop\""
    ;;
flush)
    flush_sets
    ;;
*)
    echo "Usage: $0 {start|restart|reload|force-reload|save|flush}" >&2
    exit 1
    ;;
esac