Re: sockstat tcp/udp switches

2006-11-07 Thread Michael M. Press

Josh Carroll wrote:

I included a limitation on the maximum length of a proto (mostly to
avoid buffer overflows) and 20 is probably way too large, so I can
lower that if need be.


I'm not sure buffer overflows are prevented:

static int
parse_protos(const char *protospec)
{
   ...
  char curr_proto[MAX_PROTO_LEN];

  while(...) {
  ...
  if(pindex == MAX_PROTO_LEN) {
 printf(Warning: truncating protocol\n);
 curr_proto[pindex] = '\0';
  ...
  }
  }
  ...
}

The code above writes past the end of the array when the 'if' condition
is true. You probably meant if(pindex == MAX_PROTO_LEN-1).
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: sockstat tcp/udp switches

2006-11-07 Thread Brooks Davis
On Mon, Nov 06, 2006 at 03:17:17PM -0800, Josh Carroll wrote:
 I suggest you use /etc/protocols rather than hard code the protocols.
 This will make the code future-proof.  See getprotoent(3) for the
 correct way to read /etc/protocols.
 
 Thanks Peter, that's a great idea. Below is a new patch that uses
 getprotoent(3). For now, to maintain backward compatibility, I've
 defined a default list of protocols (tcp, udp, divert), in the event
 -P is not specified. This should retain the normal command line
 behavior.
 
 Thanks again for the suggestion.
 
 Dmitry - with this change, diver is now the default but can also be
 specified as an argument to -P as well.

On other suggestion I'd have it to consider using strsep to parse the
string.  I'm pretty the code will be smaller and more readable.

-- Brooks


pgpWuaE79OFf9.pgp
Description: PGP signature


Re: sockstat tcp/udp switches

2006-11-07 Thread Josh Carroll

On other suggestion I'd have it to consider using strsep to parse the
string.  I'm pretty the code will be smaller and more readable.



Good point. And yes, per the other mail I do need to fix the
MAX_PROTO_LEN checking, but I'll make sure that is proper when I
update it to use strsep.

Josh
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


Re: sockstat tcp/udp switches

2006-11-07 Thread Josh Carroll

Below is the patch using strsep instead. I also updated the
gather_inet function to print a message that a protocol is not
supported if it exists in /etc/protocols, but does not have a case in
the gather_inet function.

patch is here if you'd rather just fetch it:

http://pflog.net/~floyd/sockstat.patch

Thanks,
Josh


--- sockstat.c.orig Thu Jun  9 23:36:03 2005
+++ sockstat.c  Tue Nov  7 10:49:28 2006
@@ -66,8 +66,15 @@
static int   opt_u; /* Show Unix domain sockets */
static int   opt_v; /* Verbose mode */

+/* default protocols to use if no -P was defined, currently
+   tcp, udp and divert */
+const char *default_protos[] = {tcp, udp, divert, NULL};
+
+static int *protos;/* protocols to use */
+
static int  *ports;

+
#define INT_BIT (sizeof(int)*CHAR_BIT)
#define SET_PORT(p) do { ports[p / INT_BIT] |= 1  (p % INT_BIT); } while (0)
#define CHK_PORT(p) (ports[p / INT_BIT]  (1  (p % INT_BIT)))
@@ -104,6 +111,68 @@
return (len);
}

+
+/* this function needs to be updated to reflect additional protocols
+   that are to be supported */
+static int
+get_proto_type(const char *proto)
+{
+   struct protoent *pent;
+
+   if(strlen(proto) == 0)
+   return 0;
+
+   pent = getprotobyname(proto);
+   if(pent == NULL) {
+   printf(Unrecognized protocol: %s\n, proto);
+   return -1;
+   } else {
+   return pent-p_proto;
+   }
+}
+
+
+static void init_protos(int num)
+{
+   int proto_count = 0;
+
+   if(num  0) {
+   proto_count = num;
+   } else {
+   /* find the maximum number of possible protocols */
+   while(getprotoent() != NULL)
+   proto_count++;
+   endprotoent();
+   }
+
+   if ((protos = malloc(sizeof(int) * proto_count)) == NULL)
+   err(1, malloc());
+}
+
+
+static int
+parse_protos(char *protospec)
+{
+   char **prot;
+   char *tmp = protospec;
+   int protos_defined = 0, proto_type, proto_index = 0;
+
+   init_protos(0);
+
+   while( (*prot = strsep(tmp, ,)) != NULL) {
+   /* handle ,, */
+   if(strlen(*prot)  0) {
+   proto_type = get_proto_type(*prot);
+   if(proto_type != -1) {
+   protos[proto_index++] = proto_type;
+   protos_defined++;
+   }
+   }
+   }
+   return protos_defined;
+}
+
+
static void
parse_ports(const char *portspec)
{
@@ -188,6 +257,7 @@
size_t len, bufsize;
void *buf;
int hash, retry, vflag;
+   struct protoent *pent;

vflag = 0;
if (opt_4)
@@ -209,7 +279,9 @@
protoname = div;
break;
default:
-   abort();
+   pent = getprotobynumber(proto);
+   printf(protocol `%s' not supported.\n, pent-p_name);
+   exit(EXIT_FAILURE);
}

buf = NULL;
@@ -264,7 +336,9 @@
so = xip-xi_socket;
break;
default:
-   abort();
+   pent = getprotobynumber(proto);
+   printf(protocol `%s' not supported.\n, pent-p_name);
+   exit(EXIT_FAILURE);
}
if ((inp-inp_vflag  vflag) == 0)
continue;
@@ -573,19 +647,49 @@
}
}

