Documentation
¶
Overview ¶
+groupName=maps
Index ¶
- Constants
- Variables
- func OpenPolicyMap(logger *slog.Logger, path string) (*policyMap, error)
- func RemoveGlobalMapping(logger *slog.Logger, id uint32) error
- type CallKey
- type CallValue
- type Factory
- type PlumbingKey
- type PlumbingValue
- type PolicyConfig
- type PolicyEntriesDump
- type PolicyEntry
- type PolicyEntryDump
- type PolicyKey
- type PolicyMap
- type PolicyPlumbingMap
- type StatsKey
- type StatsMap
- type StatsValue
- type StatsValues
Constants ¶
const ( PolicyMapMaxName = "bpf-policy-map-max" PolicyStatsMapMaxName = "bpf-policy-stats-map-max" )
const ( // PolicyCallMapName is the name of the map to do tail calls into policy // enforcement programs. PolicyCallMapName = "cilium_call_policy" // PolicyEgressCallMapName is the name of the map to do tail calls into egress policy // enforcement programs. PolicyEgressCallMapName = "cilium_egresscall_policy" // MapName is the prefix for endpoint-specific policy maps which map // identity+ports+direction to whether the policy allows communication // with that identity on that port for that direction. // // This MUST be changed each time there is a bpf format change OR semantic change with the // existing map layout in the policy map as interpreted by the bpf programs. Renaming leads // to clean separation with the old map and program vs. the new map and program. // // Whenever this is changed, leave a comment here: // "_v2_": removal of policy accounting fields and addition of the precedence field // to the policy map value. // "_v3_": semantic change due to policy identity aggregation. MapName = "cilium_policy_v3_" // PolicyCallMaxEntries is the upper limit of entries in the program // array for the tail calls to jump into the endpoint specific policy // programs. This number *MUST* be identical to the maximum endpoint ID. PolicyCallMaxEntries = ^uint16(0) // AllPorts is used to ignore the L4 ports in PolicyMap lookups; all ports // are allowed. In the datapath, this is represented with the value 0 in the // port field of map elements. AllPorts = uint16(0) // SinglePortPrefixLen represents the mask argument required to lookup or // insert a single port key into the bpf map. SinglePortPrefixLen = uint8(16) )
const ( NexthdrBits = uint8(sizeofNexthdr) * 8 DestPortBits = uint8(sizeofDestPort) * 8 FullPrefixBits = NexthdrBits + DestPortBits StaticPrefixBits = uint32(sizeofPolicyKey-sizeofPrefixlen)*8 - uint32(FullPrefixBits) )
const ( // Name is the canonical name for the policy stats map on the filesystem. // Note: There is no underscore between 'policy' and 'stats' as that would confuse tools // trying to parse an endpoint ID from 'stats'. StatsMapName = "cilium_policystats" StatNotAvailable = uint64(math.MaxUint64) )
Variables ¶
var Cell = cell.Module( "policymap", "Policymap provides access to the datapath policy maps", cell.Config(DefaultPolicyConfig), cell.Provide(createFactory), )
var DefaultPolicyConfig = PolicyConfig{
BpfPolicyMapMax: 16384,
BpfPolicyStatsMapMax: 1 << 16,
}
Functions ¶
func OpenPolicyMap ¶ added in v1.18.0
OpenPolicyMap opens the policymap at the specified path. This is only used from the 'cilium-dbg bpf policy' tool.
Types ¶
type CallKey ¶ added in v0.15.7
type CallKey struct {
Index uint32
}
CallKey is the index into the prog array map.
type CallValue ¶ added in v0.15.7
type CallValue struct {
ProgID uint32
}
CallValue is the program ID in the prog array map.
type PlumbingKey ¶ added in v0.15.7
type PlumbingKey struct {
Key uint32
}
func (*PlumbingKey) New ¶ added in v0.15.7
func (k *PlumbingKey) New() bpf.MapKey
func (*PlumbingKey) String ¶ added in v0.15.7
func (k *PlumbingKey) String() string
type PlumbingValue ¶ added in v0.15.7
type PlumbingValue struct {
Fd uint32
}
func (*PlumbingValue) New ¶ added in v0.15.7
func (k *PlumbingValue) New() bpf.MapValue
func (*PlumbingValue) String ¶ added in v0.15.7
func (v *PlumbingValue) String() string
type PolicyConfig ¶ added in v1.18.0
type PolicyConfig struct {
// BpfPolicyMapMax is the maximum number of peer identities that an
// endpoint may allow traffic to exchange traffic with.
BpfPolicyMapMax int
// PolicyStatsMapMax is the maximum number of entries allowed in a BPF policy map.
BpfPolicyStatsMapMax int
}
func (PolicyConfig) Flags ¶ added in v1.18.0
func (def PolicyConfig) Flags(flags *pflag.FlagSet)
type PolicyEntriesDump ¶ added in v0.15.7
type PolicyEntriesDump []PolicyEntryDump
PolicyEntriesDump is a wrapper for a slice of PolicyEntryDump
func (PolicyEntriesDump) Less ¶ added in v0.15.7
func (p PolicyEntriesDump) Less(i, j int) bool
Less is a function used to sort PolicyEntriesDump by Policy Type (Deny / Allow), TrafficDirection (Ingress / Egress) and Identity (ascending order).
func (PolicyEntriesDump) String ¶ added in v0.15.7
func (p PolicyEntriesDump) String() string
String returns a string representation of PolicyEntriesDump
type PolicyEntry ¶
type PolicyEntry struct {
ProxyPortNetwork uint16 `align:"proxy_port"` // In network byte-order
Flags policyEntryFlags `align:"deny"`
AuthRequirement policyTypes.AuthRequirement `align:"auth_type"`
Precedence policyTypes.Precedence `align:"precedence"`
Cookie uint32 `align:"cookie"`
}
PolicyEntry represents an entry in the BPF policy map for an endpoint.
Must be in sync with struct policy_entry in <bpf/lib/policy.h>
func NewEntryFromPolicyEntry ¶ added in v1.18.0
func NewEntryFromPolicyEntry(key PolicyKey, pe policyTypes.MapStateEntry) PolicyEntry
NewEntryFromPolicyEntry converts a policy MapState entry to a PolicyMap entry.
func (*PolicyEntry) GetPrefixLen ¶ added in v1.16.4
func (pe *PolicyEntry) GetPrefixLen() uint8
GetPrefixLen returns the prefix length for the protocol / destination port (0 to 24 bits, 8 bits for unwildcarded protocol + 0 - 16 bits for the port)
func (*PolicyEntry) GetProxyPort ¶ added in v0.15.7
func (pe *PolicyEntry) GetProxyPort() uint16
GetProxyPort returns the ProxyPortNetwork in host byte order
func (PolicyEntry) IsDeny ¶ added in v0.15.7
func (pe PolicyEntry) IsDeny() bool
func (*PolicyEntry) IsValid ¶ added in v1.17.0
func (v *PolicyEntry) IsValid(k *PolicyKey) bool
func (*PolicyEntry) New ¶ added in v0.15.7
func (pe *PolicyEntry) New() bpf.MapValue
func (*PolicyEntry) String ¶
func (pe *PolicyEntry) String() string
type PolicyEntryDump ¶
type PolicyEntryDump struct {
PolicyEntry
StatsValue
Key PolicyKey
}
type PolicyKey ¶ added in v0.15.7
type PolicyKey struct {
Prefixlen uint32 `align:"lpm_key"`
Identity uint32 `align:"sec_label"`
TrafficDirection uint8 `align:"egress"`
Nexthdr uint8 `align:"protocol"`
DestPortNetwork uint16 `align:"dport"` // In network byte-order
}
PolicyKey represents a key in the BPF policy map for an endpoint.
Must be in sync with struct policy_key in <bpf/lib/policy.h>
func NewKeyFromPolicyKey ¶ added in v1.18.0
func NewKeyFromPolicyKey(pk policyTypes.Key) PolicyKey
NewKeyFromPolicyKey converts a policy MapState key to a bpf PolicyMap key.
func (*PolicyKey) GetDestPort ¶ added in v0.15.7
GetDestPort returns the DestPortNetwork in host byte order
func (*PolicyKey) GetPortMask ¶ added in v1.16.0
GetPortMask returns the port mask of the key
func (*PolicyKey) GetPortPrefixLen ¶ added in v1.17.0
GetPortPrefixLen returns the prefix length applicable to the port in the key
func (*PolicyKey) GetPrefixLen ¶ added in v1.18.0
GetPrefixLen returns the prefix length applicable to the protocol and port in the key
func (*PolicyKey) PortProtoString ¶ added in v0.15.7
type PolicyMap ¶
type PolicyMap interface {
Update(key *PolicyKey, entry *PolicyEntry) error
DeleteKey(key PolicyKey) error
DeleteEntry(entry *PolicyEntryDump) error
String() string
Dump() (string, error)
DumpToSlice() (PolicyEntriesDump, error)
DumpToMapStateMap() (policyTypes.MapStateMap, error)
MaxEntries() uint32
Close() error
}
type PolicyPlumbingMap ¶ added in v0.15.7
PolicyPlumbingMap maps endpoint IDs to the fd for the program which implements its policy.
func OpenCallMap ¶ added in v0.15.7
func OpenCallMap(logger *slog.Logger, name string) (*PolicyPlumbingMap, error)
OpenCallMap opens the map that maps endpoint IDs to program file descriptors, which allows tail calling into the policy datapath code from other BPF programs.
type StatsMap ¶ added in v1.18.0
PolicyStatsMap maps endpoint IDs to the fd for the program which implements its policy.
func OpenStatsMap ¶ added in v1.18.0
OpenStatsMap opens the existing global policy stats map. Should only be called from cilium-dbg
func (*StatsMap) ClearStat ¶ added in v1.18.0
ClearStat removes stats for the given endpoint and policy key
type StatsValue ¶ added in v1.18.0
func (*StatsValue) String ¶ added in v1.18.0
func (v *StatsValue) String() string
type StatsValues ¶ added in v1.18.0
type StatsValues []StatsValue
StatsMap is a per-CPU map, so the value is a slice