From 7e16435ee21b4ae23011bdf0e88e361b437c73d4 Mon Sep 17 00:00:00 2001 From: Anjali Nijhara Date: Wed, 7 Feb 2024 16:51:55 +0530 Subject: [PATCH] Add dlog support Change-Id: Ica5fb4f28eccd095ee10b27ee1b48e612eb45b77 --- packaging/toybox.spec | 7 +++- toys/pending/dhcp.c | 91 ++++++++++++++++++++-------------------- toys/pending/dhcpd.c | 113 +++++++++++++++++++++++++------------------------- toys/pending/log.h | 14 +++++++ 4 files changed, 122 insertions(+), 103 deletions(-) create mode 100644 toys/pending/log.h diff --git a/packaging/toybox.spec b/packaging/toybox.spec index c875a22..ec015f9 100644 --- a/packaging/toybox.spec +++ b/packaging/toybox.spec @@ -14,6 +14,7 @@ Source1001: toybox.manifest BuildRequires : smack-devel BuildRequires : libattr-devel +BuildRequires : pkgconfig(dlog) %description Toybox is a single binary which includes versions of a large number @@ -86,12 +87,14 @@ cp %{SOURCE1001} . # create a minimum dynamic toybox (ELF) that consists of 'nslookup', 'ping', and 'dhcpd'. cp %{SOURCE1} .config -make -j 4 CC="gcc $RPM_OPT_FLAGS" CFLAGS="$CFLAGS -fPIE" LDOPTIMIZE="-Wl,--gc-sections -pie" +export LDFLAGS=" -ldlog" +make -j 4 CC+="gcc $RPM_OPT_FLAGS" CFLAGS="$CFLAGS -fPIE -I/usr/include/dlog/" LDOPTIMIZE="-Wl,--gc-sections -pie" cp toybox toybox-dynamic # create a dynamic toybox-full (ELF) that include most of the applets including 'init'. cp %{SOURCE11} .config -make -j 4 CC="gcc $RPM_OPT_FLAGS" CFLAGS="$CFLAGS -fPIE" LDOPTIMIZE="-Wl,--gc-sections -pie" +export LDFLAGS=" -ldlog" +make -j 4 CC+="gcc $RPM_OPT_FLAGS" CFLAGS="$CFLAGS -fPIE -I/usr/include/dlog/" LDOPTIMIZE="-Wl,--gc-sections -pie" cp toybox toybox-dynamic-full %install diff --git a/toys/pending/dhcp.c b/toys/pending/dhcp.c index 0451c81..25d1c48 100644 --- a/toys/pending/dhcp.c +++ b/toys/pending/dhcp.c @@ -48,6 +48,7 @@ config DHCP #define FOR_dhcp #include "toys.h" +#include "log.h" // TODO: headers not in posix: #include @@ -300,18 +301,18 @@ static int get_interface( char *interface, int *ifindex, uint32_t *oip, uint8_t if (oip) { xioctl(fd, SIOCGIFADDR, &req); ip = (struct sockaddr_in*) &req.ifr_addr; - dbg("IP %s\n", inet_ntoa(ip->sin_addr)); + SERR("IP %s\n", inet_ntoa(ip->sin_addr)); *oip = ntohl(ip->sin_addr.s_addr); } if (ifindex) { xioctl(fd, SIOCGIFINDEX, &req); - dbg("Adapter index %d\n", req.ifr_ifindex); + SERR("Adapter index %d\n", req.ifr_ifindex); *ifindex = req.ifr_ifindex; } if (mac) { xioctl(fd, SIOCGIFHWADDR, &req); memcpy(mac, req.ifr_hwaddr.sa_data, 6); - dbg("MAC %02x:%02x:%02x:%02x:%02x:%02x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); + SERR("MAC %02x:%02x:%02x:%02x:%02x:%02x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); } close(fd); return 0; @@ -402,7 +403,7 @@ static int strtoopt( char *str, uint8_t optonly) option = strtok((char*)str, ":"); if (!option) return -1; - dbg("-x option : %s ", option); + SERR("-x option : %s ", option); optcode = strtou32(option); if (optcode > 0 && optcode < 256) { // raw option @@ -428,7 +429,7 @@ static int strtoopt( char *str, uint8_t optonly) valstr = strtok(NULL, "\n"); if (!valstr) error_exit("option %s has no value defined.\n", option); - dbg(" value : %-20s \n ", valstr); + SERR(" value : %-20s \n ", valstr); switch (flag) { case DHCP_NUM32: options_list[count].len = sizeof(uint32_t); @@ -540,10 +541,10 @@ static void run_script(dhcpc_result_t *res, char *name) if (stat(script, &sts) == -1 && errno == ENOENT) return; if (fill_envp(res)) { - dbg("Failed to create environment variables."); + SERR("Failed to create environment variables."); return; } - dbg("Executing %s %s\n", script, name); + SERR("Executing %s %s\n", script, name); argv[0] = (char*) script; argv[1] = (char*) name; argv[2] = NULL; @@ -551,7 +552,7 @@ static void run_script(dhcpc_result_t *res, char *name) pid = vfork(); if (pid < 0) { - dbg("Fork failed.\n"); + SERR("Fork failed.\n"); return; } if (!pid) { @@ -564,7 +565,7 @@ static void run_script(dhcpc_result_t *res, char *name) errno = error; perror_msg("script exec failed"); } - dbg("script complete.\n"); + SERR("script complete.\n"); } // returns a randome ID @@ -584,29 +585,29 @@ static int mode_raw(void) struct sockaddr_ll sock; if (state->sockfd > 0) close(state->sockfd); - dbg("Opening raw socket on ifindex %d\n", state->ifindex); + SERR("Opening raw socket on ifindex %d\n", state->ifindex); state->sockfd = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP)); if (state->sockfd < 0) { - dbg("MODE RAW : socket fail ERROR : %d\n", state->sockfd); + SERR("MODE RAW : socket fail ERROR : %d\n", state->sockfd); return -1; } - dbg("Got raw socket fd %d\n", state->sockfd); + SERR("Got raw socket fd %d\n", state->sockfd); memset(&sock, 0, sizeof(sock)); sock.sll_family = AF_PACKET; sock.sll_protocol = htons(ETH_P_IP); sock.sll_ifindex = state->ifindex; if (bind(state->sockfd, (struct sockaddr *) &sock, sizeof(sock))) { - dbg("MODE RAW : bind fail.\n"); + SERR("MODE RAW : bind fail.\n"); close(state->sockfd); return -1; } state->mode = MODE_RAW; if (setsockopt(state->sockfd, SOL_SOCKET, SO_ATTACH_FILTER, &filter_prog, sizeof(filter_prog)) < 0) - dbg("MODE RAW : filter attach fail.\n"); + SERR("MODE RAW : filter attach fail.\n"); - dbg("MODE RAW : success\n"); + SERR("MODE RAW : success\n"); return 0; } @@ -619,15 +620,15 @@ static int mode_app(void) state->mode = MODE_OFF; if (state->sockfd > 0) close(state->sockfd); - dbg("Opening listen socket on *:%d %s\n", DHCPC_CLIENT_PORT, state->iface); + SERR("Opening listen socket on *:%d %s\n", DHCPC_CLIENT_PORT, state->iface); state->sockfd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); if (state->sockfd < 0) { - dbg("MODE APP : socket fail ERROR: %d\n", state->sockfd); + SERR("MODE APP : socket fail ERROR: %d\n", state->sockfd); return -1; } setsockopt(state->sockfd, SOL_SOCKET, SO_REUSEADDR, &set, sizeof(set)); if (setsockopt(state->sockfd, SOL_SOCKET, SO_BROADCAST, &set, sizeof(set)) == -1) { - dbg("MODE APP : brodcast failed.\n"); + SERR("MODE APP : brodcast failed.\n"); close(state->sockfd); return -1; } @@ -642,11 +643,11 @@ static int mode_app(void) if (bind(state->sockfd, (struct sockaddr *) &addr, sizeof(addr))) { close(state->sockfd); - dbg("MODE APP : bind failed.\n"); + SERR("MODE APP : bind failed.\n"); return -1; } state->mode = MODE_APP; - dbg("MODE APP : success\n"); + SERR("MODE APP : success\n"); return 0; } @@ -658,15 +659,15 @@ static int read_raw(void) memset(&packet, 0, sizeof(packet)); if ((bytes = read(state->sockfd, &packet, sizeof(packet))) < 0) { - dbg("\tPacket read error, ignoring\n"); + SERR("\tPacket read error, ignoring\n"); return bytes; } if (bytes < (int) (sizeof(packet.iph) + sizeof(packet.udph))) { - dbg("\tPacket is too short, ignoring\n"); + SERR("\tPacket is too short, ignoring\n"); return -2; } if (bytes < ntohs(packet.iph.tot_len)) { - dbg("\tOversized packet, ignoring\n"); + SERR("\tOversized packet, ignoring\n"); return -2; } // ignore any extra garbage bytes @@ -676,14 +677,14 @@ static int read_raw(void) || packet.iph.ihl != (sizeof(packet.iph) >> 2) || packet.udph.dest != htons(DHCPC_CLIENT_PORT) || ntohs(packet.udph.len) != (uint16_t)(bytes - sizeof(packet.iph))) { - dbg("\tUnrelated/bogus packet, ignoring\n"); + SERR("\tUnrelated/bogus packet, ignoring\n"); return -2; } // verify IP checksum check = packet.iph.check; packet.iph.check = 0; if (check != dhcp_checksum(&packet.iph, sizeof(packet.iph))) { - dbg("\tBad IP header checksum, ignoring\n"); + SERR("\tBad IP header checksum, ignoring\n"); return -2; } memset(&packet.iph, 0, ((size_t) &((struct iphdr *)0)->protocol)); @@ -691,12 +692,12 @@ static int read_raw(void) check = packet.udph.check; packet.udph.check = 0; if (check && check != dhcp_checksum(&packet, bytes)) { - dbg("\tPacket with bad UDP checksum received, ignoring\n"); + SERR("\tPacket with bad UDP checksum received, ignoring\n"); return -2; } memcpy(&state->pdhcp, &packet.dhcp, bytes - (sizeof(packet.iph) + sizeof(packet.udph))); if (state->pdhcp.cookie != htonl(DHCP_MAGIC)) { - dbg("\tPacket with bad magic, ignoring\n"); + SERR("\tPacket with bad magic, ignoring\n"); return -2; } return bytes - sizeof(packet.iph) - sizeof(packet.udph); @@ -708,11 +709,11 @@ static int read_app(void) memset(&state->pdhcp, 0, sizeof(dhcp_msg_t)); if ((ret = read(state->sockfd, &state->pdhcp, sizeof(dhcp_msg_t))) < 0) { - dbg("Packet read error, ignoring\n"); + SERR("Packet read error, ignoring\n"); return ret; /* returns -1 */ } if (state->pdhcp.cookie != htonl(DHCP_MAGIC)) { - dbg("Packet with bad magic, ignoring\n"); + SERR("Packet with bad magic, ignoring\n"); return -2; } return ret; @@ -730,7 +731,7 @@ static int send_raw(void) memcpy(&packet.dhcp, &state->pdhcp, sizeof(dhcp_msg_t)); if ((fd = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP))) < 0) { - dbg("SEND RAW: socket failed\n"); + SERR("SEND RAW: socket failed\n"); return result; } memset(&dest_sll, 0, sizeof(dest_sll)); @@ -741,7 +742,7 @@ static int send_raw(void) memcpy(dest_sll.sll_addr, bmacaddr , 6); if (bind(fd, (struct sockaddr *) &dest_sll, sizeof(dest_sll)) < 0) { - dbg("SEND RAW: bind failed\n"); + SERR("SEND RAW: bind failed\n"); close(fd); return result; } @@ -764,7 +765,7 @@ static int send_raw(void) (struct sockaddr *) &dest_sll, sizeof(dest_sll)); close(fd); - if (result < 0) dbg("SEND RAW: PACKET send error\n"); + if (result < 0) SERR("SEND RAW: PACKET send error\n"); return result; } @@ -775,7 +776,7 @@ static int send_app(void) int fd, ret = -1; if ((fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) { - dbg("SEND APP: sock failed.\n"); + SERR("SEND APP: sock failed.\n"); return ret; } setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &set, sizeof(set)); @@ -785,7 +786,7 @@ static int send_app(void) cli.sin_port = htons(DHCPC_CLIENT_PORT); cli.sin_addr.s_addr = state->pdhcp.ciaddr; if (bind(fd, (struct sockaddr *)&cli, sizeof(cli)) == -1) { - dbg("SEND APP: bind failed.\n"); + SERR("SEND APP: bind failed.\n"); goto error_fd; } memset(&cli, 0, sizeof(cli)); @@ -793,15 +794,15 @@ static int send_app(void) cli.sin_port = htons(DHCPC_SERVER_PORT); cli.sin_addr.s_addr = state->serverid.s_addr; if (connect(fd, (struct sockaddr *)&cli, sizeof(cli)) == -1) { - dbg("SEND APP: connect failed.\n"); + SERR("SEND APP: connect failed.\n"); goto error_fd; } int padding = 308 - 1 - dhcp_opt_size(state->pdhcp.options); if((ret = write(fd, &state->pdhcp, sizeof(dhcp_msg_t) - padding)) < 0) { - dbg("SEND APP: write failed error %d\n", ret); + SERR("SEND APP: write failed error %d\n", ret); goto error_fd; } - dbg("SEND APP: write success wrote %d\n", ret); + SERR("SEND APP: write success wrote %d\n", ret); error_fd: close(fd); return ret; @@ -811,14 +812,14 @@ error_fd: static void signal_handler(int sig) { unsigned char ch = sig; - if (write(sigfd.wr, &ch, 1) != 1) dbg("can't send signal\n"); + if (write(sigfd.wr, &ch, 1) != 1) SERR("can't send signal\n"); } // signal setup for SIGUSR1 SIGUSR2 SIGTERM static int setup_signal() { if (pipe((int *)&sigfd) < 0) { - dbg("signal pipe failed\n"); + SERR("signal pipe failed\n"); return -1; } fcntl(sigfd.wr , F_SETFD, FD_CLOEXEC); @@ -1329,7 +1330,7 @@ void dhcp_main(void) retval = 0; int maxfd = (sigfd.rd > state->sockfd)? sigfd.rd : state->sockfd; - dbg("select wait ....\n"); + SERR("select wait ....\n"); uint32_t timestmp = time(NULL); if((retval = select(maxfd + 1, &rfds, NULL, NULL, &tv)) < 0) { if (errno == EINTR) { @@ -1389,7 +1390,7 @@ lease_fail: goto lease_fail; case STATE_BOUND: state->status = STATE_RENEWING; - dbg("Entering renew state\n"); + SERR("Entering renew state\n"); // FALLTHROUGH case STATE_RENEW_REQUESTED: // FALLTHROUGH case STATE_RENEWING: @@ -1400,7 +1401,7 @@ renew_requested: waited = 0; continue; } - dbg("Entering rebinding state\n"); + SERR("Entering rebinding state\n"); state->status = STATE_REBINDING; // FALLTHROUGH case STATE_REBINDING: @@ -1427,7 +1428,7 @@ renew_requested: if (FD_ISSET(sigfd.rd, &rfds)) { // Some Activity on RDFDs : is signal unsigned char sig; if (read(sigfd.rd, &sig, 1) != 1) { - dbg("signal read failed.\n"); + SERR("signal read failed.\n"); continue; } switch (sig) { @@ -1454,7 +1455,7 @@ renew_requested: } } if (FD_ISSET(state->sockfd, &rfds)) { // Some Activity on RDFDs : is socket - dbg("main sock read\n"); + SERR("main sock read\n"); uint8_t msgType; if (state->mode == MODE_RAW) bufflen = read_raw(); if (state->mode == MODE_APP) bufflen = read_app(); @@ -1508,7 +1509,7 @@ renew_requested: waited = 0; continue; } else if (msgType == DHCPNAK) { - dbg("NACK received.\n"); + SERR("NACK received.\n"); run_script(&result, "nak"); if (state->status != STATE_REQUESTING) run_script(NULL, "deconfig"); mode_raw(); diff --git a/toys/pending/dhcpd.c b/toys/pending/dhcpd.c index 3bac14d..751b8c6 100644 --- a/toys/pending/dhcpd.c +++ b/toys/pending/dhcpd.c @@ -37,6 +37,7 @@ config DEBUG_DHCP #define FOR_dhcpd #include "toys.h" +#include "log.h" #include #include @@ -414,7 +415,7 @@ static int get_interface(const char *interface, int *ifindex, uint32_t *oip, for (i = 32; i; i--) if ((*(ptr--) = ipv6_addr[i])) if (!(i&3)) *(ptr--) = ':'; - dbg("ipv6 %s\n", ipv6_addr); + SERR("ipv6 %s\n", ipv6_addr); if(inet_pton(AF_INET6, ipv6_addr, &ip6.sin6_addr) <= 0) error_msg("inet : the ipv6 address is not proper"); else @@ -424,20 +425,20 @@ static int get_interface(const char *interface, int *ifindex, uint32_t *oip, if (oip) { xioctl(fd, SIOCGIFADDR, &req); ip = (struct sockaddr_in*) &req.ifr_addr; - dbg("IP %s\n", inet_ntoa(ip->sin_addr)); + SERR("IP %s\n", inet_ntoa(ip->sin_addr)); *oip = ntohl(ip->sin_addr.s_addr); } } if (ifindex) { xioctl(fd, SIOCGIFINDEX, &req); - dbg("Adapter index %d\n", req.ifr_ifindex); + SERR("Adapter index %d\n", req.ifr_ifindex); *ifindex = req.ifr_ifindex; } if (mac) { xioctl(fd, SIOCGIFHWADDR, &req); memcpy(mac, req.ifr_hwaddr.sa_data, 6); - dbg("MAC %02x:%02x:%02x:%02x:%02x:%02x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); + SERR("MAC %02x:%02x:%02x:%02x:%02x:%02x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); } close(fd); @@ -494,7 +495,7 @@ static void signal_handler(int sig) { unsigned char ch = sig; if (write(sigfd.wr, &ch, 1) != 1) { - dbg("can't send signal\n"); + SERR("can't send signal\n"); exit(0); } } @@ -503,7 +504,7 @@ static void signal_handler(int sig) static int setup_signal() { if (pipe((int *)&sigfd) < 0) { - dbg("signal pipe failed\n"); + SERR("signal pipe failed\n"); return -1; } fcntl(sigfd.wr , F_SETFD, FD_CLOEXEC); @@ -597,10 +598,10 @@ static int strtoopt(const char *str, void *var) if (!flag || !optcode) return -1; if (!(valstr = strtok(NULL, " \t"))) { - dbg("config : option %s has no value defined.\n", option); + SERR("config : option %s has no value defined.\n", option); return -1; } - dbg(" value : %-20s : ", valstr); + SERR(" value : %-20s : ", valstr); switch (flag) { case DHCP_NUM32: options_list[count].len = sizeof(uint32_t); @@ -773,9 +774,9 @@ static int parse_server_config(char *config_file, struct config_keyword *confkey if (tcount<=1) goto free_tk0_continue; for (count = 0; count < size; count++) { if (!strcmp(confkey[count].keyword,tokens[0])) { - dbg("got config : %15s : ", confkey[count].keyword); + SERR("got config : %15s : ", confkey[count].keyword); if (confkey[count].handler(tokens[1], confkey[count].var) == 0) - dbg("%s \n", tokens[1]); + SERR("%s \n", tokens[1]); break; } } @@ -798,7 +799,7 @@ static int open_listensock6(void) if (gstate.listensock > 0) close(gstate.listensock); - dbg("Opening listen socket on *:%d %s\n", gconfig.port, gconfig.interface); + SERR("Opening listen socket on *:%d %s\n", gconfig.port, gconfig.interface); gstate.listensock = xsocket(PF_INET6, SOCK_DGRAM, 0); setsockopt(gstate.listensock, SOL_SOCKET, SO_REUSEADDR, &constone, sizeof(constone)); @@ -834,7 +835,7 @@ static int open_listensock6(void) return -1; } - dbg("OPEN : success\n"); + SERR("OPEN : success\n"); return 0; } @@ -846,7 +847,7 @@ static int open_listensock(void) if (gstate.listensock > 0) close(gstate.listensock); - dbg("Opening listen socket on *:%d %s\n", gconfig.port, gconfig.interface); + SERR("Opening listen socket on *:%d %s\n", gconfig.port, gconfig.interface); gstate.listensock = xsocket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); setsockopt(gstate.listensock, SOL_SOCKET, SO_REUSEADDR, &constone, sizeof(constone)); if (setsockopt(gstate.listensock, SOL_SOCKET, SO_BROADCAST, &constone, sizeof(constone)) == -1) { @@ -867,7 +868,7 @@ static int open_listensock(void) close(gstate.listensock); perror_exit("bind failed"); } - dbg("OPEN : success\n"); + SERR("OPEN : success\n"); return 0; } @@ -884,7 +885,7 @@ static int send_packet6(uint8_t relay, uint8_t *client_lla, uint16_t optlen) padding = sizeof(packet.dhcp6.options) - optlen; if ((fd = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IPV6))) < 0) { - dbg("SEND : ipv6 socket failed\n"); + SERR("SEND : ipv6 socket failed\n"); return -1; } memset(&dest_sll, 0, sizeof(dest_sll)); @@ -895,7 +896,7 @@ static int send_packet6(uint8_t relay, uint8_t *client_lla, uint16_t optlen) memcpy(dest_sll.sll_addr, client_lla, sizeof(client_lla)); if (bind(fd, (struct sockaddr *) &dest_sll, sizeof(dest_sll)) < 0) { - dbg("SEND : bind failed\n"); + SERR("SEND : bind failed\n"); close(fd); return -1; } @@ -924,9 +925,9 @@ static int send_packet6(uint8_t relay, uint8_t *client_lla, uint16_t optlen) result = sendto(fd, &packet, sizeof(dhcp6_raw_t)-padding, 0, (struct sockaddr *) &dest_sll, sizeof(dest_sll)); - dbg("sendto %d\n", result); + SERR("sendto %d\n", result); close(fd); - if (result < 0) dbg("PACKET send error\n"); + if (result < 0) SERR("PACKET send error\n"); return result; } @@ -943,7 +944,7 @@ static int send_packet(uint8_t broadcast) memcpy(&packet.dhcp, &gstate.send.send_pkt, sizeof(dhcp_msg_t)); if ((fd = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP))) < 0) { - dbg("SEND : socket failed\n"); + SERR("SEND : socket failed\n"); return -1; } memset(&dest_sll, 0, sizeof(dest_sll)); @@ -954,7 +955,7 @@ static int send_packet(uint8_t broadcast) memcpy(dest_sll.sll_addr, (broadcast)?bmacaddr:gstate.rcvd.rcvd_pkt.chaddr , 6); if (bind(fd, (struct sockaddr *) &dest_sll, sizeof(dest_sll)) < 0) { - dbg("SEND : bind failed\n"); + SERR("SEND : bind failed\n"); close(fd); return -1; } @@ -976,9 +977,9 @@ static int send_packet(uint8_t broadcast) result = sendto(fd, &packet, sizeof(dhcp_raw_t) - padding, 0, (struct sockaddr *) &dest_sll, sizeof(dest_sll)); - dbg("sendto %d\n", result); + SERR("sendto %d\n", result); close(fd); - if (result < 0) dbg("PACKET send error\n"); + if (result < 0) SERR("PACKET send error\n"); return result; } @@ -989,15 +990,15 @@ static int read_packet6(void) memset(&gstate.rcvd.rcvd_pkt6, 0, sizeof(dhcp6_msg_t)); ret = read(gstate.listensock, &gstate.rcvd.rcvd_pkt6, sizeof(dhcp6_msg_t)); if (ret < 0) { - dbg("Packet read error, ignoring. \n"); + SERR("Packet read error, ignoring. \n"); return ret; // returns -1 } if (gstate.rcvd.rcvd_pkt6.msgtype < 1) { - dbg("Bad message type, igroning. \n"); + SERR("Bad message type, igroning. \n"); return -2; } - dbg("Received an ipv6 packet. Size : %d \n", ret); + SERR("Received an ipv6 packet. Size : %d \n", ret); return ret; } @@ -1009,22 +1010,22 @@ static int read_packet(void) memset(&gstate.rcvd.rcvd_pkt, 0, sizeof(dhcp_msg_t)); ret = read(gstate.listensock, &gstate.rcvd.rcvd_pkt, sizeof(dhcp_msg_t)); if (ret < 0) { - dbg("Packet read error, ignoring. \n"); + SERR("Packet read error, ignoring. \n"); return ret; // returns -1 } if (gstate.rcvd.rcvd_pkt.cookie != htonl(DHCP_MAGIC)) { - dbg("Packet with bad magic, ignoring. \n"); + SERR("Packet with bad magic, ignoring. \n"); return -2; } if (gstate.rcvd.rcvd_pkt.op != 1) { //BOOTPREQUEST - dbg("Not a BOOT REQUEST ignoring. \n"); + SERR("Not a BOOT REQUEST ignoring. \n"); return -2; } if (gstate.rcvd.rcvd_pkt.hlen != 6) { - dbg("hlen != 6 ignoring. \n"); + SERR("hlen != 6 ignoring. \n"); return -2; } - dbg("Received a packet. Size : %d \n", ret); + SERR("Received a packet. Size : %d \n", ret); return ret; } @@ -1125,7 +1126,7 @@ static uint8_t* get_optval6(uint8_t *optptr, uint16_t opt, uint16_t *datalen, vo memcpy(&optcode, optptr, sizeof(uint16_t)); memcpy(&len, optptr+2, sizeof(uint16_t)); if(!optcode) { - dbg("Option %d is not exist.\n", opt); + SERR("Option %d is not exist.\n", opt); return optptr; } optcode = ntohs(optcode); @@ -1187,7 +1188,7 @@ static void run_notify(char **argv) volatile int error = 0; pid_t pid; int rv = 0; - dbg("run_notify"); + SERR("run_notify"); if (stat(argv[0], &sts) == -1 && errno == ENOENT) { infomsg(infomode, "notify file: %s : not exist.", argv[0]); @@ -1197,7 +1198,7 @@ static void run_notify(char **argv) pid = vfork(); if (pid < 0) { - dbg("Fork failed.\n"); + SERR("Fork failed.\n"); return; } if (!pid) { @@ -1207,7 +1208,7 @@ static void run_notify(char **argv) } waitpid(pid, &rv, 0); errno = error; - dbg("wait pid (%u) rv (%d)", pid, rv); + SERR("wait pid (%u) rv (%d)", pid, rv); } static void write_leasefile(void) @@ -1706,9 +1707,9 @@ void dhcpd_main(void) msgtype = 0; int maxfd = (sigfd.rd > gstate.listensock)? sigfd.rd : gstate.listensock; - dbg("select waiting ....\n"); + SERR("select waiting ....\n"); if (tv.tv_sec < 0) { - dbg("timestmp: %u waited: %u tv_sec: %u, reset tv_sec to default value\n", timestmp, waited, tv.tv_sec); + SERR("timestmp: %u waited: %u tv_sec: %ld, reset tv_sec to default value\n", timestmp, waited, tv.tv_sec); waited = 0; tv.tv_sec = gconfig.auto_time - waited; tv.tv_usec = 0; @@ -1720,11 +1721,11 @@ void dhcpd_main(void) waited += (unsigned) time(NULL) - timestmp; continue; } - dbg("Error in select wait again...\n"); + SERR("Error in select wait again...\n"); continue; } if (!retval) { // Timed out - dbg("select wait Timed Out...\n"); + SERR("select wait Timed Out...\n"); waited = 0; (addr_version==AF_INET6)? write_lease6file() : write_leasefile(); if (get_interface(gconfig.interface, &gconfig.ifindex, @@ -1739,7 +1740,7 @@ void dhcpd_main(void) if (FD_ISSET(sigfd.rd, &rfds)) { // Some Activity on RDFDs : is signal unsigned char sig; if (read(sigfd.rd, &sig, 1) != 1) { - dbg("signal read failed.\n"); + SERR("signal read failed.\n"); continue; } switch (sig) { @@ -1751,7 +1752,7 @@ void dhcpd_main(void) } } if (FD_ISSET(gstate.listensock, &rfds)) { // Some Activity on RDFDs : is socke - dbg("select listen sock read\n"); + SERR("select listen sock read\n"); if(addr_version==AF_INET6) { void *client_duid, *server_duid, *client_ia_na, *server_ia_na, *client_ia_pd, *server_ia_pd; @@ -1771,19 +1772,19 @@ void dhcpd_main(void) if (!gstate.rqcode || gstate.rqcode < DHCP6SOLICIT || gstate.rqcode > DHCP6RELAYREPLY) { - dbg("no or bad message type option, ignoring packet.\n"); + SERR("no or bad message type option, ignoring packet.\n"); continue; } if (!gstate.rcvd.rcvd_pkt6.transaction_id || memcmp(gstate.rcvd.rcvd_pkt6.transaction_id, transactionid, 3)) { - dbg("no or bad transaction id, ignoring packet.\n"); + SERR("no or bad transaction id, ignoring packet.\n"); continue; } waited += time(NULL) - timestmp; switch (gstate.rqcode) { case DHCP6SOLICIT: - dbg("Message Type: DHCP6SOLICIT\n"); + SERR("Message Type: DHCP6SOLICIT\n"); optptr = prepare_send_pkt6(DHCP6ADVERTISE); optlen = 0; @@ -1909,7 +1910,7 @@ void dhcpd_main(void) write_lease6file(); break; case DHCP6REQUEST: - dbg("Message Type: DHCP6REQUEST\n"); + SERR("Message Type: DHCP6REQUEST\n"); optptr = prepare_send_pkt6(DHCP6REPLY); optlen = 0; @@ -1995,11 +1996,11 @@ void dhcpd_main(void) case DHCP6RENEW: //TODO case DHCP6REBIND: //TODO case DHCP6RELEASE: - dbg("Message Type: DHCP6RELEASE\n"); + SERR("Message Type: DHCP6RELEASE\n"); optptr = prepare_send_pkt6(DHCP6REPLY); break; default: - dbg("Message Type : %u\n", gstate.rqcode); + SERR("Message Type : %u\n", gstate.rqcode); break; } @@ -2014,13 +2015,13 @@ void dhcpd_main(void) DHCP_OPT_MESSAGE_TYPE, &gstate.rqcode); if (gstate.rqcode == 0 || gstate.rqcode < DHCPDISCOVER || gstate.rqcode > DHCPINFORM) { - dbg("no or bad message type option, ignoring packet.\n"); + SERR("no or bad message type option, ignoring packet.\n"); continue; } get_optval((uint8_t*) &gstate.rcvd.rcvd_pkt.options, DHCP_OPT_SERVER_ID, &serverid); if (serverid && (serverid != gconfig.server_nip)) { - dbg("server ID doesn't match, ignoring packet.\n"); + SERR("server ID doesn't match, ignoring packet.\n"); continue; } @@ -2028,7 +2029,7 @@ void dhcpd_main(void) switch (gstate.rqcode) { case DHCPDISCOVER: msgtype = DHCPOFFER; - dbg("Message Type : DHCPDISCOVER\n"); + SERR("Message Type : DHCPDISCOVER\n"); get_optval((uint8_t*) &gstate.rcvd.rcvd_pkt.options, DHCP_OPT_REQUESTED_IP, &requested_nip); get_optval((uint8_t*) &gstate.rcvd.rcvd_pkt.options, @@ -2042,7 +2043,7 @@ void dhcpd_main(void) msgtype = DHCPNAK; optptr = set_optval(optptr, DHCP_OPT_MESSAGE_TYPE, &msgtype, 1); send_packet(1); - dbg("Send Message Type : DHCPNAK\n"); + SERR("Send Message Type : DHCPNAK\n"); break; } get_optval((uint8_t*) &gstate.rcvd.rcvd_pkt.options, @@ -2053,11 +2054,11 @@ void dhcpd_main(void) optptr = set_optval(optptr, DHCP_OPT_LEASE_TIME, &reqested_lease, 4); optptr = set_reqparam(optptr, gstate.rqopt); send_packet(1); - dbg("Send Message Type : DHCPOFFER\n"); + SERR("Send Message Type : DHCPOFFER\n"); break; case DHCPREQUEST: msgtype = DHCPACK; - dbg("Message Type : DHCPREQUEST\n"); + SERR("Message Type : DHCPREQUEST\n"); optptr = prepare_send_pkt(); get_optval((uint8_t*) &gstate.rcvd.rcvd_pkt.options, DHCP_OPT_REQUESTED_IP, &requested_nip); @@ -2072,7 +2073,7 @@ void dhcpd_main(void) msgtype = DHCPNAK; optptr = set_optval(optptr, DHCP_OPT_MESSAGE_TYPE, &msgtype, 1); send_packet(1); - dbg("Send Message Type : DHCPNAK\n"); + SERR("Send Message Type : DHCPNAK\n"); break; } get_reqparam(&gstate.rqopt); @@ -2082,12 +2083,12 @@ void dhcpd_main(void) optptr = set_optval(optptr, DHCP_OPT_LEASE_TIME, &reqested_lease, 4); optptr = set_reqparam(optptr, gstate.rqopt); send_packet(1); - dbg("Send Message Type : DHCPACK\n"); + SERR("Send Message Type : DHCPACK\n"); write_leasefile(); break; case DHCPDECLINE:// FALL THROUGH case DHCPRELEASE: - dbg("Message Type : DHCPDECLINE or DHCPRELEASE \n"); + SERR("Message Type : DHCPDECLINE or DHCPRELEASE \n"); get_optval((uint8_t*) &gstate.rcvd.rcvd_pkt.options, DHCP_OPT_SERVER_ID, &serverid); if (serverid != gconfig.server_nip) break; @@ -2097,7 +2098,7 @@ void dhcpd_main(void) (gstate.rqcode==DHCPRELEASE)?0:gconfig.decline_time); break; default: - dbg("Message Type : %u\n", gstate.rqcode); + SERR("Message Type : %u\n", gstate.rqcode); break; } } diff --git a/toys/pending/log.h b/toys/pending/log.h new file mode 100644 index 0000000..88fa7cb --- /dev/null +++ b/toys/pending/log.h @@ -0,0 +1,14 @@ +/* + * Toybox logging mechanism in Tizen based device + * + * Copyright (c) 2024 Samsung Electronics Co., Ltd. All rights reserved. + */ + +#include + +#define LOG_TAG "TOYBOX" + +#define SERR(format, args...) \ + do { \ + SLOGE(format, ##args); \ + } while (0) -- 2.7.4