dccp: Initialisation and type-checking of feature sysctls
authorGerrit Renker <gerrit@erg.abdn.ac.uk>
Fri, 16 Jan 2009 23:36:32 +0000 (23:36 +0000)
committerDavid S. Miller <davem@davemloft.net>
Wed, 21 Jan 2009 22:34:05 +0000 (14:34 -0800)
This patch takes care of initialising and type-checking sysctls
related to feature negotiation. Type checking is important since some
of the sysctls now directly impact the feature-negotiation process.

The sysctls are initialised with the known default values for each
feature.  For the type-checking the value constraints from RFC 4340
are used:

 * Sequence Window uses the specified Wmin=32, the maximum is ulong (4 bytes),
   tested and confirmed that it works up to 4294967295 - for Gbps speed;
 * Ack Ratio is between 0 .. 0xffff (2-byte unsigned integer);
 * CCIDs are between 0 .. 255;
 * request_retries, retries1, retries2 also between 0..255 for good measure;
 * tx_qlen is checked to be non-negative;
 * sync_ratelimit remains as before.

Notes:
------
 1. Die s@sysctl_dccp_feat@sysctl_dccp@g since the sysctls are now in feat.c.
 2. As pointed out by Arnaldo, the pattern of type-checking repeats itself in
    other places, sometimes with exactly the same kind of definitions (e.g.
    "static int zero;"). It may be a good idea (kernel janitors?) to consolidate
    type checking. For the sake of keeping the changeset small and in order not
    to affect other subsystems, I have not strived to generalise here.

Signed-off-by: Gerrit Renker <gerrit@erg.abdn.ac.uk>
Acked-by: Ian McDonald <ian.mcdonald@jandi.co.nz>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/linux/dccp.h
net/dccp/dccp.h
net/dccp/feat.c
net/dccp/feat.h
net/dccp/options.c
net/dccp/sysctl.c

index 7a0502ab383a39147bc8b33bd6913f3de0108984..7434a8353e2301dcb548ad94965ef0e73390335f 100644 (file)
@@ -355,14 +355,6 @@ static inline unsigned int dccp_hdr_len(const struct sk_buff *skb)
        return __dccp_hdr_len(dccp_hdr(skb));
 }
 
-
-/* initial values for each feature */
-#define DCCPF_INITIAL_SEQUENCE_WINDOW          100
-#define DCCPF_INITIAL_ACK_RATIO                        2
-#define DCCPF_INITIAL_CCID                     DCCPC_CCID2
-/* FIXME: for now we're default to 1 but it should really be 0 */
-#define DCCPF_INITIAL_SEND_NDP_COUNT           1
-
 /**
  * struct dccp_request_sock  -  represent DCCP-specific connection request
  * @dreq_inet_rsk: structure inherited from
index 04ae91898a6862eb81e991000c2aa686abd7e97e..44a5bc6f678501179b84044bc2aaab5cbaf9ce7e 100644 (file)
@@ -95,9 +95,6 @@ extern void dccp_time_wait(struct sock *sk, int state, int timeo);
 extern int  sysctl_dccp_request_retries;
 extern int  sysctl_dccp_retries1;
 extern int  sysctl_dccp_retries2;
-extern int  sysctl_dccp_feat_sequence_window;
-extern int  sysctl_dccp_feat_rx_ccid;
-extern int  sysctl_dccp_feat_tx_ccid;
 extern int  sysctl_dccp_tx_qlen;
 extern int  sysctl_dccp_sync_ratelimit;
 
index 7303f79705d26b6b80c744a23197ca5ad962f3a2..12006e9b2472e48b55d3697fda4a9ae3a4db4620 100644 (file)
 #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.
  *
@@ -1146,7 +1151,7 @@ int dccp_feat_init(struct sock *sk)
 
        /* Non-negotiable (NN) features */
        rc = __feat_register_nn(fn, DCCPF_SEQUENCE_WINDOW, 0,
-                                   sysctl_dccp_feat_sequence_window);
+                                   sysctl_dccp_sequence_window);
        if (rc)
                return rc;
 
@@ -1172,8 +1177,8 @@ int dccp_feat_init(struct sock *sk)
            ccid_get_builtin_ccids(&rx.val, &rx.len))
                return -ENOBUFS;
 
-       if (!dccp_feat_prefer(sysctl_dccp_feat_tx_ccid, tx.val, tx.len) ||
-           !dccp_feat_prefer(sysctl_dccp_feat_rx_ccid, rx.val, rx.len))
+       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);
index 5e7b8481cd0466493edf6a984af4156c900b0da9..40aa7a10bd5fe55d0fe7061e55ddcf3a5a6b1958 100644 (file)
@@ -100,6 +100,13 @@ struct ccid_dependency {
        u8      val;
 };
 
+/*
+ * Sysctls to seed defaults for feature negotiation
+ */
+extern unsigned long sysctl_dccp_sequence_window;
+extern int          sysctl_dccp_rx_ccid;
+extern int          sysctl_dccp_tx_ccid;
+
 #ifdef CONFIG_IP_DCCP_DEBUG
 extern const char *dccp_feat_typename(const u8 type);
 extern const char *dccp_feat_name(const u8 feat);
