Re-do r240271:
- Set IP_RECVDSTADDR sockopt on the socket only in case if it is INADDR_ANY bound. - Supply IP_SENDSRCADDR control message only if we did receive IP_RECVDSTADDR control message. This fixes operation of snmpd bound to a specific local IP address. PR: bin/171279
This commit is contained in:
parent
d62a0fbf2a
commit
23cea7199b
@ -1203,6 +1203,8 @@ snmpd_input(struct port_input *pi, struct tport *tport)
|
||||
|
||||
ret = recv_stream(pi);
|
||||
} else {
|
||||
struct in_addr *laddr;
|
||||
|
||||
memset(cbuf, 0, CMSG_SPACE(sizeof(struct in_addr)));
|
||||
msg.msg_control = cbuf;
|
||||
msg.msg_controllen = CMSG_SPACE(sizeof(struct in_addr));
|
||||
@ -1210,8 +1212,14 @@ snmpd_input(struct port_input *pi, struct tport *tport)
|
||||
cmsgp->cmsg_len = CMSG_LEN(sizeof(struct in_addr));
|
||||
cmsgp->cmsg_level = IPPROTO_IP;
|
||||
cmsgp->cmsg_type = IP_SENDSRCADDR;
|
||||
laddr = (struct in_addr *)CMSG_DATA(cmsgp);
|
||||
|
||||
ret = recv_dgram(pi, (struct in_addr *)CMSG_DATA(cmsgp));
|
||||
ret = recv_dgram(pi, laddr);
|
||||
|
||||
if (laddr->s_addr == 0) {
|
||||
msg.msg_control = NULL;
|
||||
msg.msg_controllen = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (ret == -1)
|
||||
|
@ -109,13 +109,6 @@ udp_init_port(struct tport *tp)
|
||||
syslog(LOG_ERR, "creating UDP socket: %m");
|
||||
return (SNMP_ERR_RES_UNAVAIL);
|
||||
}
|
||||
if (setsockopt(p->input.fd, IPPROTO_IP, IP_RECVDSTADDR, &on,
|
||||
sizeof(on)) == -1) {
|
||||
syslog(LOG_ERR, "setsockopt(IP_RECVDSTADDR): %m");
|
||||
close(p->input.fd);
|
||||
p->input.fd = -1;
|
||||
return (SNMP_ERR_GENERR);
|
||||
}
|
||||
ip = (p->addr[0] << 24) | (p->addr[1] << 16) | (p->addr[2] << 8) |
|
||||
p->addr[3];
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
@ -123,6 +116,14 @@ udp_init_port(struct tport *tp)
|
||||
addr.sin_port = htons(p->port);
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_len = sizeof(addr);
|
||||
if (addr.sin_addr.s_addr == INADDR_ANY &&
|
||||
setsockopt(p->input.fd, IPPROTO_IP, IP_RECVDSTADDR, &on,
|
||||
sizeof(on)) == -1) {
|
||||
syslog(LOG_ERR, "setsockopt(IP_RECVDSTADDR): %m");
|
||||
close(p->input.fd);
|
||||
p->input.fd = -1;
|
||||
return (SNMP_ERR_GENERR);
|
||||
}
|
||||
if (bind(p->input.fd, (struct sockaddr *)&addr, sizeof(addr))) {
|
||||
if (errno == EADDRNOTAVAIL) {
|
||||
close(p->input.fd);
|
||||
|
Loading…
Reference in New Issue
Block a user