/tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/

i/'>index : litmus-rt-budgetable-locks.git/.git
Unnamed repository; edit this file 'description' to name the repository.Zelin Tong
summaryrefslogblamecommitdiffstats
path: root/net/sctp/ipv6.c
blob: 0657d18a85bf7aa751a0456d0cc9adae3ff95e42 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
                             




                                           
                                                      


                  
                                             




                                                                      
                                                              





                                                                     

                                                        


                                                       
                                                    
  









                                                   

   

                                           





                          




                            
                       






                           
                      
                   









                            

                                                              



                                                                          
 





                                                                      

                                                                              

                                                              

                                                
                                                  
                      






                                                                               
                                                         
                                                                           
                                        



                                                                                   


                         
                                                         
                                                    
                                                                           


                                                                              
                                                                            
                                          

                                                          


                                      
                                                           
                          
                                             





                           
                                                        
                                              


                         

                                                                        

                               
                        


                                         
                               
                
                                            



                                                            

                                         
                                      
                                              
                                                                                   
                                              

                                         
                  
                                                                 








                                                             

                                                                                


                                                 
                                                                         


                                        

                                                       
                                













                                                     
                                  




                                  
                                                                              


                                             
                                                  
                
 
                                                                          
                                                     
 
                                              
 
                                                         
                                   
 

                                                            



                                                                           




                                                                      

                                                                             
 
                                                
                                     
                                        
                                  
                                             

                                          
                                            
                                  
                                        


                           
 
                                              
                                         

                                             
                                                                       
                                                          
 
                                                         
 

                                                                  

                    
                                                 
                                                     

                                                     

         



                                                                        
                                                    


                           




                                                                     
                           

                                                                               
                   
                                                                          

                                                                         


                                                                             
                                         





                                                                        


                                  




                                                                              

         




                                                                 
                                  
                                 

                                                          





                                                                             

                 
                    
                                                 
                                                     
                                                                                
                                                            
         
                          
 
    
                                   
                                    
 
                                            
                             
                                                   

                                                               
                                      

                              

                                       
         







                                                                          
                                                                    




                                                                             
                                                   
                                                       
                                               
 

                                           
 
                                                                    
 

                                                 
                                                 
         









                                                             
                        
                                                     
                                  


                       
                                     
                                                                
                                                         
                                                          
                           

                                                          
                                                         
                                                                
                                        




                                                             
                                       
                          


                                                         
                                                                        

                                          
                     






                                                                         
                           
                       
                                    
                                                          
                
                                 
                                                          
         





                                                                   
                               
                                                 




                                                                       
                                            



                                                                     

                                                 
                                                         





                                                                       
                                            



                                                                        
                
                                                     





                                                                 
                                                         



                                             
                                            











                                                                         
                                                   
                                            



                      

                                                                          
                                          
 

                                      
                                    










                                                         
                                                               






                                                                        
                                                               






                                                                        

                                                       













                                                                           
                                                                  








                                                      
                                                  





                                                                         
                                                                                  




                                       







                                                                          
                                                                   








                                                                        


                                                        







                                                                       


                                                          
                                                                                
































                                                                       
         







                                                                               
                           

                                                     
                                   
 
                                                                             




                                    
                                        




                                                    

                                                         



                                                     






                                                   


                                                                              

                                                             

                                                     
                                   









                                          



                                                                            
 











                                                            











                                                                       
                                                            




                                                                              
                                                      

 




                                                



                                                                 


                                      
 

                       
 


                                          
 












                                                                               
         

                                                                      





                                                                      
                              
                           
 















                                                                                
                                                                       
                                                         

                 

                                                                 









                                                                            
                                                       














                                                             
                                           





                                                        

                                                                 
                                               

                         
                                               
                                                             


















                                                                               
                                                               

                                       
                                                 
                                        

                                                    
                                                      
                                        
                                                                                
                                   
                                                                               
                                                  

                                         
                                          
                 
 




                                        
                                                                           









                                                                               
                                                               

                                       
                                                 

                                                    
                                        
                                                                           

                                                                           
                                 














                                                                     
                                                    
 





                                                        

 
















                                                                           
                                                     






                                                
                                          








                                                    
                    

                                                           
      






                                                       






                                                    


                                           
                                         
 
                                      

 
                                                      




                                                                 
                                       








                                                   

                                                     








                                                   
                                                 

                                                         
                    

                                                    
      

  
                                       







                                                      


                                              
                                        

  
                                                              
                          
 
                                                            
                                                   

                                                            
                                         










                                                              

                                             
               
                          




                                                                   

                 
 







                                                            


                                

                                                                      




                                                                   

 




                                                                
 
