MCPcopy Create free account
hub / github.com/encodeous/nylon / IpcSetOperation

Method IpcSetOperation

polyamide/device/uapi.go:144–199  ·  view source on GitHub ↗

IpcSetOperation implements the WireGuard configuration protocol "set" operation. See https://www.wireguard.com/xplatform/#configuration-protocol for details.

(r io.Reader)

Source from the content-addressed store, hash-verified

142// IpcSetOperation implements the WireGuard configuration protocol "set" operation.
143// See https://www.wireguard.com/xplatform/#configuration-protocol for details.
144func (device *Device) IpcSetOperation(r io.Reader) (err error) {
145 device.ipcMutex.Lock()
146 defer device.ipcMutex.Unlock()
147
148 defer func() {
149 if err != nil {
150 device.Log.Errorf("%v", err)
151 }
152 }()
153
154 peer := new(ipcSetPeer)
155 deviceConfig := true
156
157 scanner := bufio.NewScanner(r)
158 for scanner.Scan() {
159 line := scanner.Text()
160 if line == "" {
161 // Blank line means terminate operation.
162 peer.handlePostConfig()
163 return nil
164 }
165 key, value, ok := strings.Cut(line, "=")
166 if !ok {
167 return ipcErrorf(ipc.IpcErrorProtocol, "failed to parse line %q", line)
168 }
169
170 if key == "public_key" {
171 if deviceConfig {
172 deviceConfig = false
173 }
174 peer.handlePostConfig()
175 // Load/create the peer we are now configuring.
176 err := device.handlePublicKeyLine(peer, value)
177 if err != nil {
178 return err
179 }
180 continue
181 }
182
183 var err error
184 if deviceConfig {
185 err = device.handleDeviceLine(key, value)
186 } else {
187 err = device.handlePeerLine(peer, key, value)
188 }
189 if err != nil {
190 return err
191 }
192 }
193 peer.handlePostConfig()
194
195 if err := scanner.Err(); err != nil {
196 return ipcErrorf(ipc.IpcErrorIO, "failed to read input: %w", err)
197 }
198 return nil
199}
200
201func (device *Device) handleDeviceLine(key, value string) error {

Callers 2

IpcSetMethod · 0.95
IpcHandleMethod · 0.95

Implementers 4

NativeTunpolyamide/tun/tun_linux.go
netTunpolyamide/tun/netstack/tun.go
chTunpolyamide/tun/tuntest/tuntest.go
fakeTUNDeviceSizedpolyamide/device/device_test.go

Calls 5

handlePublicKeyLineMethod · 0.95
handleDeviceLineMethod · 0.95
handlePeerLineMethod · 0.95
ipcErrorfFunction · 0.85
handlePostConfigMethod · 0.80

Tested by

no test coverage detected