dccp: Remove obsolete parts of the old CCID interface
[linux-2.6.git] / net / dccp / feat.c
index 5be8b85..a0d5891 100644 (file)
@@ -3,7 +3,6 @@
  *
  *  Feature negotiation for the DCCP protocol (RFC 4340, section 6)
  *
- *  Copyright (c) 2008 The University of Aberdeen, Scotland, UK
  *  Copyright (c) 2008 Gerrit Renker <gerrit@erg.abdn.ac.uk>
  *  Rewrote from scratch, some bits from earlier code by
  *  Copyright (c) 2005 Andrea Bittau <a.bittau@cs.ucl.ac.uk>
@@ -13,7 +12,6 @@
  *  -----------
  *  o Feature negotiation is coordinated with connection setup (as in TCP), wild
  *    changes of parameters of an established connection are not supported.
- *  o Changing NN values (Ack Ratio only) is supported in state OPEN/PARTOPEN.
  *  o All currently known SP features have 1-byte quantities. If in the future
  *    extensions of RFCs 4340..42 define features with item lengths larger than
  *    one byte, a feature-specific extension of the code will be required.
 #include "ccid.h"
 #include "feat.h"
 
-/* feature-specific sysctls - initialised to the defaults from RFC 4340, 6.4 */
-unsigned long  sysctl_dccp_sequence_window __read_mostly = 100;
-int            sysctl_dccp_rx_ccid         __read_mostly = 2,
-               sysctl_dccp_tx_ccid         __read_mostly = 2;
-
 /*
  * Feature activation handlers.
  *
@@ -58,17 +51,8 @@ static int dccp_hdlr_ccid(struct sock *sk, u64 ccid, bool rx)
 
 static int dccp_hdlr_seq_win(struct sock *sk, u64 seq_win, bool rx)
 {
-       struct dccp_sock *dp = dccp_sk(sk);
-
-       if (rx) {
-               dp->dccps_r_seq_win = seq_win;
-               /* propagate changes to update SWL/SWH */
-               dccp_update_gsr(sk, dp->dccps_gsr);
-       } else {
-               dp->dccps_l_seq_win = seq_win;
-               /* propagate changes to update AWL */
-               dccp_update_gss(sk, dp->dccps_gss);
-       }
+       if (!rx)
+               dccp_msk(sk)->dccpms_sequence_window = seq_win;
        return 0;
 }
 
@@ -101,7 +85,7 @@ static int dccp_hdlr_ackvec(struct sock *sk, u64 enable, bool rx)
 static int dccp_hdlr_ndp(struct sock *sk, u64 enable, bool rx)
 {
        if (!rx)
-               dccp_sk(sk)->dccps_send_ndp_count = (enable > 0);
+               dccp_msk(sk)->dccpms_send_ndp_count = (enable > 0);
        return 0;
 }
 
