Skip to content

Commit

Permalink
Merge pull request #894 from tomdee/align-subnets
Browse files Browse the repository at this point in the history
subnet/config.go: Ensure that Subnets are aligned
  • Loading branch information
gunjan5 authored Dec 11, 2017
2 parents 13f01f0 + 5e2caec commit 7257bcc
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion subnet/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func ParseConfig(s string) (*Config, error) {
if cfg.SubnetMin == ip.IP4(0) {
// skip over the first subnet otherwise it causes problems. e.g.
// if Network is 10.100.0.0/16, having an interface with 10.0.0.0
// makes ping think it's a broadcast address (not sure why)
// conflicts with the broadcast address.
cfg.SubnetMin = cfg.Network.IP + subnetSize
} else if !cfg.Network.Contains(cfg.SubnetMin) {
return nil, errors.New("SubnetMin is not in the range of the Network")
Expand All @@ -83,6 +83,16 @@ func ParseConfig(s string) (*Config, error) {
return nil, errors.New("SubnetMax is not in the range of the Network")
}

// The SubnetMin and SubnetMax need to be aligned to a SubnetLen boundary
mask := ip.IP4(0xFFFFFFFF << (32 - cfg.SubnetLen))
if cfg.SubnetMin != cfg.SubnetMin&mask {
return nil, fmt.Errorf("SubnetMin is not on a SubnetLen boundary: %v", cfg.SubnetMin)
}

if cfg.SubnetMax != cfg.SubnetMax&mask {
return nil, fmt.Errorf("SubnetMax is not on a SubnetLen boundary: %v", cfg.SubnetMax)
}

bt, err := parseBackendType(cfg.Backend)
if err != nil {
return nil, err
Expand Down

0 comments on commit 7257bcc

Please sign in to comment.