27 #include <linux/kernel.h>
28 #include <linux/net.h>
29 #include <linux/poll.h>
33 #include <linux/phonet.h>
34 #include <linux/export.h>
39 static int pn_socket_release(
struct socket *
sock)
41 struct sock *
sk = sock->
sk;
45 sk->sk_prot->close(sk, 0);
50 #define PN_HASHSIZE 16
51 #define PN_HASHMASK (PN_HASHSIZE-1)
81 struct sock *rval =
NULL;
82 u16 obj = pn_sockaddr_get_object(spn);
91 if (!net_eq(sock_net(sknode), net))
95 if (pn_port(pn->
sobject) != pn_port(obj))
103 pn_addr(pn->
sobject) != pn_addr(obj))
129 if (!net_eq(sock_net(sknode), net))
150 sk_add_node_rcu(sk, hlist);
169 struct sock *sk = sock->
sk;
176 if (sk->sk_prot->bind)
177 return sk->sk_prot->bind(sk, addr, len);
184 handle = pn_sockaddr_get_object((
struct sockaddr_pn *)addr);
185 saddr = pn_addr(handle);
196 err = sk->sk_prot->get_port(sk, pn_port(handle));
205 sk->sk_prot->hash(sk);
213 static int pn_socket_autobind(
struct socket *sock)
220 err = pn_socket_bind(sock, (
struct sockaddr *)&
sa,
224 BUG_ON(!pn_port(pn_sk(sock->
sk)->sobject));
228 static int pn_socket_connect(
struct socket *sock,
struct sockaddr *addr,
231 struct sock *sk = sock->
sk;
232 struct pn_sock *pn = pn_sk(sk);
235 long timeo = sock_rcvtimeo(sk, flags &
O_NONBLOCK);
238 if (pn_socket_autobind(sock))
247 switch (sock->
state) {
262 pn->
dobject = pn_sockaddr_get_object(spn);
263 pn->
resource = pn_sockaddr_get_resource(spn);
266 err = sk->sk_prot->connect(sk, addr, len);
280 if (signal_pending(tsk)) {
281 err = sock_intr_errno(timeo);
305 static int pn_socket_accept(
struct socket *sock,
struct socket *newsock,
308 struct sock *sk = sock->
sk;
315 newsk = sk->sk_prot->accept(sk, flags, &err);
320 sock_graft(newsk, newsock);
326 static int pn_socket_getname(
struct socket *sock,
struct sockaddr *addr,
327 int *sockaddr_len,
int peer)
329 struct sock *sk = sock->
sk;
330 struct pn_sock *pn = pn_sk(sk);
342 static unsigned int pn_socket_poll(
struct file *
file,
struct socket *sock,
345 struct sock *sk = sock->
sk;
347 unsigned int mask = 0;
349 poll_wait(file, sk_sleep(sk), wait);
368 static int pn_socket_ioctl(
struct socket *sock,
unsigned int cmd,
371 struct sock *sk = sock->
sk;
372 struct pn_sock *pn = pn_sk(sk);
383 if (sk->sk_bound_dev_if)
385 sk->sk_bound_dev_if);
399 handle = pn_object(saddr, pn_port(pn->
sobject));
403 return sk->sk_prot->ioctl(sk, cmd, arg);
406 static int pn_socket_listen(
struct socket *sock,
int backlog)
408 struct sock *sk = sock->
sk;
411 if (pn_socket_autobind(sock))
433 struct sock *sk = sock->
sk;
435 if (pn_socket_autobind(sock))
438 return sk->sk_prot->sendmsg(iocb, sk, m, total_len);
444 .release = pn_socket_release,
445 .bind = pn_socket_bind,
449 .getname = pn_socket_getname,
451 .ioctl = pn_socket_ioctl,
460 .sendmsg = pn_socket_sendmsg,
469 .release = pn_socket_release,
470 .bind = pn_socket_bind,
471 .connect = pn_socket_connect,
473 .accept = pn_socket_accept,
474 .getname = pn_socket_getname,
475 .poll = pn_socket_poll,
476 .ioctl = pn_socket_ioctl,
477 .listen = pn_socket_listen,
485 .sendmsg = pn_socket_sendmsg,
496 struct net *
net = sock_net(sk);
497 struct pn_sock *pn = pn_sk(sk);
503 WARN_ON(!mutex_is_locked(&port_mutex));
506 int port, pmin, pmax;
509 for (port = pmin; port <= pmax; port++) {
511 if (port_cur < pmin || port_cur > pmax)
514 pn_sockaddr_set_port(&try_sa, port_cur);
524 pn_sockaddr_set_port(&try_sa, sport);
541 #ifdef CONFIG_PROC_FS
542 static struct sock *pn_sock_get_idx(
struct seq_file *seq, loff_t
pos)
544 struct net *
net = seq_file_net(seq);
552 if (!net_eq(net, sock_net(sknode)))
563 static struct sock *pn_sock_get_next(
struct seq_file *seq,
struct sock *sk)
565 struct net *net = seq_file_net(seq);
569 while (sk && !net_eq(net, sock_net(sk)));
574 static void *pn_sock_seq_start(
struct seq_file *seq, loff_t *pos)
581 static void *pn_sock_seq_next(
struct seq_file *seq,
void *
v, loff_t *pos)
586 sk = pn_sock_get_idx(seq, 0);
588 sk = pn_sock_get_next(seq, v);
593 static void pn_sock_seq_stop(
struct seq_file *seq,
void *v)
599 static int pn_sock_seq_show(
struct seq_file *seq,
void *v)
604 seq_printf(seq,
"%s%n",
"pt loc rem rs st tx_queue rx_queue "
605 " uid inode ref pointer drops", &len);
608 struct pn_sock *pn = pn_sk(sk);
610 seq_printf(seq,
"%2d %04X:%04X:%02X %02X %08X:%08X %5d %lu "
614 sk_wmem_alloc_get(sk), sk_rmem_alloc_get(sk),
625 .
start = pn_sock_seq_start,
626 .next = pn_sock_seq_next,
627 .stop = pn_sock_seq_stop,
628 .show = pn_sock_seq_show,
631 static int pn_sock_open(
struct inode *
inode,
struct file *file)
639 .open = pn_sock_open,
647 struct sock *sk[256];
674 if (!net_eq(sock_net(sk), &
init_net))
682 if (pnres.sk[res] ==
NULL) {
699 if (pnres.sk[res] == sk) {
717 for (res = 0; res < 256; res++) {
718 if (pnres.sk[res] == sk) {
732 #ifdef CONFIG_PROC_FS
733 static struct sock **pn_res_get_idx(
struct seq_file *seq, loff_t pos)
735 struct net *net = seq_file_net(seq);
741 for (i = 0; i < 256; i++) {
742 if (pnres.sk[i] ==
NULL)
751 static struct sock **pn_res_get_next(
struct seq_file *seq,
struct sock **sk)
753 struct net *net = seq_file_net(seq);
758 for (i = (sk - pnres.sk) + 1; i < 256; i++)
764 static void *pn_res_seq_start(
struct seq_file *seq, loff_t *pos)
771 static void *pn_res_seq_next(
struct seq_file *seq,
void *v, loff_t *pos)
776 sk = pn_res_get_idx(seq, 0);
778 sk = pn_res_get_next(seq, v);
783 static void pn_res_seq_stop(
struct seq_file *seq,
void *v)
789 static int pn_res_seq_show(
struct seq_file *seq,
void *v)
794 seq_printf(seq,
"%s%n",
"rs uid inode", &len);
796 struct sock **psk =
v;
797 struct sock *sk = *psk;
800 (
int) (psk - pnres.sk),
809 .
start = pn_res_seq_start,
810 .next = pn_res_seq_next,
811 .stop = pn_res_seq_stop,
812 .show = pn_res_seq_show,
815 static int pn_res_open(
struct inode *inode,
struct file *file)