From nobody Mon Feb 14 15:07:07 2022 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 1C2B219B461A; Mon, 14 Feb 2022 15:07:08 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Jy6yM4qHVz3DFp; Mon, 14 Feb 2022 15:07:07 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1644851227; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=zqsZ0YGt4/IEj7xCXIPk7QjVL6YpLOsrPE/g2CQxHfA=; b=Ak8Dw4DN1jm1/Ktf84vDW+JbFWXyLyC1yiukvL5387iZy/zjSKN3AyY13m/H87WeYnubbY LSKWn4dit0UeoDEvud1JL1SqEfIFj5wJjFcK5Z1kZNro7da7xheFCJgEpreJClM3MzMJNY 9MdUKiTTeXA0VR66T5hY1miY8FVCvrEFvbo42fi6gw3OPuz2ApBDLOZ4U8BFveyerWJoVn ddfOh7G3lPXK6pUnDOCjO3PegJbNnbP36P0kpmZfk3sbGr7SlaDbqaLvNFOI5EIt2kw1wq gPC2Jts+ng1ER0HfZCOlGoy4yU0HJRTQyG04ZkLESGIp44+W2iOWb+9tnCZbcw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 26FCE10FC4; Mon, 14 Feb 2022 15:07:07 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 21EF77UH060156; Mon, 14 Feb 2022 15:07:07 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 21EF77TC060155; Mon, 14 Feb 2022 15:07:07 GMT (envelope-from git) Date: Mon, 14 Feb 2022 15:07:07 GMT Message-Id: <202202141507.21EF77TC060155@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: abf5bff71d38 - main - dhclient: support VID 0 (no vlan) decapsulation List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: abf5bff71d38da3c797a3b6decb426c375cc0f8f Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1644851227; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=zqsZ0YGt4/IEj7xCXIPk7QjVL6YpLOsrPE/g2CQxHfA=; b=W9M0KF438GfTALGi/KUXusqGKEn/8T/blqVBtDG4bMeftxh065PZzn4BBXuaTDZeF0FoGm R7jXeSqaNYEthQVfJmOnGT65Z+k8OWQNHfS4EE/HVSe7jDi8SdtrouvvPjfo4sa+1rniR/ UvnxXG7BbX8HYSXdKrleWcZq8ozGwWwChiDYDwztt0w7+HXvG0bagaUrvEZGJD/CNCW8+w cDYUicFuurowcszBgSZnsBXLAcKs8RlXqj/ypA/In45SMGIW0zl27c7EFsYiCZO4M1T2GT z073Kkcd7Og89QKMPqI8+Dkb8xOHeomCJm28zpavfXY4HNXbqDW9CJbWze1eiA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1644851227; a=rsa-sha256; cv=none; b=SfJ9hIYv6qx1WBS8/P+hwnNHWt9+eM6tDT5YVmFym1oAQitRGIbfx3n92BmHNXr4wLlPIU +MHTNO7fETJKb9dkkDDKDvu0YvR+0w0kuW1WDG+TWNmmJoqUhfW3IriqWoXgFOETg0bs8j eoObSjs0AfXvOo8z8WcgDha+SUS+HNw0EoN2c0i1yQ2yNB3IfhhqidRzKzKEDcm60q8ING Lo+Ltv+Z93aunAJw+KqFKpCJKfDlymEeJlvdylYiU/PRuhGVI/2Be/QlVNcRC6khkct8EY Q3fn2DK4HReUSP0bdOFyJINs+YJQZKv4BqJg5KbEhZLUnY1pQVe6EzKqN/FD+g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=abf5bff71d38da3c797a3b6decb426c375cc0f8f commit abf5bff71d38da3c797a3b6decb426c375cc0f8f Author: Franco Fichtner AuthorDate: 2022-02-14 14:43:29 +0000 Commit: Mark Johnston CommitDate: 2022-02-14 15:06:47 +0000 dhclient: support VID 0 (no vlan) decapsulation VLAN ID 0 is supposed to be interpreted as having no VLAN with a bit of priority on the side, but the kernel is not able to decapsulate this on the fly so dhclient needs to take care of it. Reviewed by: markj MFC after: 3 weeks Differential Revision: https://reviews.freebsd.org/D31515 --- sbin/dhclient/bpf.c | 53 +++++++++++++++++++++++++++++++++++++++++++------- sbin/dhclient/packet.c | 3 ++- 2 files changed, 48 insertions(+), 8 deletions(-) diff --git a/sbin/dhclient/bpf.c b/sbin/dhclient/bpf.c index 41eb4f402e66..d938b68c7c94 100644 --- a/sbin/dhclient/bpf.c +++ b/sbin/dhclient/bpf.c @@ -5,6 +5,7 @@ /*- * SPDX-License-Identifier: BSD-3-Clause * + * Copyright (c) 2021 Franco Fichtner * Copyright (c) 1995, 1996, 1998, 1999 * The Internet Software Consortium. All rights reserved. * @@ -187,20 +188,58 @@ if_register_send(struct interface_info *info) * Packet filter program... */ static const struct bpf_insn dhcp_bpf_filter[] = { + /* Use relative index (0) for IP packet... */ + BPF_STMT(BPF_LDX + BPF_W + BPF_IMM, 0), + + /* + * Test whether this is a VLAN packet... + * + * In case the server packet is using a VLAN ID + * of 0, meaning an untagged priority was set, the + * response shall be read and replied to. + */ + BPF_STMT(BPF_LD + BPF_H + BPF_IND, 12), + BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, ETHERTYPE_VLAN, 0, 4), + + /* Test whether it has a VID of 0 */ + BPF_STMT(BPF_LD + BPF_H + BPF_IND, 14), + BPF_STMT(BPF_ALU + BPF_AND + BPF_K, EVL_VLID_MASK), + BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, 0, 0, 17), + + /* Correct the relative index for VLAN packet (4)... */ + BPF_STMT(BPF_LDX + BPF_W + BPF_IMM, 4), + /* Make sure this is an IP packet... */ - BPF_STMT(BPF_LD + BPF_H + BPF_ABS, 12), - BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, ETHERTYPE_IP, 0, 8), + BPF_STMT(BPF_LD + BPF_H + BPF_IND, 12), + BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, ETHERTYPE_IP, 0, 14), /* Make sure it's a UDP packet... */ - BPF_STMT(BPF_LD + BPF_B + BPF_ABS, 23), - BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, IPPROTO_UDP, 0, 6), + BPF_STMT(BPF_LD + BPF_B + BPF_IND, 23), + BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, IPPROTO_UDP, 0, 12), /* Make sure this isn't a fragment... */ - BPF_STMT(BPF_LD + BPF_H + BPF_ABS, 20), - BPF_JUMP(BPF_JMP + BPF_JSET + BPF_K, IP_MF|IP_OFFMASK, 4, 0), + BPF_STMT(BPF_LD + BPF_H + BPF_IND, 20), + BPF_JUMP(BPF_JMP + BPF_JSET + BPF_K, IP_MF|IP_OFFMASK, 10, 0), - /* Get the IP header length... */ + /* + * Get the IP header length... + * + * To find the correct position of the IP header + * length field store the index (0 or 4) in the + * accumulator and compare it with 0. + */ + BPF_STMT(BPF_MISC + BPF_TXA, 0), + BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, 0, 0, 2), + /* Store IP header length of IP packet in index. */ BPF_STMT(BPF_LDX + BPF_B + BPF_MSH, 14), + /* Skip over following VLAN handling instruction. */ + BPF_JUMP(BPF_JMP + BPF_JA, 1, 0, 0), + /* Store IP header length of VLAN packet in index. */ + BPF_STMT(BPF_LDX + BPF_B + BPF_MSH, 18), + /* Add IP header length to previous relative index. */ + BPF_STMT(BPF_ALU + BPF_ADD + BPF_X, 0), + /* Move result back to index to reach UDP header below. */ + BPF_STMT(BPF_MISC + BPF_TAX, 0), /* Make sure it's to the right port... */ BPF_STMT(BPF_LD + BPF_H + BPF_IND, 16), diff --git a/sbin/dhclient/packet.c b/sbin/dhclient/packet.c index 21726aaaeb84..276bb5c2457f 100644 --- a/sbin/dhclient/packet.c +++ b/sbin/dhclient/packet.c @@ -157,7 +157,8 @@ decode_hw_header(unsigned char *buf, int bufix, struct hardware *from) from->htype = ARPHRD_ETHER; from->hlen = sizeof(eh.ether_shost); - return (sizeof(eh)); + return (sizeof(eh) + (ntohs(eh.ether_type) == ETHERTYPE_VLAN ? + ETHER_VLAN_ENCAP_LEN : 0)); } ssize_t