Wednesday, 03 November 2010

Configuring a static 6in4 tunnel in Gentoo

I recently started experimenting with IPv6, using tunnels available from Hurricane Electric and SixXS. I want the tunnel to automatically be set up when my computer starts, but the directions available from the official IPv6 Router Guide only show how to manually configure the tunnel using the ip command from the iproute2 package.

Fortunately, it is possible to use Gentoo’s network configuration scripts to set up the tunnel, and I hope to document how to do this in this post.

Getting started

In order to configure your tunnel, you must ensure that you are running an IPv6-enabled kernel. Additionally, you should have set up a 6in4 tunnel with a broker such as Hurricane Electric or SixXS. If you need help with these steps, please refer to the Gentoo IPv6 Router Guide.

Tunnel endpoint addresses

Your tunnel broker should have provided the following information for you:

Name Example value Description
IPv4 server endpoint 172.17.15.24 The IPv4 address of the tunnel server
IPv4 client endpoint 172.21.187.195 Your public IPv4 address
IPv6 server endpoint 2001:db8:a7d0:d3fa::1/64 The IPv6 address of the tunnel server
IPv6 client endpoint 2001:db8:a7d0:d3fa::2/64 Your IPv6 address in the tunnel
Network interface names

The interface name for the tunnel generally has the form sitn where sit stands for Simple Internet Transition and n is a number. You will most likely already have a sit0 interface created by the kernel. This guide will use the generic name sit1, but you can give it any name you like.

You will also need to know the name of the interface that has your public IPv4 address, such as eth0.

Updating /etc/conf.d/net

You will need to add the following lines to /etc/conf.d/net, substituting your tunnel’s address and interface names:

  # Create tunnel interface ‘sit1’ with given IPv4 endpoints
  iptunnel_sit1="mode sit local 172.21.187.195 remote 172.17.15.24 ttl 255"
  # Assign local IPv6 address to tunnel interface
  config_sit1="2001:db8:a7d0:d3fa::2/64"
  # Make the tunnel the default route for IPv6 traffic
  routes_sit1="::/0"
  # Ensure that eth0 is up before setting up the tunnel
  RC_NEED_sit1="net.eth0"

Creating and starting the service

Finally, you will need to create the service for your tunnel just as you would for any other network interface:

  # cd /etc/init.d
  # ln -s net.lo net.sit1

You can now add the service to the default run level and start it:

  # rc-update add net.sit1 default
   * net.sit1 added to runlevel default
  # /etc/init.d/net.sit1 start
   * Caching service dependencies ...
   * Starting sit1
   *   Creating tunnel sixxs ...                                             [ ok ]
   *   Bringing up sixxs
   *     2001:db8:a7d0:d3fa::2/64                                            [ ok ]
   *   Adding routes
   *     ::/0 ...                                                            [ ok ]

Testing your tunnel

Now that your tunnel has been established, you should be able to ping the other end of your tunnel. This requires the ping6 utility which should be available if you installed iputils with the ipv6 USE flag.

  # ping6 -c 1 2001:db8:a7d0:d3fa::1
  PING 2001:db8:a7d0:d3fa::1(2001:db8:a7d0:d3fa::1) 56 data bytes
  64 bytes from 2001:db8:a7d0:d3fa::1: icmp_seq=1 ttl=64 time=16.4 ms

  --- 2001:db8:a7d0:d3fa::1 ping statistics ---
  1 packets transmitted, 1 received, 0% packet loss, time 0ms
  rtt min/avg/max/mdev = 16.410/16.410/16.410/0.000 ms

If the above test worked, you have successfully set up your tunnel. Welcome to the world of IPv6.

Learning more

Now that you have set up your IPv6 tunnel, there are any number of things you can do. Some good resources for further reading include:

  • Gentoo IPv6 Router Guide: From the Gentoo documentation team, this guide covers setting up DNS, routing, automatic configuration (e.g. DHCP), and client configuration.
  • Linux+IPv6-HOWTO: This HOWTO contains some good background information on IPv6 and contains some more detailed instructions on setting up IPv6 on Linux.

In the next couple of weeks I plan to write about both Hurricane Electric and SixXS and their IPv6 services.

Thursday, 25 March 2010

Clojure now in java-overlay

