5 echo "ip stub command: \"$1\" not implemented"
9 ######################################################################
18 up
) ip_link_set_up
"$1" ;;
19 down
) ip_link_down_up
"$1" ;;
20 *) not_implemented
"\"$2\" in \"$orig_args\"" ;;
23 show
) shift ; ip_link_show
"$@" ;;
24 del
*) shift ; ip_link_delete
"$@" ;;
25 *) not_implemented
"$*" ;;
31 mkdir
-p "${FAKE_IP_STATE}/interfaces-deleted"
32 touch "${FAKE_IP_STATE}/interfaces-deleted/$1"
37 rm -f "${FAKE_IP_STATE}/interfaces-down/$1"
38 rm -f "${FAKE_IP_STATE}/interfaces-deleted/$1"
43 rm -f "${FAKE_IP_STATE}/interfaces-deleted/$1"
44 mkdir
-p "${FAKE_IP_STATE}/interfaces-down"
45 touch "${FAKE_IP_STATE}/interfaces-down/$1"
51 if [ "$dev" = "dev" -a -n "$2" ] ; then
55 if [ -e "${FAKE_IP_STATE}/interfaces-deleted/$dev" ] ; then
56 echo "Device \"${dev}\" does not exist." >&2
60 mac
=$
(echo $dev |
md5sum |
sed -r -e 's@(..)(..)(..)(..)(..)(..).*@\1:\2:\3:\4:\5:\6@')
63 if [ -e "${FAKE_IP_STATE}/interfaces-down/$dev" ] ; then
67 echo "${n}: ${dev}: <BROADCAST,MULTICAST${_flags}> mtu 1500 qdisc pfifo_fast state ${_state} qlen 1000"
68 echo " link/ether ${mac} brd ff:ff:ff:ff:ff:ff"
71 # This is incomplete because it doesn't actually look up table ids in
72 # /etc/iproute2/rt_tables. The rules/routes are actually associated
73 # with the name instead of the number. However, we include a variable
74 # to fake a bad table id.
75 [ -n "$IP_ROUTE_BAD_TABLE_ID" ] || IP_ROUTE_BAD_TABLE_ID
=false
81 [ -n "$_table" ] || not_implemented
"ip rule/route without \"table\""
83 # Only allow tables names from 13.per_ip_routing. This is a cheap
84 # way of avoiding implementing the default/main/local tables.
87 if $IP_ROUTE_BAD_TABLE_ID ; then
88 # Ouch. Simulate inconsistent errors from ip. :-(
91 echo "Error: argument "${_table}" is wrong: table id value is invalid" >&2
95 echo "Error: argument "${_table}" is wrong: invalid table ID" >&2
100 *) not_implemented
"table=${_table} ${orig_args}" ;;
104 ######################################################################
109 show|list|
"") shift ; ip_addr_show
"$@" ;;
110 add
*) shift ; ip_addr_add
"$@" ;;
111 del
*) shift ; ip_addr_del
"$@" ;;
112 *) not_implemented
"\"$1\" in \"$orig_args\"" ;;
122 while [ -n "$1" ] ; do
127 # Do stupid things and stupid things will happen!
129 primary
=true
; secondary
=false
; shift
132 secondary
=true
; primary
=false
; shift
138 # Assume an interface name
143 if [ -z "$devices" ] ; then
144 # No device specified? Get all the primaries...
145 devices
=$
(ls "${FAKE_IP_STATE}/addresses/"*-primary 2>/dev
/null | \
146 sed -e 's@.*/@@' -e 's@-primary$@@')
150 case "${local#*/}" in
152 brd
="${local%.*}.255"
155 not_implemented
"list ... fake bits other than 24: ${local#*/}"
160 pf
="${FAKE_IP_STATE}/addresses/${dev}-primary"
161 sf
="${FAKE_IP_STATE}/addresses/${dev}-secondary"
163 if $primary && [ -r "$pf" ] ; then
165 if [ -z "$_to" -o "${_to%/*}" = "${local%/*}" ] ; then
167 echo " inet ${local} brd ${brd} scope global ${dev}"
170 if $secondary && [ -r "$sf" ] ; then
171 while read local ; do
172 if [ -z "$_to" -o "${_to%/*}" = "${local%/*}" ] ; then
174 echo " inet ${local} brd ${brd} scope global secondary ${dev}"
178 if [ -z "$_to" ] ; then
179 echo " valid_lft forever preferred_lft forever"
183 for dev
in $devices ; do
184 if [ -z "$_to" ] || \
185 grep -F "${_to%/*}/" "${FAKE_IP_STATE}/addresses/${dev}-"* >/dev
/null
; then
197 while [ -n "$1" ] ; do
206 # For now assume this is always '+'.
207 if [ "$2" != "+" ] ; then
208 not_implemented
"addr add ... brd $2 ..."
219 if [ -z "$dev" ] ; then
220 not_implemented
"addr add (without dev)"
222 mkdir
-p "${FAKE_IP_STATE}/addresses"
223 pf
="${FAKE_IP_STATE}/addresses/${dev}-primary"
224 sf
="${FAKE_IP_STATE}/addresses/${dev}-secondary"
225 # We could lock here... but we should be the only ones playing
226 # around here with these stubs.
227 if [ ! -f "$pf" ] ; then
229 elif grep -Fq "$local" "$pf" ; then
230 echo "RTNETLINK answers: File exists" >&2
232 elif [ -f "$sf" ] && grep -Fq "$local" "$sf" ; then
233 echo "RTNETLINK answers: File exists" >&2
236 echo "$local" >>"$sf"
244 while [ -n "$1" ] ; do
256 not_implemented
"addr del ... $1 ..."
259 if [ -z "$dev" ] ; then
260 not_implemented
"addr del (without dev)"
262 mkdir
-p "${FAKE_IP_STATE}/addresses"
263 pf
="${FAKE_IP_STATE}/addresses/${dev}-primary"
264 sf
="${FAKE_IP_STATE}/addresses/${dev}-secondary"
265 # We could lock here... but we should be the only ones playing
266 # around here with these stubs.
267 if [ ! -f "$pf" ] ; then
268 echo "RTNETLINK answers: Cannot assign requested address" >&2
270 elif grep -Fq "$local" "$pf" ; then
271 # Remove primaries AND SECONDARIES.
273 elif [ -f "$sf" ] && grep -Fq "$local" "$sf" ; then
274 grep -Fv "$local" "$sf" >"${sf}.new"
277 echo "RTNETLINK answers: Cannot assign requested address" >&2
282 ######################################################################
287 show|list|
"") shift ; ip_rule_show
"$@" ;;
288 add
) shift ; ip_rule_add
"$@" ;;
289 del
*) shift ; ip_rule_del
"$@" ;;
290 *) not_implemented
"$1 in \"$orig_args\"" ;;
295 # All non-default rules are in $FAKE_IP_STATE_RULES/rules. As with
296 # the real version, rules can be repeated. Deleting just deletes the
306 # potentially more options
308 printf "%d:\t%s lookup %s \n" $_pre "$_selectors" "$_table"
316 [ -f "${FAKE_IP_STATE}/rules" ] ||
return
318 while read _pre _table _selectors
; do
319 # Only print those in range
320 [ $_min -le $_pre -a $_pre -le $_max ] ||
continue
322 ip_rule_show_1
$_pre "$_table" "$_selectors"
323 done <"${FAKE_IP_STATE}/rules"
326 ip_rule_show_1
0 "local" "from all"
328 ip_rule_show_some
1 32765
330 ip_rule_show_1
32766 "main" "from all"
331 ip_rule_show_1
32767 "default" "from all"
333 ip_rule_show_some
32768 2147483648
341 while [ -n "$1" ] ; do
343 from
) _from
="$2" ; shift 2 ;;
344 pref
) _pre
="$2" ; shift 2 ;;
345 table
) _table
="$2" ; shift 2 ;;
346 *) not_implemented
"$1 in \"$orig_args\"" ;;
350 [ -n "$_pre" ] || not_implemented
"ip rule without \"pref\""
351 ip_check_table
"rule"
352 # Relax this if more selectors added later...
353 [ -n "$_from" ] || not_implemented
"ip rule without \"from\""
360 _f
="${FAKE_IP_STATE}/rules"
364 # Filter order must be consistent with the comparison in ip_rule_del()
365 echo "$_pre $_table${_from:+ from }$_from" >>"$_f"
373 _f
="${FAKE_IP_STATE}/rules"
379 while read _p _t _s
; do
381 [ "$_p" = "$_pre" -a "$_t" = "$_table" -a \
382 "$_s" = "${_from:+from }$_from" ] ; then
383 # Found. Skip this one but not future ones.
386 echo "$_p $_t $_s" >>"$_tmp"
389 if cmp -s "$_tmp" "$_f" ; then
390 # No changes, must not have found what we wanted to delete
391 echo "RTNETLINK answers: No such file or directory" >&2
400 ######################################################################
405 show|list
) shift ; ip_route_show
"$@" ;;
406 flush
) shift ; ip_route_flush
"$@" ;;
407 add
) shift ; ip_route_add
"$@" ;;
408 *) not_implemented
"$1 in \"ip route\"" ;;
414 [ "$1" = table
] || not_implemented
"$1 in \"$orig_args\""
417 ip_check_table
"route"
420 # Routes are in a file per table in the directory
421 # $FAKE_IP_STATE/routes. These routes just use the table ID
422 # that is passed and don't do any lookup. This could be "improved" if
429 # Missing file is just an empty table
430 cat "$FAKE_IP_STATE/routes/${_table}" 2>/dev
/null || true
437 rm -f "$FAKE_IP_STATE/routes/${_table}"
447 while [ -n "$1" ] ; do
449 *.
*.
*.
*/*|
*.
*.
*.
*) _prefix
="$1" ; shift 1 ;;
450 local) _prefix
="$2" ; shift 2 ;;
451 dev
) _dev
="$2" ; shift 2 ;;
452 via
) _gw
="$2" ; shift 2 ;;
453 table
) _table
="$2" ; shift 2 ;;
454 *) not_implemented
"$1 in \"$orig_args\"" ;;
458 ip_check_table
"route"
459 [ -n "$_prefix" ] || not_implemented
"ip route without inet prefix in \"$orig_args\""
460 [ -n "$_dev" ] || not_implemented
"ip route without \"dev\" in \"$orig_args\""
462 # Alias or add missing bits
464 0.0.0.0/0) _prefix
="default" ;;
466 *) _prefix
="${_prefix}/32" ;;
469 _f
="$FAKE_IP_STATE/routes/${_table}"
470 mkdir
-p "$FAKE_IP_STATE/routes"
476 if [ -n "$_gw" ] ; then
477 echo "${_prefix} via ${_gw} dev ${_dev} "
479 echo "${_prefix} dev ${_dev} scope link "
485 ######################################################################
490 link
) shift ; ip_link
"$@" ;;
491 addr
*) shift ; ip_addr
"$@" ;;
492 rule
) shift ; ip_rule
"$@" ;;
493 route
) shift ; ip_route
"$@" ;;
494 *) not_implemented
"$1" ;;