@@ -201,103 +185,14 @@ static u8 dccp_feat_type(u8 feat_num)
 static int dccp_feat_default_value(u8 feat_num)
 {
        int idx = dccp_feat_index(feat_num);
+       /*
+        * There are no default values for unknown features, so encountering a
+        * negative index here indicates a serious problem somewhere else.
+        */
+       DCCP_BUG_ON(idx < 0);
 
-       return idx < 0 ? : dccp_feat_table[idx].default_value;
-}
-
-/*
- *     Debugging and verbose-printing section
- */
-static const char *dccp_feat_fname(const u8 feat)
-{
-       static const char *feature_names[] = {
-               [DCCPF_RESERVED]        = "Reserved",
-               [DCCPF_CCID]            = "CCID",
-               [DCCPF_SHORT_SEQNOS]    = "Allow Short Seqnos",
-               [DCCPF_SEQUENCE_WINDOW] = "Sequence Window",
-               [DCCPF_ECN_INCAPABLE]   = "ECN Incapable",
-               [DCCPF_ACK_RATIO]       = "Ack Ratio",
-               [DCCPF_SEND_ACK_VECTOR] = "Send ACK Vector",
-               [DCCPF_SEND_NDP_COUNT]  = "Send NDP Count",
-               [DCCPF_MIN_CSUM_COVER]  = "Min. Csum Coverage",
-               [DCCPF_DATA_CHECKSUM]   = "Send Data Checksum",
-       };
-       if (feat > DCCPF_DATA_CHECKSUM && feat < DCCPF_MIN_CCID_SPECIFIC)
-               return feature_names[DCCPF_RESERVED];
-
-       if (feat ==  DCCPF_SEND_LEV_RATE)
-               return "Send Loss Event Rate";
-       if (feat >= DCCPF_MIN_CCID_SPECIFIC)
-               return "CCID-specific";
-
-       return feature_names[feat];
-}
-
-static const char *dccp_feat_sname[] = { "DEFAULT", "INITIALISING", "CHANGING",
-                                        "UNSTABLE", "STABLE" };
-
-#ifdef CONFIG_IP_DCCP_DEBUG
-static const char *dccp_feat_oname(const u8 opt)
-{
-       switch (opt) {
-       case DCCPO_CHANGE_L:  return "Change_L";
-       case DCCPO_CONFIRM_L: return "Confirm_L";
-       case DCCPO_CHANGE_R:  return "Change_R";
-       case DCCPO_CONFIRM_R: return "Confirm_R";
-       }
-       return NULL;
-}
-
-static void dccp_feat_printval(u8 feat_num, dccp_feat_val const *val)
-{
-       u8 i, type = dccp_feat_type(feat_num);
-
-       if (val == NULL || (type == FEAT_SP && val->sp.vec == NULL))
-               dccp_pr_debug_cat("(NULL)");
-       else if (type == FEAT_SP)
-               for (i = 0; i < val->sp.len; i++)
-                       dccp_pr_debug_cat("%s%u", i ? " " : "", val->sp.vec[i]);
-       else if (type == FEAT_NN)
-               dccp_pr_debug_cat("%llu", (unsigned long long)val->nn);
-       else
-               dccp_pr_debug_cat("unknown type %u", type);
-}
-
-static void dccp_feat_printvals(u8 feat_num, u8 *list, u8 len)
-{
-       u8 type = dccp_feat_type(feat_num);
-       dccp_feat_val fval = { .sp.vec = list, .sp.len = len };
-
-       if (type == FEAT_NN)
-               fval.nn = dccp_decode_value_var(list, len);
-       dccp_feat_printval(feat_num, &fval);
-}
-
-static void dccp_feat_print_entry(struct dccp_feat_entry const *entry)
-{
-       dccp_debug("   * %s %s = ", entry->is_local ? "local" : "remote",
-                                   dccp_feat_fname(entry->feat_num));
-       dccp_feat_printval(entry->feat_num, &entry->val);
-       dccp_pr_debug_cat(", state=%s %s\n", dccp_feat_sname[entry->state],
-                         entry->needs_confirm ? "(Confirm pending)" : "");
-}
-
-#define dccp_feat_print_opt(opt, feat, val, len, mandatory)    do {          \
-       dccp_pr_debug("%s(%s, ", dccp_feat_oname(opt), dccp_feat_fname(feat));\
-       dccp_feat_printvals(feat, val, len);                                  \
-       dccp_pr_debug_cat(") %s\n", mandatory ? "!" : "");      } while (0)
-
-#define dccp_feat_print_fnlist(fn_list)  {             \
-       const struct dccp_feat_entry *___entry;         \
-                                                       \
-       dccp_pr_debug("List Dump:\n");                  \
-       list_for_each_entry(___entry, fn_list, node)    \
-               dccp_feat_print_entry(___entry);        \
+       return idx < 0 ? 0 : dccp_feat_table[idx].default_value;
 }
-#else  /* ! CONFIG_IP_DCCP_DEBUG */
-#define dccp_feat_print_opt(opt, feat, val, len, mandatory)
-#define dccp_feat_print_fnlist(fn_list)
-#endif
 
 static int __dccp_feat_activate(struct sock *sk, const int idx,
                                const bool is_local, dccp_feat_val const *fval)
