2005-08-10 03:14:34 +00:00
|
|
|
/*
|
|
|
|
* net/dccp/proto.c
|
|
|
|
*
|
|
|
|
* An implementation of the DCCP protocol
|
|
|
|
* Arnaldo Carvalho de Melo <acme@conectiva.com.br>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/dccp.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/in.h>
|
|
|
|
#include <linux/if_arp.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/random.h>
|
|
|
|
#include <net/checksum.h>
|
|
|
|
|
2005-12-27 04:43:12 +00:00
|
|
|
#include <net/inet_sock.h>
|
2005-08-10 03:14:34 +00:00
|
|
|
#include <net/sock.h>
|
|
|
|
#include <net/xfrm.h>
|
|
|
|
|
2007-10-24 03:23:30 +00:00
|
|
|
#include <asm/ioctls.h>
|
2005-08-10 03:14:34 +00:00
|
|
|
#include <asm/semaphore.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/timer.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/poll.h>
|
|
|
|
|
|
|
|
#include "ccid.h"
|
|
|
|
#include "dccp.h"
|
[DCCP]: Initial feature negotiation implementation
Still needs more work, but boots and doesn't crashes, even
does some negotiation!
18:38:52.174934 127.0.0.1.43458 > 127.0.0.1.5001: request <change_l ack_ratio 2, change_r ccid 2, change_l ccid 2>
18:38:52.218526 127.0.0.1.5001 > 127.0.0.1.43458: response <nop, nop, change_l ack_ratio 2, confirm_r ccid 2 2, confirm_l ccid 2 2, confirm_r ack_ratio 2>
18:38:52.185398 127.0.0.1.43458 > 127.0.0.1.5001: <nop, confirm_r ack_ratio 2, ack_vector0 0x00, elapsed_time 212>
:-)
Signed-off-by: Andrea Bittau <a.bittau@cs.ucl.ac.uk>
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2006-03-21 01:43:56 +00:00
|
|
|
#include "feat.h"
|
2005-08-10 03:14:34 +00:00
|
|
|
|
2005-08-26 19:05:31 +00:00
|
|
|
DEFINE_SNMP_STAT(struct dccp_mib, dccp_statistics) __read_mostly;
|
2005-08-10 03:14:34 +00:00
|
|
|
|
2005-12-14 07:24:16 +00:00
|
|
|
EXPORT_SYMBOL_GPL(dccp_statistics);
|
|
|
|
|
2005-08-10 03:14:34 +00:00
|
|
|
atomic_t dccp_orphan_count = ATOMIC_INIT(0);
|
|
|
|
|
2005-12-14 07:24:16 +00:00
|
|
|
EXPORT_SYMBOL_GPL(dccp_orphan_count);
|
|
|
|
|
2006-03-21 05:24:19 +00:00
|
|
|
struct inet_hashinfo __cacheline_aligned dccp_hashinfo = {
|
|
|
|
.lhash_lock = RW_LOCK_UNLOCKED,
|
|
|
|
.lhash_users = ATOMIC_INIT(0),
|
|
|
|
.lhash_wait = __WAIT_QUEUE_HEAD_INITIALIZER(dccp_hashinfo.lhash_wait),
|
|
|
|
};
|
|
|
|
|
|
|
|
EXPORT_SYMBOL_GPL(dccp_hashinfo);
|
|
|
|
|
2006-11-20 20:30:17 +00:00
|
|
|
/* the maximum queue length for tx in packets. 0 is no limit */
|
|
|
|
int sysctl_dccp_tx_qlen __read_mostly = 5;
|
|
|
|
|
2006-03-21 05:58:56 +00:00
|
|
|
void dccp_set_state(struct sock *sk, const int state)
|
|
|
|
{
|
|
|
|
const int oldstate = sk->sk_state;
|
|
|
|
|
2007-11-28 13:34:53 +00:00
|
|
|
dccp_pr_debug("%s(%p) %s --> %s\n", dccp_role(sk), sk,
|
2006-03-21 05:58:56 +00:00
|
|
|
dccp_state_name(oldstate), dccp_state_name(state));
|
|
|
|
WARN_ON(state == oldstate);
|
|
|
|
|
|
|
|
switch (state) {
|
|
|
|
case DCCP_OPEN:
|
|
|
|
if (oldstate != DCCP_OPEN)
|
|
|
|
DCCP_INC_STATS(DCCP_MIB_CURRESTAB);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DCCP_CLOSED:
|
[DCCP]: Integrate state transitions for passive-close
This adds the necessary state transitions for the two forms of passive-close
* PASSIVE_CLOSE - which is entered when a host receives a Close;
* PASSIVE_CLOSEREQ - which is entered when a client receives a CloseReq.
Here is a detailed account of what the patch does in each state.
1) Receiving CloseReq
The pseudo-code in 8.5 says:
Step 13: Process CloseReq
If P.type == CloseReq and S.state < CLOSEREQ,
Generate Close
S.state := CLOSING
Set CLOSING timer.
This means we need to address what to do in CLOSED, LISTEN, REQUEST, RESPOND, PARTOPEN, and OPEN.
* CLOSED: silently ignore - it may be a late or duplicate CloseReq;
* LISTEN/RESPOND: will not appear, since Step 7 is performed first (we know we are the client);
* REQUEST: perform Step 13 directly (no need to enqueue packet);
* OPEN/PARTOPEN: enter PASSIVE_CLOSEREQ so that the application has a chance to process unread data.
When already in PASSIVE_CLOSEREQ, no second CloseReq is enqueued. In any other state, the CloseReq is ignored.
I think that this offers some robustness against rare and pathological cases: e.g. a simultaneous close where
the client sends a Close and the server a CloseReq. The client will then be retransmitting its Close until it
gets the Reset, so ignoring the CloseReq while in state CLOSING is sane.
2) Receiving Close
The code below from 8.5 is unconditional.
Step 14: Process Close
If P.type == Close,
Generate Reset(Closed)
Tear down connection
Drop packet and return
Thus we need to consider all states:
* CLOSED: silently ignore, since this can happen when a retransmitted or late Close arrives;
* LISTEN: dccp_rcv_state_process() will generate a Reset ("No Connection");
* REQUEST: perform Step 14 directly (no need to enqueue packet);
* RESPOND: dccp_check_req() will generate a Reset ("Packet Error") -- left it at that;
* OPEN/PARTOPEN: enter PASSIVE_CLOSE so that application has a chance to process unread data;
* CLOSEREQ: server performed active-close -- perform Step 14;
* CLOSING: simultaneous-close: use a tie-breaker to avoid message ping-pong (see comment);
* PASSIVE_CLOSEREQ: ignore - the peer has a bug (sending first a CloseReq and now a Close);
* TIMEWAIT: packet is ignored.
Note that the condition of receiving a packet in state CLOSED here is different from the condition "there
is no socket for such a connection": the socket still exists, but its state indicates it is unusable.
Last, dccp_finish_passive_close sets either DCCP_CLOSED or DCCP_CLOSING = TCP_CLOSING, so that
sk_stream_wait_close() will wait for the final Reset (which will trigger CLOSING => CLOSED).
Signed-off-by: Gerrit Renker <gerrit@erg.abdn.ac.uk>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-11-28 13:59:48 +00:00
|
|
|
if (oldstate == DCCP_OPEN || oldstate == DCCP_ACTIVE_CLOSEREQ ||
|
|
|
|
oldstate == DCCP_CLOSING)
|
2006-03-21 05:58:56 +00:00
|
|
|
DCCP_INC_STATS(DCCP_MIB_ESTABRESETS);
|
|
|
|
|
|
|
|
sk->sk_prot->unhash(sk);
|
|
|
|
if (inet_csk(sk)->icsk_bind_hash != NULL &&
|
|
|
|
!(sk->sk_userlocks & SOCK_BINDPORT_LOCK))
|
[SOCK] proto: Add hashinfo member to struct proto
This way we can remove TCP and DCCP specific versions of
sk->sk_prot->get_port: both v4 and v6 use inet_csk_get_port
sk->sk_prot->hash: inet_hash is directly used, only v6 need
a specific version to deal with mapped sockets
sk->sk_prot->unhash: both v4 and v6 use inet_hash directly
struct inet_connection_sock_af_ops also gets a new member, bind_conflict, so
that inet_csk_get_port can find the per family routine.
Now only the lookup routines receive as a parameter a struct inet_hashtable.
With this we further reuse code, reducing the difference among INET transport
protocols.
Eventually work has to be done on UDP and SCTP to make them share this
infrastructure and get as a bonus inet_diag interfaces so that iproute can be
used with these protocols.
net-2.6/net/ipv4/inet_hashtables.c:
struct proto | +8
struct inet_connection_sock_af_ops | +8
2 structs changed
__inet_hash_nolisten | +18
__inet_hash | -210
inet_put_port | +8
inet_bind_bucket_create | +1
__inet_hash_connect | -8
5 functions changed, 27 bytes added, 218 bytes removed, diff: -191
net-2.6/net/core/sock.c:
proto_seq_show | +3
1 function changed, 3 bytes added, diff: +3
net-2.6/net/ipv4/inet_connection_sock.c:
inet_csk_get_port | +15
1 function changed, 15 bytes added, diff: +15
net-2.6/net/ipv4/tcp.c:
tcp_set_state | -7
1 function changed, 7 bytes removed, diff: -7
net-2.6/net/ipv4/tcp_ipv4.c:
tcp_v4_get_port | -31
tcp_v4_hash | -48
tcp_v4_destroy_sock | -7
tcp_v4_syn_recv_sock | -2
tcp_unhash | -179
5 functions changed, 267 bytes removed, diff: -267
net-2.6/net/ipv6/inet6_hashtables.c:
__inet6_hash | +8
1 function changed, 8 bytes added, diff: +8
net-2.6/net/ipv4/inet_hashtables.c:
inet_unhash | +190
inet_hash | +242
2 functions changed, 432 bytes added, diff: +432
vmlinux:
16 functions changed, 485 bytes added, 492 bytes removed, diff: -7
/home/acme/git/net-2.6/net/ipv6/tcp_ipv6.c:
tcp_v6_get_port | -31
tcp_v6_hash | -7
tcp_v6_syn_recv_sock | -9
3 functions changed, 47 bytes removed, diff: -47
/home/acme/git/net-2.6/net/dccp/proto.c:
dccp_destroy_sock | -7
dccp_unhash | -179
dccp_hash | -49
dccp_set_state | -7
dccp_done | +1
5 functions changed, 1 bytes added, 242 bytes removed, diff: -241
/home/acme/git/net-2.6/net/dccp/ipv4.c:
dccp_v4_get_port | -31
dccp_v4_request_recv_sock | -2
2 functions changed, 33 bytes removed, diff: -33
/home/acme/git/net-2.6/net/dccp/ipv6.c:
dccp_v6_get_port | -31
dccp_v6_hash | -7
dccp_v6_request_recv_sock | +5
3 functions changed, 5 bytes added, 38 bytes removed, diff: -33
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2008-02-03 12:06:04 +00:00
|
|
|
inet_put_port(sk);
|
2006-03-21 05:58:56 +00:00
|
|
|
/* fall through */
|
|
|
|
default:
|
|
|
|
if (oldstate == DCCP_OPEN)
|
|
|
|
DCCP_DEC_STATS(DCCP_MIB_CURRESTAB);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Change state AFTER socket is unhashed to avoid closed
|
|
|
|
* socket sitting in hash tables.
|
|
|
|
*/
|
|
|
|
sk->sk_state = state;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL_GPL(dccp_set_state);
|
|
|
|
|
[DCCP]: Integrate state transitions for passive-close
This adds the necessary state transitions for the two forms of passive-close
* PASSIVE_CLOSE - which is entered when a host receives a Close;
* PASSIVE_CLOSEREQ - which is entered when a client receives a CloseReq.
Here is a detailed account of what the patch does in each state.
1) Receiving CloseReq
The pseudo-code in 8.5 says:
Step 13: Process CloseReq
If P.type == CloseReq and S.state < CLOSEREQ,
Generate Close
S.state := CLOSING
Set CLOSING timer.
This means we need to address what to do in CLOSED, LISTEN, REQUEST, RESPOND, PARTOPEN, and OPEN.
* CLOSED: silently ignore - it may be a late or duplicate CloseReq;
* LISTEN/RESPOND: will not appear, since Step 7 is performed first (we know we are the client);
* REQUEST: perform Step 13 directly (no need to enqueue packet);
* OPEN/PARTOPEN: enter PASSIVE_CLOSEREQ so that the application has a chance to process unread data.
When already in PASSIVE_CLOSEREQ, no second CloseReq is enqueued. In any other state, the CloseReq is ignored.
I think that this offers some robustness against rare and pathological cases: e.g. a simultaneous close where
the client sends a Close and the server a CloseReq. The client will then be retransmitting its Close until it
gets the Reset, so ignoring the CloseReq while in state CLOSING is sane.
2) Receiving Close
The code below from 8.5 is unconditional.
Step 14: Process Close
If P.type == Close,
Generate Reset(Closed)
Tear down connection
Drop packet and return
Thus we need to consider all states:
* CLOSED: silently ignore, since this can happen when a retransmitted or late Close arrives;
* LISTEN: dccp_rcv_state_process() will generate a Reset ("No Connection");
* REQUEST: perform Step 14 directly (no need to enqueue packet);
* RESPOND: dccp_check_req() will generate a Reset ("Packet Error") -- left it at that;
* OPEN/PARTOPEN: enter PASSIVE_CLOSE so that application has a chance to process unread data;
* CLOSEREQ: server performed active-close -- perform Step 14;
* CLOSING: simultaneous-close: use a tie-breaker to avoid message ping-pong (see comment);
* PASSIVE_CLOSEREQ: ignore - the peer has a bug (sending first a CloseReq and now a Close);
* TIMEWAIT: packet is ignored.
Note that the condition of receiving a packet in state CLOSED here is different from the condition "there
is no socket for such a connection": the socket still exists, but its state indicates it is unusable.
Last, dccp_finish_passive_close sets either DCCP_CLOSED or DCCP_CLOSING = TCP_CLOSING, so that
sk_stream_wait_close() will wait for the final Reset (which will trigger CLOSING => CLOSED).
Signed-off-by: Gerrit Renker <gerrit@erg.abdn.ac.uk>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-11-28 13:59:48 +00:00
|
|
|
static void dccp_finish_passive_close(struct sock *sk)
|
|
|
|
{
|
|
|
|
switch (sk->sk_state) {
|
|
|
|
case DCCP_PASSIVE_CLOSE:
|
|
|
|
/* Node (client or server) has received Close packet. */
|
|
|
|
dccp_send_reset(sk, DCCP_RESET_CODE_CLOSED);
|
|
|
|
dccp_set_state(sk, DCCP_CLOSED);
|
|
|
|
break;
|
|
|
|
case DCCP_PASSIVE_CLOSEREQ:
|
|
|
|
/*
|
|
|
|
* Client received CloseReq. We set the `active' flag so that
|
|
|
|
* dccp_send_close() retransmits the Close as per RFC 4340, 8.3.
|
|
|
|
*/
|
|
|
|
dccp_send_close(sk, 1);
|
|
|
|
dccp_set_state(sk, DCCP_CLOSING);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-21 05:58:56 +00:00
|
|
|
void dccp_done(struct sock *sk)
|
|
|
|
{
|
|
|
|
dccp_set_state(sk, DCCP_CLOSED);
|
|
|
|
dccp_clear_xmit_timers(sk);
|
|
|
|
|
|
|
|
sk->sk_shutdown = SHUTDOWN_MASK;
|
|
|
|
|
|
|
|
if (!sock_flag(sk, SOCK_DEAD))
|
|
|
|
sk->sk_state_change(sk);
|
|
|
|
else
|
|
|
|
inet_csk_destroy_sock(sk);
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL_GPL(dccp_done);
|
|
|
|
|
2005-08-10 03:14:34 +00:00
|
|
|
const char *dccp_packet_name(const int type)
|
|
|
|
{
|
|
|
|
static const char *dccp_packet_names[] = {
|
|
|
|
[DCCP_PKT_REQUEST] = "REQUEST",
|
|
|
|
[DCCP_PKT_RESPONSE] = "RESPONSE",
|
|
|
|
[DCCP_PKT_DATA] = "DATA",
|
|
|
|
[DCCP_PKT_ACK] = "ACK",
|
|
|
|
[DCCP_PKT_DATAACK] = "DATAACK",
|
|
|
|
[DCCP_PKT_CLOSEREQ] = "CLOSEREQ",
|
|
|
|
[DCCP_PKT_CLOSE] = "CLOSE",
|
|
|
|
[DCCP_PKT_RESET] = "RESET",
|
|
|
|
[DCCP_PKT_SYNC] = "SYNC",
|
|
|
|
[DCCP_PKT_SYNCACK] = "SYNCACK",
|
|
|
|
};
|
|
|
|
|
|
|
|
if (type >= DCCP_NR_PKT_TYPES)
|
|
|
|
return "INVALID";
|
|
|
|
else
|
|
|
|
return dccp_packet_names[type];
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL_GPL(dccp_packet_name);
|
|
|
|
|
|
|
|
const char *dccp_state_name(const int state)
|
|
|
|
{
|
|
|
|
static char *dccp_state_names[] = {
|
2007-11-28 13:34:53 +00:00
|
|
|
[DCCP_OPEN] = "OPEN",
|
|
|
|
[DCCP_REQUESTING] = "REQUESTING",
|
|
|
|
[DCCP_PARTOPEN] = "PARTOPEN",
|
|
|
|
[DCCP_LISTEN] = "LISTEN",
|
|
|
|
[DCCP_RESPOND] = "RESPOND",
|
|
|
|
[DCCP_CLOSING] = "CLOSING",
|
|
|
|
[DCCP_ACTIVE_CLOSEREQ] = "CLOSEREQ",
|
|
|
|
[DCCP_PASSIVE_CLOSE] = "PASSIVE_CLOSE",
|
|
|
|
[DCCP_PASSIVE_CLOSEREQ] = "PASSIVE_CLOSEREQ",
|
|
|
|
[DCCP_TIME_WAIT] = "TIME_WAIT",
|
|
|
|
[DCCP_CLOSED] = "CLOSED",
|
2005-08-10 03:14:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (state >= DCCP_MAX_STATES)
|
|
|
|
return "INVALID STATE!";
|
|
|
|
else
|
|
|
|
return dccp_state_names[state];
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL_GPL(dccp_state_name);
|
|
|
|
|
2006-03-21 06:00:37 +00:00
|
|
|
int dccp_init_sock(struct sock *sk, const __u8 ctl_sock_initialized)
|
2006-03-21 05:23:15 +00:00
|
|
|
{
|
|
|
|
struct dccp_sock *dp = dccp_sk(sk);
|
2006-03-21 06:50:58 +00:00
|
|
|
struct dccp_minisock *dmsk = dccp_msk(sk);
|
2006-03-21 05:23:15 +00:00
|
|
|
struct inet_connection_sock *icsk = inet_csk(sk);
|
|
|
|
|
2006-03-21 06:50:58 +00:00
|
|
|
dccp_minisock_init(&dp->dccps_minisock);
|
2006-03-21 05:23:15 +00:00
|
|
|
|
2007-11-24 23:42:53 +00:00
|
|
|
icsk->icsk_rto = DCCP_TIMEOUT_INIT;
|
|
|
|
icsk->icsk_syn_retries = sysctl_dccp_request_retries;
|
|
|
|
sk->sk_state = DCCP_CLOSED;
|
|
|
|
sk->sk_write_space = dccp_write_space;
|
|
|
|
icsk->icsk_sync_mss = dccp_sync_mss;
|
|
|
|
dp->dccps_mss_cache = 536;
|
|
|
|
dp->dccps_rate_last = jiffies;
|
|
|
|
dp->dccps_role = DCCP_ROLE_UNDEFINED;
|
|
|
|
dp->dccps_service = DCCP_SERVICE_CODE_IS_ABSENT;
|
|
|
|
dp->dccps_l_ack_ratio = dp->dccps_r_ack_ratio = 1;
|
|
|
|
|
|
|
|
dccp_init_xmit_timers(sk);
|
|
|
|
|
2006-03-21 05:23:15 +00:00
|
|
|
/*
|
|
|
|
* FIXME: We're hardcoding the CCID, and doing this at this point makes
|
|
|
|
* the listening (master) sock get CCID control blocks, which is not
|
|
|
|
* necessary, but for now, to not mess with the test userspace apps,
|
|
|
|
* lets leave it here, later the real solution is to do this in a
|
|
|
|
* setsockopt(CCIDs-I-want/accept). -acme
|
|
|
|
*/
|
2006-03-21 06:00:37 +00:00
|
|
|
if (likely(ctl_sock_initialized)) {
|
2006-03-21 06:51:53 +00:00
|
|
|
int rc = dccp_feat_init(dmsk);
|
2006-03-21 05:23:15 +00:00
|
|
|
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
2006-03-21 06:50:58 +00:00
|
|
|
if (dmsk->dccpms_send_ack_vector) {
|
2006-03-21 05:23:15 +00:00
|
|
|
dp->dccps_hc_rx_ackvec = dccp_ackvec_alloc(GFP_KERNEL);
|
|
|
|
if (dp->dccps_hc_rx_ackvec == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2006-03-21 06:50:58 +00:00
|
|
|
dp->dccps_hc_rx_ccid = ccid_hc_rx_new(dmsk->dccpms_rx_ccid,
|
|
|
|
sk, GFP_KERNEL);
|
|
|
|
dp->dccps_hc_tx_ccid = ccid_hc_tx_new(dmsk->dccpms_tx_ccid,
|
|
|
|
sk, GFP_KERNEL);
|
2006-12-10 18:01:18 +00:00
|
|
|
if (unlikely(dp->dccps_hc_rx_ccid == NULL ||
|
2006-03-21 05:23:15 +00:00
|
|
|
dp->dccps_hc_tx_ccid == NULL)) {
|
|
|
|
ccid_hc_rx_delete(dp->dccps_hc_rx_ccid, sk);
|
|
|
|
ccid_hc_tx_delete(dp->dccps_hc_tx_ccid, sk);
|
2006-03-21 06:50:58 +00:00
|
|
|
if (dmsk->dccpms_send_ack_vector) {
|
2006-03-21 05:23:15 +00:00
|
|
|
dccp_ackvec_free(dp->dccps_hc_rx_ackvec);
|
|
|
|
dp->dccps_hc_rx_ackvec = NULL;
|
|
|
|
}
|
|
|
|
dp->dccps_hc_rx_ccid = dp->dccps_hc_tx_ccid = NULL;
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* control socket doesn't need feat nego */
|
2006-03-21 06:50:58 +00:00
|
|
|
INIT_LIST_HEAD(&dmsk->dccpms_pending);
|
|
|
|
INIT_LIST_HEAD(&dmsk->dccpms_conf);
|
2006-03-21 05:23:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL_GPL(dccp_init_sock);
|
|
|
|
|
|
|
|
int dccp_destroy_sock(struct sock *sk)
|
|
|
|
{
|
|
|
|
struct dccp_sock *dp = dccp_sk(sk);
|
2006-03-21 06:51:53 +00:00
|
|
|
struct dccp_minisock *dmsk = dccp_msk(sk);
|
2006-03-21 05:23:15 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* DCCP doesn't use sk_write_queue, just sk_send_head
|
|
|
|
* for retransmissions
|
|
|
|
*/
|
|
|
|
if (sk->sk_send_head != NULL) {
|
|
|
|
kfree_skb(sk->sk_send_head);
|
|
|
|
sk->sk_send_head = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clean up a referenced DCCP bind bucket. */
|
|
|
|
if (inet_csk(sk)->icsk_bind_hash != NULL)
|
[SOCK] proto: Add hashinfo member to struct proto
This way we can remove TCP and DCCP specific versions of
sk->sk_prot->get_port: both v4 and v6 use inet_csk_get_port
sk->sk_prot->hash: inet_hash is directly used, only v6 need
a specific version to deal with mapped sockets
sk->sk_prot->unhash: both v4 and v6 use inet_hash directly
struct inet_connection_sock_af_ops also gets a new member, bind_conflict, so
that inet_csk_get_port can find the per family routine.
Now only the lookup routines receive as a parameter a struct inet_hashtable.
With this we further reuse code, reducing the difference among INET transport
protocols.
Eventually work has to be done on UDP and SCTP to make them share this
infrastructure and get as a bonus inet_diag interfaces so that iproute can be
used with these protocols.
net-2.6/net/ipv4/inet_hashtables.c:
struct proto | +8
struct inet_connection_sock_af_ops | +8
2 structs changed
__inet_hash_nolisten | +18
__inet_hash | -210
inet_put_port | +8
inet_bind_bucket_create | +1
__inet_hash_connect | -8
5 functions changed, 27 bytes added, 218 bytes removed, diff: -191
net-2.6/net/core/sock.c:
proto_seq_show | +3
1 function changed, 3 bytes added, diff: +3
net-2.6/net/ipv4/inet_connection_sock.c:
inet_csk_get_port | +15
1 function changed, 15 bytes added, diff: +15
net-2.6/net/ipv4/tcp.c:
tcp_set_state | -7
1 function changed, 7 bytes removed, diff: -7
net-2.6/net/ipv4/tcp_ipv4.c:
tcp_v4_get_port | -31
tcp_v4_hash | -48
tcp_v4_destroy_sock | -7
tcp_v4_syn_recv_sock | -2
tcp_unhash | -179
5 functions changed, 267 bytes removed, diff: -267
net-2.6/net/ipv6/inet6_hashtables.c:
__inet6_hash | +8
1 function changed, 8 bytes added, diff: +8
net-2.6/net/ipv4/inet_hashtables.c:
inet_unhash | +190
inet_hash | +242
2 functions changed, 432 bytes added, diff: +432
vmlinux:
16 functions changed, 485 bytes added, 492 bytes removed, diff: -7
/home/acme/git/net-2.6/net/ipv6/tcp_ipv6.c:
tcp_v6_get_port | -31
tcp_v6_hash | -7
tcp_v6_syn_recv_sock | -9
3 functions changed, 47 bytes removed, diff: -47
/home/acme/git/net-2.6/net/dccp/proto.c:
dccp_destroy_sock | -7
dccp_unhash | -179
dccp_hash | -49
dccp_set_state | -7
dccp_done | +1
5 functions changed, 1 bytes added, 242 bytes removed, diff: -241
/home/acme/git/net-2.6/net/dccp/ipv4.c:
dccp_v4_get_port | -31
dccp_v4_request_recv_sock | -2
2 functions changed, 33 bytes removed, diff: -33
/home/acme/git/net-2.6/net/dccp/ipv6.c:
dccp_v6_get_port | -31
dccp_v6_hash | -7
dccp_v6_request_recv_sock | +5
3 functions changed, 5 bytes added, 38 bytes removed, diff: -33
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2008-02-03 12:06:04 +00:00
|
|
|
inet_put_port(sk);
|
2006-03-21 05:23:15 +00:00
|
|
|
|
|
|
|
kfree(dp->dccps_service_list);
|
|
|
|
dp->dccps_service_list = NULL;
|
|
|
|
|
2006-03-21 06:51:53 +00:00
|
|
|
if (dmsk->dccpms_send_ack_vector) {
|
2006-03-21 05:23:15 +00:00
|
|
|
dccp_ackvec_free(dp->dccps_hc_rx_ackvec);
|
|
|
|
dp->dccps_hc_rx_ackvec = NULL;
|
|
|
|
}
|
|
|
|
ccid_hc_rx_delete(dp->dccps_hc_rx_ccid, sk);
|
|
|
|
ccid_hc_tx_delete(dp->dccps_hc_tx_ccid, sk);
|
|
|
|
dp->dccps_hc_rx_ccid = dp->dccps_hc_tx_ccid = NULL;
|
|
|
|
|
|
|
|
/* clean up feature negotiation state */
|
2006-03-21 06:51:53 +00:00
|
|
|
dccp_feat_clean(dmsk);
|
2006-03-21 05:23:15 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL_GPL(dccp_destroy_sock);
|
|
|
|
|
2006-11-16 10:30:37 +00:00
|
|
|
static inline int dccp_listen_start(struct sock *sk, int backlog)
|
2005-08-10 03:14:34 +00:00
|
|
|
{
|
2005-09-16 23:58:40 +00:00
|
|
|
struct dccp_sock *dp = dccp_sk(sk);
|
|
|
|
|
|
|
|
dp->dccps_role = DCCP_ROLE_LISTEN;
|
2006-11-16 10:30:37 +00:00
|
|
|
return inet_csk_listen_start(sk, backlog);
|
2005-08-10 03:14:34 +00:00
|
|
|
}
|
|
|
|
|
2007-11-25 00:14:15 +00:00
|
|
|
static inline int dccp_need_reset(int state)
|
|
|
|
{
|
|
|
|
return state != DCCP_CLOSED && state != DCCP_LISTEN &&
|
|
|
|
state != DCCP_REQUESTING;
|
|
|
|
}
|
|
|
|
|
2005-08-10 03:14:34 +00:00
|
|
|
int dccp_disconnect(struct sock *sk, int flags)
|
|
|
|
{
|
|
|
|
struct inet_connection_sock *icsk = inet_csk(sk);
|
|
|
|
struct inet_sock *inet = inet_sk(sk);
|
|
|
|
int err = 0;
|
|
|
|
const int old_state = sk->sk_state;
|
|
|
|
|
|
|
|
if (old_state != DCCP_CLOSED)
|
|
|
|
dccp_set_state(sk, DCCP_CLOSED);
|
|
|
|
|
2007-11-25 00:14:15 +00:00
|
|
|
/*
|
|
|
|
* This corresponds to the ABORT function of RFC793, sec. 3.8
|
|
|
|
* TCP uses a RST segment, DCCP a Reset packet with Code 2, "Aborted".
|
|
|
|
*/
|
2005-08-10 03:14:34 +00:00
|
|
|
if (old_state == DCCP_LISTEN) {
|
|
|
|
inet_csk_listen_stop(sk);
|
2007-11-25 00:14:15 +00:00
|
|
|
} else if (dccp_need_reset(old_state)) {
|
|
|
|
dccp_send_reset(sk, DCCP_RESET_CODE_ABORTED);
|
|
|
|
sk->sk_err = ECONNRESET;
|
2005-08-10 03:14:34 +00:00
|
|
|
} else if (old_state == DCCP_REQUESTING)
|
|
|
|
sk->sk_err = ECONNRESET;
|
|
|
|
|
|
|
|
dccp_clear_xmit_timers(sk);
|
|
|
|
__skb_queue_purge(&sk->sk_receive_queue);
|
|
|
|
if (sk->sk_send_head != NULL) {
|
|
|
|
__kfree_skb(sk->sk_send_head);
|
|
|
|
sk->sk_send_head = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
inet->dport = 0;
|
|
|
|
|
|
|
|
if (!(sk->sk_userlocks & SOCK_BINDADDR_LOCK))
|
|
|
|
inet_reset_saddr(sk);
|
|
|
|
|
|
|
|
sk->sk_shutdown = 0;
|
|
|
|
sock_reset_flag(sk, SOCK_DONE);
|
|
|
|
|
|
|
|
icsk->icsk_backoff = 0;
|
|
|
|
inet_csk_delack_init(sk);
|
|
|
|
__sk_dst_reset(sk);
|
|
|
|
|
|
|
|
BUG_TRAP(!inet->num || icsk->icsk_bind_hash);
|
|
|
|
|
|
|
|
sk->sk_error_report(sk);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2005-12-14 07:24:16 +00:00
|
|
|
EXPORT_SYMBOL_GPL(dccp_disconnect);
|
|
|
|
|
2005-08-24 04:54:23 +00:00
|
|
|
/*
|
|
|
|
* Wait for a DCCP event.
|
|
|
|
*
|
|
|
|
* Note that we don't need to lock the socket, as the upper poll layers
|
|
|
|
* take care of normal races (between the test and the event) and we don't
|
|
|
|
* go look at any of the socket buffers directly.
|
|
|
|
*/
|
2005-12-14 07:24:16 +00:00
|
|
|
unsigned int dccp_poll(struct file *file, struct socket *sock,
|
|
|
|
poll_table *wait)
|
2005-08-24 04:54:23 +00:00
|
|
|
{
|
|
|
|
unsigned int mask;
|
|
|
|
struct sock *sk = sock->sk;
|
|
|
|
|
|
|
|
poll_wait(file, sk->sk_sleep, wait);
|
|
|
|
if (sk->sk_state == DCCP_LISTEN)
|
|
|
|
return inet_csk_listen_poll(sk);
|
|
|
|
|
|
|
|
/* Socket is not locked. We are protected from async events
|
|
|
|
by poll logic and correct handling of state changes
|
|
|
|
made by another threads is impossible in any case.
|
|
|
|
*/
|
|
|
|
|
|
|
|
mask = 0;
|
|
|
|
if (sk->sk_err)
|
|
|
|
mask = POLLERR;
|
|
|
|
|
|
|
|
if (sk->sk_shutdown == SHUTDOWN_MASK || sk->sk_state == DCCP_CLOSED)
|
|
|
|
mask |= POLLHUP;
|
|
|
|
if (sk->sk_shutdown & RCV_SHUTDOWN)
|
2006-03-25 11:07:39 +00:00
|
|
|
mask |= POLLIN | POLLRDNORM | POLLRDHUP;
|
2005-08-24 04:54:23 +00:00
|
|
|
|
|
|
|
/* Connected? */
|
|
|
|
if ((1 << sk->sk_state) & ~(DCCPF_REQUESTING | DCCPF_RESPOND)) {
|
|
|
|
if (atomic_read(&sk->sk_rmem_alloc) > 0)
|
|
|
|
mask |= POLLIN | POLLRDNORM;
|
|
|
|
|
|
|
|
if (!(sk->sk_shutdown & SEND_SHUTDOWN)) {
|
|
|
|
if (sk_stream_wspace(sk) >= sk_stream_min_wspace(sk)) {
|
|
|
|
mask |= POLLOUT | POLLWRNORM;
|
|
|
|
} else { /* send SIGIO later */
|
|
|
|
set_bit(SOCK_ASYNC_NOSPACE,
|
|
|
|
&sk->sk_socket->flags);
|
|
|
|
set_bit(SOCK_NOSPACE, &sk->sk_socket->flags);
|
|
|
|
|
|
|
|
/* Race breaker. If space is freed after
|
|
|
|
* wspace test but before the flags are set,
|
|
|
|
* IO signal will be lost.
|
|
|
|
*/
|
|
|
|
if (sk_stream_wspace(sk) >= sk_stream_min_wspace(sk))
|
|
|
|
mask |= POLLOUT | POLLWRNORM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return mask;
|
|
|
|
}
|
|
|
|
|
2005-12-14 07:24:16 +00:00
|
|
|
EXPORT_SYMBOL_GPL(dccp_poll);
|
|
|
|
|
2005-08-10 03:14:34 +00:00
|
|
|
int dccp_ioctl(struct sock *sk, int cmd, unsigned long arg)
|
|
|
|
{
|
2007-10-24 03:23:30 +00:00
|
|
|
int rc = -ENOTCONN;
|
|
|
|
|
|
|
|
lock_sock(sk);
|
|
|
|
|
|
|
|
if (sk->sk_state == DCCP_LISTEN)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case SIOCINQ: {
|
|
|
|
struct sk_buff *skb;
|
|
|
|
unsigned long amount = 0;
|
|
|
|
|
|
|
|
skb = skb_peek(&sk->sk_receive_queue);
|
|
|
|
if (skb != NULL) {
|
|
|
|
/*
|
|
|
|
* We will only return the amount of this packet since
|
|
|
|
* that is all that will be read.
|
|
|
|
*/
|
|
|
|
amount = skb->len;
|
|
|
|
}
|
|
|
|
rc = put_user(amount, (int __user *)arg);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
rc = -ENOIOCTLCMD;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
release_sock(sk);
|
|
|
|
return rc;
|
2005-08-10 03:14:34 +00:00
|
|
|
}
|
|
|
|
|
2005-12-14 07:24:16 +00:00
|
|
|
EXPORT_SYMBOL_GPL(dccp_ioctl);
|
|
|
|
|
2006-03-21 03:23:32 +00:00
|
|
|
static int dccp_setsockopt_service(struct sock *sk, const __be32 service,
|
2005-09-16 23:58:40 +00:00
|
|
|
char __user *optval, int optlen)
|
|
|
|
{
|
|
|
|
struct dccp_sock *dp = dccp_sk(sk);
|
|
|
|
struct dccp_service_list *sl = NULL;
|
|
|
|
|
2006-12-10 18:01:18 +00:00
|
|
|
if (service == DCCP_SERVICE_INVALID_VALUE ||
|
2005-09-16 23:58:40 +00:00
|
|
|
optlen > DCCP_SERVICE_LIST_MAX_LEN * sizeof(u32))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (optlen > sizeof(service)) {
|
|
|
|
sl = kmalloc(optlen, GFP_KERNEL);
|
|
|
|
if (sl == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
sl->dccpsl_nr = optlen / sizeof(u32) - 1;
|
|
|
|
if (copy_from_user(sl->dccpsl_list,
|
|
|
|
optval + sizeof(service),
|
|
|
|
optlen - sizeof(service)) ||
|
|
|
|
dccp_list_has_service(sl, DCCP_SERVICE_INVALID_VALUE)) {
|
|
|
|
kfree(sl);
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
lock_sock(sk);
|
|
|
|
dp->dccps_service = service;
|
|
|
|
|
2005-11-08 17:41:34 +00:00
|
|
|
kfree(dp->dccps_service_list);
|
2005-09-16 23:58:40 +00:00
|
|
|
|
|
|
|
dp->dccps_service_list = sl;
|
|
|
|
release_sock(sk);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
[DCCP]: Initial feature negotiation implementation
Still needs more work, but boots and doesn't crashes, even
does some negotiation!
18:38:52.174934 127.0.0.1.43458 > 127.0.0.1.5001: request <change_l ack_ratio 2, change_r ccid 2, change_l ccid 2>
18:38:52.218526 127.0.0.1.5001 > 127.0.0.1.43458: response <nop, nop, change_l ack_ratio 2, confirm_r ccid 2 2, confirm_l ccid 2 2, confirm_r ack_ratio 2>
18:38:52.185398 127.0.0.1.43458 > 127.0.0.1.5001: <nop, confirm_r ack_ratio 2, ack_vector0 0x00, elapsed_time 212>
:-)
Signed-off-by: Andrea Bittau <a.bittau@cs.ucl.ac.uk>
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2006-03-21 01:43:56 +00:00
|
|
|
/* byte 1 is feature. the rest is the preference list */
|
|
|
|
static int dccp_setsockopt_change(struct sock *sk, int type,
|
|
|
|
struct dccp_so_feat __user *optval)
|
|
|
|
{
|
|
|
|
struct dccp_so_feat opt;
|
|
|
|
u8 *val;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (copy_from_user(&opt, optval, sizeof(opt)))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
val = kmalloc(opt.dccpsf_len, GFP_KERNEL);
|
|
|
|
if (!val)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
if (copy_from_user(val, opt.dccpsf_val, opt.dccpsf_len)) {
|
|
|
|
rc = -EFAULT;
|
|
|
|
goto out_free_val;
|
|
|
|
}
|
|
|
|
|
2006-03-21 06:51:53 +00:00
|
|
|
rc = dccp_feat_change(dccp_msk(sk), type, opt.dccpsf_feat,
|
|
|
|
val, opt.dccpsf_len, GFP_KERNEL);
|
[DCCP]: Initial feature negotiation implementation
Still needs more work, but boots and doesn't crashes, even
does some negotiation!
18:38:52.174934 127.0.0.1.43458 > 127.0.0.1.5001: request <change_l ack_ratio 2, change_r ccid 2, change_l ccid 2>
18:38:52.218526 127.0.0.1.5001 > 127.0.0.1.43458: response <nop, nop, change_l ack_ratio 2, confirm_r ccid 2 2, confirm_l ccid 2 2, confirm_r ack_ratio 2>
18:38:52.185398 127.0.0.1.43458 > 127.0.0.1.5001: <nop, confirm_r ack_ratio 2, ack_vector0 0x00, elapsed_time 212>
:-)
Signed-off-by: Andrea Bittau <a.bittau@cs.ucl.ac.uk>
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2006-03-21 01:43:56 +00:00
|
|
|
if (rc)
|
|
|
|
goto out_free_val;
|
|
|
|
|
|
|
|
out:
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
out_free_val:
|
|
|
|
kfree(val);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2006-03-21 06:45:21 +00:00
|
|
|
static int do_dccp_setsockopt(struct sock *sk, int level, int optname,
|
|
|
|
char __user *optval, int optlen)
|
2005-08-10 03:14:34 +00:00
|
|
|
{
|
2006-11-14 14:57:34 +00:00
|
|
|
struct dccp_sock *dp = dccp_sk(sk);
|
|
|
|
int val, err = 0;
|
2005-08-10 03:14:34 +00:00
|
|
|
|
2005-08-28 07:51:32 +00:00
|
|
|
if (optlen < sizeof(int))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (get_user(val, (int __user *)optval))
|
|
|
|
return -EFAULT;
|
|
|
|
|
2005-09-16 23:58:40 +00:00
|
|
|
if (optname == DCCP_SOCKOPT_SERVICE)
|
|
|
|
return dccp_setsockopt_service(sk, val, optval, optlen);
|
2005-08-28 07:51:32 +00:00
|
|
|
|
2005-09-16 23:58:40 +00:00
|
|
|
lock_sock(sk);
|
2005-08-28 07:51:32 +00:00
|
|
|
switch (optname) {
|
|
|
|
case DCCP_SOCKOPT_PACKET_SIZE:
|
2006-11-28 21:33:36 +00:00
|
|
|
DCCP_WARN("sockopt(PACKET_SIZE) is deprecated: fix your app\n");
|
2006-11-28 21:42:03 +00:00
|
|
|
err = 0;
|
2005-08-28 07:51:32 +00:00
|
|
|
break;
|
[DCCP]: Initial feature negotiation implementation
Still needs more work, but boots and doesn't crashes, even
does some negotiation!
18:38:52.174934 127.0.0.1.43458 > 127.0.0.1.5001: request <change_l ack_ratio 2, change_r ccid 2, change_l ccid 2>
18:38:52.218526 127.0.0.1.5001 > 127.0.0.1.43458: response <nop, nop, change_l ack_ratio 2, confirm_r ccid 2 2, confirm_l ccid 2 2, confirm_r ack_ratio 2>
18:38:52.185398 127.0.0.1.43458 > 127.0.0.1.5001: <nop, confirm_r ack_ratio 2, ack_vector0 0x00, elapsed_time 212>
:-)
Signed-off-by: Andrea Bittau <a.bittau@cs.ucl.ac.uk>
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2006-03-21 01:43:56 +00:00
|
|
|
case DCCP_SOCKOPT_CHANGE_L:
|
|
|
|
if (optlen != sizeof(struct dccp_so_feat))
|
|
|
|
err = -EINVAL;
|
|
|
|
else
|
|
|
|
err = dccp_setsockopt_change(sk, DCCPO_CHANGE_L,
|
2007-02-09 14:24:38 +00:00
|
|
|
(struct dccp_so_feat __user *)
|
[DCCP]: Initial feature negotiation implementation
Still needs more work, but boots and doesn't crashes, even
does some negotiation!
18:38:52.174934 127.0.0.1.43458 > 127.0.0.1.5001: request <change_l ack_ratio 2, change_r ccid 2, change_l ccid 2>
18:38:52.218526 127.0.0.1.5001 > 127.0.0.1.43458: response <nop, nop, change_l ack_ratio 2, confirm_r ccid 2 2, confirm_l ccid 2 2, confirm_r ack_ratio 2>
18:38:52.185398 127.0.0.1.43458 > 127.0.0.1.5001: <nop, confirm_r ack_ratio 2, ack_vector0 0x00, elapsed_time 212>
:-)
Signed-off-by: Andrea Bittau <a.bittau@cs.ucl.ac.uk>
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2006-03-21 01:43:56 +00:00
|
|
|
optval);
|
|
|
|
break;
|
|
|
|
case DCCP_SOCKOPT_CHANGE_R:
|
|
|
|
if (optlen != sizeof(struct dccp_so_feat))
|
|
|
|
err = -EINVAL;
|
|
|
|
else
|
|
|
|
err = dccp_setsockopt_change(sk, DCCPO_CHANGE_R,
|
2006-07-10 21:24:23 +00:00
|
|
|
(struct dccp_so_feat __user *)
|
[DCCP]: Initial feature negotiation implementation
Still needs more work, but boots and doesn't crashes, even
does some negotiation!
18:38:52.174934 127.0.0.1.43458 > 127.0.0.1.5001: request <change_l ack_ratio 2, change_r ccid 2, change_l ccid 2>
18:38:52.218526 127.0.0.1.5001 > 127.0.0.1.43458: response <nop, nop, change_l ack_ratio 2, confirm_r ccid 2 2, confirm_l ccid 2 2, confirm_r ack_ratio 2>
18:38:52.185398 127.0.0.1.43458 > 127.0.0.1.5001: <nop, confirm_r ack_ratio 2, ack_vector0 0x00, elapsed_time 212>
:-)
Signed-off-by: Andrea Bittau <a.bittau@cs.ucl.ac.uk>
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2006-03-21 01:43:56 +00:00
|
|
|
optval);
|
|
|
|
break;
|
2007-12-13 14:25:01 +00:00
|
|
|
case DCCP_SOCKOPT_SERVER_TIMEWAIT:
|
|
|
|
if (dp->dccps_role != DCCP_ROLE_SERVER)
|
|
|
|
err = -EOPNOTSUPP;
|
|
|
|
else
|
|
|
|
dp->dccps_server_timewait = (val != 0);
|
|
|
|
break;
|
2006-11-10 19:43:06 +00:00
|
|
|
case DCCP_SOCKOPT_SEND_CSCOV: /* sender side, RFC 4340, sec. 9.2 */
|
|
|
|
if (val < 0 || val > 15)
|
|
|
|
err = -EINVAL;
|
|
|
|
else
|
|
|
|
dp->dccps_pcslen = val;
|
|
|
|
break;
|
|
|
|
case DCCP_SOCKOPT_RECV_CSCOV: /* receiver side, RFC 4340 sec. 9.2.1 */
|
|
|
|
if (val < 0 || val > 15)
|
|
|
|
err = -EINVAL;
|
|
|
|
else {
|
|
|
|
dp->dccps_pcrlen = val;
|
|
|
|
/* FIXME: add feature negotiation,
|
|
|
|
* ChangeL(MinimumChecksumCoverage, val) */
|
|
|
|
}
|
|
|
|
break;
|
2005-08-28 07:51:32 +00:00
|
|
|
default:
|
|
|
|
err = -ENOPROTOOPT;
|
|
|
|
break;
|
|
|
|
}
|
2006-11-10 19:43:06 +00:00
|
|
|
|
2005-08-28 07:51:32 +00:00
|
|
|
release_sock(sk);
|
|
|
|
return err;
|
2005-08-10 03:14:34 +00:00
|
|
|
}
|
|
|
|
|
2006-03-21 06:45:21 +00:00
|
|
|
int dccp_setsockopt(struct sock *sk, int level, int optname,
|
|
|
|
char __user *optval, int optlen)
|
|
|
|
{
|
|
|
|
if (level != SOL_DCCP)
|
|
|
|
return inet_csk(sk)->icsk_af_ops->setsockopt(sk, level,
|
|
|
|
optname, optval,
|
|
|
|
optlen);
|
|
|
|
return do_dccp_setsockopt(sk, level, optname, optval, optlen);
|
|
|
|
}
|
2006-03-21 06:48:35 +00:00
|
|
|
|
2005-12-14 07:24:16 +00:00
|
|
|
EXPORT_SYMBOL_GPL(dccp_setsockopt);
|
|
|
|
|
2006-03-21 06:45:21 +00:00
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
int compat_dccp_setsockopt(struct sock *sk, int level, int optname,
|
2006-03-21 06:48:35 +00:00
|
|
|
char __user *optval, int optlen)
|
2006-03-21 06:45:21 +00:00
|
|
|
{
|
2006-03-21 06:46:16 +00:00
|
|
|
if (level != SOL_DCCP)
|
|
|
|
return inet_csk_compat_setsockopt(sk, level, optname,
|
|
|
|
optval, optlen);
|
2006-03-21 06:45:21 +00:00
|
|
|
return do_dccp_setsockopt(sk, level, optname, optval, optlen);
|
|
|
|
}
|
2006-03-21 06:48:35 +00:00
|
|
|
|
2006-03-21 06:45:21 +00:00
|
|
|
EXPORT_SYMBOL_GPL(compat_dccp_setsockopt);
|
|
|
|
#endif
|
|
|
|
|
2005-09-16 23:58:40 +00:00
|
|
|
static int dccp_getsockopt_service(struct sock *sk, int len,
|
2006-03-21 03:23:32 +00:00
|
|
|
__be32 __user *optval,
|
2005-09-16 23:58:40 +00:00
|
|
|
int __user *optlen)
|
|
|
|
{
|
|
|
|
const struct dccp_sock *dp = dccp_sk(sk);
|
|
|
|
const struct dccp_service_list *sl;
|
|
|
|
int err = -ENOENT, slen = 0, total_len = sizeof(u32);
|
|
|
|
|
|
|
|
lock_sock(sk);
|
|
|
|
if ((sl = dp->dccps_service_list) != NULL) {
|
|
|
|
slen = sl->dccpsl_nr * sizeof(u32);
|
|
|
|
total_len += slen;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = -EINVAL;
|
|
|
|
if (total_len > len)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
err = 0;
|
|
|
|
if (put_user(total_len, optlen) ||
|
|
|
|
put_user(dp->dccps_service, optval) ||
|
|
|
|
(sl != NULL && copy_to_user(optval + 1, sl->dccpsl_list, slen)))
|
|
|
|
err = -EFAULT;
|
|
|
|
out:
|
|
|
|
release_sock(sk);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2006-03-21 06:45:21 +00:00
|
|
|
static int do_dccp_getsockopt(struct sock *sk, int level, int optname,
|
2005-08-14 01:42:25 +00:00
|
|
|
char __user *optval, int __user *optlen)
|
2005-08-10 03:14:34 +00:00
|
|
|
{
|
2005-08-28 07:51:32 +00:00
|
|
|
struct dccp_sock *dp;
|
|
|
|
int val, len;
|
2005-08-10 03:14:34 +00:00
|
|
|
|
2005-08-28 07:51:32 +00:00
|
|
|
if (get_user(len, optlen))
|
|
|
|
return -EFAULT;
|
|
|
|
|
2007-03-28 18:54:32 +00:00
|
|
|
if (len < (int)sizeof(int))
|
2005-08-28 07:51:32 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
dp = dccp_sk(sk);
|
|
|
|
|
|
|
|
switch (optname) {
|
|
|
|
case DCCP_SOCKOPT_PACKET_SIZE:
|
2006-11-28 21:33:36 +00:00
|
|
|
DCCP_WARN("sockopt(PACKET_SIZE) is deprecated: fix your app\n");
|
2006-11-28 21:42:03 +00:00
|
|
|
return 0;
|
2005-09-18 07:19:32 +00:00
|
|
|
case DCCP_SOCKOPT_SERVICE:
|
|
|
|
return dccp_getsockopt_service(sk, len,
|
2006-03-21 03:23:32 +00:00
|
|
|
(__be32 __user *)optval, optlen);
|
2007-10-04 21:39:22 +00:00
|
|
|
case DCCP_SOCKOPT_GET_CUR_MPS:
|
|
|
|
val = dp->dccps_mss_cache;
|
|
|
|
break;
|
2007-12-13 14:25:01 +00:00
|
|
|
case DCCP_SOCKOPT_SERVER_TIMEWAIT:
|
|
|
|
val = dp->dccps_server_timewait;
|
|
|
|
break;
|
2006-11-10 19:43:06 +00:00
|
|
|
case DCCP_SOCKOPT_SEND_CSCOV:
|
|
|
|
val = dp->dccps_pcslen;
|
|
|
|
break;
|
|
|
|
case DCCP_SOCKOPT_RECV_CSCOV:
|
|
|
|
val = dp->dccps_pcrlen;
|
|
|
|
break;
|
2005-09-18 07:19:32 +00:00
|
|
|
case 128 ... 191:
|
|
|
|
return ccid_hc_rx_getsockopt(dp->dccps_hc_rx_ccid, sk, optname,
|
|
|
|
len, (u32 __user *)optval, optlen);
|
|
|
|
case 192 ... 255:
|
|
|
|
return ccid_hc_tx_getsockopt(dp->dccps_hc_tx_ccid, sk, optname,
|
|
|
|
len, (u32 __user *)optval, optlen);
|
2005-08-28 07:51:32 +00:00
|
|
|
default:
|
|
|
|
return -ENOPROTOOPT;
|
|
|
|
}
|
|
|
|
|
2007-12-13 14:27:14 +00:00
|
|
|
len = sizeof(val);
|
2005-08-28 07:51:32 +00:00
|
|
|
if (put_user(len, optlen) || copy_to_user(optval, &val, len))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
return 0;
|
2005-08-10 03:14:34 +00:00
|
|
|
}
|
|
|
|
|
2006-03-21 06:45:21 +00:00
|
|
|
int dccp_getsockopt(struct sock *sk, int level, int optname,
|
|
|
|
char __user *optval, int __user *optlen)
|
|
|
|
{
|
|
|
|
if (level != SOL_DCCP)
|
|
|
|
return inet_csk(sk)->icsk_af_ops->getsockopt(sk, level,
|
|
|
|
optname, optval,
|
|
|
|
optlen);
|
|
|
|
return do_dccp_getsockopt(sk, level, optname, optval, optlen);
|
|
|
|
}
|
2006-03-21 06:48:35 +00:00
|
|
|
|
2005-12-14 07:24:16 +00:00
|
|
|
EXPORT_SYMBOL_GPL(dccp_getsockopt);
|
|
|
|
|
2006-03-21 06:45:21 +00:00
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
int compat_dccp_getsockopt(struct sock *sk, int level, int optname,
|
2006-03-21 06:48:35 +00:00
|
|
|
char __user *optval, int __user *optlen)
|
2006-03-21 06:45:21 +00:00
|
|
|
{
|
2006-03-21 06:46:16 +00:00
|
|
|
if (level != SOL_DCCP)
|
|
|
|
return inet_csk_compat_getsockopt(sk, level, optname,
|
|
|
|
optval, optlen);
|
2006-03-21 06:45:21 +00:00
|
|
|
return do_dccp_getsockopt(sk, level, optname, optval, optlen);
|
|
|
|
}
|
2006-03-21 06:48:35 +00:00
|
|
|
|
2006-03-21 06:45:21 +00:00
|
|
|
EXPORT_SYMBOL_GPL(compat_dccp_getsockopt);
|
|
|
|
#endif
|
|
|
|
|
2005-08-10 03:14:34 +00:00
|
|
|
int dccp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
|
|
|
|
size_t len)
|
|
|
|
{
|
|
|
|
const struct dccp_sock *dp = dccp_sk(sk);
|
|
|
|
const int flags = msg->msg_flags;
|
|
|
|
const int noblock = flags & MSG_DONTWAIT;
|
|
|
|
struct sk_buff *skb;
|
|
|
|
int rc, size;
|
|
|
|
long timeo;
|
|
|
|
|
|
|
|
if (len > dp->dccps_mss_cache)
|
|
|
|
return -EMSGSIZE;
|
|
|
|
|
|
|
|
lock_sock(sk);
|
2006-11-20 20:30:17 +00:00
|
|
|
|
|
|
|
if (sysctl_dccp_tx_qlen &&
|
|
|
|
(sk->sk_write_queue.qlen >= sysctl_dccp_tx_qlen)) {
|
|
|
|
rc = -EAGAIN;
|
|
|
|
goto out_release;
|
|
|
|
}
|
|
|
|
|
2005-08-10 03:30:56 +00:00
|
|
|
timeo = sock_sndtimeo(sk, noblock);
|
2005-08-10 03:14:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We have to use sk_stream_wait_connect here to set sk_write_pending,
|
|
|
|
* so that the trick in dccp_rcv_request_sent_state_process.
|
|
|
|
*/
|
|
|
|
/* Wait for a connection to finish. */
|
2007-09-26 22:36:08 +00:00
|
|
|
if ((1 << sk->sk_state) & ~(DCCPF_OPEN | DCCPF_PARTOPEN))
|
2005-08-10 03:14:34 +00:00
|
|
|
if ((rc = sk_stream_wait_connect(sk, &timeo)) != 0)
|
2005-08-10 03:30:56 +00:00
|
|
|
goto out_release;
|
2005-08-10 03:14:34 +00:00
|
|
|
|
|
|
|
size = sk->sk_prot->max_header + len;
|
|
|
|
release_sock(sk);
|
|
|
|
skb = sock_alloc_send_skb(sk, size, noblock, &rc);
|
|
|
|
lock_sock(sk);
|
|
|
|
if (skb == NULL)
|
|
|
|
goto out_release;
|
|
|
|
|
|
|
|
skb_reserve(skb, sk->sk_prot->max_header);
|
|
|
|
rc = memcpy_fromiovec(skb_put(skb, len), msg->msg_iov, len);
|
2005-08-10 03:30:56 +00:00
|
|
|
if (rc != 0)
|
|
|
|
goto out_discard;
|
|
|
|
|
2006-08-27 02:16:45 +00:00
|
|
|
skb_queue_tail(&sk->sk_write_queue, skb);
|
|
|
|
dccp_write_xmit(sk,0);
|
2005-08-10 03:14:34 +00:00
|
|
|
out_release:
|
|
|
|
release_sock(sk);
|
|
|
|
return rc ? : len;
|
2005-08-10 03:30:56 +00:00
|
|
|
out_discard:
|
|
|
|
kfree_skb(skb);
|
2005-08-10 03:14:34 +00:00
|
|
|
goto out_release;
|
|
|
|
}
|
|
|
|
|
2005-12-14 07:24:16 +00:00
|
|
|
EXPORT_SYMBOL_GPL(dccp_sendmsg);
|
|
|
|
|
2005-08-10 03:14:34 +00:00
|
|
|
int dccp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
|
|
|
|
size_t len, int nonblock, int flags, int *addr_len)
|
|
|
|
{
|
|
|
|
const struct dccp_hdr *dh;
|
|
|
|
long timeo;
|
|
|
|
|
|
|
|
lock_sock(sk);
|
|
|
|
|
2005-08-13 23:35:17 +00:00
|
|
|
if (sk->sk_state == DCCP_LISTEN) {
|
|
|
|
len = -ENOTCONN;
|
2005-08-10 03:14:34 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2005-08-13 23:35:17 +00:00
|
|
|
timeo = sock_rcvtimeo(sk, nonblock);
|
2005-08-10 03:14:34 +00:00
|
|
|
|
|
|
|
do {
|
2005-08-13 23:35:17 +00:00
|
|
|
struct sk_buff *skb = skb_peek(&sk->sk_receive_queue);
|
2005-08-10 03:14:34 +00:00
|
|
|
|
2005-08-13 23:35:17 +00:00
|
|
|
if (skb == NULL)
|
|
|
|
goto verify_sock_status;
|
2005-08-10 03:14:34 +00:00
|
|
|
|
2005-08-13 23:35:17 +00:00
|
|
|
dh = dccp_hdr(skb);
|
2005-08-10 03:14:34 +00:00
|
|
|
|
[DCCP]: Integrate state transitions for passive-close
This adds the necessary state transitions for the two forms of passive-close
* PASSIVE_CLOSE - which is entered when a host receives a Close;
* PASSIVE_CLOSEREQ - which is entered when a client receives a CloseReq.
Here is a detailed account of what the patch does in each state.
1) Receiving CloseReq
The pseudo-code in 8.5 says:
Step 13: Process CloseReq
If P.type == CloseReq and S.state < CLOSEREQ,
Generate Close
S.state := CLOSING
Set CLOSING timer.
This means we need to address what to do in CLOSED, LISTEN, REQUEST, RESPOND, PARTOPEN, and OPEN.
* CLOSED: silently ignore - it may be a late or duplicate CloseReq;
* LISTEN/RESPOND: will not appear, since Step 7 is performed first (we know we are the client);
* REQUEST: perform Step 13 directly (no need to enqueue packet);
* OPEN/PARTOPEN: enter PASSIVE_CLOSEREQ so that the application has a chance to process unread data.
When already in PASSIVE_CLOSEREQ, no second CloseReq is enqueued. In any other state, the CloseReq is ignored.
I think that this offers some robustness against rare and pathological cases: e.g. a simultaneous close where
the client sends a Close and the server a CloseReq. The client will then be retransmitting its Close until it
gets the Reset, so ignoring the CloseReq while in state CLOSING is sane.
2) Receiving Close
The code below from 8.5 is unconditional.
Step 14: Process Close
If P.type == Close,
Generate Reset(Closed)
Tear down connection
Drop packet and return
Thus we need to consider all states:
* CLOSED: silently ignore, since this can happen when a retransmitted or late Close arrives;
* LISTEN: dccp_rcv_state_process() will generate a Reset ("No Connection");
* REQUEST: perform Step 14 directly (no need to enqueue packet);
* RESPOND: dccp_check_req() will generate a Reset ("Packet Error") -- left it at that;
* OPEN/PARTOPEN: enter PASSIVE_CLOSE so that application has a chance to process unread data;
* CLOSEREQ: server performed active-close -- perform Step 14;
* CLOSING: simultaneous-close: use a tie-breaker to avoid message ping-pong (see comment);
* PASSIVE_CLOSEREQ: ignore - the peer has a bug (sending first a CloseReq and now a Close);
* TIMEWAIT: packet is ignored.
Note that the condition of receiving a packet in state CLOSED here is different from the condition "there
is no socket for such a connection": the socket still exists, but its state indicates it is unusable.
Last, dccp_finish_passive_close sets either DCCP_CLOSED or DCCP_CLOSING = TCP_CLOSING, so that
sk_stream_wait_close() will wait for the final Reset (which will trigger CLOSING => CLOSED).
Signed-off-by: Gerrit Renker <gerrit@erg.abdn.ac.uk>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-11-28 13:59:48 +00:00
|
|
|
switch (dh->dccph_type) {
|
|
|
|
case DCCP_PKT_DATA:
|
|
|
|
case DCCP_PKT_DATAACK:
|
2005-08-13 23:35:17 +00:00
|
|
|
goto found_ok_skb;
|
2005-08-10 03:14:34 +00:00
|
|
|
|
[DCCP]: Integrate state transitions for passive-close
This adds the necessary state transitions for the two forms of passive-close
* PASSIVE_CLOSE - which is entered when a host receives a Close;
* PASSIVE_CLOSEREQ - which is entered when a client receives a CloseReq.
Here is a detailed account of what the patch does in each state.
1) Receiving CloseReq
The pseudo-code in 8.5 says:
Step 13: Process CloseReq
If P.type == CloseReq and S.state < CLOSEREQ,
Generate Close
S.state := CLOSING
Set CLOSING timer.
This means we need to address what to do in CLOSED, LISTEN, REQUEST, RESPOND, PARTOPEN, and OPEN.
* CLOSED: silently ignore - it may be a late or duplicate CloseReq;
* LISTEN/RESPOND: will not appear, since Step 7 is performed first (we know we are the client);
* REQUEST: perform Step 13 directly (no need to enqueue packet);
* OPEN/PARTOPEN: enter PASSIVE_CLOSEREQ so that the application has a chance to process unread data.
When already in PASSIVE_CLOSEREQ, no second CloseReq is enqueued. In any other state, the CloseReq is ignored.
I think that this offers some robustness against rare and pathological cases: e.g. a simultaneous close where
the client sends a Close and the server a CloseReq. The client will then be retransmitting its Close until it
gets the Reset, so ignoring the CloseReq while in state CLOSING is sane.
2) Receiving Close
The code below from 8.5 is unconditional.
Step 14: Process Close
If P.type == Close,
Generate Reset(Closed)
Tear down connection
Drop packet and return
Thus we need to consider all states:
* CLOSED: silently ignore, since this can happen when a retransmitted or late Close arrives;
* LISTEN: dccp_rcv_state_process() will generate a Reset ("No Connection");
* REQUEST: perform Step 14 directly (no need to enqueue packet);
* RESPOND: dccp_check_req() will generate a Reset ("Packet Error") -- left it at that;
* OPEN/PARTOPEN: enter PASSIVE_CLOSE so that application has a chance to process unread data;
* CLOSEREQ: server performed active-close -- perform Step 14;
* CLOSING: simultaneous-close: use a tie-breaker to avoid message ping-pong (see comment);
* PASSIVE_CLOSEREQ: ignore - the peer has a bug (sending first a CloseReq and now a Close);
* TIMEWAIT: packet is ignored.
Note that the condition of receiving a packet in state CLOSED here is different from the condition "there
is no socket for such a connection": the socket still exists, but its state indicates it is unusable.
Last, dccp_finish_passive_close sets either DCCP_CLOSED or DCCP_CLOSING = TCP_CLOSING, so that
sk_stream_wait_close() will wait for the final Reset (which will trigger CLOSING => CLOSED).
Signed-off-by: Gerrit Renker <gerrit@erg.abdn.ac.uk>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-11-28 13:59:48 +00:00
|
|
|
case DCCP_PKT_CLOSE:
|
|
|
|
case DCCP_PKT_CLOSEREQ:
|
|
|
|
if (!(flags & MSG_PEEK))
|
|
|
|
dccp_finish_passive_close(sk);
|
|
|
|
/* fall through */
|
|
|
|
case DCCP_PKT_RESET:
|
|
|
|
dccp_pr_debug("found fin (%s) ok!\n",
|
|
|
|
dccp_packet_name(dh->dccph_type));
|
2005-08-13 23:35:17 +00:00
|
|
|
len = 0;
|
|
|
|
goto found_fin_ok;
|
[DCCP]: Integrate state transitions for passive-close
This adds the necessary state transitions for the two forms of passive-close
* PASSIVE_CLOSE - which is entered when a host receives a Close;
* PASSIVE_CLOSEREQ - which is entered when a client receives a CloseReq.
Here is a detailed account of what the patch does in each state.
1) Receiving CloseReq
The pseudo-code in 8.5 says:
Step 13: Process CloseReq
If P.type == CloseReq and S.state < CLOSEREQ,
Generate Close
S.state := CLOSING
Set CLOSING timer.
This means we need to address what to do in CLOSED, LISTEN, REQUEST, RESPOND, PARTOPEN, and OPEN.
* CLOSED: silently ignore - it may be a late or duplicate CloseReq;
* LISTEN/RESPOND: will not appear, since Step 7 is performed first (we know we are the client);
* REQUEST: perform Step 13 directly (no need to enqueue packet);
* OPEN/PARTOPEN: enter PASSIVE_CLOSEREQ so that the application has a chance to process unread data.
When already in PASSIVE_CLOSEREQ, no second CloseReq is enqueued. In any other state, the CloseReq is ignored.
I think that this offers some robustness against rare and pathological cases: e.g. a simultaneous close where
the client sends a Close and the server a CloseReq. The client will then be retransmitting its Close until it
gets the Reset, so ignoring the CloseReq while in state CLOSING is sane.
2) Receiving Close
The code below from 8.5 is unconditional.
Step 14: Process Close
If P.type == Close,
Generate Reset(Closed)
Tear down connection
Drop packet and return
Thus we need to consider all states:
* CLOSED: silently ignore, since this can happen when a retransmitted or late Close arrives;
* LISTEN: dccp_rcv_state_process() will generate a Reset ("No Connection");
* REQUEST: perform Step 14 directly (no need to enqueue packet);
* RESPOND: dccp_check_req() will generate a Reset ("Packet Error") -- left it at that;
* OPEN/PARTOPEN: enter PASSIVE_CLOSE so that application has a chance to process unread data;
* CLOSEREQ: server performed active-close -- perform Step 14;
* CLOSING: simultaneous-close: use a tie-breaker to avoid message ping-pong (see comment);
* PASSIVE_CLOSEREQ: ignore - the peer has a bug (sending first a CloseReq and now a Close);
* TIMEWAIT: packet is ignored.
Note that the condition of receiving a packet in state CLOSED here is different from the condition "there
is no socket for such a connection": the socket still exists, but its state indicates it is unusable.
Last, dccp_finish_passive_close sets either DCCP_CLOSED or DCCP_CLOSING = TCP_CLOSING, so that
sk_stream_wait_close() will wait for the final Reset (which will trigger CLOSING => CLOSED).
Signed-off-by: Gerrit Renker <gerrit@erg.abdn.ac.uk>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-11-28 13:59:48 +00:00
|
|
|
default:
|
|
|
|
dccp_pr_debug("packet_type=%s\n",
|
|
|
|
dccp_packet_name(dh->dccph_type));
|
|
|
|
sk_eat_skb(sk, skb, 0);
|
2005-08-13 23:35:17 +00:00
|
|
|
}
|
|
|
|
verify_sock_status:
|
|
|
|
if (sock_flag(sk, SOCK_DONE)) {
|
|
|
|
len = 0;
|
2005-08-10 03:14:34 +00:00
|
|
|
break;
|
2005-08-13 23:35:17 +00:00
|
|
|
}
|
2005-08-10 03:14:34 +00:00
|
|
|
|
2005-08-13 23:35:17 +00:00
|
|
|
if (sk->sk_err) {
|
|
|
|
len = sock_error(sk);
|
|
|
|
break;
|
|
|
|
}
|
2005-08-10 03:14:34 +00:00
|
|
|
|
2005-08-13 23:35:17 +00:00
|
|
|
if (sk->sk_shutdown & RCV_SHUTDOWN) {
|
|
|
|
len = 0;
|
|
|
|
break;
|
|
|
|
}
|
2005-08-10 03:14:34 +00:00
|
|
|
|
2005-08-13 23:35:17 +00:00
|
|
|
if (sk->sk_state == DCCP_CLOSED) {
|
|
|
|
if (!sock_flag(sk, SOCK_DONE)) {
|
|
|
|
/* This occurs when user tries to read
|
|
|
|
* from never connected socket.
|
|
|
|
*/
|
|
|
|
len = -ENOTCONN;
|
2005-08-10 03:14:34 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-08-13 23:35:17 +00:00
|
|
|
len = 0;
|
|
|
|
break;
|
2005-08-10 03:14:34 +00:00
|
|
|
}
|
|
|
|
|
2005-08-13 23:35:17 +00:00
|
|
|
if (!timeo) {
|
|
|
|
len = -EAGAIN;
|
|
|
|
break;
|
|
|
|
}
|
2005-08-10 03:14:34 +00:00
|
|
|
|
2005-08-13 23:35:17 +00:00
|
|
|
if (signal_pending(current)) {
|
|
|
|
len = sock_intr_errno(timeo);
|
|
|
|
break;
|
|
|
|
}
|
2005-08-10 03:14:34 +00:00
|
|
|
|
2005-08-13 23:35:17 +00:00
|
|
|
sk_wait_data(sk, &timeo);
|
2005-08-10 03:14:34 +00:00
|
|
|
continue;
|
|
|
|
found_ok_skb:
|
2005-08-13 23:35:17 +00:00
|
|
|
if (len > skb->len)
|
|
|
|
len = skb->len;
|
|
|
|
else if (len < skb->len)
|
|
|
|
msg->msg_flags |= MSG_TRUNC;
|
|
|
|
|
|
|
|
if (skb_copy_datagram_iovec(skb, 0, msg->msg_iov, len)) {
|
|
|
|
/* Exception. Bailout! */
|
|
|
|
len = -EFAULT;
|
|
|
|
break;
|
2005-08-10 03:14:34 +00:00
|
|
|
}
|
|
|
|
found_fin_ok:
|
|
|
|
if (!(flags & MSG_PEEK))
|
2006-05-24 01:01:28 +00:00
|
|
|
sk_eat_skb(sk, skb, 0);
|
2005-08-10 03:14:34 +00:00
|
|
|
break;
|
2005-08-13 23:35:17 +00:00
|
|
|
} while (1);
|
2005-08-10 03:14:34 +00:00
|
|
|
out:
|
|
|
|
release_sock(sk);
|
2005-08-13 23:35:17 +00:00
|
|
|
return len;
|
2005-08-10 03:14:34 +00:00
|
|
|
}
|
|
|
|
|
2005-12-14 07:24:16 +00:00
|
|
|
EXPORT_SYMBOL_GPL(dccp_recvmsg);
|
|
|
|
|
|
|
|
int inet_dccp_listen(struct socket *sock, int backlog)
|
2005-08-10 03:14:34 +00:00
|
|
|
{
|
|
|
|
struct sock *sk = sock->sk;
|
|
|
|
unsigned char old_state;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
lock_sock(sk);
|
|
|
|
|
|
|
|
err = -EINVAL;
|
|
|
|
if (sock->state != SS_UNCONNECTED || sock->type != SOCK_DCCP)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
old_state = sk->sk_state;
|
|
|
|
if (!((1 << old_state) & (DCCPF_CLOSED | DCCPF_LISTEN)))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
/* Really, if the socket is already in listen state
|
|
|
|
* we can only allow the backlog to be adjusted.
|
|
|
|
*/
|
|
|
|
if (old_state != DCCP_LISTEN) {
|
|
|
|
/*
|
|
|
|
* FIXME: here it probably should be sk->sk_prot->listen_start
|
|
|
|
* see tcp_listen_start
|
|
|
|
*/
|
2006-11-16 10:30:37 +00:00
|
|
|
err = dccp_listen_start(sk, backlog);
|
2005-08-10 03:14:34 +00:00
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
sk->sk_max_ack_backlog = backlog;
|
|
|
|
err = 0;
|
|
|
|
|
|
|
|
out:
|
|
|
|
release_sock(sk);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2005-12-14 07:24:16 +00:00
|
|
|
EXPORT_SYMBOL_GPL(inet_dccp_listen);
|
|
|
|
|
[DCCP]: Integrate state transitions for passive-close
This adds the necessary state transitions for the two forms of passive-close
* PASSIVE_CLOSE - which is entered when a host receives a Close;
* PASSIVE_CLOSEREQ - which is entered when a client receives a CloseReq.
Here is a detailed account of what the patch does in each state.
1) Receiving CloseReq
The pseudo-code in 8.5 says:
Step 13: Process CloseReq
If P.type == CloseReq and S.state < CLOSEREQ,
Generate Close
S.state := CLOSING
Set CLOSING timer.
This means we need to address what to do in CLOSED, LISTEN, REQUEST, RESPOND, PARTOPEN, and OPEN.
* CLOSED: silently ignore - it may be a late or duplicate CloseReq;
* LISTEN/RESPOND: will not appear, since Step 7 is performed first (we know we are the client);
* REQUEST: perform Step 13 directly (no need to enqueue packet);
* OPEN/PARTOPEN: enter PASSIVE_CLOSEREQ so that the application has a chance to process unread data.
When already in PASSIVE_CLOSEREQ, no second CloseReq is enqueued. In any other state, the CloseReq is ignored.
I think that this offers some robustness against rare and pathological cases: e.g. a simultaneous close where
the client sends a Close and the server a CloseReq. The client will then be retransmitting its Close until it
gets the Reset, so ignoring the CloseReq while in state CLOSING is sane.
2) Receiving Close
The code below from 8.5 is unconditional.
Step 14: Process Close
If P.type == Close,
Generate Reset(Closed)
Tear down connection
Drop packet and return
Thus we need to consider all states:
* CLOSED: silently ignore, since this can happen when a retransmitted or late Close arrives;
* LISTEN: dccp_rcv_state_process() will generate a Reset ("No Connection");
* REQUEST: perform Step 14 directly (no need to enqueue packet);
* RESPOND: dccp_check_req() will generate a Reset ("Packet Error") -- left it at that;
* OPEN/PARTOPEN: enter PASSIVE_CLOSE so that application has a chance to process unread data;
* CLOSEREQ: server performed active-close -- perform Step 14;
* CLOSING: simultaneous-close: use a tie-breaker to avoid message ping-pong (see comment);
* PASSIVE_CLOSEREQ: ignore - the peer has a bug (sending first a CloseReq and now a Close);
* TIMEWAIT: packet is ignored.
Note that the condition of receiving a packet in state CLOSED here is different from the condition "there
is no socket for such a connection": the socket still exists, but its state indicates it is unusable.
Last, dccp_finish_passive_close sets either DCCP_CLOSED or DCCP_CLOSING = TCP_CLOSING, so that
sk_stream_wait_close() will wait for the final Reset (which will trigger CLOSING => CLOSED).
Signed-off-by: Gerrit Renker <gerrit@erg.abdn.ac.uk>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-11-28 13:59:48 +00:00
|
|
|
static void dccp_terminate_connection(struct sock *sk)
|
2005-08-10 03:14:34 +00:00
|
|
|
{
|
[DCCP]: Integrate state transitions for passive-close
This adds the necessary state transitions for the two forms of passive-close
* PASSIVE_CLOSE - which is entered when a host receives a Close;
* PASSIVE_CLOSEREQ - which is entered when a client receives a CloseReq.
Here is a detailed account of what the patch does in each state.
1) Receiving CloseReq
The pseudo-code in 8.5 says:
Step 13: Process CloseReq
If P.type == CloseReq and S.state < CLOSEREQ,
Generate Close
S.state := CLOSING
Set CLOSING timer.
This means we need to address what to do in CLOSED, LISTEN, REQUEST, RESPOND, PARTOPEN, and OPEN.
* CLOSED: silently ignore - it may be a late or duplicate CloseReq;
* LISTEN/RESPOND: will not appear, since Step 7 is performed first (we know we are the client);
* REQUEST: perform Step 13 directly (no need to enqueue packet);
* OPEN/PARTOPEN: enter PASSIVE_CLOSEREQ so that the application has a chance to process unread data.
When already in PASSIVE_CLOSEREQ, no second CloseReq is enqueued. In any other state, the CloseReq is ignored.
I think that this offers some robustness against rare and pathological cases: e.g. a simultaneous close where
the client sends a Close and the server a CloseReq. The client will then be retransmitting its Close until it
gets the Reset, so ignoring the CloseReq while in state CLOSING is sane.
2) Receiving Close
The code below from 8.5 is unconditional.
Step 14: Process Close
If P.type == Close,
Generate Reset(Closed)
Tear down connection
Drop packet and return
Thus we need to consider all states:
* CLOSED: silently ignore, since this can happen when a retransmitted or late Close arrives;
* LISTEN: dccp_rcv_state_process() will generate a Reset ("No Connection");
* REQUEST: perform Step 14 directly (no need to enqueue packet);
* RESPOND: dccp_check_req() will generate a Reset ("Packet Error") -- left it at that;
* OPEN/PARTOPEN: enter PASSIVE_CLOSE so that application has a chance to process unread data;
* CLOSEREQ: server performed active-close -- perform Step 14;
* CLOSING: simultaneous-close: use a tie-breaker to avoid message ping-pong (see comment);
* PASSIVE_CLOSEREQ: ignore - the peer has a bug (sending first a CloseReq and now a Close);
* TIMEWAIT: packet is ignored.
Note that the condition of receiving a packet in state CLOSED here is different from the condition "there
is no socket for such a connection": the socket still exists, but its state indicates it is unusable.
Last, dccp_finish_passive_close sets either DCCP_CLOSED or DCCP_CLOSING = TCP_CLOSING, so that
sk_stream_wait_close() will wait for the final Reset (which will trigger CLOSING => CLOSED).
Signed-off-by: Gerrit Renker <gerrit@erg.abdn.ac.uk>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-11-28 13:59:48 +00:00
|
|
|
u8 next_state = DCCP_CLOSED;
|
2005-08-10 03:14:34 +00:00
|
|
|
|
[DCCP]: Integrate state transitions for passive-close
This adds the necessary state transitions for the two forms of passive-close
* PASSIVE_CLOSE - which is entered when a host receives a Close;
* PASSIVE_CLOSEREQ - which is entered when a client receives a CloseReq.
Here is a detailed account of what the patch does in each state.
1) Receiving CloseReq
The pseudo-code in 8.5 says:
Step 13: Process CloseReq
If P.type == CloseReq and S.state < CLOSEREQ,
Generate Close
S.state := CLOSING
Set CLOSING timer.
This means we need to address what to do in CLOSED, LISTEN, REQUEST, RESPOND, PARTOPEN, and OPEN.
* CLOSED: silently ignore - it may be a late or duplicate CloseReq;
* LISTEN/RESPOND: will not appear, since Step 7 is performed first (we know we are the client);
* REQUEST: perform Step 13 directly (no need to enqueue packet);
* OPEN/PARTOPEN: enter PASSIVE_CLOSEREQ so that the application has a chance to process unread data.
When already in PASSIVE_CLOSEREQ, no second CloseReq is enqueued. In any other state, the CloseReq is ignored.
I think that this offers some robustness against rare and pathological cases: e.g. a simultaneous close where
the client sends a Close and the server a CloseReq. The client will then be retransmitting its Close until it
gets the Reset, so ignoring the CloseReq while in state CLOSING is sane.
2) Receiving Close
The code below from 8.5 is unconditional.
Step 14: Process Close
If P.type == Close,
Generate Reset(Closed)
Tear down connection
Drop packet and return
Thus we need to consider all states:
* CLOSED: silently ignore, since this can happen when a retransmitted or late Close arrives;
* LISTEN: dccp_rcv_state_process() will generate a Reset ("No Connection");
* REQUEST: perform Step 14 directly (no need to enqueue packet);
* RESPOND: dccp_check_req() will generate a Reset ("Packet Error") -- left it at that;
* OPEN/PARTOPEN: enter PASSIVE_CLOSE so that application has a chance to process unread data;
* CLOSEREQ: server performed active-close -- perform Step 14;
* CLOSING: simultaneous-close: use a tie-breaker to avoid message ping-pong (see comment);
* PASSIVE_CLOSEREQ: ignore - the peer has a bug (sending first a CloseReq and now a Close);
* TIMEWAIT: packet is ignored.
Note that the condition of receiving a packet in state CLOSED here is different from the condition "there
is no socket for such a connection": the socket still exists, but its state indicates it is unusable.
Last, dccp_finish_passive_close sets either DCCP_CLOSED or DCCP_CLOSING = TCP_CLOSING, so that
sk_stream_wait_close() will wait for the final Reset (which will trigger CLOSING => CLOSED).
Signed-off-by: Gerrit Renker <gerrit@erg.abdn.ac.uk>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-11-28 13:59:48 +00:00
|
|
|
switch (sk->sk_state) {
|
|
|
|
case DCCP_PASSIVE_CLOSE:
|
|
|
|
case DCCP_PASSIVE_CLOSEREQ:
|
|
|
|
dccp_finish_passive_close(sk);
|
|
|
|
break;
|
|
|
|
case DCCP_PARTOPEN:
|
|
|
|
dccp_pr_debug("Stop PARTOPEN timer (%p)\n", sk);
|
|
|
|
inet_csk_clear_xmit_timer(sk, ICSK_TIME_DACK);
|
|
|
|
/* fall through */
|
|
|
|
case DCCP_OPEN:
|
|
|
|
dccp_send_close(sk, 1);
|
2005-08-10 03:14:34 +00:00
|
|
|
|
2007-12-13 14:25:01 +00:00
|
|
|
if (dccp_sk(sk)->dccps_role == DCCP_ROLE_SERVER &&
|
|
|
|
!dccp_sk(sk)->dccps_server_timewait)
|
[DCCP]: Integrate state transitions for passive-close
This adds the necessary state transitions for the two forms of passive-close
* PASSIVE_CLOSE - which is entered when a host receives a Close;
* PASSIVE_CLOSEREQ - which is entered when a client receives a CloseReq.
Here is a detailed account of what the patch does in each state.
1) Receiving CloseReq
The pseudo-code in 8.5 says:
Step 13: Process CloseReq
If P.type == CloseReq and S.state < CLOSEREQ,
Generate Close
S.state := CLOSING
Set CLOSING timer.
This means we need to address what to do in CLOSED, LISTEN, REQUEST, RESPOND, PARTOPEN, and OPEN.
* CLOSED: silently ignore - it may be a late or duplicate CloseReq;
* LISTEN/RESPOND: will not appear, since Step 7 is performed first (we know we are the client);
* REQUEST: perform Step 13 directly (no need to enqueue packet);
* OPEN/PARTOPEN: enter PASSIVE_CLOSEREQ so that the application has a chance to process unread data.
When already in PASSIVE_CLOSEREQ, no second CloseReq is enqueued. In any other state, the CloseReq is ignored.
I think that this offers some robustness against rare and pathological cases: e.g. a simultaneous close where
the client sends a Close and the server a CloseReq. The client will then be retransmitting its Close until it
gets the Reset, so ignoring the CloseReq while in state CLOSING is sane.
2) Receiving Close
The code below from 8.5 is unconditional.
Step 14: Process Close
If P.type == Close,
Generate Reset(Closed)
Tear down connection
Drop packet and return
Thus we need to consider all states:
* CLOSED: silently ignore, since this can happen when a retransmitted or late Close arrives;
* LISTEN: dccp_rcv_state_process() will generate a Reset ("No Connection");
* REQUEST: perform Step 14 directly (no need to enqueue packet);
* RESPOND: dccp_check_req() will generate a Reset ("Packet Error") -- left it at that;
* OPEN/PARTOPEN: enter PASSIVE_CLOSE so that application has a chance to process unread data;
* CLOSEREQ: server performed active-close -- perform Step 14;
* CLOSING: simultaneous-close: use a tie-breaker to avoid message ping-pong (see comment);
* PASSIVE_CLOSEREQ: ignore - the peer has a bug (sending first a CloseReq and now a Close);
* TIMEWAIT: packet is ignored.
Note that the condition of receiving a packet in state CLOSED here is different from the condition "there
is no socket for such a connection": the socket still exists, but its state indicates it is unusable.
Last, dccp_finish_passive_close sets either DCCP_CLOSED or DCCP_CLOSING = TCP_CLOSING, so that
sk_stream_wait_close() will wait for the final Reset (which will trigger CLOSING => CLOSED).
Signed-off-by: Gerrit Renker <gerrit@erg.abdn.ac.uk>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-11-28 13:59:48 +00:00
|
|
|
next_state = DCCP_ACTIVE_CLOSEREQ;
|
|
|
|
else
|
|
|
|
next_state = DCCP_CLOSING;
|
|
|
|
/* fall through */
|
|
|
|
default:
|
|
|
|
dccp_set_state(sk, next_state);
|
|
|
|
}
|
2005-08-10 03:14:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void dccp_close(struct sock *sk, long timeout)
|
|
|
|
{
|
2006-08-27 02:16:45 +00:00
|
|
|
struct dccp_sock *dp = dccp_sk(sk);
|
2005-08-10 03:14:34 +00:00
|
|
|
struct sk_buff *skb;
|
2007-12-17 00:06:03 +00:00
|
|
|
u32 data_was_unread = 0;
|
2006-05-06 00:09:13 +00:00
|
|
|
int state;
|
2005-08-10 03:14:34 +00:00
|
|
|
|
|
|
|
lock_sock(sk);
|
|
|
|
|
|
|
|
sk->sk_shutdown = SHUTDOWN_MASK;
|
|
|
|
|
|
|
|
if (sk->sk_state == DCCP_LISTEN) {
|
|
|
|
dccp_set_state(sk, DCCP_CLOSED);
|
|
|
|
|
|
|
|
/* Special case. */
|
|
|
|
inet_csk_listen_stop(sk);
|
|
|
|
|
|
|
|
goto adjudge_to_death;
|
|
|
|
}
|
|
|
|
|
2006-08-27 02:16:45 +00:00
|
|
|
sk_stop_timer(sk, &dp->dccps_xmit_timer);
|
|
|
|
|
2005-08-10 03:14:34 +00:00
|
|
|
/*
|
|
|
|
* We need to flush the recv. buffs. We do this only on the
|
|
|
|
* descriptor close, not protocol-sourced closes, because the
|
|
|
|
*reader process may not have drained the data yet!
|
|
|
|
*/
|
|
|
|
while ((skb = __skb_dequeue(&sk->sk_receive_queue)) != NULL) {
|
2007-12-17 00:06:03 +00:00
|
|
|
data_was_unread += skb->len;
|
2005-08-10 03:14:34 +00:00
|
|
|
__kfree_skb(skb);
|
|
|
|
}
|
|
|
|
|
2007-12-17 00:06:03 +00:00
|
|
|
if (data_was_unread) {
|
|
|
|
/* Unread data was tossed, send an appropriate Reset Code */
|
|
|
|
DCCP_WARN("DCCP: ABORT -- %u bytes unread\n", data_was_unread);
|
|
|
|
dccp_send_reset(sk, DCCP_RESET_CODE_ABORTED);
|
|
|
|
dccp_set_state(sk, DCCP_CLOSED);
|
|
|
|
} else if (sock_flag(sk, SOCK_LINGER) && !sk->sk_lingertime) {
|
2005-08-10 03:14:34 +00:00
|
|
|
/* Check zero linger _after_ checking for unread data. */
|
|
|
|
sk->sk_prot->disconnect(sk, 0);
|
[DCCP]: Integrate state transitions for passive-close
This adds the necessary state transitions for the two forms of passive-close
* PASSIVE_CLOSE - which is entered when a host receives a Close;
* PASSIVE_CLOSEREQ - which is entered when a client receives a CloseReq.
Here is a detailed account of what the patch does in each state.
1) Receiving CloseReq
The pseudo-code in 8.5 says:
Step 13: Process CloseReq
If P.type == CloseReq and S.state < CLOSEREQ,
Generate Close
S.state := CLOSING
Set CLOSING timer.
This means we need to address what to do in CLOSED, LISTEN, REQUEST, RESPOND, PARTOPEN, and OPEN.
* CLOSED: silently ignore - it may be a late or duplicate CloseReq;
* LISTEN/RESPOND: will not appear, since Step 7 is performed first (we know we are the client);
* REQUEST: perform Step 13 directly (no need to enqueue packet);
* OPEN/PARTOPEN: enter PASSIVE_CLOSEREQ so that the application has a chance to process unread data.
When already in PASSIVE_CLOSEREQ, no second CloseReq is enqueued. In any other state, the CloseReq is ignored.
I think that this offers some robustness against rare and pathological cases: e.g. a simultaneous close where
the client sends a Close and the server a CloseReq. The client will then be retransmitting its Close until it
gets the Reset, so ignoring the CloseReq while in state CLOSING is sane.
2) Receiving Close
The code below from 8.5 is unconditional.
Step 14: Process Close
If P.type == Close,
Generate Reset(Closed)
Tear down connection
Drop packet and return
Thus we need to consider all states:
* CLOSED: silently ignore, since this can happen when a retransmitted or late Close arrives;
* LISTEN: dccp_rcv_state_process() will generate a Reset ("No Connection");
* REQUEST: perform Step 14 directly (no need to enqueue packet);
* RESPOND: dccp_check_req() will generate a Reset ("Packet Error") -- left it at that;
* OPEN/PARTOPEN: enter PASSIVE_CLOSE so that application has a chance to process unread data;
* CLOSEREQ: server performed active-close -- perform Step 14;
* CLOSING: simultaneous-close: use a tie-breaker to avoid message ping-pong (see comment);
* PASSIVE_CLOSEREQ: ignore - the peer has a bug (sending first a CloseReq and now a Close);
* TIMEWAIT: packet is ignored.
Note that the condition of receiving a packet in state CLOSED here is different from the condition "there
is no socket for such a connection": the socket still exists, but its state indicates it is unusable.
Last, dccp_finish_passive_close sets either DCCP_CLOSED or DCCP_CLOSING = TCP_CLOSING, so that
sk_stream_wait_close() will wait for the final Reset (which will trigger CLOSING => CLOSED).
Signed-off-by: Gerrit Renker <gerrit@erg.abdn.ac.uk>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-11-28 13:59:48 +00:00
|
|
|
} else if (sk->sk_state != DCCP_CLOSED) {
|
|
|
|
dccp_terminate_connection(sk);
|
2005-08-10 03:14:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sk_stream_wait_close(sk, timeout);
|
|
|
|
|
|
|
|
adjudge_to_death:
|
2006-05-06 00:09:13 +00:00
|
|
|
state = sk->sk_state;
|
|
|
|
sock_hold(sk);
|
|
|
|
sock_orphan(sk);
|
|
|
|
atomic_inc(sk->sk_prot->orphan_count);
|
|
|
|
|
2005-08-24 04:50:06 +00:00
|
|
|
/*
|
|
|
|
* It is the last release_sock in its life. It will remove backlog.
|
|
|
|
*/
|
2005-08-10 03:14:34 +00:00
|
|
|
release_sock(sk);
|
|
|
|
/*
|
|
|
|
* Now socket is owned by kernel and we acquire BH lock
|
|
|
|
* to finish close. No need to check for user refs.
|
|
|
|
*/
|
|
|
|
local_bh_disable();
|
|
|
|
bh_lock_sock(sk);
|
|
|
|
BUG_TRAP(!sock_owned_by_user(sk));
|
|
|
|
|
2006-05-06 00:09:13 +00:00
|
|
|
/* Have we already been destroyed by a softirq or backlog? */
|
|
|
|
if (state != DCCP_CLOSED && sk->sk_state == DCCP_CLOSED)
|
|
|
|
goto out;
|
2005-08-24 04:50:06 +00:00
|
|
|
|
2005-08-10 03:14:34 +00:00
|
|
|
if (sk->sk_state == DCCP_CLOSED)
|
|
|
|
inet_csk_destroy_sock(sk);
|
|
|
|
|
|
|
|
/* Otherwise, socket is reprieved until protocol close. */
|
|
|
|
|
2006-05-06 00:09:13 +00:00
|
|
|
out:
|
2005-08-10 03:14:34 +00:00
|
|
|
bh_unlock_sock(sk);
|
|
|
|
local_bh_enable();
|
|
|
|
sock_put(sk);
|
|
|
|
}
|
|
|
|
|
2005-12-14 07:24:16 +00:00
|
|
|
EXPORT_SYMBOL_GPL(dccp_close);
|
|
|
|
|
2005-08-10 03:14:34 +00:00
|
|
|
void dccp_shutdown(struct sock *sk, int how)
|
|
|
|
{
|
[DCCP]: Honour and make use of shutdown option set by user
This extends the DCCP socket API by honouring any shutdown(2) option set by the user.
The behaviour is, as much as possible, made consistent with the API for TCP's shutdown.
This patch exploits the information provided by the user via the socket API to reduce
processing costs:
* if the read end is closed (SHUT_RD), it is not necessary to deliver to input CCID;
* if the write end is closed (SHUT_WR), the same idea applies, but with a difference -
as long as the TX queue has not been drained, we need to receive feedback to keep
congestion-control rates up to date. Hence SHUT_WR is honoured only after the last
packet (under congestion control) has been sent;
* although SHUT_RDWR seems nonsensical, it is nevertheless supported in the same manner
as for TCP (and agrees with test for SHUTDOWN_MASK in dccp_poll() in net/dccp/proto.c).
Furthermore, most of the code already honours the sk_shutdown flags (dccp_recvmsg() for
instance sets the read length to 0 if SHUT_RD had been called); CCID handling is now added
to this by the present patch.
There will also no longer be any delivery when the socket is in the final stages, i.e. when
one of dccp_close(), dccp_fin(), or dccp_done() has been called - which is fine since at
that stage the connection is its final stages.
Motivation and background are on http://www.erg.abdn.ac.uk/users/gerrit/dccp/notes/shutdown
A FIXME has been added to notify the other end if SHUT_RD has been set (RFC 4340, 11.7).
Note: There is a comment in inet_shutdown() in net/ipv4/af_inet.c which asks to "make
sure the socket is a TCP socket". This should probably be extended to mean
`TCP or DCCP socket' (the code is also used by UDP and raw sockets).
Signed-off-by: Gerrit Renker <gerrit@erg.abdn.ac.uk>
Signed-off-by: Ian McDonald <ian.mcdonald@jandi.co.nz>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-11-21 11:56:48 +00:00
|
|
|
dccp_pr_debug("called shutdown(%x)\n", how);
|
2005-08-10 03:14:34 +00:00
|
|
|
}
|
|
|
|
|
2005-12-14 07:24:16 +00:00
|
|
|
EXPORT_SYMBOL_GPL(dccp_shutdown);
|
|
|
|
|
2008-04-10 10:48:43 +00:00
|
|
|
static inline int dccp_mib_init(void)
|
2005-08-10 03:14:34 +00:00
|
|
|
{
|
2008-04-10 10:48:43 +00:00
|
|
|
return snmp_mib_init((void**)dccp_statistics, sizeof(struct dccp_mib));
|
2005-08-10 03:14:34 +00:00
|
|
|
}
|
|
|
|
|
2008-04-10 10:48:43 +00:00
|
|
|
static inline void dccp_mib_exit(void)
|
2006-03-21 05:24:42 +00:00
|
|
|
{
|
2008-04-10 10:48:43 +00:00
|
|
|
snmp_mib_free((void**)dccp_statistics);
|
2006-03-21 05:24:42 +00:00
|
|
|
}
|
|
|
|
|
2005-08-10 03:14:34 +00:00
|
|
|
static int thash_entries;
|
|
|
|
module_param(thash_entries, int, 0444);
|
|
|
|
MODULE_PARM_DESC(thash_entries, "Number of ehash buckets");
|
|
|
|
|
2005-08-14 01:42:25 +00:00
|
|
|
#ifdef CONFIG_IP_DCCP_DEBUG
|
2005-08-10 03:14:34 +00:00
|
|
|
int dccp_debug;
|
2007-10-04 21:39:53 +00:00
|
|
|
module_param(dccp_debug, bool, 0444);
|
2005-08-10 03:14:34 +00:00
|
|
|
MODULE_PARM_DESC(dccp_debug, "Enable debug messages");
|
2005-12-14 07:24:16 +00:00
|
|
|
|
|
|
|
EXPORT_SYMBOL_GPL(dccp_debug);
|
2005-08-14 01:42:25 +00:00
|
|
|
#endif
|
2005-08-10 03:14:34 +00:00
|
|
|
|
|
|
|
static int __init dccp_init(void)
|
|
|
|
{
|
|
|
|
unsigned long goal;
|
|
|
|
int ehash_order, bhash_order, i;
|
2006-03-21 05:25:11 +00:00
|
|
|
int rc = -ENOBUFS;
|
2005-08-10 03:14:34 +00:00
|
|
|
|
2005-08-13 23:34:54 +00:00
|
|
|
dccp_hashinfo.bind_bucket_cachep =
|
|
|
|
kmem_cache_create("dccp_bind_bucket",
|
|
|
|
sizeof(struct inet_bind_bucket), 0,
|
2007-07-20 01:11:58 +00:00
|
|
|
SLAB_HWCACHE_ALIGN, NULL);
|
2005-08-10 03:14:34 +00:00
|
|
|
if (!dccp_hashinfo.bind_bucket_cachep)
|
2006-03-21 05:25:11 +00:00
|
|
|
goto out;
|
2005-08-10 03:14:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Size and allocate the main established and bind bucket
|
|
|
|
* hash tables.
|
|
|
|
*
|
|
|
|
* The methodology is similar to that of the buffer cache.
|
|
|
|
*/
|
|
|
|
if (num_physpages >= (128 * 1024))
|
|
|
|
goal = num_physpages >> (21 - PAGE_SHIFT);
|
|
|
|
else
|
|
|
|
goal = num_physpages >> (23 - PAGE_SHIFT);
|
|
|
|
|
|
|
|
if (thash_entries)
|
2005-08-13 23:34:54 +00:00
|
|
|
goal = (thash_entries *
|
|
|
|
sizeof(struct inet_ehash_bucket)) >> PAGE_SHIFT;
|
2005-08-10 03:14:34 +00:00
|
|
|
for (ehash_order = 0; (1UL << ehash_order) < goal; ehash_order++)
|
|
|
|
;
|
|
|
|
do {
|
|
|
|
dccp_hashinfo.ehash_size = (1UL << ehash_order) * PAGE_SIZE /
|
|
|
|
sizeof(struct inet_ehash_bucket);
|
2005-08-13 23:34:54 +00:00
|
|
|
while (dccp_hashinfo.ehash_size &
|
|
|
|
(dccp_hashinfo.ehash_size - 1))
|
2005-08-10 03:14:34 +00:00
|
|
|
dccp_hashinfo.ehash_size--;
|
|
|
|
dccp_hashinfo.ehash = (struct inet_ehash_bucket *)
|
|
|
|
__get_free_pages(GFP_ATOMIC, ehash_order);
|
|
|
|
} while (!dccp_hashinfo.ehash && --ehash_order > 0);
|
|
|
|
|
|
|
|
if (!dccp_hashinfo.ehash) {
|
2006-11-20 20:39:23 +00:00
|
|
|
DCCP_CRIT("Failed to allocate DCCP established hash table");
|
2005-08-10 03:14:34 +00:00
|
|
|
goto out_free_bind_bucket_cachep;
|
|
|
|
}
|
|
|
|
|
[NET]: change layout of ehash table
ehash table layout is currently this one :
First half of this table is used by sockets not in TIME_WAIT state
Second half of it is used by sockets in TIME_WAIT state.
This is non optimal because of for a given hash or socket, the two chain heads
are located in separate cache lines.
Moreover the locks of the second half are never used.
If instead of this halving, we use two list heads in inet_ehash_bucket instead
of only one, we probably can avoid one cache miss, and reduce ram usage,
particularly if sizeof(rwlock_t) is big (various CONFIG_DEBUG_SPINLOCK,
CONFIG_DEBUG_LOCK_ALLOC settings). So we still halves the table but we keep
together related chains to speedup lookups and socket state change.
In this patch I did not try to align struct inet_ehash_bucket, but a future
patch could try to make this structure have a convenient size (a power of two
or a multiple of L1_CACHE_SIZE).
I guess rwlock will just vanish as soon as RCU is plugged into ehash :) , so
maybe we dont need to scratch our heads to align the bucket...
Note : In case struct inet_ehash_bucket is not a power of two, we could
probably change alloc_large_system_hash() (in case it use __get_free_pages())
to free the unused space. It currently allocates a big zone, but the last
quarter of it could be freed. Again, this should be a temporary 'problem'.
Patch tested on ipv4 tcp only, but should be OK for IPV6 and DCCP.
Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-02-08 22:16:46 +00:00
|
|
|
for (i = 0; i < dccp_hashinfo.ehash_size; i++) {
|
2005-08-10 03:14:34 +00:00
|
|
|
INIT_HLIST_HEAD(&dccp_hashinfo.ehash[i].chain);
|
[NET]: change layout of ehash table
ehash table layout is currently this one :
First half of this table is used by sockets not in TIME_WAIT state
Second half of it is used by sockets in TIME_WAIT state.
This is non optimal because of for a given hash or socket, the two chain heads
are located in separate cache lines.
Moreover the locks of the second half are never used.
If instead of this halving, we use two list heads in inet_ehash_bucket instead
of only one, we probably can avoid one cache miss, and reduce ram usage,
particularly if sizeof(rwlock_t) is big (various CONFIG_DEBUG_SPINLOCK,
CONFIG_DEBUG_LOCK_ALLOC settings). So we still halves the table but we keep
together related chains to speedup lookups and socket state change.
In this patch I did not try to align struct inet_ehash_bucket, but a future
patch could try to make this structure have a convenient size (a power of two
or a multiple of L1_CACHE_SIZE).
I guess rwlock will just vanish as soon as RCU is plugged into ehash :) , so
maybe we dont need to scratch our heads to align the bucket...
Note : In case struct inet_ehash_bucket is not a power of two, we could
probably change alloc_large_system_hash() (in case it use __get_free_pages())
to free the unused space. It currently allocates a big zone, but the last
quarter of it could be freed. Again, this should be a temporary 'problem'.
Patch tested on ipv4 tcp only, but should be OK for IPV6 and DCCP.
Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2007-02-08 22:16:46 +00:00
|
|
|
INIT_HLIST_HEAD(&dccp_hashinfo.ehash[i].twchain);
|
2005-08-10 03:14:34 +00:00
|
|
|
}
|
|
|
|
|
2007-11-07 10:40:20 +00:00
|
|
|
if (inet_ehash_locks_alloc(&dccp_hashinfo))
|
|
|
|
goto out_free_dccp_ehash;
|
|
|
|
|
2005-08-10 03:14:34 +00:00
|
|
|
bhash_order = ehash_order;
|
|
|
|
|
|
|
|
do {
|
|
|
|
dccp_hashinfo.bhash_size = (1UL << bhash_order) * PAGE_SIZE /
|
|
|
|
sizeof(struct inet_bind_hashbucket);
|
2005-08-13 23:34:54 +00:00
|
|
|
if ((dccp_hashinfo.bhash_size > (64 * 1024)) &&
|
|
|
|
bhash_order > 0)
|
2005-08-10 03:14:34 +00:00
|
|
|
continue;
|
|
|
|
dccp_hashinfo.bhash = (struct inet_bind_hashbucket *)
|
|
|
|
__get_free_pages(GFP_ATOMIC, bhash_order);
|
|
|
|
} while (!dccp_hashinfo.bhash && --bhash_order >= 0);
|
|
|
|
|
|
|
|
if (!dccp_hashinfo.bhash) {
|
2006-11-20 20:39:23 +00:00
|
|
|
DCCP_CRIT("Failed to allocate DCCP bind hash table");
|
2007-11-07 10:40:20 +00:00
|
|
|
goto out_free_dccp_locks;
|
2005-08-10 03:14:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < dccp_hashinfo.bhash_size; i++) {
|
|
|
|
spin_lock_init(&dccp_hashinfo.bhash[i].lock);
|
|
|
|
INIT_HLIST_HEAD(&dccp_hashinfo.bhash[i].chain);
|
|
|
|
}
|
|
|
|
|
2006-03-21 05:24:42 +00:00
|
|
|
rc = dccp_mib_init();
|
2006-03-21 01:16:01 +00:00
|
|
|
if (rc)
|
2005-08-10 03:14:34 +00:00
|
|
|
goto out_free_dccp_bhash;
|
|
|
|
|
2006-03-21 01:16:17 +00:00
|
|
|
rc = dccp_ackvec_init();
|
2005-08-10 03:14:34 +00:00
|
|
|
if (rc)
|
2006-03-21 05:25:11 +00:00
|
|
|
goto out_free_dccp_mib;
|
2006-03-21 01:16:17 +00:00
|
|
|
|
2006-03-21 03:25:02 +00:00
|
|
|
rc = dccp_sysctl_init();
|
2006-03-21 01:16:17 +00:00
|
|
|
if (rc)
|
|
|
|
goto out_ackvec_exit;
|
2007-09-26 05:40:13 +00:00
|
|
|
|
|
|
|
dccp_timestamping_init();
|
2005-08-10 03:14:34 +00:00
|
|
|
out:
|
|
|
|
return rc;
|
2006-03-21 01:16:17 +00:00
|
|
|
out_ackvec_exit:
|
|
|
|
dccp_ackvec_exit();
|
2006-03-21 05:25:11 +00:00
|
|
|
out_free_dccp_mib:
|
2006-03-21 05:24:42 +00:00
|
|
|
dccp_mib_exit();
|
2005-08-10 03:14:34 +00:00
|
|
|
out_free_dccp_bhash:
|
|
|
|
free_pages((unsigned long)dccp_hashinfo.bhash, bhash_order);
|
|
|
|
dccp_hashinfo.bhash = NULL;
|
2007-11-07 10:40:20 +00:00
|
|
|
out_free_dccp_locks:
|
|
|
|
inet_ehash_locks_free(&dccp_hashinfo);
|
2005-08-10 03:14:34 +00:00
|
|
|
out_free_dccp_ehash:
|
|
|
|
free_pages((unsigned long)dccp_hashinfo.ehash, ehash_order);
|
|
|
|
dccp_hashinfo.ehash = NULL;
|
|
|
|
out_free_bind_bucket_cachep:
|
|
|
|
kmem_cache_destroy(dccp_hashinfo.bind_bucket_cachep);
|
|
|
|
dccp_hashinfo.bind_bucket_cachep = NULL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit dccp_fini(void)
|
|
|
|
{
|
2006-03-21 05:24:42 +00:00
|
|
|
dccp_mib_exit();
|
2005-08-13 23:35:39 +00:00
|
|
|
free_pages((unsigned long)dccp_hashinfo.bhash,
|
|
|
|
get_order(dccp_hashinfo.bhash_size *
|
|
|
|
sizeof(struct inet_bind_hashbucket)));
|
|
|
|
free_pages((unsigned long)dccp_hashinfo.ehash,
|
|
|
|
get_order(dccp_hashinfo.ehash_size *
|
|
|
|
sizeof(struct inet_ehash_bucket)));
|
2007-11-07 10:40:20 +00:00
|
|
|
inet_ehash_locks_free(&dccp_hashinfo);
|
2005-08-10 03:14:34 +00:00
|
|
|
kmem_cache_destroy(dccp_hashinfo.bind_bucket_cachep);
|
2006-03-21 01:16:17 +00:00
|
|
|
dccp_ackvec_exit();
|
2006-03-21 03:25:02 +00:00
|
|
|
dccp_sysctl_exit();
|
2005-08-10 03:14:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(dccp_init);
|
|
|
|
module_exit(dccp_fini);
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("Arnaldo Carvalho de Melo <acme@conectiva.com.br>");
|
|
|
|
MODULE_DESCRIPTION("DCCP - Datagram Congestion Controlled Protocol");
|