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) | ||||
| 		} | ||||
| 
 | ||||
| 		for _, cidr := range r.CIDR { | ||||
| 		for _, s := range r.CIDR { | ||||
| 			if _, cidr, err := net.ParseCIDR(s); err == nil { | ||||
| 				rd.cidrMap.Store(cidr, sd) | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 	} | ||||
| 
 | ||||
| 	return rd | ||||
| } | ||||
| 
 | ||||
| @ -73,14 +76,12 @@ func (p *RuleDialer) NextDialer(dstAddr string) Dialer { | ||||
| 
 | ||||
| 		var ret Dialer | ||||
| 		// check cidr
 | ||||
| 		// TODO: do not parse cidr every time
 | ||||
| 		p.cidrMap.Range(func(key, value interface{}) bool { | ||||
| 			if _, net, err := net.ParseCIDR(key.(string)); err == nil { | ||||
| 				if net.Contains(ip) { | ||||
| 			cidr := key.(*net.IPNet) | ||||
| 			if cidr.Contains(ip) { | ||||
| 				ret = value.(Dialer) | ||||
| 				return false | ||||
| 			} | ||||
| 			} | ||||
| 
 | ||||
| 			return true | ||||
| 		}) | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 nadoo
						nadoo