From 89caf954db743cb8b8f38c0c474f6c591611b672 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Sun, 5 Feb 2012 15:28:02 +0000 Subject: [PATCH] [packages_10.03.2] mini_snmpd: merge r29040, r29062, r29182, r29211 SVN-Revision: 30220 --- net/mini_snmpd/Makefile | 29 +++---- net/mini_snmpd/files/mini_snmpd.config | 18 +++-- net/mini_snmpd/files/mini_snmpd.init | 46 ++++++++--- net/mini_snmpd/patches/100-dualstack.patch | 93 ++++++++++++++++++---- 4 files changed, 137 insertions(+), 49 deletions(-) diff --git a/net/mini_snmpd/Makefile b/net/mini_snmpd/Makefile index ecc27177f9..2dc6a7dd49 100644 --- a/net/mini_snmpd/Makefile +++ b/net/mini_snmpd/Makefile @@ -9,40 +9,35 @@ include $(TOPDIR)/rules.mk PKG_NAME:=mini_snmpd PKG_VERSION:=1.2b -PKG_RELEASE:=3 +PKG_RELEASE:=6 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_NAME) +PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME) PKG_BUILD_PARALLEL:=1 PKG_INSTALL:=1 include $(INCLUDE_DIR)/package.mk -define Package/mini-snmpd/Default - TITLE:=SNMP server for embedded systems - URL:=http://members.aon.at/linuxfreak/linux/mini_snmpd.html -endef - define Package/mini-snmpd -$(call Package/mini-snmpd/Default) SECTION:=net CATEGORY:=Network - TITLE+= Mini Snmpd + TITLE:=SNMP server for embedded systems + URL:=http://members.aon.at/linuxfreak/linux/mini_snmpd.html endef -PKG_OFLAGS:=$(TARGET_CFLAGS) -DSYSLOG - -ifeq ($(CONFIG_IPV6),y) - PKG_OFLAGS+= -D__IPV6__ +ifneq ($(CONFIG_IPV6),) + TARGET_CFLAGS+= -D__IPV6__ else - PKG_OFLAGS+= -D__IPV4__ + TARGET_CFLAGS+= -D__IPV4__ endif +TARGET_CFLAGS+= -DSYSLOG + MAKE_FLAGS+= \ - OFLAGS="$(PKG_OFLAGS)" \ + OFLAGS="$(TARGET_CFLAGS)" \ STRIP="/bin/true" \ INSTALL_ROOT="$(PKG_INSTALL_DIR)" @@ -59,6 +54,8 @@ define Package/mini-snmpd/install $(INSTALL_BIN) ./files/mini_snmpd.init $(1)/etc/init.d/mini_snmpd endef -Package/mini-snmpd6/install=$(Package/mini-snmpd/install) +define Package/mini-snmpd/conffiles +/etc/config/mini_snmpd +endef $(eval $(call BuildPackage,mini-snmpd)) diff --git a/net/mini_snmpd/files/mini_snmpd.config b/net/mini_snmpd/files/mini_snmpd.config index 43ab93141f..e41bdc9578 100644 --- a/net/mini_snmpd/files/mini_snmpd.config +++ b/net/mini_snmpd/files/mini_snmpd.config @@ -1,8 +1,16 @@ config mini_snmpd - option enabled 1 + option enabled 0 option ipv6 0 - option community public - option location '' + option community 'public' option contact '' - option disks '/tmp,/jffs' - option interfaces 'lo,br-lan,eth0.1,eth1' # Max 4 + 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' diff --git a/net/mini_snmpd/files/mini_snmpd.init b/net/mini_snmpd/files/mini_snmpd.init index cc051c0bdb..0e48eff5cb 100644 --- a/net/mini_snmpd/files/mini_snmpd.init +++ b/net/mini_snmpd/files/mini_snmpd.init @@ -1,10 +1,23 @@ #!/bin/sh /etc/rc.common -# Copyright (C) 2009 OpenWrt.org +# Copyright (C) 2009-2011 OpenWrt.org -NAME=mini_snmpd -PROG=/usr/bin/$NAME START=50 +SERVICE_DAEMONIZE=1 +SERVICE_WRITE_PID=1 + +append_disk() { + local disk="$1" + append disks "$disk" ',' +} + +append_interface() { + local name="$1" + local interface + config_get interface "$name" 'ifname' "$name" + append interfaces "$interface" ',' +} + append_string() { local section="$1" local option="$2" @@ -14,28 +27,39 @@ append_string() { [ -n "$_val" ] && append args "$3 $_val" } -mini_snmpd_config() { +start_instance() { local cfg="$1" - args="" + local args="" + local disks="" + local interfaces="" + local ipv6 append_string "$cfg" community "-c" append_string "$cfg" location "-L" append_string "$cfg" contact "-C" - append_string "$cfg" disks "-d" - append_string "$cfg" interfaces "-i" config_get_bool ipv6 "$cfg" "ipv6" '0' [ "$ipv6" -gt 0 ] && append args "-6" config_get_bool enabled "$cfg" "enabled" '1' - [ "$enabled" -gt 0 ] && $PROG $args & + [ "$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() { - config_load mini_snmpd - config_foreach mini_snmpd_config mini_snmpd + include /lib/network + scan_interfaces + config_load 'mini_snmpd' + config_foreach start_instance 'mini_snmpd' } stop() { - killall mini_snmpd + service_stop /usr/bin/mini_snmpd } diff --git a/net/mini_snmpd/patches/100-dualstack.patch b/net/mini_snmpd/patches/100-dualstack.patch index a83236af2e..08aa4a0b6f 100644 --- a/net/mini_snmpd/patches/100-dualstack.patch +++ b/net/mini_snmpd/patches/100-dualstack.patch @@ -1,14 +1,17 @@ --- a/globals.c +++ b/globals.c -@@ -31,6 +31,8 @@ - const struct in_addr inaddr_any = { INADDR_ANY }; - #endif +@@ -27,9 +27,9 @@ + * Global variables + */ -+int g_family = AF_INET; +-#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; - int g_timeout = 100; --- a/mini_snmpd.c +++ b/mini_snmpd.c @@ -54,6 +54,10 @@ static void print_help(void) @@ -99,7 +102,21 @@ { "timeout", 1, 0, 't' }, { "traps", 1, 0, 'T' }, { "auth", 0, 0, 'a' }, -@@ -396,6 +408,14 @@ int main(int argc, char *argv[]) +@@ -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; @@ -114,7 +131,7 @@ case 'l': print_version(); exit(EXIT_ARGS); -@@ -435,12 +455,12 @@ int main(int argc, char *argv[]) +@@ -435,15 +460,24 @@ int main(int argc, char *argv[]) #endif /* Open the server's UDP port and prepare it for listening */ @@ -125,11 +142,26 @@ exit(EXIT_SYSCALL); } - sockaddr.my_sin_family = my_af_inet; -+ sockaddr.my_sin_family = g_family; - sockaddr.my_sin_port = htons(g_udp_port); - sockaddr.my_sin_addr = my_inaddr_any; - socklen = sizeof (sockaddr); -@@ -457,7 +477,7 @@ int main(int argc, char *argv[]) +- 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 */ @@ -138,15 +170,30 @@ if (g_tcp_sockfd == -1) { lprintf(LOG_ERR, "could not create TCP socket: %m\n"); exit(EXIT_SYSCALL); -@@ -474,7 +494,7 @@ int main(int argc, char *argv[]) +@@ -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_family = g_family; - sockaddr.my_sin_port = htons(g_tcp_port); - sockaddr.my_sin_addr = my_inaddr_any; - socklen = sizeof (sockaddr); +- 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 { @@ -157,3 +204,15 @@ 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; -- 2.30.2