Sync with dhcpcd-9.3.2diff -r1.41 -r1.42 src/external/bsd/dhcpcd/dist/src/dhcp.c
(roy)
--- src/external/bsd/dhcpcd/dist/src/dhcp.c 2020/10/12 14:09:03 1.41
+++ src/external/bsd/dhcpcd/dist/src/dhcp.c 2020/11/01 14:24:01 1.42
@@ -1510,53 +1510,74 @@ again: | @@ -1510,53 +1510,74 @@ again: | |||
1510 | goto again; | 1510 | goto again; | |
1511 | } | 1511 | } | |
1512 | 1512 | |||
1513 | /* We can't do this when sharing leases across interfaes */ | 1513 | /* We can't do this when sharing leases across interfaes */ | |
1514 | #if 0 | 1514 | #if 0 | |
1515 | /* As the XID changes, re-apply the filter. */ | 1515 | /* As the XID changes, re-apply the filter. */ | |
1516 | if (state->bpf_fd != -1) { | 1516 | if (state->bpf_fd != -1) { | |
1517 | if (bpf_bootp(ifp, state->bpf_fd) == -1) | 1517 | if (bpf_bootp(ifp, state->bpf_fd) == -1) | |
1518 | logerr(__func__); /* try to continue */ | 1518 | logerr(__func__); /* try to continue */ | |
1519 | } | 1519 | } | |
1520 | #endif | 1520 | #endif | |
1521 | } | 1521 | } | |
1522 | 1522 | |||
1523 | void | 1523 | static void | |
1524 | dhcp_close(struct interface *ifp) | 1524 | dhcp_closebpf(struct interface *ifp) | |
1525 | { | 1525 | { | |
1526 | struct dhcpcd_ctx *ctx = ifp->ctx; | 1526 | struct dhcpcd_ctx *ctx = ifp->ctx; | |
1527 | struct dhcp_state *state = D_STATE(ifp); | 1527 | struct dhcp_state *state = D_STATE(ifp); | |
1528 | 1528 | |||
1529 | if (state == NULL) | |||
1530 | return; | |||
1531 | ||||
1532 | #ifdef PRIVSEP | 1529 | #ifdef PRIVSEP | |
1533 | if (IN_PRIVSEP_SE(ctx)) { | 1530 | if (IN_PRIVSEP_SE(ctx)) | |
1534 | ps_bpf_closebootp(ifp); | 1531 | ps_bpf_closebootp(ifp); | |
1535 | if (state->addr != NULL) | |||
1536 | ps_inet_closebootp(state->addr); | |||
1537 | } | |||
1538 | #endif | 1532 | #endif | |
1539 | 1533 | |||
1540 | if (state->bpf != NULL) { | 1534 | if (state->bpf != NULL) { | |
1541 | eloop_event_delete(ctx->eloop, state->bpf->bpf_fd); | 1535 | eloop_event_delete(ctx->eloop, state->bpf->bpf_fd); | |
1542 | bpf_close(state->bpf); | 1536 | bpf_close(state->bpf); | |
1543 | state->bpf = NULL; | 1537 | state->bpf = NULL; | |
1544 | } | 1538 | } | |
1539 | } | |||
1540 | ||||
1541 | static void | |||
1542 | dhcp_closeinet(struct interface *ifp) | |||
1543 | { | |||
1544 | struct dhcpcd_ctx *ctx = ifp->ctx; | |||
1545 | struct dhcp_state *state = D_STATE(ifp); | |||
1546 | ||||
1547 | #ifdef PRIVSEP | |||
1548 | if (IN_PRIVSEP_SE(ctx)) { | |||
1549 | if (state->addr != NULL) | |||
1550 | ps_inet_closebootp(state->addr); | |||
1551 | } | |||
1552 | #endif | |||
1553 | ||||
1545 | if (state->udp_rfd != -1) { | 1554 | if (state->udp_rfd != -1) { | |
1546 | eloop_event_delete(ctx->eloop, state->udp_rfd); | 1555 | eloop_event_delete(ctx->eloop, state->udp_rfd); | |
1547 | close(state->udp_rfd); | 1556 | close(state->udp_rfd); | |
1548 | state->udp_rfd = -1; | 1557 | state->udp_rfd = -1; | |
1549 | } | 1558 | } | |
1559 | } | |||
1560 | ||||
1561 | void | |||
1562 | dhcp_close(struct interface *ifp) | |||
1563 | { | |||
1564 | struct dhcp_state *state = D_STATE(ifp); | |||
1565 | ||||
1566 | if (state == NULL) | |||
1567 | return; | |||
1568 | ||||
1569 | dhcp_closebpf(ifp); | |||
1570 | dhcp_closeinet(ifp); | |||
1550 | 1571 | |||
1551 | state->interval = 0; | 1572 | state->interval = 0; | |
1552 | } | 1573 | } | |
1553 | 1574 | |||
1554 | int | 1575 | int | |
1555 | dhcp_openudp(struct in_addr *ia) | 1576 | dhcp_openudp(struct in_addr *ia) | |
1556 | { | 1577 | { | |
1557 | int s; | 1578 | int s; | |
1558 | struct sockaddr_in sin; | 1579 | struct sockaddr_in sin; | |
1559 | int n; | 1580 | int n; | |
1560 | 1581 | |||
1561 | if ((s = xsocket(PF_INET, SOCK_DGRAM | SOCK_CXNB, IPPROTO_UDP)) == -1) | 1582 | if ((s = xsocket(PF_INET, SOCK_DGRAM | SOCK_CXNB, IPPROTO_UDP)) == -1) | |
1562 | return -1; | 1583 | return -1; | |
@@ -2051,32 +2072,34 @@ dhcp_addr_duplicated(struct interface *i | @@ -2051,32 +2072,34 @@ dhcp_addr_duplicated(struct interface *i | |||
2051 | #define NOT_ONLY_SELF (DHCPCD_MASTER | DHCPCD_IPV6RS | DHCPCD_DHCP6) | 2072 | #define NOT_ONLY_SELF (DHCPCD_MASTER | DHCPCD_IPV6RS | DHCPCD_DHCP6) | |
2052 | if (!(ctx->options & NOT_ONLY_SELF)) | 2073 | if (!(ctx->options & NOT_ONLY_SELF)) | |
2053 | eloop_exit(ifp->ctx->eloop, EXIT_FAILURE); | 2074 | eloop_exit(ifp->ctx->eloop, EXIT_FAILURE); | |
2054 | return deleted; | 2075 | return deleted; | |
2055 | } | 2076 | } | |
2056 | eloop_timeout_add_sec(ifp->ctx->eloop, | 2077 | eloop_timeout_add_sec(ifp->ctx->eloop, | |
2057 | DHCP_RAND_MAX, dhcp_discover, ifp); | 2078 | DHCP_RAND_MAX, dhcp_discover, ifp); | |
2058 | return deleted; | 2079 | return deleted; | |
2059 | } | 2080 | } | |
2060 | #endif | 2081 | #endif | |
2061 | 2082 | |||
2062 | #ifdef ARP | 2083 | #ifdef ARP | |
2063 | #ifdef KERNEL_RFC5227 | 2084 | #ifdef KERNEL_RFC5227 | |
2085 | #ifdef ARPING | |||
2064 | static void | 2086 | static void | |
2065 | dhcp_arp_announced(struct arp_state *state) | 2087 | dhcp_arp_announced(struct arp_state *state) | |
2066 | { | 2088 | { | |
2067 | 2089 | |||
2068 | arp_free(state); | 2090 | arp_free(state); | |
2069 | } | 2091 | } | |
2092 | #endif | |||
2070 | #else | 2093 | #else | |
2071 | static void | 2094 | static void | |
2072 | dhcp_arp_defend_failed(struct arp_state *astate) | 2095 | dhcp_arp_defend_failed(struct arp_state *astate) | |
2073 | { | 2096 | { | |
2074 | struct interface *ifp = astate->iface; | 2097 | struct interface *ifp = astate->iface; | |
2075 | 2098 | |||
2076 | dhcp_drop(ifp, "EXPIRED"); | 2099 | dhcp_drop(ifp, "EXPIRED"); | |
2077 | dhcp_start1(ifp); | 2100 | dhcp_start1(ifp); | |
2078 | } | 2101 | } | |
2079 | #endif | 2102 | #endif | |
2080 | 2103 | |||
2081 | #if !defined(KERNEL_RFC5227) || defined(ARPING) | 2104 | #if !defined(KERNEL_RFC5227) || defined(ARPING) | |
2082 | static void dhcp_arp_not_found(struct arp_state *); | 2105 | static void dhcp_arp_not_found(struct arp_state *); | |
@@ -2311,43 +2334,44 @@ dhcp_bind(struct interface *ifp) | @@ -2311,43 +2334,44 @@ dhcp_bind(struct interface *ifp) | |||
2311 | " seconds", | 2334 | " seconds", | |
2312 | ifp->name, lease->renewaltime, lease->rebindtime); | 2335 | ifp->name, lease->renewaltime, lease->rebindtime); | |
2313 | } | 2336 | } | |
2314 | state->state = DHS_BOUND; | 2337 | state->state = DHS_BOUND; | |
2315 | if (!state->lease.frominfo && | 2338 | if (!state->lease.frominfo && | |
2316 | !(ifo->options & (DHCPCD_INFORM | DHCPCD_STATIC))) { | 2339 | !(ifo->options & (DHCPCD_INFORM | DHCPCD_STATIC))) { | |
2317 | logdebugx("%s: writing lease: %s", | 2340 | logdebugx("%s: writing lease: %s", | |
2318 | ifp->name, state->leasefile); | 2341 | ifp->name, state->leasefile); | |
2319 | if (dhcp_writefile(ifp->ctx, state->leasefile, 0640, | 2342 | if (dhcp_writefile(ifp->ctx, state->leasefile, 0640, | |
2320 | state->new, state->new_len) == -1) | 2343 | state->new, state->new_len) == -1) | |
2321 | logerr("dhcp_writefile: %s", state->leasefile); | 2344 | logerr("dhcp_writefile: %s", state->leasefile); | |
2322 | } | 2345 | } | |
2323 | 2346 | |||
2347 | old_state = state->added; | |||
2348 | ||||
2324 | /* Close the BPF filter as we can now receive DHCP messages | 2349 | /* Close the BPF filter as we can now receive DHCP messages | |
2325 | * on a UDP socket. */ | 2350 | * on a UDP socket. */ | |
2326 | old_state = state->added; | 2351 | dhcp_closebpf(ifp); | |
2327 | if (ctx->options & DHCPCD_MASTER || | |||
2328 | state->old == NULL || | |||
2329 | state->old->yiaddr != state->new->yiaddr || old_state & STATE_FAKE) | |||
2330 | dhcp_close(ifp); | |||
2331 | 2352 | |||
2353 | /* Add the address */ | |||
2332 | ipv4_applyaddr(ifp); | 2354 | ipv4_applyaddr(ifp); | |
2333 | 2355 | |||
2334 | /* If not in master mode, open an address specific socket. */ | 2356 | /* If not in master mode, open an address specific socket. */ | |
2335 | if (ctx->options & DHCPCD_MASTER || | 2357 | if (ctx->options & DHCPCD_MASTER || | |
2336 | (state->old != NULL && | 2358 | (state->old != NULL && | |
2337 | state->old->yiaddr == state->new->yiaddr && | 2359 | state->old->yiaddr == state->new->yiaddr && | |
2338 | old_state & STATE_ADDED && !(old_state & STATE_FAKE))) | 2360 | old_state & STATE_ADDED && !(old_state & STATE_FAKE))) | |
2339 | return; | 2361 | return; | |
2340 | 2362 | |||
2363 | dhcp_closeinet(ifp); | |||
2364 | ||||
2341 | #ifdef PRIVSEP | 2365 | #ifdef PRIVSEP | |
2342 | if (IN_PRIVSEP_SE(ctx)) { | 2366 | if (IN_PRIVSEP_SE(ctx)) { | |
2343 | if (ps_inet_openbootp(state->addr) == -1) | 2367 | if (ps_inet_openbootp(state->addr) == -1) | |
2344 | logerr(__func__); | 2368 | logerr(__func__); | |
2345 | return; | 2369 | return; | |
2346 | } | 2370 | } | |
2347 | #endif | 2371 | #endif | |
2348 | 2372 | |||
2349 | state->udp_rfd = dhcp_openudp(&state->addr->addr); | 2373 | state->udp_rfd = dhcp_openudp(&state->addr->addr); | |
2350 | if (state->udp_rfd == -1) { | 2374 | if (state->udp_rfd == -1) { | |
2351 | logerr(__func__); | 2375 | logerr(__func__); | |
2352 | /* Address sharing without master mode is not supported. | 2376 | /* Address sharing without master mode is not supported. | |
2353 | * It's also possible another DHCP client could be running, | 2377 | * It's also possible another DHCP client could be running, | |
@@ -2916,26 +2940,28 @@ dhcp_redirect_dhcp(struct interface *ifp | @@ -2916,26 +2940,28 @@ dhcp_redirect_dhcp(struct interface *ifp | |||
2916 | 2940 | |||
2917 | static void | 2941 | static void | |
2918 | dhcp_handledhcp(struct interface *ifp, struct bootp *bootp, size_t bootp_len, | 2942 | dhcp_handledhcp(struct interface *ifp, struct bootp *bootp, size_t bootp_len, | |
2919 | const struct in_addr *from) | 2943 | const struct in_addr *from) | |
2920 | { | 2944 | { | |
2921 | struct dhcp_state *state = D_STATE(ifp); | 2945 | struct dhcp_state *state = D_STATE(ifp); | |
2922 | struct if_options *ifo = ifp->options; | 2946 | struct if_options *ifo = ifp->options; | |
2923 | struct dhcp_lease *lease = &state->lease; | 2947 | struct dhcp_lease *lease = &state->lease; | |
2924 | uint8_t type, tmp; | 2948 | uint8_t type, tmp; | |
2925 | struct in_addr addr; | 2949 | struct in_addr addr; | |
2926 | unsigned int i; | 2950 | unsigned int i; | |
2927 | char *msg; | 2951 | char *msg; | |
2928 | bool bootp_copied; | 2952 | bool bootp_copied; | |
2953 | uint32_t v6only_time = 0; | |||
2954 | bool use_v6only = false; | |||
2929 | #ifdef AUTH | 2955 | #ifdef AUTH | |
2930 | const uint8_t *auth; | 2956 | const uint8_t *auth; | |
2931 | size_t auth_len; | 2957 | size_t auth_len; | |
2932 | #endif | 2958 | #endif | |
2933 | #ifdef IN_IFF_DUPLICATED | 2959 | #ifdef IN_IFF_DUPLICATED | |
2934 | struct ipv4_addr *ia; | 2960 | struct ipv4_addr *ia; | |
2935 | #endif | 2961 | #endif | |
2936 | 2962 | |||
2937 | #define LOGDHCP0(l, m) \ | 2963 | #define LOGDHCP0(l, m) \ | |
2938 | log_dhcp((l), (m), ifp, bootp, bootp_len, from, 0) | 2964 | log_dhcp((l), (m), ifp, bootp, bootp_len, from, 0) | |
2939 | #define LOGDHCP(l, m) \ | 2965 | #define LOGDHCP(l, m) \ | |
2940 | log_dhcp((l), (m), ifp, bootp, bootp_len, from, 1) | 2966 | log_dhcp((l), (m), ifp, bootp, bootp_len, from, 1) | |
2941 | 2967 | |||
@@ -3133,26 +3159,43 @@ dhcp_handledhcp(struct interface *ifp, s | @@ -3133,26 +3159,43 @@ dhcp_handledhcp(struct interface *ifp, s | |||
3133 | { | 3159 | { | |
3134 | /* If we are BOOTP, then ignore the need for serverid. | 3160 | /* If we are BOOTP, then ignore the need for serverid. | |
3135 | * To ignore BOOTP, require dhcp_message_type. | 3161 | * To ignore BOOTP, require dhcp_message_type. | |
3136 | * However, nothing really stops BOOTP from providing | 3162 | * However, nothing really stops BOOTP from providing | |
3137 | * DHCP style options as well so the above isn't | 3163 | * DHCP style options as well so the above isn't | |
3138 | * always true. */ | 3164 | * always true. */ | |
3139 | if (type == 0 && i == DHO_SERVERID) | 3165 | if (type == 0 && i == DHO_SERVERID) | |
3140 | continue; | 3166 | continue; | |
3141 | LOGDHCP(LOG_WARNING, "reject DHCP"); | 3167 | LOGDHCP(LOG_WARNING, "reject DHCP"); | |
3142 | return; | 3168 | return; | |
3143 | } | 3169 | } | |
3144 | } | 3170 | } | |
3145 | 3171 | |||
3172 | if (has_option_mask(ifo->requestmask, DHO_IPV6_PREFERRED_ONLY)) { | |||
3173 | if (get_option_uint32(ifp->ctx, &v6only_time, bootp, bootp_len, | |||
3174 | DHO_IPV6_PREFERRED_ONLY) == 0 && | |||
3175 | (state->state == DHS_DISCOVER || state->state == DHS_REBOOT)) | |||
3176 | { | |||
3177 | char v6msg[128]; | |||
3178 | ||||
3179 | use_v6only = true; | |||
3180 | if (v6only_time < MIN_V6ONLY_WAIT) | |||
3181 | v6only_time = MIN_V6ONLY_WAIT; | |||
3182 | snprintf(v6msg, sizeof(v6msg), | |||
3183 | "IPv6-Only Preferred received (%u seconds)", | |||
3184 | v6only_time); | |||
3185 | LOGDHCP(LOG_INFO, v6msg); | |||
3186 | } | |||
3187 | } | |||
3188 | ||||
3146 | /* DHCP Auto-Configure, RFC 2563 */ | 3189 | /* DHCP Auto-Configure, RFC 2563 */ | |
3147 | if (type == DHCP_OFFER && bootp->yiaddr == 0) { | 3190 | if (type == DHCP_OFFER && bootp->yiaddr == 0) { | |
3148 | LOGDHCP(LOG_WARNING, "no address given"); | 3191 | LOGDHCP(LOG_WARNING, "no address given"); | |
3149 | if ((msg = get_option_string(ifp->ctx, | 3192 | if ((msg = get_option_string(ifp->ctx, | |
3150 | bootp, bootp_len, DHO_MESSAGE))) | 3193 | bootp, bootp_len, DHO_MESSAGE))) | |
3151 | { | 3194 | { | |
3152 | logwarnx("%s: message: %s", ifp->name, msg); | 3195 | logwarnx("%s: message: %s", ifp->name, msg); | |
3153 | free(msg); | 3196 | free(msg); | |
3154 | } | 3197 | } | |
3155 | #ifdef IPV4LL | 3198 | #ifdef IPV4LL | |
3156 | if (state->state == DHS_DISCOVER && | 3199 | if (state->state == DHS_DISCOVER && | |
3157 | get_option_uint8(ifp->ctx, &tmp, bootp, bootp_len, | 3200 | get_option_uint8(ifp->ctx, &tmp, bootp, bootp_len, | |
3158 | DHO_AUTOCONFIGURE) == 0) | 3201 | DHO_AUTOCONFIGURE) == 0) | |
@@ -3167,32 +3210,42 @@ dhcp_handledhcp(struct interface *ifp, s | @@ -3167,32 +3210,42 @@ dhcp_handledhcp(struct interface *ifp, s | |||
3167 | break; | 3210 | break; | |
3168 | case 1: | 3211 | case 1: | |
3169 | LOGDHCP(LOG_WARNING, "IPv4LL enabled from"); | 3212 | LOGDHCP(LOG_WARNING, "IPv4LL enabled from"); | |
3170 | ipv4ll_start(ifp); | 3213 | ipv4ll_start(ifp); | |
3171 | break; | 3214 | break; | |
3172 | default: | 3215 | default: | |
3173 | logerrx("%s: unknown auto configuration " | 3216 | logerrx("%s: unknown auto configuration " | |
3174 | "option %d", | 3217 | "option %d", | |
3175 | ifp->name, tmp); | 3218 | ifp->name, tmp); | |
3176 | break; | 3219 | break; | |
3177 | } | 3220 | } | |
3178 | eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp); | 3221 | eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp); | |
3179 | eloop_timeout_add_sec(ifp->ctx->eloop, | 3222 | eloop_timeout_add_sec(ifp->ctx->eloop, | |
3180 | DHCP_MAX, dhcp_discover, ifp); | 3223 | use_v6only ? v6only_time : DHCP_MAX, | |
3224 | dhcp_discover, ifp); | |||
3181 | } | 3225 | } | |
3182 | #endif | 3226 | #endif | |
3183 | return; | 3227 | return; | |
3184 | } | 3228 | } | |
3185 | 3229 | |||
3230 | if (use_v6only) { | |||
3231 | dhcp_drop(ifp, "EXPIRE"); | |||
3232 | dhcp_unlink(ifp->ctx, state->leasefile); | |||
3233 | eloop_timeout_delete(ifp->ctx->eloop, NULL, ifp); | |||
3234 | eloop_timeout_add_sec(ifp->ctx->eloop, v6only_time, | |||
3235 | dhcp_discover, ifp); | |||
3236 | return; | |||
3237 | } | |||
3238 | ||||
3186 | /* Ensure that the address offered is valid */ | 3239 | /* Ensure that the address offered is valid */ | |
3187 | if ((type == 0 || type == DHCP_OFFER || type == DHCP_ACK) && | 3240 | if ((type == 0 || type == DHCP_OFFER || type == DHCP_ACK) && | |
3188 | (bootp->ciaddr == INADDR_ANY || bootp->ciaddr == INADDR_BROADCAST) | 3241 | (bootp->ciaddr == INADDR_ANY || bootp->ciaddr == INADDR_BROADCAST) | |
3189 | && | 3242 | && | |
3190 | (bootp->yiaddr == INADDR_ANY || bootp->yiaddr == INADDR_BROADCAST)) | 3243 | (bootp->yiaddr == INADDR_ANY || bootp->yiaddr == INADDR_BROADCAST)) | |
3191 | { | 3244 | { | |
3192 | LOGDHCP(LOG_WARNING, "reject invalid address"); | 3245 | LOGDHCP(LOG_WARNING, "reject invalid address"); | |
3193 | return; | 3246 | return; | |
3194 | } | 3247 | } | |
3195 | 3248 | |||
3196 | #ifdef IN_IFF_DUPLICATED | 3249 | #ifdef IN_IFF_DUPLICATED | |
3197 | ia = ipv4_iffindaddr(ifp, &lease->addr, NULL); | 3250 | ia = ipv4_iffindaddr(ifp, &lease->addr, NULL); | |
3198 | if (ia && ia->addr_flags & IN_IFF_DUPLICATED) { | 3251 | if (ia && ia->addr_flags & IN_IFF_DUPLICATED) { |
--- src/external/bsd/dhcpcd/dist/src/Attic/dhcpcd.8.in 2020/09/06 14:55:34 1.8
+++ src/external/bsd/dhcpcd/dist/src/Attic/dhcpcd.8.in 2020/11/01 14:24:01 1.9
@@ -14,27 +14,27 @@ | @@ -14,27 +14,27 @@ | |||
14 | .\" | 14 | .\" | |
15 | .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | 15 | .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | |
16 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 16 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
17 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 17 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
18 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | 18 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | |
19 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 19 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
20 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 20 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
21 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 21 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
22 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 22 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
23 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 23 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
24 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 24 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
25 | .\" SUCH DAMAGE. | 25 | .\" SUCH DAMAGE. | |
26 | .\" | 26 | .\" | |
27 | .Dd September 2, 2020 | 27 | .Dd October 30, 2020 | |
28 | .Dt DHCPCD 8 | 28 | .Dt DHCPCD 8 | |
29 | .Os | 29 | .Os | |
30 | .Sh NAME | 30 | .Sh NAME | |
31 | .Nm dhcpcd | 31 | .Nm dhcpcd | |
32 | .Nd a DHCP client | 32 | .Nd a DHCP client | |
33 | .Sh SYNOPSIS | 33 | .Sh SYNOPSIS | |
34 | .Nm | 34 | .Nm | |
35 | .Op Fl 146ABbDdEGgHJKLMNPpqTV | 35 | .Op Fl 146ABbDdEGgHJKLMNPpqTV | |
36 | .Op Fl C , Fl Fl nohook Ar hook | 36 | .Op Fl C , Fl Fl nohook Ar hook | |
37 | .Op Fl c , Fl Fl script Ar script | 37 | .Op Fl c , Fl Fl script Ar script | |
38 | .Op Fl e , Fl Fl env Ar value | 38 | .Op Fl e , Fl Fl env Ar value | |
39 | .Op Fl F , Fl Fl fqdn Ar FQDN | 39 | .Op Fl F , Fl Fl fqdn Ar FQDN | |
40 | .Op Fl f , Fl Fl config Ar file | 40 | .Op Fl f , Fl Fl config Ar file | |
@@ -836,23 +836,15 @@ Control socket to per interface daemon. | @@ -836,23 +836,15 @@ Control socket to per interface daemon. | |||
836 | .Xr resolv.conf 5 , | 836 | .Xr resolv.conf 5 , | |
837 | .Xr dhcpcd-run-hooks 8 , | 837 | .Xr dhcpcd-run-hooks 8 , | |
838 | .Xr resolvconf 8 | 838 | .Xr resolvconf 8 | |
839 | .Sh STANDARDS | 839 | .Sh STANDARDS | |
840 | RFC\ 951, RFC\ 1534, RFC\ 2104, RFC\ 2131, RFC\ 2132, RFC\ 2563, RFC\ 2855, | 840 | RFC\ 951, RFC\ 1534, RFC\ 2104, RFC\ 2131, RFC\ 2132, RFC\ 2563, RFC\ 2855, | |
841 | RFC\ 3004, RFC\ 3118, RFC\ 3203, RFC\ 3315, RFC\ 3361, RFC\ 3633, RFC\ 3396, | 841 | RFC\ 3004, RFC\ 3118, RFC\ 3203, RFC\ 3315, RFC\ 3361, RFC\ 3633, RFC\ 3396, | |
842 | RFC\ 3397, RFC\ 3442, RFC\ 3495, RFC\ 3925, RFC\ 3927, RFC\ 4039, RFC\ 4075, | 842 | RFC\ 3397, RFC\ 3442, RFC\ 3495, RFC\ 3925, RFC\ 3927, RFC\ 4039, RFC\ 4075, | |
843 | RFC\ 4242, RFC\ 4361, RFC\ 4390, RFC\ 4702, RFC\ 4074, RFC\ 4861, RFC\ 4833, | 843 | RFC\ 4242, RFC\ 4361, RFC\ 4390, RFC\ 4702, RFC\ 4074, RFC\ 4861, RFC\ 4833, | |
844 | RFC\ 4941, RFC\ 5227, RFC\ 5942, RFC\ 5969, RFC\ 6106, RFC\ 6334, RFC\ 6355, | 844 | RFC\ 4941, RFC\ 5227, RFC\ 5942, RFC\ 5969, RFC\ 6106, RFC\ 6334, RFC\ 6355, | |
845 | RFC\ 6603, RFC\ 6704, RFC\ 7217, RFC\ 7550, RFC\ 7844. | 845 | RFC\ 6603, RFC\ 6704, RFC\ 7217, RFC\ 7550, RFC\ 7844. | |
846 | .Sh AUTHORS | 846 | .Sh AUTHORS | |
847 | .An Roy Marples Aq Mt roy@marples.name | 847 | .An Roy Marples Aq Mt roy@marples.name | |
848 | .Sh BUGS | 848 | .Sh BUGS | |
849 | If | |||
850 | .Nm | |||
851 | is running in a | |||
852 | .Xr chroot 2 | |||
853 | then re-opening the | |||
854 | .Fl Fl logfile | |||
855 | from SIGUSR2 may not work. | |||
856 | .Pp | |||
857 | Please report them to | 849 | Please report them to | |
858 | .Lk http://roy.marples.name/projects/dhcpcd | 850 | .Lk http://roy.marples.name/projects/dhcpcd |
--- src/external/bsd/dhcpcd/dist/src/dhcpcd.c 2020/10/12 14:09:03 1.44
+++ src/external/bsd/dhcpcd/dist/src/dhcpcd.c 2020/11/01 14:24:01 1.45
@@ -1412,30 +1412,35 @@ dhcpcd_signal_cb(int sig, void *arg) | @@ -1412,30 +1412,35 @@ dhcpcd_signal_cb(int sig, void *arg) | |||
1412 | loginfox(sigmsg, "SIGHUP", "rebinding"); | 1412 | loginfox(sigmsg, "SIGHUP", "rebinding"); | |
1413 | reload_config(ctx); | 1413 | reload_config(ctx); | |
1414 | /* Preserve any options passed on the commandline | 1414 | /* Preserve any options passed on the commandline | |
1415 | * when we were started. */ | 1415 | * when we were started. */ | |
1416 | reconf_reboot(ctx, 1, ctx->argc, ctx->argv, | 1416 | reconf_reboot(ctx, 1, ctx->argc, ctx->argv, | |
1417 | ctx->argc - ctx->ifc); | 1417 | ctx->argc - ctx->ifc); | |
1418 | return; | 1418 | return; | |
1419 | case SIGUSR1: | 1419 | case SIGUSR1: | |
1420 | loginfox(sigmsg, "SIGUSR1", "renewing"); | 1420 | loginfox(sigmsg, "SIGUSR1", "renewing"); | |
1421 | dhcpcd_renew(ctx); | 1421 | dhcpcd_renew(ctx); | |
1422 | return; | 1422 | return; | |
1423 | case SIGUSR2: | 1423 | case SIGUSR2: | |
1424 | loginfox(sigmsg, "SIGUSR2", "reopening log"); | 1424 | loginfox(sigmsg, "SIGUSR2", "reopening log"); | |
1425 | /* XXX This may not work that well in a chroot */ | 1425 | #ifdef PRIVSEP | |
1426 | logclose(); | 1426 | if (IN_PRIVSEP(ctx)) { | |
1427 | if (ps_root_logreopen(ctx) == -1) | |||
1428 | logerr("ps_root_logreopen"); | |||
1429 | return; | |||
1430 | } | |||
1431 | #endif | |||
1427 | if (logopen(ctx->logfile) == -1) | 1432 | if (logopen(ctx->logfile) == -1) | |
1428 | logerr(__func__); | 1433 | logerr("logopen"); | |
1429 | return; | 1434 | return; | |
1430 | case SIGCHLD: | 1435 | case SIGCHLD: | |
1431 | while (waitpid(-1, NULL, WNOHANG) > 0) | 1436 | while (waitpid(-1, NULL, WNOHANG) > 0) | |
1432 | ; | 1437 | ; | |
1433 | return; | 1438 | return; | |
1434 | default: | 1439 | default: | |
1435 | logerrx("received signal %d but don't know what to do with it", | 1440 | logerrx("received signal %d but don't know what to do with it", | |
1436 | sig); | 1441 | sig); | |
1437 | return; | 1442 | return; | |
1438 | } | 1443 | } | |
1439 | 1444 | |||
1440 | if (!(ctx->options & DHCPCD_TEST)) | 1445 | if (!(ctx->options & DHCPCD_TEST)) | |
1441 | stop_all_interfaces(ctx, opts); | 1446 | stop_all_interfaces(ctx, opts); | |
@@ -1850,27 +1855,27 @@ main(int argc, char **argv, char **envp) | @@ -1850,27 +1855,27 @@ main(int argc, char **argv, char **envp) | |||
1850 | #endif | 1855 | #endif | |
1851 | #ifdef INET | 1856 | #ifdef INET | |
1852 | ctx.udp_rfd = -1; | 1857 | ctx.udp_rfd = -1; | |
1853 | ctx.udp_wfd = -1; | 1858 | ctx.udp_wfd = -1; | |
1854 | #endif | 1859 | #endif | |
1855 | #if defined(INET6) && !defined(__sun) | 1860 | #if defined(INET6) && !defined(__sun) | |
1856 | ctx.nd_fd = -1; | 1861 | ctx.nd_fd = -1; | |
1857 | #endif | 1862 | #endif | |
1858 | #ifdef DHCP6 | 1863 | #ifdef DHCP6 | |
1859 | ctx.dhcp6_rfd = -1; | 1864 | ctx.dhcp6_rfd = -1; | |
1860 | ctx.dhcp6_wfd = -1; | 1865 | ctx.dhcp6_wfd = -1; | |
1861 | #endif | 1866 | #endif | |
1862 | #ifdef PRIVSEP | 1867 | #ifdef PRIVSEP | |
1863 | ctx.ps_root_fd = ctx.ps_data_fd = -1; | 1868 | ctx.ps_root_fd = ctx.ps_log_fd = ctx.ps_data_fd = -1; | |
1864 | ctx.ps_inet_fd = ctx.ps_control_fd = -1; | 1869 | ctx.ps_inet_fd = ctx.ps_control_fd = -1; | |
1865 | TAILQ_INIT(&ctx.ps_processes); | 1870 | TAILQ_INIT(&ctx.ps_processes); | |
1866 | #endif | 1871 | #endif | |
1867 | 1872 | |||
1868 | /* Check our streams for validity */ | 1873 | /* Check our streams for validity */ | |
1869 | ctx.stdin_valid = fcntl(STDIN_FILENO, F_GETFD) != -1; | 1874 | ctx.stdin_valid = fcntl(STDIN_FILENO, F_GETFD) != -1; | |
1870 | ctx.stdout_valid = fcntl(STDOUT_FILENO, F_GETFD) != -1; | 1875 | ctx.stdout_valid = fcntl(STDOUT_FILENO, F_GETFD) != -1; | |
1871 | ctx.stderr_valid = fcntl(STDERR_FILENO, F_GETFD) != -1; | 1876 | ctx.stderr_valid = fcntl(STDERR_FILENO, F_GETFD) != -1; | |
1872 | 1877 | |||
1873 | logopts = LOGERR_LOG | LOGERR_LOG_DATE | LOGERR_LOG_PID; | 1878 | logopts = LOGERR_LOG | LOGERR_LOG_DATE | LOGERR_LOG_PID; | |
1874 | if (ctx.stderr_valid) | 1879 | if (ctx.stderr_valid) | |
1875 | logopts |= LOGERR_ERR; | 1880 | logopts |= LOGERR_ERR; | |
1876 | 1881 | |||
@@ -2318,26 +2323,27 @@ printpidfile: | @@ -2318,26 +2323,27 @@ printpidfile: | |||
2318 | eloop_event_add(ctx.eloop, ctx.stderr_fd, | 2323 | eloop_event_add(ctx.eloop, ctx.stderr_fd, | |
2319 | dhcpcd_stderr_cb, &ctx); | 2324 | dhcpcd_stderr_cb, &ctx); | |
2320 | } | 2325 | } | |
2321 | #ifdef PRIVSEP | 2326 | #ifdef PRIVSEP | |
2322 | if (IN_PRIVSEP(&ctx) && ps_mastersandbox(&ctx, NULL) == -1) | 2327 | if (IN_PRIVSEP(&ctx) && ps_mastersandbox(&ctx, NULL) == -1) | |
2323 | goto exit_failure; | 2328 | goto exit_failure; | |
2324 | #endif | 2329 | #endif | |
2325 | goto run_loop; | 2330 | goto run_loop; | |
2326 | } | 2331 | } | |
2327 | 2332 | |||
2328 | /* We have now forked, setsid, forked once more. | 2333 | /* We have now forked, setsid, forked once more. | |
2329 | * From this point on, we are the controlling daemon. */ | 2334 | * From this point on, we are the controlling daemon. */ | |
2330 | ctx.options |= DHCPCD_STARTED; | 2335 | ctx.options |= DHCPCD_STARTED; | |
2336 | logdebugx("spawned master process on PID %d", getpid()); | |||
2331 | if ((pid = pidfile_lock(ctx.pidfile)) != 0) { | 2337 | if ((pid = pidfile_lock(ctx.pidfile)) != 0) { | |
2332 | logerr("%s: pidfile_lock %d", __func__, pid); | 2338 | logerr("%s: pidfile_lock %d", __func__, pid); | |
2333 | #ifdef PRIVSEP | 2339 | #ifdef PRIVSEP | |
2334 | /* privsep has not started ... */ | 2340 | /* privsep has not started ... */ | |
2335 | ctx.options &= ~DHCPCD_PRIVSEP; | 2341 | ctx.options &= ~DHCPCD_PRIVSEP; | |
2336 | #endif | 2342 | #endif | |
2337 | goto exit_failure; | 2343 | goto exit_failure; | |
2338 | } | 2344 | } | |
2339 | #endif | 2345 | #endif | |
2340 | 2346 | |||
2341 | os_init(); | 2347 | os_init(); | |
2342 | 2348 | |||
2343 | #if defined(BSD) && defined(INET6) | 2349 | #if defined(BSD) && defined(INET6) |
--- src/external/bsd/dhcpcd/dist/src/logerr.c 2020/10/12 14:09:03 1.10
+++ src/external/bsd/dhcpcd/dist/src/logerr.c 2020/11/01 14:24:01 1.11
@@ -37,61 +37,71 @@ | @@ -37,61 +37,71 @@ | |||
37 | #include <time.h> | 37 | #include <time.h> | |
38 | #include <unistd.h> | 38 | #include <unistd.h> | |
39 | 39 | |||
40 | #include "logerr.h" | 40 | #include "logerr.h" | |
41 | 41 | |||
42 | #ifndef LOGERR_SYSLOG_FACILITY | 42 | #ifndef LOGERR_SYSLOG_FACILITY | |
43 | #define LOGERR_SYSLOG_FACILITY LOG_DAEMON | 43 | #define LOGERR_SYSLOG_FACILITY LOG_DAEMON | |
44 | #endif | 44 | #endif | |
45 | 45 | |||
46 | #ifdef SMALL | 46 | #ifdef SMALL | |
47 | #undef LOGERR_TAG | 47 | #undef LOGERR_TAG | |
48 | #endif | 48 | #endif | |
49 | 49 | |||
50 | /* syslog protocol is 1k message max, RFC 3164 section 4.1 */ | |||
51 | #define LOGERR_SYSLOGBUF 1024 + sizeof(int) + sizeof(pid_t) | |||
52 | ||||
50 | #define UNUSED(a) (void)(a) | 53 | #define UNUSED(a) (void)(a) | |
51 | 54 | |||
52 | struct logctx { | 55 | struct logctx { | |
53 | char log_buf[BUFSIZ]; | 56 | char log_buf[BUFSIZ]; | |
54 | unsigned int log_opts; | 57 | unsigned int log_opts; | |
58 | int log_fd; | |||
59 | pid_t log_pid; | |||
55 | #ifndef SMALL | 60 | #ifndef SMALL | |
56 | FILE *log_file; | 61 | FILE *log_file; | |
57 | #ifdef LOGERR_TAG | 62 | #ifdef LOGERR_TAG | |
58 | const char *log_tag; | 63 | const char *log_tag; | |
59 | #endif | 64 | #endif | |
60 | #endif | 65 | #endif | |
61 | }; | 66 | }; | |
62 | 67 | |||
63 | static struct logctx _logctx = { | 68 | static struct logctx _logctx = { | |
64 | /* syslog style, but without the hostname or tag. */ | 69 | /* syslog style, but without the hostname or tag. */ | |
65 | .log_opts = LOGERR_LOG | LOGERR_LOG_DATE | LOGERR_LOG_PID, | 70 | .log_opts = LOGERR_LOG | LOGERR_LOG_DATE | LOGERR_LOG_PID, | |
71 | .log_fd = -1, | |||
72 | .log_pid = 0, | |||
66 | }; | 73 | }; | |
67 | 74 | |||
68 | #if defined(LOGERR_TAG) && defined(__linux__) | 75 | #if defined(__linux__) | |
69 | /* Poor man's getprogname(3). */ | 76 | /* Poor man's getprogname(3). */ | |
70 | static char *_logprog; | 77 | static char *_logprog; | |
71 | static const char * | 78 | static const char * | |
72 | getprogname(void) | 79 | getprogname(void) | |
73 | { | 80 | { | |
74 | const char *p; | 81 | const char *p; | |
75 | 82 | |||
76 | /* Use PATH_MAX + 1 to avoid truncation. */ | 83 | /* Use PATH_MAX + 1 to avoid truncation. */ | |
77 | if (_logprog == NULL) { | 84 | if (_logprog == NULL) { | |
78 | /* readlink(2) does not append a NULL byte, | 85 | /* readlink(2) does not append a NULL byte, | |
79 | * so zero the buffer. */ | 86 | * so zero the buffer. */ | |
80 | if ((_logprog = calloc(1, PATH_MAX + 1)) == NULL) | 87 | if ((_logprog = calloc(1, PATH_MAX + 1)) == NULL) | |
81 | return NULL; | 88 | return NULL; | |
89 | if (readlink("/proc/self/exe", _logprog, PATH_MAX + 1) == -1) { | |||
90 | free(_logprog); | |||
91 | _logprog = NULL; | |||
92 | return NULL; | |||
93 | } | |||
82 | } | 94 | } | |
83 | if (readlink("/proc/self/exe", _logprog, PATH_MAX + 1) == -1) | |||
84 | return NULL; | |||
85 | if (_logprog[0] == '[') | 95 | if (_logprog[0] == '[') | |
86 | return NULL; | 96 | return NULL; | |
87 | p = strrchr(_logprog, '/'); | 97 | p = strrchr(_logprog, '/'); | |
88 | if (p == NULL) | 98 | if (p == NULL) | |
89 | return _logprog; | 99 | return _logprog; | |
90 | return p + 1; | 100 | return p + 1; | |
91 | } | 101 | } | |
92 | #endif | 102 | #endif | |
93 | 103 | |||
94 | #ifndef SMALL | 104 | #ifndef SMALL | |
95 | /* Write the time, syslog style. month day time - */ | 105 | /* Write the time, syslog style. month day time - */ | |
96 | static int | 106 | static int | |
97 | logprintdate(FILE *stream) | 107 | logprintdate(FILE *stream) | |
@@ -137,27 +147,33 @@ vlogprintf_r(struct logctx *ctx, FILE *s | @@ -137,27 +147,33 @@ vlogprintf_r(struct logctx *ctx, FILE *s | |||
137 | (stream != stderr && ctx->log_opts & LOGERR_LOG_TAG)); | 147 | (stream != stderr && ctx->log_opts & LOGERR_LOG_TAG)); | |
138 | if (log_tag) { | 148 | if (log_tag) { | |
139 | if (ctx->log_tag == NULL) | 149 | if (ctx->log_tag == NULL) | |
140 | ctx->log_tag = getprogname(); | 150 | ctx->log_tag = getprogname(); | |
141 | if ((e = fprintf(stream, "%s", ctx->log_tag)) == -1) | 151 | if ((e = fprintf(stream, "%s", ctx->log_tag)) == -1) | |
142 | return -1; | 152 | return -1; | |
143 | len += e; | 153 | len += e; | |
144 | } | 154 | } | |
145 | #endif | 155 | #endif | |
146 | 156 | |||
147 | log_pid = ((stream == stderr && ctx->log_opts & LOGERR_ERR_PID) || | 157 | log_pid = ((stream == stderr && ctx->log_opts & LOGERR_ERR_PID) || | |
148 | (stream != stderr && ctx->log_opts & LOGERR_LOG_PID)); | 158 | (stream != stderr && ctx->log_opts & LOGERR_LOG_PID)); | |
149 | if (log_pid) { | 159 | if (log_pid) { | |
150 | if ((e = fprintf(stream, "[%d]", getpid())) == -1) | 160 | pid_t pid; | |
161 | ||||
162 | if (ctx->log_pid == 0) | |||
163 | pid = getpid(); | |||
164 | else | |||
165 | pid = ctx->log_pid; | |||
166 | if ((e = fprintf(stream, "[%d]", pid)) == -1) | |||
151 | return -1; | 167 | return -1; | |
152 | len += e; | 168 | len += e; | |
153 | } | 169 | } | |
154 | 170 | |||
155 | #ifdef LOGERR_TAG | 171 | #ifdef LOGERR_TAG | |
156 | if (log_tag || log_pid) | 172 | if (log_tag || log_pid) | |
157 | #else | 173 | #else | |
158 | if (log_pid) | 174 | if (log_pid) | |
159 | #endif | 175 | #endif | |
160 | { | 176 | { | |
161 | if ((e = fprintf(stream, ": ")) == -1) | 177 | if ((e = fprintf(stream, ": ")) == -1) | |
162 | return -1; | 178 | return -1; | |
163 | len += e; | 179 | len += e; | |
@@ -188,42 +204,57 @@ vlogprintf_r(struct logctx *ctx, FILE *s | @@ -188,42 +204,57 @@ vlogprintf_r(struct logctx *ctx, FILE *s | |||
188 | * Until NetBSD solves this issue, we have to disable a gcc diagnostic | 204 | * Until NetBSD solves this issue, we have to disable a gcc diagnostic | |
189 | * for our fully standards compliant code in the logger function. | 205 | * for our fully standards compliant code in the logger function. | |
190 | */ | 206 | */ | |
191 | #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 5)) | 207 | #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 5)) | |
192 | #pragma GCC diagnostic push | 208 | #pragma GCC diagnostic push | |
193 | #pragma GCC diagnostic ignored "-Wmissing-format-attribute" | 209 | #pragma GCC diagnostic ignored "-Wmissing-format-attribute" | |
194 | #endif | 210 | #endif | |
195 | __printflike(2, 0) static int | 211 | __printflike(2, 0) static int | |
196 | vlogmessage(int pri, const char *fmt, va_list args) | 212 | vlogmessage(int pri, const char *fmt, va_list args) | |
197 | { | 213 | { | |
198 | struct logctx *ctx = &_logctx; | 214 | struct logctx *ctx = &_logctx; | |
199 | int len = 0; | 215 | int len = 0; | |
200 | 216 | |||
217 | if (ctx->log_fd != -1) { | |||
218 | char buf[LOGERR_SYSLOGBUF]; | |||
219 | pid_t pid; | |||
220 | ||||
221 | memcpy(buf, &pri, sizeof(pri)); | |||
222 | pid = getpid(); | |||
223 | memcpy(buf + sizeof(pri), &pid, sizeof(pid)); | |||
224 | len = vsnprintf(buf + sizeof(pri) + sizeof(pid), | |||
225 | sizeof(buf) - sizeof(pri) - sizeof(pid), | |||
226 | fmt, args); | |||
227 | if (len != -1) | |||
228 | len = (int)write(ctx->log_fd, buf, | |||
229 | ((size_t)++len) + sizeof(pri) + sizeof(pid)); | |||
230 | return len; | |||
231 | } | |||
232 | ||||
201 | if (ctx->log_opts & LOGERR_ERR && | 233 | if (ctx->log_opts & LOGERR_ERR && | |
202 | (pri <= LOG_ERR || | 234 | (pri <= LOG_ERR || | |
203 | (!(ctx->log_opts & LOGERR_QUIET) && pri <= LOG_INFO) || | 235 | (!(ctx->log_opts & LOGERR_QUIET) && pri <= LOG_INFO) || | |
204 | (ctx->log_opts & LOGERR_DEBUG && pri <= LOG_DEBUG))) | 236 | (ctx->log_opts & LOGERR_DEBUG && pri <= LOG_DEBUG))) | |
205 | len = vlogprintf_r(ctx, stderr, fmt, args); | 237 | len = vlogprintf_r(ctx, stderr, fmt, args); | |
206 | 238 | |||
207 | if (!(ctx->log_opts & LOGERR_LOG)) | |||
208 | return len; | |||
209 | ||||
210 | #ifndef SMALL | 239 | #ifndef SMALL | |
211 | if (ctx->log_file != NULL && | 240 | if (ctx->log_file != NULL && | |
212 | (pri != LOG_DEBUG || (ctx->log_opts & LOGERR_DEBUG))) | 241 | (pri != LOG_DEBUG || (ctx->log_opts & LOGERR_DEBUG))) | |
213 | len = vlogprintf_r(ctx, ctx->log_file, fmt, args); | 242 | len = vlogprintf_r(ctx, ctx->log_file, fmt, args); | |
214 | #endif | 243 | #endif | |
215 | 244 | |||
216 | vsyslog(pri, fmt, args); | 245 | if (ctx->log_opts & LOGERR_LOG) | |
246 | vsyslog(pri, fmt, args); | |||
247 | ||||
217 | return len; | 248 | return len; | |
218 | } | 249 | } | |
219 | #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 5)) | 250 | #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 5)) | |
220 | #pragma GCC diagnostic pop | 251 | #pragma GCC diagnostic pop | |
221 | #endif | 252 | #endif | |
222 | 253 | |||
223 | __printflike(2, 3) void | 254 | __printflike(2, 3) void | |
224 | logmessage(int pri, const char *fmt, ...) | 255 | logmessage(int pri, const char *fmt, ...) | |
225 | { | 256 | { | |
226 | va_list args; | 257 | va_list args; | |
227 | 258 | |||
228 | va_start(args, fmt); | 259 | va_start(args, fmt); | |
229 | vlogmessage(pri, fmt, args); | 260 | vlogmessage(pri, fmt, args); | |
@@ -321,26 +352,74 @@ log_err(const char *fmt, ...) | @@ -321,26 +352,74 @@ log_err(const char *fmt, ...) | |||
321 | va_end(args); | 352 | va_end(args); | |
322 | } | 353 | } | |
323 | 354 | |||
324 | void | 355 | void | |
325 | log_errx(const char *fmt, ...) | 356 | log_errx(const char *fmt, ...) | |
326 | { | 357 | { | |
327 | va_list args; | 358 | va_list args; | |
328 | 359 | |||
329 | va_start(args, fmt); | 360 | va_start(args, fmt); | |
330 | vlogmessage(LOG_ERR, fmt, args); | 361 | vlogmessage(LOG_ERR, fmt, args); | |
331 | va_end(args); | 362 | va_end(args); | |
332 | } | 363 | } | |
333 | 364 | |||
365 | int | |||
366 | loggetfd(void) | |||
367 | { | |||
368 | struct logctx *ctx = &_logctx; | |||
369 | ||||
370 | return ctx->log_fd; | |||
371 | } | |||
372 | ||||
373 | void | |||
374 | logsetfd(int fd) | |||
375 | { | |||
376 | struct logctx *ctx = &_logctx; | |||
377 | ||||
378 | ctx->log_fd = fd; | |||
379 | #ifndef SMALL | |||
380 | if (fd != -1 && ctx->log_file != NULL) { | |||
381 | fclose(ctx->log_file); | |||
382 | ctx->log_file = NULL; | |||
383 | } | |||
384 | #endif | |||
385 | } | |||
386 | ||||
387 | int | |||
388 | logreadfd(int fd) | |||
389 | { | |||
390 | struct logctx *ctx = &_logctx; | |||
391 | char buf[LOGERR_SYSLOGBUF]; | |||
392 | int len, pri; | |||
393 | ||||
394 | len = (int)read(fd, buf, sizeof(buf)); | |||
395 | if (len == -1) | |||
396 | return -1; | |||
397 | ||||
398 | /* Ensure we have pri, pid and a terminator */ | |||
399 | if (len < (int)(sizeof(pri) + sizeof(pid_t) + 1) || | |||
400 | buf[len - 1] != '\0') | |||
401 | { | |||
402 | errno = EINVAL; | |||
403 | return -1; | |||
404 | } | |||
405 | ||||
406 | memcpy(&pri, buf, sizeof(pri)); | |||
407 | memcpy(&ctx->log_pid, buf + sizeof(pri), sizeof(ctx->log_pid)); | |||
408 | logmessage(pri, "%s", buf + sizeof(pri) + sizeof(ctx->log_pid)); | |||
409 | ctx->log_pid = 0; | |||
410 | return len; | |||
411 | } | |||
412 | ||||
334 | unsigned int | 413 | unsigned int | |
335 | loggetopts(void) | 414 | loggetopts(void) | |
336 | { | 415 | { | |
337 | struct logctx *ctx = &_logctx; | 416 | struct logctx *ctx = &_logctx; | |
338 | 417 | |||
339 | return ctx->log_opts; | 418 | return ctx->log_opts; | |
340 | } | 419 | } | |
341 | 420 | |||
342 | void | 421 | void | |
343 | logsetopts(unsigned int opts) | 422 | logsetopts(unsigned int opts) | |
344 | { | 423 | { | |
345 | struct logctx *ctx = &_logctx; | 424 | struct logctx *ctx = &_logctx; | |
346 | 425 | |||
@@ -363,35 +442,36 @@ logsettag(const char *tag) | @@ -363,35 +442,36 @@ logsettag(const char *tag) | |||
363 | #endif | 442 | #endif | |
364 | 443 | |||
365 | int | 444 | int | |
366 | logopen(const char *path) | 445 | logopen(const char *path) | |
367 | { | 446 | { | |
368 | struct logctx *ctx = &_logctx; | 447 | struct logctx *ctx = &_logctx; | |
369 | int opts = 0; | 448 | int opts = 0; | |
370 | 449 | |||
371 | /* Cache timezone */ | 450 | /* Cache timezone */ | |
372 | tzset(); | 451 | tzset(); | |
373 | 452 | |||
374 | (void)setvbuf(stderr, ctx->log_buf, _IOLBF, sizeof(ctx->log_buf)); | 453 | (void)setvbuf(stderr, ctx->log_buf, _IOLBF, sizeof(ctx->log_buf)); | |
375 | 454 | |||
376 | if (!(ctx->log_opts & LOGERR_LOG)) | 455 | #ifndef SMALL | |
377 | return 1; | 456 | if (ctx->log_file != NULL) { | |
378 | 457 | fclose(ctx->log_file); | ||
379 | #ifdef LOG_NDELAY | 458 | ctx->log_file = NULL; | |
380 | opts |= LOG_NDELAY; | 459 | } | |
381 | #endif | 460 | #endif | |
461 | ||||
382 | if (ctx->log_opts & LOGERR_LOG_PID) | 462 | if (ctx->log_opts & LOGERR_LOG_PID) | |
383 | opts |= LOG_PID; | 463 | opts |= LOG_PID; | |
384 | openlog(NULL, opts, LOGERR_SYSLOG_FACILITY); | 464 | openlog(getprogname(), opts, LOGERR_SYSLOG_FACILITY); | |
385 | if (path == NULL) | 465 | if (path == NULL) | |
386 | return 1; | 466 | return 1; | |
387 | 467 | |||
388 | #ifndef SMALL | 468 | #ifndef SMALL | |
389 | if ((ctx->log_file = fopen(path, "ae")) == NULL) | 469 | if ((ctx->log_file = fopen(path, "ae")) == NULL) | |
390 | return -1; | 470 | return -1; | |
391 | setlinebuf(ctx->log_file); | 471 | setlinebuf(ctx->log_file); | |
392 | return fileno(ctx->log_file); | 472 | return fileno(ctx->log_file); | |
393 | #else | 473 | #else | |
394 | errno = ENOTSUP; | 474 | errno = ENOTSUP; | |
395 | return -1; | 475 | return -1; | |
396 | #endif | 476 | #endif | |
397 | } | 477 | } | |
@@ -400,17 +480,17 @@ void | @@ -400,17 +480,17 @@ void | |||
400 | logclose(void) | 480 | logclose(void) | |
401 | { | 481 | { | |
402 | #ifndef SMALL | 482 | #ifndef SMALL | |
403 | struct logctx *ctx = &_logctx; | 483 | struct logctx *ctx = &_logctx; | |
404 | #endif | 484 | #endif | |
405 | 485 | |||
406 | closelog(); | 486 | closelog(); | |
407 | #ifndef SMALL | 487 | #ifndef SMALL | |
408 | if (ctx->log_file == NULL) | 488 | if (ctx->log_file == NULL) | |
409 | return; | 489 | return; | |
410 | fclose(ctx->log_file); | 490 | fclose(ctx->log_file); | |
411 | ctx->log_file = NULL; | 491 | ctx->log_file = NULL; | |
412 | #endif | 492 | #endif | |
413 | #if defined(LOGERR_TAG) && defined(__linux__) | 493 | #if defined(__linux__) | |
414 | free(_logprog); | 494 | free(_logprog); | |
415 | #endif | 495 | #endif | |
416 | } | 496 | } |
--- src/external/bsd/dhcpcd/dist/src/privsep.c 2020/10/12 14:09:03 1.9
+++ src/external/bsd/dhcpcd/dist/src/privsep.c 2020/11/01 14:24:01 1.10
@@ -532,26 +532,39 @@ ps_entersandbox(const char *_pledge, con | @@ -532,26 +532,39 @@ ps_entersandbox(const char *_pledge, con | |||
532 | 532 | |||
533 | int | 533 | int | |
534 | ps_mastersandbox(struct dhcpcd_ctx *ctx, const char *_pledge) | 534 | ps_mastersandbox(struct dhcpcd_ctx *ctx, const char *_pledge) | |
535 | { | 535 | { | |
536 | const char *sandbox = NULL; | 536 | const char *sandbox = NULL; | |
537 | bool forked; | 537 | bool forked; | |
538 | int dropped; | 538 | int dropped; | |
539 | 539 | |||
540 | forked = ctx->options & DHCPCD_FORKED; | 540 | forked = ctx->options & DHCPCD_FORKED; | |
541 | ctx->options &= ~DHCPCD_FORKED; | 541 | ctx->options &= ~DHCPCD_FORKED; | |
542 | dropped = ps_dropprivs(ctx); | 542 | dropped = ps_dropprivs(ctx); | |
543 | if (forked) | 543 | if (forked) | |
544 | ctx->options |= DHCPCD_FORKED; | 544 | ctx->options |= DHCPCD_FORKED; | |
545 | ||||
546 | /* | |||
547 | * If we don't have a root process, we cannot use syslog. | |||
548 | * If it cannot be opened before chrooting then syslog(3) will fail. | |||
549 | * openlog(3) does not return an error which doubly sucks. | |||
550 | */ | |||
551 | if (ctx->ps_root_fd == -1) { | |||
552 | unsigned int logopts = loggetopts(); | |||
553 | ||||
554 | logopts &= ~LOGERR_LOG; | |||
555 | logsetopts(logopts); | |||
556 | } | |||
557 | ||||
545 | if (dropped == -1) { | 558 | if (dropped == -1) { | |
546 | logerr("%s: ps_dropprivs", __func__); | 559 | logerr("%s: ps_dropprivs", __func__); | |
547 | return -1; | 560 | return -1; | |
548 | } | 561 | } | |
549 | 562 | |||
550 | #ifdef PRIVSEP_RIGHTS | 563 | #ifdef PRIVSEP_RIGHTS | |
551 | if ((ctx->pf_inet_fd != -1 && | 564 | if ((ctx->pf_inet_fd != -1 && | |
552 | ps_rights_limit_ioctl(ctx->pf_inet_fd) == -1) || | 565 | ps_rights_limit_ioctl(ctx->pf_inet_fd) == -1) || | |
553 | ps_rights_limit_stdio(ctx) == -1) | 566 | ps_rights_limit_stdio(ctx) == -1) | |
554 | { | 567 | { | |
555 | logerr("%s: cap_rights_limit", __func__); | 568 | logerr("%s: cap_rights_limit", __func__); | |
556 | return -1; | 569 | return -1; | |
557 | } | 570 | } |