Changes in uspace/srv/net/dhcp/dhcp.c [3e6bca8:b7155d7] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/net/dhcp/dhcp.c
r3e6bca8 rb7155d7 1 1 /* 2 * Copyright (c) 202 1Jiri Svoboda2 * Copyright (c) 2022 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> … … 95 96 /** DNS server */ 96 97 inet_addr_t dns_server; 98 /** Transaction ID */ 99 uint32_t xid; 97 100 } dhcp_offer_t; 98 101 … … 114 117 /** Last received offer */ 115 118 dhcp_offer_t offer; 119 /** Random number generator */ 120 rndgen_t *rndgen; 116 121 } dhcp_link_t; 117 122 … … 154 159 dhcp_hdr_t *hdr = (dhcp_hdr_t *)msgbuf; 155 160 uint8_t *opt = msgbuf + sizeof(dhcp_hdr_t); 161 uint32_t xid; 162 errno_t rc; 163 size_t i; 164 165 rc = rndgen_uint32(dlink->rndgen, &xid); 166 if (rc != EOK) 167 return rc; 156 168 157 169 memset(msgbuf, 0, MAX_MSG_SIZE); … … 159 171 hdr->htype = 1; /* AHRD_ETHERNET */ 160 172 hdr->hlen = ETH_ADDR_SIZE; 161 hdr->xid = host2uint32_t_be( 42);162 hdr->flags = flag_broadcast;173 hdr->xid = host2uint32_t_be(xid); 174 hdr->flags = host2uint16_t_be(flag_broadcast); 163 175 164 176 eth_addr_encode(&dlink->link_info.mac_addr, hdr->chaddr); 165 177 hdr->opt_magic = host2uint32_t_be(dhcp_opt_magic); 166 178 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); 179 i = 0; 180 181 opt[i++] = opt_msg_type; 182 opt[i++] = 1; 183 opt[i++] = msg_dhcpdiscover; 184 185 opt[i++] = opt_param_req_list; 186 opt[i++] = 3; 187 opt[i++] = 1; /* subnet mask */ 188 opt[i++] = 6; /* DNS server */ 189 opt[i++] = 3; /* router */ 190 191 opt[i++] = opt_end; 192 193 return dhcp_send(&dlink->dt, msgbuf, sizeof(dhcp_hdr_t) + i); 173 194 } 174 195 … … 183 204 hdr->htype = 1; /* AHRD_ETHERNET */ 184 205 hdr->hlen = 6; 185 hdr->xid = host2uint32_t_be(42); 186 hdr->flags = flag_broadcast; 187 hdr->ciaddr = host2uint32_t_be(offer->oaddr.addr); 206 hdr->xid = host2uint32_t_be(offer->xid); 207 hdr->flags = host2uint16_t_be(flag_broadcast); 188 208 eth_addr_encode(&dlink->link_info.mac_addr, hdr->chaddr); 189 209 hdr->opt_magic = host2uint32_t_be(dhcp_opt_magic); … … 258 278 259 279 inet_naddr_set(yiaddr.addr, 0, &offer->oaddr); 280 offer->xid = uint32_t_be2host(hdr->xid); 260 281 261 282 msgb = (uint8_t *)msg; … … 457 478 return ENOMEM; 458 479 480 rc = rndgen_create(&dlink->rndgen); 481 if (rc != EOK) 482 goto error; 483 459 484 dlink->link_id = link_id; 460 485 dlink->timeout = fibril_timer_create(NULL); … … 494 519 return EOK; 495 520 error: 521 if (dlink != NULL && dlink->rndgen != NULL) 522 rndgen_destroy(dlink->rndgen); 496 523 if (dlink != NULL && dlink->timeout != NULL) 497 524 fibril_timer_destroy(dlink->timeout);
Note:
See TracChangeset
for help on using the changeset viewer.