socsvn commit: r272116 - soc2014/shonali/head/contrib/bsnmp/snmpd
shonali at FreeBSD.org
shonali at FreeBSD.org
Sat Aug 9 08:40:19 UTC 2014
Author: shonali
Date: Sat Aug 9 08:40:17 2014
New Revision: 272116
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272116
Log:
Review and revision of config.c, export.c, trans_udpv6.c & headers
Modified:
soc2014/shonali/head/contrib/bsnmp/snmpd/config.c
soc2014/shonali/head/contrib/bsnmp/snmpd/export.c
soc2014/shonali/head/contrib/bsnmp/snmpd/snmpmod.h
soc2014/shonali/head/contrib/bsnmp/snmpd/trans_udpv6.c
soc2014/shonali/head/contrib/bsnmp/snmpd/trans_udpv6.h
Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/config.c
==============================================================================
--- soc2014/shonali/head/contrib/bsnmp/snmpd/config.c Sat Aug 9 05:00:34 2014 (r272115)
+++ soc2014/shonali/head/contrib/bsnmp/snmpd/config.c Sat Aug 9 08:40:17 2014 (r272116)
@@ -778,6 +778,8 @@
static void
gethost(const char *host, u_char *ip)
{
+ struct sockaddr_in *sain;
+ struct sockaddr_in6 *sain6;
struct addrinfo hints, *res;
int error;
@@ -796,19 +798,22 @@
case AF_INET :
addr_type = AF_INET;
- struct sockaddr_in *sain ;
sain = (struct sockaddr_in *)(void *)res->ai_addr;
sain->sin_addr.s_addr = ntohl(sain->sin_addr.s_addr);
- ip[0] = sain->sin_addr.s_addr >> 24;
+ inet_ntop(AF_INET, &(sain->sin_addr), *ip, INET_ADDRSTRLEN);
+
+ /*
+ ip[0] = sain->sin_addr.s_addr >> 24;
ip[1] = sain->sin_addr.s_addr >> 16;
ip[2] = sain->sin_addr.s_addr >> 8;
- ip[3] = sain->sin_addr.s_addr >> 0;
+ ip[3] = sain->sin_addr.s_addr >> 0;
+ */
+
+ break;
case AF_INET6 :
addr_type = AF_INET6;
- struct sockaddr_in6 *sain6 ;
sain6 = (struct sockaddr_in6 *)(void *)res->ai_addr;
-
/* ipv6 implementation of network to host byte order function */
/*
@@ -894,13 +899,16 @@
gettoken();
}
- if (addr_type == AF_INET6){
+ else if (addr_type == AF_INET6){
if (oid->len + 16 > ASN_MAXOIDLEN)
report("index too long");
for (i = 0; i < 16; i++)
oid->subs[oid->len++] = ip[i];
gettoken();
}
+
+ else
+ report("invalid ip protocol version");
} else
report("bad token in index");
Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/export.c
==============================================================================
--- soc2014/shonali/head/contrib/bsnmp/snmpd/export.c Sat Aug 9 05:00:34 2014 (r272115)
+++ soc2014/shonali/head/contrib/bsnmp/snmpd/export.c Sat Aug 9 08:40:17 2014 (r272116)
@@ -153,15 +153,14 @@
int
ip_save(struct snmp_value *value, struct snmp_context *ctx, u_char *valp)
{
- ctx->scratch->int1 = (valp[0] << 24) | (valp[1] << 16) | (valp[2] << 8)
- | valp[3];
+ 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];
+ 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);
}
@@ -173,12 +172,12 @@
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);
+ 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);
}
/*
@@ -187,11 +186,10 @@
void
ip_rollback(struct snmp_context *ctx, u_char *valp)
{
-
- valp[0] = ctx->scratch->int1 >> 24;
- valp[1] = ctx->scratch->int1 >> 16;
- valp[2] = ctx->scratch->int1 >> 8;
- valp[3] = ctx->scratch->int1;
+ valp[0] = ctx->scratch->int1 >> 24;
+ valp[1] = ctx->scratch->int1 >> 16;
+ valp[2] = ctx->scratch->int1 >> 8;
+ valp[3] = ctx->scratch->int1;
}
/*
@@ -200,11 +198,12 @@
void
ip6_rollback(struct snmp_context *ctx, u_char *valp)
{
- *valp = (u_char)ctx->scratch->ptr1;
+ *valp = (u_char)ctx->scratch->ptr1;
+ free(ctx->scratch->ptr1);
}
/*
- * Nothing to do for commit
+ * Nothing to do for IPv4 commit
*/
void
ip_commit(struct snmp_context *ctx __unused)
@@ -212,18 +211,25 @@
}
/*
+ * Nothing to do for IPv6 commit
+ */
+void
+ip6_commit(struct snmp_context *ctx __unused)
+{
+}
+
+/*
* Retrieve an IPv4 address
*/
int
ip_get(struct snmp_value *value, u_char *valp)
{
- value->v.ipaddress[0] = valp[0];
- value->v.ipaddress[1] = valp[1];
- value->v.ipaddress[2] = valp[2];
- value->v.ipaddress[3] = valp[3];
-
+ value->v.ipaddress[0] = valp[0];
+ value->v.ipaddress[1] = valp[1];
+ value->v.ipaddress[2] = valp[2];
+ value->v.ipaddress[3] = valp[3];
- return (SNMP_ERR_NOERROR);
+ return (SNMP_ERR_NOERROR);
}
/*
@@ -232,13 +238,12 @@
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);
+ for (int i = 0; i < 16; i++) {
+ value->v.ipaddress6[i] = valp[i];
+ }
+ return (SNMP_ERR_NOERROR);
}
-
/*
* Object ID support
*
@@ -354,28 +359,29 @@
}
case SNMP_SYNTAX_IPADDRESS:
- { u_int8_t *pval;
+ {
+ u_int8_t *pval;
u_int i;
switch (oid->len) {
- case 4: if (sub + 4 > oid->len)
+ case 4:
+ if (sub + 4 > oid->len)
goto err;
- //pval = va_arg(ap, u_int8_t *);
- pval = malloc(sizeof(u_int8_t)*4);
- for (i = 0; i < 4; i++) {
- if (oid->subs[sub] > 0xff)
- goto err;
- pval[i] = oid->subs[sub++];
- }
+ pval = va_arg(ap, u_int8_t *);
+ for (i = 0; i < 4; i++) {
+ if (oid->subs[sub] > 0xff)
+ goto err;
+ pval[i] = oid->subs[sub++];
+ }
- case 16: if (sub + 16 > oid->len)
- goto err;
- //pval = va_arg(ap, u_int8_t *);
- pval = malloc(sizeof(u_int8_t)*16);
- for (i = 0; i < 16; i++) {
- pval[i] = oid->subs[sub++];
- }
+ case 16:
+ if (sub + 16 > oid->len)
+ goto err;
+ pval = va_arg(ap, u_int8_t *);
+ for (i = 0; i < 16; i++) {
+ pval[i] = oid->subs[sub++];
+ }
default:
return (NULL);
Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/snmpmod.h
==============================================================================
--- soc2014/shonali/head/contrib/bsnmp/snmpd/snmpmod.h Sat Aug 9 05:00:34 2014 (r272115)
+++ soc2014/shonali/head/contrib/bsnmp/snmpd/snmpmod.h Sat Aug 9 08:40:17 2014 (r272116)
@@ -475,8 +475,8 @@
#define SNMP_TAG_SIZ (255 + 1)
enum target_domain {
- TransportAddressIPv4 = 0,
- TransportAddressIPv6 = 1,
+ TransportAddressIPv4 = 0,
+ TransportAddressIPv6 = 1,
};
struct target_address {
Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/trans_udpv6.c
==============================================================================
--- soc2014/shonali/head/contrib/bsnmp/snmpd/trans_udpv6.c Sat Aug 9 05:00:34 2014 (r272115)
+++ soc2014/shonali/head/contrib/bsnmp/snmpd/trans_udpv6.c Sat Aug 9 08:40:17 2014 (r272116)
@@ -3,7 +3,13 @@
* Fraunhofer Institute for Open Communication Systems (FhG Fokus).
* All rights reserved.
*
- * Author: Harti Brandt <harti at freebsd.org>
+ * Author: Harti Brandt <harti at freebsd.org>
+ *
+ * Copyright (c) 2014 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * Portions of this software were developed by Shonali Balakrishna
+ * as a Google Summer of Code student working for The FreeBSD Foundation.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -66,7 +72,7 @@
udpv6_close_port,
udpv6_init_port,
udpv6_send,
- udpv6_recv
+ udpv6_recv
};
static struct transport *my_trans;
@@ -113,23 +119,8 @@
syslog(LOG_ERR, "creating UDP socket: %m");
return (SNMP_ERR_RES_UNAVAIL);
}
-
- ip[0] = p->addr[0] >> 120;
- ip[1] = p->addr[1] >> 112;
- ip[2] = p->addr[2] >> 104;
- ip[3] = p->addr[3] >> 96;
- ip[4] = p->addr[4] >> 88;
- ip[5] = p->addr[5] >> 80;
- ip[6] = p->addr[6] >> 72;
- ip[7] = p->addr[7] >> 64;
- ip[8] = p->addr[8] >> 56;
- ip[9] = p->addr[9] >> 48;
- ip[10] = p->addr[10] >> 40;
- ip[11] = p->addr[11] >> 32;
- ip[12] = p->addr[12] >> 24;
- ip[13] = p->addr[13] >> 16;
- ip[14] = p->addr[14] >> 8;
- ip[15] = p->addr[15] >> 0;
+
+ inet_ntop(AF_INET6, &(p->addr), &ip, INET6_ADDRSTRLEN);
/* Need to check - can use getaddrinfo instead to fill up addr structure */
memset(&addr, 0, sizeof(addr));
@@ -138,7 +129,7 @@
addr.sin6_family = AF_INET6;
addr.sin6_len = sizeof(addr);
if ((addr.sin6_addr.s6_addr == in6addr_any.s6_addr) &&
- ( setsockopt(p->input.fd, IPPROTO_IPV6, IPV6_V6ONLY, &on,
+ (setsockopt(p->input.fd, IPPROTO_IPV6, IPV6_V6ONLY, &on,
sizeof(on)) == -1)) {
syslog(LOG_ERR, "setsockopt(IP_RECVDSTADDR): %m");
close(p->input.fd);
Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/trans_udpv6.h
==============================================================================
--- soc2014/shonali/head/contrib/bsnmp/snmpd/trans_udpv6.h Sat Aug 9 05:00:34 2014 (r272115)
+++ soc2014/shonali/head/contrib/bsnmp/snmpd/trans_udpv6.h Sat Aug 9 08:40:17 2014 (r272116)
@@ -3,7 +3,13 @@
* Fraunhofer Institute for Open Communication Systems (FhG Fokus).
* All rights reserved.
*
- * Author: Harti Brandt <harti at freebsd.org>
+ * Author: Harti Brandt <harti at freebsd.org>
+ *
+ * Copyright (c) 2014 The FreeBSD Foundation
+ * All rights reserved.
+ *
+ * Portions of this software were developed by Shonali Balakrishna
+ * as a Google Summer of Code student working for The FreeBSD Foundation.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
More information about the svn-soc-all
mailing list