-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathroutes.awk
More file actions
39 lines (35 loc) · 695 Bytes
/
Copy pathroutes.awk
File metadata and controls
39 lines (35 loc) · 695 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# Pipe `ip r` or `ip -6 r` into this script
# The script returns one route per line.
# Each line consists of three parts (;-delimited):
# - The first part is the route target
# - The second part is the `via` part of the route
# - The third part is the `dev` part of the route
# Both via and dev may be empty.
{
if ($1 == "unreachable" || $1 ~ /^fe80::/)
next
# Parse fields
isVia = 0
isDev = 0
via = ""
dev = ""
for (i=1;i<=NF;i++) {
if (isVia == 1)
via = $i
if (isDev == 1)
dev = $i
# State
if ($i == "via")
isVia = 1
else
isVia = 0
if ($i == "dev")
isDev = 1
else
isDev = 0
}
# No loopback routes
if (dev == "lo")
next
print $1";"via";"dev
}