Skip to content

Instantly share code, notes, and snippets.

@fser
Created October 14, 2016 22:23
Show Gist options
  • Save fser/bc05886307ab289a2ba66ea0605406c0 to your computer and use it in GitHub Desktop.
Save fser/bc05886307ab289a2ba66ea0605406c0 to your computer and use it in GitHub Desktop.
Adds eth0 to the vlan 73
#!/usr/bin/env perl
use strict;
use warnings;
# https://fossies.org/dox/iproute2-4.7.0/if__vlan_8h_source.html
# struct vlan_ioctl_args {
# int cmd; /* Should be one of the vlan_ioctl_cmds enum above. */
# char device1[24];
# union {
# char device2[24];
# int VID;
# unsigned int skb_priority;
# unsigned int name_type;
# unsigned int bind_type;
# unsigned int flag; /* Matches vlan_dev_priv flags */
# } u;
# short vlan_qos;
# };
ReuseAddr => 1,
# for debug purpose only
sub DumpString {
my @a = unpack('C*',$_[0]);
my $o = 0;
while (@a) {
my @b = splice @a,0,16;
my @d = map sprintf("%03d",$_), @b;
my @x = map sprintf("%02x",$_), @b;
my $c = substr($_[0],$o,16);
$c =~ s/[[:^print:]]/ /g;
printf "%6d %s\n",$o,join(' ',@d);
print " "x8,join(' ',@x),"\n";
print " "x9,join(' ',split(//,$c)),"\n";
$o += 16;
}
}
my $COMMAND = 0x8983; # SIOCSIFVLAN
my $format = 'l Z24 L s'; # int (cmd) 24 char (device1) int (vlan id in union) short (vlan qos)
my $value = pack($format, 0, "bond0", 234, 0);
# debug only
# DumpString($value);
use IO::Socket;
my $server = IO::Socket::INET->new( Proto => 'tcp',
Listen => 1,
ReuseAddr => 1,
);
die "can't setup server... $!... $@..." unless $server;
ioctl($server, $COMMAND, $value) || die "Can't ioctl: $!\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment