Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 637394 | Differences between
and this patch

Collapse All | Expand All

(-)a/net/iproute2.sh (-12 / +27 lines)
Lines 204-209 _add_address() Link Here
204
	return $rc
204
	return $rc
205
}
205
}
206
206
207
_filter_metric()
208
{
209
	# ip route show does not allow to filter by metric
210
	# so we need to filter metric manually
211
212
	local metric_value="$1"
213
	shift
214
215
	if [ "${metric_value}" -eq 0 ]; then
216
		# metric 0 is not displayed
217
		ip -o "$@" | fgrep -vsq " metric "
218
	else
219
		# add trailing space for matching
220
		echo "$(ip -o "$@") " | fgrep -sq " metric ${metric_value} "
221
	fi
222
}
223
207
_add_route()
224
_add_route()
208
{
225
{
209
	local family=
226
	local family=
Lines 222-254 _add_route() Link Here
222
	if [ $# -eq 3 ]; then
239
	if [ $# -eq 3 ]; then
223
		set -- "$1" "$2" via "$3"
240
		set -- "$1" "$2" via "$3"
224
	elif [ "$3" = "gw" ]; then
241
	elif [ "$3" = "gw" ]; then
225
		local one=$1 two=$2
242
		local one="$1" two="$2"
226
		shift; shift; shift
243
		shift; shift; shift
227
		set -- "${one}" "${two}" via "$@"
244
		set -- "${one}" "${two}" via "$@"
228
	fi
245
	fi
229
246
230
	local cmd_add= cmd_show= have_metric=false
247
	local cmd_add= cmd_show= metric_value= have_metric=false
231
	while [ -n "$1" ]; do
248
	while [ -n "$1" ]; do
232
		case "$1" in
249
		case "$1" in
233
			metric) metric=$2 ; cmd_add="${cmd_add} metric $2" ; shift ; have_metric=true ;;
250
			metric|preference) metric="$2" ; cmd_add="${cmd_add} metric ${2}" ; metric_value="$2" ; shift ; have_metric=true ;;
234
			netmask) x="/$(_netmask2cidr "$2")" ; cmd_add="${cmd_add}${x}" ; cmd_show="${cmd_show}${x}" ; shift;;
251
			netmask) x="/$(_netmask2cidr "$2")" ; cmd_add="${cmd_add}${x}" ; cmd_show="${cmd_show}${x}" ; shift;;
252
			table|tos) cmd_add="${cmd_add} ${1} ${2}" ; cmd_show="${cmd_show} ${1} ${2}" ; shift;;
235
			-host|-net);;
253
			-host|-net);;
236
			*) cmd_add="${cmd_add} ${1}" ; cmd_show="${cmd_show} ${1}" ;;
254
			*) cmd_add="${cmd_add} ${1}" ;;
237
		esac
255
		esac
238
		shift
256
		shift
239
	done
257
	done
240
258
241
	# We cannot use a metric if we're using a nexthop
259
	# Add interface's metric by default
242
	if ! ${have_metric} && \
260
	if ! ${have_metric} && [ -n "${metric}" ]; then
243
		[ -n "${metric}" -a \
244
			"${cmd_add##* nexthop }" = "${cmd_add}" ]
245
	then
246
		cmd_add="${cmd_add} metric ${metric}"
261
		cmd_add="${cmd_add} metric ${metric}"
262
		metric_value="${metric}"
247
	fi
263
	fi
248
264
249
	# Check for route already existing:
265
	# Check for route already existing:
250
	ip ${family} route show ${cmd_show} dev "${IFACE}" 2>/dev/null | \
266
	_filter_metric "${metric_value}" ${family} route show ${cmd_show} dev "${IFACE}" 2>/dev/null
251
		fgrep -sq "${cmd_add%% *}"
252
	route_already_exists=$?
267
	route_already_exists=$?
253
268
254
	veinfo ip ${family} route append ${cmd_add} dev "${IFACE}"
269
	veinfo ip ${family} route append ${cmd_add} dev "${IFACE}"
Lines 268-274 _add_route() Link Here
268
				*) msgfunc=eerror rc=1 ; eerror "Unknown error behavior: $eh_behavior" ;;
283
				*) msgfunc=eerror rc=1 ; eerror "Unknown error behavior: $eh_behavior" ;;
269
			esac
284
			esac
270
			eval $msgfunc "Route '$cmd_show' already existed:"
285
			eval $msgfunc "Route '$cmd_show' already existed:"
271
			eval $msgfunc \"$(ip $family route show ${cmd_show} dev "${IFACE}" 2>&1)\"
286
			eval $msgfunc "\"$(_filter_metric "${metric_value}" $family route show ${cmd_show} dev "${IFACE}" 2>&1)\""
272
		else
287
		else
273
			: # TODO: Handle other errors
288
			: # TODO: Handle other errors
274
		fi
289
		fi

Return to bug 637394