* [PATCH 1/6] Phonet: allow multiple listen() and fix small race condition
2011-02-25 9:13 [PATCH net-next 0/6] Phonet: small pipe protocol fixes Rémi Denis-Courmont
@ 2011-02-25 9:14 ` Rémi Denis-Courmont
2011-02-25 9:14 ` [PATCH 2/6] Phonet: implement per-socket destination/peer address Rémi Denis-Courmont
` (5 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: Rémi Denis-Courmont @ 2011-02-25 9:14 UTC (permalink / raw)
To: netdev
Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
---
net/phonet/socket.c | 10 +++++-----
1 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/net/phonet/socket.c b/net/phonet/socket.c
index 25f746d..ceb5143 100644
--- a/net/phonet/socket.c
+++ b/net/phonet/socket.c
@@ -428,19 +428,19 @@ static int pn_socket_listen(struct socket *sock, int backlog)
struct sock *sk = sock->sk;
int err = 0;
- if (sock->state != SS_UNCONNECTED)
- return -EINVAL;
if (pn_socket_autobind(sock))
return -ENOBUFS;
lock_sock(sk);
- if (sk->sk_state != TCP_CLOSE) {
+ if (sock->state != SS_UNCONNECTED) {
err = -EINVAL;
goto out;
}
- sk->sk_state = TCP_LISTEN;
- sk->sk_ack_backlog = 0;
+ if (sk->sk_state != TCP_LISTEN) {
+ sk->sk_state = TCP_LISTEN;
+ sk->sk_ack_backlog = 0;
+ }
sk->sk_max_ack_backlog = backlog;
out:
release_sock(sk);
--
1.7.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 2/6] Phonet: implement per-socket destination/peer address
2011-02-25 9:13 [PATCH net-next 0/6] Phonet: small pipe protocol fixes Rémi Denis-Courmont
2011-02-25 9:14 ` [PATCH 1/6] Phonet: allow multiple listen() and fix small race condition Rémi Denis-Courmont
@ 2011-02-25 9:14 ` Rémi Denis-Courmont
2011-02-25 9:14 ` [PATCH 3/6] Phonet: use socket destination in pipe protocol Rémi Denis-Courmont
` (4 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: Rémi Denis-Courmont @ 2011-02-25 9:14 UTC (permalink / raw)
To: netdev
Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
---
include/net/phonet/phonet.h | 1 +
net/phonet/af_phonet.c | 19 ++++++++++++++-----
net/phonet/socket.c | 4 ++--
3 files changed, 17 insertions(+), 7 deletions(-)
diff --git a/include/net/phonet/phonet.h b/include/net/phonet/phonet.h
index 5395e09..68e5097 100644
--- a/include/net/phonet/phonet.h
+++ b/include/net/phonet/phonet.h
@@ -36,6 +36,7 @@
struct pn_sock {
struct sock sk;
u16 sobject;
+ u16 dobject;
u8 resource;
};
diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
index 1072b2c..30cc676 100644
--- a/net/phonet/af_phonet.c
+++ b/net/phonet/af_phonet.c
@@ -110,6 +110,7 @@ static int pn_socket_create(struct net *net, struct socket *sock, int protocol,
sk->sk_protocol = protocol;
pn = pn_sk(sk);
pn->sobject = 0;
+ pn->dobject = 0;
pn->resource = 0;
sk->sk_prot->init(sk);
err = 0;
@@ -242,8 +243,18 @@ int pn_skb_send(struct sock *sk, struct sk_buff *skb,
struct net_device *dev;
struct pn_sock *pn = pn_sk(sk);
int err;
- u16 src;
- u8 daddr = pn_sockaddr_get_addr(target), saddr = PN_NO_ADDR;
+ u16 src, dst;
+ u8 daddr, saddr, res;
+
+ src = pn->sobject;
+ if (target != NULL) {
+ dst = pn_sockaddr_get_object(target);
+ res = pn_sockaddr_get_resource(target);
+ } else {
+ dst = pn->dobject;
+ res = pn->resource;
+ }
+ daddr = pn_addr(dst);
err = -EHOSTUNREACH;
if (sk->sk_bound_dev_if)
@@ -271,12 +282,10 @@ int pn_skb_send(struct sock *sk, struct sk_buff *skb,
if (saddr == PN_NO_ADDR)
goto drop;
- src = pn->sobject;
if (!pn_addr(src))
src = pn_object(saddr, pn_obj(src));
- err = pn_send(skb, dev, pn_sockaddr_get_object(target),
- src, pn_sockaddr_get_resource(target), 0);
+ err = pn_send(skb, dev, dst, src, res, 0);
dev_put(dev);
return err;
diff --git a/net/phonet/socket.c b/net/phonet/socket.c
index ceb5143..65a0333 100644
--- a/net/phonet/socket.c
+++ b/net/phonet/socket.c
@@ -633,8 +633,8 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
seq_printf(seq, "%2d %04X:%04X:%02X %02X %08X:%08X %5d %lu "
"%d %p %d%n",
- sk->sk_protocol, pn->sobject, 0, pn->resource,
- sk->sk_state,
+ sk->sk_protocol, pn->sobject, pn->dobject,
+ pn->resource, sk->sk_state,
sk_wmem_alloc_get(sk), sk_rmem_alloc_get(sk),
sock_i_uid(sk), sock_i_ino(sk),
atomic_read(&sk->sk_refcnt), sk,
--
1.7.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 3/6] Phonet: use socket destination in pipe protocol
2011-02-25 9:13 [PATCH net-next 0/6] Phonet: small pipe protocol fixes Rémi Denis-Courmont
2011-02-25 9:14 ` [PATCH 1/6] Phonet: allow multiple listen() and fix small race condition Rémi Denis-Courmont
2011-02-25 9:14 ` [PATCH 2/6] Phonet: implement per-socket destination/peer address Rémi Denis-Courmont
@ 2011-02-25 9:14 ` Rémi Denis-Courmont
2011-02-25 9:14 ` [PATCH 4/6] Phonet: remove redumdant pep->pipe_state Rémi Denis-Courmont
` (3 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: Rémi Denis-Courmont @ 2011-02-25 9:14 UTC (permalink / raw)
To: netdev
Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
---
include/net/phonet/pep.h | 1 -
net/phonet/pep.c | 41 ++++++++++++++++-------------------------
2 files changed, 16 insertions(+), 26 deletions(-)
diff --git a/include/net/phonet/pep.h b/include/net/phonet/pep.h
index b60b28c..788ccf3 100644
--- a/include/net/phonet/pep.h
+++ b/include/net/phonet/pep.h
@@ -47,7 +47,6 @@ struct pep_sock {
u8 aligned;
#ifdef CONFIG_PHONET_PIPECTRLR
u8 pipe_state;
- struct sockaddr_pn remote_pep;
#endif
};
diff --git a/net/phonet/pep.c b/net/phonet/pep.c
index 3e60f2e..4fce882 100644
--- a/net/phonet/pep.c
+++ b/net/phonet/pep.c
@@ -50,11 +50,6 @@
#define CREDITS_MAX 10
#define CREDITS_THR 7
-static const struct sockaddr_pn pipe_srv = {
- .spn_family = AF_PHONET,
- .spn_resource = 0xD9, /* pipe service */
-};
-
#define pep_sb_size(s) (((s) + 5) & ~3) /* 2-bytes head, 32-bits aligned */
/* Get the next TLV sub-block. */
@@ -88,6 +83,7 @@ static int pep_reply(struct sock *sk, struct sk_buff *oskb,
const struct pnpipehdr *oph = pnp_hdr(oskb);
struct pnpipehdr *ph;
struct sk_buff *skb;
+ struct sockaddr_pn peer;
skb = alloc_skb(MAX_PNPIPE_HEADER + len, priority);
if (!skb)
@@ -105,7 +101,8 @@ static int pep_reply(struct sock *sk, struct sk_buff *oskb,
ph->pipe_handle = oph->pipe_handle;
ph->error_code = code;
- return pn_skb_send(sk, skb, &pipe_srv);
+ pn_skb_get_src_sockaddr(oskb, &peer);
+ return pn_skb_send(sk, skb, &peer);
}
#define PAD 0x00
@@ -220,7 +217,7 @@ static int pipe_handler_send_req(struct sock *sk, u8 utid,
ph->pipe_handle = pn->pipe_handle;
ph->error_code = PN_PIPE_NO_ERROR;
- return pn_skb_send(sk, skb, &pn->remote_pep);
+ return pn_skb_send(sk, skb, NULL);
}
static int pipe_handler_send_created_ind(struct sock *sk,
@@ -262,7 +259,7 @@ static int pipe_handler_send_created_ind(struct sock *sk,
ph->pipe_handle = pn->pipe_handle;
ph->error_code = err_code;
- return pn_skb_send(sk, skb, &pn->remote_pep);
+ return pn_skb_send(sk, skb, NULL);
}
static int pipe_handler_send_ind(struct sock *sk, u8 utid, u8 msg_id)
@@ -295,7 +292,7 @@ static int pipe_handler_send_ind(struct sock *sk, u8 utid, u8 msg_id)
ph->pipe_handle = pn->pipe_handle;
ph->error_code = err_code;
- return pn_skb_send(sk, skb, &pn->remote_pep);
+ return pn_skb_send(sk, skb, NULL);
}
static int pipe_handler_enable_pipe(struct sock *sk, int enable)
@@ -396,11 +393,7 @@ static int pipe_snd_status(struct sock *sk, u8 type, u8 status, gfp_t priority)
ph->data[3] = PAD;
ph->data[4] = status;
-#ifdef CONFIG_PHONET_PIPECTRLR
- return pn_skb_send(sk, skb, &pn->remote_pep);
-#else
- return pn_skb_send(sk, skb, &pipe_srv);
-#endif
+ return pn_skb_send(sk, skb, NULL);
}
/* Send our RX flow control information to the sender.
@@ -722,7 +715,7 @@ static int pep_connreq_rcv(struct sock *sk, struct sk_buff *skb)
struct sock *newsk;
struct pep_sock *newpn, *pn = pep_sk(sk);
struct pnpipehdr *hdr;
- struct sockaddr_pn dst;
+ struct sockaddr_pn dst, src;
u16 peer_type;
u8 pipe_handle, enabled, n_sb;
u8 aligned = 0;
@@ -789,8 +782,10 @@ static int pep_connreq_rcv(struct sock *sk, struct sk_buff *skb)
newpn = pep_sk(newsk);
pn_skb_get_dst_sockaddr(skb, &dst);
+ pn_skb_get_src_sockaddr(skb, &src);
newpn->pn_sk.sobject = pn_sockaddr_get_object(&dst);
- newpn->pn_sk.resource = pn->pn_sk.resource;
+ newpn->pn_sk.dobject = pn_sockaddr_get_object(&src);
+ newpn->pn_sk.resource = pn_sockaddr_get_resource(&dst);
skb_queue_head_init(&newpn->ctrlreq_queue);
newpn->pipe_handle = pipe_handle;
atomic_set(&newpn->tx_credits, 0);
@@ -925,7 +920,7 @@ static int pipe_do_remove(struct sock *sk)
ph->pipe_handle = pn->pipe_handle;
ph->data[0] = PAD;
- return pn_skb_send(sk, skb, &pipe_srv);
+ return pn_skb_send(sk, skb, NULL);
}
/* associated socket ceases to exist */
@@ -1042,10 +1037,10 @@ out:
static int pep_sock_connect(struct sock *sk, struct sockaddr *addr, int len)
{
struct pep_sock *pn = pep_sk(sk);
- struct sockaddr_pn *spn = (struct sockaddr_pn *)addr;
-
- memcpy(&pn->remote_pep, spn, sizeof(struct sockaddr_pn));
+ const struct sockaddr_pn *spn = (struct sockaddr_pn *)addr;
+ pn->pn_sk.dobject = pn_sockaddr_get_object(spn);
+ pn->pn_sk.resource = pn_sockaddr_get_resource(spn);
return pipe_handler_send_req(sk,
PNS_PEP_CONNECT_UTID, PNS_PEP_CONNECT_REQ,
GFP_ATOMIC);
@@ -1222,11 +1217,7 @@ static int pipe_skb_send(struct sock *sk, struct sk_buff *skb)
} else
ph->message_id = PNS_PIPE_DATA;
ph->pipe_handle = pn->pipe_handle;
-#ifdef CONFIG_PHONET_PIPECTRLR
- err = pn_skb_send(sk, skb, &pn->remote_pep);
-#else
- err = pn_skb_send(sk, skb, &pipe_srv);
-#endif
+ err = pn_skb_send(sk, skb, NULL);
if (err && pn_flow_safe(pn->tx_fc))
atomic_inc(&pn->tx_credits);
--
1.7.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 4/6] Phonet: remove redumdant pep->pipe_state
2011-02-25 9:13 [PATCH net-next 0/6] Phonet: small pipe protocol fixes Rémi Denis-Courmont
` (2 preceding siblings ...)
2011-02-25 9:14 ` [PATCH 3/6] Phonet: use socket destination in pipe protocol Rémi Denis-Courmont
@ 2011-02-25 9:14 ` Rémi Denis-Courmont
2011-02-25 9:15 ` [PATCH 5/6] Phonet: don't bother with transaction IDs (especially for indications) Rémi Denis-Courmont
` (2 subsequent siblings)
6 siblings, 0 replies; 10+ messages in thread
From: Rémi Denis-Courmont @ 2011-02-25 9:14 UTC (permalink / raw)
To: netdev
sk->sk_state already contains the pipe state.
Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
---
include/net/phonet/pep.h | 9 ---------
net/phonet/pep.c | 25 ++++++-------------------
2 files changed, 6 insertions(+), 28 deletions(-)
diff --git a/include/net/phonet/pep.h b/include/net/phonet/pep.h
index 788ccf3..4c48ed8 100644
--- a/include/net/phonet/pep.h
+++ b/include/net/phonet/pep.h
@@ -45,9 +45,6 @@ struct pep_sock {
u8 tx_fc; /* TX flow control */
u8 init_enable; /* auto-enable at creation */
u8 aligned;
-#ifdef CONFIG_PHONET_PIPECTRLR
- u8 pipe_state;
-#endif
};
static inline struct pep_sock *pep_sk(struct sock *sk)
@@ -177,12 +174,6 @@ enum {
#define PNS_PIPE_DISABLED_IND_UTID 0x11
#define PNS_PEP_DISCONNECT_UTID 0x06
-/* Used for tracking state of a pipe */
-enum {
- PIPE_IDLE,
- PIPE_DISABLED,
- PIPE_ENABLED,
-};
#endif /* CONFIG_PHONET_PIPECTRLR */
#endif
diff --git a/net/phonet/pep.c b/net/phonet/pep.c
index 4fce882..15775a7 100644
--- a/net/phonet/pep.c
+++ b/net/phonet/pep.c
@@ -527,7 +527,6 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
#ifdef CONFIG_PHONET_PIPECTRLR
case PNS_PEP_DISCONNECT_RESP:
- pn->pipe_state = PIPE_IDLE;
sk->sk_state = TCP_CLOSE;
break;
#endif
@@ -539,7 +538,6 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
#ifdef CONFIG_PHONET_PIPECTRLR
case PNS_PEP_ENABLE_RESP:
- pn->pipe_state = PIPE_ENABLED;
pipe_handler_send_ind(sk, PNS_PIPE_ENABLED_IND_UTID,
PNS_PIPE_ENABLED_IND);
@@ -574,7 +572,6 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
#ifdef CONFIG_PHONET_PIPECTRLR
case PNS_PEP_DISABLE_RESP:
- pn->pipe_state = PIPE_DISABLED;
atomic_set(&pn->tx_credits, 0);
pipe_handler_send_ind(sk, PNS_PIPE_DISABLED_IND_UTID,
PNS_PIPE_DISABLED_IND);
@@ -692,7 +689,6 @@ static int pep_connresp_rcv(struct sock *sk, struct sk_buff *skb)
remote_pref_rx_fc,
sizeof(host_pref_rx_fc));
- pn->pipe_state = PIPE_DISABLED;
sk->sk_state = TCP_SYN_RECV;
sk->sk_backlog_rcv = pipe_do_rcv;
sk->sk_destruct = pipe_destruct;
@@ -941,21 +937,18 @@ static void pep_sock_close(struct sock *sk, long timeout)
sk_for_each_safe(sknode, p, n, &pn->ackq)
sk_del_node_init(sknode);
sk->sk_state = TCP_CLOSE;
- } else if ((1 << sk->sk_state) & (TCPF_SYN_RECV|TCPF_ESTABLISHED))
+ } else if ((1 << sk->sk_state) & (TCPF_SYN_RECV|TCPF_ESTABLISHED)) {
+#ifndef CONFIG_PHONET_PIPECTRLR
/* Forcefully remove dangling Phonet pipe */
pipe_do_remove(sk);
-
-#ifdef CONFIG_PHONET_PIPECTRLR
- if (pn->pipe_state != PIPE_IDLE) {
+#else
/* send pep disconnect request */
pipe_handler_send_req(sk,
PNS_PEP_DISCONNECT_UTID, PNS_PEP_DISCONNECT_REQ,
GFP_KERNEL);
-
- pn->pipe_state = PIPE_IDLE;
sk->sk_state = TCP_CLOSE;
- }
#endif
+ }
ifindex = pn->ifindex;
pn->ifindex = 0;
@@ -1101,10 +1094,6 @@ static int pep_setsockopt(struct sock *sk, int level, int optname,
#ifdef CONFIG_PHONET_PIPECTRLR
case PNPIPE_PIPE_HANDLE:
if (val) {
- if (pn->pipe_state > PIPE_IDLE) {
- err = -EFAULT;
- break;
- }
pn->pipe_handle = val;
break;
}
@@ -1138,7 +1127,7 @@ static int pep_setsockopt(struct sock *sk, int level, int optname,
#ifdef CONFIG_PHONET_PIPECTRLR
case PNPIPE_ENABLE:
- if (pn->pipe_state <= PIPE_IDLE) {
+ if ((1 << sk->sk_state) & ~(TCPF_SYN_RECV|TCPF_ESTABLISHED)) {
err = -ENOTCONN;
break;
}
@@ -1177,9 +1166,7 @@ static int pep_getsockopt(struct sock *sk, int level, int optname,
#ifdef CONFIG_PHONET_PIPECTRLR
case PNPIPE_ENABLE:
- if (pn->pipe_state <= PIPE_IDLE)
- return -ENOTCONN;
- val = pn->pipe_state != PIPE_DISABLED;
+ val = sk->sk_state == TCP_ESTABLISHED;
break;
#endif
--
1.7.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 5/6] Phonet: don't bother with transaction IDs (especially for indications)
2011-02-25 9:13 [PATCH net-next 0/6] Phonet: small pipe protocol fixes Rémi Denis-Courmont
` (3 preceding siblings ...)
2011-02-25 9:14 ` [PATCH 4/6] Phonet: remove redumdant pep->pipe_state Rémi Denis-Courmont
@ 2011-02-25 9:15 ` Rémi Denis-Courmont
2011-02-25 9:15 ` [PATCH 6/6] Phonet: fix flawed "SYN/ACK" logic Rémi Denis-Courmont
2011-02-25 19:20 ` [PATCH net-next 0/6] Phonet: small pipe protocol fixes David Miller
6 siblings, 0 replies; 10+ messages in thread
From: Rémi Denis-Courmont @ 2011-02-25 9:15 UTC (permalink / raw)
To: netdev
Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
---
include/net/phonet/pep.h | 11 ----------
net/phonet/pep.c | 49 +++++++++++++--------------------------------
2 files changed, 14 insertions(+), 46 deletions(-)
diff --git a/include/net/phonet/pep.h b/include/net/phonet/pep.h
index 4c48ed8..37f23dc 100644
--- a/include/net/phonet/pep.h
+++ b/include/net/phonet/pep.h
@@ -165,15 +165,4 @@ enum {
PEP_IND_READY,
};
-#ifdef CONFIG_PHONET_PIPECTRLR
-#define PNS_PEP_CONNECT_UTID 0x02
-#define PNS_PIPE_CREATED_IND_UTID 0x04
-#define PNS_PIPE_ENABLE_UTID 0x0A
-#define PNS_PIPE_ENABLED_IND_UTID 0x0C
-#define PNS_PIPE_DISABLE_UTID 0x0F
-#define PNS_PIPE_DISABLED_IND_UTID 0x11
-#define PNS_PEP_DISCONNECT_UTID 0x06
-
-#endif /* CONFIG_PHONET_PIPECTRLR */
-
#endif
diff --git a/net/phonet/pep.c b/net/phonet/pep.c
index 15775a7..0ecab59 100644
--- a/net/phonet/pep.c
+++ b/net/phonet/pep.c
@@ -172,8 +172,7 @@ static int pipe_get_flow_info(struct sock *sk, struct sk_buff *skb,
return 0;
}
-static int pipe_handler_send_req(struct sock *sk, u8 utid,
- u8 msg_id, gfp_t priority)
+static int pipe_handler_send_req(struct sock *sk, u8 msg_id, gfp_t priority)
{
int len;
struct pnpipehdr *ph;
@@ -212,7 +211,7 @@ static int pipe_handler_send_req(struct sock *sk, u8 utid,
__skb_push(skb, sizeof(*ph));
skb_reset_transport_header(skb);
ph = pnp_hdr(skb);
- ph->utid = utid;
+ ph->utid = msg_id; /* whatever */
ph->message_id = msg_id;
ph->pipe_handle = pn->pipe_handle;
ph->error_code = PN_PIPE_NO_ERROR;
@@ -220,8 +219,7 @@ static int pipe_handler_send_req(struct sock *sk, u8 utid,
return pn_skb_send(sk, skb, NULL);
}
-static int pipe_handler_send_created_ind(struct sock *sk,
- u8 utid, u8 msg_id)
+static int pipe_handler_send_created_ind(struct sock *sk, u8 msg_id)
{
int err_code;
struct pnpipehdr *ph;
@@ -254,7 +252,7 @@ static int pipe_handler_send_created_ind(struct sock *sk,
__skb_push(skb, sizeof(*ph));
skb_reset_transport_header(skb);
ph = pnp_hdr(skb);
- ph->utid = utid;
+ ph->utid = 0;
ph->message_id = msg_id;
ph->pipe_handle = pn->pipe_handle;
ph->error_code = err_code;
@@ -262,7 +260,7 @@ static int pipe_handler_send_created_ind(struct sock *sk,
return pn_skb_send(sk, skb, NULL);
}
-static int pipe_handler_send_ind(struct sock *sk, u8 utid, u8 msg_id)
+static int pipe_handler_send_ind(struct sock *sk, u8 msg_id)
{
int err_code;
struct pnpipehdr *ph;
@@ -287,7 +285,7 @@ static int pipe_handler_send_ind(struct sock *sk, u8 utid, u8 msg_id)
__skb_push(skb, sizeof(*ph));
skb_reset_transport_header(skb);
ph = pnp_hdr(skb);
- ph->utid = utid;
+ ph->utid = 0;
ph->message_id = msg_id;
ph->pipe_handle = pn->pipe_handle;
ph->error_code = err_code;
@@ -297,16 +295,9 @@ static int pipe_handler_send_ind(struct sock *sk, u8 utid, u8 msg_id)
static int pipe_handler_enable_pipe(struct sock *sk, int enable)
{
- int utid, req;
-
- if (enable) {
- utid = PNS_PIPE_ENABLE_UTID;
- req = PNS_PEP_ENABLE_REQ;
- } else {
- utid = PNS_PIPE_DISABLE_UTID;
- req = PNS_PEP_DISABLE_REQ;
- }
- return pipe_handler_send_req(sk, utid, req, GFP_ATOMIC);
+ u8 id = enable ? PNS_PEP_ENABLE_REQ : PNS_PEP_DISABLE_REQ;
+
+ return pipe_handler_send_req(sk, id, GFP_KERNEL);
}
#endif
@@ -538,8 +529,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
#ifdef CONFIG_PHONET_PIPECTRLR
case PNS_PEP_ENABLE_RESP:
- pipe_handler_send_ind(sk, PNS_PIPE_ENABLED_IND_UTID,
- PNS_PIPE_ENABLED_IND);
+ pipe_handler_send_ind(sk, PNS_PIPE_ENABLED_IND);
if (!pn_flow_safe(pn->tx_fc)) {
atomic_set(&pn->tx_credits, 1);
@@ -573,8 +563,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
#ifdef CONFIG_PHONET_PIPECTRLR
case PNS_PEP_DISABLE_RESP:
atomic_set(&pn->tx_credits, 0);
- pipe_handler_send_ind(sk, PNS_PIPE_DISABLED_IND_UTID,
- PNS_PIPE_DISABLED_IND);
+ pipe_handler_send_ind(sk, PNS_PIPE_DISABLED_IND);
sk->sk_state = TCP_SYN_RECV;
pn->rx_credits = 0;
break;
@@ -678,7 +667,6 @@ static int pep_connresp_rcv(struct sock *sk, struct sk_buff *skb)
u8 host_pref_rx_fc[3] = {3, 2, 1}, host_req_tx_fc[3] = {3, 2, 1};
u8 remote_pref_rx_fc[3], remote_req_tx_fc[3];
u8 negotiated_rx_fc, negotiated_tx_fc;
- int ret;
pipe_get_flow_info(sk, skb, remote_pref_rx_fc,
remote_req_tx_fc);
@@ -697,12 +685,7 @@ static int pep_connresp_rcv(struct sock *sk, struct sk_buff *skb)
pn->tx_fc = negotiated_tx_fc;
sk->sk_state_change(sk);
- ret = pipe_handler_send_created_ind(sk,
- PNS_PIPE_CREATED_IND_UTID,
- PNS_PIPE_CREATED_IND
- );
-
- return ret;
+ return pipe_handler_send_created_ind(sk, PNS_PIPE_CREATED_IND);
}
#endif
@@ -943,9 +926,7 @@ static void pep_sock_close(struct sock *sk, long timeout)
pipe_do_remove(sk);
#else
/* send pep disconnect request */
- pipe_handler_send_req(sk,
- PNS_PEP_DISCONNECT_UTID, PNS_PEP_DISCONNECT_REQ,
- GFP_KERNEL);
+ pipe_handler_send_req(sk, PNS_PEP_DISCONNECT_REQ, GFP_KERNEL);
sk->sk_state = TCP_CLOSE;
#endif
}
@@ -1034,9 +1015,7 @@ static int pep_sock_connect(struct sock *sk, struct sockaddr *addr, int len)
pn->pn_sk.dobject = pn_sockaddr_get_object(spn);
pn->pn_sk.resource = pn_sockaddr_get_resource(spn);
- return pipe_handler_send_req(sk,
- PNS_PEP_CONNECT_UTID, PNS_PEP_CONNECT_REQ,
- GFP_ATOMIC);
+ return pipe_handler_send_req(sk, PNS_PEP_CONNECT_REQ, GFP_KERNEL);
}
#endif
--
1.7.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 6/6] Phonet: fix flawed "SYN/ACK" logic
2011-02-25 9:13 [PATCH net-next 0/6] Phonet: small pipe protocol fixes Rémi Denis-Courmont
` (4 preceding siblings ...)
2011-02-25 9:15 ` [PATCH 5/6] Phonet: don't bother with transaction IDs (especially for indications) Rémi Denis-Courmont
@ 2011-02-25 9:15 ` Rémi Denis-Courmont
2011-02-25 19:20 ` [PATCH net-next 0/6] Phonet: small pipe protocol fixes David Miller
6 siblings, 0 replies; 10+ messages in thread
From: Rémi Denis-Courmont @ 2011-02-25 9:15 UTC (permalink / raw)
To: netdev
* Do not fail if the peer supports more or less than 3 algorithms.
* Ignore unknown congestion control algorithms instead of failing.
* Simplify congestion algorithm negotiation (largest is best).
* Do not use a static buffer.
* Fix off-by-two read overflow.
* Avoid extra memory copy (in addition to skb_copy_bits()).
The previous code really made no sense.
Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
---
include/net/phonet/pep.h | 1 +
net/phonet/pep.c | 125 +++++++++++++++++----------------------------
2 files changed, 48 insertions(+), 78 deletions(-)
diff --git a/include/net/phonet/pep.h b/include/net/phonet/pep.h
index 37f23dc..38eed1b 100644
--- a/include/net/phonet/pep.h
+++ b/include/net/phonet/pep.h
@@ -154,6 +154,7 @@ enum {
PN_LEGACY_FLOW_CONTROL,
PN_ONE_CREDIT_FLOW_CONTROL,
PN_MULTI_CREDIT_FLOW_CONTROL,
+ PN_MAX_FLOW_CONTROL,
};
#define pn_flow_safe(fc) ((fc) >> 1)
diff --git a/net/phonet/pep.c b/net/phonet/pep.c
index 0ecab59..b8c31fc 100644
--- a/net/phonet/pep.c
+++ b/net/phonet/pep.c
@@ -108,70 +108,6 @@ static int pep_reply(struct sock *sk, struct sk_buff *oskb,
#define PAD 0x00
#ifdef CONFIG_PHONET_PIPECTRLR
-static u8 pipe_negotiate_fc(u8 *host_fc, u8 *remote_fc, int len)
-{
- int i, j;
- u8 base_fc, final_fc;
-
- for (i = 0; i < len; i++) {
- base_fc = host_fc[i];
- for (j = 0; j < len; j++) {
- if (remote_fc[j] == base_fc) {
- final_fc = base_fc;
- goto done;
- }
- }
- }
- return -EINVAL;
-
-done:
- return final_fc;
-
-}
-
-static int pipe_get_flow_info(struct sock *sk, struct sk_buff *skb,
- u8 *pref_rx_fc, u8 *req_tx_fc)
-{
- struct pnpipehdr *hdr;
- u8 n_sb;
-
- if (!pskb_may_pull(skb, sizeof(*hdr) + 4))
- return -EINVAL;
-
- hdr = pnp_hdr(skb);
- n_sb = hdr->data[4];
-
- __skb_pull(skb, sizeof(*hdr) + 4);
- while (n_sb > 0) {
- u8 type, buf[3], len = sizeof(buf);
- u8 *data = pep_get_sb(skb, &type, &len, buf);
-
- if (data == NULL)
- return -EINVAL;
-
- switch (type) {
- case PN_PIPE_SB_REQUIRED_FC_TX:
- if (len < 3 || (data[2] | data[3] | data[4]) > 3)
- break;
- req_tx_fc[0] = data[2];
- req_tx_fc[1] = data[3];
- req_tx_fc[2] = data[4];
- break;
-
- case PN_PIPE_SB_PREFERRED_FC_RX:
- if (len < 3 || (data[2] | data[3] | data[4]) > 3)
- break;
- pref_rx_fc[0] = data[2];
- pref_rx_fc[1] = data[3];
- pref_rx_fc[2] = data[4];
- break;
-
- }
- n_sb--;
- }
- return 0;
-}
-
static int pipe_handler_send_req(struct sock *sk, u8 msg_id, gfp_t priority)
{
int len;
@@ -661,28 +597,61 @@ static void pipe_destruct(struct sock *sk)
}
#ifdef CONFIG_PHONET_PIPECTRLR
+static u8 pipe_negotiate_fc(const u8 *fcs, unsigned n)
+{
+ unsigned i;
+ u8 final_fc = PN_NO_FLOW_CONTROL;
+
+ for (i = 0; i < n; i++) {
+ u8 fc = fcs[i];
+
+ if (fc > final_fc && fc < PN_MAX_FLOW_CONTROL)
+ final_fc = fc;
+ }
+ return final_fc;
+}
+
static int pep_connresp_rcv(struct sock *sk, struct sk_buff *skb)
{
struct pep_sock *pn = pep_sk(sk);
- u8 host_pref_rx_fc[3] = {3, 2, 1}, host_req_tx_fc[3] = {3, 2, 1};
- u8 remote_pref_rx_fc[3], remote_req_tx_fc[3];
- u8 negotiated_rx_fc, negotiated_tx_fc;
-
- pipe_get_flow_info(sk, skb, remote_pref_rx_fc,
- remote_req_tx_fc);
- negotiated_tx_fc = pipe_negotiate_fc(remote_req_tx_fc,
- host_pref_rx_fc,
- sizeof(host_pref_rx_fc));
- negotiated_rx_fc = pipe_negotiate_fc(host_req_tx_fc,
- remote_pref_rx_fc,
- sizeof(host_pref_rx_fc));
+ struct pnpipehdr *hdr;
+ u8 n_sb;
+
+ if (!pskb_pull(skb, sizeof(*hdr) + 4))
+ return -EINVAL;
+
+ hdr = pnp_hdr(skb);
+
+ /* Parse sub-blocks */
+ n_sb = hdr->data[4];
+ while (n_sb > 0) {
+ u8 type, buf[6], len = sizeof(buf);
+ const u8 *data = pep_get_sb(skb, &type, &len, buf);
+
+ if (data == NULL)
+ return -EINVAL;
+
+ switch (type) {
+ case PN_PIPE_SB_REQUIRED_FC_TX:
+ if (len < 2 || len < data[0])
+ break;
+ pn->tx_fc = pipe_negotiate_fc(data + 2, len - 2);
+ break;
+
+ case PN_PIPE_SB_PREFERRED_FC_RX:
+ if (len < 2 || len < data[0])
+ break;
+ pn->rx_fc = pipe_negotiate_fc(data + 2, len - 2);
+ break;
+
+ }
+ n_sb--;
+ }
sk->sk_state = TCP_SYN_RECV;
sk->sk_backlog_rcv = pipe_do_rcv;
sk->sk_destruct = pipe_destruct;
pn->rx_credits = 0;
- pn->rx_fc = negotiated_rx_fc;
- pn->tx_fc = negotiated_tx_fc;
sk->sk_state_change(sk);
return pipe_handler_send_created_ind(sk, PNS_PIPE_CREATED_IND);
--
1.7.1
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH net-next 0/6] Phonet: small pipe protocol fixes
2011-02-25 9:13 [PATCH net-next 0/6] Phonet: small pipe protocol fixes Rémi Denis-Courmont
` (5 preceding siblings ...)
2011-02-25 9:15 ` [PATCH 6/6] Phonet: fix flawed "SYN/ACK" logic Rémi Denis-Courmont
@ 2011-02-25 19:20 ` David Miller
2011-02-25 19:24 ` David Miller
6 siblings, 1 reply; 10+ messages in thread
From: David Miller @ 2011-02-25 19:20 UTC (permalink / raw)
To: netdev, remi.denis-courmont; +Cc: ofono
From: "Rémi Denis-Courmont" <remi.denis-courmont@nokia.com>
Date: Fri, 25 Feb 2011 11:13:41 +0200
> This patch series cleans up and fixes a number of small bits in the
> Phonet pipe code, especially the experimental pipe controller. Once
> this small bits are sorted out, I will try to fix the controller
> protocol implementation proper so that we do not need the
> compile-time (experimental) flag anymore.
All applied thanks.
If you want to start using GIT to push phonet changes to me, frankly I
would welcome that :-)
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH net-next 0/6] Phonet: small pipe protocol fixes
2011-02-25 19:20 ` [PATCH net-next 0/6] Phonet: small pipe protocol fixes David Miller
@ 2011-02-25 19:24 ` David Miller
[not found] ` <20110225.112406.246526410.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
0 siblings, 1 reply; 10+ messages in thread
From: David Miller @ 2011-02-25 19:24 UTC (permalink / raw)
To: netdev, remi.denis-courmont; +Cc: ofono
From: David Miller <davem@davemloft.net>
Date: Fri, 25 Feb 2011 11:20:55 -0800 (PST)
> From: "Rémi Denis-Courmont" <remi.denis-courmont@nokia.com>
> Date: Fri, 25 Feb 2011 11:13:41 +0200
>
>> This patch series cleans up and fixes a number of small bits in the
>> Phonet pipe code, especially the experimental pipe controller. Once
>> this small bits are sorted out, I will try to fix the controller
>> protocol implementation proper so that we do not need the
>> compile-time (experimental) flag anymore.
>
> All applied thanks.
>
> If you want to start using GIT to push phonet changes to me, frankly I
> would welcome that :-)
BTW, I had to add the following patch to fix a build warning:
--------------------
phonet: Protect pipe_do_remove() with appropriate ifdefs.
It is only used when CONFIG_PHONET_PIPECTRLR is not set.
Signed-off-by: David S. Miller <davem@davemloft.net>
---
net/phonet/pep.c | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/net/phonet/pep.c b/net/phonet/pep.c
index b8c31fc..875e86c 100644
--- a/net/phonet/pep.c
+++ b/net/phonet/pep.c
@@ -849,6 +849,7 @@ drop:
return err;
}
+#ifndef CONFIG_PHONET_PIPECTRLR
static int pipe_do_remove(struct sock *sk)
{
struct pep_sock *pn = pep_sk(sk);
@@ -870,6 +871,7 @@ static int pipe_do_remove(struct sock *sk)
return pn_skb_send(sk, skb, NULL);
}
+#endif
/* associated socket ceases to exist */
static void pep_sock_close(struct sock *sk, long timeout)
--
1.7.4.1
^ permalink raw reply related [flat|nested] 10+ messages in thread