| 1 |
/* |
| 2 |
* Copyright (c) Espressif Systems (Shanghai) CO LTD |
| 3 |
* All rights reserved. |
| 4 |
* |
| 5 |
* Redistribution and use in source and binary forms, with or without modification, |
| 6 |
* are permitted provided that the following conditions are met: |
| 7 |
* |
| 8 |
* 1. Redistributions of source code must retain the above copyright notice, |
| 9 |
* this list of conditions and the following disclaimer. |
| 10 |
* 2. Redistributions in binary form must reproduce the above copyright notice, |
| 11 |
* this list of conditions and the following disclaimer in the documentation |
| 12 |
* and/or other materials provided with the distribution. |
| 13 |
* 3. Neither the name of the copyright holder nor the names of its contributors |
| 14 |
* may be used to endorse or promote products derived from this software |
| 15 |
* without specific prior written permission. |
| 16 |
* |
| 17 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 18 |
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 19 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 20 |
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
| 21 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 22 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 23 |
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 24 |
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 25 |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 |
*/ |
| 28 |
#include <string.h> |
| 29 |
|
| 30 |
#include "lwip/prot/dhcp.h" |
| 31 |
#include "lwip/dhcp.h" |
| 32 |
#include "lwip/netif.h" |
| 33 |
#include "lwip/prot/iana.h" |
| 34 |
|
| 35 |
|
| 36 |
void dhcp_parse_extra_opts(struct dhcp *dhcp, uint8_t state, uint8_t option, uint8_t len, struct pbuf* p, uint16_t offset) |
| 37 |
{ |
| 38 |
LWIP_UNUSED_ARG(dhcp); |
| 39 |
LWIP_UNUSED_ARG(state); |
| 40 |
LWIP_UNUSED_ARG(option); |
| 41 |
LWIP_UNUSED_ARG(len); |
| 42 |
LWIP_UNUSED_ARG(p); |
| 43 |
LWIP_UNUSED_ARG(offset); |
| 44 |
#if LWIP_DHCP_ENABLE_MTU_UPDATE |
| 45 |
if ((option == DHCP_OPTION_MTU) && |
| 46 |
(state == DHCP_STATE_REBOOTING || state == DHCP_STATE_REBINDING || |
| 47 |
state == DHCP_STATE_RENEWING || state == DHCP_STATE_REQUESTING)) { |
| 48 |
u32_t mtu = 0; |
| 49 |
struct netif *netif; |
| 50 |
LWIP_ERROR("dhcp_parse_extra_opts(): MTU option's len != 2", len == 2, return;); |
| 51 |
LWIP_ERROR("dhcp_parse_extra_opts(): extracting MTU option failed", |
| 52 |
pbuf_copy_partial(p, &mtu, 2, offset) == 2, return;); |
| 53 |
mtu = lwip_htons((u16_t)mtu); |
| 54 |
NETIF_FOREACH(netif) { |
| 55 |
/* find the netif related to this dhcp */ |
| 56 |
if (dhcp == netif_dhcp_data(netif)) { |
| 57 |
if (mtu < netif->mtu) { |
| 58 |
netif->mtu = mtu; |
| 59 |
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_parse_extra_opts(): Negotiated netif MTU is %d\n", netif->mtu)); |
| 60 |
} |
| 61 |
return; |
| 62 |
} |
| 63 |
} |
| 64 |
} /* DHCP_OPTION_MTU */ |
| 65 |
#endif /* LWIP_DHCP_ENABLE_MTU_UPDATE */ |
| 66 |
} |
| 67 |
|
| 68 |
void dhcp_append_extra_opts(struct netif *netif, uint8_t state, struct dhcp_msg *msg_out, uint16_t *options_out_len) |
| 69 |
{ |
| 70 |
LWIP_UNUSED_ARG(netif); |
| 71 |
LWIP_UNUSED_ARG(state); |
| 72 |
LWIP_UNUSED_ARG(msg_out); |
| 73 |
LWIP_UNUSED_ARG(options_out_len); |
| 74 |
#if LWIP_DHCP_ENABLE_CLIENT_ID |
| 75 |
if (state == DHCP_STATE_RENEWING || state == DHCP_STATE_REBINDING || |
| 76 |
state == DHCP_STATE_REBOOTING || state == DHCP_STATE_OFF || |
| 77 |
state == DHCP_STATE_REQUESTING || state == DHCP_STATE_BACKING_OFF || state == DHCP_STATE_SELECTING) { |
| 78 |
size_t i; |
| 79 |
u8_t *options = msg_out->options + *options_out_len; |
| 80 |
LWIP_ERROR("dhcp_append(client_id): options_out_len + 3 + netif->hwaddr_len <= DHCP_OPTIONS_LEN", |
| 81 |
*options_out_len + 3U + netif->hwaddr_len <= DHCP_OPTIONS_LEN, return;); |
| 82 |
*options_out_len = *options_out_len + netif->hwaddr_len + 3; |
| 83 |
*options++ = DHCP_OPTION_CLIENT_ID; |
| 84 |
*options++ = netif->hwaddr_len + 1; /* option size */ |
| 85 |
*options++ = LWIP_IANA_HWTYPE_ETHERNET; |
| 86 |
for (i = 0; i < netif->hwaddr_len; i++) { |
| 87 |
*options++ = netif->hwaddr[i]; |
| 88 |
} |
| 89 |
} |
| 90 |
#endif /* LWIP_DHCP_ENABLE_CLIENT_ID */ |
| 91 |
} |