This repository was archived by the owner on Dec 9, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +19
-3
lines changed
Expand file tree Collapse file tree 1 file changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -226,9 +226,25 @@ func (db *DB) netdevToDRAdev(ifName string) (*resourceapi.Device, error) {
226226 }
227227
228228 if ips , err := netlink .AddrList (link , netlink .FAMILY_ALL ); err == nil && len (ips ) > 0 {
229- // TODO assume only one addres by now
230- ip := ips [0 ].IP .String ()
231- device .Basic .Attributes ["ip" ] = resourceapi.DeviceAttribute {StringValue : & ip }
229+ // TODO assume only one address by now but prefer the global ones
230+ var v6found , v4found bool
231+ for _ , address := range ips {
232+ if v4found && v6found {
233+ break
234+ }
235+ if ! address .IP .IsGlobalUnicast () {
236+ continue
237+ }
238+
239+ if address .IP .To4 () == nil && ! v6found {
240+ device .Basic .Attributes ["ipv6" ] = resourceapi.DeviceAttribute {StringValue : ptr .To (address .IP .String ())}
241+ } else if ! v4found {
242+ device .Basic .Attributes ["ip" ] = resourceapi.DeviceAttribute {StringValue : ptr .To (address .IP .String ())}
243+ }
244+ }
245+ if ! v4found {
246+ device .Basic .Attributes ["ip" ] = resourceapi.DeviceAttribute {StringValue : ptr .To (ips [0 ].String ())}
247+ }
232248 mac := link .Attrs ().HardwareAddr .String ()
233249 device .Basic .Attributes ["mac" ] = resourceapi.DeviceAttribute {StringValue : & mac }
234250 mtu := int64 (link .Attrs ().MTU )
You can’t perform that action at this time.
0 commit comments