@@ -331,27 +226,9 @@ static int __dccp_feat_activate(struct sock *sk, const int idx,
        /* Location is RX if this is a local-RX or remote-TX feature */
        rx = (is_local == (dccp_feat_table[idx].rxtx == FEAT_AT_RX));
 
-       dccp_debug("   -> activating %s %s, %sval=%llu\n", rx ? "RX" : "TX",
-                  dccp_feat_fname(dccp_feat_table[idx].feat_num),
-                  fval ? "" : "default ",  (unsigned long long)val);
-
        return dccp_feat_table[idx].activation_hdlr(sk, val, rx);
 }
 
-/**
- * dccp_feat_activate  -  Activate feature value on socket
- * @sk: fully connected DCCP socket (after handshake is complete)
- * @feat_num: feature to activate, one of %dccp_feature_numbers
- * @local: whether local (1) or remote (0) @feat_num is meant
- * @fval: the value (SP or NN) to activate, or NULL to use the default value
- * For general use this function is preferable over __dccp_feat_activate().
- */
-static int dccp_feat_activate(struct sock *sk, u8 feat_num, bool local,
-                             dccp_feat_val const *fval)
-{
-       return __dccp_feat_activate(sk, dccp_feat_index(feat_num), local, fval);
-}
-
 /* Test for "Req'd" feature (RFC 4340, 6.4) */
 static inline int dccp_feat_must_be_understood(u8 feat_num)
 {
@@ -426,11 +303,12 @@ static struct dccp_feat_entry *dccp_feat_list_lookup(struct list_head *fn_list,
 {
        struct dccp_feat_entry *entry;
 
-       list_for_each_entry(entry, fn_list, node)
+       list_for_each_entry(entry, fn_list, node) {
                if (entry->feat_num == feat_num && entry->is_local == is_local)
                        return entry;
                else if (entry->feat_num > feat_num)
                        break;
+       }
        return NULL;
 }
 
@@ -652,7 +530,6 @@ int dccp_feat_insert_opts(struct dccp_sock *dp, struct dccp_request_sock *dreq,
                                return -1;
                        }
                }
-               dccp_feat_print_opt(opt, pos->feat_num, ptr, len, 0);
 
                if (dccp_insert_fn_opt(skb, opt, pos->feat_num, ptr, len, rpt))
                        return -1;
@@ -749,48 +626,6 @@ int dccp_feat_register_nn(struct sock *sk, u8 feat, u64 val)
        return __feat_register_nn(&dccp_sk(sk)->dccps_featneg, feat, 0, val);
 }
 
-/**
- * dccp_feat_signal_nn_change  -  Update NN values for an established connection
- * @sk: DCCP socket of an established connection
- * @feat: NN feature number from %dccp_feature_numbers
- * @nn_val: the new value to use
- * This function is used to communicate NN updates out-of-band. The difference
- * to feature negotiation during connection setup is that values are activated
- * immediately after validation, i.e. we don't wait for the Confirm: either the
- * value is accepted by the peer (and then the waiting is futile), or it is not
- * (Reset or empty Confirm). We don't accept empty Confirms - transmitted values
- * are validated, and the peer "MUST accept any valid value" (RFC 4340, 6.3.2).
- */
-int dccp_feat_signal_nn_change(struct sock *sk, u8 feat, u64 nn_val)
-{
-       struct list_head *fn = &dccp_sk(sk)->dccps_featneg;
-       dccp_feat_val fval = { .nn = nn_val };
-       struct dccp_feat_entry *entry;
-
-       if (sk->sk_state != DCCP_OPEN && sk->sk_state != DCCP_PARTOPEN)
-               return 0;
-
-       if (dccp_feat_type(feat) != FEAT_NN ||
-           !dccp_feat_is_valid_nn_val(feat, nn_val))
-               return -EINVAL;
-
-       entry = dccp_feat_list_lookup(fn, feat, 1);
-       if (entry != NULL) {
-               dccp_pr_debug("Ignoring %llu, entry %llu exists in state %s\n",
-                             (unsigned long long)nn_val,
-                             (unsigned long long)entry->val.nn,
-                             dccp_feat_sname[entry->state]);
-               return 0;
-       }
-
-       if (dccp_feat_activate(sk, feat, 1, &fval))
-               return -EADV;
-
-       inet_csk_schedule_ack(sk);
-       return dccp_feat_push_change(fn, feat, 1, 0, &fval);
-}
-EXPORT_SYMBOL_GPL(dccp_feat_signal_nn_change);
-
 /*
  *     Tracking features whose value depend on the choice of CCID
  *
@@ -948,7 +783,6 @@ int dccp_feat_finalise_settings(struct dccp_sock *dp)
        while (i--)
                if (ccids[i] > 0 && dccp_feat_propagate_ccid(fn, ccids[i], i))
                        return -1;
-       dccp_feat_print_fnlist(fn);
        return 0;
 }
 
@@ -1067,8 +901,6 @@ static u8 dccp_feat_change_recv(struct list_head *fn, u8 is_mandatory, u8 opt,
        if (len == 0 || type == FEAT_UNKNOWN)           /* 6.1 and 6.6.8 */
                goto unknown_feature_or_value;
 
