MySQL selecting IPs via CIDR

Quick little snippet here for selecting IPs from a database based off a CIDR subnet. First off a table structure with some test data:

Now let’s say we want all IPs from the subnet 173.192.175.16/28, using a simple 173.192.175.% would provide false results since you don’t want the whole /24.

If your IP is stored as an unsigned int (good for you) than you can use this snippet to search for matching IPs:

If your IP is stored as a varchar (for whatever reason), the only difference is a inet_aton() around the IP field.

No matter which one you use, the result will be:

Windows reinstall and Adobe fun

I never got around to posting it, but a few weeks back the hard drive of my PC with Windows on it died … a little bit. Technically a large chunk of the harddrive is simply unaccessable. after poking and pushing I at least got windows to boot up again, but a large part of the software was dead. I bough a new drive and went through the fun process of installing a fresh windows, patching it, and then installing all the software again.

I didn’t get around to installing my video and picture software on the new windows until this morning, and it turned out to be lots of fun. Due to pure luck I found the license key for sony vegas (it is shown in the splash screen when starting up, shortly before it crashes due to my harddisk malfunction). Any Photomatix was where I keep most licenses stored. But my Photoshop license was more of a challenge. Adobe only allows 2 activated copies of the software per license, activated copies are bound to hardware … you probably see where this is going. I couldn’t deactivate the old installation since the harddrive was kinda dead, and the new installation says “different hardware (new harddrives), must be a different computer”. Yay, fun. The bright side was that the support was easily contacted and they could reset the activation counter (after lecturing me about using it on “2 computers” and deactivating, bla bla bla). I learned one thing: the more expensive the software, the more problems you have with licenses. A shame I never liked Gimp for photo editing.

XEN 3.4 with ipv6 routing

Yes, there are a few postings out there about getting ipv6 routing running with XEN. But I’ll throw this online anyway since there are a few changes I had to make for it to work on my server. This text is intended for people who know their way around Linux and XEN so it will be a bit technical and won’t spell out every single step you have to make.

Most of the changes are based off scripts and information from BenV and wnagele (latter is interesting for me since I am also running XEN on a hetzner server). Have a look at the two links if anything is unclear. Now let’s start the fun 🙂

First of all we need IPv6 up and running on the host (dom0). Add the IP and gateway to your /etc/network/interfaces
This is what mine looks like:
iface eth0 inet6 static
address 2a01:4f8:100:1123::2
netmask 64
gateway 2a01:4f8:100:1120::1
pre-up ip -6 route add 2a01:4f8:100:1120::1 dev eth0

Check if the IP address is responding to the outside world (e.g. with wiberg.nu/iptools.php), if everything looks ok, proceed …
Now we need to enable a few things to get routing and neighbor discovery running on the host (dom0). Edit your /etc/sysctl.conf and add/change these 2 entries (and while you are at it, set them with “sysctl -w” too):
net.ipv6.conf.all.forwarding=1
net.ipv6.conf.all.proxy_ndp=1

So, your host should by now be online with ipv6 and soon be able to route packets to it’s guests. By default XEN will only take care of IPv4 when a guest is created, so here is a small patchfile that adds support for IPv6: xen-ipv6-vif-route.patch. The patch changes vif-route and vif-common.sh, while these files may be in different places depending on your distribution, /etc/xen/scripts/ is where they can commonly be found. Download the patch to the directory with the scripts to be changed and execute a “patch -p0 < xen-ipv6-vif-route.patch” (vif-common.sh gets a few new IPv6 functions, and iptables now won’t try to change stuff for IPv6 IPs. vif-route changes are: ndp is enabled for the vif device and the route/neighbor IPv6 settings are set)

So, now that the scripts know how to setup all our IPv6 needs, we need to add the IPv6 IP to our guest settings (.cfg file typically found in /etc/xen/). What we want to change is the “vif” setting. Add the IPv6 IP of the guest to the IPv4 IP (just the IP without the trailing /network, space separated form the IPv4 IP):
vif = [ 'mac=B1:A3:3F:25:11:B8, ip=2a01:4f8:100:1123::5 188.40.34.101' ]

Now you can create the guest(domU) and add the IPv6 IP to the /etc/network/interfaces of the guest if you haven’t so already (it uses the host (dom0) as the gateway).

iface eth0 inet6 static
address 2a01:4f8:100:1123::5
netmask 64
gateway 2a01:4f8:100:1123::2

Restart the networking on the guest (or reboot it) and you should now be able to ping the guest from the internet. See, easy wasn’t it 🙂

Ubuntu upgrade to 10.04 and lirc

Ubuntu 10.04 (lucid) came out a short while ago … and because it contained new themes and the latest version of mythtv, I went and upgraded. These updates are tested by gazillions of people, any serious problems would be noticed before release .. right? right?

Well, looks like I did it again. Turned a working tv recorder into a “electronic beeping thing under the TV that doesn’t do much except show a pretty screensaver if you wait long enough”. After fixing up some stuff that the update broke (thanks for overwriting my config files. I’ll just use the version from the backup I made before the update if you don’t mind), I got almost everything up and running again. As of right now the only things broken are a) the theme not displaying any text when I’m in LiveTV or a video (yeah, try to get out of there without any menus) and b) my remote control is also not working.

At first I thought that some sonfig was just b0rked with the lirc config, but after doing a “top” and seeing that lirc_dev was consuming a modest 90% of my CPU, I decided that it was googles turn to find out what was wrong with Ubuntu 10.04. And sure enough, it seems this wa a know problem that made it into release (hooray). Anyone stumbling across this post via goole: go to https://bugs.launchpad.net/ubuntu/+source/lirc/+bug/550369, there are fixes for the problem towards the end of the page. Since it looks like they will make it into the 10.04 updates you can also just wait for a few days/weeks and they will pop up as a update automatically. Anyone wanting to fix the problem now: the short version ist: go to https://wiki.ubuntu.com/Testing/EnableProposed to set up proposed updates for lucid, and install “lirc” and “lirc-modules-source” from the proposed repository.

As for the broken themes? I’m still working on that, have a few updates and poking around to go before the system is back to the running condition it was before.

*Update*
For some strange reason, I had to set the IRQ of the serial port to 4 any specify it in the /etc/modconf.d directory (was getting busy errors with IRQ 3)

The broken themes were “only” the OSD using bold font. After changing it back to the normal version in the OSD settings everything worked fine.

XEN and Kernel update

Server is up and running again. This morning I finished the xen (3.4) and kernel (2.6.32) updates I prepared yesterday evening. The only pitfall I stumbled across, was that the kernel in the debian repository (2.6.26-xen) seemingly wasn’t compatible with the latest xen in the debian repository (system would hang while booting, I guess that’s what I get for using “testing”).

Anyway, anyone using “lenny” or “testing” and wanting to update xen; here are a few tips to make the transition a breeze:

  • The debian wiki is full of useful information regarding xen
  • backports.org has a current xen kernel (linux-image-2.6.32-bpo.4-xen-amd64) that works fine with xen 3.4, just follow the instructions on backports.org on how to add it to apt.
  • I had to deactivate the “vfb” (VNC console) setting in the domU config files to get my guests to boot, browsing the Internet I saw people having the same problem with the “dhcp” setting.
  • If you are planning on updating the guests kernels too (advised), remember to change the “kernel” and “ramdisk” settings in the domU config files accordingly

With these few points in mind, the update is a breeze.