@@ -30,78 +30,72 @@ type pfdnsRefreshableConfig struct {
30
30
}
31
31
32
32
func newPfconfigRefreshableConfig (ctx context.Context ) * pfdnsRefreshableConfig {
33
- p := & pfdnsRefreshableConfig {
33
+ rc := & pfdnsRefreshableConfig {
34
34
DNSFilter : cache .New (300 * time .Second , 10 * time .Second ),
35
35
IpsetCache : cache .New (1 * time .Hour , 10 * time .Second ),
36
36
}
37
- pfconfigdriver .FetchDecodeSocket (ctx , & p .registration )
38
- pfconfigdriver .FetchDecodeSocket (ctx , & p .isolation )
39
- pfconfigdriver .FetchDecodeSocket (ctx , & p .PfConfDns )
40
- p .PassthroughsInit (ctx )
41
- p .PassthroughsIsolationInit (ctx )
42
- p .recordDNS = p .PfConfDns .RecordDNS == "enabled"
43
- return p
37
+ pfconfigdriver .FetchDecodeSocket (ctx , & rc .registration )
38
+ pfconfigdriver .FetchDecodeSocket (ctx , & rc .isolation )
39
+ pfconfigdriver .FetchDecodeSocket (ctx , & rc .PfConfDns )
40
+ rc .PassthroughsInit (ctx )
41
+ rc .PassthroughsIsolationInit (ctx )
42
+ rc .recordDNS = rc .PfConfDns .RecordDNS == "enabled"
43
+ return rc
44
44
}
45
45
46
- func (pf * pfdnsRefreshableConfig ) PassthroughsInit (ctx context.Context ) error {
47
- pfconfigdriver . FetchDecodeSocket ( ctx , & pf . registration )
46
+ func (rc * pfdnsRefreshableConfig ) PassthroughsInit (ctx context.Context ) error {
47
+ rc . FqdnPort = make ( map [ * regexp. Regexp ][] string )
48
48
49
- pf .FqdnPort = make (map [* regexp.Regexp ][]string )
50
-
51
- for k , v := range pf .registration .Wildcard {
49
+ for k , v := range rc .registration .Wildcard {
52
50
rgx , _ := regexp .Compile (".*" + k )
53
- pf .FqdnPort [rgx ] = v
51
+ rc .FqdnPort [rgx ] = v
54
52
}
55
53
56
- for k , v := range pf .registration .Normal {
54
+ for k , v := range rc .registration .Normal {
57
55
rgx , _ := regexp .Compile ("^" + k + ".$" )
58
- pf .FqdnPort [rgx ] = v
56
+ rc .FqdnPort [rgx ] = v
59
57
}
60
58
61
59
return nil
62
60
}
63
61
64
- func (pf * pfdnsRefreshableConfig ) PassthroughsIsolationInit (ctx context.Context ) error {
65
- pfconfigdriver .FetchDecodeSocket (ctx , & pf .isolation )
66
-
67
- pf .FqdnIsolationPort = make (map [* regexp.Regexp ][]string )
62
+ func (rc * pfdnsRefreshableConfig ) PassthroughsIsolationInit (ctx context.Context ) error {
63
+ rc .FqdnIsolationPort = make (map [* regexp.Regexp ][]string )
68
64
69
- for k , v := range pf .isolation .Wildcard {
65
+ for k , v := range rc .isolation .Wildcard {
70
66
rgx , _ := regexp .Compile (".*" + k )
71
- pf .FqdnIsolationPort [rgx ] = v
67
+ rc .FqdnIsolationPort [rgx ] = v
72
68
}
73
69
74
- for k , v := range pf .isolation .Normal {
70
+ for k , v := range rc .isolation .Normal {
75
71
rgx , _ := regexp .Compile ("^" + k + ".$" )
76
- pf .FqdnIsolationPort [rgx ] = v
72
+ rc .FqdnIsolationPort [rgx ] = v
77
73
}
78
74
79
75
return nil
80
76
}
81
77
82
- func (p * pfdnsRefreshableConfig ) IsValid (ctx context.Context ) bool {
83
- return pfconfigdriver .IsValid (ctx , & p .registration ) && pfconfigdriver .IsValid (ctx , & p .isolation ) && pfconfigdriver .IsValid (ctx , & p .PfConfDns )
78
+ func (rc * pfdnsRefreshableConfig ) IsValid (ctx context.Context ) bool {
79
+ return pfconfigdriver .IsValid (ctx , & rc .registration ) && pfconfigdriver .IsValid (ctx , & rc .isolation ) && pfconfigdriver .IsValid (ctx , & rc .PfConfDns )
84
80
}
85
81
86
- func (p * pfdnsRefreshableConfig ) Refresh (ctx context.Context ) {
87
- if ! pfconfigdriver .IsValid (ctx , & p .registration ) || ! pfconfigdriver .IsValid (ctx , & p .isolation ) {
88
- p .PassthroughsInit (ctx )
89
- p .PassthroughsIsolationInit (ctx )
90
- p .DNSFilter = cache .New (300 * time .Second , 10 * time .Second )
91
- p .IpsetCache = cache .New (1 * time .Hour , 10 * time .Second )
92
- }
82
+ func (rc * pfdnsRefreshableConfig ) Refresh (ctx context.Context ) {
83
+ pfconfigdriver .FetchDecodeSocket (ctx , & rc .registration )
84
+ pfconfigdriver .FetchDecodeSocket (ctx , & rc .isolation )
85
+ pfconfigdriver .FetchDecodeSocket (ctx , & rc .PfConfDns )
86
+ rc .PassthroughsInit (ctx )
87
+ rc .PassthroughsIsolationInit (ctx )
93
88
94
- pfconfigdriver .FetchDecodeSocket (ctx , & p .PfConfDns )
95
- p .recordDNS = p .PfConfDns .RecordDNS == "enabled"
89
+ rc .recordDNS = rc .PfConfDns .RecordDNS == "enabled"
96
90
}
97
91
98
- func (p * pfdnsRefreshableConfig ) Clone () pfconfigdriver.Refresh {
92
+ func (rc * pfdnsRefreshableConfig ) Clone () pfconfigdriver.Refresh {
99
93
return & pfdnsRefreshableConfig {
100
- registration : p .registration ,
101
- isolation : p .isolation ,
102
- PfConfDns : p .PfConfDns ,
103
- DNSFilter : p .DNSFilter ,
104
- IpsetCache : p .IpsetCache ,
94
+ registration : rc .registration ,
95
+ isolation : rc .isolation ,
96
+ PfConfDns : rc .PfConfDns ,
97
+ DNSFilter : rc .DNSFilter ,
98
+ IpsetCache : rc .IpsetCache ,
105
99
}
106
100
}
107
101
0 commit comments