-       dccp_feat_print_opt(opt, feat, val, len, is_mandatory);
-
        /*
         *      Negotiation of NN features: Change R is invalid, so there is no
         *      simultaneous negotiation; hence we do not look up in the list.
@@ -1174,8 +1006,6 @@ static u8 dccp_feat_confirm_recv(struct list_head *fn, u8 is_mandatory, u8 opt,
        const bool local = (opt == DCCPO_CONFIRM_R);
        struct dccp_feat_entry *entry = dccp_feat_list_lookup(fn, feat, local);
 
-       dccp_feat_print_opt(opt, feat, val, len, is_mandatory);
-
        if (entry == NULL) {    /* nothing queued: ignore or handle error */
                if (is_mandatory && type == FEAT_UNKNOWN)
                        return DCCP_RESET_CODE_MANDATORY_ERROR;
@@ -1285,75 +1115,23 @@ int dccp_feat_parse_options(struct sock *sk, struct dccp_request_sock *dreq,
        return 0;       /* ignore FN options in all other states */
 }
 
-/**
- * dccp_feat_init  -  Seed feature negotiation with host-specific defaults
- * This initialises global defaults, depending on the value of the sysctls.
- * These can later be overridden by registering changes via setsockopt calls.
- * The last link in the chain is finalise_settings, to make sure that between
- * here and the start of actual feature negotiation no inconsistencies enter.
- *
- * All features not appearing below use either defaults or are otherwise
- * later adjusted through dccp_feat_finalise_settings().
- */
 int dccp_feat_init(struct sock *sk)
 {
-       struct list_head *fn = &dccp_sk(sk)->dccps_featneg;
-       u8 on = 1, off = 0;
+       struct dccp_sock *dp = dccp_sk(sk);
+       struct dccp_minisock *dmsk = dccp_msk(sk);
        int rc;
-       struct {
-               u8 *val;
-               u8 len;
-       } tx, rx;
-
-       /* Non-negotiable (NN) features */
-       rc = __feat_register_nn(fn, DCCPF_SEQUENCE_WINDOW, 0,
-                                   sysctl_dccp_sequence_window);
-       if (rc)
-               return rc;
-
-       /* Server-priority (SP) features */
-
-       /* Advertise that short seqnos are not supported (7.6.1) */
-       rc = __feat_register_sp(fn, DCCPF_SHORT_SEQNOS, true, true, &off, 1);
-       if (rc)
-               return rc;
-
-       /* RFC 4340 12.1: "If a DCCP is not ECN capable, ..." */
-       rc = __feat_register_sp(fn, DCCPF_ECN_INCAPABLE, true, true, &on, 1);
-       if (rc)
-               return rc;
-
-       /*
-        * We advertise the available list of CCIDs and reorder according to
-        * preferences, to avoid failure resulting from negotiating different
-        * singleton values (which always leads to failure).
-        * These settings can still (later) be overridden via sockopts.
-        */
-       if (ccid_get_builtin_ccids(&tx.val, &tx.len) ||
-           ccid_get_builtin_ccids(&rx.val, &rx.len))
-               return -ENOBUFS;
-
-       /* Pre-load all CCID modules that are going to be advertised */
-       rc = -EUNATCH;
-       if (ccid_request_modules(tx.val, tx.len))
-               goto free_ccid_lists;
-
-       if (!dccp_feat_prefer(sysctl_dccp_tx_ccid, tx.val, tx.len) ||
-           !dccp_feat_prefer(sysctl_dccp_rx_ccid, rx.val, rx.len))
-               goto free_ccid_lists;
-
-       rc = __feat_register_sp(fn, DCCPF_CCID, true, false, tx.val, tx.len);
-       if (rc)
-               goto free_ccid_lists;
 
-       rc = __feat_register_sp(fn, DCCPF_CCID, false, false, rx.val, rx.len);
+       INIT_LIST_HEAD(&dmsk->dccpms_pending);  /* XXX no longer used */
+       INIT_LIST_HEAD(&dmsk->dccpms_conf);     /* XXX no longer used */
 
-free_ccid_lists:
-       kfree(tx.val);
-       kfree(rx.val);
+       /* Ack ratio */
+       rc = __feat_register_nn(&dp->dccps_featneg, DCCPF_ACK_RATIO, 0,
+                               dp->dccps_l_ack_ratio);
        return rc;
 }
 
