Lines Matching +full:tp +full:- +full:link

2  * Copyright (c) 2001-2003
64 TAILQ_ENTRY(depend) link;
104 TAILQ_INIT(&context->dlist); in snmp_init_context()
106 return (&context->ctx); in snmp_init_context()
117 struct snmp_node *tp; in find_node() local
121 asn_oid2str_r(&value->var, oidbuf)); in find_node()
125 * sub-oid from the variable) we have found what we are for. in find_node()
128 for (tp = tree; tp < tree + tree_size; tp++) { in find_node()
129 if (asn_is_suboid(&tp->oid, &value->var)) in find_node()
131 if (asn_compare_oid(&tp->oid, &value->var) >= 0) in find_node()
142 if (tp->type == SNMP_NODE_LEAF && in find_node()
143 (value->var.len != tp->oid.len + 1 || in find_node()
144 value->var.subs[tp->oid.len] != 0)) { in find_node()
152 asn_oid2str_r(&value->var, oidbuf)); in find_node()
153 return (tp); in find_node()
159 struct snmp_node *tp; in find_subnode() local
161 for (tp = tree; tp < tree + tree_size; tp++) { in find_subnode()
162 if (asn_is_suboid(&value->var, &tp->oid)) in find_subnode()
163 return (tp); in find_subnode()
172 strcpy(resp->community, pdu->community); in snmp_pdu_create_response()
173 resp->version = pdu->version; in snmp_pdu_create_response()
174 if (pdu->flags & SNMP_MSG_AUTODISCOVER) in snmp_pdu_create_response()
175 resp->type = SNMP_PDU_REPORT; /* RFC 3414.4 */ in snmp_pdu_create_response()
177 resp->type = SNMP_PDU_RESPONSE; in snmp_pdu_create_response()
178 resp->request_id = pdu->request_id; in snmp_pdu_create_response()
179 resp->version = pdu->version; in snmp_pdu_create_response()
181 if (resp->version != SNMP_V3) in snmp_pdu_create_response()
184 memcpy(&resp->engine, &pdu->engine, sizeof(pdu->engine)); in snmp_pdu_create_response()
185 memcpy(&resp->user, &pdu->user, sizeof(pdu->user)); in snmp_pdu_create_response()
187 resp->identifier = pdu->identifier; in snmp_pdu_create_response()
188 resp->security_model = pdu->security_model; in snmp_pdu_create_response()
189 resp->context_engine_len = pdu->context_engine_len; in snmp_pdu_create_response()
190 memcpy(resp->context_engine, pdu->context_engine, in snmp_pdu_create_response()
191 resp->context_engine_len); in snmp_pdu_create_response()
192 strlcpy(resp->context_name, pdu->context_name, in snmp_pdu_create_response()
193 sizeof(resp->context_name)); in snmp_pdu_create_response()
207 struct snmp_node *tp; in snmp_get() local
218 /* cannot even encode header - very bad */ in snmp_get()
221 for (i = 0; i < pdu->nbindings; i++) { in snmp_get()
222 resp->bindings[i].var = pdu->bindings[i].var; in snmp_get()
223 if ((tp = find_node(&pdu->bindings[i], &except)) == NULL) { in snmp_get()
224 if (pdu->version == SNMP_V1) { in snmp_get()
227 pdu->error_status = SNMP_ERR_NOSUCHNAME; in snmp_get()
228 pdu->error_index = i + 1; in snmp_get()
234 resp->bindings[i].syntax = except; in snmp_get()
238 resp->bindings[i].syntax = tp->syntax; in snmp_get()
239 ret = (*tp->op)(&context.ctx, &resp->bindings[i], in snmp_get()
240 tp->oid.len, tp->index, SNMP_OP_GET); in snmp_get()
245 if (pdu->version == SNMP_V1) { in snmp_get()
246 pdu->error_status = SNMP_ERR_NOSUCHNAME; in snmp_get()
247 pdu->error_index = i + 1; in snmp_get()
253 resp->bindings[i].syntax = SNMP_SYNTAX_NOSUCHINSTANCE; in snmp_get()
256 pdu->error_status = SNMP_ERR_GENERR; in snmp_get()
257 pdu->error_index = i + 1; in snmp_get()
262 resp->nbindings++; in snmp_get()
264 err = snmp_binding_encode(resp_b, &resp->bindings[i]); in snmp_get()
267 pdu->error_status = SNMP_ERR_TOOBIG; in snmp_get()
268 pdu->error_index = 0; in snmp_get()
275 pdu->error_status = SNMP_ERR_GENERR; in snmp_get()
276 pdu->error_index = i + 1; in snmp_get()
293 struct snmp_node *tp; in next_node() local
297 asn_oid2str_r(&value->var, oidbuf)); in next_node()
300 for (tp = tree; tp < tree + tree_size; tp++) { in next_node()
301 if (asn_is_suboid(&tp->oid, &value->var)) { in next_node()
302 /* the tree OID is a sub-oid of the requested OID. */ in next_node()
303 if (tp->type == SNMP_NODE_LEAF) { in next_node()
304 if (tp->oid.len == value->var.len) { in next_node()
308 asn_oid2str_r(&tp->oid, oidbuf)); in next_node()
309 return (tp); in next_node()
315 asn_oid2str_r(&tp->oid, oidbuf)); in next_node()
316 return (tp); in next_node()
318 } else if (asn_is_suboid(&value->var, &tp->oid) || in next_node()
319 asn_compare_oid(&tp->oid, &value->var) >= 0) { in next_node()
322 asn_oid2str_r(&tp->oid, oidbuf)); in next_node()
324 return (tp); in next_node()
338 const struct snmp_node *tp; in do_getnext() local
341 if ((tp = next_node(inb, &next)) == NULL) in do_getnext()
346 if (tp->type == SNMP_NODE_LEAF || next) in do_getnext()
347 outb->var = tp->oid; in do_getnext()
349 outb->var = inb->var; in do_getnext()
352 outb->syntax = tp->syntax; in do_getnext()
353 if (tp->type == SNMP_NODE_LEAF) { in do_getnext()
355 outb->var.subs[outb->var.len++] = 0; in do_getnext()
356 ret = (*tp->op)(&context->ctx, outb, tp->oid.len, in do_getnext()
357 tp->index, SNMP_OP_GET); in do_getnext()
360 ret = (*tp->op)(&context->ctx, outb, tp->oid.len, in do_getnext()
361 tp->index, SNMP_OP_GETNEXT); in do_getnext()
367 asn_oid2str(&outb->var), ret); in do_getnext()
371 /* object has no data - try next */ in do_getnext()
372 if (++tp == tree + tree_size) in do_getnext()
376 snmp_debug("getnext: no data - avancing to %s", in do_getnext()
377 asn_oid2str(&tp->oid)); in do_getnext()
379 outb->var = tp->oid; in do_getnext()
384 outb->var = inb->var; in do_getnext()
385 if (pdu->version == SNMP_V1) { in do_getnext()
386 pdu->error_status = SNMP_ERR_NOSUCHNAME; in do_getnext()
389 outb->syntax = SNMP_SYNTAX_ENDOFMIBVIEW; in do_getnext()
392 pdu->error_status = SNMP_ERR_GENERR; in do_getnext()
420 for (i = 0; i < pdu->nbindings; i++) { in snmp_getnext()
421 result = do_getnext(&context, &pdu->bindings[i], in snmp_getnext()
422 &resp->bindings[i], pdu); in snmp_getnext()
425 pdu->error_index = i + 1; in snmp_getnext()
430 resp->nbindings++; in snmp_getnext()
432 err = snmp_binding_encode(resp_b, &resp->bindings[i]); in snmp_getnext()
435 pdu->error_status = SNMP_ERR_TOOBIG; in snmp_getnext()
436 pdu->error_index = 0; in snmp_getnext()
443 pdu->error_status = SNMP_ERR_GENERR; in snmp_getnext()
444 pdu->error_index = i + 1; in snmp_getnext()
476 /* cannot even encode header - very bad */ in snmp_getbulk()
479 if ((non_rep = pdu->error_status) > pdu->nbindings) in snmp_getbulk()
480 non_rep = pdu->nbindings; in snmp_getbulk()
482 /* non-repeaters */ in snmp_getbulk()
484 result = do_getnext(&context, &pdu->bindings[i], in snmp_getbulk()
485 &resp->bindings[resp->nbindings], pdu); in snmp_getbulk()
488 pdu->error_index = i + 1; in snmp_getbulk()
494 &resp->bindings[resp->nbindings++]); in snmp_getbulk()
502 pdu->error_status = SNMP_ERR_GENERR; in snmp_getbulk()
503 pdu->error_index = i + 1; in snmp_getbulk()
509 if (non_rep == pdu->nbindings) in snmp_getbulk()
513 for (cnt = 0; cnt < pdu->error_index; cnt++) { in snmp_getbulk()
515 for (i = non_rep; i < pdu->nbindings; i++) { in snmp_getbulk()
517 if (resp->nbindings == SNMP_MAX_BINDINGS) in snmp_getbulk()
522 result = do_getnext(&context, &pdu->bindings[i], in snmp_getbulk()
523 &resp->bindings[resp->nbindings], pdu); in snmp_getbulk()
526 &resp->bindings[resp->nbindings - in snmp_getbulk()
527 (pdu->nbindings - non_rep)], in snmp_getbulk()
528 &resp->bindings[resp->nbindings], pdu); in snmp_getbulk()
531 pdu->error_index = i + 1; in snmp_getbulk()
535 if (resp->bindings[resp->nbindings].syntax != in snmp_getbulk()
540 &resp->bindings[resp->nbindings++]); in snmp_getbulk()
548 pdu->error_status = SNMP_ERR_GENERR; in snmp_getbulk()
549 pdu->error_index = i + 1; in snmp_getbulk()
577 while (i-- > 0) { in rollback()
578 b = &pdu->bindings[i]; in rollback()
579 np = context->node[i]; in rollback()
581 context->ctx.scratch = &context->scratch[i]; in rollback()
583 ret = (*np->op)(&context->ctx, b, np->oid.len, np->index, in rollback()
588 "index %u", ret, asn_oid2str(&b->var), i); in rollback()
589 if (pdu->version != SNMP_V1) { in rollback()
590 pdu->error_status = SNMP_ERR_UNDO_FAILED; in rollback()
591 pdu->error_index = 0; in rollback()
606 TAILQ_FOREACH(context->depend, &context->dlist, link) { in snmp_dep_commit()
607 ctx->dep = &context->depend->dep; in snmp_dep_commit()
611 asn_oid2str(&ctx->dep->obj)); in snmp_dep_commit()
613 ret = context->depend->func(ctx, ctx->dep, SNMP_DEPOP_COMMIT); in snmp_dep_commit()
636 while ((context->depend = in snmp_dep_rollback()
637 TAILQ_PREV(context->depend, depend_list, link)) != NULL) { in snmp_dep_rollback()
638 ctx->dep = &context->depend->dep; in snmp_dep_rollback()
642 asn_oid2str(&ctx->dep->obj)); in snmp_dep_rollback()
644 ret = context->depend->func(ctx, ctx->dep, SNMP_DEPOP_ROLLBACK); in snmp_dep_rollback()
648 asn_oid2str_r(&ctx->dep->obj, objbuf), in snmp_dep_rollback()
649 asn_oid2str_r(&ctx->dep->idx, idxbuf)); in snmp_dep_rollback()
663 while ((d = TAILQ_FIRST(&context->dlist)) != NULL) { in snmp_dep_finish()
664 ctx->dep = &d->dep; in snmp_dep_finish()
665 (void)d->func(ctx, ctx->dep, SNMP_DEPOP_FINISH); in snmp_dep_finish()
666 TAILQ_REMOVE(&context->dlist, d, link); in snmp_dep_finish()
699 for (i = 0; i < pdu->nbindings; i++) { in snmp_set()
700 b = &pdu->bindings[i]; in snmp_set()
706 asn_oid2str_r(&b->var, oidbuf)); in snmp_set()
707 if (pdu->version == SNMP_V1) { in snmp_set()
708 pdu->error_index = i + 1; in snmp_set()
709 pdu->error_status = SNMP_ERR_NOSUCHNAME; in snmp_set()
712 pdu->error_index = i + 1; in snmp_set()
713 pdu->error_status = SNMP_ERR_NOT_WRITEABLE; in snmp_set()
715 pdu->error_index = i + 1; in snmp_set()
716 pdu->error_status = SNMP_ERR_NO_ACCESS; in snmp_set()
718 pdu->error_index = i + 1; in snmp_set()
719 pdu->error_status = SNMP_ERR_NO_CREATION; in snmp_set()
731 if (np->type == SNMP_NODE_LEAF && in snmp_set()
732 !(np->flags & SNMP_NODE_CANSET)) { in snmp_set()
733 if (pdu->version == SNMP_V1) { in snmp_set()
734 pdu->error_index = i + 1; in snmp_set()
735 pdu->error_status = SNMP_ERR_NOSUCHNAME; in snmp_set()
737 pdu->error_index = i + 1; in snmp_set()
738 pdu->error_status = SNMP_ERR_NOT_WRITEABLE; in snmp_set()
746 if (np->syntax != b->syntax) { in snmp_set()
747 if (pdu->version == SNMP_V1) { in snmp_set()
748 pdu->error_index = i + 1; in snmp_set()
749 pdu->error_status = SNMP_ERR_BADVALUE; /* v2: wrongType */ in snmp_set()
751 pdu->error_index = i + 1; in snmp_set()
752 pdu->error_status = SNMP_ERR_WRONG_TYPE; in snmp_set()
760 if (snmp_value_copy(&resp->bindings[i], b)) { in snmp_set()
761 pdu->error_index = i + 1; in snmp_set()
762 pdu->error_status = SNMP_ERR_GENERR; in snmp_set()
766 asnerr = snmp_binding_encode(resp_b, &resp->bindings[i]); in snmp_set()
768 pdu->error_index = i + 1; in snmp_set()
769 pdu->error_status = SNMP_ERR_TOOBIG; in snmp_set()
773 pdu->error_index = i + 1; in snmp_set()
774 pdu->error_status = SNMP_ERR_GENERR; in snmp_set()
778 resp->nbindings++; in snmp_set()
787 for (i = 0; i < pdu->nbindings; i++) { in snmp_set()
788 b = &pdu->bindings[i]; in snmp_set()
794 ret = (*np->op)(&context.ctx, b, np->oid.len, np->index, in snmp_set()
798 snmp_debug("set: action %s returns %d", np->name, ret); in snmp_set()
800 if (pdu->version == SNMP_V1) { in snmp_set()
847 pdu->error_index = i + 1; in snmp_set()
848 pdu->error_status = ret; in snmp_set()
866 pdu->error_status = ret; in snmp_set()
867 pdu->error_index = context.ctx.var_index; in snmp_set()
870 if (pdu->version != SNMP_V1) { in snmp_set()
871 pdu->error_status = SNMP_ERR_UNDO_FAILED; in snmp_set()
872 pdu->error_index = 0; in snmp_set()
891 for (i = 0; i < pdu->nbindings; i++) { in snmp_set()
892 b = &resp->bindings[i]; in snmp_set()
898 ret = (*np->op)(&context.ctx, b, np->oid.len, np->index, in snmp_set()
904 asn_oid2str_r(&b->var, oidbuf), i); in snmp_set()
935 ((char *)ctx - offsetof(struct context, ctx)); in snmp_dep_lookup()
941 TAILQ_FOREACH(d, &context->dlist, link) in snmp_dep_lookup()
942 if (asn_compare_oid(obj, &d->dep.obj) == 0 && in snmp_dep_lookup()
943 ((idx == NULL && d->dep.idx.len == 0) || in snmp_dep_lookup()
944 (idx != NULL && asn_compare_oid(idx, &d->dep.idx) == 0))) { in snmp_dep_lookup()
947 return (&d->dep); in snmp_dep_lookup()
955 memset(&d->dep, 0, len); in snmp_dep_lookup()
957 d->dep.obj = *obj; in snmp_dep_lookup()
959 d->dep.idx.len = 0; in snmp_dep_lookup()
961 d->dep.idx = *idx; in snmp_dep_lookup()
962 d->len = len; in snmp_dep_lookup()
963 d->func = func; in snmp_dep_lookup()
965 TAILQ_INSERT_TAIL(&context->dlist, d, link); in snmp_dep_lookup()
967 return (&d->dep); in snmp_dep_lookup()
990 if (pdu->version == SNMP_V3) { in snmp_make_errresp()
1034 if (pdu_b->asn_len < len) in snmp_make_errresp()
1036 pdu_b->asn_len = len; in snmp_make_errresp()
1038 /* now we have the bindings left - construct new message */ in snmp_make_errresp()
1039 resp.error_status = pdu->error_status; in snmp_make_errresp()
1040 resp.error_index = pdu->error_index; in snmp_make_errresp()
1047 if (pdu_b->asn_len > resp_b->asn_len) in snmp_make_errresp()
1050 (void)memcpy(resp_b->asn_ptr, pdu_b->asn_cptr, pdu_b->asn_len); in snmp_make_errresp()
1051 resp_b->asn_len -= pdu_b->asn_len; in snmp_make_errresp()
1052 resp_b->asn_ptr += pdu_b->asn_len; in snmp_make_errresp()