/*
* net/dccp/feat.c
*
* Feature negotiation for the DCCP protocol (RFC 4340, section 6)
*
* 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>
*
*
* ASSUMPTIONS
* -----------
* o Feature negotiation is coordinated with connection setup (as in TCP), wild
* changes of parameters of an established connection are not supported.
* 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.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*/
#include <linux/module.h>
#include "ccid.h"
#include "feat.h"
/*
* Feature activation handlers.
*
* These all use an u64 argument, to provide enough room for NN/SP features. At
* this stage the negotiated values have been checked to be within their range.
*/
static int dccp_hdlr_ccid(struct sock *sk, u64 ccid, bool rx)
{
struct dccp_sock *dp = dccp_sk(sk);
struct ccid *new_ccid = ccid_new(ccid, sk, rx, gfp_any());
if (new_ccid == NULL)
return -ENOMEM;
if (rx) {
ccid_hc_rx_delete(dp->dccps_hc_rx_ccid, sk);
dp->dccps_hc_rx_ccid = new_ccid;
} else {
ccid_hc_tx_delete(dp->dccps_hc_tx_ccid, sk);
dp->dccps_hc_tx_ccid = new_ccid;
}
return 0;
}
static int dccp_hdlr_seq_win(struct sock *sk, u64 seq_win, bool rx)
{
if (!rx)
dccp_msk(sk)->dccpms_sequence_window = seq_win;
return 0;
}
static int dccp_hdlr_ack_ratio(struct sock *sk, u64 ratio, bool rx)
{
if (rx)
dccp_sk(sk)->dccps_r_ack_ratio = ratio;
else
dccp_sk(sk)->dccps_l_ack_ratio = ratio;
return 0;
}
static int dccp_hdlr_ackvec(struct sock *sk, u64 enable, bool rx)
{
struct dccp_sock *dp = dccp_sk(sk);
if (rx) {
if (enable && dp->dccps_hc_rx_ackvec == NULL) {
dp->dccps_hc_rx_ackvec = dccp_ackvec_alloc(gfp_any());
if (dp->dccps_hc_rx_ackvec == NULL)
return -ENOMEM;
} else if (!enable) {
dccp_ackvec_free(dp->dccps_hc_rx_ackvec);
dp->dccps_hc_rx_ackvec = NULL;
}
}
return 0;
}
static int dccp_hdlr_ndp(struct sock *sk, u64 enable, bool rx)
{
if (!rx)
dccp_msk(sk)->dccpms_send_ndp_count = (enable > 0);
return 0;
}
/*
* Minimum Checksum Coverage is located at the RX side (9.2.1). This means that
* `rx' holds when the sending peer informs about his partial coverage via a
* ChangeR() option. In the other case, we are the sender and the receiver
* announces its coverage via ChangeL() options. The policy here is to honour
* such communication by enabling the corresponding partial coverage - but only
* if it has not been set manually before; the warning here means that all
* packets will be dropped.