mirror of
https://github.com/alice-lg/alice-lg.git
synced 2024-05-11 05:55:03 +00:00
improved communities parsing
This commit is contained in:
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -307,11 +308,19 @@ func getBgpCommunities(config *ini.File) BgpCommunities {
|
|||||||
return communities // nothing else to do here, go with the default
|
return communities // nothing else to do here, go with the default
|
||||||
}
|
}
|
||||||
|
|
||||||
keys := communitiesConfig.Keys()
|
// Parse and merge communities
|
||||||
// Merge communities
|
lines := strings.Split(communitiesConfig.Body(), "\n")
|
||||||
for _, key := range keys {
|
for _, line := range lines {
|
||||||
community := strings.Replace(key.Name(), "_", ":", -1)
|
kv := strings.SplitN(line, "=", 2)
|
||||||
communities[community] = communitiesConfig.Key(key.Name()).MustString("")
|
if len(kv) != 2 {
|
||||||
|
log.Println("Skipping malformed BGP community:", line)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
community := strings.TrimSpace(kv[0])
|
||||||
|
label := strings.TrimSpace(kv[1])
|
||||||
|
|
||||||
|
communities[community] = label
|
||||||
}
|
}
|
||||||
|
|
||||||
return communities
|
return communities
|
||||||
@ -484,7 +493,11 @@ func loadConfig(file string) (*Config, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
parsedConfig, err := ini.LooseLoad(file)
|
// Load configuration, but handle bgp communities section
|
||||||
|
// with our own parser
|
||||||
|
parsedConfig, err := ini.LoadSources(ini.LoadOptions{
|
||||||
|
UnparseableSections: []string{"bgp_communities"},
|
||||||
|
}, file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -46,10 +46,10 @@ load_on_demand = true # Default: false
|
|||||||
7 = The Sender has set (peerRTTLowerDeny:ms) and the targets RTT ms <= then the ms in the community
|
7 = The Sender has set (peerRTTLowerDeny:ms) and the targets RTT ms <= then the ms in the community
|
||||||
|
|
||||||
# Define Known Bgp Communities
|
# Define Known Bgp Communities
|
||||||
# Caveat: The usual : must be substitued by a _ because of ini parsing limitations.
|
|
||||||
[bgp_communities]
|
[bgp_communities]
|
||||||
1_23 = some tag
|
1:23 = some tag
|
||||||
9033_65666_1 = ip bogon detected
|
# Another
|
||||||
|
9033:65666:1 = ip bogon detected
|
||||||
|
|
||||||
#
|
#
|
||||||
# Define columns for neighbours and routes table,
|
# Define columns for neighbours and routes table,
|
||||||
|
Reference in New Issue
Block a user