Commit 7c053fe7 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Export add_filters and simplify interface.

parent 91c44f82
...@@ -853,9 +853,26 @@ parse_key(int c, gnc_t gnc, void *closure, struct key **key_return) ...@@ -853,9 +853,26 @@ parse_key(int c, gnc_t gnc, void *closure, struct key **key_return)
return -2; return -2;
} }
static void int
add_filter(struct filter *filter, struct filter **filters) add_filter(struct filter *filter, int type)
{ {
struct filter **filters;
switch(type) {
case FILTER_TYPE_INPUT:
filters = &input_filters;
break;
case FILTER_TYPE_OUTPUT:
filters = &output_filters;
break;
case FILTER_TYPE_REDISTRIBUTE:
filters = &redistribute_filters;
break;
case FILTER_TYPE_INSTALL:
filters = &install_filters;
break;
default:
return -1;
}
if(*filters == NULL) { if(*filters == NULL) {
filter->next = NULL; filter->next = NULL;
*filters = filter; *filters = filter;
...@@ -867,6 +884,7 @@ add_filter(struct filter *filter, struct filter **filters) ...@@ -867,6 +884,7 @@ add_filter(struct filter *filter, struct filter **filters)
filter->next = NULL; filter->next = NULL;
f->next = filter; f->next = filter;
} }
return 1;
} }
static void static void
...@@ -1174,7 +1192,7 @@ parse_config_line(int c, gnc_t gnc, void *closure, ...@@ -1174,7 +1192,7 @@ parse_config_line(int c, gnc_t gnc, void *closure,
c = parse_filter(c, gnc, closure, &filter); c = parse_filter(c, gnc, closure, &filter);
if(c < -1) if(c < -1)
goto fail; goto fail;
add_filter(filter, &input_filters); add_filter(filter, FILTER_TYPE_INPUT);
} else if(strcmp(token, "out") == 0) { } else if(strcmp(token, "out") == 0) {
struct filter *filter; struct filter *filter;
if(config_finalised) if(config_finalised)
...@@ -1182,7 +1200,7 @@ parse_config_line(int c, gnc_t gnc, void *closure, ...@@ -1182,7 +1200,7 @@ parse_config_line(int c, gnc_t gnc, void *closure,
c = parse_filter(c, gnc, closure, &filter); c = parse_filter(c, gnc, closure, &filter);
if(c < -1) if(c < -1)
goto fail; goto fail;
add_filter(filter, &output_filters); add_filter(filter, FILTER_TYPE_OUTPUT);
} else if(strcmp(token, "redistribute") == 0) { } else if(strcmp(token, "redistribute") == 0) {
struct filter *filter; struct filter *filter;
if(config_finalised) if(config_finalised)
...@@ -1190,7 +1208,7 @@ parse_config_line(int c, gnc_t gnc, void *closure, ...@@ -1190,7 +1208,7 @@ parse_config_line(int c, gnc_t gnc, void *closure,
c = parse_filter(c, gnc, closure, &filter); c = parse_filter(c, gnc, closure, &filter);
if(c < -1) if(c < -1)
goto fail; goto fail;
add_filter(filter, &redistribute_filters); add_filter(filter, FILTER_TYPE_REDISTRIBUTE);
} else if(strcmp(token, "install") == 0) { } else if(strcmp(token, "install") == 0) {
struct filter *filter; struct filter *filter;
if(config_finalised) if(config_finalised)
...@@ -1198,7 +1216,7 @@ parse_config_line(int c, gnc_t gnc, void *closure, ...@@ -1198,7 +1216,7 @@ parse_config_line(int c, gnc_t gnc, void *closure,
c = parse_filter(c, gnc, closure, &filter); c = parse_filter(c, gnc, closure, &filter);
if(c < -1) if(c < -1)
goto fail; goto fail;
add_filter(filter, &install_filters); add_filter(filter, FILTER_TYPE_INSTALL);
} else if(strcmp(token, "interface") == 0) { } else if(strcmp(token, "interface") == 0) {
struct interface_conf *if_conf; struct interface_conf *if_conf;
c = parse_ifconf(c, gnc, closure, &if_conf); c = parse_ifconf(c, gnc, closure, &if_conf);
...@@ -1531,7 +1549,7 @@ finalise_config() ...@@ -1531,7 +1549,7 @@ finalise_config()
filter->proto = RTPROT_BABEL_LOCAL; filter->proto = RTPROT_BABEL_LOCAL;
filter->plen_le = 128; filter->plen_le = 128;
filter->src_plen_le = 128; filter->src_plen_le = 128;
add_filter(filter, &redistribute_filters); add_filter(filter, FILTER_TYPE_REDISTRIBUTE);
while(interface_confs) { while(interface_confs) {
struct interface_conf *if_conf; struct interface_conf *if_conf;
......
...@@ -33,6 +33,11 @@ THE SOFTWARE. ...@@ -33,6 +33,11 @@ THE SOFTWARE.
#define AUTH_TYPE_SHA256 1 #define AUTH_TYPE_SHA256 1
#define AUTH_TYPE_BLAKE2S128 2 #define AUTH_TYPE_BLAKE2S128 2
#define FILTER_TYPE_INPUT 0
#define FILTER_TYPE_OUTPUT 1
#define FILTER_TYPE_REDISTRIBUTE 2
#define FILTER_TYPE_INSTALL 3
struct filter_result { struct filter_result {
unsigned int add_metric; /* allow = 0, deny = INF, metric = <0..INF> */ unsigned int add_metric; /* allow = 0, deny = INF, metric = <0..INF> */
unsigned char *src_prefix; unsigned char *src_prefix;
...@@ -64,6 +69,7 @@ void flush_ifconf(struct interface_conf *if_conf); ...@@ -64,6 +69,7 @@ void flush_ifconf(struct interface_conf *if_conf);
int parse_config_from_file(const char *filename, int *line_return); int parse_config_from_file(const char *filename, int *line_return);
int parse_config_from_string(char *string, int n, const char **message_return); int parse_config_from_string(char *string, int n, const char **message_return);
int add_filter(struct filter *filter, int type);
void renumber_filters(void); void renumber_filters(void);
int input_filter(const unsigned char *id, int input_filter(const unsigned char *id,
......
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