dhcp_server.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  1. /*
  2. * File : dhcp_server.c
  3. * A simple DHCP server implementation
  4. *
  5. * COPYRIGHT (C) 2011-2018, Shanghai Real-Thread Technology Co., Ltd
  6. * http://www.rt-thread.com
  7. * All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without modification,
  10. * are permitted provided that the following conditions are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright notice,
  13. * this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright notice,
  15. * this list of conditions and the following disclaimer in the documentation
  16. * and/or other materials provided with the distribution.
  17. * 3. The name of the author may not be used to endorse or promote products
  18. * derived from this software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  21. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  22. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
  23. * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  24. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
  25. * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  26. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  27. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  28. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  29. * OF SUCH DAMAGE.
  30. *
  31. * Change Logs:
  32. * Date Author Notes
  33. * 2013-01-30 aozima the first version
  34. * 2013-08-08 aozima support different network segments.
  35. * 2015-01-30 bernard release to RT-Thread RTOS.
  36. * 2017-12-27 aozima add [mac-ip] table support.
  37. */
  38. #include <stdio.h>
  39. #include <stdint.h>
  40. #include <rtthread.h>
  41. #include <lwip/opt.h>
  42. #include <lwip/sockets.h>
  43. #include <lwip/inet_chksum.h>
  44. #include <netif/etharp.h>
  45. #include <netif/ethernetif.h>
  46. #include <lwip/ip.h>
  47. #include <lwip/init.h>
  48. #if (LWIP_VERSION) >= 0x02000000U
  49. #include <lwip/prot/dhcp.h>
  50. #endif
  51. /* DHCP server option */
  52. /* allocated client ip range */
  53. #ifndef DHCPD_CLIENT_IP_MIN
  54. #define DHCPD_CLIENT_IP_MIN 2
  55. #endif
  56. #ifndef DHCPD_CLIENT_IP_MAX
  57. #define DHCPD_CLIENT_IP_MAX 254
  58. #endif
  59. /* the DHCP server address */
  60. #ifndef DHCPD_SERVER_IP
  61. #define DHCPD_SERVER_IP "192.168.169.1"
  62. #endif
  63. //#define DHCP_DEBUG_PRINTF
  64. #ifdef DHCP_DEBUG_PRINTF
  65. #define DEBUG_PRINTF rt_kprintf("[DHCP] "); rt_kprintf
  66. #else
  67. #define DEBUG_PRINTF(...)
  68. #endif /* DHCP_DEBUG_PRINTF */
  69. /* we need some routines in the DHCP of lwIP */
  70. #undef LWIP_DHCP
  71. #define LWIP_DHCP 1
  72. #include <lwip/dhcp.h>
  73. /* buffer size for receive DHCP packet */
  74. #define BUFSZ 1024
  75. #ifndef MAC_ADDR_LEN
  76. #define MAC_ADDR_LEN 6
  77. #endif
  78. #ifndef MAC_TABLE_LEN
  79. #define MAC_TABLE_LEN 4
  80. #endif
  81. struct mac_addr_t
  82. {
  83. uint8_t add[MAC_ADDR_LEN];
  84. };
  85. struct mac_ip_item_t
  86. {
  87. struct mac_addr_t mac_addr;
  88. uint8_t ip_addr_3;
  89. };
  90. static rt_err_t _low_level_dhcp_send(struct netif *netif,
  91. const void *buffer,
  92. rt_size_t size)
  93. {
  94. struct pbuf *p;
  95. struct eth_hdr *ethhdr;
  96. struct ip_hdr *iphdr;
  97. struct udp_hdr *udphdr;
  98. p = pbuf_alloc(PBUF_LINK,
  99. SIZEOF_ETH_HDR + sizeof(struct ip_hdr)
  100. + sizeof(struct udp_hdr) + size,
  101. PBUF_RAM);
  102. if (p == RT_NULL) return -RT_ENOMEM;
  103. ethhdr = (struct eth_hdr *)p->payload;
  104. iphdr = (struct ip_hdr *)((char *)ethhdr + SIZEOF_ETH_HDR);
  105. udphdr = (struct udp_hdr *)((char *)iphdr + sizeof(struct ip_hdr));
  106. ETHADDR32_COPY(&ethhdr->dest, (struct eth_addr *)&ethbroadcast);
  107. ETHADDR16_COPY(&ethhdr->src, netif->hwaddr);
  108. ethhdr->type = PP_HTONS(ETHTYPE_IP);
  109. iphdr->src.addr = 0x00000000; /* src: 0.0.0.0 */
  110. iphdr->dest.addr = 0xFFFFFFFF; /* src: 255.255.255.255 */
  111. IPH_VHL_SET(iphdr, 4, IP_HLEN / 4);
  112. IPH_TOS_SET(iphdr, 0x00);
  113. IPH_LEN_SET(iphdr, htons(IP_HLEN + sizeof(struct udp_hdr) + size));
  114. IPH_ID_SET(iphdr, htons(2));
  115. IPH_OFFSET_SET(iphdr, 0);
  116. IPH_TTL_SET(iphdr, 255);
  117. IPH_PROTO_SET(iphdr, IP_PROTO_UDP);
  118. IPH_CHKSUM_SET(iphdr, 0);
  119. IPH_CHKSUM_SET(iphdr, inet_chksum(iphdr, IP_HLEN));
  120. udphdr->src = htons(DHCP_SERVER_PORT);
  121. udphdr->dest = htons(DHCP_CLIENT_PORT);
  122. udphdr->len = htons(sizeof(struct udp_hdr) + size);
  123. udphdr->chksum = 0;
  124. memcpy((char *)udphdr + sizeof(struct udp_hdr),
  125. buffer, size);
  126. netif->linkoutput(netif, p);
  127. pbuf_free(p);
  128. return RT_EOK;
  129. }
  130. static uint8_t get_ip(struct mac_addr_t *p_mac_addr)
  131. {
  132. static uint8_t next_client_ip = DHCPD_CLIENT_IP_MIN;
  133. static struct mac_ip_item_t mac_table[MAC_TABLE_LEN];
  134. static int offset = 0;
  135. struct mac_addr_t bad_mac;
  136. int i;
  137. uint8_t ip_addr_3;
  138. rt_memset(&bad_mac, 0, sizeof(bad_mac));
  139. if (!rt_memcmp(&bad_mac, p_mac_addr, sizeof(bad_mac)))
  140. {
  141. DEBUG_PRINTF("mac address all zero");
  142. ip_addr_3 = DHCPD_CLIENT_IP_MAX;
  143. goto _return;
  144. }
  145. rt_memset(&bad_mac, 0xFF, sizeof(bad_mac));
  146. if (!rt_memcmp(&bad_mac, p_mac_addr, sizeof(bad_mac)))
  147. {
  148. DEBUG_PRINTF("mac address all one");
  149. ip_addr_3 = DHCPD_CLIENT_IP_MAX;
  150. goto _return;
  151. }
  152. for (i = 0; i < MAC_TABLE_LEN; i++)
  153. {
  154. if (!rt_memcmp(&mac_table[i].mac_addr, p_mac_addr, sizeof(bad_mac)))
  155. {
  156. //use old ip
  157. ip_addr_3 = mac_table[i].ip_addr_3;
  158. DEBUG_PRINTF("return old ip: %d\n", (int)ip_addr_3);
  159. goto _return;
  160. }
  161. }
  162. /* add new ip */
  163. mac_table[offset].mac_addr = *p_mac_addr;
  164. mac_table[offset].ip_addr_3 = next_client_ip;
  165. ip_addr_3 = mac_table[offset].ip_addr_3 ;
  166. offset++;
  167. if (offset >= MAC_TABLE_LEN)
  168. offset = 0;
  169. next_client_ip++;
  170. if (next_client_ip > DHCPD_CLIENT_IP_MAX)
  171. next_client_ip = DHCPD_CLIENT_IP_MIN;
  172. DEBUG_PRINTF("create new ip: %d\n", (int)ip_addr_3);
  173. DEBUG_PRINTF("next_client_ip %d\n", next_client_ip);
  174. _return:
  175. return ip_addr_3;
  176. }
  177. static void dhcpd_thread_entry(void *parameter)
  178. {
  179. struct netif *netif = RT_NULL;
  180. int sock;
  181. int bytes_read;
  182. char *recv_data;
  183. rt_uint32_t addr_len;
  184. struct sockaddr_in server_addr, client_addr;
  185. struct dhcp_msg *msg;
  186. int optval = 1;
  187. struct mac_addr_t mac_addr;
  188. uint8_t DHCPD_SERVER_IPADDR0, DHCPD_SERVER_IPADDR1, DHCPD_SERVER_IPADDR2, DHCPD_SERVER_IPADDR3;
  189. /* get ethernet interface. */
  190. netif = (struct netif *) parameter;
  191. RT_ASSERT(netif != RT_NULL);
  192. /* our DHCP server information */
  193. {
  194. #if (LWIP_VERSION) >= 0x02000000U
  195. ip4_addr_t addr;
  196. ip4addr_aton(DHCPD_SERVER_IP, &addr);
  197. #else
  198. struct ip_addr addr;
  199. ipaddr_aton(DHCPD_SERVER_IP, &addr);
  200. #endif /* LWIP_VERSION */
  201. DHCPD_SERVER_IPADDR0 = (ntohl(addr.addr) >> 24) & 0xFF;
  202. DHCPD_SERVER_IPADDR1 = (ntohl(addr.addr) >> 16) & 0xFF;
  203. DHCPD_SERVER_IPADDR2 = (ntohl(addr.addr) >> 8) & 0xFF;
  204. DHCPD_SERVER_IPADDR3 = (ntohl(addr.addr) >> 0) & 0xFF;
  205. }
  206. DEBUG_PRINTF("DHCP server IP: %d.%d.%d.%d client IP: %d.%d.%d.%d-%d\n",
  207. DHCPD_SERVER_IPADDR0, DHCPD_SERVER_IPADDR1,
  208. DHCPD_SERVER_IPADDR2, DHCPD_SERVER_IPADDR3,
  209. DHCPD_SERVER_IPADDR0, DHCPD_SERVER_IPADDR1,
  210. DHCPD_SERVER_IPADDR2, DHCPD_CLIENT_IP_MIN, DHCPD_CLIENT_IP_MAX);
  211. /* allocate buffer for receive */
  212. recv_data = rt_malloc(BUFSZ);
  213. if (recv_data == RT_NULL)
  214. {
  215. /* No memory */
  216. DEBUG_PRINTF("Out of memory\n");
  217. return;
  218. }
  219. /* create a socket with UDP */
  220. if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
  221. {
  222. DEBUG_PRINTF("create socket failed, errno = %d\n", errno);
  223. rt_free(recv_data);
  224. return;
  225. }
  226. /* set to receive broadcast packet */
  227. setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &optval, sizeof(optval));
  228. /* initialize server address */
  229. server_addr.sin_family = AF_INET;
  230. server_addr.sin_port = htons(DHCP_SERVER_PORT);
  231. server_addr.sin_addr.s_addr = INADDR_ANY;
  232. rt_memset(&(server_addr.sin_zero), 0, sizeof(server_addr.sin_zero));
  233. /* bind socket to the server address */
  234. if (bind(sock, (struct sockaddr *)&server_addr,
  235. sizeof(struct sockaddr)) == -1)
  236. {
  237. /* bind failed. */
  238. DEBUG_PRINTF("bind server address failed, errno=%d\n", errno);
  239. closesocket(sock);
  240. rt_free(recv_data);
  241. return;
  242. }
  243. addr_len = sizeof(struct sockaddr);
  244. DEBUG_PRINTF("DHCP server listen on port %d...\n", DHCP_SERVER_PORT);
  245. while (1)
  246. {
  247. bytes_read = recvfrom(sock, recv_data, BUFSZ - 1, 0,
  248. (struct sockaddr *)&client_addr, &addr_len);
  249. if (bytes_read <= 0)
  250. {
  251. closesocket(sock);
  252. rt_free(recv_data);
  253. return;
  254. }
  255. else if (bytes_read < DHCP_MSG_LEN)
  256. {
  257. DEBUG_PRINTF("packet too short, wait for next!\n");
  258. continue;
  259. }
  260. msg = (struct dhcp_msg *)recv_data;
  261. /* check message type to make sure we can handle it */
  262. if ((msg->op != DHCP_BOOTREQUEST) || (msg->cookie != PP_HTONL(DHCP_MAGIC_COOKIE)))
  263. {
  264. continue;
  265. }
  266. memcpy(mac_addr.add, msg->chaddr, MAC_ADDR_LEN);
  267. /* handler. */
  268. {
  269. uint8_t *dhcp_opt;
  270. uint8_t option;
  271. uint8_t length;
  272. uint8_t message_type = 0;
  273. uint8_t finished = 0;
  274. uint32_t request_ip = 0;
  275. uint8_t client_ip_3;
  276. client_ip_3 = get_ip(&mac_addr);
  277. dhcp_opt = (uint8_t *)msg + DHCP_OPTIONS_OFS;
  278. while (finished == 0)
  279. {
  280. option = *dhcp_opt;
  281. length = *(dhcp_opt + 1);
  282. switch (option)
  283. {
  284. case DHCP_OPTION_REQUESTED_IP:
  285. request_ip = *(dhcp_opt + 2) << 24 | *(dhcp_opt + 3) << 16
  286. | *(dhcp_opt + 4) << 8 | *(dhcp_opt + 5);
  287. break;
  288. case DHCP_OPTION_END:
  289. finished = 1;
  290. break;
  291. case DHCP_OPTION_MESSAGE_TYPE:
  292. message_type = *(dhcp_opt + 2);
  293. break;
  294. default:
  295. break;
  296. } /* switch(option) */
  297. dhcp_opt += (2 + length);
  298. }
  299. /* reply. */
  300. dhcp_opt = (uint8_t *)msg + DHCP_OPTIONS_OFS;
  301. /* check. */
  302. if (request_ip)
  303. {
  304. uint32_t client_ip = DHCPD_SERVER_IPADDR0 << 24 | DHCPD_SERVER_IPADDR1 << 16
  305. | DHCPD_SERVER_IPADDR2 << 8 | client_ip_3;
  306. DEBUG_PRINTF("message_type: %d, request_ip: %08X, client_ip: %08X.\n", message_type, request_ip, client_ip);
  307. if (request_ip != client_ip)
  308. {
  309. *dhcp_opt++ = DHCP_OPTION_MESSAGE_TYPE;
  310. *dhcp_opt++ = DHCP_OPTION_MESSAGE_TYPE_LEN;
  311. *dhcp_opt++ = DHCP_NAK;
  312. *dhcp_opt++ = DHCP_OPTION_END;
  313. DEBUG_PRINTF("requested IP invalid, reply DHCP_NAK\n");
  314. if (netif != RT_NULL)
  315. {
  316. int send_byte = (dhcp_opt - (uint8_t *)msg);
  317. _low_level_dhcp_send(netif, msg, send_byte);
  318. DEBUG_PRINTF("DHCP server send %d byte\n", send_byte);
  319. }
  320. continue;
  321. }
  322. }
  323. if (message_type == DHCP_DISCOVER)
  324. {
  325. DEBUG_PRINTF("request DHCP_DISCOVER\n");
  326. DEBUG_PRINTF("reply DHCP_OFFER\n");
  327. // DHCP_OPTION_MESSAGE_TYPE
  328. *dhcp_opt++ = DHCP_OPTION_MESSAGE_TYPE;
  329. *dhcp_opt++ = DHCP_OPTION_MESSAGE_TYPE_LEN;
  330. *dhcp_opt++ = DHCP_OFFER;
  331. // DHCP_OPTION_SERVER_ID
  332. *dhcp_opt++ = DHCP_OPTION_SERVER_ID;
  333. *dhcp_opt++ = 4;
  334. *dhcp_opt++ = DHCPD_SERVER_IPADDR0;
  335. *dhcp_opt++ = DHCPD_SERVER_IPADDR1;
  336. *dhcp_opt++ = DHCPD_SERVER_IPADDR2;
  337. *dhcp_opt++ = DHCPD_SERVER_IPADDR3;
  338. // DHCP_OPTION_LEASE_TIME
  339. *dhcp_opt++ = DHCP_OPTION_LEASE_TIME;
  340. *dhcp_opt++ = 4;
  341. *dhcp_opt++ = 0x00;
  342. *dhcp_opt++ = 0x01;
  343. *dhcp_opt++ = 0x51;
  344. *dhcp_opt++ = 0x80;
  345. }
  346. else if (message_type == DHCP_REQUEST)
  347. {
  348. DEBUG_PRINTF("request DHCP_REQUEST\n");
  349. DEBUG_PRINTF("reply DHCP_ACK\n");
  350. // DHCP_OPTION_MESSAGE_TYPE
  351. *dhcp_opt++ = DHCP_OPTION_MESSAGE_TYPE;
  352. *dhcp_opt++ = DHCP_OPTION_MESSAGE_TYPE_LEN;
  353. *dhcp_opt++ = DHCP_ACK;
  354. // DHCP_OPTION_SERVER_ID
  355. *dhcp_opt++ = DHCP_OPTION_SERVER_ID;
  356. *dhcp_opt++ = 4;
  357. *dhcp_opt++ = DHCPD_SERVER_IPADDR0;
  358. *dhcp_opt++ = DHCPD_SERVER_IPADDR1;
  359. *dhcp_opt++ = DHCPD_SERVER_IPADDR2;
  360. *dhcp_opt++ = DHCPD_SERVER_IPADDR3;
  361. // DHCP_OPTION_SUBNET_MASK
  362. *dhcp_opt++ = DHCP_OPTION_SUBNET_MASK;
  363. *dhcp_opt++ = 4;
  364. *dhcp_opt++ = 0xFF;
  365. *dhcp_opt++ = 0xFF;
  366. *dhcp_opt++ = 0xFF;
  367. *dhcp_opt++ = 0x00;
  368. #ifdef DHCPD_USING_ROUTER
  369. // DHCP_OPTION_ROUTER
  370. *dhcp_opt++ = DHCP_OPTION_ROUTER;
  371. *dhcp_opt++ = 4;
  372. *dhcp_opt++ = DHCPD_SERVER_IPADDR0;
  373. *dhcp_opt++ = DHCPD_SERVER_IPADDR1;
  374. *dhcp_opt++ = DHCPD_SERVER_IPADDR2;
  375. *dhcp_opt++ = 1;
  376. #endif
  377. // DHCP_OPTION_DNS_SERVER, use the default DNS server address in lwIP
  378. *dhcp_opt++ = DHCP_OPTION_DNS_SERVER;
  379. *dhcp_opt++ = 4;
  380. #ifndef DHCP_DNS_SERVER_IP
  381. *dhcp_opt++ = DHCPD_SERVER_IPADDR0;
  382. *dhcp_opt++ = DHCPD_SERVER_IPADDR1;
  383. *dhcp_opt++ = DHCPD_SERVER_IPADDR2;
  384. *dhcp_opt++ = 1;
  385. #else
  386. {
  387. #if (LWIP_VERSION) >= 0x02000000U
  388. ip4_addr_t dns_addr;
  389. #else
  390. struct ip_addr dns_addr;
  391. #endif /* LWIP_VERSION */
  392. ip4addr_aton(DHCP_DNS_SERVER_IP, &dns_addr);
  393. *dhcp_opt++ = (ntohl(dns_addr.addr) >> 24) & 0xFF;
  394. *dhcp_opt++ = (ntohl(dns_addr.addr) >> 16) & 0xFF;
  395. *dhcp_opt++ = (ntohl(dns_addr.addr) >> 8) & 0xFF;
  396. *dhcp_opt++ = (ntohl(dns_addr.addr) >> 0) & 0xFF;
  397. }
  398. #endif
  399. // DHCP_OPTION_LEASE_TIME
  400. *dhcp_opt++ = DHCP_OPTION_LEASE_TIME;
  401. *dhcp_opt++ = 4;
  402. *dhcp_opt++ = 0x00;
  403. *dhcp_opt++ = 0x01;
  404. *dhcp_opt++ = 0x51;
  405. *dhcp_opt++ = 0x80;
  406. }
  407. else
  408. {
  409. DEBUG_PRINTF("un handle message:%d\n", message_type);
  410. }
  411. // append DHCP_OPTION_END
  412. *dhcp_opt++ = DHCP_OPTION_END;
  413. /* send reply. */
  414. if ((message_type == DHCP_DISCOVER) || (message_type == DHCP_REQUEST))
  415. {
  416. msg->op = DHCP_BOOTREPLY;
  417. IP4_ADDR(&msg->yiaddr,
  418. DHCPD_SERVER_IPADDR0, DHCPD_SERVER_IPADDR1,
  419. DHCPD_SERVER_IPADDR2, client_ip_3);
  420. client_addr.sin_addr.s_addr = INADDR_BROADCAST;
  421. if (netif != RT_NULL)
  422. {
  423. int send_byte = (dhcp_opt - (uint8_t *)msg);
  424. _low_level_dhcp_send(netif, msg, send_byte);
  425. DEBUG_PRINTF("DHCP server send %d byte\n", send_byte);
  426. }
  427. }
  428. } /* handler. */
  429. }
  430. }
  431. void dhcpd_start(const char *netif_name)
  432. {
  433. rt_thread_t thread;
  434. struct netif *netif = netif_list;
  435. if (strlen(netif_name) > sizeof(netif->name))
  436. {
  437. rt_kprintf("network interface name too long!\r\n");
  438. return;
  439. }
  440. while (netif != RT_NULL)
  441. {
  442. if (strncmp(netif_name, netif->name, sizeof(netif->name)) == 0)
  443. break;
  444. netif = netif->next;
  445. if (netif == RT_NULL)
  446. {
  447. rt_kprintf("network interface: %s not found!\r\n", netif_name);
  448. return;
  449. }
  450. }
  451. if (1)
  452. {
  453. extern void set_if(const char *netif_name, const char *ip_addr, const char *gw_addr, const char *nm_addr);
  454. dhcp_stop(netif);
  455. set_if(netif_name, DHCPD_SERVER_IP, "0.0.0.0", "255.255.255.0");
  456. netif_set_up(netif);
  457. }
  458. thread = rt_thread_create("dhcpd",
  459. dhcpd_thread_entry, netif,
  460. 1024,
  461. RT_THREAD_PRIORITY_MAX - 3,
  462. 2);
  463. if (thread != RT_NULL)
  464. {
  465. rt_thread_startup(thread);
  466. }
  467. }