Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql: extend peer_configs and child_configs to support modern features #503

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 42 additions & 13 deletions src/libcharon/plugins/sql/sql_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,19 @@ static void add_esp_proposals(private_sql_config_t *this,
static child_cfg_t *build_child_cfg(private_sql_config_t *this, enumerator_t *e)
{
int id, lifetime, rekeytime, jitter, hostaccess, mode, ipcomp, reqid;
int start, dpd, close;
char *name, *updown;
int start, dpd, close, if_id_in, if_id_out, inactivity, tfc, hw_offload;
int copy_dscp;
char *name, *updown, *interface;
mark_t mark_in, mark_out, set_mark_in, set_mark_out;
child_cfg_t *child_cfg;

if (e->enumerate(e, &id, &name, &lifetime, &rekeytime, &jitter, &updown,
&hostaccess, &mode, &start, &dpd, &close, &ipcomp, &reqid))
&hostaccess, &mode, &start, &dpd, &close, &ipcomp, &reqid,
&if_id_in, &if_id_out, &mark_in.value, &mark_in.mask,
&mark_out.value, &mark_out.mask, &set_mark_in.value,
&set_mark_in.mask, &set_mark_out.value,
&set_mark_out.mask, &inactivity, &tfc, &interface,
&hw_offload, &copy_dscp))
{
child_cfg_create_t child = {
.mode = mode,
Expand All @@ -185,6 +192,17 @@ static child_cfg_t *build_child_cfg(private_sql_config_t *this, enumerator_t *e)
.dpd_action = dpd,
.close_action = close,
.updown = updown,
.if_id_in = if_id_in,
.if_id_out = if_id_out,
.mark_in = mark_in,
.mark_out = mark_out,
.set_mark_in = set_mark_in,
.set_mark_out = set_mark_out,
.inactivity = inactivity,
.tfc = tfc,
.interface = interface,
.hw_offload = hw_offload,
.copy_dscp = copy_dscp,
};
child_cfg = child_cfg_create(name, &child);
add_esp_proposals(this, child_cfg, id);
Expand All @@ -205,12 +223,18 @@ static void add_child_cfgs(private_sql_config_t *this, peer_cfg_t *peer, int id)
e = this->db->query(this->db,
"SELECT c.id, c.name, c.lifetime, c.rekeytime, c.jitter, c.updown, "
"c.hostaccess, c.mode, c.start_action, c.dpd_action, "
"c.close_action, c.ipcomp, c.reqid "
"c.close_action, c.ipcomp, c.reqid, c.if_id_in, c.if_id_out, "
"c.mark_in, c.mark_in_mask, c.mark_out, c.mark_out_mask, "
"c.set_mark_in, c.set_mark_in_mask, c.set_mark_out, "
"c.set_mark_out_mask, c.inactivity, c.tfc, c.interface, "
"c.hw_offload, c.copy_dscp "
"FROM child_configs AS c JOIN peer_config_child_config AS pc "
"ON c.id = pc.child_cfg WHERE pc.peer_cfg = ?",
DB_INT, id,
DB_INT, DB_TEXT, DB_INT, DB_INT, DB_INT, DB_TEXT, DB_INT,
DB_INT, DB_INT, DB_INT, DB_INT, DB_INT, DB_INT);
DB_INT, DB_INT, DB_INT, DB_INT, DB_INT, DB_INT, DB_INT, DB_INT,
DB_INT, DB_INT, DB_INT, DB_INT, DB_INT, DB_INT, DB_INT, DB_INT,
DB_INT, DB_INT, DB_TEXT, DB_INT, DB_INT);
if (e)
{
while ((child_cfg = build_child_cfg(this, e)))
Expand Down Expand Up @@ -325,7 +349,8 @@ static peer_cfg_t *get_peer_cfg_by_id(private_sql_config_t *this, int id)
"c.cert_policy, c.uniqueid, c.auth_method, c.eap_type, "
"c.eap_vendor, c.keyingtries, c.rekeytime, c.reauthtime, c.jitter, "
"c.overtime, c.mobike, c.dpd_delay, c.virtual, c.pool, "
"c.mediation, c.mediated_by, COALESCE(p.type, 0), p.data "
"c.mediation, c.mediated_by, c.if_id_in, c.if_id_out, "
"COALESCE(p.type, 0), p.data "
"FROM peer_configs AS c "
"JOIN identities AS l ON c.local_id = l.id "
"JOIN identities AS r ON c.remote_id = r.id "
Expand All @@ -336,7 +361,7 @@ static peer_cfg_t *get_peer_cfg_by_id(private_sql_config_t *this, int id)
DB_INT, DB_INT, DB_INT, DB_INT, DB_INT,
DB_INT, DB_INT, DB_INT, DB_INT, DB_INT, DB_INT,
DB_INT, DB_TEXT, DB_TEXT,
DB_INT, DB_INT, DB_INT, DB_BLOB);
DB_INT, DB_INT, DB_INT, DB_INT, DB_INT, DB_BLOB);
if (e)
{
peer_cfg = build_peer_cfg(this, e, NULL, NULL);
Expand All @@ -363,7 +388,7 @@ static peer_cfg_t *build_peer_cfg(private_sql_config_t *this, enumerator_t *e,
int id, ike_cfg, l_type, r_type,
cert_policy, uniqueid, auth_method, eap_type, eap_vendor, keyingtries,
rekeytime, reauthtime, jitter, overtime, mobike, dpd_delay,
mediation, mediated_by, p_type;
mediation, mediated_by, if_id_in, if_id_out, p_type;
chunk_t l_data, r_data, p_data;
char *name, *virtual, *pool;
enumerator_t *enumerator;
Expand All @@ -373,7 +398,7 @@ static peer_cfg_t *build_peer_cfg(private_sql_config_t *this, enumerator_t *e,
&cert_policy, &uniqueid, &auth_method, &eap_type, &eap_vendor,
&keyingtries, &rekeytime, &reauthtime, &jitter, &overtime, &mobike,
&dpd_delay, &virtual, &pool,
&mediation, &mediated_by, &p_type, &p_data))
&mediation, &mediated_by, &if_id_in, &if_id_out, &p_type, &p_data))
{
identification_t *local_id, *remote_id, *peer_id = NULL;
peer_cfg_t *peer_cfg, *mediated_cfg = NULL;
Expand Down Expand Up @@ -416,6 +441,8 @@ static peer_cfg_t *build_peer_cfg(private_sql_config_t *this, enumerator_t *e,
.over_time = overtime,
.no_mobike = !mobike,
.dpd = dpd_delay,
.if_id_in = if_id_in,
.if_id_out = if_id_out,
#ifdef ME
.mediation = mediation,
.mediated_by = mediated_cfg ?
Expand Down Expand Up @@ -480,7 +507,8 @@ METHOD(backend_t, get_peer_cfg_by_name, peer_cfg_t*,
"c.cert_policy, c.uniqueid, c.auth_method, c.eap_type, "
"c.eap_vendor, c.keyingtries, c.rekeytime, c.reauthtime, c.jitter, "
"c.overtime, c.mobike, c.dpd_delay, c.virtual, c.pool, "
"c.mediation, c.mediated_by, COALESCE(p.type, 0), p.data "
"c.mediation, c.mediated_by, c.if_id_in, c.if_id_out, "
"COALESCE(p.type, 0), p.data "
"FROM peer_configs AS c "
"JOIN identities AS l ON c.local_id = l.id "
"JOIN identities AS r ON c.remote_id = r.id "
Expand All @@ -491,7 +519,7 @@ METHOD(backend_t, get_peer_cfg_by_name, peer_cfg_t*,
DB_INT, DB_INT, DB_INT, DB_INT, DB_INT,
DB_INT, DB_INT, DB_INT, DB_INT, DB_INT, DB_INT,
DB_INT, DB_TEXT, DB_TEXT,
DB_INT, DB_INT, DB_INT, DB_BLOB);
DB_INT, DB_INT, DB_INT, DB_INT, DB_INT, DB_BLOB);
if (e)
{
peer_cfg = build_peer_cfg(this, e, NULL, NULL);
Expand Down Expand Up @@ -628,7 +656,8 @@ METHOD(backend_t, create_peer_cfg_enumerator, enumerator_t*,
"c.cert_policy, c.uniqueid, c.auth_method, c.eap_type, "
"c.eap_vendor, c.keyingtries, c.rekeytime, c.reauthtime, c.jitter, "
"c.overtime, c.mobike, c.dpd_delay, c.virtual, c.pool, "
"c.mediation, c.mediated_by, COALESCE(p.type, 0), p.data "
"c.mediation, c.mediated_by, c.if_id_in, c.if_id_out, "
"COALESCE(p.type, 0), p.data "
"FROM peer_configs AS c "
"JOIN identities AS l ON c.local_id = l.id "
"JOIN identities AS r ON c.remote_id = r.id "
Expand All @@ -639,7 +668,7 @@ METHOD(backend_t, create_peer_cfg_enumerator, enumerator_t*,
DB_INT, DB_INT, DB_INT, DB_INT, DB_INT,
DB_INT, DB_INT, DB_INT, DB_INT, DB_INT, DB_INT,
DB_INT, DB_TEXT, DB_TEXT,
DB_INT, DB_INT, DB_INT, DB_BLOB);
DB_INT, DB_INT, DB_INT, DB_INT, DB_INT, DB_BLOB);
if (!e->inner)
{
free(e);
Expand Down
17 changes: 17 additions & 0 deletions src/pool/mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@ CREATE TABLE `child_configs` (
`close_action` tinyint(4) unsigned NOT NULL default '0',
`ipcomp` tinyint(4) unsigned NOT NULL default '0',
`reqid` mediumint(8) unsigned NOT NULL default '0',
`if_id_in` mediumint(8) unsigned NOT NULL default '0',
`if_id_out` mediumint(8) unsigned NOT NULL default '0',
`mark_in` mediumint(8) unsigned NOT NULL default '0',
`mark_in_mask` mediumint(8) unsigned NOT NULL default '0',
`mark_out` mediumint(8) unsigned NOT NULL default '0',
`mark_out_mask` mediumint(8) unsigned NOT NULL default '0',
`set_mark_in` mediumint(8) unsigned NOT NULL default '0',
`set_mark_in_mask` mediumint(8) unsigned NOT NULL default '0',
`set_mark_out` mediumint(8) unsigned NOT NULL default '0',
`set_mark_out_mask` mediumint(8) unsigned NOT NULL default '0',
`inactivity` mediumint(8) unsigned NOT NULL default '0',
`tfc` mediumint(8) unsigned NOT NULL default '0',
`interface` varchar(16) collate utf8_unicode_ci default NULL,
`hw_offload` tinyint(4) unsigned NOT NULL default '0',
`copy_dscp` tinyint(4) unsigned NOT NULL default '0',
PRIMARY KEY (`id`),
INDEX (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
Expand Down Expand Up @@ -98,6 +113,8 @@ CREATE TABLE `peer_configs` (
`mediation` tinyint(1) NOT NULL default '0',
`mediated_by` int(10) unsigned NOT NULL default '0',
`peer_id` int(10) unsigned NOT NULL default '0',
`if_id_in` mediumint(8) unsigned NOT NULL default '0',
`if_id_out` mediumint(8) unsigned NOT NULL default '0',
PRIMARY KEY (`id`),
INDEX (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
Expand Down
21 changes: 19 additions & 2 deletions src/pool/sqlite.sql
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,22 @@ CREATE TABLE child_configs (
dpd_action INTEGER NOT NULL DEFAULT '0',
close_action INTEGER NOT NULL DEFAULT '0',
ipcomp INTEGER NOT NULL DEFAULT '0',
reqid INTEGER NOT NULL DEFAULT '0'
reqid INTEGER NOT NULL DEFAULT '0',
if_id_in INTEGER NOT NULL DEFAULT '0',
if_id_out INTEGER NOT NULL DEFAULT '0',
mark_in INTEGER NOT NULL DEFAULT '0',
mark_in_mask INTEGER NOT NULL DEFAULT '0',
mark_out INTEGER NOT NULL DEFAULT '0',
mark_out_mask INTEGER NOT NULL DEFAULT '0',
set_mark_in INTEGER NOT NULL DEFAULT '0',
set_mark_in_mask INTEGER NOT NULL DEFAULT '0',
set_mark_out INTEGER NOT NULL DEFAULT '0',
set_mark_out_mask INTEGER NOT NULL DEFAULT '0',
inactivity INTEGER NOT NULL DEFAULT '0',
tfc INTEGER NOT NULL DEFAULT '0',
interface TEXT DEFAULT NULL,
hw_offload INTEGER NOT NULL DEFAULT '0',
copy_dscp INTEGER NOT NULL DEFAULT '0'
);
DROP INDEX IF EXISTS child_configs_name;
CREATE INDEX child_configs_name ON child_configs (
Expand Down Expand Up @@ -99,7 +114,9 @@ CREATE TABLE peer_configs (
pool TEXT DEFAULT NULL,
mediation INTEGER NOT NULL DEFAULT '0',
mediated_by INTEGER NOT NULL DEFAULT '0',
peer_id INTEGER NOT NULL DEFAULT '0'
peer_id INTEGER NOT NULL DEFAULT '0',
if_id_in INTEGER NOT NULL DEFAULT '0',
if_id_out INTEGER NOT NULL DEFAULT '0'
);
DROP INDEX IF EXISTS peer_configs_name;
CREATE INDEX peer_configs_name ON peer_configs (
Expand Down