netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net/x25: add new state X25_STATE_5
@ 2019-12-06 13:34 Martin Schiller
  2019-12-07 19:59 ` David Miller
  0 siblings, 1 reply; 4+ messages in thread
From: Martin Schiller @ 2019-12-06 13:34 UTC (permalink / raw)
  To: andrew.hendry, davem
  Cc: edumazet, linux-x25, netdev, linux-kernel, Martin Schiller

This is needed, because if the flag X25_ACCPT_APPRV_FLAG is not set on a
socket (manual call confirmation) and the channel is cleared by remote
before the manual call confirmation was sent, this situation needs to
be handled.

Signed-off-by: Martin Schiller <ms@dev.tdt.de>
---
 include/net/x25.h |  3 ++-
 net/x25/af_x25.c  |  8 ++++++++
 net/x25/x25_in.c  | 35 +++++++++++++++++++++++++++++++++++
 3 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/include/net/x25.h b/include/net/x25.h
index ed1acc3044ac..d7d6c2b4ffa7 100644
--- a/include/net/x25.h
+++ b/include/net/x25.h
@@ -62,7 +62,8 @@ enum {
 	X25_STATE_1,		/* Awaiting Call Accepted */
 	X25_STATE_2,		/* Awaiting Clear Confirmation */
 	X25_STATE_3,		/* Data Transfer */
-	X25_STATE_4		/* Awaiting Reset Confirmation */
+	X25_STATE_4,		/* Awaiting Reset Confirmation */
+	X25_STATE_5		/* Call Accepted / Call Connected pending */
 };
 
 enum {
diff --git a/net/x25/af_x25.c b/net/x25/af_x25.c
index c34f7d077604..2efe44a34644 100644
--- a/net/x25/af_x25.c
+++ b/net/x25/af_x25.c
@@ -659,6 +659,12 @@ static int x25_release(struct socket *sock)
 			sock_set_flag(sk, SOCK_DEAD);
 			sock_set_flag(sk, SOCK_DESTROY);
 			break;
+
+		case X25_STATE_5:
+			x25_write_internal(sk, X25_CLEAR_REQUEST);
+			x25_disconnect(sk, 0, 0, 0);
+			__x25_destroy_socket(sk);
+			goto out;
 	}
 
 	sock_orphan(sk);
@@ -1054,6 +1060,8 @@ int x25_rx_call_request(struct sk_buff *skb, struct x25_neigh *nb,
 	if (test_bit(X25_ACCPT_APPRV_FLAG, &makex25->flags)) {
 		x25_write_internal(make, X25_CALL_ACCEPTED);
 		makex25->state = X25_STATE_3;
+	} else {
+		makex25->state = X25_STATE_5;
 	}
 
 	/*
diff --git a/net/x25/x25_in.c b/net/x25/x25_in.c
index f97c43344e95..3f0f42bdd086 100644
--- a/net/x25/x25_in.c
+++ b/net/x25/x25_in.c
@@ -382,6 +382,38 @@ static int x25_state4_machine(struct sock *sk, struct sk_buff *skb, int frametyp
 	return 0;
 }
 
+/*
+ * State machine for state 5, Call Accepted / Call Connected pending (X25_ACCPT_APPRV_FLAG).
+ * The handling of the timer(s) is in file x25_timer.c
+ * Handling of state 0 and connection release is in af_x25.c.
+ */
+static int x25_state5_machine(struct sock *sk, struct sk_buff *skb, int frametype)
+{
+	struct x25_sock *x25 = x25_sk(sk);
+
+	switch (frametype) {
+
+		case X25_CLEAR_REQUEST:
+			if (!pskb_may_pull(skb, X25_STD_MIN_LEN + 2))
+				goto out_clear;
+
+			x25_write_internal(sk, X25_CLEAR_CONFIRMATION);
+			x25_disconnect(sk, 0, skb->data[3], skb->data[4]);
+			break;
+
+		default:
+			break;
+	}
+
+	return 0;
+
+out_clear:
+	x25_write_internal(sk, X25_CLEAR_REQUEST);
+	x25->state = X25_STATE_2;
+	x25_start_t23timer(sk);
+	return 0;
+}
+
 /* Higher level upcall for a LAPB frame */
 int x25_process_rx_frame(struct sock *sk, struct sk_buff *skb)
 {
@@ -406,6 +438,9 @@ int x25_process_rx_frame(struct sock *sk, struct sk_buff *skb)
 	case X25_STATE_4:
 		queued = x25_state4_machine(sk, skb, frametype);
 		break;
+	case X25_STATE_5:
+		queued = x25_state5_machine(sk, skb, frametype);
+		break;
 	}
 
 	x25_kick(sk);
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] net/x25: add new state X25_STATE_5
  2019-12-06 13:34 [PATCH] net/x25: add new state X25_STATE_5 Martin Schiller
@ 2019-12-07 19:59 ` David Miller
  2019-12-09  5:28   ` Martin Schiller
  0 siblings, 1 reply; 4+ messages in thread
From: David Miller @ 2019-12-07 19:59 UTC (permalink / raw)
  To: ms; +Cc: andrew.hendry, edumazet, linux-x25, netdev, linux-kernel

From: Martin Schiller <ms@dev.tdt.de>
Date: Fri,  6 Dec 2019 14:34:18 +0100

> +	switch (frametype) {
> +
> +		case X25_CLEAR_REQUEST:

Please remove this unnecessary empty line.

> +			if (!pskb_may_pull(skb, X25_STD_MIN_LEN + 2))
> +				goto out_clear;

A goto path for a single call site?  Just inline the operations here.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] net/x25: add new state X25_STATE_5
  2019-12-07 19:59 ` David Miller
