diff options
| author | Peter Lawrence <[email protected]> | 2020-10-14 20:26:40 -0500 |
|---|---|---|
| committer | Peter Lawrence <[email protected]> | 2020-10-14 20:26:40 -0500 |
| commit | 56277ce21639a1e3ed608e73d67367d2b21c1764 (patch) | |
| tree | 0ab8065c30b2a9477de8886bb7ef0328cc80d7e1 /lib | |
| parent | 41083cb67a1f7ef5d2647125ec90b4ed7db1d623 (diff) | |
net_lwip_webserver: efficiency tweaks
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/networking/dhserver.c | 43 | ||||
| -rw-r--r-- | lib/networking/dhserver.h | 7 |
2 files changed, 25 insertions, 25 deletions
diff --git a/lib/networking/dhserver.c b/lib/networking/dhserver.c index a1a570f93..9287858ea 100644 --- a/lib/networking/dhserver.c +++ b/lib/networking/dhserver.c @@ -96,23 +96,23 @@ static const dhcp_config_t *config = NULL; char magic_cookie[] = {0x63,0x82,0x53,0x63}; -static uint32_t get_ip(const uint8_t *pnt) +static ip_addr_t get_ip(const uint8_t *pnt) { - uint32_t result; + ip_addr_t result; memcpy(&result, pnt, sizeof(result)); return result; } -static void set_ip(uint8_t *pnt, uint32_t value) +static void set_ip(uint8_t *pnt, ip_addr_t value) { - memcpy(pnt, &value, sizeof(value)); + memcpy(pnt, &value.addr, sizeof(value.addr)); } -static dhcp_entry_t *entry_by_ip(uint32_t ip) +static dhcp_entry_t *entry_by_ip(ip_addr_t ip) { int i; for (i = 0; i < config->num_entry; i++) - if (get_ip(config->entries[i].addr) == ip) + if (config->entries[i].addr.addr == ip.addr) return &config->entries[i]; return NULL; } @@ -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, - uint32_t dns, + ip_addr_t dns, int lease_time, - uint32_t serverid, - uint32_t router, - uint32_t subnet) + ip_addr_t serverid, + ip_addr_t router, + ip_addr_t subnet) { uint8_t *ptr = (uint8_t *)dest; /* ACK message type */ @@ -195,7 +195,7 @@ int fill_options(void *dest, ptr += 4; /* router */ - if (router != 0) + if (router.addr != 0) { *ptr++ = DHCP_ROUTER; *ptr++ = 4; @@ -214,7 +214,7 @@ int fill_options(void *dest, } /* domain name server (DNS) */ - if (dns != 0) + if (dns.addr != 0) { *ptr++ = DHCP_DNSSERVER; *ptr++ = 4; @@ -232,6 +232,7 @@ static void udp_recv_proc(void *arg, struct udp_pcb *upcb, struct pbuf *p, const uint8_t *ptr; dhcp_entry_t *entry; struct pbuf *pp; + struct netif *netif = netif_get_by_index(p->if_idx); (void)arg; (void)addr; @@ -249,7 +250,7 @@ static void udp_recv_proc(void *arg, struct udp_pcb *upcb, struct pbuf *p, const dhcp_data.dp_op = 2; /* reply */ dhcp_data.dp_secs = 0; dhcp_data.dp_flags = 0; - set_ip(dhcp_data.dp_yiaddr, get_ip(entry->addr)); + set_ip(dhcp_data.dp_yiaddr, entry->addr); memcpy(dhcp_data.dp_magic, magic_cookie, 4); memset(dhcp_data.dp_options, 0, sizeof(dhcp_data.dp_options)); @@ -257,11 +258,11 @@ static void udp_recv_proc(void *arg, struct udp_pcb *upcb, struct pbuf *p, const fill_options(dhcp_data.dp_options, DHCP_OFFER, config->domain, - get_ip(config->dns), + config->dns, entry->lease, - get_ip(config->addr), - get_ip(config->addr), - get_ip(entry->subnet)); + *netif_ip4_addr(netif), + config->router, + *netif_ip4_netmask(netif)); pp = pbuf_alloc(PBUF_TRANSPORT, sizeof(dhcp_data), PBUF_POOL); if (pp == NULL) break; @@ -299,11 +300,11 @@ static void udp_recv_proc(void *arg, struct udp_pcb *upcb, struct pbuf *p, const fill_options(dhcp_data.dp_options, DHCP_ACK, config->domain, - get_ip(config->dns), + config->dns, entry->lease, - get_ip(config->addr), - get_ip(config->addr), - get_ip(entry->subnet)); + *netif_ip4_addr(netif), + config->router, + *netif_ip4_netmask(netif)); /* 6. send ACK */ pp = pbuf_alloc(PBUF_TRANSPORT, sizeof(dhcp_data), PBUF_POOL); diff --git a/lib/networking/dhserver.h b/lib/networking/dhserver.h index 901f6e351..0d22461c7 100644 --- a/lib/networking/dhserver.h +++ b/lib/networking/dhserver.h @@ -42,16 +42,15 @@ typedef struct dhcp_entry { uint8_t mac[6]; - uint8_t addr[4]; - uint8_t subnet[4]; + ip_addr_t addr; uint32_t lease; } dhcp_entry_t; typedef struct dhcp_config { - uint8_t addr[4]; + ip_addr_t router; uint16_t port; - uint8_t dns[4]; + ip_addr_t dns; const char *domain; int num_entry; dhcp_entry_t *entries; |
