mirror of
				https://github.com/nadoo/glider.git
				synced 2025-10-31 05:45:51 +08:00 
			
		
		
		
	rule: parse cidr once
This commit is contained in:
		
							parent
							
								
									1b400d984e
								
							
						
					
					
						commit
						6055efa537
					
				
							
								
								
									
										11
									
								
								rule.go
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								rule.go
									
									
									
									
									
								
							| @ -44,11 +44,14 @@ func NewRuleDialer(rules []*RuleConf, gDialer Dialer) *RuleDialer { | |||||||
| 			rd.ipMap.Store(ip, sd) | 			rd.ipMap.Store(ip, sd) | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		for _, cidr := range r.CIDR { | 		for _, s := range r.CIDR { | ||||||
|  | 			if _, cidr, err := net.ParseCIDR(s); err == nil { | ||||||
| 				rd.cidrMap.Store(cidr, sd) | 				rd.cidrMap.Store(cidr, sd) | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	return rd | 	return rd | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -73,14 +76,12 @@ func (p *RuleDialer) NextDialer(dstAddr string) Dialer { | |||||||
| 
 | 
 | ||||||
| 		var ret Dialer | 		var ret Dialer | ||||||
| 		// check cidr
 | 		// check cidr
 | ||||||
| 		// TODO: do not parse cidr every time
 |  | ||||||
| 		p.cidrMap.Range(func(key, value interface{}) bool { | 		p.cidrMap.Range(func(key, value interface{}) bool { | ||||||
| 			if _, net, err := net.ParseCIDR(key.(string)); err == nil { | 			cidr := key.(*net.IPNet) | ||||||
| 				if net.Contains(ip) { | 			if cidr.Contains(ip) { | ||||||
| 				ret = value.(Dialer) | 				ret = value.(Dialer) | ||||||
| 				return false | 				return false | ||||||
| 			} | 			} | ||||||
| 			} |  | ||||||
| 
 | 
 | ||||||
| 			return true | 			return true | ||||||
| 		}) | 		}) | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 nadoo
						nadoo