-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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. This is similar to the VLAN ID send use case where we latch on to a parent interface in order to be able to serve responses with the correct VLAN priority. Patch is inspired by the pfSense proposal below, but the filter was rewritten for minimal impact. PR: #114 See also: pfsense/FreeBSD-src#9
- Loading branch information
Showing
2 changed files
with
31 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
/*- | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
* | ||
* Copyright (c) 2018 Franco Fichtner <[email protected]> | ||
* Copyright (c) 2018-2021 Franco Fichtner <[email protected]> | ||
* Copyright (c) 1995, 1996, 1998, 1999 | ||
* The Internet Software Consortium. All rights reserved. | ||
* | ||
|
@@ -203,20 +203,41 @@ if_register_send(struct interface_info *info) | |
* constant offsets used in if_register_send to patch the BPF program! | ||
*/ | ||
static struct bpf_insn dhcp_bpf_filter[] = { | ||
/* Set packet index for IP packet... */ | ||
BPF_STMT(BPF_LDX + BPF_W + BPF_IMM, 0), | ||
|
||
/* Test whether this is a VLAN packet... */ | ||
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, 0xfff), | ||
BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, 0, 0, 1), | ||
|
||
/* Correct the packet index for VLAN... */ | ||
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, 0x1fff, 4, 0), | ||
BPF_STMT(BPF_LD + BPF_H + BPF_IND, 20), | ||
BPF_JUMP(BPF_JMP + BPF_JSET + BPF_K, 0x1fff, 10, 0), | ||
|
||
/* Get the IP header length... */ | ||
BPF_STMT(BPF_MISC + BPF_TXA, 0), | ||
BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, 0, 0, 2), | ||
BPF_STMT(BPF_LDX + BPF_B + BPF_MSH, 14), | ||
BPF_JUMP(BPF_JMP + BPF_JA, 1, 0, 0), | ||
BPF_STMT(BPF_LDX + BPF_B + BPF_MSH, 18), | ||
BPF_STMT(BPF_ALU + BPF_ADD + BPF_X, 0), | ||
BPF_STMT(BPF_MISC + BPF_TAX, 0), | ||
|
||
/* Make sure it's to the right port... */ | ||
BPF_STMT(BPF_LD + BPF_H + BPF_IND, 16), | ||
|
@@ -279,7 +300,7 @@ if_register_receive(struct interface_info *info) | |
* XXX: changes to filter program may require changes to the | ||
* insn number(s) used below! | ||
*/ | ||
dhcp_bpf_filter[8].k = LOCAL_PORT; | ||
dhcp_bpf_filter[21].k = LOCAL_PORT; | ||
|
||
if (ioctl(info->rfdesc, BIOCSETF, &p) < 0) | ||
error("Can't install packet filter program: %m"); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters