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
68 ${n}: ${dev}: <BROADCAST,MULTICAST${_flags}> mtu 1500 qdisc pfifo_fast state ${_state} qlen 1000
69 link/ether ${mac} brd ff:ff:ff:ff:ff:ff
73 # This is incomplete because it doesn't actually look up table ids in
74 # /etc/iproute2/rt_tables. The rules/routes are actually associated
75 # with the name instead of the number. However, we include a variable
76 # to fake a bad table id.
77 [ -n "$IP_ROUTE_BAD_TABLE_ID" ] || IP_ROUTE_BAD_TABLE_ID
=false
83 [ -n "$_table" ] || not_implemented
"ip rule/route without \"table\""
85 # Only allow tables names from 13.per_ip_routing. This is a cheap
86 # way of avoiding implementing the default/main/local tables.
89 if $IP_ROUTE_BAD_TABLE_ID ; then
90 # Ouch. Simulate inconsistent errors from ip. :-(
93 echo "Error: argument "${_table}" is wrong: table id value is invalid" >&2
97 echo "Error: argument "${_table}" is wrong: invalid table ID" >&2
102 *) not_implemented
"table=${_table} ${orig_args}" ;;
106 ######################################################################
111 show|list|
"") shift ; ip_addr_show
"$@" ;;
112 add
*) shift ; ip_addr_add
"$@" ;;
113 del
*) shift ; ip_addr_del
"$@" ;;
114 *) not_implemented
"\"$1\" in \"$orig_args\"" ;;
124 while [ -n "$1" ] ; do
129 # Do stupid things and stupid things will happen!
131 primary
=true
; secondary
=false
; shift
134 secondary
=true
; primary
=false
; shift
140 # Assume an interface name
145 if [ -z "$devices" ] ; then
146 # No device specified? Get all the primaries...
147 devices
=$
(ls "${FAKE_IP_STATE}/addresses/"*-primary 2>/dev
/null | \
148 sed -e 's@.*/@@' -e 's@-primary$@@')
152 case "${local#*/}" in
154 brd
="${local%.*}.255"
157 not_implemented
"list ... fake bits other than 24: ${local#*/}"
162 pf
="${FAKE_IP_STATE}/addresses/${dev}-primary"
163 sf
="${FAKE_IP_STATE}/addresses/${dev}-secondary"
165 if $primary && [ -r "$pf" ] ; then
167 if [ -z "$_to" -o "${_to%/*}" = "${local%/*}" ] ; then
170 inet ${local} brd ${brd} scope global ${dev}
174 if $secondary && [ -r "$sf" ] ; then
175 while read local ; do
176 if [ -z "$_to" -o "${_to%/*}" = "${local%/*}" ] ; then
179 inet ${local} brd ${brd} scope global secondary ${dev}
184 if [ -z "$_to" ] ; then
186 valid_lft forever preferred_lft forever
191 for dev
in $devices ; do
192 if [ -z "$_to" ] || \
193 grep -F "${_to%/*}/" "${FAKE_IP_STATE}/addresses/${dev}-"* >/dev
/null
; then
205 while [ -n "$1" ] ; do
214 # For now assume this is always '+'.
215 if [ "$2" != "+" ] ; then
216 not_implemented
"addr add ... brd $2 ..."
227 if [ -z "$dev" ] ; then
228 not_implemented
"addr add (without dev)"
230 mkdir
-p "${FAKE_IP_STATE}/addresses"
231 pf
="${FAKE_IP_STATE}/addresses/${dev}-primary"
232 sf
="${FAKE_IP_STATE}/addresses/${dev}-secondary"
233 # We could lock here... but we should be the only ones playing
234 # around here with these stubs.
235 if [ ! -f "$pf" ] ; then
237 elif grep -Fq "$local" "$pf" ; then
238 echo "RTNETLINK answers: File exists" >&2
240 elif [ -f "$sf" ] && grep -Fq "$local" "$sf" ; then
241 echo "RTNETLINK answers: File exists" >&2
244 echo "$local" >>"$sf"
252 while [ -n "$1" ] ; do
264 not_implemented
"addr del ... $1 ..."
267 if [ -z "$dev" ] ; then
268 not_implemented
"addr del (without dev)"
270 mkdir
-p "${FAKE_IP_STATE}/addresses"
271 pf
="${FAKE_IP_STATE}/addresses/${dev}-primary"
272 sf
="${FAKE_IP_STATE}/addresses/${dev}-secondary"
273 # We could lock here... but we should be the only ones playing
274 # around here with these stubs.
275 if [ ! -f "$pf" ] ; then
276 echo "RTNETLINK answers: Cannot assign requested address" >&2
278 elif grep -Fq "$local" "$pf" ; then
279 # Remove primaries AND SECONDARIES.
281 elif [ -f "$sf" ] && grep -Fq "$local" "$sf" ; then
282 grep -Fv "$local" "$sf" >"${sf}.new"
285 echo "RTNETLINK answers: Cannot assign requested address" >&2
290 ######################################################################
295 show|list|
"") shift ; ip_rule_show
"$@" ;;
296 add
) shift ; ip_rule_add
"$@" ;;
297 del
*) shift ; ip_rule_del
"$@" ;;
298 *) not_implemented
"$1 in \"$orig_args\"" ;;
303 # All non-default rules are in $FAKE_IP_STATE_RULES/rules. As with
304 # the real version, rules can be repeated. Deleting just deletes the
314 # potentially more options
316 printf "%d:\t%s lookup %s \n" $_pre "$_selectors" "$_table"
324 [ -f "${FAKE_IP_STATE}/rules" ] ||
return
326 while read _pre _table _selectors
; do
327 # Only print those in range
328 [ $_min -le $_pre -a $_pre -le $_max ] ||
continue
330 ip_rule_show_1
$_pre "$_table" "$_selectors"
331 done <"${FAKE_IP_STATE}/rules"
334 ip_rule_show_1
0 "local" "from all"
336 ip_rule_show_some
1 32765
338 ip_rule_show_1
32766 "main" "from all"
339 ip_rule_show_1
32767 "default" "from all"
341 ip_rule_show_some
32768 2147483648
349 while [ -n "$1" ] ; do
351 from
) _from
="$2" ; shift 2 ;;
352 pref
) _pre
="$2" ; shift 2 ;;
353 table
) _table
="$2" ; shift 2 ;;
354 *) not_implemented
"$1 in \"$orig_args\"" ;;
358 [ -n "$_pre" ] || not_implemented
"ip rule without \"pref\""
359 ip_check_table
"rule"
360 # Relax this if more selectors added later...
361 [ -n "$_from" ] || not_implemented
"ip rule without \"from\""
368 _f
="${FAKE_IP_STATE}/rules"
372 # Filter order must be consistent with the comparison in ip_rule_del()
373 echo "$_pre $_table${_from:+ from }$_from" >>"$_f"
381 _f
="${FAKE_IP_STATE}/rules"
387 while read _p _t _s
; do
389 [ "$_p" = "$_pre" -a "$_t" = "$_table" -a \
390 "$_s" = "${_from:+from }$_from" ] ; then
391 # Found. Skip this one but not future ones.
394 echo "$_p $_t $_s" >>"$_tmp"
397 if cmp -s "$_tmp" "$_f" ; then
398 # No changes, must not have found what we wanted to delete
399 echo "RTNETLINK answers: No such file or directory" >&2
408 ######################################################################
413 show|list
) shift ; ip_route_show
"$@" ;;
414 flush
) shift ; ip_route_flush
"$@" ;;
415 add
) shift ; ip_route_add
"$@" ;;
416 *) not_implemented
"$1 in \"ip route\"" ;;
422 [ "$1" = table
] || not_implemented
"$1 in \"$orig_args\""
425 ip_check_table
"route"
428 # Routes are in a file per table in the directory
429 # $FAKE_IP_STATE/routes. These routes just use the table ID
430 # that is passed and don't do any lookup. This could be "improved" if
437 # Missing file is just an empty table
438 cat "$FAKE_IP_STATE/routes/${_table}" 2>/dev
/null || true
445 rm -f "$FAKE_IP_STATE/routes/${_table}"
455 while [ -n "$1" ] ; do
457 *.
*.
*.
*/*|
*.
*.
*.
*) _prefix
="$1" ; shift 1 ;;
458 local) _prefix
="$2" ; shift 2 ;;
459 dev
) _dev
="$2" ; shift 2 ;;
460 via
) _gw
="$2" ; shift 2 ;;
461 table
) _table
="$2" ; shift 2 ;;
462 *) not_implemented
"$1 in \"$orig_args\"" ;;
466 ip_check_table
"route"
467 [ -n "$_prefix" ] || not_implemented
"ip route without inet prefix in \"$orig_args\""
468 [ -n "$_dev" ] || not_implemented
"ip route without \"dev\" in \"$orig_args\""
470 # Alias or add missing bits
472 0.0.0.0/0) _prefix
="default" ;;
474 *) _prefix
="${_prefix}/32" ;;
477 _f
="$FAKE_IP_STATE/routes/${_table}"
478 mkdir
-p "$FAKE_IP_STATE/routes"
484 if [ -n "$_gw" ] ; then
485 echo "${_prefix} via ${_gw} dev ${_dev} "
487 echo "${_prefix} dev ${_dev} scope link "
493 ######################################################################
498 link
) shift ; ip_link
"$@" ;;
499 addr
*) shift ; ip_addr
"$@" ;;
500 rule
) shift ; ip_rule
"$@" ;;
501 route
) shift ; ip_route
"$@" ;;
502 *) not_implemented
"$1" ;;