Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2130.outbound.protection.outlook.com [40.107.20.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8090C1FB8 for ; Tue, 12 Apr 2022 11:52:04 +0000 (UTC) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fGJYoojSsqB1POFUdJCdxk3oTrWUJIEuHnoZ9YUwx5oibv3Ov2yaRJvlElKOnO+Sx38BlOUJuZwJVSNh76eyCKOTSfBpiRzNa9Nm4EQ5P4XGVDpLJIExgtg39qEWWaYekONs7kuxt+wQKGVxA5m6pRMjjG1F6h9K/h0o19+BXOp1I1uo+maBJzCtwxV9SbTY8tdKp1Ijqsh6JACpMSskrWFJw55HflzIlSYLxto2QopfRn6+R/fyPZGn704AWSYkcq3yPRfg5spvAyQ4bUc5K+n5s3o9QYuczsjgY8vaZK9gK0ba1DDs4tyhqyWyTgJaUhg3f5+rpgDOz9sI5S0cSg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=dCSj03n1Gbv0JkJlLMeteCMbZ5kWB5u4uimq07zrrL0=; b=if4uVCTk+JbqDqWy4X8hz0F4d2YsBZZj6u+Ibrqpiz+RevNe+F3hzAPf6ekMVJoGaUntIcVxYURpwBPZlrktBZcc4HOD+3vHdvaFd+g6DyfPxD2OakPAU25K/nMvcbTIAUJZTgXo71aBL6tcz9gCNJLUWNQhXbNUACLcUJOa7IbfkSPd8RFRmIAdRVj0A3ZrFrLD746LT3Yu9JSf78TLZ54BiDp3SiDsO6k+ihmfBtB6LqPjHVIT2XrYPiyzLjAJxtP7v/MYakDvGRDGQbR2pVRyLn5FA7POhB4Fx22ygoXYKlhNjmQ5zZo4pH7d7qe6nr/F/oLPDPSjnn+QiIn8rw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 212.159.232.72) smtp.rcpttodomain=lists.linux.dev smtp.mailfrom=bbl.ms.philips.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=bbl.ms.philips.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Philips.onmicrosoft.com; s=selector2-Philips-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dCSj03n1Gbv0JkJlLMeteCMbZ5kWB5u4uimq07zrrL0=; b=GJ6Gv2XT2tE2NdiWPiDsam8Caz+9zUrgF2swwXZTiyk2C+ZzBDaj/8h+Fs8AU94aEixcnqrupDif2/3gq81QfnLMEoC94pyKTJns2gixSAw0fYctUIktEHelSjT+AK9AcNpQhO5mumsgXby3Tx8/HNBvn/79CyPP2s3sOR9Gu+g= Received: from AM8P191CA0018.EURP191.PROD.OUTLOOK.COM (2603:10a6:20b:21a::23) by VI1P122MB0126.EURP122.PROD.OUTLOOK.COM (2603:10a6:802:6e::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5144.30; Tue, 12 Apr 2022 11:52:01 +0000 Received: from VE1EUR01FT102.eop-EUR01.prod.protection.outlook.com (2603:10a6:20b:21a:cafe::26) by AM8P191CA0018.outlook.office365.com (2603:10a6:20b:21a::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5144.29 via Frontend Transport; Tue, 12 Apr 2022 11:52:00 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 212.159.232.72) smtp.mailfrom=bbl.ms.philips.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=bbl.ms.philips.com; Received-SPF: Pass (protection.outlook.com: domain of bbl.ms.philips.com designates 212.159.232.72 as permitted sender) receiver=protection.outlook.com; client-ip=212.159.232.72; helo=ext-eur1.smtp.philips.com; Received: from ext-eur1.smtp.philips.com (212.159.232.72) by VE1EUR01FT102.mail.protection.outlook.com (10.152.3.141) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5144.20 via Frontend Transport; Tue, 12 Apr 2022 11:52:00 +0000 Received: from smtprelay-eur1.philips.com ([130.144.57.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 256/256 bits) (Client did not present a certificate) by ext-eur1.smtp.philips.com with ESMTP id e7wvn5qElYo8veF3wnfVe8; Tue, 12 Apr 2022 13:52:00 +0200 Received: from mail.bbl.ms.philips.com ([130.143.87.230]) by smtprelay-eur1.philips.com with ESMTP id eF3vnKrnXK8w9eF3wnTEP7; Tue, 12 Apr 2022 13:52:00 +0200 X-CLAM-Verdict: legit X-CLAM-Score: ?? X-CLAM-Description: ?? Received: from bbl1llst.bbl.ms.philips.com (bbl1llst.bbl.ms.philips.com [130.143.222.207]) by mail.bbl.ms.philips.com (Postfix) with ESMTP id D34A018300C for ; Tue, 12 Apr 2022 13:51:59 +0200 (CEST) Received: by bbl1llst.bbl.ms.philips.com (Postfix, from userid 10189) id C921B5403AB; Tue, 12 Apr 2022 13:51:59 +0200 (CEST) From: Lars Steubesand To: connman@lists.linux.dev Subject: [PATCH resend 3/3] gdhcp: Add unit tests for dhcp_get_option Date: Tue, 12 Apr 2022 13:51:59 +0200 Message-Id: <20220412115159.2845-4-lars@bbl.ms.philips.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220412115159.2845-1-lars@bbl.ms.philips.com> References: <20220412115159.2845-1-lars@bbl.ms.philips.com> Reply-To: Lars Steubesand Precedence: bulk X-Mailing-List: connman@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: 6c00bf6c-aee7-48ea-8472-08da1c7ada6b X-MS-TrafficTypeDiagnostic: VI1P122MB0126:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wID7yJ1vwBbKPmq7IvfpYLrcfXPDCwvlYYV1GjXWU0yqiJ5j5Z+nzrGjW9qe5D2xZc4qmiIXYl+sJgpLB/o73geIG+hZxorG6eHBpYGVBcy2UrZwuTFiUnug2SPPrf3ALLRVSaLwN9SIM510Zz2X0xQeNz1vlJI2ajYCucG6T8C6oKJI9hzczYfq7W0+KAuI+BjcHzPURGiJa7PtK3KYMWDFboHx2VhqcGGf7wW/mYoy5XPaYAeaVUa/TIStqJej1mBRULyv6kimKGMvKKry3HXZIVu8WKTaJPElW1+xK2wCSnND7EA5Op9tLArIliNcVmWoHiI78NY3Nmh9olXIsC0/v3E4i0ayResECqBtg0vKpvuQf7okKcraWfCHOz9C0MWseSNif6S5W89g0ZXbbzIFP4ykZzK9SRRkiQvPeSpwUqjuq9BwqtS8yHB4XMHFq+h5ZWYOOCwsfypDL36zKQ4SJJ4TjqfKSd2Yag34d+4pfVkoLe8atSag2ROYeiPUjfois6AN3Kh2qb6UoQcAGNfZbi+WgNV1m0nWZdqp/K9ORkoQzllXzk5d0iEkbCtX3oVQu/ii/cKPJuCI6e6zg3iXaLE5uXrkVfBaGHoNUs/SNbcRfqFBW0YAfwxGfwe0te3cbFF2VXIjEpjpXkPmj1khbqiEY6zaDXO+zkofe2Jsf3ab28KCupTMXGaad2U/JxFChV1E0aY70Uv5GDjhLg== X-Forefront-Antispam-Report: CIP:212.159.232.72;CTRY:NL;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:ext-eur1.smtp.philips.com;PTR:ext-eur1.smtp.philips.com;CAT:NONE;SFS:(13230001)(4636009)(40470700004)(36840700001)(46966006)(26005)(120186005)(86362001)(7596003)(7636003)(83380400001)(426003)(66574015)(336012)(47076005)(36860700001)(6266002)(2616005)(186003)(1076003)(82310400005)(316002)(70206006)(70586007)(42186006)(8936002)(40460700003)(8676002)(6916009)(5660300002)(508600001)(82960400001)(356005)(2906002)(30864003)(2004002);DIR:OUT;SFP:1102; X-OriginatorOrg: ms.philips.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Apr 2022 11:52:00.1632 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6c00bf6c-aee7-48ea-8472-08da1c7ada6b X-MS-Exchange-CrossTenant-Id: 1a407a2d-7675-4d17-8692-b3ac285306e4 X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=1a407a2d-7675-4d17-8692-b3ac285306e4;Ip=[212.159.232.72];Helo=[ext-eur1.smtp.philips.com] X-MS-Exchange-CrossTenant-AuthSource: VE1EUR01FT102.eop-EUR01.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1P122MB0126 From: Lars Steubesand --- .gitignore | 1 + Makefile.am | 9 + gdhcp/client.c | 10 +- gdhcp/common.c | 20 ++- gdhcp/common.h | 2 +- gdhcp/server.c | 6 +- unit/test-dhcp-options.c | 365 +++++++++++++++++++++++++++++++++++++++ 7 files changed, 402 insertions(+), 11 deletions(-) create mode 100644 unit/test-dhcp-options.c diff --git a/.gitignore b/.gitignore index 9e8d1a409bce..80441c38808d 100644 --- a/.gitignore +++ b/.gitignore @@ -69,6 +69,7 @@ tools/netlink-test unit/test-ippool unit/test-nat unit/test-iptables +unit/test-dhcp-options doc/*.bak doc/*.stamp diff --git a/Makefile.am b/Makefile.am index c108b8f3c1fd..052ae3cf6aa8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -326,6 +326,15 @@ unit_test_ippool_LDADD = gdbus/libgdbus-internal.la \ TESTS = unit/test-ippool +noinst_PROGRAMS += unit/test-dhcp-options + +unit_test_dhcp_options_SOURCES = $(backtrace_sources) src/log.c \ + src/error.c src/util.c gdhcp/common.c unit/test-dhcp-options.c +unit_test_dhcp_options_LDADD = gdbus/libgdbus-internal.la \ + @GLIB_LIBS@ @DBUS_LIBS@ -ldl + +TESTS += unit/test-dhcp-options + if WISPR noinst_PROGRAMS += tools/wispr diff --git a/gdhcp/client.c b/gdhcp/client.c index dcde98ea95b6..4701306b2166 100644 --- a/gdhcp/client.c +++ b/gdhcp/client.c @@ -1634,7 +1634,7 @@ static uint32_t get_lease(struct dhcp_packet *packet, uint16_t packet_len) uint8_t *option; uint32_t lease_seconds; - option = dhcp_get_option(packet, packet_len, DHCP_LEASE_TIME); + option = dhcp_get_option(packet, packet_len, DHCP_LEASE_TIME, NULL); if (!option) return 3600; @@ -2238,7 +2238,7 @@ static void get_request(GDHCPClient *dhcp_client, struct dhcp_packet *packet, for (list = dhcp_client->request_list; list; list = list->next) { code = (uint8_t) GPOINTER_TO_INT(list->data); - option = dhcp_get_option(packet, packet_len, code); + option = dhcp_get_option(packet, packet_len, code, NULL); if (!option) { g_hash_table_remove(dhcp_client->code_value_hash, GINT_TO_POINTER((int) code)); @@ -2364,7 +2364,7 @@ static gboolean listener_event(GIOChannel *channel, GIOCondition condition, dhcp_client->status_code = status; } } else { - message_type = dhcp_get_option(&packet, pkt_len, DHCP_MESSAGE_TYPE); + message_type = dhcp_get_option(&packet, pkt_len, DHCP_MESSAGE_TYPE, NULL); if (!message_type) return TRUE; } @@ -2381,7 +2381,7 @@ static gboolean listener_event(GIOChannel *channel, GIOCondition condition, dhcp_client->timeout = 0; dhcp_client->retry_times = 0; - option = dhcp_get_option(&packet, pkt_len, DHCP_SERVER_ID); + option = dhcp_get_option(&packet, pkt_len, DHCP_SERVER_ID, NULL); if (!option) return TRUE; @@ -2445,7 +2445,7 @@ static gboolean listener_event(GIOChannel *channel, GIOCondition condition, if (dhcp_client->state == REBOOTING) { option = dhcp_get_option(&packet, pkt_len, - DHCP_SERVER_ID); + DHCP_SERVER_ID, NULL); if (!option) return TRUE; dhcp_client->server_ip = get_be32(option); diff --git a/gdhcp/common.c b/gdhcp/common.c index b3b725f5edc1..1e9dbb003754 100644 --- a/gdhcp/common.c +++ b/gdhcp/common.c @@ -103,7 +103,7 @@ bool dhcp_check_option(uint8_t code, uint8_t data_len) return true; } -uint8_t *dhcp_get_option(struct dhcp_packet *packet, uint16_t packet_len, int code) +uint8_t *dhcp_get_option(struct dhcp_packet *packet, uint16_t packet_len, int code, int *error) { int len, rem; uint8_t *optionptr, *options_end; @@ -115,7 +115,12 @@ uint8_t *dhcp_get_option(struct dhcp_packet *packet, uint16_t packet_len, int co rem = sizeof(packet->options); if (offsetof(struct dhcp_packet, options) >= packet_len) + { + if (error) + *error = 1; + return NULL; + } options_len = packet_len - offsetof(struct dhcp_packet, options); options_end = optionptr + options_len - 1; @@ -123,6 +128,8 @@ uint8_t *dhcp_get_option(struct dhcp_packet *packet, uint16_t packet_len, int co while (1) { if ((rem <= 0) || (optionptr + OPT_CODE > options_end)) { /* Bad packet, malformed option field */ + if (error) + *error = 2; return NULL; } @@ -155,6 +162,8 @@ uint8_t *dhcp_get_option(struct dhcp_packet *packet, uint16_t packet_len, int co if (optionptr + OPT_LEN > options_end) { /* bad packet, would read length field from OOB */ + if (error) + *error = 3; return NULL; } @@ -162,15 +171,22 @@ uint8_t *dhcp_get_option(struct dhcp_packet *packet, uint16_t packet_len, int co if (optionptr + len > options_end) { /* bad packet, option length points OOB */ + if (error) + *error = 4; return NULL; } rem -= len; - if (rem < 0) + if (rem < 0) { + if (error) + *error = 5; return NULL; + } if (optionptr[OPT_CODE] == code) { if (!dhcp_check_option(code, optionptr[OPT_LEN])) { + if (error) + *error = 6; return NULL; } else diff --git a/gdhcp/common.h b/gdhcp/common.h index 8f63fd755623..b99128df62e1 100644 --- a/gdhcp/common.h +++ b/gdhcp/common.h @@ -179,7 +179,7 @@ struct in6_pktinfo { }; #endif -uint8_t *dhcp_get_option(struct dhcp_packet *packet, uint16_t packet_len, int code); +uint8_t *dhcp_get_option(struct dhcp_packet *packet, uint16_t packet_len, int code, int *error); uint8_t *dhcpv6_get_option(struct dhcpv6_packet *packet, uint16_t pkt_len, int code, uint16_t *option_len, int *option_count); uint8_t *dhcpv6_get_sub_option(unsigned char *option, uint16_t max_len, diff --git a/gdhcp/server.c b/gdhcp/server.c index 52ea2a55b230..75c502a1a601 100644 --- a/gdhcp/server.c +++ b/gdhcp/server.c @@ -423,7 +423,7 @@ static uint8_t check_packet_type(struct dhcp_packet *packet, uint16_t packet_len if (packet->op != BOOTREQUEST) return 0; - type = dhcp_get_option(packet, packet_len, DHCP_MESSAGE_TYPE); + type = dhcp_get_option(packet, packet_len, DHCP_MESSAGE_TYPE, NULL); if (!type) return 0; @@ -668,7 +668,7 @@ static gboolean listener_event(GIOChannel *channel, GIOCondition condition, if (type == 0) return TRUE; - server_id_option = dhcp_get_option(&packet, packet_len, DHCP_SERVER_ID); + server_id_option = dhcp_get_option(&packet, packet_len, DHCP_SERVER_ID, NULL); if (server_id_option) { uint32_t server_nid = get_unaligned((const uint32_t *) server_id_option); @@ -677,7 +677,7 @@ static gboolean listener_event(GIOChannel *channel, GIOCondition condition, return TRUE; } - request_ip_option = dhcp_get_option(&packet, packet_len, DHCP_REQUESTED_IP); + request_ip_option = dhcp_get_option(&packet, packet_len, DHCP_REQUESTED_IP, NULL); if (request_ip_option) requested_nip = get_be32(request_ip_option); diff --git a/unit/test-dhcp-options.c b/unit/test-dhcp-options.c new file mode 100644 index 000000000000..e07c433f5cd1 --- /dev/null +++ b/unit/test-dhcp-options.c @@ -0,0 +1,365 @@ +/* + * + * Connection Manager + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include + +#include "../src/connman.h" + +/* #define DEBUG */ +#ifdef DEBUG +#include + +#define LOG(fmt, arg...) do { \ + fprintf(stdout, "%s:%s() " fmt "\n", \ + __FILE__, __func__ , ## arg); \ +} while (0) +#else +#define LOG(fmt, arg...) +#endif + +#include +#include "../gdhcp/common.h" + +bool dhcp_check_option(uint8_t code, uint8_t data_len); + +/* proper packet */ +static int reply_len_1 = 240 + 16 + 4; +static unsigned char reply_bin_1[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x82, 0x53, 0x63, + 0x35, 0x01, 0x05, 0x01, 0x04, 0x00, 0x00, 0x00, 0x00, 0x03, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xff, +}; + +/* packet too short, no options field */ +static int reply_len_2 = 240; +static unsigned char reply_bin_2[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x82, 0x53, 0x63, + 0x35, 0x01, 0x05, 0xff, +}; + +/* packet too short, only opt code */ +static int reply_len_3 = 241; +static unsigned char reply_bin_3[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x82, 0x53, 0x63, + 0x35, 0x01, 0x05, 0xff, +}; + +/* packet too short, only opt code and len */ +static int reply_len_4 = 242; +static unsigned char reply_bin_4[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x82, 0x53, 0x63, + 0x35, 0x01, 0x05, 0xff, +}; + +/* option too long */ +static int reply_len_5 = 244; +static unsigned char reply_bin_5[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x82, 0x53, 0x63, + 0x35, 0x03, 0x05, 0xff, +}; + +/* bad length for u8 option */ +static int reply_len_6 = 245; +static unsigned char reply_bin_6[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x82, 0x53, 0x63, + 0x35, 0x02, 0x05, 0x05, 0xff, +}; + +/* bad length for u32 option */ +static int reply_len_7 = 251; +static unsigned char reply_bin_7[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x82, 0x53, 0x63, + 0x35, 0x01, 0x05, 0x01, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, +}; + +/* bad length for u32 list option */ +static int reply_len_8 = 251; +static unsigned char reply_bin_8[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x82, 0x53, 0x63, + 0x35, 0x01, 0x05, 0x03, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, +}; + +static void test_case_0(void) +{ + bool ret; + + ret = dhcp_check_option(DHCP_SUBNET, 4); + g_assert(ret); + ret = dhcp_check_option(DHCP_SUBNET, 3); + g_assert(!ret); + ret = dhcp_check_option(DHCP_ROUTER, 4); + g_assert(ret); + ret = dhcp_check_option(DHCP_ROUTER, 8); + g_assert(ret); + ret = dhcp_check_option(DHCP_ROUTER, 7); + g_assert(!ret); + ret = dhcp_check_option(DHCP_HOST_NAME, 1); + g_assert(ret); + ret = dhcp_check_option(DHCP_HOST_NAME, 2); + g_assert(ret); + ret = dhcp_check_option(DHCP_MAX_SIZE, 2); + g_assert(ret); + ret = dhcp_check_option(DHCP_MAX_SIZE, 1); + g_assert(!ret); + ret = dhcp_check_option(DHCP_MESSAGE_TYPE, 1); + g_assert(ret); + ret = dhcp_check_option(DHCP_MESSAGE_TYPE, 2); + g_assert(!ret); + ret = dhcp_check_option(DHCP_SERVER_ID, 4); + g_assert(ret); + ret = dhcp_check_option(DHCP_SERVER_ID, 5); + g_assert(!ret); + ret = dhcp_check_option(241, 5); + g_assert(ret); +} + +static void test_case_1(void) +{ + uint8_t *opt_ptr; + int error = 0; + + opt_ptr = dhcp_get_option((struct dhcp_packet*)reply_bin_1, reply_len_1, 241, &error); + g_assert_cmpint(error, ==, 0); + g_assert(!opt_ptr); + + opt_ptr = dhcp_get_option((struct dhcp_packet*)reply_bin_1, reply_len_1, DHCP_SUBNET, &error); + g_assert_cmpint(error, ==, 0); + g_assert(opt_ptr); + + opt_ptr = dhcp_get_option((struct dhcp_packet*)reply_bin_1, reply_len_1, DHCP_ROUTER, &error); + g_assert_cmpint(error, ==, 0); + g_assert(opt_ptr); +} + +static void test_case_2(void) +{ + uint8_t *opt_ptr; + int error = 0; + + opt_ptr = dhcp_get_option((struct dhcp_packet*)reply_bin_2, reply_len_2, 241, &error); + + g_assert_cmpint(error, ==, 1); + + g_assert(!opt_ptr); +} + +static void test_case_3(void) +{ + uint8_t *opt_ptr; + int error = 0; + + opt_ptr = dhcp_get_option((struct dhcp_packet*)reply_bin_3, reply_len_3, 241, &error); + + g_assert_cmpint(error, ==, 3); + + g_assert(!opt_ptr); +} + +static void test_case_4(void) +{ + uint8_t *opt_ptr; + int error = 0; + + opt_ptr = dhcp_get_option((struct dhcp_packet*)reply_bin_4, reply_len_4, 241, &error); + + g_assert_cmpint(error, ==, 4); + + g_assert(!opt_ptr); +} + +static void test_case_5(void) +{ + uint8_t *opt_ptr; + int error = 0; + + opt_ptr = dhcp_get_option((struct dhcp_packet*)reply_bin_5, reply_len_5, 241, &error); + + g_assert_cmpint(error, ==, 4); + + g_assert(!opt_ptr); +} + +static void test_case_6(void) +{ + uint8_t *opt_ptr; + int error = 0; + + opt_ptr = dhcp_get_option((struct dhcp_packet*)reply_bin_6, reply_len_6, DHCP_MESSAGE_TYPE, &error); + + g_assert_cmpint(error, ==, 6); + + g_assert(!opt_ptr); +} + +static void test_case_7(void) +{ + uint8_t *opt_ptr; + int error = 0; + + opt_ptr = dhcp_get_option((struct dhcp_packet*)reply_bin_7, reply_len_7, DHCP_SUBNET, &error); + + g_assert_cmpint(error, ==, 6); + + g_assert(!opt_ptr); +} + +static void test_case_8(void) +{ + uint8_t *opt_ptr; + int error = 0; + + opt_ptr = dhcp_get_option((struct dhcp_packet*)reply_bin_8, reply_len_8, DHCP_ROUTER, &error); + + g_assert_cmpint(error, ==, 6); + + g_assert(!opt_ptr); +} + +int main(int argc, char *argv[]) +{ + g_test_init(&argc, &argv, NULL); + + g_test_add_func("/dhcp parse options/Test case 0", test_case_0); + g_test_add_func("/dhcp parse options/Test case 1", test_case_1); + g_test_add_func("/dhcp parse options/Test case 2", test_case_2); + g_test_add_func("/dhcp parse options/Test case 3", test_case_3); + g_test_add_func("/dhcp parse options/Test case 4", test_case_4); + g_test_add_func("/dhcp parse options/Test case 5", test_case_5); + g_test_add_func("/dhcp parse options/Test case 6", test_case_6); + g_test_add_func("/dhcp parse options/Test case 7", test_case_7); + g_test_add_func("/dhcp parse options/Test case 8", test_case_8); + + return g_test_run(); +} -- 2.35.1