Commit ae417d54 authored by Matthieu Boutier's avatar Matthieu Boutier Committed by Juliusz Chroboczek

Rename "struct kernel_table" in "struct rule".

parent 2c151460
...@@ -1689,16 +1689,16 @@ flush_rule(int prio, int family) ...@@ -1689,16 +1689,16 @@ flush_rule(int prio, int family)
/* The table used for non-specific routes is "export_table", therefore, we can /* The table used for non-specific routes is "export_table", therefore, we can
take the convention of plen == 0 <=> empty table. */ take the convention of plen == 0 <=> empty table. */
struct kernel_table { struct rule {
unsigned char src[16]; unsigned char src[16];
unsigned char plen; unsigned char plen;
unsigned char table; unsigned char table;
}; };
/* kernel_tables contains informations about the rules we installed. It is an /* rules contains informations about the rules we installed. It is an array
array indexed by: <table priority> - src_table_prio. indexed by: <table priority> - src_table_prio.
(First entries are the most specific, since they have priority.) */ (First entries are the most specific, since they have priority.) */
static struct kernel_table kernel_tables[SRC_TABLE_NUM]; static struct rule rules[SRC_TABLE_NUM];
/* used tables is indexed by: <table number> - src_table_idx /* used tables is indexed by: <table number> - src_table_idx
used_tables[i] == 1 <=> the table number (i + src_table_idx) is used */ used_tables[i] == 1 <=> the table number (i + src_table_idx) is used */
static char used_tables[SRC_TABLE_NUM] = {0}; static char used_tables[SRC_TABLE_NUM] = {0};
...@@ -1717,9 +1717,9 @@ change_table_priority(const unsigned char *src, int plen, int table, ...@@ -1717,9 +1717,9 @@ change_table_priority(const unsigned char *src, int plen, int table,
return flush_rule(old_prio, v4mapped(src) ? AF_INET : AF_INET6); return flush_rule(old_prio, v4mapped(src) ? AF_INET : AF_INET6);
} }
/* Return a new table at index [idx] of kernel_tables. If cell at that index is /* Return a new table at index [idx] of rules. If cell at that index is not
not free, we need to shift cells (and rules). If it's full, return NULL. */ free, we need to shift cells (and rules). If it's full, return NULL. */
static struct kernel_table * static struct rule *
insert_table(const unsigned char *src, unsigned short src_plen, int idx) insert_table(const unsigned char *src, unsigned short src_plen, int idx)
{ {
int table; int table;
...@@ -1743,22 +1743,22 @@ insert_table(const unsigned char *src, unsigned short src_plen, int idx) ...@@ -1743,22 +1743,22 @@ insert_table(const unsigned char *src, unsigned short src_plen, int idx)
table += src_table_idx; table += src_table_idx;
/* Create the table's rule at the right place. Shift rules if necessary. */ /* Create the table's rule at the right place. Shift rules if necessary. */
if(kernel_tables[idx].plen != 0) { if(rules[idx].plen != 0) {
/* shift right */ /* shift right */
i = src_table_used; i = src_table_used;
while(i > idx) { while(i > idx) {
i--; i--;
rc = change_table_priority(kernel_tables[i].src, rc = change_table_priority(rules[i].src,
kernel_tables[i].plen, rules[i].plen,
kernel_tables[i].table, rules[i].table,
i + src_table_prio, i + src_table_prio,
i + 1 + src_table_prio); i + 1 + src_table_prio);
if(rc < 0) { if(rc < 0) {
perror("change_table_priority"); perror("change_table_priority");
return NULL; return NULL;
} }
kernel_tables[i+1] = kernel_tables[i]; rules[i+1] = rules[i];
kernel_tables[i].plen = 0; rules[i].plen = 0;
} }
} }
...@@ -1768,27 +1768,27 @@ insert_table(const unsigned char *src, unsigned short src_plen, int idx) ...@@ -1768,27 +1768,27 @@ insert_table(const unsigned char *src, unsigned short src_plen, int idx)
return NULL; return NULL;
} }
used_tables[table - src_table_idx] = 1; used_tables[table - src_table_idx] = 1;
memcpy(kernel_tables[idx].src, src, 16); memcpy(rules[idx].src, src, 16);
kernel_tables[idx].plen = src_plen; rules[idx].plen = src_plen;
kernel_tables[idx].table = table; rules[idx].table = table;
src_table_used++; src_table_used++;
return &kernel_tables[idx]; return &rules[idx];
} }
/* Sorting kernel_tables in a well ordered fashion will increase code complexity /* Sorting rules in a well ordered fashion will increase code complexity and
and decrease performances, because more rule shifs will be required, so more decrease performances, because more rule shifs will be required, so more
system calls invoked. */ system calls invoked. */
static int static int
find_table_slot(const unsigned char *src, unsigned short src_plen, find_table_slot(const unsigned char *src, unsigned short src_plen,
int *new_return) int *new_return)
{ {
struct kernel_table *kt = NULL; struct rule *kt = NULL;
int i; int i;
*new_return = -1; *new_return = -1;
for(i = 0; i < SRC_TABLE_NUM; i++) { for(i = 0; i < SRC_TABLE_NUM; i++) {
kt = &kernel_tables[i]; kt = &rules[i];
if(kt->plen == 0) if(kt->plen == 0)
goto new_table_here; /* empty table here */ goto new_table_here; /* empty table here */
switch(prefix_cmp(src, src_plen, kt->src, kt->plen)) { switch(prefix_cmp(src, src_plen, kt->src, kt->plen)) {
...@@ -1811,7 +1811,7 @@ find_table_slot(const unsigned char *src, unsigned short src_plen, ...@@ -1811,7 +1811,7 @@ find_table_slot(const unsigned char *src, unsigned short src_plen,
static int static int
find_table(const unsigned char *src, unsigned short src_plen) find_table(const unsigned char *src, unsigned short src_plen)
{ {
struct kernel_table *kt = NULL; struct rule *kt = NULL;
int i, new_i; int i, new_i;
if(src_plen == 0 || if(src_plen == 0 ||
...@@ -1827,7 +1827,7 @@ find_table(const unsigned char *src, unsigned short src_plen) ...@@ -1827,7 +1827,7 @@ find_table(const unsigned char *src, unsigned short src_plen)
return -1; return -1;
kt = insert_table(src, src_plen, new_i); kt = insert_table(src, src_plen, new_i);
} else { } else {
kt = &kernel_tables[i]; kt = &rules[i];
} }
return kt == NULL ? -1 : kt->table; return kt == NULL ? -1 : kt->table;
} }
...@@ -1837,10 +1837,10 @@ release_tables(void) ...@@ -1837,10 +1837,10 @@ release_tables(void)
{ {
int i; int i;
for(i = 0; i < SRC_TABLE_NUM; i++) { for(i = 0; i < SRC_TABLE_NUM; i++) {
if(kernel_tables[i].plen != 0) { if(rules[i].plen != 0) {
flush_rule(i + src_table_prio, flush_rule(i + src_table_prio,
v4mapped(kernel_tables[i].src) ? AF_INET : AF_INET6); v4mapped(rules[i].src) ? AF_INET : AF_INET6);
kernel_tables[i].plen = 0; rules[i].plen = 0;
} }
used_tables[i] = 0; used_tables[i] = 0;
} }
...@@ -1935,8 +1935,8 @@ filter_kernel_rules(struct nlmsghdr *nh, void *data) ...@@ -1935,8 +1935,8 @@ filter_kernel_rules(struct nlmsghdr *nh, void *data)
return 1; return 1;
if(prefix_cmp(src, src_plen, if(prefix_cmp(src, src_plen,
kernel_tables[i].src, kernel_tables[i].plen) == PST_EQUALS && rules[i].src, rules[i].plen) == PST_EQUALS &&
table == kernel_tables[i].table && table == rules[i].table &&
!rule_exists[i]) { !rule_exists[i]) {
rule_exists[i] = 1; rule_exists[i] = 1;
} else { } else {
...@@ -1944,7 +1944,7 @@ filter_kernel_rules(struct nlmsghdr *nh, void *data) ...@@ -1944,7 +1944,7 @@ filter_kernel_rules(struct nlmsghdr *nh, void *data)
do { do {
rc = flush_rule(i + src_table_prio, is_v4 ? AF_INET : AF_INET6); rc = flush_rule(i + src_table_prio, is_v4 ? AF_INET : AF_INET6);
} while(rc >= 0); } while(rc >= 0);
/* flush unexpected rules, but keep information in kernel_tables[i]. It /* flush unexpected rules, but keep information in rules[i]. It
will be used afterwards to reinstall the rule. */ will be used afterwards to reinstall the rule. */
if(errno != ENOENT && errno != EEXIST) if(errno != ENOENT && errno != EEXIST)
fprintf(stderr, fprintf(stderr,
...@@ -1968,16 +1968,16 @@ install_missing_rules(char rule_exists[SRC_TABLE_NUM], int v4) ...@@ -1968,16 +1968,16 @@ install_missing_rules(char rule_exists[SRC_TABLE_NUM], int v4)
{ {
int i, rc; int i, rc;
for(i = 0; i < SRC_TABLE_NUM; i++) for(i = 0; i < SRC_TABLE_NUM; i++)
if(v4mapped(kernel_tables[i].src) == v4 && if(v4mapped(rules[i].src) == v4 &&
!rule_exists[i] && kernel_tables[i].plen != 0) { !rule_exists[i] && rules[i].plen != 0) {
rc = add_rule(i + src_table_prio, kernel_tables[i].src, rc = add_rule(i + src_table_prio, rules[i].src,
kernel_tables[i].plen, kernel_tables[i].table); rules[i].plen, rules[i].table);
if(rc < 0) if(rc < 0)
fprintf(stderr, fprintf(stderr,
"install_missing_rules: " "install_missing_rules: "
"Cannot install rule: table %d prio %d from %s\n", "Cannot install rule: table %d prio %d from %s\n",
kernel_tables[i].table, i + src_table_prio, rules[i].table, i + src_table_prio,
format_prefix(kernel_tables[i].src, format_prefix(rules[i].src,
kernel_tables[i].plen)); rules[i].plen));
} }
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment