Added a ipsec.conf "inactivity" option to configure inactivity timeout for CHILD_SAs
[strongswan.git] / src / starter / args.c
index f9d1824..ebbd42c 100644 (file)
@@ -36,6 +36,7 @@ typedef enum {
        ARG_UINT,
        ARG_TIME,
        ARG_ULNG,
        ARG_UINT,
        ARG_TIME,
        ARG_ULNG,
+       ARG_ULLI,
        ARG_PCNT,
        ARG_STR,
        ARG_LST,
        ARG_PCNT,
        ARG_STR,
        ARG_LST,
@@ -111,6 +112,11 @@ static const char *LST_pfsgroup[] = {
        "modp4096",
        "modp6144",
        "modp8192",
        "modp4096",
        "modp6144",
        "modp8192",
+       "ecp192",
+       "ecp224",
+       "ecp256",
+       "ecp384",
+       "ecp521",
         NULL
 };
 
         NULL
 };
 
@@ -207,6 +213,10 @@ static const token_info_t token_info[] =
        { ARG_TIME, offsetof(starter_conn_t, sa_ike_life_seconds), NULL                },
        { ARG_TIME, offsetof(starter_conn_t, sa_ipsec_life_seconds), NULL              },
        { ARG_TIME, offsetof(starter_conn_t, sa_rekey_margin), NULL                    },
        { ARG_TIME, offsetof(starter_conn_t, sa_ike_life_seconds), NULL                },
        { ARG_TIME, offsetof(starter_conn_t, sa_ipsec_life_seconds), NULL              },
        { ARG_TIME, offsetof(starter_conn_t, sa_rekey_margin), NULL                    },
+       { ARG_ULLI, offsetof(starter_conn_t, sa_ipsec_life_bytes), NULL                },
+       { ARG_ULLI, offsetof(starter_conn_t, sa_ipsec_margin_bytes), NULL              },
+       { ARG_ULLI, offsetof(starter_conn_t, sa_ipsec_life_packets), NULL              },
+       { ARG_ULLI, offsetof(starter_conn_t, sa_ipsec_margin_packets), NULL            },
        { ARG_MISC, 0, NULL  /* KW_KEYINGTRIES */                                      },
        { ARG_PCNT, offsetof(starter_conn_t, sa_rekey_fuzz), NULL                      },
        { ARG_MISC, 0, NULL  /* KW_REKEY */                                            },
        { ARG_MISC, 0, NULL  /* KW_KEYINGTRIES */                                      },
        { ARG_PCNT, offsetof(starter_conn_t, sa_rekey_fuzz), NULL                      },
        { ARG_MISC, 0, NULL  /* KW_REKEY */                                            },
@@ -217,6 +227,7 @@ static const token_info_t token_info[] =
        { ARG_TIME, offsetof(starter_conn_t, dpd_delay), NULL                          },
        { ARG_TIME, offsetof(starter_conn_t, dpd_timeout), NULL                        },
        { ARG_ENUM, offsetof(starter_conn_t, dpd_action), LST_dpd_action               },
        { ARG_TIME, offsetof(starter_conn_t, dpd_delay), NULL                          },
        { ARG_TIME, offsetof(starter_conn_t, dpd_timeout), NULL                        },
        { ARG_ENUM, offsetof(starter_conn_t, dpd_action), LST_dpd_action               },
+       { ARG_TIME, offsetof(starter_conn_t, inactivity), NULL                         },
        { ARG_MISC, 0, NULL  /* KW_MODECONFIG */                                       },
        { ARG_MISC, 0, NULL  /* KW_XAUTH */                                            },
        { ARG_ENUM, offsetof(starter_conn_t, me_mediation), LST_bool                   },
        { ARG_MISC, 0, NULL  /* KW_MODECONFIG */                                       },
        { ARG_MISC, 0, NULL  /* KW_XAUTH */                                            },
        { ARG_ENUM, offsetof(starter_conn_t, me_mediation), LST_bool                   },
@@ -241,7 +252,7 @@ static const token_info_t token_info[] =
        { ARG_STR, offsetof(starter_end_t, subnet), NULL                               },
        { ARG_MISC, 0, NULL  /* KW_SUBNETWITHIN */                                     },
        { ARG_MISC, 0, NULL  /* KW_PROTOPORT */                                        },
        { ARG_STR, offsetof(starter_end_t, subnet), NULL                               },
        { ARG_MISC, 0, NULL  /* KW_SUBNETWITHIN */                                     },
        { ARG_MISC, 0, NULL  /* KW_PROTOPORT */                                        },
