[pisa-src] r1723 - in trunk/pisacd: cdconf.c cdconf.h cdservers.c pisacd.conf

  • From: Thomas Jansen <mithi@xxxxxxxxx>
  • To: pisa-src@xxxxxxxxxxxxx
  • Date: Thu, 19 Nov 2009 15:58:19 +0100

Author: tjansen
Date: Thu Nov 19 15:58:18 2009
New Revision: 1723

Log:
Changed pisacd.conf file format.

Previously, each entry of the servers section had its own type (relay,
service, legacyrouter) which required complicated parsing and sanity
checking. The type is now removed from individual HITs and only set globally
for the client. Either we are a native client, running HIP and PISA on our
mobile device or we want to serve legacy devices when we are an access point.
This is reflected in "mode", that can either be "native" or "legacy".

The relay is configured in a special new block called "trustpoint" that
contains the hit. For simplicity in the code the format is the same as that of
a service. The services block will not be parsed though. The trustpoint is
only evaluated if we run in native mode.

Please refer to the sample pisacd.conf when you have to update your configs.

Modified:
   trunk/pisacd/cdconf.c
   trunk/pisacd/cdconf.h
   trunk/pisacd/cdservers.c
   trunk/pisacd/pisacd.conf

Modified: trunk/pisacd/cdconf.c
==============================================================================
--- trunk/pisacd/cdconf.c       Thu Nov 19 15:57:56 2009        (r1722)
+++ trunk/pisacd/cdconf.c       Thu Nov 19 15:58:18 2009        (r1723)
@@ -139,6 +139,30 @@
 }
 
 /**
+ * Read the delay before idle connections are deregistered from the
+ * configuration file.
+ */
+static void cdconf_read_mode(void)
+{
+       char tmp[64];
+
+       if (!pisa_cfg_get_string_value("mode", tmp, sizeof(tmp))) {
+               PISA_ERROR("Error: Reading mode failed.\n");
+       } else {
+               if (!strcmp(tmp, "native")) {
+                       cd_cfg.flag_native = true;
+                       return;
+               }
+               if (!strcmp(tmp, "legacy")) {
+                       cd_cfg.flag_native = false;
+                       return;
+               }
+               cd_cfg.flag_native = false;
+               PISA_ERROR("Found invalid mode \"%s\".", tmp);
+       }
+}
+
+/**
  * Reads the netmask for the local ip range from the pisacd.conf file
  */
 static void cdconf_read_local_ipv4(void)
@@ -204,4 +228,5 @@
        cdconf_read_idle_disconnect_delay();
        cdconf_read_local_ipv4();
        cdconf_read_local_netmask();
+       cdconf_read_mode();
 }

Modified: trunk/pisacd/cdconf.h
==============================================================================
--- trunk/pisacd/cdconf.h       Thu Nov 19 15:57:56 2009        (r1722)
+++ trunk/pisacd/cdconf.h       Thu Nov 19 15:58:18 2009        (r1723)
@@ -16,6 +16,8 @@
 #include "libpisa/global.h"
 #include "libpisa/debug.h"
 
+#include <stdbool.h>
+
 /**
  * data structure containing all configurations about the current client.
  */
@@ -28,6 +30,8 @@
        int idle_disconnect_delay; /**< number of seconds to wait before idle 
connections are deregistered */
        struct in_addr local_ipv4;
        struct in_addr local_netmask;
+
+       bool flag_native; /** native client (using relay & services directly) 
or legacy (no relay) */
 } cd_conf;
 
 extern cd_conf cd_cfg;

Modified: trunk/pisacd/cdservers.c
==============================================================================
--- trunk/pisacd/cdservers.c    Thu Nov 19 15:57:56 2009        (r1722)
+++ trunk/pisacd/cdservers.c    Thu Nov 19 15:58:18 2009        (r1723)
@@ -10,6 +10,7 @@
  * @date Jun. 2009
  */
 
+#include "cdconf.h"
 #include "cdctx.h"
 #include "cdregister.h"
 #include "cdservers.h"
