• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /freebsd-12-stable/contrib/bsnmp/lib/

Lines Matching defs:pdu

199 snmp_parse_pdus_hdr(struct asn_buf *b, struct snmp_pdu *pdu, asn_len_t *lenp)
201 if (pdu->type == SNMP_PDU_TRAP) {
202 if (asn_get_objid(b, &pdu->enterprise) != ASN_ERR_OK) {
206 if (asn_get_ipaddress(b, pdu->agent_addr) != ASN_ERR_OK) {
210 if (asn_get_integer(b, &pdu->generic_trap) != ASN_ERR_OK) {
214 if (asn_get_integer(b, &pdu->specific_trap) != ASN_ERR_OK) {
218 if (asn_get_timeticks(b, &pdu->time_stamp) != ASN_ERR_OK) {
223 if (asn_get_integer(b, &pdu->request_id) != ASN_ERR_OK) {
227 if (asn_get_integer(b, &pdu->error_status) != ASN_ERR_OK) {
231 if (asn_get_integer(b, &pdu->error_index) != ASN_ERR_OK) {
246 parse_pdus(struct asn_buf *b, struct snmp_pdu *pdu, int32_t *ip)
252 err = snmp_parse_pdus_hdr(b, pdu, &len);
258 v = pdu->bindings;
261 if (pdu->nbindings == SNMP_MAX_BINDINGS) {
271 *ip = pdu->nbindings + 1;
273 pdu->nbindings++;
284 parse_secparams(struct asn_buf *b, struct snmp_pdu *pdu)
307 if (asn_get_octetstring(&tb, (u_char *)&pdu->engine.engine_id,
312 pdu->engine.engine_len = octs_len;
314 if (asn_get_integer(&tb, &pdu->engine.engine_boots) != ASN_ERR_OK) {
319 if (asn_get_integer(&tb, &pdu->engine.engine_time) != ASN_ERR_OK) {
325 if (asn_get_octetstring(&tb, (u_char *)&pdu->user.sec_name, &octs_len)
330 pdu->user.sec_name[octs_len] = '\0';
332 octs_len = sizeof(pdu->msg_digest);
333 if (asn_get_octetstring(&tb, (u_char *)&pdu->msg_digest, &octs_len) !=
334 ASN_ERR_OK || ((pdu->flags & SNMP_MSG_AUTH_FLAG) != 0 &&
335 octs_len != sizeof(pdu->msg_digest))) {
340 octs_len = sizeof(pdu->msg_salt);
341 if (asn_get_octetstring(&tb, (u_char *)&pdu->msg_salt, &octs_len) !=
342 ASN_ERR_OK ||((pdu->flags & SNMP_MSG_PRIV_FLAG) != 0 &&
343 octs_len != sizeof(pdu->msg_salt))) {
348 if ((pdu->flags & SNMP_MSG_AUTH_FLAG) != 0) {
349 pdu->digest_ptr = b->asn_ptr - SNMP_USM_AUTH_SIZE;
350 pdu->digest_ptr -= octs_len + ASN_MAXLENLEN;
357 pdu_encode_secparams(struct asn_buf *b, struct snmp_pdu *pdu)
372 if (asn_put_octetstring(&tb, (u_char *)pdu->engine.engine_id,
373 pdu->engine.engine_len) != ASN_ERR_OK)
376 if (asn_put_integer(&tb, pdu->engine.engine_boots) != ASN_ERR_OK)
379 if (asn_put_integer(&tb, pdu->engine.engine_time) != ASN_ERR_OK)
382 if (asn_put_octetstring(&tb, (u_char *)pdu->user.sec_name,
383 strlen(pdu->user.sec_name)) != ASN_ERR_OK)
386 if ((pdu->flags & SNMP_MSG_AUTH_FLAG) != 0) {
388 if (asn_put_octetstring(&tb, (u_char *)pdu->msg_digest,
389 sizeof(pdu->msg_digest)) != ASN_ERR_OK)
392 if (asn_put_octetstring(&tb, (u_char *)pdu->msg_digest, 0)
397 if ((pdu->flags & SNMP_MSG_PRIV_FLAG) != 0) {
398 if (asn_put_octetstring(&tb, (u_char *)pdu->msg_salt,
399 sizeof(pdu->msg_salt)) != ASN_ERR_OK)
402 if (asn_put_octetstring(&tb, (u_char *)pdu->msg_salt, 0)
410 if ((pdu->flags & SNMP_MSG_AUTH_FLAG) != 0)
411 pdu->digest_ptr = b->asn_ptr + auth_off - moved;
415 pdu->digest_ptr += ASN_MAXLENLEN;
417 if ((pdu->flags & SNMP_MSG_PRIV_FLAG) != 0 && asn_put_temp_header(b,
418 ASN_TYPE_OCTETSTRING, &pdu->encrypted_ptr) != ASN_ERR_OK)
431 snmp_pdu_decode(struct asn_buf *b, struct snmp_pdu *pdu, int32_t *ip)
435 if ((code = snmp_pdu_decode_header(b, pdu)) != SNMP_CODE_OK)
438 if (pdu->version == SNMP_V3) {
439 if (pdu->security_model != SNMP_SECMODEL_USM)
441 if ((code = snmp_pdu_decode_secmode(b, pdu)) != SNMP_CODE_OK)
445 code = snmp_pdu_decode_scoped(b, pdu, ip);
449 snmp_pdu_free(pdu);
453 if (pdu->version == SNMP_Verr)
464 snmp_pdu_decode_header(struct asn_buf *b, struct snmp_pdu *pdu)
470 pdu->outer_ptr = b->asn_ptr;
471 pdu->outer_len = b->asn_len;
474 snmp_error("cannot decode pdu header");
492 pdu->version = SNMP_V1;
494 pdu->version = SNMP_V2c;
496 pdu->version = SNMP_V3;
498 pdu->version = SNMP_Verr;
503 if (pdu->version == SNMP_V3) {
505 snmp_error("cannot decode pdu global data header");
509 if (asn_get_integer(b, &pdu->identifier) != ASN_ERR_OK) {
514 if (asn_get_integer(b, &pdu->engine.max_msg_size)
521 if (asn_get_octetstring(b, (u_char *)&pdu->flags,
527 if (asn_get_integer(b, &pdu->security_model) != ASN_ERR_OK) {
532 if (pdu->security_model != SNMP_SECMODEL_USM)
535 if (parse_secparams(b, pdu) != ASN_ERR_OK)
539 if (asn_get_octetstring(b, (u_char *)pdu->community,
544 pdu->community[octs_len] = '\0';
551 snmp_pdu_decode_scoped(struct asn_buf *b, struct snmp_pdu *pdu, int32_t *ip)
557 if (pdu->version == SNMP_V3) {
559 snmp_error("cannot decode scoped pdu header");
564 if (asn_get_octetstring(b, (u_char *)&pdu->context_engine,
569 pdu->context_engine_len = len;
572 if (asn_get_octetstring(b, (u_char *)&pdu->context_name,
577 pdu->context_name[len] = '\0';
581 snmp_error("cannot get pdu header");
586 snmp_error("bad pdu header tag");
589 pdu->type = type & ASN_TYPE_MASK;
591 switch (pdu->type) {
600 if (pdu->version != SNMP_V1) {
601 snmp_error("bad pdu type %u", pdu->type);
610 if (pdu->version == SNMP_V1) {
611 snmp_error("bad pdu type %u", pdu->type);
617 snmp_error("bad pdu type %u", pdu->type);
624 err = parse_pdus(b, pdu, ip);
629 snmp_error("ignoring trailing junk after pdu");
637 snmp_pdu_decode_secmode(struct asn_buf *b, struct snmp_pdu *pdu)
643 if (pdu->user.auth_proto != SNMP_AUTH_NOAUTH &&
644 (pdu->flags & SNMP_MSG_AUTH_FLAG) == 0)
647 if ((code = snmp_pdu_calc_digest(pdu, digest)) !=
651 if (pdu->user.auth_proto != SNMP_AUTH_NOAUTH &&
652 memcmp(digest, pdu->msg_digest, sizeof(pdu->msg_digest)) != 0)
655 if (pdu->user.priv_proto != SNMP_PRIV_NOPRIV && (asn_get_header(b, &type,
656 &pdu->scoped_len) != ASN_ERR_OK || type != ASN_TYPE_OCTETSTRING)) {
657 snmp_error("cannot decode encrypted pdu");
660 pdu->scoped_ptr = b->asn_ptr;
662 if (pdu->user.priv_proto != SNMP_PRIV_NOPRIV &&
663 (pdu->flags & SNMP_MSG_PRIV_FLAG) == 0)
666 if ((code = snmp_pdu_decrypt(pdu)) != SNMP_CODE_OK)
738 snmp_pdu_encode_header(struct asn_buf *b, struct snmp_pdu *pdu)
744 &pdu->outer_ptr) != ASN_ERR_OK)
747 if (pdu->version == SNMP_V1)
749 else if (pdu->version == SNMP_V2c)
751 else if (pdu->version == SNMP_V3)
758 if (pdu->version == SNMP_V3) {
763 if (asn_put_integer(b, pdu->identifier) != ASN_ERR_OK)
766 if (asn_put_integer(b, pdu->engine.max_msg_size) != ASN_ERR_OK)
769 if (pdu->type != SNMP_PDU_RESPONSE &&
770 pdu->type != SNMP_PDU_TRAP &&
771 pdu->type != SNMP_PDU_TRAP2 &&
772 pdu->type != SNMP_PDU_REPORT)
773 pdu->flags |= SNMP_MSG_REPORT_FLAG;
775 if (asn_put_octetstring(b, (u_char *)&pdu->flags, 1)
779 if (asn_put_integer(b, pdu->security_model) != ASN_ERR_OK)
785 if (pdu->security_model != SNMP_SECMODEL_USM)
788 if (pdu_encode_secparams(b, pdu) != SNMP_CODE_OK)
793 ASN_TYPE_CONSTRUCTED), &pdu->scoped_ptr) != ASN_ERR_OK)
796 if (asn_put_octetstring(b, (u_char *)pdu->context_engine,
797 pdu->context_engine_len) != ASN_ERR_OK)
800 if (asn_put_octetstring(b, (u_char *)pdu->context_name,
801 strlen(pdu->context_name)) != ASN_ERR_OK)
804 if (asn_put_octetstring(b, (u_char *)pdu->community,
805 strlen(pdu->community)) != ASN_ERR_OK)
810 pdu->type), &pdu->pdu_ptr) != ASN_ERR_OK)
813 if (pdu->type == SNMP_PDU_TRAP) {
814 if (pdu->version != SNMP_V1 ||
815 asn_put_objid(b, &pdu->enterprise) != ASN_ERR_OK ||
816 asn_put_ipaddress(b, pdu->agent_addr) != ASN_ERR_OK ||
817 asn_put_integer(b, pdu->generic_trap) != ASN_ERR_OK ||
818 asn_put_integer(b, pdu->specific_trap) != ASN_ERR_OK ||
819 asn_put_timeticks(b, pdu->time_stamp) != ASN_ERR_OK)
822 if (pdu->version == SNMP_V1 && (pdu->type == SNMP_PDU_GETBULK ||
823 pdu->type == SNMP_PDU_INFORM ||
824 pdu->type == SNMP_PDU_TRAP2 ||
825 pdu->type == SNMP_PDU_REPORT))
828 if (asn_put_integer(b, pdu->request_id) != ASN_ERR_OK ||
829 asn_put_integer(b, pdu->error_status) != ASN_ERR_OK ||
830 asn_put_integer(b, pdu->error_index) != ASN_ERR_OK)
835 &pdu->vars_ptr) != ASN_ERR_OK)
842 snmp_pdu_fix_padd(struct asn_buf *b, struct snmp_pdu *pdu)
846 if (pdu->user.priv_proto == SNMP_PRIV_DES && pdu->scoped_len % 8 != 0) {
847 padlen = 8 - (pdu->scoped_len % 8);
850 pdu->scoped_len += padlen;
857 snmp_fix_encoding(struct asn_buf *b, struct snmp_pdu *pdu)
862 if (asn_commit_header(b, pdu->vars_ptr, NULL) != ASN_ERR_OK ||
863 asn_commit_header(b, pdu->pdu_ptr, NULL) != ASN_ERR_OK)
866 if (pdu->version == SNMP_V3) {
867 if (asn_commit_header(b, pdu->scoped_ptr, NULL) != ASN_ERR_OK)
870 pdu->scoped_len = b->asn_ptr - pdu->scoped_ptr;
871 if (snmp_pdu_fix_padd(b, pdu) != ASN_ERR_OK)
874 if (pdu->security_model != SNMP_SECMODEL_USM)
877 if (snmp_pdu_encrypt(pdu) != SNMP_CODE_OK)
880 if (pdu->user.priv_proto != SNMP_PRIV_NOPRIV &&
881 asn_commit_header(b, pdu->encrypted_ptr, NULL) != ASN_ERR_OK)
885 if (asn_commit_header(b, pdu->outer_ptr, &moved) != ASN_ERR_OK)
888 pdu->outer_len = b->asn_ptr - pdu->outer_ptr;
889 pdu->digest_ptr -= moved;
891 if (pdu->version == SNMP_V3) {
892 if ((code = snmp_pdu_calc_digest(pdu, pdu->msg_digest)) !=
896 if ((pdu->flags & SNMP_MSG_AUTH_FLAG) != 0)
897 memcpy(pdu->digest_ptr, pdu->msg_digest,
898 sizeof(pdu->msg_digest));
996 snmp_pdu_encode(struct snmp_pdu *pdu, struct asn_buf *resp_b)
1001 if ((err = snmp_pdu_encode_header(resp_b, pdu)) != SNMP_CODE_OK)
1003 for (idx = 0; idx < pdu->nbindings; idx++)
1004 if (snmp_binding_encode(resp_b, &pdu->bindings[idx])
1008 return (snmp_fix_encoding(resp_b, pdu));
1078 dump_bindings(const struct snmp_pdu *pdu)
1082 for (i = 0; i < pdu->nbindings; i++) {
1084 dump_binding(&pdu->bindings[i]);
1090 dump_notrap(const struct snmp_pdu *pdu)
1092 snmp_printf(" request_id=%d", pdu->request_id);
1093 snmp_printf(" error_status=%d", pdu->error_status);
1094 snmp_printf(" error_index=%d\n", pdu->error_index);
1095 dump_bindings(pdu);
1099 snmp_pdu_dump(const struct snmp_pdu *pdu)
1115 if (pdu->version == SNMP_V1)
1117 else if (pdu->version == SNMP_V2c)
1119 else if (pdu->version == SNMP_V3)
1124 switch (pdu->type) {
1126 snmp_printf("%s %s '%s'", types[pdu->type], vers, pdu->community);
1127 snmp_printf(" enterprise=%s", asn_oid2str_r(&pdu->enterprise, buf));
1128 snmp_printf(" agent_addr=%u.%u.%u.%u", pdu->agent_addr[0],
1129 pdu->agent_addr[1], pdu->agent_addr[2], pdu->agent_addr[3]);
1130 snmp_printf(" generic_trap=%d", pdu->generic_trap);
1131 snmp_printf(" specific_trap=%d", pdu->specific_trap);
1132 snmp_printf(" time-stamp=%u\n", pdu->time_stamp);
1133 dump_bindings(pdu);
1144 snmp_printf("%s %s '%s'", types[pdu->type], vers, pdu->community);
1145 dump_notrap(pdu);
1149 snmp_printf("bad pdu type %u\n", pdu->type);
1187 snmp_pdu_init_secparams(struct snmp_pdu *pdu)
1191 if (pdu->user.auth_proto != SNMP_AUTH_NOAUTH)
1192 pdu->flags |= SNMP_MSG_AUTH_FLAG;
1194 switch (pdu->user.priv_proto) {
1196 memcpy(pdu->msg_salt, &pdu->engine.engine_boots,
1197 sizeof(pdu->engine.engine_boots));
1199 memcpy(pdu->msg_salt + sizeof(pdu->engine.engine_boots), &rval,
1201 pdu->flags |= SNMP_MSG_PRIV_FLAG;
1205 memcpy(pdu->msg_salt, &rval, sizeof(int32_t));
1207 memcpy(pdu->msg_salt + sizeof(int32_t), &rval, sizeof(int32_t));
1208 pdu->flags |= SNMP_MSG_PRIV_FLAG;
1216 snmp_pdu_free(struct snmp_pdu *pdu)
1220 for (i = 0; i < pdu->nbindings; i++)
1221 snmp_value_free(&pdu->bindings[i]);
1222 pdu->nbindings = 0;