1#!/bin/sh 2# 3# Copyright (c) 2018 Intel Corporation 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17# Setup virtual lan (VLAN) in Linux side that would work with this sample. 18 19if [ -z "$1" ]; then 20 echo "Network interface is missing." 21 echo "This is the network interface where the VLAN will be running." 22 echo "Example: eth0, tap0 etc." 23 exit 1 24fi 25 26if [ `id -u` != 0 ]; then 27 echo "Run this script as a root user!" 28 exit 2 29fi 30 31IFACE="$1" 32 33VLAN_NAME_PREFIX="vlan" 34 35PREFIX_1_IPV6="2001:db8:100" 36PREFIXLEN_1_IPV6="64" 37PREFIX_2_IPV6="2001:db8:200" 38PREFIXLEN_2_IPV6="64" 39 40# From RFC 5737 41PREFIX_1_IPV4="198.51.100" 42PREFIXLEN_1_IPV4="24" 43PREFIX_2_IPV4="203.0.113" 44PREFIXLEN_2_IPV4="24" 45 46ip link add link ${IFACE} name ${VLAN_NAME_PREFIX}.100 type vlan id 100 47ip link add link ${IFACE} name ${VLAN_NAME_PREFIX}.200 type vlan id 200 48 49ip link set ${VLAN_NAME_PREFIX}.100 up 50ip link set ${VLAN_NAME_PREFIX}.200 up 51 52ip -6 addr add ${PREFIX_1_IPV6}::2/${PREFIXLEN_1_IPV6} dev ${VLAN_NAME_PREFIX}.100 53ip -6 route add ${PREFIX_1_IPV6}::/${PREFIXLEN_1_IPV6} \ 54 dev ${VLAN_NAME_PREFIX}.100 55 56ip -6 addr add ${PREFIX_2_IPV6}::2/${PREFIXLEN_2_IPV6} dev ${VLAN_NAME_PREFIX}.200 57ip -6 route add ${PREFIX_2_IPV6}::/${PREFIXLEN_2_IPV6} \ 58 dev ${VLAN_NAME_PREFIX}.200 59 60ip addr add ${PREFIX_1_IPV4}.2 dev ${VLAN_NAME_PREFIX}.100 61ip route add ${PREFIX_1_IPV4}/${PREFIXLEN_1_IPV4} dev ${VLAN_NAME_PREFIX}.100 62 63ip addr add ${PREFIX_2_IPV4}.2 dev ${VLAN_NAME_PREFIX}.200 64ip route add ${PREFIX_2_IPV4}/${PREFIXLEN_2_IPV4} dev ${VLAN_NAME_PREFIX}.200 65 66 67# You can remove the virtual interface like this 68# ip link del link eth0 dev vlan.100 69# ip link del link eth0 dev vlan.200 70 71# If your devices HW MAC address changes when rebooting or flashing, 72# then you can flush the neighbor cache in Linux like this: 73# ip neigh flush dev vlan.100 74# ip neigh flush dev vlan.200 75