in pkg/tcp_metrics/parser/parse.go [80:134]
func MakeSnapShot(msg *NetlinkMessage, skipLocal bool) (*Snapshot, error) {
if msg.Header.Type != 20 {
return nil, ErrNotType20
}
raw, attrBytes := inetdiag.SplitInetDiagMsg(msg.Data)
if raw == nil {
return nil, ErrParseFailed
}
if skipLocal {
idm, err := raw.Parse()
if err != nil {
return nil, err
}
if isLocal(idm.ID.SrcIP()) || isLocal(idm.ID.DstIP()) {
return nil, nil
}
}
attrsUnsafe, err := ParseRouteAttr(attrBytes)
if err != nil {
return nil, err
}
maxAttrType := uint16(0)
for _, a := range attrsUnsafe {
t := a.Attr.Type
if t > maxAttrType {
maxAttrType = t
}
}
if maxAttrType > 2*inetdiag.INET_DIAG_MAX {
maxAttrType = 2 * inetdiag.INET_DIAG_MAX
}
attributes := make([][]byte, maxAttrType+1, maxAttrType+1)
for _, a := range attrsUnsafe {
t := a.Attr.Type
if t > maxAttrType {
fmt.Println("Error!! Received RouteAttr with very large Type:", t)
continue
}
if attributes[t] != nil {
// TODO - add metric so we can alert on these.
fmt.Println("Parse error - Attribute appears more than once:", t)
}
attributes[t] = a.Value
}
snp, err := decode(&raw, attributes)
if err != nil {
return nil, err
}
sockInfo := snp.InetDiagMsg.ID.GetSockID()
snp.SockInfo = &sockInfo
return snp, nil
}