From owner-svn-soc-all@FreeBSD.ORG Sun Aug 3 07:18:46 2014 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 17A8EACF for ; Sun, 3 Aug 2014 07:18:46 +0000 (UTC) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id ED3082640 for ; Sun, 3 Aug 2014 07:18:45 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.9/8.14.9) with ESMTP id s737Ij9u081595 for ; Sun, 3 Aug 2014 07:18:45 GMT (envelope-from shonali@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.9/8.14.9/Submit) id s737Ijvl081589 for svn-soc-all@FreeBSD.org; Sun, 3 Aug 2014 07:18:45 GMT (envelope-from shonali@FreeBSD.org) Date: Sun, 3 Aug 2014 07:18:45 GMT Message-Id: <201408030718.s737Ijvl081589@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to shonali@FreeBSD.org using -f From: shonali@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r271776 - soc2014/shonali/head/contrib/bsnmp/snmpd MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 03 Aug 2014 07:18:46 -0000 Author: shonali Date: Sun Aug 3 07:18:45 2014 New Revision: 271776 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=271776 Log: Added separate calls for ipv4 and ipv6 for ip_XXX functions. Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/export.c Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/export.c ============================================================================== --- soc2014/shonali/head/contrib/bsnmp/snmpd/export.c Sun Aug 3 05:53:53 2014 (r271775) +++ soc2014/shonali/head/contrib/bsnmp/snmpd/export.c Sun Aug 3 07:18:45 2014 (r271776) @@ -148,84 +148,59 @@ /* * Support for IPADDRESS * - * Save the old IP address in scratch->int1 and set the new one. + * Save the old IPv4 address in scratch->int1 and set the new one. */ int ip_save(struct snmp_value *value, struct snmp_context *ctx, u_char *valp) -{ - /* XX - sizeof of a pointer to an array doesn't give you size of array - Need to find a fix to this or a new way of finding address type */ - - if (sizeof(*valp)== 4) { - ctx->scratch->int1 = (valp[0] << 24) | (valp[1] << 16) | (valp[2] << 8) - | valp[3]; - - valp[0] = value->v.ipaddress[0]; - valp[1] = value->v.ipaddress[1]; - valp[2] = value->v.ipaddress[2]; - valp[3] = value->v.ipaddress[3]; - } - - if (sizeof(*valp)== 16) { - ctx->scratch->int1 = (valp[0] << 120) | (valp[1] << 112) | (valp[2] << 104) | (valp[3] << 96) | (valp[4] << 88) | - (valp[5] << 80) | (valp[6] << 72) | (valp[7] << 64) | (valp[8] << 56) | (valp[9] << 48) | (valp[10] << 40) | - (valp[11] << 32) | (valp[12] << 24) | (valp[13] << 16) | (valp[14] << 8) | valp[15]; - - valp[0] = value->v.ipaddress6[0]; - valp[1] = value->v.ipaddress6[1]; - valp[2] = value->v.ipaddress6[2]; - valp[3] = value->v.ipaddress6[3]; - valp[4] = value->v.ipaddress6[4]; - valp[5] = value->v.ipaddress6[5]; - valp[6] = value->v.ipaddress6[6]; - valp[7] = value->v.ipaddress6[7]; - valp[8] = value->v.ipaddress6[8]; - valp[9] = value->v.ipaddress6[9]; - valp[10] = value->v.ipaddress6[10]; - valp[11] = value->v.ipaddress6[11]; - valp[12] = value->v.ipaddress6[12]; - valp[13] = value->v.ipaddress6[13]; - valp[14] = value->v.ipaddress6[14]; - valp[15] = value->v.ipaddress6[15]; +{ + ctx->scratch->int1 = (valp[0] << 24) | (valp[1] << 16) | (valp[2] << 8) + | valp[3]; - } + valp[0] = value->v.ipaddress[0]; + valp[1] = value->v.ipaddress[1]; + valp[2] = value->v.ipaddress[2]; + valp[3] = value->v.ipaddress[3]; + - return (0); + return (0); +} + +/* + * Support for IPADDRESS + * + * Save the old IPv6 address in scratch->int1 and set the new one. + */ +int +ip6_save(struct snmp_value *value, struct snmp_context *ctx, u_char *valp) +{ + if ((ctx->scratch->ptr1 = malloc(sizeof(u_int8_t)*16)) == NULL) + return (SNMP_ERR_RES_UNAVAIL); + ctx->scratch->ptr1 = *valp; + for (int i = 0; i < 16; i++) + valp[i] = value->v.ipaddress6[i]; + return (0); } /* - * Rollback the address by copying back the old one + * Rollback the IPv4 address by copying back the old one */ void ip_rollback(struct snmp_context *ctx, u_char *valp) -{ - /* XX - sizeof of a pointer to an array doesn't give you size of array - Need to find a fix to this or a new way of finding address type */ - - if (sizeof(*valp)== 4) { - valp[0] = ctx->scratch->int1 >> 24; - valp[1] = ctx->scratch->int1 >> 16; - valp[2] = ctx->scratch->int1 >> 8; - valp[3] = ctx->scratch->int1; - } - if (sizeof(*valp)== 16) { - valp[0] = ctx->scratch->int1 >> 120; - valp[1] = ctx->scratch->int1 >> 112; - valp[2] = ctx->scratch->int1 >> 104; - valp[3] = ctx->scratch->int1 >> 96; - valp[4] = ctx->scratch->int1 >> 88; - valp[5] = ctx->scratch->int1 >> 80; - valp[6] = ctx->scratch->int1 >> 72; - valp[7] = ctx->scratch->int1 >> 64; - valp[8] = ctx->scratch->int1 >> 56; - valp[9] = ctx->scratch->int1 >> 48; - valp[10] = ctx->scratch->int1 >> 40; - valp[11] = ctx->scratch->int1 >> 32; - valp[12] = ctx->scratch->int1 >> 24; - valp[13] = ctx->scratch->int1 >> 16; - valp[14] = ctx->scratch->int1 >> 8; - valp[15] = ctx->scratch->int1 >> 0; - } +{ + + valp[0] = ctx->scratch->int1 >> 24; + valp[1] = ctx->scratch->int1 >> 16; + valp[2] = ctx->scratch->int1 >> 8; + valp[3] = ctx->scratch->int1; +} + +/* + * Rollback the IPv6 address by copying back the old one + */ +void +ip6_rollback(struct snmp_context *ctx, u_char *valp) +{ + *valp = (u_char)ctx->scratch->ptr1; } /* @@ -237,43 +212,33 @@ } /* - * Retrieve an IP address + * Retrieve an IPv4 address */ int ip_get(struct snmp_value *value, u_char *valp) { - /* XX - sizeof of a pointer to an array doesn't give you size of array - Need to find a fix to this or a new way of finding address type */ + value->v.ipaddress[0] = valp[0]; + value->v.ipaddress[1] = valp[1]; + value->v.ipaddress[2] = valp[2]; + value->v.ipaddress[3] = valp[3]; + - if (sizeof(*valp)== 4) { - value->v.ipaddress[0] = valp[0]; - value->v.ipaddress[1] = valp[1]; - value->v.ipaddress[2] = valp[2]; - value->v.ipaddress[3] = valp[3]; - } - - if (sizeof(*valp)== 16) { - value->v.ipaddress6[0] = valp[0]; - value->v.ipaddress6[1] = valp[1]; - value->v.ipaddress6[2] = valp[2]; - value->v.ipaddress6[3] = valp[3]; - value->v.ipaddress6[4] = valp[4]; - value->v.ipaddress6[5] = valp[5]; - value->v.ipaddress6[6] = valp[6]; - value->v.ipaddress6[7] = valp[7]; - value->v.ipaddress6[8] = valp[8]; - value->v.ipaddress6[9] = valp[9]; - value->v.ipaddress6[10] = valp[10]; - value->v.ipaddress6[11] = valp[11]; - value->v.ipaddress6[12] = valp[12]; - value->v.ipaddress6[13] = valp[13]; - value->v.ipaddress6[14] = valp[14]; - value->v.ipaddress6[15] = valp[15]; + return (SNMP_ERR_NOERROR); +} - } - return (SNMP_ERR_NOERROR); +/* + * Retrieve an IPv6 address + */ +int +ip6_get(struct snmp_value *value, u_char *valp) +{ + for (int i = 0; i < 16; i++){ + value->v.ipaddress6[i] = valp[i]; + } + return (SNMP_ERR_NOERROR); } + /* * Object ID support * @@ -389,8 +354,7 @@ } case SNMP_SYNTAX_IPADDRESS: - { - u_int8_t *pval; + { u_int8_t *pval; u_int i; switch (oid->len) { @@ -398,7 +362,7 @@ case 4: if (sub + 4 > oid->len) goto err; //pval = va_arg(ap, u_int8_t *); - u_int8_t pval[4]; + pval = malloc(sizeof(u_int8_t)*4); for (i = 0; i < 4; i++) { if (oid->subs[sub] > 0xff) goto err; @@ -408,7 +372,7 @@ case 16: if (sub + 16 > oid->len) goto err; //pval = va_arg(ap, u_int8_t *); - u_int8_t pval[16]; + pval = malloc(sizeof(u_int8_t)*16); for (i = 0; i < 16; i++) { pval[i] = oid->subs[sub++]; }