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