mirror of
https://github.com/alice-lg/alice-lg.git
synced 2024-05-11 05:55:03 +00:00
include own asn in server section
This commit is contained in:
@@ -25,6 +25,8 @@ type CacheableResponse interface {
|
||||
|
||||
// Config
|
||||
type ConfigResponse struct {
|
||||
Asn int `json:"asn"`
|
||||
|
||||
Rejection Rejection `json:"rejection"`
|
||||
RejectReasons map[string]string `json:"reject_reasons"`
|
||||
|
||||
@@ -104,7 +106,6 @@ type StatusResponse struct {
|
||||
type Routeserver struct {
|
||||
Id int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Asn int `json:"asn"`
|
||||
Blackholes []string `json:"blackholes"`
|
||||
}
|
||||
|
||||
|
@@ -17,7 +17,6 @@ func apiRouteserversList(_req *http.Request, _params httprouter.Params) (api.Res
|
||||
routeservers = append(routeservers, api.Routeserver{
|
||||
Id: source.Id,
|
||||
Name: source.Name,
|
||||
Asn: source.Asn,
|
||||
Blackholes: source.Blackholes,
|
||||
})
|
||||
}
|
||||
|
@@ -21,6 +21,7 @@ type ServerConfig struct {
|
||||
EnablePrefixLookup bool `ini:"enable_prefix_lookup"`
|
||||
NeighboursStoreRefreshInterval int `ini:"neighbours_store_refresh_interval"`
|
||||
RoutesStoreRefreshInterval int `ini:"routes_store_refresh_interval"`
|
||||
Asn int `ini:"asn"`
|
||||
}
|
||||
|
||||
type RejectionsConfig struct {
|
||||
@@ -88,7 +89,6 @@ type PaginationConfig struct {
|
||||
type SourceConfig struct {
|
||||
Id int
|
||||
Name string
|
||||
Asn int
|
||||
|
||||
// Blackhole IPs
|
||||
Blackholes []string
|
||||
@@ -350,7 +350,7 @@ func getRpkiConfig(config *ini.File) (RpkiConfig, error) {
|
||||
fallbackAsn, err := getOwnASN(config)
|
||||
if err != nil {
|
||||
log.Println(
|
||||
"Could not derive own ASN.",
|
||||
"Own ASN is not configured.",
|
||||
"This might lead to unexpected behaviour with BGP large communities",
|
||||
)
|
||||
}
|
||||
@@ -395,21 +395,15 @@ func getRpkiConfig(config *ini.File) (RpkiConfig, error) {
|
||||
return rpki, nil
|
||||
}
|
||||
|
||||
// Helper: Get own ASN
|
||||
// - Try to determine own ASN, for now it is most
|
||||
// likely configured in the rejection or noexport section
|
||||
//
|
||||
// Helper: Get own ASN from ini
|
||||
// This is now easy, since we enforce an ASN in
|
||||
// the [server] section.
|
||||
func getOwnASN(config *ini.File) (int, error) {
|
||||
noexport := config.Section("noexport")
|
||||
rejection := config.Section("rejection")
|
||||
|
||||
asn := rejection.Key("asn").MustInt(-1)
|
||||
if asn == -1 {
|
||||
asn = noexport.Key("asn").MustInt(-1)
|
||||
}
|
||||
server := config.Section("server")
|
||||
asn := server.Key("asn").MustInt(-1)
|
||||
|
||||
if asn == -1 {
|
||||
return 0, fmt.Errorf("Could not derive own ASN from config")
|
||||
return 0, fmt.Errorf("Could not get own ASN from config")
|
||||
}
|
||||
|
||||
return asn, nil
|
||||
@@ -573,25 +567,14 @@ func getSources(config *ini.File) ([]*SourceConfig, error) {
|
||||
return sources, fmt.Errorf("%s has an unsupported backend", section.Name())
|
||||
}
|
||||
|
||||
// Get fallback ASN
|
||||
fallbackAsn, err := getOwnASN(config)
|
||||
if err != nil {
|
||||
log.Println(
|
||||
"Could not derive own ASN.",
|
||||
"This might lead to unexpected behaviour with BGP large communities",
|
||||
)
|
||||
}
|
||||
|
||||
// Make config
|
||||
sourceName := section.Key("name").MustString("Unknown Source")
|
||||
sourceBlackholes := TrimmedStringList(
|
||||
section.Key("blackholes").MustString(""))
|
||||
sourceAsn := section.Key("asn").MustInt(fallbackAsn)
|
||||
|
||||
config := &SourceConfig{
|
||||
Id: sourceId,
|
||||
Name: sourceName,
|
||||
Asn: sourceAsn,
|
||||
Blackholes: sourceBlackholes,
|
||||
Type: backendType,
|
||||
}
|
||||
|
@@ -88,21 +88,14 @@ func TestBlackholeParsing(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSourceASN(t *testing.T) {
|
||||
func TestOwnASN(t *testing.T) {
|
||||
config, err := loadConfig("../etc/alicelg/alice.example.conf")
|
||||
if err != nil {
|
||||
t.Error("Could not load test config:", err)
|
||||
}
|
||||
|
||||
// Get sources
|
||||
rs1 := config.Sources[0]
|
||||
if rs1.Asn != 99999 {
|
||||
t.Error("Expected RS1 ASN to be: 99999, not:", rs1.Asn)
|
||||
}
|
||||
|
||||
rs2 := config.Sources[1]
|
||||
if rs2.Asn != 9033 {
|
||||
t.Error("Expected RS2 to fall back to AS9033, not:", rs2.Asn)
|
||||
if config.Server.Asn != 9033 {
|
||||
t.Error("Expected a set server asn")
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user