[zones-discuss] Netmask conversion fix
Hi Brad, Thanks for zonemgr, I find it really handy and use it alot! I noticed that there was a small issue with the netmask conversion after 255.255.255.192, the script converts this to 27 instead of 26. This causes an error message when attempting to set the network as the broadcast address would be greater than the global zone (when gz is 26). Here's a test script with a fixed function called nm2cidr2. Thanks again! Cheers, Graham #!/bin/bash ## # # Convert the netmask from dot notation to CIDR format # nm2cidr2() { nm=$1 oct1=`echo $nm | cut -d. -f1` oct2=`echo $nm | cut -d. -f2` oct3=`echo $nm | cut -d. -f3` oct4=`echo $nm | cut -d. -f4` # Assume that most networks are class C (e.g. cidr = 24) cidr=24 if [ $oct1 -lt 128 ]&&[ $oct2 -eq 0 ]&&[ $oct3 -eq 0 ]&&[ $oct4 -eq 0 ];then cidr=0; elif [ $oct1 -lt 192 ]&&[ $oct2 -eq 0 ]&&[ $oct3 -eq 0 ]&&[ $oct4 -eq 0 ];then cidr=1; elif [ $oct1 -lt 224 ]&&[ $oct2 -eq 0 ]&&[ $oct3 -eq 0 ]&&[ $oct4 -eq 0 ];then cidr=2; elif [ $oct1 -lt 240 ]&&[ $oct2 -eq 0 ]&&[ $oct3 -eq 0 ]&&[ $oct4 -eq 0 ];then cidr=3; elif [ $oct1 -lt 248 ]&&[ $oct2 -eq 0 ]&&[ $oct3 -eq 0 ]&&[ $oct4 -eq 0 ];then cidr=4; elif [ $oct1 -lt 252 ]&&[ $oct2 -eq 0 ]&&[ $oct3 -eq 0 ]&&[ $oct4 -eq 0 ];then cidr=5; elif [ $oct1 -lt 254 ]&&[ $oct2 -eq 0 ]&&[ $oct3 -eq 0 ]&&[ $oct4 -eq 0 ];then cidr=5; elif [ $oct1 -lt 255 ]&&[ $oct2 -eq 0 ]&&[ $oct3 -eq 0 ]&&[ $oct4 -eq 0 ];then cidr=7; elif [ $oct1 -eq 255 ]&&[ $oct2 -lt 127 ]&&[ $oct3 -eq 0 ]&&[ $oct4 -eq 0 ];then cidr=8; elif [ $oct1 -eq 255 ]&&[ $oct2 -lt 192 ]&&[ $oct3 -eq 0 ]&&[ $oct4 -eq 0 ];then cidr=9; elif [ $oct1 -eq 255 ]&&[ $oct2 -lt 224 ]&&[ $oct3 -eq 0 ]&&[ $oct4 -eq 0 ];then cidr=10; elif [ $oct1 -eq 255 ]&&[ $oct2 -lt 240 ]&&[ $oct3 -eq 0 ]&&[ $oct4 -eq 0 ];then cidr=11; elif [ $oct1 -eq 255 ]&&[ $oct2 -lt 248 ]&&[ $oct3 -eq 0 ]&&[ $oct4 -eq 0 ];then cidr=12; elif [ $oct1 -eq 255 ]&&[ $oct2 -lt 252 ]&&[ $oct3 -eq 0 ]&&[ $oct4 -eq 0 ];then cidr=13; elif [ $oct1 -eq 255 ]&&[ $oct2 -lt 254 ]&&[ $oct3 -eq 0 ]&&[ $oct4 -eq 0 ];then cidr=14; elif [ $oct1 -eq 255 ]&&[ $oct2 -lt 255 ]&&[ $oct3 -eq 0 ]&&[ $oct4 -eq 0 ];then cidr=15; elif [ $oct1 -eq 255 ]&&[ $oct2 -eq 255 ]&&[ $oct3 -lt 128 ]&&[ $oct4 -eq 0 ];then cidr=16; elif [ $oct1 -eq 255 ]&&[ $oct2 -eq 255 ]&&[ $oct3 -lt 192 ]&&[ $oct4 -eq 0 ];then cidr=17; elif [ $oct1 -eq 255 ]&&[ $oct2 -eq 255 ]&&[ $oct3 -lt 224 ]&&[ $oct4 -eq 0 ];then cidr=18; elif [ $oct1 -eq 255 ]&&[ $oct2 -eq 255 ]&&[ $oct3 -lt 240 ]&&[ $oct4 -eq 0 ];then cidr=19; elif [ $oct1 -eq 255 ]&&[ $oct2 -eq 255 ]&&[ $oct3 -lt 248 ]&&[ $oct4 -eq 0 ];then cidr=20; elif [ $oct1 -eq 255 ]&&[ $oct2 -eq 255 ]&&[ $oct3 -lt 252 ]&&[ $oct4 -eq 0 ];then cidr=21; elif [ $oct1 -eq 255 ]&&[ $oct2 -eq 255 ]&&[ $oct3 -lt 254 ]&&[ $oct4 -eq 0 ];then cidr=22; elif [ $oct1 -eq 255 ]&&[ $oct2 -eq 255 ]&&[ $oct3 -lt 255 ]&&[ $oct4 -eq 0 ];then cidr=23; elif [ $oct1 -eq 255 ]&&[ $oct2 -eq 255 ]&&[ $oct3 -eq 255 ]&&[ $oct4 -eq 0 ];then cidr=24; elif [ $oct1 -eq 255 ]&&[ $oct2 -eq 255 ]&&[ $oct3 -eq 255 ]&&[ $oct4 -le 128 ];then cidr=25; elif [ $oct1 -eq 255 ]&&[ $oct2 -eq 255 ]&&[ $oct3 -eq 255 ]&&[ $oct4 -le 192 ];then cidr=26; elif [ $oct1 -eq 255 ]&&[ $oct2 -eq 255 ]&&[ $oct3 -eq 255 ]&&[ $oct4 -le 224 ];then cidr=27; elif [ $oct1 -eq 255 ]&&[ $oct2 -eq 255 ]&&[ $oct3 -eq 255 ]&&[ $oct4 -le 240 ];then cidr=28; elif [ $oct1 -eq 255 ]&&[ $oct2 -eq 255 ]&&[ $oct3 -eq 255 ]&&[ $oct4 -le 248 ];then cidr=29; elif [ $oct1 -eq 255 ]&&[ $oct2 -eq 255 ]&&[ $oct3 -eq 255 ]&&[ $oct4 -le 252 ];then cidr=30; elif [ $oct1 -eq 255 ]&&[ $oct2 -eq 255 ]&&[ $oct3 -eq 255 ]&&[ $oct4 -lt 255 ];then cidr=31; elif [ $oct1 -eq 255 ]&&[ $oct2 -eq 255 ]&&[ $oct3 -eq 255 ]&&[ $oct4 -eq 255 ];then cidr=32; fi echo "$cidr" } ## # # Convert the netmask from dot notation to CIDR format # nm2cidr() { nm=$1 oct1=`echo $nm | cut -d. -f1` oct2=`echo $nm | cut -d. -f2` oct3=`echo $nm | cut -d. -f3` oct4=`echo $nm | cut -d. -f4` # Assume that most networks are class C (e.g. cidr = 24) cidr=24 if [ $oct1 -lt 128 ]&&[ $oct2 -eq 0 ]&&[ $oct3 -eq 0 ]&&[ $oct4 -eq 0 ];then cidr=0; elif [ $oct1 -lt 192 ]&&[ $oct2 -eq 0 ]&&[ $oct3 -eq 0 ]&&[ $oct4 -eq 0 ];then cidr=1; elif [ $oct1 -lt 224 ]&&[ $oct2 -eq 0 ]&&[ $oct3 -eq 0 ]&&[ $oct4 -eq 0 ];then cidr=2; elif [ $oct1 -lt 240 ]&&[ $oct2 -eq 0 ]&&[ $oct3 -eq 0 ]&&[ $oct4 -eq 0 ];then cidr=3; elif [ $oct1 -lt 248 ]&&[ $oct2 -eq 0 ]&&[ $oct3 -eq 0 ]&&[ $oct4 -eq 0 ];then cidr=4; elif [ $oct1 -lt 252 ]&&[ $oct2 -eq 0 ]&&[ $oct3 -eq
[zones-discuss] Re: Netmask conversion fix
Here's the output of the test script: -- 0: -cidr2dot-> 0.0.0.0 -nm2cidr-> 0 (nm2cidr2: 0) 1: -cidr2dot->128.0.0.0 -nm2cidr-> 1 (nm2cidr2: 1) 2: -cidr2dot->192.0.0.0 -nm2cidr-> 2 (nm2cidr2: 2) 3: -cidr2dot->224.0.0.0 -nm2cidr-> 3 (nm2cidr2: 3) 4: -cidr2dot->240.0.0.0 -nm2cidr-> 4 (nm2cidr2: 4) 5: -cidr2dot->248.0.0.0 -nm2cidr-> 5 (nm2cidr2: 5) 6: -cidr2dot->252.0.0.0 -nm2cidr-> 5 (nm2cidr2: 5) 7: -cidr2dot->254.0.0.0 -nm2cidr-> 7 (nm2cidr2: 7) 8: -cidr2dot->255.0.0.0 -nm2cidr-> 8 (nm2cidr2: 8) 9: -cidr2dot-> 255.128.0.0 -nm2cidr-> 9 (nm2cidr2: 9) 10: -cidr2dot-> 255.192.0.0 -nm2cidr-> 10 (nm2cidr2: 10) 11: -cidr2dot-> 255.224.0.0 -nm2cidr-> 11 (nm2cidr2: 11) 12: -cidr2dot-> 255.240.0.0 -nm2cidr-> 12 (nm2cidr2: 12) 13: -cidr2dot-> 255.248.0.0 -nm2cidr-> 13 (nm2cidr2: 13) 14: -cidr2dot-> 255.252.0.0 -nm2cidr-> 14 (nm2cidr2: 14) 15: -cidr2dot-> 255.254.0.0 -nm2cidr-> 15 (nm2cidr2: 15) 16: -cidr2dot-> 255.255.0.0 -nm2cidr-> 16 (nm2cidr2: 16) 17: -cidr2dot->255.255.128.0 -nm2cidr-> 17 (nm2cidr2: 17) 18: -cidr2dot->255.255.192.0 -nm2cidr-> 18 (nm2cidr2: 18) 19: -cidr2dot->255.255.224.0 -nm2cidr-> 19 (nm2cidr2: 19) 20: -cidr2dot->255.255.240.0 -nm2cidr-> 20 (nm2cidr2: 20) 21: -cidr2dot->255.255.248.0 -nm2cidr-> 21 (nm2cidr2: 21) 22: -cidr2dot->255.255.252.0 -nm2cidr-> 22 (nm2cidr2: 22) 23: -cidr2dot->255.255.254.0 -nm2cidr-> 23 (nm2cidr2: 23) 24: -cidr2dot->255.255.255.0 -nm2cidr-> 24 (nm2cidr2: 24) 25: -cidr2dot-> 255.255.255.128 -nm2cidr-> 26 (nm2cidr2: 25) 26: -cidr2dot-> 255.255.255.192 -nm2cidr-> 27 (nm2cidr2: 26) 27: -cidr2dot-> 255.255.255.224 -nm2cidr-> 28 (nm2cidr2: 27) 28: -cidr2dot-> 255.255.255.240 -nm2cidr-> 29 (nm2cidr2: 28) 29: -cidr2dot-> 255.255.255.248 -nm2cidr-> 30 (nm2cidr2: 29) 30: -cidr2dot-> 255.255.255.252 -nm2cidr-> 30 (nm2cidr2: 30) 31: -cidr2dot-> 255.255.255.254 -nm2cidr-> 31 (nm2cidr2: 31) 32: -cidr2dot-> 255.255.255.255 -nm2cidr-> 32 (nm2cidr2: 32) -- This message posted from opensolaris.org ___ zones-discuss mailing list zones-discuss@opensolaris.org
Re: [zones-discuss] Netmask conversion fix
Graham Hares writes: > if [ $oct1 -lt 128 ]&&[ $oct2 -eq 0 ]&&[ $oct3 -eq 0 ]&&[ $oct4 -eq > 0 ];then cidr=0; You can do most of this with: perl -e 'use Socket; print unpack("%32b*",inet_aton($ARGV[0])), "\n";' $nm If you really want to make sure that unsupported non-contiguous netmasks are all transformed into /24 as this script does (not sure why that's a good thing), then: perl -e 'use Socket; $addr = inet_aton($ARGV[0]); $bits = unpack("%32b*",$addr); $contig = pack("N",~((1<<(32-$bits))-1)); print (($contig eq $addr ? $bits : 24), "\n");' $nm > cidr2dot() { >cidr=$1 > if [ $cidr -ge 32 ];then netmask='255.255.255.255' Similarly: perl -e 'use Socket; ($c1,$c2,$c3,$c4) = unpack("C4",pack("N",~((1<<(32-$ARGV[0]))-1))); print "$c1.$c2.$c3.$c4\n";' $cidr There probably ought to be better ways of handling IP values in your shell of choice. -- James Carlson, Solaris Networking <[EMAIL PROTECTED]> Sun Microsystems / 1 Network Drive 71.232W Vox +1 781 442 2084 MS UBUR02-212 / Burlington MA 01803-2757 42.496N Fax +1 781 442 1677 ___ zones-discuss mailing list zones-discuss@opensolaris.org
[zones-discuss] Re: Fwd: Re: Tivoli Storage Manager (TSM) and zones
TSM client is supported in non-global-zones (only zsf is not supported) we have in every zone a TSM client, which backuped the entire Zone (FS and Oracle/SAP with rman ), so you can move zones without a reconfigure of TSM. lofs mounts are per default excluded. This message posted from opensolaris.org ___ zones-discuss mailing list zones-discuss@opensolaris.org
Re: [zones-discuss] Re: Fwd: Re: Tivoli Storage Manager (TSM) and zones
Let's see if I got the whole picture right... To summarize, ie on a practical example using the following template: / would be the only filesystem that we could backup from within the zone but we would have to use tsm to backup /dev, /var and else thru the global zone client ... guess after all with our current setup, we should keep backuping everything thru the global zone and develop a process for users to requests backup restore thru the unix admins instead of a self service model as we don't want them to access the global and they would in any case be confuse with the filesystem structure being completly differently presented within the global. dbsz8005 #mount -v / on / type ufs read/write/setuid/devices/intr/largefiles/logging/xattr/onerror=panic/dev=41c59d8 on Thu Nov 30 14:14:01 2006 /dev on /dev type lofs read/write/setuid/devices/zonedevfs/dev=4d40016 on Thu Jan 25 11:29:34 2007 /var on /var type lofs read/write/setuid/devices/dev=41c59d9 on Thu Jan 25 11:29:34 2007 [..] Mario, how do you present your filesystems to oracle ? Are you using raw devices ? On 1/25/07, mario heimel <[EMAIL PROTECTED]> wrote: TSM client is supported in non-global-zones (only zsf is not supported) we have in every zone a TSM client, which backuped the entire Zone (FS and Oracle/SAP with rman ), so you can move zones without a reconfigure of TSM. lofs mounts are per default excluded. This message posted from opensolaris.org ___ zones-discuss mailing list zones-discuss@opensolaris.org Regards -- Gael ___ zones-discuss mailing list zones-discuss@opensolaris.org
Re: [zones-discuss] Re: Fwd: Re: Tivoli Storage Manager (TSM) and zones
I would check with IBM on that. From my understanding from IBM is that TSM is supported with zones only if the TSM client is installed within the local zone. I do not think backing up the local zones through the global zone is supported. Nick On 1/25/07, Gael <[EMAIL PROTECTED]> wrote: Let's see if I got the whole picture right... To summarize, ie on a practical example using the following template: / would be the only filesystem that we could backup from within the zone but we would have to use tsm to backup /dev, /var and else thru the global zone client ... guess after all with our current setup, we should keep backuping everything thru the global zone and develop a process for users to requests backup restore thru the unix admins instead of a self service model as we don't want them to access the global and they would in any case be confuse with the filesystem structure being completly differently presented within the global. dbsz8005 #mount -v / on / type ufs read/write/setuid/devices/intr/largefiles/logging/xattr/onerror=panic/dev=41c59d8 on Thu Nov 30 14:14:01 2006 /dev on /dev type lofs read/write/setuid/devices/zonedevfs/dev=4d40016 on Thu Jan 25 11:29:34 2007 /var on /var type lofs read/write/setuid/devices/dev=41c59d9 on Thu Jan 25 11:29:34 2007 [..] Mario, how do you present your filesystems to oracle ? Are you using raw devices ? On 1/25/07, mario heimel <[EMAIL PROTECTED]> wrote: > > TSM client is supported in non-global-zones (only zsf is not supported) > > we have in every zone a TSM client, which backuped the entire Zone (FS > and Oracle/SAP with rman ), so you can move zones without a reconfigure of > TSM. > > lofs mounts are per default excluded. > > > This message posted from opensolaris.org > ___ > zones-discuss mailing list > zones-discuss@opensolaris.org > Regards -- Gael ___ zones-discuss mailing list zones-discuss@opensolaris.org ___ zones-discuss mailing list zones-discuss@opensolaris.org
Re: [Fwd: Re: [zones-discuss] Re: zonemgr -s syntax]
On Wed 24 Jan 2007 at 02:00PM, The Real Warren Belfer wrote: > We install the Core and add the 10 or so packages needed to > get zones. I assume that other customers might well do the > same thing. My desire is to have zones be part of the core in Nevada, possibly by folding them right into SUNWcsu/SUNWcsr. That will make life easier for a lot of people, including the development team, I think. -dp -- Daniel Price - Solaris Kernel Engineering - [EMAIL PROTECTED] - blogs.sun.com/dp ___ zones-discuss mailing list zones-discuss@opensolaris.org
Re: [Fwd: Re: [zones-discuss] Re: zonemgr -s syntax]
On Wed 24 Jan 2007 at 01:04PM, The Real Warren Belfer wrote: > John Clingan wrote: > >If we had used ksh, I am sure we would have gotten the bash question :) > > > >Developer preference I suppose. If you still have issues, blame Brad. He > >started it :) > > Hi, > > Well, shouldn't system utilities be written using tools > available in all install metaclusters. Bash is only available > in the End User install and larger, so folks using a Core install > or smaller wouldn't be able to use this. > > OTOH, ksh is available in all clusters, Well zonemgr isn't part of the Solaris product, so no such rules apply (and there never were any such rules in the first place, although there probably should have been). As long as the zonemgr package states a package dependency on what it needs, then it can be considered an acceptably packaged utility, IMO. -dp -- Daniel Price - Solaris Kernel Engineering - [EMAIL PROTECTED] - blogs.sun.com/dp ___ zones-discuss mailing list zones-discuss@opensolaris.org
Re: [zones-discuss] Re: Fwd: Re: Tivoli Storage Manager (TSM) and zones
On Thu, Jan 25, 2007 at 07:00:23AM -0800, mario heimel wrote: > TSM client is supported in non-global-zones (only zsf is not supported) > > we have in every zone a TSM client, which backuped the entire Zone (FS and > Oracle/SAP with rman ), so you can move zones without a reconfigure of TSM. > > lofs mounts are per default excluded. So any "rw" lofs mounts in a non-global zone will be backed up by the TSM client in the global zone. Seems reasonable. There is one final opportunity for "double backup" the case "TSM client in every zone" case. That is each non-global zone's "/" filesystem. For instance: global zone: "/zones" mounted on /dev/dsk/whatever, with subdir /zones/zone_a/root zone_a "/" is mounted on /zones/zone_a/root, a "ufs" mount from the perspective on zone_a. /zones/zone_a/root/var is just a regular directory (not a mountpoint) inside of the /zones filesystem mounted on /dev/dsk/whatever. >From global zone: TSM client backup of "/zones" or "/zones/zone_a" will backup /zones/zone_a/root/var >From zone_a: TSM client backup of "/" will backup /var, backing up /zones/zone_a/root/var again. -Steve > > > This message posted from opensolaris.org > ___ > zones-discuss mailing list > zones-discuss@opensolaris.org ___ zones-discuss mailing list zones-discuss@opensolaris.org
Re: [Fwd: Re: [zones-discuss] Re: zonemgr -s syntax]
My desire is to have zones be part of the core in Nevada, possibly by folding them right into SUNWcsu/SUNWcsr. There's also a related CR open 6421453 RFE: SUNWCzone should be available in SUNWCmreq and above Fixing is involves an examination of SUNWzoneu's dependencies and seeing what else needs to move along with the zone packages or what can be refactored in a different way. dsc ___ zones-discuss mailing list zones-discuss@opensolaris.org
Re: [zones-discuss] Netmask conversion fix
James, Honestly when I initially wrote these conversions I had hoped that someone would provide a much simpler way of doing them. I was surprised that there wasn't a standard OS command to do the conversions for you. That being said, your method is absolutely brilliant. Thanks! With respect to the default cidr=/24, I meant to condition both directions of conversion to throw an error if the inputs exceeded boundary conditions. However as you can see I forgot to get around to that. Now I will get it into 1.8.1 thanks to your contribution. Brad On Thu, 2007-01-25 at 09:27 -0500, James Carlson wrote: > Graham Hares writes: > > if [ $oct1 -lt 128 ]&&[ $oct2 -eq 0 ]&&[ $oct3 -eq 0 ]&&[ $oct4 > > -eq 0 ];then cidr=0; > > You can do most of this with: > > perl -e 'use Socket; print unpack("%32b*",inet_aton($ARGV[0])), "\n";' $nm > > If you really want to make sure that unsupported non-contiguous > netmasks are all transformed into /24 as this script does (not sure > why that's a good thing), then: > > perl -e 'use Socket; > $addr = inet_aton($ARGV[0]); > $bits = unpack("%32b*",$addr); > $contig = pack("N",~((1<<(32-$bits))-1)); > print (($contig eq $addr ? $bits : 24), "\n");' $nm > > > cidr2dot() { > >cidr=$1 > > if [ $cidr -ge 32 ];then netmask='255.255.255.255' > > Similarly: > > perl -e 'use Socket; > ($c1,$c2,$c3,$c4) = unpack("C4",pack("N",~((1<<(32-$ARGV[0]))-1))); > print "$c1.$c2.$c3.$c4\n";' $cidr > > There probably ought to be better ways of handling IP values in your > shell of choice. > ___ zones-discuss mailing list zones-discuss@opensolaris.org
Re: [zones-discuss] Netmask conversion fix
James, I submitted the bug, implemented your contribution into 1.8.1, QA'ed the changes, uploaded the updated version of 1.8.1, filed the change log, and documented your contribution. The updated 1.8.1 download is available here: http://opensolaris.org/os/project/zonemgr/files/zonemgr-1.8.1.txt Thanks again! Brad On Thu, 2007-01-25 at 22:01 -0600, Brad Diggs wrote: > James, > > Honestly when I initially wrote these conversions I had hoped > that someone would provide a much simpler way of doing them. > I was surprised that there wasn't a standard OS command to do > the conversions for you. > > That being said, your method is absolutely brilliant. Thanks! > > With respect to the default cidr=/24, I meant to condition both > directions of conversion to throw an error if the inputs exceeded > boundary conditions. However as you can see I forgot to get > around to that. Now I will get it into 1.8.1 thanks to your > contribution. > > Brad > > On Thu, 2007-01-25 at 09:27 -0500, James Carlson wrote: > > Graham Hares writes: > > > if [ $oct1 -lt 128 ]&&[ $oct2 -eq 0 ]&&[ $oct3 -eq 0 ]&&[ $oct4 > > > -eq 0 ];then cidr=0; > > > > You can do most of this with: > > > > perl -e 'use Socket; print unpack("%32b*",inet_aton($ARGV[0])), "\n";' $nm > > > > If you really want to make sure that unsupported non-contiguous > > netmasks are all transformed into /24 as this script does (not sure > > why that's a good thing), then: > > > > perl -e 'use Socket; > > $addr = inet_aton($ARGV[0]); > > $bits = unpack("%32b*",$addr); > > $contig = pack("N",~((1<<(32-$bits))-1)); > > print (($contig eq $addr ? $bits : 24), "\n");' $nm > > > > > cidr2dot() { > > >cidr=$1 > > > if [ $cidr -ge 32 ];then netmask='255.255.255.255' > > > > Similarly: > > > > perl -e 'use Socket; > > ($c1,$c2,$c3,$c4) = unpack("C4",pack("N",~((1<<(32-$ARGV[0]))-1))); > > print "$c1.$c2.$c3.$c4\n";' $cidr > > > > There probably ought to be better ways of handling IP values in your > > shell of choice. > > > > ___ > zones-discuss mailing list > zones-discuss@opensolaris.org ___ zones-discuss mailing list zones-discuss@opensolaris.org