Babel und dnsmasq in unsere firmware

Aus Freifunk Franken
Wechseln zu:Navigation, Suche

Diese Seite befindet sich noch im Entwurfsstadium.
Hilf mit sie zu verbessern!

Um aus einem Router ein Gateway zu machen, muss in die Firmware Olsr und dnsmasq mit eingebaut werden. Dieses Patch baut diese 2 Programme plain mit ein, es müssen danach noch diverse Konfigurationen und Routingparameter gesetzt werden. Es kann sich dazu ganz grob an die Anleitung zum Gateway aufsetzen gehalten werden.

Achtung! Man sollte sich bei solchen Experiementen immer gut überlegen wie man den Router noch erreichen kann, man kann sich relativ leicht selbst komplett aussperren. Nach diesem Patch baut der Router z.b. kein fastd Batman mehr zu einem Gateway auf, er mesht aber noch frei mit anderen Routern und spannt auch noch ein WLAN auf.

Zu beachten gilt auch, das dnsmasq und Olsr zu groß für 4MB Router sind, die Firmware wird nicht für jeden Router bauen. Ich hab sie aktuell für ar71xx gebaut und auf einen wr1043 (hat 8MB Flash) verwendet.

From d0ae5dc119e091b25d35d494d1514eb7aa48a521 Mon Sep 17 00:00:00 2001
From: Christian Dresel <fff@chrisi01.de>
Date: Sat, 7 May 2016 08:54:08 +0200
Subject: [PATCH] Add Olsr and dnsmasq

        modified:   bsp/ar71xx/.config
        modified:   buildscript
        deleted:    src/packages/fff/fff-fastd/files/usr/lib/micron.d/fff-fastd
        modified:   src/packages/fff/fff-fastd/files/usr/sbin/fastdstart
---
 bsp/ar71xx/.config                                 |  4 +-
 buildscript                                        |  8 +-
 .../fff/fff-fastd/files/usr/lib/micron.d/fff-fastd |  1 -
 .../fff/fff-fastd/files/usr/sbin/fastdstart        | 98 +---------------------
 4 files changed, 11 insertions(+), 100 deletions(-)
 delete mode 100644 src/packages/fff/fff-fastd/files/usr/lib/micron.d/fff-fastd

diff --git a/bsp/ar71xx/.config b/bsp/ar71xx/.config
index f7b0097..fdad7d6 100644
--- a/bsp/ar71xx/.config
+++ b/bsp/ar71xx/.config
@@ -17,7 +17,6 @@ CONFIG_CLEAN_IPKG=y
 # CONFIG_FASTD_ENABLE_METHOD_COMPOSED_GMAC is not set
 # CONFIG_FASTD_ENABLE_METHOD_GENERIC_GMAC is not set
 # CONFIG_PACKAGE_ALFRED_VIS is not set
-# CONFIG_PACKAGE_dnsmasq is not set
 # CONFIG_PACKAGE_firewall is not set
 CONFIG_PACKAGE_gpioctl-sysfs=y
 CONFIG_PACKAGE_kmod-ifb=y
@@ -29,6 +28,9 @@ CONFIG_PACKAGE_kmod-ledtrig-netdev=y
 CONFIG_PACKAGE_kmod-sched-connmark=y
 CONFIG_PACKAGE_libugpio=y
 # CONFIG_PACKAGE_odhcpd is not set
+CONFIG_PACKAGE_olsrd=y
+CONFIG_PACKAGE_olsrd-mod-dyn-gw-plain=y
+CONFIG_PACKAGE_olsrd-mod-txtinfo=y
 # CONFIG_PACKAGE_opkg is not set
 # CONFIG_PACKAGE_ppp is not set
 CONFIG_PACKAGE_qos-scripts=y
diff --git a/buildscript b/buildscript
index 7e16687..1563be6 100755
--- a/buildscript
+++ b/buildscript
@@ -26,6 +26,11 @@ OPENWRT=(openwrt
          $PACKAGEREV)
 OPENWRT_PKGS="gpioctl-sysfs libugpio fastd haserl"

