Why did snmpd show "Failure in sendto" when requested with a broadcast address?
Issue
- When we requested SNMP with a broadcast source IP address '10.x.x.255', nothing is returned and following error message was shown in
/var/log/messages
at the snmpd server:
snmpd[xxxx]: send response: Failure in sendto
In the strace of snmpd
service, sendmsg
returned ENETUNREACH
before the message was output.
887241 11:20:29.860297 sendmsg(11, {msg_name={sa_family=AF_INET, sin_port=htons(36750), sin_addr=inet_addr("10.x.x.yyy")}, msg_namelen=16, msg_iov=[{iov_base="...", iov_len=53}], msg_iovlen=1, msg_control=[{cmsg_len=28, cmsg_level=SOL_IP, cmsg_type=IP_PKTINFO, cmsg_data={ipi_ifindex=0, ipi_spec_dst=inet_addr("10.x.x.255"), ipi_addr=inet_addr("0.0.0.0")}}], msg_controllen=32, msg_flags=0}, MSG_DONTWAIT|MSG_NOSIGNAL) = -1 ENETUNREACH (Network is unreachable) <0.000011>
887241 11:20:29.860389 getpid() = 887241 <0.000005>
887241 11:20:29.860410 sendto(8, "<27>Mar 15 11:20:29 snmpd[887241]: send response: Failure in sendto\n", 68, MSG_NOSIGNAL, NULL, 0) = 68 <0.002007>
887241 11:20:29.862764 getpid() = 887241 <0.000006>
887241 11:20:29.862798 sendto(8, "<27>Mar 15 11:20:29 snmpd[887241]: -- IP-MIB::ipAdEntAddr.10.x.x.yyy\n", 74, MSG_NOSIGNAL, NULL, 0) = 74 <0.001213>
According to the source code of net-snmp, sendmsg
is supposed to return EINVAL
when it requested with a broadcast address. We think that sendmsg
returning ENETUNREACH
instead of EINVAL
was the reason why the error message was shown.
net-snmp-5.8-14.el8.x86_64/snmplib/transports/snmpUDPBaseDomain.c
rc = sendmsg(fd, &m, MSG_NOSIGNAL|MSG_DONTWAIT);
if (rc >= 0 || errno != EINVAL)
return rc;
/*
* The error might be caused by broadcast srcip (i.e. we're responding
* to a broadcast request) - sendmsg does not like it. Try to resend it
* using the interface on which it was received
*/
...
rc = sendmsg(fd, &m, MSG_NOSIGNAL|MSG_DONTWAIT);
Could you please tell us why sendmsg
returned ENETUNREACH
instead of EINVAL
and the error message was shown?
Environment
- Red Hat Enterprise Linux (RHEL) 8
net-snmp
- SNMP
sendmsg
withIP_PKTINFO
ancillary data control message (cmsg
)
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.