@@ -27,30 +28,7 @@
 pisa_conmgr_entry *pisa_server_add(struct in6_addr *hit, int port, 
pisa_contype type)
 {
        pisa_conmgr_entry *entry = NULL;
-       static int relay = 0;
-       static int legacy = 0;
-       /* 1 if we had legacy router connections before, 0 if no connections
-        * were processed before and -1 if we had non-legacy connections
-        * before */
-
-       /* Do not use more than one relay connection */
-       if (type == PISA_CONTYPE_RELAY) {
-               if (relay != 0) {
-                       PISA_ERROR("Found more than one relay connection.\n");
-                       return NULL;
-               }
-               relay = 1;
-       }
-
-       /* Do not mix legacy router connections with other connection types */
-       if ((legacy ==  1 && type != PISA_CONTYPE_LEGACY_ROUTER) ||
-           (legacy == -1 && type == PISA_CONTYPE_LEGACY_ROUTER)) {
-               PISA_ERROR("Mixing legacy router connections with other 
connections is forbidden.\n");
-               return NULL;
-       }
-       legacy = type == PISA_CONTYPE_LEGACY_ROUTER ? 1 : -1;
 
-       /* Accept the server into the internal list */
        entry = pisa_conmgr_add(cd_ctx.conlist, hit, port);
        entry->type = type;
        if (type == PISA_CONTYPE_RELAY)
@@ -62,12 +40,12 @@
 /**
  * Parse a server block and add it.
  * @param server configuration block containing the server parameters
+ * @param contype connection type
  */
-static void pisa_servers_add_block(config_setting_t *server)
+static void pisa_servers_add_block(config_setting_t *server, pisa_contype 
contype)
 {
-       const char *hit = NULL, *type = NULL;
+       const char *hit = NULL;
        long port = PISACD_DEFAULT_PORTNUM_CONTROL;
-       pisa_contype contype;
        struct in6_addr hitaddr;
        pisa_conmgr_entry *entry;
 
@@ -83,26 +61,7 @@
                return;
        }
 
-       PISA_DEBUG(PL_CONFIG, "Server HIT: %s port: %i ", hit, port);
-
-       if (config_setting_lookup_string(server, "type", &type) == CONFIG_TRUE) 
{
-               if (!strcmp("relay", type)) {
-                       contype = PISA_CONTYPE_RELAY;
-                       PISA_DEBUG(PL_CONFIG, "relay\n");
-               } else if (!strcmp("service", type)) {
-                       contype = PISA_CONTYPE_SERVICE;
-                       PISA_DEBUG(PL_CONFIG, "service\n");
-               } else if (!strcmp("legacyrouter", type)) {
-                       contype = PISA_CONTYPE_LEGACY_ROUTER;
-                       PISA_DEBUG(PL_CONFIG, "legacy router\n");
-               } else {
-                       PISA_DEBUG(PL_CONFIG, "wrong type, skipping\n");
-                       return;
-               }
-       } else {
-               PISA_DEBUG(PL_CONFIG, "default (service)\n");
-               contype = PISA_CONTYPE_SERVICE;
-       }
+       PISA_DEBUG(PL_CONFIG, "Server HIT: %s port: %i\n", hit, port);
 
        if ((entry = pisa_server_add(&hitaddr, port, contype)) != NULL)
                pisa_servers_add_services(entry);
@@ -116,14 +75,28 @@
 {
        config_setting_t *servers = pisa_cfg_get_setting("servers");
        int i, max;
+       pisa_contype type;
 
        if (!servers)
                return;
 
+       type = cd_cfg.flag_native ? PISA_CONTYPE_SERVICE : 
PISA_CONTYPE_LEGACY_ROUTER;
+
        max = config_setting_length(servers);
        PISA_DEBUG(PL_CONFIG, "\nParsing %i server block(s):\n", max);
        for (i = 0; i < max; i++)
-               pisa_servers_add_block(config_setting_get_elem(servers, i));
+               pisa_servers_add_block(config_setting_get_elem(servers, i), 
type);
+
+       if (!cd_cfg.flag_native)
+               return;
+
+       servers = pisa_cfg_get_setting("trustpoint");
+       if (servers) {
+               PISA_DEBUG(PL_CONFIG, "Trustpoint:\n");
+               pisa_servers_add_block(servers, PISA_CONTYPE_RELAY);
+       } else {
+               PISA_DEBUG(PL_CONFIG, "No trustpoint defined for this native 
client.\n");
+       }
 }
 
 /**

Modified: trunk/pisacd/pisacd.conf
==============================================================================
--- trunk/pisacd/pisacd.conf    Thu Nov 19 15:57:56 2009        (r1722)
+++ trunk/pisacd/pisacd.conf    Thu Nov 19 15:58:18 2009        (r1723)
@@ -16,18 +16,22 @@
 local_ipv4 = "192.168.44.1";
 local_netmask = "255.255.255.0";
 
+# Mode of operation:
+#  - native: We're a native client, a mobile guest running HIP/PISA itself
+#  - legacy: We're a legacy router, an access point running HIP/PISA
+mode = "native";
+
+# Trust point HIT, only used if we are in "native" mode.
+trustpoint = {
+       hit = "2001:1a:b1b0:aad:f92:15ca:280c:1234";
+};
+
 # A list of all servers we want to connect to.
 servers = (
        {
                # HIT is mandatory.
                hit = "2001:1a:b1b0:aad:f92:15ca:280c:9430";
 
-               # Connection type: "relay", "service" or "legacyrouter".
-               # Only one relay connection is allowed.
-               # Legacy router connections may not be mixed with other types.
-               # Type is optional and defaults to service if omitted.
-               type = "relay";
-
                # List of NAT mappings for this server. May be omitted, but
                # this does not make sense for service connections. Each
                # mapping has two IPv4 addresses, a local one from the

Other related posts:

  • » [pisa-src] r1723 - in trunk/pisacd: cdconf.c cdconf.h cdservers.c pisacd.conf - Thomas Jansen