13 #include <linux/capability.h>
14 #include <linux/module.h>
17 #include <linux/errno.h>
18 #include <linux/types.h>
19 #include <linux/socket.h>
21 #include <linux/slab.h>
22 #include <linux/kernel.h>
23 #include <linux/sched.h>
26 #include <linux/string.h>
28 #include <linux/net.h>
29 #include <linux/stat.h>
33 #include <linux/netdevice.h>
34 #include <linux/if_arp.h>
37 #include <asm/uaccess.h>
38 #include <linux/fcntl.h>
50 static int rose_ndevs = 10;
66 static const struct proto_ops rose_proto_ops;
89 netdev_for_each_tx_queue(dev, rose_set_lockdep_one,
NULL);
119 for (i = 0; i < 5; i++)
136 for (i = 0; i <
mask; i++) {
154 static void rose_remove_socket(
struct sock *
sk)
156 spin_lock_bh(&rose_list_lock);
157 sk_del_node_init(sk);
158 spin_unlock_bh(&rose_list_lock);
170 spin_lock_bh(&rose_list_lock);
180 spin_unlock_bh(&rose_list_lock);
191 spin_lock_bh(&rose_list_lock);
195 if (rose->
device == dev) {
201 spin_unlock_bh(&rose_list_lock);
212 if (!net_eq(dev_net(dev), &
init_net))
220 rose_kill_by_device(dev);
234 static void rose_insert_socket(
struct sock *
sk)
237 spin_lock_bh(&rose_list_lock);
238 sk_add_node(sk, &rose_list);
239 spin_unlock_bh(&rose_list_lock);
251 spin_lock_bh(&rose_list_lock);
271 spin_unlock_bh(&rose_list_lock);
283 spin_lock_bh(&rose_list_lock);
292 spin_unlock_bh(&rose_list_lock);
324 static void rose_destroy_timer(
unsigned long data)
339 rose_remove_socket(sk);
357 if (sk_has_allocations(sk)) {
361 sk->sk_timer.expires =
jiffies + 10 *
HZ;
372 static int rose_setsockopt(
struct socket *
sock,
int level,
int optname,
373 char __user *optval,
unsigned int optlen)
375 struct sock *
sk = sock->
sk;
382 if (optlen <
sizeof(
int))
385 if (
get_user(opt, (
int __user *)optval))
390 rose->
defer = opt ? 1 : 0;
420 rose->
idle = opt * 60 *
HZ;
432 static int rose_getsockopt(
struct socket *sock,
int level,
int optname,
433 char __user *optval,
int __user *optlen)
435 struct sock *sk = sock->
sk;
471 val = rose->
idle / (60 *
HZ);
482 len =
min_t(
unsigned int, len,
sizeof(
int));
492 struct sock *sk = sock->
sk;
509 static struct proto rose_proto = {
537 skb_queue_head_init(&rose->frag_queue);
541 sock->
ops = &rose_proto_ops;
558 static struct sock *rose_make_new(
struct sock *osk)
576 skb_queue_head_init(&rose->frag_queue);
586 sock_copy_flags(sk, osk);
592 rose->
t1 = orose->
t1;
593 rose->
t2 = orose->
t2;
594 rose->
t3 = orose->
t3;
595 rose->
hb = orose->
hb;
604 static int rose_release(
struct socket *sock)
606 struct sock *sk = sock->
sk;
609 if (sk ==
NULL)
return 0;
616 switch (rose->
state) {
661 struct sock *sk = sock->
sk;
713 rose_insert_socket(sk);
720 static int rose_connect(
struct socket *sock,
struct sockaddr *uaddr,
int addr_len,
int flags)
722 struct sock *sk = sock->
sk;
725 unsigned char cause, diagnostic;
801 rose_insert_socket(sk);
848 if (!signal_pending(
current)) {
865 err = sock_error(sk);
877 static int rose_accept(
struct socket *sock,
struct socket *newsock,
int flags)
885 if ((sk = sock->
sk) ==
NULL)
910 if (flags & O_NONBLOCK) {
914 if (!signal_pending(
current)) {
928 sock_graft(newsk, newsock);
941 static int rose_getname(
struct socket *sock,
struct sockaddr *uaddr,
942 int *uaddr_len,
int peer)
945 struct sock *sk = sock->
sk;
949 memset(srose, 0,
sizeof(*srose));
999 if (sk ==
NULL || sk_acceptq_is_full(sk) ||
1000 (make = rose_make_new(sk)) ==
NULL) {
1009 make_rose->
lci = lci;
1041 rose_insert_socket(make);
1056 struct sock *sk = sock->
sk;
1062 unsigned char *asmptr;
1063 int n,
size, qbit = 0;
1079 if (usrose !=
NULL) {
1125 skb_reset_transport_header(skb);
1139 qbit = skb->
data[0];
1146 asmptr =
skb_push(skb, ROSE_MIN_LEN);
1150 asmptr[1] = (rose->
lci >> 0) & 0xFF;
1162 #define ROSE_PACLEN (256-ROSE_MIN_LEN)
1163 if (skb->
len - ROSE_MIN_LEN > ROSE_PACLEN) {
1170 skb_copy_from_linear_data(skb, header, ROSE_MIN_LEN);
1173 frontlen = skb_headroom(skb);
1175 while (skb->
len > 0) {
1185 skb_reserve(skbn, frontlen);
1187 lg = (ROSE_PACLEN > skb->
len) ? skb->
len : ROSE_PACLEN;
1190 skb_copy_from_linear_data(skb,
skb_put(skbn, lg), lg);
1195 skb_copy_to_linear_data(skbn, header, ROSE_MIN_LEN);
1198 skbn->
data[2] |= M_BIT;
1218 static int rose_recvmsg(
struct kiocb *iocb,
struct socket *sock,
1221 struct sock *sk = sock->
sk;
1225 unsigned char *asmptr;
1249 skb_reset_transport_header(skb);
1252 if (copied > size) {
1259 if (srose !=
NULL) {
1284 static int rose_ioctl(
struct socket *sock,
unsigned int cmd,
unsigned long arg)
1286 struct sock *sk = sock->
sk;
1294 amount = sk->
sk_sndbuf - sk_wmem_alloc_get(sk);
1297 return put_user(amount, (
unsigned int __user *) argp);
1306 return put_user(amount, (
unsigned int __user *) argp);
1345 rose->
cause = rose_cause.cause;
1384 #ifdef CONFIG_PROC_FS
1385 static void *rose_info_start(
struct seq_file *seq, loff_t *
pos)
1388 spin_lock_bh(&rose_list_lock);
1392 static void *rose_info_next(
struct seq_file *seq,
void *
v, loff_t *
pos)
1397 static void rose_info_stop(
struct seq_file *seq,
void *
v)
1400 spin_unlock_bh(&rose_list_lock);
1403 static int rose_info_show(
struct seq_file *seq,
void *
v)
1405 char buf[11], rsbuf[11];
1409 "dest_addr dest_call src_addr src_call dev lci neigh st vs vr va t t1 t2 t3 hb idle Snd-Q Rcv-Q inode\n");
1412 struct sock *s = sk_entry(v);
1414 const char *devname, *callsign;
1420 devname = dev->
name;
1427 callsign =
"??????-?";
1432 "%-10s %-9s %-5s %3.3X %05d %d %d %d %d %3lu %3lu %3lu %3lu %3lu %3lu/%03lu %5d %5d %ld\n",
1448 rose->
idle / (60 * HZ),
1449 sk_wmem_alloc_get(s),
1450 sk_rmem_alloc_get(s),
1458 .
start = rose_info_start,
1459 .next = rose_info_next,
1460 .stop = rose_info_stop,
1461 .show = rose_info_show,
1466 return seq_open(file, &rose_info_seqops);
1471 .open = rose_info_open,
1480 .create = rose_create,
1484 static const struct proto_ops rose_proto_ops = {
1487 .release = rose_release,
1489 .connect = rose_connect,
1491 .accept = rose_accept,
1492 .getname = rose_getname,
1494 .ioctl = rose_ioctl,
1495 .listen = rose_listen,
1497 .setsockopt = rose_setsockopt,
1498 .getsockopt = rose_getsockopt,
1499 .sendmsg = rose_sendmsg,
1500 .recvmsg = rose_recvmsg,
1506 .notifier_call = rose_device_event,
1520 static int __init rose_proto_init(
void)
1525 if (rose_ndevs > 0x7FFFFFFF/
sizeof(
struct net_device *)) {
1526 printk(
KERN_ERR "ROSE: rose_proto_init - rose_ndevs parameter to large\n");
1538 if (dev_rose ==
NULL) {
1539 printk(
KERN_ERR "ROSE: rose_proto_init - unable to allocate device structure\n");
1541 goto out_proto_unregister;
1544 for (i = 0; i < rose_ndevs; i++) {
1551 printk(
KERN_ERR "ROSE: rose_proto_init - unable to allocate memory\n");
1561 rose_set_lockdep_key(dev);
1571 #ifdef CONFIG_SYSCTL
1590 out_proto_unregister:
1604 static void __exit rose_exit(
void)
1622 #ifdef CONFIG_SYSCTL
1629 for (i = 0; i < rose_ndevs; i++) {