Commit 36fa3423 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Implement flush_interface.

parent 336de763
...@@ -675,6 +675,27 @@ add_ifconf(struct interface_conf *if_conf, struct interface_conf **if_confs) ...@@ -675,6 +675,27 @@ add_ifconf(struct interface_conf *if_conf, struct interface_conf **if_confs)
} }
} }
void
flush_ifconf(struct interface_conf *if_conf)
{
if(if_conf == interface_confs) {
interface_confs = if_conf->next;
free(if_conf);
return;
} else {
struct interface_conf *prev = interface_confs;
while(prev) {
if(prev->next == if_conf) {
prev->next = if_conf->next;
free(if_conf);
return;
}
prev = prev->next;
}
}
fprintf(stderr, "Warning: attempting to free nonexistent ifconf.\n");
}
static int static int
parse_option(int c, gnc_t gnc, void *closure, char *token) parse_option(int c, gnc_t gnc, void *closure, char *token)
{ {
......
...@@ -54,6 +54,8 @@ struct filter { ...@@ -54,6 +54,8 @@ struct filter {
extern struct interface_conf *default_interface_conf; extern struct interface_conf *default_interface_conf;
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); int parse_config_from_string(char *string, int n);
void renumber_filters(void); void renumber_filters(void);
......
...@@ -65,7 +65,10 @@ add_interface(char *ifname, struct interface_conf *if_conf) ...@@ -65,7 +65,10 @@ add_interface(char *ifname, struct interface_conf *if_conf)
FOR_ALL_INTERFACES(ifp) { FOR_ALL_INTERFACES(ifp) {
if(strcmp(ifp->name, ifname) == 0) { if(strcmp(ifp->name, ifname) == 0) {
assert(if_conf == NULL); if(if_conf)
fprintf(stderr,
"Warning: attempting to add existing interface, "
"new configuration ignored.\n");
return ifp; return ifp;
} }
} }
...@@ -89,6 +92,35 @@ add_interface(char *ifname, struct interface_conf *if_conf) ...@@ -89,6 +92,35 @@ add_interface(char *ifname, struct interface_conf *if_conf)
return ifp; return ifp;
} }
void
flush_interface(char *ifname)
{
struct interface *ifp, *prev;
prev = NULL;
ifp = interfaces;
while(ifp) {
if(strcmp(ifp->name, ifname) == 0)
break;
prev = ifp;
ifp = ifp->next;
}
if(ifp == NULL) {
fprintf(stderr, "Warning: attempting to flush nonexistent interface.\n");
return;
}
interface_up(ifp, 0);
if(prev)
prev->next = ifp->next;
else
interfaces = ifp->next;
if(ifp->conf != NULL && ifp->conf != default_interface_conf)
flush_ifconf(ifp->conf);
free(ifp);
}
/* This should be no more than half the hello interval, so that hellos /* This should be no more than half the hello interval, so that hellos
aren't sent late. The result is in milliseconds. */ aren't sent late. The result is in milliseconds. */
unsigned unsigned
......
...@@ -123,6 +123,7 @@ if_up(struct interface *ifp) ...@@ -123,6 +123,7 @@ if_up(struct interface *ifp)
} }
struct interface *add_interface(char *ifname, struct interface_conf *if_conf); struct interface *add_interface(char *ifname, struct interface_conf *if_conf);
void flush_interface(char *ifname);
unsigned jitter(struct interface *ifp, int urgent); unsigned jitter(struct interface *ifp, int urgent);
unsigned update_jitter(struct interface *ifp, int urgent); unsigned update_jitter(struct interface *ifp, int urgent);
void set_timeout(struct timeval *timeout, int msecs); void set_timeout(struct timeval *timeout, int msecs);
......
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