summaryrefslogtreecommitdiffstats
path: root/meta-networking/recipes-protocols/net-snmp
diff options
context:
space:
mode:
authorTudor Florea <tudor.florea@enea.com>2014-10-10 03:20:04 +0200
committerTudor Florea <tudor.florea@enea.com>2014-10-10 03:20:04 +0200
commit1b8dfe266937a37a4c642f96ceb2347bf4c00a17 (patch)
tree0c6aab146bb3c82efd9c7846a9a4e70dcb0ec84f /meta-networking/recipes-protocols/net-snmp
downloadmeta-openembedded-daisy-140929.tar.gz
initial commit for Enea Linux 4.0-140929daisy-140929
Migrated from the internal git server on the daisy-enea-point-release branch Signed-off-by: Tudor Florea <tudor.florea@enea.com>
Diffstat (limited to 'meta-networking/recipes-protocols/net-snmp')
-rw-r--r--meta-networking/recipes-protocols/net-snmp/files/ifmib.patch66
-rwxr-xr-xmeta-networking/recipes-protocols/net-snmp/files/init63
-rw-r--r--meta-networking/recipes-protocols/net-snmp/files/snmpd.conf422
-rw-r--r--meta-networking/recipes-protocols/net-snmp/files/snmptrapd.conf18
-rw-r--r--meta-networking/recipes-protocols/net-snmp/net-snmp/snmpd.service13
-rw-r--r--meta-networking/recipes-protocols/net-snmp/net-snmp/snmptrapd.service13
-rw-r--r--meta-networking/recipes-protocols/net-snmp/net-snmp/systemd-support.patch1618
-rw-r--r--meta-networking/recipes-protocols/net-snmp/net-snmp_5.7.2.bb120
8 files changed, 2333 insertions, 0 deletions
diff --git a/meta-networking/recipes-protocols/net-snmp/files/ifmib.patch b/meta-networking/recipes-protocols/net-snmp/files/ifmib.patch
new file mode 100644
index 0000000000..859c52c3e3
--- /dev/null
+++ b/meta-networking/recipes-protocols/net-snmp/files/ifmib.patch
@@ -0,0 +1,66 @@
1Signed-off-by: Jack Mitchell <jack@embed.me.uk>
2Upstream-Status: Pending
3Bug-Report: http://sourceforge.net/p/net-snmp/bugs/2449/
4
5diff --git a/agent/mibgroup/if-mib/data_access/interface_linux.c b/agent/mibgroup/if-mib/data_access/interface_linux.c
6index 3419811..d6eb91a 100644
7--- a/agent/mibgroup/if-mib/data_access/interface_linux.c
8+++ b/agent/mibgroup/if-mib/data_access/interface_linux.c
9@@ -18,7 +18,31 @@ netsnmp_feature_require(interface_ioctl_flags_set)
10
11 #ifdef HAVE_PCI_LOOKUP_NAME
12 #include <pci/pci.h>
13+#include <setjmp.h>
14 static struct pci_access *pci_access;
15+
16+/* Avoid letting libpci call exit(1) when no PCI bus is available. */
17+static int do_longjmp =0;
18+static jmp_buf err_buf;
19+static void
20+netsnmp_pci_error(char *msg, ...)
21+{
22+ va_list args;
23+ char *buf;
24+ int buflen;
25+
26+ va_start(args, msg);
27+ buflen = strlen("pcilib: ")+strlen(msg)+2;
28+ buf = malloc(buflen);
29+ snprintf(buf, buflen, "pcilib: %s\n", msg);
30+ snmp_vlog(LOG_ERR, buf, args);
31+ free(buf);
32+ va_end(args);
33+ if (do_longjmp)
34+ longjmp(err_buf, 1);
35+ else
36+ exit(1);
37+}
38 #endif
39
40 #ifdef HAVE_LINUX_ETHTOOL_H
41@@ -147,10 +171,22 @@ netsnmp_arch_interface_init(void)
42
43 #ifdef HAVE_PCI_LOOKUP_NAME
44 pci_access = pci_alloc();
45- if (pci_access)
46+ if (!pci_access) {
47+ snmp_log(LOG_ERR, "pcilib: pci_alloc failed\n");
48+ return;
49+ }
50+
51+ pci_access->error = netsnmp_pci_error;
52+
53+ do_longjmp = 1;
54+ if (setjmp(err_buf)) {
55+ pci_cleanup(pci_access);
56+ snmp_log(LOG_ERR, "pcilib: pci_init failed\n");
57+ pci_access = NULL;
58+ }
59+ else if (pci_access)
60 pci_init(pci_access);
61- else
62- snmp_log(LOG_ERR, "Unable to create pci access method\n");
63+ do_longjmp = 0;
64 #endif
65 }
66
diff --git a/meta-networking/recipes-protocols/net-snmp/files/init b/meta-networking/recipes-protocols/net-snmp/files/init
new file mode 100755
index 0000000000..434b2fa3f2
--- /dev/null
+++ b/meta-networking/recipes-protocols/net-snmp/files/init
@@ -0,0 +1,63 @@
1#! /bin/sh
2# /etc/init.d/snmpd: start snmp daemon.
3
4test -x /usr/sbin/snmpd || exit 0
5test -x /usr/sbin/snmptrapd || exit 0
6
7# Defaults
8export MIBDIRS=/usr/share/snmp/mibs
9SNMPDRUN=yes
10SNMPDOPTS='-Lsd -Lf /dev/null -p /var/run/snmpd.pid'
11TRAPDRUN=no
12TRAPDOPTS='-Lsd -p /var/run/snmptrapd.pid'
13
14# Cd to / before starting any daemons.
15cd /
16
17case "$1" in
18 start)
19 echo -n "Starting network management services:"
20 if [ "$SNMPDRUN" = "yes" -a -f /etc/snmp/snmpd.conf ]; then
21 start-stop-daemon -S -x /usr/sbin/snmpd \
22 -- $SNMPDOPTS
23 echo -n " snmpd"
24 fi
25 if [ "$TRAPDRUN" = "yes" -a -f /etc/snmp/snmptrapd.conf ]; then
26 start-stop-daemon -S -x /usr/sbin/snmptrapd \
27 -- $TRAPDOPTS
28 echo -n " snmptrapd"
29 fi
30 echo "."
31 ;;
32 stop)
33 echo -n "Stopping network management services:"
34 start-stop-daemon -K -x /usr/sbin/snmpd
35 echo -n " snmpd"
36 start-stop-daemon -K -x /usr/sbin/snmptrapd
37 echo -n " snmptrapd"
38 echo "."
39 ;;
40 restart|reload|force-reload)
41 echo -n "Restarting network management services:"
42 start-stop-daemon -K -x /usr/sbin/snmpd
43 start-stop-daemon -K -x /usr/sbin/snmptrapd
44 # Allow the daemons time to exit completely.
45 sleep 2
46 if [ "$SNMPDRUN" = "yes" -a -f /etc/snmp/snmpd.conf ]; then
47 start-stop-daemon -S -x /usr/sbin/snmpd -- $SNMPDOPTS
48 echo -n " snmpd"
49 fi
50 if [ "$TRAPDRUN" = "yes" -a -f /etc/snmp/snmptrapd.conf ]; then
51 # Allow snmpd time to start up.
52 sleep 1
53 start-stop-daemon -S -x /usr/sbin/snmptrapd -- $TRAPDOPTS
54 echo -n " snmptrapd"
55 fi
56 echo "."
57 ;;
58 *)
59 echo "Usage: /etc/init.d/snmpd {start|stop|restart|reload|force-reload}"
60 exit 1
61esac
62
63exit 0
diff --git a/meta-networking/recipes-protocols/net-snmp/files/snmpd.conf b/meta-networking/recipes-protocols/net-snmp/files/snmpd.conf
new file mode 100644
index 0000000000..728171c427
--- /dev/null
+++ b/meta-networking/recipes-protocols/net-snmp/files/snmpd.conf
@@ -0,0 +1,422 @@
1###############################################################################
2#
3# EXAMPLE.conf:
4# An example configuration file for configuring the ucd-snmp snmpd agent.
5#
6###############################################################################
7#
8# This file is intended to only be an example. If, however, you want
9# to use it, it should be placed in /etc/snmp/snmpd.conf.
10# When the snmpd agent starts up, this is where it will look for it.
11#
12# You might be interested in generating your own snmpd.conf file using
13# the "snmpconf" program (perl script) instead. It's a nice menu
14# based interface to writing well commented configuration files. Try it!
15#
16# Note: This file is automatically generated from EXAMPLE.conf.def.
17# Do NOT read the EXAMPLE.conf.def file! Instead, after you have run
18# configure & make, and then make sure you read the EXAMPLE.conf file
19# instead, as it will tailor itself to your configuration.
20
21# All lines beginning with a '#' are comments and are intended for you
22# to read. All other lines are configuration commands for the agent.
23
24#
25# PLEASE: read the snmpd.conf(5) manual page as well!
26#
27
28
29###############################################################################
30# Access Control
31###############################################################################
32
33# YOU SHOULD CHANGE THE "COMMUNITY" TOKEN BELOW TO A NEW KEYWORD ONLY
34# KNOWN AT YOUR SITE. YOU *MUST* CHANGE THE NETWORK TOKEN BELOW TO
35# SOMETHING REFLECTING YOUR LOCAL NETWORK ADDRESS SPACE.
36
37# By far, the most common question I get about the agent is "why won't
38# it work?", when really it should be "how do I configure the agent to
39# allow me to access it?"
40#
41# By default, the agent responds to the "public" community for read
42# only access, if run out of the box without any configuration file in
43# place. The following examples show you other ways of configuring
44# the agent so that you can change the community names, and give
45# yourself write access as well.
46#
47# The following lines change the access permissions of the agent so
48# that the COMMUNITY string provides read-only access to your entire
49# NETWORK (EG: 10.10.10.0/24), and read/write access to only the
50# localhost (127.0.0.1, not its real ipaddress).
51#
52# For more information, read the FAQ as well as the snmpd.conf(5)
53# manual page.
54
55####
56# First, map the community name (COMMUNITY) into a security name
57# (local and mynetwork, depending on where the request is coming
58# from):
59
60# sec.name source community
61com2sec paranoid default public
62#com2sec readonly default public
63#com2sec readwrite default private
64
65####
66# Second, map the security names into group names:
67
68# sec.model sec.name
69group MyROSystem v1 paranoid
70group MyROSystem v2c paranoid
71group MyROSystem usm paranoid
72group MyROGroup v1 readonly
73group MyROGroup v2c readonly
74group MyROGroup usm readonly
75group MyRWGroup v1 readwrite
76group MyRWGroup v2c readwrite
77group MyRWGroup usm readwrite
78
79####
80# Third, create a view for us to let the groups have rights to:
81
82# incl/excl subtree mask
83view all included .1 80
84view system included .iso.org.dod.internet.mgmt.mib-2.system
85
86####
87# Finally, grant the 2 groups access to the 1 view with different
88# write permissions:
89
90# context sec.model sec.level match read write notif
91access MyROSystem "" any noauth exact system none none
92access MyROGroup "" any noauth exact all none none
93access MyRWGroup "" any noauth exact all all none
94
95# -----------------------------------------------------------------------------
96
97
98###############################################################################
99# System contact information
100#
101
102# It is also possible to set the sysContact and sysLocation system
103# variables through the snmpd.conf file. **PLEASE NOTE** that setting
104# the value of these objects here makes these objects READ-ONLY
105# (regardless of any access control settings). Any attempt to set the
106# value of an object whose value is given here will fail with an error
107# status of notWritable.
108
109syslocation Unknown (configure /etc/snmp/snmpd.local.conf)
110syscontact Root <root@localhost> (configure /etc/snmp/snmpd.local.conf)
111
112# Example output of snmpwalk:
113# % snmpwalk -v 1 -c public localhost system
114# system.sysDescr.0 = "SunOS name sun4c"
115# system.sysObjectID.0 = OID: enterprises.ucdavis.ucdSnmpAgent.sunos4
116# system.sysUpTime.0 = Timeticks: (595637548) 68 days, 22:32:55
117# system.sysContact.0 = "Me <me@somewhere.org>"
118# system.sysName.0 = "name"
119# system.sysLocation.0 = "Right here, right now."
120# system.sysServices.0 = 72
121
122
123# -----------------------------------------------------------------------------
124
125
126###############################################################################
127# Process checks.
128#
129# The following are examples of how to use the agent to check for
130# processes running on the host. The syntax looks something like:
131#
132# proc NAME [MAX=0] [MIN=0]
133#
134# NAME: the name of the process to check for. It must match
135# exactly (ie, http will not find httpd processes).
136# MAX: the maximum number allowed to be running. Defaults to 0.
137# MIN: the minimum number to be running. Defaults to 0.
138
139#
140# Examples:
141#
142
143# Make sure mountd is running
144#proc mountd
145
146# Make sure there are no more than 4 ntalkds running, but 0 is ok too.
147#proc ntalkd 4
148
149# Make sure at least one sendmail, but less than or equal to 10 are running.
150#proc sendmail 10 1
151
152# A snmpwalk of the prTable would look something like this:
153#
154# % snmpwalk -v 1 -c public localhost .1.3.6.1.4.1.2021.2
155# enterprises.ucdavis.procTable.prEntry.prIndex.1 = 1
156# enterprises.ucdavis.procTable.prEntry.prIndex.2 = 2
157# enterprises.ucdavis.procTable.prEntry.prIndex.3 = 3
158# enterprises.ucdavis.procTable.prEntry.prNames.1 = "mountd"
159# enterprises.ucdavis.procTable.prEntry.prNames.2 = "ntalkd"
160# enterprises.ucdavis.procTable.prEntry.prNames.3 = "sendmail"
161# enterprises.ucdavis.procTable.prEntry.prMin.1 = 0
162# enterprises.ucdavis.procTable.prEntry.prMin.2 = 0
163# enterprises.ucdavis.procTable.prEntry.prMin.3 = 1
164# enterprises.ucdavis.procTable.prEntry.prMax.1 = 0
165# enterprises.ucdavis.procTable.prEntry.prMax.2 = 4
166# enterprises.ucdavis.procTable.prEntry.prMax.3 = 10
167# enterprises.ucdavis.procTable.prEntry.prCount.1 = 0
168# enterprises.ucdavis.procTable.prEntry.prCount.2 = 0
169# enterprises.ucdavis.procTable.prEntry.prCount.3 = 1
170# enterprises.ucdavis.procTable.prEntry.prErrorFlag.1 = 1
171# enterprises.ucdavis.procTable.prEntry.prErrorFlag.2 = 0
172# enterprises.ucdavis.procTable.prEntry.prErrorFlag.3 = 0
173# enterprises.ucdavis.procTable.prEntry.prErrMessage.1 = "No mountd process running."
174# enterprises.ucdavis.procTable.prEntry.prErrMessage.2 = ""
175# enterprises.ucdavis.procTable.prEntry.prErrMessage.3 = ""
176# enterprises.ucdavis.procTable.prEntry.prErrFix.1 = 0
177# enterprises.ucdavis.procTable.prEntry.prErrFix.2 = 0
178# enterprises.ucdavis.procTable.prEntry.prErrFix.3 = 0
179#
180# Note that the errorFlag for mountd is set to 1 because one is not
181# running (in this case an rpc.mountd is, but thats not good enough),
182# and the ErrMessage tells you what's wrong. The configuration
183# imposed in the snmpd.conf file is also shown.
184#
185# Special Case: When the min and max numbers are both 0, it assumes
186# you want a max of infinity and a min of 1.
187#
188
189
190# -----------------------------------------------------------------------------
191
192
193###############################################################################
194# Executables/scripts
195#
196
197#
198# You can also have programs run by the agent that return a single
199# line of output and an exit code. Here are two examples.
200#
201# exec NAME PROGRAM [ARGS ...]
202#
203# NAME: A generic name.
204# PROGRAM: The program to run. Include the path!
205# ARGS: optional arguments to be passed to the program
206
207# a simple hello world
208#exec echotest /bin/echo hello world
209
210# Run a shell script containing:
211#
212# #!/bin/sh
213# echo hello world
214# echo hi there
215# exit 35
216#
217# Note: this has been specifically commented out to prevent
218# accidental security holes due to someone else on your system writing
219# a /tmp/shtest before you do. Uncomment to use it.
220#
221#exec shelltest /bin/sh /tmp/shtest
222
223# Then,
224# % snmpwalk -v 1 -c public localhost .1.3.6.1.4.1.2021.8
225# enterprises.ucdavis.extTable.extEntry.extIndex.1 = 1
226# enterprises.ucdavis.extTable.extEntry.extIndex.2 = 2
227# enterprises.ucdavis.extTable.extEntry.extNames.1 = "echotest"
228# enterprises.ucdavis.extTable.extEntry.extNames.2 = "shelltest"
229# enterprises.ucdavis.extTable.extEntry.extCommand.1 = "/bin/echo hello world"
230# enterprises.ucdavis.extTable.extEntry.extCommand.2 = "/bin/sh /tmp/shtest"
231# enterprises.ucdavis.extTable.extEntry.extResult.1 = 0
232# enterprises.ucdavis.extTable.extEntry.extResult.2 = 35
233# enterprises.ucdavis.extTable.extEntry.extOutput.1 = "hello world."
234# enterprises.ucdavis.extTable.extEntry.extOutput.2 = "hello world."
235# enterprises.ucdavis.extTable.extEntry.extErrFix.1 = 0
236# enterprises.ucdavis.extTable.extEntry.extErrFix.2 = 0
237
238# Note that the second line of the /tmp/shtest shell script is cut
239# off. Also note that the exit status of 35 was returned.
240
241# -----------------------------------------------------------------------------
242
243
244###############################################################################
245# disk checks
246#
247
248# The agent can check the amount of available disk space, and make
249# sure it is above a set limit.
250
251# disk PATH [MIN=DEFDISKMINIMUMSPACE]
252#
253# PATH: mount path to the disk in question.
254# MIN: Disks with space below this value will have the Mib's errorFlag set.
255# Default value = DEFDISKMINIMUMSPACE.
256
257# Check the / partition and make sure it contains at least 10 megs.
258
259#disk / 10000
260
261# % snmpwalk -v 1 -c public localhost .1.3.6.1.4.1.2021.9
262# enterprises.ucdavis.diskTable.dskEntry.diskIndex.1 = 0
263# enterprises.ucdavis.diskTable.dskEntry.diskPath.1 = "/" Hex: 2F
264# enterprises.ucdavis.diskTable.dskEntry.diskDevice.1 = "/dev/dsk/c201d6s0"
265# enterprises.ucdavis.diskTable.dskEntry.diskMinimum.1 = 10000
266# enterprises.ucdavis.diskTable.dskEntry.diskTotal.1 = 837130
267# enterprises.ucdavis.diskTable.dskEntry.diskAvail.1 = 316325
268# enterprises.ucdavis.diskTable.dskEntry.diskUsed.1 = 437092
269# enterprises.ucdavis.diskTable.dskEntry.diskPercent.1 = 58
270# enterprises.ucdavis.diskTable.dskEntry.diskErrorFlag.1 = 0
271# enterprises.ucdavis.diskTable.dskEntry.diskErrorMsg.1 = ""
272
273# -----------------------------------------------------------------------------
274
275
276###############################################################################
277# load average checks
278#
279
280# load [1MAX=DEFMAXLOADAVE] [5MAX=DEFMAXLOADAVE] [15MAX=DEFMAXLOADAVE]
281#
282# 1MAX: If the 1 minute load average is above this limit at query
283# time, the errorFlag will be set.
284# 5MAX: Similar, but for 5 min average.
285# 15MAX: Similar, but for 15 min average.
286
287# Check for loads:
288#load 12 14 14
289
290# % snmpwalk -v 1 -c public localhost .1.3.6.1.4.1.2021.10
291# enterprises.ucdavis.loadTable.laEntry.loadaveIndex.1 = 1
292# enterprises.ucdavis.loadTable.laEntry.loadaveIndex.2 = 2
293# enterprises.ucdavis.loadTable.laEntry.loadaveIndex.3 = 3
294# enterprises.ucdavis.loadTable.laEntry.loadaveNames.1 = "Load-1"
295# enterprises.ucdavis.loadTable.laEntry.loadaveNames.2 = "Load-5"
296# enterprises.ucdavis.loadTable.laEntry.loadaveNames.3 = "Load-15"
297# enterprises.ucdavis.loadTable.laEntry.loadaveLoad.1 = "0.49" Hex: 30 2E 34 39
298# enterprises.ucdavis.loadTable.laEntry.loadaveLoad.2 = "0.31" Hex: 30 2E 33 31
299# enterprises.ucdavis.loadTable.laEntry.loadaveLoad.3 = "0.26" Hex: 30 2E 32 36
300# enterprises.ucdavis.loadTable.laEntry.loadaveConfig.1 = "12.00"
301# enterprises.ucdavis.loadTable.laEntry.loadaveConfig.2 = "14.00"
302# enterprises.ucdavis.loadTable.laEntry.loadaveConfig.3 = "14.00"
303# enterprises.ucdavis.loadTable.laEntry.loadaveErrorFlag.1 = 0
304# enterprises.ucdavis.loadTable.laEntry.loadaveErrorFlag.2 = 0
305# enterprises.ucdavis.loadTable.laEntry.loadaveErrorFlag.3 = 0
306# enterprises.ucdavis.loadTable.laEntry.loadaveErrMessage.1 = ""
307# enterprises.ucdavis.loadTable.laEntry.loadaveErrMessage.2 = ""
308# enterprises.ucdavis.loadTable.laEntry.loadaveErrMessage.3 = ""
309
310# -----------------------------------------------------------------------------
311
312
313###############################################################################
314# Extensible sections.
315#
316
317# This alleviates the multiple line output problem found in the
318# previous executable mib by placing each mib in its own mib table:
319
320# Run a shell script containing:
321#
322# #!/bin/sh
323# echo hello world
324# echo hi there
325# exit 35
326#
327# Note: this has been specifically commented out to prevent
328# accidental security holes due to someone else on your system writing
329# a /tmp/shtest before you do. Uncomment to use it.
330#
331# exec .1.3.6.1.4.1.2021.50 shelltest /bin/sh /tmp/shtest
332
333# % snmpwalk -v 1 -c public localhost .1.3.6.1.4.1.2021.50
334# enterprises.ucdavis.50.1.1 = 1
335# enterprises.ucdavis.50.2.1 = "shelltest"
336# enterprises.ucdavis.50.3.1 = "/bin/sh /tmp/shtest"
337# enterprises.ucdavis.50.100.1 = 35
338# enterprises.ucdavis.50.101.1 = "hello world."
339# enterprises.ucdavis.50.101.2 = "hi there."
340# enterprises.ucdavis.50.102.1 = 0
341
342# Now the Output has grown to two lines, and we can see the 'hi
343# there.' output as the second line from our shell script.
344#
345# Note that you must alter the mib.txt file to be correct if you want
346# the .50.* outputs above to change to reasonable text descriptions.
347
348# Other ideas:
349#
350# exec .1.3.6.1.4.1.2021.51 ps /bin/ps
351# exec .1.3.6.1.4.1.2021.52 top /usr/local/bin/top
352# exec .1.3.6.1.4.1.2021.53 mailq /usr/bin/mailq
353
354# -----------------------------------------------------------------------------
355
356
357###############################################################################
358# Pass through control.
359#
360
361# Usage:
362# pass MIBOID EXEC-COMMAND
363#
364# This will pass total control of the mib underneath the MIBOID
365# portion of the mib to the EXEC-COMMAND.
366#
367# Note: You'll have to change the path of the passtest script to your
368# source directory or install it in the given location.
369#
370# Example: (see the script for details)
371# (commented out here since it requires that you place the
372# script in the right location. (its not installed by default))
373
374# pass .1.3.6.1.4.1.2021.255 /bin/sh /usr/local/passtest
375
376# % snmpwalk -v 1 -c public localhost .1.3.6.1.4.1.2021.255
377# enterprises.ucdavis.255.1 = "life the universe and everything"
378# enterprises.ucdavis.255.2.1 = 42
379# enterprises.ucdavis.255.2.2 = OID: 42.42.42
380# enterprises.ucdavis.255.3 = Timeticks: (363136200) 42 days, 0:42:42
381# enterprises.ucdavis.255.4 = IpAddress: 127.0.0.1
382# enterprises.ucdavis.255.5 = 42
383# enterprises.ucdavis.255.6 = Gauge: 42
384#
385# % snmpget -v 1 -c public localhost .1.3.6.1.4.1.2021.255.5
386# enterprises.ucdavis.255.5 = 42
387#
388# % snmpset -v 1 -c public localhost .1.3.6.1.4.1.2021.255.1 s "New string"
389# enterprises.ucdavis.255.1 = "New string"
390#
391
392# For specific usage information, see the man/snmpd.conf.5 manual page
393# as well as the local/passtest script used in the above example.
394
395###############################################################################
396# Subagent control
397#
398
399# The agent can support subagents using a number of extension mechanisms.
400# From the 4.2.1 release, AgentX support is being compiled in by default.
401# However, this is still experimental code, so should not be used on
402# critical production systems.
403# Please see the file README.agentx for more details.
404#
405# If having read, marked, learnt and inwardly digested this information,
406# you decide that you do wish to make use of this mechanism, simply
407# uncomment the following directive.
408#
409# master agentx
410#
411# I repeat - this is *NOT* regarded as suitable for front-line production
412# systems, though it is probably stable enough for day-to-day use.
413# Probably.
414#
415# No refunds will be given.
416
417###############################################################################
418# Further Information
419#
420# See the snmpd.conf manual page, and the output of "snmpd -H".
421# MUCH more can be done with the snmpd.conf than is shown as an
422# example here.
diff --git a/meta-networking/recipes-protocols/net-snmp/files/snmptrapd.conf b/meta-networking/recipes-protocols/net-snmp/files/snmptrapd.conf
new file mode 100644
index 0000000000..8d2e4375ef
--- /dev/null
+++ b/meta-networking/recipes-protocols/net-snmp/files/snmptrapd.conf
@@ -0,0 +1,18 @@
1###############################################################################
2#
3# EXAMPLE.conf:
4# An example configuration file for configuring the ucd-snmp snmptrapd agent.
5#
6###############################################################################
7#
8# This file is intended to only be an example. If, however, you want
9# to use it, it should be placed in /etc/snmp/snmptrapd.conf.
10# When the snmptrapd agent starts up, this is where it will look for it.
11#
12# All lines beginning with a '#' are comments and are intended for you
13# to read. All other lines are configuration commands for the agent.
14
15#
16# PLEASE: read the snmptrapd.conf(5) manual page as well!
17#
18
diff --git a/meta-networking/recipes-protocols/net-snmp/net-snmp/snmpd.service b/meta-networking/recipes-protocols/net-snmp/net-snmp/snmpd.service
new file mode 100644
index 0000000000..10a1eb2128
--- /dev/null
+++ b/meta-networking/recipes-protocols/net-snmp/net-snmp/snmpd.service
@@ -0,0 +1,13 @@
1[Unit]
2Description=Simple Network Management Protocol (SNMP) Daemon.
3After=syslog.target network.target
4
5[Service]
6Type=notify
7Environment=OPTIONS="-LS0-6d"
8EnvironmentFile=-/etc/default/snmpd
9ExecStart=/usr/sbin/snmpd $OPTIONS -f
10ExecReload=/bin/kill -HUP $MAINPID
11
12[Install]
13WantedBy=multi-user.target
diff --git a/meta-networking/recipes-protocols/net-snmp/net-snmp/snmptrapd.service b/meta-networking/recipes-protocols/net-snmp/net-snmp/snmptrapd.service
new file mode 100644
index 0000000000..951f9f2707
--- /dev/null
+++ b/meta-networking/recipes-protocols/net-snmp/net-snmp/snmptrapd.service
@@ -0,0 +1,13 @@
1[Unit]
2Description=Simple Network Management Protocol (SNMP) Trap Daemon.
3After=syslog.target network.target
4
5[Service]
6Type=notify
7Environment=OPTIONS="-Lsd"
8EnvironmentFile=-/etc/default/snmptrapd
9ExecStart=/usr/sbin/snmptrapd $OPTIONS -f
10ExecReload=/bin/kill -HUP $MAINPID
11
12[Install]
13WantedBy=multi-user.target
diff --git a/meta-networking/recipes-protocols/net-snmp/net-snmp/systemd-support.patch b/meta-networking/recipes-protocols/net-snmp/net-snmp/systemd-support.patch
new file mode 100644
index 0000000000..e19153bbc4
--- /dev/null
+++ b/meta-networking/recipes-protocols/net-snmp/net-snmp/systemd-support.patch
@@ -0,0 +1,1618 @@
1Systemd support backported from the master branch as of 23/04/2012 (post 5.7.1, pre 5.8).
2
3The following commits have been cherry-picked:
4
519499c3c90bf9d7b2b9e5d08baa26cc6bba28a11
6fef6cddfdb94da1a6b1fb768af62918b80f11fd3
70641e43c694c485cbbffef0556efc4641bd3ff50
876530a89f1c8bbd0b63acce63e10d5d4812a1a16 (conflict resolved)
9bf108d7f1354f6276fc43c129963f2c49b9fc242
103692875172352f72cf3afd0d35f355e83d7e421b
1174412748067c685e1d8ab6ed3bcc3ca9c2774844
1286132e3f1e6ef7b4e0b96d8fa24e37c81b71b0e0
1363557cf8986a33dba1d4429b583a901361052c4f
14
15Upstream-Status: Backport
16
17Signed-off-by: Thomas Fitzsimmons <fitzsim@cisco.com>
18diff --git a/README.systemd b/README.systemd
19new file mode 100644
20index 0000000..f731851
21--- /dev/null
22+++ b/README.systemd
23@@ -0,0 +1,41 @@
24+README.systemd
25+--------------
26+Net-SNMP provides two daemons, which support systemd system manager.
27+See http://www.freedesktop.org/wiki/Software/systemd to learn how
28+systemd works. Both socket activation and notification is supported by these
29+daemons.
30+
31+To enable systemd support, the sources must be compiled with
32+--with-systemd configure option.
33+
34+snmpd - The SNMP agent
35+----------------------
36+Socket activation od snmpd daemon is implemented, but it's discouraged.
37+The reason is simple - snmpd not only listens and processes SNMP requests
38+from network, but also gathers system statistics counters, sends traps and
39+communicates with subagents. It even opens few netlink sockets.
40+
41+In other words, snmpd should run from system start to properly work.
42+This can be done in two ways:
43+1) either as snmpd service unit with 'Type=notification' and without a socket
44+ unit
45+2) or as snmpd service unit with 'Type=simple', appropriate socket socket unit
46+ and the snmpd service enabled. This way systemd creates the snmpd listening
47+ socket early during boot and passes the sockets to snmpd slightly later
48+ (but still during machine boot). This way systemd can paralelize start of
49+ services, which depend on snmpd. Admins must adjust the socket file manually,
50+ depending if the snmpd support AgentX, IPv6, SMUX etc.
51+
52+snmpd should be started with '-f' command line parameter to disable forking -
53+systemd does that for us automatically.
54+
55+
56+snmptrapd - The trap processing daemon
57+--------------------------------------
58+snmptrapd supports full socket activation and also notification (if needed).
59+Both 'Type=simple' (with appropriate socket unit) and 'Type=notify' services
60+will work. Again, '-f' parameter should be provided on snmptrapd command line.
61+
62+If integration with SNMP agent using AgentX protocol is enabled, snmptrapd should
63+start during boot and not after first SNMP trap arrives. Same rules as for snmpd
64+applies then.
65\ No newline at end of file
66diff --git a/agent/snmpd.c b/agent/snmpd.c
67index b177d5b..08bdfc7 100644
68--- a/agent/snmpd.c
69+++ b/agent/snmpd.c
70@@ -164,6 +164,10 @@ typedef long fd_mask;
71
72 #endif
73
74+#ifndef NETSNMP_NO_SYSTEMD
75+#include <net-snmp/library/sd-daemon.h>
76+#endif
77+
78 netsnmp_feature_want(logging_file)
79 netsnmp_feature_want(logging_stdio)
80 netsnmp_feature_want(logging_syslog)
81@@ -441,18 +445,28 @@ main(int argc, char *argv[])
82 int agent_mode = -1;
83 char *pid_file = NULL;
84 char option_compatability[] = "-Le";
85+#ifndef WIN32
86+ int prepared_sockets = 0;
87+#endif
88 #if HAVE_GETPID
89 int fd;
90 FILE *PID;
91 #endif
92
93 #ifndef WIN32
94+#ifndef NETSNMP_NO_SYSTEMD
95+ /* check if systemd has sockets for us and don't close them */
96+ prepared_sockets = netsnmp_sd_listen_fds(0);
97+#endif /* NETSNMP_NO_SYSTEMD */
98+
99 /*
100 * close all non-standard file descriptors we may have
101 * inherited from the shell.
102 */
103- for (i = getdtablesize() - 1; i > 2; --i) {
104- (void) close(i);
105+ if (!prepared_sockets) {
106+ for (i = getdtablesize() - 1; i > 2; --i) {
107+ (void) close(i);
108+ }
109 }
110 #endif /* #WIN32 */
111
112@@ -1100,6 +1114,19 @@ main(int argc, char *argv[])
113 netsnmp_addrcache_initialise();
114
115 /*
116+ * Let systemd know we're up.
117+ */
118+#ifndef NETSNMP_NO_SYSTEMD
119+ netsnmp_sd_notify(1, "READY=1\n");
120+ if (prepared_sockets)
121+ /*
122+ * Clear the environment variable, we already processed all the sockets
123+ * by now.
124+ */
125+ netsnmp_sd_listen_fds(1);
126+#endif
127+
128+ /*
129 * Forever monitor the dest_port for incoming PDUs.
130 */
131 DEBUGMSGTL(("snmpd/main", "We're up. Starting to process data.\n"));
132diff --git a/apps/snmptrapd.c b/apps/snmptrapd.c
133index 1a52080..0857ae1 100644
134--- a/apps/snmptrapd.c
135+++ b/apps/snmptrapd.c
136@@ -125,6 +125,10 @@ SOFTWARE.
137
138 #include <net-snmp/net-snmp-features.h>
139
140+#ifndef NETSNMP_NO_SYSTEMD
141+#include <net-snmp/library/sd-daemon.h>
142+#endif
143+
144 #ifndef BSD4_3
145 #define BSD4_2
146 #endif
147@@ -655,15 +659,24 @@ main(int argc, char *argv[])
148 int agentx_subagent = 1;
149 #endif
150 netsnmp_trapd_handler *traph;
151+#ifndef WIN32
152+ int prepared_sockets = 0;
153+#endif
154
155
156 #ifndef WIN32
157+#ifndef NETSNMP_NO_SYSTEMD
158+ /* check if systemd has sockets for us and don't close them */
159+ prepared_sockets = netsnmp_sd_listen_fds(0);
160+#endif
161 /*
162 * close all non-standard file descriptors we may have
163 * inherited from the shell.
164 */
165- for (i = getdtablesize() - 1; i > 2; --i) {
166- (void) close(i);
167+ if (!prepared_sockets) {
168+ for (i = getdtablesize() - 1; i > 2; --i) {
169+ (void) close(i);
170+ }
171 }
172 #endif /* #WIN32 */
173
174@@ -1311,6 +1324,19 @@ main(int argc, char *argv[])
175 #endif
176 #endif
177
178+ /*
179+ * Let systemd know we're up.
180+ */
181+#ifndef NETSNMP_NO_SYSTEMD
182+ netsnmp_sd_notify(1, "READY=1\n");
183+ if (prepared_sockets)
184+ /*
185+ * Clear the environment variable, we already processed all the sockets
186+ * by now.
187+ */
188+ netsnmp_sd_listen_fds(1);
189+#endif
190+
191 #ifdef WIN32SERVICE
192 trapd_status = SNMPTRAPD_RUNNING;
193 #endif
194diff --git a/configure.d/config_modules_lib b/configure.d/config_modules_lib
195index b6609c1..5849072 100644
196--- a/configure.d/config_modules_lib
197+++ b/configure.d/config_modules_lib
198@@ -53,6 +53,14 @@ if test "x$PARTIALTARGETOS" = "xmingw32" -o "x$PARTIALTARGETOS" = "xmingw32msvc"
199 other_ftobjs_list="$other_ftobjs_list winpipe.ft"
200 fi
201
202+# Linux systemd
203+if test "x$with_systemd" == "xyes"; then
204+ other_src_list="$other_src_list sd-daemon.c"
205+ other_objs_list="$other_objs_list sd-daemon.o"
206+ other_lobjs_list="$other_lobjs_list sd-daemon.lo"
207+ other_ftobjs_list="$other_ftobjs_list sd-daemon.ft"
208+fi
209+
210 AC_SUBST(other_src_list)
211 AC_SUBST(other_objs_list)
212 AC_SUBST(other_lobjs_list)
213diff --git a/configure.d/config_project_with_enable b/configure.d/config_project_with_enable
214index 8b46ad2..59d6d5c 100644
215--- a/configure.d/config_project_with_enable
216+++ b/configure.d/config_project_with_enable
217@@ -689,6 +689,15 @@ if test "x$with_dummy_values" != "xyes"; then
218 data for])
219 fi
220
221+NETSNMP_ARG_WITH(systemd,
222+[ --with-systemd Provide systemd support. See README.systemd
223+ for details.])
224+# Define unless specifically suppressed (i.e., option defaults to false).
225+if test "x$with_systemd" != "xyes"; then
226+ AC_DEFINE(NETSNMP_NO_SYSTEMD, 1,
227+ [If you don't want to integrate with systemd.])
228+fi
229+
230 NETSNMP_ARG_ENABLE(set-support,
231 [ --disable-set-support Do not allow SNMP set requests.])
232 if test "x$enable_set_support" = "xno"; then
233diff --git a/dist/snmpd.service b/dist/snmpd.service
234new file mode 100644
235index 0000000..31391e5
236--- /dev/null
237+++ b/dist/snmpd.service
238@@ -0,0 +1,18 @@
239+#
240+# SNMP agent service file for systemd
241+#
242+#
243+# The service should be enabled, i.e. snmpd should start during machine boot.
244+# Socket activation shall not be used. See README.systemd for details.
245+
246+[Unit]
247+Description=Simple Network Management Protocol (SNMP) daemon.
248+After=syslog.target network.target
249+
250+[Service]
251+# Type=notify is also supported. It should be set when snmpd.socket is not used.
252+Type=simple
253+ExecStart=/usr/sbin/snmpd -f
254+
255+[Install]
256+WantedBy=multi-user.target
257diff --git a/dist/snmpd.socket b/dist/snmpd.socket
258new file mode 100644
259index 0000000..7f3a2d9
260--- /dev/null
261+++ b/dist/snmpd.socket
262@@ -0,0 +1,17 @@
263+[Unit]
264+Description=Socket listening for SNMP and AgentX messages
265+
266+[Socket]
267+ListenDatagram=0.0.0.0:161
268+# Uncomment other listening addresses as needed - TCP, UDP6, TCP6.
269+# It must match listening addresses/ports defined in snmpd.service
270+# or snmpd.conf.
271+# ListenStream=0.0.0.0:161
272+# ListenDatagram=[::]:161
273+# ListenStream=[::]:161
274+#
275+# Uncomment AgentX socket if snmpd.conf enables AgentX protocol.
276+# ListenStream=/var/agentx/master
277+
278+[Install]
279+WantedBy=sockets.target
280diff --git a/dist/snmptrapd.service b/dist/snmptrapd.service
281new file mode 100644
282index 0000000..e88a5b4
283--- /dev/null
284+++ b/dist/snmptrapd.service
285@@ -0,0 +1,16 @@
286+#
287+# SNMP trap-processing service file for systemd
288+#
289+
290+[Unit]
291+Description=Simple Network Management Protocol (SNMP) Trap daemon.
292+After=syslog.target network.target
293+
294+[Service]
295+# Type=notify is also supported. It should be set when snmptrapd.socket is not
296+# used.
297+Type=simple
298+ExecStart=/usr/sbin/snmptrapd -f
299+
300+[Install]
301+WantedBy=multi-user.target
302diff --git a/dist/snmptrapd.socket b/dist/snmptrapd.socket
303new file mode 100644
304index 0000000..0fc8a7c
305--- /dev/null
306+++ b/dist/snmptrapd.socket
307@@ -0,0 +1,14 @@
308+[Unit]
309+Description=Socket listening for SNMP trap messages
310+
311+[Socket]
312+ListenDatagram=0.0.0.0:162
313+# Uncomment other listening addresses as needed - TCP, UDP6, TCP6.
314+# It must match listening addresses/ports defined in snmptrapd.service
315+# or snmptrapd.conf.
316+# ListenStream=0.0.0.0:162
317+# ListenDatagram=[::]:162
318+# ListenStream=[::]:162
319+
320+[Install]
321+WantedBy=sockets.target
322diff --git a/include/net-snmp/library/sd-daemon.h b/include/net-snmp/library/sd-daemon.h
323new file mode 100644
324index 0000000..85274c9
325--- /dev/null
326+++ b/include/net-snmp/library/sd-daemon.h
327@@ -0,0 +1,290 @@
328+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
329+
330+#ifndef SNMPD_SD_DAEMON_H
331+#define SNMPD_SD_DAEMON_H
332+
333+/***
334+ Copyright 2010 Lennart Poettering
335+
336+ Permission is hereby granted, free of charge, to any person
337+ obtaining a copy of this software and associated documentation files
338+ (the "Software"), to deal in the Software without restriction,
339+ including without limitation the rights to use, copy, modify, merge,
340+ publish, distribute, sublicense, and/or sell copies of the Software,
341+ and to permit persons to whom the Software is furnished to do so,
342+ subject to the following conditions:
343+
344+ The above copyright notice and this permission notice shall be
345+ included in all copies or substantial portions of the Software.
346+
347+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
348+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
349+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
350+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
351+ BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
352+ ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
353+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
354+ SOFTWARE.
355+***/
356+
357+#ifdef HAVE_SYS_TYPES_H
358+#include <sys/types.h>
359+#endif
360+#ifdef HAVE_INTTYPES_H
361+#include <inttypes.h>
362+#endif
363+
364+#ifdef __cplusplus
365+extern "C" {
366+#endif
367+
368+/*
369+ Reference implementation of a few systemd related interfaces for
370+ writing daemons. These interfaces are trivial to implement. To
371+ simplify porting we provide this reference implementation.
372+ Applications are welcome to reimplement the algorithms described
373+ here if they do not want to include these two source files.
374+
375+ The following functionality is provided:
376+
377+ - Support for logging with log levels on stderr
378+ - File descriptor passing for socket-based activation
379+ - Daemon startup and status notification
380+ - Detection of systemd boots
381+
382+ You may compile this with -DDISABLE_SYSTEMD to disable systemd
383+ support. This makes all those calls NOPs that are directly related to
384+ systemd (i.e. only sd_is_xxx() will stay useful).
385+
386+ Since this is drop-in code we don't want any of our symbols to be
387+ exported in any case. Hence we declare hidden visibility for all of
388+ them.
389+
390+ You may find an up-to-date version of these source files online:
391+
392+ http://cgit.freedesktop.org/systemd/plain/src/sd-daemon.h
393+ http://cgit.freedesktop.org/systemd/plain/src/sd-daemon.c
394+
395+ This should compile on non-Linux systems, too, but with the
396+ exception of the sd_is_xxx() calls all functions will become NOPs.
397+
398+ See sd-daemon(7) for more information.
399+*/
400+
401+#ifndef _sd_printf_attr_
402+#if __GNUC__ >= 4
403+#define _sd_printf_attr_(a,b) __attribute__ ((format (printf, a, b)))
404+#else
405+#define _sd_printf_attr_(a,b)
406+#endif
407+#endif
408+
409+/*
410+ Log levels for usage on stderr:
411+
412+ fprintf(stderr, SD_NOTICE "Hello World!\n");
413+
414+ This is similar to printk() usage in the kernel.
415+*/
416+#define SD_EMERG "<0>" /* system is unusable */
417+#define SD_ALERT "<1>" /* action must be taken immediately */
418+#define SD_CRIT "<2>" /* critical conditions */
419+#define SD_ERR "<3>" /* error conditions */
420+#define SD_WARNING "<4>" /* warning conditions */
421+#define SD_NOTICE "<5>" /* normal but significant condition */
422+#define SD_INFO "<6>" /* informational */
423+#define SD_DEBUG "<7>" /* debug-level messages */
424+
425+/* The first passed file descriptor is fd 3 */
426+#define SD_LISTEN_FDS_START 3
427+
428+/*
429+ Returns how many file descriptors have been passed, or a negative
430+ errno code on failure. Optionally, removes the $LISTEN_FDS and
431+ $LISTEN_PID file descriptors from the environment (recommended, but
432+ problematic in threaded environments). If r is the return value of
433+ this function you'll find the file descriptors passed as fds
434+ SD_LISTEN_FDS_START to SD_LISTEN_FDS_START+r-1. Returns a negative
435+ errno style error code on failure. This function call ensures that
436+ the FD_CLOEXEC flag is set for the passed file descriptors, to make
437+ sure they are not passed on to child processes. If FD_CLOEXEC shall
438+ not be set, the caller needs to unset it after this call for all file
439+ descriptors that are used.
440+
441+ See sd_listen_fds(3) for more information.
442+*/
443+int netsnmp_sd_listen_fds(int unset_environment);
444+
445+/*
446+ Helper call for identifying a passed file descriptor. Returns 1 if
447+ the file descriptor is a FIFO in the file system stored under the
448+ specified path, 0 otherwise. If path is NULL a path name check will
449+ not be done and the call only verifies if the file descriptor
450+ refers to a FIFO. Returns a negative errno style error code on
451+ failure.
452+
453+ See sd_is_fifo(3) for more information.
454+*/
455+int netsnmp_sd_is_fifo(int fd, const char *path);
456+
457+/*
458+ Helper call for identifying a passed file descriptor. Returns 1 if
459+ the file descriptor is a special character device on the file
460+ system stored under the specified path, 0 otherwise.
461+ If path is NULL a path name check will not be done and the call
462+ only verifies if the file descriptor refers to a special character.
463+ Returns a negative errno style error code on failure.
464+
465+ See sd_is_special(3) for more information.
466+*/
467+int netsnmp_sd_is_special(int fd, const char *path);
468+
469+/*
470+ Helper call for identifying a passed file descriptor. Returns 1 if
471+ the file descriptor is a socket of the specified family (AF_INET,
472+ ...) and type (SOCK_DGRAM, SOCK_STREAM, ...), 0 otherwise. If
473+ family is 0 a socket family check will not be done. If type is 0 a
474+ socket type check will not be done and the call only verifies if
475+ the file descriptor refers to a socket. If listening is > 0 it is
476+ verified that the socket is in listening mode. (i.e. listen() has
477+ been called) If listening is == 0 it is verified that the socket is
478+ not in listening mode. If listening is < 0 no listening mode check
479+ is done. Returns a negative errno style error code on failure.
480+
481+ See sd_is_socket(3) for more information.
482+*/
483+int netsnmp_sd_is_socket(int fd, int family, int type, int listening);
484+
485+/*
486+ Helper call for identifying a passed file descriptor. Returns 1 if
487+ the file descriptor is an Internet socket, of the specified family
488+ (either AF_INET or AF_INET6) and the specified type (SOCK_DGRAM,
489+ SOCK_STREAM, ...), 0 otherwise. If version is 0 a protocol version
490+ check is not done. If type is 0 a socket type check will not be
491+ done. If port is 0 a socket port check will not be done. The
492+ listening flag is used the same way as in sd_is_socket(). Returns a
493+ negative errno style error code on failure.
494+
495+ See sd_is_socket_inet(3) for more information.
496+*/
497+int netsnmp_sd_is_socket_inet(int fd, int family, int type, int listening, uint16_t port);
498+
499+/*
500+ Helper call for identifying a passed file descriptor. Returns 1 if
501+ the file descriptor is an AF_UNIX socket of the specified type
502+ (SOCK_DGRAM, SOCK_STREAM, ...) and path, 0 otherwise. If type is 0
503+ a socket type check will not be done. If path is NULL a socket path
504+ check will not be done. For normal AF_UNIX sockets set length to
505+ 0. For abstract namespace sockets set length to the length of the
506+ socket name (including the initial 0 byte), and pass the full
507+ socket path in path (including the initial 0 byte). The listening
508+ flag is used the same way as in sd_is_socket(). Returns a negative
509+ errno style error code on failure.
510+
511+ See sd_is_socket_unix(3) for more information.
512+*/
513+int netsnmp_sd_is_socket_unix(int fd, int type, int listening, const char *path, size_t length);
514+
515+/*
516+ Informs systemd about changed daemon state. This takes a number of
517+ newline separated environment-style variable assignments in a
518+ string. The following variables are known:
519+
520+ READY=1 Tells systemd that daemon startup is finished (only
521+ relevant for services of Type=notify). The passed
522+ argument is a boolean "1" or "0". Since there is
523+ little value in signaling non-readiness the only
524+ value daemons should send is "READY=1".
525+
526+ STATUS=... Passes a single-line status string back to systemd
527+ that describes the daemon state. This is free-from
528+ and can be used for various purposes: general state
529+ feedback, fsck-like programs could pass completion
530+ percentages and failing programs could pass a human
531+ readable error message. Example: "STATUS=Completed
532+ 66% of file system check..."
533+
534+ ERRNO=... If a daemon fails, the errno-style error code,
535+ formatted as string. Example: "ERRNO=2" for ENOENT.
536+
537+ BUSERROR=... If a daemon fails, the D-Bus error-style error
538+ code. Example: "BUSERROR=org.freedesktop.DBus.Error.TimedOut"
539+
540+ MAINPID=... The main pid of a daemon, in case systemd did not
541+ fork off the process itself. Example: "MAINPID=4711"
542+
543+ Daemons can choose to send additional variables. However, it is
544+ recommended to prefix variable names not listed above with X_.
545+
546+ Returns a negative errno-style error code on failure. Returns > 0
547+ if systemd could be notified, 0 if it couldn't possibly because
548+ systemd is not running.
549+
550+ Example: When a daemon finished starting up, it could issue this
551+ call to notify systemd about it:
552+
553+ sd_notify(0, "READY=1");
554+
555+ See sd_notifyf() for more complete examples.
556+
557+ See sd_notify(3) for more information.
558+*/
559+int netsnmp_sd_notify(int unset_environment, const char *state);
560+
561+/*
562+ Similar to sd_notify() but takes a format string.
563+
564+ Example 1: A daemon could send the following after initialization:
565+
566+ sd_notifyf(0, "READY=1\n"
567+ "STATUS=Processing requests...\n"
568+ "MAINPID=%lu",
569+ (unsigned long) getpid());
570+
571+ Example 2: A daemon could send the following shortly before
572+ exiting, on failure:
573+
574+ sd_notifyf(0, "STATUS=Failed to start up: %s\n"
575+ "ERRNO=%i",
576+ strerror(errno),
577+ errno);
578+
579+ See sd_notifyf(3) for more information.
580+*/
581+int netsnmp_sd_notifyf(int unset_environment, const char *format, ...) _sd_printf_attr_(2,3);
582+
583+/*
584+ Returns > 0 if the system was booted with systemd. Returns < 0 on
585+ error. Returns 0 if the system was not booted with systemd. Note
586+ that all of the functions above handle non-systemd boots just
587+ fine. You should NOT protect them with a call to this function. Also
588+ note that this function checks whether the system, not the user
589+ session is controlled by systemd. However the functions above work
590+ for both user and system services.
591+
592+ See sd_booted(3) for more information.
593+*/
594+int netsnmp_sd_booted(void);
595+
596+/**
597+ * Find an socket with given parameters. See man sd_is_socket_inet for
598+ * description of the arguments.
599+ *
600+ * Returns the file descriptor if it is found, 0 otherwise.
601+ */
602+int netsnmp_sd_find_inet_socket(int family, int type, int listening, int port);
603+
604+/**
605+ * Find an unix socket with given parameters. See man sd_is_socket_unix for
606+ * description of the arguments.
607+ *
608+ * Returns the file descriptor if it is found, 0 otherwise.
609+ */
610+int
611+netsnmp_sd_find_unix_socket(int type, int listening, const char *path);
612+
613+#ifdef __cplusplus
614+}
615+#endif
616+
617+#endif /* SNMPD_SD_DAEMON_H */
618diff --git a/snmplib/sd-daemon.c b/snmplib/sd-daemon.c
619new file mode 100644
620index 0000000..42dba29
621--- /dev/null
622+++ b/snmplib/sd-daemon.c
623@@ -0,0 +1,532 @@
624+/*
625+ * Systemd integration parts.
626+ *
627+ * Most of this file is directly copied from systemd sources.
628+ * Changes:
629+ * - all functions were renamed to have netsnmp_ prefix
630+ * - includes were changed to match Net-SNMP style.
631+ * - removed gcc export macros
632+ * - removed POSIX message queues
633+ */
634+
635+#include <net-snmp/net-snmp-config.h>
636+#include <net-snmp/net-snmp-features.h>
637+#include <net-snmp/types.h>
638+#include <net-snmp/library/snmp_debug.h>
639+
640+#ifndef NETSNMP_NO_SYSTEMD
641+
642+/***
643+ Copyright 2010 Lennart Poettering
644+
645+ Permission is hereby granted, free of charge, to any person
646+ obtaining a copy of this software and associated documentation files
647+ (the "Software"), to deal in the Software without restriction,
648+ including without limitation the rights to use, copy, modify, merge,
649+ publish, distribute, sublicense, and/or sell copies of the Software,
650+ and to permit persons to whom the Software is furnished to do so,
651+ subject to the following conditions:
652+
653+ The above copyright notice and this permission notice shall be
654+ included in all copies or substantial portions of the Software.
655+
656+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
657+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
658+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
659+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
660+ BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
661+ ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
662+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
663+ SOFTWARE.
664+***/
665+
666+#ifndef _GNU_SOURCE
667+#define _GNU_SOURCE
668+#endif
669+
670+#include <sys/types.h>
671+#include <sys/stat.h>
672+#include <sys/socket.h>
673+#include <sys/un.h>
674+#include <sys/fcntl.h>
675+#include <netinet/in.h>
676+#include <stdlib.h>
677+#include <errno.h>
678+#include <unistd.h>
679+#include <string.h>
680+#include <stdarg.h>
681+#include <stdio.h>
682+#include <stddef.h>
683+#include <limits.h>
684+
685+#include <net-snmp/library/sd-daemon.h>
686+
687+int netsnmp_sd_listen_fds(int unset_environment) {
688+
689+ int r, fd;
690+ const char *e;
691+ char *p = NULL;
692+ unsigned long l;
693+
694+ if (!(e = getenv("LISTEN_PID"))) {
695+ r = 0;
696+ goto finish;
697+ }
698+
699+ errno = 0;
700+ l = strtoul(e, &p, 10);
701+
702+ if (errno != 0) {
703+ r = -errno;
704+ goto finish;
705+ }
706+
707+ if (!p || *p || l <= 0) {
708+ r = -EINVAL;
709+ goto finish;
710+ }
711+
712+ /* Is this for us? */
713+ if (getpid() != (pid_t) l) {
714+ r = 0;
715+ goto finish;
716+ }
717+
718+ if (!(e = getenv("LISTEN_FDS"))) {
719+ r = 0;
720+ goto finish;
721+ }
722+
723+ errno = 0;
724+ l = strtoul(e, &p, 10);
725+
726+ if (errno != 0) {
727+ r = -errno;
728+ goto finish;
729+ }
730+
731+ if (!p || *p) {
732+ r = -EINVAL;
733+ goto finish;
734+ }
735+
736+ for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + (int) l; fd ++) {
737+ int flags;
738+
739+ if ((flags = fcntl(fd, F_GETFD)) < 0) {
740+ r = -errno;
741+ goto finish;
742+ }
743+
744+ if (flags & FD_CLOEXEC)
745+ continue;
746+
747+ if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) < 0) {
748+ r = -errno;
749+ goto finish;
750+ }
751+ }
752+
753+ r = (int) l;
754+
755+finish:
756+ if (unset_environment) {
757+ unsetenv("LISTEN_PID");
758+ unsetenv("LISTEN_FDS");
759+ }
760+
761+ return r;
762+}
763+
764+int netsnmp_sd_is_fifo(int fd, const char *path) {
765+ struct stat st_fd;
766+
767+ if (fd < 0)
768+ return -EINVAL;
769+
770+ memset(&st_fd, 0, sizeof(st_fd));
771+ if (fstat(fd, &st_fd) < 0)
772+ return -errno;
773+
774+ if (!S_ISFIFO(st_fd.st_mode))
775+ return 0;
776+
777+ if (path) {
778+ struct stat st_path;
779+
780+ memset(&st_path, 0, sizeof(st_path));
781+ if (stat(path, &st_path) < 0) {
782+
783+ if (errno == ENOENT || errno == ENOTDIR)
784+ return 0;
785+
786+ return -errno;
787+ }
788+
789+ return
790+ st_path.st_dev == st_fd.st_dev &&
791+ st_path.st_ino == st_fd.st_ino;
792+ }
793+
794+ return 1;
795+}
796+
797+int netsnmp_sd_is_special(int fd, const char *path) {
798+ struct stat st_fd;
799+
800+ if (fd < 0)
801+ return -EINVAL;
802+
803+ if (fstat(fd, &st_fd) < 0)
804+ return -errno;
805+
806+ if (!S_ISREG(st_fd.st_mode) && !S_ISCHR(st_fd.st_mode))
807+ return 0;
808+
809+ if (path) {
810+ struct stat st_path;
811+
812+ if (stat(path, &st_path) < 0) {
813+
814+ if (errno == ENOENT || errno == ENOTDIR)
815+ return 0;
816+
817+ return -errno;
818+ }
819+
820+ if (S_ISREG(st_fd.st_mode) && S_ISREG(st_path.st_mode))
821+ return
822+ st_path.st_dev == st_fd.st_dev &&
823+ st_path.st_ino == st_fd.st_ino;
824+ else if (S_ISCHR(st_fd.st_mode) && S_ISCHR(st_path.st_mode))
825+ return st_path.st_rdev == st_fd.st_rdev;
826+ else
827+ return 0;
828+ }
829+
830+ return 1;
831+}
832+
833+static int sd_is_socket_internal(int fd, int type, int listening) {
834+ struct stat st_fd;
835+
836+ if (fd < 0 || type < 0)
837+ return -EINVAL;
838+
839+ if (fstat(fd, &st_fd) < 0)
840+ return -errno;
841+
842+ if (!S_ISSOCK(st_fd.st_mode))
843+ return 0;
844+
845+ if (type != 0) {
846+ int other_type = 0;
847+ socklen_t l = sizeof(other_type);
848+
849+ if (getsockopt(fd, SOL_SOCKET, SO_TYPE, &other_type, &l) < 0)
850+ return -errno;
851+
852+ if (l != sizeof(other_type))
853+ return -EINVAL;
854+
855+ if (other_type != type)
856+ return 0;
857+ }
858+
859+ if (listening >= 0) {
860+ int accepting = 0;
861+ socklen_t l = sizeof(accepting);
862+
863+ if (getsockopt(fd, SOL_SOCKET, SO_ACCEPTCONN, &accepting, &l) < 0)
864+ return -errno;
865+
866+ if (l != sizeof(accepting))
867+ return -EINVAL;
868+
869+ if (!accepting != !listening)
870+ return 0;
871+ }
872+
873+ return 1;
874+}
875+
876+union sockaddr_union {
877+ struct sockaddr sa;
878+ struct sockaddr_in in4;
879+ struct sockaddr_in6 in6;
880+ struct sockaddr_un un;
881+ struct sockaddr_storage storage;
882+};
883+
884+int netsnmp_sd_is_socket(int fd, int family, int type, int listening) {
885+ int r;
886+
887+ if (family < 0)
888+ return -EINVAL;
889+
890+ if ((r = sd_is_socket_internal(fd, type, listening)) <= 0)
891+ return r;
892+
893+ if (family > 0) {
894+ union sockaddr_union sockaddr;
895+ socklen_t l;
896+
897+ memset(&sockaddr, 0, sizeof(sockaddr));
898+ l = sizeof(sockaddr);
899+
900+ if (getsockname(fd, &sockaddr.sa, &l) < 0)
901+ return -errno;
902+
903+ if (l < sizeof(sa_family_t))
904+ return -EINVAL;
905+
906+ return sockaddr.sa.sa_family == family;
907+ }
908+
909+ return 1;
910+}
911+
912+int netsnmp_sd_is_socket_inet(int fd, int family, int type, int listening, uint16_t port) {
913+ union sockaddr_union sockaddr;
914+ socklen_t l;
915+ int r;
916+
917+ if (family != 0 && family != AF_INET && family != AF_INET6)
918+ return -EINVAL;
919+
920+ if ((r = sd_is_socket_internal(fd, type, listening)) <= 0)
921+ return r;
922+
923+ memset(&sockaddr, 0, sizeof(sockaddr));
924+ l = sizeof(sockaddr);
925+
926+ if (getsockname(fd, &sockaddr.sa, &l) < 0)
927+ return -errno;
928+
929+ if (l < sizeof(sa_family_t))
930+ return -EINVAL;
931+
932+ if (sockaddr.sa.sa_family != AF_INET &&
933+ sockaddr.sa.sa_family != AF_INET6)
934+ return 0;
935+
936+ if (family > 0)
937+ if (sockaddr.sa.sa_family != family)
938+ return 0;
939+
940+ if (port > 0) {
941+ if (sockaddr.sa.sa_family == AF_INET) {
942+ if (l < sizeof(struct sockaddr_in))
943+ return -EINVAL;
944+
945+ return htons(port) == sockaddr.in4.sin_port;
946+ } else {
947+ if (l < sizeof(struct sockaddr_in6))
948+ return -EINVAL;
949+
950+ return htons(port) == sockaddr.in6.sin6_port;
951+ }
952+ }
953+
954+ return 1;
955+}
956+
957+int netsnmp_sd_is_socket_unix(int fd, int type, int listening, const char *path, size_t length) {
958+ union sockaddr_union sockaddr;
959+ socklen_t l;
960+ int r;
961+
962+ if ((r = sd_is_socket_internal(fd, type, listening)) <= 0)
963+ return r;
964+
965+ memset(&sockaddr, 0, sizeof(sockaddr));
966+ l = sizeof(sockaddr);
967+
968+ if (getsockname(fd, &sockaddr.sa, &l) < 0)
969+ return -errno;
970+
971+ if (l < sizeof(sa_family_t))
972+ return -EINVAL;
973+
974+ if (sockaddr.sa.sa_family != AF_UNIX)
975+ return 0;
976+
977+ if (path) {
978+ if (length <= 0)
979+ length = strlen(path);
980+
981+ if (length <= 0)
982+ /* Unnamed socket */
983+ return l == offsetof(struct sockaddr_un, sun_path);
984+
985+ if (path[0])
986+ /* Normal path socket */
987+ return
988+ (l >= offsetof(struct sockaddr_un, sun_path) + length + 1) &&
989+ memcmp(path, sockaddr.un.sun_path, length+1) == 0;
990+ else
991+ /* Abstract namespace socket */
992+ return
993+ (l == offsetof(struct sockaddr_un, sun_path) + length) &&
994+ memcmp(path, sockaddr.un.sun_path, length) == 0;
995+ }
996+
997+ return 1;
998+}
999+
1000+int netsnmp_sd_notify(int unset_environment, const char *state) {
1001+ int fd = -1, r;
1002+ struct msghdr msghdr;
1003+ struct iovec iovec;
1004+ union sockaddr_union sockaddr;
1005+ const char *e;
1006+
1007+ if (!state) {
1008+ r = -EINVAL;
1009+ goto finish;
1010+ }
1011+
1012+ if (!(e = getenv("NOTIFY_SOCKET")))
1013+ return 0;
1014+
1015+ /* Must be an abstract socket, or an absolute path */
1016+ if ((e[0] != '@' && e[0] != '/') || e[1] == 0) {
1017+ r = -EINVAL;
1018+ goto finish;
1019+ }
1020+
1021+ if ((fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0)) < 0) {
1022+ r = -errno;
1023+ goto finish;
1024+ }
1025+
1026+ memset(&sockaddr, 0, sizeof(sockaddr));
1027+ sockaddr.sa.sa_family = AF_UNIX;
1028+ strncpy(sockaddr.un.sun_path, e, sizeof(sockaddr.un.sun_path));
1029+
1030+ if (sockaddr.un.sun_path[0] == '@')
1031+ sockaddr.un.sun_path[0] = 0;
1032+
1033+ memset(&iovec, 0, sizeof(iovec));
1034+ iovec.iov_base = (char *)state;
1035+ iovec.iov_len = strlen(state);
1036+
1037+ memset(&msghdr, 0, sizeof(msghdr));
1038+ msghdr.msg_name = &sockaddr;
1039+ msghdr.msg_namelen = offsetof(struct sockaddr_un, sun_path) + strlen(e);
1040+
1041+ if (msghdr.msg_namelen > sizeof(struct sockaddr_un))
1042+ msghdr.msg_namelen = sizeof(struct sockaddr_un);
1043+
1044+ msghdr.msg_iov = &iovec;
1045+ msghdr.msg_iovlen = 1;
1046+
1047+ if (sendmsg(fd, &msghdr, MSG_NOSIGNAL) < 0) {
1048+ r = -errno;
1049+ goto finish;
1050+ }
1051+
1052+ r = 1;
1053+
1054+finish:
1055+ if (unset_environment)
1056+ unsetenv("NOTIFY_SOCKET");
1057+
1058+ if (fd >= 0)
1059+ close(fd);
1060+
1061+ return r;
1062+}
1063+
1064+int netsnmp_sd_notifyf(int unset_environment, const char *format, ...) {
1065+ va_list ap;
1066+ char *p = NULL;
1067+ int r;
1068+
1069+ va_start(ap, format);
1070+ r = vasprintf(&p, format, ap);
1071+ va_end(ap);
1072+
1073+ if (r < 0 || !p)
1074+ return -ENOMEM;
1075+
1076+ r = netsnmp_sd_notify(unset_environment, p);
1077+ free(p);
1078+
1079+ return r;
1080+}
1081+
1082+int netsnmp_sd_booted(void) {
1083+ struct stat a, b;
1084+
1085+ /* We simply test whether the systemd cgroup hierarchy is
1086+ * mounted */
1087+
1088+ if (lstat("/sys/fs/cgroup", &a) < 0)
1089+ return 0;
1090+
1091+ if (lstat("/sys/fs/cgroup/systemd", &b) < 0)
1092+ return 0;
1093+
1094+ return a.st_dev != b.st_dev;
1095+}
1096+
1097+/* End of original sd-daemon.c from systemd sources */
1098+
1099+int
1100+netsnmp_sd_find_inet_socket(int family, int type, int listening, int port)
1101+{
1102+ int count, fd;
1103+
1104+ count = netsnmp_sd_listen_fds(0);
1105+ if (count <= 0) {
1106+ DEBUGMSGTL(("systemd:find_inet_socket", "No LISTEN_FDS found.\n"));
1107+ return 0;
1108+ }
1109+ DEBUGMSGTL(("systemd:find_inet_socket", "LISTEN_FDS reports %d sockets.\n",
1110+ count));
1111+
1112+ for (fd = 3; fd < 3+count; fd++) {
1113+ int rc = netsnmp_sd_is_socket_inet(fd, family, type, listening, port);
1114+ if (rc < 0)
1115+ DEBUGMSGTL(("systemd:find_inet_socket",
1116+ "sd_is_socket_inet error: %d\n", rc));
1117+ if (rc > 0) {
1118+ DEBUGMSGTL(("systemd:find_inet_socket",
1119+ "Found the socket in LISTEN_FDS\n"));
1120+ return fd;
1121+ }
1122+ }
1123+ DEBUGMSGTL(("systemd:find_inet_socket", "Socket not found in LISTEN_FDS\n"));
1124+ return 0;
1125+}
1126+
1127+int
1128+netsnmp_sd_find_unix_socket(int type, int listening, const char *path)
1129+{
1130+ int count, fd;
1131+
1132+ count = netsnmp_sd_listen_fds(0);
1133+ if (count <= 0) {
1134+ DEBUGMSGTL(("systemd:find_unix_socket", "No LISTEN_FDS found.\n"));
1135+ return 0;
1136+ }
1137+ DEBUGMSGTL(("systemd:find_unix_socket", "LISTEN_FDS reports %d sockets.\n",
1138+ count));
1139+
1140+ for (fd = 3; fd < 3+count; fd++) {
1141+ int rc = netsnmp_sd_is_socket_unix(fd, type, listening, path, 0);
1142+ if (rc < 0)
1143+ DEBUGMSGTL(("systemd:find_unix_socket",
1144+ "netsnmp_sd_is_socket_unix error: %d\n", rc));
1145+ if (rc > 0) {
1146+ DEBUGMSGTL(("systemd:find_unix_socket",
1147+ "Found the socket in LISTEN_FDS\n"));
1148+ return fd;
1149+ }
1150+ }
1151+ DEBUGMSGTL(("systemd:find_unix_socket", "Socket not found in LISTEN_FDS\n"));
1152+ return 0;
1153+}
1154+
1155+#endif /* ! NETSNMP_NO_SYSTEMD */
1156diff --git a/snmplib/transports/snmpTCPDomain.c b/snmplib/transports/snmpTCPDomain.c
1157index b8bdba4..ab7f3a1 100644
1158--- a/snmplib/transports/snmpTCPDomain.c
1159+++ b/snmplib/transports/snmpTCPDomain.c
1160@@ -43,6 +43,10 @@
1161 #include <net-snmp/library/snmpTCPBaseDomain.h>
1162 #include <net-snmp/library/tools.h>
1163
1164+#ifndef NETSNMP_NO_SYSTEMD
1165+#include <net-snmp/library/sd-daemon.h>
1166+#endif
1167+
1168 /*
1169 * needs to be in sync with the definitions in snmplib/snmpUDPDomain.c
1170 * and perl/agent/agent.xs
1171@@ -149,6 +153,7 @@ netsnmp_tcp_transport(struct sockaddr_in *addr, int local)
1172 netsnmp_transport *t = NULL;
1173 netsnmp_udp_addr_pair *addr_pair = NULL;
1174 int rc = 0;
1175+ int socket_initialized = 0;
1176
1177 #ifdef NETSNMP_NO_LISTEN_SUPPORT
1178 if (local)
1179@@ -178,7 +183,19 @@ netsnmp_tcp_transport(struct sockaddr_in *addr, int local)
1180 t->domain_length =
1181 sizeof(netsnmp_snmpTCPDomain) / sizeof(netsnmp_snmpTCPDomain[0]);
1182
1183- t->sock = socket(PF_INET, SOCK_STREAM, 0);
1184+#ifndef NETSNMP_NO_SYSTEMD
1185+ /*
1186+ * Maybe the socket was already provided by systemd...
1187+ */
1188+ if (local) {
1189+ t->sock = netsnmp_sd_find_inet_socket(PF_INET, SOCK_STREAM, 1,
1190+ ntohs(addr->sin_port));
1191+ if (t->sock)
1192+ socket_initialized = 1;
1193+ }
1194+#endif
1195+ if (!socket_initialized)
1196+ t->sock = socket(PF_INET, SOCK_STREAM, 0);
1197 if (t->sock < 0) {
1198 netsnmp_transport_free(t);
1199 return NULL;
1200@@ -215,11 +232,13 @@ netsnmp_tcp_transport(struct sockaddr_in *addr, int local)
1201 setsockopt(t->sock, SOL_SOCKET, SO_REUSEADDR, (void *)&opt,
1202 sizeof(opt));
1203
1204- rc = bind(t->sock, (struct sockaddr *)addr, sizeof(struct sockaddr));
1205- if (rc != 0) {
1206- netsnmp_socketbase_close(t);
1207- netsnmp_transport_free(t);
1208- return NULL;
1209+ if (!socket_initialized) {
1210+ rc = bind(t->sock, (struct sockaddr *)addr, sizeof(struct sockaddr));
1211+ if (rc != 0) {
1212+ netsnmp_socketbase_close(t);
1213+ netsnmp_transport_free(t);
1214+ return NULL;
1215+ }
1216 }
1217
1218 /*
1219@@ -235,12 +254,13 @@ netsnmp_tcp_transport(struct sockaddr_in *addr, int local)
1220 /*
1221 * Now sit here and wait for connections to arrive.
1222 */
1223-
1224- rc = listen(t->sock, NETSNMP_STREAM_QUEUE_LEN);
1225- if (rc != 0) {
1226- netsnmp_socketbase_close(t);
1227- netsnmp_transport_free(t);
1228- return NULL;
1229+ if (!socket_initialized) {
1230+ rc = listen(t->sock, NETSNMP_STREAM_QUEUE_LEN);
1231+ if (rc != 0) {
1232+ netsnmp_socketbase_close(t);
1233+ netsnmp_transport_free(t);
1234+ return NULL;
1235+ }
1236 }
1237
1238 /*
1239diff --git a/snmplib/transports/snmpTCPIPv6Domain.c b/snmplib/transports/snmpTCPIPv6Domain.c
1240index 3c96856..305a861 100644
1241--- a/snmplib/transports/snmpTCPIPv6Domain.c
1242+++ b/snmplib/transports/snmpTCPIPv6Domain.c
1243@@ -49,6 +49,10 @@
1244 #include <net-snmp/library/snmpTCPBaseDomain.h>
1245 #include <net-snmp/library/tools.h>
1246
1247+#ifndef NETSNMP_NO_SYSTEMD
1248+#include <net-snmp/library/sd-daemon.h>
1249+#endif
1250+
1251 #include "inet_ntop.h"
1252
1253 oid netsnmp_TCPIPv6Domain[] = { TRANSPORT_DOMAIN_TCP_IPV6 };
1254@@ -140,6 +144,8 @@ netsnmp_tcp6_transport(struct sockaddr_in6 *addr, int local)
1255 {
1256 netsnmp_transport *t = NULL;
1257 int rc = 0;
1258+ char *str = NULL;
1259+ int socket_initialized = 0;
1260
1261 #ifdef NETSNMP_NO_LISTEN_SUPPORT
1262 if (local)
1263@@ -174,7 +180,19 @@ netsnmp_tcp6_transport(struct sockaddr_in6 *addr, int local)
1264 t->domain = netsnmp_TCPIPv6Domain;
1265 t->domain_length = sizeof(netsnmp_TCPIPv6Domain) / sizeof(oid);
1266
1267- t->sock = socket(PF_INET6, SOCK_STREAM, 0);
1268+#ifndef NETSNMP_NO_SYSTEMD
1269+ /*
1270+ * Maybe the socket was already provided by systemd...
1271+ */
1272+ if (local) {
1273+ t->sock = netsnmp_sd_find_inet_socket(PF_INET6, SOCK_STREAM, 1,
1274+ ntohs(addr->sin6_port));
1275+ if (t->sock)
1276+ socket_initialized = 1;
1277+ }
1278+#endif
1279+ if (!socket_initialized)
1280+ t->sock = socket(PF_INET6, SOCK_STREAM, 0);
1281 if (t->sock < 0) {
1282 netsnmp_transport_free(t);
1283 return NULL;
1284@@ -220,12 +238,14 @@ netsnmp_tcp6_transport(struct sockaddr_in6 *addr, int local)
1285
1286 setsockopt(t->sock, SOL_SOCKET, SO_REUSEADDR, (void *)&opt, sizeof(opt));
1287
1288- rc = bind(t->sock, (struct sockaddr *) addr,
1289- sizeof(struct sockaddr_in6));
1290- if (rc != 0) {
1291- netsnmp_socketbase_close(t);
1292- netsnmp_transport_free(t);
1293- return NULL;
1294+ if (!socket_initialized) {
1295+ rc = bind(t->sock, (struct sockaddr *) addr,
1296+ sizeof(struct sockaddr_in6));
1297+ if (rc != 0) {
1298+ netsnmp_socketbase_close(t);
1299+ netsnmp_transport_free(t);
1300+ return NULL;
1301+ }
1302 }
1303
1304 /*
1305@@ -242,11 +262,13 @@ netsnmp_tcp6_transport(struct sockaddr_in6 *addr, int local)
1306 * Now sit here and wait for connections to arrive.
1307 */
1308
1309- rc = listen(t->sock, NETSNMP_STREAM_QUEUE_LEN);
1310- if (rc != 0) {
1311- netsnmp_socketbase_close(t);
1312- netsnmp_transport_free(t);
1313- return NULL;
1314+ if (!socket_initialized) {
1315+ rc = listen(t->sock, NETSNMP_STREAM_QUEUE_LEN);
1316+ if (rc != 0) {
1317+ netsnmp_socketbase_close(t);
1318+ netsnmp_transport_free(t);
1319+ return NULL;
1320+ }
1321 }
1322
1323 /*
1324diff --git a/snmplib/transports/snmpUDPIPv4BaseDomain.c b/snmplib/transports/snmpUDPIPv4BaseDomain.c
1325index c67427b..428e6d6 100644
1326--- a/snmplib/transports/snmpUDPIPv4BaseDomain.c
1327+++ b/snmplib/transports/snmpUDPIPv4BaseDomain.c
1328@@ -40,6 +40,10 @@
1329
1330 #include <net-snmp/library/snmpSocketBaseDomain.h>
1331
1332+#ifndef NETSNMP_NO_SYSTEMD
1333+#include <net-snmp/library/sd-daemon.h>
1334+#endif
1335+
1336 #if (defined(linux) && defined(IP_PKTINFO)) \
1337 || defined(IP_RECVDSTADDR) && HAVE_STRUCT_MSGHDR_MSG_CONTROL \
1338 && HAVE_STRUCT_MSGHDR_MSG_FLAGS
1339@@ -67,6 +71,7 @@ netsnmp_udpipv4base_transport(struct sockaddr_in *addr, int local)
1340 char *client_socket = NULL;
1341 netsnmp_indexed_addr_pair addr_pair;
1342 socklen_t local_addr_len;
1343+ int socket_initialized = 0;
1344
1345 #ifdef NETSNMP_NO_LISTEN_SUPPORT
1346 if (local)
1347@@ -91,7 +96,19 @@ netsnmp_udpipv4base_transport(struct sockaddr_in *addr, int local)
1348 free(str);
1349 }
1350
1351- t->sock = socket(PF_INET, SOCK_DGRAM, 0);
1352+#ifndef NETSNMP_NO_SYSTEMD
1353+ /*
1354+ * Maybe the socket was already provided by systemd...
1355+ */
1356+ if (local) {
1357+ t->sock = netsnmp_sd_find_inet_socket(PF_INET, SOCK_DGRAM, -1,
1358+ ntohs(addr->sin_port));
1359+ if (t->sock)
1360+ socket_initialized = 1;
1361+ }
1362+#endif
1363+ if (!socket_initialized)
1364+ t->sock = socket(PF_INET, SOCK_DGRAM, 0);
1365 DEBUGMSGTL(("UDPBase", "openned socket %d as local=%d\n", t->sock, local));
1366 if (t->sock < 0) {
1367 netsnmp_transport_free(t);
1368@@ -141,12 +158,14 @@ netsnmp_udpipv4base_transport(struct sockaddr_in *addr, int local)
1369 DEBUGMSGTL(("netsnmp_udp", "set IP_RECVDSTADDR\n"));
1370 }
1371 #endif
1372- rc = bind(t->sock, (struct sockaddr *) addr,
1373- sizeof(struct sockaddr));
1374- if (rc != 0) {
1375- netsnmp_socketbase_close(t);
1376- netsnmp_transport_free(t);
1377- return NULL;
1378+ if (!socket_initialized) {
1379+ rc = bind(t->sock, (struct sockaddr *) addr,
1380+ sizeof(struct sockaddr));
1381+ if (rc != 0) {
1382+ netsnmp_socketbase_close(t);
1383+ netsnmp_transport_free(t);
1384+ return NULL;
1385+ }
1386 }
1387 t->data = NULL;
1388 t->data_length = 0;
1389diff --git a/snmplib/transports/snmpUDPIPv6Domain.c b/snmplib/transports/snmpUDPIPv6Domain.c
1390index b3eaae4..35b617f 100644
1391--- a/snmplib/transports/snmpUDPIPv6Domain.c
1392+++ b/snmplib/transports/snmpUDPIPv6Domain.c
1393@@ -67,6 +67,10 @@ static const struct in6_addr in6addr_any = IN6ADDR_ANY_INIT;
1394 #include <net-snmp/library/snmpSocketBaseDomain.h>
1395 #include <net-snmp/library/tools.h>
1396
1397+#ifndef NETSNMP_NO_SYSTEMD
1398+#include <net-snmp/library/sd-daemon.h>
1399+#endif
1400+
1401 #include "inet_ntop.h"
1402 #include "inet_pton.h"
1403
1404@@ -190,6 +194,8 @@ netsnmp_udp6_transport(struct sockaddr_in6 *addr, int local)
1405 {
1406 netsnmp_transport *t = NULL;
1407 int rc = 0;
1408+ char *str = NULL;
1409+ int socket_initialized = 0;
1410
1411 #ifdef NETSNMP_NO_LISTEN_SUPPORT
1412 if (local)
1413@@ -217,7 +223,19 @@ netsnmp_udp6_transport(struct sockaddr_in6 *addr, int local)
1414 t->domain_length =
1415 sizeof(netsnmp_UDPIPv6Domain) / sizeof(netsnmp_UDPIPv6Domain[0]);
1416
1417- t->sock = socket(PF_INET6, SOCK_DGRAM, 0);
1418+#ifndef NETSNMP_NO_SYSTEMD
1419+ /*
1420+ * Maybe the socket was already provided by systemd...
1421+ */
1422+ if (local) {
1423+ t->sock = netsnmp_sd_find_inet_socket(PF_INET6, SOCK_DGRAM, -1,
1424+ ntohs(addr->sin6_port));
1425+ if (t->sock)
1426+ socket_initialized = 1;
1427+ }
1428+#endif
1429+ if (!socket_initialized)
1430+ t->sock = socket(PF_INET6, SOCK_DGRAM, 0);
1431 if (t->sock < 0) {
1432 netsnmp_transport_free(t);
1433 return NULL;
1434@@ -242,13 +260,14 @@ netsnmp_udp6_transport(struct sockaddr_in6 *addr, int local)
1435 }
1436 }
1437 #endif
1438-
1439- rc = bind(t->sock, (struct sockaddr *) addr,
1440- sizeof(struct sockaddr_in6));
1441- if (rc != 0) {
1442- netsnmp_socketbase_close(t);
1443- netsnmp_transport_free(t);
1444- return NULL;
1445+ if (!socket_initialized) {
1446+ rc = bind(t->sock, (struct sockaddr *) addr,
1447+ sizeof(struct sockaddr_in6));
1448+ if (rc != 0) {
1449+ netsnmp_socketbase_close(t);
1450+ netsnmp_transport_free(t);
1451+ return NULL;
1452+ }
1453 }
1454 t->local = (unsigned char*)malloc(18);
1455 if (t->local == NULL) {
1456diff --git a/snmplib/transports/snmpUnixDomain.c b/snmplib/transports/snmpUnixDomain.c
1457index 674dc2b..9f3d3cb 100644
1458--- a/snmplib/transports/snmpUnixDomain.c
1459+++ b/snmplib/transports/snmpUnixDomain.c
1460@@ -37,6 +37,10 @@
1461 #include <net-snmp/library/system.h> /* mkdirhier */
1462 #include <net-snmp/library/tools.h>
1463
1464+#ifndef NETSNMP_NO_SYSTEMD
1465+#include <net-snmp/library/sd-daemon.h>
1466+#endif
1467+
1468 netsnmp_feature_child_of(transport_unix_socket_all, transport_all)
1469 netsnmp_feature_child_of(unix_socket_paths, transport_unix_socket_all)
1470
1471@@ -295,6 +299,8 @@ netsnmp_unix_transport(struct sockaddr_un *addr, int local)
1472 netsnmp_transport *t = NULL;
1473 sockaddr_un_pair *sup = NULL;
1474 int rc = 0;
1475+ char *string = NULL;
1476+ int socket_initialized = 0;
1477
1478 #ifdef NETSNMP_NO_LISTEN_SUPPORT
1479 /* SPECIAL CIRCUMSTANCE: We still want AgentX to be able to operate,
1480@@ -333,7 +339,18 @@ netsnmp_unix_transport(struct sockaddr_un *addr, int local)
1481 t->data_length = sizeof(sockaddr_un_pair);
1482 sup = (sockaddr_un_pair *) t->data;
1483
1484- t->sock = socket(PF_UNIX, SOCK_STREAM, 0);
1485+#ifndef NETSNMP_NO_SYSTEMD
1486+ /*
1487+ * Maybe the socket was already provided by systemd...
1488+ */
1489+ if (local) {
1490+ t->sock = netsnmp_sd_find_unix_socket(SOCK_STREAM, 1, addr->sun_path);
1491+ if (t->sock)
1492+ socket_initialized = 1;
1493+ }
1494+#endif
1495+ if (!socket_initialized)
1496+ t->sock = socket(PF_UNIX, SOCK_STREAM, 0);
1497 if (t->sock < 0) {
1498 netsnmp_transport_free(t);
1499 return NULL;
1500@@ -357,25 +374,26 @@ netsnmp_unix_transport(struct sockaddr_un *addr, int local)
1501
1502 t->flags |= NETSNMP_TRANSPORT_FLAG_LISTEN;
1503
1504- unlink(addr->sun_path);
1505- rc = bind(t->sock, (struct sockaddr *) addr, SUN_LEN(addr));
1506-
1507- if (rc != 0 && errno == ENOENT && create_path) {
1508- rc = mkdirhier(addr->sun_path, create_mode, 1);
1509+ if (!socket_initialized) {
1510+ unlink(addr->sun_path);
1511+ rc = bind(t->sock, (struct sockaddr *) addr, SUN_LEN(addr));
1512+ if (rc != 0 && errno == ENOENT && create_path) {
1513+ rc = mkdirhier(addr->sun_path, create_mode, 1);
1514+ if (rc != 0) {
1515+ netsnmp_unix_close(t);
1516+ netsnmp_transport_free(t);
1517+ return NULL;
1518+ }
1519+ rc = bind(t->sock, (struct sockaddr *) addr, SUN_LEN(addr));
1520+ }
1521 if (rc != 0) {
1522+ DEBUGMSGTL(("netsnmp_unix_transport",
1523+ "couldn't bind \"%s\", errno %d (%s)\n",
1524+ addr->sun_path, errno, strerror(errno)));
1525 netsnmp_unix_close(t);
1526 netsnmp_transport_free(t);
1527 return NULL;
1528 }
1529- rc = bind(t->sock, (struct sockaddr *) addr, SUN_LEN(addr));
1530- }
1531- if (rc != 0) {
1532- DEBUGMSGTL(("netsnmp_unix_transport",
1533- "couldn't bind \"%s\", errno %d (%s)\n",
1534- addr->sun_path, errno, strerror(errno)));
1535- netsnmp_unix_close(t);
1536- netsnmp_transport_free(t);
1537- return NULL;
1538 }
1539
1540 /*
1541@@ -391,16 +409,17 @@ netsnmp_unix_transport(struct sockaddr_un *addr, int local)
1542 * Now sit here and listen for connections to arrive.
1543 */
1544
1545- rc = listen(t->sock, NETSNMP_STREAM_QUEUE_LEN);
1546- if (rc != 0) {
1547- DEBUGMSGTL(("netsnmp_unix_transport",
1548- "couldn't listen to \"%s\", errno %d (%s)\n",
1549- addr->sun_path, errno, strerror(errno)));
1550- netsnmp_unix_close(t);
1551- netsnmp_transport_free(t);
1552- return NULL;
1553+ if (!socket_initialized) {
1554+ rc = listen(t->sock, NETSNMP_STREAM_QUEUE_LEN);
1555+ if (rc != 0) {
1556+ DEBUGMSGTL(("netsnmp_unix_transport",
1557+ "couldn't listen to \"%s\", errno %d (%s)\n",
1558+ addr->sun_path, errno, strerror(errno)));
1559+ netsnmp_unix_close(t);
1560+ netsnmp_transport_free(t);
1561+ return NULL;
1562+ }
1563 }
1564-
1565 } else {
1566 t->remote = (u_char *)malloc(strlen(addr->sun_path));
1567 if (t->remote == NULL) {
1568diff --git a/win32/libsnmp/Makefile.in b/win32/libsnmp/Makefile.in
1569index 98d83c8..dd5689b 100644
1570--- a/win32/libsnmp/Makefile.in
1571+++ b/win32/libsnmp/Makefile.in
1572@@ -42,6 +42,7 @@ LIB32_OBJS= \
1573 "$(INTDIR)\read_config.obj" \
1574 "$(INTDIR)\readdir.obj" \
1575 "$(INTDIR)\scapi.obj" \
1576+ "$(INTDIR)\sd-daemon.obj" \
1577 "$(INTDIR)\snmp-tc.obj" \
1578 "$(INTDIR)\snmp.obj" \
1579 "$(INTDIR)\snmpCallbackDomain.obj" \
1580@@ -307,6 +308,12 @@ SOURCE=..\..\snmplib\scapi.c
1581 $(CPP) $(CPP_PROJ) $(SOURCE)
1582
1583
1584+SOURCE=..\..\snmplib\sd-daemon.c
1585+
1586+"$(INTDIR)\sd-daemon.obj" : $(SOURCE) "$(INTDIR)"
1587+ $(CPP) $(CPP_PROJ) $(SOURCE)
1588+
1589+
1590 SOURCE="..\..\snmplib\snmp-tc.c"
1591
1592 "$(INTDIR)\snmp-tc.obj" : $(SOURCE) "$(INTDIR)"
1593diff --git a/win32/net-snmp/net-snmp-config.h b/win32/net-snmp/net-snmp-config.h
1594index 7791ee0..1eccf42 100644
1595--- a/win32/net-snmp/net-snmp-config.h
1596+++ b/win32/net-snmp/net-snmp-config.h
1597@@ -1705,6 +1705,8 @@ enum {
1598 #define DMALLOC_FUNC_CHECK
1599 #endif
1600
1601+#define NETSNMP_NO_SYSTEMD
1602+
1603 /* #undef NETSNMP_ENABLE_LOCAL_SMUX */
1604
1605 /* define if agentx transport is to use domain sockets only */
1606diff --git a/win32/net-snmp/net-snmp-config.h.in b/win32/net-snmp/net-snmp-config.h.in
1607index 5215865..1607bfa 100644
1608--- a/win32/net-snmp/net-snmp-config.h.in
1609+++ b/win32/net-snmp/net-snmp-config.h.in
1610@@ -1705,6 +1705,8 @@ enum {
1611 #define DMALLOC_FUNC_CHECK
1612 #endif
1613
1614+#define NETSNMP_NO_SYSTEMD
1615+
1616 /* #undef NETSNMP_ENABLE_LOCAL_SMUX */
1617
1618 /* define if agentx transport is to use domain sockets only */
diff --git a/meta-networking/recipes-protocols/net-snmp/net-snmp_5.7.2.bb b/meta-networking/recipes-protocols/net-snmp/net-snmp_5.7.2.bb
new file mode 100644
index 0000000000..d21995a9e1
--- /dev/null
+++ b/meta-networking/recipes-protocols/net-snmp/net-snmp_5.7.2.bb
@@ -0,0 +1,120 @@
1SUMMARY = "Various tools relating to the Simple Network Management Protocol"
2HOMEPAGE = "http://www.net-snmp.org/"
3LICENSE = "BSD"
4
5LIC_FILES_CHKSUM = "file://README;beginline=3;endline=8;md5=7f7f00ba639ac8e8deb5a622ea24634e"
6
7DEPENDS = "openssl libnl pciutils"
8
9PR = "r1"
10
11SRC_URI = "${SOURCEFORGE_MIRROR}/net-snmp/net-snmp-${PV}.tar.gz \
12 file://init \
13 file://snmpd.conf \
14 file://snmptrapd.conf \
15 file://systemd-support.patch \
16 file://snmpd.service \
17 file://snmptrapd.service \
18 file://ifmib.patch \
19"
20
21SRC_URI[md5sum] = "5bddd02e2f82b62daa79f82717737a14"
22SRC_URI[sha256sum] = "09ed31b4cc1f3c0411ef9a16eff79ef3b30d89c32ca46d5a01a41826c4ceb816"
23
24inherit autotools update-rc.d siteinfo systemd
25
26EXTRA_OEMAKE = "INSTALL_PREFIX=${D}"
27
28PARALLEL_MAKE = ""
29CCACHE = ""
30
31TARGET_CC_ARCH += "${LDFLAGS}"
32
33EXTRA_OECONF = "--disable-embedded-perl \
34 --with-perl-modules=no \
35 --enable-shared \
36 --disable-manuals \
37 --with-defaults \
38 ${@base_conditional('SITEINFO_ENDIANNESS', 'le', '--with-endianness=little', '--with-endianness=big', d)}"
39
40do_install_append() {
41 install -d ${D}${sysconfdir}/snmp
42 install -d ${D}${sysconfdir}/init.d
43 install -m 755 ${WORKDIR}/init ${D}${sysconfdir}/init.d/snmpd
44 install -m 644 ${WORKDIR}/snmpd.conf ${D}${sysconfdir}/snmp/
45 install -m 644 ${WORKDIR}/snmptrapd.conf ${D}${sysconfdir}/snmp/
46 install -d ${STAGING_BINDIR}
47 install -m 0755 ${D}${bindir}/net-snmp-config ${STAGING_BINDIR}/
48 sed -e "s@-I/usr/include@@g" \
49 -e "s@^prefix=.*@prefix=${STAGING_DIR_HOST}@g" \
50 -e "s@^exec_prefix=.*@exec_prefix=${STAGING_DIR_HOST}@g" \
51 -e "s@^includedir=.*@includedir=${STAGING_INCDIR}@g" \
52 -e "s@^libdir=.*@libdir=${STAGING_LIBDIR}@g" \
53 -i ${STAGING_BINDIR}/net-snmp-config
54 install -d ${D}${systemd_unitdir}/system
55 install -m 0644 ${WORKDIR}/snmpd.service ${D}${systemd_unitdir}/system
56 install -m 0644 ${WORKDIR}/snmptrapd.service ${D}${systemd_unitdir}/system
57}
58
59PACKAGES = "${PN}-dbg ${PN}-doc ${PN}-dev ${PN}-staticdev ${PN}-static ${PN}-libs \
60 ${PN}-mibs ${PN}-server ${PN}-client ${PN}-server-snmpd ${PN}-server-snmptrapd"
61
62ALLOW_EMPTY_${PN}-server = "1"
63
64FILES_${PN}-libs = "${libdir}/lib*${SOLIBS}"
65FILES_${PN}-mibs = "${datadir}/snmp/mibs"
66FILES_${PN}-server-snmpd = "${sbindir}/snmpd \
67 ${sysconfdir}/snmp/snmpd.conf \
68 ${sysconfdir}/init.d \
69 ${systemd_unitdir}/system/snmpd.service \
70"
71
72FILES_${PN}-server-snmptrapd = "${sbindir}/snmptrapd \
73 ${sysconfdir}/snmp/snmptrapd.conf \
74 ${systemd_unitdir}/system/snmptrapd.service \
75"
76
77FILES_${PN}-client = "${bindir}/* ${datadir}/snmp/"
78FILES_${PN}-dbg += "${libdir}/.debug/ ${sbindir}/.debug/ ${bindir}/.debug/"
79FILES_${PN}-dev += "${bindir}/net-snmp-config ${bindir}/mib2c ${bindir}/mib2c-update"
80
81CONFFILES_${PN}-server-snmpd = "${sysconfdir}/snmp/snmpd.conf"
82CONFFILES_${PN}-server-snmptrapd = "${sysconfdir}/snmp/snmptrapd.conf"
83
84INITSCRIPT_PACKAGES = "${PN}-server"
85INITSCRIPT_NAME_${PN}-server = "snmpd"
86INITSCRIPT_PARAMS_${PN}-server = "defaults"
87
88EXTRA_OECONF += "${@base_contains('DISTRO_FEATURES', 'systemd', '--with-systemd', '--without-systemd', d)}"
89
90SYSTEMD_PACKAGES = "${PN}-server-snmpd \
91 ${PN}-server-snmptrapd"
92
93SYSTEMD_SERVICE_${PN}-server-snmpd = "snmpd.service"
94SYSTEMD_SERVICE_${PN}-server-snmptrapd = "snmptrapd.service"
95
96RDEPENDS_${PN}-server-snmpd += "net-snmp-mibs"
97RDEPENDS_${PN}-server-snmptrapd += "net-snmp-server-snmpd"
98RDEPENDS_${PN}-server += "net-snmp-server-snmpd net-snmp-server-snmptrapd"
99RDEPENDS_${PN}-client += "net-snmp-mibs"
100RDEPENDS_${PN}-dev = "net-snmp-client (= ${EXTENDPKGV}) net-snmp-server (= ${EXTENDPKGV})"
101RRECOMMENDS_${PN}-dbg = "net-snmp-client (= ${EXTENDPKGV}) net-snmp-server (= ${EXTENDPKGV})"
102
103RPROVIDES_${PN}-server-snmpd += "${PN}-server-snmpd-systemd"
104RREPLACES_${PN}-server-snmpd += "${PN}-server-snmpd-systemd"
105RCONFLICTS_${PN}-server-snmpd += "${PN}-server-snmpd-systemd"
106
107RPROVIDES_${PN}-server-snmptrapd += "${PN}-server-snmptrapd-systemd"
108RREPLACES_${PN}-server-snmptrapd += "${PN}-server-snmptrapd-systemd"
109RCONFLICTS_${PN}-server-snmptrapd += "${PN}-server-snmptrapd-systemd"
110
111LEAD_SONAME = "libnetsnmp.so"
112
113pkg_postrm_${PN}-server() {
114 if test "x$D" != "x"; then
115 OPT="-r $D "
116 else
117 OPT=""
118 /etc/init.d/snmpd stop
119 fi
120}