• Home
  • Raw
  • Download

Lines Matching refs:ifp

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