-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmethod.go
More file actions
807 lines (739 loc) · 21.7 KB
/
method.go
File metadata and controls
807 lines (739 loc) · 21.7 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
/*
Copyright © 2024 weidongkl <weidongkx@gmail.com>
*/
package firewalld
import (
"fmt"
"github.com/godbus/dbus"
)
// Helper function to handle common DBus call patterns
func (c *Client) handleCall(call *dbus.Call, err error) error {
if err != nil {
return fmt.Errorf("dbus call failed: %w", err)
}
return call.Err
}
// Helper function to handle DBus calls that return a single value
func (c *Client) handleDBusCall(call *dbus.Call, err error, result interface{}) error {
if err != nil {
return fmt.Errorf("dbus call failed: %w", err)
}
if err := call.Store(result); err != nil {
return fmt.Errorf("failed to store result: %w", err)
}
return nil
}
// Reload firewall rules and keep state information.
// Current permanent configuration will become new runtime configuration,
// i.e. all runtime only changes done until reload are lost with reload if
// they have not been also in permanent configuration.
func (c *Client) Reload() error {
call, err := c.CallMethod("reload")
return c.handleCall(call, err)
}
// RuntimeToPermanent Make runtime settings permanent.
// Replaces permanent settings with runtime settings for zones, services, icmptypes,
// direct (deprecated) and policies (lockdown whitelist).
func (c *Client) RuntimeToPermanent() error {
call, err := c.CallMethod("runtimeToPermanent")
return c.handleCall(call, err)
}
// CheckPermanentConfig Run checks on the permanent configuration.
// This is most useful if changes were made manually to configuration files.
func (c *Client) CheckPermanentConfig() error {
call, err := c.CallMethod("checkPermanentConfig")
return c.handleCall(call, err)
}
// ListServices Return array of service names
func (c *Client) ListServices() ([]string, error) {
if c.opt.Permanent {
return c.GetServiceNames()
}
var services []string
call, err := c.CallMethod("listServices")
if err := c.handleDBusCall(call, err, &services); err != nil {
return nil, err
}
return services, nil
}
// ListServicesPath Return array of objects paths (o) of services in permanent configuration.
func (c *Client) ListServicesPath() (servicesPath []string, err error) {
if !c.opt.Permanent {
return nil, ErrNotSupportRuntime
} else {
call, err := c.CallMethod("listServices")
if err != nil {
return servicesPath, err
}
err = call.Store(&servicesPath)
return servicesPath, err
}
}
// AddZone Add zone with given settings into permanent configuration.
func (c *Client) AddZone(zoneSet ZoneSetting) error {
if !c.opt.Permanent {
return ErrNotSupportRuntime
}
zsSlice := []interface{}{
zoneSet.Version,
zoneSet.Name,
zoneSet.Description,
zoneSet.Unused,
zoneSet.Target,
zoneSet.Services,
zoneSet.Ports,
zoneSet.IcmpBlocks,
zoneSet.Masquerade,
zoneSet.ForwardPorts,
zoneSet.Interfaces,
zoneSet.SourceAddresses,
zoneSet.RichRules,
zoneSet.Protocols,
zoneSet.SourcePorts,
zoneSet.IcmpBlockInversion,
}
call, err := c.CallMethod("addZone", zoneSet.Name, zsSlice)
return c.handleCall(call, err)
}
// GetServiceByName Return object path (permanent configuration) of service
// with given name.
func (c *Client) GetServiceByName(service string) (string, error) {
if !c.opt.Permanent {
return "", ErrNotSupportRuntime
}
var path string
call, err := c.CallMethod("getServiceByName", service)
if err := c.handleDBusCall(call, err, &path); err != nil {
return "", err
}
return path, nil
}
// GetServiceNames Return list of service names (permanent configuration).
func (c *Client) GetServiceNames() ([]string, error) {
if !c.opt.Permanent {
return nil, ErrNotSupportRuntime
}
var names []string
call, err := c.CallMethod("getServiceNames")
if err := c.handleDBusCall(call, err, &names); err != nil {
return nil, err
}
return names, nil
}
// GetZoneByName Return object path (permanent configuration) of zone with given name.
func (c *Client) GetZoneByName(zone string) (string, error) {
if !c.opt.Permanent {
return "", ErrNotSupportRuntime
}
var path string
call, err := c.CallMethod("getZoneByName", zone)
if err := c.handleDBusCall(call, err, &path); err != nil {
return "", err
}
return path, nil
}
// GetZoneNames Return list of zone names (permanent configuration).
func (c *Client) GetZoneNames() (names []string, err error) {
if !c.opt.Permanent {
return names, ErrNotSupportRuntime
}
call, err := c.CallMethod("getZoneNames")
if err != nil {
return names, err
}
err = call.Store(&names)
return names, err
}
// GetZoneOfSource Return name of zone the source is bound to or empty string.
func (c *Client) GetZoneOfSource(source string) (string, error) {
if !c.opt.Permanent {
return "", ErrNotSupportRuntime
}
var zoneName string
call, err := c.CallMethod("getZoneOfSource", source)
if err := c.handleDBusCall(call, err, &zoneName); err != nil {
return "", err
}
return zoneName, nil
}
// GetServiceSettings Return permanent settings of a service.
func (c *Client) GetServiceSettings(svc string) (ServiceSetting, error) {
var svcSet ServiceSetting
var call *dbus.Call
var err error
if c.opt.Permanent {
call, err = c.CallPermanentServiceMethod2(svc, "getSettings")
} else {
call, err = c.CallMethod("getServiceSettings", svc)
}
if err := c.handleDBusCall(call, err, &svcSet); err != nil {
return ServiceSetting{}, err
}
return svcSet, nil
}
// AddForwardPort Add the IPv4 forward port into zone. If zone is empty, use default zone. The port can either be a
// single port number portid or a port range portid-portid. The protocol can either be tcp or udp. The destination
// address is a simple IP address. If timeout(The timeout configuration does not take effect for permanent
// configuration) is non-zero, the operation will be active only for the amount of seconds.
func (c *Client) AddForwardPort(zone, port, protocol, toPort, toAddress string, timeout int) error {
var (
call *dbus.Call
err error
)
if c.opt.Permanent {
call, err = c.CallPermanentZoneMethod2(zone, "addForwardPort", port, protocol, toPort, toAddress)
} else {
call, err = c.CallRuntimeZoneMethod("addForwardPort", zone, port, protocol, toPort, toAddress, timeout)
}
return c.handleCall(call, err)
}
// AddInterface Bind interface with zone.
func (c *Client) AddInterface(zone, interFace string) error {
var (
call *dbus.Call
err error
)
if c.opt.Permanent {
call, err = c.CallPermanentZoneMethod2(zone, "addInterface", interFace)
} else {
call, err = c.CallRuntimeZoneMethod("addInterface", zone, interFace)
}
return c.handleCall(call, err)
}
// AddPort when the timeout((The timeout configuration does not take effect for permanent
// configuration) is set to 0, the timeout is ignored.
func (c *Client) AddPort(zone, port, protocol string, timeout int) error {
var (
call *dbus.Call
err error
)
if c.opt.Permanent {
call, err = c.CallPermanentZoneMethod2(zone, "addPort", port, protocol)
} else {
call, err = c.CallRuntimeZoneMethod("addPort", zone, port, protocol, timeout)
}
return c.handleCall(call, err)
}
// AddProtocol add protocol into zone. The protocol can be any protocol supported by the system. Please have a look at /etc/protocols for supported protocols.
func (c *Client) AddProtocol(zone, protocol string, timeout int) error {
var (
call *dbus.Call
err error
)
if c.opt.Permanent {
call, err = c.CallPermanentZoneMethod2(zone, "addProtocol", protocol)
} else {
call, err = c.CallRuntimeZoneMethod("addProtocol", zone, protocol, timeout)
}
if err != nil {
return err
}
err = call.Err
return err
}
// AddRichRule add rule to list of rich-language rules in zone.
func (c *Client) AddRichRule(zone, rule string, timeout int) error {
var (
call *dbus.Call
err error
)
if c.opt.Permanent {
call, err = c.CallPermanentZoneMethod2(zone, "addRichRule", rule)
} else {
call, err = c.CallRuntimeZoneMethod("addRichRule", zone, rule, timeout)
}
if err != nil {
return err
}
err = call.Err
return err
}
// AddService Add service into zone. If timeout is non-zero,
// the operation will be active only for the amount of seconds.
func (c *Client) AddService(zone, service string, timeout int) error {
var (
call *dbus.Call
err error
)
if c.opt.Permanent {
call, err = c.CallPermanentZoneMethod2(zone, "addService", service)
} else {
call, err = c.CallRuntimeZoneMethod("addService", zone, service, timeout)
}
if err != nil {
return err
}
err = call.Err
return err
}
// AddSource add source to list of source addresses bound to zone.
func (c *Client) AddSource(zone, source string, timeout int) error {
var (
call *dbus.Call
err error
)
if c.opt.Permanent {
call, err = c.CallPermanentZoneMethod2(zone, "addSource", source)
} else {
call, err = c.CallRuntimeZoneMethod("addSource", zone, source, timeout)
}
if err != nil {
return err
}
err = call.Err
return err
}
// AddSourcePort add (port, protocol) to list of source ports of zone.
func (c *Client) AddSourcePort(zone, port, protocol string, timeout int) error {
var (
call *dbus.Call
err error
)
if c.opt.Permanent {
call, err = c.CallPermanentZoneMethod2(zone, "addSourcePort", port, protocol)
} else {
call, err = c.CallRuntimeZoneMethod("addSourcePort", zone, port, protocol, timeout)
}
if err != nil {
return err
}
err = call.Err
return err
}
// GetActiveZones Return dictionary of currently active zones altogether with interfaces and sources used in these
// zones. Active zones are zones, that have a binding to an interface or source.
func (c *Client) GetActiveZones() (map[string]ActivateZone, error) {
var (
azMap = make(map[string]map[string][]string)
azs = make(map[string]ActivateZone)
)
call, err := c.CallRuntimeZoneMethod("getActiveZones")
if err := c.handleDBusCall(call, err, &azMap); err != nil {
return nil, err
}
for zoneName, zone := range azMap {
azs[zoneName] = ActivateZone{
Interfaces: zone["interfaces"],
Sources: zone["sources"],
}
}
return azs, nil
}
// GetForwardPorts Get list of (port, protocol, toport, toaddr) defined in zone.
func (c *Client) GetForwardPorts(zone string) (ForwardPorts, error) {
var fps ForwardPorts
var call *dbus.Call
var err error
if c.opt.Permanent {
call, err = c.CallPermanentZoneMethod2(zone, "getForwardPorts")
} else {
call, err = c.CallRuntimeZoneMethod("getForwardPorts", zone)
}
if err := c.handleDBusCall(call, err, &fps); err != nil {
return nil, err
}
return fps, nil
}
// GetInterfaces Return array of interfaces (s) previously bound with zone.
func (c *Client) GetInterfaces(zone string) ([]string, error) {
var interfaces []string
var call *dbus.Call
var err error
if c.opt.Permanent {
call, err = c.CallPermanentZoneMethod2(zone, "getInterfaces")
} else {
call, err = c.CallRuntimeZoneMethod("getInterfaces", zone)
}
if err := c.handleDBusCall(call, err, &interfaces); err != nil {
return nil, err
}
return interfaces, nil
}
// GetPorts Return array of ports (2-tuple of port and protocol) previously enabled in zone
func (c *Client) GetPorts(zone string) (Ports, error) {
var (
rawPorts [][]string
ports Ports
call *dbus.Call
err error
)
if c.opt.Permanent {
call, err = c.CallPermanentZoneMethod2(zone, "getPorts")
} else {
call, err = c.CallRuntimeZoneMethod("getPorts", zone)
}
if err := c.handleDBusCall(call, err, &rawPorts); err != nil {
return nil, err
}
ports, err = convertToPorts(rawPorts)
return ports, err
}
// GetProtocols Return array of protocols (s) previously enabled in zone.
func (c *Client) GetProtocols(zone string) ([]string, error) {
var protocols []string
var call *dbus.Call
var err error
if c.opt.Permanent {
call, err = c.CallPermanentZoneMethod2(zone, "getProtocols")
} else {
call, err = c.CallRuntimeZoneMethod("getProtocols", zone)
}
if err := c.handleDBusCall(call, err, &protocols); err != nil {
return nil, err
}
return protocols, nil
}
// GetRichRules Get list of rich-language rules in zone.
func (c *Client) GetRichRules(zone string) ([]string, error) {
var rules []string
var call *dbus.Call
var err error
if c.opt.Permanent {
call, err = c.CallPermanentZoneMethod2(zone, "getRichRules")
} else {
call, err = c.CallRuntimeZoneMethod("getRichRules", zone)
}
if err := c.handleDBusCall(call, err, &rules); err != nil {
return nil, err
}
return rules, nil
}
// GetServices Get list of service names used in zone.
func (c *Client) GetServices(zone string) ([]string, error) {
var services []string
var call *dbus.Call
var err error
if c.opt.Permanent {
call, err = c.CallPermanentZoneMethod2(zone, "getServices")
} else {
call, err = c.CallRuntimeZoneMethod("getServices", zone)
}
if err := c.handleDBusCall(call, err, &services); err != nil {
return nil, err
}
return services, nil
}
// GetSourcePorts Get list of (port, protocol) defined in zone.
func (c *Client) GetSourcePorts(zone string) (Ports, error) {
var (
rawPorts [][]string
ports Ports
call *dbus.Call
err error
)
if c.opt.Permanent {
call, err = c.CallPermanentZoneMethod2(zone, "getSourcePorts")
} else {
call, err = c.CallRuntimeZoneMethod("getSourcePorts", zone)
}
if err := c.handleDBusCall(call, err, &rawPorts); err != nil {
return nil, err
}
ports, err = convertToPorts(rawPorts)
return ports, err
}
// GetSources Get list of source addresses bound to zone.
func (c *Client) GetSources(zone string) ([]string, error) {
var sources []string
var call *dbus.Call
var err error
if c.opt.Permanent {
call, err = c.CallPermanentZoneMethod2(zone, "getSources")
} else {
call, err = c.CallRuntimeZoneMethod("getSources", zone)
}
if err := c.handleDBusCall(call, err, &sources); err != nil {
return nil, err
}
return sources, nil
}
// RemoveForwardPort remove (port, protocol, toport, toaddr) from list of forward ports of zone.
func (c *Client) RemoveForwardPort(zone, port, protocol, toPort, toAddress string) error {
var (
err error
call *dbus.Call
)
if c.opt.Permanent {
call, err = c.CallPermanentZoneMethod2(zone, "removeForwardPort", port, protocol, toPort, toAddress)
} else {
call, err = c.CallRuntimeZoneMethod("removeForwardPort", zone, port, protocol, toPort, toAddress)
}
return c.handleCall(call, err)
}
// RemovePort If zone is empty, use default zone.
func (c *Client) RemovePort(zone, port, protocol string) error {
var (
err error
call *dbus.Call
)
if c.opt.Permanent {
call, err = c.CallPermanentZoneMethod2(zone, "removePort", port, protocol)
} else {
call, err = c.CallRuntimeZoneMethod("removePort", zone, port, protocol)
}
return c.handleCall(call, err)
}
// RemoveProtocol Remove protocol from zone.
func (c *Client) RemoveProtocol(zone, protocol string) error {
var (
err error
call *dbus.Call
)
if c.opt.Permanent {
call, err = c.CallPermanentZoneMethod2(zone, "removeProtocol", protocol)
} else {
call, err = c.CallRuntimeZoneMethod("removeProtocol", zone, protocol)
}
return c.handleCall(call, err)
}
// RemoveRichRule remove rule from list of rich-language rules in zone.
func (c *Client) RemoveRichRule(zone, rule string) error {
var (
err error
call *dbus.Call
)
if c.opt.Permanent {
call, err = c.CallPermanentZoneMethod2(zone, "removeRichRule", rule)
} else {
call, err = c.CallRuntimeZoneMethod("removeRichRule", zone, rule)
}
return c.handleCall(call, err)
}
// RemoveService remove service from list of services used in zone.
func (c *Client) RemoveService(zone, service string) error {
var (
err error
call *dbus.Call
)
if c.opt.Permanent {
call, err = c.CallPermanentZoneMethod2(zone, "removeService", service)
} else {
call, err = c.CallRuntimeZoneMethod("removeService", zone, service)
}
return c.handleCall(call, err)
}
// RemoveSource remove source from list of source addresses bound to zone.
func (c *Client) RemoveSource(zone, source string) error {
var (
err error
call *dbus.Call
)
if c.opt.Permanent {
call, err = c.CallPermanentZoneMethod2(zone, "removeSource", source)
} else {
call, err = c.CallRuntimeZoneMethod("removeSource", zone, source)
}
return c.handleCall(call, err)
}
// RemoveSourcePort remove (port, protocol) from list of source ports of zone.
func (c *Client) RemoveSourcePort(zone, port, protocol string) error {
var (
err error
call *dbus.Call
)
if c.opt.Permanent {
call, err = c.CallPermanentZoneMethod2(zone, "removeSourcePort", port, protocol)
} else {
call, err = c.CallRuntimeZoneMethod("removeSourcePort", zone, port, protocol)
}
return c.handleCall(call, err)
}
// GetDefaultZone Return default zone.
func (c *Client) GetDefaultZone() (string, error) {
if c.opt.Permanent {
return "", ErrNotSupportPermanent
}
var defaultZone string
call, err := c.CallMethod("getDefaultZone")
if err := c.handleDBusCall(call, err, &defaultZone); err != nil {
return "", err
}
return defaultZone, nil
}
// GetZones Return array of names (s) of predefined zones known to
// current runtime environment.
func (c *Client) GetZones() ([]string, error) {
if c.opt.Permanent {
return nil, ErrNotSupportPermanent
}
var zones []string
call, err := c.CallMethod("getZones")
if err := c.handleDBusCall(call, err, &zones); err != nil {
return nil, err
}
return zones, nil
}
// ListZones List object paths of zones known to permanent environment.
func (c *Client) ListZones() ([]string, error) {
if !c.opt.Permanent {
return nil, ErrNotSupportRuntime
}
var zonesPath []string
call, err := c.CallMethod("listZones")
if err := c.handleDBusCall(call, err, &zonesPath); err != nil {
return nil, err
}
return zonesPath, nil
}
// GetZoneSettings Return zone settings.
func (c *Client) GetZoneSettings(zone string) (ZoneSetting, error) {
if c.opt.Permanent {
return ZoneSetting{}, ErrNotSupportPermanent
}
var (
zs ZoneSetting
call *dbus.Call
err error
)
call, err = c.CallMethod("getZoneSettings", zone)
if err := c.handleDBusCall(call, err, &zs); err != nil {
return ZoneSetting{}, err
}
return zs, nil
}
func (c *Client) GetZoneSettings2(zone string) (ZoneSetting, error) {
var (
zs ZoneSetting
call *dbus.Call
err error
sm map[string]interface{}
)
if c.opt.Permanent {
call, err = c.CallPermanentZoneMethod2(zone, "getSettings2")
} else {
call, err = c.CallRuntimeZoneMethod("getZoneSettings2", zone)
}
if err := c.handleDBusCall(call, err, &sm); err != nil {
return ZoneSetting{}, err
}
zs, err = convertToZoneSetting(sm)
if zs.Name == "" {
zs.Name = zone
}
return zs, err
}
func (c *Client) GetSettings2(zone string) (ZoneSetting, error) {
if !c.opt.Permanent {
return ZoneSetting{}, ErrNotSupportRuntime
}
return c.GetZoneSettings2(zone)
}
// SetDefaultZone Set default zone for connections and interfaces where no zone has been selected to zone.
// Setting the default zone changes the zone for the connections or interfaces,
// that are using the default zone. This is a runtime and permanent change.
func (c *Client) SetDefaultZone(zone string) error {
call, err := c.CallMethod("setDefaultZone", zone)
return c.handleCall(call, err)
}
// SetForwardPorts Permanently set forward ports of zone
func (c *Client) SetForwardPorts(zone string, fps ForwardPorts) error {
if !c.opt.Permanent {
return ErrNotSupportRuntime
}
var (
call *dbus.Call
err error
)
var dpSlice [][]string
for _, fp := range fps {
dpSlice = append(dpSlice, []string{fp.Port, fp.Protocol, fp.ToAddress, fp.ToPort})
}
call, err = c.CallPermanentZoneMethod2(zone, "setForwardPorts", dpSlice)
return c.handleCall(call, err)
}
// SetPorts Permanently set ports of zone
func (c *Client) SetPorts(zone string, ports Ports) error {
if !c.opt.Permanent {
return ErrNotSupportRuntime
}
var (
call *dbus.Call
err error
)
var psSlice [][]string
for _, port := range ports {
psSlice = append(psSlice, []string{port.Port, port.Protocol})
}
call, err = c.CallPermanentZoneMethod2(zone, "setPorts", psSlice)
return c.handleCall(call, err)
}
// SetProtocols Permanently set list of protocols used in zone to protocols.
func (c *Client) SetProtocols(zone string, protocols []string) error {
if !c.opt.Permanent {
return ErrNotSupportRuntime
}
var (
call *dbus.Call
err error
)
call, err = c.CallPermanentZoneMethod2(zone, "setProtocols", protocols)
return c.handleCall(call, err)
}
// SetRichRules Permanently set list of rich-language rules to rules.
func (c *Client) SetRichRules(zone string, rules []string) error {
if !c.opt.Permanent {
return ErrNotSupportRuntime
}
var (
call *dbus.Call
err error
)
call, err = c.CallPermanentZoneMethod2(zone, "setRichRules", rules)
return c.handleCall(call, err)
}
// SetServices Set services in zone.
func (c *Client) SetServices(zone string, services []string) error {
if !c.opt.Permanent {
return ErrNotSupportRuntime
}
var (
call *dbus.Call
err error
)
call, err = c.CallPermanentZoneMethod2(zone, "setServices", services)
return c.handleCall(call, err)
}
// SetSourcePorts Set source ports in zone.
func (c *Client) SetSourcePorts(zone string, ports Ports) error {
if !c.opt.Permanent {
return ErrNotSupportRuntime
}
var (
call *dbus.Call
err error
)
var psSlice [][]string
for _, port := range ports {
psSlice = append(psSlice, []string{port.Port, port.Protocol})
}
call, err = c.CallPermanentZoneMethod2(zone, "setSourcePorts", psSlice)
return c.handleCall(call, err)
}
// SetSources Permanently set list of source addresses bound to zone to sources.
func (c *Client) SetSources(zone string, sources []string) error {
if !c.opt.Permanent {
return ErrNotSupportRuntime
}
var (
call *dbus.Call
err error
)
call, err = c.CallPermanentZoneMethod2(zone, "setSources", sources)
return c.handleCall(call, err)
}
// getZoneID Get zone ID by name.
func (c *Client) getZoneID(zone string) (int, error) {
path, err := c.GetZoneByName(zone)
if err != nil {
return 0, err
}
return getIdByPath(path)
}
// getServiceID Get service ID by name.
func (c *Client) getServiceID(svc string) (int, error) {
path, err := c.GetServiceByName(svc)
if err != nil {
return 0, err
}
return getIdByPath(path)
}