+OLSRD=(olsrd
+      https://github.com/OLSR/olsrd
+      d48b0bc3d50b9b79545efca09fff39ee060794b9)
+OLSRD_PKGS="olsrd"
+
 ## Be careful: FFF uses COMPAT_VERSION 14 at the moment.
 ## See http://www.open-mesh.org/projects/batman-adv/wiki/Compatversion
 BATMAN_ADV=(batman_adv
@@ -42,7 +47,7 @@ ROUTING_PKGS="alfred"
 FFF=(fff)
 FFF_PKGS="-a"

-FEEDS=(OPENWRT ROUTING BATMAN_ADV FFF)
+FEEDS=(OPENWRT ROUTING BATMAN_ADV OLSRD FFF)

 checkout_git(){
     local DIRECTORY=$1
@@ -61,6 +66,7 @@ checkout_git(){
         else
             echo "wrong remote or not an git repo at all -> deleting whole directory"
             /bin/rm -rf "$DIRECTORY"
+
             #needs to be without -C!!!
             git clone "$REPO_URL" "$DIRECTORY"
             $MYGIT checkout "$COMMITID"
diff --git a/src/packages/fff/fff-fastd/files/usr/lib/micron.d/fff-fastd b/src/packages/fff/fff-fastd/files/usr/lib/micron.d/fff-fastd
deleted file mode 100644
index b0022e8..0000000
--- a/src/packages/fff/fff-fastd/files/usr/lib/micron.d/fff-fastd
+++ /dev/null
@@ -1 +0,0 @@
-*/5 * * * * sleep $(/usr/bin/random 0 29); sh /usr/sbin/fastdstart
diff --git a/src/packages/fff/fff-fastd/files/usr/sbin/fastdstart b/src/packages/fff/fff-fastd/files/usr/sbin/fastdstart
index 611a3f8..e9975e5 100755
--- a/src/packages/fff/fff-fastd/files/usr/sbin/fastdstart
+++ b/src/packages/fff/fff-fastd/files/usr/sbin/fastdstart
@@ -1,97 +1 @@
-#!/bin/sh
-
-SERVER="no"
-#SERVERNAME="--servername--"
-
-. /etc/community.cfg
-
-project="$VPN_PROJECT"
-
-test_ipv4_host1="keyserver.freifunk-franken.de" # Freifunk-Franken keyserver
-test_ipv4_host2="8.8.8.8"        # Google DNS
-test_ipv6_host1="heise.de"       # heise Zeitschriftenverlag
-
-if [ "$SERVER" = "no" ]; then
-       test -f /tmp/started || exit
-fi
-
-# Only do something with fastd when the router has internet connection
-if ping -w5 -c3 "$test_ipv4_host1" &>/dev/null ||
-   ping -w5 -c3 "$test_ipv4_host2" &>/dev/null ||
-   ping6 -w5 -c3 "$test_ipv6_host1" &>/dev/null; then
-       mac=$(awk '{ mac=toupper($1); gsub(":", "", mac); print mac }' /sys/class/net/br-mesh/address 2>/dev/null)
-       if [ "$SERVER" = "no" ]; then
-               hostname=$(cat /proc/sys/kernel/hostname)
-
-               if [ "$hostname" = "OpenWrt" ]; then
-                       hostname=""
-               fi
-
-               if [ "$hostname" = "" ]; then
-                       hostname=$mac
-               fi
-       else
-               hostname=$SERVERNAME
-       fi
-
-       if [ ! -d /etc/fastd ]; then
-               mkdir /etc/fastd
-       fi
-
-       if [ ! -d /etc/fastd/$project ]; then
-               mkdir /etc/fastd/$project
-
-               mkdir /tmp/fastd_${project}_peers
-               ln -s /tmp/fastd_${project}_peers /etc/fastd/$project/peers
-               echo "#!/bin/sh" > /etc/fastd/$project/up.sh
-               echo "ip link set up dev ${project}VPN" >> /etc/fastd/$project/up.sh
-               echo "echo enable > /sys/devices/virtual/net/${project}VPN/batman_adv/no_rebroadcast" >> /etc/fastd/$project/up.sh
-               echo "batctl if add ${project}VPN" >> /etc/fastd/$project/up.sh
-               chmod +x /etc/fastd/$project/up.sh
-
-               secret=$(fastd --generate-key 2>&1 | grep -i secret | awk '{ print $2 }')
-               echo "include peers from \"/etc/fastd/$project/peers\";" >> /etc/fastd/${project}/${project}.conf
-               echo "log to syslog level warn;" >> /etc/fastd/${project}/${project}.conf
-               echo "method \"null\";" >> /etc/fastd/${project}/${project}.conf
-#              http://lists.nord-west.net/pipermail/freifunk-ol-dev/2013-July/000322.html
-#              echo "bind 0.0.0.0:10000;" >> /etc/fastd/${project}/${project}.conf
-               echo "interface \"${project}VPN\";" >> /etc/fastd/${project}/${project}.conf
-               echo "mtu 1426;" >> /etc/fastd/${project}/${project}.conf
-               echo "secret \"$secret\";" >> /etc/fastd/${project}/${project}.conf
-               echo "on up \"/etc/fastd/${project}/up.sh\";" >> /etc/fastd/${project}/${project}.conf
-               echo "secure handshakes no;" >> /etc/fastd/${project}/${project}.conf
-       fi
-
-       if [ ! -d /tmp/fastd_${project}_peers ]; then
-               mkdir /tmp/fastd_${project}_peers
-       fi
-
-       pubkey=$(fastd -c /etc/fastd/$project/$project.conf --show-key --machine-readable)
-#      port=666
-       lat=$(uci get system.@system[0].latitude)
-       long=$(uci get system.@system[0].longitude)
-
-#      fire up
-       if [ "$(/sbin/ifconfig -a | grep -i ethernet | grep $project)" = "" ]; then
-               /bin/rm /var/run/fastd.$project.pid
-               fastd -c /etc/fastd/$project/$project.conf -d --pid-file /var/run/fastd.$project.pid
-       fi
-
-#      register
-       wget -T15 "http://keyserver.freifunk-franken.de/${project}/geo.php?mac=$mac&name=$hostname&port=$port&key=$pubkey&lat=$lat&long=$long" -O /tmp/fastd_${project}_output
-
-       filenames=$(awk '/^####/ { gsub(/^####/, "", $0); gsub(/.conf/, "", $0); print $0; }' /tmp/fastd_${project}_output)
-       for file in $filenames; do
-               awk "{ if(a) print }; /^####$file.conf$/{a=1}; /^$/{a=0};" /tmp/fastd_${project}_output | sed 's/ float;/;/g' > /etc/fastd/$project/peers/$file
-               echo 'float yes;' >> /etc/fastd/$project/peers/$file
-       done
-
-       #reload
-       kill -HUP $(cat /var/run/fastd.$project.pid)
-else
-       echo "Der Router kann keine Verbindung zum Fastdserver aufbauen"
-       echo "$0 macht nichts!"
-fi
-
-exit 0
-# vim: noexpandtab
+echo "nothing to do...."
--
2.1.4

Ich hab dies mal grundsätzlich in einem neuen Git getan: [[1]] Das ganze ist noch ungetestet!

Folgendes muss grundsätzlich danach noch getan werden damit er als Gateway verwendet werden kann:

Verbindung ins L3 Netz

Irgendeine Art von Verbindung in unser L3 Netz. Ich habe dazu fastd im tun Modus verwendet um ein Gateway über das Internet zu erreichen, natürlich sind auch Glasfaser, WLAN, Laser, Morsecode o.ä. Verbindungen denkbar.

Server:

bind any:1234; # UDP Port 1234 auf allen Interfaces
mode tun;
interface "fffolsrVPN";
method "null";
mtu 1426;
secret "SECRET KEY DES SERVERS";

#include peers from "peers";
include peer "/etc/fastd/fff.olsr/peers/router1";
on up "
  ip link set up $INTERFACE
  ip address add 10.50.252.****/32 dev $INTERFACE # eigene Tunnelip setzen
";
fff-gw-cd1 /etc/fastd/fff.olsr/peers # cat router1
key "PUBLIC KEY DES ROUTERS";

Client:

 
log to syslog level warn;
method "null";
mode tun;
interface "fffgwcd1VPN";
mtu 1426;
peer "fffgwcd1" {
  remote ipv4 "SERVERIP" port 1234;
  key "SERVER PUBLIC KEY";
}
secret "EIGENER SECRET KEY";
on up "
#/etc/fastd/fff/up.sh
";
secure handshakes no;

irgendwo muss hier noch eine IP gesetzt werden für den Tunnel, bin mir eben nicht sicher wie ich das getan habe:

ip link set up fffgwcd1VPN
ip address add 10.50.252.*** dev fffgwcd1VPN

Ebenfalls muss fastd noch in den Autostart, ich glaub ich hab dazu einen Cron gebastelt, damit falls der Link abbricht wieder neu aufgebaut wird. Muss u.U. noch schöner gemacht werden ;)

2 wertvolle Links die bei fastd extrem weiterhelfen: [2] [3]

Folgende Routingregeln müssen am Router angelegt werden

Auf dem Router muss ebenfalls die 10 fff angelegt werden:

vi /etc/iproute2/rt_tables

...
10     fff
...

Weiterhin müssen folgende Regeln angelegt werden (z.b. in der /etc/rc.local):

ip rule add from 10.0.0.0/8 table fff prio 20
ip rule add to 10.0.0.0/8 table fff prio 20
ip route add 10.50.XXX.XXX/XX dev br-mesh table fff # eigenes Subnetz das später per DHCP vergeben wird

Olsr konfigurieren

Olsr muss am Router konfiguriert werden, dazu wird im /etc/olsrd/olsrd.conf eine Konfigurationsdatei erwartet die Beispielhaft so aussehen kann. Zwingend angepasst werden muss das/die Interface(s) und die HNA.


#
# olsr.org OLSR daemon config file
#
# Lines starting with a # are discarded
#
# This file was shipped with the debian olsrd package
#

# Debug level(0-9)
# If set to 0 the daemon runs in the background

DebugLevel 0	

# the interface the mesh runs on is specified at run time using the -i flag

Interface "fffgwcd1VPN"
{
  # Olsrd can autodetect changes in NIC configurations (IP address
  # changes etc.).  This is enabled by default and the interval to
  # poll for changes on is defined by NicChgsPollInt.  This polling
  # can be disabled pr. NIC by setting AutoDetectChanges to no.

  #AutoDetectChanges            no

  # IPv4 broadcast address to use. The
  # one usefull example would be 255.255.255.255
  # If not defined the broadcastaddress
  # every card is configured with is used

  Ip4Broadcast		255.255.255.255

  # IPv6 address scope to use.
  # Must be 'site-local' or 'global'

  #Ip6AddrType		site-local

  # IPv6 multicast address to use when
  # using site-local addresses.
  # If not defined, ff05::15 is used

  #Ip6MulticastSite		ff05::11

  # IPv6 multicast address to use when
  # using global addresses
  # If not defined, ff0e::1 is used

  #Ip6MulticastGlobal	ff0e::1


  # Emission intervals.
  # If not defined, RFC proposed values will
  # be used in most cases.

  # Hello interval in seconds(float)
    HelloInterval		6.0

  # HELLO validity time
    HelloValidityTime		600.0

  # TC interval in seconds(float)
    TcInterval			0.5

  # TC validity time
    TcValidityTime		300.0

  # MID interval in seconds(float)
    MidInterval			10.0

  # MID validity time
    MidValidityTime		300.0

  # HNA interval in seconds(float)
    HnaInterval			10.0

  # HNA validity time
    HnaValidityTime		300.0

  # When multiple links exist between hosts
  # the weight of interface is used to determine
  # the link to use. Normally the weight is
  # automatically calculated by olsrd based
  # on the characteristics of the interface,
  # but here you can specify a fixed value.
  # Olsrd will choose links with the lowest value.

  #Weight 0


  # If a certain route should be preferred 
  # or ignored by the mesh, the Link Quality 
  # value of a node can be multiplied with a factor 
  # entered here. In the example the route 
  # using 192.168.0.1 would rather be ignored.
  # A multiplier of 0.5 will result in a small
  # (bad) LinkQuality value and a high (bad)
  # ETX value.

#NatThreshold  0.7

#LinkQualityMult 10.50.252.251 1.0 
#LinkQualityMult 10.50.252.10 0.7
#LinkQualityMult default 0.5

  #LinkQualityMult 192.168.0.1 0.5

  # This multiplier applies to all other nodes 
  # LinkQualityMult default 0.8
}

#NatThreshold  0.7

#LinkQualityMult 10.50.252.250 0.8
#LinkQualityMult default 0.3

## these settings should work for funkfeuer, freifunk, etc.
# Fisheye mechanism for TC messages 0=off, 1=on
LinkQualityFishEye 1
#LinkQualityAlgorithm "etx_ff"

## if using commotionwireless.net, comment the line above and uncomment these:
#LinkQualityFishEye 0
#LinkQualityAlgorithm "etx_ffeth"

# IP version to use (4 or 6)

IpVersion	4

# Clear the screen each time the internal state changes

ClearScreen     yes

# HNA IPv4 routes
# syntax: netaddr netmask
# Example Internet gateway:
# 0.0.0.0 0.0.0.0

Hna4
{
#   Internet gateway:
#   0.0.0.0      0.0.0.0
#   more entries can be added:
#   192.168.1.0  255.255.255.0
10.50.130.0/23
}

# HNA IPv6 routes
# syntax: netaddr prefix
# Example Internet gateway:
Hna6
{
#   Internet gateway:
#   ::              0
#   more entries can be added:
#   fec0:2200:106:: 48
}


# Should olsrd keep on running even if there are
# no interfaces available? This is a good idea
# for a PCMCIA/USB hotswap environment.
# "yes" OR "no"

AllowNoInt	yes

# TOS(type of service) value for
# the IP header of control traffic.
# If not set it will default to 16

#TosValue	16

# The fixed willingness to use(0-7)
# If not set willingness will be calculated
# dynamically based on battery/power status
# if such information is available

Willingness    	3

# Allow processes like the GUI front-end
# to connect to the daemon.

IpcConnect
{
     # Determines how many simultaneously
     # IPC connections that will be allowed
     # Setting this to 0 disables IPC

     MaxConnections  0

     # By default only 127.0.0.1 is allowed
     # to connect. Here allowed hosts can
     # be added

     Host            127.0.0.1
     #Host            10.0.0.5

     # You can also specify entire net-ranges 
     # that are allowed to connect. Multiple
     # entries are allowed

     #Net             192.168.1.0 255.255.255.0     
}

# Wether to use hysteresis or not
# Hysteresis adds more robustness to the
# link sensing but delays neighbor registration.
# Used by default. 'yes' or 'no'
# Do not use hysteresis with ETX!

UseHysteresis	no

# Hysteresis parameters
# Do not alter these unless you know 
# what you are doing!
# Set to auto by default. Allowed
# values are floating point values
# in the interval 0,1
# THR_LOW must always be lower than
# THR_HIGH.

#HystScaling	0.50
#HystThrHigh	0.80
#HystThrLow	0.30


# Link quality level
# 0 = do not use link quality
# 1 = use link quality for MPR selection
# 2 = use link quality for MPR selection and routing
# Defaults to 0

LinkQualityLevel	2

# Polling rate in seconds(float). 
# Default value 0.05 sec

Pollrate	0.1


# TC redundancy
# Specifies how much neighbor info should
# be sent in TC messages
# Possible values are:
# 0 - only send MPR selectors
# 1 - send MPR selectors and MPRs
# 2 - send all neighbors
#
# defaults to 0

TcRedundancy	2


#
# MPR coverage
# Specifies how many MPRs a node should
# try select to reach every 2 hop neighbor
#
# Can be set to any integer >0
#
# defaults to 1

MprCoverage	5


# Olsrd plugins to load
# This must be the absolute path to the file
# or the loader will use the following scheme:
# - Try the paths in the LD_LIBRARY_PATH 
#   environment variable.
# - The list of libraries cached in /etc/ld.so.cache
# - /lib, followed by /usr/lib

# Configuration examples for plugins:
# see /usr/share/doc/olsrd-plugins/ for some for documentation

# these are loaded from LD_LIBRARY_PATH


## for more info: http://olsr.org/?q=txtinfo_plugin
#LoadPlugin "olsrd_txtinfo.so.0.1"
#{
#  PlParam     "port"   "2006"
#  PlParam     "accept" "0.0.0.0"
#}


# useful if your machine has an uplink
#LoadPlugin "olsrd_dyn_gw.so.0.5"
#{
  # Here parameters are set to be sent to the
  # plugin. Theese are on the form "key" "value".
  # Parameters ofcause, differs from plugin to plugin.
  # Consult the documentation of your plugin for details.

  # Example: dyn_gw params

  # how often to check for Internet connectivity
  # defaults to 5 secs
 # PlParam     "Interval"   "5"
    
  # if one or more IPv4 addresses are given, do a ping on these in
  # descending order to validate that there is not only an entry in
  # routing table, but also a real internet connection. If any of
  # these addresses could be pinged successfully, the test was
  # succesful, i.e. if the ping on the 1st address was successful,the
  # 2nd won't be pinged
  #PlParam     "Ping"       "8.8.8.8"
 #PlParam     "Ping"       "82.165.230.17"
#PlParam     "pingcmd"    "ping -c 1 -q -I tun0 %s"
#}







# Specify the proto tag to be used for routes olsr inserts into kernel
# currently only implemented for linux
# valid values under linux are 1 .. 254
# 1 gets remapped by olsrd to 0 UNSPECIFIED (1 is reserved for ICMP redirects)
# 2 KERNEL routes (not very wise to use)
# 3 BOOT (should in fact not be used by routing daemons)
# 4 STATIC
# 8 .. 15 various routing daemons (gated, zebra, bird, & co)
# (defaults to 0 which gets replaced by an OS-specific default value
# under linux 3 (BOOT) (for backward compatibility)
#
RtProto 8
#
# Specifies the routing Table olsr uses
# RtTable is for host routes, RtTableDefault for the route to the default
# internet gateway (2 in case of IPv6+NIIT) and RtTableTunnel is for
# routes to the ipip tunnels, valid values are 1 to 254
# There is a special parameter "auto" (choose default below)
# (with smartgw: default is 254/223/224)
# (without smartgw: default is 254/254/254, linux main table)
#
RtTable 10
RtTableDefault 10
RtTableTunnel 10
#
# Specifies the policy rule priorities for the three routing tables and
# a special rule for smartgateway routing (see README-Olsr-Extensions)
# Priorities can only be set if three different routing tables are set.
# if set the values must obey to condition
# RtTablePriority < RtTableDefaultOlsrPriority
# < RtTableTunnelPriority < RtTableDefaultPriority.
# There are two special parameters, "auto" (choose fitting to SmartGW
# mode) and "none" (do not set policy rule)
# (with smartgw: default is none/32776/32776/32796)
# (without smartgw: default is none/none/none/none)
#
# RtTablePriority auto
# RtTableDefaultOlsrPriority auto
# RtTableTunnelPriority auto
# RtTableDefaultPriority auto

Olsr muss noch in den Autostart gekickt werden, ich hab dazu in die rc.local einfach olsrd eingetragen, dann startet Olsr bei Routerstart mit.

dnsmasq konfigurieren

ebenfalls muss noch dnsmasq konfiguriert werden:

/etc/dnsmasq.conf

dhcp-range=10.50.131.1,10.50.131.127,255.255.254.0,1h                            
dhcp-option=3,10.50.130.1
dhcp-option=option:dnsserver,10.50.252.250                                                             
log-queries  

natürlich die IP Adressen entsprechend anpassen der Syntax lautet:

dhcp-range=DHCP_RANGE_START,DHCP_RANGE_ENDE,SUBNETZMASK,LEASETIME
dhcp-option=3,STANDARTGATEWAYIP
dhcp-option=option:dnsserver,DNSSERVER
log-queries  

muss noch auf Vollständigkeit geprüft werden!

WLAN Parameter

Ebenfalls müssen die WLAN Parameter angepasst werden, wenn eine eigene Hood entsteht sollten mindestens folgende Parameter geändert werden:

Mesh:

  • BSSID
  • SSID

AP:

  • SSID

Die eigene Hood kann aber auch mit ganz anderen Parametern betrieben werden, so ist z.b. denkbar die Hood auf 802.11s umzustellen oder gar eine andere Batmanversion zu verwenden.