#!/bin/bash ############################################################################### # # # IPFire.org - A linux based firewall # # Copyright (C) 2010 Michael Tremer & Christian Schmidt # # # # 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 program is distributed in the hope that it will be useful, # # but WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU General Public License for more details. # # # # You should have received a copy of the GNU General Public License # # along with this program. If not, see . # # # ############################################################################### IP_SUPPORTED_PROTOCOLS="${IP_SUPPORTED_PROTOCOLS} ipv4" function ipv4_is_valid() { ipcalc --ipv4 -c $@ >/dev/null 2>&1 case "$?" in 0) return ${EXIT_OK} ;; *) return ${EXIT_ERROR} ;; esac } function ipv4_detect_duplicate() { local device=${1} local address=${2} assert isset address assert isset device assert device_exists ${device} # Don't check on PPP devices. device_is_ppp ${device} && return ${EXIT_ERROR} if ! arping -q -c 2 -w 3 -D -I ${device} ${address}; then log DEBUG "Detected duplicate address '${address}' on device '${device}'." return ${EXIT_OK} fi return ${EXIT_ERROR} } function ipv4_update_neighbours() { local device=${1} local address=${2} # Don't do anything on PPP devices. device_is_ppp ${device} && return ${EXIT_OK} arping -q -A -c 1 -I ${device} ${address} ( sleep 2; arping -q -U -c 1 -I ${device} ${address} ) >/dev/null 2>&1 /dev/null 2>&1 ip -4 route flush dev ${device} >/dev/null 2>&1 ip -4 neigh flush dev ${device} >/dev/null 2>&1 return 0 function ipv4_prefix2netmask() { local prefix=${1} shift assert isinteger prefix # XXX this function is a stub case "${prefix}" in 24) echo "255.255.255.0" ;; *) assert false NOT IMPLEMENTED ;; esac }