+static int set_default_protos(void)
+{
+   struct protoent *prot;
+   const char **curr_proto;
+   int proto_index = 0;
+   int proto_count = 0;
+
+   /* determine the number of default protocols */
+   for(curr_proto = default_protos; *curr_proto; curr_proto++, 
proto_count++)
+   ;
+
+   init_protos(proto_count);
+
+   for(curr_proto = default_protos; *curr_proto; curr_proto++) {
+   prot = getprotobyname(*curr_proto);
+   if(prot == NULL) {
+   printf(Cannot determine default protocols\n);
+   exit(EXIT_FAILURE);
+   }
+   protos[proto_index++] = prot-p_proto;
+   }
+
+   return proto_index;
+}
+
+
static void
usage(void)
{
-   fprintf(stderr, Usage: sockstat [-46clu] [-p ports]\n);
+   fprintf(stderr, Usage: sockstat [-46clu] [-p ports] [-P protos]\n);
exit(1);
}

int
main(int argc, char *argv[])
{
-   int o;
+   /* if protos_defined remains -1, no -P was provided, sowe avoid
+   attempting to read from that int array later */
+   int protos_defined = -1;
+
+   int o, i;

-   while ((o = getopt(argc, argv, 46clp:uv)) != -1)
+   while ((o = getopt(argc, argv, 46clp:P:uv)) != -1)
switch (o) {
case '4':
opt_4 = 1;
@@ -602,6 +706,9 @@
case 'p':

Re: NFS on 6.1 limits at 4 Gig

2006-11-07 Thread Julian H. Stacey
John Baldwin wrote:
 On Thursday 02 November 2006 15:10, Julian H. Stacey wrote:
  John Baldwin wrote:
   On Thursday 02 November 2006 05:50, Julian Stacey wrote:
NFS fails on files = 4 Gig  Can someone confirm please. 

uname -r# 6.1-RELEASE   (both hosts)
# echo 1024 1024 * 4 * 1 + p | dc # 4194305   
dd if=/dev/zero of=junk bs=1k count=4194305 
ls -l junk  # 4294968320 bytes
rsh an_nfs_host ls -l /host/`hostname -s`/usr/tmp/junk # 1024 byte size!
# with count=4194304, ls shows 0 bytes.

It's not AMD failing, but NFS, as with an /etc/amd.map with a
non NFS entry for my host laps for efficiency (in case some
shell on host laps mounts itself), the full size 4294968320 is seen.
/etc/amd.map 
/defaults   
type:=host;fs:=${autodir}/${rhost};rhost:=${key}
lapstype:=link;fs:=..

It's not just ls, cmp fails too, ( as also does my
http://berklix.com/~jhs/src/bsd/jhs/bin/public/cmpd/cmpd.c )
cmp -z junk /host/laps/usr/tmp/junk # junk /host/laps/usr/tmp/junk 
differ: size

Is send-pr appropriate ?
   
   Are you using NFS v2 or v3?  v2 doesn't support large files.
   John Baldwin
  
  Thanks, I don't know !  Whatever 6.1-RELEASE comes standard with.
  
  After your mail I did cd /usr/ports ; echo */*nfs*
  net-mgmt/nfsen net/nfsshell net/pcnfsd net/unfs3
  /usr/ports/net/unfs3 offers a non ernel V3 server
  but I'd still need a v3 client I suppose ?
  Are 6.2-pre or current using V3 NFS then ?
  Hints which way to jump / where to RTFM please :-)
 
 It should default to v3, the nfs client in the base system can do either
 v2 or v3.  I'm not sure if amd is going to default to v2 with your map
 file though.

Ah Yes !  Fresh eyes :-)My /etc/amd.map had bit rot with vers=2 in
*   opts:=rw,grpid,resvport,vers=2,proto=udp,nodev
I tested with manually mounted mount_nfs -2  -3, then
removed vers=2 from amd.map  now all OK, comparing 5 gig files over NFS.

 You can use tcpdump on the port with NFS traffic to see
 if it's v2 or v3 though.

I tried tcpdump -v -t -s 192 -i rl0 port 2049
  IP (tos 0x0, ttl  64, id 52774, offset 0, flags [none], proto: UDP (17), 
length: 128) fire.jhs.private.1181802316  laps.jhs.private.nfs: 100 lookup fh 
1041,235166/2 usr2
  IP (tos 0x0, ttl  64, id 35491, offset 0, flags [none], proto: UDP (17), 
length: 156) laps.jhs.private.nfs  fire.jhs.private.1181802316: reply ok 128 
lookup fh 1041,235166/16512 DIR 40755 ids 0/0 sz 512

But didnt know how to read it for NFS 2/3 hence used mount_nfs -2  -3.
Problem solved.  Thanks John.

-- 
Julian Stacey.  BSD Unix C Net Consultancy, Munich/Muenchen  http://berklix.com
Mail Ascii, not HTML.   Ihr Rauch = mein allergischer Kopfschmerz.
http://berklix.org/free-software
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]


SEEK_HOLE and SEEK_DATA for sparse files any takers?

2006-11-07 Thread Pedro F Giffuni
Hi;

From http://blogs.sun.com/bonwick/date/200512

At this writing, SEEK_HOLE and SEEK_DATA are Solaris-specific. I encourage
(implore? beg?) other operating systems to adopt these lseek(2) extensions
verbatim (100% tax-free) so that sparse file navigation becomes a ubiquitous
feature that every backup and archiving program can rely on. It's long
overdue.

It should be mentioned that linux adopted them and they would help the ZFS
port.

cheers,

Pedro

__
Do You Yahoo!?
Poco spazio e tanto spam? Yahoo! Mail ti protegge dallo spam e ti da tanto 
spazio gratuito per i tuoi file e i messaggi 
http://mail.yahoo.it 
___
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to [EMAIL PROTECTED]