forked from tailscale/wf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenum.go
83 lines (68 loc) · 1.83 KB
/
enum.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package wf
import (
"golang.org/x/sys/windows"
)
type RuleEnumerator struct {
session *Session
enumTemplate fwpmFilterEnumTemplate0
}
func (e RuleEnumerator) WithProvider(provider ProviderID) RuleEnumerator {
e.enumTemplate.ProviderKey = &provider
return e
}
func (e RuleEnumerator) WithLayer(layer LayerID) RuleEnumerator {
e.enumTemplate.LayerKey = layer
return e
}
func (e RuleEnumerator) WithType(typ FilterEnumType) RuleEnumerator {
e.enumTemplate.EnumType = typ
return e
}
func (e RuleEnumerator) WithFlags(flags FilterEnumFlags) RuleEnumerator {
e.enumTemplate.Flags = flags
return e
}
func (e RuleEnumerator) WithProviderContext(provider ProviderID, contextType uint32) RuleEnumerator {
contextEnumTemplate := fwpmProviderContextEnumTemplate0{
ProviderKey: new(ProviderID),
ProviderContextType: contextType,
}
*contextEnumTemplate.ProviderKey = provider
e.enumTemplate.ProviderContextTemplate = &contextEnumTemplate
return e
}
func (e RuleEnumerator) WithActionMask(mask ActionFlag) RuleEnumerator {
e.enumTemplate.ActionMask = mask
return e
}
func (e RuleEnumerator) WithCalloutKey(key CalloutID) RuleEnumerator {
e.enumTemplate.CalloutKey = &key
return e
}
func (e RuleEnumerator) Execute() ([]*Rule, error) {
var enum windows.Handle
if err := fwpmFilterCreateEnumHandle0(e.session.handle, &e.enumTemplate, &enum); err != nil {
return nil, err
}
defer fwpmFilterDestroyEnumHandle0(e.session.handle, enum)
var ret []*Rule
for {
rules, err := e.session.getRulePage(enum)
if err != nil {
return nil, err
}
if len(rules) == 0 {
return ret, nil
}
ret = append(ret, rules...)
}
}
func (s *Session) EnumerateRules(typ FilterEnumType, layer LayerID) RuleEnumerator {
return RuleEnumerator{
session: s,
enumTemplate: fwpmFilterEnumTemplate0{
EnumType: typ,
LayerKey: layer,
},
}
}