/* SCTP kernel implementation
 * (C) Copyright IBM Corp. 2002, 2004
 * Copyright (c) 2001 Nokia, Inc.
 * Copyright (c) 2001 La Monte H.P. Yarroll
 * Copyright (c) 2002-2003 Intel Corp.
 *
 * This file is part of the SCTP kernel implementation
 *
 * SCTP over IPv6.
 *
 * This SCTP implementation is free software;
 * you can redistribute it and/or modify it under the terms of
 * the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This SCTP implementation is distributed in the hope that it
 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
 *		   ************************
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with GNU CC; see the file COPYING.  If not, see
 * <http://www.gnu.org/licenses/>.
 *
 * Please send any bug reports or fixes you make to the
 * email address(es):
 *    lksctp developers <linux-sctp@vger.kernel.org>
 *
 * Written or modified by:
 *    Le Yanqun		    <yanqun.le@nokia.com>
 *    Hui Huang		    <hui.huang@nokia.com>
 *    La Monte H.P. Yarroll <piggy@acm.org>
 *    Sridhar Samudrala	    <sri@us.ibm.com>
 *    Jon Grimm		    <jgrimm@us.ibm.com>
 *    Ardelle Fan	    <ardelle.fan@intel.com>
 *
 * Based on:
 *	linux/net/ipv6/tcp_ipv6.c
 */

#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

#include <linux/module.h>
#include <linux/errno.h>
#include <linux/types.h>
#include <linux/socket.h>
#include <linux/sockios.h>
#include <linux/net.h>
#include <linux/in.h>
#include <linux/in6.h>
#include <linux/netdevice.h>
#include <linux/init.h>
#include <linux/ipsec.h>
#include <linux/slab.h>

#include <linux/ipv6.h>
#include <linux/icmpv6.h>
#include <linux/random.h>
#include <linux/seq_file.h>

#include <net/protocol.h>
#include <net/ndisc.h>
#include <net/ip.h>
#include <net/ipv6.h>
#include <net/transp_v6.h>
#include <net/addrconf.h>
#include <net/ip6_route.h>
#include <net/inet_common.h>
#include <net/inet_ecn.h>
#include <net/sctp/sctp.h>

#include <asm/uaccess.h>

static inline int sctp_v6_addr_match_len(union sctp_addr *s1,
					 union sctp_addr *s2);
static void sctp_v6_to_addr(union sctp_addr *addr, struct in6_addr *saddr,
			      __be16 port);
static int sctp_v6_cmp_addr(const union sctp_addr *addr1,
			    const union sctp_addr *addr2);

/* Event handler for inet6 address addition/deletion events.
 * The sctp_local_addr_list needs to be protocted by a spin lock since
 * multiple notifiers (say IPv4 and IPv6) may be running at the same
 * time and thus corrupt the list.
 * The reader side is protected with RCU.
 */
