@@ -75,6 +75,10 @@ type KernelLPMTrieStringPostfix struct {
75
75
data [StringPostfixMaxLength ]byte
76
76
}
77
77
78
+ var gStringMaps StringMapLists
79
+ var gStringPrefixMaps []map [KernelLPMTrieStringPrefix ]struct {}
80
+ var gStringPostfixMaps []map [KernelLPMTrieStringPostfix ]struct {}
81
+
78
82
type KernelSelectorState struct {
79
83
off uint32 // offset into encoding
80
84
e [4096 ]byte // kernel encoding of selectors
@@ -92,20 +96,30 @@ type KernelSelectorState struct {
92
96
newBinVals map [uint32 ]string // these should be added in the names_map
93
97
94
98
listReader ValueReader
95
- // stringMaps are used to populate string and char buf matches
96
- stringMaps StringMapLists
97
99
100
+ // stringMaps are used to populate string and char buf matches
101
+ stringMaps * StringMapLists
98
102
// stringPrefixMaps are used to populate string and char buf prefix matches
99
- stringPrefixMaps []map [KernelLPMTrieStringPrefix ]struct {}
103
+ stringPrefixMaps * []map [KernelLPMTrieStringPrefix ]struct {}
100
104
// stringPostfixMaps are used to populate string and char buf postfix matches
101
- stringPostfixMaps []map [KernelLPMTrieStringPostfix ]struct {}
105
+ stringPostfixMaps * []map [KernelLPMTrieStringPostfix ]struct {}
102
106
}
103
107
104
- func NewKernelSelectorState (listReader ValueReader ) * KernelSelectorState {
108
+ func NewKernelSelectorState (listReader ValueReader , newMaps bool ) * KernelSelectorState {
109
+ if newMaps {
110
+ for i := 0 ; i < StringMapsNumSubMaps ; i ++ {
111
+ gStringMaps [i ] = nil
112
+ }
113
+ gStringPrefixMaps = nil
114
+ gStringPostfixMaps = nil
115
+ }
105
116
return & KernelSelectorState {
106
- matchBinaries : make (map [int ]* MatchBinariesMappings ),
107
- newBinVals : make (map [uint32 ]string ),
108
- listReader : listReader ,
117
+ matchBinaries : make (map [int ]* MatchBinariesMappings ),
118
+ newBinVals : make (map [uint32 ]string ),
119
+ listReader : listReader ,
120
+ stringMaps : & gStringMaps ,
121
+ stringPrefixMaps : & gStringPrefixMaps ,
122
+ stringPostfixMaps : & gStringPostfixMaps ,
109
123
}
110
124
}
111
125
@@ -169,11 +183,11 @@ func (k *KernelSelectorState) StringMaps(subMap int) []map[[MaxStringMapsSize]by
169
183
}
170
184
171
185
func (k * KernelSelectorState ) StringPrefixMaps () []map [KernelLPMTrieStringPrefix ]struct {} {
172
- return k .stringPrefixMaps
186
+ return * k .stringPrefixMaps
173
187
}
174
188
175
189
func (k * KernelSelectorState ) StringPostfixMaps () []map [KernelLPMTrieStringPostfix ]struct {} {
176
- return k .stringPostfixMaps
190
+ return * k .stringPostfixMaps
177
191
}
178
192
179
193
// ValueMapsMaxEntries returns the maximum entries over all maps
@@ -223,7 +237,7 @@ func (k *KernelSelectorState) StringMapsMaxEntries(subMap int) int {
223
237
// StringPrefixMapsMaxEntries returns the maximum entries over all maps
224
238
func (k * KernelSelectorState ) StringPrefixMapsMaxEntries () int {
225
239
maxEntries := 1
226
- for _ , vm := range k .stringPrefixMaps {
240
+ for _ , vm := range * k .stringPrefixMaps {
227
241
if l := len (vm ); l > maxEntries {
228
242
maxEntries = l
229
243
}
@@ -234,7 +248,7 @@ func (k *KernelSelectorState) StringPrefixMapsMaxEntries() int {
234
248
// StringPostfixMapsMaxEntries returns the maximum entries over all maps
235
249
func (k * KernelSelectorState ) StringPostfixMapsMaxEntries () int {
236
250
maxEntries := 1
237
- for _ , vm := range k .stringPostfixMaps {
251
+ for _ , vm := range * k .stringPostfixMaps {
238
252
if l := len (vm ); l > maxEntries {
239
253
maxEntries = l
240
254
}
@@ -402,8 +416,8 @@ func (k *KernelSelectorState) insertStringMaps(stringMaps SelectorStringMaps) [S
402
416
403
417
for subMap := 0 ; subMap < StringMapsNumSubMaps ; subMap ++ {
404
418
if len (stringMaps [subMap ]) > 0 {
405
- mapid = uint32 (len (k . stringMaps [subMap ]))
406
- k . stringMaps [subMap ] = append (k . stringMaps [subMap ], stringMaps [subMap ])
419
+ mapid = uint32 (len (gStringMaps [subMap ]))
420
+ gStringMaps [subMap ] = append (gStringMaps [subMap ], stringMaps [subMap ])
407
421
} else {
408
422
mapid = 0xffffffff
409
423
}
@@ -414,13 +428,13 @@ func (k *KernelSelectorState) insertStringMaps(stringMaps SelectorStringMaps) [S
414
428
}
415
429
416
430
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 ]
431
+ mapid := len (gStringPrefixMaps )
432
+ gStringPrefixMaps = append (gStringPrefixMaps , map [KernelLPMTrieStringPrefix ]struct {}{})
433
+ return uint32 (mapid ), ( gStringPrefixMaps ) [mapid ]
420
434
}
421
435
422
436
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 ]
437
+ mapid := len (gStringPostfixMaps )
438
+ gStringPostfixMaps = append (gStringPostfixMaps , map [KernelLPMTrieStringPostfix ]struct {}{})
439
+ return uint32 (mapid ), ( gStringPostfixMaps ) [mapid ]
426
440
}
0 commit comments