/arch/arm/mach-ks8695/

ip_vs_ctl.c?id=b4e955e9f372035361fbc6f07b21fe2cc6a5be4a'>diffstats
path: root/net/netfilter/ipvs/ip_vs_ctl.c
blob: 83395bf6dc35e2a3ea486246e98de99b6e1094da (plain) (tree)
1
2
3
4
5
6
7






                                                                            












                                                                             


                                           


                         
                             




                            
                           
                       


                                 
                        
 
                              
                          
                   



                          
                      
                     
                          
 
                          



                                                                
                                   
 
                      









                                        

             
                                                                         

 

                                                                            

                                                                 
 

                               
          

                                                                  
 
                                                                               
 

                         

      

                    
  

                                                                    
   
                                                         














                                                                         
                                                     
 

                           
                        

                                          
               
                                                


                            

                                                        
                        
                                                        



                            
                                                        
                        

                                                        
                 

                      
                                                

                      
                                           

                         

                                           
               
                                    


                            



                                                                   
                        
                                            



                            


                                                                   
                        

                                                     


                      
                                                           

                      
                                            

                        

                                          







                                               
                                                    











                                                
                                                    






                                       
                                                 
                           
                                                   

                                                                           

                          






                                      
 
                                                          
 

                                                                         

                                   
                                          
                                             
                                                                         
 
      





















                                                        
                                                             
                                        
                                                                 
 



                                              
                          
                                                                      
                                                              
 
                                                  
                                    
                    
 




                                                      
                                 
                                      
 

                                                                        




                                                               
                                                                                       
 
                                                                 


  
                                                                          




                                                    
                          

                                              
                                                                             
                                                              




                               
                                                                            
                   
                                                                           
                                                                
                                                                         

                  
                                                      
                   
                                                                     
                                                                             









                                                                           
                                                          




                                                      
                                                                             
                                                              



                               
                                                        
                                            
                
                                                            
                                            








                                          
                                                                     
   
                                    
                                                                     
                                                                   
 
                          


                                                
                                                                   
 
                                                                       

                                                              
                                           
                                                  
                                             
                                 










                                                     
                                    
                                                                   
 
                          


                                                
                                                   
 
                                                                           
                                                          
                                             
                                 






                                   
                                         
                      
                                                                                 
                                                                 

                                  
 


                                                      
                     
                                                             


                                 




                                                              
                                                                     
 


                                                                              



                                                                
                                                                               


                       
                                                     


                                                                 
                                                                         


         



                                                                








                                                                    
                                           

 

                                                         
                                         


                   
                                                         
 




                                                                 
 

                                                                     
                                                
                                                               

                                                                  
                                                



                                                                         
         





                                           
                                                   

                                                                           
 
                                                  






                                                      
 
                                                                


                                  

                                                                           
 
                          
 

                              




                                                             

                                                                   

                                                                 

 

                                                    

          
                                             
           


                                             
         

 
                                                           
                                                                            
                                                                          
 
                          

                                
                                                
                                                  
 




                                                                       
                                 
                                    

                 
 
                     

 





























                                                                           

                                                         

                          

                                                                





                                                     
                                                                   


                                                                    







                                    

                                                   
                                                   


                                                     
                                                
   
                                                                                    
                                                                   

                                                                   

                                                                              


                                  
                            
 
                                                                               

                            

                                                                           
                                                            
                  
                                                                            

                    
 










                                                                             

                                                            
                                   
 




                                                                  

 










                                                                           

                                                                   
 
                                
                                            



                                        

                                                              


                                                                        
                                                                    
                                                
                                                            

                                                                    



                                                      
                                                                            

                                                   
                                                
                                 


                 





                                               

 

                                                    

                                                                            
                                      
                                    
                                          
                                      
 







                                                                     
                                         
   
                                                        


                                      




                                                                        


         
           
                                                                   
 
                                                                           








                                           
                                       


                                   

           














                                                                               


                                           
 

                                                                  
                                                                      






                                           
                                    
 
                                     





                                                 

                                                                       
 
                                            
                                      
                                      

                       





                                                                       



                                                              

                                                 

                                                                
 
                                                                        
                                                                        


                                                    
                                                                      

                                           
                                          


                                                             



                                                  

                                                          

                                            
                                     

                                                       
                                                       









                                                                              
 

                             
                                      
                                      
                                        
 
                  
                                                               
                                                                
                                 

                                                                     
                                                   
                

                                                                     
                                                   
         






                                                  
                                                                             


                                          
                              


                         
                        
                                    
                                                         

                                                       
                                                                                    



                                       
                                                                       


                                                               
 
                                                              
                         
                               
 
                                                                    
                                  
                               
 





                                                                        
                             
                                       
                                

                                    
                                                              




                                           
                                       
 
                                       

                                          
                                                 




                         



                       






                                                  
                                                                             

                                
                                 
                                   




                                
                                                                         



                                                      

                                                                                


                               
                                                         
 

                                                    
                                                                
                          
 
                           
                                                                      






                                                            
                                                                   
 
                           

                                                                     
                                                                              
                                                           



                                                                    


                                                         
                  
                                                             
                   
                                                        
         

                         
                   






                                               
                                                                              

                                
                                 
                                   



                                
                                                                         



                                                      

                                                                                


                               
                                                         
 

                                                    
                                                                
                          
 
                           
                                                                     


                               
                                                 




                         


                                                                        
                                                                              
                                          
 
                                                 



                                                                    
                              
 


                                                                               
                                                    

                                                      
                                                                    
                                                
                                                   
                             
                                               














                                                          
                                    
                         
 
                                
                                                        
 

                                              
 
                                                                     
                                             

                                                   






                                                        
                                                                             

                                
                                   


                         

                                                    
                                                                      
                          
 
                           
                                                                         


                               




                                            


                                      
                                                 





                         
                                                         
 
                                                                        
                                       
                                    


                                                                         
                                                     
                                 







                                                                      

                                                                              
                                                                    





                                                  
                                                                    

                                            




                                                 
                                                                             
                                               
 
                       
                                             
                                   





                                                     







                                                                        

         
                                        
                                                    







                                                                        
                        






                                                        


         
                                                                
                          
                                                            


                              
                                                                   

                                   
                             
         
 






                                                                  
                                               

                                    
                        
                                    
                                                       




                                       
                         

                                           
                                         


                                         





                                                       
 
                                   
                                      

                  

                                                 
                                                  
                                
                                                   

                                                    
 
                                                 


                                                                       
                                     

                                                     
                            

                     

                                                    

                 
 
         
                          

                                                   

                                   
                         
 










                                                       
                                                                                
 
                                                         
                                                   
                    
                                              



                                                   






                                                                        


                          
                                        
                                                    








                                                                        
                        






                                                        


         

                                                                 





                                                               
                                            





                                                               
                 
         







                                                   
                                                       
                           
                                                







                                                                              
 
    
                                       
                             


                   




                                                                    
                                                                        


                                          
                                
                                            
 

                                                                       
                                     
 
                                                     

                              

                                                                 
                                       
 

                                                       

                                                    

                             




                                                                         
                                                           





                                                 
                                                  
                                
                                                   



                                                     
                                   





                                           
                                                                          
   
                                                                         
 
                                        

                                                              


                                           

                              
                                          








                                                       
                                         







                                      
                                                             

                

                                  

          
                                                                       

                                                       

                                                                        
                                              
                                                                   






                                                       

                                                                            
                                              
                                                                   





                 



                                                       
                                                       



                                                
                                


                                     

                                               
                  
                                                                 
 

                                        
                                      

                                                                



                                                                              
                                                            
                                              



                                        

                                                                       

                                                                            
                                     
 
                                                                  
                                       
                                                



                                  
                                          




                                                           
                                                                          
                                                

                                                                             
                                                                    



                                 
                                                                              
                                                

                                                                             
                                                                    





                                 

                                                              
                                            
         
                                               



                                     







                                                        



                                                               


                 
                                                  




                                                       
                                                                          
                                              
                                                        



                                                       
                                                                              
                                              
                                                        


                 
                                           


                 
                    



                     
          
                                                        

                                                                     
                                                



                                
                                                             




                                                       
                                                   




                  
          
                                                          








                                                                       
                                                             

                                                   





                                               
          
                                                     










                                                                     





                  
                                                      










                                                                   



                  


                                                            
                                                         
                                                         



                                     
                                               

                                              
                                                
          
         
                                                

                                              
                                                

          
                                               

                                              
                                                       

          
                                                

                                              
                                                       
          


                                              




                                                 
         
                                               

                                              
                                                       
          

                                                 



                                                 

                                                 

                                              
                                                    
          
         


                                               
                                                     

          





                                                      
                                                  
                                                        
                                       
                                                         







                                                   











                                                       











                                                












                                                                                













                                                        




                                                  





                                                





                                                





                                                    





                                                  





                                                    








                                                            
           

  
      
 


                     
                                                                               
                                 






                                                                 
                                                            
















                                                                               
                                            
                                                





                                                        
                                                                              
                                                                








                                                              

                                                                        
                                                                










                                                                    
                       
 
                        





                                                                            
                             











                                                              


                                                                            

                                                             


                                                                                









                                                  


                                                                    


                                                     


                                                                            






                                                              
                       
 
                          







                                                                         
                                                                           




                                                                                          

                                                        


                                                             
                                                                                
                                                                
 

                                      


                                                     
                                                                      
                                                                           
                                                          
                                                            
                                                       

                            
                                                                       


                                                                           
                                                      
                                                                                           
                        
                                                          
                                                           
                                                                                   
                 







                                                               
                                                                           


                                                 
                                                             
                                                                           
                                                           
















                                                                                          




                 
                                                         





                                      

                                                          
                                                   
                                 



                                                                                   

                                                                                   
 
                                                           







                                                                                
                     






                                                                                   



                 


                                                                 
                                                                  
                                                                        
                                   




                                                                                       

                                                                                       

                                  

                                                                     
                                                              

                    
                                                                     




                                                   
                                                                      
 



                                                                   

         
                                             
 





                                                             
 
                                                                                     
                     






                                                                                       


                 




                                                                   
                                                                                   
 
                                                                      
                                    
      
 






                                                                 
                                                             
                                                          



                                              
                                                             
                                                       





                                                  
                                                             
                                                     





                                              
                                                      
 


                                          

  



























                                                                              


                                                                         

                                       
















                                                                        

                                         





                                                            
                                          

 


                                                                               
                                       
                
                                          

                                               
                                  

                                             
                                                
 
                                        
                                                              

                              

                                                           


                                                       








                                                




                                                                               
                                                      


                                                        



                                                                 
                                                
                                                                       

                                                      
                                                                

                                                        


                             
                                   

                                               
                                               


                                                             
                                                                                
                                

         






                                                                           


                                                                        
                                                                  
                                                   



                                        






                                                                    


                                                                              
                                                                 
                                                    
                                         




                                                                          
                        
                             
                                                                        
                                                                  
            
                                                                       
                          

                                   
                                                                 
                             
                                






                                      
                                                                   

                               
                                                     









                                              
                                                  

                                   
                                                   

                                  
                                                  




                              
             
                                     








                                           

                                                                              
                                      
                                   
                         

                                                             
                                                  
                                      
                                 

                                  
                                                                      



                                         

                                                      


                 
                                                    
                                                                 







                                                                   
                                                                          
                                                                       
                                                                      

                                         

                                                       
                                                         










                                                                  
                                                                              
                                                                       
                                                                      

                                         

                                                       
                                                         








                                                                  
    



                   
                                                                                    


                                                             
                                                      

                    
                        
                        
                                                                       
            
                                                                               
                                                      
                          
 



                                              
                                           
 
                                                 



                                                                       





                                                                          
                                                   







                                                                              

                                                                       






                                                                  





                             
                                                                           
 
                                                                      
                                    
      
 

                                  
                             
                                                     

                                                                          

                             
                                                     
                        
                                                                   


      








                                                                              
 







                                                                       

  

                                                      


                                                                       
                                          
                    
                             
                                       
                                                
 
                     
                                        
                                                              

                              


                                                           


                                                                      


                               
                                                    
                               






                                                            
                                              

                                                            
                                                                     
                                                        
                                                        


                                                            
                                                                     
                                                        
                                                        





                                                           
 
                                   





                                                                            
                                                                           











                                                                  
                                                
                                                       













                                                                               
                                                                 


                                      
                                                                   






                                                  
                                        

                                                          
                                      
                                
                                  
                                                                                 
                    
                                                                 

                                                                          
                                  



                                                                           













                                                                         
                                                                 


                                      
                                                                






                                            
                                               




                                                           



                              
    
                                     











                                               
                                      

  




                            
                                            














                                                                                
                                                                             
                                                              
                                                              



                                                                             










                                                                                
                                                                                

                                                                         



















                                                                                
                                                              


                                                                         









                                                                              



                                                                              
















                                                                            

                                                                      
 


                                 



















                                                                              
                                     




                                    






                                                             
                                      
                            


                                                         
                                   
                         




                                                                

                                                        
                          

                                                                        
                

                                                                                      
                                                                     
                                             

         
                                                             
                                                  
                                                   
                                                                        
                                                                           

                                                                         
                                                                   
                                     



                                                                         
















                                                               
                                                                              







                                                          

                              











                                                                

                                                


                                                  
                                                                        
                                                                  








                                                                        
                                                                            
                                                                  














                                                                        










                                                 
                                                            
                                                                         

                                                                       


                                                                                
                                  


                                                              

                                                           










                                                                                

                                       
                                       
                                         







                                                                      
                                                    


                                 
                        
                         
                                                                         
            
                                                                          
                                                                    
                          

                       

                                                                            
                                                                            

                                           

                                                            
                                                      









                                                                            
                        
                                                 



                                                           
                                                       
                                                                 
                                                         
                                                          




                 
                                                                             
                                                                        
 
                                            
                                  

                
                                                                  
                                        




                                                                             
                                   




                                                          
                                                                                 
                                                                 











                                                                           

                                                                   
                                     



                                                                          















                                                                             
                                                                              







                                                          

                              













                                                             
                                            
                                                



                                                                    
                                                                       
                                                      

                             
 
                                                                          
                                













                                                               






                                     
                                                                    



                                                                    
                                       


                                                                  

                                                            



                                                     
                                                            



                                    

                                         
                                                                
                                             
 




                                                         






















                                                                             
                                                                   
                                                                 






                                                              
                                                              

                                                                            


                                                                             
                                     










                                                                        








                                        
                                                                   
                                                                 


                                                              
                                                                              




                                                          
                                                  

                                     

                              








                                                               
                                            

                                                
                                      
                                                                      
                                                                   
                                                                




                                             
                                                                      
                                                                   
                                                                





                                             
                                        



                        
                                                                                
 

                                      

                
                                 



                                                  






                                                                         
 






























                                                                       


                                                                         
                                                 

                               
                                         
                                                                            
                   

 
                                                                                
 

                


                                           
                                      
                                    


                                                                           

 
                                                                                


                                    
                                       










                                                                              
                                           

 
                                                                             
 
                               

                                                


                                 
                                                                       




                                                                        
                                                                        
                                 

                                               
                                                                        
                    
                                                                        
         

    









                                                                          

                                                
 




                                    
                                               

                                                
                                                               


                                                         
                                           








                                                                             
                                                   
                                                                          
                                                            


                         


















                                                                               








                                                                           
 




                                                   
                                                                      


                                                                       
                                               













                                                                   




                                  
                                                                   







                                                     
                                                     

















                                                   









                                                                          

                                                









                                                 
                                                            

















                                                                               
                                                   
                                                                                  




                                                                













                                                     
                                               
                             




                                                                   

                             

                                                                               





                               




                                                                  



                                
                                       


                 
                                                        










                                     
                                                 




















































                                                   
                                                




                                              
                                                


































                                                  
                                                               


                                            
                                            





                                                                           

                                           
                                                        








                                                   


                             
                    
                                                                            
 
                                    
                
                              
 



                                               



                                                                    
                                       



                                                                


                                        



                                                                  














                                                     

                                                   
                                                          



                                                                 

                                                           

                                                    
                                                                  

                                                                

                                                                



                                                                             
                                                      

                                                  
                                                    

                                                        
                                                      
                                                        
 
                                                                        


                                            
                               
         
                                                      
                               


                                                                         
 
                 

 
                                                                                
 
                                    
 

                                                      
                                                      
                                                     


                                        



     

                                                                                          
 
      
 



                                                   
                                                              
 
                   
 

                                                   
                                                      

                                          
                                               
                                                                         

                                              
                                               


                                                                        
                                      
                               
 





                                                                          

                                              

                                                                             



                                                                            
 
                                                




                         
                                              


                       
                                                                  
 
                                  
                                               


                                                                     
                                              

 
                                        
 
                
 

                                                   
                                                     
                              

         

                                    
                                                                       
                              
         
                 
 


                                               
                   

 












                                               
                                                       
                                                        

                                                           











                                                               



                                
                                                           

                         
/*
 * IPVS         An implementation of the IP virtual server support for the
 *              LINUX operating system.  IPVS is now implemented as a module
 *              over the NetFilter framework. IPVS can be used to build a
 *              high-performance and highly available server based on a
 *              cluster of servers.
 *
 * Authors:     Wensong Zhang <wensong@linuxvirtualserver.org>
 *              Peter Kese <peter.kese@ijs.si>
 *              Julian Anastasov <ja@ssi.bg>
 *
 *              This program 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 of the License, or (at your option) any later version.
 *
 * Changes:
 *
 */

