[Babel-users] A walk through the babeld code

Juliusz Chroboczek jch at pps.jussieu.fr
Tue Jul 12 16:45:00 UTC 2011


Dear all,

I've been asked for a quick guide to the code.  Here it is.

General conventions
===================

Four spaces per indentation, no tabs.  K&R indentation style, except for
function headings, which are in GNU style.

When the external interface and the implementation are split, the
external interface is called foo, while the implementation is called
really_foo.  See send_update and really_send_update.

Main program
============

The main program is in babeld.c.  Argument parsing, daemonisation, etc.


Packet I/O
==========

There are two files that deal with packet I/O:

  - message.c for most stuff;
  - resend.c for packets that need to be remembered in order to do
    duplicate elimination and resending.

Most packet I/O and related logic happens in message.c.  Input logic is
in parse_packet (read it!) while output logic is split among the send_*
functions.

The send_* functions only buffer a message, and schedule flushing the
buffer.  This allows for message aggregation and jitter.  See flushbuf.

This is *not* true of the send_update function, which uses a specific
buffer.  See flushupdates.


Data structures
===============

There are five main data structures, with a file for each:

* struct network, network.c: interfaces (yeah, it's a misnomer);
* struct source, source.c: sources (remote routers originating routing
  information);
* struct neighbour, neighbour.c: neighbours (neighbouring routers);
* struct route, route.c: routes learned from Babel;
* struct xroute, xroute.c: redistributed routes (learnt by other means).

Most of the interesting stuff is in route.c and neighbour.c.


Configuration and filtering
===========================

The configuration file parser and the filters implementation is in
config.c.  (In case you're wondering, it's a recursive-descent parser
with one character of look-ahead.)


Low-level files
===============

Low-level networking is in net.c.  Yuck.

The kernel interface is in kernel.c, with implementations in
kernel_netlink.c (Linux) and kernel_socket.c (BSD).  Doubleplusyuck.

Random small functions that fit nowhere else are in util.c.

Hope that helps,

-- Juliusz



More information about the Babel-users mailing list