projects
/
project
/
mdnsd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Use unicast IP address when sending unicast service reply
[project/mdnsd.git]
/
interface.c
diff --git
a/interface.c
b/interface.c
index
9ca85e1
..
1cc9499
100644
(file)
--- a/
interface.c
+++ b/
interface.c
@@
-41,7
+41,7
@@
#include "service.h"
static int
#include "service.h"
static int
-interface_send_packet4(struct interface *iface, struct iovec *iov, int iov_len)
+interface_send_packet4(struct interface *iface, struct
sockaddr_in *to, struct
iovec *iov, int iov_len)
{
static size_t cmsg_data[( CMSG_SPACE(sizeof(struct in_pktinfo)) / sizeof(size_t)) + 1];
static struct sockaddr_in a;
{
static size_t cmsg_data[( CMSG_SPACE(sizeof(struct in_pktinfo)) / sizeof(size_t)) + 1];
static struct sockaddr_in a;
@@
-69,13
+69,19
@@
interface_send_packet4(struct interface *iface, struct iovec *iov, int iov_len)
pkti = (struct in_pktinfo*) CMSG_DATA(cmsg);
pkti->ipi_ifindex = iface->ifindex;
pkti = (struct in_pktinfo*) CMSG_DATA(cmsg);
pkti->ipi_ifindex = iface->ifindex;
- a.sin_addr.s_addr = inet_addr(MCAST_ADDR);
+ if (iface->multicast || !to) {
+ a.sin_addr.s_addr = inet_addr(MCAST_ADDR);
+ if (to)
+ fprintf(stderr, "Ignoring IPv4 address for multicast interface\n");
+ } else {
+ a.sin_addr.s_addr = to->sin_addr.s_addr;
+ }
return sendmsg(fd, &m, 0);
}
static int
return sendmsg(fd, &m, 0);
}
static int
-interface_send_packet6(struct interface *iface, struct iovec *iov, int iov_len)
+interface_send_packet6(struct interface *iface, struct
sockaddr_in6 *to, struct
iovec *iov, int iov_len)
{
static size_t cmsg_data[( CMSG_SPACE(sizeof(struct in6_pktinfo)) / sizeof(size_t)) + 1];
static struct sockaddr_in6 a;
{
static size_t cmsg_data[( CMSG_SPACE(sizeof(struct in6_pktinfo)) / sizeof(size_t)) + 1];
static struct sockaddr_in6 a;
@@
-103,13
+109,19
@@
interface_send_packet6(struct interface *iface, struct iovec *iov, int iov_len)
pkti = (struct in6_pktinfo*) CMSG_DATA(cmsg);
pkti->ipi6_ifindex = iface->ifindex;
pkti = (struct in6_pktinfo*) CMSG_DATA(cmsg);
pkti->ipi6_ifindex = iface->ifindex;
- inet_pton(AF_INET6, MCAST_ADDR6, &a.sin6_addr);
+ if (iface->multicast || !to) {
+ inet_pton(AF_INET6, MCAST_ADDR6, &a.sin6_addr);
+ if (to)
+ fprintf(stderr, "Ignoring IPv6 address for multicast interface\n");
+ } else {
+ a.sin6_addr = to->sin6_addr;
+ }
return sendmsg(fd, &m, 0);
}
int
return sendmsg(fd, &m, 0);
}
int
-interface_send_packet(struct interface *iface, struct iovec *iov, int iov_len)
+interface_send_packet(struct interface *iface, struct
sockaddr *to, struct
iovec *iov, int iov_len)
{
if (debug > 1) {
fprintf(stderr, "TX ipv%d: %s\n", iface->v6 * 2 + 4, iface->name);
{
if (debug > 1) {
fprintf(stderr, "TX ipv%d: %s\n", iface->v6 * 2 + 4, iface->name);
@@
-117,9
+129,9
@@
interface_send_packet(struct interface *iface, struct iovec *iov, int iov_len)
}
if (iface->v6)
}
if (iface->v6)
- return interface_send_packet6(iface, iov, iov_len);
+ return interface_send_packet6(iface,
(struct sockaddr_in6 *)to,
iov, iov_len);
- return interface_send_packet4(iface, iov, iov_len);
+ return interface_send_packet4(iface,
(struct sockaddr_in *)to,
iov, iov_len);
}
static void interface_close(struct interface *iface)
}
static void interface_close(struct interface *iface)
@@
-306,7
+318,7
@@
read_socket6(struct uloop_fd *u, unsigned int events)
if (inp->ipi6_ifindex != iface->ifindex)
fprintf(stderr, "invalid iface index %d != %d\n", ifindex, iface->ifindex);
if (inp->ipi6_ifindex != iface->ifindex)
fprintf(stderr, "invalid iface index %d != %d\n", ifindex, iface->ifindex);
- else if (!interface_valid_src((void *) &iface->v
4_addr, (void *) &iface->v4
_netmask, (void *) &from.sin6_addr, 16))
+ else if (!interface_valid_src((void *) &iface->v
6_addr, (void *) &iface->v6
_netmask, (void *) &from.sin6_addr, 16))
dns_handle_packet(iface, (struct sockaddr *) &from, from.sin6_port, buffer, len);
}
dns_handle_packet(iface, (struct sockaddr *) &from, from.sin6_port, buffer, len);
}
@@
-315,7
+327,7
@@
interface_mcast_setup4(struct interface *iface)
{
struct ip_mreqn mreq;
uint8_t ttl = 255;
{
struct ip_mreqn mreq;
uint8_t ttl = 255;
- int
yes = 1
;
+ int
no = 0
;
struct sockaddr_in sa = { 0 };
int fd = iface->fd.fd;
struct sockaddr_in sa = { 0 };
int fd = iface->fd.fd;
@@
-345,7
+357,7
@@
interface_mcast_setup4(struct interface *iface)
return -1;
}
return -1;
}
- if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP, &
yes, sizeof(yes
)) < 0)
+ if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP, &
no, sizeof(no
)) < 0)
fprintf(stderr, "ioctl failed: IP_MULTICAST_LOOP\n");
return 0;
fprintf(stderr, "ioctl failed: IP_MULTICAST_LOOP\n");
return 0;
@@
-356,7
+368,7
@@
interface_socket_setup6(struct interface *iface)
{
struct ipv6_mreq mreq;
int ttl = 255;
{
struct ipv6_mreq mreq;
int ttl = 255;
- int
yes = 1
;
+ int
no = 0
;
struct sockaddr_in6 sa = { 0 };
int fd = iface->fd.fd;
struct sockaddr_in6 sa = { 0 };
int fd = iface->fd.fd;
@@
-379,7
+391,7
@@
interface_socket_setup6(struct interface *iface)
return -1;
}
return -1;
}
- if (setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, &
yes, sizeof(yes
)) < 0)
+ if (setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, &
no, sizeof(no
)) < 0)
fprintf(stderr, "ioctl failed: IPV6_MULTICAST_LOOP\n");
return 0;
fprintf(stderr, "ioctl failed: IPV6_MULTICAST_LOOP\n");
return 0;
@@
-389,6
+401,7
@@
static void
reconnect_socket4(struct uloop_timeout *timeout)
{
struct interface *iface = container_of(timeout, struct interface, reconnect);
reconnect_socket4(struct uloop_timeout *timeout)
{
struct interface *iface = container_of(timeout, struct interface, reconnect);
+ int ttl = 255;
int yes = 1;
iface->fd.fd = usock(USOCK_UDP | USOCK_SERVER | USOCK_NONBLOCK | USOCK_IPV4ONLY,
int yes = 1;
iface->fd.fd = usock(USOCK_UDP | USOCK_SERVER | USOCK_NONBLOCK | USOCK_IPV4ONLY,
@@
-404,6
+417,9
@@
reconnect_socket4(struct uloop_timeout *timeout)
if (setsockopt(iface->fd.fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) < 0)
fprintf(stderr, "ioctl failed: SO_REUSEADDR\n");
if (setsockopt(iface->fd.fd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) < 0)
fprintf(stderr, "ioctl failed: SO_REUSEADDR\n");
+ if (setsockopt(iface->fd.fd, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl)) < 0)
+ fprintf(stderr, "ioctl failed: IP_TTL\n");
+
if (setsockopt(iface->fd.fd, IPPROTO_IP, IP_RECVTTL, &yes, sizeof(yes)) < 0)
fprintf(stderr, "ioctl failed: IP_RECVTTL\n");
if (setsockopt(iface->fd.fd, IPPROTO_IP, IP_RECVTTL, &yes, sizeof(yes)) < 0)
fprintf(stderr, "ioctl failed: IP_RECVTTL\n");
@@
-417,7
+433,7
@@
reconnect_socket4(struct uloop_timeout *timeout)
uloop_fd_add(&iface->fd, ULOOP_READ);
if (iface->multicast) {
uloop_fd_add(&iface->fd, ULOOP_READ);
if (iface->multicast) {
- dns_send_question(iface, "_services._dns-sd._udp.local", TYPE_PTR,
1
);
+ dns_send_question(iface, "_services._dns-sd._udp.local", TYPE_PTR,
0
);
announce_init(iface);
}
announce_init(iface);
}
@@
-465,7
+481,7
@@
reconnect_socket6(struct uloop_timeout *timeout)
uloop_fd_add(&iface->fd, ULOOP_READ);
if (iface->multicast) {
uloop_fd_add(&iface->fd, ULOOP_READ);
if (iface->multicast) {
- dns_send_question(iface, "_services._dns-sd._udp.local", TYPE_PTR,
1
);
+ dns_send_question(iface, "_services._dns-sd._udp.local", TYPE_PTR,
0
);
announce_init(iface);
}
announce_init(iface);
}
@@
-620,8
+636,8
@@
void interface_shutdown(void)
vlist_for_each_element(&interfaces, iface, node)
if (iface->fd.fd > 0 && iface->multicast) {
vlist_for_each_element(&interfaces, iface, node)
if (iface->fd.fd > 0 && iface->multicast) {
-
service_announce(iface
, 0);
- service_
reply_a(iface
, 0);
+
dns_reply_a(iface, NULL
, 0);
+ service_
announce_services(iface, NULL
, 0);
}
vlist_for_each_element(&interfaces, iface, node)
interface_close(iface);
}
vlist_for_each_element(&interfaces, iface, node)
interface_close(iface);