#define KMSG_COMPONENT "IPVS"
#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt

#include <linux/module.h>
#include <linux/init.h>
#include <linux/types.h>
#include <linux/capability.h>
#include <linux/fs.h>
#include <linux/sysctl.h>
#include <linux/proc_fs.h>
#include <linux/workqueue.h>
#include <linux/swap.h>
#include <linux/seq_file.h>
#include <linux/slab.h>

#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>
#include <linux/mutex.h>

#include <net/net_namespace.h>
#include <linux/nsproxy.h>
#include <net/ip.h>
#ifdef CONFIG_IP_VS_IPV6
#include <net/ipv6.h>
#include <net/ip6_route.h>
#endif
#include <net/route.h>
#include <net/sock.h>
#include <net/genetlink.h>

#include <linux/uaccess.h>

#include <net/ip_vs.h>

/* semaphore for IPVS sockopts. And, [gs]etsockopt may sleep. */
static DEFINE_MUTEX(__ip_vs_mutex);

/* sysctl variables */

#ifdef CONFIG_IP_VS_DEBUG
static int sysctl_ip_vs_debug_level = 0;

int ip_vs_get_debug_level(void)
{
	return sysctl_ip_vs_debug_level;
}
#endif


/*  Protos */
static void __ip_vs_del_service(struct ip_vs_service *svc, bool cleanup);


