147505b8bSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
260c778b2SVlad Yasevich /* SCTP kernel implementation
31da177e4SLinus Torvalds * (C) Copyright IBM Corp. 2001, 2004
41da177e4SLinus Torvalds * Copyright (c) 1999-2000 Cisco, Inc.
51da177e4SLinus Torvalds * Copyright (c) 1999-2001 Motorola, Inc.
61da177e4SLinus Torvalds * Copyright (c) 2001 Intel Corp.
71da177e4SLinus Torvalds * Copyright (c) 2001 Nokia, Inc.
81da177e4SLinus Torvalds * Copyright (c) 2001 La Monte H.P. Yarroll
91da177e4SLinus Torvalds *
1060c778b2SVlad Yasevich * This file is part of the SCTP kernel implementation
111da177e4SLinus Torvalds *
121da177e4SLinus Torvalds * Initialization/cleanup for SCTP protocol support.
131da177e4SLinus Torvalds *
141da177e4SLinus Torvalds * Please send any bug reports or fixes you make to the
151da177e4SLinus Torvalds * email address(es):
1691705c61SDaniel Borkmann * lksctp developers <linux-sctp@vger.kernel.org>
171da177e4SLinus Torvalds *
181da177e4SLinus Torvalds * Written or modified by:
191da177e4SLinus Torvalds * La Monte H.P. Yarroll <piggy@acm.org>
201da177e4SLinus Torvalds * Karl Knutson <karl@athena.chicago.il.us>
211da177e4SLinus Torvalds * Jon Grimm <jgrimm@us.ibm.com>
221da177e4SLinus Torvalds * Sridhar Samudrala <sri@us.ibm.com>
231da177e4SLinus Torvalds * Daisy Chang <daisyc@us.ibm.com>
241da177e4SLinus Torvalds * Ardelle Fan <ardelle.fan@intel.com>
251da177e4SLinus Torvalds */
261da177e4SLinus Torvalds
27145ce502SJoe Perches #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
28145ce502SJoe Perches
291da177e4SLinus Torvalds #include <linux/module.h>
301da177e4SLinus Torvalds #include <linux/init.h>
311da177e4SLinus Torvalds #include <linux/netdevice.h>
321da177e4SLinus Torvalds #include <linux/inetdevice.h>
331da177e4SLinus Torvalds #include <linux/seq_file.h>
3457c8a661SMike Rapoport #include <linux/memblock.h>
35845525a6SVlad Yasevich #include <linux/highmem.h>
365a0e3ad6STejun Heo #include <linux/slab.h>
37457c4cbcSEric W. Biederman #include <net/net_namespace.h>
381da177e4SLinus Torvalds #include <net/protocol.h>
391da177e4SLinus Torvalds #include <net/ip.h>
401da177e4SLinus Torvalds #include <net/ipv6.h>
4114c85021SArnaldo Carvalho de Melo #include <net/route.h>
421da177e4SLinus Torvalds #include <net/sctp/sctp.h>
431da177e4SLinus Torvalds #include <net/addrconf.h>
441da177e4SLinus Torvalds #include <net/inet_common.h>
451da177e4SLinus Torvalds #include <net/inet_ecn.h>
46965ae444SXin Long #include <net/udp_tunnel.h>
471da177e4SLinus Torvalds
48d9749fb5SNeil Horman #define MAX_SCTP_PORT_HASH_ENTRIES (64 * 1024)
49d9749fb5SNeil Horman
501da177e4SLinus Torvalds /* Global data structures. */
514cbf1caeSBrian Haley struct sctp_globals sctp_globals __read_mostly;
521da177e4SLinus Torvalds
531da177e4SLinus Torvalds struct idr sctp_assocs_id;
541da177e4SLinus Torvalds DEFINE_SPINLOCK(sctp_assocs_id_lock);
551da177e4SLinus Torvalds
561da177e4SLinus Torvalds static struct sctp_pf *sctp_pf_inet6_specific;
571da177e4SLinus Torvalds static struct sctp_pf *sctp_pf_inet_specific;
581da177e4SLinus Torvalds static struct sctp_af *sctp_af_v4_specific;
591da177e4SLinus Torvalds static struct sctp_af *sctp_af_v6_specific;
601da177e4SLinus Torvalds
61e18b890bSChristoph Lameter struct kmem_cache *sctp_chunk_cachep __read_mostly;
62e18b890bSChristoph Lameter struct kmem_cache *sctp_bucket_cachep __read_mostly;
631da177e4SLinus Torvalds
648d987e5cSEric Dumazet long sysctl_sctp_mem[3];
65007e3936SVlad Yasevich int sysctl_sctp_rmem[3];
66007e3936SVlad Yasevich int sysctl_sctp_wmem[3];
674d93df0aSNeil Horman
681da177e4SLinus Torvalds /* Private helper to extract ipv4 address and stash them in
691da177e4SLinus Torvalds * the protocol structure.
701da177e4SLinus Torvalds */
sctp_v4_copy_addrlist(struct list_head * addrlist,struct net_device * dev)711da177e4SLinus Torvalds static void sctp_v4_copy_addrlist(struct list_head *addrlist,
721da177e4SLinus Torvalds struct net_device *dev)
731da177e4SLinus Torvalds {
741da177e4SLinus Torvalds struct in_device *in_dev;
751da177e4SLinus Torvalds struct in_ifaddr *ifa;
761da177e4SLinus Torvalds struct sctp_sockaddr_entry *addr;
771da177e4SLinus Torvalds
781da177e4SLinus Torvalds rcu_read_lock();
79e5ed6399SHerbert Xu if ((in_dev = __in_dev_get_rcu(dev)) == NULL) {
801da177e4SLinus Torvalds rcu_read_unlock();
811da177e4SLinus Torvalds return;
821da177e4SLinus Torvalds }
831da177e4SLinus Torvalds
84cd5a411dSFlorian Westphal in_dev_for_each_ifa_rcu(ifa, in_dev) {
851da177e4SLinus Torvalds /* Add the address to the local list. */
86939cfa75SDaniel Borkmann addr = kzalloc(sizeof(*addr), GFP_ATOMIC);
871da177e4SLinus Torvalds if (addr) {
882a6fd78aSAl Viro addr->a.v4.sin_family = AF_INET;
892a6fd78aSAl Viro addr->a.v4.sin_addr.s_addr = ifa->ifa_local;
9029303547SVlad Yasevich addr->valid = 1;
9129303547SVlad Yasevich INIT_LIST_HEAD(&addr->list);
921da177e4SLinus Torvalds list_add_tail(&addr->list, addrlist);
931da177e4SLinus Torvalds }
941da177e4SLinus Torvalds }
951da177e4SLinus Torvalds
961da177e4SLinus Torvalds rcu_read_unlock();
971da177e4SLinus Torvalds }
981da177e4SLinus Torvalds
991da177e4SLinus Torvalds /* Extract our IP addresses from the system and stash them in the
1001da177e4SLinus Torvalds * protocol structure.
1011da177e4SLinus Torvalds */
sctp_get_local_addr_list(struct net * net)1024db67e80SEric W. Biederman static void sctp_get_local_addr_list(struct net *net)
1031da177e4SLinus Torvalds {
1041da177e4SLinus Torvalds struct net_device *dev;
1051da177e4SLinus Torvalds struct list_head *pos;
1061da177e4SLinus Torvalds struct sctp_af *af;
1071da177e4SLinus Torvalds
108c6d14c84SEric Dumazet rcu_read_lock();
1094db67e80SEric W. Biederman for_each_netdev_rcu(net, dev) {
1102c0740e4SDave Jones list_for_each(pos, &sctp_address_families) {
1111da177e4SLinus Torvalds af = list_entry(pos, struct sctp_af, list);
1124db67e80SEric W. Biederman af->copy_addrlist(&net->sctp.local_addr_list, dev);
1131da177e4SLinus Torvalds }
1141da177e4SLinus Torvalds }
115c6d14c84SEric Dumazet rcu_read_unlock();
1161da177e4SLinus Torvalds }
1171da177e4SLinus Torvalds
1181da177e4SLinus Torvalds /* Free the existing local addresses. */
sctp_free_local_addr_list(struct net * net)1194db67e80SEric W. Biederman static void sctp_free_local_addr_list(struct net *net)
1201da177e4SLinus Torvalds {
1211da177e4SLinus Torvalds struct sctp_sockaddr_entry *addr;
1221da177e4SLinus Torvalds struct list_head *pos, *temp;
1231da177e4SLinus Torvalds
1244db67e80SEric W. Biederman list_for_each_safe(pos, temp, &net->sctp.local_addr_list) {
1251da177e4SLinus Torvalds addr = list_entry(pos, struct sctp_sockaddr_entry, list);
1261da177e4SLinus Torvalds list_del(pos);
1271da177e4SLinus Torvalds kfree(addr);
1281da177e4SLinus Torvalds }
1291da177e4SLinus Torvalds }
1301da177e4SLinus Torvalds
1311da177e4SLinus Torvalds /* Copy the local addresses which are valid for 'scope' into 'bp'. */
sctp_copy_local_addr_list(struct net * net,struct sctp_bind_addr * bp,enum sctp_scope scope,gfp_t gfp,int copy_flags)1324db67e80SEric W. Biederman int sctp_copy_local_addr_list(struct net *net, struct sctp_bind_addr *bp,
1331c662018SXin Long enum sctp_scope scope, gfp_t gfp, int copy_flags)
1341da177e4SLinus Torvalds {
1351da177e4SLinus Torvalds struct sctp_sockaddr_entry *addr;
1362e3ce5bcSXin Long union sctp_addr laddr;
1371da177e4SLinus Torvalds int error = 0;
1381da177e4SLinus Torvalds
13929303547SVlad Yasevich rcu_read_lock();
1404db67e80SEric W. Biederman list_for_each_entry_rcu(addr, &net->sctp.local_addr_list, list) {
14129303547SVlad Yasevich if (!addr->valid)
14229303547SVlad Yasevich continue;
143165f2cf6SXin Long if (!sctp_in_scope(net, &addr->a, scope))
144165f2cf6SXin Long continue;
145165f2cf6SXin Long
1461da177e4SLinus Torvalds /* Now that the address is in scope, check to see if
1471da177e4SLinus Torvalds * the address type is really supported by the local
1481da177e4SLinus Torvalds * sock as well as the remote peer.
1491da177e4SLinus Torvalds */
150165f2cf6SXin Long if (addr->a.sa.sa_family == AF_INET &&
151471e39dfSMarcelo Ricardo Leitner (!(copy_flags & SCTP_ADDR4_ALLOWED) ||
152471e39dfSMarcelo Ricardo Leitner !(copy_flags & SCTP_ADDR4_PEERSUPP)))
153165f2cf6SXin Long continue;
154165f2cf6SXin Long if (addr->a.sa.sa_family == AF_INET6 &&
155165f2cf6SXin Long (!(copy_flags & SCTP_ADDR6_ALLOWED) ||
156165f2cf6SXin Long !(copy_flags & SCTP_ADDR6_PEERSUPP)))
157165f2cf6SXin Long continue;
158165f2cf6SXin Long
1592e3ce5bcSXin Long laddr = addr->a;
1602e3ce5bcSXin Long /* also works for setting ipv6 address port */
1612e3ce5bcSXin Long laddr.v4.sin_port = htons(bp->port);
1622e3ce5bcSXin Long if (sctp_bind_addr_state(bp, &laddr) != -1)
163b8607805SXin Long continue;
164b8607805SXin Long
165165f2cf6SXin Long error = sctp_add_bind_addr(bp, &addr->a, sizeof(addr->a),
166f57d96b2SVlad Yasevich SCTP_ADDR_SRC, GFP_ATOMIC);
1671da177e4SLinus Torvalds if (error)
168165f2cf6SXin Long break;
1691da177e4SLinus Torvalds }
1701da177e4SLinus Torvalds
17129303547SVlad Yasevich rcu_read_unlock();
1721da177e4SLinus Torvalds return error;
1731da177e4SLinus Torvalds }
1741da177e4SLinus Torvalds
175b7e10c25SRichard Haines /* Copy over any ip options */
sctp_v4_copy_ip_options(struct sock * sk,struct sock * newsk)176b7e10c25SRichard Haines static void sctp_v4_copy_ip_options(struct sock *sk, struct sock *newsk)
177b7e10c25SRichard Haines {
178b7e10c25SRichard Haines struct inet_sock *newinet, *inet = inet_sk(sk);
179b7e10c25SRichard Haines struct ip_options_rcu *inet_opt, *newopt = NULL;
180b7e10c25SRichard Haines
181b7e10c25SRichard Haines newinet = inet_sk(newsk);
182b7e10c25SRichard Haines
183b7e10c25SRichard Haines rcu_read_lock();
184b7e10c25SRichard Haines inet_opt = rcu_dereference(inet->inet_opt);
185b7e10c25SRichard Haines if (inet_opt) {
186b7e10c25SRichard Haines newopt = sock_kmalloc(newsk, sizeof(*inet_opt) +
187b7e10c25SRichard Haines inet_opt->opt.optlen, GFP_ATOMIC);
188b7e10c25SRichard Haines if (newopt)
189b7e10c25SRichard Haines memcpy(newopt, inet_opt, sizeof(*inet_opt) +
190b7e10c25SRichard Haines inet_opt->opt.optlen);
191b7e10c25SRichard Haines else
192b7e10c25SRichard Haines pr_err("%s: Failed to copy ip options\n", __func__);
193b7e10c25SRichard Haines }
194b7e10c25SRichard Haines RCU_INIT_POINTER(newinet->inet_opt, newopt);
195b7e10c25SRichard Haines rcu_read_unlock();
196b7e10c25SRichard Haines }
197b7e10c25SRichard Haines
198b7e10c25SRichard Haines /* Account for the IP options */
sctp_v4_ip_options_len(struct sock * sk)199b7e10c25SRichard Haines static int sctp_v4_ip_options_len(struct sock *sk)
200b7e10c25SRichard Haines {
201b7e10c25SRichard Haines struct inet_sock *inet = inet_sk(sk);
202b7e10c25SRichard Haines struct ip_options_rcu *inet_opt;
203b7e10c25SRichard Haines int len = 0;
204b7e10c25SRichard Haines
205b7e10c25SRichard Haines rcu_read_lock();
206b7e10c25SRichard Haines inet_opt = rcu_dereference(inet->inet_opt);
207b7e10c25SRichard Haines if (inet_opt)
208b7e10c25SRichard Haines len = inet_opt->opt.optlen;
209b7e10c25SRichard Haines
210b7e10c25SRichard Haines rcu_read_unlock();
211b7e10c25SRichard Haines return len;
212b7e10c25SRichard Haines }
213b7e10c25SRichard Haines
2141da177e4SLinus Torvalds /* Initialize a sctp_addr from in incoming skb. */
sctp_v4_from_skb(union sctp_addr * addr,struct sk_buff * skb,int is_saddr)2151da177e4SLinus Torvalds static void sctp_v4_from_skb(union sctp_addr *addr, struct sk_buff *skb,
2161da177e4SLinus Torvalds int is_saddr)
2171da177e4SLinus Torvalds {
2180630c56eSMarcelo Ricardo Leitner /* Always called on head skb, so this is safe */
2190630c56eSMarcelo Ricardo Leitner struct sctphdr *sh = sctp_hdr(skb);
2200630c56eSMarcelo Ricardo Leitner struct sockaddr_in *sa = &addr->v4;
2211da177e4SLinus Torvalds
2221da177e4SLinus Torvalds addr->v4.sin_family = AF_INET;
2231da177e4SLinus Torvalds
2241da177e4SLinus Torvalds if (is_saddr) {
2250630c56eSMarcelo Ricardo Leitner sa->sin_port = sh->source;
2260630c56eSMarcelo Ricardo Leitner sa->sin_addr.s_addr = ip_hdr(skb)->saddr;
2271da177e4SLinus Torvalds } else {
2280630c56eSMarcelo Ricardo Leitner sa->sin_port = sh->dest;
2290630c56eSMarcelo Ricardo Leitner sa->sin_addr.s_addr = ip_hdr(skb)->daddr;
2301da177e4SLinus Torvalds }
231b6f3320bSXin Long memset(sa->sin_zero, 0, sizeof(sa->sin_zero));
2321da177e4SLinus Torvalds }
2331da177e4SLinus Torvalds
2341da177e4SLinus Torvalds /* Initialize an sctp_addr from a socket. */
sctp_v4_from_sk(union sctp_addr * addr,struct sock * sk)2351da177e4SLinus Torvalds static void sctp_v4_from_sk(union sctp_addr *addr, struct sock *sk)
2361da177e4SLinus Torvalds {
2371da177e4SLinus Torvalds addr->v4.sin_family = AF_INET;
2387dcdbd95SAl Viro addr->v4.sin_port = 0;
239c720c7e8SEric Dumazet addr->v4.sin_addr.s_addr = inet_sk(sk)->inet_rcv_saddr;
240b6f3320bSXin Long memset(addr->v4.sin_zero, 0, sizeof(addr->v4.sin_zero));
2411da177e4SLinus Torvalds }
2421da177e4SLinus Torvalds
2431da177e4SLinus Torvalds /* Initialize sk->sk_rcv_saddr from sctp_addr. */
sctp_v4_to_sk_saddr(union sctp_addr * addr,struct sock * sk)2441da177e4SLinus Torvalds static void sctp_v4_to_sk_saddr(union sctp_addr *addr, struct sock *sk)
2451da177e4SLinus Torvalds {
246c720c7e8SEric Dumazet inet_sk(sk)->inet_rcv_saddr = addr->v4.sin_addr.s_addr;
2471da177e4SLinus Torvalds }
2481da177e4SLinus Torvalds
2491da177e4SLinus Torvalds /* Initialize sk->sk_daddr from sctp_addr. */
sctp_v4_to_sk_daddr(union sctp_addr * addr,struct sock * sk)2501da177e4SLinus Torvalds static void sctp_v4_to_sk_daddr(union sctp_addr *addr, struct sock *sk)
2511da177e4SLinus Torvalds {
252c720c7e8SEric Dumazet inet_sk(sk)->inet_daddr = addr->v4.sin_addr.s_addr;
2531da177e4SLinus Torvalds }
2541da177e4SLinus Torvalds
2551da177e4SLinus Torvalds /* Initialize a sctp_addr from an address parameter. */
sctp_v4_from_addr_param(union sctp_addr * addr,union sctp_addr_param * param,__be16 port,int iif)2560c5dc070SMarcelo Ricardo Leitner static bool sctp_v4_from_addr_param(union sctp_addr *addr,
2571da177e4SLinus Torvalds union sctp_addr_param *param,
258dd86d136SAl Viro __be16 port, int iif)
2591da177e4SLinus Torvalds {
2600c5dc070SMarcelo Ricardo Leitner if (ntohs(param->v4.param_hdr.length) < sizeof(struct sctp_ipv4addr_param))
2610c5dc070SMarcelo Ricardo Leitner return false;
2620c5dc070SMarcelo Ricardo Leitner
2631da177e4SLinus Torvalds addr->v4.sin_family = AF_INET;
2641da177e4SLinus Torvalds addr->v4.sin_port = port;
2651da177e4SLinus Torvalds addr->v4.sin_addr.s_addr = param->v4.addr.s_addr;
266b6f3320bSXin Long memset(addr->v4.sin_zero, 0, sizeof(addr->v4.sin_zero));
2670c5dc070SMarcelo Ricardo Leitner
2680c5dc070SMarcelo Ricardo Leitner return true;
2691da177e4SLinus Torvalds }
2701da177e4SLinus Torvalds
2711da177e4SLinus Torvalds /* Initialize an address parameter from a sctp_addr and return the length
2721da177e4SLinus Torvalds * of the address parameter.
2731da177e4SLinus Torvalds */
sctp_v4_to_addr_param(const union sctp_addr * addr,union sctp_addr_param * param)2741da177e4SLinus Torvalds static int sctp_v4_to_addr_param(const union sctp_addr *addr,
2751da177e4SLinus Torvalds union sctp_addr_param *param)
2761da177e4SLinus Torvalds {
277a38905e6SXin Long int length = sizeof(struct sctp_ipv4addr_param);
2781da177e4SLinus Torvalds
2791da177e4SLinus Torvalds param->v4.param_hdr.type = SCTP_PARAM_IPV4_ADDRESS;
280dbc16db1SAl Viro param->v4.param_hdr.length = htons(length);
2811da177e4SLinus Torvalds param->v4.addr.s_addr = addr->v4.sin_addr.s_addr;
2821da177e4SLinus Torvalds
2831da177e4SLinus Torvalds return length;
2841da177e4SLinus Torvalds }
2851da177e4SLinus Torvalds
2861da177e4SLinus Torvalds /* Initialize a sctp_addr from a dst_entry. */
sctp_v4_dst_saddr(union sctp_addr * saddr,struct flowi4 * fl4,__be16 port)28718a353f4SDavid S. Miller static void sctp_v4_dst_saddr(union sctp_addr *saddr, struct flowi4 *fl4,
288854d43a4SAl Viro __be16 port)
2891da177e4SLinus Torvalds {
2901da177e4SLinus Torvalds saddr->v4.sin_family = AF_INET;
2911da177e4SLinus Torvalds saddr->v4.sin_port = port;
29218a353f4SDavid S. Miller saddr->v4.sin_addr.s_addr = fl4->saddr;
293b6f3320bSXin Long memset(saddr->v4.sin_zero, 0, sizeof(saddr->v4.sin_zero));
2941da177e4SLinus Torvalds }
2951da177e4SLinus Torvalds
2961da177e4SLinus Torvalds /* Compare two addresses exactly. */
sctp_v4_cmp_addr(const union sctp_addr * addr1,const union sctp_addr * addr2)2971da177e4SLinus Torvalds static int sctp_v4_cmp_addr(const union sctp_addr *addr1,
2981da177e4SLinus Torvalds const union sctp_addr *addr2)
2991da177e4SLinus Torvalds {
3001da177e4SLinus Torvalds if (addr1->sa.sa_family != addr2->sa.sa_family)
3011da177e4SLinus Torvalds return 0;
3021da177e4SLinus Torvalds if (addr1->v4.sin_port != addr2->v4.sin_port)
3031da177e4SLinus Torvalds return 0;
3041da177e4SLinus Torvalds if (addr1->v4.sin_addr.s_addr != addr2->v4.sin_addr.s_addr)
3051da177e4SLinus Torvalds return 0;
3061da177e4SLinus Torvalds
3071da177e4SLinus Torvalds return 1;
3081da177e4SLinus Torvalds }
3091da177e4SLinus Torvalds
3101da177e4SLinus Torvalds /* Initialize addr struct to INADDR_ANY. */
sctp_v4_inaddr_any(union sctp_addr * addr,__be16 port)3116fbfa9f9SAl Viro static void sctp_v4_inaddr_any(union sctp_addr *addr, __be16 port)
3121da177e4SLinus Torvalds {
3131da177e4SLinus Torvalds addr->v4.sin_family = AF_INET;
314e6f1cebfSAl Viro addr->v4.sin_addr.s_addr = htonl(INADDR_ANY);
3151da177e4SLinus Torvalds addr->v4.sin_port = port;
316b6f3320bSXin Long memset(addr->v4.sin_zero, 0, sizeof(addr->v4.sin_zero));
3171da177e4SLinus Torvalds }
3181da177e4SLinus Torvalds
3191da177e4SLinus Torvalds /* Is this a wildcard address? */
sctp_v4_is_any(const union sctp_addr * addr)3201da177e4SLinus Torvalds static int sctp_v4_is_any(const union sctp_addr *addr)
3211da177e4SLinus Torvalds {
322e6f1cebfSAl Viro return htonl(INADDR_ANY) == addr->v4.sin_addr.s_addr;
3231da177e4SLinus Torvalds }
3241da177e4SLinus Torvalds
3251da177e4SLinus Torvalds /* This function checks if the address is a valid address to be used for
3261da177e4SLinus Torvalds * SCTP binding.
3271da177e4SLinus Torvalds *
3281da177e4SLinus Torvalds * Output:
3291da177e4SLinus Torvalds * Return 0 - If the address is a non-unicast or an illegal address.
3301da177e4SLinus Torvalds * Return 1 - If the address is a unicast.
3311da177e4SLinus Torvalds */
sctp_v4_addr_valid(union sctp_addr * addr,struct sctp_sock * sp,const struct sk_buff * skb)3325636bef7SVlad Yasevich static int sctp_v4_addr_valid(union sctp_addr *addr,
3335636bef7SVlad Yasevich struct sctp_sock *sp,
3345636bef7SVlad Yasevich const struct sk_buff *skb)
3351da177e4SLinus Torvalds {
3367dab83deSVlad Yasevich /* IPv4 addresses not allowed */
3377dab83deSVlad Yasevich if (sp && ipv6_only_sock(sctp_opt2sk(sp)))
3387dab83deSVlad Yasevich return 0;
3397dab83deSVlad Yasevich
3401da177e4SLinus Torvalds /* Is this a non-unicast address or a unusable SCTP address? */
341b5cb2bbcSJoe Perches if (IS_IPV4_UNUSABLE_ADDRESS(addr->v4.sin_addr.s_addr))
3421da177e4SLinus Torvalds return 0;
3431da177e4SLinus Torvalds
3445636bef7SVlad Yasevich /* Is this a broadcast address? */
345511c3f92SEric Dumazet if (skb && skb_rtable(skb)->rt_flags & RTCF_BROADCAST)
3465636bef7SVlad Yasevich return 0;
3475636bef7SVlad Yasevich
3481da177e4SLinus Torvalds return 1;
3491da177e4SLinus Torvalds }
3501da177e4SLinus Torvalds
3511da177e4SLinus Torvalds /* Should this be available for binding? */
sctp_v4_available(union sctp_addr * addr,struct sctp_sock * sp)3521da177e4SLinus Torvalds static int sctp_v4_available(union sctp_addr *addr, struct sctp_sock *sp)
3531da177e4SLinus Torvalds {
35426943aefSXin Long struct sock *sk = &sp->inet.sk;
35526943aefSXin Long struct net *net = sock_net(sk);
35626943aefSXin Long int tb_id = RT_TABLE_LOCAL;
35726943aefSXin Long int ret;
3581da177e4SLinus Torvalds
35926943aefSXin Long tb_id = l3mdev_fib_table_by_index(net, sk->sk_bound_dev_if) ?: tb_id;
36026943aefSXin Long ret = inet_addr_type_table(net, addr->v4.sin_addr.s_addr, tb_id);
361e6f1cebfSAl Viro if (addr->v4.sin_addr.s_addr != htonl(INADDR_ANY) &&
362cdac4e07SNeil Horman ret != RTN_LOCAL &&
363*3f7e7532SEric Dumazet !inet_test_bit(FREEBIND, sk) &&
364289d3b21SKuniyuki Iwashima !READ_ONCE(net->ipv4.sysctl_ip_nonlocal_bind))
3651da177e4SLinus Torvalds return 0;
366cdac4e07SNeil Horman
3677dab83deSVlad Yasevich if (ipv6_only_sock(sctp_opt2sk(sp)))
3687dab83deSVlad Yasevich return 0;
3697dab83deSVlad Yasevich
3701da177e4SLinus Torvalds return 1;
3711da177e4SLinus Torvalds }
3721da177e4SLinus Torvalds
3731da177e4SLinus Torvalds /* Checking the loopback, private and other address scopes as defined in
3741da177e4SLinus Torvalds * RFC 1918. The IPv4 scoping is based on the draft for SCTP IPv4
3751da177e4SLinus Torvalds * scoping <draft-stewart-tsvwg-sctp-ipv4-00.txt>.
3761da177e4SLinus Torvalds *
3771da177e4SLinus Torvalds * Level 0 - unusable SCTP addresses
3781da177e4SLinus Torvalds * Level 1 - loopback address
3791da177e4SLinus Torvalds * Level 2 - link-local addresses
3801da177e4SLinus Torvalds * Level 3 - private addresses.
3811da177e4SLinus Torvalds * Level 4 - global addresses
3821da177e4SLinus Torvalds * For INIT and INIT-ACK address list, let L be the level of
38393c3216aSRandy Dunlap * requested destination address, sender and receiver
3841da177e4SLinus Torvalds * SHOULD include all of its addresses with level greater
3851da177e4SLinus Torvalds * than or equal to L.
38672388433SBhaskar Dutta *
38772388433SBhaskar Dutta * IPv4 scoping can be controlled through sysctl option
38872388433SBhaskar Dutta * net.sctp.addr_scope_policy
3891da177e4SLinus Torvalds */
sctp_v4_scope(union sctp_addr * addr)3901c662018SXin Long static enum sctp_scope sctp_v4_scope(union sctp_addr *addr)
3911da177e4SLinus Torvalds {
3921c662018SXin Long enum sctp_scope retval;
3931da177e4SLinus Torvalds
3941da177e4SLinus Torvalds /* Check for unusable SCTP addresses. */
395b5cb2bbcSJoe Perches if (IS_IPV4_UNUSABLE_ADDRESS(addr->v4.sin_addr.s_addr)) {
3961da177e4SLinus Torvalds retval = SCTP_SCOPE_UNUSABLE;
397b5cb2bbcSJoe Perches } else if (ipv4_is_loopback(addr->v4.sin_addr.s_addr)) {
3981da177e4SLinus Torvalds retval = SCTP_SCOPE_LOOPBACK;
399b5cb2bbcSJoe Perches } else if (ipv4_is_linklocal_169(addr->v4.sin_addr.s_addr)) {
4001da177e4SLinus Torvalds retval = SCTP_SCOPE_LINK;
401b5cb2bbcSJoe Perches } else if (ipv4_is_private_10(addr->v4.sin_addr.s_addr) ||
402b5cb2bbcSJoe Perches ipv4_is_private_172(addr->v4.sin_addr.s_addr) ||
4031d11fa23SXin Long ipv4_is_private_192(addr->v4.sin_addr.s_addr) ||
4041d11fa23SXin Long ipv4_is_test_198(addr->v4.sin_addr.s_addr)) {
4051da177e4SLinus Torvalds retval = SCTP_SCOPE_PRIVATE;
4061da177e4SLinus Torvalds } else {
4071da177e4SLinus Torvalds retval = SCTP_SCOPE_GLOBAL;
4081da177e4SLinus Torvalds }
4091da177e4SLinus Torvalds
4101da177e4SLinus Torvalds return retval;
4111da177e4SLinus Torvalds }
4121da177e4SLinus Torvalds
4131da177e4SLinus Torvalds /* Returns a valid dst cache entry for the given source and destination ip
4141da177e4SLinus Torvalds * addresses. If an association is passed, trys to get a dst entry with a
4151da177e4SLinus Torvalds * source address that matches an address in the bind address list.
4161da177e4SLinus Torvalds */
sctp_v4_get_dst(struct sctp_transport * t,union sctp_addr * saddr,struct flowi * fl,struct sock * sk)417da0420beSVlad Yasevich static void sctp_v4_get_dst(struct sctp_transport *t, union sctp_addr *saddr,
418da0420beSVlad Yasevich struct flowi *fl, struct sock *sk)
4191da177e4SLinus Torvalds {
420da0420beSVlad Yasevich struct sctp_association *asoc = t->asoc;
4211da177e4SLinus Torvalds struct rtable *rt;
422582eea23SMarcelo Ricardo Leitner struct flowi _fl;
423582eea23SMarcelo Ricardo Leitner struct flowi4 *fl4 = &_fl.u.ip4;
4241da177e4SLinus Torvalds struct sctp_bind_addr *bp;
4251da177e4SLinus Torvalds struct sctp_sockaddr_entry *laddr;
4261da177e4SLinus Torvalds struct dst_entry *dst = NULL;
427da0420beSVlad Yasevich union sctp_addr *daddr = &t->ipaddr;
4281da177e4SLinus Torvalds union sctp_addr dst_saddr;
4298a9c58d2SXin Long __u8 tos = inet_sk(sk)->tos;
4301da177e4SLinus Torvalds
4318a9c58d2SXin Long if (t->dscp & SCTP_DSCP_SET_MASK)
4328a9c58d2SXin Long tos = t->dscp & SCTP_DSCP_VAL_MASK;
433582eea23SMarcelo Ricardo Leitner memset(&_fl, 0x0, sizeof(_fl));
4349914ae3cSVlad Yasevich fl4->daddr = daddr->v4.sin_addr.s_addr;
4359914ae3cSVlad Yasevich fl4->fl4_dport = daddr->v4.sin_port;
4369914ae3cSVlad Yasevich fl4->flowi4_proto = IPPROTO_SCTP;
4371da177e4SLinus Torvalds if (asoc) {
438ba80e20dSGuillaume Nault fl4->flowi4_tos = RT_TOS(tos);
439ba80e20dSGuillaume Nault fl4->flowi4_scope = ip_sock_rt_scope(asoc->base.sk);
4409914ae3cSVlad Yasevich fl4->flowi4_oif = asoc->base.sk->sk_bound_dev_if;
4419914ae3cSVlad Yasevich fl4->fl4_sport = htons(asoc->base.bind_addr.port);
4421da177e4SLinus Torvalds }
4436429d3dcSWei Yongjun if (saddr) {
4449914ae3cSVlad Yasevich fl4->saddr = saddr->v4.sin_addr.s_addr;
445ecf938feSXin Long if (!fl4->fl4_sport)
4469914ae3cSVlad Yasevich fl4->fl4_sport = saddr->v4.sin_port;
4476429d3dcSWei Yongjun }
4481da177e4SLinus Torvalds
449bb33381dSDaniel Borkmann pr_debug("%s: dst:%pI4, src:%pI4 - ", __func__, &fl4->daddr,
450bb33381dSDaniel Borkmann &fl4->saddr);
4511da177e4SLinus Torvalds
452bb2db45bSEric W. Biederman rt = ip_route_output_key(sock_net(sk), fl4);
453582eea23SMarcelo Ricardo Leitner if (!IS_ERR(rt)) {
454d8d1f30bSChangli Gao dst = &rt->dst;
455582eea23SMarcelo Ricardo Leitner t->dst = dst;
456582eea23SMarcelo Ricardo Leitner memcpy(fl, &_fl, sizeof(_fl));
457582eea23SMarcelo Ricardo Leitner }
4581da177e4SLinus Torvalds
4591da177e4SLinus Torvalds /* If there is no association or if a source address is passed, no
4601da177e4SLinus Torvalds * more validation is required.
4611da177e4SLinus Torvalds */
4621da177e4SLinus Torvalds if (!asoc || saddr)
4631da177e4SLinus Torvalds goto out;
4641da177e4SLinus Torvalds
4651da177e4SLinus Torvalds bp = &asoc->base.bind_addr;
4661da177e4SLinus Torvalds
4671da177e4SLinus Torvalds if (dst) {
4681da177e4SLinus Torvalds /* Walk through the bind address list and look for a bind
4691da177e4SLinus Torvalds * address that matches the source address of the returned dst.
4701da177e4SLinus Torvalds */
47118a353f4SDavid S. Miller sctp_v4_dst_saddr(&dst_saddr, fl4, htons(bp->port));
472559cf710SVlad Yasevich rcu_read_lock();
473559cf710SVlad Yasevich list_for_each_entry_rcu(laddr, &bp->address_list, list) {
4748a07eb0aSMichio Honda if (!laddr->valid || (laddr->state == SCTP_ADDR_DEL) ||
4758a07eb0aSMichio Honda (laddr->state != SCTP_ADDR_SRC &&
4768a07eb0aSMichio Honda !asoc->src_out_of_asoc_ok))
477dc022a98SSridhar Samudrala continue;
478854d43a4SAl Viro if (sctp_v4_cmp_addr(&dst_saddr, &laddr->a))
4791da177e4SLinus Torvalds goto out_unlock;
4801da177e4SLinus Torvalds }
481559cf710SVlad Yasevich rcu_read_unlock();
4821da177e4SLinus Torvalds
4831da177e4SLinus Torvalds /* None of the bound addresses match the source address of the
4841da177e4SLinus Torvalds * dst. So release it.
4851da177e4SLinus Torvalds */
4861da177e4SLinus Torvalds dst_release(dst);
4871da177e4SLinus Torvalds dst = NULL;
4881da177e4SLinus Torvalds }
4891da177e4SLinus Torvalds
4901da177e4SLinus Torvalds /* Walk through the bind address list and try to get a dst that
4911da177e4SLinus Torvalds * matches a bind address as the source address.
4921da177e4SLinus Torvalds */
493559cf710SVlad Yasevich rcu_read_lock();
494559cf710SVlad Yasevich list_for_each_entry_rcu(laddr, &bp->address_list, list) {
4950ca50d12SMarcelo Ricardo Leitner struct net_device *odev;
4960ca50d12SMarcelo Ricardo Leitner
497559cf710SVlad Yasevich if (!laddr->valid)
498559cf710SVlad Yasevich continue;
49907868284SMarcelo Ricardo Leitner if (laddr->state != SCTP_ADDR_SRC ||
50007868284SMarcelo Ricardo Leitner AF_INET != laddr->a.sa.sa_family)
50107868284SMarcelo Ricardo Leitner continue;
50207868284SMarcelo Ricardo Leitner
5039914ae3cSVlad Yasevich fl4->fl4_sport = laddr->a.v4.sin_port;
5043f06760cSGuillaume Nault flowi4_update_output(fl4, asoc->base.sk->sk_bound_dev_if,
50585350871SXufeng Zhang daddr->v4.sin_addr.s_addr,
50685350871SXufeng Zhang laddr->a.v4.sin_addr.s_addr);
50785350871SXufeng Zhang
508bb2db45bSEric W. Biederman rt = ip_route_output_key(sock_net(sk), fl4);
50907868284SMarcelo Ricardo Leitner if (IS_ERR(rt))
51007868284SMarcelo Ricardo Leitner continue;
51107868284SMarcelo Ricardo Leitner
5120ca50d12SMarcelo Ricardo Leitner /* Ensure the src address belongs to the output
5130ca50d12SMarcelo Ricardo Leitner * interface.
5140ca50d12SMarcelo Ricardo Leitner */
5150ca50d12SMarcelo Ricardo Leitner odev = __ip_dev_find(sock_net(sk), laddr->a.v4.sin_addr.s_addr,
5160ca50d12SMarcelo Ricardo Leitner false);
517d82f0f1fSMarcelo Ricardo Leitner if (!odev || odev->ifindex != fl4->flowi4_oif) {
518582eea23SMarcelo Ricardo Leitner if (!dst) {
5194a31a6b1STommi Rantala dst = &rt->dst;
520582eea23SMarcelo Ricardo Leitner t->dst = dst;
521582eea23SMarcelo Ricardo Leitner memcpy(fl, &_fl, sizeof(_fl));
522582eea23SMarcelo Ricardo Leitner } else {
523d82f0f1fSMarcelo Ricardo Leitner dst_release(&rt->dst);
524582eea23SMarcelo Ricardo Leitner }
5250ca50d12SMarcelo Ricardo Leitner continue;
526d82f0f1fSMarcelo Ricardo Leitner }
5270ca50d12SMarcelo Ricardo Leitner
528410f0383SMarcelo Ricardo Leitner dst_release(dst);
529d8d1f30bSChangli Gao dst = &rt->dst;
530582eea23SMarcelo Ricardo Leitner t->dst = dst;
531582eea23SMarcelo Ricardo Leitner memcpy(fl, &_fl, sizeof(_fl));
53207868284SMarcelo Ricardo Leitner break;
5331da177e4SLinus Torvalds }
5341da177e4SLinus Torvalds
5351da177e4SLinus Torvalds out_unlock:
536559cf710SVlad Yasevich rcu_read_unlock();
5371da177e4SLinus Torvalds out:
538582eea23SMarcelo Ricardo Leitner if (dst) {
539bb33381dSDaniel Borkmann pr_debug("rt_dst:%pI4, rt_src:%pI4\n",
540582eea23SMarcelo Ricardo Leitner &fl->u.ip4.daddr, &fl->u.ip4.saddr);
541582eea23SMarcelo Ricardo Leitner } else {
542582eea23SMarcelo Ricardo Leitner t->dst = NULL;
543bb33381dSDaniel Borkmann pr_debug("no route\n");
5441da177e4SLinus Torvalds }
545582eea23SMarcelo Ricardo Leitner }
5461da177e4SLinus Torvalds
5471da177e4SLinus Torvalds /* For v4, the source address is cached in the route entry(dst). So no need
5481da177e4SLinus Torvalds * to cache it separately and hence this is an empty routine.
5491da177e4SLinus Torvalds */
sctp_v4_get_saddr(struct sctp_sock * sk,struct sctp_transport * t,struct flowi * fl)550e5117101SYOSHIFUJI Hideaki static void sctp_v4_get_saddr(struct sctp_sock *sk,
5519914ae3cSVlad Yasevich struct sctp_transport *t,
5529914ae3cSVlad Yasevich struct flowi *fl)
5531da177e4SLinus Torvalds {
5549914ae3cSVlad Yasevich union sctp_addr *saddr = &t->saddr;
5559914ae3cSVlad Yasevich struct rtable *rt = (struct rtable *)t->dst;
55623ec47a0SVladislav Yasevich
5571da177e4SLinus Torvalds if (rt) {
5581da177e4SLinus Torvalds saddr->v4.sin_family = AF_INET;
559902ebd3eSDavid S. Miller saddr->v4.sin_addr.s_addr = fl->u.ip4.saddr;
5601da177e4SLinus Torvalds }
5611da177e4SLinus Torvalds }
5621da177e4SLinus Torvalds
5631da177e4SLinus Torvalds /* What interface did this skb arrive on? */
sctp_v4_skb_iif(const struct sk_buff * skb)5641da177e4SLinus Torvalds static int sctp_v4_skb_iif(const struct sk_buff *skb)
5651da177e4SLinus Torvalds {
56692101b3bSDavid S. Miller return inet_iif(skb);
5671da177e4SLinus Torvalds }
5681da177e4SLinus Torvalds
sctp_v4_skb_sdif(const struct sk_buff * skb)56933e93ed2SXin Long static int sctp_v4_skb_sdif(const struct sk_buff *skb)
57033e93ed2SXin Long {
57133e93ed2SXin Long return inet_sdif(skb);
57233e93ed2SXin Long }
57333e93ed2SXin Long
5741da177e4SLinus Torvalds /* Was this packet marked by Explicit Congestion Notification? */
sctp_v4_is_ce(const struct sk_buff * skb)5751da177e4SLinus Torvalds static int sctp_v4_is_ce(const struct sk_buff *skb)
5761da177e4SLinus Torvalds {
577eddc9ec5SArnaldo Carvalho de Melo return INET_ECN_is_ce(ip_hdr(skb)->tos);
5781da177e4SLinus Torvalds }
5791da177e4SLinus Torvalds
5801da177e4SLinus Torvalds /* Create and initialize a new sk for the socket returned by accept(). */
sctp_v4_create_accept_sk(struct sock * sk,struct sctp_association * asoc,bool kern)5811da177e4SLinus Torvalds static struct sock *sctp_v4_create_accept_sk(struct sock *sk,
582cdfbabfbSDavid Howells struct sctp_association *asoc,
583cdfbabfbSDavid Howells bool kern)
5841da177e4SLinus Torvalds {
5853b1e0a65SYOSHIFUJI Hideaki struct sock *newsk = sk_alloc(sock_net(sk), PF_INET, GFP_KERNEL,
586cdfbabfbSDavid Howells sk->sk_prot, kern);
587914e1c8bSVlad Yasevich struct inet_sock *newinet;
5881da177e4SLinus Torvalds
5891da177e4SLinus Torvalds if (!newsk)
5901da177e4SLinus Torvalds goto out;
5911da177e4SLinus Torvalds
5921da177e4SLinus Torvalds sock_init_data(NULL, newsk);
5931da177e4SLinus Torvalds
594914e1c8bSVlad Yasevich sctp_copy_sock(newsk, sk, asoc);
5951da177e4SLinus Torvalds sock_reset_flag(newsk, SOCK_ZAPPED);
5961da177e4SLinus Torvalds
597b7e10c25SRichard Haines sctp_v4_copy_ip_options(sk, newsk);
598b7e10c25SRichard Haines
5991da177e4SLinus Torvalds newinet = inet_sk(newsk);
6001da177e4SLinus Torvalds
601c720c7e8SEric Dumazet newinet->inet_daddr = asoc->peer.primary_addr.v4.sin_addr.s_addr;
6021da177e4SLinus Torvalds
6031da177e4SLinus Torvalds if (newsk->sk_prot->init(newsk)) {
6041da177e4SLinus Torvalds sk_common_release(newsk);
6051da177e4SLinus Torvalds newsk = NULL;
6061da177e4SLinus Torvalds }
6071da177e4SLinus Torvalds
6081da177e4SLinus Torvalds out:
6091da177e4SLinus Torvalds return newsk;
6101da177e4SLinus Torvalds }
6111da177e4SLinus Torvalds
sctp_v4_addr_to_user(struct sctp_sock * sp,union sctp_addr * addr)612299ee123SJason Gunthorpe static int sctp_v4_addr_to_user(struct sctp_sock *sp, union sctp_addr *addr)
6131da177e4SLinus Torvalds {
614299ee123SJason Gunthorpe /* No address mapping for V4 sockets */
61509279e61SXin Long memset(addr->v4.sin_zero, 0, sizeof(addr->v4.sin_zero));
616299ee123SJason Gunthorpe return sizeof(struct sockaddr_in);
6171da177e4SLinus Torvalds }
6181da177e4SLinus Torvalds
6191da177e4SLinus Torvalds /* Dump the v4 addr to the seq file. */
sctp_v4_seq_dump_addr(struct seq_file * seq,union sctp_addr * addr)6201da177e4SLinus Torvalds static void sctp_v4_seq_dump_addr(struct seq_file *seq, union sctp_addr *addr)
6211da177e4SLinus Torvalds {
62221454aaaSHarvey Harrison seq_printf(seq, "%pI4 ", &addr->v4.sin_addr);
6231da177e4SLinus Torvalds }
6241da177e4SLinus Torvalds
sctp_v4_ecn_capable(struct sock * sk)625b9031d9dSVlad Yasevich static void sctp_v4_ecn_capable(struct sock *sk)
626b9031d9dSVlad Yasevich {
627b9031d9dSVlad Yasevich INET_ECN_xmit(sk);
628b9031d9dSVlad Yasevich }
629b9031d9dSVlad Yasevich
sctp_addr_wq_timeout_handler(struct timer_list * t)6309c3b5751SKees Cook static void sctp_addr_wq_timeout_handler(struct timer_list *t)
6319f7d653bSMichio Honda {
6329c3b5751SKees Cook struct net *net = from_timer(net, t, sctp.addr_wq_timer);
6339f7d653bSMichio Honda struct sctp_sockaddr_entry *addrw, *temp;
6349f7d653bSMichio Honda struct sctp_sock *sp;
6359f7d653bSMichio Honda
6364db67e80SEric W. Biederman spin_lock_bh(&net->sctp.addr_wq_lock);
6379f7d653bSMichio Honda
6384db67e80SEric W. Biederman list_for_each_entry_safe(addrw, temp, &net->sctp.addr_waitq, list) {
639bb33381dSDaniel Borkmann pr_debug("%s: the first ent in wq:%p is addr:%pISc for cmd:%d at "
640bb33381dSDaniel Borkmann "entry:%p\n", __func__, &net->sctp.addr_waitq, &addrw->a.sa,
641bb33381dSDaniel Borkmann addrw->state, addrw);
6429f7d653bSMichio Honda
643dfd56b8bSEric Dumazet #if IS_ENABLED(CONFIG_IPV6)
6449f7d653bSMichio Honda /* Now we send an ASCONF for each association */
6459f7d653bSMichio Honda /* Note. we currently don't handle link local IPv6 addressees */
6469f7d653bSMichio Honda if (addrw->a.sa.sa_family == AF_INET6) {
6479f7d653bSMichio Honda struct in6_addr *in6;
6489f7d653bSMichio Honda
6499f7d653bSMichio Honda if (ipv6_addr_type(&addrw->a.v6.sin6_addr) &
6509f7d653bSMichio Honda IPV6_ADDR_LINKLOCAL)
6519f7d653bSMichio Honda goto free_next;
6529f7d653bSMichio Honda
6539f7d653bSMichio Honda in6 = (struct in6_addr *)&addrw->a.v6.sin6_addr;
6544db67e80SEric W. Biederman if (ipv6_chk_addr(net, in6, NULL, 0) == 0 &&
6559f7d653bSMichio Honda addrw->state == SCTP_ADDR_NEW) {
6569f7d653bSMichio Honda unsigned long timeo_val;
6579f7d653bSMichio Honda
658bb33381dSDaniel Borkmann pr_debug("%s: this is on DAD, trying %d sec "
659bb33381dSDaniel Borkmann "later\n", __func__,
6609f7d653bSMichio Honda SCTP_ADDRESS_TICK_DELAY);
661bb33381dSDaniel Borkmann
6629f7d653bSMichio Honda timeo_val = jiffies;
6639f7d653bSMichio Honda timeo_val += msecs_to_jiffies(SCTP_ADDRESS_TICK_DELAY);
6644db67e80SEric W. Biederman mod_timer(&net->sctp.addr_wq_timer, timeo_val);
6659f7d653bSMichio Honda break;
6669f7d653bSMichio Honda }
6679f7d653bSMichio Honda }
6685d0c90cfSDavid S. Miller #endif
6694db67e80SEric W. Biederman list_for_each_entry(sp, &net->sctp.auto_asconf_splist, auto_asconf_list) {
6709f7d653bSMichio Honda struct sock *sk;
6719f7d653bSMichio Honda
6729f7d653bSMichio Honda sk = sctp_opt2sk(sp);
6739f7d653bSMichio Honda /* ignore bound-specific endpoints */
6749f7d653bSMichio Honda if (!sctp_is_ep_boundall(sk))
6759f7d653bSMichio Honda continue;
6765bc1d1b4Swangweidong bh_lock_sock(sk);
6779f7d653bSMichio Honda if (sctp_asconf_mgmt(sp, addrw) < 0)
678bb33381dSDaniel Borkmann pr_debug("%s: sctp_asconf_mgmt failed\n", __func__);
6795bc1d1b4Swangweidong bh_unlock_sock(sk);
6809f7d653bSMichio Honda }
68139d84a58SDaniel Halperin #if IS_ENABLED(CONFIG_IPV6)
6829f7d653bSMichio Honda free_next:
68339d84a58SDaniel Halperin #endif
6849f7d653bSMichio Honda list_del(&addrw->list);
6859f7d653bSMichio Honda kfree(addrw);
6869f7d653bSMichio Honda }
6874db67e80SEric W. Biederman spin_unlock_bh(&net->sctp.addr_wq_lock);
6889f7d653bSMichio Honda }
6899f7d653bSMichio Honda
sctp_free_addr_wq(struct net * net)6904db67e80SEric W. Biederman static void sctp_free_addr_wq(struct net *net)
6919f7d653bSMichio Honda {
6929f7d653bSMichio Honda struct sctp_sockaddr_entry *addrw;
6939f7d653bSMichio Honda struct sctp_sockaddr_entry *temp;
6949f7d653bSMichio Honda
6954db67e80SEric W. Biederman spin_lock_bh(&net->sctp.addr_wq_lock);
6964db67e80SEric W. Biederman del_timer(&net->sctp.addr_wq_timer);
6974db67e80SEric W. Biederman list_for_each_entry_safe(addrw, temp, &net->sctp.addr_waitq, list) {
6989f7d653bSMichio Honda list_del(&addrw->list);
6999f7d653bSMichio Honda kfree(addrw);
7009f7d653bSMichio Honda }
7014db67e80SEric W. Biederman spin_unlock_bh(&net->sctp.addr_wq_lock);
7029f7d653bSMichio Honda }
7039f7d653bSMichio Honda
7049f7d653bSMichio Honda /* lookup the entry for the same address in the addr_waitq
7059f7d653bSMichio Honda * sctp_addr_wq MUST be locked
7069f7d653bSMichio Honda */
sctp_addr_wq_lookup(struct net * net,struct sctp_sockaddr_entry * addr)7074db67e80SEric W. Biederman static struct sctp_sockaddr_entry *sctp_addr_wq_lookup(struct net *net,
7084db67e80SEric W. Biederman struct sctp_sockaddr_entry *addr)
7099f7d653bSMichio Honda {
7109f7d653bSMichio Honda struct sctp_sockaddr_entry *addrw;
7119f7d653bSMichio Honda
7124db67e80SEric W. Biederman list_for_each_entry(addrw, &net->sctp.addr_waitq, list) {
7139f7d653bSMichio Honda if (addrw->a.sa.sa_family != addr->a.sa.sa_family)
7149f7d653bSMichio Honda continue;
7159f7d653bSMichio Honda if (addrw->a.sa.sa_family == AF_INET) {
7169f7d653bSMichio Honda if (addrw->a.v4.sin_addr.s_addr ==
7179f7d653bSMichio Honda addr->a.v4.sin_addr.s_addr)
7189f7d653bSMichio Honda return addrw;
7199f7d653bSMichio Honda } else if (addrw->a.sa.sa_family == AF_INET6) {
7209f7d653bSMichio Honda if (ipv6_addr_equal(&addrw->a.v6.sin6_addr,
7219f7d653bSMichio Honda &addr->a.v6.sin6_addr))
7229f7d653bSMichio Honda return addrw;
7239f7d653bSMichio Honda }
7249f7d653bSMichio Honda }
7259f7d653bSMichio Honda return NULL;
7269f7d653bSMichio Honda }
7279f7d653bSMichio Honda
sctp_addr_wq_mgmt(struct net * net,struct sctp_sockaddr_entry * addr,int cmd)7284db67e80SEric W. Biederman void sctp_addr_wq_mgmt(struct net *net, struct sctp_sockaddr_entry *addr, int cmd)
7299f7d653bSMichio Honda {
7309f7d653bSMichio Honda struct sctp_sockaddr_entry *addrw;
7319f7d653bSMichio Honda unsigned long timeo_val;
7329f7d653bSMichio Honda
7339f7d653bSMichio Honda /* first, we check if an opposite message already exist in the queue.
7349f7d653bSMichio Honda * If we found such message, it is removed.
7359f7d653bSMichio Honda * This operation is a bit stupid, but the DHCP client attaches the
7369f7d653bSMichio Honda * new address after a couple of addition and deletion of that address
7379f7d653bSMichio Honda */
7389f7d653bSMichio Honda
7394db67e80SEric W. Biederman spin_lock_bh(&net->sctp.addr_wq_lock);
7409f7d653bSMichio Honda /* Offsets existing events in addr_wq */
7414db67e80SEric W. Biederman addrw = sctp_addr_wq_lookup(net, addr);
7429f7d653bSMichio Honda if (addrw) {
7439f7d653bSMichio Honda if (addrw->state != cmd) {
744bb33381dSDaniel Borkmann pr_debug("%s: offsets existing entry for %d, addr:%pISc "
745bb33381dSDaniel Borkmann "in wq:%p\n", __func__, addrw->state, &addrw->a.sa,
7464db67e80SEric W. Biederman &net->sctp.addr_waitq);
747bb33381dSDaniel Borkmann
7489f7d653bSMichio Honda list_del(&addrw->list);
7499f7d653bSMichio Honda kfree(addrw);
7509f7d653bSMichio Honda }
7514db67e80SEric W. Biederman spin_unlock_bh(&net->sctp.addr_wq_lock);
7529f7d653bSMichio Honda return;
7539f7d653bSMichio Honda }
7549f7d653bSMichio Honda
7559f7d653bSMichio Honda /* OK, we have to add the new address to the wait queue */
7569f7d653bSMichio Honda addrw = kmemdup(addr, sizeof(struct sctp_sockaddr_entry), GFP_ATOMIC);
7579f7d653bSMichio Honda if (addrw == NULL) {
7584db67e80SEric W. Biederman spin_unlock_bh(&net->sctp.addr_wq_lock);
7599f7d653bSMichio Honda return;
7609f7d653bSMichio Honda }
7619f7d653bSMichio Honda addrw->state = cmd;
7624db67e80SEric W. Biederman list_add_tail(&addrw->list, &net->sctp.addr_waitq);
763bb33381dSDaniel Borkmann
764bb33381dSDaniel Borkmann pr_debug("%s: add new entry for cmd:%d, addr:%pISc in wq:%p\n",
765bb33381dSDaniel Borkmann __func__, addrw->state, &addrw->a.sa, &net->sctp.addr_waitq);
7669f7d653bSMichio Honda
7674db67e80SEric W. Biederman if (!timer_pending(&net->sctp.addr_wq_timer)) {
7689f7d653bSMichio Honda timeo_val = jiffies;
7699f7d653bSMichio Honda timeo_val += msecs_to_jiffies(SCTP_ADDRESS_TICK_DELAY);
7704db67e80SEric W. Biederman mod_timer(&net->sctp.addr_wq_timer, timeo_val);
7719f7d653bSMichio Honda }
7724db67e80SEric W. Biederman spin_unlock_bh(&net->sctp.addr_wq_lock);
7739f7d653bSMichio Honda }
7749f7d653bSMichio Honda
77529303547SVlad Yasevich /* Event handler for inet address addition/deletion events.
77629303547SVlad Yasevich * The sctp_local_addr_list needs to be protocted by a spin lock since
77729303547SVlad Yasevich * multiple notifiers (say IPv4 and IPv6) may be running at the same
77829303547SVlad Yasevich * time and thus corrupt the list.
77929303547SVlad Yasevich * The reader side is protected with RCU.
78029303547SVlad Yasevich */
sctp_inetaddr_event(struct notifier_block * this,unsigned long ev,void * ptr)78124123186SAdrian Bunk static int sctp_inetaddr_event(struct notifier_block *this, unsigned long ev,
7821da177e4SLinus Torvalds void *ptr)
7831da177e4SLinus Torvalds {
78429c7cf96SSridhar Samudrala struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
78529303547SVlad Yasevich struct sctp_sockaddr_entry *addr = NULL;
78629303547SVlad Yasevich struct sctp_sockaddr_entry *temp;
7874db67e80SEric W. Biederman struct net *net = dev_net(ifa->ifa_dev->dev);
78822626216SChidambar 'ilLogict' Zinnoury int found = 0;
7891da177e4SLinus Torvalds
79029c7cf96SSridhar Samudrala switch (ev) {
79129c7cf96SSridhar Samudrala case NETDEV_UP:
792400b8b9aSXin Long addr = kzalloc(sizeof(*addr), GFP_ATOMIC);
79329c7cf96SSridhar Samudrala if (addr) {
79429c7cf96SSridhar Samudrala addr->a.v4.sin_family = AF_INET;
79529c7cf96SSridhar Samudrala addr->a.v4.sin_addr.s_addr = ifa->ifa_local;
79629303547SVlad Yasevich addr->valid = 1;
7974db67e80SEric W. Biederman spin_lock_bh(&net->sctp.local_addr_lock);
7984db67e80SEric W. Biederman list_add_tail_rcu(&addr->list, &net->sctp.local_addr_list);
7994db67e80SEric W. Biederman sctp_addr_wq_mgmt(net, addr, SCTP_ADDR_NEW);
8004db67e80SEric W. Biederman spin_unlock_bh(&net->sctp.local_addr_lock);
80129c7cf96SSridhar Samudrala }
80229c7cf96SSridhar Samudrala break;
80329c7cf96SSridhar Samudrala case NETDEV_DOWN:
8044db67e80SEric W. Biederman spin_lock_bh(&net->sctp.local_addr_lock);
80529303547SVlad Yasevich list_for_each_entry_safe(addr, temp,
8064db67e80SEric W. Biederman &net->sctp.local_addr_list, list) {
807a40a7d15SPavel Emelyanov if (addr->a.sa.sa_family == AF_INET &&
808a40a7d15SPavel Emelyanov addr->a.v4.sin_addr.s_addr ==
809a40a7d15SPavel Emelyanov ifa->ifa_local) {
8104db67e80SEric W. Biederman sctp_addr_wq_mgmt(net, addr, SCTP_ADDR_DEL);
81122626216SChidambar 'ilLogict' Zinnoury found = 1;
81229303547SVlad Yasevich addr->valid = 0;
81329303547SVlad Yasevich list_del_rcu(&addr->list);
81429c7cf96SSridhar Samudrala break;
81529c7cf96SSridhar Samudrala }
81629c7cf96SSridhar Samudrala }
8174db67e80SEric W. Biederman spin_unlock_bh(&net->sctp.local_addr_lock);
81822626216SChidambar 'ilLogict' Zinnoury if (found)
8191231f0baSLai Jiangshan kfree_rcu(addr, rcu);
82029c7cf96SSridhar Samudrala break;
82129c7cf96SSridhar Samudrala }
8221da177e4SLinus Torvalds
8231da177e4SLinus Torvalds return NOTIFY_DONE;
8241da177e4SLinus Torvalds }
8251da177e4SLinus Torvalds
8261da177e4SLinus Torvalds /*
8271da177e4SLinus Torvalds * Initialize the control inode/socket with a control endpoint data
8281da177e4SLinus Torvalds * structure. This endpoint is reserved exclusively for the OOTB processing.
8291da177e4SLinus Torvalds */
sctp_ctl_sock_init(struct net * net)8302ce95503SEric W. Biederman static int sctp_ctl_sock_init(struct net *net)
8311da177e4SLinus Torvalds {
8321da177e4SLinus Torvalds int err;
833fb13d9f9SBrian Haley sa_family_t family = PF_INET;
8341da177e4SLinus Torvalds
8351da177e4SLinus Torvalds if (sctp_get_pf_specific(PF_INET6))
8361da177e4SLinus Torvalds family = PF_INET6;
8371da177e4SLinus Torvalds
8382ce95503SEric W. Biederman err = inet_ctl_sock_create(&net->sctp.ctl_sock, family,
8392ce95503SEric W. Biederman SOCK_SEQPACKET, IPPROTO_SCTP, net);
840fb13d9f9SBrian Haley
841fb13d9f9SBrian Haley /* If IPv6 socket could not be created, try the IPv4 socket */
842fb13d9f9SBrian Haley if (err < 0 && family == PF_INET6)
8432ce95503SEric W. Biederman err = inet_ctl_sock_create(&net->sctp.ctl_sock, AF_INET,
844fb13d9f9SBrian Haley SOCK_SEQPACKET, IPPROTO_SCTP,
8452ce95503SEric W. Biederman net);
846fb13d9f9SBrian Haley
8471da177e4SLinus Torvalds if (err < 0) {
848145ce502SJoe Perches pr_err("Failed to create the SCTP control socket\n");
8491da177e4SLinus Torvalds return err;
8501da177e4SLinus Torvalds }
8511da177e4SLinus Torvalds return 0;
8521da177e4SLinus Torvalds }
8531da177e4SLinus Torvalds
sctp_udp_rcv(struct sock * sk,struct sk_buff * skb)854965ae444SXin Long static int sctp_udp_rcv(struct sock *sk, struct sk_buff *skb)
855965ae444SXin Long {
856a1dd2cf2SXin Long SCTP_INPUT_CB(skb)->encap_port = udp_hdr(skb)->source;
857a1dd2cf2SXin Long
858965ae444SXin Long skb_set_transport_header(skb, sizeof(struct udphdr));
859965ae444SXin Long sctp_rcv(skb);
860965ae444SXin Long return 0;
861965ae444SXin Long }
862965ae444SXin Long
sctp_udp_sock_start(struct net * net)863965ae444SXin Long int sctp_udp_sock_start(struct net *net)
864965ae444SXin Long {
865965ae444SXin Long struct udp_tunnel_sock_cfg tuncfg = {NULL};
866965ae444SXin Long struct udp_port_cfg udp_conf = {0};
867965ae444SXin Long struct socket *sock;
868965ae444SXin Long int err;
869965ae444SXin Long
870965ae444SXin Long udp_conf.family = AF_INET;
871965ae444SXin Long udp_conf.local_ip.s_addr = htonl(INADDR_ANY);
872965ae444SXin Long udp_conf.local_udp_port = htons(net->sctp.udp_port);
873965ae444SXin Long err = udp_sock_create(net, &udp_conf, &sock);
874965ae444SXin Long if (err) {
875965ae444SXin Long pr_err("Failed to create the SCTP UDP tunneling v4 sock\n");
876965ae444SXin Long return err;
877965ae444SXin Long }
878965ae444SXin Long
879965ae444SXin Long tuncfg.encap_type = 1;
880965ae444SXin Long tuncfg.encap_rcv = sctp_udp_rcv;
8819e47df00SXin Long tuncfg.encap_err_lookup = sctp_udp_v4_err;
882965ae444SXin Long setup_udp_tunnel_sock(net, sock, &tuncfg);
883965ae444SXin Long net->sctp.udp4_sock = sock->sk;
884965ae444SXin Long
8859d6ba260SXin Long #if IS_ENABLED(CONFIG_IPV6)
8869d6ba260SXin Long memset(&udp_conf, 0, sizeof(udp_conf));
8879d6ba260SXin Long
8889d6ba260SXin Long udp_conf.family = AF_INET6;
8899d6ba260SXin Long udp_conf.local_ip6 = in6addr_any;
8909d6ba260SXin Long udp_conf.local_udp_port = htons(net->sctp.udp_port);
8919d6ba260SXin Long udp_conf.use_udp6_rx_checksums = true;
8929d6ba260SXin Long udp_conf.ipv6_v6only = true;
8939d6ba260SXin Long err = udp_sock_create(net, &udp_conf, &sock);
8949d6ba260SXin Long if (err) {
8959d6ba260SXin Long pr_err("Failed to create the SCTP UDP tunneling v6 sock\n");
8969d6ba260SXin Long udp_tunnel_sock_release(net->sctp.udp4_sock->sk_socket);
8979d6ba260SXin Long net->sctp.udp4_sock = NULL;
8989d6ba260SXin Long return err;
8999d6ba260SXin Long }
9009d6ba260SXin Long
9019d6ba260SXin Long tuncfg.encap_type = 1;
9029d6ba260SXin Long tuncfg.encap_rcv = sctp_udp_rcv;
9039e47df00SXin Long tuncfg.encap_err_lookup = sctp_udp_v6_err;
9049d6ba260SXin Long setup_udp_tunnel_sock(net, sock, &tuncfg);
9059d6ba260SXin Long net->sctp.udp6_sock = sock->sk;
9069d6ba260SXin Long #endif
9079d6ba260SXin Long
908965ae444SXin Long return 0;
909965ae444SXin Long }
910965ae444SXin Long
sctp_udp_sock_stop(struct net * net)911965ae444SXin Long void sctp_udp_sock_stop(struct net *net)
912965ae444SXin Long {
913965ae444SXin Long if (net->sctp.udp4_sock) {
914965ae444SXin Long udp_tunnel_sock_release(net->sctp.udp4_sock->sk_socket);
915965ae444SXin Long net->sctp.udp4_sock = NULL;
916965ae444SXin Long }
9179d6ba260SXin Long if (net->sctp.udp6_sock) {
9189d6ba260SXin Long udp_tunnel_sock_release(net->sctp.udp6_sock->sk_socket);
9199d6ba260SXin Long net->sctp.udp6_sock = NULL;
9209d6ba260SXin Long }
921965ae444SXin Long }
922965ae444SXin Long
9231da177e4SLinus Torvalds /* Register address family specific functions. */
sctp_register_af(struct sctp_af * af)9241da177e4SLinus Torvalds int sctp_register_af(struct sctp_af *af)
9251da177e4SLinus Torvalds {
9261da177e4SLinus Torvalds switch (af->sa_family) {
9271da177e4SLinus Torvalds case AF_INET:
9281da177e4SLinus Torvalds if (sctp_af_v4_specific)
9291da177e4SLinus Torvalds return 0;
9301da177e4SLinus Torvalds sctp_af_v4_specific = af;
9311da177e4SLinus Torvalds break;
9321da177e4SLinus Torvalds case AF_INET6:
9331da177e4SLinus Torvalds if (sctp_af_v6_specific)
9341da177e4SLinus Torvalds return 0;
9351da177e4SLinus Torvalds sctp_af_v6_specific = af;
9361da177e4SLinus Torvalds break;
9371da177e4SLinus Torvalds default:
9381da177e4SLinus Torvalds return 0;
9391da177e4SLinus Torvalds }
9401da177e4SLinus Torvalds
9411da177e4SLinus Torvalds INIT_LIST_HEAD(&af->list);
9421da177e4SLinus Torvalds list_add_tail(&af->list, &sctp_address_families);
9431da177e4SLinus Torvalds return 1;
9441da177e4SLinus Torvalds }
9451da177e4SLinus Torvalds
9461da177e4SLinus Torvalds /* Get the table of functions for manipulating a particular address
9471da177e4SLinus Torvalds * family.
9481da177e4SLinus Torvalds */
sctp_get_af_specific(sa_family_t family)9491da177e4SLinus Torvalds struct sctp_af *sctp_get_af_specific(sa_family_t family)
9501da177e4SLinus Torvalds {
9511da177e4SLinus Torvalds switch (family) {
9521da177e4SLinus Torvalds case AF_INET:
9531da177e4SLinus Torvalds return sctp_af_v4_specific;
9541da177e4SLinus Torvalds case AF_INET6:
9551da177e4SLinus Torvalds return sctp_af_v6_specific;
9561da177e4SLinus Torvalds default:
9571da177e4SLinus Torvalds return NULL;
9581da177e4SLinus Torvalds }
9591da177e4SLinus Torvalds }
9601da177e4SLinus Torvalds
9611da177e4SLinus Torvalds /* Common code to initialize a AF_INET msg_name. */
sctp_inet_msgname(char * msgname,int * addr_len)9621da177e4SLinus Torvalds static void sctp_inet_msgname(char *msgname, int *addr_len)
9631da177e4SLinus Torvalds {
9641da177e4SLinus Torvalds struct sockaddr_in *sin;
9651da177e4SLinus Torvalds
9661da177e4SLinus Torvalds sin = (struct sockaddr_in *)msgname;
9671da177e4SLinus Torvalds *addr_len = sizeof(struct sockaddr_in);
9681da177e4SLinus Torvalds sin->sin_family = AF_INET;
9691da177e4SLinus Torvalds memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
9701da177e4SLinus Torvalds }
9711da177e4SLinus Torvalds
9721da177e4SLinus Torvalds /* Copy the primary address of the peer primary address as the msg_name. */
sctp_inet_event_msgname(struct sctp_ulpevent * event,char * msgname,int * addr_len)9731da177e4SLinus Torvalds static void sctp_inet_event_msgname(struct sctp_ulpevent *event, char *msgname,
9741da177e4SLinus Torvalds int *addr_len)
9751da177e4SLinus Torvalds {
9761da177e4SLinus Torvalds struct sockaddr_in *sin, *sinfrom;
9771da177e4SLinus Torvalds
9781da177e4SLinus Torvalds if (msgname) {
9791da177e4SLinus Torvalds struct sctp_association *asoc;
9801da177e4SLinus Torvalds
9811da177e4SLinus Torvalds asoc = event->asoc;
9821da177e4SLinus Torvalds sctp_inet_msgname(msgname, addr_len);
9831da177e4SLinus Torvalds sin = (struct sockaddr_in *)msgname;
9841da177e4SLinus Torvalds sinfrom = &asoc->peer.primary_addr.v4;
9851da177e4SLinus Torvalds sin->sin_port = htons(asoc->peer.port);
9861da177e4SLinus Torvalds sin->sin_addr.s_addr = sinfrom->sin_addr.s_addr;
9871da177e4SLinus Torvalds }
9881da177e4SLinus Torvalds }
9891da177e4SLinus Torvalds
9901da177e4SLinus Torvalds /* Initialize and copy out a msgname from an inbound skb. */
sctp_inet_skb_msgname(struct sk_buff * skb,char * msgname,int * len)9911da177e4SLinus Torvalds static void sctp_inet_skb_msgname(struct sk_buff *skb, char *msgname, int *len)
9921da177e4SLinus Torvalds {
9931da177e4SLinus Torvalds if (msgname) {
9942c0fd387SArnaldo Carvalho de Melo struct sctphdr *sh = sctp_hdr(skb);
9952c0fd387SArnaldo Carvalho de Melo struct sockaddr_in *sin = (struct sockaddr_in *)msgname;
9962c0fd387SArnaldo Carvalho de Melo
9971da177e4SLinus Torvalds sctp_inet_msgname(msgname, len);
9981da177e4SLinus Torvalds sin->sin_port = sh->source;
999eddc9ec5SArnaldo Carvalho de Melo sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
10001da177e4SLinus Torvalds }
10011da177e4SLinus Torvalds }
10021da177e4SLinus Torvalds
10031da177e4SLinus Torvalds /* Do we support this AF? */
sctp_inet_af_supported(sa_family_t family,struct sctp_sock * sp)10041da177e4SLinus Torvalds static int sctp_inet_af_supported(sa_family_t family, struct sctp_sock *sp)
10051da177e4SLinus Torvalds {
10061da177e4SLinus Torvalds /* PF_INET only supports AF_INET addresses. */
1007a02cec21SEric Dumazet return AF_INET == family;
10081da177e4SLinus Torvalds }
10091da177e4SLinus Torvalds
10101da177e4SLinus Torvalds /* Address matching with wildcards allowed. */
sctp_inet_cmp_addr(const union sctp_addr * addr1,const union sctp_addr * addr2,struct sctp_sock * opt)10111da177e4SLinus Torvalds static int sctp_inet_cmp_addr(const union sctp_addr *addr1,
10121da177e4SLinus Torvalds const union sctp_addr *addr2,
10131da177e4SLinus Torvalds struct sctp_sock *opt)
10141da177e4SLinus Torvalds {
10151da177e4SLinus Torvalds /* PF_INET only supports AF_INET addresses. */
10161da177e4SLinus Torvalds if (addr1->sa.sa_family != addr2->sa.sa_family)
10171da177e4SLinus Torvalds return 0;
1018e6f1cebfSAl Viro if (htonl(INADDR_ANY) == addr1->v4.sin_addr.s_addr ||
1019e6f1cebfSAl Viro htonl(INADDR_ANY) == addr2->v4.sin_addr.s_addr)
10201da177e4SLinus Torvalds return 1;
10211da177e4SLinus Torvalds if (addr1->v4.sin_addr.s_addr == addr2->v4.sin_addr.s_addr)
10221da177e4SLinus Torvalds return 1;
10231da177e4SLinus Torvalds
10241da177e4SLinus Torvalds return 0;
10251da177e4SLinus Torvalds }
10261da177e4SLinus Torvalds
10271da177e4SLinus Torvalds /* Verify that provided sockaddr looks bindable. Common verification has
10281da177e4SLinus Torvalds * already been taken care of.
10291da177e4SLinus Torvalds */
sctp_inet_bind_verify(struct sctp_sock * opt,union sctp_addr * addr)10301da177e4SLinus Torvalds static int sctp_inet_bind_verify(struct sctp_sock *opt, union sctp_addr *addr)
10311da177e4SLinus Torvalds {
10321da177e4SLinus Torvalds return sctp_v4_available(addr, opt);
10331da177e4SLinus Torvalds }
10341da177e4SLinus Torvalds
10351da177e4SLinus Torvalds /* Verify that sockaddr looks sendable. Common verification has already
10361da177e4SLinus Torvalds * been taken care of.
10371da177e4SLinus Torvalds */
sctp_inet_send_verify(struct sctp_sock * opt,union sctp_addr * addr)10381da177e4SLinus Torvalds static int sctp_inet_send_verify(struct sctp_sock *opt, union sctp_addr *addr)
10391da177e4SLinus Torvalds {
10401da177e4SLinus Torvalds return 1;
10411da177e4SLinus Torvalds }
10421da177e4SLinus Torvalds
10431da177e4SLinus Torvalds /* Fill in Supported Address Type information for INIT and INIT-ACK
10441da177e4SLinus Torvalds * chunks. Returns number of addresses supported.
10451da177e4SLinus Torvalds */
sctp_inet_supported_addrs(const struct sctp_sock * opt,__be16 * types)10461da177e4SLinus Torvalds static int sctp_inet_supported_addrs(const struct sctp_sock *opt,
10473dbe8656SAl Viro __be16 *types)
10481da177e4SLinus Torvalds {
10491da177e4SLinus Torvalds types[0] = SCTP_PARAM_IPV4_ADDRESS;
10501da177e4SLinus Torvalds return 1;
10511da177e4SLinus Torvalds }
10521da177e4SLinus Torvalds
10531da177e4SLinus Torvalds /* Wrapper routine that calls the ip transmit routine. */
sctp_v4_xmit(struct sk_buff * skb,struct sctp_transport * t)1054600af7fdSXin Long static inline int sctp_v4_xmit(struct sk_buff *skb, struct sctp_transport *t)
10551da177e4SLinus Torvalds {
1056600af7fdSXin Long struct dst_entry *dst = dst_clone(t->dst);
1057600af7fdSXin Long struct flowi4 *fl4 = &t->fl.u.ip4;
1058600af7fdSXin Long struct sock *sk = skb->sk;
1059600af7fdSXin Long struct inet_sock *inet = inet_sk(sk);
10608a9c58d2SXin Long __u8 dscp = inet->tos;
1061600af7fdSXin Long __be16 df = 0;
1062f880374cSHerbert Xu
1063bb33381dSDaniel Borkmann pr_debug("%s: skb:%p, len:%d, src:%pI4, dst:%pI4\n", __func__, skb,
1064600af7fdSXin Long skb->len, &fl4->saddr, &fl4->daddr);
10658a9c58d2SXin Long
1066600af7fdSXin Long if (t->dscp & SCTP_DSCP_SET_MASK)
1067600af7fdSXin Long dscp = t->dscp & SCTP_DSCP_VAL_MASK;
10681da177e4SLinus Torvalds
1069600af7fdSXin Long inet->pmtudisc = t->param_flags & SPP_PMTUD_ENABLE ? IP_PMTUDISC_DO
1070600af7fdSXin Long : IP_PMTUDISC_DONT;
1071600af7fdSXin Long SCTP_INC_STATS(sock_net(sk), SCTP_MIB_OUTSCTPPACKS);
1072f880374cSHerbert Xu
1073600af7fdSXin Long if (!t->encap_port || !sctp_sk(sk)->udp_port) {
1074600af7fdSXin Long skb_dst_set(skb, dst);
1075600af7fdSXin Long return __ip_queue_xmit(sk, skb, &t->fl, dscp);
1076600af7fdSXin Long }
1077bb33381dSDaniel Borkmann
1078600af7fdSXin Long if (skb_is_gso(skb))
1079600af7fdSXin Long skb_shinfo(skb)->gso_type |= SKB_GSO_UDP_TUNNEL_CSUM;
1080600af7fdSXin Long
1081600af7fdSXin Long if (ip_dont_fragment(sk, dst) && !skb->ignore_df)
1082600af7fdSXin Long df = htons(IP_DF);
1083600af7fdSXin Long
1084600af7fdSXin Long skb->encapsulation = 1;
1085600af7fdSXin Long skb_reset_inner_mac_header(skb);
1086600af7fdSXin Long skb_reset_inner_transport_header(skb);
1087600af7fdSXin Long skb_set_inner_ipproto(skb, IPPROTO_SCTP);
1088600af7fdSXin Long udp_tunnel_xmit_skb((struct rtable *)dst, sk, skb, fl4->saddr,
1089600af7fdSXin Long fl4->daddr, dscp, ip4_dst_hoplimit(dst), df,
1090600af7fdSXin Long sctp_sk(sk)->udp_port, t->encap_port, false, false);
1091600af7fdSXin Long return 0;
10921da177e4SLinus Torvalds }
10931da177e4SLinus Torvalds
109415efbe76SNeil Horman static struct sctp_af sctp_af_inet;
10951da177e4SLinus Torvalds
10961da177e4SLinus Torvalds static struct sctp_pf sctp_pf_inet = {
10971da177e4SLinus Torvalds .event_msgname = sctp_inet_event_msgname,
10981da177e4SLinus Torvalds .skb_msgname = sctp_inet_skb_msgname,
10991da177e4SLinus Torvalds .af_supported = sctp_inet_af_supported,
11001da177e4SLinus Torvalds .cmp_addr = sctp_inet_cmp_addr,
11011da177e4SLinus Torvalds .bind_verify = sctp_inet_bind_verify,
11021da177e4SLinus Torvalds .send_verify = sctp_inet_send_verify,
11031da177e4SLinus Torvalds .supported_addrs = sctp_inet_supported_addrs,
11041da177e4SLinus Torvalds .create_accept_sk = sctp_v4_create_accept_sk,
1105299ee123SJason Gunthorpe .addr_to_user = sctp_v4_addr_to_user,
1106299ee123SJason Gunthorpe .to_sk_saddr = sctp_v4_to_sk_saddr,
1107299ee123SJason Gunthorpe .to_sk_daddr = sctp_v4_to_sk_daddr,
1108b7e10c25SRichard Haines .copy_ip_options = sctp_v4_copy_ip_options,
110915efbe76SNeil Horman .af = &sctp_af_inet
11101da177e4SLinus Torvalds };
11111da177e4SLinus Torvalds
11121da177e4SLinus Torvalds /* Notifier for inetaddr addition/deletion events. */
11131da177e4SLinus Torvalds static struct notifier_block sctp_inetaddr_notifier = {
11141da177e4SLinus Torvalds .notifier_call = sctp_inetaddr_event,
11151da177e4SLinus Torvalds };
11161da177e4SLinus Torvalds
11171da177e4SLinus Torvalds /* Socket operations. */
111890ddc4f0SEric Dumazet static const struct proto_ops inet_seqpacket_ops = {
11191da177e4SLinus Torvalds .family = PF_INET,
11201da177e4SLinus Torvalds .owner = THIS_MODULE,
11211da177e4SLinus Torvalds .release = inet_release, /* Needs to be wrapped... */
11221da177e4SLinus Torvalds .bind = inet_bind,
1123644fbdeaSXin Long .connect = sctp_inet_connect,
11241da177e4SLinus Torvalds .socketpair = sock_no_socketpair,
11251da177e4SLinus Torvalds .accept = inet_accept,
11261da177e4SLinus Torvalds .getname = inet_getname, /* Semantics are different. */
1127a11e1d43SLinus Torvalds .poll = sctp_poll,
11281da177e4SLinus Torvalds .ioctl = inet_ioctl,
1129c7cbdbf2SArnd Bergmann .gettstamp = sock_gettstamp,
11301da177e4SLinus Torvalds .listen = sctp_inet_listen,
11311da177e4SLinus Torvalds .shutdown = inet_shutdown, /* Looks harmless. */
1132543d9cfeSArnaldo Carvalho de Melo .setsockopt = sock_common_setsockopt, /* IP_SOL IP_OPTION is a problem */
11331da177e4SLinus Torvalds .getsockopt = sock_common_getsockopt,
11341da177e4SLinus Torvalds .sendmsg = inet_sendmsg,
1135fd2d180aSXin Long .recvmsg = inet_recvmsg,
11361da177e4SLinus Torvalds .mmap = sock_no_mmap,
11371da177e4SLinus Torvalds };
11381da177e4SLinus Torvalds
11391da177e4SLinus Torvalds /* Registration with AF_INET family. */
11401da177e4SLinus Torvalds static struct inet_protosw sctp_seqpacket_protosw = {
11411da177e4SLinus Torvalds .type = SOCK_SEQPACKET,
11421da177e4SLinus Torvalds .protocol = IPPROTO_SCTP,
11431da177e4SLinus Torvalds .prot = &sctp_prot,
11441da177e4SLinus Torvalds .ops = &inet_seqpacket_ops,
11451da177e4SLinus Torvalds .flags = SCTP_PROTOSW_FLAG
11461da177e4SLinus Torvalds };
11471da177e4SLinus Torvalds static struct inet_protosw sctp_stream_protosw = {
11481da177e4SLinus Torvalds .type = SOCK_STREAM,
11491da177e4SLinus Torvalds .protocol = IPPROTO_SCTP,
11501da177e4SLinus Torvalds .prot = &sctp_prot,
11511da177e4SLinus Torvalds .ops = &inet_seqpacket_ops,
11521da177e4SLinus Torvalds .flags = SCTP_PROTOSW_FLAG
11531da177e4SLinus Torvalds };
11541da177e4SLinus Torvalds
sctp4_rcv(struct sk_buff * skb)1155a1dd2cf2SXin Long static int sctp4_rcv(struct sk_buff *skb)
1156a1dd2cf2SXin Long {
11570356010dSXin Long SCTP_INPUT_CB(skb)->encap_port = 0;
1158a1dd2cf2SXin Long return sctp_rcv(skb);
1159a1dd2cf2SXin Long }
1160a1dd2cf2SXin Long
11611da177e4SLinus Torvalds /* Register with IP layer. */
116232613090SAlexey Dobriyan static const struct net_protocol sctp_protocol = {
1163a1dd2cf2SXin Long .handler = sctp4_rcv,
11641da177e4SLinus Torvalds .err_handler = sctp_v4_err,
11651da177e4SLinus Torvalds .no_policy = 1,
11668ed1dc44SHannes Frederic Sowa .icmp_strict_tag_validation = 1,
11671da177e4SLinus Torvalds };
11681da177e4SLinus Torvalds
11691da177e4SLinus Torvalds /* IPv4 address related functions. */
117015efbe76SNeil Horman static struct sctp_af sctp_af_inet = {
1171543d9cfeSArnaldo Carvalho de Melo .sa_family = AF_INET,
11721da177e4SLinus Torvalds .sctp_xmit = sctp_v4_xmit,
11731da177e4SLinus Torvalds .setsockopt = ip_setsockopt,
11741da177e4SLinus Torvalds .getsockopt = ip_getsockopt,
11751da177e4SLinus Torvalds .get_dst = sctp_v4_get_dst,
11761da177e4SLinus Torvalds .get_saddr = sctp_v4_get_saddr,
11771da177e4SLinus Torvalds .copy_addrlist = sctp_v4_copy_addrlist,
11781da177e4SLinus Torvalds .from_skb = sctp_v4_from_skb,
11791da177e4SLinus Torvalds .from_sk = sctp_v4_from_sk,
11801da177e4SLinus Torvalds .from_addr_param = sctp_v4_from_addr_param,
11811da177e4SLinus Torvalds .to_addr_param = sctp_v4_to_addr_param,
11821da177e4SLinus Torvalds .cmp_addr = sctp_v4_cmp_addr,
11831da177e4SLinus Torvalds .addr_valid = sctp_v4_addr_valid,
11841da177e4SLinus Torvalds .inaddr_any = sctp_v4_inaddr_any,
11851da177e4SLinus Torvalds .is_any = sctp_v4_is_any,
11861da177e4SLinus Torvalds .available = sctp_v4_available,
11871da177e4SLinus Torvalds .scope = sctp_v4_scope,
11881da177e4SLinus Torvalds .skb_iif = sctp_v4_skb_iif,
118933e93ed2SXin Long .skb_sdif = sctp_v4_skb_sdif,
11901da177e4SLinus Torvalds .is_ce = sctp_v4_is_ce,
11911da177e4SLinus Torvalds .seq_dump_addr = sctp_v4_seq_dump_addr,
1192b9031d9dSVlad Yasevich .ecn_capable = sctp_v4_ecn_capable,
11931da177e4SLinus Torvalds .net_header_len = sizeof(struct iphdr),
11941da177e4SLinus Torvalds .sockaddr_len = sizeof(struct sockaddr_in),
1195b7e10c25SRichard Haines .ip_options_len = sctp_v4_ip_options_len,
11961da177e4SLinus Torvalds };
11971da177e4SLinus Torvalds
sctp_get_pf_specific(sa_family_t family)11988d72651dSwangweidong struct sctp_pf *sctp_get_pf_specific(sa_family_t family)
11998d72651dSwangweidong {
12001da177e4SLinus Torvalds switch (family) {
12011da177e4SLinus Torvalds case PF_INET:
12021da177e4SLinus Torvalds return sctp_pf_inet_specific;
12031da177e4SLinus Torvalds case PF_INET6:
12041da177e4SLinus Torvalds return sctp_pf_inet6_specific;
12051da177e4SLinus Torvalds default:
12061da177e4SLinus Torvalds return NULL;
12071da177e4SLinus Torvalds }
12081da177e4SLinus Torvalds }
12091da177e4SLinus Torvalds
12101da177e4SLinus Torvalds /* Register the PF specific function table. */
sctp_register_pf(struct sctp_pf * pf,sa_family_t family)12111da177e4SLinus Torvalds int sctp_register_pf(struct sctp_pf *pf, sa_family_t family)
12121da177e4SLinus Torvalds {
12131da177e4SLinus Torvalds switch (family) {
12141da177e4SLinus Torvalds case PF_INET:
12151da177e4SLinus Torvalds if (sctp_pf_inet_specific)
12161da177e4SLinus Torvalds return 0;
12171da177e4SLinus Torvalds sctp_pf_inet_specific = pf;
12181da177e4SLinus Torvalds break;
12191da177e4SLinus Torvalds case PF_INET6:
12201da177e4SLinus Torvalds if (sctp_pf_inet6_specific)
12211da177e4SLinus Torvalds return 0;
12221da177e4SLinus Torvalds sctp_pf_inet6_specific = pf;
12231da177e4SLinus Torvalds break;
12241da177e4SLinus Torvalds default:
12251da177e4SLinus Torvalds return 0;
12261da177e4SLinus Torvalds }
12271da177e4SLinus Torvalds return 1;
12281da177e4SLinus Torvalds }
12291da177e4SLinus Torvalds
init_sctp_mibs(struct net * net)1230b01a2407SEric W. Biederman static inline int init_sctp_mibs(struct net *net)
12311da177e4SLinus Torvalds {
1232698365faSWANG Cong net->sctp.sctp_statistics = alloc_percpu(struct sctp_mib);
1233698365faSWANG Cong if (!net->sctp.sctp_statistics)
1234698365faSWANG Cong return -ENOMEM;
1235698365faSWANG Cong return 0;
12361da177e4SLinus Torvalds }
12371da177e4SLinus Torvalds
cleanup_sctp_mibs(struct net * net)1238b01a2407SEric W. Biederman static inline void cleanup_sctp_mibs(struct net *net)
12391da177e4SLinus Torvalds {
1240698365faSWANG Cong free_percpu(net->sctp.sctp_statistics);
12411da177e4SLinus Torvalds }
12421da177e4SLinus Torvalds
sctp_v4_pf_init(void)1243270637abSVlad Yasevich static void sctp_v4_pf_init(void)
1244270637abSVlad Yasevich {
1245270637abSVlad Yasevich /* Initialize the SCTP specific PF functions. */
1246270637abSVlad Yasevich sctp_register_pf(&sctp_pf_inet, PF_INET);
1247270637abSVlad Yasevich sctp_register_af(&sctp_af_inet);
1248270637abSVlad Yasevich }
1249270637abSVlad Yasevich
sctp_v4_pf_exit(void)1250270637abSVlad Yasevich static void sctp_v4_pf_exit(void)
1251270637abSVlad Yasevich {
1252270637abSVlad Yasevich list_del(&sctp_af_inet.list);
1253270637abSVlad Yasevich }
1254270637abSVlad Yasevich
sctp_v4_protosw_init(void)1255270637abSVlad Yasevich static int sctp_v4_protosw_init(void)
1256270637abSVlad Yasevich {
1257270637abSVlad Yasevich int rc;
1258270637abSVlad Yasevich
1259270637abSVlad Yasevich rc = proto_register(&sctp_prot, 1);
1260270637abSVlad Yasevich if (rc)
1261270637abSVlad Yasevich return rc;
1262270637abSVlad Yasevich
1263270637abSVlad Yasevich /* Register SCTP(UDP and TCP style) with socket layer. */
1264270637abSVlad Yasevich inet_register_protosw(&sctp_seqpacket_protosw);
1265270637abSVlad Yasevich inet_register_protosw(&sctp_stream_protosw);
1266270637abSVlad Yasevich
1267270637abSVlad Yasevich return 0;
1268270637abSVlad Yasevich }
1269270637abSVlad Yasevich
sctp_v4_protosw_exit(void)1270270637abSVlad Yasevich static void sctp_v4_protosw_exit(void)
1271270637abSVlad Yasevich {
1272270637abSVlad Yasevich inet_unregister_protosw(&sctp_stream_protosw);
1273270637abSVlad Yasevich inet_unregister_protosw(&sctp_seqpacket_protosw);
1274270637abSVlad Yasevich proto_unregister(&sctp_prot);
1275270637abSVlad Yasevich }
1276270637abSVlad Yasevich
sctp_v4_add_protocol(void)1277270637abSVlad Yasevich static int sctp_v4_add_protocol(void)
1278270637abSVlad Yasevich {
1279270637abSVlad Yasevich /* Register notifier for inet address additions/deletions. */
1280270637abSVlad Yasevich register_inetaddr_notifier(&sctp_inetaddr_notifier);
1281270637abSVlad Yasevich
1282270637abSVlad Yasevich /* Register SCTP with inet layer. */
1283270637abSVlad Yasevich if (inet_add_protocol(&sctp_protocol, IPPROTO_SCTP) < 0)
1284270637abSVlad Yasevich return -EAGAIN;
1285270637abSVlad Yasevich
1286270637abSVlad Yasevich return 0;
1287270637abSVlad Yasevich }
1288270637abSVlad Yasevich
sctp_v4_del_protocol(void)1289270637abSVlad Yasevich static void sctp_v4_del_protocol(void)
1290270637abSVlad Yasevich {
1291270637abSVlad Yasevich inet_del_protocol(&sctp_protocol, IPPROTO_SCTP);
1292270637abSVlad Yasevich unregister_inetaddr_notifier(&sctp_inetaddr_notifier);
1293270637abSVlad Yasevich }
1294270637abSVlad Yasevich
sctp_defaults_init(struct net * net)12958e2d61e0SMarcelo Ricardo Leitner static int __net_init sctp_defaults_init(struct net *net)
12964db67e80SEric W. Biederman {
12972ce95503SEric W. Biederman int status;
12982ce95503SEric W. Biederman
1299e1fc3b14SEric W. Biederman /*
1300e1fc3b14SEric W. Biederman * 14. Suggested SCTP Protocol Parameter Values
1301e1fc3b14SEric W. Biederman */
1302e1fc3b14SEric W. Biederman /* The following protocol parameters are RECOMMENDED: */
1303e1fc3b14SEric W. Biederman /* RTO.Initial - 3 seconds */
1304e1fc3b14SEric W. Biederman net->sctp.rto_initial = SCTP_RTO_INITIAL;
1305e1fc3b14SEric W. Biederman /* RTO.Min - 1 second */
1306e1fc3b14SEric W. Biederman net->sctp.rto_min = SCTP_RTO_MIN;
1307e1fc3b14SEric W. Biederman /* RTO.Max - 60 seconds */
1308e1fc3b14SEric W. Biederman net->sctp.rto_max = SCTP_RTO_MAX;
1309e1fc3b14SEric W. Biederman /* RTO.Alpha - 1/8 */
1310e1fc3b14SEric W. Biederman net->sctp.rto_alpha = SCTP_RTO_ALPHA;
1311e1fc3b14SEric W. Biederman /* RTO.Beta - 1/4 */
1312e1fc3b14SEric W. Biederman net->sctp.rto_beta = SCTP_RTO_BETA;
1313e1fc3b14SEric W. Biederman
1314e1fc3b14SEric W. Biederman /* Valid.Cookie.Life - 60 seconds */
1315e1fc3b14SEric W. Biederman net->sctp.valid_cookie_life = SCTP_DEFAULT_COOKIE_LIFE;
1316e1fc3b14SEric W. Biederman
1317e1fc3b14SEric W. Biederman /* Whether Cookie Preservative is enabled(1) or not(0) */
1318e1fc3b14SEric W. Biederman net->sctp.cookie_preserve_enable = 1;
1319e1fc3b14SEric W. Biederman
13203c68198eSNeil Horman /* Default sctp sockets to use md5 as their hmac alg */
13210d0863b0SNeil Horman #if defined (CONFIG_SCTP_DEFAULT_COOKIE_HMAC_MD5)
13223c68198eSNeil Horman net->sctp.sctp_hmac_alg = "md5";
13230d0863b0SNeil Horman #elif defined (CONFIG_SCTP_DEFAULT_COOKIE_HMAC_SHA1)
13243c68198eSNeil Horman net->sctp.sctp_hmac_alg = "sha1";
13253c68198eSNeil Horman #else
13263c68198eSNeil Horman net->sctp.sctp_hmac_alg = NULL;
13273c68198eSNeil Horman #endif
13283c68198eSNeil Horman
1329e1fc3b14SEric W. Biederman /* Max.Burst - 4 */
1330e1fc3b14SEric W. Biederman net->sctp.max_burst = SCTP_DEFAULT_MAX_BURST;
1331e1fc3b14SEric W. Biederman
133234515e94SXin Long /* Disable of Primary Path Switchover by default */
133334515e94SXin Long net->sctp.ps_retrans = SCTP_PS_RETRANS_MAX;
133434515e94SXin Long
1335566178f8SZhu Yanjun /* Enable pf state by default */
1336566178f8SZhu Yanjun net->sctp.pf_enable = 1;
1337566178f8SZhu Yanjun
1338aef587beSXin Long /* Ignore pf exposure feature by default */
1339aef587beSXin Long net->sctp.pf_expose = SCTP_PF_EXPOSE_UNSET;
1340aef587beSXin Long
1341e1fc3b14SEric W. Biederman /* Association.Max.Retrans - 10 attempts
1342e1fc3b14SEric W. Biederman * Path.Max.Retrans - 5 attempts (per destination address)
1343e1fc3b14SEric W. Biederman * Max.Init.Retransmits - 8 attempts
1344e1fc3b14SEric W. Biederman */
1345e1fc3b14SEric W. Biederman net->sctp.max_retrans_association = 10;
1346e1fc3b14SEric W. Biederman net->sctp.max_retrans_path = 5;
1347e1fc3b14SEric W. Biederman net->sctp.max_retrans_init = 8;
1348e1fc3b14SEric W. Biederman
1349e1fc3b14SEric W. Biederman /* Sendbuffer growth - do per-socket accounting */
1350e1fc3b14SEric W. Biederman net->sctp.sndbuf_policy = 0;
1351e1fc3b14SEric W. Biederman
1352e1fc3b14SEric W. Biederman /* Rcvbuffer growth - do per-socket accounting */
1353e1fc3b14SEric W. Biederman net->sctp.rcvbuf_policy = 0;
1354e1fc3b14SEric W. Biederman
1355e1fc3b14SEric W. Biederman /* HB.interval - 30 seconds */
1356e1fc3b14SEric W. Biederman net->sctp.hb_interval = SCTP_DEFAULT_TIMEOUT_HEARTBEAT;
1357e1fc3b14SEric W. Biederman
1358e1fc3b14SEric W. Biederman /* delayed SACK timeout */
1359e1fc3b14SEric W. Biederman net->sctp.sack_timeout = SCTP_DEFAULT_TIMEOUT_SACK;
1360e1fc3b14SEric W. Biederman
1361e1fc3b14SEric W. Biederman /* Disable ADDIP by default. */
1362e1fc3b14SEric W. Biederman net->sctp.addip_enable = 0;
1363e1fc3b14SEric W. Biederman net->sctp.addip_noauth = 0;
1364e1fc3b14SEric W. Biederman net->sctp.default_auto_asconf = 0;
1365e1fc3b14SEric W. Biederman
1366e1fc3b14SEric W. Biederman /* Enable PR-SCTP by default. */
1367e1fc3b14SEric W. Biederman net->sctp.prsctp_enable = 1;
1368e1fc3b14SEric W. Biederman
1369c28445c3SXin Long /* Disable RECONF by default. */
1370c28445c3SXin Long net->sctp.reconf_enable = 0;
1371c28445c3SXin Long
1372e1fc3b14SEric W. Biederman /* Disable AUTH by default. */
1373e1fc3b14SEric W. Biederman net->sctp.auth_enable = 0;
1374e1fc3b14SEric W. Biederman
13751b0b8114SXin Long /* Enable ECN by default. */
13761b0b8114SXin Long net->sctp.ecn_enable = 1;
13771b0b8114SXin Long
1378965ae444SXin Long /* Set UDP tunneling listening port to 0 by default */
1379965ae444SXin Long net->sctp.udp_port = 0;
1380965ae444SXin Long
1381e8a3001cSXin Long /* Set remote encap port to 0 by default */
1382e8a3001cSXin Long net->sctp.encap_port = 0;
1383e8a3001cSXin Long
1384e1fc3b14SEric W. Biederman /* Set SCOPE policy to enabled */
1385e1fc3b14SEric W. Biederman net->sctp.scope_policy = SCTP_SCOPE_POLICY_ENABLE;
1386e1fc3b14SEric W. Biederman
1387e1fc3b14SEric W. Biederman /* Set the default rwnd update threshold */
1388e1fc3b14SEric W. Biederman net->sctp.rwnd_upd_shift = SCTP_DEFAULT_RWND_SHIFT;
1389e1fc3b14SEric W. Biederman
1390e1fc3b14SEric W. Biederman /* Initialize maximum autoclose timeout. */
1391e1fc3b14SEric W. Biederman net->sctp.max_autoclose = INT_MAX / HZ;
1392e1fc3b14SEric W. Biederman
13930af03170SXin Long #ifdef CONFIG_NET_L3_MASTER_DEV
13940af03170SXin Long net->sctp.l3mdev_accept = 1;
13950af03170SXin Long #endif
13960af03170SXin Long
1397ebb7e95dSEric W. Biederman status = sctp_sysctl_net_register(net);
1398ebb7e95dSEric W. Biederman if (status)
1399ebb7e95dSEric W. Biederman goto err_sysctl_register;
1400ebb7e95dSEric W. Biederman
1401b01a2407SEric W. Biederman /* Allocate and initialise sctp mibs. */
1402b01a2407SEric W. Biederman status = init_sctp_mibs(net);
1403b01a2407SEric W. Biederman if (status)
1404b01a2407SEric W. Biederman goto err_init_mibs;
1405b01a2407SEric W. Biederman
1406d47d08c8SAl Viro #ifdef CONFIG_PROC_FS
140713d782f6SEric W. Biederman /* Initialize proc fs directory. */
140813d782f6SEric W. Biederman status = sctp_proc_init(net);
140913d782f6SEric W. Biederman if (status)
141013d782f6SEric W. Biederman goto err_init_proc;
1411d47d08c8SAl Viro #endif
141213d782f6SEric W. Biederman
141313d782f6SEric W. Biederman sctp_dbg_objcnt_init(net);
141413d782f6SEric W. Biederman
14154db67e80SEric W. Biederman /* Initialize the local address list. */
14164db67e80SEric W. Biederman INIT_LIST_HEAD(&net->sctp.local_addr_list);
14174db67e80SEric W. Biederman spin_lock_init(&net->sctp.local_addr_lock);
14184db67e80SEric W. Biederman sctp_get_local_addr_list(net);
14194db67e80SEric W. Biederman
14204db67e80SEric W. Biederman /* Initialize the address event list */
14214db67e80SEric W. Biederman INIT_LIST_HEAD(&net->sctp.addr_waitq);
14224db67e80SEric W. Biederman INIT_LIST_HEAD(&net->sctp.auto_asconf_splist);
14234db67e80SEric W. Biederman spin_lock_init(&net->sctp.addr_wq_lock);
14244db67e80SEric W. Biederman net->sctp.addr_wq_timer.expires = 0;
14259c3b5751SKees Cook timer_setup(&net->sctp.addr_wq_timer, sctp_addr_wq_timeout_handler, 0);
14264db67e80SEric W. Biederman
14274db67e80SEric W. Biederman return 0;
14282ce95503SEric W. Biederman
14297ae665f1SArnd Bergmann #ifdef CONFIG_PROC_FS
143013d782f6SEric W. Biederman err_init_proc:
1431b01a2407SEric W. Biederman cleanup_sctp_mibs(net);
14327ae665f1SArnd Bergmann #endif
1433b01a2407SEric W. Biederman err_init_mibs:
1434ebb7e95dSEric W. Biederman sctp_sysctl_net_unregister(net);
1435ebb7e95dSEric W. Biederman err_sysctl_register:
14362ce95503SEric W. Biederman return status;
14374db67e80SEric W. Biederman }
14384db67e80SEric W. Biederman
sctp_defaults_exit(struct net * net)14398e2d61e0SMarcelo Ricardo Leitner static void __net_exit sctp_defaults_exit(struct net *net)
14404db67e80SEric W. Biederman {
14414db67e80SEric W. Biederman /* Free the local address list */
14424db67e80SEric W. Biederman sctp_free_addr_wq(net);
14434db67e80SEric W. Biederman sctp_free_local_addr_list(net);
14442ce95503SEric W. Biederman
1445d47d08c8SAl Viro #ifdef CONFIG_PROC_FS
1446d47d08c8SAl Viro remove_proc_subtree("sctp", net->proc_net);
1447d47d08c8SAl Viro net->sctp.proc_net_sctp = NULL;
1448d47d08c8SAl Viro #endif
1449b01a2407SEric W. Biederman cleanup_sctp_mibs(net);
1450ebb7e95dSEric W. Biederman sctp_sysctl_net_unregister(net);
14514db67e80SEric W. Biederman }
14524db67e80SEric W. Biederman
14538e2d61e0SMarcelo Ricardo Leitner static struct pernet_operations sctp_defaults_ops = {
14548e2d61e0SMarcelo Ricardo Leitner .init = sctp_defaults_init,
14558e2d61e0SMarcelo Ricardo Leitner .exit = sctp_defaults_exit,
14568e2d61e0SMarcelo Ricardo Leitner };
14578e2d61e0SMarcelo Ricardo Leitner
sctp_ctrlsock_init(struct net * net)14588e2d61e0SMarcelo Ricardo Leitner static int __net_init sctp_ctrlsock_init(struct net *net)
14598e2d61e0SMarcelo Ricardo Leitner {
14608e2d61e0SMarcelo Ricardo Leitner int status;
14618e2d61e0SMarcelo Ricardo Leitner
14628e2d61e0SMarcelo Ricardo Leitner /* Initialize the control inode/socket for handling OOTB packets. */
14638e2d61e0SMarcelo Ricardo Leitner status = sctp_ctl_sock_init(net);
14648e2d61e0SMarcelo Ricardo Leitner if (status)
14658e2d61e0SMarcelo Ricardo Leitner pr_err("Failed to initialize the SCTP control sock\n");
14668e2d61e0SMarcelo Ricardo Leitner
14678e2d61e0SMarcelo Ricardo Leitner return status;
14688e2d61e0SMarcelo Ricardo Leitner }
14698e2d61e0SMarcelo Ricardo Leitner
sctp_ctrlsock_exit(struct net * net)1470b456d724SChristophe JAILLET static void __net_exit sctp_ctrlsock_exit(struct net *net)
14718e2d61e0SMarcelo Ricardo Leitner {
14728e2d61e0SMarcelo Ricardo Leitner /* Free the control endpoint. */
14738e2d61e0SMarcelo Ricardo Leitner inet_ctl_sock_destroy(net->sctp.ctl_sock);
14748e2d61e0SMarcelo Ricardo Leitner }
14758e2d61e0SMarcelo Ricardo Leitner
14768e2d61e0SMarcelo Ricardo Leitner static struct pernet_operations sctp_ctrlsock_ops = {
14778e2d61e0SMarcelo Ricardo Leitner .init = sctp_ctrlsock_init,
14788e2d61e0SMarcelo Ricardo Leitner .exit = sctp_ctrlsock_exit,
14794db67e80SEric W. Biederman };
14804db67e80SEric W. Biederman
14811da177e4SLinus Torvalds /* Initialize the universe into something sensible. */
sctp_init(void)1482dda91928SDaniel Borkmann static __init int sctp_init(void)
14831da177e4SLinus Torvalds {
1484ca79b0c2SArun KS unsigned long nr_pages = totalram_pages();
1485623b57beSColin Ian King unsigned long limit;
1486623b57beSColin Ian King unsigned long goal;
1487d9749fb5SNeil Horman int max_entry_order;
1488623b57beSColin Ian King int num_entries;
1489623b57beSColin Ian King int max_share;
1490623b57beSColin Ian King int status;
1491623b57beSColin Ian King int order;
1492623b57beSColin Ian King int i;
14931da177e4SLinus Torvalds
1494b4772ef8SEyal Birger sock_skb_cb_check_size(sizeof(struct sctp_ulpevent));
14951da177e4SLinus Torvalds
1496827bf122SSridhar Samudrala /* Allocate bind_bucket and chunk caches. */
14971da177e4SLinus Torvalds status = -ENOBUFS;
14981da177e4SLinus Torvalds sctp_bucket_cachep = kmem_cache_create("sctp_bind_bucket",
14991da177e4SLinus Torvalds sizeof(struct sctp_bind_bucket),
15001da177e4SLinus Torvalds 0, SLAB_HWCACHE_ALIGN,
150120c2df83SPaul Mundt NULL);
15021da177e4SLinus Torvalds if (!sctp_bucket_cachep)
1503827bf122SSridhar Samudrala goto out;
15041da177e4SLinus Torvalds
15051da177e4SLinus Torvalds sctp_chunk_cachep = kmem_cache_create("sctp_chunk",
15061da177e4SLinus Torvalds sizeof(struct sctp_chunk),
15071da177e4SLinus Torvalds 0, SLAB_HWCACHE_ALIGN,
150820c2df83SPaul Mundt NULL);
15091da177e4SLinus Torvalds if (!sctp_chunk_cachep)
15101da177e4SLinus Torvalds goto err_chunk_cachep;
15111da177e4SLinus Torvalds
1512908c7f19STejun Heo status = percpu_counter_init(&sctp_sockets_allocated, 0, GFP_KERNEL);
1513632c928aSEric W. Biederman if (status)
1514632c928aSEric W. Biederman goto err_percpu_counter_init;
1515632c928aSEric W. Biederman
15161da177e4SLinus Torvalds /* Implementation specific variables. */
15171da177e4SLinus Torvalds
15181da177e4SLinus Torvalds /* Initialize default stream count setup information. */
15191da177e4SLinus Torvalds sctp_max_instreams = SCTP_DEFAULT_INSTREAMS;
15201da177e4SLinus Torvalds sctp_max_outstreams = SCTP_DEFAULT_OUTSTREAMS;
15211da177e4SLinus Torvalds
15221da177e4SLinus Torvalds /* Initialize handle used for association ids. */
15231da177e4SLinus Torvalds idr_init(&sctp_assocs_id);
15241da177e4SLinus Torvalds
1525f03d78dbSEric Dumazet limit = nr_free_buffer_pages() / 8;
15264d93df0aSNeil Horman limit = max(limit, 128UL);
15274d93df0aSNeil Horman sysctl_sctp_mem[0] = limit / 4 * 3;
15284d93df0aSNeil Horman sysctl_sctp_mem[1] = limit;
15294d93df0aSNeil Horman sysctl_sctp_mem[2] = sysctl_sctp_mem[0] * 2;
15304d93df0aSNeil Horman
15314d93df0aSNeil Horman /* Set per-socket limits to no more than 1/128 the pressure threshold*/
15324d93df0aSNeil Horman limit = (sysctl_sctp_mem[1]) << (PAGE_SHIFT - 7);
15334d93df0aSNeil Horman max_share = min(4UL*1024*1024, limit);
15344d93df0aSNeil Horman
1535100fdd1fSEric Dumazet sysctl_sctp_rmem[0] = PAGE_SIZE; /* give each asoc 1 page min */
153687fb4b7bSEric Dumazet sysctl_sctp_rmem[1] = 1500 * SKB_TRUESIZE(1);
15374d93df0aSNeil Horman sysctl_sctp_rmem[2] = max(sysctl_sctp_rmem[1], max_share);
15384d93df0aSNeil Horman
1539100fdd1fSEric Dumazet sysctl_sctp_wmem[0] = PAGE_SIZE;
15404d93df0aSNeil Horman sysctl_sctp_wmem[1] = 16*1024;
15414d93df0aSNeil Horman sysctl_sctp_wmem[2] = max(64*1024, max_share);
15424d93df0aSNeil Horman
15431da177e4SLinus Torvalds /* Size and allocate the association hash table.
15441da177e4SLinus Torvalds * The methodology is similar to that of the tcp hash tables.
1545d9749fb5SNeil Horman * Though not identical. Start by getting a goal size
15461da177e4SLinus Torvalds */
15473d6357deSArun KS if (nr_pages >= (128 * 1024))
15483d6357deSArun KS goal = nr_pages >> (22 - PAGE_SHIFT);
15491da177e4SLinus Torvalds else
15503d6357deSArun KS goal = nr_pages >> (24 - PAGE_SHIFT);
15511da177e4SLinus Torvalds
1552d9749fb5SNeil Horman /* Then compute the page order for said goal */
1553d9749fb5SNeil Horman order = get_order(goal);
1554d9749fb5SNeil Horman
1555d9749fb5SNeil Horman /* Now compute the required page order for the maximum sized table we
1556d9749fb5SNeil Horman * want to create
1557d9749fb5SNeil Horman */
1558d9749fb5SNeil Horman max_entry_order = get_order(MAX_SCTP_PORT_HASH_ENTRIES *
1559d9749fb5SNeil Horman sizeof(struct sctp_bind_hashbucket));
1560d9749fb5SNeil Horman
1561d9749fb5SNeil Horman /* Limit the page order by that maximum hash table size */
1562d9749fb5SNeil Horman order = min(order, max_entry_order);
15631da177e4SLinus Torvalds
15641da177e4SLinus Torvalds /* Allocate and initialize the endpoint hash table. */
15651da177e4SLinus Torvalds sctp_ep_hashsize = 64;
15663b77d661SZhang Yanfei sctp_ep_hashtable =
15676da2ec56SKees Cook kmalloc_array(64, sizeof(struct sctp_hashbucket), GFP_KERNEL);
15681da177e4SLinus Torvalds if (!sctp_ep_hashtable) {
1569145ce502SJoe Perches pr_err("Failed endpoint_hash alloc\n");
15701da177e4SLinus Torvalds status = -ENOMEM;
15711da177e4SLinus Torvalds goto err_ehash_alloc;
15721da177e4SLinus Torvalds }
15731da177e4SLinus Torvalds for (i = 0; i < sctp_ep_hashsize; i++) {
15741da177e4SLinus Torvalds rwlock_init(&sctp_ep_hashtable[i].lock);
1575d970dbf8SVlad Yasevich INIT_HLIST_HEAD(&sctp_ep_hashtable[i].chain);
15761da177e4SLinus Torvalds }
15771da177e4SLinus Torvalds
1578d9749fb5SNeil Horman /* Allocate and initialize the SCTP port hash table.
1579d9749fb5SNeil Horman * Note that order is initalized to start at the max sized
1580d9749fb5SNeil Horman * table we want to support. If we can't get that many pages
1581d9749fb5SNeil Horman * reduce the order and try again
1582d9749fb5SNeil Horman */
15831da177e4SLinus Torvalds do {
15841da177e4SLinus Torvalds sctp_port_hashtable = (struct sctp_bind_hashbucket *)
15856857a02aSEric Dumazet __get_free_pages(GFP_KERNEL | __GFP_NOWARN, order);
15861da177e4SLinus Torvalds } while (!sctp_port_hashtable && --order > 0);
1587d9749fb5SNeil Horman
15881da177e4SLinus Torvalds if (!sctp_port_hashtable) {
1589145ce502SJoe Perches pr_err("Failed bind hash alloc\n");
15901da177e4SLinus Torvalds status = -ENOMEM;
15911da177e4SLinus Torvalds goto err_bhash_alloc;
15921da177e4SLinus Torvalds }
1593d9749fb5SNeil Horman
1594d9749fb5SNeil Horman /* Now compute the number of entries that will fit in the
1595d9749fb5SNeil Horman * port hash space we allocated
1596d9749fb5SNeil Horman */
1597d9749fb5SNeil Horman num_entries = (1UL << order) * PAGE_SIZE /
1598d9749fb5SNeil Horman sizeof(struct sctp_bind_hashbucket);
1599d9749fb5SNeil Horman
160093c3216aSRandy Dunlap /* And finish by rounding it down to the nearest power of two.
160193c3216aSRandy Dunlap * This wastes some memory of course, but it's needed because
1602d9749fb5SNeil Horman * the hash function operates based on the assumption that
160393c3216aSRandy Dunlap * the number of entries is a power of two.
1604d9749fb5SNeil Horman */
1605d9749fb5SNeil Horman sctp_port_hashsize = rounddown_pow_of_two(num_entries);
1606d9749fb5SNeil Horman
16071da177e4SLinus Torvalds for (i = 0; i < sctp_port_hashsize; i++) {
16081da177e4SLinus Torvalds spin_lock_init(&sctp_port_hashtable[i].lock);
1609d970dbf8SVlad Yasevich INIT_HLIST_HEAD(&sctp_port_hashtable[i].chain);
16101da177e4SLinus Torvalds }
16111da177e4SLinus Torvalds
1612a5e27d18SWei Yongjun status = sctp_transport_hashtable_init();
1613a5e27d18SWei Yongjun if (status)
16144f008781SXin Long goto err_thash_alloc;
16154f008781SXin Long
1616d9749fb5SNeil Horman pr_info("Hash tables configured (bind %d/%d)\n", sctp_port_hashsize,
1617d9749fb5SNeil Horman num_entries);
16181da177e4SLinus Torvalds
16191da177e4SLinus Torvalds sctp_sysctl_register();
16201da177e4SLinus Torvalds
16211da177e4SLinus Torvalds INIT_LIST_HEAD(&sctp_address_families);
1622270637abSVlad Yasevich sctp_v4_pf_init();
1623270637abSVlad Yasevich sctp_v6_pf_init();
16241ba896f6SXin Long sctp_sched_ops_init();
16251da177e4SLinus Torvalds
16268e2d61e0SMarcelo Ricardo Leitner status = register_pernet_subsys(&sctp_defaults_ops);
16278e2d61e0SMarcelo Ricardo Leitner if (status)
16288e2d61e0SMarcelo Ricardo Leitner goto err_register_defaults;
1629270637abSVlad Yasevich
16308e2d61e0SMarcelo Ricardo Leitner status = sctp_v4_protosw_init();
1631827bf122SSridhar Samudrala if (status)
1632270637abSVlad Yasevich goto err_protosw_init;
1633827bf122SSridhar Samudrala
1634270637abSVlad Yasevich status = sctp_v6_protosw_init();
16351da177e4SLinus Torvalds if (status)
1636270637abSVlad Yasevich goto err_v6_protosw_init;
16371da177e4SLinus Torvalds
16388e2d61e0SMarcelo Ricardo Leitner status = register_pernet_subsys(&sctp_ctrlsock_ops);
16394db67e80SEric W. Biederman if (status)
16408e2d61e0SMarcelo Ricardo Leitner goto err_register_ctrlsock;
16414db67e80SEric W. Biederman
1642270637abSVlad Yasevich status = sctp_v4_add_protocol();
1643270637abSVlad Yasevich if (status)
1644827bf122SSridhar Samudrala goto err_add_protocol;
1645827bf122SSridhar Samudrala
1646827bf122SSridhar Samudrala /* Register SCTP with inet6 layer. */
1647827bf122SSridhar Samudrala status = sctp_v6_add_protocol();
1648827bf122SSridhar Samudrala if (status)
1649827bf122SSridhar Samudrala goto err_v6_add_protocol;
1650827bf122SSridhar Samudrala
165190017accSMarcelo Ricardo Leitner if (sctp_offload_init() < 0)
165290017accSMarcelo Ricardo Leitner pr_crit("%s: Cannot add SCTP protocol offload\n", __func__);
165390017accSMarcelo Ricardo Leitner
16541da177e4SLinus Torvalds out:
16551da177e4SLinus Torvalds return status;
1656827bf122SSridhar Samudrala err_v6_add_protocol:
1657270637abSVlad Yasevich sctp_v4_del_protocol();
1658d1dd5247SVlad Yasevich err_add_protocol:
16598e2d61e0SMarcelo Ricardo Leitner unregister_pernet_subsys(&sctp_ctrlsock_ops);
16608e2d61e0SMarcelo Ricardo Leitner err_register_ctrlsock:
1661270637abSVlad Yasevich sctp_v6_protosw_exit();
1662270637abSVlad Yasevich err_v6_protosw_init:
1663270637abSVlad Yasevich sctp_v4_protosw_exit();
1664270637abSVlad Yasevich err_protosw_init:
16658e2d61e0SMarcelo Ricardo Leitner unregister_pernet_subsys(&sctp_defaults_ops);
16668e2d61e0SMarcelo Ricardo Leitner err_register_defaults:
1667270637abSVlad Yasevich sctp_v4_pf_exit();
1668270637abSVlad Yasevich sctp_v6_pf_exit();
16691da177e4SLinus Torvalds sctp_sysctl_unregister();
16701da177e4SLinus Torvalds free_pages((unsigned long)sctp_port_hashtable,
16711da177e4SLinus Torvalds get_order(sctp_port_hashsize *
16721da177e4SLinus Torvalds sizeof(struct sctp_bind_hashbucket)));
16731da177e4SLinus Torvalds err_bhash_alloc:
16744f008781SXin Long sctp_transport_hashtable_destroy();
16754f008781SXin Long err_thash_alloc:
16761da177e4SLinus Torvalds kfree(sctp_ep_hashtable);
16771da177e4SLinus Torvalds err_ehash_alloc:
1678632c928aSEric W. Biederman percpu_counter_destroy(&sctp_sockets_allocated);
1679632c928aSEric W. Biederman err_percpu_counter_init:
16801da177e4SLinus Torvalds kmem_cache_destroy(sctp_chunk_cachep);
16811da177e4SLinus Torvalds err_chunk_cachep:
16821da177e4SLinus Torvalds kmem_cache_destroy(sctp_bucket_cachep);
16831da177e4SLinus Torvalds goto out;
16841da177e4SLinus Torvalds }
16851da177e4SLinus Torvalds
16861da177e4SLinus Torvalds /* Exit handler for the SCTP protocol. */
sctp_exit(void)1687dda91928SDaniel Borkmann static __exit void sctp_exit(void)
16881da177e4SLinus Torvalds {
16891da177e4SLinus Torvalds /* BUG. This should probably do something useful like clean
16901da177e4SLinus Torvalds * up all the remaining associations and all that memory.
16911da177e4SLinus Torvalds */
16921da177e4SLinus Torvalds
1693827bf122SSridhar Samudrala /* Unregister with inet6/inet layers. */
1694827bf122SSridhar Samudrala sctp_v6_del_protocol();
1695270637abSVlad Yasevich sctp_v4_del_protocol();
16961da177e4SLinus Torvalds
16978e2d61e0SMarcelo Ricardo Leitner unregister_pernet_subsys(&sctp_ctrlsock_ops);
16984db67e80SEric W. Biederman
1699270637abSVlad Yasevich /* Free protosw registrations */
1700270637abSVlad Yasevich sctp_v6_protosw_exit();
1701270637abSVlad Yasevich sctp_v4_protosw_exit();
1702270637abSVlad Yasevich
17038e2d61e0SMarcelo Ricardo Leitner unregister_pernet_subsys(&sctp_defaults_ops);
17048e2d61e0SMarcelo Ricardo Leitner
1705827bf122SSridhar Samudrala /* Unregister with socket layer. */
1706270637abSVlad Yasevich sctp_v6_pf_exit();
1707270637abSVlad Yasevich sctp_v4_pf_exit();
1708827bf122SSridhar Samudrala
17091da177e4SLinus Torvalds sctp_sysctl_unregister();
17101da177e4SLinus Torvalds
17111da177e4SLinus Torvalds free_pages((unsigned long)sctp_port_hashtable,
17121da177e4SLinus Torvalds get_order(sctp_port_hashsize *
17131da177e4SLinus Torvalds sizeof(struct sctp_bind_hashbucket)));
1714b5eff712SXin Long kfree(sctp_ep_hashtable);
17154f008781SXin Long sctp_transport_hashtable_destroy();
17161da177e4SLinus Torvalds
1717632c928aSEric W. Biederman percpu_counter_destroy(&sctp_sockets_allocated);
17181da177e4SLinus Torvalds
1719eaa184a1SJesper Dangaard Brouer rcu_barrier(); /* Wait for completion of call_rcu()'s */
1720eaa184a1SJesper Dangaard Brouer
1721827bf122SSridhar Samudrala kmem_cache_destroy(sctp_chunk_cachep);
1722827bf122SSridhar Samudrala kmem_cache_destroy(sctp_bucket_cachep);
17231da177e4SLinus Torvalds }
17241da177e4SLinus Torvalds
17251da177e4SLinus Torvalds module_init(sctp_init);
17261da177e4SLinus Torvalds module_exit(sctp_exit);
17271da177e4SLinus Torvalds
1728bb97d31fSArnaldo Carvalho de Melo /*
1729bb97d31fSArnaldo Carvalho de Melo * __stringify doesn't likes enums, so use IPPROTO_SCTP value (132) directly.
1730bb97d31fSArnaldo Carvalho de Melo */
1731bb97d31fSArnaldo Carvalho de Melo MODULE_ALIAS("net-pf-" __stringify(PF_INET) "-proto-132");
1732882a382cSSridhar Samudrala MODULE_ALIAS("net-pf-" __stringify(PF_INET6) "-proto-132");
173391705c61SDaniel Borkmann MODULE_AUTHOR("Linux Kernel SCTP developers <linux-sctp@vger.kernel.org>");
17341da177e4SLinus Torvalds MODULE_DESCRIPTION("Support for the SCTP protocol (RFC2960)");
173571acc0ddSDavid S. Miller module_param_named(no_checksums, sctp_checksum_disable, bool, 0644);
173671acc0ddSDavid S. Miller MODULE_PARM_DESC(no_checksums, "Disable checksums computing and verification");
17371da177e4SLinus Torvalds MODULE_LICENSE("GPL");
1738