+ bool enable_packet = false;
+ struct interface *i;
+ list_for_each_entry(i, &interfaces, head) {
+ if (i == iface && !enable)
+ continue;
+
+ if (i->ndp == RELAYD_RELAY)
+ enable_packet = true;
+ }
+
+ if (enable_packet && ndp_event.uloop.fd < 0) {
+ // Create socket for intercepting NDP
+ int sock = socket(AF_PACKET, SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK,
+ htons(ETH_P_ALL)); // ETH_P_ALL for ingress + egress
+ if (sock < 0) {
+ syslog(LOG_ERR, "Unable to open packet socket: %s",
+ strerror(errno));
+ return -1;
+ }
+
+ if (setsockopt(sock, SOL_SOCKET, SO_ATTACH_FILTER,
+ &bpf_prog, sizeof(bpf_prog))) {
+ syslog(LOG_ERR, "Failed to set BPF: %s", strerror(errno));
+ return -1;
+ }
+
+ ndp_event.uloop.fd = sock;
+ odhcpd_register(&ndp_event);
+ } else if (!enable_packet && ndp_event.uloop.fd >= 0) {
+ close(ndp_event.uloop.fd);
+ ndp_event.uloop.fd = -1;
+ }
+