~juju-qa/ubuntu/xenial/juju/2.0-rc2

« back to all changes in this revision

Viewing changes to src/github.com/juju/juju/network/address.go

  • Committer: Nicholas Skaggs
  • Date: 2016-09-30 14:39:30 UTC
  • mfrom: (1.8.1)
  • Revision ID: nicholas.skaggs@canonical.com-20160930143930-vwwhrefh6ftckccy
import upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
436
436
func publicMatch(addr Address) scopeMatch {
437
437
        switch addr.Scope {
438
438
        case ScopePublic:
 
439
                if addr.Type == IPv4Address {
 
440
                        return exactScopeIPv4
 
441
                }
439
442
                return exactScope
440
443
        case ScopeCloudLocal, ScopeUnknown:
 
444
                if addr.Type == IPv4Address {
 
445
                        return fallbackScopeIPv4
 
446
                }
441
447
                return fallbackScope
442
448
        }
443
449
        return invalidScope
453
459
func cloudLocalMatch(addr Address) scopeMatch {
454
460
        switch addr.Scope {
455
461
        case ScopeCloudLocal:
 
462
                if addr.Type == IPv4Address {
 
463
                        return exactScopeIPv4
 
464
                }
456
465
                return exactScope
457
466
        case ScopePublic, ScopeUnknown:
 
467
                if addr.Type == IPv4Address {
 
468
                        return fallbackScopeIPv4
 
469
                }
458
470
                return fallbackScope
459
471
        }
460
472
        return invalidScope
462
474
 
463
475
func cloudOrMachineLocalMatch(addr Address) scopeMatch {
464
476
        if addr.Scope == ScopeMachineLocal {
 
477
                if addr.Type == IPv4Address {
 
478
                        return exactScopeIPv4
 
479
                }
465
480
                return exactScope
466
481
        }
467
482
        return cloudLocalMatch(addr)
471
486
 
472
487
const (
473
488
        invalidScope scopeMatch = iota
 
489
        exactScopeIPv4
474
490
        exactScope
 
491
        fallbackScopeIPv4
475
492
        fallbackScope
476
493
)
477
494
 
498
515
        matches := filterAndCollateAddressIndexes(numAddr, getAddrFunc, matchFunc)
499
516
 
500
517
        // Retrieve the indexes of the addresses with the best scope and type match.
501
 
        allowedMatchTypes := []scopeMatch{exactScope, fallbackScope}
 
518
        allowedMatchTypes := []scopeMatch{exactScopeIPv4, exactScope, fallbackScopeIPv4, fallbackScope}
502
519
        for _, matchType := range allowedMatchTypes {
503
520
                indexes, ok := matches[matchType]
504
521
                if ok && len(indexes) > 0 {
513
530
        matches := filterAndCollateAddressIndexes(numAddr, getAddrFunc, matchFunc)
514
531
 
515
532
        // Retrieve the indexes of the addresses with the best scope and type match.
516
 
        allowedMatchTypes := []scopeMatch{exactScope, fallbackScope}
 
533
        allowedMatchTypes := []scopeMatch{exactScopeIPv4, exactScope, fallbackScopeIPv4, fallbackScope}
517
534
        var prioritized []int
518
535
        for _, matchType := range allowedMatchTypes {
519
536
                indexes, ok := matches[matchType]
530
547
        for i := 0; i < numAddr; i++ {
531
548
                matchType := matchFunc(getAddrFunc(i))
532
549
                switch matchType {
533
 
                case exactScope, fallbackScope:
 
550
                case exactScopeIPv4, exactScope, fallbackScopeIPv4, fallbackScope:
534
551
                        matches[matchType] = append(matches[matchType], i)
535
552
                }
536
553
        }