-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice.go
66 lines (52 loc) · 1.65 KB
/
service.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
package yafw
import (
"github.com/google/nftables/expr"
)
type ServiceGroup struct {
Name string `json:"name"`
Services []*Service `json:"services"`
}
type Service struct {
Name string `json:"name"`
Protocol uint8 `json:"protocol"`
SourcePortMin uint16 `json:"source_port_min"`
SourcePortMax uint16 `json:"source_port_max"`
DestinationPortMin uint16 `json:"destination_port_min"`
DestinationPortMax uint16 `json:"destination_port_max"`
}
func (s *Service) Exprs() []expr.Any {
builder := &ExprBuilder{}
builder.MetaL4Protocol(1).CompareL4Protocol(1, s.Protocol)
if s.SourcePortMin != 0 && s.SourcePortMax != 0 {
builder.LoadSourcePort(1).ComparePortRange(1, s.SourcePortMin, s.SourcePortMax)
}
if s.DestinationPortMin != 0 && s.DestinationPortMax != 0 {
builder.LoadDestinationPort(1).ComparePortRange(1, s.DestinationPortMin, s.DestinationPortMax)
}
return builder.Exprs()
}
// func (r *Router) ServiceGroups() []*ServiceGroup {
// ret := make([]*ServiceGroup, 0)
// for _, sg := range r.serviceGroups {
// ret = append(ret, sg)
// }
// return ret
// }
// func (r *Router) AddService(sg *ServiceGroup) error {
// if _, ok := r.serviceGroups[sg.Name]; ok {
// return fmt.Errorf("service group name duplicated")
// }
// r.serviceGroups[sg.Name] = sg
// return nil
// }
// func (r *Router) UpdateService(sg *ServiceGroup) {
// r.serviceGroups[sg.Name] = sg
// }
// func (r *Router) DeleteService(sg *ServiceGroup) error {
// if _, ok := r.serviceGroups[sg.Name]; ok {
// delete(r.serviceGroups, sg.Name)
// } else {
// return fmt.Errorf("service group name not found")
// }
// return nil
// }