From: Paul Donald Date: Fri, 19 Dec 2025 15:50:55 +0000 (+0100) Subject: all: add log helpers X-Git-Url: http://git.cdn.openwrt.org/?a=commitdiff_plain;h=HEAD;p=project%2Fodhcp6c.git all: add log helpers avoids multiple syslog.h include (sync with implementation in odhcpd) We deprecate the `-v` param. Add new `-l` param for level, identical to odhcpd. The odhcp6c `dhcpv6.sh` script in openwrt main should be updated to recognize this change, but it is harmless if it is not changed. Signed-off-by: Paul Donald Link: https://github.com/openwrt/odhcp6c/pull/142 Signed-off-by: Álvaro Fernández Rojas --- diff --git a/src/config.c b/src/config.c index 7db8b02..2866175 100644 --- a/src/config.c +++ b/src/config.c @@ -64,7 +64,6 @@ #include #include #include -#include #include "config.h" #include "odhcp6c.h" @@ -78,6 +77,7 @@ struct config_dhcp *config_dhcp_get(void) { } void config_dhcp_reset(void) { + config_dhcp.log_level = LOG_WARNING; config_dhcp.release = true; config_dhcp.dscp = 0; config_dhcp.sk_prio = 0; @@ -119,7 +119,7 @@ void config_set_release(bool enable) { bool config_set_dscp(unsigned int value) { if (value > 63) { - syslog(LOG_ERR, "Invalid DSCP value"); + error("Invalid DSCP value"); return false; } config_dhcp.dscp = value; @@ -128,7 +128,7 @@ bool config_set_dscp(unsigned int value) { bool config_set_sk_priority(unsigned int priority) { if (priority > 6) { - syslog(LOG_ERR, "Invalid SK priority value"); + error("Invalid SK priority value"); return false; } config_dhcp.sk_prio = priority; @@ -152,7 +152,7 @@ bool config_set_request_addresses(char* mode) { } else if (!strcmp(mode, "try")) { config_dhcp.ia_na_mode = IA_MODE_TRY; } else { - syslog(LOG_ERR, "Invalid IA_NA Request Addresses mode"); + error("Invalid IA_NA Request Addresses mode"); return false; } @@ -172,7 +172,7 @@ bool config_set_request_prefix(unsigned int length, unsigned int id) { prefix.iaid = htonl(id); if (odhcp6c_add_state(STATE_IA_PD_INIT, &prefix, sizeof(prefix))) { - syslog(LOG_ERR, "Failed to set request IPv6-Prefix"); + error("Failed to set request IPv6-Prefix"); return false; } } @@ -203,13 +203,13 @@ void config_clear_requested_options(void) { bool config_add_requested_options(unsigned int option) { if (option > UINT16_MAX) { - syslog(LOG_ERR, "Invalid requested option"); + error("Invalid requested option"); return false; } option = htons(option); if (odhcp6c_insert_state(STATE_ORO, 0, &option, 2)) { - syslog(LOG_ERR, "Failed to set requested option"); + error("Failed to set requested option"); return false; } config_dhcp.oro_user_cnt++; @@ -227,7 +227,7 @@ bool config_add_send_options(char* option) { bool config_set_rtx_delay_max(enum config_dhcp_msg msg, unsigned int value) { if (msg >= CONFIG_DHCP_MAX || value > UINT8_MAX) { - syslog(LOG_ERR, "Invalid retransmission Maximum Delay value"); + error("Invalid retransmission Maximum Delay value"); return false; } config_dhcp.message_rtx[msg].delay_max = value; @@ -237,7 +237,7 @@ bool config_set_rtx_delay_max(enum config_dhcp_msg msg, unsigned int value) bool config_set_rtx_timeout_init(enum config_dhcp_msg msg, unsigned int value) { if (msg >= CONFIG_DHCP_MAX || value > UINT8_MAX || value == 0) { - syslog(LOG_ERR, "Invalid retransmission Initial Timeout value"); + error("Invalid retransmission Initial Timeout value"); return false; } config_dhcp.message_rtx[msg].timeout_init = value; @@ -247,7 +247,7 @@ bool config_set_rtx_timeout_init(enum config_dhcp_msg msg, unsigned int value) bool config_set_rtx_timeout_max(enum config_dhcp_msg msg, unsigned int value) { if (msg >= CONFIG_DHCP_MAX || value > UINT16_MAX) { - syslog(LOG_ERR, "Invalid retransmission Maximum Timeout value"); + error("Invalid retransmission Maximum Timeout value"); return false; } config_dhcp.message_rtx[msg].timeout_max = value; @@ -257,7 +257,7 @@ bool config_set_rtx_timeout_max(enum config_dhcp_msg msg, unsigned int value) bool config_set_rtx_rc_max(enum config_dhcp_msg msg, unsigned int value) { if (msg >= CONFIG_DHCP_MAX || value > UINT8_MAX) { - syslog(LOG_ERR, "Invalid retransmission Retry Attempt value"); + error("Invalid retransmission Retry Attempt value"); return false; } config_dhcp.message_rtx[msg].rc_max = value; @@ -267,7 +267,7 @@ bool config_set_rtx_rc_max(enum config_dhcp_msg msg, unsigned int value) bool config_set_irt_default(unsigned int value) { if (value == 0) { - syslog(LOG_ERR, "Invalid Default Information Refresh Time value"); + error("Invalid Default Information Refresh Time value"); return false; } config_dhcp.irt_default = value; @@ -277,7 +277,7 @@ bool config_set_irt_default(unsigned int value) bool config_set_irt_min(unsigned int value) { if (value == 0) { - syslog(LOG_ERR, "Invalid Minimum Information Refresh Time value"); + error("Invalid Minimum Information Refresh Time value"); return false; } config_dhcp.irt_min = value; @@ -287,7 +287,7 @@ bool config_set_irt_min(unsigned int value) bool config_set_rand_factor(unsigned int value) { if (value > 999 || value < 10) { - syslog(LOG_ERR, "Invalid Random Factor value"); + error("Invalid Random Factor value"); return false; } config_dhcp.rand_factor = value; @@ -303,7 +303,7 @@ bool config_set_auth_protocol(const char* protocol) } else if (!strcmp(protocol, "ReconfigureKeyAuthentication")) { config_dhcp.auth_protocol = AUTH_PROT_RKAP; } else { - syslog(LOG_ERR, "Invalid Authentication protocol"); + error("Invalid Authentication protocol"); return false; } @@ -493,7 +493,7 @@ int config_add_opt(const uint16_t code, const uint8_t *data, const uint16_t len) if (odhcp6c_add_state(STATE_OPTS, &opt_hdr, sizeof(opt_hdr)) || odhcp6c_add_state(STATE_OPTS, data, len)) { - syslog(LOG_ERR, "Failed to add option %hu", code); + error("Failed to add option %hu", code); return 1; } diff --git a/src/config.h b/src/config.h index 03dbf88..cce1c04 100644 --- a/src/config.h +++ b/src/config.h @@ -83,7 +83,9 @@ enum config_dhcp_msg { }; struct config_dhcp { + bool log_syslog; bool release; + int log_level; int dscp; int sk_prio; bool stateful_only_mode; diff --git a/src/dhcpv6.c b/src/dhcpv6.c index b8e5292..7e9415b 100644 --- a/src/dhcpv6.c +++ b/src/dhcpv6.c @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include @@ -485,7 +484,7 @@ static int fd_set_nonblocking(int sockfd) { int flags = fcntl(sockfd, F_GETFL, 0); if (flags == -1) { - syslog(LOG_ERR, + error( "Failed to get the dhcpv6 socket flags: fcntl F_GETFL failed (%s)", strerror(errno)); return -1; @@ -493,7 +492,7 @@ static int fd_set_nonblocking(int sockfd) // Set the socket to non-blocking if (fcntl(sockfd, F_SETFL, flags | O_NONBLOCK) == -1) { - syslog(LOG_ERR, + error( "Failed to set the dhcpv6 socket to non-blocking: fcntl F_SETFL failed (%s)", strerror(errno)); return -1; @@ -1019,7 +1018,7 @@ static void dhcpv6_send(enum dhcpv6_msg req_msg_type, uint8_t trid[3], uint32_t if (sendmsg(sock, &msg, 0) < 0) { char in6_str[INET6_ADDRSTRLEN]; - syslog(LOG_ERR, "Failed to send %s message to %s (%s)", + error("Failed to send %s message to %s (%s)", dhcpv6_msg_to_str(req_msg_type), inet_ntop(AF_INET6, (const void *)&srv.sin6_addr, in6_str, sizeof(in6_str)), strerror(errno)); @@ -1196,7 +1195,7 @@ static int dhcpv6_handle_reconfigure(enum dhcpv6_msg orig, const int rc, _o_fallthrough; case DHCPV6_MSG_INFO_REQ: msg = odata[0]; - syslog(LOG_NOTICE, "Need to respond with %s in reply to %s", + notice("Need to respond with %s in reply to %s", dhcpv6_msg_to_str(msg), dhcpv6_msg_to_str(DHCPV6_MSG_RECONF)); break; @@ -1724,7 +1723,7 @@ static unsigned int dhcpv6_parse_ia(void *opt, void *end, int *ret) if (t1 > t2 && t1 > 0 && t2 > 0) return 0; - syslog(LOG_INFO, "%s %04x T1 %d T2 %d", ntohs(ia_hdr->type) == DHCPV6_OPT_IA_PD ? "IA_PD" : "IA_NA", ntohl(ia_hdr->iaid), t1, t2); + info("%s %04x T1 %d T2 %d", ntohs(ia_hdr->type) == DHCPV6_OPT_IA_PD ? "IA_PD" : "IA_NA", ntohl(ia_hdr->iaid), t1, t2); // Update address IA dhcpv6_for_each_option(&ia_hdr[1], end, otype, olen, odata) { @@ -1825,7 +1824,7 @@ static unsigned int dhcpv6_parse_ia(void *opt, void *end, int *ret) if (odhcp6c_update_entry(STATE_IA_PD, &entry, 0)) updated_IAs++; - syslog(LOG_INFO, "%s/%d preferred %d valid %d", + info("%s/%d preferred %d valid %d", inet_ntop(AF_INET6, &entry.target, buf, sizeof(buf)), entry.length, entry.preferred , entry.valid); } @@ -1880,7 +1879,7 @@ static unsigned int dhcpv6_parse_ia(void *opt, void *end, int *ret) if (odhcp6c_update_entry(STATE_IA_NA, &entry, 0)) updated_IAs++; - syslog(LOG_INFO, "%s preferred %d valid %d", + info("%s preferred %d valid %d", inet_ntop(AF_INET6, &entry.target, buf, sizeof(buf)), entry.preferred , entry.valid); } @@ -1947,7 +1946,7 @@ static unsigned int dhcpv6_calc_refresh_timers(void) t2 = l_t2; t3 = l_t3; - syslog(LOG_INFO, "T1 %"PRId64"s, T2 %"PRId64"s, T3 %"PRId64"s", t1, t2, t3); + info("T1 %"PRId64"s, T2 %"PRId64"s, T3 %"PRId64"s", t1, t2, t3); } return (unsigned int)(ia_pd_entry_cnt + ia_na_entry_cnt); @@ -1972,7 +1971,7 @@ static void dhcpv6_log_status_code(const uint16_t code, const char *scope, *dst = 0; - syslog(LOG_WARNING, "Server returned %s status '%s %s'", + warn("Server returned %s status '%s %s'", scope, dhcpv6_status_code_to_str(code), buf); } @@ -2198,7 +2197,7 @@ int dhcpv6_send_request(enum dhcpv6_msg req_msg_type) if (retx->timeout == 0) return -1; - syslog(LOG_NOTICE, "Starting %s transaction (timeout %"PRIu64"s, max rc %d)", + notice("Starting %s transaction (timeout %"PRIu64"s, max rc %d)", retx->name, retx->timeout, retx->max_rc); // Generate transaction ID @@ -2248,7 +2247,7 @@ int dhcpv6_send_request(enum dhcpv6_msg req_msg_type) case DHCPV6_MSG_UNKNOWN: break; default: - syslog(LOG_NOTICE, "Send %s message (elapsed %"PRIu64"ms, rc %d)", + notice("Send %s message (elapsed %"PRIu64"ms, rc %d)", retx->name, elapsed, retx->rc); _o_fallthrough; case DHCPV6_MSG_SOLICIT: @@ -2285,7 +2284,7 @@ int dhcpv6_receive_response(enum dhcpv6_msg req_msg_type) // Receive cycle len = recvmsg(sock, &msg, 0); if (len < 0) { - syslog(LOG_ERR, "Error occurred when reading the response of (%s) error(%s)", + error("Error occurred when reading the response of (%s) error(%s)", retx->name, strerror(errno)); return -1; } @@ -2317,7 +2316,7 @@ int dhcpv6_receive_response(enum dhcpv6_msg req_msg_type) retx->round_start = odhcp6c_get_milli_time(); uint64_t elapsed = retx->round_start - retx->start; - syslog(LOG_NOTICE, "Got a valid %s after %"PRIu64"ms", + notice("Got a valid %s after %"PRIu64"ms", dhcpv6_msg_to_str(hdr->msg_type), elapsed); if (retx->handler_reply) { diff --git a/src/odhcp6c.c b/src/odhcp6c.c index 9b37c24..72705ff 100644 --- a/src/odhcp6c.c +++ b/src/odhcp6c.c @@ -27,10 +27,10 @@ #include #include #include +#include #include #include #include -#include #include #include #include @@ -67,6 +67,25 @@ static time_t last_update = 0; static char *ifname = NULL; struct config_dhcp *config_dhcp = NULL; +void __iflog(int lvl, const char *fmt, ...) +{ + va_list ap; + + if (lvl > config_dhcp->log_level) + return; + + va_start(ap, fmt); + + if (config_dhcp->log_syslog) { + vsyslog(lvl, fmt, ap); + } else { + vfprintf(stderr, fmt, ap); + fprintf(stderr, "\n"); + } + + va_end(ap); +} + static unsigned int script_sync_delay = 10; static unsigned int script_accu_delay = 1; @@ -174,7 +193,6 @@ int main(_o_unused int argc, char* const argv[]) uint16_t opttype; struct odhcp6c_opt *opt; int ia_pd_iaid_index = 0; - int verbosity = 0; bool help = false, daemonize = false; int logopt = LOG_PID; int c; @@ -183,11 +201,12 @@ int main(_o_unused int argc, char* const argv[]) unsigned int ra_holdoff_interval = RA_MIN_ADV_INTERVAL; ra_ifid_mode_t ra_ifid_mode = RA_IFID_LLA; bool terminate = false; + bool deprecated_opt = false; config_dhcp = config_dhcp_get(); config_dhcp_reset(); - while ((c = getopt(argc, argv, "SDN:V:P:FB:c:i:r:Ru:Ux:s:EkK:t:C:m:Lhedp:fav")) != -1) { + while ((c = getopt(argc, argv, "SDN:V:P:FB:c:i:r:Ru:Ux:s:EkK:t:C:m:Lhedp:favl:")) != -1) { switch (c) { case 'S': config_set_allow_slaac_only(false); @@ -205,7 +224,7 @@ int main(_o_unused int argc, char* const argv[]) case 'V': opt = odhcp6c_find_opt(DHCPV6_OPT_VENDOR_CLASS); if (!opt) { - syslog(LOG_ERR, "Failed to set vendor-class option"); + error("Failed to set vendor-class option"); return 1; } @@ -238,7 +257,7 @@ int main(_o_unused int argc, char* const argv[]) strncpy((char *)buf, optarg, optpos - optarg); buf[optpos - optarg] = '\0'; if (inet_pton(AF_INET6, (char *)buf, &prefix.addr) <= 0) { - syslog(LOG_ERR, "invalid argument: '%s'", optarg); + error("invalid argument: '%s'", optarg); return 1; } optpos++; @@ -251,7 +270,7 @@ int main(_o_unused int argc, char* const argv[]) prefix.length = strtoul(optpos, &iaid_begin, 10); if (*iaid_begin != '\0' && *iaid_begin != ',' && *iaid_begin != ':') { - syslog(LOG_ERR, "invalid argument: '%s'", optarg); + error("invalid argument: '%s'", optarg); return 1; } @@ -263,7 +282,7 @@ int main(_o_unused int argc, char* const argv[]) prefix.iaid = htonl(++ia_pd_iaid_index); if (odhcp6c_add_state(STATE_IA_PD_INIT, &prefix, sizeof(prefix))) { - syslog(LOG_ERR, "Failed to set request IPv6-Prefix"); + error("Failed to set request IPv6-Prefix"); return 1; } break; @@ -280,7 +299,7 @@ int main(_o_unused int argc, char* const argv[]) buf[2] = 0; buf[3] = l; if (odhcp6c_add_state(STATE_CLIENT_ID, buf, l + 4)) { - syslog(LOG_ERR, "Failed to override client-ID"); + error("Failed to override client-ID"); return 1; } else { client_id_param = true; @@ -301,7 +320,7 @@ int main(_o_unused int argc, char* const argv[]) ifid.s6_addr[1] = 0x80; } else { /* Do not error on bad values; fall back to default */ - syslog(LOG_ERR, "Invalid interface-ID: %s", optarg); + error("Invalid interface-ID: %s", optarg); } break; @@ -315,7 +334,7 @@ int main(_o_unused int argc, char* const argv[]) optarg = &optpos[1]; if (odhcp6c_add_state(STATE_ORO, &opttype, 2)) { - syslog(LOG_ERR, "Failed to add requested option"); + error("Failed to add requested option"); return 1; } } @@ -328,7 +347,7 @@ int main(_o_unused int argc, char* const argv[]) case 'u': opt = odhcp6c_find_opt(DHCPV6_OPT_USER_CLASS); if (!opt) { - syslog(LOG_ERR, "Failed to set user-class option"); + error("Failed to set user-class option"); return 1; } @@ -361,7 +380,7 @@ int main(_o_unused int argc, char* const argv[]) case 'E': #ifndef WITH_UBUS - syslog(LOG_ERR, "Failed to use ubus event: ENABLE_UBUS compilation flag missing"); + error("Failed to use ubus event: ENABLE_UBUS compilation flag missing"); return 1; #endif /* WITH_UBUS */ script = NULL; @@ -412,7 +431,12 @@ int main(_o_unused int argc, char* const argv[]) break; case 'v': - ++verbosity; + /* deprecated - remove -v options from start scripts first */ + deprecated_opt = true; + break; + + case 'l': + config_dhcp->log_level = (atoi(optarg) & LOG_PRIMASK); break; case 'x': @@ -432,8 +456,7 @@ int main(_o_unused int argc, char* const argv[]) } openlog("odhcp6c", logopt, LOG_DAEMON); - if (!verbosity) - setlogmask(LOG_UPTO(LOG_WARNING)); + setlogmask(LOG_UPTO(config_dhcp->log_level)); ifname = argv[optind]; @@ -450,7 +473,7 @@ int main(_o_unused int argc, char* const argv[]) if (daemonize) { openlog("odhcp6c", LOG_PID, LOG_DAEMON); // Disable LOG_PERROR if (daemon(0, 0)) { - syslog(LOG_ERR, "Failed to daemonize: %s", + error("Failed to daemonize: %s", strerror(errno)); return 3; } @@ -465,12 +488,17 @@ int main(_o_unused int argc, char* const argv[]) fprintf(fp, "%i\n", getpid()); fclose(fp); } + } else { + config_dhcp->log_syslog = false; } + if (deprecated_opt) + warn("The -v flag is deprecated and will be removed. Use -l[0-7]."); + if ((urandom_fd = open("/dev/urandom", O_CLOEXEC | O_RDONLY)) < 0 || ra_init(ifname, &ifid, ra_ifid_mode, ra_options, ra_holdoff_interval) || script_init(script, ifname)) { - syslog(LOG_ERR, "failed to initialize: %s", strerror(errno)); + error("failed to initialize: %s", strerror(errno)); return 4; } @@ -487,14 +515,14 @@ int main(_o_unused int argc, char* const argv[]) #ifdef WITH_UBUS char *err = ubus_init(ifname); if (err) { - syslog(LOG_ERR, "ubus error: %s", err); + error("ubus error: %s", err); return 1; } struct ubus_context *ubus = ubus_get_ctx(); int ubus_socket = ubus->sock.fd; if (ubus_socket < 0) { - syslog(LOG_ERR, "Invalid ubus file descriptor"); + error("Invalid ubus file descriptor"); return 1; } fds[UBUS_FD_INDEX].fd = ubus_socket; @@ -528,13 +556,13 @@ int main(_o_unused int argc, char* const argv[]) config_dhcp->oro_user_cnt = oro_len / sizeof(uint16_t); if (init_dhcpv6(ifname)) { - syslog(LOG_ERR, "failed to initialize: %s", strerror(errno)); + error("failed to initialize: %s", strerror(errno)); return 1; } fds[DHCPV6_FD_INDEX].fd = dhcpv6_get_socket(); - syslog(LOG_NOTICE, "(re)starting transaction on %s", ifname); + notice("(re)starting transaction on %s", ifname); signal_usr1 = signal_usr2 = false; @@ -587,12 +615,12 @@ int main(_o_unused int argc, char* const argv[]) if (!bound) { bound = true; if (mode == DHCPV6_STATELESS) { - syslog(LOG_NOTICE, "entering stateless-mode on %s", ifname); + notice("entering stateless-mode on %s", ifname); signal_usr1 = false; notify_state_change("informed", script_sync_delay, true); } else { notify_state_change("bound", script_sync_delay, true); - syslog(LOG_NOTICE, "entering stateful-mode on %s", ifname); + notice("entering stateful-mode on %s", ifname); } } @@ -812,7 +840,7 @@ static int usage(void) " -p Set pidfile (/var/run/odhcp6c.pid)\n" " -d Daemonize\n" " -e Write logmessages to stderr\n" - " -v Increase logging verbosity\n" + " -l Set logging level (0-7)\n" " -h Show this help\n\n"; fputs(buf, stderr); diff --git a/src/odhcp6c.h b/src/odhcp6c.h index d022b24..bd3c515 100644 --- a/src/odhcp6c.h +++ b/src/odhcp6c.h @@ -19,6 +19,7 @@ #include #include #include +#include #ifndef _o_aligned #define _o_aligned(n) __attribute__((aligned(n))) @@ -38,6 +39,16 @@ #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) +void __iflog(int lvl, const char *fmt, ...); +#define debug(fmt, ...) __iflog(LOG_DEBUG, fmt __VA_OPT__(, ) __VA_ARGS__) +#define info(fmt, ...) __iflog(LOG_INFO, fmt __VA_OPT__(, ) __VA_ARGS__) +#define notice(fmt, ...) __iflog(LOG_NOTICE, fmt __VA_OPT__(, ) __VA_ARGS__) +#define warn(fmt, ...) __iflog(LOG_WARNING, fmt __VA_OPT__(, ) __VA_ARGS__) +#define error(fmt, ...) __iflog(LOG_ERR, fmt __VA_OPT__(, ) __VA_ARGS__) +#define critical(fmt, ...) __iflog(LOG_CRIT, fmt __VA_OPT__(, ) __VA_ARGS__) +#define alert(fmt, ...) __iflog(LOG_ALERT, fmt __VA_OPT__(, ) __VA_ARGS__) +#define emergency(fmt, ...) __iflog(LOG_EMERG, fmt __VA_OPT__(, ) __VA_ARGS__) + #define ND_OPT_RECURSIVE_DNS 25 #define ND_OPT_DNSSL 31 diff --git a/src/ra.c b/src/ra.c index 47343aa..40621d7 100644 --- a/src/ra.c +++ b/src/ra.c @@ -28,7 +28,6 @@ #include #include #include -#include #include #include #include @@ -231,7 +230,7 @@ static void ra_send_rs(_o_unused int signal) len = sizeof(struct icmp6_hdr); if (sendto(sock, &rs, len, MSG_DONTWAIT, (struct sockaddr*)&dest, sizeof(dest)) < 0) - syslog(LOG_ERR, "Failed to send RS (%s)", strerror(errno)); + error("Failed to send RS (%s)", strerror(errno)); if (++rs_attempt <= 3) alarm(4); @@ -281,7 +280,7 @@ bool ra_link_up(void) } while (read > 0); if (ret) { - syslog(LOG_NOTICE, "carrier => %i event on %s", (int)!nocarrier, if_name); + notice("carrier => %i event on %s", (int)!nocarrier, if_name); rs_attempt = 0; ra_send_rs(SIGALRM); @@ -363,7 +362,7 @@ static bool ra_generate_addr_eui64(void) sock = socket(AF_INET6, SOCK_DGRAM, 0); if (sock < 0) { - syslog(LOG_ERR, + error( "%s: error creating EUI64 socket", if_name); return false; @@ -373,7 +372,7 @@ static bool ra_generate_addr_eui64(void) strncpy(ifr.ifr_name, if_name, sizeof(ifr.ifr_name) - 1); if (ioctl(sock, SIOCGIFHWADDR, &ifr) != 0) { - syslog(LOG_ERR, + error( "%s: error getting EUI64 HW address", if_name); close(sock); @@ -383,7 +382,7 @@ static bool ra_generate_addr_eui64(void) close(sock); if (!odhcp6c_is_valid_ether_addr((uint8_t *) ifr.ifr_hwaddr.sa_data)) { - syslog(LOG_ERR, + error( "%s: invalid EUI64 HW address", if_name); return false; @@ -411,14 +410,14 @@ static bool ra_generate_addr_ll(void) sock = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6); if (sock < 0) { - syslog(LOG_ERR, + error( "%s: error creating LLA socket", if_name); return false; } if (connect(sock, (struct sockaddr*) &addr, sizeof(addr)) != 0) { - syslog(LOG_ERR, + error( "%s: error connecting LLA socket", if_name); close(sock); @@ -426,7 +425,7 @@ static bool ra_generate_addr_ll(void) } if (getsockname(sock, (struct sockaddr*) &addr, &alen) != 0) { - syslog(LOG_ERR, + error( "%s: error getting address from LLA socket", if_name); close(sock); @@ -445,7 +444,7 @@ static bool ra_generate_addr_rand(void) if (odhcp6c_random(&ra_addr.s6_addr[8], 8) != 8) { ra_addr.s6_addr32[2] = 0; ra_addr.s6_addr32[3] = 0; - syslog(LOG_ERR, + error( "%s: error generating random interface address", if_name); return false; diff --git a/src/script.c b/src/script.c index 209f7ee..8621d98 100644 --- a/src/script.c +++ b/src/script.c @@ -22,7 +22,6 @@ #include #include #include -#include #include #include @@ -500,7 +499,7 @@ void script_call(const char *status, int delay, bool resume) if (capt_port_ra_len > 0 && capt_port_dhcpv6_len > 0) { if (capt_port_ra_len != capt_port_dhcpv6_len || !memcmp(capt_port_dhcpv6, capt_port_ra, capt_port_dhcpv6_len)) - syslog(LOG_ERR, + error( "%s received via different vectors differ: preferring URI from DHCPv6", CAPT_PORT_URI_STR); } diff --git a/src/ubus.c b/src/ubus.c index 44349e8..3530f33 100644 --- a/src/ubus.c +++ b/src/ubus.c @@ -65,7 +65,6 @@ #include #include #include -#include #include "config.h" #include "odhcp6c.h" @@ -76,7 +75,7 @@ int ret = (stmt); \ if (ret != UBUS_STATUS_OK) \ { \ - syslog(LOG_ERR, "%s failed: %s (%d)", #stmt, ubus_strerror(ret), ret); \ + error("%s failed: %s (%d)", #stmt, ubus_strerror(ret), ret); \ return ret; \ } \ } while (0) @@ -195,7 +194,7 @@ static void ubus_disconnect_cb(struct ubus_context *ubus) ret = ubus_reconnect(ubus, NULL); if (ret) { - syslog(LOG_ERR, "Cannot reconnect to ubus: %s", ubus_strerror(ret)); + error("Cannot reconnect to ubus: %s", ubus_strerror(ret)); ubus_destroy(ubus); } } @@ -227,7 +226,7 @@ struct ubus_context *ubus_get_ctx(void) void ubus_destroy(struct ubus_context *ubus) { - syslog(LOG_NOTICE, "Disconnecting from ubus"); + notice("Disconnecting from ubus"); if (ubus != NULL) ubus_free(ubus); @@ -565,7 +564,7 @@ static int states_to_blob(void) if (capt_port_ra_len > 0 && capt_port_dhcpv6_len > 0) { if (capt_port_ra_len != capt_port_dhcpv6_len || !memcmp(capt_port_dhcpv6, capt_port_ra, capt_port_dhcpv6_len)) - syslog(LOG_ERR, + error( "%s received via different vectors differ: preferring URI from DHCPv6", CAPT_PORT_URI_STR); }