MCPcopy
hub / github.com/vishvananda/netlink / ClassList

Method ClassList

class_linux.go:218–305  ·  view source on GitHub ↗

ClassList gets a list of classes in the system. Equivalent to: `tc class show`. Generally returns nothing if link and parent are not specified. If the returned error is [ErrDumpInterrupted], results may be inconsistent or incomplete.

(link Link, parent uint32)

Source from the content-addressed store, hash-verified

216// If the returned error is [ErrDumpInterrupted], results may be inconsistent
217// or incomplete.
218func (h *Handle) ClassList(link Link, parent uint32) ([]Class, error) {
219 req := h.newNetlinkRequest(unix.RTM_GETTCLASS, unix.NLM_F_DUMP)
220 msg := &nl.TcMsg{
221 Family: nl.FAMILY_ALL,
222 Parent: parent,
223 }
224 if link != nil {
225 base := link.Attrs()
226 h.ensureIndex(base)
227 msg.Ifindex = int32(base.Index)
228 }
229 req.AddData(msg)
230
231 msgs, executeErr := req.Execute(unix.NETLINK_ROUTE, unix.RTM_NEWTCLASS)
232 if executeErr != nil && !errors.Is(executeErr, ErrDumpInterrupted) {
233 return nil, executeErr
234 }
235
236 var res []Class
237 for _, m := range msgs {
238 msg := nl.DeserializeTcMsg(m)
239
240 attrs, err := nl.ParseRouteAttr(m[msg.Len():])
241 if err != nil {
242 return nil, err
243 }
244
245 base := ClassAttrs{
246 LinkIndex: int(msg.Ifindex),
247 Handle: msg.Handle,
248 Parent: msg.Parent,
249 Statistics: nil,
250 }
251
252 var class Class
253 classType := ""
254 for _, attr := range attrs {
255 switch attr.Attr.Type {
256 case nl.TCA_KIND:
257 classType = string(attr.Value[:len(attr.Value)-1])
258 switch classType {
259 case "htb":
260 class = &HtbClass{}
261 case "hfsc":
262 class = &HfscClass{}
263 default:
264 class = &GenericClass{ClassType: classType}
265 }
266 case nl.TCA_OPTIONS:
267 switch classType {
268 case "htb":
269 data, err := nl.ParseRouteAttr(attr.Value)
270 if err != nil {
271 return nil, err
272 }
273 _, err = parseHtbClassData(class, data)
274 if err != nil {
275 return nil, err

Callers 1

ClassListFunction · 0.45

Calls 14

newNetlinkRequestMethod · 0.95
ensureIndexMethod · 0.95
LenMethod · 0.95
AttrsMethod · 0.95
DeserializeTcMsgFunction · 0.92
ParseRouteAttrFunction · 0.92
parseHtbClassDataFunction · 0.85
parseHfscClassDataFunction · 0.85
parseTcStatsFunction · 0.85
parseTcStats2Function · 0.85
AddDataMethod · 0.80
ExecuteMethod · 0.80

Tested by

no test coverage detected