void rpc2_HandlePacket(RPC2_PacketBuffer *pb) { struct CEntry *ce = NULL; assert(pb->Prefix.LE.Queue == &rpc2_PBList); rpc2_Recvd.Total++; rpc2_Recvd.Bytes += pb->Prefix.LengthOfPacket; /* no handle, this must be an INIT1 packet */ if (!pb->Header.RemoteHandle) { HandleInit1(pb); return; } ce = FindOrNak(pb); if (!ce) return; if ((ntohl(pb->Header.LocalHandle) == -1) || (ntohl(pb->Header.Opcode) == RPC2_NAKED)) { HandleSLPacket(pb, ce); return; } if (!TestState(ce, CLIENT, C_AWAITINIT2) && !TestState(ce, SERVER, S_AWAITINIT3) && !TestState(ce, CLIENT, C_AWAITINIT4)) rpc2_ApplyD(pb, ce); #ifdef RPC2DEBUG /* debugging */ if (RPC2_DebugLevel >= 10) rpc2_PrintCEntry(ce, rpc2_tracefile); #endif /* update the host entry if there is one */ if (ce->HostInfo) ce->HostInfo->LastWord = pb->Prefix.RecvStamp; /* convert to host-byte order */ rpc2_ntohp(pb); /* maintain causality */ if (pb->Header.Lamport >= rpc2_LamportClock) rpc2_LamportClock = pb->Header.Lamport + 1; say(9, RPC2_DebugLevel, "Decoding opcode %d\n", pb->Header.Opcode); DecodePacket(pb, ce); say(9, RPC2_DebugLevel, "Decoding complete\n"); }
void rpc2_PrintMEntry(struct MEntry *mPtr, FILE *tFile) { if (tFile == NULL) tFile = rpc2_logfile; /* it's ok, call-by-value */ fprintf(tFile, "MyAddr: 0x%lx\n\tNextEntry = 0x%lx PrevEntry = 0x%lx MagicNumber = %s Role = %s State = ", (long)mPtr, (long)mPtr->Next, (long)mPtr->Prev, WhichMagic(mPtr->MagicNumber), TestRole(mPtr,FREE) ? "FREE" :(TestRole(mPtr, CLIENT) ? "CLIENT" : (TestRole(mPtr, SERVER) ? "SERVER" : "?????") )); if (TestRole(mPtr,CLIENT)) switch((int) (mPtr->State & 0x0000ffff)) { case C_THINK: fprintf(tFile, "C_THINK");break; case C_AWAITREPLY: fprintf(tFile, "C_AWAITREPLY");break; case C_HARDERROR: fprintf(tFile, "C_HARDERROR");break; default: fprintf(tFile, "???????"); break; } if (TestRole(mPtr,SERVER)) switch((int) (mPtr->State & 0x0000ffff)) { case S_AWAITREQUEST: fprintf(tFile, "S_AWAITREQUEST");break; case S_PROCESS: fprintf(tFile, "S_PROCESS");break; case S_REQINQUEUE: fprintf(tFile, "S_REQINQUEUE");break; case S_HARDERROR: fprintf(tFile, "S_HARDERROR");break; case S_INSE: fprintf(tFile, "S_INSE");break; case S_AWAITENABLE: fprintf(tFile, "S_AWAITENABLE");break; default: fprintf(tFile, "??????"); break; } fprintf(tFile, "\n\tMgrpID = %#x NextSeqNumber = %d\n", mPtr->MgroupID, mPtr->NextSeqNumber); fprintf(tFile, "Client Host Ident: "); rpc2_printaddrinfo(mPtr->ClientAddr, tFile); fprintf(tFile, "\n"); if (TestRole(mPtr,CLIENT)) { fprintf(tFile, "\n\tMaxlisteners = %ld Listeners = %ld\n", mPtr->me_conns.me_client.mec_maxlisteners, mPtr->me_conns.me_client.mec_howmanylisteners); } else { fprintf(tFile, "Client CEntry:\n"); rpc2_PrintCEntry(mPtr->me_conns.mes_conn, tFile); } fprintf(tFile, "\n"); (void) fflush(tFile); }
void rpc2_PrintTraceElem(struct TraceElem *whichTE, long whichIndex, FILE *outFile) { long i; fprintf(outFile, "\nTrace Entry %ld: <<<<<< %s: %s", whichIndex, whichTE->ActiveLWP, CallName(whichTE->CallCode)); switch(whichTE->CallCode) { case SLNEWPACKET: case CLOCKTICK: fprintf(outFile, " >>>>>>\n"); break; default: fprintf(outFile, "() >>>>>>\n"); break; } switch(whichTE->CallCode) { case INIT: break; case EXPORT: { struct te_EXPORT *tea; tea = &whichTE->Args.ExportEntry; if (tea->Subsys.Tag == RPC2_SUBSYSBYID) fprintf(outFile, "Subsys: Tag = RPC2_SUBSYSBYID SubsysId = %ld\n", tea->Subsys.Value.SubsysId); else fprintf(outFile, "Subsys: Tag = RPC2_SUBSYSBYNAME Name = \"%s\"\n", tea->Subsys.Value.Name); break; /* switch */ } case DEEXPORT: { struct te_DEEXPORT *tea; tea = &whichTE->Args.DeExportEntry; if (tea->Subsys.Tag == RPC2_SUBSYSBYID) fprintf(outFile, "Subsys: Tag = RPC2_SUBSYSBYID SubsysId = %ld\n", tea->Subsys.Value.SubsysId); else fprintf(outFile, "Subsys: Tag = RPC2_SUBSYSBYNAME Name = \"%s\"\n", tea->Subsys.Value.Name); break; /* switch */ } case ALLOCBUFFER: { struct te_ALLOCBUFFER *tea; tea = &whichTE->Args.AllocBufferEntry; fprintf(outFile, "MinBodySize: %d\n", tea->MinBodySize); break; /* switch */ } case FREEBUFFER: { struct te_FREEBUFFER *tea; tea = &whichTE->Args.FreeBufferEntry; fprintf(outFile, "*BuffPtr: %p\n", tea->BuffPtr); break; /* switch */ } case SENDRESPONSE: { struct te_SENDRESPONSE *tea; tea = &whichTE->Args.SendResponseEntry; fprintf(outFile, "ConnHandle: %#x\n", tea->ConnHandle); break; /* switch */ } case GETREQUEST: { struct te_GETREQUEST *tea; tea = &whichTE->Args.GetRequestEntry; fprintf(outFile, "Filter: "); rpc2_PrintFilter(&tea->Filter, outFile); if (tea->IsNullBreathOfLife) fprintf(outFile, "BreathOfLife: NULL\n"); else fprintf(outFile, "BreathOfLife: %ld.%ld\n", tea->BreathOfLife.tv_sec, tea->BreathOfLife.tv_usec); break; /* switch */ } case MAKERPC: { struct te_MAKERPC *tea; tea = &whichTE->Args.MakeRPCEntry; fprintf(outFile, "Conn: %#x ", tea->ConnHandle); fprintf(outFile, "Enqueue: %d ", tea->EnqueueRequest); if (tea->IsNullBreathOfLife) fprintf(outFile, "BreathOfLife: NULL "); else fprintf(outFile, "BreathOfLife: %ld.%ld ", tea->BreathOfLife.tv_sec, tea->BreathOfLife.tv_usec); if (tea->IsNullSDesc) fprintf(outFile, "SDesc: NULL\n"); else {fprintf(outFile, "\nSDesc: "); rpc2_PrintSEDesc(&tea->SDesc, outFile);} break; /* switch */ } case MULTIRPC: { struct te_MULTIRPC *tea; tea = &whichTE->Args.MultiRPCEntry; fprintf(outFile, "ConnHandle: 0x%lx\n", (unsigned long)tea->ConnHandle); fprintf(outFile, "Request: OriginalAddress = %p ", tea->Request_Address); rpc2_PrintPacketHeader(&tea->Request, outFile); if (tea->IsNullSDesc) fprintf(outFile, "SDesc: NULL\n"); else {fprintf(outFile, "SDesc: "); rpc2_PrintSEDesc(&tea->SDesc, outFile);} fprintf(outFile, "HandleResult: %p\n", tea->HandleResult); if (tea->IsNullBreathOfLife) fprintf(outFile, "BreathOfLife: NULL\n"); else fprintf(outFile, "BreathOfLife: %ld.%ld\n", tea->BreathOfLife.tv_sec, tea->BreathOfLife.tv_usec); break; /* switch */ } case BIND: { struct te_BIND *tea; tea = &whichTE->Args.BindEntry; switch (tea->Host.Tag) { case RPC2_HOSTBYNAME: fprintf(outFile, "Host: Tag = RPC2_HOSTBYNAME Name = \"%s\"\n", tea->Host.Value.Name); break; case RPC2_HOSTBYADDRINFO: { char addr[RPC2_ADDRSTRLEN]; RPC2_formataddrinfo(tea->Host.Value.AddrInfo, addr, RPC2_ADDRSTRLEN); fprintf(outFile, "Host: Tag = RPC2_HOSTBYINETADDR AddrInfo = %s\n", addr); break; } case RPC2_HOSTBYINETADDR: fprintf(outFile, "Host: Tag = RPC2_HOSTBYINETADDR InetAddress = %s\n", inet_ntoa(tea->Host.Value.InetAddress)); break; default: fprintf(outFile, "Host: ?????????\n"); break; } switch (tea->Port.Tag) { case RPC2_PORTBYNAME: fprintf(outFile, "Port: Tag = RPC2_PORTBYNAME Name = \"%s\"\n", tea->Port.Value.Name); break; case RPC2_PORTBYINETNUMBER: fprintf(outFile, "Port: Tag = RPC2_PORTBYINETNUMBER InetNumber = \"%u\"\n", ntohs(tea->Port.Value.InetPortNumber)); break; default: fprintf(outFile, "Port: ??????\n"); break; } switch(tea->Subsys.Tag) { case RPC2_SUBSYSBYNAME: fprintf(outFile, "Subsys: Tag = RPC2_SUBSYSBYNAME Name = \"%s\"\n", tea->Subsys.Value.Name); break; case RPC2_SUBSYSBYID: fprintf(outFile, "Subsys: Tag = RPC2_SUBSYSBYID Name = %ld\n", tea->Subsys.Value.SubsysId); break; default: fprintf(outFile, "Subsys: ??????\n"); } fprintf(outFile, "SideEffectType = %d\n", tea->SideEffectType); if (tea->IsNullClientIdent) fprintf(outFile, "ClientIdent: NULL\n"); else { long max; fprintf(outFile, "ClientIdent: SeqLen = %u SeqBody\"", tea->ClientIdent.SeqLen); max = (tea->ClientIdent.SeqLen < sizeof(tea->ClientIdent_Value)) ? tea->ClientIdent.SeqLen : sizeof(tea->ClientIdent_Value); for (i = 0; i < max; i++) fprintf(outFile, "%c", (tea->ClientIdent_Value)[i]); if (max < tea->ClientIdent.SeqLen) fprintf(outFile, "....."); fprintf(outFile, "\"\n"); } break; /* switch */ } case INITSIDEEFFECT: { struct te_INITSIDEEFFECT *tea; tea = &whichTE->Args.InitSideEffectEntry; fprintf(outFile, "ConnHandle: %#x\n", tea->ConnHandle); if (tea->IsNullSDesc) fprintf(outFile, "SDesc: NULL\n"); else {fprintf(outFile, "SDesc: "); rpc2_PrintSEDesc(&tea->SDesc, outFile); } break; /* switch */ } case CHECKSIDEEFFECT: { struct te_CHECKSIDEEFFECT *tea; tea = &whichTE->Args.CheckSideEffectEntry; fprintf(outFile, "ConnHandle: %#x\n", tea->ConnHandle); if (tea->IsNullSDesc) fprintf(outFile, "SDesc: NULL\n"); else {fprintf(outFile, "SDesc: "); rpc2_PrintSEDesc(&tea->SDesc, outFile);} fprintf(outFile, "Flags: { "); if (tea->Flags & SE_AWAITLOCALSTATUS) fprintf(outFile, "SE_AWAITLOCALSTATUS "); if (tea->Flags & SE_AWAITREMOTESTATUS) fprintf(outFile, "SE_AWAITREMOTESTATUS "); fprintf(outFile, "}\n"); break; /* switch */ } case UNBIND: { struct te_UNBIND *tea; tea = &whichTE->Args.UnbindEntry; fprintf(outFile, "whichConn: %#x\n", tea->whichConn); break; /* switch */ } case GETPRIVATEPOINTER: { struct te_GETPRIVATEPOINTER *tea; tea = &whichTE->Args.GetPrivatePointerEntry; fprintf(outFile, "ConnHandle: %#x\n", tea->ConnHandle); break; /* switch */ } case SETPRIVATEPOINTER: { struct te_SETPRIVATEPOINTER *tea; tea = &whichTE->Args.SetPrivatePointerEntry; fprintf(outFile, "ConnHandle: %#x\n", tea->ConnHandle); fprintf(outFile, "PrivatePtr: %p\n", tea->PrivatePtr); break; /* switch */ } case GETSEPOINTER: { struct te_GETSEPOINTER *tea; tea = &whichTE->Args.GetSEPointerEntry; fprintf(outFile, "ConnHandle: %#x\n", tea->ConnHandle); break; /* switch */ } case SETSEPOINTER: { struct te_SETSEPOINTER *tea; tea = &whichTE->Args.SetSEPointerEntry; fprintf(outFile, "ConnHandle: %#x\n", tea->ConnHandle); fprintf(outFile, "SEPtr: %p\n", tea->SEPtr); break; /* switch */ } case GETPEERINFO: { struct te_GETPEERINFO *tea; tea = &whichTE->Args.GetPeerInfoEntry; fprintf(outFile, "ConnHandle: 0x%lx\n", (long)tea->ConnHandle); break; /* switch */ } case SLNEWPACKET: { struct te_SLNEWPACKET *tea; tea = &whichTE->Args.SLNewPacketEntry; rpc2_PrintPacketHeader(&tea->pb, outFile); break; /* switch */ } case SENDRELIABLY: { struct te_SENDRELIABLY *tea; tea = &whichTE->Args.SendReliablyEntry; fprintf(outFile, "Conn.UniqueCID = 0x%x ",tea->Conn_UniqueCID); if (tea->IsNullTimeout) fprintf(outFile, "TimeOut: NULL\n"); else fprintf(outFile, "TimeOut: %ld.%ld\n", tea->Timeout.tv_sec, tea->Timeout.tv_usec); break; /* switch */ } case MSENDPACKETSRELIABLY: { struct te_MSENDPACKETSRELIABLY *tea; tea = &whichTE->Args.MSendPacketsReliablyEntry; fprintf(outFile, "HowMany: %d ConnArray[0]: %p ConnArray[0].UniqueCID = 0x%x\n", tea->HowMany, tea->ConnArray0, tea->ConnArray0_UniqueCID); fprintf(outFile, "PacketArray[0]: OriginalAddress = 0x%lx ", (long)tea->PacketArray0_Address); rpc2_PrintPacketHeader(&tea->PacketArray0, outFile); if (tea->IsNullTimeout) fprintf(outFile, "TimeOut: NULL\n"); else fprintf(outFile, "TimeOut: %ld.%ld\n", tea->Timeout.tv_sec, tea->Timeout.tv_usec); break; /* switch */ } case XMITPACKET: { struct te_XMITPACKET *tea; tea = &whichTE->Args.XmitPacketEntry; fprintf(outFile, "whichSocket = %ld\n", tea->whichSocket); fprintf(outFile, "whichAddr: "); rpc2_printaddrinfo(&tea->whichAddr, outFile); fprintf(outFile,"\n"); rpc2_PrintPacketHeader(&tea->whichPB, outFile); break; /* switch */ } case CLOCKTICK: { struct te_CLOCKTICK *tea; tea = &whichTE->Args.ClockTickEntry; fprintf(outFile, "TimeNow: %d\n", tea->TimeNow); break; /* switch */ } case CREATEMGRP: { struct te_CREATEMGRP *tea; tea = &whichTE->Args.CreateMgrpEntry; fprintf(outFile, "MgroupHandle: %#x\n", tea->MgroupHandle); fprintf(outFile, "McastHost: "); rpc2_PrintHostIdent((RPC2_HostIdent *)&(tea->McastHost), outFile); fprintf(outFile, " "); fprintf(outFile, "McastPort: "); rpc2_PrintPortIdent(&(tea->Port), outFile); fprintf(outFile, " "); fprintf(outFile, "Subsystem: "); rpc2_PrintSubsysIdent(&(tea->Subsys), outFile); fprintf(outFile, "\n"); break; /* switch */ } case ADDTOMGRP: { struct te_ADDTOMGRP *tea; tea = &whichTE->Args.AddToMgrpEntry; fprintf(outFile, "MgroupHandle: %#x ConnHandle: %#x\n", tea->MgroupHandle, tea->ConnHandle); break; /* switch */ } case REMOVEFROMMGRP: { struct te_REMOVEFROMMGRP *tea; tea = &whichTE->Args.RemoveFromMgrpEntry; fprintf(outFile, "MEntry: "); rpc2_PrintMEntry(&tea->me, outFile); fprintf(outFile, " "); fprintf(outFile, "CEntry: "); rpc2_PrintCEntry(&tea->ce, outFile); fprintf(outFile, "\n"); break; /* switch */ } case XLATEMCASTPACKET: { struct te_XLATEMCASTPACKET *tea; tea = &whichTE->Args.XlateMcastPacketEntry; fprintf(outFile, "PacketBuffer Address: 0x%lx PacketHeader: ", tea->pb_address); rpc2_PrintPacketHeader(&tea->pb, outFile); fprintf(outFile, " ClientHost: "); rpc2_printaddrinfo(&tea->ThisAddr, outFile); fprintf(outFile, "\n"); break; /* switch */ } } }
static struct CEntry *MakeConn(struct RPC2_PacketBuffer *pb) { struct Init1Body *ib1; struct CEntry *ce; say(9, RPC2_DebugLevel, " Request on brand new connection\n"); ib1 = (struct Init1Body *)(pb->Body); #define INIT1LENGTH \ (sizeof(struct RPC2_PacketHeader) + sizeof(struct Init1Body) - \ sizeof(ib1->Text)) if (pb->Prefix.LengthOfPacket < INIT1LENGTH || pb->Prefix.LengthOfPacket < (INIT1LENGTH + ntohl(ib1->FakeBody_ClientIdent_SeqLen))) { /* avoid memory reference errors from bogus packets */ say(1, RPC2_DebugLevel, "Ignoring short Init1 packet\n"); return NULL; } ce = rpc2_AllocConn(pb->Prefix.PeerAddr); ce->TimeStampEcho = pb->Header.TimeStamp; TVTOTS(&pb->Prefix.RecvStamp, ce->RequestTime); say(15, RPC2_DebugLevel, "makeconn TS %u RQ %u\n", ce->TimeStampEcho, ce->RequestTime); switch ((int)pb->Header.Opcode) { case RPC2_INIT1OPENKIMONO: ce->SecurityLevel = RPC2_OPENKIMONO; break; case RPC2_INIT1AUTHONLY: ce->SecurityLevel = RPC2_AUTHONLY; break; case RPC2_INIT1HEADERSONLY: ce->SecurityLevel = RPC2_HEADERSONLY; break; case RPC2_INIT1SECURE: ce->SecurityLevel = RPC2_SECURE; break; default: assert(FALSE); } if (ce->SecurityLevel != RPC2_OPENKIMONO) { secure_random_bytes(&ce->NextSeqNumber, sizeof(ce->NextSeqNumber)); ce->EncryptionType = ntohl(ib1->FakeBody_EncryptionType); } SetRole(ce, SERVER); SetState(ce, S_STARTBIND); ce->PeerHandle = pb->Header.LocalHandle; ce->sa.peer_spi = pb->Header.LocalHandle; ce->SubsysId = pb->Header.SubsysId; ce->PeerUnique = pb->Header.Uniquefier; ce->SEProcs = NULL; ce->Color = GetPktColor(pb); #ifdef RPC2DEBUG if (RPC2_DebugLevel > 9) { printf("New Connection %p......\n", ce); rpc2_PrintCEntry(ce, rpc2_tracefile); (void)fflush(rpc2_tracefile); } #endif rpc2_NoteBinding(pb->Prefix.PeerAddr, ce->PeerHandle, pb->Header.Uniquefier, ce->UniqueCID); return (ce); }