Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

Commit 3858c8a

Browse files
committed
feat: Add Delete RPC to dhclientd (#10)
1 parent 5652b6d commit 3858c8a

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

pkg/svc/dhclient.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,42 @@ func (m *DHClientManager) Get(_ context.Context, args *godhcpd.DHClientManagedId
104104
return nil, status.Errorf(codes.NotFound, msg)
105105
}
106106

107+
// Delete deletes a dhcp client.
108+
func (m *DHClientManager) Delete(_ context.Context, args *godhcpd.DHClientManagedId) (*godhcpd.DHClientManagedId, error) {
109+
id := args.GetId()
110+
111+
DHClient := m.DHClientsManaged[id]
112+
if DHClient == nil {
113+
msg := "dhcp client not found"
114+
115+
log.Error(msg)
116+
117+
return nil, status.Errorf(codes.NotFound, msg)
118+
}
119+
120+
log.Info("Stopping dhcp client")
121+
122+
if err := DHClient.DisableAutoRestart(); err != nil { // Manually disable auto restart; disables crash recovery even if process is not running
123+
log.Error(err.Error())
124+
125+
return nil, status.Errorf(codes.Unknown, err.Error())
126+
}
127+
128+
if DHClient.IsRunning() {
129+
if err := DHClient.Stop(); err != nil { // Stop is sync, so no need to `.Wait()`
130+
log.Error(err.Error())
131+
132+
return nil, status.Errorf(codes.Unknown, err.Error())
133+
}
134+
}
135+
136+
delete(m.DHClientsManaged, id)
137+
138+
return &godhcpd.DHClientManagedId{
139+
Id: id,
140+
}, nil
141+
}
142+
107143
// Extract extracts the ISC DHCP client binary.
108144
func (m *DHClientManager) Extract() error {
109145
statikFS, err := fs.New()

0 commit comments

Comments
 (0)