1/* 2 * Copyright (c) 2001-2003 3 * Fraunhofer Institute for Open Communication Systems (FhG Fokus). 4 * All rights reserved. 5 * 6 * Author: Harti Brandt <harti@freebsd.org> 7 * 8 * Redistribution and use in source and binary forms, with or without --- 151 unchanged lines hidden (view full) --- 160 161 for (tp = tree; tp < tree + tree_size; tp++) { 162 if (asn_is_suboid(&value->var, &tp->oid)) 163 return (tp); 164 } 165 return (NULL); 166} 167 |
168static void 169snmp_pdu_create_response(struct snmp_pdu *pdu, struct snmp_pdu *resp) 170{ 171 memset(resp, 0, sizeof(*resp)); 172 strcpy(resp->community, pdu->community); 173 resp->version = pdu->version; 174 resp->type = SNMP_PDU_RESPONSE; 175 resp->request_id = pdu->request_id; 176 resp->version = pdu->version; 177 178 if (resp->version != SNMP_V3) 179 return; 180 181 snmp_pdu_init_secparams(resp, &pdu->engine, &pdu->user); 182 resp->identifier = pdu->identifier; 183 resp->security_model = pdu->security_model; 184 resp->context_engine_len = pdu->context_engine_len; 185 memcpy(resp->context_engine, pdu->context_engine, 186 resp->context_engine_len); 187 strlcpy(resp->context_name, pdu->context_name, 188 sizeof(resp->context_name)); 189} 190 |
191/* 192 * Execute a GET operation. The tree is rooted at the global 'root'. 193 * Build the response PDU on the fly. If the return code is SNMP_RET_ERR 194 * the pdu error status and index will be set. 195 */ 196enum snmp_ret 197snmp_get(struct snmp_pdu *pdu, struct asn_buf *resp_b, 198 struct snmp_pdu *resp, void *data) 199{ 200 int ret; 201 u_int i; 202 struct snmp_node *tp; 203 enum snmp_syntax except; 204 struct context context; 205 enum asn_err err; 206 207 memset(&context, 0, sizeof(context)); 208 context.ctx.data = data; 209 |
210 snmp_pdu_create_response(pdu, resp); |
211 212 if (snmp_pdu_encode_header(resp_b, resp) != SNMP_CODE_OK) 213 /* cannot even encode header - very bad */ 214 return (SNMP_RET_IGN); 215 216 for (i = 0; i < pdu->nbindings; i++) { 217 resp->bindings[i].var = pdu->bindings[i].var; 218 if ((tp = find_node(&pdu->bindings[i], &except)) == NULL) { --- 178 unchanged lines hidden (view full) --- 397 struct context context; 398 u_int i; 399 enum asn_err err; 400 enum snmp_ret result; 401 402 memset(&context, 0, sizeof(context)); 403 context.ctx.data = data; 404 |
405 snmp_pdu_create_response(pdu, resp); |
406 407 if (snmp_pdu_encode_header(resp_b, resp)) 408 return (SNMP_RET_IGN); 409 410 for (i = 0; i < pdu->nbindings; i++) { 411 result = do_getnext(&context, &pdu->bindings[i], 412 &resp->bindings[i], pdu); 413 --- 35 unchanged lines hidden (view full) --- 449 u_int non_rep; 450 int eomib; 451 enum snmp_ret result; 452 enum asn_err err; 453 454 memset(&context, 0, sizeof(context)); 455 context.ctx.data = data; 456 |
457 snmp_pdu_create_response(pdu, resp); |
458 459 if (snmp_pdu_encode_header(resp_b, resp) != SNMP_CODE_OK) 460 /* cannot even encode header - very bad */ 461 return (SNMP_RET_IGN); 462 463 if ((non_rep = pdu->error_status) > pdu->nbindings) 464 non_rep = pdu->nbindings; 465 --- 190 unchanged lines hidden (view full) --- 656 const struct snmp_node *np; 657 struct snmp_value *b; 658 enum snmp_syntax except; 659 660 memset(&context, 0, sizeof(context)); 661 TAILQ_INIT(&context.dlist); 662 context.ctx.data = data; 663 |
664 snmp_pdu_create_response(pdu, resp); |
665 666 if (snmp_pdu_encode_header(resp_b, resp)) 667 return (SNMP_RET_IGN); 668 669 /* 670 * 1. Find all nodes, check that they are writeable and 671 * that the syntax is ok, copy over the binding to the response. 672 */ --- 278 unchanged lines hidden (view full) --- 951 struct asn_buf *resp_b) 952{ 953 asn_len_t len; 954 struct snmp_pdu resp; 955 enum asn_err err; 956 enum snmp_code code; 957 958 memset(&resp, 0, sizeof(resp)); |
959 if ((code = snmp_pdu_decode_header(pdu_b, &resp)) != SNMP_CODE_OK) |
960 return (SNMP_RET_IGN); |
961 |
962 if (pdu_b->asn_len < len) 963 return (SNMP_RET_IGN); 964 pdu_b->asn_len = len; 965 966 err = snmp_parse_pdus_hdr(pdu_b, &resp, &len); 967 if (ASN_ERR_STOPPED(err)) 968 return (SNMP_RET_IGN); 969 if (pdu_b->asn_len < len) --- 36 unchanged lines hidden --- |