Monday 14 October 2013

Walkthrough. Part 1


Getting to know finer details....end of Week 3


Ankur - I guess the most difficult thing to do is figuring out the code others have written.


Charitha - Yeah, I had a look at tayga implementation. It polls.


Ankur - Same here! Tayga is written in C. As I was looking through the code, it consists of 5 implementation files and few header files.
The "main" is in tayga.c file, which reads command line arguments and the configuration file parameters.


For eg: tayga --mkTUN to make a TUN driver
tayga --rmTUN to remove the TUN driver


Configuration file parameters
TUN-device nat64   # Name of the TUN driver
ipv4-addr 192.168.255.1 # Tayga’s IPv4 address
prefix 2001:db8:1:ffff::/96 # /96 prefix for IPv6 clients
dynamic-pool 192.168.255.0/24 # pool of assignable IPv4 addresses




Charitha - As I remember from our previous conversation, TUN interfaces are a feature offered by Linux that can do user space networking, allowing user space programs to see raw network traffic at IP level.


Ankur - Absolutely! You mentioned something about polling.


Charitha - Once the TUN driver is created, the program attaches to the TUN interface where it gets a special file descriptor. The program uses poll() to wait for some event on the file descriptor.


                  int poll(struct pollfd *fds, nfds_t nfds, int timeout);


Poll waits for one of a set of file descriptors to become ready to perform I/O. The file descriptor we are talking about here is the TUN fd.
Another set of fd which it keeps track of  is signals. These are user interrupt signals like SIGINT, SIGSTOP and also few other signals like SIGUSR1, SIGUSR2.


From description of TUN interface, we know that it sends both IPv4 and IPv6 packet.


Ankur - Yes So basically, the Program manipulates the IP packets(IPv4 to IPv6 and vice versa) and sends it back to the TUN interface.


Charitha - Exactly. Have a look at this function in tayga.c file.
    static void read_from_tun(void)
It reads the packets from TUN fd and forwards it for translation.


Ankur - Let me go and have a look at how the translation happens!