aboutsummaryrefslogblamecommitdiffstats
path: root/net/tipc/socket.c
blob: 41688da233aba37f92416d01a59a9e6b68a74e31 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
  
                                     
  
                                                  
                                                         

                       
                                                                     

                                                                              







                                                                          
  













                                                                              


                              
                             

                               
                 
                       
                 
                 
                       
                   
                  
                    
                  
                  
 
                                                                          
                                                                            
                                 

                                          
                                                                              
 

                                 
                                           
                              
                                            
                                       

  




                                    


                                                                       



                                                                                
                                                               
                                                          
                                                                
                                       
                                               
                                                                             
                                                                        

                                                                             
                                            
                                                                     
                                                                        
                                        
                         
                                                                
                                 


                       



                          
                     
                   
                             
                                    

                                      
                             
                         
                           
                          

                        
                      

                        
                                  
                               
                                        
                            
                                 



                        
                           
  
 
                                                                     
                                             
                                              
                                                
                                             

                                                                               
                                                  
                                                             
                                                            
                                                              
                                                             
                                                
                                                                     

                                                  
                                                                                
                                                                             
                                                        
 


                                         
                               

                                                     




                                              
                                               
 
                                        

 
                                               
 
                                        

 
                                                  
 
                                                  

 
                                                                      
 
                                                              

 
                                                   
 
                                                   

 
                                                                          
 
                                                                 

 
                                                
 
                                          

 
                                                             


                                           
                                                 

                 
 




                                                       
                                                
 
                                               

 




                                            

















                                                                       

 



















                                                                          
   
                                                                      

                               
   
                                                 
 
                                                                   
                                                        

 










                                                                          
                                                                       




                                                               
   
                                                                

                               
   
                                             
 
                            
 

                                                            

 

                                              
                                                

 









                                                                       
                                                                     



                                                                  
                                                                     
 
                                   
                                               
                                           
                                 
 
                                             





                                                     
                                       



                                           
                                            

                            
                                            




                            








                                                        
                                       


                          


                        
                         
                             
                                             

                                
                              
                                                     
                                             

                                
                                
                                                     


                                                    







                                     





















                                                               

                                                                                
                                                                                



                                                                                

                                                                                



                                                                                
                                                                                






                                                                                

  
   
                                        
                                                    

                                            
                                           
  

                                                                           


                                        

                                                               
 
                                    
                        
                              
                             

                                


                                        

                             
                                  

                            
                                  

                        
                      
                               
                      
                
                                   

         
                                             
                                                                   
                       
                               
 
                          
                                       
                          
                                           
                                         
                         
 
                                                        
                        
                                 
                                         
                                  
                                                                         

                               



                                                            

                                                                   
 
                                           
                                                       
                            
                                                 
                                            

                                              
                                             
                                                 
                                  
                                         
 



                                                                              
                                              
                                                
                                             
                                                      
         
                                                         
                                                            


                 






                                                                          





                                                           
                                                              


                                       



                                                                               



                                                        
 





                                                                         
                                 
                 





                                                                       
         



                                            






                                                                            

                                                               


         
   
                                       






                                                                            
  





                                                                             
                                            
 
                                   
                              
 



                                                                                
                       
                         
 
                          

                      
                                                            

                                                
                           
                                       
                                                     
                                         
                            
 
                        
                                                                   
                         
                                               
                               
                                              
                        
 
                 


   
                                                                  


                                                                  
  


                                                                            
  
                                        


                                                                           
   

                                                                 
 
                                   
                                                                   
                                            
                          
 

                                   
                                                     

                          



                              







                                                       
 

                                                                    



                                                       
 
                                                              
                                                        



                                                        
 
                                  

                                                                         


                         

 
   
                                                      


                                                         
                                                                     
  
                                        
  

                                                                            
                                          
   
                                                                    
                                 
 
                                                                   

                                            
 
                                       
                   
                                               
                                                                          
                                         

                                                        
                
                                                
                                                                 
         
 


                                      

                                   
                             


   
                                                  

                                                     
             
  







                                                                             


                                                                            
   

                                                                 
 
                                   
                                            
                             
 
                                         
                                                         
 
                                           
                                                              
                                             
                                    
 

                               
                                                               
                                            
                                  
                         
                             
                                                                     
                                                         

                       
                                                              
                                            

                                                     
                                                                    
                              
                                                 

                                
                                                           
                      
         
                       

 



                                          
                        

                                       




                                                                          
                                                                        

                                   
                                            
                                          
                                       
                                          
                                                        
                                 
                               

               


                               
                                                                  


                                                                     
 


                                                                 
                                                         



                                        
                                          
                                          





                                                      
 
                                               
                                     
                                                           
 
                                                  


                                                                
                                                               
                                                          
         

                                

                              

 
   











                                                                        
                                                           
                                                        









                                                   
                                              

                                               
                                     
                                                                










                                                            
                                

                                           


                                                                              



















                                                                         












                                                                             


                                                                              











                                                                    
















                                                                           
                                          



                                         
                              
                              





                              
                                 
                                             
                                      

                               

                                                         



                                                                         
                                                                               


                                                                          

                                                                            

















                                                                                

                                                                                

















                                                                        











                                                                             
                                                                    


                                            
                                
                                                        
                                                      
                                                   




                                          
                                                                            


                                                                       


                          



                                            
                                     






                                                                     
                                          

                                 
                                                                     
 


                                                                 
                                               
                                     




                                                         
                                                                            


                          
                                                               





                                                                            



                    













                                                                          

                                            
                                          
                                       
                                       
                              
                   


                              


                                             
                                          


                                                               











                                                                              




                                                                              
   

                                                                   
 
                                      
                                      
                                   
                          
                                 
                                


                             
 
                                     
                                
 

                                                                



                                                           


                                          





                                                                           
                                       


                                                      















                                                                               
                 





                                                               
                                                               
                                                                  





                                                                        
                 








                                                                          
         
                                 

 







                                                                         
                                            

               




                                                    









                                                          
   
                                                                     
                         
                                   
   
                                                                              
                                                               
                                                              
 
                                            

                                      
                                 
                      
 
                                                       

                                                                               
                          
         
 




                                                                       









                                                                   

         
                                   
 

                                                    

                                                           

                                      


                                              


                                                        
                                                    


                                                             
         
     
                       

 
   
                                                       

                          
                                       
  
                                                         
                                             

                                                                        
  

                                                                  
                                            
                                                     
 









                                           
                                                                             
 
                                   
                                       




                                                                      
                                            
                                          
                                  
                                 
                             
                       
                    
 
                                                    
                                 
 









                                                                             

                                                                               

                                                                               

                                                                             

                               
 
                              
                                  
                                                    
                                             
         
 
                            
                                                
                                      
                                              


                                           
                                                       

                                                                           
                 
                                    
         
 


                                                                   
 


                                                     
                                               



                                                  
                                                                  
                                                                        

                                             

                                               

                                                    




                                                         

                               

         
                                                              

                                                                   


                          
                                     
                                                                

                                                         
                          

                                                                               
                               
         
 
                                                                           

                                                            
                                                 


                                     
 



                                                       

 
   
                                              
                          

                                               
  
                             
  

                                                                    
   
                                                                             
 
                                   


                      
                                              




                         
                                                                                

                                   
                                                                    
                                                                      
                                                       


                                            
                                       

                                     
                           
                           
 

                                     
 


                                                   

                                                                                
                                                                                
                 
                          
         
 
            

                                                               

                                                                 

                                 
                                                                          


















                                                                             
                                                                 
                                                                  




                                                 

                                                   


                                     
 
                                

 
   
                                                        
                          

                                         
  
                                    
  
                                                                  
   
                                                                              
 

                                         
 
                                             

 
                                                           
   
                                                                     
                                              
 

                                       
                                          
 
                            




                                          
 
                                                                       
                                                
                                                                   
                                                                            
                                                                    
                           
                                               





                                                     


   
                                                                        
                                  
                                
  

                                                              
                                                                        
 







                                                                       
                                


                                                       







                                                                           
                                  



                                                                                


   
                                                                                 
                                  
                                
                                          
  
                                                                     
  

                                           
                                                                       
                                                       
 
                             


                        
                     



                                           
                           

                                                          



                                               

                                                                       
                                   
                                  


                                               




                                                                              


                                                           


                                                          
                             




                                                 
                             




                                                 



                                                 

                      
                             
         




                                                                         



                 
                                                   
 

                                       
                                   
                             

                                           
 
                                   
                       


                                                                    
                 
                       
                           







                                                                 
                                                                    

 
                                                                  

                                   
                                                    
                             



                                 

                  
                                                                      
                                                             


                                                
                                                            
                                         

                                                                             
                                      
                                                               



                                                            


                              


                                             



                                     
         
                        


                   
   
                                                 
                                  
                                      
                        
  




                                                                 

                                                              
 
                                   
                                                          
                                            
                                      
                                  


                             
                     
 
                                            
                              

                               
                      

                                                               

                          
                                                          
 
                                                                               
            







                                                          
                                              

                                        
                                         
                    
 
                                                                           
                                      
                                                
                         
                          
                           
 



                                                                            
                                                  
                                                               
                



                                                                              
         

                          
 







                                                       
                                                                        


                                       

                                                                   
                                              





                                                                               
                                 
 


                               
                                                                        


                                                             
     
                         
                              

 
   
                                                 
                                  
                                          
                        

                                                                       



                                                         

                                                                 
 
                                   
                                            





                                               
                         
                     
 
                                            
                              

                               
                      
 
                                                  
                               
                          
         

                                                                  
 










                                                                           
 




                                                                  
 

                                                                               
                                                      
                                                                

                                      
                                           
                 
 

                                                                              
                                                    

















                                                                                
                 
 

                                   
 
                                         
 

                                                                                
                                                                            
                                              
 


                                                                      
 
                                                                               
     
                         
                                    


   








                                                                   
                                 

                                                                           







                                                                            
                                            




                                        
                                 

                                                                           


                          




                                                 






                                                          
                                            
                            


                                
                                                                

                         
                                                                      

                                                                    
                                     
                              
                                          
                      
                            
                                                                       
                      
                     
                                                                          
                                                          




                      


                                       


                       
   
                                                                                
                    

                                                                            
   
                                                                              
 
                                   
                                       
                                            





                                          
                            
 

                                     
                        
 

                               









                                                                               
                                                

                                                       
                 


                                                                                
 











                                                                          
                       
                                
                             
                         
                                             


                                                                          
                                     
                                    
                             
                              

                                                          
                                                                        


                                                                                
                                     




                                                               
                            
                
                                                              
         




                                                  


   

                                                                   
                
  

                                                                
  

                                                                 
  



                                    


                                                                       
                                                                      
 


                                            
                                        
                                                
 
                                          
                                                                       
 
                                                        
                                                
 
                               


   
                                                 
              
                            
  


                                                                      
                                        
  
   

                                                                    
 
                                                        
                                            
                                            
                                            

                                       
                                 
                                 
 
                                                              


                                         
 

                                                      
 


                                                           
                                                     
                                                                               
 




                                                                     

                                                       
                                               
                                                                          

                                                                  
                                                  
                                                
                 
 
                                    




                                                                              




                                                             

                                                                 
                                      
         
 
 
   
                                                                   
              
                
  
                               
   
                                                                    
 
                                                    
                                  
                           
 

                                      


                                                     
 
                                                             
                                                   



                 




                                                                            

                               
   
                                                                         
                                                                  
 

                                               

                         
                  

                                       
                                                                 

                               

                                                      


                                                                       
                                              
                                                           
                                 
                 

                                                                        
                                                 
                                        

                                                                


                                                                                
                                 
                 
 
                                                                            
                                                               
                                                    
                                          


                                                                       
                                                     
                 
                      
         


   



                                                                      
   
                                                              
 
                                  
                             
                
                              
                        
                            
 
                                      
                                       

                                                          
 


                                                                          
                                                                           
                                                                   
                         
                                                                             
                                                                   
                                     
                                 
                 











                                                                         
                                 

                                                                             
     
                                                   
                                                           
         

 

                                                                    
                                                    
                                   










                                                         
                                                    
                                                 

                                                                             



                        









                                                                              
   
                                                             


                                                  
                                                    


                                        

                                                                   
 
                                   
                                            

                                                                 
                                                                    
                     
                    
 


                                                    

                      




                              


                                                                    
                                      

                          
                                          
                              
                          
         


                                                         
                          


                                                         

         
                                


                               









                                                                          
                                                  


                                                       
                                                               



                                                                  
                                  



                                                        
                                  
                 


                                                                               

                              
                               

                      
                              
         
 

                         
                   

 
   
                                                                

                          
  

                                        
                                                    
 



                                   
                                                 
                         
 
                   

 













                                                                    
                                                                      






                                                            


                              


                                             




                                         
   
                                            


                                                    
  

                                        

                                                                               
 
                                            
                            
                                    
                             
                   
                
 
                      
 
                                          
                              

                          



                                                      


                                              
                                                                    

                          
                                                  
 
                              
                                    
                           
 






                                                                 
                                 

                                             
                                                                             
 
                                                           
                             

                                                             
         







                                                                 
                                         
                                                   


                                                                 
                                             

                             
     
                         



                   
                                             
                          
                                               

                                                                            
  

                                        
                                                      
 
                                   

                

                               
 
                      
 
                                                             

                                                  
 
                                                 
                                                     
                                                         


                                                     
                        
                


                                
                         


                   

























                                                                       












                                                                             
                                                 
 

                                                      

                                       
                   
 
                                     
                         



                                                                     
                                   
                             
                       
         
 

                                                       

                                                 
 
                           

                                    
                                                                             
 




                                                           
                     

 
                                                             

                                                           

                                       


                                 


                                           
                                  
                               

                                               

                                   
                                                                           
                                                             


                               
                                                          

                           


                 
                                                              

                                                            
                                             



                                 


                                           
                                                                                








                                                      
                                                                           
                                                                      


                               
                                                                   
                                                              

                       

                                           


                  


                                                               
                                    
 
                                                            
                                    
                              
                             
 


                                                  
                                             

                                                                             


                                                    
                                         

                                                                  


                                                     
                 
 

                                            

                                    

 
                                                                    
 
                                                            
                              
 
                        
                                                                      


                                    
 
                   

 
                                                
 


                                                            

                                                               
 





                                                                         

                                                                           

                                   

         
                  

 
                                                 
 
                                   
                                                                     
 
                                                                               
                                                            
                               
         

 




                                                         

                            
                                    

  
                                     
 
                                                            

                                                             

 
                                         
 

                                                            

                                                 
 
                                        

 


                                                                           






                                             

                                          

                               
                                                                             








                                               
                                                                    
                                                     
                 
                                            
                                  
                          
         
                                                                      

                                        
                                                      


















                                               
   
                                      




                                   

                                                                       
                           
  

                                        

                                                                 
 
                                   
                                            
                                   
                      
                    
 

                                                                

                                    





                                 
                          

                                       







                                                            




                                       
 
                      
 

                             
                                                     


                                              
                                                       
                    


                                           
                                                 

                               
                                                  
                      







                                                





                                               



                                       



                              

                         



                   
                                      




                                             

                                                                               
                           
  

                                        

                                                                 
 
                                   
                                            

                                 
                  
                
 

                                                                

                                    

                                
                           
 
                      


                             
                                            

                                
                                            

                                 
                                              

                               
                                          
                                                                         
                      
                                   
                                                                  
                      
                                   

                                                             


                                              





                                                                  



                              

                         

                                                  
 






                                                    

 
                                                                               
 

                                             






                                                            
                                                
                                                                             





                                                                                







                                                                




                                    



                                                                      














                                                       


                 

                                                             
                                         
                                      
                                  


                                       
                                          
                                         
                                       
                                    
                                     
                                         




                                          

                                          

  
                                            
                                      
                                  


                                       
                                          

                                       
                                    
                                     





                                           

                                          

  
                                            
                                      
                                  


                                       
                                          

                                       
                                    
                                     



                                          
                                          
                                          

                                          

  
                                                        
                                      
                                  
                                        




                                      

                                                   


   
                                                      
  

                                        
                          


                
                                             
                  
                                                                  




                                              
                                                                


                                              




                   
                                                
   
                           
 


                                                

                                                                
                                                                           







                                       
                                                             

                                 























                                                                            



                                                                      


                                                               
                                                                     











                                                              
                                                                

                                                                             
 
                             
                  

                                                                              
                                                                            


                                
                                                          

                                    

                                            

                                     












                                    



                                                                     
 
                                                           

                              
 





                                                            

                                         

                              
 







                                                
                 


                                            
         
                                   
    

                        

                               

                                                







                                                                   






                                                          
                                         




                                                 


                                               
                                                          






                                  

                                                                            









                                                                        
                                                          









                                                                            
                                                                            
                                                            




                                                        
                                                              





                                                                


                                                              










                                                            




                                                               











                                      
 

                                                                     
                                                          

 
                                                                


                                                             




                                                                              
                                                                            


                                
                                                          

























                                                                


                                                                        




                              
                                                                          















                                                                               
                                                   

         
                                                                       













                                                                       
                                     

                                    
                                            

                              
                          
                                                                    

                                                           


                                          


                                                                             





                                             
                                                                  




                         
                                              







                                                               
                           
 
                                 




                                
 



























































                                                                               





                                                


































                                                                           

























































                                                                               
                                                                                  






















                                                                           
/*
 * net/tipc/socket.c: TIPC socket API
 *
 * Copyright (c) 2001-2007, 2012-2017, Ericsson AB
 * Copyright (c) 2004-2008, 2010-2013, Wind River Systems
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the names of the copyright holders nor the names of its
 *    contributors may be used to endorse or promote products derived from
 *    this software without specific prior written permission.
 *
 * Alternatively, this software may be distributed under the terms of the
 * GNU General Public License ("GPL") version 2 as published by the Free
 * Software Foundation.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#include <linux/rhashtable.h>
#include <linux/sched/signal.h>

#include "core.h"
#include "name_table.h"
#include "node.h"
#include "link.h"
#include "name_distr.h"
#include "socket.h"
#include "bcast.h"
#include "netlink.h"
#include "group.h"
#include "trace.h"

#define CONN_TIMEOUT_DEFAULT    8000    /* default connect timeout = 8s */
#define CONN_PROBING_INTV	msecs_to_jiffies(3600000)  /* [ms] => 1 h */
#define TIPC_FWD_MSG		1
#define TIPC_MAX_PORT		0xffffffff
#define TIPC_MIN_PORT		1
#define TIPC_ACK_RATE		4       /* ACK at 1/4 of of rcv window size */

