ipsec-types: Add helper to parse interface ID
This commit is contained in:
@@ -147,3 +147,44 @@ bool mark_from_string(const char *value, mark_op_t ops, mark_t *mark)
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
* See header
|
||||
*/
|
||||
bool if_id_from_string(const char *value, uint32_t *if_id)
|
||||
{
|
||||
char *endptr;
|
||||
|
||||
if (!value)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
if (strcasepfx(value, "%unique"))
|
||||
{
|
||||
endptr = (char*)value + strlen("%unique");
|
||||
if (strcasepfx(endptr, "-dir"))
|
||||
{
|
||||
*if_id = IF_ID_UNIQUE_DIR;
|
||||
endptr += strlen("-dir");
|
||||
}
|
||||
else if (!*endptr)
|
||||
{
|
||||
*if_id = IF_ID_UNIQUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
DBG1(DBG_APP, "invalid interface ID: %s", value);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
*if_id = strtoul(value, &endptr, 0);
|
||||
}
|
||||
if (*endptr)
|
||||
{
|
||||
DBG1(DBG_APP, "invalid interface ID: %s", value);
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -240,4 +240,20 @@ enum mark_op_t {
|
||||
*/
|
||||
bool mark_from_string(const char *value, mark_op_t ops, mark_t *mark);
|
||||
|
||||
/**
|
||||
* Special interface ID values to allocate a unique ID for each CHILD_SA/dir
|
||||
*/
|
||||
#define IF_ID_UNIQUE (0xFFFFFFFF)
|
||||
#define IF_ID_UNIQUE_DIR (0xFFFFFFFE)
|
||||
#define IF_ID_IS_UNIQUE(m) ((m) == IF_ID_UNIQUE || (m) == IF_ID_UNIQUE_DIR)
|
||||
|
||||
/**
|
||||
* Try to parse an interface ID from the given string.
|
||||
*
|
||||
* @param value string to parse
|
||||
* @param if_id interface ID to fill
|
||||
* @return TRUE if parsing was successful
|
||||
*/
|
||||
bool if_id_from_string(const char *value, uint32_t *if_id);
|
||||
|
||||
#endif /** IPSEC_TYPES_H_ @}*/
|
||||
|
||||
Reference in New Issue
Block a user