req->chaddr[0],req->chaddr[1],req->chaddr[2],
req->chaddr[3],req->chaddr[4],req->chaddr[5]);
+#ifdef WITH_UBUS
+ if (reqmsg == DHCPV4_MSG_RELEASE)
+ ubus_bcast_dhcp_event("dhcp.release", req->chaddr, req->hlen,
+ &req->ciaddr, hostname, iface->ifname);
+#endif
if (reqmsg == DHCPV4_MSG_DECLINE || reqmsg == DHCPV4_MSG_RELEASE)
return;
sendto(sock, &reply, sizeof(reply), MSG_DONTWAIT,
(struct sockaddr*)&dest, sizeof(dest));
+
+#ifdef WITH_UBUS
+ if (msg == DHCPV4_MSG_ACK)
+ ubus_bcast_dhcp_event("dhcp.ack", req->chaddr, req->hlen, &reply.yiaddr,
+ hostname, iface->ifname);
+#endif
}
static bool dhcpv4_assign(struct interface *iface,
*dst = 0;
}
+const char *odhcpd_print_mac(const uint8_t *mac, const size_t len)
+{
+ static char buf[32];
+
+ snprintf(buf, sizeof(buf), "%02x", mac[0]);
+ for (size_t i = 1, j = 2; i < len && j < sizeof(buf); i++, j += 3)
+ snprintf(buf + j, sizeof(buf) - j, ":%02x", mac[i]);
+
+ return buf;
+}
int odhcpd_bmemcmp(const void *av, const void *bv, size_t bits)
{
time_t odhcpd_time(void);
ssize_t odhcpd_unhexlify(uint8_t *dst, size_t len, const char *src);
void odhcpd_hexlify(char *dst, const uint8_t *src, size_t len);
+const char *odhcpd_print_mac(const uint8_t *mac, const size_t len);
int odhcpd_bmemcmp(const void *av, const void *bv, size_t bits);
void odhcpd_bmemcpy(void *av, const void *bv, size_t bits);
const char* ubus_get_ifname(const char *name);
void ubus_apply_network(void);
bool ubus_has_prefix(const char *name, const char *ifname);
+void ubus_bcast_dhcp_event(const char *type, const uint8_t *mac, const size_t mac_len,
+ const struct in_addr *addr, const char *name, const char *interface);
#endif
int netlink_add_netevent_handler(struct netevent_handler *hdlr);
[OBJ_ATTR_PATH] = { .name = "path", .type = BLOBMSG_TYPE_STRING },
};
+void ubus_bcast_dhcp_event(const char *type, const uint8_t *mac,
+ const size_t mlen, const struct in_addr *addr, const char *name,
+ const char *interface)
+{
+ if (!ubus || !main_object.has_subscribers)
+ return;
+
+ blob_buf_init(&b, 0);
+ if (mac)
+ blobmsg_add_string(&b, "mac", odhcpd_print_mac(mac, mlen));
+ if (addr)
+ blobmsg_add_string(&b, "ip", inet_ntoa(*addr));
+ if (name)
+ blobmsg_add_string(&b, "name", name);
+ if (interface)
+ blobmsg_add_string(&b, "interface", interface);
+
+ ubus_notify(ubus, &main_object, type, b.head, -1);
+}
static void handle_event(_unused struct ubus_context *ctx, _unused struct ubus_event_handler *ev,
_unused const char *type, struct blob_attr *msg)