Created
January 27, 2025 11:14
-
-
Save qinqon/5b7ca85cd655ed86eb8ace7d4b43c9c5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| index d8515aa..60b5365 100644 | |
| --- a/dhcp.c | |
| +++ b/dhcp.c | |
| @@ -291,8 +291,8 @@ int dhcp(const struct ctx *c, const struct pool *p) | |
| const struct ethhdr *eh; | |
| const struct iphdr *iph; | |
| const struct udphdr *uh; | |
| + struct msg *m, resp; | |
| unsigned int i; | |
| - struct msg *m; | |
| eh = packet_get(p, 0, offset, sizeof(*eh), NULL); | |
| offset += sizeof(*eh); | |
| @@ -321,6 +321,8 @@ int dhcp(const struct ctx *c, const struct pool *p) | |
| m->op != BOOTREQUEST) | |
| return -1; | |
| + memcpy(&resp, m, mlen); | |
| + | |
| offset += offsetof(struct msg, o); | |
| for (i = 0; i < ARRAY_SIZE(opts); i++) | |
| @@ -362,9 +364,9 @@ int dhcp(const struct ctx *c, const struct pool *p) | |
| return -1; | |
| } | |
| - info(" from %s", eth_ntop(m->chaddr, macstr, sizeof(macstr))); | |
| + info(" from %s", eth_ntop(resp.chaddr, macstr, sizeof(macstr))); | |
| - m->yiaddr = c->ip4.addr; | |
| + resp.yiaddr = c->ip4.addr; | |
| mask.s_addr = htonl(0xffffffff << (32 - c->ip4.prefix_len)); | |
| memcpy(opts[1].s, &mask, sizeof(mask)); | |
| memcpy(opts[3].s, &c->ip4.guest_gw, sizeof(c->ip4.guest_gw)); | |
| @@ -399,16 +401,16 @@ int dhcp(const struct ctx *c, const struct pool *p) | |
| opts[6].slen = -1; | |
| if (!c->no_dhcp_dns_search) | |
| - opt_set_dns_search(c, sizeof(m->o)); | |
| + opt_set_dns_search(c, sizeof(resp.o)); | |
| - dlen = offsetof(struct msg, o) + fill(m); | |
| + dlen = offsetof(struct msg, o) + fill(&resp); | |
| if (m->flags & FLAG_BROADCAST) | |
| dst = in4addr_broadcast; | |
| else | |
| dst = c->ip4.addr; | |
| - tap_udp4_send(c, c->ip4.our_tap_addr, 67, dst, 68, m, dlen); | |
| + tap_udp4_send(c, c->ip4.our_tap_addr, 67, dst, 68, &resp, dlen); | |
| return 1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment