Developing lightweight computation at the DSG edge

Commit 9151e75c authored by Roger Pueyo Centelles's avatar Roger Pueyo Centelles
Browse files

[mini_snmpd] Remove package from qMp feed (it is already in LEDE's, and newer)

parent 8faf70c3
#
# Copyright (C) 2009-2014 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
include $(TOPDIR)/rules.mk
PKG_NAME:=mini_snmpd
PKG_VERSION:=1.2b
PKG_RELEASE:=8
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=http://members.aon.at/linuxfreak/linux/
PKG_MD5SUM:=9e432c50ba8216d7fab0983b11b7112a
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
PKG_BUILD_PARALLEL:=1
PKG_INSTALL:=1
include $(INCLUDE_DIR)/package.mk
define Package/mini-snmpd
SECTION:=net
CATEGORY:=Network
TITLE:=SNMP server for embedded systems
URL:=http://members.aon.at/linuxfreak/linux/mini_snmpd.html
endef
ifneq ($(CONFIG_IPV6),)
TARGET_CFLAGS+= -D__IPV6__
else
TARGET_CFLAGS+= -D__IPV4__
endif
TARGET_CFLAGS+= -DSYSLOG
MAKE_FLAGS+= \
OFLAGS="$(TARGET_CFLAGS)" \
STRIP="/bin/true" \
INSTALL_ROOT="$(PKG_INSTALL_DIR)"
define Build/Compile
$(call Build/Compile/Default,mini_snmpd)
endef
define Package/mini-snmpd/install
$(INSTALL_DIR) $(1)/usr/bin
$(CP) $(PKG_INSTALL_DIR)/sbin/mini_snmpd $(1)/usr/bin/
$(INSTALL_DIR) $(1)/etc/config
$(INSTALL_CONF) ./files/mini_snmpd.config $(1)/etc/config/mini_snmpd
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_BIN) ./files/mini_snmpd.init $(1)/etc/init.d/mini_snmpd
endef
define Package/mini-snmpd/conffiles
/etc/config/mini_snmpd
endef
$(eval $(call BuildPackage,mini-snmpd))
config mini_snmpd
option enabled 0
option ipv6 0
option community 'public'
option contact ''
option location ''
# enable basic disk usage statistics on specified mountpoint
list disks '/jffs'
list disks '/tmp'
# enable basic network statistics on specified interface
# 4 interfaces maximum, as named in /etc/config/network
list interfaces 'loopback'
list interfaces 'lan'
list interfaces 'wan'
#!/bin/sh /etc/rc.common
# Copyright (C) 2009-2012 OpenWrt.org
START=50
SERVICE_DAEMONIZE=1
SERVICE_WRITE_PID=1
append_disk() {
local disk="$1"
append disks "$disk" ','
}
append_interface() {
local name="$1"
local device
network_get_device device "$name"
append interfaces "${device:-$name}" ','
}
append_string() {
local section="$1"
local option="$2"
local value="$3"
local _val
config_get _val "$section" "$option"
[ -n "$_val" ] && append args "$3 $_val"
}
start_instance() {
local cfg="$1"
local args=""
local disks=""
local interfaces=""
local ipv6
append_string "$cfg" community "-c"
append_string "$cfg" location "-L"
append_string "$cfg" contact "-C"
config_get_bool ipv6 "$cfg" "ipv6" '0'
[ "$ipv6" -gt 0 ] && append args "-6"
config_get_bool enabled "$cfg" "enabled" '1'
[ "$enabled" -gt 0 ] || return 1
config_list_foreach "$section" 'disks' append_disk
args="${args}${disks:+ -d $disks}"
config_list_foreach "$section" 'interfaces' append_interface
args="${args}${interfaces:+ -i $interfaces}"
service_start /usr/bin/mini_snmpd $args
}
start() {
. /lib/functions/network.sh
config_load 'mini_snmpd'
config_foreach start_instance 'mini_snmpd'
}
stop() {
service_stop /usr/bin/mini_snmpd
}
--- a/globals.c
+++ b/globals.c
@@ -27,9 +27,9 @@
* Global variables
*/
-#ifdef __IPV4__
const struct in_addr inaddr_any = { INADDR_ANY };
-#endif
+
+int g_family = AF_INET;
in_port_t g_udp_port = 161;
in_port_t g_tcp_port = 161;
--- a/mini_snmpd.c
+++ b/mini_snmpd.c
@@ -54,6 +54,10 @@ static void print_help(void)
fprintf(stderr, "-d, --disks nnn set the disks to monitor (/)\n");
fprintf(stderr, "-i, --interfaces nnn set the network interfaces to monitor (lo)\n");
fprintf(stderr, "-I, --listen nnn set the network interface to listen (all)\n");
+#ifdef __IPV6__
+ fprintf(stderr, "-4, --ipv4 use IPv4 (default)\n");
+ fprintf(stderr, "-6, --ipv6 use IPv6\n");
+#endif
fprintf(stderr, "-t, --timeout nnn set the timeout for MIB updates (1 second)\n");
fprintf(stderr, "-a, --auth require authentication (thus SNMP version 2c)\n");
fprintf(stderr, "-v, --verbose verbose syslog messages \n");
@@ -117,7 +121,7 @@ static void handle_udp_client(void)
#endif
/* Call the protocol handler which will prepare the response packet */
- inet_ntop(my_af_inet, &sockaddr.my_sin_addr, straddr, sizeof(straddr));
+ inet_ntop(g_family, &sockaddr.my_sin_addr, straddr, sizeof(straddr));
if (snmp(&g_udp_client) == -1) {
lprintf(LOG_WARNING, "could not handle packet from UDP client %s:%d: %m\n",
straddr, sockaddr.my_sin_port);
@@ -132,7 +136,7 @@ static void handle_udp_client(void)
/* Send the whole UDP packet to the socket at once */
rv = sendto(g_udp_sockfd, g_udp_client.packet, g_udp_client.size,
MSG_DONTWAIT, (struct sockaddr *)&sockaddr, socklen);
- inet_ntop(my_af_inet, &sockaddr.my_sin_addr, straddr, sizeof(straddr));
+ inet_ntop(g_family, &sockaddr.my_sin_addr, straddr, sizeof(straddr));
if (rv == -1) {
lprintf(LOG_WARNING, "could not send packet to UDP client %s:%d: %m\n",
straddr, sockaddr.my_sin_port);
@@ -176,7 +180,7 @@ static void handle_tcp_connect(void)
}
tmp_sockaddr.my_sin_addr = client->addr;
tmp_sockaddr.my_sin_port = client->port;
- inet_ntop(my_af_inet, &tmp_sockaddr.my_sin_addr, straddr, sizeof(straddr));
+ inet_ntop(g_family, &tmp_sockaddr.my_sin_addr, straddr, sizeof(straddr));
lprintf(LOG_WARNING, "maximum number of %d clients reached, kicking out %s:%d\n",
MAX_NR_CLIENTS, straddr, tmp_sockaddr.my_sin_port);
close(client->sockfd);
@@ -190,7 +194,7 @@ static void handle_tcp_connect(void)
}
/* Now fill out the client control structure values */
- inet_ntop(my_af_inet, &sockaddr.my_sin_addr, straddr, sizeof(straddr));
+ inet_ntop(g_family, &sockaddr.my_sin_addr, straddr, sizeof(straddr));
lprintf(LOG_DEBUG, "connected TCP client %s:%d\n",
straddr, sockaddr.my_sin_port);
client->timestamp = time(NULL);
@@ -211,7 +215,7 @@ static void handle_tcp_client_write(clie
sockaddr.my_sin_addr = client->addr;
sockaddr.my_sin_port = client->port;
rv = send(client->sockfd, client->packet, client->size, 0);
- inet_ntop(my_af_inet, &sockaddr.my_sin_addr, straddr, sizeof(straddr));
+ inet_ntop(g_family, &sockaddr.my_sin_addr, straddr, sizeof(straddr));
if (rv == -1) {
lprintf(LOG_WARNING, "could not send packet to TCP client %s:%d: %m\n",
straddr, sockaddr.my_sin_port);
@@ -246,7 +250,7 @@ static void handle_tcp_client_read(clien
sockaddr.my_sin_port = client->port;
rv = read(client->sockfd, client->packet + client->size,
sizeof (client->packet) - client->size);
- inet_ntop(my_af_inet, &sockaddr.my_sin_addr, straddr, sizeof(straddr));
+ inet_ntop(g_family, &sockaddr.my_sin_addr, straddr, sizeof(straddr));
if (rv == -1) {
lprintf(LOG_WARNING, "could not read packet from TCP client %s:%d: %m\n",
straddr, sockaddr.my_sin_port);
@@ -304,7 +308,11 @@ static void handle_tcp_client_read(clien
int main(int argc, char *argv[])
{
+#ifdef __IPV6__
+ static const char short_options[] = "p:P:c:D:V:L:C:d:i:I:t:T:avl46h";
+#else
static const char short_options[] = "p:P:c:D:V:L:C:d:i:I:t:T:avlh";
+#endif
static const struct option long_options[] = {
{ "udp-port", 1, 0, 'p' },
{ "tcp-port", 1, 0, 'P' },
@@ -316,6 +324,10 @@ int main(int argc, char *argv[])
{ "disks", 1, 0, 'd' },
{ "interfaces", 1, 0, 'i' },
{ "listen", 1, 0, 'I' },
+#ifdef __IPV6__
+ { "ipv4", 0, 0, '4' },
+ { "ipv6", 0, 0, '6' },
+#endif
{ "timeout", 1, 0, 't' },
{ "traps", 1, 0, 'T' },
{ "auth", 0, 0, 'a' },
@@ -327,7 +339,12 @@ int main(int argc, char *argv[])
int option_index = 1;
int c;
- struct my_sockaddr_t sockaddr;
+ union {
+ struct sockaddr_in sa;
+#ifdef __IPV6__
+ struct sockaddr_in6 sa6;
+#endif
+ } sockaddr;
my_socklen_t socklen;
struct timeval tv_last;
struct timeval tv_now;
@@ -396,6 +413,14 @@ int main(int argc, char *argv[])
case 'v':
g_verbose = 1;
break;
+#ifdef __IPV6__
+ case '4':
+ g_family = AF_INET;
+ break;
+ case '6':
+ g_family = AF_INET6;
+ break;
+#endif
case 'l':
print_version();
exit(EXIT_ARGS);
@@ -435,15 +460,24 @@ int main(int argc, char *argv[])
#endif
/* Open the server's UDP port and prepare it for listening */
- g_udp_sockfd = socket(my_pf_inet, SOCK_DGRAM, 0);
+ g_udp_sockfd = socket((g_family == AF_INET) ? PF_INET : PF_INET6, SOCK_DGRAM, 0);
if (g_udp_sockfd == -1) {
lprintf(LOG_ERR, "could not create UDP socket: %m\n");
exit(EXIT_SYSCALL);
}
- sockaddr.my_sin_family = my_af_inet;
- sockaddr.my_sin_port = htons(g_udp_port);
- sockaddr.my_sin_addr = my_inaddr_any;
- socklen = sizeof (sockaddr);
+ if (g_family == AF_INET) {
+ sockaddr.sa.sin_family = g_family;
+ sockaddr.sa.sin_port = htons(g_udp_port);
+ sockaddr.sa.sin_addr = inaddr_any;
+ socklen = sizeof(sockaddr.sa);
+#ifdef __IPV6__
+ } else {
+ sockaddr.sa6.sin6_family = g_family;
+ sockaddr.sa6.sin6_port = htons(g_udp_port);
+ sockaddr.sa6.sin6_addr = in6addr_any;
+ socklen = sizeof(sockaddr.sa6);
+#endif
+ }
if (bind(g_udp_sockfd, (struct sockaddr *)&sockaddr, socklen) == -1) {
lprintf(LOG_ERR, "could not bind UDP socket to port %d: %m\n", g_udp_port);
exit(EXIT_SYSCALL);
@@ -457,7 +491,7 @@ int main(int argc, char *argv[])
}
/* Open the server's TCP port and prepare it for listening */
- g_tcp_sockfd = socket(my_pf_inet, SOCK_STREAM, 0);
+ g_tcp_sockfd = socket((g_family == AF_INET) ? PF_INET : PF_INET6, SOCK_STREAM, 0);
if (g_tcp_sockfd == -1) {
lprintf(LOG_ERR, "could not create TCP socket: %m\n");
exit(EXIT_SYSCALL);
@@ -474,10 +508,19 @@ int main(int argc, char *argv[])
lprintf(LOG_WARNING, "could not set SO_REUSEADDR on TCP socket: %m\n");
exit(EXIT_SYSCALL);
}
- sockaddr.my_sin_family = my_af_inet;
- sockaddr.my_sin_port = htons(g_tcp_port);
- sockaddr.my_sin_addr = my_inaddr_any;
- socklen = sizeof (sockaddr);
+ if (g_family == AF_INET) {
+ sockaddr.sa.sin_family = g_family;
+ sockaddr.sa.sin_port = htons(g_udp_port);
+ sockaddr.sa.sin_addr = inaddr_any;
+ socklen = sizeof(sockaddr.sa);
+#ifdef __IPV6__
+ } else {
+ sockaddr.sa6.sin6_family = g_family;
+ sockaddr.sa6.sin6_port = htons(g_udp_port);
+ sockaddr.sa6.sin6_addr = in6addr_any;
+ socklen = sizeof(sockaddr.sa6);
+#endif
+ }
if (bind(g_tcp_sockfd, (struct sockaddr *)&sockaddr, socklen) == -1) {
lprintf(LOG_ERR, "could not bind TCP socket to port %d: %m\n", g_tcp_port);
exit(EXIT_SYSCALL);
--- a/mini_snmpd.h
+++ b/mini_snmpd.h
@@ -255,6 +255,7 @@ typedef struct demoinfo_s {
extern in_port_t g_udp_port;
extern in_port_t g_tcp_port;
+extern int g_family;
extern int g_timeout;
extern int g_auth;
extern int g_verbose;
@@ -265,9 +266,9 @@ extern char *g_vendor;
extern char *g_location;
extern char *g_contact;
extern char *g_bind_to_device;
-#ifdef __IPV4__
+
extern const struct in_addr inaddr_any;
-#endif
+
extern char *g_disk_list[MAX_NR_DISKS];
extern int g_disk_list_length;
--- a/Makefile
+++ b/Makefile
@@ -32,9 +32,9 @@ HEADERS = mini_snmpd.h
SOURCES = mini_snmpd.c protocol.c mib.c globals.c utils.c linux.c freebsd.c
VERSION = 1.2b
VENDOR = .1.3.6.1.4.1
-OFLAGS = -O2 -DDEBUG -g
+OFLAGS = -O2
CFLAGS = -Wall -Werror -DVERSION="\"$(VERSION)\"" -DVENDOR="\"$(VENDOR)\"" \
- $(OFLAGS) -D__TRAPS__ -D__LINUX__ -D__IPV6__
+ $(OFLAGS) -D__TRAPS__ -D__LINUX__
LDFLAGS = $(OFLAGS)
TARGET = mini_snmpd
MAN = mini_snmpd.8
--- a/mib.c
+++ b/mib.c
@@ -290,6 +290,7 @@ static int mib_build_entry(const oid_t *
value->data.max_length = sizeof (int) + 2;
value->data.encoded_length = 0;
value->data.buffer = malloc(value->data.max_length);
+ memset(value->data.buffer, 0, value->data.max_length);
if (encode_snmp_element_integer(value, (int)default_value) == -1) {
return -1;
}
@@ -298,6 +299,7 @@ static int mib_build_entry(const oid_t *
value->data.max_length = strlen((const char *)default_value) + 4;
value->data.encoded_length = 0;
value->data.buffer = malloc(value->data.max_length);
+ memset(value->data.buffer, 0, value->data.max_length);
if (encode_snmp_element_string(value, (const char *)default_value) == -1) {
return -1;
}
@@ -306,6 +308,7 @@ static int mib_build_entry(const oid_t *
value->data.max_length = MAX_NR_SUBIDS * 5 + 4;
value->data.encoded_length = 0;
value->data.buffer = malloc(value->data.max_length);
+ memset(value->data.buffer, 0, value->data.max_length);
if (encode_snmp_element_oid(value, oid_aton((const char *)default_value)) == -1) {
return -1;
}
@@ -316,6 +319,7 @@ static int mib_build_entry(const oid_t *
value->data.max_length = sizeof (unsigned int) + 2;
value->data.encoded_length = 0;
value->data.buffer = malloc(value->data.max_length);
+ memset(value->data.buffer, 0, value->data.max_length);
if (encode_snmp_element_unsigned(value, type, (unsigned int)default_value) == -1) {
return -1;
}
--- a/mib.c
+++ b/mib.c
@@ -120,6 +120,9 @@ static int encode_snmp_element_oid(value
int length;
int i;
+ if (oid_value == NULL) {
+ return -1;
+ }
buffer = value->data.buffer;
length = 1;
for (i = 2; i < oid_value->subid_list_length; i++) {
@@ -310,6 +313,8 @@ static int mib_build_entry(const oid_t *
value->data.buffer = malloc(value->data.max_length);
memset(value->data.buffer, 0, value->data.max_length);
if (encode_snmp_element_oid(value, oid_aton((const char *)default_value)) == -1) {
+ lprintf(LOG_ERR, "could not create MIB entry '%s.%d.%d': invalid oid '%s'\n",
+ oid_ntoa(prefix), column, row, (char *)default_value);
return -1;
}
break;
--- a/mini_snmpd.c
+++ b/mini_snmpd.c
@@ -443,7 +443,7 @@ int main(int argc, char *argv[])
/* Store the starting time since we need it for MIB updates */
if (gettimeofday(&tv_last, NULL) == -1) {
memset(&tv_last, 0, sizeof (tv_last));
- memset(&tv_sleep, 0, sizeof (&tv_sleep));
+ memset(&tv_sleep, 0, sizeof (tv_sleep));
} else {
tv_sleep.tv_sec = g_timeout / 100;
tv_sleep.tv_usec = (g_timeout % 100) * 10000;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment