starter: Use custom type to mark seen keywords.
authorTobias Brunner <tobias@strongswan.org>
Tue, 15 May 2012 08:41:08 +0000 (10:41 +0200)
committerTobias Brunner <tobias@strongswan.org>
Mon, 11 Jun 2012 15:33:30 +0000 (17:33 +0200)
src/starter/args.c
src/starter/confread.c
src/starter/confread.h

index 3531bf7..3856c3d 100644 (file)
@@ -360,21 +360,20 @@ bool assign_arg(kw_token_t token, kw_token_t first, kw_list_t *kw, char *base,
 
        int index = -1;  /* used for enumeration arguments */
 
-       lset_t *seen = (lset_t *)base;    /* seen flags are at the top of the struct */
-       lset_t f = LELEM(token - first);  /* compute flag position of argument */
+       seen_t *seen = (seen_t*)base; /* seen flags are at the top of the struct */
 
        *assigned = FALSE;
 
        DBG3(DBG_APP, "  %s=%s", kw->entry->name, kw->value);
 
-       if (*seen & f)
+       if (*seen & SEEN_KW(token, first))
        {
                DBG1(DBG_APP, "# duplicate '%s' option", kw->entry->name);
                return FALSE;
        }
 
        /* set flag that this argument has been seen */
-       *seen |= f;
+       *seen |= SEEN_KW(token, first);
 
        /* is there a keyword list? */
        if (list != NULL && token_info[token].type != ARG_LST)
index cc94b85..9814482 100644 (file)
@@ -57,7 +57,7 @@ static void default_values(starter_config_t *cfg)
 
        memset(cfg, 0, sizeof(struct starter_config));
 
-    /* is there enough space for all seen flags? */
+       /* is there enough space for all seen flags? */
        assert(KW_SETUP_LAST - KW_SETUP_FIRST <
                sizeof(cfg->setup.seen) * BITS_PER_BYTE);
        assert(KW_CONN_LAST  - KW_CONN_FIRST <
@@ -67,7 +67,7 @@ static void default_values(starter_config_t *cfg)
        assert(KW_CA_LAST - KW_CA_FIRST <
                sizeof(cfg->ca_default.seen) * BITS_PER_BYTE);
 
-       cfg->setup.seen        = LEMPTY;
+       cfg->setup.seen        = SEEN_NONE;
        cfg->setup.fragicmp    = TRUE;
        cfg->setup.hidetos     = TRUE;
        cfg->setup.uniqueids   = TRUE;
@@ -80,7 +80,7 @@ static void default_values(starter_config_t *cfg)
        cfg->setup.plutostart  = TRUE;
 #endif
 
-       cfg->conn_default.seen    = LEMPTY;
+       cfg->conn_default.seen    = SEEN_NONE;
        cfg->conn_default.startup = STARTUP_NO;
        cfg->conn_default.state   = STATE_IGNORE;
        cfg->conn_default.policy  = POLICY_ENCRYPT | POLICY_TUNNEL | POLICY_PUBKEY |
@@ -95,12 +95,12 @@ static void default_values(starter_config_t *cfg)
        cfg->conn_default.sa_keying_tries       = SA_REPLACEMENT_RETRIES_DEFAULT;
        cfg->conn_default.addr_family           = AF_INET;
        cfg->conn_default.tunnel_addr_family    = AF_INET;
-       cfg->conn_default.install_policy        = TRUE;
-       cfg->conn_default.dpd_delay                     =  30; /* seconds */
-       cfg->conn_default.dpd_timeout           = 150; /* seconds */
+       cfg->conn_default.install_policy        = TRUE;
+       cfg->conn_default.dpd_delay             =  30; /* seconds */
+       cfg->conn_default.dpd_timeout           = 150; /* seconds */
 
-       cfg->conn_default.left.seen  = LEMPTY;
-       cfg->conn_default.right.seen = LEMPTY;
+       cfg->conn_default.left.seen  = SEEN_NONE;
+       cfg->conn_default.right.seen = SEEN_NONE;
 
        cfg->conn_default.left.sendcert  = CERT_SEND_IF_ASKED;
        cfg->conn_default.right.sendcert = CERT_SEND_IF_ASKED;
@@ -110,7 +110,7 @@ static void default_values(starter_config_t *cfg)
        cfg->conn_default.left.ikeport = 500;
        cfg->conn_default.right.ikeport = 500;
 
-       cfg->ca_default.seen = LEMPTY;
+       cfg->ca_default.seen = SEEN_NONE;
 }
 
 #define KW_POLICY_FLAG(sy, sn, fl) \
@@ -412,7 +412,7 @@ static void handle_dns_failure(const char *label, starter_end_t *end,
 static void handle_firewall(const char *label, starter_end_t *end,
                                                        starter_config_t *cfg)
 {
-       if (end->firewall && (end->seen & LELEM(KW_FIREWALL - KW_END_FIRST)))
+       if (end->firewall && (end->seen & SEEN_KW(KW_FIREWALL, KW_END_FIRST)))
        {
                if (end->updown != NULL)
                {
@@ -955,7 +955,7 @@ starter_config_t* confread_load(const char *file)
        }
 
        /* parameters defined in ca %default sections can be overloads */
-       cfg->ca_default.seen = LEMPTY;
+       cfg->ca_default.seen = SEEN_NONE;
 
        /* load other ca sections */
        for (sca = cfgp->ca_first; sca; sca = sca->next)
@@ -1019,10 +1019,10 @@ starter_config_t* confread_load(const char *file)
                }
        }
 
-       /* parameter defined in conn %default sections can be overloaded */
-       cfg->conn_default.seen       = LEMPTY;
-       cfg->conn_default.right.seen = LEMPTY;
-       cfg->conn_default.left.seen  = LEMPTY;
+       /* parameters defined in conn %default sections can be overloaded */
+       cfg->conn_default.seen       = SEEN_NONE;
+       cfg->conn_default.right.seen = SEEN_NONE;
+       cfg->conn_default.left.seen  = SEEN_NONE;
 
        /* load other conn sections */
        for (sconn = cfgp->conn_first; sconn; sconn = sconn->next)
index 42f9983..fecce3f 100644 (file)
 
 #include "ipsec-parser.h"
 
+/** to mark seen keywords */
+typedef u_int64_t seen_t;
+#define SEEN_NONE 0;
+#define SEEN_KW(kw, base) ((seen_t)1 << ((kw) - (base)))
+
 typedef enum {
                STARTUP_NO,
                STARTUP_ADD,
@@ -52,7 +57,7 @@ typedef enum {
 typedef struct starter_end starter_end_t;
 
 struct starter_end {
-               lset_t          seen;
+               seen_t          seen;
                char            *auth;
                char            *auth2;
                char            *id;
@@ -98,7 +103,7 @@ struct also {
 typedef struct starter_conn starter_conn_t;
 
 struct starter_conn {
-               lset_t          seen;
+               seen_t          seen;
                char            *name;
                also_t          *also;
                kw_list_t       *kw;
@@ -156,7 +161,7 @@ struct starter_conn {
 typedef struct starter_ca starter_ca_t;
 
 struct starter_ca {
-               lset_t          seen;
+               seen_t          seen;
                char            *name;
                also_t          *also;
                kw_list_t       *kw;
@@ -182,7 +187,7 @@ typedef struct starter_config starter_config_t;
 
 struct starter_config {
                struct {
-                               lset_t  seen;
+                               seen_t  seen;
                                char    **interfaces;
                                char    *dumpdir;
                                bool    charonstart;