@ 2019-12-09  5:28   ` Martin Schiller
  2019-12-09  6:41     ` David Miller
  0 siblings, 1 reply; 4+ messages in thread
From: Martin Schiller @ 2019-12-09  5:28 UTC (permalink / raw)
  To: David Miller; +Cc: andrew.hendry, edumazet, linux-x25, netdev, linux-kernel

On 2019-12-07 20:59, David Miller wrote:
> From: Martin Schiller <ms@dev.tdt.de>
> Date: Fri,  6 Dec 2019 14:34:18 +0100
> 
>> +	switch (frametype) {
>> +
>> +		case X25_CLEAR_REQUEST:
> 
> Please remove this unnecessary empty line.
> 
>> +			if (!pskb_may_pull(skb, X25_STD_MIN_LEN + 2))
>> +				goto out_clear;
> 
> A goto path for a single call site?  Just inline the operations here.

Well, I was guided by the code style of the other states.
I could add a patch to also clean up the other states.
What do you think?


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] net/x25: add new state X25_STATE_5
  2019-12-09  5:28   ` Martin Schiller
@ 2019-12-09  6:41     ` David Miller
  0 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2019-12-09  6:41 UTC (permalink / raw)
  To: ms; +Cc: andrew.hendry, edumazet, linux-x25, netdev, linux-kernel

From: Martin Schiller <ms@dev.tdt.de>
Date: Mon, 09 Dec 2019 06:28:53 +0100

> On 2019-12-07 20:59, David Miller wrote:
>> From: Martin Schiller <ms@dev.tdt.de>
>> Date: Fri,  6 Dec 2019 14:34:18 +0100
>> 
>>> +	switch (frametype) {
>>> +
>>> +		case X25_CLEAR_REQUEST:
>> Please remove this unnecessary empty line.
>> 
>>> +			if (!pskb_may_pull(skb, X25_STD_MIN_LEN + 2))
>>> +				goto out_clear;
>> A goto path for a single call site?  Just inline the operations here.
> 
> Well, I was guided by the code style of the other states.
> I could add a patch to also clean up the other states.
> What do you think?

Leave the other states and existing code alone.

Make your new code reasonable.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-12-09  6:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-06 13:34 [PATCH] net/x25: add new state X25_STATE_5 Martin Schiller
2019-12-07 19:59 ` David Miller
2019-12-09  5:28   ` Martin Schiller
2019-12-09  6:41     ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).