From 92a5a13aa05ae495ac94a081fe8f745a21919761 Mon Sep 17 00:00:00 2001 From: Luke McKee Date: Sat, 9 Jul 2016 20:36:28 +0700 Subject: [PATCH 1/4] mini_snmpd: import 1.2b from oldpackages for reference http://git.openwrt.org/?p=packages.git;a=commit;h=787e4e15a2792eb4d059001e1fb8bc84da8d65fd Signed-off-by: Luke McKee --- net/mini_snmpd/Makefile | 61 +++++ net/mini_snmpd/files/mini_snmpd.config | 16 ++ net/mini_snmpd/files/mini_snmpd.init | 65 ++++++ net/mini_snmpd/files/mini_snmpd.init-v2 | 146 ++++++++++++ net/mini_snmpd/files/mini_snmpd.init.orig | 65 ++++++ net/mini_snmpd/patches/100-dualstack.patch | 218 ++++++++++++++++++ net/mini_snmpd/patches/101-opt_flags.patch | 14 ++ .../102-mib_fix_uninitialized_memory.patch | 34 +++ .../103-mib_encode_snmp_element_oid_fix.patch | 21 ++ net/mini_snmpd/patches/104-memset_fix.patch | 11 + 10 files changed, 651 insertions(+) create mode 100644 net/mini_snmpd/Makefile create mode 100644 net/mini_snmpd/files/mini_snmpd.config create mode 100644 net/mini_snmpd/files/mini_snmpd.init create mode 100644 net/mini_snmpd/files/mini_snmpd.init-v2 create mode 100644 net/mini_snmpd/files/mini_snmpd.init.orig create mode 100644 net/mini_snmpd/patches/100-dualstack.patch create mode 100644 net/mini_snmpd/patches/101-opt_flags.patch create mode 100644 net/mini_snmpd/patches/102-mib_fix_uninitialized_memory.patch create mode 100644 net/mini_snmpd/patches/103-mib_encode_snmp_element_oid_fix.patch create mode 100644 net/mini_snmpd/patches/104-memset_fix.patch diff --git a/net/mini_snmpd/Makefile b/net/mini_snmpd/Makefile new file mode 100644 index 0000000000..e4a77b5950 --- /dev/null +++ b/net/mini_snmpd/Makefile @@ -0,0 +1,61 @@ +# +# 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)) diff --git a/net/mini_snmpd/files/mini_snmpd.config b/net/mini_snmpd/files/mini_snmpd.config new file mode 100644 index 0000000000..e41bdc9578 --- /dev/null +++ b/net/mini_snmpd/files/mini_snmpd.config @@ -0,0 +1,16 @@ +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' diff --git a/net/mini_snmpd/files/mini_snmpd.init b/net/mini_snmpd/files/mini_snmpd.init new file mode 100644 index 0000000000..20e2c62237 --- /dev/null +++ b/net/mini_snmpd/files/mini_snmpd.init @@ -0,0 +1,65 @@ +#!/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 +} diff --git a/net/mini_snmpd/files/mini_snmpd.init-v2 b/net/mini_snmpd/files/mini_snmpd.init-v2 new file mode 100644 index 0000000000..9b81407246 --- /dev/null +++ b/net/mini_snmpd/files/mini_snmpd.init-v2 @@ -0,0 +1,146 @@ +#!/bin/sh /etc/rc.common +# Copyright (C) 2009-2016 OpenWrt.org + +START=95 +USE_PROCD=1 +PROCD_DEBUG=1 +PROG=/usr/bin/mini_snmpd +NAME=mini_snmpd + +# mini_snmpd now starts later in the game. Expects filesystems monitored to be already mounted, +# and at least configuration entry for network physical interface defined in /etc/config/network +# It handles network interfaces not yet present (e.g. ppp) but will statfs() the root/wrong filesystem if device not mounted + +append_disk() { + local disk="$1" + [ -z $disk_count ] && disk_count=1 + if grep -qF "$disk" /proc/mounts ; then + if [ $disk_count -le 4 ] ; then + append disks "$disk" ',' + disk_count=$((disk_count++)) + else + logger -s -t mini_snmpd -p daemon.error "more than 4 mountpoints defined in uci. Disc $disk ignored." + fi + else + logger -s -t mini_snmpd -p daemon.error "mountpoint $disk for snmp monitoring not mounted, ignoring." + fi +} + +append_interface() { + local name="$1" + local device + [ $(ubus -S call network.interface dump | jsonfilter -e "@.interface[@.interface=\"$name\"].device") ] && { + append interfaces "${device:-$name}" ',' + } +} + +append_arg() { + local cfg="$1" + local var="$2" + local opt="$3" + local def="$4" + local val + config_get val "$cfg" "$var" + [ -n "$val" -o -n "$def" ] && procd_append_param command $opt "${val:-$def}" +} + +listen_interface_status() { + local cfg="$1" +} + +watch_interfaces() { + local cfg="$1" + local enabled listen_interface + config_get_bool enabled "$cfg" "enabled" '1' + [ "$enabled" -gt 0 ] || return 0 + config_get listen_interface "$cfg" listen_interface + [ "$listen_interface" = "all" ] && return 0 + local listen_interface_up=$(ubus -S call network.interface dump | jsonfilter -e "@.interface[@.interface=\"$listen_interface\"].up") + # if ubus knows about it regardless if it's status we'll watch for changes. + [ -n "$listen_interface" -a -n "$listen_interface_up" ] && trigger_interfaces=" ${listen_interface} ${trigger_interfaces}" +} + +service_triggers() { + #procd_add_reload_trigger mini_snmpd + procd_open_trigger + procd_add_config_trigger "config.change" "mini_snmpd" /etc/init.d/mini_snmpd reload + config_load 'mini_snmpd' + config_foreach watch_interfaces 'mini_snmpd' + [ -n "${trigger_interfaces}" ] & { + for n in $trigger_interfaces ; do + procd_add_interface_trigger "interface.*" $n /etc/init.d/mini_snmpd restart + done + } + procd_close_trigger + #procd_add_validation validate_section_mini_snmpd +} + + +start_instance() { + local cfg="$1" disks="" interfaces="" + local ipv6 debug auth + + config_get_bool enabled "$cfg" "enabled" '1' + [ "$enabled" -gt 0 ] || return 1 + + local listen_interface listen_interface_json listen_interface_ip listen_interface_device listen_interface_up + config_get_bool ipv6 "$cfg" "ipv6" '0' + config_get listen_interface "$cfg" listen_interface + [ -n "$listen_interface" -a "$listen_interface" != "all" ] && { + listen_interface_json=$(ubus -S call network.interface.$listen_interface status) + [ -z "$listen_interface_json" ] && { + logger -s -t mini_snmpd -p daemon.error "interface configured to bind to is not configured in /etc/config/network" + return 1 + } + listen_interface_up=$(jsonfilter -s "$listen_interface_json" -e '@.up') + if [ "$ipv6" -gt 0 ]; then + listen_interface_ip=$(jsonfilter -s "$listen_interface_json" -e "@['ipv6-address'][0].address") + else + listen_interface_ip=$(jsonfilter -s "$listen_interface_json" -e "@['ipv4-address'][0].address") + fi + [ -n "$listen_interface_ip" -a "$listen_interface_up" = 'true' ] || { + logger -s -t mini_snmpd -p daemon.debug "interface configured to bind to is not up yet, procd will try again later" + return 0 + } + listen_interface_device=$(jsonfilter -s "$listen_interface_json" -e '@.l3_device') + } + + procd_open_instance + + procd_set_param command "$PROG" -n + procd_set_param stdout "1" + procd_set_param stderr "1" + procd_set_param respawn ${respawn_threshold:-3600} ${respawn_timeout:-5} ${respawn_retry:-5} + + append_arg "$cfg" community "-c" + append_arg "$cfg" location "-L" + append_arg "$cfg" contact "-C" + append_arg "$cfg" udp_port "-p" + append_arg "$cfg" tcp_port "-P" + append_arg "$cfg" vendor_oid "-V" + append_arg "$cfg" mib_timeout "-t" + + [ "$ipv6" -gt 0 ] && procd_append_param command "-6" + config_get_bool debug "$cfg" "debug" '0' + [ "$debug" -gt 0 ] && procd_append_param command "-v" + config_get_bool auth "$cfg" "auth" '0' + [ "$auth" -gt 0 ] && procd_append_param command "-a" + config_list_foreach "$cfg" 'disks' append_disk + [ -n "$disks" ] && procd_append_param command "-d $disks" + config_list_foreach "$cfg" 'interfaces' append_interface + [ -n "$interfaces" ] && procd_append_param command "-i $interfaces" + # https://github.com/troglobit/mini-snmpd/issues/4 - yes I know there is no space after the -I + [ -n "$listen_interface_device" ] && procd_append_param command "-I$listen_interface_device" + + procd_close_instance +} + +start_service() { + config_load 'mini_snmpd' + config_foreach start_instance 'mini_snmpd' +} + +reload_service() { + stop + start +} diff --git a/net/mini_snmpd/files/mini_snmpd.init.orig b/net/mini_snmpd/files/mini_snmpd.init.orig new file mode 100644 index 0000000000..20e2c62237 --- /dev/null +++ b/net/mini_snmpd/files/mini_snmpd.init.orig @@ -0,0 +1,65 @@ +#!/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 +} diff --git a/net/mini_snmpd/patches/100-dualstack.patch b/net/mini_snmpd/patches/100-dualstack.patch new file mode 100644 index 0000000000..08aa4a0b6f --- /dev/null +++ b/net/mini_snmpd/patches/100-dualstack.patch @@ -0,0 +1,218 @@ +--- 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; diff --git a/net/mini_snmpd/patches/101-opt_flags.patch b/net/mini_snmpd/patches/101-opt_flags.patch new file mode 100644 index 0000000000..70dbce5d27 --- /dev/null +++ b/net/mini_snmpd/patches/101-opt_flags.patch @@ -0,0 +1,14 @@ +--- 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 diff --git a/net/mini_snmpd/patches/102-mib_fix_uninitialized_memory.patch b/net/mini_snmpd/patches/102-mib_fix_uninitialized_memory.patch new file mode 100644 index 0000000000..fc8cecf2e5 --- /dev/null +++ b/net/mini_snmpd/patches/102-mib_fix_uninitialized_memory.patch @@ -0,0 +1,34 @@ +--- 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; + } diff --git a/net/mini_snmpd/patches/103-mib_encode_snmp_element_oid_fix.patch b/net/mini_snmpd/patches/103-mib_encode_snmp_element_oid_fix.patch new file mode 100644 index 0000000000..a1f105cb4a --- /dev/null +++ b/net/mini_snmpd/patches/103-mib_encode_snmp_element_oid_fix.patch @@ -0,0 +1,21 @@ +--- 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; diff --git a/net/mini_snmpd/patches/104-memset_fix.patch b/net/mini_snmpd/patches/104-memset_fix.patch new file mode 100644 index 0000000000..0ed2a2e3c3 --- /dev/null +++ b/net/mini_snmpd/patches/104-memset_fix.patch @@ -0,0 +1,11 @@ +--- 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; From cfb086812ab273c41525fbf0143e5d3195d289ae Mon Sep 17 00:00:00 2001 From: Luke McKee Date: Sat, 9 Jul 2016 20:38:29 +0700 Subject: [PATCH 2/4] mini_snmpd: patches are now all merged upstream in 1.4-rc1 Signed-off-by: Luke McKee --- net/mini_snmpd/patches/100-dualstack.patch | 218 ------------------ net/mini_snmpd/patches/101-opt_flags.patch | 14 -- .../102-mib_fix_uninitialized_memory.patch | 34 --- .../103-mib_encode_snmp_element_oid_fix.patch | 21 -- net/mini_snmpd/patches/104-memset_fix.patch | 11 - 5 files changed, 298 deletions(-) delete mode 100644 net/mini_snmpd/patches/100-dualstack.patch delete mode 100644 net/mini_snmpd/patches/101-opt_flags.patch delete mode 100644 net/mini_snmpd/patches/102-mib_fix_uninitialized_memory.patch delete mode 100644 net/mini_snmpd/patches/103-mib_encode_snmp_element_oid_fix.patch delete mode 100644 net/mini_snmpd/patches/104-memset_fix.patch diff --git a/net/mini_snmpd/patches/100-dualstack.patch b/net/mini_snmpd/patches/100-dualstack.patch deleted file mode 100644 index 08aa4a0b6f..0000000000 --- a/net/mini_snmpd/patches/100-dualstack.patch +++ /dev/null @@ -1,218 +0,0 @@ ---- 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; diff --git a/net/mini_snmpd/patches/101-opt_flags.patch b/net/mini_snmpd/patches/101-opt_flags.patch deleted file mode 100644 index 70dbce5d27..0000000000 --- a/net/mini_snmpd/patches/101-opt_flags.patch +++ /dev/null @@ -1,14 +0,0 @@ ---- 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 diff --git a/net/mini_snmpd/patches/102-mib_fix_uninitialized_memory.patch b/net/mini_snmpd/patches/102-mib_fix_uninitialized_memory.patch deleted file mode 100644 index fc8cecf2e5..0000000000 --- a/net/mini_snmpd/patches/102-mib_fix_uninitialized_memory.patch +++ /dev/null @@ -1,34 +0,0 @@ ---- 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; - } diff --git a/net/mini_snmpd/patches/103-mib_encode_snmp_element_oid_fix.patch b/net/mini_snmpd/patches/103-mib_encode_snmp_element_oid_fix.patch deleted file mode 100644 index a1f105cb4a..0000000000 --- a/net/mini_snmpd/patches/103-mib_encode_snmp_element_oid_fix.patch +++ /dev/null @@ -1,21 +0,0 @@ ---- 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; diff --git a/net/mini_snmpd/patches/104-memset_fix.patch b/net/mini_snmpd/patches/104-memset_fix.patch deleted file mode 100644 index 0ed2a2e3c3..0000000000 --- a/net/mini_snmpd/patches/104-memset_fix.patch +++ /dev/null @@ -1,11 +0,0 @@ ---- 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; From 82cf5ca5c6da5bf7ec7f457e18440b1161bd04df Mon Sep 17 00:00:00 2001 From: Luke McKee Date: Sat, 9 Jul 2016 20:54:37 +0700 Subject: [PATCH 3/4] mini_snmpd: 1.4-rc1 add git,autoconf,procd init script,uci validation - new upstream/openwrt maintainer Makes use of all available runtime options that can be passed to mini_snmpd such as -I listen_on interface Run-tested on trunk on ar71xx. Please review the init script regarding procd monitoring interfaces, though everything else due to the conversion to procd should be and done properly, if not overkill compared to most other script bundled with openwrt. The main benefit of all this is now larger routers can run multiple instances of mini_snmpd on different ports, to get around the MIB hard coded 4 interface/mountpoint limits. Due to somewhat lacking dev / package maintainer docs except for http://wiki.prplfoundation.org/wiki/Procd_reference writing this script took longer than it should. You can see it's evolution here: https://github.com/hojuruku/openwrt-packages/blob/mini_snmpd/net/mini_snmpd/files/mini_snmpd.init If everything in it is found to be sane, please include it to the openwrt wiki on procd as an example. Due to procd / uci /sbin/validate_data cbi element datatype (uciname) being used to check uci config, the configuration file now only takes openwrt uci network names not physical network names as it did before. http://git.openwrt.org/?p=packages.git;a=commit;h=783e5578ad104d1ca3c31582add08fc8eb4ad083 Like busybox the package Makefile has depends for all runtime dependencies needed by the init script. mini_snmpd only depends on libc squashed commits: mini_snmpd: fix typo to fix procd triggers calling daemon binary directly instead of init script - misuse of $PROG var mini_snmpd: enable SSP & mini_snmpd to start by default and listen on lan mini_snmpd: disable RELRO blocker in Makefile after consulation mini_snmpd: add smarts to init script to detect if ubusd hasn't started yet mini_snmpd: fix init script - ubus -S doesn't print meaningful errors to give the user mini_snmpd: Makefile roll back Makefile PKG_RELEASE to 1 for feng shui --- net/mini_snmpd/Makefile | 64 +++--- net/mini_snmpd/files/mini_snmpd.config | 28 ++- net/mini_snmpd/files/mini_snmpd.init | 261 ++++++++++++++++++---- net/mini_snmpd/files/mini_snmpd.init-v2 | 146 ------------ net/mini_snmpd/files/mini_snmpd.init.orig | 65 ------ 5 files changed, 276 insertions(+), 288 deletions(-) delete mode 100644 net/mini_snmpd/files/mini_snmpd.init-v2 delete mode 100644 net/mini_snmpd/files/mini_snmpd.init.orig diff --git a/net/mini_snmpd/Makefile b/net/mini_snmpd/Makefile index e4a77b5950..5fab7fcc05 100644 --- a/net/mini_snmpd/Makefile +++ b/net/mini_snmpd/Makefile @@ -1,5 +1,5 @@ # -# Copyright (C) 2009-2014 OpenWrt.org +# Copyright (C) 2009-2016 OpenWrt.org # # This is free software, licensed under the GNU General Public License v2. # See /LICENSE for more information. @@ -8,54 +8,68 @@ include $(TOPDIR)/rules.mk PKG_NAME:=mini_snmpd -PKG_VERSION:=1.2b -PKG_RELEASE:=8 +PKG_VERSION:=1.4-rc1 +PKG_RELEASE:=1 +PKG_MAINTAINER:=Luke McKee +PKG_LICENSE:=GPL-2.0 +PKG_LICENSE_FILES:=COPYING +PKG_SOURCE_PROTO:=git +PKG_SOURCE_URL:=https://github.com/troglobit/mini-snmpd.git +PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION) +PKG_SOURCE_VERSION:=203d92e60ed09466d6676c6ad20ad6cb2ce08a5d 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_FIXUP:=autoreconf +PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION) PKG_BUILD_PARALLEL:=1 PKG_INSTALL:=1 +# As warned by upstream maintainer and binutils +# however compiler warnings can be ignored until next binutils release +# https://github.com/wongsyrone/openwrt-1/issues/67 +# PKG_SSP:=0 +# PKG_RELRO:=0 include $(INCLUDE_DIR)/package.mk -define Package/mini-snmpd +define Package/mini_snmpd SECTION:=net CATEGORY:=Network - TITLE:=SNMP server for embedded systems - URL:=http://members.aon.at/linuxfreak/linux/mini_snmpd.html + TITLE:=A tiny SNMP server for embedded systems + URL:=http://troglobit.github.io/mini-snmpd.html +# uncomment if you just want the binary, not the init script +# openwrt requires init script runtime dependencies be defined for make menuconfig +# (e.g busybox sysntpd) + DEPENDS:=+jsonfilter +ubus +procd +ubox endef -ifneq ($(CONFIG_IPV6),) - TARGET_CFLAGS+= -D__IPV6__ -else - TARGET_CFLAGS+= -D__IPV4__ -endif +CONFIGURE_ARGS+= \ + $(if $(CONFIG_IPV6),,--disable-ipv6) -TARGET_CFLAGS+= -DSYSLOG +# Configure weirdness - Disabled by default, explicitately disabling turns feature on! +# --disable-debug \ +# --disable-demo - Upstream Github Issue #4 Fixed 20160707 -MAKE_FLAGS+= \ - OFLAGS="$(TARGET_CFLAGS)" \ +# We make sure that only openwrt buildroot does the stripping as per user request via make menuconfig +CONFIGURE_VARS+= LD="$(TARGET_CC)" \ STRIP="/bin/true" \ - INSTALL_ROOT="$(PKG_INSTALL_DIR)" + CFLAGS="$(TARGET_CFLAGS)" +MAKE_FLAGS+= STRIP="/bin/true" -define Build/Compile - $(call Build/Compile/Default,mini_snmpd) -endef +# FYI upstream suggested stripping options +# STRIP="strip -S --strip-unneeded --remove-section=.note.gnu.gold-version --remove-section=.comment --remove-section=.note --remove-section=.note.gnu.build-id --remove-section=.note.ABI-tag mini_snmpd" -define Package/mini-snmpd/install +define Package/mini_snmpd/install $(INSTALL_DIR) $(1)/usr/bin - $(CP) $(PKG_INSTALL_DIR)/sbin/mini_snmpd $(1)/usr/bin/ + $(CP) $(PKG_INSTALL_DIR)/usr/bin/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 +define Package/mini_snmpd/conffiles /etc/config/mini_snmpd endef -$(eval $(call BuildPackage,mini-snmpd)) +$(eval $(call BuildPackage,mini_snmpd)) diff --git a/net/mini_snmpd/files/mini_snmpd.config b/net/mini_snmpd/files/mini_snmpd.config index e41bdc9578..c06f7b1901 100644 --- a/net/mini_snmpd/files/mini_snmpd.config +++ b/net/mini_snmpd/files/mini_snmpd.config @@ -1,16 +1,26 @@ -config mini_snmpd - option enabled 0 +# you may add more than the 'default' mini_snmpd instances provided they all bind to different ports/interfaces +# to get around max 4 interface or mountpoint limit constrained by mini_snmpd's mib +config mini_snmpd 'default' + option enabled 1 option ipv6 0 + # Verbose flag given to mini_snmpd, extra verbose is only possible with compile time config flags + option debug 0 + # Turn on community authentication (snmp agent must use community name) + option auth 0 option community 'public' - option contact '' - option location '' - + option contact 'OpenWRT router ' + option location 'Undisclosed' + # to listen on all interfaces you need to set option listen_interface '' + option listen_interface 'lan' + #option udp_port '161' + #option tcp_port '161' + #option vendor_oid '' + option mib_timeout 1 # enable basic disk usage statistics on specified mountpoint - list disks '/jffs' + list disks '/overlay' list disks '/tmp' - # enable basic network statistics on specified interface - # 4 interfaces maximum, as named in /etc/config/network - list interfaces 'loopback' + # 4 interfaces maximum per instance, as named in /etc/config/network and luci + # not physical device names 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 20e2c62237..442e350af3 100644 --- a/net/mini_snmpd/files/mini_snmpd.init +++ b/net/mini_snmpd/files/mini_snmpd.init @@ -1,65 +1,240 @@ #!/bin/sh /etc/rc.common -# Copyright (C) 2009-2012 OpenWrt.org +# Copyright (C) 2009-2016 OpenWrt.org +# Copyright (C) 2016 Luke McKee +# Procd init script reference: http://wiki.prplfoundation.org/wiki/Procd_reference -START=50 +START=98 +USE_PROCD=1 +PROG=/usr/bin/mini_snmpd +NAME=mini_snmpd -SERVICE_DAEMONIZE=1 -SERVICE_WRITE_PID=1 +_log() { + logger -p daemon.info -t mini_snmpd "$@" +} + +_err() { + logger -p daemon.err -t mini_snmpd "$@" +} + + +# mini_snmpd 1.3+ now starts later in the game. Expects filesystems monitored to be already mounted, or wont pass args to mini_snmpd +# and at least configuration entry for network physical interface defined in /etc/config/network +# It handles network interfaces not yet present (e.g. ppp) but will statfs() the root/wrong filesystem if device not mounted +# Tip: complex scripts run faster without in openwrt if you stop busybox forking and searching for applets. Faster bootups +# CONFIG_BUSYBOX_CONFIG_FEATURE_SH_NOFORK +# CONFIG_BUSYBOX_CONFIG_FEATURE_PREFER_APPLETS +# BUSYBOX_CONFIG_ASH_OPTIMIZE_FOR_SIZE [=n] +# CONFIG_BUSYBOX_CONFIG_ASH_CMDCMD + +mini_snmpd_validation="enabled:bool:0 \ + ipv6:bool:0 \ + debug:bool:0 \ + auth:bool:1 \ + community:rangelength(1,32):public \ + contact:maxlength(255) \ + location:maxlength(255) \ + listen_interface:uciname \ + udp_port:port \ + tcp_port:port \ + vendor_oid:string \ + mib_timeout:and(min(1),uinteger) \ + disks:list(directory) \ + interfaces:list(uciname) \ + respawn_threshold:uinteger respawn_timeout:uinteger respawn_retry:uinteger" +# busybox ash has no array variable support, when put validations in a string be careful to have no spaces in each validate constraint +# this makes it very difficult to use the 'or(uciname, "all")' test, so listen_interface '' or undefined now meands bind to "all". +# this is the sarafice you have to make to avoid typing it all in twice in this script so we can give feedback to user on what's misconfigered +# in syslog append_disk() { - local disk="$1" - append disks "$disk" ',' + local disk="$1" disk_count + [ -z $disk_count ] && disk_count=0 + if grep -qF "$disk" /proc/mounts ; then + # check the fileystem is mountpoint, and directory search permissions available for statfs() + # presence as a directory -d test done is already done by uci_validate_section() + [ -x "$disk" ] || { + _err "$cfg: mountpoint $disk for snmp monitoring EACCES error. Check permissions, ignoring" + return 1 + } + if [ $disk_count -lt 4 ] ; then + append disks_arg "$disk" ',' + disk_count=$((disk_count++)) + else + _err "$cfg: more than 4 mountpoints defined in uci. Disc $disk ignored." + fi + else + _err "$cfg: mountpoint $disk for snmp monitoring not mounted, ignoring." + fi } append_interface() { - local name="$1" - local device - network_get_device device "$name" - append interfaces "${device:-$name}" ',' + local name="$1" netdev netdev_count + [ -z $netdev_count ] && netdev_count=0 + # for the purposes of snmp monitoring it doesn't need to be up, it just needs to exist in /proc/net/dev + netdev=$(ubus -S call network.interface dump|jsonfilter -e "@.interface[@.interface=\"$name\"].device") + if [ -n "$netdev" ] && grep -qF "$netdev" /proc/net/dev ]; then + [ $netdev_count -ge 4 ] && { + _err "$cfg: too many network interfaces configured, ignoring $name" + return + } + netdev_count=$((netdev_count++)) + if [ -n "$interfaces_arg" ]; then + append interfaces_arg "$netdev" ',' + else + append interfaces_arg "$netdev" + fi + else + _err "$cfg: physical interface for network $name not found in uci or kernel so not monitoring" + fi } -append_string() { - local section="$1" - local option="$2" - local value="$3" - local _val - config_get _val "$section" "$option" - [ -n "$_val" ] && append args "$3 $_val" +append_arg() { + local var="$2" + local opt="$1" + [ -n "$var" ] && procd_append_param command $opt "$var" } +watch_interfaces() { + local cfg="$1" + local enabled listen_interface # listen_interface_up + config_get_bool enabled "$cfg" "enabled" '1' + [ "$enabled" -gt 0 ] || return 0 + config_get listen_interface "$cfg" listen_interface + # listen_interface_up=$(ubus -S call network.interface dump | jsonfilter -e "@.interface[@.interface=\"$listen_interface\"].up") + # If the interface is up & instance is running we'll watch at the instance level and only restart that instance if it's bound interface changes + # Regardless of ubus knowing about an interface (in the case it's not yet configured) + [ -n "$listen_interface" ] && trigger_interfaces="${listen_interface} ${trigger_interfaces} " +} + +validate_mini_snmpd_section() { + # validate a mini_snmpd instance in uci config file mini_snmpd + # http://luci.subsignal.org/trac/wiki/Documentation/Datatypes ubox/validate/validate.c + uci_validate_section mini_snmpd mini_snmpd "${1}" $mini_snmpd_validation +} + + +service_triggers() { + config_load 'mini_snmpd' + procd_open_trigger + procd_add_config_trigger "config.change" "mini_snmpd" /etc/init.d/mini_snmpd reload + config_foreach watch_interfaces 'mini_snmpd' + # this only watches interfaces for which there is no running instance due to interface down / not in ubus + # hence start not reload, this trigger will not affect running instances as another start will not change their procd command arguments + # or stop the already running process + [ -n "$trigger_interfaces" ] & { + for n in $trigger_interfaces ; do + procd_add_interface_trigger "interface.*" $n /etc/init.d/mini_snmpd start + done + } + procd_close_trigger + procd_add_validation validate_mini_snmpd_section +} + + start_instance() { - local cfg="$1" - local args="" - local disks="" - local interfaces="" - local ipv6 + local cfg validation_failed validation_err disks_arg interfaces_arg + cfg="$1" + #uci_validate_section should unset undefined variables from other instances + #however defining uci variables as local will scope them to this instance + #"local variables are also visible to functions called by the parent function" so it's good practice + local enabled ipv6 debug auth community contact location listen_interface \ + udp_port tcp_port vendor_oid mib_timeout + local disks="" interfaces="" + validate_mini_snmpd_section "$cfg" 2>/dev/null || validation_failed=1 + [ "$enabled" == 1 ] || { + _log "instance:$cfg disabled not starting" + return 1 + } + + local listen_interface_json listen_interface_ip listen_interface_device listen_interface_up ubus_exit ubus_err + [ -n "$listen_interface" ] && { + listen_interface_json=$(ubus -S call network.interface.$listen_interface status) + ubus_exit=$? + [ $ubus_exit = 4 ] && { + _err "$cfg: listen_interface $listen_interface not properly configured in ubus network.interface.* not starting this instance " + return 1 + } + [ $ubus_exit = 255 -a -z "$listen_interface_json" ] && { + _log "$cfg: ubusd not yet up, will try to start mini_snmpd shorlty when procd detects $listen_interface comes up" + return 1 + } + [ -z "$listen_interface_json" ] && { + ubus_err=`ubus call network.interface.$listen_interface status 2>&1 >/dev/null` + _err "$cfg: unknown ubus error. exit: $ubus_exit errormsg: $ubus_err " + return 1 + } + listen_interface_up=$(jsonfilter -s "$listen_interface_json" -e '@.up') + if [ "$ipv6" = 1 ]; then + listen_interface_ip=$(jsonfilter -s "$listen_interface_json" -e "@['ipv6-address'][0].address") + else + listen_interface_ip=$(jsonfilter -s "$listen_interface_json" -e "@['ipv4-address'][0].address") + fi + [ -n "$listen_interface_ip" -a "$listen_interface_up" = 'true' ] || { + _log "$cfg:listen interface $listen_interface not up yet / not configured properly" + _log "$cfg:procd will try again when interface state changes" + return 1 + } + listen_interface_device=$(jsonfilter -s "$listen_interface_json" -e '@.l3_device') + } - append_string "$cfg" community "-c" - append_string "$cfg" location "-L" - append_string "$cfg" contact "-C" + [ $validation_failed ] && { + _err "validation of $NAME configuration for $cfg instance failed, all tests should be within constraints" + _err "please edit the configuration values below using [l]uci " + validation_err=`/sbin/validate_data mini_snmpd mini_snmpd "$cfg" $mini_snmpd_validation 2>&1 | sed '/with\ false$/!d;s/validates\ as\ /needs\ to\ be\ /;s/with\ false//' ` + _err "${validation_err}" + return 1 + } + config_list_foreach "$cfg" 'disks' append_disk + config_list_foreach "$cfg" 'interfaces' append_interface + # test if variables are unset or zero length + [ -z "${disks_arg:+1}" -a -z "${interfaces_arg:+1}" ] && { + _err "$cfg: you haven't sucessfully configured any mountpoints or disks for this instance, not starting" + return 1 + } + + procd_open_instance - config_get_bool ipv6 "$cfg" "ipv6" '0' - [ "$ipv6" -gt 0 ] && append args "-6" + procd_set_param command "$PROG" -n + procd_set_param stdout "1" + procd_set_param stderr "1" + # don't the like default respawn values? you can override through uci. + # vars left as global so you only need to do it in the first mini_snmpd instance + procd_set_param respawn ${respawn_threshold:-3600} ${respawn_timeout:-10} ${respawn_retry:-1} + # this monitors ubus changes + [ -n "$listen_interface" ] && { + #procd_open_trigger + #procd_add_interface_trigger "interface.*" $listen_interface /etc/init.d/mini_snmpd reload + #procd_close_trigger + procd_add_reload_interface_trigger $listen_interface #or use shorthand of above + } + # this re-starts the daemon if a properly configured network interface is changed whilst it is already running + # igmpproxy has this as well as "procd_set_param netdev" - 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 + append_arg "-c" "$community" + append_arg "-L" "${location}" + append_arg "-C" "${contact}" + append_arg "-p" $udp_port + append_arg "-P" $tcp_port + append_arg "-V" "${vendor_oid}" + append_arg "-t" $mib_timeout + + [ "$ipv6" = 1 ] && procd_append_param command "-6" + [ "$debug" = 1 ] && procd_append_param command "-v" + # uci_validate_section() aka /sbin/validate_data can only cast default values not defined in /etc/config/* to string + # e.g. ="1" however it sets bools defined in /etc/config/* to =1 / =0 + [ "$auth" = 1 -o "$auth" = "1" ] && procd_append_param command "-a" + [ -n "$disks_arg" ] && procd_append_param command "-d $disks_arg" + [ -n "$interfaces_arg" ] && procd_append_param command "-i $interfaces_arg" + [ -n "$listen_interface_device" ] && { + procd_append_param command "-I" "$listen_interface_device" + # and this monitors the hardware device for changes outside of ubus - just a guess + procd_set_param netdev $listen_interface_device + } + procd_close_instance } -start() { - . /lib/functions/network.sh - +start_service() { config_load 'mini_snmpd' config_foreach start_instance 'mini_snmpd' } -stop() { - service_stop /usr/bin/mini_snmpd -} diff --git a/net/mini_snmpd/files/mini_snmpd.init-v2 b/net/mini_snmpd/files/mini_snmpd.init-v2 deleted file mode 100644 index 9b81407246..0000000000 --- a/net/mini_snmpd/files/mini_snmpd.init-v2 +++ /dev/null @@ -1,146 +0,0 @@ -#!/bin/sh /etc/rc.common -# Copyright (C) 2009-2016 OpenWrt.org - -START=95 -USE_PROCD=1 -PROCD_DEBUG=1 -PROG=/usr/bin/mini_snmpd -NAME=mini_snmpd - -# mini_snmpd now starts later in the game. Expects filesystems monitored to be already mounted, -# and at least configuration entry for network physical interface defined in /etc/config/network -# It handles network interfaces not yet present (e.g. ppp) but will statfs() the root/wrong filesystem if device not mounted - -append_disk() { - local disk="$1" - [ -z $disk_count ] && disk_count=1 - if grep -qF "$disk" /proc/mounts ; then - if [ $disk_count -le 4 ] ; then - append disks "$disk" ',' - disk_count=$((disk_count++)) - else - logger -s -t mini_snmpd -p daemon.error "more than 4 mountpoints defined in uci. Disc $disk ignored." - fi - else - logger -s -t mini_snmpd -p daemon.error "mountpoint $disk for snmp monitoring not mounted, ignoring." - fi -} - -append_interface() { - local name="$1" - local device - [ $(ubus -S call network.interface dump | jsonfilter -e "@.interface[@.interface=\"$name\"].device") ] && { - append interfaces "${device:-$name}" ',' - } -} - -append_arg() { - local cfg="$1" - local var="$2" - local opt="$3" - local def="$4" - local val - config_get val "$cfg" "$var" - [ -n "$val" -o -n "$def" ] && procd_append_param command $opt "${val:-$def}" -} - -listen_interface_status() { - local cfg="$1" -} - -watch_interfaces() { - local cfg="$1" - local enabled listen_interface - config_get_bool enabled "$cfg" "enabled" '1' - [ "$enabled" -gt 0 ] || return 0 - config_get listen_interface "$cfg" listen_interface - [ "$listen_interface" = "all" ] && return 0 - local listen_interface_up=$(ubus -S call network.interface dump | jsonfilter -e "@.interface[@.interface=\"$listen_interface\"].up") - # if ubus knows about it regardless if it's status we'll watch for changes. - [ -n "$listen_interface" -a -n "$listen_interface_up" ] && trigger_interfaces=" ${listen_interface} ${trigger_interfaces}" -} - -service_triggers() { - #procd_add_reload_trigger mini_snmpd - procd_open_trigger - procd_add_config_trigger "config.change" "mini_snmpd" /etc/init.d/mini_snmpd reload - config_load 'mini_snmpd' - config_foreach watch_interfaces 'mini_snmpd' - [ -n "${trigger_interfaces}" ] & { - for n in $trigger_interfaces ; do - procd_add_interface_trigger "interface.*" $n /etc/init.d/mini_snmpd restart - done - } - procd_close_trigger - #procd_add_validation validate_section_mini_snmpd -} - - -start_instance() { - local cfg="$1" disks="" interfaces="" - local ipv6 debug auth - - config_get_bool enabled "$cfg" "enabled" '1' - [ "$enabled" -gt 0 ] || return 1 - - local listen_interface listen_interface_json listen_interface_ip listen_interface_device listen_interface_up - config_get_bool ipv6 "$cfg" "ipv6" '0' - config_get listen_interface "$cfg" listen_interface - [ -n "$listen_interface" -a "$listen_interface" != "all" ] && { - listen_interface_json=$(ubus -S call network.interface.$listen_interface status) - [ -z "$listen_interface_json" ] && { - logger -s -t mini_snmpd -p daemon.error "interface configured to bind to is not configured in /etc/config/network" - return 1 - } - listen_interface_up=$(jsonfilter -s "$listen_interface_json" -e '@.up') - if [ "$ipv6" -gt 0 ]; then - listen_interface_ip=$(jsonfilter -s "$listen_interface_json" -e "@['ipv6-address'][0].address") - else - listen_interface_ip=$(jsonfilter -s "$listen_interface_json" -e "@['ipv4-address'][0].address") - fi - [ -n "$listen_interface_ip" -a "$listen_interface_up" = 'true' ] || { - logger -s -t mini_snmpd -p daemon.debug "interface configured to bind to is not up yet, procd will try again later" - return 0 - } - listen_interface_device=$(jsonfilter -s "$listen_interface_json" -e '@.l3_device') - } - - procd_open_instance - - procd_set_param command "$PROG" -n - procd_set_param stdout "1" - procd_set_param stderr "1" - procd_set_param respawn ${respawn_threshold:-3600} ${respawn_timeout:-5} ${respawn_retry:-5} - - append_arg "$cfg" community "-c" - append_arg "$cfg" location "-L" - append_arg "$cfg" contact "-C" - append_arg "$cfg" udp_port "-p" - append_arg "$cfg" tcp_port "-P" - append_arg "$cfg" vendor_oid "-V" - append_arg "$cfg" mib_timeout "-t" - - [ "$ipv6" -gt 0 ] && procd_append_param command "-6" - config_get_bool debug "$cfg" "debug" '0' - [ "$debug" -gt 0 ] && procd_append_param command "-v" - config_get_bool auth "$cfg" "auth" '0' - [ "$auth" -gt 0 ] && procd_append_param command "-a" - config_list_foreach "$cfg" 'disks' append_disk - [ -n "$disks" ] && procd_append_param command "-d $disks" - config_list_foreach "$cfg" 'interfaces' append_interface - [ -n "$interfaces" ] && procd_append_param command "-i $interfaces" - # https://github.com/troglobit/mini-snmpd/issues/4 - yes I know there is no space after the -I - [ -n "$listen_interface_device" ] && procd_append_param command "-I$listen_interface_device" - - procd_close_instance -} - -start_service() { - config_load 'mini_snmpd' - config_foreach start_instance 'mini_snmpd' -} - -reload_service() { - stop - start -} diff --git a/net/mini_snmpd/files/mini_snmpd.init.orig b/net/mini_snmpd/files/mini_snmpd.init.orig deleted file mode 100644 index 20e2c62237..0000000000 --- a/net/mini_snmpd/files/mini_snmpd.init.orig +++ /dev/null @@ -1,65 +0,0 @@ -#!/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 -} From f9dfffb6f06adfa4fb80076c7a76c405590a5f75 Mon Sep 17 00:00:00 2001 From: Luke McKee Date: Tue, 12 Jul 2016 03:30:34 +0700 Subject: [PATCH 4/4] mini_snmpd: @champtar requested PKG_FIXUP:=autoreconf take care of strip and CFLAGS options Signed-off-by: Luke McKee --- net/mini_snmpd/Makefile | 9 --------- 1 file changed, 9 deletions(-) diff --git a/net/mini_snmpd/Makefile b/net/mini_snmpd/Makefile index 5fab7fcc05..9945b8fa01 100644 --- a/net/mini_snmpd/Makefile +++ b/net/mini_snmpd/Makefile @@ -50,15 +50,6 @@ CONFIGURE_ARGS+= \ # --disable-debug \ # --disable-demo - Upstream Github Issue #4 Fixed 20160707 -# We make sure that only openwrt buildroot does the stripping as per user request via make menuconfig -CONFIGURE_VARS+= LD="$(TARGET_CC)" \ - STRIP="/bin/true" \ - CFLAGS="$(TARGET_CFLAGS)" -MAKE_FLAGS+= STRIP="/bin/true" - -# FYI upstream suggested stripping options -# STRIP="strip -S --strip-unneeded --remove-section=.note.gnu.gold-version --remove-section=.comment --remove-section=.note --remove-section=.note.gnu.build-id --remove-section=.note.ABI-tag mini_snmpd" - define Package/mini_snmpd/install $(INSTALL_DIR) $(1)/usr/bin $(CP) $(PKG_INSTALL_DIR)/usr/bin/mini_snmpd $(1)/usr/bin/