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