static int sctp_inet6addr_event(struct notifier_block *this, unsigned long ev,
				void *ptr)
{
	struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
	struct sctp_sockaddr_entry *addr = NULL;
	struct sctp_sockaddr_entry *temp;
	struct net *net = dev_net(ifa->idev->dev);
	int found = 0;

	switch (ev) {
	case NETDEV_UP:
		addr = kmalloc(sizeof(struct sctp_sockaddr_entry), GFP_ATOMIC);
		if (addr) {
			addr->a.v6.sin6_family = AF_INET6;
			addr->a.v6.sin6_port = 0;
			addr->a.v6.sin6_addr = ifa->addr;
			addr->a.v6.sin6_scope_id = ifa->idev->dev->ifindex;
			addr->valid = 1;
			spin_lock_bh(&net->sctp.local_addr_lock);
			list_add_tail_rcu(&addr->list, &net->sctp.local_addr_list);
			sctp_addr_wq_mgmt(net, addr, SCTP_ADDR_NEW);
			spin_unlock_bh(&net->sctp.local_addr_lock);
		}
		break;
	case NETDEV_DOWN:
		spin_lock_bh(&net->sctp.local_addr_lock);
		list_for_each_entry_safe(addr, temp,
					&net->sctp.local_addr_list, list) {
			if (addr->a.sa.sa_family == AF_INET6 &&
					ipv6_addr_equal(&addr->a.v6.sin6_addr,
						&ifa->addr)) {
				sctp_addr_wq_mgmt(net, addr, SCTP_ADDR_DEL);
				found = 1;
				addr->valid = 0;
				list_del_rcu(&addr->list);
				break;
			}
		}
		spin_unlock_bh(&net->sctp.local_addr_lock);
		if (found)
			kfree_rcu(addr, rcu);
		break;
	}

	return NOTIFY_DONE;
}

static struct notifier_block sctp_inet6addr_notifier = {
	.notifier_call = sctp_inet6addr_event,
};

/* ICMP error handler. */
static void sctp_v6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
			u8 type, u8 code, int offset, __be32 info)
{
	struct inet6_dev *idev;
	struct sock *sk;
	struct sctp_association *asoc;
	struct sctp_transport *transport;
	struct ipv6_pinfo *np;
	__u16 saveip, savesctp;
	int err;
	struct net *net = dev_net(skb->dev);

	idev = in6_dev_get(skb->dev);

	/* Fix up skb to look at the embedded net header. */
	saveip	 = skb->network_header;
	savesctp = skb->transport_header;
	skb_reset_network_header(skb);
	skb_set_transport_header(skb, offset);
	sk = sctp_err_lookup(net, AF_INET6, skb, sctp_hdr(skb), &asoc, &transport);
	/* Put back, the original pointers. */
	skb->network_header   = saveip;
	skb->transport_header = savesctp;
	if (!sk) {
		__ICMP6_INC_STATS(net, idev, ICMP6_MIB_INERRORS);
		goto out;
	}

	/* Warning:  The sock lock is held.  Remember to call
	 * sctp_err_finish!
	 */

	switch (type) {
	case ICMPV6_PKT_TOOBIG:
		if (ip6_sk_accept_pmtu(sk))
			sctp_icmp_frag_needed(sk, asoc, transport, ntohl(info));
		goto out_unlock;
	case ICMPV6_PARAMPROB:
		if (ICMPV6_UNK_NEXTHDR == code) {
			sctp_icmp_proto_unreachable(sk, asoc, transport);
			goto out_unlock;
		}
		break;
	case NDISC_REDIRECT:
		sctp_icmp_redirect(sk, transport, skb);
		goto out_unlock;
	default:
		break;
	}

	np = inet6_sk(sk);
	icmpv6_err_convert(type, code, &err);
	if (!sock_owned_by_user(sk) && np->recverr) {
		sk->sk_err = err;
		sk->sk_error_report(sk);
	} else {  /* Only an error on timeout */
		sk->sk_err_soft = err;
	}

out_unlock:
	sctp_err_finish(sk, asoc);
out:
	if (likely(idev != NULL))
		in6_dev_put(idev);
}

static int sctp_v6_xmit(struct sk_buff *skb, struct sctp_transport *transport)
{