mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2025-01-10 15:10:38 +00:00
Phonet: receive pipe control requests as out-of-band data
Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
9641458d3e
commit
c41bd97f81
@ -33,6 +33,8 @@ struct pep_sock {
|
|||||||
|
|
||||||
/* Connected socket stuff: */
|
/* Connected socket stuff: */
|
||||||
struct sock *listener;
|
struct sock *listener;
|
||||||
|
struct sk_buff_head ctrlreq_queue;
|
||||||
|
#define PNPIPE_CTRLREQ_MAX 10
|
||||||
u16 peer_type; /* peer type/subtype */
|
u16 peer_type; /* peer type/subtype */
|
||||||
u8 pipe_handle;
|
u8 pipe_handle;
|
||||||
|
|
||||||
|
@ -137,14 +137,15 @@ static int pep_reject_conn(struct sock *sk, struct sk_buff *skb, u8 code)
|
|||||||
|
|
||||||
/* Control requests are not sent by the pipe service and have a specific
|
/* Control requests are not sent by the pipe service and have a specific
|
||||||
* message format. */
|
* message format. */
|
||||||
static int pep_ctrlreq_error(struct sock *sk, struct sk_buff *oskb, u8 code)
|
static int pep_ctrlreq_error(struct sock *sk, struct sk_buff *oskb, u8 code,
|
||||||
|
gfp_t priority)
|
||||||
{
|
{
|
||||||
const struct pnpipehdr *oph = pnp_hdr(oskb);
|
const struct pnpipehdr *oph = pnp_hdr(oskb);
|
||||||
struct sk_buff *skb;
|
struct sk_buff *skb;
|
||||||
struct pnpipehdr *ph;
|
struct pnpipehdr *ph;
|
||||||
struct sockaddr_pn dst;
|
struct sockaddr_pn dst;
|
||||||
|
|
||||||
skb = alloc_skb(MAX_PNPIPE_HEADER + 4, GFP_ATOMIC);
|
skb = alloc_skb(MAX_PNPIPE_HEADER + 4, priority);
|
||||||
if (!skb)
|
if (!skb)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
skb_set_owner_w(skb, sk);
|
skb_set_owner_w(skb, sk);
|
||||||
@ -305,6 +306,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
|
|||||||
{
|
{
|
||||||
struct pep_sock *pn = pep_sk(sk);
|
struct pep_sock *pn = pep_sk(sk);
|
||||||
struct pnpipehdr *hdr = pnp_hdr(skb);
|
struct pnpipehdr *hdr = pnp_hdr(skb);
|
||||||
|
struct sk_buff_head *queue;
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
BUG_ON(sk->sk_state == TCP_CLOSE_WAIT);
|
BUG_ON(sk->sk_state == TCP_CLOSE_WAIT);
|
||||||
@ -345,9 +347,11 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case PNS_PEP_CTRL_REQ:
|
case PNS_PEP_CTRL_REQ:
|
||||||
/* TODO */
|
if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX)
|
||||||
pep_ctrlreq_error(sk, skb, PN_PIPE_NO_ERROR);
|
|
||||||
break;
|
break;
|
||||||
|
__skb_pull(skb, 4);
|
||||||
|
queue = &pn->ctrlreq_queue;
|
||||||
|
goto queue;
|
||||||
|
|
||||||
case PNS_PIPE_DATA:
|
case PNS_PIPE_DATA:
|
||||||
__skb_pull(skb, 3); /* Pipe data header */
|
__skb_pull(skb, 3); /* Pipe data header */
|
||||||
@ -363,13 +367,8 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
pn->rx_credits--;
|
pn->rx_credits--;
|
||||||
skb->dev = NULL;
|
queue = &sk->sk_receive_queue;
|
||||||
skb_set_owner_r(skb, sk);
|
goto queue;
|
||||||
err = skb->len;
|
|
||||||
skb_queue_tail(&sk->sk_receive_queue, skb);
|
|
||||||
if (!sock_flag(sk, SOCK_DEAD))
|
|
||||||
sk->sk_data_ready(sk, err);
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
case PNS_PEP_STATUS_IND:
|
case PNS_PEP_STATUS_IND:
|
||||||
pipe_rcv_status(sk, skb);
|
pipe_rcv_status(sk, skb);
|
||||||
@ -412,12 +411,24 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
|
|||||||
out:
|
out:
|
||||||
kfree_skb(skb);
|
kfree_skb(skb);
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
|
queue:
|
||||||
|
skb->dev = NULL;
|
||||||
|
skb_set_owner_r(skb, sk);
|
||||||
|
err = skb->len;
|
||||||
|
skb_queue_tail(queue, skb);
|
||||||
|
if (!sock_flag(sk, SOCK_DEAD))
|
||||||
|
sk->sk_data_ready(sk, err);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Destroy connected sock. */
|
/* Destroy connected sock. */
|
||||||
static void pipe_destruct(struct sock *sk)
|
static void pipe_destruct(struct sock *sk)
|
||||||
{
|
{
|
||||||
|
struct pep_sock *pn = pep_sk(sk);
|
||||||
|
|
||||||
skb_queue_purge(&sk->sk_receive_queue);
|
skb_queue_purge(&sk->sk_receive_queue);
|
||||||
|
skb_queue_purge(&pn->ctrlreq_queue);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int pep_connreq_rcv(struct sock *sk, struct sk_buff *skb)
|
static int pep_connreq_rcv(struct sock *sk, struct sk_buff *skb)
|
||||||
@ -490,6 +501,7 @@ static int pep_connreq_rcv(struct sock *sk, struct sk_buff *skb)
|
|||||||
pn_skb_get_dst_sockaddr(skb, &dst);
|
pn_skb_get_dst_sockaddr(skb, &dst);
|
||||||
newpn->pn_sk.sobject = pn_sockaddr_get_object(&dst);
|
newpn->pn_sk.sobject = pn_sockaddr_get_object(&dst);
|
||||||
newpn->pn_sk.resource = pn->pn_sk.resource;
|
newpn->pn_sk.resource = pn->pn_sk.resource;
|
||||||
|
skb_queue_head_init(&newpn->ctrlreq_queue);
|
||||||
newpn->pipe_handle = pipe_handle;
|
newpn->pipe_handle = pipe_handle;
|
||||||
newpn->peer_type = peer_type;
|
newpn->peer_type = peer_type;
|
||||||
newpn->rx_credits = newpn->tx_credits = 0;
|
newpn->rx_credits = newpn->tx_credits = 0;
|
||||||
@ -581,7 +593,7 @@ static int pep_do_rcv(struct sock *sk, struct sk_buff *skb)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case PNS_PEP_CTRL_REQ:
|
case PNS_PEP_CTRL_REQ:
|
||||||
pep_ctrlreq_error(sk, skb, PN_PIPE_INVALID_HANDLE);
|
pep_ctrlreq_error(sk, skb, PN_PIPE_INVALID_HANDLE, GFP_ATOMIC);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case PNS_PEP_RESET_REQ:
|
case PNS_PEP_RESET_REQ:
|
||||||
@ -684,6 +696,7 @@ out:
|
|||||||
|
|
||||||
static int pep_ioctl(struct sock *sk, int cmd, unsigned long arg)
|
static int pep_ioctl(struct sock *sk, int cmd, unsigned long arg)
|
||||||
{
|
{
|
||||||
|
struct pep_sock *pn = pep_sk(sk);
|
||||||
int answ;
|
int answ;
|
||||||
|
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
@ -692,7 +705,10 @@ static int pep_ioctl(struct sock *sk, int cmd, unsigned long arg)
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
lock_sock(sk);
|
lock_sock(sk);
|
||||||
if (!skb_queue_empty(&sk->sk_receive_queue))
|
if (sock_flag(sk, SOCK_URGINLINE)
|
||||||
|
&& !skb_queue_empty(&pn->ctrlreq_queue))
|
||||||
|
answ = skb_peek(&pn->ctrlreq_queue)->len;
|
||||||
|
else if (!skb_queue_empty(&sk->sk_receive_queue))
|
||||||
answ = skb_peek(&sk->sk_receive_queue)->len;
|
answ = skb_peek(&sk->sk_receive_queue)->len;
|
||||||
else
|
else
|
||||||
answ = 0;
|
answ = 0;
|
||||||
@ -709,6 +725,7 @@ static int pep_init(struct sock *sk)
|
|||||||
|
|
||||||
INIT_HLIST_HEAD(&pn->ackq);
|
INIT_HLIST_HEAD(&pn->ackq);
|
||||||
INIT_HLIST_HEAD(&pn->hlist);
|
INIT_HLIST_HEAD(&pn->hlist);
|
||||||
|
skb_queue_head_init(&pn->ctrlreq_queue);
|
||||||
pn->pipe_handle = PN_PIPE_INVALID_HANDLE;
|
pn->pipe_handle = PN_PIPE_INVALID_HANDLE;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -810,11 +827,24 @@ static int pep_recvmsg(struct kiocb *iocb, struct sock *sk,
|
|||||||
struct sk_buff *skb;
|
struct sk_buff *skb;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (unlikely(flags & MSG_OOB))
|
|
||||||
return -EOPNOTSUPP;
|
|
||||||
if (unlikely(1 << sk->sk_state & (TCPF_LISTEN | TCPF_CLOSE)))
|
if (unlikely(1 << sk->sk_state & (TCPF_LISTEN | TCPF_CLOSE)))
|
||||||
return -ENOTCONN;
|
return -ENOTCONN;
|
||||||
|
|
||||||
|
if ((flags & MSG_OOB) || sock_flag(sk, SOCK_URGINLINE)) {
|
||||||
|
/* Dequeue and acknowledge control request */
|
||||||
|
struct pep_sock *pn = pep_sk(sk);
|
||||||
|
|
||||||
|
skb = skb_dequeue(&pn->ctrlreq_queue);
|
||||||
|
if (skb) {
|
||||||
|
pep_ctrlreq_error(sk, skb, PN_PIPE_NO_ERROR,
|
||||||
|
GFP_KERNEL);
|
||||||
|
msg->msg_flags |= MSG_OOB;
|
||||||
|
goto copy;
|
||||||
|
}
|
||||||
|
if (flags & MSG_OOB)
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
skb = skb_recv_datagram(sk, flags, noblock, &err);
|
skb = skb_recv_datagram(sk, flags, noblock, &err);
|
||||||
lock_sock(sk);
|
lock_sock(sk);
|
||||||
if (skb == NULL) {
|
if (skb == NULL) {
|
||||||
@ -827,9 +857,8 @@ static int pep_recvmsg(struct kiocb *iocb, struct sock *sk,
|
|||||||
if (sk->sk_state == TCP_ESTABLISHED)
|
if (sk->sk_state == TCP_ESTABLISHED)
|
||||||
pipe_grant_credits(sk);
|
pipe_grant_credits(sk);
|
||||||
release_sock(sk);
|
release_sock(sk);
|
||||||
|
copy:
|
||||||
msg->msg_flags |= MSG_EOR;
|
msg->msg_flags |= MSG_EOR;
|
||||||
|
|
||||||
if (skb->len > len)
|
if (skb->len > len)
|
||||||
msg->msg_flags |= MSG_TRUNC;
|
msg->msg_flags |= MSG_TRUNC;
|
||||||
else
|
else
|
||||||
|
@ -220,7 +220,9 @@ static unsigned int pn_socket_poll(struct file *file, struct socket *sock,
|
|||||||
|
|
||||||
if (!skb_queue_empty(&sk->sk_receive_queue))
|
if (!skb_queue_empty(&sk->sk_receive_queue))
|
||||||
mask |= POLLIN | POLLRDNORM;
|
mask |= POLLIN | POLLRDNORM;
|
||||||
else if (sk->sk_state == TCP_CLOSE_WAIT)
|
if (!skb_queue_empty(&pn->ctrlreq_queue))
|
||||||
|
mask |= POLLPRI;
|
||||||
|
if (!mask && sk->sk_state == TCP_CLOSE_WAIT)
|
||||||
return POLLHUP;
|
return POLLHUP;
|
||||||
|
|
||||||
if (sk->sk_state == TCP_ESTABLISHED && pn->tx_credits)
|
if (sk->sk_state == TCP_ESTABLISHED && pn->tx_credits)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user