enum {
	TIPC_LISTEN = TCP_LISTEN,
	TIPC_ESTABLISHED = TCP_ESTABLISHED,
	TIPC_OPEN = TCP_CLOSE,
	TIPC_DISCONNECTING = TCP_CLOSE_WAIT,
	TIPC_CONNECTING = TCP_SYN_SENT,
};

struct sockaddr_pair {
	struct sockaddr_tipc sock;
	struct sockaddr_tipc member;
};

/**
 * struct tipc_sock - TIPC socket structure
 * @sk: socket - interacts with 'port' and with user via the socket API
 * @conn_type: TIPC type used when connection was established
 * @conn_instance: TIPC instance used when connection was established
 * @published: non-zero if port has one or more associated names
 * @max_pkt: maximum packet size "hint" used when building messages sent by port
 * @maxnagle: maximum size of msg which can be subject to nagle
 * @portid: unique port identity in TIPC socket hash table
 * @phdr: preformatted message header used when sending messages
 * #cong_links: list of congested links
 * @publications: list of publications for port
 * @blocking_link: address of the congested link we are currently sleeping on
 * @pub_count: total # of publications port has made during its lifetime
 * @conn_timeout: the time we can wait for an unresponded setup request
 * @dupl_rcvcnt: number of bytes counted twice, in both backlog and rcv queue
 * @cong_link_cnt: number of congested links
 * @snt_unacked: # messages sent by socket, and not yet acked by peer
 * @rcv_unacked: # messages read by user, but not yet acked back to peer
 * @peer: 'connected' peer for dgram/rdm
 * @node: hash table node
 * @mc_method: cookie for use between socket and broadcast layer
 * @rcu: rcu struct for tipc_sock
 */