-       { ARG_STR, offsetof(starter_end_t, srcip), NULL                                },
+       { ARG_MISC, 0, NULL  /* KW_SOURCEIP */                                             },
        { ARG_MISC, 0, NULL  /* KW_NATIP */                                            },
        { ARG_ENUM, offsetof(starter_end_t, firewall), LST_bool                        },
        { ARG_ENUM, offsetof(starter_end_t, hostaccess), LST_bool                      },
        { ARG_MISC, 0, NULL  /* KW_NATIP */                                            },
        { ARG_ENUM, offsetof(starter_end_t, firewall), LST_bool                        },
        { ARG_ENUM, offsetof(starter_end_t, hostaccess), LST_bool                      },
@@ -261,8 +272,7 @@ static const token_info_t token_info[] =
        { ARG_STR,  offsetof(starter_end_t, iface), NULL                               }
 };
 
        { ARG_STR,  offsetof(starter_end_t, iface), NULL                               }
 };
 
-static void
-free_list(char **list)
+static void free_list(char **list)
 {
        char **s;
 
 {
        char **s;
 
@@ -273,22 +283,25 @@ free_list(char **list)
        free(list);
 }
 
        free(list);
 }
 
-char **
-new_list(char *value)
+char** new_list(char *value)
 {
        char *val, *b, *e, *end, **ret;
        int count;
 
        val = value ? clone_str(value) : NULL;
        if (!val)
 {
        char *val, *b, *e, *end, **ret;
        int count;
 
        val = value ? clone_str(value) : NULL;
        if (!val)
+       {
                return NULL;
                return NULL;
+       }
        end = val + strlen(val);
        for (b = val, count = 0; b < end;)
        {
                for (e = b; ((*e != ' ') && (*e != '\0')); e++);
                *e = '\0';
                if (e != b)
        end = val + strlen(val);
        for (b = val, count = 0; b < end;)
        {
                for (e = b; ((*e != ' ') && (*e != '\0')); e++);
                *e = '\0';
                if (e != b)
+               {
                        count++;
                        count++;
+               }
                b = e + 1;
        }
        if (count == 0)
                b = e + 1;
        }
        if (count == 0)
@@ -302,7 +315,9 @@ new_list(char *value)
        {
                for (e = b; (*e != '\0'); e++);
                if (e != b)
        {
                for (e = b; (*e != '\0'); e++);
                if (e != b)
+               {
                        ret[count++] = clone_str(b);
                        ret[count++] = clone_str(b);
+               }
                b = e + 1;
        }
        ret[count] = NULL;
                b = e + 1;
        }
        ret[count] = NULL;
@@ -314,9 +329,8 @@ new_list(char *value)
 /*
  * assigns an argument value to a struct field
  */
 /*
  * assigns an argument value to a struct field
  */
-bool
-assign_arg(kw_token_t token, kw_token_t first, kw_list_t *kw, char *base
-       , bool *assigned)
+bool assign_arg(kw_token_t token, kw_token_t first, kw_list_t *kw, char *base,
+                               bool *assigned)
 {
        char *p = base + token_info[token].offset;
        const char **list = token_info[token].list;
 {
        char *p = base + token_info[token].offset;
        const char **list = token_info[token].list;
@@ -388,7 +402,7 @@ assign_arg(kw_token_t token, kw_token_t first, kw_list_t *kw, char *base
        case ARG_UINT:
                {
                        char *endptr;
        case ARG_UINT:
                {
                        char *endptr;
-                       u_int *u = (u_int *)p; 
+                       u_int *u = (u_int *)p;
 
                        *u = strtoul(kw->value, &endptr, 10);
 
 
                        *u = strtoul(kw->value, &endptr, 10);
 
@@ -426,6 +440,20 @@ assign_arg(kw_token_t token, kw_token_t first, kw_list_t *kw, char *base
 
                }
                break;
 
                }
                break;
+       case ARG_ULLI:
+               {
+                       char *endptr;
+                       unsigned long long *ll = (unsigned long long *)p;
+
+                       *ll = strtoull(kw->value, &endptr, 10);
+
+                       if (*endptr != '\0')
+                       {
+                               plog("# bad integer value: %s=%s", kw->entry->name, kw->value);
+                               return FALSE;
+                       }
+               }
+               break;
        case ARG_TIME:
                {
                        char *endptr;
        case ARG_TIME:
                {
                        char *endptr;
@@ -435,8 +463,9 @@ assign_arg(kw_token_t token, kw_token_t first, kw_list_t *kw, char *base
 
                        /* time in seconds? */
                        if (*endptr == '\0' || (*endptr == 's' && endptr[1] == '\0'))
 
                        /* time in seconds? */
                        if (*endptr == '\0' || (*endptr == 's' && endptr[1] == '\0'))
+                       {
                                break;
                                break;
-
+                       }
                        if (endptr[1] == '\0')
                        {
                                if (*endptr == 'm')  /* time in minutes? */
                        if (endptr[1] == '\0')
                        {
                                if (*endptr == 'm')  /* time in minutes? */
@@ -475,8 +504,9 @@ assign_arg(kw_token_t token, kw_token_t first, kw_list_t *kw, char *base
 
                        /* free any existing list */
                        if (*listp != NULL)
 
                        /* free any existing list */
                        if (*listp != NULL)
+                       {
                                free_list(*listp);
                                free_list(*listp);
-
+                       }
                        /* create a new list and assign values */
                        *listp = new_list(kw->value);
 
                        /* create a new list and assign values */
                        *listp = new_list(kw->value);
 
@@ -485,12 +515,12 @@ assign_arg(kw_token_t token, kw_token_t first, kw_list_t *kw, char *base
                        {
                                char ** lst;
 
                        {
                                char ** lst;
 
-                               for (lst = *listp; lst && *lst; lst++) 
+                               for (lst = *listp; lst && *lst; lst++)
                                {
                                        bool match = FALSE;
 
                                        list = token_info[token].list;
                                {
                                        bool match = FALSE;
 
                                        list = token_info[token].list;
-                               
+
                                        while (*list != NULL && !match)
                                        {
                                                match = streq(*lst, *list++);
                                        while (*list != NULL && !match)
                                        {
                                                match = streq(*lst, *list++);
@@ -514,8 +544,7 @@ assign_arg(kw_token_t token, kw_token_t first, kw_list_t *kw, char *base
 /*
  *  frees all dynamically allocated arguments in a struct
  */
 /*
  *  frees all dynamically allocated arguments in a struct
  */
-void
-free_args(kw_token_t first, kw_token_t last, char *base)
+void free_args(kw_token_t first, kw_token_t last, char *base)
 {
        kw_token_t token;
 
 {
        kw_token_t token;
 
@@ -553,8 +582,7 @@ free_args(kw_token_t first, kw_token_t last, char *base)
 /*
  *  clone all dynamically allocated arguments in a struct
  */
 /*
  *  clone all dynamically allocated arguments in a struct
  */
-void
-clone_args(kw_token_t first, kw_token_t last, char *base1, char *base2)
+void clone_args(kw_token_t first, kw_token_t last, char *base1, char *base2)
 {
        kw_token_t token;
 
 {
        kw_token_t token;
 
@@ -570,22 +598,29 @@ clone_args(kw_token_t first, kw_token_t last, char *base1, char *base2)
        }
 }
 
        }
 }
 
-static bool
-cmp_list(char **list1, char **list2)
+static bool cmp_list(char **list1, char **list2)
 {
        if ((list1 == NULL) && (list2 == NULL))
 {
        if ((list1 == NULL) && (list2 == NULL))
+       {
                return TRUE;
                return TRUE;
+       }
        if ((list1 == NULL) || (list2 == NULL))
        if ((list1 == NULL) || (list2 == NULL))
+       {
                return FALSE;
                return FALSE;
+       }
 
        for ( ; *list1 && *list2; list1++, list2++)
        {
                if (strcmp(*list1,*list2) != 0)
 
        for ( ; *list1 && *list2; list1++, list2++)
        {
                if (strcmp(*list1,*list2) != 0)
+               {
                        return FALSE;
                        return FALSE;
+               }
        }
 
        if ((*list1 != NULL) || (*list2 != NULL))
        }
 
        if ((*list1 != NULL) || (*list2 != NULL))
+       {
                return FALSE;
                return FALSE;
+       }
 
        return TRUE;
 }
 
        return TRUE;
 }
@@ -593,8 +628,7 @@ cmp_list(char **list1, char **list2)
 /*
  *  compare all arguments in a struct
  */
 /*
  *  compare all arguments in a struct
  */
-bool
-cmp_args(kw_token_t first, kw_token_t last, char *base1, char *base2)
+bool cmp_args(kw_token_t first, kw_token_t last, char *base1, char *base2)
 {
        kw_token_t token;
 
 {
        kw_token_t token;
 
@@ -606,12 +640,25 @@ cmp_args(kw_token_t first, kw_token_t last, char *base1, char *base2)
                switch (token_info[token].type)
                {
                case ARG_ENUM:
                switch (token_info[token].type)
                {
                case ARG_ENUM:
+                       if (token_info[token].list == LST_bool)
+                       {
+                               bool *b1 = (bool *)p1;
+                               bool *b2 = (bool *)p2;
+
+                               if (*b1 != *b2)
+                               {
+                                       return FALSE;
+                               }
+                       }
+                       else
                        {
                                int *i1 = (int *)p1;
                                int *i2 = (int *)p2;
 
                                if (*i1 != *i2)
                        {
                                int *i1 = (int *)p1;
                                int *i2 = (int *)p2;
 
                                if (*i1 != *i2)
+                               {
                                        return FALSE;
                                        return FALSE;
+                               }
                        }
                        break;
                case ARG_UINT:
                        }
                        break;
                case ARG_UINT:
@@ -620,7 +667,9 @@ cmp_args(kw_token_t first, kw_token_t last, char *base1, char *base2)
                                u_int *u2 = (u_int *)p2;
 
                                if (*u1 != *u2)
                                u_int *u2 = (u_int *)p2;
 
                                if (*u1 != *u2)
+                               {
                                        return FALSE;
                                        return FALSE;
+                               }
                        }
                        break;
                case ARG_ULNG:
                        }
                        break;
                case ARG_ULNG:
@@ -630,7 +679,20 @@ cmp_args(kw_token_t first, kw_token_t last, char *base1, char *base2)
                                unsigned long *l2 = (unsigned long *)p2;
 
                                if (*l1 != *l2)
                                unsigned long *l2 = (unsigned long *)p2;
 
                                if (*l1 != *l2)
+                               {
+                                       return FALSE;
+                               }
+                       }
+                       break;
+               case ARG_ULLI:
+                       {
+                               unsigned long long *ll1 = (unsigned long long *)p1;
+                               unsigned long long *ll2 = (unsigned long long *)p2;
+
+                               if (*ll1 != *ll2)
+                               {
                                        return FALSE;
                                        return FALSE;
+                               }
                        }
                        break;
                case ARG_TIME:
                        }
                        break;
                case ARG_TIME:
@@ -639,7 +701,9 @@ cmp_args(kw_token_t first, kw_token_t last, char *base1, char *base2)
                                time_t *t2 = (time_t *)p2;
 
                                if (*t1 != *t2)
                                time_t *t2 = (time_t *)p2;
 
                                if (*t1 != *t2)
+                               {
                                        return FALSE;
                                        return FALSE;
+                               }
                        }
                        break;
                case ARG_STR:
                        }
                        break;
                case ARG_STR:
@@ -648,9 +712,13 @@ cmp_args(kw_token_t first, kw_token_t last, char *base1, char *base2)
                                char **cp2 = (char **)p2;
 
                                if (*cp1 == NULL && *cp2 == NULL)
                                char **cp2 = (char **)p2;
 
                                if (*cp1 == NULL && *cp2 == NULL)
+                               {
                                        break;
                                        break;
+                               }
                                if (*cp1 == NULL || *cp2 == NULL || strcmp(*cp1, *cp2) != 0)
                                if (*cp1 == NULL || *cp2 == NULL || strcmp(*cp1, *cp2) != 0)
+                               {
                                        return FALSE;
                                        return FALSE;
+                               }
                        }
                        break;
                case ARG_LST:
                        }
                        break;
                case ARG_LST:
@@ -659,7 +727,9 @@ cmp_args(kw_token_t first, kw_token_t last, char *base1, char *base2)
                                char ***listp2 = (char ***)p2;
 
                                if (!cmp_list(*listp1, *listp2))
                                char ***listp2 = (char ***)p2;
 
                                if (!cmp_list(*listp1, *listp2))
+                               {
                                        return FALSE;
                                        return FALSE;
+                               }
                        }
                        break;
                default:
                        }
                        break;
                default: