udp6: set the scope id when sending to link local addresses.
Signed-off-by: Richard Cochran <richardcochran@gmail.com>master
parent
8e7a6da80c
commit
f92f09f563
10
udp6.c
10
udp6.c
|
@ -45,6 +45,11 @@ struct udp6 {
|
||||||
int index;
|
int index;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static int is_link_local(struct in6_addr *addr)
|
||||||
|
{
|
||||||
|
return addr->s6_addr[1] == 0x02 ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int mc_bind(int fd, int index)
|
static int mc_bind(int fd, int index)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
@ -190,6 +195,7 @@ static int udp6_recv(struct transport *t, int fd, void *buf, int buflen,
|
||||||
static int udp6_send(struct transport *t, struct fdarray *fda, int event, int peer,
|
static int udp6_send(struct transport *t, struct fdarray *fda, int event, int peer,
|
||||||
void *buf, int len, struct hw_timestamp *hwts)
|
void *buf, int len, struct hw_timestamp *hwts)
|
||||||
{
|
{
|
||||||
|
struct udp6 *udp6 = container_of(t, struct udp6, t);
|
||||||
ssize_t cnt;
|
ssize_t cnt;
|
||||||
int fd = event ? fda->fd[FD_EVENT] : fda->fd[FD_GENERAL];
|
int fd = event ? fda->fd[FD_EVENT] : fda->fd[FD_GENERAL];
|
||||||
struct sockaddr_in6 addr;
|
struct sockaddr_in6 addr;
|
||||||
|
@ -200,6 +206,10 @@ static int udp6_send(struct transport *t, struct fdarray *fda, int event, int pe
|
||||||
addr.sin6_addr = peer ? mc6_addr[MC_PDELAY] : mc6_addr[MC_PRIMARY];
|
addr.sin6_addr = peer ? mc6_addr[MC_PDELAY] : mc6_addr[MC_PRIMARY];
|
||||||
addr.sin6_port = htons(event ? EVENT_PORT : GENERAL_PORT);
|
addr.sin6_port = htons(event ? EVENT_PORT : GENERAL_PORT);
|
||||||
|
|
||||||
|
if (is_link_local(&addr.sin6_addr)) {
|
||||||
|
addr.sin6_scope_id = udp6->index;
|
||||||
|
}
|
||||||
|
|
||||||
len += 2; /* Extend the payload by two, for UDP checksum corrections. */
|
len += 2; /* Extend the payload by two, for UDP checksum corrections. */
|
||||||
|
|
||||||
cnt = sendto(fd, buf, len, 0, (struct sockaddr *)&addr, sizeof(addr));
|
cnt = sendto(fd, buf, len, 0, (struct sockaddr *)&addr, sizeof(addr));
|
||||||
|
|
Loading…
Reference in New Issue