@@ -17,7 +17,7 @@ type structOpsKernTypes struct {
17
17
// target kernel struct type (e.g. tcp_congestion_ops).
18
18
typ * btf.Struct
19
19
typeID btf.TypeID
20
- // wrapper struct "bpf_struct_ops_<name>" that contains typ.
20
+ // value struct "bpf_struct_ops_<name>" that contains typ.
21
21
valueType * btf.Struct
22
22
// The *btf.Member within valueType that embeds typ.
23
23
dataMember * btf.Member
@@ -92,33 +92,7 @@ func findByTypeFromStruct(spec *btf.Spec, st *btf.Struct, typ btf.Type) (*btf.Me
92
92
return nil , fmt .Errorf ("member of type %s not found in %s" , typ .TypeName (), st .Name )
93
93
}
94
94
95
- // findStructByNameWithPrefix resolves a struct_ops "value" type by name,
96
- // after applying the standard prefix convention.
97
- //
98
- // It expects val to be the user-visible struct type (e.g. "bpf_dummy_ops")
99
- // and looks up the kernel-side wrapper name:
100
- //
101
- // "bpf_dummy_ops" -> "bpf_struct_ops_bpf_dummy_ops"
102
- //
103
- // Returns the matching *btf.Struct, the *btf.Spec it was found in (either the
104
- // base vmlinux spec or a module spec), and the module BTF ID (0 for vmlinux).
105
- // See doFindStructTypeByName for resolution details and error behavior.
106
- func findStructByNameWithPrefix (s * btf.Spec , val * btf.Struct ) (* btf.Struct , * btf.Spec , uint32 , error ) {
107
- return doFindStructTypeByName (s , structOpsValuePrefix + val .TypeName ())
108
- }
109
-
110
- // findStructTypeByName resolves the exact BTF struct type that corresponds
111
- // to typ.TypeName() by searching first in vmlinux and then across all loaded
112
- // kernel modules.
113
- //
114
- // Returns the first *btf.Struct that matches the name verbatim, the *btf.Spec
115
- // where it was found, and the module BTF ID (0 if found in vmlinux).
116
- // If no matching struct exists anywhere, btf.ErrNotFound is returned.
117
- func findStructTypeByName (s * btf.Spec , typ * btf.Struct ) (* btf.Struct , * btf.Spec , uint32 , error ) {
118
- return doFindStructTypeByName (s , typ .TypeName ())
119
- }
120
-
121
- // doFindStructTypeByName looks up a struct type with the exact name in the
95
+ // findStructTypeByName looks up a struct type with the exact name in the
122
96
// provided base BTF spec, and falls back to scanning all loaded module BTFs
123
97
// if it is not present in vmlinux.
124
98
//
@@ -131,7 +105,7 @@ func findStructTypeByName(s *btf.Spec, typ *btf.Struct) (*btf.Struct, *btf.Spec,
131
105
//
132
106
// Returns (*btf.Struct, *btf.Spec, moduleID, nil) on success, or btf.ErrNotFound
133
107
// if no matching struct is present in vmlinux or any module.
134
- func doFindStructTypeByName (s * btf.Spec , name string ) (* btf.Struct , * btf.Spec , uint32 , error ) {
108
+ func findStructTypeByName (s * btf.Spec , name string ) (* btf.Struct , * btf.Spec , uint32 , error ) {
135
109
if s == nil {
136
110
return nil , nil , 0 , fmt .Errorf ("nil BTF: %w" , btf .ErrNotFound )
137
111
}
@@ -194,26 +168,27 @@ func findStructTypeByNameFromModule(base *btf.Spec, name string) (*btf.Struct, *
194
168
// findStructOpsKernTypes discovers all kernel-side BTF artifacts that belong to
195
169
// a given struct_ops, identified by the user-visible base struct name
196
170
// (e.g., "tcp_congestion_ops").
197
- func findStructOpsKernTypes (userStructType * btf.Struct ) (* structOpsKernTypes , error ) {
171
+ func findStructOpsKernTypes (kType * btf.Struct ) (* structOpsKernTypes , error ) {
198
172
spec , err := btf .LoadKernelSpec ()
199
173
if err != nil {
200
174
return nil , fmt .Errorf ("load vmlinux BTF: %w" , err )
201
175
}
202
176
203
177
// 1. kernel target struct (e.g. tcp_congestion_ops)
204
- kType , s , modID , err := findStructTypeByName (spec , userStructType )
178
+ kType , s , modID , err := findStructTypeByName (spec , kType . Name )
205
179
if err != nil {
206
- return nil , fmt .Errorf ("struct type: %s %w" , userStructType .TypeName (), err )
180
+ return nil , fmt .Errorf ("struct type: %s %w" , kType .TypeName (), err )
207
181
}
208
182
209
- // 2. wrapper struct (bpf_struct_ops_<name>)
210
- wType , _ , _ , err := findStructByNameWithPrefix (s , userStructType )
183
+ // 2. value struct (bpf_struct_ops_<name>)
184
+ vTypeName := structOpsValuePrefix + kType .Name
185
+ vType , _ , _ , err := findStructTypeByName (s , vTypeName )
211
186
if err != nil {
212
- return nil , fmt .Errorf ("kern struct type for %s %w" , userStructType .TypeName (), err )
187
+ return nil , fmt .Errorf ("kern struct type for %s %w" , kType .TypeName (), err )
213
188
}
214
189
215
190
// 3. member “data” that embeds the real ops
216
- dataMem , err := findByTypeFromStruct (s , wType , kType )
191
+ dataMem , err := findByTypeFromStruct (s , vType , kType )
217
192
if err != nil {
218
193
return nil , err
219
194
}
@@ -228,7 +203,7 @@ func findStructOpsKernTypes(userStructType *btf.Struct) (*structOpsKernTypes, er
228
203
spec : s ,
229
204
typ : kType ,
230
205
typeID : kID ,
231
- valueType : wType ,
206
+ valueType : vType ,
232
207
dataMember : dataMem ,
233
208
modBtfObjId : uint32 (modID ),
234
209
}, nil
0 commit comments