Exemplo n.º 1
0
func receiveEvent(msg *bpf.PerfEventSample, cpu int) {
	prefix := fmt.Sprintf("CPU %02d:", cpu)

	data := msg.DataDirect()
	if data[0] == bpf.CILIUM_NOTIFY_DROP {
		dn := bpf.DropNotify{}
		if err := binary.Read(bytes.NewReader(data), binary.LittleEndian, &dn); err != nil {
			log.Warningf("Error while parsing drop notification message: %s\n", err)
		}
		dn.Dump(dissect, data, prefix)
	} else if data[0] == bpf.CILIUM_DBG_MSG {
		dm := bpf.DebugMsg{}
		if err := binary.Read(bytes.NewReader(data), binary.LittleEndian, &dm); err != nil {
			log.Warningf("Error while parsing debug message: %s\n", err)
		} else {
			dm.Dump(data, prefix)
		}
	} else if data[0] == bpf.CILIUM_DBG_CAPTURE {
		dc := bpf.DebugCapture{}
		if err := binary.Read(bytes.NewReader(data), binary.LittleEndian, &dc); err != nil {
			log.Warningf("Error while parsing debug capture message: %s\n", err)
		}
		dc.Dump(dissect, data, prefix)
	} else {
		fmt.Printf("%s Unknonwn event: %+v\n", prefix, msg)
	}
}
Exemplo n.º 2
0
func (d *Daemon) receiveEvent(msg *bpf.PerfEventSample, cpu int) {
	data := msg.DataDirect()
	if data[0] == bpf.CILIUM_NOTIFY_DROP {
		dn := bpf.DropNotify{}
		if err := binary.Read(bytes.NewReader(data), binary.LittleEndian, &dn); err != nil {
			log.Warningf("Error while parsing drop notification message: %s\n", err)
			return
		}
		d.endpointsLearningMU.RLock()
		for _, v := range d.endpointsLearning {
			if dn.DstID == uint32(v.EndpointID) {
				go func(epID uint16, lblID uint32) {
					sec, err := d.GetLabels(lblID)
					if err != nil {
						log.Errorf("Error while getting label ID %d: %s", lblID, err)
						return
					}
					if sec == nil {
						log.Warningf("Endpoint %d is receiving traffic from an unknown label ID %d", epID, lblID)
						return
					}
					if err := d.EndpointLabelsUpdate(epID, labels.LabelOp{labels.AddLabelsOp: sec.Labels}); err != nil {
						log.Warningf("Error while add learned labels into the daemon %s", err)
					}
				}(v.EndpointID, dn.SrcLabel)
			}
		}
		d.endpointsLearningMU.RUnlock()
	}
}