]>
Commit | Line | Data |
---|---|---|
05c234a8 MT |
1 | #!/bin/bash |
2 | ############################################################################### | |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
5 | # Copyright (C) 2010 Michael Tremer & Christian Schmidt # | |
6 | # # | |
7 | # This program is free software: you can redistribute it and/or modify # | |
8 | # it under the terms of the GNU General Public License as published by # | |
9 | # the Free Software Foundation, either version 3 of the License, or # | |
10 | # (at your option) any later version. # | |
11 | # # | |
12 | # This program is distributed in the hope that it will be useful, # | |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | |
15 | # GNU General Public License for more details. # | |
16 | # # | |
17 | # You should have received a copy of the GNU General Public License # | |
18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # | |
19 | # # | |
20 | ############################################################################### | |
21 | ||
e617226b MT |
22 | IP_SUPPORTED_PROTOCOLS="${IP_SUPPORTED_PROTOCOLS} ipv4" |
23 | ||
05c234a8 MT |
24 | function ipv4_split_prefix() { |
25 | ip_split_prefix $@ | |
26 | } | |
27 | ||
28 | function ipv4_is_valid() { | |
29 | local address=${1} | |
30 | ||
31 | assert isset address | |
32 | ||
33 | # Cut the /24 if there is one given | |
34 | address=$(ipv4_split_prefix ${address}) | |
35 | ||
36 | local IFS="." | |
37 | local octet | |
38 | local count | |
39 | for octet in ${address}; do | |
40 | if [ ${octet} -ge 0 ] && [ ${octet} -le 255 ]; then | |
41 | count=$(( ${count} + 1 )) | |
42 | continue | |
43 | fi | |
44 | ||
45 | # If we get here the address was not valid | |
46 | break | |
47 | done | |
48 | ||
49 | if [ ${count} -eq 4 ]; then | |
50 | return ${EXIT_OK} | |
51 | fi | |
52 | ||
53 | return ${EXIT_ERROR} | |
54 | } | |
55 | ||
56 | function ipv4_detect_duplicate() { | |
57 | local device=${1} | |
58 | local address=${2} | |
59 | ||
60 | assert isset address | |
61 | assert isset device | |
62 | assert device_exists ${device} | |
63 | ||
64 | if ! arping -q -c 2 -w 3 -D -I ${device} ${address}; then | |
65 | log DEBUG "Detected duplicate address '${address}' on device '${device}'." | |
9eebfc55 | 66 | return ${EXIT_OK} |
05c234a8 MT |
67 | fi |
68 | ||
9eebfc55 | 69 | return ${EXIT_ERROR} |
05c234a8 MT |
70 | } |
71 | ||
72 | function ipv4_update_neighbours() { | |
73 | local device=${1} | |
74 | local address=${2} | |
75 | ||
76 | arping -q -A -c 1 -I ${device} ${address} | |
77 | ( sleep 2; arping -q -U -c 1 -I ${device} ${address} ) >/dev/null 2>&1 </dev/null & | |
78 | } |