1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
|
/* BLURB lgpl
Coda File System
Release 5
Copyright (c) 1987-1999 Carnegie Mellon University
Additional copyrights listed below
This code is distributed "AS IS" without warranty of any kind under
the terms of the GNU Library General Public Licence Version 2, as
shown in the file LICENSE. The technical and financial contributors to
Coda are listed in the file CREDITS.
Additional copyrights
#*/
/*
IBM COPYRIGHT NOTICE
Copyright (C) 1986
International Business Machines Corporation
All Rights Reserved
This file contains some code identical to or derived from the 1986
version of the Andrew File System ("AFS"), which is owned by the IBM
Corporation. This code is provided "AS IS" and IBM does not warrant
that it is free of infringement of any intellectual rights of any
third party. IBM disclaims liability of any kind for any damages
whatsoever resulting directly or indirectly from use of this software
or of any derivative work. Carnegie Mellon University has obtained
permission to modify, distribute and sublicense this code, which is
based on Version 2 of AFS and does not contain the features and
enhancements that are part of Version 3 of AFS. Version 3 of AFS is
commercially available and supported by Transarc Corporation,
Pittsburgh, PA.
*/
/*
-- SFTP routines related to tracing
*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/file.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <netinet/in.h>
#include <sys/uio.h>
#include <sys/socket.h>
#include <assert.h>
#include "rpc2.private.h"
#include <rpc2/se.h>
#include "sftp.h"
#include "cbuf.h"
#define TRACELEN 1000
struct TraceEntry {
enum PktType {SENT, RECVD, STATUS, BOGUS} tcode;
struct RPC2_PacketHeader ph;
};
#ifdef RPC2DEBUG
struct CBUF_Header *TraceBuf;
#endif
int sftp_XmitPacket(struct SFTP_Entry *sEntry, RPC2_PacketBuffer *pb,
int confirm)
{
#ifdef RPC2DEBUG
struct TraceEntry *te;
te = (struct TraceEntry *)CBUF_NextSlot(TraceBuf);
te->tcode = SENT;
te->ph = pb->Header; /* structure assignment */
#endif
rpc2_XmitPacket(pb, sEntry->HostInfo->Addr, confirm);
rpc2_Sent.Total--;
rpc2_Sent.Bytes -= pb->Prefix.LengthOfPacket;
sftp_Sent.Total++;
sftp_Sent.Bytes += pb->Prefix.LengthOfPacket;
return(RPC2_SUCCESS);
}
void sftp_TraceStatus(struct SFTP_Entry *sEntry, int filenum, int linenum)
{
#ifdef RPC2DEBUG
struct TraceEntry *te;
te = (struct TraceEntry *)CBUF_NextSlot(TraceBuf);
te->tcode = STATUS;
if (IsSource(sEntry))
{
te->ph.GotEmAll = htonl(sEntry->SendLastContig);
te->ph.BitMask0 = (unsigned) htonl(sEntry->SendTheseBits[0]);
te->ph.BitMask1 = (unsigned) htonl(sEntry->SendTheseBits[1]);
}
else
{
te->ph.GotEmAll = htonl(sEntry->RecvLastContig);
te->ph.BitMask0 = (unsigned) htonl(sEntry->RecvTheseBits[0]);
te->ph.BitMask1 = (unsigned) htonl(sEntry->RecvTheseBits[1]);
}
te->ph.Opcode = htonl(-1);
te->ph.LocalHandle = htonl(sEntry->LocalHandle);
te->ph.RemoteHandle = htonl(sEntry->PInfo.RemoteHandle);
te->ph.SeqNumber = htonl(filenum);
te->ph.Flags = 0;
te->ph.SEFlags = 0;
te->ph.BodyLength = htonl(linenum);
#endif
}
/* 1 ==> sftp1.c, 2 ==> sftp2.c, .... */
void sftp_TraceBogus(long filenum, long linenum)
{
#ifdef RPC2DEBUG
struct TraceEntry *te;
te = (struct TraceEntry *)CBUF_NextSlot(TraceBuf);
te->tcode = BOGUS;
te->ph.GotEmAll = 0;
te->ph.BitMask0 = 0;
te->ph.BitMask1 = 0;
te->ph.Opcode = htonl(-1);
te->ph.LocalHandle = 0;
te->ph.RemoteHandle = 0;
te->ph.SeqNumber = htonl(filenum);
te->ph.Flags = 0;
te->ph.SEFlags = 0;
te->ph.BodyLength = htonl(linenum);
#endif
}
static void PrintSFEntry(tEntry, tId, outFile)
struct TraceEntry *tEntry;
long tId;
FILE *outFile;
{
#ifdef RPC2DEBUG
char *s;
struct RPC2_PacketHeader *ph;
switch(tEntry->tcode)
{
case SENT: s = "SENT "; break;
case RECVD: s = "RECVD"; break;
case STATUS: s = "STATUS"; break;
case BOGUS: s = "BOGUS"; break;
default: s = "?????"; break;
}
fprintf(outFile, "%8ld: %8s ", tId, s);
ph = &tEntry->ph;
switch((int)ntohl(ph->Opcode))
{
case SFTP_START: s = "START"; break;
case SFTP_ACK: s = "ACK "; break;
case SFTP_DATA: s = "DATA "; break;
case SFTP_NAK: s = "NAK "; break;
case SFTP_RESET: s = "RESET"; break;
case SFTP_BUSY: s = "BUSY "; break;
case -1: s = ""; break;
default: s = "?????"; break;
}
fprintf(outFile, "%6s %6lu 0x%08lx 0x%08lx %6lu 0x%08lx|%08lx 0x%08lx 0x%08lx %4lu\n", s,
(unsigned long)ntohl(ph->SeqNumber),
(unsigned long)ntohl(ph->Flags),
(unsigned long)ntohl(ph->SEFlags),
(unsigned long)ntohl(ph->GotEmAll),
(unsigned long)ntohl(ph->BitMask0),
(unsigned long)ntohl(ph->BitMask1),
(unsigned long)ntohl(ph->RemoteHandle),
(unsigned long)ntohl(ph->LocalHandle),
(unsigned long)ntohl(ph->BodyLength));
#endif
}
void sftp_DumpTrace(char *fName)
{
#ifdef RPC2DEBUG
FILE *dumpfile;
if ((dumpfile = fopen(fName, "w")) == NULL)
{
perror(fName);
exit(-1);
}
fprintf(dumpfile, "%20s", "");
fprintf(dumpfile, "%6s %6s %8s %8s %6s %8s %8s %8s %4s\n\n",
"Op", "SNo", "Flags", "SEFlags", "GotEm", "AlsoSeen", "RHandle", "LHandle", "Blen");
CBUF_WalkBuff(TraceBuf, PrintSFEntry, TRACELEN, dumpfile);
fclose(dumpfile);
#endif
}
void sftp_InitTrace(void)
{
#ifdef RPC2DEBUG
TraceBuf = (struct CBUF_Header *)CBUF_Init(sizeof(struct TraceEntry), TRACELEN, "SFTP Trace");
#endif
}
|