agent/eni/watcher/watcher_linux.go
func (udevWatcher *UdevWatcher) eventHandler() {
	// The shutdown channel will be used to terminate the watch for udev events
	shutdown := udevWatcher.udevMonitor.Monitor(udevWatcher.events)
	for {
		select {
		case event := <-udevWatcher.events:
			subsystem, ok := event.Env[udevSubsystem]
			if !ok || subsystem != udevNetSubsystem {
				continue
			}
			if event.Env[udevEventAction] != udevAddEvent {
				continue
			}
			if !networkutils.IsValidNetworkDevice(event.Env[udevDevPath]) {
				log.Debugf("Udev watcher event handler: ignoring event for invalid network device: %s", event.String())
				continue
			}
			netInterface := event.Env[udevInterface]
			// GetMACAddres and sendENIStateChangeWithRetries can block the execution
			// of this method for a few seconds in the worst-case scenario.
			// Execute these within a go-routine
			go func(ctx context.Context, dev string, timeout time.Duration) {
				log.Debugf("Udev watcher event-handler: add interface: %s", dev)
				macAddress, err := networkutils.GetMACAddress(udevWatcher.ctx, macAddressRetryTimeout,
					dev, udevWatcher.netlinkClient)
				if err != nil {
					log.Warnf("Udev watcher event-handler: error obtaining MACAddress for interface %s", dev)
					return
				}

				if err := udevWatcher.sendENIStateChangeWithRetries(ctx, macAddress, timeout); err != nil {
					log.Warnf("Udev watcher event-handler: unable to send state change: %v", err)
				}
			}(udevWatcher.ctx, netInterface, sendENIStateChangeRetryTimeout)
		case <-udevWatcher.ctx.Done():
			log.Info("Stopping udev event handler")
			// Send the shutdown signal and close the connection
			shutdown <- true
			if err := udevWatcher.udevMonitor.Close(); err != nil {
				log.Warnf("Unable to close the udev monitoring socket: %v", err)
			}
			return
		}
	}
}
func (udevWatcher *UdevWatcher) eventHandler() {
	// The shutdown channel will be used to terminate the watch for udev events
	shutdown := udevWatcher.udevMonitor.Monitor(udevWatcher.events)
	for {
		select {
		case event := <-udevWatcher.events:
			subsystem, ok := event.Env[udevSubsystem]
			if !ok || subsystem != udevNetSubsystem {
				continue
			}
			if event.Env[udevEventAction] != udevAddEvent {
				continue
			}
			if !networkutils.IsValidNetworkDevice(event.Env[udevDevPath]) {
				log.Debugf("Udev watcher event handler: ignoring event for invalid network device: %s", event.String())
				continue
			}
			netInterface := event.Env[udevInterface]
			// GetMACAddres and sendENIStateChangeWithRetries can block the execution
			// of this method for a few seconds in the worst-case scenario.
			// Execute these within a go-routine
			go func(ctx context.Context, dev string, timeout time.Duration) {
				log.Debugf("Udev watcher event-handler: add interface: %s", dev)
				macAddress, err := networkutils.GetMACAddress(udevWatcher.ctx, macAddressRetryTimeout,
					dev, udevWatcher.netlinkClient)
				if err != nil {
					log.Warnf("Udev watcher event-handler: error obtaining MACAddress for interface %s", dev)
					return
				}

				if err := udevWatcher.sendENIStateChangeWithRetries(ctx, macAddress, timeout); err != nil {
					log.Warnf("Udev watcher event-handler: unable to send state change: %v", err)
				}
			}(udevWatcher.ctx, netInterface, sendENIStateChangeRetryTimeout)
		case <-udevWatcher.ctx.Done():
			log.Info("Stopping udev event handler")
			// Send the shutdown signal and close the connection
			shutdown <- true
			if err := udevWatcher.udevMonitor.Close(); err != nil {
				log.Warnf("Unable to close the udev monitoring socket: %v", err)
			}
			return
		}
	}
}
// eventHandler is used to manage udev net subsystem events to add/remove interfaces