-/* $OpenBSD: ipsecctl.c,v 1.70 2008/07/01 15:00:53 bluhm Exp $ */
+/* $OpenBSD: ipsecctl.c,v 1.71 2008/07/21 14:37:53 bluhm Exp $ */
/*
* Copyright (c) 2004, 2005 Hans-Joerg Hoexer <hshoexer@openbsd.org>
*
int
ipsecctl_rules(char *filename, int opts)
{
- struct ipsecctl ipsec;
- int action, error = 0;
+ struct ipsecctl ipsec;
+ struct ipsec_rule *rp;
+ int action, error = 0;
bzero(&ipsec, sizeof(ipsec));
ipsec.opts = opts;
if ((opts & IPSECCTL_OPT_NOACTION) == 0)
error = ipsecctl_commit(action, &ipsec);
+
+ }
+
+ /* This also frees the rules in ipsec.group_queue. */
+ while ((rp = TAILQ_FIRST(&ipsec.rule_queue))) {
+ TAILQ_REMOVE(&ipsec.rule_queue, rp, rule_entry);
+ ipsecctl_free_rule(rp);
}
+
return (error);
}
if (pfkey_init() == -1)
errx(1, "ipsecctl_commit: failed to open PF_KEY socket");
- while ((rp = TAILQ_FIRST(&ipsec->rule_queue))) {
- TAILQ_REMOVE(&ipsec->rule_queue, rp, rule_entry);
-
+ TAILQ_FOREACH(rp, &ipsec->rule_queue, rule_entry) {
if (rp->type & RULE_IKE) {
if (ike_ipsec_establish(action, rp) == -1) {
warnx("failed to %s rule %d",
ret = 2;
}
}
- ipsecctl_free_rule(rp);
}
return (ret);