From nobody Mon Mar 07 13:29:55 2022 X-Original-To: dev-commits-src-all@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 8977F19F7228; Mon, 7 Mar 2022 13:29:56 +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 4KBzpW6y1Lz4pDg; Mon, 7 Mar 2022 13:29:55 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1646659796; 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=L/vmgpA1PK5Oh14UEF2a+WyRW1j1KazGT6pBEUKT/40=; b=vofD23tzMz+kdw3UFbJUV9o1MidX6PFbaK32WqGKzbEz0rJZ7Rwyt6ANWRIh7K98XmgwNR YUgsy4rSb+w3/laO9zhB0M8xyiUg6xK7Uav0quObR4miN6WA5keuqICDQmigdqgAF2Pv/U fz0CXpgDVkV2Hz7iZxmmc2dut8KoMhG7xpRq0Vp2gVNigIppSJ/u7IkfXRXsexf5cnwHAq TihGxjKUqvnzvqXYLsW5worPIPB/+WZRU47ZFei2zZG7yZc8TMFWWXqaxg4BBqz32XeFz4 qD3ILrd+F8lT7IrIu8GVdAn+44ACmRk8GmcZ7isEaO1OIp+kn6MjaBWXn4fFoA== 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 3C8C4E70; Mon, 7 Mar 2022 13:29:55 +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 227DTtQD060288; Mon, 7 Mar 2022 13:29:55 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 227DTtcb060287; Mon, 7 Mar 2022 13:29:55 GMT (envelope-from git) Date: Mon, 7 Mar 2022 13:29:55 GMT Message-Id: <202203071329.227DTtcb060287@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 586827df60ce - stable/13 - dhclient: support VID 0 (no vlan) decapsulation List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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/stable/13 X-Git-Reftype: branch X-Git-Commit: 586827df60cefacd0414b5f9df1243f2b2d4e526 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1646659796; 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=L/vmgpA1PK5Oh14UEF2a+WyRW1j1KazGT6pBEUKT/40=; b=v7irxyDl4pJtuuqMdYTdQHgBc3/hbYyDGU9xnZBqj1bRZBLgA6ubFlKMaCXGe1LdgNbcQe 5v92ch0k5j/oPZR2e8q0OrpvmTHW92I6Z7RIp2/OqWl34C1Tl5vKlsj431aGIMslvwcgLN d7GxpHDKh1qmIg6JDGu6cuKcHA4pHon/uoTSlViE1XgF6rW97lxMlnKFzhtG+68VhiKqeE xujkkBbo8PeuQBczkMnPF/DzTZ2lpRopktOp6lm0Zx9wMvulS1J/6ElFIczizTBWfnVqdT qf7LyYM7+Hd1SE+1IXfBN2r0S8OU1UeJdtPoGazZ7YhkpdUlOLv6mtYbRd21rw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1646659796; a=rsa-sha256; cv=none; b=IiXjxxXgxgo88iIJaUVV38X6XRF8ppfe2Xnqh1C2gimWCYOULpcbISlliY4rBn8yO64348 s11LPJhOjQDQO/X0lzjn4WFBvONonprqC2YFz8FuDPLykhiHUvhU/1eu+EiVBH8ew+LB3c E+QOEb7ovlHZITJe3gPoK4FQ6ccXMWnQfD5kUYUSB8vZAEfrM96t2TkIP0UZzGKzRjclcI RaGut7jo5FJ7nAMnw9Op8L7pj1CZntA0V40XuWMzN6cRby2gf30FPteTuNkXaoxoAp03Ri zcX8C4qSQRYCC0N48l8n+3m0fXJxC+z6DeLsSaZYxBAARnGPYyAl61DtbVF9kw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=586827df60cefacd0414b5f9df1243f2b2d4e526 commit 586827df60cefacd0414b5f9df1243f2b2d4e526 Author: Franco Fichtner AuthorDate: 2022-02-14 14:43:29 +0000 Commit: Mark Johnston CommitDate: 2022-03-07 13:18:57 +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 (cherry picked from commit abf5bff71d38da3c797a3b6decb426c375cc0f8f) --- 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