コード例 #1
0
ファイル: main.go プロジェクト: cilium-team/cilium
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)
	}
}
コード例 #2
0
ファイル: monitor.go プロジェクト: cilium-team/cilium
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()
	}
}