struct tipc_sock {
	struct sock sk;
	u32 conn_type;
	u32 conn_instance;
	int published;
	u32 max_pkt;
	u32 maxnagle;
	u32 portid;
	struct tipc_msg phdr;
	struct list_head cong_links;
	struct list_head publications;
	u32 pub_count;
	atomic_t dupl_rcvcnt;
	u16 conn_timeout;
	bool probe_unacked;
	u16 cong_link_cnt;
	u16 snt_unacked;
	u16 snd_win;
	u16 peer_caps;
	u16 rcv_unacked;
	u16 rcv_win;
	struct sockaddr_tipc peer;
	struct rhash_head node;
	struct tipc_mc_method mc_method;
	struct rcu_head rcu;
	struct tipc_group *group;
	u32 oneway;
	u16 snd_backlog;
	bool expect_ack;
	bool nodelay;
	bool group_is_open;
};

static int tipc_sk_backlog_rcv(struct sock *sk, struct sk_buff *skb);
static void tipc_data_ready(struct sock *sk);
static void tipc_write_space(struct sock *sk);
static void tipc_sock_destruct(struct sock *sk);
static int tipc_release(struct socket *sock);
static int tipc_accept(struct socket *sock, struct socket *new_sock, int flags,
		       bool kern);
static void tipc_sk_timeout(struct timer_list *t);
static int tipc_sk_publish(struct tipc_sock *tsk, uint scope,
			   struct tipc_name_seq const *seq);
static int tipc_sk_withdraw(struct tipc_sock *tsk, uint scope,
			    struct tipc_name_seq const *seq);
static int tipc_sk_leave(struct tipc_sock *tsk);
static struct tipc_sock *tipc_sk_lookup(struct net *net, u32 portid);
static int tipc_sk_insert(struct tipc_sock *tsk);
static void tipc_sk_remove(struct tipc_sock *tsk);
static int __tipc_sendstream(struct socket *sock, struct msghdr *m, size_t dsz);
static int __tipc_sendmsg(struct socket *sock, struct msghdr *