#ifdef CONFIG_IP_VS_IPV6
/* Taken from rt6_fill_node() in net/ipv6/route.c, is there a better way? */
static bool __ip_vs_addr_is_local_v6(struct net *net,
				     const struct in6_addr *addr)
{
	struct flowi6 fl6 = {
		.daddr = *addr,
	};
	struct dst_entry *dst = ip6_route_output(net, NULL, &fl6);
	bool is_local;

	is_local = !dst->error && dst->dev && (dst->dev->flags & IFF_LOOPBACK);

	dst_release(dst);
	return is_local;
}
#endif

#ifdef CONFIG_SYSCTL
/*
 *	update_defense_level is called from keventd and from sysctl,
 *	so it needs to protect itself from softirqs
 */
static void update_defense_level(struct netns_ipvs *ipvs)
{
	struct sysinfo i;
	static int old_secure_tcp = 0;
	int availmem;
	int nomem;
	int to_change = -1;

	/* we only count free and buffered memory (in pages) */
	si_meminfo(&i);
	availmem = i.freeram + i.bufferram;
	/* however in linux 2.5 the i.bufferram is total page cache size,
	   we need adjust it */
	/* si_swapinfo(&i); */
	/* availmem = availmem - (i.totalswap - i.freeswap); */

	nomem = (availmem < ipvs->sysctl_amemthresh);

	local_bh_disable();

	/* drop_entry */
	spin_lock(&ipvs->dropentry_lock);
	switch (ipvs->sysctl_drop_entry) {
	case 0:
		atomic_set(&ipvs->dropentry, 0);
		break;
	case 1:
		if (nomem) {
			atomic_set(&ipvs->dropentry, 1);
			ipvs->sysctl_drop_entry = 2;
		} else {
			atomic_set(&ipvs->dropentry, 0);
		}
		break;
	case 2:
		if (nomem) {
			atomic_set(&ipvs->dropentry, 1);
		} else {
			atomic_set(&ipvs->dropentry, 0);
			ipvs->sysctl_drop_entry = 1;
		}
		break;
	case 3:
		atomic_set(&ipvs->dropentry, 1);
		break;
	}
	spin_unlock(&ipvs->dropentry_lock);

	/* drop_packet */
	spin_lock(&ipvs->droppacket_lock);
	switch (ipvs->sysctl_drop_packet) {
	case 0:
		ipvs->drop_rate = 0;
		break;