- new configuration support added to ike_sa and states

This commit is contained in:
Jan Hutter
2005-12-01 17:16:10 +00:00
parent bae00c63f7
commit a9428251cd
16 changed files with 772 additions and 597 deletions
+55 -19
View File
@@ -69,6 +69,34 @@ static socklen_t *get_sockaddr_len(private_host_t *this)
return &(this->socklen);
}
/**
* Implementation of host_t.is_default_route.
*/
static bool is_default_route (private_host_t *this)
{
switch (this->family)
{
case AF_INET:
{
int i;
for (i = 0; i < 4;i++)
{
struct sockaddr_in *sin = (struct sockaddr_in*)&(this->address);
if (*((&sin->sin_addr.s_addr) + i) != 0)
{
return FALSE;
}
}
return TRUE;
}
default:
{
/* empty chunk is returned */
return FALSE;
}
}
}
/**
* implements host_t.get_address
*/
@@ -156,7 +184,7 @@ static private_host_t *clone(private_host_t *this)
/**
* Impelements host_t.equals
*/
static bool equals(private_host_t *this, private_host_t *other)
static bool ip_is_equal(private_host_t *this, private_host_t *other)
{
switch (this->family)
{
@@ -166,7 +194,6 @@ static bool equals(private_host_t *this, private_host_t *other)
struct sockaddr_in *sin1 = (struct sockaddr_in*)&(this->address);
struct sockaddr_in *sin2 = (struct sockaddr_in*)&(other->address);
if ((sin1->sin_family == sin2->sin_family) &&
(sin1->sin_port == sin2->sin_port) &&
(sin1->sin_addr.s_addr == sin2->sin_addr.s_addr))
{
return TRUE;
@@ -177,10 +204,10 @@ static bool equals(private_host_t *this, private_host_t *other)
}
/*
* Described in header.
/**
* Creates an empty host_t object
*/
host_t *host_create(int family, char *address, u_int16_t port)
static private_host_t *host_create_empty()
{
private_host_t *this = allocator_alloc_thing(private_host_t);
@@ -190,8 +217,20 @@ host_t *host_create(int family, char *address, u_int16_t port)
this->public.get_address = (char* (*) (host_t *))get_address;
this->public.get_address_as_chunk = (chunk_t (*) (host_t *)) get_address_as_chunk;
this->public.get_port = (u_int16_t (*) (host_t *))get_port;
this->public.ip_is_equal = (bool (*) (host_t *,host_t *)) ip_is_equal;
this->public.is_default_route = (bool (*) (host_t *)) is_default_route;
this->public.destroy = (void (*) (host_t*))destroy;
return this;
}
/*
* Described in header.
*/
host_t *host_create(int family, char *address, u_int16_t port)
{
private_host_t *this = host_create_empty();
this->family = family;
switch (family)
@@ -204,11 +243,16 @@ host_t *host_create(int family, char *address, u_int16_t port)
sin->sin_addr.s_addr = inet_addr(address);
sin->sin_port = htons(port);
this->socklen = sizeof(struct sockaddr_in);
return (host_t*)this;
return &(this->public);
}
default:
{
allocator_free(this);
return NULL;
}
}
allocator_free(this);
return NULL;
}
/*
@@ -216,16 +260,7 @@ host_t *host_create(int family, char *address, u_int16_t port)
*/
host_t *host_create_from_chunk(int family, chunk_t address, u_int16_t port)
{
private_host_t *this = allocator_alloc_thing(private_host_t);
this->public.get_sockaddr = (sockaddr_t* (*) (host_t*))get_sockaddr;
this->public.get_sockaddr_len = (socklen_t*(*) (host_t*))get_sockaddr_len;
this->public.clone = (host_t* (*) (host_t*))clone;
this->public.get_address = (char* (*) (host_t *))get_address;
this->public.get_address_as_chunk = (chunk_t (*) (host_t *)) get_address_as_chunk;
this->public.get_port = (u_int16_t (*) (host_t *))get_port;
this->public.equals = (bool (*) (host_t *,host_t *))equals;
this->public.destroy = (void (*) (host_t*))destroy;
private_host_t *this = host_create_empty();
this->family = family;
@@ -241,8 +276,9 @@ host_t *host_create_from_chunk(int family, chunk_t address, u_int16_t port)
memcpy(&(sin->sin_addr.s_addr),address.ptr,4);
sin->sin_port = htons(port);
this->socklen = sizeof(struct sockaddr_in);
return (host_t*)this;
return &(this->public);
}
}
}
allocator_free(this);
+15 -5
View File
@@ -81,17 +81,27 @@ struct host_t {
* Mostly used for debugging purposes.
* @warning string must NOT be freed
*
* @param this object to clone
* @param this object
* @return address string,
*/
char* (*get_address) (host_t *this);
/**
* @brief Checks if the ip address of host is set to default route.
*
* @param this calling object
* @return
* - TRUE if host has IP 0.0.0.0 for default route
* - FALSE otherwise
*/
bool (*is_default_route) (host_t *this);
/**
* @brief get the address of this host as chunk_t
*
* @warning returned chunk has to get destroyed by caller.
*
* @param this object to clone
* @param this object
* @return address string,
*/
chunk_t (*get_address_as_chunk) (host_t *this);
@@ -107,13 +117,13 @@ struct host_t {
u_int16_t (*get_port) (host_t *this);
/**
* @brief Compare two hosts.
* @brief Compare the ips of two hosts hosts.
*
* @param this object to compare
* @param other the other to compare
* @return TRUE if port and address are equal
* @return TRUE if addresses are equal.
*/
bool (*equals) (host_t *this, host_t *other);
bool (*ip_is_equal) (host_t *this, host_t *other);
/**
* @brief Destroy this host object