Changes in uspace/srv/net/dhcp/dhcp.c [3e6bca8:1bbc6dc] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/dhcp/dhcp.c
r3e6bca8 r1bbc6dc 1 1 /* 2 * Copyright (c) 202 1Jiri Svoboda2 * Copyright (c) 2024 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 47 47 #include <io/log.h> 48 48 #include <loc.h> 49 #include <rndgen.h> 49 50 #include <stdio.h> 50 51 #include <stdlib.h> … … 69 70 /** List of registered links (of dhcp_link_t) */ 70 71 static list_t dhcp_links; 72 73 bool inetcfg_inited = false; 71 74 72 75 static void dhcpsrv_discover_timeout(void *); … … 95 98 /** DNS server */ 96 99 inet_addr_t dns_server; 100 /** Transaction ID */ 101 uint32_t xid; 97 102 } dhcp_offer_t; 98 103 … … 114 119 /** Last received offer */ 115 120 dhcp_offer_t offer; 121 /** Random number generator */ 122 rndgen_t *rndgen; 116 123 } dhcp_link_t; 117 124 … … 154 161 dhcp_hdr_t *hdr = (dhcp_hdr_t *)msgbuf; 155 162 uint8_t *opt = msgbuf + sizeof(dhcp_hdr_t); 163 uint32_t xid; 164 errno_t rc; 165 size_t i; 166 167 rc = rndgen_uint32(dlink->rndgen, &xid); 168 if (rc != EOK) 169 return rc; 156 170 157 171 memset(msgbuf, 0, MAX_MSG_SIZE); … … 159 173 hdr->htype = 1; /* AHRD_ETHERNET */ 160 174 hdr->hlen = ETH_ADDR_SIZE; 161 hdr->xid = host2uint32_t_be( 42);162 hdr->flags = flag_broadcast;175 hdr->xid = host2uint32_t_be(xid); 176 hdr->flags = host2uint16_t_be(flag_broadcast); 163 177 164 178 eth_addr_encode(&dlink->link_info.mac_addr, hdr->chaddr); 165 179 hdr->opt_magic = host2uint32_t_be(dhcp_opt_magic); 166 180 167 opt[0] = opt_msg_type; 168 opt[1] = 1; 169 opt[2] = msg_dhcpdiscover; 170 opt[3] = opt_end; 171 172 return dhcp_send(&dlink->dt, msgbuf, sizeof(dhcp_hdr_t) + 4); 181 i = 0; 182 183 opt[i++] = opt_msg_type; 184 opt[i++] = 1; 185 opt[i++] = msg_dhcpdiscover; 186 187 opt[i++] = opt_param_req_list; 188 opt[i++] = 3; 189 opt[i++] = 1; /* subnet mask */ 190 opt[i++] = 6; /* DNS server */ 191 opt[i++] = 3; /* router */ 192 193 opt[i++] = opt_end; 194 195 return dhcp_send(&dlink->dt, msgbuf, sizeof(dhcp_hdr_t) + i); 173 196 } 174 197 … … 183 206 hdr->htype = 1; /* AHRD_ETHERNET */ 184 207 hdr->hlen = 6; 185 hdr->xid = host2uint32_t_be(42); 186 hdr->flags = flag_broadcast; 187 hdr->ciaddr = host2uint32_t_be(offer->oaddr.addr); 208 hdr->xid = host2uint32_t_be(offer->xid); 209 hdr->flags = host2uint16_t_be(flag_broadcast); 188 210 eth_addr_encode(&dlink->link_info.mac_addr, hdr->chaddr); 189 211 hdr->opt_magic = host2uint32_t_be(dhcp_opt_magic); … … 258 280 259 281 inet_naddr_set(yiaddr.addr, 0, &offer->oaddr); 282 offer->xid = uint32_t_be2host(hdr->xid); 260 283 261 284 msgb = (uint8_t *)msg; … … 447 470 log_msg(LOG_DEFAULT, LVL_DEBUG, "dhcpsrv_link_add(%zu)", link_id); 448 471 472 if (!inetcfg_inited) { 473 rc = inetcfg_init(); 474 if (rc != EOK) { 475 log_msg(LOG_DEFAULT, LVL_ERROR, "Error contacting " 476 "inet configuration service.\n"); 477 return EIO; 478 } 479 480 inetcfg_inited = true; 481 } 482 449 483 if (dhcpsrv_link_find(link_id) != NULL) { 450 484 log_msg(LOG_DEFAULT, LVL_NOTE, "Link %zu already added", … … 456 490 if (dlink == NULL) 457 491 return ENOMEM; 492 493 rc = rndgen_create(&dlink->rndgen); 494 if (rc != EOK) 495 goto error; 458 496 459 497 dlink->link_id = link_id; … … 494 532 return EOK; 495 533 error: 534 if (dlink != NULL && dlink->rndgen != NULL) 535 rndgen_destroy(dlink->rndgen); 496 536 if (dlink != NULL && dlink->timeout != NULL) 497 537 fibril_timer_destroy(dlink->timeout);
Note:
See TracChangeset
for help on using the changeset viewer.