Commit 625b767798470b5890cda834767436c1eda12971
1 parent
a549d6e5
get all ips configured on an interface
Showing
1 changed file
with
31 additions
and
12 deletions
... | ... | @@ -73,25 +73,34 @@ gather_if_info_ip() { |
73 | 73 | no=r_if_numbers[if_no]; |
74 | 74 | if ($3 == "inet") { |
75 | 75 | split($4,addr,/[\/]/); |
76 | - print "IF" no "_IPV4=\"${IF" no "_IPV4}" addr[1] " \";"; | |
76 | + ipv4=ipv4 addr[1] " "; | |
77 | 77 | network(no, addr[1], addr[2]); |
78 | 78 | classes=classes addr[1] " " |
79 | 79 | } |
80 | 80 | if ($3 == "inet6") { |
81 | 81 | split($4,addr,/[\/]/); |
82 | - print "IF" no "_IPV6=\"${IF" no "_IPV6}" addr[1] " \";"; | |
82 | + ipv6=ipv6 addr[1] " "; | |
83 | 83 | classes=classes addr[1] " " |
84 | 84 | } |
85 | 85 | } |
86 | + $1 != current_if { | |
87 | + print "IF" no "_IPV4=\"" ipv4 "\";"; | |
88 | + print "IF" no "_IPV6=\"" ipv6 " \";"; | |
89 | + print "IF" no "_NETWORK=\"" net "\";"; | |
90 | + print "IF" no "_MASK=\"" mask "\";"; | |
91 | + current_if=$1; | |
92 | + ipv6=ipv4=""; | |
93 | + } | |
86 | 94 | BEGIN { |
87 | 95 | classes=""; |
88 | 96 | sub(/^ */,"",if_numbers); |
89 | 97 | sub(/ *$/,"",if_numbers); |
90 | - split(if_numbers,tmp_array,/ /) | |
98 | + split(if_numbers,tmp_array,/ /); | |
91 | 99 | for(no in tmp_array) { |
92 | 100 | if_no=tmp_array[no]; |
93 | 101 | r_if_numbers[if_no]=no; |
94 | 102 | } |
103 | + current_if=$1; | |
95 | 104 | } |
96 | 105 | END { |
97 | 106 | print "set_class " classes ";" |
... | ... | @@ -122,8 +131,8 @@ gather_if_info_ip() { |
122 | 131 | } |
123 | 132 | } |
124 | 133 | classes=classes net " "; |
125 | - print "IF" no "_NETWORK=\"" net "\"; export " name "_NETWORK;"; | |
126 | - print "IF" no "_MASK=\"" mask "\"; export " name "_MASK;"; | |
134 | + networks=networks net " "; | |
135 | + netmasks=netmasks mask " "; | |
127 | 136 | }') |
128 | 137 | } |
129 | 138 | |
... | ... | @@ -133,29 +142,39 @@ gather_if_info_ip() { |
133 | 142 | # |
134 | 143 | gather_if_info_ifconfig() { |
135 | 144 | eval $(${IFCONFIG} -a | ${AWK} ' |
136 | - /ether/ { mac=$2 } | |
137 | - /inet / { ipv4=ipv4 $2 " " } | |
138 | - /inet6/ { ipv6=ipv6 $2 " " } | |
145 | + /ether/ { mac=$2 } | |
146 | + /inet / { ipv4=ipv4 $2 " "; classes=classes $2 " " } | |
139 | 147 | /^[^ \t]/ { |
140 | - if ("" != ipv4 || "" != ipv6) state="UP"; else state="DOWN"; | |
148 | + if ("UP" == state) classes=classes mac " "; | |
141 | 149 | if ("" != name) { |
142 | 150 | print "IF" no "_NAME=" name ";IF" no "_STATE=" state ";IF" no "_MAC=" mac ";" \ |
143 | 151 | "IF" no "_IPV4=\"${IF" no "_IPV4}" ipv4 " \";" \ |
144 | 152 | "IF" no "_IPV6=\"${IF" no "_IPV6}" ipv6 " \";"; |
145 | 153 | no++; |
146 | 154 | } |
147 | - ipv4=ipv6=""; | |
155 | + ipv4=ipv6=mac=""; | |
148 | 156 | sub(/:/,"",$1); |
149 | - name=$1 | |
157 | + name=$1; | |
158 | + state="DOWN"; | |
159 | + } | |
160 | + /inet6/ { | |
161 | + sub(/%.*/,"",$2); | |
162 | + ipv6=ipv6 $2 " "; | |
163 | + classes=classes $2 " " | |
150 | 164 | } |
165 | + (/status/ && /active/) || /^lo[0-9]/ { state="UP" } | |
151 | 166 | BEGIN { |
167 | + classes=""; | |
168 | + state="DOWN"; | |
152 | 169 | no=1; |
170 | + mac=""; | |
153 | 171 | } |
154 | 172 | END { |
155 | - if ("" != ipv4 || "" != ipv6) state="UP"; else state="DOWN"; | |
173 | + if ("UP" == state) classes=classes mac " "; | |
156 | 174 | print "IF" no "_NAME=" name ";IF" no "_STATE=" state ";IF" no "_MAC=" mac ";" \ |
157 | 175 | "IF" no "_IPV4=\"${IF" no "_IPV4}" ipv4 " \";" \ |
158 | 176 | "IF" no "_IPV6=\"${IF" no "_IPV6}" ipv6 " \";"; |
177 | + print "set_class " classes ";"; | |
159 | 178 | print "NINTERFACES=" no |
160 | 179 | }') |
161 | 180 | } | ... | ... |
Please
register
or
login
to post a comment