usr.sbin/amd/amd/rpc_fwd.c
/*
 * Called when some data arrives on the forwarding socket
 */
Called when some data arrives on the forwarding socket
Called when some data arrives on the forwarding socket
void fwd_reply()
{
	int len;
#ifdef DYNAMIC_BUFFERS
	voidp pkt;
#else
	u_int pkt[MAX_PACKET_SIZE/sizeof(u_int)+1];
#endif 
	u_int *pkt_int;
	int rc;
	rpc_forward *p;
	struct sockaddr_in src_addr;
	int src_addr_len;
#ifdef DYNAMIC_BUFFERS
	if (ioctl(fwd_sock, FIONREAD, &len) < 0) {
		plog(XLOG_ERROR, "Error reading packet size: %m");
		return;
	}
	pkt = (voidp) malloc((unsigned) len);
	if (!pkt) {
		plog(XLOG_ERROR, "Out of buffers in fwd_reply");
		return;
	}
#else
	len = MAX_PACKET_SIZE;
#endif 
again:
	src_addr_len = sizeof(src_addr);
	rc = recvfrom(fwd_sock, (char *) pkt, len, 0,
			(struct sockaddr *) &src_addr, &src_addr_len);
	if (rc < 0 || src_addr_len != sizeof(src_addr) ||
			src_addr.sin_family != AF_INET) {
		if (rc < 0 && errno == EINTR)
			goto again;
		plog(XLOG_ERROR, "Error reading RPC reply: %m");
		goto out;
	}
#ifdef DYNAMIC_BUFFERS
	if (rc != len) {
		plog(XLOG_ERROR, "Short read in fwd_reply");
		goto out;
	}
#endif 
	if ((int)amd_state >= (int)Finishing)
		goto out;
	pkt_int = (u_int *) pkt;
#ifdef DEBUG
	switch (*pkt_int & RPC_XID_MASK) {
	case RPC_XID_PORTMAP: dlog("Receiving PORTMAP reply"); break;
	case RPC_XID_MOUNTD: dlog("Receiving MOUNTD reply %#x", *pkt_int); break;
	case RPC_XID_NFSPING: dlog("Receiving NFS ping %#x", *pkt_int); break;
	default: dlog("UNKNOWN RPC XID"); break;
	}
#endif 
	p = fwd_locate(*pkt_int);
	if (!p) {
#ifdef DEBUG
		dlog("Can't forward reply id %#x", *pkt_int);
#endif 
		goto out;
	}
	if (p->rf_fwd) {
		*pkt_int = p->rf_oldid;
		(*p->rf_fwd)((voidp) pkt, rc, &src_addr, &p->rf_sin, p->rf_ptr, TRUE);
	}
	fwd_free(p);
out:;
#ifdef DYNAMIC_BUFFERS
	free((voidp) pkt);
#endif 
}
void fwd_reply ( ) { int len ; #ifdef DYNAMIC_BUFFERS voidp pkt ; #else u_int pkt [ MAX_PACKET_SIZE / sizeof ( u_int ) + 1 ] ; #endif u_int * pkt_int ; int rc ; rpc_forward * p ; struct sockaddr_in src_addr ; int src_addr_len ; #ifdef DYNAMIC_BUFFERS if ( ioctl ( fwd_sock , FIONREAD , & len ) < 0 ) { plog ( XLOG_ERROR , " " ) ; return ; } pkt = ( voidp ) malloc ( ( unsigned ) len ) ; if ( ! pkt ) { plog ( XLOG_ERROR , " " ) ; return ; } #else len = MAX_PACKET_SIZE ; #endif again : src_addr_len = sizeof ( src_addr ) ; rc = recvfrom ( fwd_sock , ( char * ) pkt , len , 0 , ( struct sockaddr * ) & src_addr , & src_addr_len ) ; if ( rc < 0 || src_addr_len != sizeof ( src_addr ) || src_addr . sin_family != AF_INET ) { if ( rc < 0 && errno == EINTR ) goto again ; plog ( XLOG_ERROR , " " ) ; goto out ; } #ifdef DYNAMIC_BUFFERS if ( rc != len ) { plog ( XLOG_ERROR , " " ) ; goto out ; } #endif if ( ( int ) amd_state >= ( int ) Finishing ) goto out ; pkt_int = ( u_int * ) pkt ; #ifdef DEBUG switch ( * pkt_int & RPC_XID_MASK ) { case RPC_XID_PORTMAP : dlog ( " " ) ; break ; case RPC_XID_MOUNTD : dlog ( " " , * pkt_int ) ; break ; case RPC_XID_NFSPING : dlog ( " " , * pkt_int ) ; break ; default : dlog ( " " ) ; break ; } #endif p = fwd_locate ( * pkt_int ) ; if ( ! p ) { #ifdef DEBUG dlog ( " " , * pkt_int ) ; #endif goto out ; } if ( p -> rf_fwd ) { * pkt_int = p -> rf_oldid ; ( * p -> rf_fwd ) ( ( voidp ) pkt , rc , & src_addr , & p -> rf_sin , p -> rf_ptr , TRUE ) ; } fwd_free ( p ) ; out : ; #ifdef DYNAMIC_BUFFERS free ( ( voidp ) pkt ) ; #endif }
Called when some data arrives on the forwarding socket
Called when some data arrives on the forwarding socket
/* DYNAMIC_BUFFERS */ /*
	 * Determine the length of the packet
	 */ /*
	 * Allocate a buffer
	 */ /* DYNAMIC_BUFFERS */ /*
	 * Read the packet and check for validity
	 */ /* DYNAMIC_BUFFERS */ /*
	 * Do no more work if finishing soon
	 */ /*
	 * Find packet reference
	 */ /* DEBUG */ /* DEBUG */ /*
		 * Put the original message id back
		 * into the packet.
		 */ /*
		 * Call forwarding function
		 */ /*
	 * Free forwarding info
	 */ /*
	 * Free the packet
	 */ /* DYNAMIC_BUFFERS */