1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
98
99
100
101
102
107
108
109
110
111
113
114
115
116
117
118
119
120
121
126
127
128
129
130
135
136
137
138
139
140
141
142
143
144
145
147
148
149
151
152
153
154
155
157
158
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
178
179
180
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
313
314
317
320
321
322
323
324
325
326
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
400
401
402
403
404
405
406
407
408
409
410
411
412
416
419
420
421
422
423
424
425
429
430
459
460
467
468
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
538
539
540
545
546
547
548
549
550
551
552
553
555
556
557
559
560
561
564
565
566
567
572
573
574
575
576
577
578
579
580
581
582
583
585
586
587
590
591
592
593
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
622
623
630
631
632
639
640
641
642
643
644
647
648
649
650
657
658
659
662
663
664
669
670
671
672
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
753
754
755
756
757
758
762
763
764
765
766
767
775
776
777
778
779
780
781
782
785
786
787
792
793
794
795
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
848
849
850
851
852
857
858
859
860
861
862
865
866
867
868
869
873
876
877
878
881
882
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
964
967
968
969
970
971
972
973
974
975
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1007
1008
1009
1010
1011
1012
1013
1014
1015
1018
1021
1022
1027
1028
1029
1030
1031
1032
1033
1034
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1060
1061
1064
1065
1066
1067
1068
1069
1070
1071
1072
1075
1076
1079
1080
1081
1082
1083
1084
1085
1086
1089
1090
1093
1094
1095
1096
1097
1098
1101
1102
1116
1117
1118
1119
1125
1126
1127
1132
1133
1134
1135
1137
1138
1139
1140
1141
1142
1143
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1190
1193
1194
1195
1196
1197
1198
1199
1200
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1245
1248
1249
1250
1251
1252
1253
1254
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1302
1305
1306
1307
1308
1309
1310
1311
1317
1318
1319
1320
1321
1322
1323
1324
1325
1328
1329
1330
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1368
1369
1370
1371
1372
1373
1374
1379
1380
1381
1382
1386
1387
1388
1393
1394
1399
1400
1405
1406
1410
1411
1416
1417
1425
1426
1431
1432
1433
1434
1435
1436
1437
1438
1439
1443
1444
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1482
1483
1484
1485
1486
1487
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1530
1531
1532
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1549
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1566
1567
1572
1573
1574
1575
1576
1581
1585
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1620
1624
1628
1632
1636
1637
1638
1639
1640
1641
1642
1643
1644
1647
1651
1652
1653
1654
1655
1656
1657
1658
1659
1662
1663
1664
1665
1666
1667
1668
1669
1670
1674
1675
1676
1677
1683
1684
1685
1686
1687
1688
1700
1701
1702
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1734
1735
1736
1737
1738
1739
1740
1743
1744
1745
1746
1747
1748
1749
1750
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1785
1786
1790
1791
1799
1800
1805
1806
1811
1812
1813
1814
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1837
1839
1840
1841
1842
1847
1848
1849
1855
1856
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1897
1898
1899
1900
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1933
1934
1939
1943
1944
1945
1946
1947
1950
1951
1952
1953
1959
1960
1961
1962
1963
1964
1969
1970
1971
1972
1973
1979
1980
1989
1990
/* ... */
/* ... */
#include "lwip/opt.h"
#if LWIP_IPV4 && LWIP_DHCP
#include "lwip/stats.h"
#include "lwip/mem.h"
#include "lwip/udp.h"
#include "lwip/ip_addr.h"
#include "lwip/netif.h"
#include "lwip/def.h"
#include "lwip/dhcp.h"
#include "lwip/autoip.h"
#include "lwip/dns.h"
#include "lwip/etharp.h"
#include "lwip/prot/dhcp.h"
#include "lwip/prot/iana.h"
#include <string.h>
13 includes
#ifdef LWIP_HOOK_FILENAME
#include LWIP_HOOK_FILENAME
#endif
#ifndef LWIP_HOOK_DHCP_APPEND_OPTIONS
#define LWIP_HOOK_DHCP_APPEND_OPTIONS(netif, dhcp, state, msg, msg_type, options_len_ptr)
#endif
#ifndef LWIP_HOOK_DHCP_PARSE_OPTION
#define LWIP_HOOK_DHCP_PARSE_OPTION(netif, dhcp, state, msg, msg_type, option, len, pbuf, offset) do { LWIP_UNUSED_ARG(msg); } while(0)
#endif
/* ... */
#ifndef DHCP_CREATE_RAND_XID
#define DHCP_CREATE_RAND_XID 1
#endif
/* ... */
#ifdef DHCP_GLOBAL_XID_HEADER
#include DHCP_GLOBAL_XID_HEADER
#endif
/* ... */
#define DHCP_MAX_MSG_LEN(netif) (netif->mtu)
#define DHCP_MAX_MSG_LEN_MIN_REQUIRED 576
#define DHCP_MIN_REPLY_LEN 44
#define REBOOT_TRIES 2
#if LWIP_DNS && LWIP_DHCP_MAX_DNS_SERVERS
#if DNS_MAX_SERVERS > LWIP_DHCP_MAX_DNS_SERVERS
#define LWIP_DHCP_PROVIDE_DNS_SERVERS LWIP_DHCP_MAX_DNS_SERVERS
#else
#define LWIP_DHCP_PROVIDE_DNS_SERVERS DNS_MAX_SERVERS
#endif/* ... */
#else
#define LWIP_DHCP_PROVIDE_DNS_SERVERS 0
#endif
/* ... */
enum dhcp_option_idx {
DHCP_OPTION_IDX_OVERLOAD = 0,
DHCP_OPTION_IDX_MSG_TYPE,
DHCP_OPTION_IDX_SERVER_ID,
DHCP_OPTION_IDX_LEASE_TIME,
DHCP_OPTION_IDX_T1,
DHCP_OPTION_IDX_T2,
DHCP_OPTION_IDX_SUBNET_MASK,
DHCP_OPTION_IDX_ROUTER,
#if LWIP_DHCP_PROVIDE_DNS_SERVERS
DHCP_OPTION_IDX_DNS_SERVER,
DHCP_OPTION_IDX_DNS_SERVER_LAST = DHCP_OPTION_IDX_DNS_SERVER + LWIP_DHCP_PROVIDE_DNS_SERVERS - 1,/* ... */
#endif
#if LWIP_DHCP_GET_NTP_SRV
DHCP_OPTION_IDX_NTP_SERVER,
DHCP_OPTION_IDX_NTP_SERVER_LAST = DHCP_OPTION_IDX_NTP_SERVER + LWIP_DHCP_MAX_NTP_SERVERS - 1,/* ... */
#endif
DHCP_OPTION_IDX_MAX
...};
/* ... */
u32_t dhcp_rx_options_val[DHCP_OPTION_IDX_MAX];
/* ... */
u8_t dhcp_rx_options_given[DHCP_OPTION_IDX_MAX];
static u8_t dhcp_discover_request_options[] = {
DHCP_OPTION_SUBNET_MASK,
DHCP_OPTION_ROUTER,
DHCP_OPTION_BROADCAST
#if LWIP_DHCP_PROVIDE_DNS_SERVERS
, DHCP_OPTION_DNS_SERVER
#endif
#if LWIP_DHCP_GET_NTP_SRV
, DHCP_OPTION_NTP
#endif
...};
#ifdef DHCP_GLOBAL_XID
static u32_t xid;
static u8_t xid_initialised;/* ... */
#endif
#define dhcp_option_given(dhcp, idx) (dhcp_rx_options_given[idx] != 0)
#define dhcp_got_option(dhcp, idx) (dhcp_rx_options_given[idx] = 1)
#define dhcp_clear_option(dhcp, idx) (dhcp_rx_options_given[idx] = 0)
#define dhcp_clear_all_options(dhcp) (memset(dhcp_rx_options_given, 0, sizeof(dhcp_rx_options_given)))
#define dhcp_get_option_value(dhcp, idx) (dhcp_rx_options_val[idx])
#define dhcp_set_option_value(dhcp, idx, val) (dhcp_rx_options_val[idx] = (val))
6 defines
static struct udp_pcb *dhcp_pcb;
static u8_t dhcp_pcb_refcount;
static err_t dhcp_discover(struct netif *netif);
static err_t dhcp_select(struct netif *netif);
static void dhcp_bind(struct netif *netif);
#if DHCP_DOES_ARP_CHECK
static err_t dhcp_decline(struct netif *netif);
#endif
static err_t dhcp_rebind(struct netif *netif);
static err_t dhcp_reboot(struct netif *netif);
static void dhcp_set_state(struct dhcp *dhcp, u8_t new_state);
static void dhcp_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, u16_t port);
static void dhcp_timeout(struct netif *netif);
static void dhcp_t1_timeout(struct netif *netif);
static void dhcp_t2_timeout(struct netif *netif);
static struct pbuf *dhcp_create_msg(struct netif *netif, struct dhcp *dhcp, u8_t message_type, u16_t *options_out_len);
static u16_t dhcp_option(u16_t options_out_len, u8_t *options, u8_t option_type, u8_t option_len);
static u16_t dhcp_option_byte(u16_t options_out_len, u8_t *options, u8_t value);
static u16_t dhcp_option_short(u16_t options_out_len, u8_t *options, u16_t value);
static u16_t dhcp_option_long(u16_t options_out_len, u8_t *options, u32_t value);
#if LWIP_NETIF_HOSTNAME
static u16_t dhcp_option_hostname(u16_t options_out_len, u8_t *options, struct netif *netif);
#endif
static void dhcp_option_trailer(u16_t options_out_len, u8_t *options, struct pbuf *p_out);
static err_t
dhcp_inc_pcb_refcount(void)
{
if (dhcp_pcb_refcount == 0) {
LWIP_ASSERT("dhcp_inc_pcb_refcount(): memory leak", dhcp_pcb == NULL);
dhcp_pcb = udp_new();
if (dhcp_pcb == NULL) {
return ERR_MEM;
}if (dhcp_pcb == NULL) { ... }
ip_set_option(dhcp_pcb, SOF_BROADCAST);
udp_bind(dhcp_pcb, IP4_ADDR_ANY, LWIP_IANA_PORT_DHCP_CLIENT);
udp_connect(dhcp_pcb, IP4_ADDR_ANY, LWIP_IANA_PORT_DHCP_SERVER);
udp_recv(dhcp_pcb, dhcp_recv, NULL);
}if (dhcp_pcb_refcount == 0) { ... }
dhcp_pcb_refcount++;
return ERR_OK;
}{ ... }
static void
dhcp_dec_pcb_refcount(void)
{
LWIP_ASSERT("dhcp_pcb_refcount(): refcount error", (dhcp_pcb_refcount > 0));
dhcp_pcb_refcount--;
if (dhcp_pcb_refcount == 0) {
udp_remove(dhcp_pcb);
dhcp_pcb = NULL;
}if (dhcp_pcb_refcount == 0) { ... }
}{ ... }
/* ... */
static void
dhcp_handle_nak(struct netif *netif)
{
struct dhcp *dhcp = netif_dhcp_data(netif);
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_handle_nak(netif=%p) %c%c%"U16_F"\n",
(void *)netif, netif->name[0], netif->name[1], (u16_t)netif->num));
/* ... */
dhcp_set_state(dhcp, DHCP_STATE_BACKING_OFF);
netif_set_addr(netif, IP4_ADDR_ANY4, IP4_ADDR_ANY4, IP4_ADDR_ANY4);
dhcp_discover(netif);
}{ ... }
#if DHCP_DOES_ARP_CHECK
/* ... */
static void
dhcp_check(struct netif *netif)
{
struct dhcp *dhcp = netif_dhcp_data(netif);
err_t result;
u16_t msecs;
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_check(netif=%p) %c%c\n", (void *)netif, (s16_t)netif->name[0],
(s16_t)netif->name[1]));
dhcp_set_state(dhcp, DHCP_STATE_CHECKING);
/* ... */
result = etharp_query(netif, &dhcp->offered_ip_addr, NULL);
if (result != ERR_OK) {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_WARNING, ("dhcp_check: could not perform ARP query\n"));
}if (result != ERR_OK) { ... }
if (dhcp->tries < 255) {
dhcp->tries++;
}if (dhcp->tries < 255) { ... }
msecs = 500;
dhcp->request_timeout = (u16_t)((msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS);
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_check(): set request timeout %"U16_F" msecs\n", msecs));
}{ ... }
#endif/* ... */
/* ... */
static void
dhcp_handle_offer(struct netif *netif, struct dhcp_msg *msg_in)
{
struct dhcp *dhcp = netif_dhcp_data(netif);
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_handle_offer(netif=%p) %c%c%"U16_F"\n",
(void *)netif, netif->name[0], netif->name[1], (u16_t)netif->num));
if (dhcp_option_given(dhcp, DHCP_OPTION_IDX_SERVER_ID)) {
dhcp->request_timeout = 0;
ip_addr_set_ip4_u32(&dhcp->server_ip_addr, lwip_htonl(dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_SERVER_ID)));
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_STATE, ("dhcp_handle_offer(): server 0x%08"X32_F"\n",
ip4_addr_get_u32(ip_2_ip4(&dhcp->server_ip_addr))));
ip4_addr_copy(dhcp->offered_ip_addr, msg_in->yiaddr);
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_STATE, ("dhcp_handle_offer(): offer for 0x%08"X32_F"\n",
ip4_addr_get_u32(&dhcp->offered_ip_addr)));
dhcp_select(netif);
}if (dhcp_option_given(dhcp, DHCP_OPTION_IDX_SERVER_ID)) { ... } else {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_SERIOUS,
("dhcp_handle_offer(netif=%p) did not get server ID!\n", (void *)netif));
}else { ... }
}{ ... }
/* ... */
static err_t
dhcp_select(struct netif *netif)
{
struct dhcp *dhcp;
err_t result;
u16_t msecs;
u8_t i;
struct pbuf *p_out;
u16_t options_out_len;
LWIP_ERROR("dhcp_select: netif != NULL", (netif != NULL), return ERR_ARG;);
dhcp = netif_dhcp_data(netif);
LWIP_ERROR("dhcp_select: dhcp != NULL", (dhcp != NULL), return ERR_VAL;);
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_select(netif=%p) %c%c%"U16_F"\n", (void *)netif, netif->name[0], netif->name[1], (u16_t)netif->num));
dhcp_set_state(dhcp, DHCP_STATE_REQUESTING);
p_out = dhcp_create_msg(netif, dhcp, DHCP_REQUEST, &options_out_len);
if (p_out != NULL) {
struct dhcp_msg *msg_out = (struct dhcp_msg *)p_out->payload;
options_out_len = dhcp_option(options_out_len, msg_out->options, DHCP_OPTION_MAX_MSG_SIZE, DHCP_OPTION_MAX_MSG_SIZE_LEN);
options_out_len = dhcp_option_short(options_out_len, msg_out->options, DHCP_MAX_MSG_LEN(netif));
options_out_len = dhcp_option(options_out_len, msg_out->options, DHCP_OPTION_REQUESTED_IP, 4);
options_out_len = dhcp_option_long(options_out_len, msg_out->options, lwip_ntohl(ip4_addr_get_u32(&dhcp->offered_ip_addr)));
options_out_len = dhcp_option(options_out_len, msg_out->options, DHCP_OPTION_SERVER_ID, 4);
options_out_len = dhcp_option_long(options_out_len, msg_out->options, lwip_ntohl(ip4_addr_get_u32(ip_2_ip4(&dhcp->server_ip_addr))));
options_out_len = dhcp_option(options_out_len, msg_out->options, DHCP_OPTION_PARAMETER_REQUEST_LIST, LWIP_ARRAYSIZE(dhcp_discover_request_options));
for (i = 0; i < LWIP_ARRAYSIZE(dhcp_discover_request_options); i++) {
options_out_len = dhcp_option_byte(options_out_len, msg_out->options, dhcp_discover_request_options[i]);
}for (i = 0; i < LWIP_ARRAYSIZE(dhcp_discover_request_options); i++) { ... }
#if LWIP_NETIF_HOSTNAME
options_out_len = dhcp_option_hostname(options_out_len, msg_out->options, netif);
#endif
LWIP_HOOK_DHCP_APPEND_OPTIONS(netif, dhcp, DHCP_STATE_REQUESTING, msg_out, DHCP_REQUEST, &options_out_len);
dhcp_option_trailer(options_out_len, msg_out->options, p_out);
result = udp_sendto_if_src(dhcp_pcb, p_out, IP_ADDR_BROADCAST, LWIP_IANA_PORT_DHCP_SERVER, netif, IP4_ADDR_ANY);
pbuf_free(p_out);
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_select: REQUESTING\n"));
}if (p_out != NULL) { ... } else {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_WARNING, ("dhcp_select: could not allocate DHCP request\n"));
result = ERR_MEM;
}else { ... }
if (dhcp->tries < 255) {
dhcp->tries++;
}if (dhcp->tries < 255) { ... }
msecs = (u16_t)((dhcp->tries < 6 ? 1 << dhcp->tries : 60) * 1000);
dhcp->request_timeout = (u16_t)((msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS);
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_STATE, ("dhcp_select(): set request timeout %"U16_F" msecs\n", msecs));
return result;
}{ ... }
/* ... */
void
dhcp_coarse_tmr(void)
{
struct netif *netif;
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_coarse_tmr()\n"));
NETIF_FOREACH(netif) {
struct dhcp *dhcp = netif_dhcp_data(netif);
if ((dhcp != NULL) && (dhcp->state != DHCP_STATE_OFF)) {
if (dhcp->t0_timeout && (++dhcp->lease_used == dhcp->t0_timeout)) {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_coarse_tmr(): t0 timeout\n"));
dhcp_release_and_stop(netif);
dhcp_start(netif);
}if (dhcp->t0_timeout && (++dhcp->lease_used == dhcp->t0_timeout)) { ... } else if (dhcp->t2_rebind_time && (dhcp->t2_rebind_time-- == 1)) {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_coarse_tmr(): t2 timeout\n"));
dhcp_t2_timeout(netif);
}else if (dhcp->t2_rebind_time && (dhcp->t2_rebind_time-- == 1)) { ... } else if (dhcp->t1_renew_time && (dhcp->t1_renew_time-- == 1)) {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_coarse_tmr(): t1 timeout\n"));
dhcp_t1_timeout(netif);
}else if (dhcp->t1_renew_time && (dhcp->t1_renew_time-- == 1)) { ... }
}if ((dhcp != NULL) && (dhcp->state != DHCP_STATE_OFF)) { ... }
}NETIF_FOREACH (netif) { ... }
}{ ... }
/* ... */
void
dhcp_fine_tmr(void)
{
struct netif *netif;
NETIF_FOREACH(netif) {
struct dhcp *dhcp = netif_dhcp_data(netif);
if (dhcp != NULL) {
if (dhcp->request_timeout > 1) {
dhcp->request_timeout--;
}if (dhcp->request_timeout > 1) { ... } else if (dhcp->request_timeout == 1) {
dhcp->request_timeout--;
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_fine_tmr(): request timeout\n"));
dhcp_timeout(netif);
}else if (dhcp->request_timeout == 1) { ... }
}if (dhcp != NULL) { ... }
}NETIF_FOREACH (netif) { ... }
}{ ... }
/* ... */
static void
dhcp_timeout(struct netif *netif)
{
struct dhcp *dhcp = netif_dhcp_data(netif);
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_timeout()\n"));
if ((dhcp->state == DHCP_STATE_BACKING_OFF) || (dhcp->state == DHCP_STATE_SELECTING)) {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_timeout(): restarting discovery\n"));
dhcp_discover(netif);
}if ((dhcp->state == DHCP_STATE_BACKING_OFF) || (dhcp->state == DHCP_STATE_SELECTING)) { ... } else if (dhcp->state == DHCP_STATE_REQUESTING) {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_timeout(): REQUESTING, DHCP request timed out\n"));
if (dhcp->tries <= 5) {
dhcp_select(netif);
}if (dhcp->tries <= 5) { ... } else {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_timeout(): REQUESTING, releasing, restarting\n"));
dhcp_release_and_stop(netif);
dhcp_start(netif);
}else { ... }
#if DHCP_DOES_ARP_CHECK
}else if (dhcp->state == DHCP_STATE_REQUESTING) { ... } else if (dhcp->state == DHCP_STATE_CHECKING) {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_timeout(): CHECKING, ARP request timed out\n"));
if (dhcp->tries <= 1) {
dhcp_check(netif);
/* ... */
}if (dhcp->tries <= 1) { ... } else {
dhcp_bind(netif);
}else { ... }
#endif
}else if (dhcp->state == DHCP_STATE_CHECKING) { ... } else if (dhcp->state == DHCP_STATE_REBOOTING) {
if (dhcp->tries < REBOOT_TRIES) {
dhcp_reboot(netif);
}if (dhcp->tries < REBOOT_TRIES) { ... } else {
dhcp_discover(netif);
}else { ... }
}else if (dhcp->state == DHCP_STATE_REBOOTING) { ... }
}{ ... }
/* ... */
static void
dhcp_t1_timeout(struct netif *netif)
{
struct dhcp *dhcp = netif_dhcp_data(netif);
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_STATE, ("dhcp_t1_timeout()\n"));
if ((dhcp->state == DHCP_STATE_REQUESTING) || (dhcp->state == DHCP_STATE_BOUND) ||
(dhcp->state == DHCP_STATE_RENEWING)) {
/* ... */
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE,
("dhcp_t1_timeout(): must renew\n"));
/* ... */
dhcp_renew(netif);
if (((dhcp->t2_timeout - dhcp->lease_used) / 2) >= ((60 + DHCP_COARSE_TIMER_SECS / 2) / DHCP_COARSE_TIMER_SECS)) {
dhcp->t1_renew_time = (u16_t)((dhcp->t2_timeout - dhcp->lease_used) / 2);
}if (((dhcp->t2_timeout - dhcp->lease_used) / 2) >= ((60 + DHCP_COARSE_TIMER_SECS / 2) / DHCP_COARSE_TIMER_SECS)) { ... }
}if ((dhcp->state == DHCP_STATE_REQUESTING) || (dhcp->state == DHCP_STATE_BOUND) || (dhcp->state == DHCP_STATE_RENEWING)) { ... }
}{ ... }
/* ... */
static void
dhcp_t2_timeout(struct netif *netif)
{
struct dhcp *dhcp = netif_dhcp_data(netif);
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_t2_timeout()\n"));
if ((dhcp->state == DHCP_STATE_REQUESTING) || (dhcp->state == DHCP_STATE_BOUND) ||
(dhcp->state == DHCP_STATE_RENEWING) || (dhcp->state == DHCP_STATE_REBINDING)) {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE,
("dhcp_t2_timeout(): must rebind\n"));
/* ... */
dhcp_rebind(netif);
if (((dhcp->t0_timeout - dhcp->lease_used) / 2) >= ((60 + DHCP_COARSE_TIMER_SECS / 2) / DHCP_COARSE_TIMER_SECS)) {
dhcp->t2_rebind_time = (u16_t)((dhcp->t0_timeout - dhcp->lease_used) / 2);
}if (((dhcp->t0_timeout - dhcp->lease_used) / 2) >= ((60 + DHCP_COARSE_TIMER_SECS / 2) / DHCP_COARSE_TIMER_SECS)) { ... }
}if ((dhcp->state == DHCP_STATE_REQUESTING) || (dhcp->state == DHCP_STATE_BOUND) || (dhcp->state == DHCP_STATE_RENEWING) || (dhcp->state == DHCP_STATE_REBINDING)) { ... }
}{ ... }
/* ... */
static void
dhcp_handle_ack(struct netif *netif, struct dhcp_msg *msg_in)
{
struct dhcp *dhcp = netif_dhcp_data(netif);
#if LWIP_DHCP_PROVIDE_DNS_SERVERS || LWIP_DHCP_GET_NTP_SRV
u8_t n;
#endif
#if LWIP_DHCP_GET_NTP_SRV
ip4_addr_t ntp_server_addrs[LWIP_DHCP_MAX_NTP_SERVERS];
#endif
ip4_addr_set_zero(&dhcp->offered_sn_mask);
ip4_addr_set_zero(&dhcp->offered_gw_addr);
#if LWIP_DHCP_BOOTP_FILE
ip4_addr_set_zero(&dhcp->offered_si_addr);
#endif
if (dhcp_option_given(dhcp, DHCP_OPTION_IDX_LEASE_TIME)) {
dhcp->offered_t0_lease = dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_LEASE_TIME);
}if (dhcp_option_given(dhcp, DHCP_OPTION_IDX_LEASE_TIME)) { ... }
if (dhcp_option_given(dhcp, DHCP_OPTION_IDX_T1)) {
dhcp->offered_t1_renew = dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_T1);
}if (dhcp_option_given(dhcp, DHCP_OPTION_IDX_T1)) { ... } else {
dhcp->offered_t1_renew = dhcp->offered_t0_lease / 2;
}else { ... }
if (dhcp_option_given(dhcp, DHCP_OPTION_IDX_T2)) {
dhcp->offered_t2_rebind = dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_T2);
}if (dhcp_option_given(dhcp, DHCP_OPTION_IDX_T2)) { ... } else {
dhcp->offered_t2_rebind = (dhcp->offered_t0_lease * 7U) / 8U;
}else { ... }
ip4_addr_copy(dhcp->offered_ip_addr, msg_in->yiaddr);
#if LWIP_DHCP_BOOTP_FILE
/* ... */
ip4_addr_copy(dhcp->offered_si_addr, msg_in->siaddr);/* ... */
#endif
if (dhcp_option_given(dhcp, DHCP_OPTION_IDX_SUBNET_MASK)) {
ip4_addr_set_u32(&dhcp->offered_sn_mask, lwip_htonl(dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_SUBNET_MASK)));
dhcp->subnet_mask_given = 1;
}if (dhcp_option_given(dhcp, DHCP_OPTION_IDX_SUBNET_MASK)) { ... } else {
dhcp->subnet_mask_given = 0;
}else { ... }
if (dhcp_option_given(dhcp, DHCP_OPTION_IDX_ROUTER)) {
ip4_addr_set_u32(&dhcp->offered_gw_addr, lwip_htonl(dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_ROUTER)));
}if (dhcp_option_given(dhcp, DHCP_OPTION_IDX_ROUTER)) { ... }
#if LWIP_DHCP_GET_NTP_SRV
for (n = 0; (n < LWIP_DHCP_MAX_NTP_SERVERS) && dhcp_option_given(dhcp, DHCP_OPTION_IDX_NTP_SERVER + n); n++) {
ip4_addr_set_u32(&ntp_server_addrs[n], lwip_htonl(dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_NTP_SERVER + n)));
}for (n = 0; (n < LWIP_DHCP_MAX_NTP_SERVERS) && dhcp_option_given(dhcp, DHCP_OPTION_IDX_NTP_SERVER + n); n++) { ... }
dhcp_set_ntp_servers(n, ntp_server_addrs);/* ... */
#endif
#if LWIP_DHCP_PROVIDE_DNS_SERVERS
for (n = 0; (n < LWIP_DHCP_PROVIDE_DNS_SERVERS) && dhcp_option_given(dhcp, DHCP_OPTION_IDX_DNS_SERVER + n); n++) {
ip_addr_t dns_addr;
ip_addr_set_ip4_u32_val(dns_addr, lwip_htonl(dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_DNS_SERVER + n)));
dns_setserver(n, &dns_addr);
}for (n = 0; (n < LWIP_DHCP_PROVIDE_DNS_SERVERS) && dhcp_option_given(dhcp, DHCP_OPTION_IDX_DNS_SERVER + n); n++) { ... }
/* ... */#endif
}{ ... }
/* ... */
void
dhcp_set_struct(struct netif *netif, struct dhcp *dhcp)
{
LWIP_ASSERT_CORE_LOCKED();
LWIP_ASSERT("netif != NULL", netif != NULL);
LWIP_ASSERT("dhcp != NULL", dhcp != NULL);
LWIP_ASSERT("netif already has a struct dhcp set", netif_dhcp_data(netif) == NULL);
memset(dhcp, 0, sizeof(struct dhcp));
netif_set_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_DHCP, dhcp);
}{ ... }
/* ... */
void dhcp_cleanup(struct netif *netif)
{
LWIP_ASSERT_CORE_LOCKED();
LWIP_ASSERT("netif != NULL", netif != NULL);
if (netif_dhcp_data(netif) != NULL) {
mem_free(netif_dhcp_data(netif));
netif_set_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_DHCP, NULL);
}if (netif_dhcp_data(netif) != NULL) { ... }
}{ ... }
/* ... */
err_t
dhcp_start(struct netif *netif)
{
struct dhcp *dhcp;
err_t result;
LWIP_ASSERT_CORE_LOCKED();
LWIP_ERROR("netif != NULL", (netif != NULL), return ERR_ARG;);
LWIP_ERROR("netif is not up, old style port?", netif_is_up(netif), return ERR_ARG;);
dhcp = netif_dhcp_data(netif);
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_start(netif=%p) %c%c%"U16_F"\n", (void *)netif, netif->name[0], netif->name[1], (u16_t)netif->num));
if (netif->mtu < DHCP_MAX_MSG_LEN_MIN_REQUIRED) {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_start(): Cannot use this netif with DHCP: MTU is too small\n"));
return ERR_MEM;
}if (netif->mtu < DHCP_MAX_MSG_LEN_MIN_REQUIRED) { ... }
if (dhcp == NULL) {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_start(): mallocing new DHCP client\n"));
dhcp = (struct dhcp *)mem_malloc(sizeof(struct dhcp));
if (dhcp == NULL) {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_start(): could not allocate dhcp\n"));
return ERR_MEM;
}if (dhcp == NULL) { ... }
netif_set_client_data(netif, LWIP_NETIF_CLIENT_DATA_INDEX_DHCP, dhcp);
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_start(): allocated dhcp"));
}if (dhcp == NULL) { ... } else {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_start(): restarting DHCP configuration\n"));
if (dhcp->pcb_allocated != 0) {
dhcp_dec_pcb_refcount();
}if (dhcp->pcb_allocated != 0) { ... }
}else { ... }
memset(dhcp, 0, sizeof(struct dhcp));
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_start(): starting DHCP configuration\n"));
if (dhcp_inc_pcb_refcount() != ERR_OK) {
return ERR_MEM;
}if (dhcp_inc_pcb_refcount() != ERR_OK) { ... }
dhcp->pcb_allocated = 1;
if (!netif_is_link_up(netif)) {
dhcp_set_state(dhcp, DHCP_STATE_INIT);
return ERR_OK;
}if (!netif_is_link_up(netif)) { ... }
result = dhcp_discover(netif);
if (result != ERR_OK) {
dhcp_release_and_stop(netif);
return ERR_MEM;
}if (result != ERR_OK) { ... }
return result;
}{ ... }
/* ... */
void
dhcp_inform(struct netif *netif)
{
struct dhcp dhcp;
struct pbuf *p_out;
u16_t options_out_len;
LWIP_ASSERT_CORE_LOCKED();
LWIP_ERROR("netif != NULL", (netif != NULL), return;);
if (dhcp_inc_pcb_refcount() != ERR_OK) {
return;
}if (dhcp_inc_pcb_refcount() != ERR_OK) { ... }
memset(&dhcp, 0, sizeof(struct dhcp));
dhcp_set_state(&dhcp, DHCP_STATE_INFORMING);
p_out = dhcp_create_msg(netif, &dhcp, DHCP_INFORM, &options_out_len);
if (p_out != NULL) {
struct dhcp_msg *msg_out = (struct dhcp_msg *)p_out->payload;
options_out_len = dhcp_option(options_out_len, msg_out->options, DHCP_OPTION_MAX_MSG_SIZE, DHCP_OPTION_MAX_MSG_SIZE_LEN);
options_out_len = dhcp_option_short(options_out_len, msg_out->options, DHCP_MAX_MSG_LEN(netif));
LWIP_HOOK_DHCP_APPEND_OPTIONS(netif, &dhcp, DHCP_STATE_INFORMING, msg_out, DHCP_INFORM, &options_out_len);
dhcp_option_trailer(options_out_len, msg_out->options, p_out);
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_inform: INFORMING\n"));
udp_sendto_if(dhcp_pcb, p_out, IP_ADDR_BROADCAST, LWIP_IANA_PORT_DHCP_SERVER, netif);
pbuf_free(p_out);
}if (p_out != NULL) { ... } else {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_SERIOUS, ("dhcp_inform: could not allocate DHCP request\n"));
}else { ... }
dhcp_dec_pcb_refcount();
}{ ... }
/* ... */
void
dhcp_network_changed(struct netif *netif)
{
struct dhcp *dhcp = netif_dhcp_data(netif);
if (!dhcp) {
return;
}if (!dhcp) { ... }
switch (dhcp->state) {
case DHCP_STATE_REBINDING:
case DHCP_STATE_RENEWING:
case DHCP_STATE_BOUND:
case DHCP_STATE_REBOOTING:
dhcp->tries = 0;
dhcp_reboot(netif);
break;case DHCP_STATE_REBOOTING:
case DHCP_STATE_OFF:
break;case DHCP_STATE_OFF:
default:
LWIP_ASSERT("invalid dhcp->state", dhcp->state <= DHCP_STATE_BACKING_OFF);
/* ... */
#if LWIP_DHCP_AUTOIP_COOP
if (dhcp->autoip_coop_state == DHCP_AUTOIP_COOP_STATE_ON) {
autoip_stop(netif);
dhcp->autoip_coop_state = DHCP_AUTOIP_COOP_STATE_OFF;
}if (dhcp->autoip_coop_state == DHCP_AUTOIP_COOP_STATE_ON) { ... }
/* ... */#endif
dhcp->tries = 0;
dhcp_discover(netif);
break;default
}switch (dhcp->state) { ... }
}{ ... }
#if DHCP_DOES_ARP_CHECK
/* ... */
void
dhcp_arp_reply(struct netif *netif, const ip4_addr_t *addr)
{
struct dhcp *dhcp;
LWIP_ERROR("netif != NULL", (netif != NULL), return;);
dhcp = netif_dhcp_data(netif);
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_arp_reply()\n"));
if ((dhcp != NULL) && (dhcp->state == DHCP_STATE_CHECKING)) {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_arp_reply(): CHECKING, arp reply for 0x%08"X32_F"\n",
ip4_addr_get_u32(addr)));
/* ... */
if (ip4_addr_cmp(addr, &dhcp->offered_ip_addr)) {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE | LWIP_DBG_LEVEL_WARNING,
("dhcp_arp_reply(): arp reply matched with offered address, declining\n"));
dhcp_decline(netif);
}if (ip4_addr_cmp(addr, &dhcp->offered_ip_addr)) { ... }
}if ((dhcp != NULL) && (dhcp->state == DHCP_STATE_CHECKING)) { ... }
}{ ... }
/* ... */
static err_t
dhcp_decline(struct netif *netif)
{
struct dhcp *dhcp = netif_dhcp_data(netif);
err_t result;
u16_t msecs;
struct pbuf *p_out;
u16_t options_out_len;
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_decline()\n"));
dhcp_set_state(dhcp, DHCP_STATE_BACKING_OFF);
p_out = dhcp_create_msg(netif, dhcp, DHCP_DECLINE, &options_out_len);
if (p_out != NULL) {
struct dhcp_msg *msg_out = (struct dhcp_msg *)p_out->payload;
options_out_len = dhcp_option(options_out_len, msg_out->options, DHCP_OPTION_REQUESTED_IP, 4);
options_out_len = dhcp_option_long(options_out_len, msg_out->options, lwip_ntohl(ip4_addr_get_u32(&dhcp->offered_ip_addr)));
LWIP_HOOK_DHCP_APPEND_OPTIONS(netif, dhcp, DHCP_STATE_BACKING_OFF, msg_out, DHCP_DECLINE, &options_out_len);
dhcp_option_trailer(options_out_len, msg_out->options, p_out);
result = udp_sendto_if_src(dhcp_pcb, p_out, IP_ADDR_BROADCAST, LWIP_IANA_PORT_DHCP_SERVER, netif, IP4_ADDR_ANY);
pbuf_free(p_out);
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_decline: BACKING OFF\n"));
}if (p_out != NULL) { ... } else {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_SERIOUS,
("dhcp_decline: could not allocate DHCP request\n"));
result = ERR_MEM;
}else { ... }
if (dhcp->tries < 255) {
dhcp->tries++;
}if (dhcp->tries < 255) { ... }
msecs = 10 * 1000;
dhcp->request_timeout = (u16_t)((msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS);
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_decline(): set request timeout %"U16_F" msecs\n", msecs));
return result;
}{ ... }
#endif/* ... */
/* ... */
static err_t
dhcp_discover(struct netif *netif)
{
struct dhcp *dhcp = netif_dhcp_data(netif);
err_t result = ERR_OK;
u16_t msecs;
u8_t i;
struct pbuf *p_out;
u16_t options_out_len;
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_discover()\n"));
ip4_addr_set_any(&dhcp->offered_ip_addr);
dhcp_set_state(dhcp, DHCP_STATE_SELECTING);
p_out = dhcp_create_msg(netif, dhcp, DHCP_DISCOVER, &options_out_len);
if (p_out != NULL) {
struct dhcp_msg *msg_out = (struct dhcp_msg *)p_out->payload;
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_discover: making request\n"));
options_out_len = dhcp_option(options_out_len, msg_out->options, DHCP_OPTION_MAX_MSG_SIZE, DHCP_OPTION_MAX_MSG_SIZE_LEN);
options_out_len = dhcp_option_short(options_out_len, msg_out->options, DHCP_MAX_MSG_LEN(netif));
options_out_len = dhcp_option(options_out_len, msg_out->options, DHCP_OPTION_PARAMETER_REQUEST_LIST, LWIP_ARRAYSIZE(dhcp_discover_request_options));
for (i = 0; i < LWIP_ARRAYSIZE(dhcp_discover_request_options); i++) {
options_out_len = dhcp_option_byte(options_out_len, msg_out->options, dhcp_discover_request_options[i]);
}for (i = 0; i < LWIP_ARRAYSIZE(dhcp_discover_request_options); i++) { ... }
LWIP_HOOK_DHCP_APPEND_OPTIONS(netif, dhcp, DHCP_STATE_SELECTING, msg_out, DHCP_DISCOVER, &options_out_len);
dhcp_option_trailer(options_out_len, msg_out->options, p_out);
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_discover: sendto(DISCOVER, IP_ADDR_BROADCAST, LWIP_IANA_PORT_DHCP_SERVER)\n"));
udp_sendto_if_src(dhcp_pcb, p_out, IP_ADDR_BROADCAST, LWIP_IANA_PORT_DHCP_SERVER, netif, IP4_ADDR_ANY);
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_discover: deleting()ing\n"));
pbuf_free(p_out);
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_discover: SELECTING\n"));
}if (p_out != NULL) { ... } else {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_SERIOUS, ("dhcp_discover: could not allocate DHCP request\n"));
}else { ... }
if (dhcp->tries < 255) {
dhcp->tries++;
}if (dhcp->tries < 255) { ... }
#if LWIP_DHCP_AUTOIP_COOP
if (dhcp->tries >= LWIP_DHCP_AUTOIP_COOP_TRIES && dhcp->autoip_coop_state == DHCP_AUTOIP_COOP_STATE_OFF) {
dhcp->autoip_coop_state = DHCP_AUTOIP_COOP_STATE_ON;
autoip_start(netif);
}if (dhcp->tries >= LWIP_DHCP_AUTOIP_COOP_TRIES && dhcp->autoip_coop_state == DHCP_AUTOIP_COOP_STATE_OFF) { ... }
/* ... */#endif
msecs = (u16_t)((dhcp->tries < 6 ? 1 << dhcp->tries : 60) * 1000);
dhcp->request_timeout = (u16_t)((msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS);
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_discover(): set request timeout %"U16_F" msecs\n", msecs));
return result;
}{ ... }
/* ... */
static void
dhcp_bind(struct netif *netif)
{
u32_t timeout;
struct dhcp *dhcp;
ip4_addr_t sn_mask, gw_addr;
LWIP_ERROR("dhcp_bind: netif != NULL", (netif != NULL), return;);
dhcp = netif_dhcp_data(netif);
LWIP_ERROR("dhcp_bind: dhcp != NULL", (dhcp != NULL), return;);
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_bind(netif=%p) %c%c%"U16_F"\n", (void *)netif, netif->name[0], netif->name[1], (u16_t)netif->num));
dhcp->lease_used = 0;
if (dhcp->offered_t0_lease != 0xffffffffUL) {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_bind(): t0 renewal timer %"U32_F" secs\n", dhcp->offered_t0_lease));
timeout = (dhcp->offered_t0_lease + DHCP_COARSE_TIMER_SECS / 2) / DHCP_COARSE_TIMER_SECS;
if (timeout > 0xffff) {
timeout = 0xffff;
}if (timeout > 0xffff) { ... }
dhcp->t0_timeout = (u16_t)timeout;
if (dhcp->t0_timeout == 0) {
dhcp->t0_timeout = 1;
}if (dhcp->t0_timeout == 0) { ... }
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_bind(): set request timeout %"U32_F" msecs\n", dhcp->offered_t0_lease * 1000));
}if (dhcp->offered_t0_lease != 0xffffffffUL) { ... }
if (dhcp->offered_t1_renew != 0xffffffffUL) {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_bind(): t1 renewal timer %"U32_F" secs\n", dhcp->offered_t1_renew));
timeout = (dhcp->offered_t1_renew + DHCP_COARSE_TIMER_SECS / 2) / DHCP_COARSE_TIMER_SECS;
if (timeout > 0xffff) {
timeout = 0xffff;
}if (timeout > 0xffff) { ... }
dhcp->t1_timeout = (u16_t)timeout;
if (dhcp->t1_timeout == 0) {
dhcp->t1_timeout = 1;
}if (dhcp->t1_timeout == 0) { ... }
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_bind(): set request timeout %"U32_F" msecs\n", dhcp->offered_t1_renew * 1000));
dhcp->t1_renew_time = dhcp->t1_timeout;
}if (dhcp->offered_t1_renew != 0xffffffffUL) { ... }
if (dhcp->offered_t2_rebind != 0xffffffffUL) {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_bind(): t2 rebind timer %"U32_F" secs\n", dhcp->offered_t2_rebind));
timeout = (dhcp->offered_t2_rebind + DHCP_COARSE_TIMER_SECS / 2) / DHCP_COARSE_TIMER_SECS;
if (timeout > 0xffff) {
timeout = 0xffff;
}if (timeout > 0xffff) { ... }
dhcp->t2_timeout = (u16_t)timeout;
if (dhcp->t2_timeout == 0) {
dhcp->t2_timeout = 1;
}if (dhcp->t2_timeout == 0) { ... }
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_bind(): set request timeout %"U32_F" msecs\n", dhcp->offered_t2_rebind * 1000));
dhcp->t2_rebind_time = dhcp->t2_timeout;
}if (dhcp->offered_t2_rebind != 0xffffffffUL) { ... }
if ((dhcp->t1_timeout >= dhcp->t2_timeout) && (dhcp->t2_timeout > 0)) {
dhcp->t1_timeout = 0;
}if ((dhcp->t1_timeout >= dhcp->t2_timeout) && (dhcp->t2_timeout > 0)) { ... }
if (dhcp->subnet_mask_given) {
ip4_addr_copy(sn_mask, dhcp->offered_sn_mask);
}if (dhcp->subnet_mask_given) { ... } else {
u8_t first_octet = ip4_addr1(&dhcp->offered_ip_addr);
if (first_octet <= 127) {
ip4_addr_set_u32(&sn_mask, PP_HTONL(0xff000000UL));
}if (first_octet <= 127) { ... } else if (first_octet >= 192) {
ip4_addr_set_u32(&sn_mask, PP_HTONL(0xffffff00UL));
}else if (first_octet >= 192) { ... } else {
ip4_addr_set_u32(&sn_mask, PP_HTONL(0xffff0000UL));
}else { ... }
}else { ... }
ip4_addr_copy(gw_addr, dhcp->offered_gw_addr);
if (ip4_addr_isany_val(gw_addr)) {
ip4_addr_get_network(&gw_addr, &dhcp->offered_ip_addr, &sn_mask);
ip4_addr_set_u32(&gw_addr, ip4_addr_get_u32(&gw_addr) | PP_HTONL(0x00000001UL));
}if (ip4_addr_isany_val(gw_addr)) { ... }
#if LWIP_DHCP_AUTOIP_COOP
if (dhcp->autoip_coop_state == DHCP_AUTOIP_COOP_STATE_ON) {
autoip_stop(netif);
dhcp->autoip_coop_state = DHCP_AUTOIP_COOP_STATE_OFF;
}if (dhcp->autoip_coop_state == DHCP_AUTOIP_COOP_STATE_ON) { ... }
/* ... */#endif
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_STATE, ("dhcp_bind(): IP: 0x%08"X32_F" SN: 0x%08"X32_F" GW: 0x%08"X32_F"\n",
ip4_addr_get_u32(&dhcp->offered_ip_addr), ip4_addr_get_u32(&sn_mask), ip4_addr_get_u32(&gw_addr)));
/* ... */
dhcp_set_state(dhcp, DHCP_STATE_BOUND);
netif_set_addr(netif, &dhcp->offered_ip_addr, &sn_mask, &gw_addr);
}{ ... }
/* ... */
err_t
dhcp_renew(struct netif *netif)
{
struct dhcp *dhcp = netif_dhcp_data(netif);
err_t result;
u16_t msecs;
u8_t i;
struct pbuf *p_out;
u16_t options_out_len;
LWIP_ASSERT_CORE_LOCKED();
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_renew()\n"));
dhcp_set_state(dhcp, DHCP_STATE_RENEWING);
p_out = dhcp_create_msg(netif, dhcp, DHCP_REQUEST, &options_out_len);
if (p_out != NULL) {
struct dhcp_msg *msg_out = (struct dhcp_msg *)p_out->payload;
options_out_len = dhcp_option(options_out_len, msg_out->options, DHCP_OPTION_MAX_MSG_SIZE, DHCP_OPTION_MAX_MSG_SIZE_LEN);
options_out_len = dhcp_option_short(options_out_len, msg_out->options, DHCP_MAX_MSG_LEN(netif));
options_out_len = dhcp_option(options_out_len, msg_out->options, DHCP_OPTION_PARAMETER_REQUEST_LIST, LWIP_ARRAYSIZE(dhcp_discover_request_options));
for (i = 0; i < LWIP_ARRAYSIZE(dhcp_discover_request_options); i++) {
options_out_len = dhcp_option_byte(options_out_len, msg_out->options, dhcp_discover_request_options[i]);
}for (i = 0; i < LWIP_ARRAYSIZE(dhcp_discover_request_options); i++) { ... }
#if LWIP_NETIF_HOSTNAME
options_out_len = dhcp_option_hostname(options_out_len, msg_out->options, netif);
#endif
LWIP_HOOK_DHCP_APPEND_OPTIONS(netif, dhcp, DHCP_STATE_RENEWING, msg_out, DHCP_REQUEST, &options_out_len);
dhcp_option_trailer(options_out_len, msg_out->options, p_out);
result = udp_sendto_if(dhcp_pcb, p_out, &dhcp->server_ip_addr, LWIP_IANA_PORT_DHCP_SERVER, netif);
pbuf_free(p_out);
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_renew: RENEWING\n"));
}if (p_out != NULL) { ... } else {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_SERIOUS, ("dhcp_renew: could not allocate DHCP request\n"));
result = ERR_MEM;
}else { ... }
if (dhcp->tries < 255) {
dhcp->tries++;
}if (dhcp->tries < 255) { ... }
msecs = (u16_t)(dhcp->tries < 10 ? dhcp->tries * 2000 : 20 * 1000);
dhcp->request_timeout = (u16_t)((msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS);
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_renew(): set request timeout %"U16_F" msecs\n", msecs));
return result;
}{ ... }
/* ... */
static err_t
dhcp_rebind(struct netif *netif)
{
struct dhcp *dhcp = netif_dhcp_data(netif);
err_t result;
u16_t msecs;
u8_t i;
struct pbuf *p_out;
u16_t options_out_len;
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_rebind()\n"));
dhcp_set_state(dhcp, DHCP_STATE_REBINDING);
p_out = dhcp_create_msg(netif, dhcp, DHCP_REQUEST, &options_out_len);
if (p_out != NULL) {
struct dhcp_msg *msg_out = (struct dhcp_msg *)p_out->payload;
options_out_len = dhcp_option(options_out_len, msg_out->options, DHCP_OPTION_MAX_MSG_SIZE, DHCP_OPTION_MAX_MSG_SIZE_LEN);
options_out_len = dhcp_option_short(options_out_len, msg_out->options, DHCP_MAX_MSG_LEN(netif));
options_out_len = dhcp_option(options_out_len, msg_out->options, DHCP_OPTION_PARAMETER_REQUEST_LIST, LWIP_ARRAYSIZE(dhcp_discover_request_options));
for (i = 0; i < LWIP_ARRAYSIZE(dhcp_discover_request_options); i++) {
options_out_len = dhcp_option_byte(options_out_len, msg_out->options, dhcp_discover_request_options[i]);
}for (i = 0; i < LWIP_ARRAYSIZE(dhcp_discover_request_options); i++) { ... }
#if LWIP_NETIF_HOSTNAME
options_out_len = dhcp_option_hostname(options_out_len, msg_out->options, netif);
#endif
LWIP_HOOK_DHCP_APPEND_OPTIONS(netif, dhcp, DHCP_STATE_REBINDING, msg_out, DHCP_DISCOVER, &options_out_len);
dhcp_option_trailer(options_out_len, msg_out->options, p_out);
result = udp_sendto_if(dhcp_pcb, p_out, IP_ADDR_BROADCAST, LWIP_IANA_PORT_DHCP_SERVER, netif);
pbuf_free(p_out);
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_rebind: REBINDING\n"));
}if (p_out != NULL) { ... } else {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_SERIOUS, ("dhcp_rebind: could not allocate DHCP request\n"));
result = ERR_MEM;
}else { ... }
if (dhcp->tries < 255) {
dhcp->tries++;
}if (dhcp->tries < 255) { ... }
msecs = (u16_t)(dhcp->tries < 10 ? dhcp->tries * 1000 : 10 * 1000);
dhcp->request_timeout = (u16_t)((msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS);
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_rebind(): set request timeout %"U16_F" msecs\n", msecs));
return result;
}{ ... }
/* ... */
static err_t
dhcp_reboot(struct netif *netif)
{
struct dhcp *dhcp = netif_dhcp_data(netif);
err_t result;
u16_t msecs;
u8_t i;
struct pbuf *p_out;
u16_t options_out_len;
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_reboot()\n"));
dhcp_set_state(dhcp, DHCP_STATE_REBOOTING);
p_out = dhcp_create_msg(netif, dhcp, DHCP_REQUEST, &options_out_len);
if (p_out != NULL) {
struct dhcp_msg *msg_out = (struct dhcp_msg *)p_out->payload;
options_out_len = dhcp_option(options_out_len, msg_out->options, DHCP_OPTION_MAX_MSG_SIZE, DHCP_OPTION_MAX_MSG_SIZE_LEN);
options_out_len = dhcp_option_short(options_out_len, msg_out->options, DHCP_MAX_MSG_LEN_MIN_REQUIRED);
options_out_len = dhcp_option(options_out_len, msg_out->options, DHCP_OPTION_REQUESTED_IP, 4);
options_out_len = dhcp_option_long(options_out_len, msg_out->options, lwip_ntohl(ip4_addr_get_u32(&dhcp->offered_ip_addr)));
options_out_len = dhcp_option(options_out_len, msg_out->options, DHCP_OPTION_PARAMETER_REQUEST_LIST, LWIP_ARRAYSIZE(dhcp_discover_request_options));
for (i = 0; i < LWIP_ARRAYSIZE(dhcp_discover_request_options); i++) {
options_out_len = dhcp_option_byte(options_out_len, msg_out->options, dhcp_discover_request_options[i]);
}for (i = 0; i < LWIP_ARRAYSIZE(dhcp_discover_request_options); i++) { ... }
#if LWIP_NETIF_HOSTNAME
options_out_len = dhcp_option_hostname(options_out_len, msg_out->options, netif);
#endif
LWIP_HOOK_DHCP_APPEND_OPTIONS(netif, dhcp, DHCP_STATE_REBOOTING, msg_out, DHCP_REQUEST, &options_out_len);
dhcp_option_trailer(options_out_len, msg_out->options, p_out);
result = udp_sendto_if(dhcp_pcb, p_out, IP_ADDR_BROADCAST, LWIP_IANA_PORT_DHCP_SERVER, netif);
pbuf_free(p_out);
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_reboot: REBOOTING\n"));
}if (p_out != NULL) { ... } else {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_SERIOUS, ("dhcp_reboot: could not allocate DHCP request\n"));
result = ERR_MEM;
}else { ... }
if (dhcp->tries < 255) {
dhcp->tries++;
}if (dhcp->tries < 255) { ... }
msecs = (u16_t)(dhcp->tries < 10 ? dhcp->tries * 1000 : 10 * 1000);
dhcp->request_timeout = (u16_t)((msecs + DHCP_FINE_TIMER_MSECS - 1) / DHCP_FINE_TIMER_MSECS);
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_reboot(): set request timeout %"U16_F" msecs\n", msecs));
return result;
}{ ... }
/* ... */
void
dhcp_release_and_stop(struct netif *netif)
{
struct dhcp *dhcp = netif_dhcp_data(netif);
ip_addr_t server_ip_addr;
LWIP_ASSERT_CORE_LOCKED();
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_release_and_stop()\n"));
if (dhcp == NULL) {
return;
}if (dhcp == NULL) { ... }
if (dhcp->state == DHCP_STATE_OFF) {
return;
}if (dhcp->state == DHCP_STATE_OFF) { ... }
ip_addr_copy(server_ip_addr, dhcp->server_ip_addr);
ip_addr_set_zero_ip4(&dhcp->server_ip_addr);
ip4_addr_set_zero(&dhcp->offered_ip_addr);
ip4_addr_set_zero(&dhcp->offered_sn_mask);
ip4_addr_set_zero(&dhcp->offered_gw_addr);
#if LWIP_DHCP_BOOTP_FILE
ip4_addr_set_zero(&dhcp->offered_si_addr);
#endif
dhcp->offered_t0_lease = dhcp->offered_t1_renew = dhcp->offered_t2_rebind = 0;
dhcp->t1_renew_time = dhcp->t2_rebind_time = dhcp->lease_used = dhcp->t0_timeout = 0;
if (dhcp_supplied_address(netif)) {
struct pbuf *p_out;
u16_t options_out_len;
p_out = dhcp_create_msg(netif, dhcp, DHCP_RELEASE, &options_out_len);
if (p_out != NULL) {
struct dhcp_msg *msg_out = (struct dhcp_msg *)p_out->payload;
options_out_len = dhcp_option(options_out_len, msg_out->options, DHCP_OPTION_SERVER_ID, 4);
options_out_len = dhcp_option_long(options_out_len, msg_out->options, lwip_ntohl(ip4_addr_get_u32(ip_2_ip4(&server_ip_addr))));
LWIP_HOOK_DHCP_APPEND_OPTIONS(netif, dhcp, dhcp->state, msg_out, DHCP_RELEASE, &options_out_len);
dhcp_option_trailer(options_out_len, msg_out->options, p_out);
udp_sendto_if(dhcp_pcb, p_out, &server_ip_addr, LWIP_IANA_PORT_DHCP_SERVER, netif);
pbuf_free(p_out);
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_release: RELEASED, DHCP_STATE_OFF\n"));
}if (p_out != NULL) { ... } else {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_SERIOUS, ("dhcp_release: could not allocate DHCP request\n"));
}else { ... }
}if (dhcp_supplied_address(netif)) { ... }
netif_set_addr(netif, IP4_ADDR_ANY4, IP4_ADDR_ANY4, IP4_ADDR_ANY4);
#if LWIP_DHCP_AUTOIP_COOP
if (dhcp->autoip_coop_state == DHCP_AUTOIP_COOP_STATE_ON) {
autoip_stop(netif);
dhcp->autoip_coop_state = DHCP_AUTOIP_COOP_STATE_OFF;
}if (dhcp->autoip_coop_state == DHCP_AUTOIP_COOP_STATE_ON) { ... }
/* ... */#endif
dhcp_set_state(dhcp, DHCP_STATE_OFF);
if (dhcp->pcb_allocated != 0) {
dhcp_dec_pcb_refcount();
dhcp->pcb_allocated = 0;
}if (dhcp->pcb_allocated != 0) { ... }
}{ ... }
/* ... */
err_t
dhcp_release(struct netif *netif)
{
dhcp_release_and_stop(netif);
return ERR_OK;
}{ ... }
/* ... */
void
dhcp_stop(struct netif *netif)
{
dhcp_release_and_stop(netif);
}{ ... }
/* ... */
static void
dhcp_set_state(struct dhcp *dhcp, u8_t new_state)
{
if (new_state != dhcp->state) {
dhcp->state = new_state;
dhcp->tries = 0;
dhcp->request_timeout = 0;
}if (new_state != dhcp->state) { ... }
}{ ... }
/* ... */
static u16_t
dhcp_option(u16_t options_out_len, u8_t *options, u8_t option_type, u8_t option_len)
{
LWIP_ASSERT("dhcp_option: options_out_len + 2 + option_len <= DHCP_OPTIONS_LEN", options_out_len + 2U + option_len <= DHCP_OPTIONS_LEN);
options[options_out_len++] = option_type;
options[options_out_len++] = option_len;
return options_out_len;
}{ ... }
/* ... */
static u16_t
dhcp_option_byte(u16_t options_out_len, u8_t *options, u8_t value)
{
LWIP_ASSERT("dhcp_option_byte: options_out_len < DHCP_OPTIONS_LEN", options_out_len < DHCP_OPTIONS_LEN);
options[options_out_len++] = value;
return options_out_len;
}{ ... }
static u16_t
dhcp_option_short(u16_t options_out_len, u8_t *options, u16_t value)
{
LWIP_ASSERT("dhcp_option_short: options_out_len + 2 <= DHCP_OPTIONS_LEN", options_out_len + 2U <= DHCP_OPTIONS_LEN);
options[options_out_len++] = (u8_t)((value & 0xff00U) >> 8);
options[options_out_len++] = (u8_t) (value & 0x00ffU);
return options_out_len;
}{ ... }
static u16_t
dhcp_option_long(u16_t options_out_len, u8_t *options, u32_t value)
{
LWIP_ASSERT("dhcp_option_long: options_out_len + 4 <= DHCP_OPTIONS_LEN", options_out_len + 4U <= DHCP_OPTIONS_LEN);
options[options_out_len++] = (u8_t)((value & 0xff000000UL) >> 24);
options[options_out_len++] = (u8_t)((value & 0x00ff0000UL) >> 16);
options[options_out_len++] = (u8_t)((value & 0x0000ff00UL) >> 8);
options[options_out_len++] = (u8_t)((value & 0x000000ffUL));
return options_out_len;
}{ ... }
#if LWIP_NETIF_HOSTNAME
static u16_t
dhcp_option_hostname(u16_t options_out_len, u8_t *options, struct netif *netif)
{
if (netif->hostname != NULL) {
size_t namelen = strlen(netif->hostname);
if (namelen > 0) {
size_t len;
const char *p = netif->hostname;
/* ... */
size_t available = DHCP_OPTIONS_LEN - options_out_len - 3;
LWIP_ASSERT("DHCP: hostname is too long!", namelen <= available);
len = LWIP_MIN(namelen, available);
LWIP_ASSERT("DHCP: hostname is too long!", len <= 0xFF);
options_out_len = dhcp_option(options_out_len, options, DHCP_OPTION_HOSTNAME, (u8_t)len);
while (len--) {
options_out_len = dhcp_option_byte(options_out_len, options, *p++);
}while (len--) { ... }
}if (namelen > 0) { ... }
}if (netif->hostname != NULL) { ... }
return options_out_len;
}dhcp_option_hostname (u16_t options_out_len, u8_t *options, struct netif *netif) { ... }
/* ... */#endif
/* ... */
static err_t
dhcp_parse_reply(struct pbuf *p, struct dhcp *dhcp)
{
u8_t *options;
u16_t offset;
u16_t offset_max;
u16_t options_idx;
u16_t options_idx_max;
struct pbuf *q;
int parse_file_as_options = 0;
int parse_sname_as_options = 0;
struct dhcp_msg *msg_in;
#if LWIP_DHCP_BOOTP_FILE
int file_overloaded = 0;
#endif
LWIP_UNUSED_ARG(dhcp);
dhcp_clear_all_options(dhcp);
if (p->len < DHCP_SNAME_OFS) {
return ERR_BUF;
}if (p->len < DHCP_SNAME_OFS) { ... }
msg_in = (struct dhcp_msg *)p->payload;
#if LWIP_DHCP_BOOTP_FILE
dhcp->boot_file_name[0] = 0;/* ... */
#endif
options_idx = DHCP_OPTIONS_OFS;
options_idx_max = p->tot_len;
again:
q = p;
while ((q != NULL) && (options_idx >= q->len)) {
options_idx = (u16_t)(options_idx - q->len);
options_idx_max = (u16_t)(options_idx_max - q->len);
q = q->next;
}while ((q != NULL) && (options_idx >= q->len)) { ... }
if (q == NULL) {
return ERR_BUF;
}if (q == NULL) { ... }
offset = options_idx;
offset_max = options_idx_max;
options = (u8_t *)q->payload;
while ((q != NULL) && (offset < offset_max) && (options[offset] != DHCP_OPTION_END)) {
u8_t op = options[offset];
u8_t len;
u8_t decode_len = 0;
int decode_idx = -1;
u16_t val_offset = (u16_t)(offset + 2);
if (val_offset < offset) {
return ERR_BUF;
}if (val_offset < offset) { ... }
if ((offset + 1) < q->len) {
len = options[offset + 1];
}if ((offset + 1) < q->len) { ... } else {
len = (q->next != NULL ? ((u8_t *)q->next->payload)[0] : 0);
}else { ... }
decode_len = len;
switch (op) {
case (DHCP_OPTION_PAD):
decode_len = len = 0;
break;case (DHCP_OPTION_PAD):
case (DHCP_OPTION_SUBNET_MASK):
LWIP_ERROR("len == 4", len == 4, return ERR_VAL;);
decode_idx = DHCP_OPTION_IDX_SUBNET_MASK;
break;case (DHCP_OPTION_SUBNET_MASK):
case (DHCP_OPTION_ROUTER):
decode_len = 4;
LWIP_ERROR("len >= decode_len", len >= decode_len, return ERR_VAL;);
decode_idx = DHCP_OPTION_IDX_ROUTER;
break;
#if LWIP_DHCP_PROVIDE_DNS_SERVERScase (DHCP_OPTION_ROUTER):
case (DHCP_OPTION_DNS_SERVER):
LWIP_ERROR("len %% 4 == 0", len % 4 == 0, return ERR_VAL;);
decode_len = LWIP_MIN(len, 4 * DNS_MAX_SERVERS);
LWIP_ERROR("len >= decode_len", len >= decode_len, return ERR_VAL;);
decode_idx = DHCP_OPTION_IDX_DNS_SERVER;
break;/* ... */
#endif case (DHCP_OPTION_DNS_SERVER):
case (DHCP_OPTION_LEASE_TIME):
LWIP_ERROR("len == 4", len == 4, return ERR_VAL;);
decode_idx = DHCP_OPTION_IDX_LEASE_TIME;
break;
#if LWIP_DHCP_GET_NTP_SRVcase (DHCP_OPTION_LEASE_TIME):
case (DHCP_OPTION_NTP):
LWIP_ERROR("len %% 4 == 0", len % 4 == 0, return ERR_VAL;);
decode_len = LWIP_MIN(len, 4 * LWIP_DHCP_MAX_NTP_SERVERS);
LWIP_ERROR("len >= decode_len", len >= decode_len, return ERR_VAL;);
decode_idx = DHCP_OPTION_IDX_NTP_SERVER;
break;/* ... */
#endif case (DHCP_OPTION_NTP):
case (DHCP_OPTION_OVERLOAD):
LWIP_ERROR("len == 1", len == 1, return ERR_VAL;);
LWIP_ERROR("overload in file/sname", options_idx == DHCP_OPTIONS_OFS, return ERR_VAL;);
decode_idx = DHCP_OPTION_IDX_OVERLOAD;
break;case (DHCP_OPTION_OVERLOAD):
case (DHCP_OPTION_MESSAGE_TYPE):
LWIP_ERROR("len == 1", len == 1, return ERR_VAL;);
decode_idx = DHCP_OPTION_IDX_MSG_TYPE;
break;case (DHCP_OPTION_MESSAGE_TYPE):
case (DHCP_OPTION_SERVER_ID):
LWIP_ERROR("len == 4", len == 4, return ERR_VAL;);
decode_idx = DHCP_OPTION_IDX_SERVER_ID;
break;case (DHCP_OPTION_SERVER_ID):
case (DHCP_OPTION_T1):
LWIP_ERROR("len == 4", len == 4, return ERR_VAL;);
decode_idx = DHCP_OPTION_IDX_T1;
break;case (DHCP_OPTION_T1):
case (DHCP_OPTION_T2):
LWIP_ERROR("len == 4", len == 4, return ERR_VAL;);
decode_idx = DHCP_OPTION_IDX_T2;
break;case (DHCP_OPTION_T2):
default:
decode_len = 0;
LWIP_DEBUGF(DHCP_DEBUG, ("skipping option %"U16_F" in options\n", (u16_t)op));
LWIP_HOOK_DHCP_PARSE_OPTION(ip_current_netif(), dhcp, dhcp->state, msg_in,
dhcp_option_given(dhcp, DHCP_OPTION_IDX_MSG_TYPE) ? (u8_t)dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_MSG_TYPE) : 0,
op, len, q, val_offset);
break;default
}switch (op) { ... }
if (op == DHCP_OPTION_PAD) {
offset++;
}if (op == DHCP_OPTION_PAD) { ... } else {
if (offset + len + 2 > 0xFFFF) {
return ERR_BUF;
}if (offset + len + 2 > 0xFFFF) { ... }
offset = (u16_t)(offset + len + 2);
if (decode_len > 0) {
u32_t value = 0;
u16_t copy_len;
decode_next:
LWIP_ASSERT("check decode_idx", decode_idx >= 0 && decode_idx < DHCP_OPTION_IDX_MAX);
if (!dhcp_option_given(dhcp, decode_idx)) {
copy_len = LWIP_MIN(decode_len, 4);
if (pbuf_copy_partial(q, &value, copy_len, val_offset) != copy_len) {
return ERR_BUF;
}if (pbuf_copy_partial(q, &value, copy_len, val_offset) != copy_len) { ... }
if (decode_len > 4) {
u16_t next_val_offset;
LWIP_ERROR("decode_len %% 4 == 0", decode_len % 4 == 0, return ERR_VAL;);
dhcp_got_option(dhcp, decode_idx);
dhcp_set_option_value(dhcp, decode_idx, lwip_htonl(value));
decode_len = (u8_t)(decode_len - 4);
next_val_offset = (u16_t)(val_offset + 4);
if (next_val_offset < val_offset) {
return ERR_BUF;
}if (next_val_offset < val_offset) { ... }
val_offset = next_val_offset;
decode_idx++;
goto decode_next;
}if (decode_len > 4) { ... } else if (decode_len == 4) {
value = lwip_ntohl(value);
}else if (decode_len == 4) { ... } else {
LWIP_ERROR("invalid decode_len", decode_len == 1, return ERR_VAL;);
value = ((u8_t *)&value)[0];
}else { ... }
dhcp_got_option(dhcp, decode_idx);
dhcp_set_option_value(dhcp, decode_idx, value);
}if (!dhcp_option_given(dhcp, decode_idx)) { ... }
}if (decode_len > 0) { ... }
}else { ... }
if (offset >= q->len) {
offset = (u16_t)(offset - q->len);
offset_max = (u16_t)(offset_max - q->len);
if (offset < offset_max) {
q = q->next;
LWIP_ERROR("next pbuf was null", q != NULL, return ERR_VAL;);
options = (u8_t *)q->payload;
}if (offset < offset_max) { ... } else {
return ERR_BUF;
}else { ... }
}if (offset >= q->len) { ... }
}while ((q != NULL) && (offset < offset_max) && (options[offset] != DHCP_OPTION_END)) { ... }
if (dhcp_option_given(dhcp, DHCP_OPTION_IDX_OVERLOAD)) {
u32_t overload = dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_OVERLOAD);
dhcp_clear_option(dhcp, DHCP_OPTION_IDX_OVERLOAD);
if (overload == DHCP_OVERLOAD_FILE) {
parse_file_as_options = 1;
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("overloaded file field\n"));
}if (overload == DHCP_OVERLOAD_FILE) { ... } else if (overload == DHCP_OVERLOAD_SNAME) {
parse_sname_as_options = 1;
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("overloaded sname field\n"));
}else if (overload == DHCP_OVERLOAD_SNAME) { ... } else if (overload == DHCP_OVERLOAD_SNAME_FILE) {
parse_sname_as_options = 1;
parse_file_as_options = 1;
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("overloaded sname and file field\n"));
}else if (overload == DHCP_OVERLOAD_SNAME_FILE) { ... } else {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("invalid overload option: %d\n", (int)overload));
}else { ... }
}if (dhcp_option_given(dhcp, DHCP_OPTION_IDX_OVERLOAD)) { ... }
if (parse_file_as_options) {
parse_file_as_options = 0;
options_idx = DHCP_FILE_OFS;
options_idx_max = DHCP_FILE_OFS + DHCP_FILE_LEN;
#if LWIP_DHCP_BOOTP_FILE
file_overloaded = 1;
#endif
goto again;
}if (parse_file_as_options) { ... } else if (parse_sname_as_options) {
parse_sname_as_options = 0;
options_idx = DHCP_SNAME_OFS;
options_idx_max = DHCP_SNAME_OFS + DHCP_SNAME_LEN;
goto again;
}else if (parse_sname_as_options) { ... }
#if LWIP_DHCP_BOOTP_FILE
if (!file_overloaded) {
if (dhcp_option_given(dhcp, DHCP_OPTION_IDX_MSG_TYPE) &&
(dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_MSG_TYPE) == DHCP_ACK))
if (pbuf_copy_partial(p, dhcp->boot_file_name, DHCP_FILE_LEN-1, DHCP_FILE_OFS) != (DHCP_FILE_LEN-1)) {
return ERR_BUF;
}if (pbuf_copy_partial(p, dhcp->boot_file_name, DHCP_FILE_LEN-1, DHCP_FILE_OFS) != (DHCP_FILE_LEN-1)) { ... }
dhcp->boot_file_name[DHCP_FILE_LEN-1] = 0;
}if (!file_overloaded) { ... }
/* ... */#endif
return ERR_OK;
}{ ... }
/* ... */
static void
dhcp_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, u16_t port)
{
struct netif *netif = ip_current_input_netif();
struct dhcp *dhcp = netif_dhcp_data(netif);
struct dhcp_msg *reply_msg = (struct dhcp_msg *)p->payload;
u8_t msg_type;
u8_t i;
struct dhcp_msg *msg_in;
LWIP_UNUSED_ARG(arg);
if ((dhcp == NULL) || (dhcp->pcb_allocated == 0)) {
goto free_pbuf_and_return;
}if ((dhcp == NULL) || (dhcp->pcb_allocated == 0)) { ... }
LWIP_ASSERT("invalid server address type", IP_IS_V4(addr));
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_recv(pbuf = %p) from DHCP server %"U16_F".%"U16_F".%"U16_F".%"U16_F" port %"U16_F"\n", (void *)p,
ip4_addr1_16(ip_2_ip4(addr)), ip4_addr2_16(ip_2_ip4(addr)), ip4_addr3_16(ip_2_ip4(addr)), ip4_addr4_16(ip_2_ip4(addr)), port));
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("pbuf->len = %"U16_F"\n", p->len));
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("pbuf->tot_len = %"U16_F"\n", p->tot_len));
LWIP_UNUSED_ARG(pcb);
LWIP_UNUSED_ARG(addr);
LWIP_UNUSED_ARG(port);
if (p->len < DHCP_MIN_REPLY_LEN) {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_WARNING, ("DHCP reply message or pbuf too short\n"));
goto free_pbuf_and_return;
}if (p->len < DHCP_MIN_REPLY_LEN) { ... }
if (reply_msg->op != DHCP_BOOTREPLY) {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_WARNING, ("not a DHCP reply message, but type %"U16_F"\n", (u16_t)reply_msg->op));
goto free_pbuf_and_return;
}if (reply_msg->op != DHCP_BOOTREPLY) { ... }
for (i = 0; i < netif->hwaddr_len && i < LWIP_MIN(DHCP_CHADDR_LEN, NETIF_MAX_HWADDR_LEN); i++) {
if (netif->hwaddr[i] != reply_msg->chaddr[i]) {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_WARNING,
("netif->hwaddr[%"U16_F"]==%02"X16_F" != reply_msg->chaddr[%"U16_F"]==%02"X16_F"\n",
(u16_t)i, (u16_t)netif->hwaddr[i], (u16_t)i, (u16_t)reply_msg->chaddr[i]));
goto free_pbuf_and_return;
}if (netif->hwaddr[i] != reply_msg->chaddr[i]) { ... }
}for (i = 0; i < netif->hwaddr_len && i < LWIP_MIN(DHCP_CHADDR_LEN, NETIF_MAX_HWADDR_LEN); i++) { ... }
if (lwip_ntohl(reply_msg->xid) != dhcp->xid) {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_WARNING,
("transaction id mismatch reply_msg->xid(%"X32_F")!=dhcp->xid(%"X32_F")\n", lwip_ntohl(reply_msg->xid), dhcp->xid));
goto free_pbuf_and_return;
}if (lwip_ntohl(reply_msg->xid) != dhcp->xid) { ... }
if (dhcp_parse_reply(p, dhcp) != ERR_OK) {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_SERIOUS,
("problem unfolding DHCP message - too short on memory?\n"));
goto free_pbuf_and_return;
}if (dhcp_parse_reply(p, dhcp) != ERR_OK) { ... }
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("searching DHCP_OPTION_MESSAGE_TYPE\n"));
if (!dhcp_option_given(dhcp, DHCP_OPTION_IDX_MSG_TYPE)) {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_WARNING, ("DHCP_OPTION_MESSAGE_TYPE option not found\n"));
goto free_pbuf_and_return;
}if (!dhcp_option_given(dhcp, DHCP_OPTION_IDX_MSG_TYPE)) { ... }
msg_in = (struct dhcp_msg *)p->payload;
msg_type = (u8_t)dhcp_get_option_value(dhcp, DHCP_OPTION_IDX_MSG_TYPE);
if (msg_type == DHCP_ACK) {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("DHCP_ACK received\n"));
if (dhcp->state == DHCP_STATE_REQUESTING) {
dhcp_handle_ack(netif, msg_in);
#if DHCP_DOES_ARP_CHECK
if ((netif->flags & NETIF_FLAG_ETHARP) != 0) {
dhcp_check(netif);
}if ((netif->flags & NETIF_FLAG_ETHARP) != 0) { ... } else {
dhcp_bind(netif);
}else { ... }
/* ... */#else
dhcp_bind(netif);/* ... */
#endif
}if (dhcp->state == DHCP_STATE_REQUESTING) { ... }
else if ((dhcp->state == DHCP_STATE_REBOOTING) || (dhcp->state == DHCP_STATE_REBINDING) ||
(dhcp->state == DHCP_STATE_RENEWING)) {
dhcp_handle_ack(netif, msg_in);
dhcp_bind(netif);
}else if ((dhcp->state == DHCP_STATE_REBOOTING) || (dhcp->state == DHCP_STATE_REBINDING) || (dhcp->state == DHCP_STATE_RENEWING)) { ... }
}if (msg_type == DHCP_ACK) { ... }
else if ((msg_type == DHCP_NAK) &&
((dhcp->state == DHCP_STATE_REBOOTING) || (dhcp->state == DHCP_STATE_REQUESTING) ||
(dhcp->state == DHCP_STATE_REBINDING) || (dhcp->state == DHCP_STATE_RENEWING ))) {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("DHCP_NAK received\n"));
dhcp_handle_nak(netif);
}else if ((msg_type == DHCP_NAK) && ((dhcp->state == DHCP_STATE_REBOOTING) || (dhcp->state == DHCP_STATE_REQUESTING) || (dhcp->state == DHCP_STATE_REBINDING) || (dhcp->state == DHCP_STATE_RENEWING ))) { ... }
else if ((msg_type == DHCP_OFFER) && (dhcp->state == DHCP_STATE_SELECTING)) {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("DHCP_OFFER received in DHCP_STATE_SELECTING state\n"));
dhcp_handle_offer(netif, msg_in);
}else if ((msg_type == DHCP_OFFER) && (dhcp->state == DHCP_STATE_SELECTING)) { ... }
free_pbuf_and_return:
pbuf_free(p);
}{ ... }
/* ... */
static struct pbuf *
dhcp_create_msg(struct netif *netif, struct dhcp *dhcp, u8_t message_type, u16_t *options_out_len)
{
u16_t i;
struct pbuf *p_out;
struct dhcp_msg *msg_out;
u16_t options_out_len_loc;
#ifndef DHCP_GLOBAL_XID
/* ... */
#if DHCP_CREATE_RAND_XID && defined(LWIP_RAND)
static u32_t xid;
#else
static u32_t xid = 0xABCD0000;
#endif /* ... */
#else
if (!xid_initialised) {
xid = DHCP_GLOBAL_XID;
xid_initialised = !xid_initialised;
}if (!xid_initialised) { ... }
/* ... */#endif
LWIP_ERROR("dhcp_create_msg: netif != NULL", (netif != NULL), return NULL;);
LWIP_ERROR("dhcp_create_msg: dhcp != NULL", (dhcp != NULL), return NULL;);
p_out = pbuf_alloc(PBUF_TRANSPORT, sizeof(struct dhcp_msg), PBUF_RAM);
if (p_out == NULL) {
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_LEVEL_SERIOUS,
("dhcp_create_msg(): could not allocate pbuf\n"));
return NULL;
}if (p_out == NULL) { ... }
LWIP_ASSERT("dhcp_create_msg: check that first pbuf can hold struct dhcp_msg",
(p_out->len >= sizeof(struct dhcp_msg)));
if ((message_type != DHCP_REQUEST) || (dhcp->state == DHCP_STATE_REBOOTING)) {
if (dhcp->tries == 0) {
#if DHCP_CREATE_RAND_XID && defined(LWIP_RAND)
xid = LWIP_RAND();
#else
xid++;
#endif
}if (dhcp->tries == 0) { ... }
dhcp->xid = xid;
}if ((message_type != DHCP_REQUEST) || (dhcp->state == DHCP_STATE_REBOOTING)) { ... }
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE,
("transaction id xid(%"X32_F")\n", xid));
msg_out = (struct dhcp_msg *)p_out->payload;
memset(msg_out, 0, sizeof(struct dhcp_msg));
msg_out->op = DHCP_BOOTREQUEST;
msg_out->htype = LWIP_IANA_HWTYPE_ETHERNET;
msg_out->hlen = netif->hwaddr_len;
msg_out->xid = lwip_htonl(dhcp->xid);
/* ... */
if ((message_type == DHCP_INFORM) || (message_type == DHCP_DECLINE) || (message_type == DHCP_RELEASE) ||
((message_type == DHCP_REQUEST) &&
((dhcp->state == DHCP_STATE_RENEWING) || dhcp->state == DHCP_STATE_REBINDING))) {
ip4_addr_copy(msg_out->ciaddr, *netif_ip4_addr(netif));
}if ((message_type == DHCP_INFORM) || (message_type == DHCP_DECLINE) || (message_type == DHCP_RELEASE) || ((message_type == DHCP_REQUEST) && /* DHCP_STATE_BOUND not used for sending! */ ((dhcp->state == DHCP_STATE_RENEWING) || dhcp->state == DHCP_STATE_REBINDING))) { ... }
for (i = 0; i < LWIP_MIN(DHCP_CHADDR_LEN, NETIF_MAX_HWADDR_LEN); i++) {
msg_out->chaddr[i] = netif->hwaddr[i];
}for (i = 0; i < LWIP_MIN(DHCP_CHADDR_LEN, NETIF_MAX_HWADDR_LEN); i++) { ... }
msg_out->cookie = PP_HTONL(DHCP_MAGIC_COOKIE);
options_out_len_loc = dhcp_option(0, msg_out->options, DHCP_OPTION_MESSAGE_TYPE, DHCP_OPTION_MESSAGE_TYPE_LEN);
options_out_len_loc = dhcp_option_byte(options_out_len_loc, msg_out->options, message_type);
if (options_out_len) {
*options_out_len = options_out_len_loc;
}if (options_out_len) { ... }
return p_out;
}{ ... }
/* ... */
static void
dhcp_option_trailer(u16_t options_out_len, u8_t *options, struct pbuf *p_out)
{
options[options_out_len++] = DHCP_OPTION_END;
while (((options_out_len < DHCP_MIN_OPTIONS_LEN) || (options_out_len & 3)) &&
(options_out_len < DHCP_OPTIONS_LEN)) {
options[options_out_len++] = 0;
}while (((options_out_len < DHCP_MIN_OPTIONS_LEN) || (options_out_len & 3)) && (options_out_len < DHCP_OPTIONS_LEN)) { ... }
pbuf_realloc(p_out, (u16_t)(sizeof(struct dhcp_msg) - DHCP_OPTIONS_LEN + options_out_len));
}{ ... }
/* ... */
u8_t
dhcp_supplied_address(const struct netif *netif)
{
if ((netif != NULL) && (netif_dhcp_data(netif) != NULL)) {
struct dhcp *dhcp = netif_dhcp_data(netif);
return (dhcp->state == DHCP_STATE_BOUND) || (dhcp->state == DHCP_STATE_RENEWING) ||
(dhcp->state == DHCP_STATE_REBINDING);
}if ((netif != NULL) && (netif_dhcp_data(netif) != NULL)) { ... }
return 0;
}{ ... }
/* ... */#endif