#!/bin/sh -e # Copyright (C) 2013 Andrew Shadura # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU Library General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU Library General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. usage () { cat <&2 echo "Warning: vconfig is deprecated and might be removed in the future, please migrate to ip(route2) as soon as possible!" >&2 echo "" >&2 if [ $ARGC -lt 3 -o $ARGC -gt 5 ] then echo "Expecting argc to be 3-5, inclusive. Was: $ARGC" >&2 usage exit 1 fi ip () { /sbin/ip "$@" } condret () { [ "$1" = "$2" ] && echo -n "$3" } map () { v="$1" shift for pq in "$@" do condret "$v" $pq && return 0 done false } add () { NAME_TYPE=DEV_PLUS_VID_NO_PAD [ -r "$STATEDIR/name-type" ] && NAME_TYPE=$(cat "$STATEDIR/name-type") VLAN_ID="$2" IFACE="$1" case "$NAME_TYPE" in VLAN_PLUS_VID) NAME="$(printf vlan%.4d "$VLAN_ID")" ;; VLAN_PLUS_VID_NO_PAD) NAME="vlan$VLAN_ID" ;; DEV_PLUS_VID) NAME="$(printf %s.%.4d "$IFACE" "$VLAN_ID")" ;; DEV_PLUS_VID_NO_PAD) NAME="$IFACE.$VLAN_ID" ;; esac ip link add link "$IFACE" name "$NAME" type vlan id "$VLAN_ID" || exit 3 } rem () { ip link del "$1" || exit 4 } set_name_type () { mkdir -p "$STATEDIR" || exit 8 echo "$1" > "$STATEDIR/name-type" || exit 8 } set_flag () { echo "$@" if FLAG=$(map "$3" "0 off" "1 on") then ip link set dev "$1" type vlan reorder_hdr "$FLAG" || exit 7 else echo "Invalid flag parameter specified" >&2 exit 7 fi } set_ingress_map () { ip link set dev "$1" type vlan ingress-qos-map "$2:$3" || exit 6 } set_egress_map () { ip link set dev "$1" type vlan egress-qos-map "$2:$3" || exit 5 } case "$1" in add) add "$2" "$3" ;; rem) rem "$2" ;; set_flag) set_flag "$2" "$3" "$4" ;; set_ingress_map) set_ingress_map "$2" "$3" "$4" ;; set_egress_map) set_egress_map "$2" "$3" "$4" ;; set_name_type) set_name_type "$2" ;; *) echo "Unknown command: $1" >&2 exit 5 ;; esac