DCCP protocol discussions
 help / color / mirror / Atom feed
From: Andrea Bittau <a.bittau@cs.ucl.ac.uk>
To: dccp@vger.kernel.org
Subject: [PATCH 1/X] [DCCP]: Actually change the CCID upon negotiation.
Date: Wed, 15 Feb 2006 12:49:47 +0000	[thread overview]
Message-ID: <20060215124946.GA5643@tribal.sorbonet.org> (raw)

Change the CCID upon successful feature negotiation.

Signed-off-by: Andrea Bittau <a.bittau@cs.ucl.ac.uk>

---

diff --git a/net/dccp/feat.c b/net/dccp/feat.c
index fb74260..094f1ba 100644
--- a/net/dccp/feat.c
+++ b/net/dccp/feat.c
@@ -14,6 +14,7 @@
 #include <linux/module.h>
 
 #include "dccp.h"
+#include "ccid.h"
 #include "feat.h"
 
 #define DCCP_FEAT_SP_NOAGREE (-123)
@@ -26,6 +27,8 @@ int dccp_feat_change(struct sock *sk, u8
 	
 	dccp_pr_debug("feat change type=%d feat=%d\n", type, feature);
 
+	/* XXX sanity check feat change request */
+
 	/* check if that feature is already being negotiated */
 	list_for_each_entry(opt, &dp->dccps_options.dccpo_pending,
 			    dccpop_node) {
@@ -62,11 +65,81 @@ int dccp_feat_change(struct sock *sk, u8
 
 EXPORT_SYMBOL_GPL(dccp_feat_change);
 
+static int dccp_feat_update_ccid(struct sock *sk, u8 type, u8 val)
+{
+	struct dccp_sock *dp = dccp_sk(sk);
+	struct ccid **ccid;
+	u8 *oldval;
+	/* XXX function ptrs to inline functions.  Is this legal? */
+	int  (*ccid_hc_init)(struct ccid *ccid, struct sock *sk);
+	void (*ccid_hc_exit)(struct ccid *ccid, struct sock *sk);
+	int rc = 0;
+
+	/* figure out if we are changing our CCID or the peer's */	
+	if (type = DCCPO_CHANGE_L) {
+		ccid = &dp->dccps_hc_tx_ccid;
+		oldval = &dp->dccps_options.dccpo_tx_ccid;
+		ccid_hc_init = &ccid_hc_tx_init;
+		ccid_hc_exit = &ccid_hc_tx_exit;
+	} else {
+		ccid = &dp->dccps_hc_rx_ccid;
+		oldval = &dp->dccps_options.dccpo_rx_ccid;
+		ccid_hc_init = &ccid_hc_rx_init;
+		ccid_hc_exit = &ccid_hc_rx_exit;
+	}
+
+	/* check if nothing is being changed. */
+	if (*oldval = val)
+		return 0;
+
+	/* kill old CCID */
+	/* ccid_hc_init() is called only upon receiving a RESPONSE packet */
+	if (sk->sk_state != DCCP_REQUESTING)
+		ccid_hc_exit(*ccid, sk);
+	ccid_exit(*ccid, sk);
+	
+	/* switch CCID */
+	*ccid = ccid_init(val, sk);
+	if (*ccid = NULL) {
+		/* XXX OK we have a problem here.  socket will remain without
+		 * CCID.  I think the only sensible thing is to kill the socket
+		 * ASAP.  Ideally, one would make sure the new CCID could be
+		 * allocated before the old one is deleted.  The problem is that
+		 * ccid_init might play with the private ccid state of sk,
+		 * that's why it's safer to first kill the old ccid.
+		 */
+		rc = -ENOMEM;
+		goto out_exit;
+	}
+	if (sk->sk_state != DCCP_REQUESTING) {
+		rc = ccid_hc_init(*ccid, sk);
+		if (rc)
+			goto out_exit;
+	}
+	
+	*oldval = val;
+
+out:
+	return rc;
+out_exit:
+	ccid_exit(*ccid, sk);
+	*ccid = NULL;
+	goto out;
+}
+
 /* XXX taking only u8 vals */
 static int dccp_feat_update(struct sock *sk, u8 type, u8 feat, u8 val)
 {
-	/* FIXME implement */
 	dccp_pr_debug("changing [%d] feat %d to %d\n", type, feat, val);
+
+	switch (feat) {
+	case DCCPF_CCID:
+		return dccp_feat_update_ccid(sk, type, val);
+
+	default:
+		WARN_ON(1); /* XXX implement */
+		break;
+	}
 	return 0;
 }
 

                 reply	other threads:[~2006-02-15 12:49 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060215124946.GA5643@tribal.sorbonet.org \
    --to=a.bittau@cs.ucl.ac.uk \
    --cc=dccp@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox