From: "Robin H. Johnson" <robbat2@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/netifrc:master commit in: net/
Date: Tue, 14 Nov 2017 20:48:28 +0000 (UTC) [thread overview]
Message-ID: <1510686988.af56301d75988a12c5347b8e9db6812d36f157b4.robbat2@OpenRC> (raw)
commit: af56301d75988a12c5347b8e9db6812d36f157b4
Author: Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
AuthorDate: Tue Nov 14 19:16:28 2017 +0000
Commit: Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
CommitDate: Tue Nov 14 19:16:28 2017 +0000
URL: https://gitweb.gentoo.org/proj/netifrc.git/commit/?id=af56301d
net/iproute2: refactor veinfo+CMD to _cmd helper.
Signed-off-by: Robin H. Johnson <robbat2 <AT> gentoo.org>
net/iproute2.sh | 77 +++++++++++++++++++++++++--------------------------------
1 file changed, 34 insertions(+), 43 deletions(-)
diff --git a/net/iproute2.sh b/net/iproute2.sh
index 7dea195..6d7a3b5 100644
--- a/net/iproute2.sh
+++ b/net/iproute2.sh
@@ -8,16 +8,21 @@ iproute2_depend()
after ifconfig
}
+# This helper exists for the common pattern of 'veinfo $CMD ; $CMD'
+_cmd()
+{
+ veinfo "${@}"
+ "${@}"
+}
+
_up()
{
- veinfo ip link set dev "${IFACE}" up
- ip link set dev "${IFACE}" up
+ _cmd ip link set dev "${IFACE}" up
}
_down()
{
- veinfo ip link set dev "${IFACE}" down
- ip link set dev "${IFACE}" down
+ _cmd ip link set dev "${IFACE}" down
}
_exists()
@@ -59,8 +64,7 @@ _set_flag()
flag=${flag#-}
opt="off"
fi
- veinfo ip link set dev "${IFACE}" "${flag}" "${opt}"
- ip link set dev "${IFACE}" "${flag}" "${opt}"
+ _cmd ip link set dev "${IFACE}" "${flag}" "${opt}"
}
_get_mac_address()
@@ -82,8 +86,7 @@ _get_mac_address()
_set_mac_address()
{
- veinfo ip link set dev "${IFACE}" address "$1"
- ip link set dev "${IFACE}" address "$1"
+ _cmd ip link set dev "${IFACE}" address "$1"
}
_get_inet_addresses()
@@ -102,8 +105,7 @@ _get_inet_address()
_add_address()
{
if [ "$1" = "127.0.0.1/8" -a "${IFACE}" = "lo" ]; then
- veinfo ip addr add "$@" dev "${IFACE}" 2>/dev/null
- ip addr add "$@" dev "${IFACE}" 2>/dev/null
+ _cmd ip addr add "$@" dev "${IFACE}" 2>/dev/null
return 0
fi
local x
@@ -179,8 +181,7 @@ _add_address()
# This must appear on a single line, continuations cannot be used
set -- "${address}${netmask:+/}${netmask}" ${peer:+peer} ${peer} ${broadcast:+broadcast} ${broadcast} ${anycast:+anycast} ${anycast} ${label:+label} ${label} ${scope:+scope} ${scope} dev "${IFACE}" ${valid_lft:+valid_lft} $valid_lft ${preferred_lft:+preferred_lft} $preferred_lft $confflaglist
- veinfo ip addr add "$@"
- ip addr add "$@"
+ _cmd ip addr add "$@"
rc=$?
# Check return code in some cases
if [ $rc -ne 0 ]; then
@@ -251,8 +252,7 @@ _add_route()
fgrep -sq "${cmd%% *}"
route_already_exists=$?
- veinfo ip ${family} route append ${cmd} dev "${IFACE}"
- ip ${family} route append ${cmd} dev "${IFACE}"
+ _cmd ip ${family} route append ${cmd} dev "${IFACE}"
rc=$?
# Check return code in some cases
if [ $rc -ne 0 ]; then
@@ -278,13 +278,10 @@ _add_route()
_delete_addresses()
{
- veinfo ip addr flush dev "${IFACE}" scope global 2>/dev/null
- ip addr flush dev "${IFACE}" scope global 2>/dev/null
- veinfo ip addr flush dev "${IFACE}" scope site 2>/dev/null
- ip addr flush dev "${IFACE}" scope site 2>/dev/null
+ _cmd ip addr flush dev "${IFACE}" scope global 2>/dev/null
+ _cmd ip addr flush dev "${IFACE}" scope site 2>/dev/null
if [ "${IFACE}" != "lo" ]; then
- veinfo ip addr flush dev "${IFACE}" scope host 2>/dev/null
- ip addr flush dev "${IFACE}" scope host 2>/dev/null
+ _cmd ip addr flush dev "${IFACE}" scope host 2>/dev/null
fi
return 0
}
@@ -294,10 +291,10 @@ _has_carrier()
LC_ALL=C ip link show dev "${IFACE}" | grep -q "LOWER_UP"
}
+# Used by iproute2, ip6rd & ip6to4
_tunnel()
{
- veinfo ip tunnel "$@"
- ip tunnel "$@"
+ _cmd ip $FAMILY tunnel "$@"
rc=$?
# TODO: check return code in some cases
return $rc
@@ -349,8 +346,7 @@ _iproute2_policy_routing()
_ip_rule_runner -4 add "${rules}"
fi
fi
- veinfo ip -4 route flush table cache dev "${IFACE}"
- ip -4 route flush table cache dev "${IFACE}"
+ FAMILY="-4" IFACE="${IFACE}" _iproute2_route_flush
fi
# Kernel may not have IPv6 built in
@@ -365,8 +361,7 @@ _iproute2_policy_routing()
_ip_rule_runner -6 add "${rules}"
fi
fi
- veinfo ip -6 route flush table cache dev "${IFACE}"
- ip -6 route flush table cache dev "${IFACE}"
+ FAMILY="-6" IFACE="${IFACE}" _iproute2_route_flush
fi
}
@@ -388,8 +383,7 @@ iproute2_pre_start()
esac
ebegin "Creating tunnel ${IFVAR}"
- veinfo ip ${ipproto} tunnel add ${tunnel} name "${IFACE}"
- ip ${ipproto} tunnel add ${tunnel} name "${IFACE}"
+ _cmd ip ${ipproto} tunnel add ${tunnel} name "${IFACE}"
eend $? || return 1
_up
fi
@@ -404,8 +398,7 @@ iproute2_pre_start()
esac
ebegin "Creating interface ${IFVAR}"
- veinfo ip ${ipproto} link add "${IFACE}" ${link}
- ip ${ipproto} link add "${IFACE}" ${link}
+ _cmd ip ${ipproto} link add "${IFACE}" ${link}
eend $? || return 1
_up
fi
@@ -414,16 +407,14 @@ iproute2_pre_start()
local mtu=
eval mtu=\$mtu_${IFVAR}
if [ -n "${mtu}" ]; then
- veinfo ip link set dev "${IFACE}" mtu "${mtu}"
- ip link set dev "${IFACE}" mtu "${mtu}"
+ _cmd ip link set dev "${IFACE}" mtu "${mtu}"
fi
# TX Queue Length support
local len=
eval len=\$txqueuelen_${IFVAR}
if [ -n "${len}" ]; then
- veinfo ip link set dev "${IFACE}" txqueuelen "${len}"
- ip link set dev "${IFACE}" txqueuelen "${len}"
+ _cmd ip link set dev "${IFACE}" txqueuelen "${len}"
fi
local policyroute_order=
@@ -436,18 +427,20 @@ iproute2_pre_start()
_iproute2_tunnel_delete() {
ebegin "Destroying tunnel $1"
- veinfo ip $2 tunnel del "$1"
- ip $2 tunnel del "$1"
+ _tunnel del "$1"
eend $?
}
_iproute2_link_delete() {
ebegin "Destroying interface $1"
- veinfo ip link del dev "$1"
- ip link del dev "$1"
+ _cmd ip $FAMILY link del dev "$1"
eend $?
}
+_iproute2_route_flush() {
+ _cmd ip $FAMILY route flush table cache dev "${IFACE}"
+}
+
_iproute2_ipv6_tentative()
{
[ -n "$(LC_ALL=C ip -family inet6 addr show dev ${IFACE} tentative)" ] && return 0
@@ -502,8 +495,7 @@ iproute2_post_stop()
# Only do something if the interface actually exist
if _exists; then
- veinfo ip -4 route flush table cache dev "${IFACE}"
- ip -4 route flush table cache dev "${IFACE}"
+ FAMILY="-4" IFACE="${IFACE}" _iproute2_route_flush
fi
fi
@@ -517,8 +509,7 @@ iproute2_post_stop()
# Only do something if the interface actually exist
if _exists; then
- veinfo ip -6 route flush table cache dev "${IFACE}"
- ip -6 route flush table cache dev "${IFACE}"
+ FAMILY="-6" IFACE="${IFACE}" _iproute2_route_flush
fi
fi
@@ -527,7 +518,7 @@ iproute2_post_stop()
if [ -n "$(ip tunnel show "${IFACE}" 2>/dev/null)" ]; then
_iproute2_tunnel_delete "${IFACE}"
elif [ -n "$(ip -6 tunnel show "${IFACE}" 2>/dev/null)" ]; then
- _iproute2_tunnel_delete "${IFACE}" -6
+ FAMILY=-6 _iproute2_tunnel_delete "${IFACE}"
fi
[ -n "$(ip link show "${IFACE}" type gretap 2>/dev/null)" ] && _iproute2_link_delete "${IFACE}"
next reply other threads:[~2017-11-14 20:48 UTC|newest]
Thread overview: 112+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-14 20:48 Robin H. Johnson [this message]
-- strict thread matches above, loose matches on Subject: below --
2025-03-18 21:50 [gentoo-commits] proj/netifrc:master commit in: net/ Sam James
2025-03-18 21:50 Sam James
2025-03-18 21:50 Sam James
2024-09-29 0:28 Sam James
2024-09-23 12:02 Sam James
2024-09-09 22:43 Patrick McLean
2024-09-01 9:22 Sam James
2024-09-01 9:21 Sam James
2024-08-28 18:54 Patrick McLean
2024-06-11 0:39 Patrick McLean
2024-06-11 0:39 Patrick McLean
2024-05-23 18:12 Patrick McLean
2023-11-26 5:31 Robin H. Johnson
2023-11-25 4:52 Robin H. Johnson
2023-10-19 22:57 Sam James
2023-09-10 15:15 Sam James
2023-05-29 0:17 Mike Gilbert
2023-04-19 17:14 Robin H. Johnson
2023-04-17 4:35 Sam James
2023-02-12 6:54 Sam James
2023-01-19 18:50 Sam James
2023-01-19 18:50 Sam James
2023-01-17 15:06 Sam James
2023-01-17 15:06 Sam James
2023-01-17 15:06 Sam James
2023-01-15 20:37 Sam James
2023-01-15 14:03 Sam James
2023-01-15 14:03 Sam James
2023-01-15 1:53 Sam James
2023-01-15 1:51 Sam James
2023-01-15 1:51 Sam James
2022-12-25 19:14 Robin H. Johnson
2022-12-25 19:07 Robin H. Johnson
2021-03-31 1:11 Patrick McLean
2021-03-11 16:54 Lars Wendler
2021-03-11 16:54 Lars Wendler
2021-03-11 16:54 Lars Wendler
2021-02-02 8:28 Lars Wendler
2021-01-27 16:55 Lars Wendler
2021-01-27 14:19 Lars Wendler
2021-01-27 14:06 Lars Wendler
2021-01-24 10:37 Lars Wendler
2021-01-18 14:40 Lars Wendler
2021-01-18 13:04 Lars Wendler
2021-01-18 12:33 Lars Wendler
2021-01-18 12:33 Lars Wendler
2021-01-05 14:27 Lars Wendler
2021-01-05 12:46 Lars Wendler
2021-01-05 12:46 Lars Wendler
2020-12-15 20:11 Lars Wendler
2020-06-02 21:54 Robin H. Johnson
2020-05-31 6:05 Robin H. Johnson
2020-05-31 5:42 Robin H. Johnson
2020-05-31 5:29 Robin H. Johnson
2020-05-31 5:29 Robin H. Johnson
2020-05-31 5:13 Robin H. Johnson
2020-05-31 5:13 Robin H. Johnson
2020-01-04 8:06 Robin H. Johnson
2020-01-04 7:59 Robin H. Johnson
2019-07-09 19:59 Ben Kohler
2019-07-09 19:59 Ben Kohler
2019-07-09 17:39 Ben Kohler
2019-04-21 4:11 Robin H. Johnson
2018-07-12 6:25 Robin H. Johnson
2018-07-10 21:11 Jason Donenfeld
2018-01-21 21:59 Robin H. Johnson
2017-11-27 20:22 Robin H. Johnson
2017-11-27 20:22 Robin H. Johnson
2017-11-14 20:48 Robin H. Johnson
2017-10-21 20:56 Robin H. Johnson
2017-06-09 23:59 Robin H. Johnson
2017-06-09 23:55 Robin H. Johnson
2017-06-09 23:52 Robin H. Johnson
2017-06-09 23:52 Robin H. Johnson
2017-01-27 21:54 Robin H. Johnson
2016-10-27 1:23 Robin H. Johnson
2016-10-24 23:16 Robin H. Johnson
2016-10-24 20:58 Robin H. Johnson
2016-10-24 16:49 Robin H. Johnson
2016-10-24 0:25 Robin H. Johnson
2016-10-24 0:23 Robin H. Johnson
2016-10-24 0:23 Robin H. Johnson
2016-10-24 0:04 Robin H. Johnson
2016-10-24 0:04 Robin H. Johnson
2016-10-23 23:50 Robin H. Johnson
2016-10-23 23:50 Robin H. Johnson
2016-10-23 23:50 Robin H. Johnson
2016-10-23 22:39 Robin H. Johnson
2016-10-23 22:39 Robin H. Johnson
2016-10-05 14:42 Robin H. Johnson
2016-07-19 19:59 Robin H. Johnson
2016-07-05 18:14 Robin H. Johnson
2016-07-05 18:14 Robin H. Johnson
2016-07-05 18:14 Robin H. Johnson
2016-07-05 18:09 Robin H. Johnson
2015-11-08 14:33 Robin H. Johnson
2015-11-08 14:30 Robin H. Johnson
2015-05-25 10:04 Mike Frysinger
2015-05-25 10:04 Mike Frysinger
2015-05-25 10:04 Mike Frysinger
2015-05-25 10:01 Mike Frysinger
2015-01-22 23:01 Robin H. Johnson
2015-01-22 23:01 Robin H. Johnson
2014-12-11 18:13 Robin H. Johnson
2014-09-24 6:19 Robin H. Johnson
2014-07-17 17:56 Robin H. Johnson
2014-07-17 17:56 Robin H. Johnson
2014-04-15 18:18 Robin H. Johnson
2013-08-28 16:59 Robin H. Johnson
2013-08-27 20:06 Ian Stakenvicius
2013-08-25 8:17 Robin H. Johnson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1510686988.af56301d75988a12c5347b8e9db6812d36f157b4.robbat2@OpenRC \
--to=robbat2@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox