-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcontrol.go
154 lines (129 loc) · 4.46 KB
/
control.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
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
package gobirdc
import (
"errors"
"strings"
)
// DisableProtocol sends the equivalent instruction to the BIRD Unix Domain Socket as `birdc disable [...]`
//
// An optional number of arguments can be passed to the configure command that will be forwarded with the bytes sent
// to the BIRD daemon.
//
// Arguments will be sent as-is to the BIRD daemon, so care should be taken to ensure that they are properly escaped.
// Additionally, Arguments should line up with the commandline syntax associated with the official BIRD client (birdc)
func (b *BirdClient) DisableProtocol(args ...string) (resp, replyCode []byte, err error) {
err = b.s.Connect()
if err != nil {
return
}
defer b.s.Close()
resp, replyCode, err = b.s.Send(strings.Join(append([]string{DISABLE_PROTOCOL}, args...), " "))
if err != nil {
return
}
if replyCode[0] != '0' {
err = errors.New("got a non-zero reply-code from the server")
}
return
}
// EnableProtocol sends the equivalent instruction to the BIRD Unix Domain Socket as `birdc enable [...]`
//
// An optional number of arguments can be passed to the configure command that will be forwarded with the bytes sent
// to the BIRD daemon.
//
// Arguments will be sent as-is to the BIRD daemon, so care should be taken to ensure that they are properly escaped.
// Additionally, Arguments should line up with the commandline syntax associated with the official BIRD client (birdc)
func (b *BirdClient) EnableProtocol(args ...string) (resp, replyCode []byte, err error) {
err = b.s.Connect()
if err != nil {
return
}
defer b.s.Close()
resp, replyCode, err = b.s.Send(strings.Join(append([]string{ENABLE_PROTOCOL}, args...), " "))
if err != nil {
return
}
if replyCode[0] != '0' {
err = errors.New("got a non-zero reply-code from the server")
}
return
}
// RestartProtocol sends the equivalent instruction to the BIRD Unix Domain Socket as `birdc restart [...]`
//
// An optional number of arguments can be passed to the configure command that will be forwarded with the bytes sent
// to the BIRD daemon.
//
// Arguments will be sent as-is to the BIRD daemon, so care should be taken to ensure that they are properly escaped.
// Additionally, Arguments should line up with the commandline syntax associated with the official BIRD client (birdc)
func (b *BirdClient) RestartProtocol(args ...string) (resp, replyCode []byte, err error) {
err = b.s.Connect()
if err != nil {
return
}
defer b.s.Close()
resp, replyCode, err = b.s.Send(strings.Join(append([]string{RESTART_PROTOCOL}, args...), " "))
if err != nil {
return
}
if replyCode[0] != '0' {
err = errors.New("got a non-zero reply-code from the server")
}
return
}
// ReloadProtocol sends the equivalent instruction to the BIRD Unix Domain Socket as `birdc reload [...]`
//
// An optional number of arguments can be passed to the configure command that will be forwarded with the bytes sent
// to the BIRD daemon.
//
// Arguments will be sent as-is to the BIRD daemon, so care should be taken to ensure that they are properly escaped.
// Additionally, Arguments should line up with the commandline syntax associated with the official BIRD client (birdc)
func (b *BirdClient) ReloadProtocol(args ...string) (resp, replyCode []byte, err error) {
err = b.s.Connect()
if err != nil {
return
}
defer b.s.Close()
resp, replyCode, err = b.s.Send(strings.Join(append([]string{RELOAD_PROTOCOL}, args...), " "))
if err != nil {
return
}
if replyCode[0] != '0' {
err = errors.New("got a non-zero reply-code from the server")
}
return
}
// Shutdown sends the equivalent instruction to the BIRD Unix Domain Socket as `birdc down`
//
// Shutdown will send a shutdown signal to the BIRD daemon.
func (b *BirdClient) Shutdown() (resp, replyCode []byte, err error) {
err = b.s.Connect()
if err != nil {
return
}
defer b.s.Close()
resp, replyCode, err = b.s.Send(DOWN)
if err != nil {
return
}
if replyCode[0] != '0' {
err = errors.New("got a non-zero reply-code from the server")
}
return
}
// GracefulRestart sends the equivalent instruction to the BIRD Unix Domain Socket as `birdc graceful restart`
//
// GracefulRestart will send a signal the BIRD daemon to go down gracefully
func (b *BirdClient) GracefulRestart() (resp, replyCode []byte, err error) {
err = b.s.Connect()
if err != nil {
return
}
defer b.s.Close()
resp, replyCode, err = b.s.Send(GRACEFUL_RESTART)
if err != nil {
return
}
if replyCode[0] != '0' {
err = errors.New("got a non-zero reply-code from the server")
}
return
}