I recently received commit access to Gentoo’s Java overlay, and so I took the chance to commit my ebuilds for Clojure and Clojure-contrib. This means that Clojure is now a step closer to becoming a standard part of Gentoo.

The following step-by-step guide should help you get started. Note that the following instructions assume you are using the standard Gentoo package management tools. If you use some other system, such as Paludis, you will need to refer to the documentation for your preferred manager about how to add overlays and keyword packages.

In order to get started, you will have to first make sure that the Java overlay is installed on your system.

Installing the Java overlay on Gentoo

In order to install Clojure, you will need to install layman according to the instructions in the User’s Guide. Be sure to enable the subversion USE flag. Once you have layman installed, you should be to execute layman -L and see a line similar to the following:

* java-overlay              [Subversion] (svn://overlays.gentoo.org/proj/java/java-overlay/

Once layman is installed, add the Java overlay using layman -a java-overlay. After a lengthy checkout, you should see the line:

* Successfully added overlay "java-overlay".

Congratulations, you now have the Java overlay installed. Now you can move onto installing Clojure.

Emerging Clojure

With the Java overlay installed, the Clojure and Clojure-contrib ebuilds are now available through portage.

Note that Clojure is currently keyworded ~amd64 and ~x86. This means that if you are running on the stable branch of Gentoo (the default), or if you are not using an amd64- or x86-based computer, you will need to take a few extra steps. The good news is that if you can run Java on your system, you should be able to run Clojure as well1.

With the proper keywording done, installing Clojure is as simple as emerge clojure. Note that both 1.0.0 and 1.1.0 versions of Clojure are available, and you can install them concurrently using Gentoo’s slot mechanism. By default, portage will install the latest version (1.1.0 slotted as 1.1), but you can force installing version 1.0 by using slot ‘0’, i.e. emerge clojure:0.

The above instructions also apply for installing Clojure-contrib—simply emerge clojure-contrib or emerge clojure-contrib:0.

Running Clojure

With Clojure emerged, running the REPL is as simple as typing clojure or clojure-1.1, depending on which version you are using.

Including Clojure-contrib manually

Note that, by default, the Clojure commands will not include Clojure-contrib in your class path. You can do this manually on the command line by invoking Clojure using one of the following commands:

For clojure-contrib 1.1.0:

CLASSPATH=$(java-config -p clojure-contrib-1.1) clojure-1.1

For clojure-contrib 1.0.0:

CLASSPATH=$(java-config -p clojure-contrib) clojure
Including Clojure-contrib automatically

The way I prefer to run Clojure is to have the launcher script automatically include Clojure-contrib. This can be done by customizing the launcher’s class path by adding files to the .gentoo/java-config-2/launcher.d directory under your home directory2.

For version 1.1.0:

% echo 'gjl_package="clojure-contrib-1.1"' > .gentoo/java-config-2/launcher.d/clojure-1.1

For version 1.0.0:

% echo 'gjl_package="clojure-contrib"' > .gentoo/java-config-2/launcher.d/clojure

Having accomplished the above, Clojure-contrib should now be available from the launcher. For example, you could try:

% clojure-1.1
Clojure 1.1.0
user=> (use 'clojure.contrib.str-utils)
nil
user=>

Final Thoughts

This is merely the first step towards getting better Clojure support in Gentoo. Some of the next few things I am considering doing include:

  • Add ebuilds for editor integration with Clojure. There is a VimClojure ebuild in java-experimental that I will soon be moving to java-overlay. Although I don’t use other editors, I think that Emacs integration would be good, too.
  • Add some sort of eselect-based method to automate much of the above. I envision a script that will manage it so that typing clj will launch the appropriate version of Clojure and include Clojure-contrib if desired.
  • Package more Clojure applications and libraries.

I am working towards become a full-fledged Gentoo Developer. Once I get there, I will have a better opportunity to help get Clojure-related packages into the main tree and help make Gentoo a very Clojure-friendly Linux distribution.

In the meantime, I appreciate any user feedback. You can find me as ‘sattvik’ on Freenode on #gentoo-java and #clojure. Of course, you can also leave comments on this site.

Footnotes
  1. If you do get Clojure working on non x86 or amd64 system, please make a note of it in the bugs for Clojure and Clojure-contrib.
  2. Alternatively, you can add these files to /etc/java-config-2/launcher.d/ to have the effect system-wide.