Roy's Blog

A Hacker's musings on Code | Tech | Life

A few people say that our network scripts are slow. Well, they were damn slow when 1.11 first hit portage. :( Stopping is always the slowest as every module is loaded and evaluated. As we add more modules to do more fancy networking tricks, we get slower and slower. So over time we've added a few speed ups.

First, we cached a lot of repeatedly called functions (mainly _provides, _before and _after). Then we removed a function which checked to see if a module over-wrote any functions (nice idea, but very very slow and didn't always work as you could nest functions in bash). This brought us from a stop time of around 15 seconds to the current stop time of around 5 seconds on my laptop (1.6 Celery for reference).

Ever since I've been bugged with how slow the sort routine agriffis wrote (which replaced my even slower bubble sort) as it's the slowest point of the whole process. Infact, sorting the modules when stopping normally took around 2.5 seconds on my laptop, the only part of the process which takes over 0.3 seconds.

So I had a wild idea, lets try and implement a topological sort routine. Luckily I had made one earlier for the main rc system, and written in bash (the C tsort command is in /usr/bin and may not always be available).

This has reduced our times to as follows with lan_config=( "dhcp" )

# time /etc/init.d/net.lan stop
real     0m3.005s
user     0m1.740s
sys      0m1.000s

# time /etc/init.d/net.lan start
real     0m2.662s
user     0m1.612s
sys      0m0.888s

Now, thats fast - almost cut the times in two! :) We get even faster with less modules, and of course there's still the option to force modules.

Experience it when baselayout-1.12.0_pre10 hits a portage near you!

Discuss this Post

After finding out that a localmount bug was actually a kernel issue, I also noticed that after creating a reiserfs root my prism54 card loaded by itself (when booting onto reiserfs). "That's odd" I thought as it hadn't done that for a long time and I'd attributed it starting/not starting to udev issues.When booting ext3, it loads the prism54 driver just fine, but doesn't do anything else - not even call net.agent. When booting reiserfs it calls net.agent and loads the firmware and starts net.wlan just fine.So is this a kernel issue? I'll find out once gentoo-sources-2.6.14 hits the tree. If I can still reproduce this issue 100% I'll open a nice buggie for someone to try and fix :)Another oddity is that if you remove and insert the card repeatedly, it only "starts" every other time. There's no dmesg's about it when you insert it and nothing happens either, so I'm guessing it's definitely kernel/udev related.EDIT: Looks like a ext3 error as it boots fine on reiser4 and xfs too

Discuss this Post

I've been a long time user and trumpet blower for dnsmasq which is a DNS forwarder and DHCP server. It's perfect for LAN's as it's small, light and fast especially when compared against the usual DHCP + BIND combo from ISC. What's more, it's very easy to configure and uses the standard /etc/hosts file to serve static DNS.However, it's not without its negative points as I discovered when setting up my new domain DNS server so I can serve IPv6 and redirect $familymember.marples.name to another IP.The main issue is you can't change which config file it uses, namely it always reads /etc/dnsmasq.conf. This isn't normally a problem, but I wanted a DNS server that told the world one thing and my LAN another. I'm also not the worlds greatest C developer, so I didn't want to patch dnsmasq so it could work for my needs as what I want todo is probably outside the current scope of dnsmasq.I've also had prior experience with BIND, but that was a long time ago and it wasn't pretty. PowerDNS I've also used, but my main gripe is that it takes ages to compile as it's C++ and my server isn't that fast. Another minus for PowerDNS is the inability to handle dynamic DNS as far as I could tell (which is a must when friends pop around with laptops).So to cut to the chase, I've configured BIND + DHCP from ISC which handles what I need just fine as it now handles "views" which it didn't support last I used it. Views enable me to show one DNS to my LAN and another to the world :) A big plus thats come out of this is that name resolution is much faster :DThe moral of this story is that sometimes the software that you give kudos too isn't always the right tool for the job - and the right tool may sometimes be the tool that you least wanted to use :O

Discuss this Post

Turns out that routing was very simple. Just obtain a tunnel from a broker (I use BT Exact).

Once you have a tunnel, you can set it up like so in baselayout

iptunnel_sit1="mode sit remote $REMOTE_IPV4 ttl 64"
config_sit1=( "$TUNNEL_IPV6" )
routes_sit1=( "2000::/3" )

Then setup radvd for your allocation block (don't forget to advertise the router this time) and you're good to go :)

Discuss this Post

IPv6

tech

IPv6 - the future? Not yet! :O

The problem as I see it is that it's too complicated for end users. Even though I'm the maintainer of Gentoo networking scripts, I know nada about IPv6. It's too complicated. Well it's actually quite easy, it's the documentation thats too complicated.

So here's a quick and easy for IPv6 on the home network :)

  1. Enable IPv6 in the kernel
  2. Add "ipv6" to your USE flags
  3. emerge -uaDvN world to get everything recompiled for ipv6
  4. emerge iproute2 and baselayout-1.12.0 as you'll get much better ipv6 support :)

Now we have a Gentoo IPv6 system, let's get to the meat! :D

If you look at the output from ip addr you get something like this inet6 fe80::230:48ff:fe54:45a6/64 scope link

That shows an IPv6 address encoded with your NICs MAC address.

In simple terms, the network prefix is fe80::/64 - this is akin to a subnet (255.255.255.0 or /24) 230:48ff:fe54:45a6 is based off the mac address.

Now fe80 is non routeable anywhere - it's just on your PC. So we need a routeable private IPv6 prefix - like 192.168. in IPv4 terms. Prefixes you can use are fecx, fedx, feex and fefx. For this example we'll use fec0.

Now, we combine these two bits of information to create a routeable IPv6 address fec0::230:48ff:fe54:45a6/64. Lets add this to conf.d/net

config_eth0=( "196.168.0.1/24" "fec0::230:48ff:fe54:45a6/64" )

Restart net.eth0 and you have a site local IPv6 address :)

Lastly, we need to inform other machines about the IPv6 subnet. Todo that, we use radvd, so emerge it. Then slap this into /etc/radvd.conf

interface eth0
{
    AdvSendAdvert on;
    prefix fec0::/64
    {
        AdvOnLink on;
        AdvAutonomous on;
        AdvRouterAddr off;
    };
};

Start radvd (/etc/init.d/radvd start) and hey presto, all IPv6 capable machines will now have their own IPv6 address as radvd configures a stateless network.

Thats it :D

So what's missing? Well, DHCP information for starters. IPv6 stateless config does not cater for this. You could emerge dhcpv6 and put a dhcp6s server and and get dhcp6c clients in use, but they don't do any dyanmic dns and I can't find an easy way to enable that. You could write a script on the server to parse the leases file and update a hosts file with the ipv6 info and then hup dnsmasq which can read host files but that's klunky. Especially as the hostname has to be coded into the dhcp6c.conf (just like dhclient - it cannot be specified on the commandline for some obscure reason).

But as we're using IPv6 addreses based on MAC addresses, they won't change. And they're unique. So the best solution is to put the addresses into a /etc/hosts file or install a DNS server to translate the name into an IPv6 address - dnsmasq is very good for this.

Lastly, because radvd is just broadcasting subnet information there is no gateway/default route. This is because my ADSL router and ISP don't handle IPv6 so it's pointless setting one. You'll probably be in the same boat for a while, so ......

I'll look into a 6to4 tunnel so I can use IPv6 across my IPv4 only adsl router and access IPv6 on the internet. I'll even blog about it when I get it working :)

Thanks to johnm, tigger^ and brix in #gentoo-dev on irc.freenode.net for helpful stuff :)

Resources

Discuss this Post