+EXPORT_SYMBOL_GPL(dccp_feat_init);
+
 int dccp_feat_activate_values(struct sock *sk, struct list_head *fn_list)
 {
        struct dccp_sock *dp = dccp_sk(sk);
@@ -1378,10 +1156,9 @@ int dccp_feat_activate_values(struct sock *sk, struct list_head *fn_list)
                        goto activation_failed;
                }
                if (cur->state != FEAT_STABLE) {
-                       DCCP_CRIT("Negotiation of %s %s failed in state %s",
+                       DCCP_CRIT("Negotiation of %s %u failed in state %u",
                                  cur->is_local ? "local" : "remote",
-                                 dccp_feat_fname(cur->feat_num),
-                                 dccp_feat_sname[cur->state]);
+                                 cur->feat_num, cur->state);
                        goto activation_failed;
                }
                fvals[idx][cur->is_local] = &cur->val;
@@ -1422,3 +1199,47 @@ activation_failed:
        dp->dccps_hc_rx_ackvec = NULL;
        return -1;
 }
+
+#ifdef CONFIG_IP_DCCP_DEBUG
+const char *dccp_feat_typename(const u8 type)
+{
+       switch(type) {
+       case DCCPO_CHANGE_L:  return("ChangeL");
+       case DCCPO_CONFIRM_L: return("ConfirmL");
+       case DCCPO_CHANGE_R:  return("ChangeR");
+       case DCCPO_CONFIRM_R: return("ConfirmR");
+       /* the following case must not appear in feature negotation  */
+       default:              dccp_pr_debug("unknown type %d [BUG!]\n", type);
+       }
+       return NULL;
+}
+
+EXPORT_SYMBOL_GPL(dccp_feat_typename);
+
+const char *dccp_feat_name(const u8 feat)
+{
+       static const char *feature_names[] = {
+               [DCCPF_RESERVED]        = "Reserved",
+               [DCCPF_CCID]            = "CCID",
+               [DCCPF_SHORT_SEQNOS]    = "Allow Short Seqnos",
+               [DCCPF_SEQUENCE_WINDOW] = "Sequence Window",
+               [DCCPF_ECN_INCAPABLE]   = "ECN Incapable",
+               [DCCPF_ACK_RATIO]       = "Ack Ratio",
+               [DCCPF_SEND_ACK_VECTOR] = "Send ACK Vector",
+               [DCCPF_SEND_NDP_COUNT]  = "Send NDP Count",
+               [DCCPF_MIN_CSUM_COVER]  = "Min. Csum Coverage",
+               [DCCPF_DATA_CHECKSUM]   = "Send Data Checksum",
+       };
+       if (feat > DCCPF_DATA_CHECKSUM && feat < DCCPF_MIN_CCID_SPECIFIC)
+               return feature_names[DCCPF_RESERVED];
+
+       if (feat ==  DCCPF_SEND_LEV_RATE)
+               return "Send Loss Event Rate";
+       if (feat >= DCCPF_MIN_CCID_SPECIFIC)
+               return "CCID-specific";
+
+       return feature_names[feat];
+}
+
+EXPORT_SYMBOL_GPL(dccp_feat_name);
+#endif /* CONFIG_IP_DCCP_DEBUG */