(key, value string)
| 199 | } |
| 200 | |
| 201 | func (device *Device) handleDeviceLine(key, value string) error { |
| 202 | switch key { |
| 203 | case "private_key": |
| 204 | var sk NoisePrivateKey |
| 205 | err := sk.FromMaybeZeroHex(value) |
| 206 | if err != nil { |
| 207 | return ipcErrorf(ipc.IpcErrorInvalid, "failed to set private_key: %w", err) |
| 208 | } |
| 209 | device.Log.Verbosef("UAPI: Updating private key") |
| 210 | device.SetPrivateKey(sk) |
| 211 | |
| 212 | case "listen_port": |
| 213 | port, err := strconv.ParseUint(value, 10, 16) |
| 214 | if err != nil { |
| 215 | return ipcErrorf(ipc.IpcErrorInvalid, "failed to parse listen_port: %w", err) |
| 216 | } |
| 217 | |
| 218 | // update port and rebind |
| 219 | device.Log.Verbosef("UAPI: Updating listen port") |
| 220 | |
| 221 | device.net.Lock() |
| 222 | device.net.port = uint16(port) |
| 223 | device.net.Unlock() |
| 224 | |
| 225 | if err := device.BindUpdate(); err != nil { |
| 226 | return ipcErrorf(ipc.IpcErrorPortInUse, "failed to set listen_port: %w", err) |
| 227 | } |
| 228 | |
| 229 | case "fwmark": |
| 230 | mark, err := strconv.ParseUint(value, 10, 32) |
| 231 | if err != nil { |
| 232 | return ipcErrorf(ipc.IpcErrorInvalid, "invalid fwmark: %w", err) |
| 233 | } |
| 234 | |
| 235 | device.Log.Verbosef("UAPI: Updating fwmark") |
| 236 | if err := device.BindSetMark(uint32(mark)); err != nil { |
| 237 | return ipcErrorf(ipc.IpcErrorPortInUse, "failed to update fwmark: %w", err) |
| 238 | } |
| 239 | |
| 240 | case "replace_peers": |
| 241 | if value != "true" { |
| 242 | return ipcErrorf(ipc.IpcErrorInvalid, "failed to set replace_peers, invalid value: %v", value) |
| 243 | } |
| 244 | device.Log.Verbosef("UAPI: Removing all peers") |
| 245 | device.RemoveAllPeers() |
| 246 | default: |
| 247 | return ipcErrorf(ipc.IpcErrorInvalid, "invalid UAPI device key: %v", key) |
| 248 | } |
| 249 | |
| 250 | return nil |
| 251 | } |
| 252 | |
| 253 | // An ipcSetPeer is the current state of an IPC set operation on a peer. |
| 254 | type ipcSetPeer struct { |
no test coverage detected