Home | History | Annotate | Download | only in dhcpcd-6.8.2

Lines Matching refs:ifp

121 static int dhcp_open(struct interface *ifp);
582 get_option_routes(struct interface *ifp, const struct dhcp_message *dhcp)
584 struct if_options *ifo = ifp->options;
594 p = get_option(ifp->ctx, dhcp, DHO_CSR, &len);
599 p = get_option(ifp->ctx, dhcp, DHO_MSCSR, &len);
604 routes = decode_rfc3442_rt(ifp->ctx, p, len);
608 state = D_CSTATE(ifp);
612 logger(ifp->ctx, LOG_DEBUG,
614 ifp->name, csr);
624 logger(ifp->ctx, LOG_ERR, "%s: %m", __func__);
629 p = get_option(ifp->ctx, dhcp, DHO_STATICROUTE, &len);
637 logger(ifp->ctx, LOG_ERR, "%s: %m", __func__);
659 p = get_option(ifp->ctx, dhcp, DHO_ROUTER, &len);
666 logger(ifp->ctx, LOG_ERR, "%s: %m", __func__);
713 const struct interface *ifp,
723 struct if_options *ifo = ifp->options;
724 const struct dhcp_state *state = D_CSTATE(ifp);
750 dhcp->hwtype = (uint8_t)ifp->family;
751 switch (ifp->family) {
754 dhcp->hwlen = (uint8_t)ifp->hwlen;
755 memcpy(&dhcp->chaddr, &ifp->hwaddr, ifp->hwlen);
811 !(ifp->ctx->options & DHCPCD_TEST) &&
838 mtu = if_getmtu(ifp->name);
840 if (if_setmtu(ifp->name, MTU_MIN) == 0)
956 logger(ifp->ctx, LOG_ERR,
958 ifp->name);
975 for (i = 0, opt = ifp->ctx->dhcp_opts;
976 i < ifp->ctx->dhcp_opts_len;
1033 logger(ifp->ctx, LOG_ERR,
1034 "%s: dhcp_auth_encode: %m", ifp->name);
1063 logger(ifp->ctx, LOG_ERR, "%s: DHCP messge too big", ifp->name);
1069 write_lease(const struct interface *ifp, const struct dhcp_message *dhcp)
1077 const struct dhcp_state *state = D_CSTATE(ifp);
1082 if (IS_BOOTP(ifp, dhcp)) {
1087 logger(ifp->ctx, LOG_DEBUG, "%s: writing lease `%s'",
1088 ifp->name, state->leasefile);
1127 read_lease(struct interface *ifp)
1131 struct dhcp_state *state = D_STATE(ifp);
1147 logger(ifp->ctx, LOG_ERR, "%s: open `%s': %m",
1148 ifp->name, state->leasefile);
1151 logger(ifp->ctx, LOG_DEBUG, "%s: reading lease `%s'",
1152 ifp->name, state->leasefile);
1180 if (get_option_uint8(ifp->ctx, &type, dhcp, DHO_MESSAGETYPE) == -1)
1184 auth = get_option(ifp->ctx, dhcp, DHO_AUTHENTICATION, &auth_len);
1186 if (dhcp_auth_validate(&state->auth, &ifp->options->auth,
1190 logger(ifp->ctx, LOG_DEBUG,
1191 "%s: dhcp_auth_validate: %m", ifp->name);
1196 logger(ifp->ctx, LOG_DEBUG,
1198 ifp->name, state->auth.token->secretid);
1200 logger(ifp->ctx, LOG_DEBUG,
1201 "%s: accepted reconfigure key", ifp->name);
1214 logger(ifp->ctx, LOG_DEBUG, "%s: found server info in lease '%s'",
1215 ifp->name, state->leasefile);
1218 if (state->server_info.gw_hwlen != ifp->hwlen) {
1219 logger(ifp->ctx, LOG_ERR, "%s: lease file %s has incompatible"
1221 ifp->name, state->leasefile,
1222 state->server_info.gw_hwlen, ifp->hwlen);
1279 const struct interface *ifp)
1294 ifo = ifp->options;
1295 get_option_uint8(ifp->ctx, &overl, dhcp, DHO_OPTIONSOVERLOADED);
1304 for (i = 0, opt = ifp->ctx->dhcp_opts;
1305 i < ifp->ctx->dhcp_opts_len;
1312 p = get_option(ifp->ctx, dhcp, opt->option, &pl);
1315 e += dhcp_envoption(ifp->ctx, NULL, NULL, ifp->name,
1324 p = get_option(ifp->ctx, dhcp, opt->option, &pl);
1327 e += dhcp_envoption(ifp->ctx, NULL, NULL, ifp->name,
1338 setvar(ifp->ctx, &ep, prefix, "ip_address", inet_ntoa(addr));
1339 if (get_option_addr(ifp->ctx, &net,
1342 setvar(ifp->ctx, &ep, prefix,
1346 setvar(ifp->ctx, &ep, prefix, "subnet_cidr", cidr);
1347 if (get_option_addr(ifp->ctx, &brd,
1350 setvar(ifp->ctx, &ep, prefix,
1354 setvar(ifp->ctx, &ep, prefix,
1361 setvar(ifp->ctx, &ep, prefix, "filename", safe);
1366 setvar(ifp->ctx, &ep, prefix, "server_name", safe);
1371 for (i = 0, opt = ifp->ctx->dhcp_opts;
1372 i < ifp->ctx->dhcp_opts_len;
1375 for (i = 0, opt = ifp->options->dhcp_override;
1376 i < ifp->options->dhcp_override_len;
1379 for (i = 0, opt = ifp->ctx->vivso;
1380 i < ifp->ctx->vivso_len;
1385 for (i = 0, opt = ifp->ctx->dhcp_opts;
1386 i < ifp->ctx->dhcp_opts_len;
1393 if ((p = get_option(ifp->ctx, dhcp, opt->option, &pl))) {
1394 ep += dhcp_envoption(ifp->ctx, ep, prefix, ifp->name,
1401 vo = vivso_find(en, ifp);
1406 ep += dhcp_envoption(ifp->ctx,
1407 ep, prefix, ifp->name,
1420 if ((p = get_option(ifp->ctx, dhcp, opt->option, &pl)))
1421 ep += dhcp_envoption(ifp->ctx, ep, prefix, ifp->name,
1477 dhcp_xid(const struct interface *ifp)
1481 if (ifp->options->options & DHCPCD_XID_HWADDR &&
1482 ifp->hwlen >= sizeof(xid))
1484 memcpy(&xid, (ifp->hwaddr + ifp->hwlen) - sizeof(xid),
1493 dhcp_close(struct interface *ifp)
1495 struct dhcp_state *state = D_STATE(ifp);
1501 eloop_event_delete(ifp->ctx->eloop, state->raw_fd, 0);
1510 dhcp_openudp(struct interface *ifp)
1539 if (ifp) {
1541 strlcpy(ifr.ifr_name, ifp->name, sizeof(ifr.ifr_name));
1554 if (ifp) {
1555 state = D_STATE(ifp);
1640 send_message(struct interface *ifp, uint8_t type,
1643 struct dhcp_state *state = D_STATE(ifp);
1644 struct if_options *ifo = ifp->options;
1658 logger(ifp->ctx, LOG_INFO, "%s: sending %s with xid 0x%x",
1659 ifp->name,
1674 logger(ifp->ctx, LOG_INFO,
1676 ifp->name,
1682 if (dhcp_open(ifp) == -1)
1689 ((ia = ipv4_iffindaddr(ifp, &state->addr, NULL)) &&
1693 ifp->options->options & DHCPCD_INFORM))
1695 s = dhcp_openudp(ifp);
1697 logger(ifp->ctx, LOG_ERR,
1698 "%s: dhcp_openudp: %m", ifp->name);
1708 IS_BOOTP(ifp, state->new)))
1713 r = make_message(&dhcp, ifp, type);
1734 logger(ifp->ctx, LOG_ERR,
1735 "%s: dhcp_sendpacket: %m", ifp->name);
1742 logger(ifp->ctx, LOG_ERR, "dhcp_makeudppacket: %m");
1744 r = if_sendrawpacket(ifp, ETHERTYPE_IP,
1754 logger(ifp->ctx, LOG_ERR,
1755 "%s: if_sendrawpacket: %m", ifp->name);
1762 if (!(ifp->ctx->options & DHCPCD_TEST))
1763 dhcp_drop(ifp, "FAIL");
1764 dhcp_free(ifp);
1765 eloop_timeout_delete(ifp->ctx->eloop,
1766 NULL, ifp);
1780 eloop_timeout_add_tv(ifp->ctx->eloop, &tv, callback, ifp);
1821 struct interface *ifp = arg;
1822 struct dhcp_state *state = D_STATE(ifp);
1823 struct if_options *ifo = ifp->options;
1827 state->xid = dhcp_xid(ifp);
1830 eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp);
1832 eloop_timeout_add_sec(ifp->ctx->eloop,
1833 ifo->reboot, dhcp_fallback, ifp);
1836 eloop_timeout_add_sec(ifp->ctx->eloop,
1837 ifo->reboot, ipv4ll_start, ifp);
1839 logger(ifp->ctx, LOG_INFO,
1841 ifp->name, inet_ntoa(ifo->req_addr));
1843 logger(ifp->ctx, LOG_INFO,
1845 ifp->name, ifo->options & DHCPCD_BOOTP ? "BOOTP" : "DHCP");
1846 send_discover(ifp);
1852 struct interface *ifp = arg;
1853 struct dhcp_state *state = D_STATE(ifp);
1855 logger(ifp->ctx, LOG_INFO, "%s: requesting lease of %s",
1856 ifp->name, inet_ntoa(state->lease.addr));
1861 send_request(ifp);
1867 struct interface *ifp = arg;
1868 struct dhcp_state *state = D_STATE(ifp);
1870 logger(ifp->ctx, LOG_ERR, "%s: DHCP lease expired", ifp->name);
1871 eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp);
1872 dhcp_drop(ifp, "EXPIRE");
1875 dhcp_discover(ifp);
1879 dhcp_decline(struct interface *ifp)
1882 send_message(ifp, DHCP_DECLINE, NULL);
1888 struct interface *ifp = arg;
1889 struct dhcp_state *state = D_STATE(ifp);
1893 logger(ifp->ctx, LOG_INFO, "%s: renewing lease of %s",
1894 ifp->name, inet_ntoa(lease->addr));
1895 logger(ifp->ctx, LOG_DEBUG, "%s: rebind in %"PRIu32" seconds,"
1897 ifp->name, lease->rebindtime - lease->renewaltime,
1900 state->xid = dhcp_xid(ifp);
1902 send_renew(ifp);
1917 struct interface *ifp = arg;
1918 struct dhcp_state *state = D_STATE(ifp);
1922 logger(ifp->ctx, LOG_WARNING,
1923 "%s: failed to renew DHCP, rebinding", ifp->name);
1924 logger(ifp->ctx, LOG_DEBUG, "%s: expire in %"PRIu32" seconds",
1925 ifp->name, lease->leasetime - lease->rebindtime);
1927 eloop_timeout_delete(ifp->ctx->eloop, send_renew, ifp);
1930 ifp->options->options &= ~(DHCPCD_CSR_WARNED |
1932 send_rebind(ifp);
2062 dhcp_bind(struct interface *ifp, struct arp_state *astate)
2064 struct dhcp_state *state = D_STATE(ifp);
2065 struct if_options *ifo = ifp->options;
2076 get_lease(ifp->ctx, lease, state->new);
2078 logger(ifp->ctx, LOG_INFO, "%s: using static address %s/%d",
2079 ifp->name, inet_ntoa(lease->addr),
2084 logger(ifp->ctx, LOG_INFO, "%s: using IPv4LL address %s",
2085 ifp->name, inet_ntoa(lease->addr));
2094 logger(ifp->ctx, LOG_INFO, "%s: received approval for %s",
2095 ifp->name, inet_ntoa(lease->addr));
2105 logger(ifp->ctx, LOG_INFO, "%s: leased %s for infinity",
2106 ifp->name, inet_ntoa(lease->addr));
2109 logger(ifp->ctx, LOG_WARNING,
2111 ifp->name, DHCP_MIN_LEASE);
2120 logger(ifp->ctx, LOG_WARNING,
2123 ifp->name, lease->rebindtime);
2131 logger(ifp->ctx, LOG_WARNING,
2134 ifp->name, lease->renewaltime);
2136 logger(ifp->ctx,
2140 "%s: leased %s for %"PRIu32" seconds", ifp->name,
2144 if (ifp->ctx->options & DHCPCD_TEST) {
2146 script_runreason(ifp, state->reason);
2147 eloop_exit(ifp->ctx->eloop, EXIT_SUCCESS);
2177 eloop_timeout_add_sec(ifp->ctx->eloop,
2178 (time_t)lease->renewaltime, dhcp_renew, ifp);
2179 eloop_timeout_add_sec(ifp->ctx->eloop,
2180 (time_t)lease->rebindtime, dhcp_rebind, ifp);
2181 eloop_timeout_add_sec(ifp->ctx->eloop,
2182 (time_t)lease->leasetime, dhcp_expire, ifp);
2183 logger(ifp->ctx, LOG_DEBUG,
2186 ifp->name, lease->renewaltime, lease->rebindtime);
2195 if (write_lease(ifp, state->new) == -1)
2196 logger(ifp->ctx, LOG_ERR,
2200 ipv4_applyaddr(ifp);
2202 !(ifp->ctx->options & DHCPCD_FORKED))
2208 arp_close(ifp);
2212 astate = arp_new(ifp, &state->addr);
2222 arp_close(ifp);
2230 struct interface *ifp = arg;
2231 struct dhcp_state *state = D_STATE(ifp);
2233 dhcp_bind(ifp, NULL);
2235 dhcp_discover(ifp);
2260 dhcp_static(struct interface *ifp)
2265 state = D_STATE(ifp);
2266 ifo = ifp->options;
2268 logger(ifp->ctx, LOG_INFO,
2271 ifp->name);
2273 script_runreason(ifp, state->reason);
2278 eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp);
2279 dhcp_bind(ifp, NULL);
2284 dhcp_inform(struct interface *ifp)
2290 state = D_STATE(ifp);
2291 ifo = ifp->options;
2292 logger(ifp->ctx, LOG_INFO, "%s: informing peers of local address",
2293 ifp->name);
2294 if (ifp->ctx->options & DHCPCD_TEST) {
2299 state = D_STATE(ifp);
2300 ap = ipv4_iffindaddr(ifp, NULL, NULL);
2302 logger(ifp->ctx, LOG_INFO,
2305 ifp->name);
2307 script_runreason(ifp, state->reason);
2317 dhcp_bind(ifp, NULL);
2324 state->xid = dhcp_xid(ifp);
2325 send_inform(ifp);
2329 dhcp_reboot_newopts(struct interface *ifp, unsigned long long oldopts)
2332 struct dhcp_state *state = D_STATE(ifp);
2336 ifo = ifp->options;
2342 dhcp_drop(ifp, "EXPIRE");
2346 static void start_unicast_arp(struct interface *ifp);
2349 dhcp_reboot(struct interface *ifp)
2352 struct dhcp_state *state = D_STATE(ifp);
2357 ifo = ifp->options;
2361 if (ifo->options & DHCPCD_LINK && ifp->carrier == LINK_DOWN) {
2362 logger(ifp->ctx, LOG_INFO,
2363 "%s: waiting for carrier", ifp->name);
2367 dhcp_static(ifp);
2371 start_unicast_arp(ifp);
2374 logger(ifp->ctx, LOG_INFO, "%s: informing address of %s",
2375 ifp->name, inet_ntoa(state->lease.addr));
2376 dhcp_inform(ifp);
2380 dhcp_discover(ifp);
2386 logger(ifp->ctx, LOG_INFO, "%s: rebinding lease of %s",
2387 ifp->name, inet_ntoa(state->lease.addr));
2388 state->xid = dhcp_xid(ifp);
2390 eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp);
2395 eloop_timeout_add_sec(ifp->ctx->eloop,
2396 ifo->reboot, ipv4ll_start, ifp);
2399 eloop_timeout_add_sec(ifp->ctx->eloop,
2400 ifo->reboot, dhcp_timeout, ifp);
2402 eloop_timeout_add_sec(ifp->ctx->eloop,
2403 ifo->reboot, dhcp_expire, ifp);
2407 send_request(ifp);
2411 dhcp_drop(struct interface *ifp, const char *reason)
2418 state = D_STATE(ifp);
2422 eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp);
2428 ifp->carrier != LINK_UP ||
2429 ifp->options->options & DHCPCD_DEPARTED)
2431 eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp);
2433 dhcp_close(ifp);
2436 if (ifp->options->options & DHCPCD_RELEASE ||
2439 if (ifp->carrier != LINK_DOWN &&
2443 logger(ifp->ctx, LOG_INFO, "%s: releasing lease of %s",
2444 ifp->name, inet_ntoa(state->lease.addr));
2445 state->xid = dhcp_xid(ifp);
2446 send_message(ifp, DHCP_RELEASE, NULL);
2460 ipv4_applyaddr(ifp);
2464 ifp->options->options &= ~(DHCPCD_CSR_WARNED |
2470 const struct interface *ifp, const struct dhcp_message *dhcp,
2479 a = get_option_string(ifp->ctx, dhcp, DHO_MESSAGE);
2488 logger(ifp->ctx, LOG_ERR, "%s: %m", __func__);
2500 logger(ifp->ctx, LOG_ERR, "%s: %m", __func__);
2507 r = get_option_addr(ifp->ctx, &addr, dhcp, DHO_SERVERID);
2512 logger(ifp->ctx, lvl, "%s: %s %s %s `%s'",
2513 ifp->name, msg, tfrom, inet_ntoa(addr), sname);
2515 logger(ifp->ctx, lvl, "%s: %s %s %s %s `%s'",
2516 ifp->name, msg, a, tfrom, inet_ntoa(addr), sname);
2523 logger(ifp->ctx, lvl, "%s: %s %s %s",
2524 ifp->name, msg, tfrom, inet_ntoa(addr));
2526 logger(ifp->ctx, lvl, "%s: %s %s %s %s",
2527 ifp->name, msg, a, tfrom, inet_ntoa(addr));
2534 const struct interface *ifp, const struct dhcp_message *dhcp,
2538 log_dhcp1(lvl, msg, ifp, dhcp, from, 1);
2566 save_gateway_addr(struct interface *ifp, const uint8_t *gw_hwaddr)
2568 struct dhcp_state *state = D_STATE(ifp);
2569 memcpy(state->server_info.gw_hwaddr, gw_hwaddr, ifp->hwlen);
2570 state->server_info.gw_hwlen = ifp->hwlen;
2631 dhcp_probe_gw(struct interface *ifp)
2633 struct dhcp_state *state = D_STATE(ifp);
2637 if (get_option_addr(ifp->ctx, &gateway_addr,
2639 astate = arp_new(ifp, &gateway_addr);
2652 start_unicast_arp(struct interface *ifp)
2654 struct dhcp_state *state = D_STATE(ifp);
2665 if (state->server_info.gw_hwlen != ifp->hwlen)
2668 if (get_option_addr(ifp->ctx, &gwa, state->offer, DHO_ROUTER))
2671 astate = arp_new(ifp, &gwa);
2802 struct interface *ifp = arg;
2803 struct dhcp_state *state = D_STATE(ifp);
2805 logger(ifp->ctx, LOG_INFO, "%s: Handling deferred NAK", ifp->name);
2806 if (!(ifp->ctx->options & DHCPCD_TEST)) {
2807 dhcp_drop(ifp, "NAK");
2812 eloop_timeout_add_sec(ifp->ctx->eloop,
2813 state->nakoff, dhcp_discover, ifp);
2824 dhcp_handledhcp(struct interface *ifp, struct dhcp_message **dhcpp,
2827 struct dhcp_state *state = D_STATE(ifp);
2828 struct if_options *ifo = ifp->options;
2841 if (get_option_uint8(ifp->ctx, &type, dhcp, DHO_MESSAGETYPE) == -1)
2844 logger(ifp->ctx, LOG_DEBUG,
2846 ifp->name);
2850 logger(ifp->ctx, LOG_INFO, "%s: received %s with xid 0x%x",
2851 ifp->name, get_dhcp_op(type), state->xid);
2854 auth = get_option(ifp->ctx, dhcp, DHO_AUTHENTICATION, &auth_len);
2860 logger(ifp->ctx, LOG_DEBUG,
2861 "%s: dhcp_auth_validate: %m", ifp->name);
2863 ifp, dhcp, from, 0);
2867 logger(ifp->ctx, LOG_DEBUG,
2869 ifp->name, state->auth.token->secretid);
2871 logger(ifp->ctx, LOG_DEBUG,
2872 "%s: accepted reconfigure key", ifp->name);
2874 log_dhcp1(LOG_ERR, "no authentication", ifp, dhcp, from, 0);
2878 ifp, dhcp, from, 0);
2886 ifp, dhcp, from);
2891 ifp, dhcp, from);
2896 ifp, dhcp, from);
2899 log_dhcp(LOG_ERR, "Force Renew from", ifp, dhcp, from);
2903 eloop_timeout_delete(ifp->ctx->eloop,
2904 dhcp_renew, ifp);
2905 dhcp_renew(ifp);
2907 eloop_timeout_delete(ifp->ctx->eloop,
2908 send_inform, ifp);
2909 dhcp_inform(ifp);
2924 logger(ifp->ctx, LOG_DEBUG,
2926 ifp->name, ntohl(dhcp->xid), state->xid,
2936 get_option_uint8(ifp->ctx, &tmp, dhcp, (uint8_t)i) == 0)
2938 log_dhcp(LOG_WARNING, "reject DHCP", ifp, dhcp, from);
2944 if ((msg = get_option_string(ifp->ctx, dhcp, DHO_MESSAGE))) {
2945 logger(ifp->ctx, LOG_WARNING, "%s: message: %s",
2946 ifp->name, msg);
2952 log_dhcp(LOG_WARNING, "NAK (deferred):", ifp, dhcp, from);
2955 eloop_timeout_add_sec(ifp->ctx->eloop,
2956 DHCP_BASE, handle_nak, ifp);
2964 get_option_uint8(ifp->ctx, &tmp, dhcp, (uint8_t)i) != 0)
2973 log_dhcp(LOG_WARNING, "reject DHCP", ifp, dhcp, from);
2980 log_dhcp(LOG_WARNING, "no address given", ifp, dhcp, from);
2981 if ((msg = get_option_string(ifp->ctx, dhcp, DHO_MESSAGE))) {
2982 logger(ifp->ctx, LOG_WARNING,
2983 "%s: message: %s", ifp->name, msg);
2988 get_option_uint8(ifp->ctx, &tmp, dhcp,
2994 ifp, dhcp, from);
2995 dhcp_drop(ifp, "EXPIRE");
2996 arp_close(ifp);
2997 eloop_timeout_delete(ifp->ctx->eloop,
2998 NULL, ifp);
2999 eloop_timeout_add_sec(ifp->ctx->eloop,
3001 ifp);
3005 ifp, dhcp, from);
3006 eloop_timeout_delete(ifp->ctx->eloop,
3007 NULL, ifp);
3009 eloop_timeout_add_sec(ifp->ctx->eloop,
3010 DHCP_MAX, dhcp_discover, ifp);
3012 ipv4ll_start(ifp);
3015 logger(ifp->ctx, LOG_ERR,
3017 ifp->name, tmp);
3031 ifp, dhcp, from);
3036 ia = ipv4_iffindaddr(ifp, &lease->addr, NULL);
3039 ifp, dhcp, from);
3041 dhcp_decline(ifp);
3042 ipv4_deladdr(ifp, &ia->addr, &ia->net);
3043 eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp);
3044 eloop_timeout_add_sec(ifp->ctx->eloop,
3045 DHCP_RAND_MAX, dhcp_discover, ifp);
3057 ifp, dhcp, from);
3066 get_option_addr(ifp->ctx,
3069 log_dhcp(LOG_INFO, "offered", ifp, dhcp, from);
3073 if (ifp->ctx->options & DHCPCD_TEST) {
3079 script_runreason(ifp, state->reason);
3080 eloop_exit(ifp->ctx->eloop, EXIT_SUCCESS);
3083 eloop_timeout_delete(ifp->ctx->eloop, send_discover, ifp);
3084 eloop_timeout_delete(ifp->ctx->eloop, handle_nak, ifp);
3093 dhcp_request(ifp);
3101 ifp, dhcp, from);
3109 ifp, dhcp, from);
3115 log_dhcp(LOG_INFO, "acknowledged", ifp, dhcp, from);
3135 eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp);
3140 astate = arp_new(ifp, &addr);
3157 ia = ipv4_findaddr(ifp->ctx, &addr);
3159 astate = arp_new(ifp, &addr);
3171 if ((ifo->options & DHCPCD_ARPGW) && (dhcp_probe_gw(ifp))) {
3176 dhcp_bind(ifp, astate);
3250 struct interface *ifp = arg;
3256 const struct dhcp_state *state = D_CSTATE(ifp);
3261 bytes = (size_t)if_readrawpacket(ifp, ETHERTYPE_IP,
3262 ifp->ctx->packet, udp_dhcp_len, &flags);
3264 logger(ifp->ctx, LOG_ERR,
3265 "%s: dhcp if_readrawpacket: %m", ifp->name);
3266 dhcp_close(ifp);
3267 arp_close(ifp);
3270 if (valid_udp_packet(ifp->ctx->packet, bytes,
3273 logger(ifp->ctx, LOG_ERR,
3275 ifp->name, inet_ntoa(from));
3278 i = whitelisted_ip(ifp->options, from.s_addr);
3280 logger(ifp->ctx, LOG_WARNING,
3282 ifp->name, inet_ntoa(from));
3285 blacklisted_ip(ifp->options, from.s_addr) == 1)
3287 logger(ifp->ctx, LOG_WARNING,
3289 ifp->name, inet_ntoa(from));
3292 if (ifp->flags & IFF_POINTOPOINT &&
3295 logger(ifp->ctx, LOG_WARNING,
3297 ifp->name, inet_ntoa(from));
3299 bytes = get_udp_data(&pp, ifp->ctx->packet);
3301 logger(ifp->ctx, LOG_ERR,
3303 ifp->name, inet_ntoa(from));
3309 logger(ifp->ctx, LOG_ERR,
3316 logger(ifp->ctx, LOG_DEBUG, "%s: bogus cookie from %s",
3317 ifp->name, inet_ntoa(from));
3321 if (ifp->hwlen <= sizeof(dhcp->chaddr) &&
3322 memcmp(dhcp->chaddr, ifp->hwaddr, ifp->hwlen))
3326 logger(ifp->ctx, LOG_DEBUG,
3328 ifp->name, ntohl(dhcp->xid),
3333 dhcp_handledhcp(ifp, &dhcp, &from);
3359 dhcp_open(struct interface *ifp)
3363 if (ifp->ctx->packet == NULL) {
3364 ifp->ctx->packet = malloc(udp_dhcp_len);
3365 if (ifp->ctx->packet == NULL) {
3366 logger(ifp->ctx, LOG_ERR, "%s: %m", __func__);
3371 state = D_STATE(ifp);
3373 state->raw_fd = if_openrawsocket(ifp, ETHERTYPE_IP);
3376 logger(ifp->ctx, LOG_ERR,
3380 ifp->options->options &= ~DHCPCD_IPV4;
3382 logger(ifp->ctx, LOG_ERR, "%s: %s: %m",
3383 __func__, ifp->name);
3386 eloop_event_add(ifp->ctx->eloop,
3387 state->raw_fd, dhcp_handlepacket, ifp, NULL, NULL);
3393 dhcp_dump(struct interface *ifp)
3397 ifp->if_data[IF_DATA_DHCP] = state = calloc(1, sizeof(*state));
3403 AF_INET, ifp, "");
3404 state->new = read_lease(ifp);
3406 logger(ifp->ctx, LOG_ERR, "%s: %s: %m",
3407 *ifp->name ? ifp->name : state->leasefile, __func__);
3411 return script_runreason(ifp, state->reason);
3414 logger(ifp->ctx, LOG_ERR, "%s: %m", __func__);
3419 dhcp_free(struct interface *ifp)
3421 struct dhcp_state *state = D_STATE(ifp);
3424 dhcp_close(ifp);
3425 arp_close(ifp);
3433 ifp->if_data[IF_DATA_DHCP] = NULL;
3436 ctx = ifp->ctx;
3440 TAILQ_FOREACH(ifp, ctx->ifaces, next) {
3441 if (D_STATE(ifp))
3445 if (ifp == NULL) {
3460 dhcp_init(struct interface *ifp)
3467 state = D_STATE(ifp);
3469 ifp->if_data[IF_DATA_DHCP] = calloc(1, sizeof(*state));
3470 state = D_STATE(ifp);
3478 if_initrt(ifp);
3485 AF_INET, ifp, "");
3487 ifo = ifp->options;
3504 state->clientid = malloc(ifp->ctx->duid_len + 6);
3507 state->clientid[0] =(uint8_t)(ifp->ctx->duid_len + 5);
3510 memcpy(state->clientid + 6, ifp->ctx->duid,
3511 ifp->ctx->duid_len);
3513 len = (uint8_t)(ifp->hwlen + 1);
3518 state->clientid[1] = (uint8_t)ifp->family;
3519 memcpy(state->clientid + 2, ifp->hwaddr,
3520 ifp->hwlen);
3530 logger(ifp->ctx, LOG_DEBUG, "%s: using ClientID %s", ifp->name,
3533 else if (ifp->hwlen)
3534 logger(ifp->ctx, LOG_DEBUG, "%s: using hwaddr %s", ifp->name,
3535 hwaddr_ntoa(ifp->hwaddr, ifp->hwlen, buf, sizeof(buf)));
3539 logger(ifp->ctx, LOG_ERR, "%s: error making ClientID: %m", __func__);
3546 struct interface *ifp = arg;
3547 struct if_options *ifo = ifp->options;
3558 if (ifp->ctx->udp_fd == -1) {
3559 ifp->ctx->udp_fd = dhcp_openudp(NULL);
3560 if (ifp->ctx->udp_fd == -1) {
3564 logger(ifp->ctx, LOG_ERR,
3567 eloop_event_add(ifp->ctx->eloop,
3568 ifp->ctx->udp_fd, dhcp_handleudp,
3569 ifp->ctx, NULL, NULL);
3572 if (dhcp_init(ifp) == -1) {
3573 logger(ifp->ctx, LOG_ERR, "%s: dhcp_init: %m", ifp->name);
3577 state = D_STATE(ifp);
3585 astate = arp_new(ifp, NULL);
3595 dhcp_static(ifp);
3599 if (ifo->options & DHCPCD_DHCP && dhcp_open(ifp) == -1)
3603 dhcp_inform(ifp);
3606 if (ifp->hwlen == 0 && ifo->clientid[0] == '\0') {
3607 logger(ifp->ctx, LOG_WARNING,
3608 "%s: needs a clientid to configure", ifp->name);
3609 dhcp_drop(ifp, "FAIL");
3610 eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp);
3614 nolease = state->offer && ifp->ctx->options & DHCPCD_TEST;
3616 state->offer = read_lease(ifp);
3624 ia = ipv4_iffindaddr(ifp, &addr, NULL);
3627 if ((IS_BOOTP(ifp, state->offer) &&
3632 (!IS_BOOTP(ifp, state->offer) &&
3641 get_lease(ifp->ctx, &state->lease, state->offer);
3644 ipv4_iffindaddr(ifp, &state->lease.addr, &state->lease.net))
3656 ipv4_buildroutes(ifp->ctx);
3658 logger(ifp->ctx, LOG_ERR, "%s: %m", __func__);
3675 logger(ifp->ctx, LOG_DEBUG,
3676 "%s: discarding expired lease", ifp->name);
3694 dhcp_drop(ifp, "EXPIRE");
3711 ipv4ll_start(ifp);
3717 dhcp_discover(ifp);
3719 dhcp_reboot(ifp);
3723 dhcp_start(struct interface *ifp)
3727 if (!(ifp->options->options & DHCPCD_IPV4))
3735 logger(ifp->ctx, LOG_DEBUG,
3737 ifp->name, timespec_to_double(&tv));
3739 eloop_timeout_add_tv(ifp->ctx->eloop, &tv, dhcp_start1, ifp);
3743 dhcp_handleifa(int cmd, struct interface *ifp,
3753 state = D_STATE(ifp);
3761 logger(ifp->ctx, LOG_INFO,
3763 ifp->name, inet_ntoa(state->addr),
3765 dhcp_drop(ifp, "EXPIRE");
3773 ifo = ifp->options;
3776 dhcp_inform(ifp);
3797 ipv4_buildroutes(ifp->ctx);
3798 script_runreason(ifp, state->reason);
3801 state->xid = dhcp_xid(ifp);
3805 dhcp_inform(ifp);