@@ -213,6 +213,15 @@ func getNetworkConfigs(interfaces []string) ([]string, map[string]*networkConfig
213213 return allinterfaces , links , nil
214214}
215215
216+ func parseIPFromString (portDescription string ) (net.IP , * net.IPNet , error ) {
217+ substrings := strings .Split (portDescription , " " )
218+ if len (substrings ) < 2 {
219+ return nil , nil , fmt .Errorf ("port description field doesn't follow expected format (no-alert CIDR)" )
220+ }
221+
222+ return net .ParseCIDR (substrings [1 ])
223+ }
224+
216225func selectMask30L3Address (nwconfig * networkConfiguration ) (* net.IP , * net.IP , error ) {
217226 var (
218227 peerNetwork * net.IPNet
@@ -221,15 +230,9 @@ func selectMask30L3Address(nwconfig *networkConfiguration) (*net.IP, *net.IP, er
221230 err error
222231 )
223232
224- substrings := strings .Split (nwconfig .portDescription , " " )
225- if len (substrings ) < 2 {
226- return nil , nil , fmt .Errorf ("interface '%s' could not split string '%s'" ,
227- nwconfig .link .Attrs ().Name , nwconfig .portDescription )
228- }
229-
230- peeraddr , peerNetwork , err = net .ParseCIDR (substrings [1 ])
233+ peeraddr , peerNetwork , err = parseIPFromString (nwconfig .portDescription )
231234 if err != nil {
232- return nil , nil , fmt .Errorf ("interface '%s' could not parse '%s': %v" ,
235+ return nil , nil , fmt .Errorf ("interface '%s' could not parse CIDR from port description '%s': %v" ,
233236 nwconfig .link .Attrs ().Name , nwconfig .portDescription , err )
234237 }
235238
0 commit comments