func()

in pkg/profiling/task/network/analyze/base/traffic.go [340:380]


func (t *TrafficAnalyzer) findRemotePidWhenContainsFullAddress(con *ConnectionContext) uint32 {
	// match to localWithPeerCache
	if t.ipNotEmpty(con.LocalIP, con.LocalPort) && t.ipNotEmpty(con.RemoteIP, con.RemotePort) {
		data := t.localWithPeerCache[LocalWithPeerAddress{
			LocalIP:    con.RemoteIP,
			LocalPort:  con.RemotePort,
			RemoteIP:   con.LocalIP,
			RemotePort: con.LocalPort,
		}]
		if data != nil {
			log.Debugf("found in peer cache: %s:%d->%s:%d, pid: %d", con.RemoteIP, con.RemotePort, con.LocalIP, con.LocalPort, data.Pid)
			// if current connection is unknown, but peer network has role, then just use the revert role
			// such as: cur:(a->b) unknown, remote:(b->a) client, then current connection must have the server role
			if con.Role == events.ConnectionRoleUnknown && data.Role != events.ConnectionRoleUnknown {
				con.Role = data.Role.Revert()
			}
			return data.Pid
		}
		log.Debugf("not found in peer cache: %s:%d->%s:%d", con.RemoteIP, con.RemotePort, con.LocalIP, con.LocalPort)

		// if current role is client side, and localIP:port match to envoy
		if con.Role == events.ConnectionRoleClient {
			// need update the remote address to real address
			addr := t.envoyAcceptClientAddressCache[PeerAddress{
				RemoteIP:   con.LocalIP,
				RemotePort: con.LocalPort,
			}]
			if addr != nil {
				if t.ipNotEmpty(addr.RemoteIP, addr.RemotePort) {
					con.RemoteIP = addr.RemoteIP
					con.RemotePort = addr.RemotePort
				}
				log.Debugf("found envoy connection: %s:%d->%s:%d", con.LocalIP, con.LocalPort, con.RemoteIP, con.RemotePort)
				return addr.Pid
			}
			log.Debugf("not envoy connection: %s:%d->%s:%d", con.LocalIP, con.LocalPort, con.RemoteIP, con.RemotePort)
		}
	}

	return 0
}