Subject: counting dropped packets for UDP.
To: None <tech-net@netbsd.org>
From: Darren Reed <avalon@cairo.anu.edu.au>
List: tech-net
Date: 08/10/2004 18:50:32
I'm not sure how useful this is, given that UDP packet loss can happen
in many other ways, but this at least is intended to allow an application
to see what sort of loss it is experiencing due to buffering problems.

Is it worth adding in the relevant line of code, here and there, for TCP?

Or is it just a stupid idea, anyway ?

The patches below cover AF_INET{,6} and AF_UNIX.

Darren

*** /sys/kern/uipc_usrreq.c.dist	Sun May 23 08:52:13 2004
--- /sys/kern/uipc_usrreq.c	Tue Aug 10 13:33:05 2004
***************
*** 152,157 ****
--- 152,158 ----
  	    control) == 0) {
  		m_freem(control);
  		m_freem(m);
+ 		so2->so_rcv.sb_overflowed++;
  		return (ENOBUFS);
  	} else {
  		sorwakeup(so2);
*** /sys/kern/uipc_socket.c.dist	Tue May 25 14:30:32 2004
--- /sys/kern/uipc_socket.c	Tue Aug 10 16:39:18 2004
***************
*** 1595,1600 ****
--- 1595,1604 ----
  			break;
  		    }
  
+ 		case SO_OVERFLOWED:
+ 			*mtod(m, int *) = so->so_rcv.sb_overflowed;
+ 			break;
+ 
  		default:
  			(void)m_free(m);
  			return (ENOPROTOOPT);
*** /sys/sys/socketvar.h.dist	Tue Aug 10 18:36:11 2004
--- /sys/sys/socketvar.h	Tue Aug 10 13:22:30 2004
***************
*** 63,68 ****
--- 63,69 ----
  					   socket buffer */
  	short	sb_flags;		/* flags, see below */
  	short	sb_timeo;		/* timeout for read/write */
+ 	u_long	sb_overflowed;		/* # of drops due to full buffer */
  };
  
  #ifndef SB_MAX
*** /sys/sys/socket.h.dist	Tue Aug 10 18:35:57 2004
--- /sys/sys/socket.h	Tue Aug 10 13:36:46 2004
***************
*** 133,138 ****
--- 133,139 ----
  #define SO_RCVTIMEO	0x1006		/* receive timeout */
  #define	SO_ERROR	0x1007		/* get error status and clear */
  #define	SO_TYPE		0x1008		/* get socket type */
+ #define	SO_OVERFLOWED	0x1009		/* datagrams: return packets dropped */
  
  /*
   * Structure used for manipulating linger option.
*** /sys/netinet/udp_usrreq.c.dist	Tue Aug 10 18:36:54 2004
--- /sys/netinet/udp_usrreq.c	Tue Aug 10 13:22:58 2004
***************
*** 511,516 ****
--- 511,517 ----
  			m_freem(n);
  			if (opts)
  				m_freem(opts);
+ 			so->so_rcv.sb_overflowed++;
  			udpstat.udps_fullsock++;
  		} else
  			sorwakeup(so);
***************
*** 556,561 ****
--- 557,563 ----
  			m_freem(n);
  			if (opts)
  				m_freem(opts);
+ 			so->so_rcv.sb_overflowed++;
  			udp6stat.udp6s_fullsock++;
  		} else
  			sorwakeup(so);