diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-03-05 22:48:49 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-03-05 22:48:49 +0900 |
commit | af7f4d5531f2116e01f36b99611ffdbcc19a8cdd (patch) | |
tree | 5167ba21a7157da964c35d491287459aef214eb3 /config | |
parent | 216e376c34ae38acaff3d01c22ce2eb2f1bc4a08 (diff) |
config: validate route family configuraiton
If not specified, use the same AFI with peer IP address as a default.
To avoid circular import, define BGP_ORIGIN_ATTR_TYPE consts bgp.go
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'config')
-rw-r--r-- | config/default.go | 21 | ||||
-rw-r--r-- | config/serve.go | 7 |
2 files changed, 24 insertions, 4 deletions
diff --git a/config/default.go b/config/default.go index df57103b..5820ef01 100644 --- a/config/default.go +++ b/config/default.go @@ -2,6 +2,7 @@ package config import ( "github.com/BurntSushi/toml" + "github.com/osrg/gobgp/packet" "strings" ) @@ -14,7 +15,7 @@ type neighbor struct { attributes map[string]bool } -func SetDefaultConfigValues(md toml.MetaData, bt *Bgp) { +func SetDefaultConfigValues(md toml.MetaData, bt *Bgp) error { neighbors := []neighbor{} nidx := 0 @@ -40,5 +41,23 @@ func SetDefaultConfigValues(md toml.MetaData, bt *Bgp) { if _, ok := n.attributes["NeighborList.Timers.IdleHoldTimeAfterReset"]; !ok { bt.NeighborList[i].Timers.IdleHoldTimeAfterReset = float64(DEFAULT_IDLE_HOLDTIME_AFTER_RESET) } + + if _, ok := n.attributes["NeighborList.AfiSafiList"]; !ok { + if bt.NeighborList[i].NeighborAddress.To4() != nil { + bt.NeighborList[i].AfiSafiList = []AfiSafi{ + AfiSafi{AfiSafiName: "ipv4-unicast"}} + } else { + bt.NeighborList[i].AfiSafiList = []AfiSafi{ + AfiSafi{AfiSafiName: "ipv6-unicast"}} + } + } else { + for _, rf := range bt.NeighborList[i].AfiSafiList { + _, err := bgp.GetRouteFamily(rf.AfiSafiName) + if err != nil { + return err + } + } + } } + return nil } diff --git a/config/serve.go b/config/serve.go index c4aabdec..6832f6b4 100644 --- a/config/serve.go +++ b/config/serve.go @@ -11,10 +11,11 @@ func ReadConfigfileServe(path string, configCh chan Bgp, reloadCh chan bool) { b := Bgp{} md, err := toml.DecodeFile(path, &b) + if err == nil { + err = SetDefaultConfigValues(md, &b) + } if err != nil { - log.Fatal("can't read config file ", path, err) - } else { - SetDefaultConfigValues(md, &b) + log.Fatal("can't read config file ", path, ", ", err) } configCh <- b |