1cfd6422aSLutz Donnerhacke.\"- 2*4d846d26SWarner Losh.\" SPDX-License-Identifier: BSD-2-Clause 3cfd6422aSLutz Donnerhacke.\" 4cfd6422aSLutz Donnerhacke.\" Copyright (c) 2019-2021 IKS Service GmbH 5cfd6422aSLutz Donnerhacke.\" 6cfd6422aSLutz Donnerhacke.\" Redistribution and use in source and binary forms, with or without 7cfd6422aSLutz Donnerhacke.\" modification, are permitted provided that the following conditions 8cfd6422aSLutz Donnerhacke.\" are met: 9cfd6422aSLutz Donnerhacke.\" 1. Redistributions of source code must retain the above copyright 10cfd6422aSLutz Donnerhacke.\" notice, this list of conditions and the following disclaimer. 11cfd6422aSLutz Donnerhacke.\" 2. Redistributions in binary form must reproduce the above copyright 12cfd6422aSLutz Donnerhacke.\" notice, this list of conditions and the following disclaimer in the 13cfd6422aSLutz Donnerhacke.\" documentation and/or other materials provided with the distribution. 14cfd6422aSLutz Donnerhacke.\" 15cfd6422aSLutz Donnerhacke.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16cfd6422aSLutz Donnerhacke.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17cfd6422aSLutz Donnerhacke.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18cfd6422aSLutz Donnerhacke.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19cfd6422aSLutz Donnerhacke.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20cfd6422aSLutz Donnerhacke.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21cfd6422aSLutz Donnerhacke.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22cfd6422aSLutz Donnerhacke.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23cfd6422aSLutz Donnerhacke.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24cfd6422aSLutz Donnerhacke.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25cfd6422aSLutz Donnerhacke.\" SUCH DAMAGE. 26cfd6422aSLutz Donnerhacke.\" 27cfd6422aSLutz Donnerhacke.\" Author: Lutz Donnerhacke <lutz@donnerhacke.de> 28cfd6422aSLutz Donnerhacke.\" 29cfd6422aSLutz Donnerhacke.\" $FreeBSD$ 30cfd6422aSLutz Donnerhacke.\" 31cfd6422aSLutz Donnerhacke.Dd January 26, 2021 32cfd6422aSLutz Donnerhacke.Dt NG_VLAN_ROTATE 4 33cfd6422aSLutz Donnerhacke.Os 34cfd6422aSLutz Donnerhacke.Sh NAME 35cfd6422aSLutz Donnerhacke.Nm ng_vlan_rotate 36cfd6422aSLutz Donnerhacke.Nd IEEE 802.1ad VLAN manipulation netgraph node type 37cfd6422aSLutz Donnerhacke.Sh SYNOPSIS 38cfd6422aSLutz Donnerhacke.In sys/types.h 39cfd6422aSLutz Donnerhacke.In netgraph.h 40cfd6422aSLutz Donnerhacke.In netgraph/ng_vlan_rotate.h 41cfd6422aSLutz Donnerhacke.Sh DESCRIPTION 42cfd6422aSLutz DonnerhackeThe 43cfd6422aSLutz Donnerhacke.Nm 44cfd6422aSLutz Donnerhackenode type manipulates the order of VLAN tags of frames tagged 45cfd6422aSLutz Donnerhackeaccording to the IEEE 802.1ad (an extension of IEEE 802.1Q) standard 46cfd6422aSLutz Donnerhackebetween different hooks. 47cfd6422aSLutz Donnerhacke.Pp 48cfd6422aSLutz DonnerhackeEach node has four special hooks, 49cfd6422aSLutz Donnerhacke.Va original , 50cfd6422aSLutz Donnerhacke.Va ordered , 51cfd6422aSLutz Donnerhacke.Va excessive , 52cfd6422aSLutz Donnerhackeand 53cfd6422aSLutz Donnerhacke.Va incomplete . 54cfd6422aSLutz Donnerhacke.Pp 55cfd6422aSLutz DonnerhackeA frame tagged with an arbitrary number of 56cfd6422aSLutz Donnerhacke.Dv ETHERTYPE_VLAN , 57cfd6422aSLutz Donnerhacke.Dv ETHERTYPE_QINQ , 58cfd6422aSLutz Donnerhackeand 59cfd6422aSLutz Donnerhacke.Dv 0x9100 60cfd6422aSLutz Donnerhacketags received on the 61cfd6422aSLutz Donnerhacke.Va original 62cfd6422aSLutz Donnerhackehook will be rearranged to a new order of those tags and is sent out 63cfd6422aSLutz Donnerhackethe 64cfd6422aSLutz Donnerhacke.Dq ordered 65cfd6422aSLutz Donnerhackehook. 66cfd6422aSLutz DonnerhackeAfter successful processing the 67cfd6422aSLutz Donnerhacke.Va histogram 68cfd6422aSLutz Donnerhackecounter for the observed stack size increments. 69cfd6422aSLutz Donnerhacke.Pp 70cfd6422aSLutz DonnerhackeIf it contains fewer VLANs in the stack than the configured 71cfd6422aSLutz Donnerhacke.Va min 72cfd6422aSLutz Donnerhackelimit, the frame is sent out to the 73cfd6422aSLutz Donnerhacke.Va incomplete 74cfd6422aSLutz Donnerhackehook and the 75cfd6422aSLutz Donnerhacke.Va incomplete 76cfd6422aSLutz Donnerhackecounter increments. 77cfd6422aSLutz Donnerhacke.Pp 78cfd6422aSLutz DonnerhackeIf there are more VLANs in the stack than the configured 79cfd6422aSLutz Donnerhacke.Va max 80cfd6422aSLutz Donnerhackelimit, the frame is sent out to the 81cfd6422aSLutz Donnerhacke.Va excessive 82cfd6422aSLutz Donnerhackehook and the 83cfd6422aSLutz Donnerhacke.Va excessive 84cfd6422aSLutz Donnerhackecounter increments. 85cfd6422aSLutz Donnerhacke.Pp 86cfd6422aSLutz DonnerhackeIf the destination hook is not connected, the frame is dropped and the 87cfd6422aSLutz Donnerhacke.Va drops 88cfd6422aSLutz Donnerhackecounter increments. 89cfd6422aSLutz Donnerhacke.Pp 90cfd6422aSLutz DonnerhackeFor Ethernet frames received on the 91cfd6422aSLutz Donnerhacke.Va ordered 92cfd6422aSLutz Donnerhackehook, the transformation is reversed and is passed to the 93cfd6422aSLutz Donnerhacke.Va original 94cfd6422aSLutz Donnerhackehook. 95cfd6422aSLutz DonnerhackePlease note that this process is identical to the one described 96cfd6422aSLutz Donnerhackeabove, besides the ordered/original hooks are swapped and the 97cfd6422aSLutz Donnerhacketransformation is reversed. 98cfd6422aSLutz Donnerhacke.Pp 99cfd6422aSLutz DonnerhackeAn Ethernet frame received on the 100cfd6422aSLutz Donnerhacke.Va incomplete 101cfd6422aSLutz Donnerhackeor 102cfd6422aSLutz Donnerhacke.Va excessive 103cfd6422aSLutz Donnerhackehook is forwarded to the 104cfd6422aSLutz Donnerhacke.Va original 105cfd6422aSLutz Donnerhackehook without any modification. 106cfd6422aSLutz Donnerhacke.Pp 107cfd6422aSLutz DonnerhackeThis node supports only one operation at the moment: Rotation of the 108cfd6422aSLutz DonnerhackeVLANs in the stack. 109cfd6422aSLutz DonnerhackeSetting the configuration parameter 110cfd6422aSLutz Donnerhacke.Va rot 111cfd6422aSLutz Donnerhacketo a positive value, the stack will roll up by this amount. 112cfd6422aSLutz DonnerhackeNegative values will roll down. 113cfd6422aSLutz DonnerhackeA typical scenario is setting the value to 1 in order to bring the 114cfd6422aSLutz Donnerhackeinnermost VLAN tag to the outmost level. 115cfd6422aSLutz DonnerhackeRotation includes the VLAN id, the ether type, and the QOS parameters 116cfd6422aSLutz Donnerhackepcp and cfi. 117cfd6422aSLutz DonnerhackeTypical QOS handling refers to the outmost setting, so be careful to 118cfd6422aSLutz Donnerhackekeep your QOS intact. 119cfd6422aSLutz Donnerhacke.Sh HOOKS 120cfd6422aSLutz DonnerhackeThis node type supports the following hooks: 121cfd6422aSLutz Donnerhacke.Bl -tag -width incomplete 122cfd6422aSLutz Donnerhacke.It Va original 123cfd6422aSLutz DonnerhackeTypically this hook would be connected to a 124cfd6422aSLutz Donnerhacke.Xr ng_ether 4 125cfd6422aSLutz Donnerhackenode, using the 126cfd6422aSLutz Donnerhacke.Va lower 127cfd6422aSLutz Donnerhackehook connected to a carrier network. 128cfd6422aSLutz Donnerhacke.It Va ordered 129cfd6422aSLutz DonnerhackeTypically this hook would be connected to a 130cfd6422aSLutz Donnerhacke.Xr ng_vlan 4 131cfd6422aSLutz Donnerhacketype node using the 132cfd6422aSLutz Donnerhacke.Va downstream 133cfd6422aSLutz Donnerhackehook in order to separate services. 134cfd6422aSLutz Donnerhacke.It Va excessive 135cfd6422aSLutz Donnerhackesee below. 136cfd6422aSLutz Donnerhacke.It Va incomplete 137cfd6422aSLutz DonnerhackeTypically those hooks would be attached to a 138cfd6422aSLutz Donnerhacke.Xr ng_eiface 4 139cfd6422aSLutz Donnerhacketype node using the 140cfd6422aSLutz Donnerhacke.Va ether 141cfd6422aSLutz Donnerhackehook for anomaly monitoring purposes. 142cfd6422aSLutz Donnerhacke.El 143cfd6422aSLutz Donnerhacke.Sh CONTROL MESSAGES 144cfd6422aSLutz DonnerhackeThis node type supports the generic control messages, plus the following: 145cfd6422aSLutz Donnerhacke.Bl -tag -width foo 146cfd6422aSLutz Donnerhacke.It Dv NGM_VLANROTATE_GET_CONF Pq Ic getconf 147cfd6422aSLutz DonnerhackeRead the current configuration. 148cfd6422aSLutz Donnerhacke.It Dv NGM_VLANROTATE_SET_CONF Pq Ic setconf 149cfd6422aSLutz DonnerhackeSet the current configuration. 150cfd6422aSLutz Donnerhacke.It Dv NGM_VLANROTATE_GET_STAT Pq Ic getstat 151cfd6422aSLutz DonnerhackeRead the current statistics. 152cfd6422aSLutz Donnerhacke.It Dv NGM_VLANROTATE_CLR_STAT Pq Ic clrstat 153cfd6422aSLutz DonnerhackeZeroize the statistics. 154cfd6422aSLutz Donnerhacke.It Dv NGM_VLANROTATE_GETCLR_STAT Pq Ic getclrstat 155cfd6422aSLutz DonnerhackeRead the current statistics and zeroize it in one step. 156cfd6422aSLutz Donnerhacke.El 157cfd6422aSLutz Donnerhacke.Sh EXAMPLES 158cfd6422aSLutz DonnerhackeThe first example demonstrates how to rotate double or triple tagged 159cfd6422aSLutz Donnerhackeframes so that the innermost C-VLAN can be used as service 160cfd6422aSLutz Donnerhackediscriminator. 161cfd6422aSLutz DonnerhackeThe single or double tagged frames (C-VLAN removed) are sent out to an 162cfd6422aSLutz Donnerhackeinterface pointing to different infrastucture. 163cfd6422aSLutz Donnerhacke.Bd -literal 164cfd6422aSLutz Donnerhacke#!/bin/sh 165cfd6422aSLutz Donnerhacke 166cfd6422aSLutz DonnerhackeBNG_IF=ixl3 167cfd6422aSLutz DonnerhackeVOIP_IF=bge2 168cfd6422aSLutz Donnerhacke 169cfd6422aSLutz Donnerhackengctl -f- <<EOF 170cfd6422aSLutz Donnerhackemkpeer ${BNG_IF}: vlan_rotate lower original 171cfd6422aSLutz Donnerhackename ${BNG_IF}:lower rotate 172cfd6422aSLutz Donnerhackemsg rotate: setconf { min=2 max=3 rot=1 } 173cfd6422aSLutz Donnerhackemkpeer rotate: vlan ordered downstream 174cfd6422aSLutz Donnerhackename rotate:ordered services 175cfd6422aSLutz Donnerhackeconnect services: ${VOIP_IF} voip lower 176cfd6422aSLutz Donnerhackemsg services: addfilter { vlan=123 hook="voip" } 177cfd6422aSLutz DonnerhackeEOF 178cfd6422aSLutz Donnerhacke.Ed 179cfd6422aSLutz Donnerhacke.Pp 180cfd6422aSLutz DonnerhackeNow inject the following sample frame on the 181cfd6422aSLutz Donnerhacke.Dv BNG_IF 182cfd6422aSLutz Donnerhackeinterface: 183cfd6422aSLutz Donnerhacke.Bd -literal 184cfd6422aSLutz Donnerhacke00:00:00:00:01:01 > 00:01:02:03:04:05, 185cfd6422aSLutz Donnerhacke ethertype 802.1Q-9100 (0x9100), length 110: vlan 2, p 1, 186cfd6422aSLutz Donnerhacke ethertype 802.1Q-QinQ, vlan 101, p 0, 187cfd6422aSLutz Donnerhacke ethertype 802.1Q, vlan 123, p 7, 188cfd6422aSLutz Donnerhacke ethertype IPv4, (tos 0x0, ttl 64, id 15994, offset 0, flags [none], 189cfd6422aSLutz Donnerhacke proto ICMP (1), length 84) 192.168.140.101 > 192.168.140.1: 190cfd6422aSLutz Donnerhacke ICMP echo request, id 40234, seq 0, length 64 191cfd6422aSLutz Donnerhacke.Ed 192cfd6422aSLutz Donnerhacke.Pp 193cfd6422aSLutz DonnerhackeThe frame ejected on the 194cfd6422aSLutz Donnerhacke.Va ordered 195cfd6422aSLutz Donnerhackehook will look like this: 196cfd6422aSLutz Donnerhacke.Bd -literal 197cfd6422aSLutz Donnerhacke00:00:00:00:01:01 > 00:01:02:03:04:05, 198cfd6422aSLutz Donnerhacke ethertype 802.1Q (0x8100), length 110: vlan 123, p 7, 199cfd6422aSLutz Donnerhacke ethertype 802.1Q-9100, vlan 2, p 1, 200cfd6422aSLutz Donnerhacke ethertype 802.1Q-QinQ, vlan 101, p 0, 201cfd6422aSLutz Donnerhacke ethertype IPv4, (tos 0x0, ttl 64, id 15994, offset 0, flags [none], 202cfd6422aSLutz Donnerhacke proto ICMP (1), length 84) 192.168.140.101 > 192.168.140.1: 203cfd6422aSLutz Donnerhacke ICMP echo request, id 40234, seq 0, length 64 204cfd6422aSLutz Donnerhacke.Ed 205cfd6422aSLutz Donnerhacke.Pp 206cfd6422aSLutz DonnerhackeHence, the frame pushed out to the 207cfd6422aSLutz Donnerhacke.Dv VOIP_IF 208cfd6422aSLutz Donnerhackewill have this form: 209cfd6422aSLutz Donnerhacke.Bd -literal 210cfd6422aSLutz Donnerhacke00:00:00:00:01:01 > 00:01:02:03:04:05, 211cfd6422aSLutz Donnerhacke ethertype 802.1Q-9100, vlan 2, p 1, 212cfd6422aSLutz Donnerhacke ethertype 802.1Q-QinQ, vlan 101, p 0, 213cfd6422aSLutz Donnerhacke ethertype IPv4, (tos 0x0, ttl 64, id 15994, offset 0, flags [none], 214cfd6422aSLutz Donnerhacke proto ICMP (1), length 84) 192.168.140.101 > 192.168.140.1: 215cfd6422aSLutz Donnerhacke ICMP echo request, id 40234, seq 0, length 64 216cfd6422aSLutz Donnerhacke.Ed 217cfd6422aSLutz Donnerhacke.Pp 218cfd6422aSLutz DonnerhackeThe second example distinguishes between double tagged and single 219cfd6422aSLutz Donnerhacketagged frames. 220cfd6422aSLutz Donnerhacke.Bd -literal 221cfd6422aSLutz Donnerhacke#!/bin/sh 222cfd6422aSLutz Donnerhacke 223cfd6422aSLutz DonnerhackeIN_IF=bge1 224cfd6422aSLutz Donnerhacke 225cfd6422aSLutz Donnerhackengctl -f- <<EOF 226cfd6422aSLutz Donnerhackemkpeer ${IN_IF}: vlan_rotate lower original 227cfd6422aSLutz Donnerhackename ${IN_IF}:lower separate 228cfd6422aSLutz Donnerhackemsg separate: setconf { min=1 max=1 rot=0 } 229cfd6422aSLutz Donnerhackemkpeer separate: eiface incomplete ether 230cfd6422aSLutz Donnerhackename separate:incomplete untagged 231cfd6422aSLutz Donnerhackemkpeer separate: eiface ordered ether 232cfd6422aSLutz Donnerhackename separate:ordered tagged 233cfd6422aSLutz DonnerhackeEOF 234cfd6422aSLutz Donnerhacke.Ed 235cfd6422aSLutz Donnerhacke.Pp 236cfd6422aSLutz DonnerhackeSetting the 237cfd6422aSLutz Donnerhacke.Va rot 238cfd6422aSLutz Donnerhackeparameter to zero (or omitting it) does not change 239cfd6422aSLutz Donnerhackethe order of the tags within the frame. 240cfd6422aSLutz DonnerhackeFrames with more VLAN tags are dropped. 241cfd6422aSLutz Donnerhacke.Sh SHUTDOWN 242cfd6422aSLutz DonnerhackeThis node shuts down upon receipt of a 243cfd6422aSLutz Donnerhacke.Dv NGM_SHUTDOWN 244cfd6422aSLutz Donnerhackecontrol message, or when all hooks have been disconnected. 245cfd6422aSLutz Donnerhacke.Sh SEE ALSO 246cfd6422aSLutz Donnerhacke.Xr netgraph 4 , 247cfd6422aSLutz Donnerhacke.Xr ng_eiface 4 , 248cfd6422aSLutz Donnerhacke.Xr ng_ether 4 , 249cfd6422aSLutz Donnerhacke.Xr ng_vlan 4 , 250cfd6422aSLutz Donnerhacke.Xr ngctl 8 251cfd6422aSLutz Donnerhacke.Sh AUTHORS 252cfd6422aSLutz Donnerhacke.An Lutz Donnerhacke Aq Mt lutz@donnerhacke.de 253