mirror of
https://github.com/nadoo/glider.git
synced 2025-02-23 17:35:40 +08:00
ipset: do not create ipset when ipset name is ""
This commit is contained in:
parent
ada5cdfcc3
commit
4729fc57f3
@ -32,8 +32,8 @@ General:
|
||||
TODO:
|
||||
- [x] Specify different remote dns server in rule file
|
||||
- [x] Improve DNS forwarder to resolve domain name and add ip to proxy rules
|
||||
- [ ] IPSet management
|
||||
- [ ] Improve DNS forwarder to resolve domain name and add ip to ipset
|
||||
- [x] IPSet management
|
||||
- [x] Improve DNS forwarder to resolve domain name and add ip to ipset
|
||||
- [ ] UDP Tunnel & UDP Relay
|
||||
- [ ] TUN/TAP device support
|
||||
- [ ] Code refactoring: support proxy registering so it can be pluggable
|
||||
|
@ -76,6 +76,11 @@ func NewIPSetManager(rules []*RuleConf) (*IPSetManager, error) {
|
||||
|
||||
var domainSet sync.Map
|
||||
for _, r := range rules {
|
||||
|
||||
if r.IPSet == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
CreateSet(fd, lsa, r.IPSet)
|
||||
|
||||
for _, domain := range r.Domain {
|
||||
@ -99,9 +104,8 @@ func NewIPSetManager(rules []*RuleConf) (*IPSetManager, error) {
|
||||
|
||||
// AddDomainIP used to update ipset according to domainSet rule
|
||||
func (m *IPSetManager) AddDomainIP(domain, ip string) error {
|
||||
if ip != "" {
|
||||
logf("domain: %s, ip: %s\n", domain, ip)
|
||||
|
||||
if ip != "" {
|
||||
domainParts := strings.Split(domain, ".")
|
||||
length := len(domainParts)
|
||||
for i := length - 2; i >= 0; i-- {
|
||||
@ -110,6 +114,7 @@ func (m *IPSetManager) AddDomainIP(domain, ip string) error {
|
||||
// find in domainMap
|
||||
if ipset, ok := m.domainSet.Load(domain); ok {
|
||||
AddToSet(m.fd, m.lsa, ipset.(string), ip)
|
||||
logf("ipset: domain: %s, ip: %s\n", domain, ip)
|
||||
}
|
||||
}
|
||||
|
||||
@ -148,7 +153,10 @@ func CreateSet(fd int, lsa syscall.SockaddrNetlink, setName string) {
|
||||
req.AddData(attrData)
|
||||
|
||||
err := syscall.Sendto(fd, req.Serialize(), 0, &lsa)
|
||||
logf("%s", err)
|
||||
if err != nil {
|
||||
logf("%s", err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func AddToSet(fd int, lsa syscall.SockaddrNetlink, setName, ipStr string) {
|
||||
@ -177,7 +185,9 @@ func AddToSet(fd int, lsa syscall.SockaddrNetlink, setName, ipStr string) {
|
||||
req.AddData(attrNested)
|
||||
|
||||
err := syscall.Sendto(fd, req.Serialize(), 0, &lsa)
|
||||
logf("%s", err)
|
||||
if err != nil {
|
||||
logf("%s", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Get native endianness for the system
|
||||
|
3
rule.go
3
rule.go
@ -113,8 +113,6 @@ func (rd *RuleDialer) Dial(network, addr string) (net.Conn, error) {
|
||||
// AddDomainIP used to update ipMap rules according to domainMap rule
|
||||
func (rd *RuleDialer) AddDomainIP(domain, ip string) error {
|
||||
if ip != "" {
|
||||
logf("domain: %s, ip: %s\n", domain, ip)
|
||||
|
||||
domainParts := strings.Split(domain, ".")
|
||||
length := len(domainParts)
|
||||
for i := length - 2; i >= 0; i-- {
|
||||
@ -123,6 +121,7 @@ func (rd *RuleDialer) AddDomainIP(domain, ip string) error {
|
||||
// find in domainMap
|
||||
if d, ok := rd.domainMap.Load(domain); ok {
|
||||
rd.ipMap.Store(ip, d)
|
||||
logf("rule: add domain: %s, ip: %s\n", domain, ip)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user