160c778b2SVlad Yasevich /* SCTP kernel implementation 21da177e4SLinus Torvalds * (C) Copyright IBM Corp. 2002, 2004 31da177e4SLinus Torvalds * Copyright (c) 2001 Nokia, Inc. 41da177e4SLinus Torvalds * Copyright (c) 2001 La Monte H.P. Yarroll 51da177e4SLinus Torvalds * Copyright (c) 2002-2003 Intel Corp. 61da177e4SLinus Torvalds * 760c778b2SVlad Yasevich * This file is part of the SCTP kernel implementation 81da177e4SLinus Torvalds * 91da177e4SLinus Torvalds * SCTP over IPv6. 101da177e4SLinus Torvalds * 1160c778b2SVlad Yasevich * This SCTP implementation is free software; 121da177e4SLinus Torvalds * you can redistribute it and/or modify it under the terms of 131da177e4SLinus Torvalds * the GNU General Public License as published by 141da177e4SLinus Torvalds * the Free Software Foundation; either version 2, or (at your option) 151da177e4SLinus Torvalds * any later version. 161da177e4SLinus Torvalds * 1760c778b2SVlad Yasevich * This SCTP implementation is distributed in the hope that it 181da177e4SLinus Torvalds * will be useful, but WITHOUT ANY WARRANTY; without even the implied 191da177e4SLinus Torvalds * ************************ 201da177e4SLinus Torvalds * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 211da177e4SLinus Torvalds * See the GNU General Public License for more details. 221da177e4SLinus Torvalds * 231da177e4SLinus Torvalds * You should have received a copy of the GNU General Public License 241da177e4SLinus Torvalds * along with GNU CC; see the file COPYING. If not, write to 251da177e4SLinus Torvalds * the Free Software Foundation, 59 Temple Place - Suite 330, 261da177e4SLinus Torvalds * Boston, MA 02111-1307, USA. 271da177e4SLinus Torvalds * 281da177e4SLinus Torvalds * Please send any bug reports or fixes you make to the 291da177e4SLinus Torvalds * email address(es): 301da177e4SLinus Torvalds * lksctp developers <lksctp-developers@lists.sourceforge.net> 311da177e4SLinus Torvalds * 321da177e4SLinus Torvalds * Or submit a bug report through the following website: 331da177e4SLinus Torvalds * http://www.sf.net/projects/lksctp 341da177e4SLinus Torvalds * 351da177e4SLinus Torvalds * Written or modified by: 361da177e4SLinus Torvalds * Le Yanqun <yanqun.le@nokia.com> 371da177e4SLinus Torvalds * Hui Huang <hui.huang@nokia.com> 381da177e4SLinus Torvalds * La Monte H.P. Yarroll <piggy@acm.org> 391da177e4SLinus Torvalds * Sridhar Samudrala <sri@us.ibm.com> 401da177e4SLinus Torvalds * Jon Grimm <jgrimm@us.ibm.com> 411da177e4SLinus Torvalds * Ardelle Fan <ardelle.fan@intel.com> 421da177e4SLinus Torvalds * 431da177e4SLinus Torvalds * Based on: 441da177e4SLinus Torvalds * linux/net/ipv6/tcp_ipv6.c 451da177e4SLinus Torvalds * 461da177e4SLinus Torvalds * Any bugs reported given to us we will try to fix... any fixes shared will 471da177e4SLinus Torvalds * be incorporated into the next SCTP release. 481da177e4SLinus Torvalds */ 491da177e4SLinus Torvalds 50145ce502SJoe Perches #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 51145ce502SJoe Perches 521da177e4SLinus Torvalds #include <linux/module.h> 531da177e4SLinus Torvalds #include <linux/errno.h> 541da177e4SLinus Torvalds #include <linux/types.h> 551da177e4SLinus Torvalds #include <linux/socket.h> 561da177e4SLinus Torvalds #include <linux/sockios.h> 571da177e4SLinus Torvalds #include <linux/net.h> 581da177e4SLinus Torvalds #include <linux/in.h> 591da177e4SLinus Torvalds #include <linux/in6.h> 601da177e4SLinus Torvalds #include <linux/netdevice.h> 611da177e4SLinus Torvalds #include <linux/init.h> 621da177e4SLinus Torvalds #include <linux/ipsec.h> 635a0e3ad6STejun Heo #include <linux/slab.h> 641da177e4SLinus Torvalds 651da177e4SLinus Torvalds #include <linux/ipv6.h> 661da177e4SLinus Torvalds #include <linux/icmpv6.h> 671da177e4SLinus Torvalds #include <linux/random.h> 681da177e4SLinus Torvalds #include <linux/seq_file.h> 691da177e4SLinus Torvalds 701da177e4SLinus Torvalds #include <net/protocol.h> 711da177e4SLinus Torvalds #include <net/ndisc.h> 72c752f073SArnaldo Carvalho de Melo #include <net/ip.h> 731da177e4SLinus Torvalds #include <net/ipv6.h> 741da177e4SLinus Torvalds #include <net/transp_v6.h> 751da177e4SLinus Torvalds #include <net/addrconf.h> 761da177e4SLinus Torvalds #include <net/ip6_route.h> 771da177e4SLinus Torvalds #include <net/inet_common.h> 781da177e4SLinus Torvalds #include <net/inet_ecn.h> 791da177e4SLinus Torvalds #include <net/sctp/sctp.h> 801da177e4SLinus Torvalds 811da177e4SLinus Torvalds #include <asm/uaccess.h> 821da177e4SLinus Torvalds 8362503411SWeixing Shi static inline int sctp_v6_addr_match_len(union sctp_addr *s1, 8462503411SWeixing Shi union sctp_addr *s2); 859914ae3cSVlad Yasevich static void sctp_v6_to_addr(union sctp_addr *addr, struct in6_addr *saddr, 869914ae3cSVlad Yasevich __be16 port); 879914ae3cSVlad Yasevich static int sctp_v6_cmp_addr(const union sctp_addr *addr1, 889914ae3cSVlad Yasevich const union sctp_addr *addr2); 8962503411SWeixing Shi 9029303547SVlad Yasevich /* Event handler for inet6 address addition/deletion events. 9129303547SVlad Yasevich * The sctp_local_addr_list needs to be protocted by a spin lock since 9229303547SVlad Yasevich * multiple notifiers (say IPv4 and IPv6) may be running at the same 9329303547SVlad Yasevich * time and thus corrupt the list. 9429303547SVlad Yasevich * The reader side is protected with RCU. 9529303547SVlad Yasevich */ 9624123186SAdrian Bunk static int sctp_inet6addr_event(struct notifier_block *this, unsigned long ev, 9729c7cf96SSridhar Samudrala void *ptr) 9829c7cf96SSridhar Samudrala { 9929c7cf96SSridhar Samudrala struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr; 10029303547SVlad Yasevich struct sctp_sockaddr_entry *addr = NULL; 10129303547SVlad Yasevich struct sctp_sockaddr_entry *temp; 10222626216SChidambar 'ilLogict' Zinnoury int found = 0; 10329c7cf96SSridhar Samudrala 10429c7cf96SSridhar Samudrala switch (ev) { 10529c7cf96SSridhar Samudrala case NETDEV_UP: 10629c7cf96SSridhar Samudrala addr = kmalloc(sizeof(struct sctp_sockaddr_entry), GFP_ATOMIC); 10729c7cf96SSridhar Samudrala if (addr) { 10829c7cf96SSridhar Samudrala addr->a.v6.sin6_family = AF_INET6; 10929c7cf96SSridhar Samudrala addr->a.v6.sin6_port = 0; 1104fe1d58bSJoe Perches ipv6_addr_copy(&addr->a.v6.sin6_addr, &ifa->addr); 11129c7cf96SSridhar Samudrala addr->a.v6.sin6_scope_id = ifa->idev->dev->ifindex; 11229303547SVlad Yasevich addr->valid = 1; 11329303547SVlad Yasevich spin_lock_bh(&sctp_local_addr_lock); 11429303547SVlad Yasevich list_add_tail_rcu(&addr->list, &sctp_local_addr_list); 1159f7d653bSMichio Honda sctp_addr_wq_mgmt(addr, SCTP_ADDR_NEW); 11629303547SVlad Yasevich spin_unlock_bh(&sctp_local_addr_lock); 11729c7cf96SSridhar Samudrala } 11829c7cf96SSridhar Samudrala break; 11929c7cf96SSridhar Samudrala case NETDEV_DOWN: 12029303547SVlad Yasevich spin_lock_bh(&sctp_local_addr_lock); 12129303547SVlad Yasevich list_for_each_entry_safe(addr, temp, 12229303547SVlad Yasevich &sctp_local_addr_list, list) { 123a40a7d15SPavel Emelyanov if (addr->a.sa.sa_family == AF_INET6 && 124a40a7d15SPavel Emelyanov ipv6_addr_equal(&addr->a.v6.sin6_addr, 12529303547SVlad Yasevich &ifa->addr)) { 1269f7d653bSMichio Honda sctp_addr_wq_mgmt(addr, SCTP_ADDR_DEL); 12722626216SChidambar 'ilLogict' Zinnoury found = 1; 12829303547SVlad Yasevich addr->valid = 0; 12929303547SVlad Yasevich list_del_rcu(&addr->list); 13029c7cf96SSridhar Samudrala break; 13129c7cf96SSridhar Samudrala } 13229c7cf96SSridhar Samudrala } 13329303547SVlad Yasevich spin_unlock_bh(&sctp_local_addr_lock); 13422626216SChidambar 'ilLogict' Zinnoury if (found) 1351231f0baSLai Jiangshan kfree_rcu(addr, rcu); 13629c7cf96SSridhar Samudrala break; 13729c7cf96SSridhar Samudrala } 13829c7cf96SSridhar Samudrala 13929c7cf96SSridhar Samudrala return NOTIFY_DONE; 14029c7cf96SSridhar Samudrala } 14129c7cf96SSridhar Samudrala 1421da177e4SLinus Torvalds static struct notifier_block sctp_inet6addr_notifier = { 14329c7cf96SSridhar Samudrala .notifier_call = sctp_inet6addr_event, 1441da177e4SLinus Torvalds }; 1451da177e4SLinus Torvalds 1461da177e4SLinus Torvalds /* ICMP error handler. */ 1471da177e4SLinus Torvalds SCTP_STATIC void sctp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt, 148d5fdd6baSBrian Haley u8 type, u8 code, int offset, __be32 info) 1491da177e4SLinus Torvalds { 1501da177e4SLinus Torvalds struct inet6_dev *idev; 1511da177e4SLinus Torvalds struct sock *sk; 1521da177e4SLinus Torvalds struct sctp_association *asoc; 1531da177e4SLinus Torvalds struct sctp_transport *transport; 1541da177e4SLinus Torvalds struct ipv6_pinfo *np; 1552e07fa9cSArnaldo Carvalho de Melo sk_buff_data_t saveip, savesctp; 1561da177e4SLinus Torvalds int err; 1571da177e4SLinus Torvalds 1581da177e4SLinus Torvalds idev = in6_dev_get(skb->dev); 1591da177e4SLinus Torvalds 1601da177e4SLinus Torvalds /* Fix up skb to look at the embedded net header. */ 161b0e380b1SArnaldo Carvalho de Melo saveip = skb->network_header; 162b0e380b1SArnaldo Carvalho de Melo savesctp = skb->transport_header; 1631ced98e8SArnaldo Carvalho de Melo skb_reset_network_header(skb); 164a27ef749SArnaldo Carvalho de Melo skb_set_transport_header(skb, offset); 165a27ef749SArnaldo Carvalho de Melo sk = sctp_err_lookup(AF_INET6, skb, sctp_hdr(skb), &asoc, &transport); 1661da177e4SLinus Torvalds /* Put back, the original pointers. */ 167b0e380b1SArnaldo Carvalho de Melo skb->network_header = saveip; 168b0e380b1SArnaldo Carvalho de Melo skb->transport_header = savesctp; 1691da177e4SLinus Torvalds if (!sk) { 170e41b5368SDenis V. Lunev ICMP6_INC_STATS_BH(dev_net(skb->dev), idev, ICMP6_MIB_INERRORS); 1711da177e4SLinus Torvalds goto out; 1721da177e4SLinus Torvalds } 1731da177e4SLinus Torvalds 1741da177e4SLinus Torvalds /* Warning: The sock lock is held. Remember to call 1751da177e4SLinus Torvalds * sctp_err_finish! 1761da177e4SLinus Torvalds */ 1771da177e4SLinus Torvalds 1781da177e4SLinus Torvalds switch (type) { 1791da177e4SLinus Torvalds case ICMPV6_PKT_TOOBIG: 1801da177e4SLinus Torvalds sctp_icmp_frag_needed(sk, asoc, transport, ntohl(info)); 1811da177e4SLinus Torvalds goto out_unlock; 1821da177e4SLinus Torvalds case ICMPV6_PARAMPROB: 1831da177e4SLinus Torvalds if (ICMPV6_UNK_NEXTHDR == code) { 184d1ad1ff2SSridhar Samudrala sctp_icmp_proto_unreachable(sk, asoc, transport); 1851da177e4SLinus Torvalds goto out_unlock; 1861da177e4SLinus Torvalds } 1871da177e4SLinus Torvalds break; 1881da177e4SLinus Torvalds default: 1891da177e4SLinus Torvalds break; 1901da177e4SLinus Torvalds } 1911da177e4SLinus Torvalds 1921da177e4SLinus Torvalds np = inet6_sk(sk); 1931da177e4SLinus Torvalds icmpv6_err_convert(type, code, &err); 1941da177e4SLinus Torvalds if (!sock_owned_by_user(sk) && np->recverr) { 1951da177e4SLinus Torvalds sk->sk_err = err; 1961da177e4SLinus Torvalds sk->sk_error_report(sk); 1971da177e4SLinus Torvalds } else { /* Only an error on timeout */ 1981da177e4SLinus Torvalds sk->sk_err_soft = err; 1991da177e4SLinus Torvalds } 2001da177e4SLinus Torvalds 2011da177e4SLinus Torvalds out_unlock: 202d1ad1ff2SSridhar Samudrala sctp_err_finish(sk, asoc); 2031da177e4SLinus Torvalds out: 2041da177e4SLinus Torvalds if (likely(idev != NULL)) 2051da177e4SLinus Torvalds in6_dev_put(idev); 2061da177e4SLinus Torvalds } 2071da177e4SLinus Torvalds 2081da177e4SLinus Torvalds /* Based on tcp_v6_xmit() in tcp_ipv6.c. */ 209f880374cSHerbert Xu static int sctp_v6_xmit(struct sk_buff *skb, struct sctp_transport *transport) 2101da177e4SLinus Torvalds { 2111da177e4SLinus Torvalds struct sock *sk = skb->sk; 2121da177e4SLinus Torvalds struct ipv6_pinfo *np = inet6_sk(sk); 2134c9483b2SDavid S. Miller struct flowi6 fl6; 2141da177e4SLinus Torvalds 2154c9483b2SDavid S. Miller memset(&fl6, 0, sizeof(fl6)); 2161da177e4SLinus Torvalds 2174c9483b2SDavid S. Miller fl6.flowi6_proto = sk->sk_protocol; 2181da177e4SLinus Torvalds 2191da177e4SLinus Torvalds /* Fill in the dest address from the route entry passed with the skb 2201da177e4SLinus Torvalds * and the source address from the transport. 2211da177e4SLinus Torvalds */ 2224c9483b2SDavid S. Miller ipv6_addr_copy(&fl6.daddr, &transport->ipaddr.v6.sin6_addr); 2234c9483b2SDavid S. Miller ipv6_addr_copy(&fl6.saddr, &transport->saddr.v6.sin6_addr); 2241da177e4SLinus Torvalds 2254c9483b2SDavid S. Miller fl6.flowlabel = np->flow_label; 2264c9483b2SDavid S. Miller IP6_ECN_flow_xmit(sk, fl6.flowlabel); 2274c9483b2SDavid S. Miller if (ipv6_addr_type(&fl6.saddr) & IPV6_ADDR_LINKLOCAL) 2284c9483b2SDavid S. Miller fl6.flowi6_oif = transport->saddr.v6.sin6_scope_id; 2291da177e4SLinus Torvalds else 2304c9483b2SDavid S. Miller fl6.flowi6_oif = sk->sk_bound_dev_if; 2311da177e4SLinus Torvalds 2321da177e4SLinus Torvalds if (np->opt && np->opt->srcrt) { 2331da177e4SLinus Torvalds struct rt0_hdr *rt0 = (struct rt0_hdr *) np->opt->srcrt; 2344c9483b2SDavid S. Miller ipv6_addr_copy(&fl6.daddr, rt0->addr); 2351da177e4SLinus Torvalds } 2361da177e4SLinus Torvalds 2375b095d98SHarvey Harrison SCTP_DEBUG_PRINTK("%s: skb:%p, len:%d, src:%pI6 dst:%pI6\n", 2380dc47877SHarvey Harrison __func__, skb, skb->len, 2394c9483b2SDavid S. Miller &fl6.saddr, &fl6.daddr); 2401da177e4SLinus Torvalds 2411da177e4SLinus Torvalds SCTP_INC_STATS(SCTP_MIB_OUTSCTPPACKS); 2421da177e4SLinus Torvalds 243f880374cSHerbert Xu if (!(transport->param_flags & SPP_PMTUD_ENABLE)) 244f880374cSHerbert Xu skb->local_df = 1; 245f880374cSHerbert Xu 2464c9483b2SDavid S. Miller return ip6_xmit(sk, skb, &fl6, np->opt); 2471da177e4SLinus Torvalds } 2481da177e4SLinus Torvalds 2491da177e4SLinus Torvalds /* Returns the dst cache entry for the given source and destination ip 2501da177e4SLinus Torvalds * addresses. 2511da177e4SLinus Torvalds */ 252da0420beSVlad Yasevich static void sctp_v6_get_dst(struct sctp_transport *t, union sctp_addr *saddr, 253da0420beSVlad Yasevich struct flowi *fl, struct sock *sk) 2541da177e4SLinus Torvalds { 255da0420beSVlad Yasevich struct sctp_association *asoc = t->asoc; 25662503411SWeixing Shi struct dst_entry *dst = NULL; 2579914ae3cSVlad Yasevich struct flowi6 *fl6 = &fl->u.ip6; 25862503411SWeixing Shi struct sctp_bind_addr *bp; 25962503411SWeixing Shi struct sctp_sockaddr_entry *laddr; 26062503411SWeixing Shi union sctp_addr *baddr = NULL; 261da0420beSVlad Yasevich union sctp_addr *daddr = &t->ipaddr; 2629914ae3cSVlad Yasevich union sctp_addr dst_saddr; 26362503411SWeixing Shi __u8 matchlen = 0; 26462503411SWeixing Shi __u8 bmatchlen; 26562503411SWeixing Shi sctp_scope_t scope; 2661da177e4SLinus Torvalds 2679914ae3cSVlad Yasevich memset(fl6, 0, sizeof(struct flowi6)); 2689914ae3cSVlad Yasevich ipv6_addr_copy(&fl6->daddr, &daddr->v6.sin6_addr); 2699c6a02f4SVlad Yasevich fl6->fl6_dport = daddr->v6.sin6_port; 2709c6a02f4SVlad Yasevich fl6->flowi6_proto = IPPROTO_SCTP; 2711da177e4SLinus Torvalds if (ipv6_addr_type(&daddr->v6.sin6_addr) & IPV6_ADDR_LINKLOCAL) 2729914ae3cSVlad Yasevich fl6->flowi6_oif = daddr->v6.sin6_scope_id; 2731da177e4SLinus Torvalds 2749914ae3cSVlad Yasevich SCTP_DEBUG_PRINTK("%s: DST=%pI6 ", __func__, &fl6->daddr); 2751da177e4SLinus Torvalds 2769c6a02f4SVlad Yasevich if (asoc) 2779c6a02f4SVlad Yasevich fl6->fl6_sport = htons(asoc->base.bind_addr.port); 2781da177e4SLinus Torvalds 2791da177e4SLinus Torvalds if (saddr) { 2809914ae3cSVlad Yasevich ipv6_addr_copy(&fl6->saddr, &saddr->v6.sin6_addr); 2819c6a02f4SVlad Yasevich fl6->fl6_sport = saddr->v6.sin6_port; 2829914ae3cSVlad Yasevich SCTP_DEBUG_PRINTK("SRC=%pI6 - ", &fl6->saddr); 2831da177e4SLinus Torvalds } 2841da177e4SLinus Torvalds 2859c6a02f4SVlad Yasevich dst = ip6_dst_lookup_flow(sk, fl6, NULL, false); 28662503411SWeixing Shi if (!asoc || saddr) 28762503411SWeixing Shi goto out; 28862503411SWeixing Shi 28962503411SWeixing Shi bp = &asoc->base.bind_addr; 29062503411SWeixing Shi scope = sctp_scope(daddr); 2919914ae3cSVlad Yasevich /* ip6_dst_lookup has filled in the fl6->saddr for us. Check 2929914ae3cSVlad Yasevich * to see if we can use it. 2939914ae3cSVlad Yasevich */ 2949c6a02f4SVlad Yasevich if (!IS_ERR(dst)) { 2959914ae3cSVlad Yasevich /* Walk through the bind address list and look for a bind 2969914ae3cSVlad Yasevich * address that matches the source address of the returned dst. 2979914ae3cSVlad Yasevich */ 2989914ae3cSVlad Yasevich sctp_v6_to_addr(&dst_saddr, &fl6->saddr, htons(bp->port)); 2999914ae3cSVlad Yasevich rcu_read_lock(); 3009914ae3cSVlad Yasevich list_for_each_entry_rcu(laddr, &bp->address_list, list) { 3019914ae3cSVlad Yasevich if (!laddr->valid || (laddr->state != SCTP_ADDR_SRC)) 3029914ae3cSVlad Yasevich continue; 3039914ae3cSVlad Yasevich 3049914ae3cSVlad Yasevich /* Do not compare against v4 addrs */ 3059914ae3cSVlad Yasevich if ((laddr->a.sa.sa_family == AF_INET6) && 3069914ae3cSVlad Yasevich (sctp_v6_cmp_addr(&dst_saddr, &laddr->a))) { 3079914ae3cSVlad Yasevich rcu_read_unlock(); 3089914ae3cSVlad Yasevich goto out; 3099914ae3cSVlad Yasevich } 3109914ae3cSVlad Yasevich } 3119914ae3cSVlad Yasevich rcu_read_unlock(); 3129914ae3cSVlad Yasevich /* None of the bound addresses match the source address of the 3139914ae3cSVlad Yasevich * dst. So release it. 3149914ae3cSVlad Yasevich */ 3159914ae3cSVlad Yasevich dst_release(dst); 3169914ae3cSVlad Yasevich dst = NULL; 3179914ae3cSVlad Yasevich } 3189914ae3cSVlad Yasevich 3199914ae3cSVlad Yasevich /* Walk through the bind address list and try to get the 3209914ae3cSVlad Yasevich * best source address for a given destination. 32162503411SWeixing Shi */ 32262503411SWeixing Shi rcu_read_lock(); 32362503411SWeixing Shi list_for_each_entry_rcu(laddr, &bp->address_list, list) { 3249914ae3cSVlad Yasevich if (!laddr->valid && laddr->state != SCTP_ADDR_SRC) 32562503411SWeixing Shi continue; 3269914ae3cSVlad Yasevich if ((laddr->a.sa.sa_family == AF_INET6) && 32762503411SWeixing Shi (scope <= sctp_scope(&laddr->a))) { 3289914ae3cSVlad Yasevich bmatchlen = sctp_v6_addr_match_len(daddr, &laddr->a); 32962503411SWeixing Shi if (!baddr || (matchlen < bmatchlen)) { 33062503411SWeixing Shi baddr = &laddr->a; 33162503411SWeixing Shi matchlen = bmatchlen; 33262503411SWeixing Shi } 33362503411SWeixing Shi } 33462503411SWeixing Shi } 33562503411SWeixing Shi rcu_read_unlock(); 33662503411SWeixing Shi if (baddr) { 3379914ae3cSVlad Yasevich ipv6_addr_copy(&fl6->saddr, &baddr->v6.sin6_addr); 3389c6a02f4SVlad Yasevich fl6->fl6_sport = baddr->v6.sin6_port; 3399c6a02f4SVlad Yasevich dst = ip6_dst_lookup_flow(sk, fl6, NULL, false); 34062503411SWeixing Shi } 3419914ae3cSVlad Yasevich 34262503411SWeixing Shi out: 3439c6a02f4SVlad Yasevich if (!IS_ERR(dst)) { 3441da177e4SLinus Torvalds struct rt6_info *rt; 3451da177e4SLinus Torvalds rt = (struct rt6_info *)dst; 346da0420beSVlad Yasevich t->dst = dst; 3475b095d98SHarvey Harrison SCTP_DEBUG_PRINTK("rt6_dst:%pI6 rt6_src:%pI6\n", 3489914ae3cSVlad Yasevich &rt->rt6i_dst.addr, &fl6->saddr); 349da0420beSVlad Yasevich } else { 350da0420beSVlad Yasevich t->dst = NULL; 3514251320fSVille Nuorvala SCTP_DEBUG_PRINTK("NO ROUTE\n"); 352da0420beSVlad Yasevich } 3534251320fSVille Nuorvala } 3541da177e4SLinus Torvalds 3551da177e4SLinus Torvalds /* Returns the number of consecutive initial bits that match in the 2 ipv6 3561da177e4SLinus Torvalds * addresses. 3571da177e4SLinus Torvalds */ 3581da177e4SLinus Torvalds static inline int sctp_v6_addr_match_len(union sctp_addr *s1, 3591da177e4SLinus Torvalds union sctp_addr *s2) 3601da177e4SLinus Torvalds { 361de7737e0SYOSHIFUJI Hideaki / 吉藤英明 return ipv6_addr_diff(&s1->v6.sin6_addr, &s2->v6.sin6_addr); 3621da177e4SLinus Torvalds } 3631da177e4SLinus Torvalds 3641da177e4SLinus Torvalds /* Fills in the source address(saddr) based on the destination address(daddr) 3651da177e4SLinus Torvalds * and asoc's bind address list. 3661da177e4SLinus Torvalds */ 367e5117101SYOSHIFUJI Hideaki static void sctp_v6_get_saddr(struct sctp_sock *sk, 3689914ae3cSVlad Yasevich struct sctp_transport *t, 3699914ae3cSVlad Yasevich struct flowi *fl) 3701da177e4SLinus Torvalds { 3719914ae3cSVlad Yasevich struct flowi6 *fl6 = &fl->u.ip6; 3729914ae3cSVlad Yasevich union sctp_addr *saddr = &t->saddr; 3731da177e4SLinus Torvalds 374af138470SVlad Yasevich SCTP_DEBUG_PRINTK("%s: asoc:%p dst:%p\n", __func__, t->asoc, t->dst); 3751da177e4SLinus Torvalds 3769914ae3cSVlad Yasevich if (t->dst) { 3779914ae3cSVlad Yasevich saddr->v6.sin6_family = AF_INET6; 3789914ae3cSVlad Yasevich ipv6_addr_copy(&saddr->v6.sin6_addr, &fl6->saddr); 3791da177e4SLinus Torvalds } 3801da177e4SLinus Torvalds } 3811da177e4SLinus Torvalds 3821da177e4SLinus Torvalds /* Make a copy of all potential local addresses. */ 3831da177e4SLinus Torvalds static void sctp_v6_copy_addrlist(struct list_head *addrlist, 3841da177e4SLinus Torvalds struct net_device *dev) 3851da177e4SLinus Torvalds { 3861da177e4SLinus Torvalds struct inet6_dev *in6_dev; 3871da177e4SLinus Torvalds struct inet6_ifaddr *ifp; 3881da177e4SLinus Torvalds struct sctp_sockaddr_entry *addr; 3891da177e4SLinus Torvalds 3908814c4b5SYOSHIFUJI Hideaki rcu_read_lock(); 3911da177e4SLinus Torvalds if ((in6_dev = __in6_dev_get(dev)) == NULL) { 3928814c4b5SYOSHIFUJI Hideaki rcu_read_unlock(); 3931da177e4SLinus Torvalds return; 3941da177e4SLinus Torvalds } 3951da177e4SLinus Torvalds 396e2eb8d45SJarek Poplawski read_lock_bh(&in6_dev->lock); 397502a2ffdSstephen hemminger list_for_each_entry(ifp, &in6_dev->addr_list, if_list) { 3981da177e4SLinus Torvalds /* Add the address to the local list. */ 3991da177e4SLinus Torvalds addr = t_new(struct sctp_sockaddr_entry, GFP_ATOMIC); 4001da177e4SLinus Torvalds if (addr) { 4012a6fd78aSAl Viro addr->a.v6.sin6_family = AF_INET6; 4022a6fd78aSAl Viro addr->a.v6.sin6_port = 0; 403486f50caSBrian Haley ipv6_addr_copy(&addr->a.v6.sin6_addr, &ifp->addr); 4042a6fd78aSAl Viro addr->a.v6.sin6_scope_id = dev->ifindex; 40529303547SVlad Yasevich addr->valid = 1; 4061da177e4SLinus Torvalds INIT_LIST_HEAD(&addr->list); 4071da177e4SLinus Torvalds list_add_tail(&addr->list, addrlist); 4081da177e4SLinus Torvalds } 4091da177e4SLinus Torvalds } 4101da177e4SLinus Torvalds 411e2eb8d45SJarek Poplawski read_unlock_bh(&in6_dev->lock); 4128814c4b5SYOSHIFUJI Hideaki rcu_read_unlock(); 4131da177e4SLinus Torvalds } 4141da177e4SLinus Torvalds 4151da177e4SLinus Torvalds /* Initialize a sockaddr_storage from in incoming skb. */ 4161da177e4SLinus Torvalds static void sctp_v6_from_skb(union sctp_addr *addr,struct sk_buff *skb, 4171da177e4SLinus Torvalds int is_saddr) 4181da177e4SLinus Torvalds { 4191da177e4SLinus Torvalds void *from; 420d55c41b1SAl Viro __be16 *port; 4211da177e4SLinus Torvalds struct sctphdr *sh; 4221da177e4SLinus Torvalds 4231da177e4SLinus Torvalds port = &addr->v6.sin6_port; 4241da177e4SLinus Torvalds addr->v6.sin6_family = AF_INET6; 4251da177e4SLinus Torvalds addr->v6.sin6_flowinfo = 0; /* FIXME */ 4261da177e4SLinus Torvalds addr->v6.sin6_scope_id = ((struct inet6_skb_parm *)skb->cb)->iif; 4271da177e4SLinus Torvalds 4282c0fd387SArnaldo Carvalho de Melo sh = sctp_hdr(skb); 4291da177e4SLinus Torvalds if (is_saddr) { 430d55c41b1SAl Viro *port = sh->source; 4310660e03fSArnaldo Carvalho de Melo from = &ipv6_hdr(skb)->saddr; 4321da177e4SLinus Torvalds } else { 433d55c41b1SAl Viro *port = sh->dest; 4340660e03fSArnaldo Carvalho de Melo from = &ipv6_hdr(skb)->daddr; 4351da177e4SLinus Torvalds } 4361da177e4SLinus Torvalds ipv6_addr_copy(&addr->v6.sin6_addr, from); 4371da177e4SLinus Torvalds } 4381da177e4SLinus Torvalds 4391da177e4SLinus Torvalds /* Initialize an sctp_addr from a socket. */ 4401da177e4SLinus Torvalds static void sctp_v6_from_sk(union sctp_addr *addr, struct sock *sk) 4411da177e4SLinus Torvalds { 4421da177e4SLinus Torvalds addr->v6.sin6_family = AF_INET6; 4437dcdbd95SAl Viro addr->v6.sin6_port = 0; 444486f50caSBrian Haley ipv6_addr_copy(&addr->v6.sin6_addr, &inet6_sk(sk)->rcv_saddr); 4451da177e4SLinus Torvalds } 4461da177e4SLinus Torvalds 4471da177e4SLinus Torvalds /* Initialize sk->sk_rcv_saddr from sctp_addr. */ 4481da177e4SLinus Torvalds static void sctp_v6_to_sk_saddr(union sctp_addr *addr, struct sock *sk) 4491da177e4SLinus Torvalds { 4501da177e4SLinus Torvalds if (addr->sa.sa_family == AF_INET && sctp_sk(sk)->v4mapped) { 4511da177e4SLinus Torvalds inet6_sk(sk)->rcv_saddr.s6_addr32[0] = 0; 4521da177e4SLinus Torvalds inet6_sk(sk)->rcv_saddr.s6_addr32[1] = 0; 4531da177e4SLinus Torvalds inet6_sk(sk)->rcv_saddr.s6_addr32[2] = htonl(0x0000ffff); 4541da177e4SLinus Torvalds inet6_sk(sk)->rcv_saddr.s6_addr32[3] = 4551da177e4SLinus Torvalds addr->v4.sin_addr.s_addr; 4561da177e4SLinus Torvalds } else { 457486f50caSBrian Haley ipv6_addr_copy(&inet6_sk(sk)->rcv_saddr, &addr->v6.sin6_addr); 4581da177e4SLinus Torvalds } 4591da177e4SLinus Torvalds } 4601da177e4SLinus Torvalds 4611da177e4SLinus Torvalds /* Initialize sk->sk_daddr from sctp_addr. */ 4621da177e4SLinus Torvalds static void sctp_v6_to_sk_daddr(union sctp_addr *addr, struct sock *sk) 4631da177e4SLinus Torvalds { 4641da177e4SLinus Torvalds if (addr->sa.sa_family == AF_INET && sctp_sk(sk)->v4mapped) { 4651da177e4SLinus Torvalds inet6_sk(sk)->daddr.s6_addr32[0] = 0; 4661da177e4SLinus Torvalds inet6_sk(sk)->daddr.s6_addr32[1] = 0; 4671da177e4SLinus Torvalds inet6_sk(sk)->daddr.s6_addr32[2] = htonl(0x0000ffff); 4681da177e4SLinus Torvalds inet6_sk(sk)->daddr.s6_addr32[3] = addr->v4.sin_addr.s_addr; 4691da177e4SLinus Torvalds } else { 470486f50caSBrian Haley ipv6_addr_copy(&inet6_sk(sk)->daddr, &addr->v6.sin6_addr); 4711da177e4SLinus Torvalds } 4721da177e4SLinus Torvalds } 4731da177e4SLinus Torvalds 4741da177e4SLinus Torvalds /* Initialize a sctp_addr from an address parameter. */ 4751da177e4SLinus Torvalds static void sctp_v6_from_addr_param(union sctp_addr *addr, 4761da177e4SLinus Torvalds union sctp_addr_param *param, 477dd86d136SAl Viro __be16 port, int iif) 4781da177e4SLinus Torvalds { 4791da177e4SLinus Torvalds addr->v6.sin6_family = AF_INET6; 4801da177e4SLinus Torvalds addr->v6.sin6_port = port; 4811da177e4SLinus Torvalds addr->v6.sin6_flowinfo = 0; /* BUG */ 4821da177e4SLinus Torvalds ipv6_addr_copy(&addr->v6.sin6_addr, ¶m->v6.addr); 4831da177e4SLinus Torvalds addr->v6.sin6_scope_id = iif; 4841da177e4SLinus Torvalds } 4851da177e4SLinus Torvalds 4861da177e4SLinus Torvalds /* Initialize an address parameter from a sctp_addr and return the length 4871da177e4SLinus Torvalds * of the address parameter. 4881da177e4SLinus Torvalds */ 4891da177e4SLinus Torvalds static int sctp_v6_to_addr_param(const union sctp_addr *addr, 4901da177e4SLinus Torvalds union sctp_addr_param *param) 4911da177e4SLinus Torvalds { 4921da177e4SLinus Torvalds int length = sizeof(sctp_ipv6addr_param_t); 4931da177e4SLinus Torvalds 4941da177e4SLinus Torvalds param->v6.param_hdr.type = SCTP_PARAM_IPV6_ADDRESS; 495dbc16db1SAl Viro param->v6.param_hdr.length = htons(length); 4961da177e4SLinus Torvalds ipv6_addr_copy(¶m->v6.addr, &addr->v6.sin6_addr); 4971da177e4SLinus Torvalds 4981da177e4SLinus Torvalds return length; 4991da177e4SLinus Torvalds } 5001da177e4SLinus Torvalds 5019914ae3cSVlad Yasevich /* Initialize a sctp_addr from struct in6_addr. */ 5029914ae3cSVlad Yasevich static void sctp_v6_to_addr(union sctp_addr *addr, struct in6_addr *saddr, 503854d43a4SAl Viro __be16 port) 5041da177e4SLinus Torvalds { 5051da177e4SLinus Torvalds addr->sa.sa_family = AF_INET6; 5061da177e4SLinus Torvalds addr->v6.sin6_port = port; 5079914ae3cSVlad Yasevich ipv6_addr_copy(&addr->v6.sin6_addr, saddr); 5081da177e4SLinus Torvalds } 5091da177e4SLinus Torvalds 5101da177e4SLinus Torvalds /* Compare addresses exactly. 5111da177e4SLinus Torvalds * v4-mapped-v6 is also in consideration. 5121da177e4SLinus Torvalds */ 5131da177e4SLinus Torvalds static int sctp_v6_cmp_addr(const union sctp_addr *addr1, 5141da177e4SLinus Torvalds const union sctp_addr *addr2) 5151da177e4SLinus Torvalds { 5161da177e4SLinus Torvalds if (addr1->sa.sa_family != addr2->sa.sa_family) { 5171da177e4SLinus Torvalds if (addr1->sa.sa_family == AF_INET && 5181da177e4SLinus Torvalds addr2->sa.sa_family == AF_INET6 && 519e773e4faSBrian Haley ipv6_addr_v4mapped(&addr2->v6.sin6_addr)) { 5201da177e4SLinus Torvalds if (addr2->v6.sin6_port == addr1->v4.sin_port && 5211da177e4SLinus Torvalds addr2->v6.sin6_addr.s6_addr32[3] == 5221da177e4SLinus Torvalds addr1->v4.sin_addr.s_addr) 5231da177e4SLinus Torvalds return 1; 5241da177e4SLinus Torvalds } 5251da177e4SLinus Torvalds if (addr2->sa.sa_family == AF_INET && 5261da177e4SLinus Torvalds addr1->sa.sa_family == AF_INET6 && 527e773e4faSBrian Haley ipv6_addr_v4mapped(&addr1->v6.sin6_addr)) { 5281da177e4SLinus Torvalds if (addr1->v6.sin6_port == addr2->v4.sin_port && 5291da177e4SLinus Torvalds addr1->v6.sin6_addr.s6_addr32[3] == 5301da177e4SLinus Torvalds addr2->v4.sin_addr.s_addr) 5311da177e4SLinus Torvalds return 1; 5321da177e4SLinus Torvalds } 5331da177e4SLinus Torvalds return 0; 5341da177e4SLinus Torvalds } 5351da177e4SLinus Torvalds if (!ipv6_addr_equal(&addr1->v6.sin6_addr, &addr2->v6.sin6_addr)) 5361da177e4SLinus Torvalds return 0; 5371da177e4SLinus Torvalds /* If this is a linklocal address, compare the scope_id. */ 5381da177e4SLinus Torvalds if (ipv6_addr_type(&addr1->v6.sin6_addr) & IPV6_ADDR_LINKLOCAL) { 5391da177e4SLinus Torvalds if (addr1->v6.sin6_scope_id && addr2->v6.sin6_scope_id && 5401da177e4SLinus Torvalds (addr1->v6.sin6_scope_id != addr2->v6.sin6_scope_id)) { 5411da177e4SLinus Torvalds return 0; 5421da177e4SLinus Torvalds } 5431da177e4SLinus Torvalds } 5441da177e4SLinus Torvalds 5451da177e4SLinus Torvalds return 1; 5461da177e4SLinus Torvalds } 5471da177e4SLinus Torvalds 5481da177e4SLinus Torvalds /* Initialize addr struct to INADDR_ANY. */ 5496fbfa9f9SAl Viro static void sctp_v6_inaddr_any(union sctp_addr *addr, __be16 port) 5501da177e4SLinus Torvalds { 5511da177e4SLinus Torvalds memset(addr, 0x00, sizeof(union sctp_addr)); 5521da177e4SLinus Torvalds addr->v6.sin6_family = AF_INET6; 5531da177e4SLinus Torvalds addr->v6.sin6_port = port; 5541da177e4SLinus Torvalds } 5551da177e4SLinus Torvalds 5561da177e4SLinus Torvalds /* Is this a wildcard address? */ 5571da177e4SLinus Torvalds static int sctp_v6_is_any(const union sctp_addr *addr) 5581da177e4SLinus Torvalds { 559b9b9e10fSBrian Haley return ipv6_addr_any(&addr->v6.sin6_addr); 5601da177e4SLinus Torvalds } 5611da177e4SLinus Torvalds 5621da177e4SLinus Torvalds /* Should this be available for binding? */ 5631da177e4SLinus Torvalds static int sctp_v6_available(union sctp_addr *addr, struct sctp_sock *sp) 5641da177e4SLinus Torvalds { 5651da177e4SLinus Torvalds int type; 566b71d1d42SEric Dumazet const struct in6_addr *in6 = (const struct in6_addr *)&addr->v6.sin6_addr; 5671da177e4SLinus Torvalds 5681da177e4SLinus Torvalds type = ipv6_addr_type(in6); 5691da177e4SLinus Torvalds if (IPV6_ADDR_ANY == type) 5701da177e4SLinus Torvalds return 1; 5711da177e4SLinus Torvalds if (type == IPV6_ADDR_MAPPED) { 5721da177e4SLinus Torvalds if (sp && !sp->v4mapped) 5731da177e4SLinus Torvalds return 0; 5741da177e4SLinus Torvalds if (sp && ipv6_only_sock(sctp_opt2sk(sp))) 5751da177e4SLinus Torvalds return 0; 5761da177e4SLinus Torvalds sctp_v6_map_v4(addr); 5771da177e4SLinus Torvalds return sctp_get_af_specific(AF_INET)->available(addr, sp); 5781da177e4SLinus Torvalds } 5791da177e4SLinus Torvalds if (!(type & IPV6_ADDR_UNICAST)) 5801da177e4SLinus Torvalds return 0; 5811da177e4SLinus Torvalds 582bfeade08SDaniel Lezcano return ipv6_chk_addr(&init_net, in6, NULL, 0); 5831da177e4SLinus Torvalds } 5841da177e4SLinus Torvalds 5851da177e4SLinus Torvalds /* This function checks if the address is a valid address to be used for 5861da177e4SLinus Torvalds * SCTP. 5871da177e4SLinus Torvalds * 5881da177e4SLinus Torvalds * Output: 5891da177e4SLinus Torvalds * Return 0 - If the address is a non-unicast or an illegal address. 5901da177e4SLinus Torvalds * Return 1 - If the address is a unicast. 5911da177e4SLinus Torvalds */ 5925636bef7SVlad Yasevich static int sctp_v6_addr_valid(union sctp_addr *addr, 5935636bef7SVlad Yasevich struct sctp_sock *sp, 5945636bef7SVlad Yasevich const struct sk_buff *skb) 5951da177e4SLinus Torvalds { 5961da177e4SLinus Torvalds int ret = ipv6_addr_type(&addr->v6.sin6_addr); 5971da177e4SLinus Torvalds 5981da177e4SLinus Torvalds /* Support v4-mapped-v6 address. */ 5991da177e4SLinus Torvalds if (ret == IPV6_ADDR_MAPPED) { 6001da177e4SLinus Torvalds /* Note: This routine is used in input, so v4-mapped-v6 6011da177e4SLinus Torvalds * are disallowed here when there is no sctp_sock. 6021da177e4SLinus Torvalds */ 6031da177e4SLinus Torvalds if (!sp || !sp->v4mapped) 6041da177e4SLinus Torvalds return 0; 6051da177e4SLinus Torvalds if (sp && ipv6_only_sock(sctp_opt2sk(sp))) 6061da177e4SLinus Torvalds return 0; 6071da177e4SLinus Torvalds sctp_v6_map_v4(addr); 6085636bef7SVlad Yasevich return sctp_get_af_specific(AF_INET)->addr_valid(addr, sp, skb); 6091da177e4SLinus Torvalds } 6101da177e4SLinus Torvalds 6111da177e4SLinus Torvalds /* Is this a non-unicast address */ 6121da177e4SLinus Torvalds if (!(ret & IPV6_ADDR_UNICAST)) 6131da177e4SLinus Torvalds return 0; 6141da177e4SLinus Torvalds 6151da177e4SLinus Torvalds return 1; 6161da177e4SLinus Torvalds } 6171da177e4SLinus Torvalds 6181da177e4SLinus Torvalds /* What is the scope of 'addr'? */ 6191da177e4SLinus Torvalds static sctp_scope_t sctp_v6_scope(union sctp_addr *addr) 6201da177e4SLinus Torvalds { 6211da177e4SLinus Torvalds int v6scope; 6221da177e4SLinus Torvalds sctp_scope_t retval; 6231da177e4SLinus Torvalds 6241da177e4SLinus Torvalds /* The IPv6 scope is really a set of bit fields. 6251da177e4SLinus Torvalds * See IFA_* in <net/if_inet6.h>. Map to a generic SCTP scope. 6261da177e4SLinus Torvalds */ 6271da177e4SLinus Torvalds 6281da177e4SLinus Torvalds v6scope = ipv6_addr_scope(&addr->v6.sin6_addr); 6291da177e4SLinus Torvalds switch (v6scope) { 6301da177e4SLinus Torvalds case IFA_HOST: 6311da177e4SLinus Torvalds retval = SCTP_SCOPE_LOOPBACK; 6321da177e4SLinus Torvalds break; 6331da177e4SLinus Torvalds case IFA_LINK: 6341da177e4SLinus Torvalds retval = SCTP_SCOPE_LINK; 6351da177e4SLinus Torvalds break; 6361da177e4SLinus Torvalds case IFA_SITE: 6371da177e4SLinus Torvalds retval = SCTP_SCOPE_PRIVATE; 6381da177e4SLinus Torvalds break; 6391da177e4SLinus Torvalds default: 6401da177e4SLinus Torvalds retval = SCTP_SCOPE_GLOBAL; 6411da177e4SLinus Torvalds break; 6423ff50b79SStephen Hemminger } 6431da177e4SLinus Torvalds 6441da177e4SLinus Torvalds return retval; 6451da177e4SLinus Torvalds } 6461da177e4SLinus Torvalds 6471da177e4SLinus Torvalds /* Create and initialize a new sk for the socket to be returned by accept(). */ 6481da177e4SLinus Torvalds static struct sock *sctp_v6_create_accept_sk(struct sock *sk, 6491da177e4SLinus Torvalds struct sctp_association *asoc) 6501da177e4SLinus Torvalds { 6511da177e4SLinus Torvalds struct sock *newsk; 6521da177e4SLinus Torvalds struct ipv6_pinfo *newnp, *np = inet6_sk(sk); 6531da177e4SLinus Torvalds struct sctp6_sock *newsctp6sk; 6541da177e4SLinus Torvalds 6553b1e0a65SYOSHIFUJI Hideaki newsk = sk_alloc(sock_net(sk), PF_INET6, GFP_KERNEL, sk->sk_prot); 6561da177e4SLinus Torvalds if (!newsk) 6571da177e4SLinus Torvalds goto out; 6581da177e4SLinus Torvalds 6591da177e4SLinus Torvalds sock_init_data(NULL, newsk); 6601da177e4SLinus Torvalds 661914e1c8bSVlad Yasevich sctp_copy_sock(newsk, sk, asoc); 6621da177e4SLinus Torvalds sock_reset_flag(sk, SOCK_ZAPPED); 6631da177e4SLinus Torvalds 6641da177e4SLinus Torvalds newsctp6sk = (struct sctp6_sock *)newsk; 6651da177e4SLinus Torvalds inet_sk(newsk)->pinet6 = &newsctp6sk->inet6; 6661da177e4SLinus Torvalds 667b225b884SDave Johnson sctp_sk(newsk)->v4mapped = sctp_sk(sk)->v4mapped; 668b225b884SDave Johnson 6691da177e4SLinus Torvalds newnp = inet6_sk(newsk); 6701da177e4SLinus Torvalds 6711da177e4SLinus Torvalds memcpy(newnp, np, sizeof(struct ipv6_pinfo)); 6721da177e4SLinus Torvalds 6731da177e4SLinus Torvalds /* Initialize sk's sport, dport, rcv_saddr and daddr for getsockname() 6741da177e4SLinus Torvalds * and getpeername(). 6751da177e4SLinus Torvalds */ 6761da177e4SLinus Torvalds sctp_v6_to_sk_daddr(&asoc->peer.primary_addr, newsk); 6771da177e4SLinus Torvalds 678e6848976SArnaldo Carvalho de Melo sk_refcnt_debug_inc(newsk); 6791da177e4SLinus Torvalds 6801da177e4SLinus Torvalds if (newsk->sk_prot->init(newsk)) { 6811da177e4SLinus Torvalds sk_common_release(newsk); 6821da177e4SLinus Torvalds newsk = NULL; 6831da177e4SLinus Torvalds } 6841da177e4SLinus Torvalds 6851da177e4SLinus Torvalds out: 6861da177e4SLinus Torvalds return newsk; 6871da177e4SLinus Torvalds } 6881da177e4SLinus Torvalds 6891da177e4SLinus Torvalds /* Map v4 address to mapped v6 address */ 6901da177e4SLinus Torvalds static void sctp_v6_addr_v4map(struct sctp_sock *sp, union sctp_addr *addr) 6911da177e4SLinus Torvalds { 6921da177e4SLinus Torvalds if (sp->v4mapped && AF_INET == addr->sa.sa_family) 6931da177e4SLinus Torvalds sctp_v4_map_v6(addr); 6941da177e4SLinus Torvalds } 6951da177e4SLinus Torvalds 6961da177e4SLinus Torvalds /* Where did this skb come from? */ 6971da177e4SLinus Torvalds static int sctp_v6_skb_iif(const struct sk_buff *skb) 6981da177e4SLinus Torvalds { 6991da177e4SLinus Torvalds struct inet6_skb_parm *opt = (struct inet6_skb_parm *) skb->cb; 7001da177e4SLinus Torvalds return opt->iif; 7011da177e4SLinus Torvalds } 7021da177e4SLinus Torvalds 7031da177e4SLinus Torvalds /* Was this packet marked by Explicit Congestion Notification? */ 7041da177e4SLinus Torvalds static int sctp_v6_is_ce(const struct sk_buff *skb) 7051da177e4SLinus Torvalds { 7060660e03fSArnaldo Carvalho de Melo return *((__u32 *)(ipv6_hdr(skb))) & htonl(1 << 20); 7071da177e4SLinus Torvalds } 7081da177e4SLinus Torvalds 7091da177e4SLinus Torvalds /* Dump the v6 addr to the seq file. */ 7101da177e4SLinus Torvalds static void sctp_v6_seq_dump_addr(struct seq_file *seq, union sctp_addr *addr) 7111da177e4SLinus Torvalds { 7125b095d98SHarvey Harrison seq_printf(seq, "%pI6 ", &addr->v6.sin6_addr); 7131da177e4SLinus Torvalds } 7141da177e4SLinus Torvalds 715b9031d9dSVlad Yasevich static void sctp_v6_ecn_capable(struct sock *sk) 716b9031d9dSVlad Yasevich { 717b9031d9dSVlad Yasevich inet6_sk(sk)->tclass |= INET_ECN_ECT_0; 718b9031d9dSVlad Yasevich } 719b9031d9dSVlad Yasevich 7201da177e4SLinus Torvalds /* Initialize a PF_INET6 socket msg_name. */ 7211da177e4SLinus Torvalds static void sctp_inet6_msgname(char *msgname, int *addr_len) 7221da177e4SLinus Torvalds { 7231da177e4SLinus Torvalds struct sockaddr_in6 *sin6; 7241da177e4SLinus Torvalds 7251da177e4SLinus Torvalds sin6 = (struct sockaddr_in6 *)msgname; 7261da177e4SLinus Torvalds sin6->sin6_family = AF_INET6; 7271da177e4SLinus Torvalds sin6->sin6_flowinfo = 0; 7281da177e4SLinus Torvalds sin6->sin6_scope_id = 0; /*FIXME */ 7291da177e4SLinus Torvalds *addr_len = sizeof(struct sockaddr_in6); 7301da177e4SLinus Torvalds } 7311da177e4SLinus Torvalds 7321da177e4SLinus Torvalds /* Initialize a PF_INET msgname from a ulpevent. */ 7331da177e4SLinus Torvalds static void sctp_inet6_event_msgname(struct sctp_ulpevent *event, 7341da177e4SLinus Torvalds char *msgname, int *addrlen) 7351da177e4SLinus Torvalds { 7361da177e4SLinus Torvalds struct sockaddr_in6 *sin6, *sin6from; 7371da177e4SLinus Torvalds 7381da177e4SLinus Torvalds if (msgname) { 7391da177e4SLinus Torvalds union sctp_addr *addr; 7401da177e4SLinus Torvalds struct sctp_association *asoc; 7411da177e4SLinus Torvalds 7421da177e4SLinus Torvalds asoc = event->asoc; 7431da177e4SLinus Torvalds sctp_inet6_msgname(msgname, addrlen); 7441da177e4SLinus Torvalds sin6 = (struct sockaddr_in6 *)msgname; 7451da177e4SLinus Torvalds sin6->sin6_port = htons(asoc->peer.port); 7461da177e4SLinus Torvalds addr = &asoc->peer.primary_addr; 7471da177e4SLinus Torvalds 7481da177e4SLinus Torvalds /* Note: If we go to a common v6 format, this code 7491da177e4SLinus Torvalds * will change. 7501da177e4SLinus Torvalds */ 7511da177e4SLinus Torvalds 7521da177e4SLinus Torvalds /* Map ipv4 address into v4-mapped-on-v6 address. */ 7531da177e4SLinus Torvalds if (sctp_sk(asoc->base.sk)->v4mapped && 7541da177e4SLinus Torvalds AF_INET == addr->sa.sa_family) { 7551da177e4SLinus Torvalds sctp_v4_map_v6((union sctp_addr *)sin6); 7561da177e4SLinus Torvalds sin6->sin6_addr.s6_addr32[3] = 7571da177e4SLinus Torvalds addr->v4.sin_addr.s_addr; 7581da177e4SLinus Torvalds return; 7591da177e4SLinus Torvalds } 7601da177e4SLinus Torvalds 7611da177e4SLinus Torvalds sin6from = &asoc->peer.primary_addr.v6; 7621da177e4SLinus Torvalds ipv6_addr_copy(&sin6->sin6_addr, &sin6from->sin6_addr); 7631da177e4SLinus Torvalds if (ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL) 7641da177e4SLinus Torvalds sin6->sin6_scope_id = sin6from->sin6_scope_id; 7651da177e4SLinus Torvalds } 7661da177e4SLinus Torvalds } 7671da177e4SLinus Torvalds 7681da177e4SLinus Torvalds /* Initialize a msg_name from an inbound skb. */ 7691da177e4SLinus Torvalds static void sctp_inet6_skb_msgname(struct sk_buff *skb, char *msgname, 7701da177e4SLinus Torvalds int *addr_len) 7711da177e4SLinus Torvalds { 7721da177e4SLinus Torvalds struct sctphdr *sh; 7731da177e4SLinus Torvalds struct sockaddr_in6 *sin6; 7741da177e4SLinus Torvalds 7751da177e4SLinus Torvalds if (msgname) { 7761da177e4SLinus Torvalds sctp_inet6_msgname(msgname, addr_len); 7771da177e4SLinus Torvalds sin6 = (struct sockaddr_in6 *)msgname; 7782c0fd387SArnaldo Carvalho de Melo sh = sctp_hdr(skb); 7791da177e4SLinus Torvalds sin6->sin6_port = sh->source; 7801da177e4SLinus Torvalds 7811da177e4SLinus Torvalds /* Map ipv4 address into v4-mapped-on-v6 address. */ 7821da177e4SLinus Torvalds if (sctp_sk(skb->sk)->v4mapped && 783eddc9ec5SArnaldo Carvalho de Melo ip_hdr(skb)->version == 4) { 7841da177e4SLinus Torvalds sctp_v4_map_v6((union sctp_addr *)sin6); 785eddc9ec5SArnaldo Carvalho de Melo sin6->sin6_addr.s6_addr32[3] = ip_hdr(skb)->saddr; 7861da177e4SLinus Torvalds return; 7871da177e4SLinus Torvalds } 7881da177e4SLinus Torvalds 7891da177e4SLinus Torvalds /* Otherwise, just copy the v6 address. */ 7900660e03fSArnaldo Carvalho de Melo ipv6_addr_copy(&sin6->sin6_addr, &ipv6_hdr(skb)->saddr); 7911da177e4SLinus Torvalds if (ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LINKLOCAL) { 7921da177e4SLinus Torvalds struct sctp_ulpevent *ev = sctp_skb2event(skb); 7931da177e4SLinus Torvalds sin6->sin6_scope_id = ev->iif; 7941da177e4SLinus Torvalds } 7951da177e4SLinus Torvalds } 7961da177e4SLinus Torvalds } 7971da177e4SLinus Torvalds 7981da177e4SLinus Torvalds /* Do we support this AF? */ 7991da177e4SLinus Torvalds static int sctp_inet6_af_supported(sa_family_t family, struct sctp_sock *sp) 8001da177e4SLinus Torvalds { 8011da177e4SLinus Torvalds switch (family) { 8021da177e4SLinus Torvalds case AF_INET6: 8031da177e4SLinus Torvalds return 1; 8041da177e4SLinus Torvalds /* v4-mapped-v6 addresses */ 8051da177e4SLinus Torvalds case AF_INET: 8067dab83deSVlad Yasevich if (!__ipv6_only_sock(sctp_opt2sk(sp))) 8071da177e4SLinus Torvalds return 1; 8081da177e4SLinus Torvalds default: 8091da177e4SLinus Torvalds return 0; 8101da177e4SLinus Torvalds } 8111da177e4SLinus Torvalds } 8121da177e4SLinus Torvalds 8131da177e4SLinus Torvalds /* Address matching with wildcards allowed. This extra level 8141da177e4SLinus Torvalds * of indirection lets us choose whether a PF_INET6 should 8151da177e4SLinus Torvalds * disallow any v4 addresses if we so choose. 8161da177e4SLinus Torvalds */ 8171da177e4SLinus Torvalds static int sctp_inet6_cmp_addr(const union sctp_addr *addr1, 8181da177e4SLinus Torvalds const union sctp_addr *addr2, 8191da177e4SLinus Torvalds struct sctp_sock *opt) 8201da177e4SLinus Torvalds { 8211da177e4SLinus Torvalds struct sctp_af *af1, *af2; 82252cae8f0SVlad Yasevich struct sock *sk = sctp_opt2sk(opt); 8231da177e4SLinus Torvalds 8241da177e4SLinus Torvalds af1 = sctp_get_af_specific(addr1->sa.sa_family); 8251da177e4SLinus Torvalds af2 = sctp_get_af_specific(addr2->sa.sa_family); 8261da177e4SLinus Torvalds 8271da177e4SLinus Torvalds if (!af1 || !af2) 8281da177e4SLinus Torvalds return 0; 8297dab83deSVlad Yasevich 8307dab83deSVlad Yasevich /* If the socket is IPv6 only, v4 addrs will not match */ 83152cae8f0SVlad Yasevich if (__ipv6_only_sock(sk) && af1 != af2) 8327dab83deSVlad Yasevich return 0; 8337dab83deSVlad Yasevich 8341da177e4SLinus Torvalds /* Today, wildcard AF_INET/AF_INET6. */ 83552cae8f0SVlad Yasevich if (sctp_is_any(sk, addr1) || sctp_is_any(sk, addr2)) 8361da177e4SLinus Torvalds return 1; 8371da177e4SLinus Torvalds 8381da177e4SLinus Torvalds if (addr1->sa.sa_family != addr2->sa.sa_family) 8391da177e4SLinus Torvalds return 0; 8401da177e4SLinus Torvalds 8411da177e4SLinus Torvalds return af1->cmp_addr(addr1, addr2); 8421da177e4SLinus Torvalds } 8431da177e4SLinus Torvalds 8441da177e4SLinus Torvalds /* Verify that the provided sockaddr looks bindable. Common verification, 8451da177e4SLinus Torvalds * has already been taken care of. 8461da177e4SLinus Torvalds */ 8471da177e4SLinus Torvalds static int sctp_inet6_bind_verify(struct sctp_sock *opt, union sctp_addr *addr) 8481da177e4SLinus Torvalds { 8491da177e4SLinus Torvalds struct sctp_af *af; 8501da177e4SLinus Torvalds 8511da177e4SLinus Torvalds /* ASSERT: address family has already been verified. */ 8521da177e4SLinus Torvalds if (addr->sa.sa_family != AF_INET6) 8531da177e4SLinus Torvalds af = sctp_get_af_specific(addr->sa.sa_family); 8541da177e4SLinus Torvalds else { 8551da177e4SLinus Torvalds int type = ipv6_addr_type(&addr->v6.sin6_addr); 8566a6ddb2aSSridhar Samudrala struct net_device *dev; 8571da177e4SLinus Torvalds 8586a6ddb2aSSridhar Samudrala if (type & IPV6_ADDR_LINKLOCAL) { 8596a6ddb2aSSridhar Samudrala if (!addr->v6.sin6_scope_id) 8601da177e4SLinus Torvalds return 0; 86140c9c31eSEric Dumazet rcu_read_lock(); 86240c9c31eSEric Dumazet dev = dev_get_by_index_rcu(&init_net, 86340c9c31eSEric Dumazet addr->v6.sin6_scope_id); 86440c9c31eSEric Dumazet if (!dev || 86540c9c31eSEric Dumazet !ipv6_chk_addr(&init_net, &addr->v6.sin6_addr, 866bfeade08SDaniel Lezcano dev, 0)) { 86740c9c31eSEric Dumazet rcu_read_unlock(); 8681669d857SVlad Yasevich return 0; 8691669d857SVlad Yasevich } 87040c9c31eSEric Dumazet rcu_read_unlock(); 8717dab83deSVlad Yasevich } else if (type == IPV6_ADDR_MAPPED) { 8727dab83deSVlad Yasevich if (!opt->v4mapped) 8737dab83deSVlad Yasevich return 0; 8741da177e4SLinus Torvalds } 8757dab83deSVlad Yasevich 8761da177e4SLinus Torvalds af = opt->pf->af; 8771da177e4SLinus Torvalds } 8781da177e4SLinus Torvalds return af->available(addr, opt); 8791da177e4SLinus Torvalds } 8801da177e4SLinus Torvalds 8816a6ddb2aSSridhar Samudrala /* Verify that the provided sockaddr looks sendable. Common verification, 8821da177e4SLinus Torvalds * has already been taken care of. 8831da177e4SLinus Torvalds */ 8841da177e4SLinus Torvalds static int sctp_inet6_send_verify(struct sctp_sock *opt, union sctp_addr *addr) 8851da177e4SLinus Torvalds { 8861da177e4SLinus Torvalds struct sctp_af *af = NULL; 8871da177e4SLinus Torvalds 8881da177e4SLinus Torvalds /* ASSERT: address family has already been verified. */ 8891da177e4SLinus Torvalds if (addr->sa.sa_family != AF_INET6) 8901da177e4SLinus Torvalds af = sctp_get_af_specific(addr->sa.sa_family); 8911da177e4SLinus Torvalds else { 8921da177e4SLinus Torvalds int type = ipv6_addr_type(&addr->v6.sin6_addr); 8936a6ddb2aSSridhar Samudrala struct net_device *dev; 8941da177e4SLinus Torvalds 8956a6ddb2aSSridhar Samudrala if (type & IPV6_ADDR_LINKLOCAL) { 8966a6ddb2aSSridhar Samudrala if (!addr->v6.sin6_scope_id) 8971da177e4SLinus Torvalds return 0; 89840c9c31eSEric Dumazet rcu_read_lock(); 89940c9c31eSEric Dumazet dev = dev_get_by_index_rcu(&init_net, 90040c9c31eSEric Dumazet addr->v6.sin6_scope_id); 90140c9c31eSEric Dumazet rcu_read_unlock(); 9026a6ddb2aSSridhar Samudrala if (!dev) 9036a6ddb2aSSridhar Samudrala return 0; 9041da177e4SLinus Torvalds } 9051da177e4SLinus Torvalds af = opt->pf->af; 9061da177e4SLinus Torvalds } 9071da177e4SLinus Torvalds 9081da177e4SLinus Torvalds return af != NULL; 9091da177e4SLinus Torvalds } 9101da177e4SLinus Torvalds 9111da177e4SLinus Torvalds /* Fill in Supported Address Type information for INIT and INIT-ACK 9121da177e4SLinus Torvalds * chunks. Note: In the future, we may want to look at sock options 9131da177e4SLinus Torvalds * to determine whether a PF_INET6 socket really wants to have IPV4 9141da177e4SLinus Torvalds * addresses. 9151da177e4SLinus Torvalds * Returns number of addresses supported. 9161da177e4SLinus Torvalds */ 9171da177e4SLinus Torvalds static int sctp_inet6_supported_addrs(const struct sctp_sock *opt, 9183dbe8656SAl Viro __be16 *types) 9191da177e4SLinus Torvalds { 9207dab83deSVlad Yasevich types[0] = SCTP_PARAM_IPV6_ADDRESS; 9217dab83deSVlad Yasevich if (!opt || !ipv6_only_sock(sctp_opt2sk(opt))) { 9227dab83deSVlad Yasevich types[1] = SCTP_PARAM_IPV4_ADDRESS; 9231da177e4SLinus Torvalds return 2; 9241da177e4SLinus Torvalds } 9257dab83deSVlad Yasevich return 1; 9267dab83deSVlad Yasevich } 9271da177e4SLinus Torvalds 92890ddc4f0SEric Dumazet static const struct proto_ops inet6_seqpacket_ops = { 9291da177e4SLinus Torvalds .family = PF_INET6, 9301da177e4SLinus Torvalds .owner = THIS_MODULE, 9311da177e4SLinus Torvalds .release = inet6_release, 9321da177e4SLinus Torvalds .bind = inet6_bind, 9331da177e4SLinus Torvalds .connect = inet_dgram_connect, 9341da177e4SLinus Torvalds .socketpair = sock_no_socketpair, 9351da177e4SLinus Torvalds .accept = inet_accept, 9361da177e4SLinus Torvalds .getname = inet6_getname, 9371da177e4SLinus Torvalds .poll = sctp_poll, 9381da177e4SLinus Torvalds .ioctl = inet6_ioctl, 9391da177e4SLinus Torvalds .listen = sctp_inet_listen, 9401da177e4SLinus Torvalds .shutdown = inet_shutdown, 9411da177e4SLinus Torvalds .setsockopt = sock_common_setsockopt, 9421da177e4SLinus Torvalds .getsockopt = sock_common_getsockopt, 943543d9cfeSArnaldo Carvalho de Melo .sendmsg = inet_sendmsg, 944543d9cfeSArnaldo Carvalho de Melo .recvmsg = sock_common_recvmsg, 945543d9cfeSArnaldo Carvalho de Melo .mmap = sock_no_mmap, 9463fdadf7dSDmitry Mishin #ifdef CONFIG_COMPAT 9473fdadf7dSDmitry Mishin .compat_setsockopt = compat_sock_common_setsockopt, 9483fdadf7dSDmitry Mishin .compat_getsockopt = compat_sock_common_getsockopt, 9493fdadf7dSDmitry Mishin #endif 9501da177e4SLinus Torvalds }; 9511da177e4SLinus Torvalds 9521da177e4SLinus Torvalds static struct inet_protosw sctpv6_seqpacket_protosw = { 9531da177e4SLinus Torvalds .type = SOCK_SEQPACKET, 9541da177e4SLinus Torvalds .protocol = IPPROTO_SCTP, 9551da177e4SLinus Torvalds .prot = &sctpv6_prot, 9561da177e4SLinus Torvalds .ops = &inet6_seqpacket_ops, 9571da177e4SLinus Torvalds .no_check = 0, 9581da177e4SLinus Torvalds .flags = SCTP_PROTOSW_FLAG 9591da177e4SLinus Torvalds }; 9601da177e4SLinus Torvalds static struct inet_protosw sctpv6_stream_protosw = { 9611da177e4SLinus Torvalds .type = SOCK_STREAM, 9621da177e4SLinus Torvalds .protocol = IPPROTO_SCTP, 9631da177e4SLinus Torvalds .prot = &sctpv6_prot, 9641da177e4SLinus Torvalds .ops = &inet6_seqpacket_ops, 9651da177e4SLinus Torvalds .no_check = 0, 9661da177e4SLinus Torvalds .flags = SCTP_PROTOSW_FLAG, 9671da177e4SLinus Torvalds }; 9681da177e4SLinus Torvalds 969e5bbef20SHerbert Xu static int sctp6_rcv(struct sk_buff *skb) 9701da177e4SLinus Torvalds { 971e5bbef20SHerbert Xu return sctp_rcv(skb) ? -1 : 0; 9721da177e4SLinus Torvalds } 9731da177e4SLinus Torvalds 97441135cc8SAlexey Dobriyan static const struct inet6_protocol sctpv6_protocol = { 9751da177e4SLinus Torvalds .handler = sctp6_rcv, 9761da177e4SLinus Torvalds .err_handler = sctp_v6_err, 9771da177e4SLinus Torvalds .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_FINAL, 9781da177e4SLinus Torvalds }; 9791da177e4SLinus Torvalds 98015efbe76SNeil Horman static struct sctp_af sctp_af_inet6 = { 981543d9cfeSArnaldo Carvalho de Melo .sa_family = AF_INET6, 9821da177e4SLinus Torvalds .sctp_xmit = sctp_v6_xmit, 9831da177e4SLinus Torvalds .setsockopt = ipv6_setsockopt, 9841da177e4SLinus Torvalds .getsockopt = ipv6_getsockopt, 9851da177e4SLinus Torvalds .get_dst = sctp_v6_get_dst, 9861da177e4SLinus Torvalds .get_saddr = sctp_v6_get_saddr, 9871da177e4SLinus Torvalds .copy_addrlist = sctp_v6_copy_addrlist, 9881da177e4SLinus Torvalds .from_skb = sctp_v6_from_skb, 9891da177e4SLinus Torvalds .from_sk = sctp_v6_from_sk, 9901da177e4SLinus Torvalds .to_sk_saddr = sctp_v6_to_sk_saddr, 9911da177e4SLinus Torvalds .to_sk_daddr = sctp_v6_to_sk_daddr, 9921da177e4SLinus Torvalds .from_addr_param = sctp_v6_from_addr_param, 9931da177e4SLinus Torvalds .to_addr_param = sctp_v6_to_addr_param, 9941da177e4SLinus Torvalds .cmp_addr = sctp_v6_cmp_addr, 9951da177e4SLinus Torvalds .scope = sctp_v6_scope, 9961da177e4SLinus Torvalds .addr_valid = sctp_v6_addr_valid, 9971da177e4SLinus Torvalds .inaddr_any = sctp_v6_inaddr_any, 9981da177e4SLinus Torvalds .is_any = sctp_v6_is_any, 9991da177e4SLinus Torvalds .available = sctp_v6_available, 10001da177e4SLinus Torvalds .skb_iif = sctp_v6_skb_iif, 10011da177e4SLinus Torvalds .is_ce = sctp_v6_is_ce, 10021da177e4SLinus Torvalds .seq_dump_addr = sctp_v6_seq_dump_addr, 1003b9031d9dSVlad Yasevich .ecn_capable = sctp_v6_ecn_capable, 10041da177e4SLinus Torvalds .net_header_len = sizeof(struct ipv6hdr), 10051da177e4SLinus Torvalds .sockaddr_len = sizeof(struct sockaddr_in6), 1006543d9cfeSArnaldo Carvalho de Melo #ifdef CONFIG_COMPAT 1007543d9cfeSArnaldo Carvalho de Melo .compat_setsockopt = compat_ipv6_setsockopt, 1008543d9cfeSArnaldo Carvalho de Melo .compat_getsockopt = compat_ipv6_getsockopt, 1009543d9cfeSArnaldo Carvalho de Melo #endif 10101da177e4SLinus Torvalds }; 10111da177e4SLinus Torvalds 101215efbe76SNeil Horman static struct sctp_pf sctp_pf_inet6 = { 10131da177e4SLinus Torvalds .event_msgname = sctp_inet6_event_msgname, 10141da177e4SLinus Torvalds .skb_msgname = sctp_inet6_skb_msgname, 10151da177e4SLinus Torvalds .af_supported = sctp_inet6_af_supported, 10161da177e4SLinus Torvalds .cmp_addr = sctp_inet6_cmp_addr, 10171da177e4SLinus Torvalds .bind_verify = sctp_inet6_bind_verify, 10181da177e4SLinus Torvalds .send_verify = sctp_inet6_send_verify, 10191da177e4SLinus Torvalds .supported_addrs = sctp_inet6_supported_addrs, 10201da177e4SLinus Torvalds .create_accept_sk = sctp_v6_create_accept_sk, 10211da177e4SLinus Torvalds .addr_v4map = sctp_v6_addr_v4map, 102215efbe76SNeil Horman .af = &sctp_af_inet6, 10231da177e4SLinus Torvalds }; 10241da177e4SLinus Torvalds 1025827bf122SSridhar Samudrala /* Initialize IPv6 support and register with socket layer. */ 1026270637abSVlad Yasevich void sctp_v6_pf_init(void) 10271da177e4SLinus Torvalds { 10281da177e4SLinus Torvalds /* Register the SCTP specific PF_INET6 functions. */ 102915efbe76SNeil Horman sctp_register_pf(&sctp_pf_inet6, PF_INET6); 10301da177e4SLinus Torvalds 10311da177e4SLinus Torvalds /* Register the SCTP specific AF_INET6 functions. */ 103215efbe76SNeil Horman sctp_register_af(&sctp_af_inet6); 1033270637abSVlad Yasevich } 1034270637abSVlad Yasevich 1035270637abSVlad Yasevich void sctp_v6_pf_exit(void) 1036270637abSVlad Yasevich { 1037270637abSVlad Yasevich list_del(&sctp_af_inet6.list); 1038270637abSVlad Yasevich } 1039270637abSVlad Yasevich 1040270637abSVlad Yasevich /* Initialize IPv6 support and register with socket layer. */ 1041270637abSVlad Yasevich int sctp_v6_protosw_init(void) 1042270637abSVlad Yasevich { 1043270637abSVlad Yasevich int rc; 10441da177e4SLinus Torvalds 1045827bf122SSridhar Samudrala rc = proto_register(&sctpv6_prot, 1); 1046827bf122SSridhar Samudrala if (rc) 1047827bf122SSridhar Samudrala return rc; 1048827bf122SSridhar Samudrala 1049827bf122SSridhar Samudrala /* Add SCTPv6(UDP and TCP style) to inetsw6 linked list. */ 1050827bf122SSridhar Samudrala inet6_register_protosw(&sctpv6_seqpacket_protosw); 1051827bf122SSridhar Samudrala inet6_register_protosw(&sctpv6_stream_protosw); 1052827bf122SSridhar Samudrala 1053827bf122SSridhar Samudrala return 0; 1054827bf122SSridhar Samudrala } 1055827bf122SSridhar Samudrala 1056270637abSVlad Yasevich void sctp_v6_protosw_exit(void) 1057270637abSVlad Yasevich { 1058270637abSVlad Yasevich inet6_unregister_protosw(&sctpv6_seqpacket_protosw); 1059270637abSVlad Yasevich inet6_unregister_protosw(&sctpv6_stream_protosw); 1060270637abSVlad Yasevich proto_unregister(&sctpv6_prot); 1061270637abSVlad Yasevich } 1062270637abSVlad Yasevich 1063270637abSVlad Yasevich 1064827bf122SSridhar Samudrala /* Register with inet6 layer. */ 1065827bf122SSridhar Samudrala int sctp_v6_add_protocol(void) 1066827bf122SSridhar Samudrala { 10671da177e4SLinus Torvalds /* Register notifier for inet6 address additions/deletions. */ 10681da177e4SLinus Torvalds register_inet6addr_notifier(&sctp_inet6addr_notifier); 1069827bf122SSridhar Samudrala 1070827bf122SSridhar Samudrala if (inet6_add_protocol(&sctpv6_protocol, IPPROTO_SCTP) < 0) 1071827bf122SSridhar Samudrala return -EAGAIN; 1072827bf122SSridhar Samudrala 1073827bf122SSridhar Samudrala return 0; 10741da177e4SLinus Torvalds } 10751da177e4SLinus Torvalds 1076827bf122SSridhar Samudrala /* Unregister with inet6 layer. */ 1077827bf122SSridhar Samudrala void sctp_v6_del_protocol(void) 1078827bf122SSridhar Samudrala { 1079827bf122SSridhar Samudrala inet6_del_protocol(&sctpv6_protocol, IPPROTO_SCTP); 1080827bf122SSridhar Samudrala unregister_inet6addr_notifier(&sctp_inet6addr_notifier); 10811da177e4SLinus Torvalds } 1082