17c657876SArnaldo Carvalho de Melo /* 27c657876SArnaldo Carvalho de Melo * net/dccp/proto.c 37c657876SArnaldo Carvalho de Melo * 47c657876SArnaldo Carvalho de Melo * An implementation of the DCCP protocol 57c657876SArnaldo Carvalho de Melo * Arnaldo Carvalho de Melo <acme@conectiva.com.br> 67c657876SArnaldo Carvalho de Melo * 77c657876SArnaldo Carvalho de Melo * This program is free software; you can redistribute it and/or modify it 87c657876SArnaldo Carvalho de Melo * under the terms of the GNU General Public License version 2 as 97c657876SArnaldo Carvalho de Melo * published by the Free Software Foundation. 107c657876SArnaldo Carvalho de Melo */ 117c657876SArnaldo Carvalho de Melo 127c657876SArnaldo Carvalho de Melo #include <linux/config.h> 137c657876SArnaldo Carvalho de Melo #include <linux/dccp.h> 147c657876SArnaldo Carvalho de Melo #include <linux/module.h> 157c657876SArnaldo Carvalho de Melo #include <linux/types.h> 167c657876SArnaldo Carvalho de Melo #include <linux/sched.h> 177c657876SArnaldo Carvalho de Melo #include <linux/kernel.h> 187c657876SArnaldo Carvalho de Melo #include <linux/skbuff.h> 197c657876SArnaldo Carvalho de Melo #include <linux/netdevice.h> 207c657876SArnaldo Carvalho de Melo #include <linux/in.h> 217c657876SArnaldo Carvalho de Melo #include <linux/if_arp.h> 227c657876SArnaldo Carvalho de Melo #include <linux/init.h> 237c657876SArnaldo Carvalho de Melo #include <linux/random.h> 247c657876SArnaldo Carvalho de Melo #include <net/checksum.h> 257c657876SArnaldo Carvalho de Melo 267c657876SArnaldo Carvalho de Melo #include <net/inet_common.h> 2714c85021SArnaldo Carvalho de Melo #include <net/inet_sock.h> 287c657876SArnaldo Carvalho de Melo #include <net/protocol.h> 297c657876SArnaldo Carvalho de Melo #include <net/sock.h> 307c657876SArnaldo Carvalho de Melo #include <net/xfrm.h> 317c657876SArnaldo Carvalho de Melo 327c657876SArnaldo Carvalho de Melo #include <asm/semaphore.h> 337c657876SArnaldo Carvalho de Melo #include <linux/spinlock.h> 347c657876SArnaldo Carvalho de Melo #include <linux/timer.h> 357c657876SArnaldo Carvalho de Melo #include <linux/delay.h> 367c657876SArnaldo Carvalho de Melo #include <linux/poll.h> 377c657876SArnaldo Carvalho de Melo 387c657876SArnaldo Carvalho de Melo #include "ccid.h" 397c657876SArnaldo Carvalho de Melo #include "dccp.h" 40afe00251SAndrea Bittau #include "feat.h" 417c657876SArnaldo Carvalho de Melo 42ba89966cSEric Dumazet DEFINE_SNMP_STAT(struct dccp_mib, dccp_statistics) __read_mostly; 437c657876SArnaldo Carvalho de Melo 44f21e68caSArnaldo Carvalho de Melo EXPORT_SYMBOL_GPL(dccp_statistics); 45f21e68caSArnaldo Carvalho de Melo 467c657876SArnaldo Carvalho de Melo atomic_t dccp_orphan_count = ATOMIC_INIT(0); 477c657876SArnaldo Carvalho de Melo 48f21e68caSArnaldo Carvalho de Melo EXPORT_SYMBOL_GPL(dccp_orphan_count); 49f21e68caSArnaldo Carvalho de Melo 507c657876SArnaldo Carvalho de Melo static struct net_protocol dccp_protocol = { 517c657876SArnaldo Carvalho de Melo .handler = dccp_v4_rcv, 527c657876SArnaldo Carvalho de Melo .err_handler = dccp_v4_err, 53a516b049SPatrick McHardy .no_policy = 1, 547c657876SArnaldo Carvalho de Melo }; 557c657876SArnaldo Carvalho de Melo 567c657876SArnaldo Carvalho de Melo const char *dccp_packet_name(const int type) 577c657876SArnaldo Carvalho de Melo { 587c657876SArnaldo Carvalho de Melo static const char *dccp_packet_names[] = { 597c657876SArnaldo Carvalho de Melo [DCCP_PKT_REQUEST] = "REQUEST", 607c657876SArnaldo Carvalho de Melo [DCCP_PKT_RESPONSE] = "RESPONSE", 617c657876SArnaldo Carvalho de Melo [DCCP_PKT_DATA] = "DATA", 627c657876SArnaldo Carvalho de Melo [DCCP_PKT_ACK] = "ACK", 637c657876SArnaldo Carvalho de Melo [DCCP_PKT_DATAACK] = "DATAACK", 647c657876SArnaldo Carvalho de Melo [DCCP_PKT_CLOSEREQ] = "CLOSEREQ", 657c657876SArnaldo Carvalho de Melo [DCCP_PKT_CLOSE] = "CLOSE", 667c657876SArnaldo Carvalho de Melo [DCCP_PKT_RESET] = "RESET", 677c657876SArnaldo Carvalho de Melo [DCCP_PKT_SYNC] = "SYNC", 687c657876SArnaldo Carvalho de Melo [DCCP_PKT_SYNCACK] = "SYNCACK", 697c657876SArnaldo Carvalho de Melo }; 707c657876SArnaldo Carvalho de Melo 717c657876SArnaldo Carvalho de Melo if (type >= DCCP_NR_PKT_TYPES) 727c657876SArnaldo Carvalho de Melo return "INVALID"; 737c657876SArnaldo Carvalho de Melo else 747c657876SArnaldo Carvalho de Melo return dccp_packet_names[type]; 757c657876SArnaldo Carvalho de Melo } 767c657876SArnaldo Carvalho de Melo 777c657876SArnaldo Carvalho de Melo EXPORT_SYMBOL_GPL(dccp_packet_name); 787c657876SArnaldo Carvalho de Melo 797c657876SArnaldo Carvalho de Melo const char *dccp_state_name(const int state) 807c657876SArnaldo Carvalho de Melo { 817c657876SArnaldo Carvalho de Melo static char *dccp_state_names[] = { 827c657876SArnaldo Carvalho de Melo [DCCP_OPEN] = "OPEN", 837c657876SArnaldo Carvalho de Melo [DCCP_REQUESTING] = "REQUESTING", 847c657876SArnaldo Carvalho de Melo [DCCP_PARTOPEN] = "PARTOPEN", 857c657876SArnaldo Carvalho de Melo [DCCP_LISTEN] = "LISTEN", 867c657876SArnaldo Carvalho de Melo [DCCP_RESPOND] = "RESPOND", 877c657876SArnaldo Carvalho de Melo [DCCP_CLOSING] = "CLOSING", 887c657876SArnaldo Carvalho de Melo [DCCP_TIME_WAIT] = "TIME_WAIT", 897c657876SArnaldo Carvalho de Melo [DCCP_CLOSED] = "CLOSED", 907c657876SArnaldo Carvalho de Melo }; 917c657876SArnaldo Carvalho de Melo 927c657876SArnaldo Carvalho de Melo if (state >= DCCP_MAX_STATES) 937c657876SArnaldo Carvalho de Melo return "INVALID STATE!"; 947c657876SArnaldo Carvalho de Melo else 957c657876SArnaldo Carvalho de Melo return dccp_state_names[state]; 967c657876SArnaldo Carvalho de Melo } 977c657876SArnaldo Carvalho de Melo 987c657876SArnaldo Carvalho de Melo EXPORT_SYMBOL_GPL(dccp_state_name); 997c657876SArnaldo Carvalho de Melo 1007c657876SArnaldo Carvalho de Melo static inline int dccp_listen_start(struct sock *sk) 1017c657876SArnaldo Carvalho de Melo { 10267e6b629SArnaldo Carvalho de Melo struct dccp_sock *dp = dccp_sk(sk); 10367e6b629SArnaldo Carvalho de Melo 10467e6b629SArnaldo Carvalho de Melo dp->dccps_role = DCCP_ROLE_LISTEN; 10567e6b629SArnaldo Carvalho de Melo /* 10667e6b629SArnaldo Carvalho de Melo * Apps need to use setsockopt(DCCP_SOCKOPT_SERVICE) 10767e6b629SArnaldo Carvalho de Melo * before calling listen() 10867e6b629SArnaldo Carvalho de Melo */ 10967e6b629SArnaldo Carvalho de Melo if (dccp_service_not_initialized(sk)) 11067e6b629SArnaldo Carvalho de Melo return -EPROTO; 1117c657876SArnaldo Carvalho de Melo return inet_csk_listen_start(sk, TCP_SYNQ_HSIZE); 1127c657876SArnaldo Carvalho de Melo } 1137c657876SArnaldo Carvalho de Melo 1147c657876SArnaldo Carvalho de Melo int dccp_disconnect(struct sock *sk, int flags) 1157c657876SArnaldo Carvalho de Melo { 1167c657876SArnaldo Carvalho de Melo struct inet_connection_sock *icsk = inet_csk(sk); 1177c657876SArnaldo Carvalho de Melo struct inet_sock *inet = inet_sk(sk); 1187c657876SArnaldo Carvalho de Melo int err = 0; 1197c657876SArnaldo Carvalho de Melo const int old_state = sk->sk_state; 1207c657876SArnaldo Carvalho de Melo 1217c657876SArnaldo Carvalho de Melo if (old_state != DCCP_CLOSED) 1227c657876SArnaldo Carvalho de Melo dccp_set_state(sk, DCCP_CLOSED); 1237c657876SArnaldo Carvalho de Melo 1247c657876SArnaldo Carvalho de Melo /* ABORT function of RFC793 */ 1257c657876SArnaldo Carvalho de Melo if (old_state == DCCP_LISTEN) { 1267c657876SArnaldo Carvalho de Melo inet_csk_listen_stop(sk); 1277c657876SArnaldo Carvalho de Melo /* FIXME: do the active reset thing */ 1287c657876SArnaldo Carvalho de Melo } else if (old_state == DCCP_REQUESTING) 1297c657876SArnaldo Carvalho de Melo sk->sk_err = ECONNRESET; 1307c657876SArnaldo Carvalho de Melo 1317c657876SArnaldo Carvalho de Melo dccp_clear_xmit_timers(sk); 1327c657876SArnaldo Carvalho de Melo __skb_queue_purge(&sk->sk_receive_queue); 1337c657876SArnaldo Carvalho de Melo if (sk->sk_send_head != NULL) { 1347c657876SArnaldo Carvalho de Melo __kfree_skb(sk->sk_send_head); 1357c657876SArnaldo Carvalho de Melo sk->sk_send_head = NULL; 1367c657876SArnaldo Carvalho de Melo } 1377c657876SArnaldo Carvalho de Melo 1387c657876SArnaldo Carvalho de Melo inet->dport = 0; 1397c657876SArnaldo Carvalho de Melo 1407c657876SArnaldo Carvalho de Melo if (!(sk->sk_userlocks & SOCK_BINDADDR_LOCK)) 1417c657876SArnaldo Carvalho de Melo inet_reset_saddr(sk); 1427c657876SArnaldo Carvalho de Melo 1437c657876SArnaldo Carvalho de Melo sk->sk_shutdown = 0; 1447c657876SArnaldo Carvalho de Melo sock_reset_flag(sk, SOCK_DONE); 1457c657876SArnaldo Carvalho de Melo 1467c657876SArnaldo Carvalho de Melo icsk->icsk_backoff = 0; 1477c657876SArnaldo Carvalho de Melo inet_csk_delack_init(sk); 1487c657876SArnaldo Carvalho de Melo __sk_dst_reset(sk); 1497c657876SArnaldo Carvalho de Melo 1507c657876SArnaldo Carvalho de Melo BUG_TRAP(!inet->num || icsk->icsk_bind_hash); 1517c657876SArnaldo Carvalho de Melo 1527c657876SArnaldo Carvalho de Melo sk->sk_error_report(sk); 1537c657876SArnaldo Carvalho de Melo return err; 1547c657876SArnaldo Carvalho de Melo } 1557c657876SArnaldo Carvalho de Melo 156f21e68caSArnaldo Carvalho de Melo EXPORT_SYMBOL_GPL(dccp_disconnect); 157f21e68caSArnaldo Carvalho de Melo 158331968bdSArnaldo Carvalho de Melo /* 159331968bdSArnaldo Carvalho de Melo * Wait for a DCCP event. 160331968bdSArnaldo Carvalho de Melo * 161331968bdSArnaldo Carvalho de Melo * Note that we don't need to lock the socket, as the upper poll layers 162331968bdSArnaldo Carvalho de Melo * take care of normal races (between the test and the event) and we don't 163331968bdSArnaldo Carvalho de Melo * go look at any of the socket buffers directly. 164331968bdSArnaldo Carvalho de Melo */ 165f21e68caSArnaldo Carvalho de Melo unsigned int dccp_poll(struct file *file, struct socket *sock, 166331968bdSArnaldo Carvalho de Melo poll_table *wait) 167331968bdSArnaldo Carvalho de Melo { 168331968bdSArnaldo Carvalho de Melo unsigned int mask; 169331968bdSArnaldo Carvalho de Melo struct sock *sk = sock->sk; 170331968bdSArnaldo Carvalho de Melo 171331968bdSArnaldo Carvalho de Melo poll_wait(file, sk->sk_sleep, wait); 172331968bdSArnaldo Carvalho de Melo if (sk->sk_state == DCCP_LISTEN) 173331968bdSArnaldo Carvalho de Melo return inet_csk_listen_poll(sk); 174331968bdSArnaldo Carvalho de Melo 175331968bdSArnaldo Carvalho de Melo /* Socket is not locked. We are protected from async events 176331968bdSArnaldo Carvalho de Melo by poll logic and correct handling of state changes 177331968bdSArnaldo Carvalho de Melo made by another threads is impossible in any case. 178331968bdSArnaldo Carvalho de Melo */ 179331968bdSArnaldo Carvalho de Melo 180331968bdSArnaldo Carvalho de Melo mask = 0; 181331968bdSArnaldo Carvalho de Melo if (sk->sk_err) 182331968bdSArnaldo Carvalho de Melo mask = POLLERR; 183331968bdSArnaldo Carvalho de Melo 184331968bdSArnaldo Carvalho de Melo if (sk->sk_shutdown == SHUTDOWN_MASK || sk->sk_state == DCCP_CLOSED) 185331968bdSArnaldo Carvalho de Melo mask |= POLLHUP; 186331968bdSArnaldo Carvalho de Melo if (sk->sk_shutdown & RCV_SHUTDOWN) 187331968bdSArnaldo Carvalho de Melo mask |= POLLIN | POLLRDNORM; 188331968bdSArnaldo Carvalho de Melo 189331968bdSArnaldo Carvalho de Melo /* Connected? */ 190331968bdSArnaldo Carvalho de Melo if ((1 << sk->sk_state) & ~(DCCPF_REQUESTING | DCCPF_RESPOND)) { 191331968bdSArnaldo Carvalho de Melo if (atomic_read(&sk->sk_rmem_alloc) > 0) 192331968bdSArnaldo Carvalho de Melo mask |= POLLIN | POLLRDNORM; 193331968bdSArnaldo Carvalho de Melo 194331968bdSArnaldo Carvalho de Melo if (!(sk->sk_shutdown & SEND_SHUTDOWN)) { 195331968bdSArnaldo Carvalho de Melo if (sk_stream_wspace(sk) >= sk_stream_min_wspace(sk)) { 196331968bdSArnaldo Carvalho de Melo mask |= POLLOUT | POLLWRNORM; 197331968bdSArnaldo Carvalho de Melo } else { /* send SIGIO later */ 198331968bdSArnaldo Carvalho de Melo set_bit(SOCK_ASYNC_NOSPACE, 199331968bdSArnaldo Carvalho de Melo &sk->sk_socket->flags); 200331968bdSArnaldo Carvalho de Melo set_bit(SOCK_NOSPACE, &sk->sk_socket->flags); 201331968bdSArnaldo Carvalho de Melo 202331968bdSArnaldo Carvalho de Melo /* Race breaker. If space is freed after 203331968bdSArnaldo Carvalho de Melo * wspace test but before the flags are set, 204331968bdSArnaldo Carvalho de Melo * IO signal will be lost. 205331968bdSArnaldo Carvalho de Melo */ 206331968bdSArnaldo Carvalho de Melo if (sk_stream_wspace(sk) >= sk_stream_min_wspace(sk)) 207331968bdSArnaldo Carvalho de Melo mask |= POLLOUT | POLLWRNORM; 208331968bdSArnaldo Carvalho de Melo } 209331968bdSArnaldo Carvalho de Melo } 210331968bdSArnaldo Carvalho de Melo } 211331968bdSArnaldo Carvalho de Melo return mask; 212331968bdSArnaldo Carvalho de Melo } 213331968bdSArnaldo Carvalho de Melo 214f21e68caSArnaldo Carvalho de Melo EXPORT_SYMBOL_GPL(dccp_poll); 215f21e68caSArnaldo Carvalho de Melo 2167c657876SArnaldo Carvalho de Melo int dccp_ioctl(struct sock *sk, int cmd, unsigned long arg) 2177c657876SArnaldo Carvalho de Melo { 2187c657876SArnaldo Carvalho de Melo dccp_pr_debug("entry\n"); 2197c657876SArnaldo Carvalho de Melo return -ENOIOCTLCMD; 2207c657876SArnaldo Carvalho de Melo } 2217c657876SArnaldo Carvalho de Melo 222f21e68caSArnaldo Carvalho de Melo EXPORT_SYMBOL_GPL(dccp_ioctl); 223f21e68caSArnaldo Carvalho de Melo 22467e6b629SArnaldo Carvalho de Melo static int dccp_setsockopt_service(struct sock *sk, const u32 service, 22567e6b629SArnaldo Carvalho de Melo char __user *optval, int optlen) 22667e6b629SArnaldo Carvalho de Melo { 22767e6b629SArnaldo Carvalho de Melo struct dccp_sock *dp = dccp_sk(sk); 22867e6b629SArnaldo Carvalho de Melo struct dccp_service_list *sl = NULL; 22967e6b629SArnaldo Carvalho de Melo 23067e6b629SArnaldo Carvalho de Melo if (service == DCCP_SERVICE_INVALID_VALUE || 23167e6b629SArnaldo Carvalho de Melo optlen > DCCP_SERVICE_LIST_MAX_LEN * sizeof(u32)) 23267e6b629SArnaldo Carvalho de Melo return -EINVAL; 23367e6b629SArnaldo Carvalho de Melo 23467e6b629SArnaldo Carvalho de Melo if (optlen > sizeof(service)) { 23567e6b629SArnaldo Carvalho de Melo sl = kmalloc(optlen, GFP_KERNEL); 23667e6b629SArnaldo Carvalho de Melo if (sl == NULL) 23767e6b629SArnaldo Carvalho de Melo return -ENOMEM; 23867e6b629SArnaldo Carvalho de Melo 23967e6b629SArnaldo Carvalho de Melo sl->dccpsl_nr = optlen / sizeof(u32) - 1; 24067e6b629SArnaldo Carvalho de Melo if (copy_from_user(sl->dccpsl_list, 24167e6b629SArnaldo Carvalho de Melo optval + sizeof(service), 24267e6b629SArnaldo Carvalho de Melo optlen - sizeof(service)) || 24367e6b629SArnaldo Carvalho de Melo dccp_list_has_service(sl, DCCP_SERVICE_INVALID_VALUE)) { 24467e6b629SArnaldo Carvalho de Melo kfree(sl); 24567e6b629SArnaldo Carvalho de Melo return -EFAULT; 24667e6b629SArnaldo Carvalho de Melo } 24767e6b629SArnaldo Carvalho de Melo } 24867e6b629SArnaldo Carvalho de Melo 24967e6b629SArnaldo Carvalho de Melo lock_sock(sk); 25067e6b629SArnaldo Carvalho de Melo dp->dccps_service = service; 25167e6b629SArnaldo Carvalho de Melo 25267e6b629SArnaldo Carvalho de Melo kfree(dp->dccps_service_list); 25367e6b629SArnaldo Carvalho de Melo 25467e6b629SArnaldo Carvalho de Melo dp->dccps_service_list = sl; 25567e6b629SArnaldo Carvalho de Melo release_sock(sk); 25667e6b629SArnaldo Carvalho de Melo return 0; 25767e6b629SArnaldo Carvalho de Melo } 25867e6b629SArnaldo Carvalho de Melo 259afe00251SAndrea Bittau /* byte 1 is feature. the rest is the preference list */ 260afe00251SAndrea Bittau static int dccp_setsockopt_change(struct sock *sk, int type, 261afe00251SAndrea Bittau struct dccp_so_feat __user *optval) 262afe00251SAndrea Bittau { 263afe00251SAndrea Bittau struct dccp_so_feat opt; 264afe00251SAndrea Bittau u8 *val; 265afe00251SAndrea Bittau int rc; 266afe00251SAndrea Bittau 267afe00251SAndrea Bittau if (copy_from_user(&opt, optval, sizeof(opt))) 268afe00251SAndrea Bittau return -EFAULT; 269afe00251SAndrea Bittau 270afe00251SAndrea Bittau val = kmalloc(opt.dccpsf_len, GFP_KERNEL); 271afe00251SAndrea Bittau if (!val) 272afe00251SAndrea Bittau return -ENOMEM; 273afe00251SAndrea Bittau 274afe00251SAndrea Bittau if (copy_from_user(val, opt.dccpsf_val, opt.dccpsf_len)) { 275afe00251SAndrea Bittau rc = -EFAULT; 276afe00251SAndrea Bittau goto out_free_val; 277afe00251SAndrea Bittau } 278afe00251SAndrea Bittau 279afe00251SAndrea Bittau rc = dccp_feat_change(sk, type, opt.dccpsf_feat, val, opt.dccpsf_len, 280afe00251SAndrea Bittau GFP_KERNEL); 281afe00251SAndrea Bittau if (rc) 282afe00251SAndrea Bittau goto out_free_val; 283afe00251SAndrea Bittau 284afe00251SAndrea Bittau out: 285afe00251SAndrea Bittau return rc; 286afe00251SAndrea Bittau 287afe00251SAndrea Bittau out_free_val: 288afe00251SAndrea Bittau kfree(val); 289afe00251SAndrea Bittau goto out; 290afe00251SAndrea Bittau } 291afe00251SAndrea Bittau 2927c657876SArnaldo Carvalho de Melo int dccp_setsockopt(struct sock *sk, int level, int optname, 293a1d3a355SArnaldo Carvalho de Melo char __user *optval, int optlen) 2947c657876SArnaldo Carvalho de Melo { 295a84ffe43SArnaldo Carvalho de Melo struct dccp_sock *dp; 296a84ffe43SArnaldo Carvalho de Melo int err; 297a84ffe43SArnaldo Carvalho de Melo int val; 2987c657876SArnaldo Carvalho de Melo 2997c657876SArnaldo Carvalho de Melo if (level != SOL_DCCP) 30057cca05aSArnaldo Carvalho de Melo return inet_csk(sk)->icsk_af_ops->setsockopt(sk, level, 30157cca05aSArnaldo Carvalho de Melo optname, optval, 30257cca05aSArnaldo Carvalho de Melo optlen); 3037c657876SArnaldo Carvalho de Melo 304a84ffe43SArnaldo Carvalho de Melo if (optlen < sizeof(int)) 305a84ffe43SArnaldo Carvalho de Melo return -EINVAL; 306a84ffe43SArnaldo Carvalho de Melo 307a84ffe43SArnaldo Carvalho de Melo if (get_user(val, (int __user *)optval)) 308a84ffe43SArnaldo Carvalho de Melo return -EFAULT; 309a84ffe43SArnaldo Carvalho de Melo 31067e6b629SArnaldo Carvalho de Melo if (optname == DCCP_SOCKOPT_SERVICE) 31167e6b629SArnaldo Carvalho de Melo return dccp_setsockopt_service(sk, val, optval, optlen); 312a84ffe43SArnaldo Carvalho de Melo 31367e6b629SArnaldo Carvalho de Melo lock_sock(sk); 314a84ffe43SArnaldo Carvalho de Melo dp = dccp_sk(sk); 315a84ffe43SArnaldo Carvalho de Melo err = 0; 316a84ffe43SArnaldo Carvalho de Melo 317a84ffe43SArnaldo Carvalho de Melo switch (optname) { 318a84ffe43SArnaldo Carvalho de Melo case DCCP_SOCKOPT_PACKET_SIZE: 319a84ffe43SArnaldo Carvalho de Melo dp->dccps_packet_size = val; 320a84ffe43SArnaldo Carvalho de Melo break; 321afe00251SAndrea Bittau 322afe00251SAndrea Bittau case DCCP_SOCKOPT_CHANGE_L: 323afe00251SAndrea Bittau if (optlen != sizeof(struct dccp_so_feat)) 324afe00251SAndrea Bittau err = -EINVAL; 325afe00251SAndrea Bittau else 326afe00251SAndrea Bittau err = dccp_setsockopt_change(sk, DCCPO_CHANGE_L, 327afe00251SAndrea Bittau (struct dccp_so_feat *) 328afe00251SAndrea Bittau optval); 329afe00251SAndrea Bittau break; 330afe00251SAndrea Bittau 331afe00251SAndrea Bittau case DCCP_SOCKOPT_CHANGE_R: 332afe00251SAndrea Bittau if (optlen != sizeof(struct dccp_so_feat)) 333afe00251SAndrea Bittau err = -EINVAL; 334afe00251SAndrea Bittau else 335afe00251SAndrea Bittau err = dccp_setsockopt_change(sk, DCCPO_CHANGE_R, 336afe00251SAndrea Bittau (struct dccp_so_feat *) 337afe00251SAndrea Bittau optval); 338afe00251SAndrea Bittau break; 339afe00251SAndrea Bittau 340a84ffe43SArnaldo Carvalho de Melo default: 341a84ffe43SArnaldo Carvalho de Melo err = -ENOPROTOOPT; 342a84ffe43SArnaldo Carvalho de Melo break; 343a84ffe43SArnaldo Carvalho de Melo } 344a84ffe43SArnaldo Carvalho de Melo 345a84ffe43SArnaldo Carvalho de Melo release_sock(sk); 346a84ffe43SArnaldo Carvalho de Melo return err; 3477c657876SArnaldo Carvalho de Melo } 3487c657876SArnaldo Carvalho de Melo 349f21e68caSArnaldo Carvalho de Melo EXPORT_SYMBOL_GPL(dccp_setsockopt); 350f21e68caSArnaldo Carvalho de Melo 35167e6b629SArnaldo Carvalho de Melo static int dccp_getsockopt_service(struct sock *sk, int len, 35267e6b629SArnaldo Carvalho de Melo u32 __user *optval, 35367e6b629SArnaldo Carvalho de Melo int __user *optlen) 35467e6b629SArnaldo Carvalho de Melo { 35567e6b629SArnaldo Carvalho de Melo const struct dccp_sock *dp = dccp_sk(sk); 35667e6b629SArnaldo Carvalho de Melo const struct dccp_service_list *sl; 35767e6b629SArnaldo Carvalho de Melo int err = -ENOENT, slen = 0, total_len = sizeof(u32); 35867e6b629SArnaldo Carvalho de Melo 35967e6b629SArnaldo Carvalho de Melo lock_sock(sk); 36067e6b629SArnaldo Carvalho de Melo if (dccp_service_not_initialized(sk)) 36167e6b629SArnaldo Carvalho de Melo goto out; 36267e6b629SArnaldo Carvalho de Melo 36367e6b629SArnaldo Carvalho de Melo if ((sl = dp->dccps_service_list) != NULL) { 36467e6b629SArnaldo Carvalho de Melo slen = sl->dccpsl_nr * sizeof(u32); 36567e6b629SArnaldo Carvalho de Melo total_len += slen; 36667e6b629SArnaldo Carvalho de Melo } 36767e6b629SArnaldo Carvalho de Melo 36867e6b629SArnaldo Carvalho de Melo err = -EINVAL; 36967e6b629SArnaldo Carvalho de Melo if (total_len > len) 37067e6b629SArnaldo Carvalho de Melo goto out; 37167e6b629SArnaldo Carvalho de Melo 37267e6b629SArnaldo Carvalho de Melo err = 0; 37367e6b629SArnaldo Carvalho de Melo if (put_user(total_len, optlen) || 37467e6b629SArnaldo Carvalho de Melo put_user(dp->dccps_service, optval) || 37567e6b629SArnaldo Carvalho de Melo (sl != NULL && copy_to_user(optval + 1, sl->dccpsl_list, slen))) 37667e6b629SArnaldo Carvalho de Melo err = -EFAULT; 37767e6b629SArnaldo Carvalho de Melo out: 37867e6b629SArnaldo Carvalho de Melo release_sock(sk); 37967e6b629SArnaldo Carvalho de Melo return err; 38067e6b629SArnaldo Carvalho de Melo } 38167e6b629SArnaldo Carvalho de Melo 3827c657876SArnaldo Carvalho de Melo int dccp_getsockopt(struct sock *sk, int level, int optname, 383a1d3a355SArnaldo Carvalho de Melo char __user *optval, int __user *optlen) 3847c657876SArnaldo Carvalho de Melo { 385a84ffe43SArnaldo Carvalho de Melo struct dccp_sock *dp; 386a84ffe43SArnaldo Carvalho de Melo int val, len; 3877c657876SArnaldo Carvalho de Melo 3887c657876SArnaldo Carvalho de Melo if (level != SOL_DCCP) 38957cca05aSArnaldo Carvalho de Melo return inet_csk(sk)->icsk_af_ops->getsockopt(sk, level, 39057cca05aSArnaldo Carvalho de Melo optname, optval, 39157cca05aSArnaldo Carvalho de Melo optlen); 392a84ffe43SArnaldo Carvalho de Melo if (get_user(len, optlen)) 393a84ffe43SArnaldo Carvalho de Melo return -EFAULT; 394a84ffe43SArnaldo Carvalho de Melo 39588f964dbSArnaldo Carvalho de Melo if (len < sizeof(int)) 396a84ffe43SArnaldo Carvalho de Melo return -EINVAL; 397a84ffe43SArnaldo Carvalho de Melo 398a84ffe43SArnaldo Carvalho de Melo dp = dccp_sk(sk); 399a84ffe43SArnaldo Carvalho de Melo 400a84ffe43SArnaldo Carvalho de Melo switch (optname) { 401a84ffe43SArnaldo Carvalho de Melo case DCCP_SOCKOPT_PACKET_SIZE: 402a84ffe43SArnaldo Carvalho de Melo val = dp->dccps_packet_size; 40388f964dbSArnaldo Carvalho de Melo len = sizeof(dp->dccps_packet_size); 404a84ffe43SArnaldo Carvalho de Melo break; 40588f964dbSArnaldo Carvalho de Melo case DCCP_SOCKOPT_SERVICE: 40688f964dbSArnaldo Carvalho de Melo return dccp_getsockopt_service(sk, len, 40788f964dbSArnaldo Carvalho de Melo (u32 __user *)optval, optlen); 40888f964dbSArnaldo Carvalho de Melo case 128 ... 191: 40988f964dbSArnaldo Carvalho de Melo return ccid_hc_rx_getsockopt(dp->dccps_hc_rx_ccid, sk, optname, 41088f964dbSArnaldo Carvalho de Melo len, (u32 __user *)optval, optlen); 41188f964dbSArnaldo Carvalho de Melo case 192 ... 255: 41288f964dbSArnaldo Carvalho de Melo return ccid_hc_tx_getsockopt(dp->dccps_hc_tx_ccid, sk, optname, 41388f964dbSArnaldo Carvalho de Melo len, (u32 __user *)optval, optlen); 414a84ffe43SArnaldo Carvalho de Melo default: 415a84ffe43SArnaldo Carvalho de Melo return -ENOPROTOOPT; 416a84ffe43SArnaldo Carvalho de Melo } 417a84ffe43SArnaldo Carvalho de Melo 418a84ffe43SArnaldo Carvalho de Melo if (put_user(len, optlen) || copy_to_user(optval, &val, len)) 419a84ffe43SArnaldo Carvalho de Melo return -EFAULT; 420a84ffe43SArnaldo Carvalho de Melo 421a84ffe43SArnaldo Carvalho de Melo return 0; 4227c657876SArnaldo Carvalho de Melo } 4237c657876SArnaldo Carvalho de Melo 424f21e68caSArnaldo Carvalho de Melo EXPORT_SYMBOL_GPL(dccp_getsockopt); 425f21e68caSArnaldo Carvalho de Melo 4267c657876SArnaldo Carvalho de Melo int dccp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg, 4277c657876SArnaldo Carvalho de Melo size_t len) 4287c657876SArnaldo Carvalho de Melo { 4297c657876SArnaldo Carvalho de Melo const struct dccp_sock *dp = dccp_sk(sk); 4307c657876SArnaldo Carvalho de Melo const int flags = msg->msg_flags; 4317c657876SArnaldo Carvalho de Melo const int noblock = flags & MSG_DONTWAIT; 4327c657876SArnaldo Carvalho de Melo struct sk_buff *skb; 4337c657876SArnaldo Carvalho de Melo int rc, size; 4347c657876SArnaldo Carvalho de Melo long timeo; 4357c657876SArnaldo Carvalho de Melo 4367c657876SArnaldo Carvalho de Melo if (len > dp->dccps_mss_cache) 4377c657876SArnaldo Carvalho de Melo return -EMSGSIZE; 4387c657876SArnaldo Carvalho de Melo 4397c657876SArnaldo Carvalho de Melo lock_sock(sk); 44027258ee5SArnaldo Carvalho de Melo timeo = sock_sndtimeo(sk, noblock); 4417c657876SArnaldo Carvalho de Melo 4427c657876SArnaldo Carvalho de Melo /* 4437c657876SArnaldo Carvalho de Melo * We have to use sk_stream_wait_connect here to set sk_write_pending, 4447c657876SArnaldo Carvalho de Melo * so that the trick in dccp_rcv_request_sent_state_process. 4457c657876SArnaldo Carvalho de Melo */ 4467c657876SArnaldo Carvalho de Melo /* Wait for a connection to finish. */ 4477c657876SArnaldo Carvalho de Melo if ((1 << sk->sk_state) & ~(DCCPF_OPEN | DCCPF_PARTOPEN | DCCPF_CLOSING)) 4487c657876SArnaldo Carvalho de Melo if ((rc = sk_stream_wait_connect(sk, &timeo)) != 0) 44927258ee5SArnaldo Carvalho de Melo goto out_release; 4507c657876SArnaldo Carvalho de Melo 4517c657876SArnaldo Carvalho de Melo size = sk->sk_prot->max_header + len; 4527c657876SArnaldo Carvalho de Melo release_sock(sk); 4537c657876SArnaldo Carvalho de Melo skb = sock_alloc_send_skb(sk, size, noblock, &rc); 4547c657876SArnaldo Carvalho de Melo lock_sock(sk); 4557c657876SArnaldo Carvalho de Melo if (skb == NULL) 4567c657876SArnaldo Carvalho de Melo goto out_release; 4577c657876SArnaldo Carvalho de Melo 4587c657876SArnaldo Carvalho de Melo skb_reserve(skb, sk->sk_prot->max_header); 4597c657876SArnaldo Carvalho de Melo rc = memcpy_fromiovec(skb_put(skb, len), msg->msg_iov, len); 46027258ee5SArnaldo Carvalho de Melo if (rc != 0) 46127258ee5SArnaldo Carvalho de Melo goto out_discard; 4627c657876SArnaldo Carvalho de Melo 463d6809c12SArnaldo Carvalho de Melo rc = dccp_write_xmit(sk, skb, &timeo); 46420472af9SArnaldo Carvalho de Melo /* 46520472af9SArnaldo Carvalho de Melo * XXX we don't use sk_write_queue, so just discard the packet. 46620472af9SArnaldo Carvalho de Melo * Current plan however is to _use_ sk_write_queue with 46720472af9SArnaldo Carvalho de Melo * an algorith similar to tcp_sendmsg, where the main difference 46820472af9SArnaldo Carvalho de Melo * is that in DCCP we have to respect packet boundaries, so 46920472af9SArnaldo Carvalho de Melo * no coalescing of skbs. 47020472af9SArnaldo Carvalho de Melo * 47120472af9SArnaldo Carvalho de Melo * This bug was _quickly_ found & fixed by just looking at an OSTRA 47220472af9SArnaldo Carvalho de Melo * generated callgraph 8) -acme 47320472af9SArnaldo Carvalho de Melo */ 4747c657876SArnaldo Carvalho de Melo out_release: 4757c657876SArnaldo Carvalho de Melo release_sock(sk); 4767c657876SArnaldo Carvalho de Melo return rc ? : len; 47727258ee5SArnaldo Carvalho de Melo out_discard: 47827258ee5SArnaldo Carvalho de Melo kfree_skb(skb); 4797c657876SArnaldo Carvalho de Melo goto out_release; 4807c657876SArnaldo Carvalho de Melo } 4817c657876SArnaldo Carvalho de Melo 482f21e68caSArnaldo Carvalho de Melo EXPORT_SYMBOL_GPL(dccp_sendmsg); 483f21e68caSArnaldo Carvalho de Melo 4847c657876SArnaldo Carvalho de Melo int dccp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg, 4857c657876SArnaldo Carvalho de Melo size_t len, int nonblock, int flags, int *addr_len) 4867c657876SArnaldo Carvalho de Melo { 4877c657876SArnaldo Carvalho de Melo const struct dccp_hdr *dh; 4887c657876SArnaldo Carvalho de Melo long timeo; 4897c657876SArnaldo Carvalho de Melo 4907c657876SArnaldo Carvalho de Melo lock_sock(sk); 4917c657876SArnaldo Carvalho de Melo 492531669a0SArnaldo Carvalho de Melo if (sk->sk_state == DCCP_LISTEN) { 493531669a0SArnaldo Carvalho de Melo len = -ENOTCONN; 4947c657876SArnaldo Carvalho de Melo goto out; 495531669a0SArnaldo Carvalho de Melo } 4967c657876SArnaldo Carvalho de Melo 4977c657876SArnaldo Carvalho de Melo timeo = sock_rcvtimeo(sk, nonblock); 4987c657876SArnaldo Carvalho de Melo 4997c657876SArnaldo Carvalho de Melo do { 500531669a0SArnaldo Carvalho de Melo struct sk_buff *skb = skb_peek(&sk->sk_receive_queue); 5017c657876SArnaldo Carvalho de Melo 502531669a0SArnaldo Carvalho de Melo if (skb == NULL) 503531669a0SArnaldo Carvalho de Melo goto verify_sock_status; 5047c657876SArnaldo Carvalho de Melo 5057c657876SArnaldo Carvalho de Melo dh = dccp_hdr(skb); 5067c657876SArnaldo Carvalho de Melo 5077c657876SArnaldo Carvalho de Melo if (dh->dccph_type == DCCP_PKT_DATA || 5087c657876SArnaldo Carvalho de Melo dh->dccph_type == DCCP_PKT_DATAACK) 5097c657876SArnaldo Carvalho de Melo goto found_ok_skb; 5107c657876SArnaldo Carvalho de Melo 5117c657876SArnaldo Carvalho de Melo if (dh->dccph_type == DCCP_PKT_RESET || 5127c657876SArnaldo Carvalho de Melo dh->dccph_type == DCCP_PKT_CLOSE) { 5137c657876SArnaldo Carvalho de Melo dccp_pr_debug("found fin ok!\n"); 514531669a0SArnaldo Carvalho de Melo len = 0; 5157c657876SArnaldo Carvalho de Melo goto found_fin_ok; 5167c657876SArnaldo Carvalho de Melo } 5177690af3fSArnaldo Carvalho de Melo dccp_pr_debug("packet_type=%s\n", 5187690af3fSArnaldo Carvalho de Melo dccp_packet_name(dh->dccph_type)); 519531669a0SArnaldo Carvalho de Melo sk_eat_skb(sk, skb); 520531669a0SArnaldo Carvalho de Melo verify_sock_status: 521531669a0SArnaldo Carvalho de Melo if (sock_flag(sk, SOCK_DONE)) { 522531669a0SArnaldo Carvalho de Melo len = 0; 5237c657876SArnaldo Carvalho de Melo break; 5247c657876SArnaldo Carvalho de Melo } 5257c657876SArnaldo Carvalho de Melo 526531669a0SArnaldo Carvalho de Melo if (sk->sk_err) { 527531669a0SArnaldo Carvalho de Melo len = sock_error(sk); 5287c657876SArnaldo Carvalho de Melo break; 529531669a0SArnaldo Carvalho de Melo } 530531669a0SArnaldo Carvalho de Melo 531531669a0SArnaldo Carvalho de Melo if (sk->sk_shutdown & RCV_SHUTDOWN) { 532531669a0SArnaldo Carvalho de Melo len = 0; 533531669a0SArnaldo Carvalho de Melo break; 534531669a0SArnaldo Carvalho de Melo } 5357c657876SArnaldo Carvalho de Melo 5367c657876SArnaldo Carvalho de Melo if (sk->sk_state == DCCP_CLOSED) { 5377c657876SArnaldo Carvalho de Melo if (!sock_flag(sk, SOCK_DONE)) { 5387c657876SArnaldo Carvalho de Melo /* This occurs when user tries to read 5397c657876SArnaldo Carvalho de Melo * from never connected socket. 5407c657876SArnaldo Carvalho de Melo */ 541531669a0SArnaldo Carvalho de Melo len = -ENOTCONN; 5427c657876SArnaldo Carvalho de Melo break; 5437c657876SArnaldo Carvalho de Melo } 544531669a0SArnaldo Carvalho de Melo len = 0; 5457c657876SArnaldo Carvalho de Melo break; 5467c657876SArnaldo Carvalho de Melo } 5477c657876SArnaldo Carvalho de Melo 5487c657876SArnaldo Carvalho de Melo if (!timeo) { 549531669a0SArnaldo Carvalho de Melo len = -EAGAIN; 5507c657876SArnaldo Carvalho de Melo break; 5517c657876SArnaldo Carvalho de Melo } 5527c657876SArnaldo Carvalho de Melo 5537c657876SArnaldo Carvalho de Melo if (signal_pending(current)) { 554531669a0SArnaldo Carvalho de Melo len = sock_intr_errno(timeo); 5557c657876SArnaldo Carvalho de Melo break; 5567c657876SArnaldo Carvalho de Melo } 5577c657876SArnaldo Carvalho de Melo 5587c657876SArnaldo Carvalho de Melo sk_wait_data(sk, &timeo); 5597c657876SArnaldo Carvalho de Melo continue; 5607c657876SArnaldo Carvalho de Melo found_ok_skb: 561531669a0SArnaldo Carvalho de Melo if (len > skb->len) 562531669a0SArnaldo Carvalho de Melo len = skb->len; 563531669a0SArnaldo Carvalho de Melo else if (len < skb->len) 564531669a0SArnaldo Carvalho de Melo msg->msg_flags |= MSG_TRUNC; 5657c657876SArnaldo Carvalho de Melo 566531669a0SArnaldo Carvalho de Melo if (skb_copy_datagram_iovec(skb, 0, msg->msg_iov, len)) { 5677c657876SArnaldo Carvalho de Melo /* Exception. Bailout! */ 568531669a0SArnaldo Carvalho de Melo len = -EFAULT; 5697c657876SArnaldo Carvalho de Melo break; 5707c657876SArnaldo Carvalho de Melo } 5717c657876SArnaldo Carvalho de Melo found_fin_ok: 5727c657876SArnaldo Carvalho de Melo if (!(flags & MSG_PEEK)) 5737c657876SArnaldo Carvalho de Melo sk_eat_skb(sk, skb); 5747c657876SArnaldo Carvalho de Melo break; 575531669a0SArnaldo Carvalho de Melo } while (1); 5767c657876SArnaldo Carvalho de Melo out: 5777c657876SArnaldo Carvalho de Melo release_sock(sk); 578531669a0SArnaldo Carvalho de Melo return len; 5797c657876SArnaldo Carvalho de Melo } 5807c657876SArnaldo Carvalho de Melo 581f21e68caSArnaldo Carvalho de Melo EXPORT_SYMBOL_GPL(dccp_recvmsg); 582f21e68caSArnaldo Carvalho de Melo 583f21e68caSArnaldo Carvalho de Melo int inet_dccp_listen(struct socket *sock, int backlog) 5847c657876SArnaldo Carvalho de Melo { 5857c657876SArnaldo Carvalho de Melo struct sock *sk = sock->sk; 5867c657876SArnaldo Carvalho de Melo unsigned char old_state; 5877c657876SArnaldo Carvalho de Melo int err; 5887c657876SArnaldo Carvalho de Melo 5897c657876SArnaldo Carvalho de Melo lock_sock(sk); 5907c657876SArnaldo Carvalho de Melo 5917c657876SArnaldo Carvalho de Melo err = -EINVAL; 5927c657876SArnaldo Carvalho de Melo if (sock->state != SS_UNCONNECTED || sock->type != SOCK_DCCP) 5937c657876SArnaldo Carvalho de Melo goto out; 5947c657876SArnaldo Carvalho de Melo 5957c657876SArnaldo Carvalho de Melo old_state = sk->sk_state; 5967c657876SArnaldo Carvalho de Melo if (!((1 << old_state) & (DCCPF_CLOSED | DCCPF_LISTEN))) 5977c657876SArnaldo Carvalho de Melo goto out; 5987c657876SArnaldo Carvalho de Melo 5997c657876SArnaldo Carvalho de Melo /* Really, if the socket is already in listen state 6007c657876SArnaldo Carvalho de Melo * we can only allow the backlog to be adjusted. 6017c657876SArnaldo Carvalho de Melo */ 6027c657876SArnaldo Carvalho de Melo if (old_state != DCCP_LISTEN) { 6037c657876SArnaldo Carvalho de Melo /* 6047c657876SArnaldo Carvalho de Melo * FIXME: here it probably should be sk->sk_prot->listen_start 6057c657876SArnaldo Carvalho de Melo * see tcp_listen_start 6067c657876SArnaldo Carvalho de Melo */ 6077c657876SArnaldo Carvalho de Melo err = dccp_listen_start(sk); 6087c657876SArnaldo Carvalho de Melo if (err) 6097c657876SArnaldo Carvalho de Melo goto out; 6107c657876SArnaldo Carvalho de Melo } 6117c657876SArnaldo Carvalho de Melo sk->sk_max_ack_backlog = backlog; 6127c657876SArnaldo Carvalho de Melo err = 0; 6137c657876SArnaldo Carvalho de Melo 6147c657876SArnaldo Carvalho de Melo out: 6157c657876SArnaldo Carvalho de Melo release_sock(sk); 6167c657876SArnaldo Carvalho de Melo return err; 6177c657876SArnaldo Carvalho de Melo } 6187c657876SArnaldo Carvalho de Melo 619f21e68caSArnaldo Carvalho de Melo EXPORT_SYMBOL_GPL(inet_dccp_listen); 620f21e68caSArnaldo Carvalho de Melo 6217c657876SArnaldo Carvalho de Melo static const unsigned char dccp_new_state[] = { 6227c657876SArnaldo Carvalho de Melo /* current state: new state: action: */ 6237c657876SArnaldo Carvalho de Melo [0] = DCCP_CLOSED, 6247c657876SArnaldo Carvalho de Melo [DCCP_OPEN] = DCCP_CLOSING | DCCP_ACTION_FIN, 6257c657876SArnaldo Carvalho de Melo [DCCP_REQUESTING] = DCCP_CLOSED, 6267c657876SArnaldo Carvalho de Melo [DCCP_PARTOPEN] = DCCP_CLOSING | DCCP_ACTION_FIN, 6277c657876SArnaldo Carvalho de Melo [DCCP_LISTEN] = DCCP_CLOSED, 6287c657876SArnaldo Carvalho de Melo [DCCP_RESPOND] = DCCP_CLOSED, 6297c657876SArnaldo Carvalho de Melo [DCCP_CLOSING] = DCCP_CLOSED, 6307c657876SArnaldo Carvalho de Melo [DCCP_TIME_WAIT] = DCCP_CLOSED, 6317c657876SArnaldo Carvalho de Melo [DCCP_CLOSED] = DCCP_CLOSED, 6327c657876SArnaldo Carvalho de Melo }; 6337c657876SArnaldo Carvalho de Melo 6347c657876SArnaldo Carvalho de Melo static int dccp_close_state(struct sock *sk) 6357c657876SArnaldo Carvalho de Melo { 6367c657876SArnaldo Carvalho de Melo const int next = dccp_new_state[sk->sk_state]; 6377c657876SArnaldo Carvalho de Melo const int ns = next & DCCP_STATE_MASK; 6387c657876SArnaldo Carvalho de Melo 6397c657876SArnaldo Carvalho de Melo if (ns != sk->sk_state) 6407c657876SArnaldo Carvalho de Melo dccp_set_state(sk, ns); 6417c657876SArnaldo Carvalho de Melo 6427c657876SArnaldo Carvalho de Melo return next & DCCP_ACTION_FIN; 6437c657876SArnaldo Carvalho de Melo } 6447c657876SArnaldo Carvalho de Melo 6457c657876SArnaldo Carvalho de Melo void dccp_close(struct sock *sk, long timeout) 6467c657876SArnaldo Carvalho de Melo { 6477c657876SArnaldo Carvalho de Melo struct sk_buff *skb; 6487c657876SArnaldo Carvalho de Melo 6497c657876SArnaldo Carvalho de Melo lock_sock(sk); 6507c657876SArnaldo Carvalho de Melo 6517c657876SArnaldo Carvalho de Melo sk->sk_shutdown = SHUTDOWN_MASK; 6527c657876SArnaldo Carvalho de Melo 6537c657876SArnaldo Carvalho de Melo if (sk->sk_state == DCCP_LISTEN) { 6547c657876SArnaldo Carvalho de Melo dccp_set_state(sk, DCCP_CLOSED); 6557c657876SArnaldo Carvalho de Melo 6567c657876SArnaldo Carvalho de Melo /* Special case. */ 6577c657876SArnaldo Carvalho de Melo inet_csk_listen_stop(sk); 6587c657876SArnaldo Carvalho de Melo 6597c657876SArnaldo Carvalho de Melo goto adjudge_to_death; 6607c657876SArnaldo Carvalho de Melo } 6617c657876SArnaldo Carvalho de Melo 6627c657876SArnaldo Carvalho de Melo /* 6637c657876SArnaldo Carvalho de Melo * We need to flush the recv. buffs. We do this only on the 6647c657876SArnaldo Carvalho de Melo * descriptor close, not protocol-sourced closes, because the 6657c657876SArnaldo Carvalho de Melo *reader process may not have drained the data yet! 6667c657876SArnaldo Carvalho de Melo */ 6677c657876SArnaldo Carvalho de Melo /* FIXME: check for unread data */ 6687c657876SArnaldo Carvalho de Melo while ((skb = __skb_dequeue(&sk->sk_receive_queue)) != NULL) { 6697c657876SArnaldo Carvalho de Melo __kfree_skb(skb); 6707c657876SArnaldo Carvalho de Melo } 6717c657876SArnaldo Carvalho de Melo 6727c657876SArnaldo Carvalho de Melo if (sock_flag(sk, SOCK_LINGER) && !sk->sk_lingertime) { 6737c657876SArnaldo Carvalho de Melo /* Check zero linger _after_ checking for unread data. */ 6747c657876SArnaldo Carvalho de Melo sk->sk_prot->disconnect(sk, 0); 6757c657876SArnaldo Carvalho de Melo } else if (dccp_close_state(sk)) { 6767ad07e7cSArnaldo Carvalho de Melo dccp_send_close(sk, 1); 6777c657876SArnaldo Carvalho de Melo } 6787c657876SArnaldo Carvalho de Melo 6797c657876SArnaldo Carvalho de Melo sk_stream_wait_close(sk, timeout); 6807c657876SArnaldo Carvalho de Melo 6817c657876SArnaldo Carvalho de Melo adjudge_to_death: 6827ad07e7cSArnaldo Carvalho de Melo /* 6837ad07e7cSArnaldo Carvalho de Melo * It is the last release_sock in its life. It will remove backlog. 6847ad07e7cSArnaldo Carvalho de Melo */ 6857c657876SArnaldo Carvalho de Melo release_sock(sk); 6867c657876SArnaldo Carvalho de Melo /* 6877c657876SArnaldo Carvalho de Melo * Now socket is owned by kernel and we acquire BH lock 6887c657876SArnaldo Carvalho de Melo * to finish close. No need to check for user refs. 6897c657876SArnaldo Carvalho de Melo */ 6907c657876SArnaldo Carvalho de Melo local_bh_disable(); 6917c657876SArnaldo Carvalho de Melo bh_lock_sock(sk); 6927c657876SArnaldo Carvalho de Melo BUG_TRAP(!sock_owned_by_user(sk)); 6937c657876SArnaldo Carvalho de Melo 6947c657876SArnaldo Carvalho de Melo sock_hold(sk); 6957c657876SArnaldo Carvalho de Melo sock_orphan(sk); 6967c657876SArnaldo Carvalho de Melo 6977ad07e7cSArnaldo Carvalho de Melo /* 6987ad07e7cSArnaldo Carvalho de Melo * The last release_sock may have processed the CLOSE or RESET 6997ad07e7cSArnaldo Carvalho de Melo * packet moving sock to CLOSED state, if not we have to fire 7007ad07e7cSArnaldo Carvalho de Melo * the CLOSE/CLOSEREQ retransmission timer, see "8.3. Termination" 7017ad07e7cSArnaldo Carvalho de Melo * in draft-ietf-dccp-spec-11. -acme 7027ad07e7cSArnaldo Carvalho de Melo */ 7037ad07e7cSArnaldo Carvalho de Melo if (sk->sk_state == DCCP_CLOSING) { 7047ad07e7cSArnaldo Carvalho de Melo /* FIXME: should start at 2 * RTT */ 7057ad07e7cSArnaldo Carvalho de Melo /* Timer for repeating the CLOSE/CLOSEREQ until an answer. */ 7067ad07e7cSArnaldo Carvalho de Melo inet_csk_reset_xmit_timer(sk, ICSK_TIME_RETRANS, 7077ad07e7cSArnaldo Carvalho de Melo inet_csk(sk)->icsk_rto, 7087ad07e7cSArnaldo Carvalho de Melo DCCP_RTO_MAX); 7097ad07e7cSArnaldo Carvalho de Melo #if 0 7107ad07e7cSArnaldo Carvalho de Melo /* Yeah, we should use sk->sk_prot->orphan_count, etc */ 7117c657876SArnaldo Carvalho de Melo dccp_set_state(sk, DCCP_CLOSED); 7127ad07e7cSArnaldo Carvalho de Melo #endif 7137ad07e7cSArnaldo Carvalho de Melo } 7147c657876SArnaldo Carvalho de Melo 7157ad07e7cSArnaldo Carvalho de Melo atomic_inc(sk->sk_prot->orphan_count); 7167c657876SArnaldo Carvalho de Melo if (sk->sk_state == DCCP_CLOSED) 7177c657876SArnaldo Carvalho de Melo inet_csk_destroy_sock(sk); 7187c657876SArnaldo Carvalho de Melo 7197c657876SArnaldo Carvalho de Melo /* Otherwise, socket is reprieved until protocol close. */ 7207c657876SArnaldo Carvalho de Melo 7217c657876SArnaldo Carvalho de Melo bh_unlock_sock(sk); 7227c657876SArnaldo Carvalho de Melo local_bh_enable(); 7237c657876SArnaldo Carvalho de Melo sock_put(sk); 7247c657876SArnaldo Carvalho de Melo } 7257c657876SArnaldo Carvalho de Melo 726f21e68caSArnaldo Carvalho de Melo EXPORT_SYMBOL_GPL(dccp_close); 727f21e68caSArnaldo Carvalho de Melo 7287c657876SArnaldo Carvalho de Melo void dccp_shutdown(struct sock *sk, int how) 7297c657876SArnaldo Carvalho de Melo { 7307c657876SArnaldo Carvalho de Melo dccp_pr_debug("entry\n"); 7317c657876SArnaldo Carvalho de Melo } 7327c657876SArnaldo Carvalho de Melo 733f21e68caSArnaldo Carvalho de Melo EXPORT_SYMBOL_GPL(dccp_shutdown); 734f21e68caSArnaldo Carvalho de Melo 73590ddc4f0SEric Dumazet static const struct proto_ops inet_dccp_ops = { 7367c657876SArnaldo Carvalho de Melo .family = PF_INET, 7377c657876SArnaldo Carvalho de Melo .owner = THIS_MODULE, 7387c657876SArnaldo Carvalho de Melo .release = inet_release, 7397c657876SArnaldo Carvalho de Melo .bind = inet_bind, 7407c657876SArnaldo Carvalho de Melo .connect = inet_stream_connect, 7417c657876SArnaldo Carvalho de Melo .socketpair = sock_no_socketpair, 7427c657876SArnaldo Carvalho de Melo .accept = inet_accept, 7437c657876SArnaldo Carvalho de Melo .getname = inet_getname, 744331968bdSArnaldo Carvalho de Melo /* FIXME: work on tcp_poll to rename it to inet_csk_poll */ 745331968bdSArnaldo Carvalho de Melo .poll = dccp_poll, 7467c657876SArnaldo Carvalho de Melo .ioctl = inet_ioctl, 7477690af3fSArnaldo Carvalho de Melo /* FIXME: work on inet_listen to rename it to sock_common_listen */ 7487690af3fSArnaldo Carvalho de Melo .listen = inet_dccp_listen, 7497c657876SArnaldo Carvalho de Melo .shutdown = inet_shutdown, 7507c657876SArnaldo Carvalho de Melo .setsockopt = sock_common_setsockopt, 7517c657876SArnaldo Carvalho de Melo .getsockopt = sock_common_getsockopt, 7527c657876SArnaldo Carvalho de Melo .sendmsg = inet_sendmsg, 7537c657876SArnaldo Carvalho de Melo .recvmsg = sock_common_recvmsg, 7547c657876SArnaldo Carvalho de Melo .mmap = sock_no_mmap, 7557c657876SArnaldo Carvalho de Melo .sendpage = sock_no_sendpage, 7567c657876SArnaldo Carvalho de Melo }; 7577c657876SArnaldo Carvalho de Melo 7587c657876SArnaldo Carvalho de Melo extern struct net_proto_family inet_family_ops; 7597c657876SArnaldo Carvalho de Melo 7607c657876SArnaldo Carvalho de Melo static struct inet_protosw dccp_v4_protosw = { 7617c657876SArnaldo Carvalho de Melo .type = SOCK_DCCP, 7627c657876SArnaldo Carvalho de Melo .protocol = IPPROTO_DCCP, 76334ca6860SArnaldo Carvalho de Melo .prot = &dccp_prot, 7647c657876SArnaldo Carvalho de Melo .ops = &inet_dccp_ops, 7657c657876SArnaldo Carvalho de Melo .capability = -1, 7667c657876SArnaldo Carvalho de Melo .no_check = 0, 767d83d8461SArnaldo Carvalho de Melo .flags = INET_PROTOSW_ICSK, 7687c657876SArnaldo Carvalho de Melo }; 7697c657876SArnaldo Carvalho de Melo 7707c657876SArnaldo Carvalho de Melo /* 7717c657876SArnaldo Carvalho de Melo * This is the global socket data structure used for responding to 7727c657876SArnaldo Carvalho de Melo * the Out-of-the-blue (OOTB) packets. A control sock will be created 7737c657876SArnaldo Carvalho de Melo * for this socket at the initialization time. 7747c657876SArnaldo Carvalho de Melo */ 7757c657876SArnaldo Carvalho de Melo struct socket *dccp_ctl_socket; 7767c657876SArnaldo Carvalho de Melo 7777c657876SArnaldo Carvalho de Melo static char dccp_ctl_socket_err_msg[] __initdata = 7787c657876SArnaldo Carvalho de Melo KERN_ERR "DCCP: Failed to create the control socket.\n"; 7797c657876SArnaldo Carvalho de Melo 7807c657876SArnaldo Carvalho de Melo static int __init dccp_ctl_sock_init(void) 7817c657876SArnaldo Carvalho de Melo { 7827c657876SArnaldo Carvalho de Melo int rc = sock_create_kern(PF_INET, SOCK_DCCP, IPPROTO_DCCP, 7837c657876SArnaldo Carvalho de Melo &dccp_ctl_socket); 7847c657876SArnaldo Carvalho de Melo if (rc < 0) 7857c657876SArnaldo Carvalho de Melo printk(dccp_ctl_socket_err_msg); 7867c657876SArnaldo Carvalho de Melo else { 7877c657876SArnaldo Carvalho de Melo dccp_ctl_socket->sk->sk_allocation = GFP_ATOMIC; 7887c657876SArnaldo Carvalho de Melo inet_sk(dccp_ctl_socket->sk)->uc_ttl = -1; 7897c657876SArnaldo Carvalho de Melo 7907c657876SArnaldo Carvalho de Melo /* Unhash it so that IP input processing does not even 7917c657876SArnaldo Carvalho de Melo * see it, we do not wish this socket to see incoming 7927c657876SArnaldo Carvalho de Melo * packets. 7937c657876SArnaldo Carvalho de Melo */ 7947c657876SArnaldo Carvalho de Melo dccp_ctl_socket->sk->sk_prot->unhash(dccp_ctl_socket->sk); 7957c657876SArnaldo Carvalho de Melo } 7967c657876SArnaldo Carvalho de Melo 7977c657876SArnaldo Carvalho de Melo return rc; 7987c657876SArnaldo Carvalho de Melo } 7997c657876SArnaldo Carvalho de Melo 800725ba8eeSArnaldo Carvalho de Melo #ifdef CONFIG_IP_DCCP_UNLOAD_HACK 801725ba8eeSArnaldo Carvalho de Melo void dccp_ctl_sock_exit(void) 8027c657876SArnaldo Carvalho de Melo { 8035480855bSArnaldo Carvalho de Melo if (dccp_ctl_socket != NULL) { 8047c657876SArnaldo Carvalho de Melo sock_release(dccp_ctl_socket); 8055480855bSArnaldo Carvalho de Melo dccp_ctl_socket = NULL; 8065480855bSArnaldo Carvalho de Melo } 8077c657876SArnaldo Carvalho de Melo } 8087c657876SArnaldo Carvalho de Melo 809725ba8eeSArnaldo Carvalho de Melo EXPORT_SYMBOL_GPL(dccp_ctl_sock_exit); 810725ba8eeSArnaldo Carvalho de Melo #endif 811725ba8eeSArnaldo Carvalho de Melo 8127c657876SArnaldo Carvalho de Melo static int __init init_dccp_v4_mibs(void) 8137c657876SArnaldo Carvalho de Melo { 8147c657876SArnaldo Carvalho de Melo int rc = -ENOMEM; 8157c657876SArnaldo Carvalho de Melo 8167c657876SArnaldo Carvalho de Melo dccp_statistics[0] = alloc_percpu(struct dccp_mib); 8177c657876SArnaldo Carvalho de Melo if (dccp_statistics[0] == NULL) 8187c657876SArnaldo Carvalho de Melo goto out; 8197c657876SArnaldo Carvalho de Melo 8207c657876SArnaldo Carvalho de Melo dccp_statistics[1] = alloc_percpu(struct dccp_mib); 8217c657876SArnaldo Carvalho de Melo if (dccp_statistics[1] == NULL) 8227c657876SArnaldo Carvalho de Melo goto out_free_one; 8237c657876SArnaldo Carvalho de Melo 8247c657876SArnaldo Carvalho de Melo rc = 0; 8257c657876SArnaldo Carvalho de Melo out: 8267c657876SArnaldo Carvalho de Melo return rc; 8277c657876SArnaldo Carvalho de Melo out_free_one: 8287c657876SArnaldo Carvalho de Melo free_percpu(dccp_statistics[0]); 8297c657876SArnaldo Carvalho de Melo dccp_statistics[0] = NULL; 8307c657876SArnaldo Carvalho de Melo goto out; 8317c657876SArnaldo Carvalho de Melo 8327c657876SArnaldo Carvalho de Melo } 8337c657876SArnaldo Carvalho de Melo 8347c657876SArnaldo Carvalho de Melo static int thash_entries; 8357c657876SArnaldo Carvalho de Melo module_param(thash_entries, int, 0444); 8367c657876SArnaldo Carvalho de Melo MODULE_PARM_DESC(thash_entries, "Number of ehash buckets"); 8377c657876SArnaldo Carvalho de Melo 838a1d3a355SArnaldo Carvalho de Melo #ifdef CONFIG_IP_DCCP_DEBUG 8397c657876SArnaldo Carvalho de Melo int dccp_debug; 8407c657876SArnaldo Carvalho de Melo module_param(dccp_debug, int, 0444); 8417c657876SArnaldo Carvalho de Melo MODULE_PARM_DESC(dccp_debug, "Enable debug messages"); 842f21e68caSArnaldo Carvalho de Melo 843f21e68caSArnaldo Carvalho de Melo EXPORT_SYMBOL_GPL(dccp_debug); 844a1d3a355SArnaldo Carvalho de Melo #endif 8457c657876SArnaldo Carvalho de Melo 8467c657876SArnaldo Carvalho de Melo static int __init dccp_init(void) 8477c657876SArnaldo Carvalho de Melo { 8487c657876SArnaldo Carvalho de Melo unsigned long goal; 8497c657876SArnaldo Carvalho de Melo int ehash_order, bhash_order, i; 85034ca6860SArnaldo Carvalho de Melo int rc = proto_register(&dccp_prot, 1); 8517c657876SArnaldo Carvalho de Melo 8527c657876SArnaldo Carvalho de Melo if (rc) 8537c657876SArnaldo Carvalho de Melo goto out; 8547c657876SArnaldo Carvalho de Melo 855fa23e2ecSArnaldo Carvalho de Melo rc = -ENOBUFS; 8567690af3fSArnaldo Carvalho de Melo dccp_hashinfo.bind_bucket_cachep = 8577690af3fSArnaldo Carvalho de Melo kmem_cache_create("dccp_bind_bucket", 8587690af3fSArnaldo Carvalho de Melo sizeof(struct inet_bind_bucket), 0, 8597690af3fSArnaldo Carvalho de Melo SLAB_HWCACHE_ALIGN, NULL, NULL); 8607c657876SArnaldo Carvalho de Melo if (!dccp_hashinfo.bind_bucket_cachep) 8617c657876SArnaldo Carvalho de Melo goto out_proto_unregister; 8627c657876SArnaldo Carvalho de Melo 8637c657876SArnaldo Carvalho de Melo /* 8647c657876SArnaldo Carvalho de Melo * Size and allocate the main established and bind bucket 8657c657876SArnaldo Carvalho de Melo * hash tables. 8667c657876SArnaldo Carvalho de Melo * 8677c657876SArnaldo Carvalho de Melo * The methodology is similar to that of the buffer cache. 8687c657876SArnaldo Carvalho de Melo */ 8697c657876SArnaldo Carvalho de Melo if (num_physpages >= (128 * 1024)) 8707c657876SArnaldo Carvalho de Melo goal = num_physpages >> (21 - PAGE_SHIFT); 8717c657876SArnaldo Carvalho de Melo else 8727c657876SArnaldo Carvalho de Melo goal = num_physpages >> (23 - PAGE_SHIFT); 8737c657876SArnaldo Carvalho de Melo 8747c657876SArnaldo Carvalho de Melo if (thash_entries) 8757690af3fSArnaldo Carvalho de Melo goal = (thash_entries * 8767690af3fSArnaldo Carvalho de Melo sizeof(struct inet_ehash_bucket)) >> PAGE_SHIFT; 8777c657876SArnaldo Carvalho de Melo for (ehash_order = 0; (1UL << ehash_order) < goal; ehash_order++) 8787c657876SArnaldo Carvalho de Melo ; 8797c657876SArnaldo Carvalho de Melo do { 8807c657876SArnaldo Carvalho de Melo dccp_hashinfo.ehash_size = (1UL << ehash_order) * PAGE_SIZE / 8817c657876SArnaldo Carvalho de Melo sizeof(struct inet_ehash_bucket); 8827c657876SArnaldo Carvalho de Melo dccp_hashinfo.ehash_size >>= 1; 8837690af3fSArnaldo Carvalho de Melo while (dccp_hashinfo.ehash_size & 8847690af3fSArnaldo Carvalho de Melo (dccp_hashinfo.ehash_size - 1)) 8857c657876SArnaldo Carvalho de Melo dccp_hashinfo.ehash_size--; 8867c657876SArnaldo Carvalho de Melo dccp_hashinfo.ehash = (struct inet_ehash_bucket *) 8877c657876SArnaldo Carvalho de Melo __get_free_pages(GFP_ATOMIC, ehash_order); 8887c657876SArnaldo Carvalho de Melo } while (!dccp_hashinfo.ehash && --ehash_order > 0); 8897c657876SArnaldo Carvalho de Melo 8907c657876SArnaldo Carvalho de Melo if (!dccp_hashinfo.ehash) { 8917c657876SArnaldo Carvalho de Melo printk(KERN_CRIT "Failed to allocate DCCP " 8927c657876SArnaldo Carvalho de Melo "established hash table\n"); 8937c657876SArnaldo Carvalho de Melo goto out_free_bind_bucket_cachep; 8947c657876SArnaldo Carvalho de Melo } 8957c657876SArnaldo Carvalho de Melo 8967c657876SArnaldo Carvalho de Melo for (i = 0; i < (dccp_hashinfo.ehash_size << 1); i++) { 8977c657876SArnaldo Carvalho de Melo rwlock_init(&dccp_hashinfo.ehash[i].lock); 8987c657876SArnaldo Carvalho de Melo INIT_HLIST_HEAD(&dccp_hashinfo.ehash[i].chain); 8997c657876SArnaldo Carvalho de Melo } 9007c657876SArnaldo Carvalho de Melo 9017c657876SArnaldo Carvalho de Melo bhash_order = ehash_order; 9027c657876SArnaldo Carvalho de Melo 9037c657876SArnaldo Carvalho de Melo do { 9047c657876SArnaldo Carvalho de Melo dccp_hashinfo.bhash_size = (1UL << bhash_order) * PAGE_SIZE / 9057c657876SArnaldo Carvalho de Melo sizeof(struct inet_bind_hashbucket); 9067690af3fSArnaldo Carvalho de Melo if ((dccp_hashinfo.bhash_size > (64 * 1024)) && 9077690af3fSArnaldo Carvalho de Melo bhash_order > 0) 9087c657876SArnaldo Carvalho de Melo continue; 9097c657876SArnaldo Carvalho de Melo dccp_hashinfo.bhash = (struct inet_bind_hashbucket *) 9107c657876SArnaldo Carvalho de Melo __get_free_pages(GFP_ATOMIC, bhash_order); 9117c657876SArnaldo Carvalho de Melo } while (!dccp_hashinfo.bhash && --bhash_order >= 0); 9127c657876SArnaldo Carvalho de Melo 9137c657876SArnaldo Carvalho de Melo if (!dccp_hashinfo.bhash) { 9147c657876SArnaldo Carvalho de Melo printk(KERN_CRIT "Failed to allocate DCCP bind hash table\n"); 9157c657876SArnaldo Carvalho de Melo goto out_free_dccp_ehash; 9167c657876SArnaldo Carvalho de Melo } 9177c657876SArnaldo Carvalho de Melo 9187c657876SArnaldo Carvalho de Melo for (i = 0; i < dccp_hashinfo.bhash_size; i++) { 9197c657876SArnaldo Carvalho de Melo spin_lock_init(&dccp_hashinfo.bhash[i].lock); 9207c657876SArnaldo Carvalho de Melo INIT_HLIST_HEAD(&dccp_hashinfo.bhash[i].chain); 9217c657876SArnaldo Carvalho de Melo } 9227c657876SArnaldo Carvalho de Melo 923fa23e2ecSArnaldo Carvalho de Melo rc = init_dccp_v4_mibs(); 924fa23e2ecSArnaldo Carvalho de Melo if (rc) 9257c657876SArnaldo Carvalho de Melo goto out_free_dccp_bhash; 9267c657876SArnaldo Carvalho de Melo 9277c657876SArnaldo Carvalho de Melo rc = -EAGAIN; 9287c657876SArnaldo Carvalho de Melo if (inet_add_protocol(&dccp_protocol, IPPROTO_DCCP)) 9297c657876SArnaldo Carvalho de Melo goto out_free_dccp_v4_mibs; 9307c657876SArnaldo Carvalho de Melo 9317c657876SArnaldo Carvalho de Melo inet_register_protosw(&dccp_v4_protosw); 9327c657876SArnaldo Carvalho de Melo 9339b07ef5dSArnaldo Carvalho de Melo rc = dccp_ackvec_init(); 9347c657876SArnaldo Carvalho de Melo if (rc) 9357c657876SArnaldo Carvalho de Melo goto out_unregister_protosw; 9369b07ef5dSArnaldo Carvalho de Melo 9379b07ef5dSArnaldo Carvalho de Melo rc = dccp_ctl_sock_init(); 9389b07ef5dSArnaldo Carvalho de Melo if (rc) 9399b07ef5dSArnaldo Carvalho de Melo goto out_ackvec_exit; 9407c657876SArnaldo Carvalho de Melo out: 9417c657876SArnaldo Carvalho de Melo return rc; 9429b07ef5dSArnaldo Carvalho de Melo out_ackvec_exit: 9439b07ef5dSArnaldo Carvalho de Melo dccp_ackvec_exit(); 9447c657876SArnaldo Carvalho de Melo out_unregister_protosw: 9457c657876SArnaldo Carvalho de Melo inet_unregister_protosw(&dccp_v4_protosw); 9467c657876SArnaldo Carvalho de Melo inet_del_protocol(&dccp_protocol, IPPROTO_DCCP); 9477c657876SArnaldo Carvalho de Melo out_free_dccp_v4_mibs: 9487c657876SArnaldo Carvalho de Melo free_percpu(dccp_statistics[0]); 9497c657876SArnaldo Carvalho de Melo free_percpu(dccp_statistics[1]); 9507c657876SArnaldo Carvalho de Melo dccp_statistics[0] = dccp_statistics[1] = NULL; 9517c657876SArnaldo Carvalho de Melo out_free_dccp_bhash: 9527c657876SArnaldo Carvalho de Melo free_pages((unsigned long)dccp_hashinfo.bhash, bhash_order); 9537c657876SArnaldo Carvalho de Melo dccp_hashinfo.bhash = NULL; 9547c657876SArnaldo Carvalho de Melo out_free_dccp_ehash: 9557c657876SArnaldo Carvalho de Melo free_pages((unsigned long)dccp_hashinfo.ehash, ehash_order); 9567c657876SArnaldo Carvalho de Melo dccp_hashinfo.ehash = NULL; 9577c657876SArnaldo Carvalho de Melo out_free_bind_bucket_cachep: 9587c657876SArnaldo Carvalho de Melo kmem_cache_destroy(dccp_hashinfo.bind_bucket_cachep); 9597c657876SArnaldo Carvalho de Melo dccp_hashinfo.bind_bucket_cachep = NULL; 9607c657876SArnaldo Carvalho de Melo out_proto_unregister: 96134ca6860SArnaldo Carvalho de Melo proto_unregister(&dccp_prot); 9627c657876SArnaldo Carvalho de Melo goto out; 9637c657876SArnaldo Carvalho de Melo } 9647c657876SArnaldo Carvalho de Melo 9657c657876SArnaldo Carvalho de Melo static const char dccp_del_proto_err_msg[] __exitdata = 9667c657876SArnaldo Carvalho de Melo KERN_ERR "can't remove dccp net_protocol\n"; 9677c657876SArnaldo Carvalho de Melo 9687c657876SArnaldo Carvalho de Melo static void __exit dccp_fini(void) 9697c657876SArnaldo Carvalho de Melo { 9707c657876SArnaldo Carvalho de Melo inet_unregister_protosw(&dccp_v4_protosw); 9717c657876SArnaldo Carvalho de Melo 9727c657876SArnaldo Carvalho de Melo if (inet_del_protocol(&dccp_protocol, IPPROTO_DCCP) < 0) 9737c657876SArnaldo Carvalho de Melo printk(dccp_del_proto_err_msg); 9747c657876SArnaldo Carvalho de Melo 975725ba8eeSArnaldo Carvalho de Melo free_percpu(dccp_statistics[0]); 976725ba8eeSArnaldo Carvalho de Melo free_percpu(dccp_statistics[1]); 977725ba8eeSArnaldo Carvalho de Melo free_pages((unsigned long)dccp_hashinfo.bhash, 978725ba8eeSArnaldo Carvalho de Melo get_order(dccp_hashinfo.bhash_size * 979725ba8eeSArnaldo Carvalho de Melo sizeof(struct inet_bind_hashbucket))); 980725ba8eeSArnaldo Carvalho de Melo free_pages((unsigned long)dccp_hashinfo.ehash, 981725ba8eeSArnaldo Carvalho de Melo get_order(dccp_hashinfo.ehash_size * 982725ba8eeSArnaldo Carvalho de Melo sizeof(struct inet_ehash_bucket))); 9837c657876SArnaldo Carvalho de Melo kmem_cache_destroy(dccp_hashinfo.bind_bucket_cachep); 98434ca6860SArnaldo Carvalho de Melo proto_unregister(&dccp_prot); 9859b07ef5dSArnaldo Carvalho de Melo dccp_ackvec_exit(); 9867c657876SArnaldo Carvalho de Melo } 9877c657876SArnaldo Carvalho de Melo 9887c657876SArnaldo Carvalho de Melo module_init(dccp_init); 9897c657876SArnaldo Carvalho de Melo module_exit(dccp_fini); 9907c657876SArnaldo Carvalho de Melo 991bb97d31fSArnaldo Carvalho de Melo /* 992bb97d31fSArnaldo Carvalho de Melo * __stringify doesn't likes enums, so use SOCK_DCCP (6) and IPPROTO_DCCP (33) 993bb97d31fSArnaldo Carvalho de Melo * values directly, Also cover the case where the protocol is not specified, 994bb97d31fSArnaldo Carvalho de Melo * i.e. net-pf-PF_INET-proto-0-type-SOCK_DCCP 995bb97d31fSArnaldo Carvalho de Melo */ 996bb97d31fSArnaldo Carvalho de Melo MODULE_ALIAS("net-pf-" __stringify(PF_INET) "-proto-33-type-6"); 997bb97d31fSArnaldo Carvalho de Melo MODULE_ALIAS("net-pf-" __stringify(PF_INET) "-proto-0-type-6"); 9987c657876SArnaldo Carvalho de Melo MODULE_LICENSE("GPL"); 9997c657876SArnaldo Carvalho de Melo MODULE_AUTHOR("Arnaldo Carvalho de Melo <acme@conectiva.com.br>"); 10007c657876SArnaldo Carvalho de Melo MODULE_DESCRIPTION("DCCP - Datagram Congestion Controlled Protocol"); 1001