forked from scionproto/scion
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Marc Odermatt
committed
Aug 7, 2024
1 parent
be0252c
commit a6a2198
Showing
1 changed file
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright 2018 ETH Zurich, Anapaya Systems | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package combinator | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/scionproto/scion/pkg/addr" | ||
"github.com/scionproto/scion/pkg/experimental/fabrid" | ||
fabrid_ext "github.com/scionproto/scion/pkg/segment/extensions/fabrid" | ||
"github.com/scionproto/scion/pkg/snet" | ||
) | ||
|
||
// We go through the list of ASEntries and store for each IA a pointer to the FABRID | ||
// Map found in the ASEntries' extensions. If there is already a map stored, check the info time, | ||
// and replace with the newer FABRID maps. This results in a map[IA]FabridMapEntry, which can be | ||
// used to find the policies that are available for each of the interface pairs on the path. | ||
type FabridMapEntry struct { | ||
Map *fabrid_ext.Detached | ||
Ts time.Time | ||
// The Digest of the Fabrid Maps, this can be empty. | ||
Digest []byte | ||
} | ||
|
||
func GetFabridInfoForIntfs(ia addr.IA, ig, eg uint16, maps map[addr.IA]FabridMapEntry, | ||
allowIpPolicies bool) *snet.FabridInfo { | ||
policies := make([]*fabrid.Policy, 0) | ||
fabridMap, exist := maps[ia] | ||
if !exist { | ||
return &snet.FabridInfo{ | ||
Enabled: false, | ||
Policies: policies, | ||
Digest: []byte{}, | ||
Detached: false, | ||
} | ||
} else if fabridMap.Map == nil { | ||
return &snet.FabridInfo{ | ||
Enabled: true, | ||
Policies: policies, | ||
Digest: fabridMap.Digest, | ||
Detached: len(fabridMap.Digest) > 0, | ||
} | ||
} | ||
for k, v := range fabridMap.Map.SupportedIndicesMap { | ||
if !k.Matches(ig, eg, allowIpPolicies) { | ||
continue | ||
} | ||
for _, policy := range v { | ||
val, ok := fabridMap.Map.IndexIdentiferMap[policy] | ||
if !ok { | ||
continue | ||
} | ||
policies = append(policies, &fabrid.Policy{ | ||
IsLocal: val.IsLocal, | ||
Identifier: val.Identifier, | ||
Index: fabrid.PolicyID(policy), | ||
}) | ||
|
||
} | ||
} | ||
|
||
return &snet.FabridInfo{ | ||
Enabled: true, | ||
Policies: policies, | ||
Digest: fabridMap.Digest, | ||
Detached: false, | ||
} | ||
} |