-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
l2_announce.go
81 lines (68 loc) · 1.71 KB
/
l2_announce.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Cilium
package tables
import (
"net/netip"
"slices"
"github.com/cilium/cilium/pkg/k8s/resource"
"github.com/cilium/cilium/pkg/statedb"
"github.com/cilium/cilium/pkg/statedb/index"
)
type L2AnnounceKey struct {
// IP and network interface are the primary key of this entry
IP netip.Addr
NetworkInterface string
}
func (k L2AnnounceKey) Key() index.Key {
key := append(index.NetIPAddr(k.IP), '+')
key = append(key, index.String(k.NetworkInterface)...)
return key
}
type L2AnnounceEntry struct {
L2AnnounceKey
// The key of the services for which this proxy entry was added
Origins []resource.Key
}
func (pne *L2AnnounceEntry) DeepCopy() *L2AnnounceEntry {
// Shallow copy
var n L2AnnounceEntry = *pne
// Explicit clone for slices
n.Origins = slices.Clone(pne.Origins)
return &n
}
var (
L2AnnounceIDIndex = statedb.Index[*L2AnnounceEntry, L2AnnounceKey]{
Name: "id",
FromObject: func(b *L2AnnounceEntry) index.KeySet {
return index.NewKeySet(b.Key())
},
FromKey: L2AnnounceKey.Key,
Unique: true,
}
L2AnnounceOriginIndex = statedb.Index[*L2AnnounceEntry, resource.Key]{
Name: "origin",
FromObject: func(b *L2AnnounceEntry) index.KeySet {
return index.StringerSlice(b.Origins)
},
FromKey: index.Stringer[resource.Key],
}
)
func NewL2AnnounceTable() (statedb.RWTable[*L2AnnounceEntry], error) {
return statedb.NewTable[*L2AnnounceEntry](
"l2-announce",
L2AnnounceIDIndex,
L2AnnounceOriginIndex,
)
}
func (*L2AnnounceEntry) TableHeader() []string {
return []string{
"IP",
"NetworkInterface",
}
}
func (e *L2AnnounceEntry) TableRow() []string {
return []string{
e.IP.String(),
e.NetworkInterface,
}
}