SNMP: tiny preparation for SNMP to support more versions than just v1: store request version in struct snmp_msg_pstat so that the response can be sent with the same version (v2c might already work but getbulk is missing)

This commit is contained in:
goldsimon 2015-08-20 09:38:17 +02:00
parent a22a92b481
commit da5ccbf7d1
3 changed files with 9 additions and 2 deletions

View File

@ -1031,6 +1031,7 @@ snmp_pdu_header_check(struct pbuf *p, u16_t ofs, u16_t pdu_len, u16_t *ofs_ret,
snmp_inc_snmpinbadversions(); snmp_inc_snmpinbadversions();
return ERR_ARG; return ERR_ARG;
} }
m_stat->version = (u8_t)version;
ofs += (1 + len_octets + len); ofs += (1 + len_octets + len);
snmp_asn1_dec_type(p, ofs, &type); snmp_asn1_dec_type(p, ofs, &type);
derr = snmp_asn1_dec_length(p, ofs+1, &len_octets, &len); derr = snmp_asn1_dec_length(p, ofs+1, &len_octets, &len);

View File

@ -328,6 +328,7 @@ static u16_t
snmp_resp_header_sum(struct snmp_msg_pstat *m_stat, u16_t vb_len) snmp_resp_header_sum(struct snmp_msg_pstat *m_stat, u16_t vb_len)
{ {
u16_t tot_len; u16_t tot_len;
s32_t snmp_req_ver;
struct snmp_resp_header_lengths *rhl; struct snmp_resp_header_lengths *rhl;
rhl = &m_stat->rhl; rhl = &m_stat->rhl;
@ -352,7 +353,8 @@ snmp_resp_header_sum(struct snmp_msg_pstat *m_stat, u16_t vb_len)
snmp_asn1_enc_length_cnt(rhl->comlen, &rhl->comlenlen); snmp_asn1_enc_length_cnt(rhl->comlen, &rhl->comlenlen);
tot_len += 1 + rhl->comlenlen + rhl->comlen; tot_len += 1 + rhl->comlenlen + rhl->comlen;
snmp_asn1_enc_s32t_cnt(snmp_version, &rhl->verlen); snmp_req_ver = m_stat->version;
snmp_asn1_enc_s32t_cnt(snmp_req_ver, &rhl->verlen);
snmp_asn1_enc_length_cnt(rhl->verlen, &rhl->verlenlen); snmp_asn1_enc_length_cnt(rhl->verlen, &rhl->verlenlen);
tot_len += 1 + rhl->verlen + rhl->verlenlen; tot_len += 1 + rhl->verlen + rhl->verlenlen;
@ -496,6 +498,7 @@ static u16_t
snmp_resp_header_enc(struct snmp_msg_pstat *m_stat, struct pbuf *p) snmp_resp_header_enc(struct snmp_msg_pstat *m_stat, struct pbuf *p)
{ {
u16_t ofs; u16_t ofs;
s32_t snmp_req_ver;
ofs = 0; ofs = 0;
snmp_asn1_enc_type(p, ofs, (SNMP_ASN1_UNIV | SNMP_ASN1_CONSTR | SNMP_ASN1_SEQ)); snmp_asn1_enc_type(p, ofs, (SNMP_ASN1_UNIV | SNMP_ASN1_CONSTR | SNMP_ASN1_SEQ));
@ -507,7 +510,8 @@ snmp_resp_header_enc(struct snmp_msg_pstat *m_stat, struct pbuf *p)
ofs += 1; ofs += 1;
snmp_asn1_enc_length(p, ofs, m_stat->rhl.verlen); snmp_asn1_enc_length(p, ofs, m_stat->rhl.verlen);
ofs += m_stat->rhl.verlenlen; ofs += m_stat->rhl.verlenlen;
snmp_asn1_enc_s32t(p, ofs, m_stat->rhl.verlen, snmp_version); snmp_req_ver = m_stat->version;
snmp_asn1_enc_s32t(p, ofs, m_stat->rhl.verlen, snmp_req_ver);
ofs += m_stat->rhl.verlen; ofs += m_stat->rhl.verlen;
snmp_asn1_enc_type(p, ofs, (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR)); snmp_asn1_enc_type(p, ofs, (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR));

View File

@ -226,6 +226,8 @@ struct snmp_msg_pstat
ip_addr_t sip; ip_addr_t sip;
/* source UDP port */ /* source UDP port */
u16_t sp; u16_t sp;
/* incoming snmp version */
u8_t version;
/* request type */ /* request type */
u8_t rt; u8_t rt;
/* request ID */ /* request ID */