FreeBSD/contrib/bsnmp/snmpd/main.c
/*
 * Will return only _OK or _FAILED
 */
Will return only _OK or _FAILED
Will return only _OK or _FAILED
enum snmpd_input_err
snmp_input_finish(struct snmp_pdu *pdu, const u_char *rcvbuf, size_t rcvlen,
    u_char *sndbuf, size_t *sndlen, const char *source,
    enum snmpd_input_err ierr, int32_t ivar, void *data)
{
	struct snmp_pdu resp;
	struct asn_buf resp_b, pdu_b;
	enum snmp_ret ret;
	resp_b.asn_ptr = sndbuf;
	resp_b.asn_len = snmpd.txbuf;
	pdu_b.asn_cptr = rcvbuf;
	pdu_b.asn_len = rcvlen;
	if (ierr != SNMPD_INPUT_OK) {
		if (pdu->version == SNMP_V1)
			pdu->error_status = SNMP_ERR_BADVALUE;
		else if (ierr == SNMPD_INPUT_VALBADLEN)
			pdu->error_status = SNMP_ERR_WRONG_LENGTH;
		else if (ierr == SNMPD_INPUT_VALRANGE)
			pdu->error_status = SNMP_ERR_WRONG_VALUE;
		else
			pdu->error_status = SNMP_ERR_WRONG_ENCODING;
		pdu->error_index = ivar;
		if (snmp_make_errresp(pdu, &pdu_b, &resp_b) == SNMP_RET_IGN) {
			syslog(LOG_WARNING, "could not encode error response");
			snmpd_stats.silentDrops++;
			return (SNMPD_INPUT_FAILED);
		}
		if (debug.dump_pdus) {
			snmp_printf("%s <- ", source);
			snmp_pdu_dump(pdu);
		}
		*sndlen = (size_t)(resp_b.asn_ptr - sndbuf);
		return (SNMPD_INPUT_OK);
	}
	switch (pdu->type) {
	  case SNMP_PDU_GET:
		ret = snmp_get(pdu, &resp_b, &resp, data);
		break;
	  case SNMP_PDU_GETNEXT:
		ret = snmp_getnext(pdu, &resp_b, &resp, data);
		break;
	  case SNMP_PDU_SET:
		ret = snmp_set(pdu, &resp_b, &resp, data);
		break;
	  case SNMP_PDU_GETBULK:
		ret = snmp_getbulk(pdu, &resp_b, &resp, data);
		break;
	  default:
		ret = SNMP_RET_IGN;
		break;
	}
	switch (ret) {
	  case SNMP_RET_OK:
		if (debug.dump_pdus) {
			snmp_printf("%s <- ", source);
			snmp_pdu_dump(&resp);
		}
		*sndlen = (size_t)(resp_b.asn_ptr - sndbuf);
		snmp_pdu_free(&resp);
		return (SNMPD_INPUT_OK);
	  case SNMP_RET_IGN:
		snmpd_stats.silentDrops++;
		return (SNMPD_INPUT_FAILED);
	  case SNMP_RET_ERR:
		resp_b.asn_ptr = sndbuf;
		resp_b.asn_len = snmpd.txbuf;
		if (snmp_make_errresp(pdu, &pdu_b, &resp_b) == SNMP_RET_IGN) {
			syslog(LOG_WARNING, "could not encode error response");
			snmpd_stats.silentDrops++;
			return (SNMPD_INPUT_FAILED);
		} else {
			if (debug.dump_pdus) {
				snmp_printf("%s <- ", source);
				snmp_pdu_dump(pdu);
			}
			*sndlen = (size_t)(resp_b.asn_ptr - sndbuf);
			return (SNMPD_INPUT_OK);
		}
	}
	abort();
}
enum snmpd_input_err snmp_input_finish ( struct snmp_pdu * pdu , const u_char * rcvbuf , size_t rcvlen , u_char * sndbuf , size_t * sndlen , const char * source , enum snmpd_input_err ierr , int32_t ivar , void * data ) { struct snmp_pdu resp ; struct asn_buf resp_b , pdu_b ; enum snmp_ret ret ; resp_b . asn_ptr = sndbuf ; resp_b . asn_len = snmpd . txbuf ; pdu_b . asn_cptr = rcvbuf ; pdu_b . asn_len = rcvlen ; if ( ierr != SNMPD_INPUT_OK ) { if ( pdu -> version == SNMP_V1 ) pdu -> error_status = SNMP_ERR_BADVALUE ; else if ( ierr == SNMPD_INPUT_VALBADLEN ) pdu -> error_status = SNMP_ERR_WRONG_LENGTH ; else if ( ierr == SNMPD_INPUT_VALRANGE ) pdu -> error_status = SNMP_ERR_WRONG_VALUE ; else pdu -> error_status = SNMP_ERR_WRONG_ENCODING ; pdu -> error_index = ivar ; if ( snmp_make_errresp ( pdu , & pdu_b , & resp_b ) == SNMP_RET_IGN ) { syslog ( LOG_WARNING , " " ) ; snmpd_stats . silentDrops ++ ; return ( SNMPD_INPUT_FAILED ) ; } if ( debug . dump_pdus ) { snmp_printf ( " " , source ) ; snmp_pdu_dump ( pdu ) ; } * sndlen = ( size_t ) ( resp_b . asn_ptr - sndbuf ) ; return ( SNMPD_INPUT_OK ) ; } switch ( pdu -> type ) { case SNMP_PDU_GET : ret = snmp_get ( pdu , & resp_b , & resp , data ) ; break ; case SNMP_PDU_GETNEXT : ret = snmp_getnext ( pdu , & resp_b , & resp , data ) ; break ; case SNMP_PDU_SET : ret = snmp_set ( pdu , & resp_b , & resp , data ) ; break ; case SNMP_PDU_GETBULK : ret = snmp_getbulk ( pdu , & resp_b , & resp , data ) ; break ; default : ret = SNMP_RET_IGN ; break ; } switch ( ret ) { case SNMP_RET_OK : if ( debug . dump_pdus ) { snmp_printf ( " " , source ) ; snmp_pdu_dump ( & resp ) ; } * sndlen = ( size_t ) ( resp_b . asn_ptr - sndbuf ) ; snmp_pdu_free ( & resp ) ; return ( SNMPD_INPUT_OK ) ; case SNMP_RET_IGN : snmpd_stats . silentDrops ++ ; return ( SNMPD_INPUT_FAILED ) ; case SNMP_RET_ERR : resp_b . asn_ptr = sndbuf ; resp_b . asn_len = snmpd . txbuf ; if ( snmp_make_errresp ( pdu , & pdu_b , & resp_b ) == SNMP_RET_IGN ) { syslog ( LOG_WARNING , " " ) ; snmpd_stats . silentDrops ++ ; return ( SNMPD_INPUT_FAILED ) ; } else { if ( debug . dump_pdus ) { snmp_printf ( " " , source ) ; snmp_pdu_dump ( pdu ) ; } * sndlen = ( size_t ) ( resp_b . asn_ptr - sndbuf ) ; return ( SNMPD_INPUT_OK ) ; } } abort ( ) ; }
Will return only _OK or _FAILED
Will return only _OK or _FAILED
/* error decoding the input of a SET */ /* normal return - send a response */ /* error - send nothing */ /* error - send error response. The snmp routine has
		 * changed the error fields in the original message. */