@@ -114,6 +121,7 @@ static inline void dccp_feat_debug(const u8 type, const u8 feat, const u8 val)
 #endif /* CONFIG_IP_DCCP_DEBUG */
 
 extern int  dccp_feat_init(struct sock *sk);
+extern void dccp_feat_initialise_sysctls(void);
 extern int  dccp_feat_register_sp(struct sock *sk, u8 feat, u8 is_local,
                                  u8 const *list, u8 len);
 extern int  dccp_feat_register_nn(struct sock *sk, u8 feat, u64 val);
index 7b1165c21f5173a40c9511f934ccc5dcc02cc896..3e2726c7182d871e33f82ee2609ef0b094667bd9 100644 (file)
 #include "dccp.h"
 #include "feat.h"
 
-int sysctl_dccp_feat_sequence_window = DCCPF_INITIAL_SEQUENCE_WINDOW;
-int sysctl_dccp_feat_rx_ccid         = DCCPF_INITIAL_CCID;
-int sysctl_dccp_feat_tx_ccid         = DCCPF_INITIAL_CCID;
-
 u64 dccp_decode_value_var(const u8 *bf, const u8 len)
 {
        u64 value = 0;
index 018e210875e168141a2aca941ab11ca7daaca9ef..a5a1856234e76bd32368b799c49ab43520092532 100644 (file)
 #error This file should not be compiled without CONFIG_SYSCTL defined
 #endif
 
+/* Boundary values */
+static int             zero     = 0,
+                       u8_max   = 0xFF;
+static unsigned long   seqw_min = 32;
+
 static struct ctl_table dccp_default_table[] = {
        {
                .procname       = "seq_window",
-               .data           = &sysctl_dccp_feat_sequence_window,
-               .maxlen         = sizeof(sysctl_dccp_feat_sequence_window),
+               .data           = &sysctl_dccp_sequence_window,
+               .maxlen         = sizeof(sysctl_dccp_sequence_window),
                .mode           = 0644,
-               .proc_handler   = proc_dointvec,
+               .proc_handler   = proc_doulongvec_minmax,
+               .extra1         = &seqw_min,            /* RFC 4340, 7.5.2 */
        },
        {
                .procname       = "rx_ccid",
-               .data           = &sysctl_dccp_feat_rx_ccid,
-               .maxlen         = sizeof(sysctl_dccp_feat_rx_ccid),
+               .data           = &sysctl_dccp_rx_ccid,
+               .maxlen         = sizeof(sysctl_dccp_rx_ccid),
                .mode           = 0644,
-               .proc_handler   = proc_dointvec,
+               .proc_handler   = proc_dointvec_minmax,
+               .extra1         = &zero,
+               .extra2         = &u8_max,              /* RFC 4340, 10. */
        },
        {
                .procname       = "tx_ccid",
-               .data           = &sysctl_dccp_feat_tx_ccid,
-               .maxlen         = sizeof(sysctl_dccp_feat_tx_ccid),
+               .data           = &sysctl_dccp_tx_ccid,
+               .maxlen         = sizeof(sysctl_dccp_tx_ccid),
                .mode           = 0644,
-               .proc_handler   = proc_dointvec,
+               .proc_handler   = proc_dointvec_minmax,
+               .extra1         = &zero,
+               .extra2         = &u8_max,              /* RFC 4340, 10. */
        },
        {
                .procname       = "request_retries",
                .data           = &sysctl_dccp_request_retries,
                .maxlen         = sizeof(sysctl_dccp_request_retries),
                .mode           = 0644,
-               .proc_handler   = proc_dointvec,
+               .proc_handler   = proc_dointvec_minmax,
+               .extra1         = &zero,
+               .extra2         = &u8_max,
        },
        {
                .procname       = "retries1",
                .data           = &sysctl_dccp_retries1,
                .maxlen         = sizeof(sysctl_dccp_retries1),
                .mode           = 0644,
-               .proc_handler   = proc_dointvec,
+               .proc_handler   = proc_dointvec_minmax,
+               .extra1         = &zero,
+               .extra2         = &u8_max,
        },
        {
                .procname       = "retries2",
                .data           = &sysctl_dccp_retries2,
                .maxlen         = sizeof(sysctl_dccp_retries2),
                .mode           = 0644,
-               .proc_handler   = proc_dointvec,
+               .proc_handler   = proc_dointvec_minmax,
+               .extra1         = &zero,
+               .extra2         = &u8_max,
        },
        {
                .procname       = "tx_qlen",
                .data           = &sysctl_dccp_tx_qlen,
                .maxlen         = sizeof(sysctl_dccp_tx_qlen),
                .mode           = 0644,
-               .proc_handler   = proc_dointvec,
+               .proc_handler   = proc_dointvec_minmax,
+               .extra1         = &zero,
        },
        {
                .procname       = "sync_ratelimit",