@@ -75,6 +75,15 @@ type KernelLPMTrieStringPostfix struct {
75
75
data [StringPostfixMaxLength ]byte
76
76
}
77
77
78
+ type KernelSelectorMaps struct {
79
+ // stringMaps are used to populate string and char buf matches
80
+ stringMaps StringMapLists
81
+ // stringPrefixMaps are used to populate string and char buf prefix matches
82
+ stringPrefixMaps []map [KernelLPMTrieStringPrefix ]struct {}
83
+ // stringPostfixMaps are used to populate string and char buf postfix matches
84
+ stringPostfixMaps []map [KernelLPMTrieStringPostfix ]struct {}
85
+ }
86
+
78
87
type KernelSelectorState struct {
79
88
off uint32 // offset into encoding
80
89
e [4096 ]byte // kernel encoding of selectors
@@ -92,20 +101,19 @@ type KernelSelectorState struct {
92
101
newBinVals map [uint32 ]string // these should be added in the names_map
93
102
94
103
listReader ValueReader
95
- // stringMaps are used to populate string and char buf matches
96
- stringMaps StringMapLists
97
104
98
- // stringPrefixMaps are used to populate string and char buf prefix matches
99
- stringPrefixMaps []map [KernelLPMTrieStringPrefix ]struct {}
100
- // stringPostfixMaps are used to populate string and char buf postfix matches
101
- stringPostfixMaps []map [KernelLPMTrieStringPostfix ]struct {}
105
+ maps * KernelSelectorMaps
102
106
}
103
107
104
- func NewKernelSelectorState (listReader ValueReader ) * KernelSelectorState {
108
+ func NewKernelSelectorState (listReader ValueReader , maps * KernelSelectorMaps ) * KernelSelectorState {
109
+ if maps == nil {
110
+ maps = & KernelSelectorMaps {}
111
+ }
105
112
return & KernelSelectorState {
106
113
matchBinaries : make (map [int ]* MatchBinariesMappings ),
107
114
newBinVals : make (map [uint32 ]string ),
108
115
listReader : listReader ,
116
+ maps : maps ,
109
117
}
110
118
}
111
119
@@ -165,15 +173,15 @@ func (k *KernelSelectorState) Addr6Maps() []map[KernelLPMTrie6]struct{} {
165
173
}
166
174
167
175
func (k * KernelSelectorState ) StringMaps (subMap int ) []map [[MaxStringMapsSize ]byte ]struct {} {
168
- return k .stringMaps [subMap ]
176
+ return k .maps . stringMaps [subMap ]
169
177
}
170
178
171
179
func (k * KernelSelectorState ) StringPrefixMaps () []map [KernelLPMTrieStringPrefix ]struct {} {
172
- return k .stringPrefixMaps
180
+ return k .maps . stringPrefixMaps
173
181
}
174
182
175
183
func (k * KernelSelectorState ) StringPostfixMaps () []map [KernelLPMTrieStringPostfix ]struct {} {
176
- return k .stringPostfixMaps
184
+ return k .maps . stringPostfixMaps
177
185
}
178
186
179
187
// ValueMapsMaxEntries returns the maximum entries over all maps
@@ -212,7 +220,7 @@ func (k *KernelSelectorState) Addr6MapsMaxEntries() int {
212
220
// StringMapsMaxEntries returns the maximum entries over all maps inside a particular map of map
213
221
func (k * KernelSelectorState ) StringMapsMaxEntries (subMap int ) int {
214
222
maxEntries := 1
215
- for _ , vm := range k .stringMaps [subMap ] {
223
+ for _ , vm := range k .maps . stringMaps [subMap ] {
216
224
if l := len (vm ); l > maxEntries {
217
225
maxEntries = l
218
226
}
@@ -223,7 +231,7 @@ func (k *KernelSelectorState) StringMapsMaxEntries(subMap int) int {
223
231
// StringPrefixMapsMaxEntries returns the maximum entries over all maps
224
232
func (k * KernelSelectorState ) StringPrefixMapsMaxEntries () int {
225
233
maxEntries := 1
226
- for _ , vm := range k .stringPrefixMaps {
234
+ for _ , vm := range k .maps . stringPrefixMaps {
227
235
if l := len (vm ); l > maxEntries {
228
236
maxEntries = l
229
237
}
@@ -234,7 +242,7 @@ func (k *KernelSelectorState) StringPrefixMapsMaxEntries() int {
234
242
// StringPostfixMapsMaxEntries returns the maximum entries over all maps
235
243
func (k * KernelSelectorState ) StringPostfixMapsMaxEntries () int {
236
244
maxEntries := 1
237
- for _ , vm := range k .stringPostfixMaps {
245
+ for _ , vm := range k .maps . stringPostfixMaps {
238
246
if l := len (vm ); l > maxEntries {
239
247
maxEntries = l
240
248
}
@@ -402,8 +410,8 @@ func (k *KernelSelectorState) insertStringMaps(stringMaps SelectorStringMaps) [S
402
410
403
411
for subMap := 0 ; subMap < StringMapsNumSubMaps ; subMap ++ {
404
412
if len (stringMaps [subMap ]) > 0 {
405
- mapid = uint32 (len (k .stringMaps [subMap ]))
406
- k .stringMaps [subMap ] = append (k .stringMaps [subMap ], stringMaps [subMap ])
413
+ mapid = uint32 (len (k .maps . stringMaps [subMap ]))
414
+ k .maps . stringMaps [subMap ] = append (k . maps .stringMaps [subMap ], stringMaps [subMap ])
407
415
} else {
408
416
mapid = 0xffffffff
409
417
}
@@ -414,13 +422,13 @@ func (k *KernelSelectorState) insertStringMaps(stringMaps SelectorStringMaps) [S
414
422
}
415
423
416
424
func (k * KernelSelectorState ) newStringPrefixMap () (uint32 , map [KernelLPMTrieStringPrefix ]struct {}) {
417
- mapid := len (k .stringPrefixMaps )
418
- k .stringPrefixMaps = append (k .stringPrefixMaps , map [KernelLPMTrieStringPrefix ]struct {}{})
419
- return uint32 (mapid ), k .stringPrefixMaps [mapid ]
425
+ mapid := len (k .maps . stringPrefixMaps )
426
+ k .maps . stringPrefixMaps = append (k . maps .stringPrefixMaps , map [KernelLPMTrieStringPrefix ]struct {}{})
427
+ return uint32 (mapid ), k .maps . stringPrefixMaps [mapid ]
420
428
}
421
429
422
430
func (k * KernelSelectorState ) newStringPostfixMap () (uint32 , map [KernelLPMTrieStringPostfix ]struct {}) {
423
- mapid := len (k .stringPostfixMaps )
424
- k .stringPostfixMaps = append (k .stringPostfixMaps , map [KernelLPMTrieStringPostfix ]struct {}{})
425
- return uint32 (mapid ), k .stringPostfixMaps [mapid ]
431
+ mapid := len (k .maps . stringPostfixMaps )
432
+ k .maps . stringPostfixMaps = append (k . maps .stringPostfixMaps , map [KernelLPMTrieStringPostfix ]struct {}{})
433
+ return uint32 (mapid ), k .maps . stringPostfixMaps [mapid ]
426
434
}
0 commit comments