Start starts the interception.
()
| 58 | |
| 59 | // Start starts the interception. |
| 60 | func start() error { |
| 61 | if disableInterception { |
| 62 | log.Warning("interception: packet interception is disabled via flag - this breaks a lot of functionality") |
| 63 | return nil |
| 64 | } |
| 65 | |
| 66 | if !isStarted.CompareAndSwap(false, true) { |
| 67 | return nil // already running |
| 68 | } |
| 69 | |
| 70 | inputPackets := Packets |
| 71 | if packetMetricsDestination != "" { |
| 72 | go metrics.writeMetrics() |
| 73 | inputPackets = make(chan packet.Packet) |
| 74 | go func() { |
| 75 | for p := range inputPackets { |
| 76 | Packets <- tracePacket(p) |
| 77 | } |
| 78 | }() |
| 79 | } |
| 80 | |
| 81 | err := startInterception(inputPackets) |
| 82 | if err != nil { |
| 83 | log.Errorf("interception: failed to start module: %q", err) |
| 84 | log.Debug("interception: cleaning up after failed start...") |
| 85 | metrics.stop() |
| 86 | if e := stopInterception(); e != nil { |
| 87 | log.Debugf("interception: error cleaning up after failed start: %q", e.Error()) |
| 88 | } |
| 89 | isStarted.Store(false) |
| 90 | } |
| 91 | return err |
| 92 | } |
| 93 | |
| 94 | // Stop starts the interception. |
| 95 | func stop() error { |
no test coverage detected