int LUA_fail_delay(struct RPC2_addrinfo *Addr, RPC2_PacketBuffer *pb, int out, struct timeval *tv) { char addr[RPC2_ADDRSTRLEN]; int rc, color; if (out) rc = setup_function("fail_delay_tx"); else rc = setup_function("fail_delay_rx"); if (rc) return 0; ntohPktColor(pb); color = GetPktColor(pb); RPC2_formataddrinfo(Addr, addr, RPC2_ADDRSTRLEN); lua_pushstring(L, addr); lua_pushinteger(L, pb->Prefix.LengthOfPacket); lua_pushinteger(L, color); if (lua_pcall(L, 3, 2, 0)) { badscript(); return 0; } if (!lua_isnil(L, -2)) { l2c_totimeval(L, -2, tv); /* delay packet */ rc = (tv->tv_sec >= 0); } else rc = -1; /* drop packet */ if (lua_isnumber(L, -1)) { /* not nil, set new color value */ color = lua_tointeger(L, -1); SetPktColor(pb, color); } lua_pop(L, 2); htonPktColor(pb); return rc; }
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); }