Skip to content
Snippets Groups Projects
Unverified Commit 3f926ba4 authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner
Browse files

Merge branch 'fwupdate'

Interminnent merge, to bring an improvement of the fwup plugin master
for easy deploy (as this plugin is not out in the wild yet, there's
nothing that would break by this merge).
parents 57627c4a 40022854
No related branches found
No related tags found
No related merge requests found
......@@ -419,7 +419,9 @@ CREATE TABLE fwup_sets (
name TEXT NOT NULL PRIMARY KEY,
type CHAR NOT NULL,
maxsize INT NOT NULL,
CHECK(maxsize > 0)
hashsize INT NOT NULL,
CHECK(maxsize > 0),
CHECK(hashsize >= maxsize)
);
CREATE TABLE fwup_addresses (
set TEXT NOT NULL,
......@@ -781,7 +783,7 @@ INSERT INTO groups (name) VALUES ('all'), ('ruth');
INSERT INTO group_members (client, in_group) SELECT clients.id, groups.id FROM clients CROSS JOIN groups WHERE groups.name = 'all';
INSERT INTO group_members (client, in_group) SELECT clients.id, groups.id FROM clients JOIN groups ON groups.name = clients.name;
INSERT INTO ping_requests (host, proto, amount, size, active) VALUES ('turris.cz', '6', 5, 100, TRUE), ('turris.cz', '4', 5, 100, TRUE), ('8.8.8.8', 'X', 3, 64, TRUE);
INSERT INTO known_plugins (name) VALUES ('Count'), ('Bandwidth'), ('Fake'), ('Flow'), ('Refused'), ('Sniff'), ('Spoof'), ('FWUp');
INSERT INTO known_plugins (name) VALUES ('Count'), ('Bandwidth'), ('Fake'), ('Flow'), ('Refused'), ('Sniff'), ('Spoof'), ('Fwup');
COMMIT;
ENDSQL
else
......
......@@ -37,14 +37,14 @@ class FWUpPlugin(plugin.Plugin, diff_addr_store.DiffAddrStore):
def __build_config(self):
def convert(name):
return struct.pack('!I' + str(len(name)) + 'scI', len(name), name, self.__sets[name][0], self.__sets[name][1])
return struct.pack('!I' + str(len(name)) + 'scII', len(name), name, self.__sets[name][0], self.__sets[name][1], self.__sets[name][2])
return ''.join(['C', struct.pack('!II', int(self._conf.get('version', 0)), len(self.__sets))] + map(convert, self.__sets.keys()))
def _broadcast_config(self):
# Read the rest of the config
with database.transaction() as t:
t.execute("SELECT name, type, maxsize FROM fwup_sets")
self.__sets = dict(map(lambda (name, tp, maxsize): (name, (tp, maxsize)), t.fetchall()))
t.execute("SELECT name, type, maxsize, hashsize FROM fwup_sets")
self.__sets = dict(map(lambda (name, tp, maxsize, hashsize): (name, (tp, maxsize, hashsize)), t.fetchall()))
self.__config_message = self.__build_config()
self.broadcast(self.__config_message)
......
......@@ -92,6 +92,9 @@ The server sends these kinds of messages:
string::: Name of the set.
`char`::: Type of the set. See above.
`uint32_t`::: Maximum size of the set.
`uint32_t`::: Hash size of the set (for now, all our supported
types are hashes, so the question what happens for non-hash
sets isn't answered yet).
`R`:: Request from the server to reload all the sets in kernel.
`V`:: Version of set info. It is followed by:
`uint32_t`;; Current version of config. If it doesn't match, the
......
......@@ -49,7 +49,7 @@ struct set {
const char *tmp_name;
enum set_state state;
const struct set_type *type;
size_t max_size;
size_t max_size, hash_size;
struct diff_addr_store *store;
struct context *context; // Filled in before each call on a function manipulating the set. It is needed inside the hooks.
};
......@@ -103,7 +103,7 @@ static void replace_start(struct diff_addr_store *store) {
struct mem_pool *tmp_pool = set->context->temp_pool;
// It is OK to allocate the data from the temporary memory pool. It's lifetime is at least the length of call to the plugin communication callback, and the whole set replacement happens there.
set->tmp_name = mem_pool_printf(tmp_pool, "%s-replace", set->name);
enqueue(set->context, set->context->user_data->queue, mem_pool_printf(tmp_pool, "create %s %s family %s maxelem %zu\n", set->tmp_name, set->type->desc, set->type->family, set->max_size));
enqueue(set->context, set->context->user_data->queue, mem_pool_printf(tmp_pool, "create %s %s family %s hashsize %zu maxelem %zu\n", set->tmp_name, set->type->desc, set->type->family, set->hash_size, set->max_size));
}
static void replace_end(struct diff_addr_store *store) {
......@@ -129,10 +129,12 @@ static bool set_parse(struct mem_pool *pool, struct set *target, const uint8_t *
char *name;
uint8_t t;
uint32_t max_size;
uplink_parse(data, length, "scu",
uint32_t hash_size;
uplink_parse(data, length, "scuu",
&name, NULL, pool, "set name in FWUp config",
&t, "set type in FWUp config",
&max_size, "max size of set in FWUp config");
&max_size, "max size of set in FWUp config",
&hash_size, "hash size of set in FWUp config");
const struct set_type *type = &set_types[t];
if (!type->desc) {
ulog(LLOG_WARN, "Set %s of unknown type '%c' (%hhu), ignoring\n", name, t, t);
......@@ -143,6 +145,7 @@ static bool set_parse(struct mem_pool *pool, struct set *target, const uint8_t *
.type = type,
.state = SS_NEWBORN,
.max_size = max_size,
.hash_size = hash_size,
.store = diff_addr_store_init(pool, name)
};
store_set_hooks(target);
......@@ -183,7 +186,7 @@ static void config_parse(struct context *context, const uint8_t *data, size_t le
else
target_count --; // The set is strange, skip it.
if (length)
ulog(LLOG_WARN, "Extra data after FWUp filter (%zu)\n", length);
ulog(LLOG_WARN, "Extra data after set list (%zu)\n", length);
// Go through the old sets and mark them as dead (so they could be resurected in the new ones)
for (size_t i = 0; i < u->set_count; i ++)
switch (u->sets[i].state) {
......@@ -199,7 +202,7 @@ static void config_parse(struct context *context, const uint8_t *data, size_t le
// Go through the new ones and look for corresponding sets in the old config
for (size_t i = 0; i < target_count; i ++) {
for (size_t j = 0; j < u->set_count; j ++)
if (strcmp(sets[i].name, u->sets[j].name) == 0 && sets[i].type == u->sets[j].type && sets[i].max_size == u->sets[j].max_size) {
if (strcmp(sets[i].name, u->sets[j].name) == 0 && sets[i].type == u->sets[j].type && sets[i].max_size == u->sets[j].max_size && sets[i].hash_size == u->sets[j].hash_size) {
switch (u->sets[j].state) {
case SS_DEAD:
diff_addr_store_cp(sets[i].store, u->sets[j].store, context->temp_pool);
......@@ -234,7 +237,7 @@ static void config_parse(struct context *context, const uint8_t *data, size_t le
for (size_t i = 0; i < target_count; i ++) {
switch (sets[i].state) {
case SS_NEWBORN:
enqueue(context, u->queue, mem_pool_printf(context->temp_pool, "create %s %s family %s maxelem %zu\n", sets[i].name, sets[i].type->desc, sets[i].type->family, sets[i].max_size));
enqueue(context, u->queue, mem_pool_printf(context->temp_pool, "create %s %s family %s hashsize %zu maxelem %zu\n", sets[i].name, sets[i].type->desc, sets[i].type->family, sets[i].hash_size, sets[i].max_size));
sets[i].state = SS_PENDING;
// Fall through to SS_PENDING, as we want to ask for the version too
case SS_PENDING:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment