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