diff options
author | Mikael Magnusson <mikma@users.sourceforge.net> | 2021-01-28 22:55:45 +0100 |
---|---|---|
committer | Mikael Magnusson <mikma@users.sourceforge.net> | 2024-01-13 19:08:01 +0000 |
commit | bcc1040a1c3f5394cea82503034d2b78696d0a4b (patch) | |
tree | 8484478f8c4d1552a7b82e583f9e2c830f0a2ed2 | |
parent | ddaa102a4f51f95def99cde2584219ec8f57d95c (diff) |
dhcpv4: add peer-4o6 to ipv4 ubus messages
-rw-r--r-- | src/dhcpv4.c | 22 | ||||
-rw-r--r-- | src/dhcpv6.c | 2 | ||||
-rw-r--r-- | src/odhcpd.h | 6 | ||||
-rw-r--r-- | src/ubus.c | 12 |
4 files changed, 31 insertions, 11 deletions
diff --git a/src/dhcpv4.c b/src/dhcpv4.c index 3191ff2..77f669c 100644 --- a/src/dhcpv4.c +++ b/src/dhcpv4.c @@ -53,7 +53,8 @@ static struct dhcp_assignment* dhcpv4_lease(struct interface *iface, enum dhcpv4_msg msg, const uint8_t *mac, const uint32_t reqaddr, uint32_t *leasetime, const char *hostname, const size_t hostname_len, const bool accept_fr_nonce, bool *incl_fr_opt, uint32_t *fr_serverid, - const char *reqopts, const size_t reqopts_len); + const char *reqopts, const size_t reqopts_len, + const struct in6_addr *peer_4o6); static struct netevent_handler dhcpv4_netevent_handler = { .cb = dhcpv4_netevent_cb, }; static struct uloop_timeout valid_until_timeout = {.cb = valid_until_cb}; @@ -604,12 +605,14 @@ static void handle_dhcpv4(void *addr, void *data, size_t len, { int sock = iface->dhcpv4_event.uloop.fd; - dhcpv4_handle_msg(addr, data, len, iface, dest_addr, dhcpv4_send_reply, &sock); + dhcpv4_handle_msg(addr, data, len, iface, dest_addr, dhcpv4_send_reply, &sock, + NULL); } void dhcpv4_handle_msg(void *addr, void *data, size_t len, struct interface *iface, _unused void *dest_addr, - send_reply_cb_t send_reply, void *opaque) + send_reply_cb_t send_reply, void *opaque, + const struct in6_addr *peer_4o6) { struct dhcpv4_message *req = data; @@ -713,7 +716,7 @@ void dhcpv4_handle_msg(void *addr, void *data, size_t len, a = dhcpv4_lease(iface, reqmsg, req->chaddr, reqaddr, &leasetime, hostname, hostname_len, accept_fr_nonce, &incl_fr_opt, &fr_serverid, - reqopts, reqopts_len); + reqopts, reqopts_len, peer_4o6); if (!a) { if (reqmsg == DHCPV4_MSG_REQUEST) @@ -759,7 +762,7 @@ void dhcpv4_handle_msg(void *addr, void *data, size_t len, #ifdef WITH_UBUS if (reqmsg == DHCPV4_MSG_RELEASE) ubus_bcast_dhcp_event("dhcp.release", req->chaddr, req->hlen, - &req->ciaddr, a ? a->hostname : NULL, iface->ifname); + &req->ciaddr, a ? a->hostname : NULL, iface->ifname, peer_4o6); #endif if (reqmsg == DHCPV4_MSG_DECLINE || reqmsg == DHCPV4_MSG_RELEASE) return; @@ -926,7 +929,7 @@ void dhcpv4_handle_msg(void *addr, void *data, size_t len, #ifdef WITH_UBUS if (msg == DHCPV4_MSG_ACK) ubus_bcast_dhcp_event("dhcp.ack", req->chaddr, req->hlen, &reply.yiaddr, - a ? a->hostname : NULL, iface->ifname); + a ? a->hostname : NULL, iface->ifname, peer_4o6); #endif } @@ -1035,7 +1038,8 @@ static struct dhcp_assignment* dhcpv4_lease(struct interface *iface, enum dhcpv4_msg msg, const uint8_t *mac, const uint32_t reqaddr, uint32_t *leasetime, const char *hostname, const size_t hostname_len, const bool accept_fr_nonce, bool *incl_fr_opt, - uint32_t *fr_serverid, const char* reqopts, const size_t reqopts_len) + uint32_t *fr_serverid, const char* reqopts, const size_t reqopts_len, + const struct in6_addr *peer_4o6) { struct dhcp_assignment *a = find_assignment_by_hwaddr(iface, mac); struct lease *l = config_find_lease_by_mac(mac); @@ -1071,6 +1075,10 @@ dhcpv4_lease(struct interface *iface, enum dhcpv4_msg msg, const uint8_t *mac, a->iface = iface; a->flags = OAF_DHCPV4; a->addr = l ? l->ipaddr : INADDR_ANY; + if (peer_4o6) { + a->peer.sin6_family = AF_INET6; + a->peer.sin6_addr = *peer_4o6; + } assigned = dhcpv4_assign(iface, a, reqaddr); diff --git a/src/dhcpv6.c b/src/dhcpv6.c index b086fd8..01adc04 100644 --- a/src/dhcpv6.c +++ b/src/dhcpv6.c @@ -298,7 +298,7 @@ static ssize_t dhcpv6_4o6_query(uint8_t *buf, size_t buflen, addrv4.sin_port = htons(DHCPV4_CLIENT_PORT); dhcpv4_handle_msg(&addrv4, msgv4_data, msgv4_len, - iface, NULL, send_reply, &reply); + iface, NULL, send_reply, &reply, &addr->sin6_addr); return reply.len; } diff --git a/src/odhcpd.h b/src/odhcpd.h index ac2dcac..e410886 100644 --- a/src/odhcpd.h +++ b/src/odhcpd.h @@ -441,7 +441,8 @@ 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); + const struct in_addr *addr, const char *name, const char *interface, + const struct in6_addr *peer_4o6); void ubus_bcast_dhcpv6_event(const char *type, const struct dhcp_assignment *a, const struct odhcpd_ipaddr *addrs, ssize_t addr_len); #endif @@ -479,7 +480,8 @@ int dhcpv4_init(void); int dhcpv4_setup_interface(struct interface *iface, bool enable); void dhcpv4_handle_msg(void *addr, void *data, size_t len, struct interface *iface, _unused void *dest_addr, - send_reply_cb_t send_reply, void *opaque); + send_reply_cb_t send_reply, void *opaque, + const struct in6_addr *peer_4o6); #endif int router_setup_interface(struct interface *iface, bool enable); int dhcpv6_setup_interface(struct interface *iface, bool enable); @@ -80,6 +80,11 @@ static int handle_dhcpv4_leases(struct ubus_context *ctx, _unused struct ubus_ob blobmsg_add_u32(&b, "valid", INFINITE_VALID(c->valid_until) ? (uint32_t)-1 : (uint32_t)(c->valid_until - now)); + char hbuf[NI_MAXHOST] = ""; + getnameinfo((struct sockaddr *)&c->peer, sizeof(c->peer), + hbuf, sizeof(hbuf), NULL, 0, NI_NUMERICHOST); + blobmsg_add_string(&b, "peer-4o6", hbuf); + blobmsg_close_table(&b, l); } @@ -349,7 +354,7 @@ static const struct blobmsg_policy obj_attrs[OBJ_ATTR_MAX] = { 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) + const char *interface, const struct in6_addr *peer_4o6) { if (!ubus || !main_object.has_subscribers) return; @@ -363,6 +368,11 @@ void ubus_bcast_dhcp_event(const char *type, const uint8_t *mac, blobmsg_add_string(&b, "name", name); if (interface) blobmsg_add_string(&b, "interface", interface); + if (peer_4o6) { + char *peer = blobmsg_alloc_string_buffer(&b, "peer-4o6", INET6_ADDRSTRLEN); + inet_ntop(AF_INET6, peer_4o6, peer, INET6_ADDRSTRLEN); + blobmsg_add_string_buffer(&b); + } ubus_notify(ubus, &main_object, type, b.head, -1); } |