Changes in uspace/srv/net/dhcp/dhcp.c [8d58fca:1bbc6dc] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/dhcp/dhcp.c
r8d58fca r1bbc6dc 1 1 /* 2 * Copyright (c) 20 13Jiri Svoboda2 * Copyright (c) 2024 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 42 42 #include <fibril_synch.h> 43 43 #include <inet/addr.h> 44 #include <inet/eth_addr.h> 44 45 #include <inet/dnsr.h> 45 46 #include <inet/inetcfg.h> 46 47 #include <io/log.h> 47 48 #include <loc.h> 49 #include <rndgen.h> 48 50 #include <stdio.h> 49 51 #include <stdlib.h> … … 68 70 /** List of registered links (of dhcp_link_t) */ 69 71 static list_t dhcp_links; 72 73 bool inetcfg_inited = false; 70 74 71 75 static void dhcpsrv_discover_timeout(void *); … … 94 98 /** DNS server */ 95 99 inet_addr_t dns_server; 100 /** Transaction ID */ 101 uint32_t xid; 96 102 } dhcp_offer_t; 97 103 … … 113 119 /** Last received offer */ 114 120 dhcp_offer_t offer; 121 /** Random number generator */ 122 rndgen_t *rndgen; 115 123 } dhcp_link_t; 116 124 … … 153 161 dhcp_hdr_t *hdr = (dhcp_hdr_t *)msgbuf; 154 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; 155 170 156 171 memset(msgbuf, 0, MAX_MSG_SIZE); 157 172 hdr->op = op_bootrequest; 158 173 hdr->htype = 1; /* AHRD_ETHERNET */ 159 hdr->hlen = sizeof(addr48_t);160 hdr->xid = host2uint32_t_be( 42);161 hdr->flags = flag_broadcast;162 163 addr48(dlink->link_info.mac_addr, hdr->chaddr);174 hdr->hlen = ETH_ADDR_SIZE; 175 hdr->xid = host2uint32_t_be(xid); 176 hdr->flags = host2uint16_t_be(flag_broadcast); 177 178 eth_addr_encode(&dlink->link_info.mac_addr, hdr->chaddr); 164 179 hdr->opt_magic = host2uint32_t_be(dhcp_opt_magic); 165 180 166 opt[0] = opt_msg_type; 167 opt[1] = 1; 168 opt[2] = msg_dhcpdiscover; 169 opt[3] = opt_end; 170 171 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); 172 196 } 173 197 … … 182 206 hdr->htype = 1; /* AHRD_ETHERNET */ 183 207 hdr->hlen = 6; 184 hdr->xid = host2uint32_t_be(42); 185 hdr->flags = flag_broadcast; 186 hdr->ciaddr = host2uint32_t_be(offer->oaddr.addr); 187 addr48(dlink->link_info.mac_addr, hdr->chaddr); 208 hdr->xid = host2uint32_t_be(offer->xid); 209 hdr->flags = host2uint16_t_be(flag_broadcast); 210 eth_addr_encode(&dlink->link_info.mac_addr, hdr->chaddr); 188 211 hdr->opt_magic = host2uint32_t_be(dhcp_opt_magic); 189 212 … … 257 280 258 281 inet_naddr_set(yiaddr.addr, 0, &offer->oaddr); 282 offer->xid = uint32_t_be2host(hdr->xid); 259 283 260 284 msgb = (uint8_t *)msg; … … 446 470 log_msg(LOG_DEFAULT, LVL_DEBUG, "dhcpsrv_link_add(%zu)", link_id); 447 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 448 483 if (dhcpsrv_link_find(link_id) != NULL) { 449 484 log_msg(LOG_DEFAULT, LVL_NOTE, "Link %zu already added", … … 455 490 if (dlink == NULL) 456 491 return ENOMEM; 492 493 rc = rndgen_create(&dlink->rndgen); 494 if (rc != EOK) 495 goto error; 457 496 458 497 dlink->link_id = link_id; … … 493 532 return EOK; 494 533 error: 534 if (dlink != NULL && dlink->rndgen != NULL) 535 rndgen_destroy(dlink->rndgen); 495 536 if (dlink != NULL && dlink->timeout != NULL) 496 537 fibril_timer_destroy(dlink->timeout);
Note:
See TracChangeset
for help on using the changeset viewer.