File: meta_time

package info (click to toggle)
nftables 1.1.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,384 kB
  • sloc: ansic: 50,901; sh: 20,277; yacc: 5,861; python: 1,746; lex: 1,367; makefile: 392
file content (97 lines) | stat: -rwxr-xr-x 2,485 bytes parent folder | download
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/bash

# NFT_TEST_REQUIRES(NFT_TEST_HAVE_meta_time)

set -e

TMP1=$(mktemp)
TMP2=$(mktemp)

cleanup()
{
	rm -f "$TMP1"
	rm -f "$TMP2"
}

check_decode()
{
	TZ=$1 $NFT list chain t c | grep meta > "$TMP2"
	diff -u "$TMP1" "$TMP2"
}

trap cleanup EXIT

$NFT -f - <<EOF
table t {
	chain c {
	}
}
EOF

for i in $(seq -w 0 23); do
	TZ=UTC $NFT add rule t c meta hour "$i:00"-"$i:59"
done

# Check decoding in UTC, this mirrors 1:1 what should have been added.
for i in $(seq 0 23); do
	printf "\t\tmeta hour \"%02d:%02d\"-\"%02d:%02d\"\n" $i 0 $i 59 >> "$TMP1"
done

check_decode UTC

printf "\t\tmeta hour \"%02d:%02d\"-\"%02d:%02d\"\n" 23 0 23 59 > "$TMP1"
for i in $(seq 0 22); do
	printf "\t\tmeta hour \"%02d:%02d\"-\"%02d:%02d\"\n" $i 0 $i 59 >> "$TMP1"
done
check_decode UTC+1

printf "\t\tmeta hour \"%02d:%02d\"-\"%02d:%02d\"\n" 1 0 1 59 > "$TMP1"
for i in $(seq 2 23); do
	printf "\t\tmeta hour \"%02d:%02d\"-\"%02d:%02d\"\n" $i 0 $i 59 >> "$TMP1"
done
printf "\t\tmeta hour \"%02d:%02d\"-\"%02d:%02d\"\n" 0 0 0 59 >> "$TMP1"

check_decode UTC-1

$NFT flush chain t c
TZ=EADT $NFT add rule t c meta hour "03:00"-"14:00"
TZ=EADT $NFT add rule t c meta hour "04:00"-"15:00"
TZ=EADT $NFT add rule t c meta hour "05:00"-"16:00"
TZ=EADT $NFT add rule t c meta hour "06:00"-"17:00"

printf "\t\tmeta hour \"%02d:%02d\"-\"%02d:%02d\"\n" 3 0 14 0 > "$TMP1"
printf "\t\tmeta hour \"%02d:%02d\"-\"%02d:%02d\"\n" 4 0 15 0 >> "$TMP1"
printf "\t\tmeta hour \"%02d:%02d\"-\"%02d:%02d\"\n" 5 0 16 0 >> "$TMP1"
printf "\t\tmeta hour \"%02d:%02d\"-\"%02d:%02d\"\n" 6 0 17 0 >> "$TMP1"

check_decode EADT

$NFT flush chain t c
TZ=UTC-2 $NFT add rule t c meta hour "00:00"-"01:00"
TZ=UTC-2 $NFT add rule t c meta hour "00:00"-"03:00"
TZ=UTC-2 $NFT add rule t c meta hour "01:00"-"04:00"

printf "\t\tmeta hour \"%02d:%02d\"-\"%02d:%02d\"\n" 0 0 1 0 > "$TMP1"
printf "\t\tmeta hour \"%02d:%02d\"-\"%02d:%02d\"\n" 0 0 3 0 >> "$TMP1"
printf "\t\tmeta hour \"%02d:%02d\"-\"%02d:%02d\"\n" 1 0 4 0 >> "$TMP1"

check_decode UTC-2

$NFT flush chain t c
TZ=UTC-2 $NFT --debug=eval -f - <<EOF
define midnight="00:00"
define threeam="03:00"
table t {
	chain c {
		meta hour \$midnight - "03:00"
		meta hour 00:00 - \$threeam
		meta hour \$midnight - \$threeam
	}
}
EOF

printf "\t\tmeta hour \"%02d:%02d\"-\"%02d:%02d\"\n" 0 0 3 0 > "$TMP1"
printf "\t\tmeta hour \"%02d:%02d\"-\"%02d:%02d\"\n" 0 0 3 0 >> "$TMP1"
printf "\t\tmeta hour \"%02d:%02d\"-\"%02d:%02d\"\n" 0 0 3 0 >> "$TMP1"

check_decode UTC-2