Skip to content

Commit c51cc41

Browse files
committed
Warn about scanning link-local or multicast IPs
1 parent ba318b3 commit c51cc41

5 files changed

Lines changed: 89 additions & 29 deletions

File tree

.github/workflows/build.yml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,17 @@ jobs:
3030
env:
3131
CC: gcc
3232

33-
- name: Test
33+
- name: Tests
3434
run: |
3535
./util/ci-test.sh
36+
./util/ci-test4.sh
3637
37-
- name: Test 2
38+
- name: Tests 2
3839
run: |
3940
sudo ./util/ci-test2.sh
40-
41-
- name: Test 3
42-
run: |
4341
sudo ./util/ci-test3.sh
4442
43+
4544
clang:
4645
name: "clang (sanitize: ${{ matrix.c.san }})"
4746
strategy:
@@ -65,14 +64,12 @@ jobs:
6564
env:
6665
CC: clang
6766

68-
- name: Test
67+
- name: Tests
6968
run: |
7069
./util/ci-test.sh
70+
./util/ci-test4.sh
7171
72-
- name: Test 2
72+
- name: Tests 2
7373
run: |
7474
sudo ./util/ci-test2.sh
75-
76-
- name: Test 3
77-
run: |
7875
sudo ./util/ci-test3.sh

src/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ int main(int argc, char *argv[])
7878
outfile = stdout;
7979
outdef = NULL;
8080

81-
srand(time(NULL) ^ getpid());
81+
srand(time(NULL) - (getpid() * argc) + monotonic_ms());
8282
memset(source_mac, 0xff, 6);
8383
memset(router_mac, 0xff, 6);
8484
memset(source_addr, 0xff, 16);

src/target-gen.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ void target_gen_print_summary(int max_rate, int nports)
299299

300300
int target_gen_sanity_check(void)
301301
{
302+
/* Target size check */
302303
uint64_t total = 0;
303304
bool overflowed = false;
304305
for(int i = 0; i < targets_i; i++) {
@@ -328,6 +329,27 @@ int target_gen_sanity_check(void)
328329
);
329330
return -1;
330331
}
332+
333+
/* Target address check */
334+
bool have_ll = false, have_mc = false;
335+
for(int i = 0; i < targets_i; i++) {
336+
const struct targetspec *s = &targets[i].spec;
337+
if(s->mask[0] == 0xff && s->mask[1] == 0xff) {
338+
have_ll |= s->addr[0] == 0xfe && s->addr[1] >= 0x80 && s->addr[1] <= 0xbf;
339+
}
340+
if(s->mask[0] == 0xff) {
341+
have_mc |= s->addr[0] == 0xff;
342+
}
343+
}
344+
if(have_ll) {
345+
log_warning("Some of your targets are link-local IPv6 addresses. "
346+
"Scanning them will not work.");
347+
}
348+
if(have_mc) {
349+
log_warning("Some of your targets are multicast IPv6 addresses. "
350+
"Scanning them will not work.");
351+
}
352+
331353
return 0;
332354
}
333355

util/ci-test2.sh

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/bin/bash -e
2-
##
32
args=(
43
--interface lo
54
--router-mac 01:01:01:01:01:01
@@ -8,23 +7,8 @@ args=(
87

98
./fi6s "${args[@]}" --icmp ::1 | tee out.txt
109
if ! grep -q "^icmp up 0 ::1 " out.txt; then
11-
echo "1: FAILED!"
10+
echo "FAILED!"
1211
exit 1
1312
fi
14-
echo "1: Passed."
15-
16-
##
17-
18-
printf '%s\n' >in.txt \
19-
2001::/112 2002::/112 2003::/114 2004::1 2004::2 2004::3
20-
21-
./fi6s --max-rate 123 --print-summary @in.txt | tee out.txt
22-
if ! grep -q "covering 147459 address" out.txt; then
23-
echo "2: FAILED!"
24-
exit 1
25-
fi
26-
echo "2: Passed."
27-
28-
##
29-
13+
echo "Passed."
3014
exit 0

util/ci-test4.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/bash -e
2+
3+
ntest=0
4+
try () {
5+
((ntest+=1))
6+
echo
7+
echo "-> fi6s $*"
8+
./fi6s "$@" 2>&1 | tee out.txt
9+
}
10+
11+
check_out () {
12+
if ! grep -iq "$1" out.txt; then
13+
echo "#$ntest: FAILED!"
14+
exit 1
15+
fi
16+
echo "#$ntest: Passed"
17+
}
18+
19+
##
20+
21+
printf '%s\n' >in.txt \
22+
2001::/112 2002::/112 2003::/114 2004::1 2004::2 2004::3
23+
24+
try --max-rate 123 --print-summary @in.txt
25+
check_out "covering 147459 addr"
26+
27+
##
28+
29+
printf '%s\n' >in.txt \
30+
cafe::xxx:xxxx:xxxx:xxxx babe::/69
31+
32+
try --print-summary @in.txt
33+
check_out "covering 1729382256910270464 addr"
34+
check_out "largest.*/68\b"
35+
check_out "smallest.*/69\b"
36+
37+
##
38+
39+
try --print-summary c0ff:ee::1/48-64
40+
check_out "covering 65536 addr"
41+
42+
##
43+
44+
try --icmp 3ffe::/48
45+
check_out "tremendous amount of time"
46+
47+
##
48+
49+
try --icmp fe80::ffff
50+
check_out "Warning:.*are link-local "
51+
52+
##
53+
54+
try --icmp ff02::2
55+
check_out "Warning:.*are multicast "
56+
57+
exit 0

0 commit comments

Comments
 (0)