summaryrefslogtreecommitdiff
path: root/lib/networking/dhserver.c
diff options
context:
space:
mode:
authorHiFiPhile <[email protected]>2024-05-09 15:51:53 +0200
committerHiFiPhile <[email protected]>2024-05-09 15:51:53 +0200
commit36ce6fad8ca997804a569fe575584b45a1b5fc79 (patch)
treef79aa084a42438667b5e26b588a6f794c9ad1608 /lib/networking/dhserver.c
parentf607a99127cc9e8dfc3f716f977e6c1bfb6f7c2d (diff)
parent74e57499baac36c4cccf76549259905162031e41 (diff)
Merge branch 'master' into vendor_class_zero_length_transfer
Diffstat (limited to 'lib/networking/dhserver.c')
-rw-r--r--lib/networking/dhserver.c38
1 files changed, 23 insertions, 15 deletions
diff --git a/lib/networking/dhserver.c b/lib/networking/dhserver.c
index 9287858ea..2f14f7a09 100644
--- a/lib/networking/dhserver.c
+++ b/lib/networking/dhserver.c
@@ -2,17 +2,17 @@
* The MIT License (MIT)
*
* Copyright (c) 2015 by Sergey Fetisov <[email protected]>
- *
+ *
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
- *
+ *
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
- *
+ *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -86,7 +86,7 @@ typedef struct
uint8_t dp_giaddr[4]; /* gateway IP address */
uint8_t dp_chaddr[16]; /* client hardware address */
uint8_t dp_legacy[192];
- uint8_t dp_magic[4];
+ uint8_t dp_magic[4];
uint8_t dp_options[275]; /* options area */
} DHCP_TYPE;
@@ -96,19 +96,19 @@ static const dhcp_config_t *config = NULL;
char magic_cookie[] = {0x63,0x82,0x53,0x63};
-static ip_addr_t get_ip(const uint8_t *pnt)
+static ip4_addr_t get_ip(const uint8_t *pnt)
{
- ip_addr_t result;
+ ip4_addr_t result;
memcpy(&result, pnt, sizeof(result));
return result;
}
-static void set_ip(uint8_t *pnt, ip_addr_t value)
+static void set_ip(uint8_t *pnt, ip4_addr_t value)
{
memcpy(pnt, &value.addr, sizeof(value.addr));
}
-static dhcp_entry_t *entry_by_ip(ip_addr_t ip)
+static dhcp_entry_t *entry_by_ip(ip4_addr_t ip)
{
int i;
for (i = 0; i < config->num_entry; i++)
@@ -162,11 +162,11 @@ uint8_t *find_dhcp_option(uint8_t *attrs, int size, uint8_t attr)
int fill_options(void *dest,
uint8_t msg_type,
const char *domain,
- ip_addr_t dns,
+ ip4_addr_t dns,
int lease_time,
- ip_addr_t serverid,
- ip_addr_t router,
- ip_addr_t subnet)
+ ip4_addr_t serverid,
+ ip4_addr_t router,
+ ip4_addr_t subnet)
{
uint8_t *ptr = (uint8_t *)dest;
/* ACK message type */
@@ -240,7 +240,15 @@ static void udp_recv_proc(void *arg, struct udp_pcb *upcb, struct pbuf *p, const
unsigned n = p->len;
if (n > sizeof(dhcp_data)) n = sizeof(dhcp_data);
memcpy(&dhcp_data, p->payload, n);
- switch (dhcp_data.dp_options[2])
+
+ ptr = find_dhcp_option(dhcp_data.dp_options, sizeof(dhcp_data.dp_options), DHCP_MESSAGETYPE);
+ if (ptr == NULL)
+ {
+ pbuf_free(p);
+ return;
+ }
+
+ switch (ptr[2])
{
case DHCP_DISCOVER:
entry = entry_by_mac(dhcp_data.dp_chaddr);
@@ -259,7 +267,7 @@ static void udp_recv_proc(void *arg, struct udp_pcb *upcb, struct pbuf *p, const
DHCP_OFFER,
config->domain,
config->dns,
- entry->lease,
+ entry->lease,
*netif_ip4_addr(netif),
config->router,
*netif_ip4_netmask(netif));
@@ -301,7 +309,7 @@ static void udp_recv_proc(void *arg, struct udp_pcb *upcb, struct pbuf *p, const
DHCP_ACK,
config->domain,
config->dns,
- entry->lease,
+ entry->lease,
*netif_ip4_addr(netif),
config->router,
*netif_ip4_netmask(netif));