aboutsummaryrefslogtreecommitdiffstats
path: root/net/appletalk
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2009-12-08 10:55:01 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2009-12-08 10:55:01 -0500
commitd7fc02c7bae7b1cf69269992cf880a43a350cdaa (patch)
treea43d56fa72913a1cc98a0bbebe054d08581b3a7c /net/appletalk
parentee1262dbc65ce0b6234a915d8432171e8d77f518 (diff)
parent28b4d5cc17c20786848cdc07b7ea237a309776bb (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next-2.6
* git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next-2.6: (1815 commits) mac80211: fix reorder buffer release iwmc3200wifi: Enable wimax core through module parameter iwmc3200wifi: Add wifi-wimax coexistence mode as a module parameter iwmc3200wifi: Coex table command does not expect a response iwmc3200wifi: Update wiwi priority table iwlwifi: driver version track kernel version iwlwifi: indicate uCode type when fail dump error/event log iwl3945: remove duplicated event logging code b43: fix two warnings ipw2100: fix rebooting hang with driver loaded cfg80211: indent regulatory messages with spaces iwmc3200wifi: fix NULL pointer dereference in pmkid update mac80211: Fix TX status reporting for injected data frames ath9k: enable 2GHz band only if the device supports it airo: Fix integer overflow warning rt2x00: Fix padding bug on L2PAD devices. WE: Fix set events not propagated b43legacy: avoid PPC fault during resume b43: avoid PPC fault during resume tcp: fix a timewait refcnt race ... Fix up conflicts due to sysctl cleanups (dead sysctl_check code and CTL_UNNUMBERED removed) in kernel/sysctl_check.c net/ipv4/sysctl_net_ipv4.c net/ipv6/addrconf.c net/sctp/sysctl.c
Diffstat (limited to 'net/appletalk')
-rw-r--r--net/appletalk/ddp.c134
1 files changed, 91 insertions, 43 deletions
diff --git a/net/appletalk/ddp.c b/net/appletalk/ddp.c
index b1a4290996b5..9fc4da56fb1d 100644
--- a/net/appletalk/ddp.c
+++ b/net/appletalk/ddp.c
@@ -56,6 +56,7 @@
56#include <linux/if_arp.h> 56#include <linux/if_arp.h>
57#include <linux/smp_lock.h> 57#include <linux/smp_lock.h>
58#include <linux/termios.h> /* For TIOCOUTQ/INQ */ 58#include <linux/termios.h> /* For TIOCOUTQ/INQ */
59#include <linux/compat.h>
59#include <net/datalink.h> 60#include <net/datalink.h>
60#include <net/psnap.h> 61#include <net/psnap.h>
61#include <net/sock.h> 62#include <net/sock.h>
@@ -922,13 +923,8 @@ static unsigned long atalk_sum_partial(const unsigned char *data,
922{ 923{
923 /* This ought to be unwrapped neatly. I'll trust gcc for now */ 924 /* This ought to be unwrapped neatly. I'll trust gcc for now */
924 while (len--) { 925 while (len--) {
925 sum += *data; 926 sum += *data++;
926 sum <<= 1; 927 sum = rol16(sum, 1);
927 if (sum & 0x10000) {
928 sum++;
929 sum &= 0xffff;
930 }
931 data++;
932 } 928 }
933 return sum; 929 return sum;
934} 930}
@@ -1021,12 +1017,13 @@ static struct proto ddp_proto = {
1021 * Create a socket. Initialise the socket, blank the addresses 1017 * Create a socket. Initialise the socket, blank the addresses
1022 * set the state. 1018 * set the state.
1023 */ 1019 */
1024static int atalk_create(struct net *net, struct socket *sock, int protocol) 1020static int atalk_create(struct net *net, struct socket *sock, int protocol,
1021 int kern)
1025{ 1022{
1026 struct sock *sk; 1023 struct sock *sk;
1027 int rc = -ESOCKTNOSUPPORT; 1024 int rc = -ESOCKTNOSUPPORT;
1028 1025
1029 if (net != &init_net) 1026 if (!net_eq(net, &init_net))
1030 return -EAFNOSUPPORT; 1027 return -EAFNOSUPPORT;
1031 1028
1032 /* 1029 /*
@@ -1054,11 +1051,13 @@ static int atalk_release(struct socket *sock)
1054{ 1051{
1055 struct sock *sk = sock->sk; 1052 struct sock *sk = sock->sk;
1056 1053
1054 lock_kernel();
1057 if (sk) { 1055 if (sk) {
1058 sock_orphan(sk); 1056 sock_orphan(sk);
1059 sock->sk = NULL; 1057 sock->sk = NULL;
1060 atalk_destroy_socket(sk); 1058 atalk_destroy_socket(sk);
1061 } 1059 }
1060 unlock_kernel();
1062 return 0; 1061 return 0;
1063} 1062}
1064 1063
@@ -1134,6 +1133,7 @@ static int atalk_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
1134 struct sockaddr_at *addr = (struct sockaddr_at *)uaddr; 1133 struct sockaddr_at *addr = (struct sockaddr_at *)uaddr;
1135 struct sock *sk = sock->sk; 1134 struct sock *sk = sock->sk;
1136 struct atalk_sock *at = at_sk(sk); 1135 struct atalk_sock *at = at_sk(sk);
1136 int err;
1137 1137
1138 if (!sock_flag(sk, SOCK_ZAPPED) || 1138 if (!sock_flag(sk, SOCK_ZAPPED) ||
1139 addr_len != sizeof(struct sockaddr_at)) 1139 addr_len != sizeof(struct sockaddr_at))
@@ -1142,37 +1142,44 @@ static int atalk_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
1142 if (addr->sat_family != AF_APPLETALK) 1142 if (addr->sat_family != AF_APPLETALK)
1143 return -EAFNOSUPPORT; 1143 return -EAFNOSUPPORT;
1144 1144
1145 lock_kernel();
1145 if (addr->sat_addr.s_net == htons(ATADDR_ANYNET)) { 1146 if (addr->sat_addr.s_net == htons(ATADDR_ANYNET)) {
1146 struct atalk_addr *ap = atalk_find_primary(); 1147 struct atalk_addr *ap = atalk_find_primary();
1147 1148
1149 err = -EADDRNOTAVAIL;
1148 if (!ap) 1150 if (!ap)
1149 return -EADDRNOTAVAIL; 1151 goto out;
1150 1152
1151 at->src_net = addr->sat_addr.s_net = ap->s_net; 1153 at->src_net = addr->sat_addr.s_net = ap->s_net;
1152 at->src_node = addr->sat_addr.s_node= ap->s_node; 1154 at->src_node = addr->sat_addr.s_node= ap->s_node;
1153 } else { 1155 } else {
1156 err = -EADDRNOTAVAIL;
1154 if (!atalk_find_interface(addr->sat_addr.s_net, 1157 if (!atalk_find_interface(addr->sat_addr.s_net,
1155 addr->sat_addr.s_node)) 1158 addr->sat_addr.s_node))
1156 return -EADDRNOTAVAIL; 1159 goto out;
1157 1160
1158 at->src_net = addr->sat_addr.s_net; 1161 at->src_net = addr->sat_addr.s_net;
1159 at->src_node = addr->sat_addr.s_node; 1162 at->src_node = addr->sat_addr.s_node;
1160 } 1163 }
1161 1164
1162 if (addr->sat_port == ATADDR_ANYPORT) { 1165 if (addr->sat_port == ATADDR_ANYPORT) {
1163 int n = atalk_pick_and_bind_port(sk, addr); 1166 err = atalk_pick_and_bind_port(sk, addr);
1164 1167
1165 if (n < 0) 1168 if (err < 0)
1166 return n; 1169 goto out;
1167 } else { 1170 } else {
1168 at->src_port = addr->sat_port; 1171 at->src_port = addr->sat_port;
1169 1172
1173 err = -EADDRINUSE;
1170 if (atalk_find_or_insert_socket(sk, addr)) 1174 if (atalk_find_or_insert_socket(sk, addr))
1171 return -EADDRINUSE; 1175 goto out;
1172 } 1176 }
1173 1177
1174 sock_reset_flag(sk, SOCK_ZAPPED); 1178 sock_reset_flag(sk, SOCK_ZAPPED);
1175 return 0; 1179 err = 0;
1180out:
1181 unlock_kernel();
1182 return err;
1176} 1183}
1177 1184
1178/* Set the address we talk to */ 1185/* Set the address we talk to */
@@ -1182,6 +1189,7 @@ static int atalk_connect(struct socket *sock, struct sockaddr *uaddr,
1182 struct sock *sk = sock->sk; 1189 struct sock *sk = sock->sk;
1183 struct atalk_sock *at = at_sk(sk); 1190 struct atalk_sock *at = at_sk(sk);
1184 struct sockaddr_at *addr; 1191 struct sockaddr_at *addr;
1192 int err;
1185 1193
1186 sk->sk_state = TCP_CLOSE; 1194 sk->sk_state = TCP_CLOSE;
1187 sock->state = SS_UNCONNECTED; 1195 sock->state = SS_UNCONNECTED;
@@ -1206,12 +1214,15 @@ static int atalk_connect(struct socket *sock, struct sockaddr *uaddr,
1206#endif 1214#endif
1207 } 1215 }
1208 1216
1217 lock_kernel();
1218 err = -EBUSY;
1209 if (sock_flag(sk, SOCK_ZAPPED)) 1219 if (sock_flag(sk, SOCK_ZAPPED))
1210 if (atalk_autobind(sk) < 0) 1220 if (atalk_autobind(sk) < 0)
1211 return -EBUSY; 1221 goto out;
1212 1222
1223 err = -ENETUNREACH;
1213 if (!atrtr_get_dev(&addr->sat_addr)) 1224 if (!atrtr_get_dev(&addr->sat_addr))
1214 return -ENETUNREACH; 1225 goto out;
1215 1226
1216 at->dest_port = addr->sat_port; 1227 at->dest_port = addr->sat_port;
1217 at->dest_net = addr->sat_addr.s_net; 1228 at->dest_net = addr->sat_addr.s_net;
@@ -1219,7 +1230,10 @@ static int atalk_connect(struct socket *sock, struct sockaddr *uaddr,
1219 1230
1220 sock->state = SS_CONNECTED; 1231 sock->state = SS_CONNECTED;
1221 sk->sk_state = TCP_ESTABLISHED; 1232 sk->sk_state = TCP_ESTABLISHED;
1222 return 0; 1233 err = 0;
1234out:
1235 unlock_kernel();
1236 return err;
1223} 1237}
1224 1238
1225/* 1239/*
@@ -1232,17 +1246,21 @@ static int atalk_getname(struct socket *sock, struct sockaddr *uaddr,
1232 struct sockaddr_at sat; 1246 struct sockaddr_at sat;
1233 struct sock *sk = sock->sk; 1247 struct sock *sk = sock->sk;
1234 struct atalk_sock *at = at_sk(sk); 1248 struct atalk_sock *at = at_sk(sk);
1249 int err;
1235 1250
1251 lock_kernel();
1252 err = -ENOBUFS;
1236 if (sock_flag(sk, SOCK_ZAPPED)) 1253 if (sock_flag(sk, SOCK_ZAPPED))
1237 if (atalk_autobind(sk) < 0) 1254 if (atalk_autobind(sk) < 0)
1238 return -ENOBUFS; 1255 goto out;
1239 1256
1240 *uaddr_len = sizeof(struct sockaddr_at); 1257 *uaddr_len = sizeof(struct sockaddr_at);
1241 memset(&sat.sat_zero, 0, sizeof(sat.sat_zero)); 1258 memset(&sat.sat_zero, 0, sizeof(sat.sat_zero));
1242 1259
1243 if (peer) { 1260 if (peer) {
1261 err = -ENOTCONN;
1244 if (sk->sk_state != TCP_ESTABLISHED) 1262 if (sk->sk_state != TCP_ESTABLISHED)
1245 return -ENOTCONN; 1263 goto out;
1246 1264
1247 sat.sat_addr.s_net = at->dest_net; 1265 sat.sat_addr.s_net = at->dest_net;
1248 sat.sat_addr.s_node = at->dest_node; 1266 sat.sat_addr.s_node = at->dest_node;
@@ -1253,9 +1271,23 @@ static int atalk_getname(struct socket *sock, struct sockaddr *uaddr,
1253 sat.sat_port = at->src_port; 1271 sat.sat_port = at->src_port;
1254 } 1272 }
1255 1273
1274 err = 0;
1256 sat.sat_family = AF_APPLETALK; 1275 sat.sat_family = AF_APPLETALK;
1257 memcpy(uaddr, &sat, sizeof(sat)); 1276 memcpy(uaddr, &sat, sizeof(sat));
1258 return 0; 1277
1278out:
1279 unlock_kernel();
1280 return err;
1281}
1282
1283static unsigned int atalk_poll(struct file *file, struct socket *sock,
1284 poll_table *wait)
1285{
1286 int err;
1287 lock_kernel();
1288 err = datagram_poll(file, sock, wait);
1289 unlock_kernel();
1290 return err;
1259} 1291}
1260 1292
1261#if defined(CONFIG_IPDDP) || defined(CONFIG_IPDDP_MODULE) 1293#if defined(CONFIG_IPDDP) || defined(CONFIG_IPDDP_MODULE)
@@ -1563,23 +1595,28 @@ static int atalk_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr
1563 if (len > DDP_MAXSZ) 1595 if (len > DDP_MAXSZ)
1564 return -EMSGSIZE; 1596 return -EMSGSIZE;
1565 1597
1598 lock_kernel();
1566 if (usat) { 1599 if (usat) {
1600 err = -EBUSY;
1567 if (sock_flag(sk, SOCK_ZAPPED)) 1601 if (sock_flag(sk, SOCK_ZAPPED))
1568 if (atalk_autobind(sk) < 0) 1602 if (atalk_autobind(sk) < 0)
1569 return -EBUSY; 1603 goto out;
1570 1604
1605 err = -EINVAL;
1571 if (msg->msg_namelen < sizeof(*usat) || 1606 if (msg->msg_namelen < sizeof(*usat) ||
1572 usat->sat_family != AF_APPLETALK) 1607 usat->sat_family != AF_APPLETALK)
1573 return -EINVAL; 1608 goto out;
1574 1609
1610 err = -EPERM;
1575 /* netatalk didn't implement this check */ 1611 /* netatalk didn't implement this check */
1576 if (usat->sat_addr.s_node == ATADDR_BCAST && 1612 if (usat->sat_addr.s_node == ATADDR_BCAST &&
1577 !sock_flag(sk, SOCK_BROADCAST)) { 1613 !sock_flag(sk, SOCK_BROADCAST)) {
1578 return -EPERM; 1614 goto out;
1579 } 1615 }
1580 } else { 1616 } else {
1617 err = -ENOTCONN;
1581 if (sk->sk_state != TCP_ESTABLISHED) 1618 if (sk->sk_state != TCP_ESTABLISHED)
1582 return -ENOTCONN; 1619 goto out;
1583 usat = &local_satalk; 1620 usat = &local_satalk;
1584 usat->sat_family = AF_APPLETALK; 1621 usat->sat_family = AF_APPLETALK;
1585 usat->sat_port = at->dest_port; 1622 usat->sat_port = at->dest_port;
@@ -1603,8 +1640,9 @@ static int atalk_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr
1603 1640
1604 rt = atrtr_find(&at_hint); 1641 rt = atrtr_find(&at_hint);
1605 } 1642 }
1643 err = ENETUNREACH;
1606 if (!rt) 1644 if (!rt)
1607 return -ENETUNREACH; 1645 goto out;
1608 1646
1609 dev = rt->dev; 1647 dev = rt->dev;
1610 1648
@@ -1614,7 +1652,7 @@ static int atalk_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr
1614 size += dev->hard_header_len; 1652 size += dev->hard_header_len;
1615 skb = sock_alloc_send_skb(sk, size, (flags & MSG_DONTWAIT), &err); 1653 skb = sock_alloc_send_skb(sk, size, (flags & MSG_DONTWAIT), &err);
1616 if (!skb) 1654 if (!skb)
1617 return err; 1655 goto out;
1618 1656
1619 skb->sk = sk; 1657 skb->sk = sk;
1620 skb_reserve(skb, ddp_dl->header_length); 1658 skb_reserve(skb, ddp_dl->header_length);
@@ -1637,7 +1675,8 @@ static int atalk_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr
1637 err = memcpy_fromiovec(skb_put(skb, len), msg->msg_iov, len); 1675 err = memcpy_fromiovec(skb_put(skb, len), msg->msg_iov, len);
1638 if (err) { 1676 if (err) {
1639 kfree_skb(skb); 1677 kfree_skb(skb);
1640 return -EFAULT; 1678 err = -EFAULT;
1679 goto out;
1641 } 1680 }
1642 1681
1643 if (sk->sk_no_check == 1) 1682 if (sk->sk_no_check == 1)
@@ -1676,7 +1715,8 @@ static int atalk_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr
1676 rt = atrtr_find(&at_lo); 1715 rt = atrtr_find(&at_lo);
1677 if (!rt) { 1716 if (!rt) {
1678 kfree_skb(skb); 1717 kfree_skb(skb);
1679 return -ENETUNREACH; 1718 err = -ENETUNREACH;
1719 goto out;
1680 } 1720 }
1681 dev = rt->dev; 1721 dev = rt->dev;
1682 skb->dev = dev; 1722 skb->dev = dev;
@@ -1696,7 +1736,9 @@ static int atalk_sendmsg(struct kiocb *iocb, struct socket *sock, struct msghdr
1696 } 1736 }
1697 SOCK_DEBUG(sk, "SK %p: Done write (%Zd).\n", sk, len); 1737 SOCK_DEBUG(sk, "SK %p: Done write (%Zd).\n", sk, len);
1698 1738
1699 return len; 1739out:
1740 unlock_kernel();
1741 return err ? : len;
1700} 1742}
1701 1743
1702static int atalk_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg, 1744static int atalk_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr *msg,
@@ -1708,10 +1750,13 @@ static int atalk_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr
1708 int copied = 0; 1750 int copied = 0;
1709 int offset = 0; 1751 int offset = 0;
1710 int err = 0; 1752 int err = 0;
1711 struct sk_buff *skb = skb_recv_datagram(sk, flags & ~MSG_DONTWAIT, 1753 struct sk_buff *skb;
1754
1755 lock_kernel();
1756 skb = skb_recv_datagram(sk, flags & ~MSG_DONTWAIT,
1712 flags & MSG_DONTWAIT, &err); 1757 flags & MSG_DONTWAIT, &err);
1713 if (!skb) 1758 if (!skb)
1714 return err; 1759 goto out;
1715 1760
1716 /* FIXME: use skb->cb to be able to use shared skbs */ 1761 /* FIXME: use skb->cb to be able to use shared skbs */
1717 ddp = ddp_hdr(skb); 1762 ddp = ddp_hdr(skb);
@@ -1739,6 +1784,9 @@ static int atalk_recvmsg(struct kiocb *iocb, struct socket *sock, struct msghdr
1739 } 1784 }
1740 1785
1741 skb_free_datagram(sk, skb); /* Free the datagram. */ 1786 skb_free_datagram(sk, skb); /* Free the datagram. */
1787
1788out:
1789 unlock_kernel();
1742 return err ? : copied; 1790 return err ? : copied;
1743} 1791}
1744 1792
@@ -1810,24 +1858,26 @@ static int atalk_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1810static int atalk_compat_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg) 1858static int atalk_compat_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
1811{ 1859{
1812 /* 1860 /*
1813 * All Appletalk ioctls except SIOCATALKDIFADDR are standard. And 1861 * SIOCATALKDIFADDR is a SIOCPROTOPRIVATE ioctl number, so we
1814 * SIOCATALKDIFADDR is handled by upper layer as well, so there is 1862 * cannot handle it in common code. The data we access if ifreq
1815 * nothing to do. Eventually SIOCATALKDIFADDR should be moved 1863 * here is compatible, so we can simply call the native
1816 * here so there is no generic SIOCPROTOPRIVATE translation in the 1864 * handler.
1817 * system.
1818 */ 1865 */
1866 if (cmd == SIOCATALKDIFADDR)
1867 return atalk_ioctl(sock, cmd, (unsigned long)compat_ptr(arg));
1868
1819 return -ENOIOCTLCMD; 1869 return -ENOIOCTLCMD;
1820} 1870}
1821#endif 1871#endif
1822 1872
1823 1873
1824static struct net_proto_family atalk_family_ops = { 1874static const struct net_proto_family atalk_family_ops = {
1825 .family = PF_APPLETALK, 1875 .family = PF_APPLETALK,
1826 .create = atalk_create, 1876 .create = atalk_create,
1827 .owner = THIS_MODULE, 1877 .owner = THIS_MODULE,
1828}; 1878};
1829 1879
1830static const struct proto_ops SOCKOPS_WRAPPED(atalk_dgram_ops) = { 1880static const struct proto_ops atalk_dgram_ops = {
1831 .family = PF_APPLETALK, 1881 .family = PF_APPLETALK,
1832 .owner = THIS_MODULE, 1882 .owner = THIS_MODULE,
1833 .release = atalk_release, 1883 .release = atalk_release,
@@ -1836,7 +1886,7 @@ static const struct proto_ops SOCKOPS_WRAPPED(atalk_dgram_ops) = {
1836 .socketpair = sock_no_socketpair, 1886 .socketpair = sock_no_socketpair,
1837 .accept = sock_no_accept, 1887 .accept = sock_no_accept,
1838 .getname = atalk_getname, 1888 .getname = atalk_getname,
1839 .poll = datagram_poll, 1889 .poll = atalk_poll,
1840 .ioctl = atalk_ioctl, 1890 .ioctl = atalk_ioctl,
1841#ifdef CONFIG_COMPAT 1891#ifdef CONFIG_COMPAT
1842 .compat_ioctl = atalk_compat_ioctl, 1892 .compat_ioctl = atalk_compat_ioctl,
@@ -1851,8 +1901,6 @@ static const struct proto_ops SOCKOPS_WRAPPED(atalk_dgram_ops) = {
1851 .sendpage = sock_no_sendpage, 1901 .sendpage = sock_no_sendpage,
1852}; 1902};
1853 1903
1854SOCKOPS_WRAP(atalk_dgram, PF_APPLETALK);
1855
1856static struct notifier_block ddp_notifier = { 1904static struct notifier_block ddp_notifier = {
1857 .notifier_call = ddp_device_event, 1905 .notifier_call = ddp_device_event,
1858}; 1906};