Commit 625b767798470b5890cda834767436c1eda12971

Authored by Georg Hopp
1 parent a549d6e5

get all ips configured on an interface

@@ -73,25 +73,34 @@ gather_if_info_ip() { @@ -73,25 +73,34 @@ gather_if_info_ip() {
73 no=r_if_numbers[if_no]; 73 no=r_if_numbers[if_no];
74 if ($3 == "inet") { 74 if ($3 == "inet") {
75 split($4,addr,/[\/]/); 75 split($4,addr,/[\/]/);
76 - print "IF" no "_IPV4=\"${IF" no "_IPV4}" addr[1] " \";"; 76 + ipv4=ipv4 addr[1] " ";
77 network(no, addr[1], addr[2]); 77 network(no, addr[1], addr[2]);
78 classes=classes addr[1] " " 78 classes=classes addr[1] " "
79 } 79 }
80 if ($3 == "inet6") { 80 if ($3 == "inet6") {
81 split($4,addr,/[\/]/); 81 split($4,addr,/[\/]/);
82 - print "IF" no "_IPV6=\"${IF" no "_IPV6}" addr[1] " \";"; 82 + ipv6=ipv6 addr[1] " ";
83 classes=classes addr[1] " " 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 BEGIN { 94 BEGIN {
87 classes=""; 95 classes="";
88 sub(/^ */,"",if_numbers); 96 sub(/^ */,"",if_numbers);
89 sub(/ *$/,"",if_numbers); 97 sub(/ *$/,"",if_numbers);
90 - split(if_numbers,tmp_array,/ /) 98 + split(if_numbers,tmp_array,/ /);
91 for(no in tmp_array) { 99 for(no in tmp_array) {
92 if_no=tmp_array[no]; 100 if_no=tmp_array[no];
93 r_if_numbers[if_no]=no; 101 r_if_numbers[if_no]=no;
94 } 102 }
  103 + current_if=$1;
95 } 104 }
96 END { 105 END {
97 print "set_class " classes ";" 106 print "set_class " classes ";"
@@ -122,8 +131,8 @@ gather_if_info_ip() { @@ -122,8 +131,8 @@ gather_if_info_ip() {
122 } 131 }
123 } 132 }
124 classes=classes net " "; 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,29 +142,39 @@ gather_if_info_ip() {
133 # 142 #
134 gather_if_info_ifconfig() { 143 gather_if_info_ifconfig() {
135 eval $(${IFCONFIG} -a | ${AWK} ' 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 /^[^ \t]/ { 147 /^[^ \t]/ {
140 - if ("" != ipv4 || "" != ipv6) state="UP"; else state="DOWN"; 148 + if ("UP" == state) classes=classes mac " ";
141 if ("" != name) { 149 if ("" != name) {
142 print "IF" no "_NAME=" name ";IF" no "_STATE=" state ";IF" no "_MAC=" mac ";" \ 150 print "IF" no "_NAME=" name ";IF" no "_STATE=" state ";IF" no "_MAC=" mac ";" \
143 "IF" no "_IPV4=\"${IF" no "_IPV4}" ipv4 " \";" \ 151 "IF" no "_IPV4=\"${IF" no "_IPV4}" ipv4 " \";" \
144 "IF" no "_IPV6=\"${IF" no "_IPV6}" ipv6 " \";"; 152 "IF" no "_IPV6=\"${IF" no "_IPV6}" ipv6 " \";";
145 no++; 153 no++;
146 } 154 }
147 - ipv4=ipv6=""; 155 + ipv4=ipv6=mac="";
148 sub(/:/,"",$1); 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 BEGIN { 166 BEGIN {
  167 + classes="";
  168 + state="DOWN";
152 no=1; 169 no=1;
  170 + mac="";
153 } 171 }
154 END { 172 END {
155 - if ("" != ipv4 || "" != ipv6) state="UP"; else state="DOWN"; 173 + if ("UP" == state) classes=classes mac " ";
156 print "IF" no "_NAME=" name ";IF" no "_STATE=" state ";IF" no "_MAC=" mac ";" \ 174 print "IF" no "_NAME=" name ";IF" no "_STATE=" state ";IF" no "_MAC=" mac ";" \
157 "IF" no "_IPV4=\"${IF" no "_IPV4}" ipv4 " \";" \ 175 "IF" no "_IPV4=\"${IF" no "_IPV4}" ipv4 " \";" \
158 "IF" no "_IPV6=\"${IF" no "_IPV6}" ipv6 " \";"; 176 "IF" no "_IPV6=\"${IF" no "_IPV6}" ipv6 " \";";
  177 + print "set_class " classes ";";
159 print "NINTERFACES=" no 178 print "NINTERFACES=" no
160 }') 179 }')
161 } 180 }
Please register or login to post a comment