summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Siegl <stesie@brokenpipe.de>2007-10-13 01:43:00 +0000
committerStefan Siegl <stesie@brokenpipe.de>2007-10-13 01:43:00 +0000
commit92f5a6111a2ae5fe7569c65afe1834382ff9147a (patch)
tree371d6357e98489b0f66311180133ddc874342379
parent1793f42c8f1c00dcc0163ee61e8f1a48fbf1b039 (diff)
2007-10-13 Stefan Siegl <stesie@brokenpipe.de>
* linux-src/net/ipv6/af_inet6.c (inet6_getname): Initialize sin6_scope_id. * linux-src/net/ipv6/datagram_ipv6.c (ipv6_recv_error): Likewise. * linux-src/net/ipv6/tcp_ipv6.c (v6_addr2sockaddr): Likewise. * linux-src/net/ipv6/udp_ipv6.c (udpv6_recvmsg): Likewise. * linux-src/net/ipv6/raw_ipv6.c (rawv6_recvmsg): Likewise. * linux-src/net/ipv6/af_inet6.c (inet6_bind): For link-local IPv6 addresses copy sin6_scope_id to bound_dev_if and error out unless bound. * linux-src/net/ipv6/tcp_ipv6.c (tcp_v6_connect): Likewise. * linux-src/net/ipv6/udp_ipv6.c (udpv6_connect): Likewise. * linux-src/net/ipv6/raw_ipv6.c (rawv6_bind): Likewise. * linux-src/net/ipv6/raw_ipv6.c (rawv6_sendmsg): For link-local IPv6 addresses bind packet to interface specified by sin6_scope_id. * linux-src/net/ipv6/udp_ipv6.c (udpv6_sendmsg): Likewise.
-rw-r--r--pfinet/ChangeLog20
-rw-r--r--pfinet/linux-src/net/ipv6/af_inet6.c26
-rw-r--r--pfinet/linux-src/net/ipv6/datagram_ipv6.c10
-rw-r--r--pfinet/linux-src/net/ipv6/raw_ipv6.c30
-rw-r--r--pfinet/linux-src/net/ipv6/tcp_ipv6.c24
-rw-r--r--pfinet/linux-src/net/ipv6/udp_ipv6.c29
6 files changed, 134 insertions, 5 deletions
diff --git a/pfinet/ChangeLog b/pfinet/ChangeLog
index b68ac2a8..f4506c5e 100644
--- a/pfinet/ChangeLog
+++ b/pfinet/ChangeLog
@@ -1,3 +1,23 @@
+2007-10-13 Stefan Siegl <stesie@brokenpipe.de>
+
+ * linux-src/net/ipv6/af_inet6.c (inet6_getname): Initialize
+ sin6_scope_id.
+ * linux-src/net/ipv6/datagram_ipv6.c (ipv6_recv_error): Likewise.
+ * linux-src/net/ipv6/tcp_ipv6.c (v6_addr2sockaddr): Likewise.
+ * linux-src/net/ipv6/udp_ipv6.c (udpv6_recvmsg): Likewise.
+ * linux-src/net/ipv6/raw_ipv6.c (rawv6_recvmsg): Likewise.
+
+ * linux-src/net/ipv6/af_inet6.c (inet6_bind): For link-local IPv6
+ addresses copy sin6_scope_id to bound_dev_if and error out unless
+ bound.
+ * linux-src/net/ipv6/tcp_ipv6.c (tcp_v6_connect): Likewise.
+ * linux-src/net/ipv6/udp_ipv6.c (udpv6_connect): Likewise.
+ * linux-src/net/ipv6/raw_ipv6.c (rawv6_bind): Likewise.
+
+ * linux-src/net/ipv6/raw_ipv6.c (rawv6_sendmsg): For link-local
+ IPv6 addresses bind packet to interface specified by sin6_scope_id.
+ * linux-src/net/ipv6/udp_ipv6.c (udpv6_sendmsg): Likewise.
+
2007-10-12 Thomas Schwinge <tschwinge@gnu.org>
* README: How to find information about IPv6 support.
diff --git a/pfinet/linux-src/net/ipv6/af_inet6.c b/pfinet/linux-src/net/ipv6/af_inet6.c
index 9077c0f1..fb5d3957 100644
--- a/pfinet/linux-src/net/ipv6/af_inet6.c
+++ b/pfinet/linux-src/net/ipv6/af_inet6.c
@@ -7,7 +7,7 @@
*
* Adapted from linux/net/ipv4/af_inet.c
*
- * $Id: af_inet6.c,v 1.2 2007/10/08 21:59:10 stesie Exp $
+ * $Id: af_inet6.c,v 1.3 2007/10/13 01:43:00 stesie Exp $
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -214,6 +214,26 @@ static int inet6_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
return(-EADDRNOTAVAIL);
} else {
if (addr_type != IPV6_ADDR_ANY) {
+ struct net_device *dev = NULL;
+
+ if (addr_type & IPV6_ADDR_LINKLOCAL) {
+ if (addr_len >= sizeof(struct sockaddr_in6) &&
+ addr->sin6_scope_id) {
+ /* Override any existing binding,
+ if another one is supplied
+ by user. */
+ sk->bound_dev_if = addr->sin6_scope_id;
+ }
+
+ /* Binding to link-local address requires
+ an interface */
+ if (!sk->bound_dev_if)
+ return(-EINVAL);
+ dev = dev_get_by_index(sk->bound_dev_if);
+ if (!dev)
+ return(-ENODEV);
+ }
+
/* ipv4 addr of the socket is invalid. Only the
* unpecified and mapped address have a v4 equivalent.
*/
@@ -312,6 +332,8 @@ static int inet6_getname(struct socket *sock, struct sockaddr *uaddr,
sin->sin6_family = AF_INET6;
sin->sin6_flowinfo = 0;
+ sin->sin6_scope_id = 0;
+
sk = sock->sk;
if (peer) {
if (!tcp_connected(sk->state))
@@ -333,6 +355,8 @@ static int inet6_getname(struct socket *sock, struct sockaddr *uaddr,
sin->sin6_port = sk->sport;
}
+ if (ipv6_addr_type(&sin->sin6_addr) & IPV6_ADDR_LINKLOCAL)
+ sin->sin6_scope_id = sk->bound_dev_if;
*uaddr_len = sizeof(*sin);
return(0);
}
diff --git a/pfinet/linux-src/net/ipv6/datagram_ipv6.c b/pfinet/linux-src/net/ipv6/datagram_ipv6.c
index af38fbcb..1ed33de8 100644
--- a/pfinet/linux-src/net/ipv6/datagram_ipv6.c
+++ b/pfinet/linux-src/net/ipv6/datagram_ipv6.c
@@ -5,7 +5,7 @@
* Authors:
* Pedro Roque <roque@di.fc.ul.pt>
*
- * $Id: datagram_ipv6.c,v 1.1 2007/10/08 21:12:30 stesie Exp $
+ * $Id: datagram_ipv6.c,v 1.2 2007/10/13 01:43:00 stesie Exp $
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -134,10 +134,14 @@ int ipv6_recv_error(struct sock *sk, struct msghdr *msg, int len)
sin->sin6_family = AF_INET6;
sin->sin6_flowinfo = 0;
sin->sin6_port = serr->port;
+ sin->sin6_scope_id = 0;
if (serr->ee.ee_origin == SO_EE_ORIGIN_ICMP6) {
memcpy(&sin->sin6_addr, skb->nh.raw + serr->addr_offset, 16);
if (sk->net_pinfo.af_inet6.sndflow)
sin->sin6_flowinfo = *(u32*)(skb->nh.raw + serr->addr_offset - 24) & IPV6_FLOWINFO_MASK;
+ if (ipv6_addr_type(&sin->sin6_addr) & IPV6_ADDR_LINKLOCAL)
+ sin->sin6_scope_id =
+ ((struct inet6_skb_parm *) skb->cb)->iif;
} else
ipv6_addr_set(&sin->sin6_addr, 0, 0,
__constant_htonl(0xffff),
@@ -150,10 +154,14 @@ int ipv6_recv_error(struct sock *sk, struct msghdr *msg, int len)
if (serr->ee.ee_origin != SO_EE_ORIGIN_LOCAL) {
sin->sin6_family = AF_INET6;
sin->sin6_flowinfo = 0;
+ sin->sin6_scope_id = 0;
if (serr->ee.ee_origin == SO_EE_ORIGIN_ICMP6) {
memcpy(&sin->sin6_addr, &skb->nh.ipv6h->saddr, 16);
if (sk->net_pinfo.af_inet6.rxopt.all)
datagram_recv_ctl(sk, msg, skb);
+ if (ipv6_addr_type(&sin->sin6_addr) & IPV6_ADDR_LINKLOCAL)
+ sin->sin6_scope_id =
+ ((struct inet6_skb_parm *) skb->cb)->iif;
} else {
ipv6_addr_set(&sin->sin6_addr, 0, 0,
__constant_htonl(0xffff),
diff --git a/pfinet/linux-src/net/ipv6/raw_ipv6.c b/pfinet/linux-src/net/ipv6/raw_ipv6.c
index 95856ea7..9980b3ad 100644
--- a/pfinet/linux-src/net/ipv6/raw_ipv6.c
+++ b/pfinet/linux-src/net/ipv6/raw_ipv6.c
@@ -7,7 +7,7 @@
*
* Adapted from linux/net/ipv4/raw.c
*
- * $Id: raw_ipv6.c,v 1.1 2007/10/08 21:12:31 stesie Exp $
+ * $Id: raw_ipv6.c,v 1.2 2007/10/13 01:43:00 stesie Exp $
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -128,6 +128,25 @@ static int rawv6_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len)
return(-EADDRNOTAVAIL);
} else {
if (addr_type != IPV6_ADDR_ANY) {
+ if (addr_type & IPV6_ADDR_LINKLOCAL) {
+ if (addr_len >= sizeof(struct sockaddr_in6) &&
+ addr->sin6_scope_id) {
+ /* Override any existing binding,
+ * if another one is supplied by user.
+ */
+ sk->bound_dev_if =
+ addr->sin6_scope_id;
+ }
+
+ /* Binding to link-local address requires
+ an interface */
+ if (!sk->bound_dev_if)
+ return(-EINVAL);
+
+ if (!dev_get_by_index(sk->bound_dev_if))
+ return(-ENODEV);
+ }
+
/* ipv4 addr of the socket is invalid. Only the
* unpecified and mapped address have a v4 equivalent.
*/
@@ -252,6 +271,10 @@ int rawv6_recvmsg(struct sock *sk, struct msghdr *msg, int len,
memcpy(&sin6->sin6_addr, &skb->nh.ipv6h->saddr,
sizeof(struct in6_addr));
sin6->sin6_flowinfo = 0;
+ sin6->sin6_scope_id = 0;
+ if (ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL)
+ sin6->sin6_scope_id =
+ ((struct inet6_skb_parm *) skb->cb)->iif;
}
if (sk->net_pinfo.af_inet6.rxopt.all)
@@ -391,6 +414,11 @@ static int rawv6_sendmsg(struct sock *sk, struct msghdr *msg, int len)
if (sk->state == TCP_ESTABLISHED &&
!ipv6_addr_cmp(daddr, &sk->net_pinfo.af_inet6.daddr))
daddr = &sk->net_pinfo.af_inet6.daddr;
+
+ if (addr_len >= sizeof(struct sockaddr_in6) &&
+ sin6->sin6_scope_id &&
+ ipv6_addr_type(daddr)&IPV6_ADDR_LINKLOCAL)
+ fl.oif = sin6->sin6_scope_id;
} else {
if (sk->state != TCP_ESTABLISHED)
return(-EINVAL);
diff --git a/pfinet/linux-src/net/ipv6/tcp_ipv6.c b/pfinet/linux-src/net/ipv6/tcp_ipv6.c
index 85a5ab27..c761e76c 100644
--- a/pfinet/linux-src/net/ipv6/tcp_ipv6.c
+++ b/pfinet/linux-src/net/ipv6/tcp_ipv6.c
@@ -5,7 +5,7 @@
* Authors:
* Pedro Roque <roque@di.fc.ul.pt>
*
- * $Id: tcp_ipv6.c,v 1.2 2007/10/08 21:59:10 stesie Exp $
+ * $Id: tcp_ipv6.c,v 1.3 2007/10/13 01:43:00 stesie Exp $
*
* Based on:
* linux/net/ipv4/tcp.c
@@ -421,6 +421,24 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr *uaddr,
if(addr_type & IPV6_ADDR_MULTICAST)
return -ENETUNREACH;
+ if (addr_type&IPV6_ADDR_LINKLOCAL) {
+ if (addr_len >= sizeof(struct sockaddr_in6) &&
+ usin->sin6_scope_id) {
+ /* If interface is set while binding, indices
+ * must coincide.
+ */
+ if (sk->bound_dev_if &&
+ sk->bound_dev_if != usin->sin6_scope_id)
+ return -EINVAL;
+
+ sk->bound_dev_if = usin->sin6_scope_id;
+ }
+
+ /* Connect to link-local address requires an interface */
+ if (!sk->bound_dev_if)
+ return -EINVAL;
+ }
+
/*
* connect to self not allowed
*/
@@ -1587,6 +1605,10 @@ static void v6_addr2sockaddr(struct sock *sk, struct sockaddr * uaddr)
sin6->sin6_port = sk->dport;
/* We do not store received flowlabel for TCP */
sin6->sin6_flowinfo = 0;
+ sin6->sin6_scope_id = 0;
+ if (sk->bound_dev_if &&
+ ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL)
+ sin6->sin6_scope_id = sk->bound_dev_if;
}
static struct tcp_func ipv6_specific = {
diff --git a/pfinet/linux-src/net/ipv6/udp_ipv6.c b/pfinet/linux-src/net/ipv6/udp_ipv6.c
index 57b5db1a..4511c024 100644
--- a/pfinet/linux-src/net/ipv6/udp_ipv6.c
+++ b/pfinet/linux-src/net/ipv6/udp_ipv6.c
@@ -7,7 +7,7 @@
*
* Based on linux/ipv4/udp.c
*
- * $Id: udp_ipv6.c,v 1.2 2007/10/08 21:59:10 stesie Exp $
+ * $Id: udp_ipv6.c,v 1.3 2007/10/13 01:43:00 stesie Exp $
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -272,6 +272,24 @@ ipv4_connected:
return 0;
}
+ if (addr_type&IPV6_ADDR_LINKLOCAL) {
+ if (addr_len >= sizeof(struct sockaddr_in6) &&
+ usin->sin6_scope_id) {
+ if (sk->bound_dev_if &&
+ sk->bound_dev_if != usin->sin6_scope_id)
+ return(-EINVAL);
+
+ sk->bound_dev_if = usin->sin6_scope_id;
+ if (!sk->bound_dev_if &&
+ (addr_type & IPV6_ADDR_MULTICAST))
+ fl.oif = np->mcast_oif;
+ }
+
+ /* Connect to link-local address requires an interface */
+ if (!sk->bound_dev_if)
+ return(-EINVAL);
+ }
+
ipv6_addr_copy(&np->daddr, daddr);
np->flow_label = fl.fl6_flowlabel;
@@ -416,6 +434,7 @@ int udpv6_recvmsg(struct sock *sk, struct msghdr *msg, int len,
sin6->sin6_family = AF_INET6;
sin6->sin6_port = skb->h.uh->source;
sin6->sin6_flowinfo = 0;
+ sin6->sin6_scope_id = 0;
if (skb->protocol == __constant_htons(ETH_P_IP)) {
ipv6_addr_set(&sin6->sin6_addr, 0, 0,
@@ -425,6 +444,9 @@ int udpv6_recvmsg(struct sock *sk, struct msghdr *msg, int len,
} else {
memcpy(&sin6->sin6_addr, &skb->nh.ipv6h->saddr,
sizeof(struct in6_addr));
+ if (ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL)
+ sin6->sin6_scope_id =
+ ((struct inet6_skb_parm *) skb->cb)->iif;
if (sk->net_pinfo.af_inet6.rxopt.all)
datagram_recv_ctl(sk, msg, skb);
@@ -805,6 +827,11 @@ static int udpv6_sendmsg(struct sock *sk, struct msghdr *msg, int ulen)
if (sk->state == TCP_ESTABLISHED &&
!ipv6_addr_cmp(daddr, &sk->net_pinfo.af_inet6.daddr))
daddr = &sk->net_pinfo.af_inet6.daddr;
+
+ if (addr_len >= sizeof(struct sockaddr_in6) &&
+ sin6->sin6_scope_id &&
+ ipv6_addr_type(daddr)&IPV6_ADDR_LINKLOCAL)
+ fl.oif = sin6->sin6_scope_id;
} else {
if (sk->state != TCP_ESTABLISHED)
return(-ENOTCONN);